|
QuarkJets posted:Think of sources as .py files. Simple enough. Sources folders are added to the PYTHONPATH so that you can import their contents. If you want to import python files from other python files, and some of those files are in directories, then you'll either need to modify your PYTHONPATH yourself or establish those directories as source folders. So if I had a folder called "data" and I mark it as a resource directory (with the top folder marked as the root directory), then you're saying I could write in my code something like: code:
|
# ? Apr 26, 2018 06:48 |
|
|
# ? May 15, 2024 05:52 |
|
Boris Galerkin posted:So if I had a folder called "data" and I mark it as a resource directory (with the top folder marked as the root directory), then you're saying I could write in my code something like: Correct, these features are only are useful from within a PyCharm session. This is a remnant of the fact that PyCharm descends from IntelliJ; in Java a developer is going to almost exclusively run code from within the IDE since there's a compilation step that needs to happen anyway, and it's easier to just let the IDE handle all of that for you. If you're running from the command line then don't even bother (but by the same note, you should probably get in the habit of running code inside of PyCharm; the PyCharm debugger is very good)
|
# ? Apr 26, 2018 06:54 |
|
QuarkJets posted:Correct, these features are only are useful from within a PyCharm session. This is a remnant of the fact that PyCharm descends from IntelliJ; in Java a developer is going to almost exclusively run code from within the IDE since there's a compilation step that needs to happen anyway, and it's easier to just let the IDE handle all of that for you. Got it, thanks. I tend to just use PyCharm for writing code for all of the cool features but run everything from a terminal because sometimes I gotta do this remotely through ssh/vim.
|
# ? Apr 26, 2018 06:58 |
|
From what I understand, yes, it allows you to run stuff in PyCharm, for example via test runners. I find it useful when I'm starting a project and it hasn't matured to the point where I'm bothering to put together a setup.py and install it (at which point running pytest from the command line will work just as well). I'm not sure if the resources root comes into play outside of specific contexts in web apps. I can't imagine PyCharm would manipulate all paths in Python code to be relative to a resource root, because that would create more problems than it solves. It's more for paths in HTML templates, for example (at least I think that's the case).
|
# ? Apr 26, 2018 07:10 |
|
Boris Galerkin posted:Got it, thanks. I tend to just use PyCharm for writing code for all of the cool features but run everything from a terminal because sometimes I gotta do this remotely through ssh/vim. That's cool. I don't personally get a lot of benefit from running code in the IDE, either, so I often don't bother.
|
# ? Apr 26, 2018 07:11 |
|
QuarkJets posted:That's cool. I don't personally get a lot of benefit from running code in the IDE, either, so I often don't bother. ctrl-b and shift-f6 are probably the key combinations I press the most e: Also ctrl-shift-up/down for moving lines of code around, and ctrl-x for deleting a line, and ctrl-d for duplicating a line. Boris Galerkin fucked around with this message at 07:35 on Apr 26, 2018 |
# ? Apr 26, 2018 07:30 |
|
Boris Galerkin posted:Got it, thanks. I tend to just use PyCharm for writing code for all of the cool features but run everything from a terminal because sometimes I gotta do this remotely through ssh/vim. PyCharm runs code remotely over ssh too. It'll auto deploy over sftp as well. You can also set up source roots etc remotely but it gets weird and I don't usually bother. Even if I'm running everything locally I still have it ssh into the windows Linux subsystem and use the interpreter there instead of setting everything up in windows.
|
# ? Apr 26, 2018 11:11 |
|
M. Night Skymall posted:PyCharm runs code remotely over ssh too. It'll auto deploy over sftp as well. You can also set up source roots etc remotely but it gets weird and I don't usually bother. Even if I'm running everything locally I still have it ssh into the windows Linux subsystem and use the interpreter there instead of setting everything up in windows. PyCharm can also debug remotely and is by far its most godlike feature.
|
# ? Apr 26, 2018 13:00 |
|
Yes, the PyCharm remote features are amazing. You basically can't tell you're running code somewhere else.
|
# ? Apr 26, 2018 16:02 |
|
I'm trying to do some port closure commands and the method I'm using is rather particular about how it formats ipv4 and ipv6 cidrs, so I need to run the same command a few times in order to make sure all the ports actually close properly. Ideally, I'd want my for loop to try a number of variations of ipv4 and ipv6 formats but if one fails I just want it to continue through the loop. Essentially, my code looks something like this:code:
|
# ? Apr 26, 2018 22:32 |
|
I don't really understand what's going on with your code, there are a few errors. I think what you're looking for though is something like (I'm phone posting)code:
You could also throw in a try/except in the while loop instead and toggle is_port_closed in the try block after the closePort function is called. Errors in your code include a try without an except, you never use port variable, and an else without a for. huhu fucked around with this message at 10:17 on Apr 27, 2018 |
# ? Apr 27, 2018 10:14 |
|
SnatchRabbit posted:I'm trying to do some port closure commands and the method I'm using is rather particular about how it formats ipv4 and ipv6 cidrs, so I need to run the same command a few times in order to make sure all the ports actually close properly. Ideally, I'd want my for loop to try a number of variations of ipv4 and ipv6 formats but if one fails I just want it to continue through the loop. Essentially, my code looks something like this: Based on your code I guess it throws an exception if it fails to close the port, if that's the case you need to retry in your except clause. code:
Most import things are: only catch exceptions related to closing ports so that other exceptions propagate back up, but catch all port related exceptions or you won't make it through your for loop if a port fails to close. If a port failing to close should be an exception then just don't have an except clause on your last port closing try and it'll propagate the exception up like normal. If retrying the same method is something you need to do then adding the while loop huhu is talking about is a good way to do that, you just catch the exception in the while loop, and might want to add some kind of counter so it doesn't go on forever.
|
# ? Apr 27, 2018 12:23 |
|
Quick question for the thread. MacOS is my primary and I use PyCharm. I mostly do network automation scripts to make my life a little easier for certain tasks. I’ve recently purchased a gaming laptop and it seems like it would make a decent platform (7700HQ, 32GB, 1TB SSD) since the thing is a beast. However, my only real Windows exposure, beyond using RDP jump servers as an end user, is for gaming. Everything else (work, home, etc...) is pretty much macOS. I usually run my programs from Linux VMs, but I don’t use anything that limits them to a UNIX platform (like pexpect) anymore. So my question is: which Python does everyone use? Windows Python distrib Using Python in my Ubuntu install on WSL (Anaconda may be an option, but I imagine that may not work since I do use the scripts in a business context. But then again, not to generate revenue. I stopped using it to err on the side of caution about a year ago) Proteus Jones fucked around with this message at 00:36 on Apr 28, 2018 |
# ? Apr 28, 2018 00:33 |
|
Use the Windows native installer.
|
# ? Apr 28, 2018 00:38 |
|
If you run into some weird case, it's easy to switch which python interpreter you're using. In other words, you're not committing yourself to anything, so just use the easiest to get started option...the windows installer.
|
# ? Apr 28, 2018 01:18 |
|
Pretty sure Anaconda is Ok for use even in commercial work
|
# ? Apr 28, 2018 01:53 |
|
vikingstrike posted:Pretty sure Anaconda is Ok for use even in commercial work Huh. For some reason I always thought it was a free for educational/personal, but required licensing for commercial. I’ll have to look at it again. Thermopyle posted:If you run into some weird case, it's easy to switch which python interpreter you're using. Cripes. I must be tired, of course I can do this.
|
# ? Apr 28, 2018 04:00 |
|
Proteus Jones posted:Huh. For some reason I always thought it was a free for educational/personal, but required licensing for commercial. I’ll have to look at it again. NumbaPro used to require a license for commercial use, but in the last year or two they completely open sourced it; Numba is now BSD-2 and conda is BSD-3. Each package that you install beyond that you need to check on a per-case basis, as any of them could have a commercial-restricting license PyCharm requires a license for commercial entities, it's like $100 and comes with extra web development features
|
# ? Apr 28, 2018 07:51 |
|
QuarkJets posted:NumbaPro used to require a license for commercial use, but in the last year or two they completely open sourced it; Numba is now BSD-2 and conda is BSD-3. Each package that you install beyond that you need to check on a per-case basis, as any of them could have a commercial-restricting license I already pay for PyCharm, so that's sorted. I'll have to check, but I'm 99% certain all the packages I use are open source. That's good to know since I cut my teeth with anaconda. I think from a familiarity perspective (especially since I'm not as familiar with Windows) I may try that first. Thanks for the info all
|
# ? Apr 28, 2018 10:20 |
|
That'll work too.The reason I recommended official over Anaconda is I prefer to avoid having multiple package management tools; using pipenv for everything is nice.
|
# ? Apr 28, 2018 13:59 |
|
I just create a new conda environment with the python interpreter I want and then use pip for python packages whenever possible, and conda for stuff like openblas.
|
# ? Apr 28, 2018 18:00 |
|
I've switched over to pipenv for everything because it takes the one thing npm does right and runs with it. Unfortunately, the whole setup.py vs Pipfile is still as murky of a mess as requirements.txt vs setup.py is.
|
# ? Apr 28, 2018 20:03 |
|
Thermopyle posted:Unfortunately, the whole setup.py vs Pipfile is still as murky of a mess as requirements.txt vs setup.py is. Npm-inspired tools with lockfiles like yarn, cargo, and pipenv are delightful. Dominoes fucked around with this message at 20:13 on Apr 28, 2018 |
# ? Apr 28, 2018 20:09 |
|
I'm on mobile so it's too much of a hassle for me to find it, but there's a long issue on pipenvs issue tracker discussing it. edit: https://github.com/pypa/pipenv/issues/209 Thermopyle fucked around with this message at 21:53 on Apr 28, 2018 |
# ? Apr 28, 2018 20:47 |
|
Dominoes posted:Any thoughts on why setup.py's install_requires can't be removed in leu of Pipfile? install_requires is for abstract requirements, pipfile is for concrete requirements. The former is best practice for library code, the latter is recommended for applications.
|
# ? Apr 29, 2018 00:07 |
|
Speaking of environments
|
# ? May 1, 2018 19:03 |
|
lol nice job xkcd guy
|
# ? May 1, 2018 19:08 |
|
Boris Galerkin posted:Speaking of environments I can’t stop giggling over “ANOTHER PIP??”
|
# ? May 1, 2018 19:08 |
|
Proteus Jones posted:I can’t stop giggling over “ANOTHER PIP??” I think that’s my favorite part.
|
# ? May 1, 2018 19:10 |
|
The question mark between pip and easy_install is my favourite
|
# ? May 1, 2018 21:02 |
|
New Diffeq solver; bindings to a Julia library. Haven't tried it yet, but this appears to overcome the limitations I've run into when trying to solve non-trivial systems in Scipy.integrate. Both the native Julia version, and its transparent Python bindings look nicer than any solver suite I've seen.
|
# ? May 2, 2018 03:42 |
|
Dominoes posted:New Diffeq solver; bindings to a Julia library. That's interesting. I've been suing scipy.integrate.solve_ivp a lot lately and haven't really found any limitations for what I'm trying to do. It's something to look into though for when I'm bored. Thanks! e: I've never heard of Julia before, well other than by name. Isn't the Ju part of Jupyter short for Julia?
|
# ? May 2, 2018 06:55 |
|
The julia diffeq library is insanely good Julia is like a Matlab successor but better
|
# ? May 2, 2018 11:18 |
|
Is anybody else going to PyCon?
|
# ? May 2, 2018 17:34 |
|
I've decided that I need to automate a tedious task that I do on a daily basis. This involves loading up a website, logging in, depositing some money and playing a game. Step 1. Load the website. Python code:
I've tried it with Safari, Chrome, Firefox + Opera. Only Chrome does the double window nonsense. edit : The logins + passwords are all saved in 1Password. If there's a Python module that'll interact nicely with 1Password that could do the first 2 steps. Sad Panda fucked around with this message at 13:02 on May 6, 2018 |
# ? May 6, 2018 12:34 |
|
I never used webbrowser before, but reading the docs, you should either: 1) Use webbrowser.open and just pass the URL, and the system will open the given URL in the default browser, or 2) If you actually need a reference to the browser controller, you just need to pass the name of the browser to webbrowser.get, and then use one of the open methods listed.
|
# ? May 6, 2018 14:43 |
|
Rocko Bonaparte posted:Is anybody else going to PyCon? conferences in america
|
# ? May 6, 2018 18:31 |
|
Every year I think "I'm going to PyCon next year" and then I put it off too long and never end up getting tickets.
|
# ? May 6, 2018 19:16 |
|
Is it possible to override Python's built-in error handling with a third-party module import? I'd like to improve them to be more like Rust's, where it makes educated guesses about what you did wrong, and what the fix is. (eg, rather than just raise an AttributeError or NameError, point out a best guess of the attribute or variable you misspelled.)
Dominoes fucked around with this message at 03:51 on May 7, 2018 |
# ? May 7, 2018 03:47 |
|
|
# ? May 15, 2024 05:52 |
|
a witch posted:conferences in america Okay fair enough.
|
# ? May 7, 2018 04:45 |