Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
NtotheTC
Dec 31, 2007


Dominoes posted:

Python code:
def try_this(my_dict: dict, key) -> Union[dict, int]:

As an aside, what syntax is this? I've not seen this before in Python.

Adbot
ADBOT LOVES YOU

NtotheTC
Dec 31, 2007


huhu posted:

I'm having a Pycharm or Python issue...
code:
from foo import bar

def test(input):
    myBar = bar()
    return myBar.myMethod(input)

AttributeError: 'bar' object has no attribute 'myMethod'
If I click on myMethod() and navigate to where it is originally declared, it opens the file foo and goes to the bar definition. What am I missing here?

Edit: It's a Pycharm issue. I renamed the directory and reopened it in Pycharm and it's working now. Any ideas what I might triggered by renaming the directory?

Was the file actually named "foo" and the class "bar"? If not its possible you named your file something that was already taken by standard lib or an external library. Is the file in the same directory as the file you're importing into? Try
code:
from .foo import bar

NtotheTC
Dec 31, 2007


So my new project is sufficiently out of the quagmires of legacy code that I get to start using the latest versions of everything- including python3.6 over python2.7. It's perhaps a bit shameful that I've done virtually no commercial coding with python3, but I'm wondering if there's a list of the biggest changes I'll need to wrap my head around? f_string_literals and type hinting are two that I've been made aware of but I'm sure there's more out there.

NtotheTC
Dec 31, 2007


That's perfect, thanks!

NtotheTC
Dec 31, 2007


So Microsoft are considering making Python an official scripting language in Excel which is pretty cool I guess. Though it means when my friends ask me "Hey fix my spreadsheets" I can't use the "sorry I don't know anything abiut vba" excuse.

NtotheTC
Dec 31, 2007


Does anyone know if pipenv can replicate the behaviour of vex? (https://pypi.python.org/pypi/vex) I've always found vex to be lightyears ahead of virtualenvwrapper for development (activating and deactivating virtualenvs manually is a horrible pattern) but I've never used pipenv and people seem very happy with it

To be clear, the behaviour I want to replicate is

Bash code:
vex myenv python myscript.py
instead of
Bash code:
workon myenv
python myscript.py
deactivate myenv

NtotheTC fucked around with this message at 15:22 on Jan 21, 2018

NtotheTC
Dec 31, 2007


I know a few of you guys run your python linux dev environments in vms due to being on windows machines out of preference or necessity...

Anyone have any experience with using Pycharm with docker / windows subsystem for Linux? My current place of work runs windows machines only but our app is switching over to docker containers on Linux and I'm looking for a way to develop on Linux without actually having to dual boot if possible.

NtotheTC
Dec 31, 2007


WSL support is huge but at the moment file permissions not transferring and the lack of systemd support meant I couldn't use it for development

NtotheTC
Dec 31, 2007


Mrenda posted:

Is there a particular setup I should have for developing with Python on windows?

Is developing on windows a requirement or a preference?

Also: Web development or desktop app or machine learning etc?

NtotheTC fucked around with this message at 15:21 on Jul 6, 2018

NtotheTC
Dec 31, 2007


Quote is not edit

NtotheTC fucked around with this message at 15:20 on Jul 6, 2018

NtotheTC
Dec 31, 2007


Mrenda posted:

I have python setup in a Linux VM where I'm playing around with Flask, but I want to be able to use it for stuff on Windows too rather than switching about in languages. I've done a few MOOC courses but never really made/finished anything, so I'm just looking to make a lil' program for Win10 that pulls weather info from an API I've yet to find, stores it and displays it.

Fair enough - I'm a big proponent of developing on the target OS so personally I'd install the latest python3 binary from python.org and then use pipenv to manage your python requirements. I don't recommend trying to go through git bash or bash for windows, if you want a posix environment then I'd just develop on native linux

NtotheTC
Dec 31, 2007


Seconding Click- using it to create neat command line apps is one of life's purest pleasures and I wish I could make it my full time job somehow

NtotheTC
Dec 31, 2007


qkkl posted:

Let's say I've defined in my_file.py several enums in an enum class called MyEnum. I now want to use those enums in another file. What works right now is to import the MyEnum class with

code:
from my_file import MyEnum
and then use the enums like

code:
MyEnum.ENUM_1
Is there a way to use the enums by using their names directly without having to prefix them with the MyEnum class name? Basically I'm looking for something similar to a static import in Java because I don't want to type out the class name every time I use an enum.

You could just define the enums at the module level and then import them directly?

code:
from my_file import ENUM_1
What is the purpose of the MyEnum class other than a container for the enums?

E: ignore me Enums are actually a thing now in python, I didn't actually know that

NtotheTC fucked around with this message at 22:15 on Jul 19, 2018

NtotheTC
Dec 31, 2007


Anyone have any experience with using Poetry for python projects? I recently moved over to using pipenv for everything (still a huge improvement over virtualenvwrapper or vex or whatever was used beforehand) only to learn about Poetry the other day and looking at it it does seem to have massive advantages despite being newer.

NtotheTC
Dec 31, 2007


Django is definitely worth exploring, just because being able to turn anything into a website is a useful tool to have. You'll find you gain quite a lot knowledge about client/server architecture, deployment and packaging, SQL and RDBMSs just through osmosis, but at any time you can drill down into any one of those topics and they're each a discipline of their own

NtotheTC
Dec 31, 2007


Boris Galerkin posted:

I found on one of their closed GitHub issues that apparently the "*" version signifier doesn't mean wildcard as it does in every other usage in the world, but instead it means "latest version." I don't really have anything constructive to say about that so it's whatever.

Maybe I assumed too much, but I thought that specifying wildcards for every package would be translated to "I don't care which versions you use, just get me the latest compatible versions of every package I listed." Isn't that what requirements.txt does if you just list packages and not versions?

Give Poetry a try. It does everything pipenv does but without some of the dafter design decisions (like upgrading your packages by default)

NtotheTC
Dec 31, 2007


It's all under the header of UX (user experience) now

Or wait when you say gui programming are you talking about the interface or the code behind it?

NtotheTC
Dec 31, 2007


Are you allowed to touch the java code? Because it would probably be much simpler to add a JSON parser library and have the python output a JSON object

To answer your question though try prepending your write string with r or ur if it's python2

code:
out.write(r'\u00fc')

NtotheTC fucked around with this message at 09:10 on Oct 9, 2018

NtotheTC
Dec 31, 2007


Considering the "flask hyphen stuff sucks" mantra, is the best solution for storage based sessions on flask to roll your own or is there an actual serviceable lib solution out there?

NtotheTC
Dec 31, 2007


I've seen that pattern used once in the wild, where it was something like

Python code:
string_from_bool = ("falsily", "verily",)

>> print(string_from_bool[False])
falsily

>> print(string_from_bool[True])
verily

NtotheTC
Dec 31, 2007


cinci zoo sniper posted:

loving hell, why?!

Well that example is slightly simplified, the two strings were actually entire sentences, and were stored in a config file and often accessed, so it was neater than writing

Python code:
my_string_response = STORED_TRUTHY_STRING if True else STORED_FALSEY_STRING
or similar, i dunno it was several jobs ago but I never found it particularly egregious

NtotheTC fucked around with this message at 21:47 on Dec 26, 2018

NtotheTC
Dec 31, 2007


I'm not trying to nominate it for code of the year, just pointing out a real-world example of it

NtotheTC
Dec 31, 2007


I've used Django exclusively up until 3 months ago when i finally had a project i thought flask wouks be perfect for.

2 weeks later i binned it and redid it in django

This is just one mans opinion of course

NtotheTC
Dec 31, 2007


For Django specifically, once youve done the tutorials (of which there are many excellent ones suxh as the one youve already found) the Two Scoops of Django book makes an excellent reference book. Its expensive in hardcopy form but I think you can get an electronic copy cheaper

NtotheTC
Dec 31, 2007


Master_Odin posted:

Except at least they have a folder within a project they install modules to and I don't have to explain virtualenvs to people starting out. Can't wait for PEP-582 to be implemented.

Is this entirely wise though? Not having to explain virtualenvs is great and the activate / deactivate schtick is terrible implementation but tools like poetry abstract that away behind a much nicer interface that functions similarly to this except you don't use the system python.

What happens with this pep if you accidently install a dependency into the system python, dont realise when importing the lib into your project that it isn't local, and then get baffling errors?

If the goal is to remove virtualenvs entirely then we need a way to replicate things likr pipx-app for exposing python command line apps neatly. And if the goal isnt to replace virtualenvs completely are you not just kicking the can down the road?

NtotheTC fucked around with this message at 22:35 on Feb 7, 2019

NtotheTC
Dec 31, 2007


Related: https://www.jetbrains.com/research/python-developers-survey-2018/

21% of Python devs dont use any sort of isolation for developing :psyduck:

NtotheTC
Dec 31, 2007


I mean thats two separate points really. You want to avoid using system python for installing an apps dependencies into because you may have multiple apps on the same system that have conflicting requirements. If you already isolate the python environment becsuse you use containers or whatever then absolutely you can install things into system python.

The PEP makes it a bit simpler to isolate by default which would be nice in production without needing extra tooling. Even in containers its a nice bit of redundancy, but I can't work out if their goal with that PEP is to replace virtualenvs entirely or just be "virtualenv lite" to aid with teaching beginners

NtotheTC fucked around with this message at 23:53 on Feb 7, 2019

NtotheTC
Dec 31, 2007


I think its very much not recommended for production. I like using it for testing port access on servers

NtotheTC
Dec 31, 2007


Why are people posting about writing cheat software ITT?

"It's just a research project". Uh-huh

NtotheTC
Dec 31, 2007


cinci zoo sniper posted:

This is a programming thread on SA , not a tech support thread of official Space Station forums or whatever.

My issue was less about white-noising the thread and more about it being scummy and maybe people should keep the blackhat poo poo they do for a dollar to themselves.

Adbot
ADBOT LOVES YOU

NtotheTC
Dec 31, 2007


QuarkJets posted:

Maybe you should keep your opinions to yourself instead since you don't seem to know what you're talking about

What that dude is doing is basically AutoHotKey with an image processing layer, and he's applying to possibly the least competitive multiplayer game in existence; there's nothing really "blackhat" to talk about there. He also wasn't "white-noising" the thread, he explained exactly what he was doing and even provided a movie of it in action.

The first post says "im writing cheat software", the second post says "here's how you'd do it for Apex" and the video is literally titled "cheating in space station 13". So why would anyone think it strange? I didnt set the tone or the topic.

I imagine automation- ahk or otherwise is listed as cheating even in a web game so who cares if it's the equivalent of botting in slither.io? How is it a contraversial opinion to say "don't talk about writing cheats ITT?“ there must be thousands of legitimate uses for that sort of tooling so use those to demonstrate it.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply