|
Nippashish posted:You'll avoid 99% of the cases this shows up if you do Well I could just disable the inspection too (although that probably is a nicer way to structure things huh), it was more about the 'who cares' aspect. I thought maybe there was an important reason!
|
# ? Aug 13, 2016 01:42 |
|
|
# ? Jun 13, 2024 06:31 |
|
It's more there in case you expect that variable to hold something when it really doesn't, I think. Someone new to Python might think "I'll write a function to modify this global scope variable" without realizing that any changes made in that local scope would be lost (unless you're just changing that variable's mutable contents, of course)
|
# ? Aug 13, 2016 01:53 |
|
baka kaba posted:Well I could just disable the inspection too (although that probably is a nicer way to structure things huh), it was more about the 'who cares' aspect. I thought maybe there was an important reason! I started writing my code that way because I found that I would forget to pass variables from the main block to my functions and use them anyway without shadowing, which works perfectly well until you want to move that function to another file.
|
# ? Aug 13, 2016 10:11 |
|
I'll only use global scope variables if they're constants, so they have to get defined or imported at the top of the file and I don't allow their value to change. Everything else needs to be in a class or function. This seems to work pretty well
|
# ? Aug 13, 2016 19:13 |
|
Yeah I tend to pass variables around instead of using global state too, which is why the b-but you already used this name warnings are annoying. Thanks for the tips anyway guys!
|
# ? Aug 13, 2016 20:53 |
|
baka kaba posted:Yeah I tend to pass variables around instead of using global state too, which is why the b-but you already used this name warnings are annoying. Thanks for the tips anyway guys! You shouldn't get those warnings if you're actually passing variables around, though. In my experience, I only get the shadowing warning if I'm re-using a variable name inside of a new function that still has access to a previously-defined variable of the same name. Technically it's not a problem, but it can lead to unexpected bugs
|
# ? Aug 13, 2016 21:20 |
|
baka kaba posted:Yeah I tend to pass variables around instead of using global state too, which is why the b-but you already used this name warnings are annoying. Thanks for the tips anyway guys! You're getting this warning because you are making global state and it is visible inside your functions. The solution is to make a scope for your global state to live in so that it isn't visible everywhere.
|
# ? Aug 13, 2016 21:38 |
|
Yeah that's what I meant about the main() method being a nice idea. Generally I'm calling functions from __main__ and getting butt from function_a and passing it to function_b later, so I'm calling it butt everywhere because it makes sense to do so, in method signatures and in local variables. So because something called butt is also accessible from the global scope (which may or may not be the same variable, I'm never accessing it so it doesn't matter) I'm getting the warnings. Having a separate main method and just keeping constants in the global scope basically clears all that up and makes things nice and safe. Is that a recommended practice? Seems like it should be, I've never run into it though
|
# ? Aug 13, 2016 21:46 |
|
QuarkJets posted:You shouldn't get those warnings if you're actually passing variables around, though. In my experience, I only get the shadowing warning if I'm re-using a variable name inside of a new function that still has access to a previously-defined variable of the same name. Technically it's not a problem, but it can lead to unexpected bugs
|
# ? Aug 13, 2016 21:47 |
|
Something is going seriously wrong with one of my programs, and I'm getting a Windows error message that "python.exe has stopped working". I then have to restart everything, and I don't get a traceback printed out, so I can't tell where the problem is. How can I debug things in this situation? (I'm running Windows 8, Python 3.4, if that makes any difference)
|
# ? Aug 15, 2016 19:42 |
|
Something's crashing in native code. You won't get a normal Python traceback from this, but the faulthandler module should be useful. It might suffice to simply add this to the top of one of the "main" Python file you're running:Python code:
|
# ? Aug 15, 2016 19:50 |
|
Oh neat, I didn't know about faulthandler. It worked too! I was able to see the module and line number where things were crashing. Turns out the problem is with some PyQt code, nothing that I wrote myself. Thanks!
|
# ? Aug 15, 2016 19:58 |
Is anyone aware of any differences between PyCharm Edu and PyCharm Community?
|
|
# ? Aug 16, 2016 16:18 |
|
From their FAQquote:PyCharm Edu is based on the Community Edition and comprises all of its functionality. Additionally, it installs and detects Python during installation. It has a simpler UI (adjustable in settings) and adds a new "Educational" project type.
|
# ? Aug 16, 2016 16:21 |
SurgicalOntologist posted:From their FAQ
|
|
# ? Aug 16, 2016 16:26 |
|
I'm looking at changing my future web projects from PHP to Python. The main things I'm looking for are better OOP features (namely method overloading), no serious loss in overall performance, excellent tooling for web applications, broad acceptance of standards (PEPs), a larger concern with code correctness compared to PHP, and an escape from the drama of PHP-FIG. Python seems like the right language, yes?
|
# ? Aug 16, 2016 16:57 |
|
rt4 posted:I'm looking at changing my future web projects from PHP to Python. The main things I'm looking for are better OOP features (namely method overloading), no serious loss in overall performance, excellent tooling for web applications, broad acceptance of standards (PEPs), a larger concern with code correctness compared to PHP, and an escape from the drama of PHP-FIG. Python is the perfect language for what you're looking for. I'd recommend PyCharm for doing web applications. It's tooling for web applications is first class. Also, there's no drama involved with anything Python-related. (hahahahahha)
|
# ? Aug 16, 2016 17:31 |
|
I don't know how to describe this question succinctly to Google if there is a method for doing this kind of thing so perhaps someone will know of something and point me in the right direction. I have a plot when the x-axis is divided into discrete equal-size intervals. During each interval, a process can either occur (that interval will be colored) or not occur (that interval will be blank). The following are two example outcomes: In the first example outcome there are 3 clusters, of length 3, 4, and 8 while in the second example outcome there are 2 clusters of length 4 and 10. I was wondering if there is a way to mathematically describe (as a single number or set of numbers) the two example outcomes in terms of the number of clusters (time intervals where a process occurred during consecutive intervals) as well as the length of the clusters (number of consecutive time intervals during which the process occurred) so that someone could have an idea of the difference in clustering between two examples given just the two numbers or two sets of numbers. Thoughts?
|
# ? Aug 17, 2016 02:24 |
|
Trying out a little bit of Python web stuff right now. In PHP, we use Composer to install libraries for the application, but keep only the composer.json file in version control. At deploy time, we tell Composer to install the libraries and the config file provides exactly what is needed. How does this workflow happen in Python? Pip's requirements.txt doesn't quite seem to fit the bill. Is there something I'm missing? Things must be very different for the typical Python web application. Is there a good article describing standard practices around virtualenv library management?
|
# ? Aug 17, 2016 02:26 |
|
What exact functionality of composer are you looking to replicate in Python land?
|
# ? Aug 17, 2016 03:54 |
|
Just library management. Pip has the freeze feature which writes out all the installed libraries and their versions, but it seems a bit verbose compared to just writing out the libraries I've asked for and letting the rest get resolved as dependencies. Seems like a good way to do things is to keep a requirements.txt and add venv/ to gitignore?
|
# ? Aug 17, 2016 12:27 |
|
rt4 posted:Just library management. Pip has the freeze feature which writes out all the installed libraries and their versions, but it seems a bit verbose compared to just writing out the libraries I've asked for and letting the rest get resolved as dependencies. Just pip freeze > requirements.txt. There's no reason not to lock down the versions, and you can just pip install -r requirements.txt later.
|
# ? Aug 17, 2016 12:50 |
|
rt4 posted:Just library management. Pip has the freeze feature which writes out all the installed libraries and their versions, but it seems a bit verbose compared to just writing out the libraries I've asked for and letting the rest get resolved as dependencies. pip/setuptools does do this. For example, you can write a requirements.txt that looks like: code:
code:
You don't really have to worry about configuring setuptools unless you're wanting to distribute your code.
|
# ? Aug 18, 2016 15:36 |
The March Hare posted:Just pip freeze > requirements.txt. There's no reason not to lock down the versions, and you can just pip install -r requirements.txt later. It seems like if you just take the output of pip freeze verbatim and stuff it in your requirements.txt it's going to make it a pain in the rear end one you want to start updating library versions since all the dependencies are included in there as well. I just do what Thermopyle suggested, my requirements.txt has only Django==1.10, I don't list the dependencies as well.
|
|
# ? Aug 18, 2016 19:35 |
|
I am trying to save data to a custom name to a default location. fn = "order + order + ".txt" fn = "'"+"C:/"+fn+ "'" myfile = open(fn, 'w') I am using ignition which uses python 2.5 Using import.os didn't work any hints would be appreciated. Thanks
|
# ? Aug 19, 2016 12:06 |
|
joebuddah posted:I am trying to save data to a custom name to a default location. which os commands were you trying? instead of C:/etc/etc, you should use / and the os.path.join function to build your path: >>> import os # Assuming we want /mydir or C:\mydir, leave the OS decide that >>> target = os.path.join('/', 'mydir') # Check if our target folder exists, if not make it. # Do this for every 'new' folder in your target path, it won't automatically create the entire tree for you. >>> if not os.path.exists(target): ... os.mkdir(target) ... # Move to folder. >>> os.chdir(target) # Print out current working directory. >>> print(os.getcwd()) c:\mydir
|
# ? Aug 19, 2016 12:54 |
|
That worked thank you. I honestly don't know what I tried. Instead of commenting out what didn't work, I just kept trying different things. Thanks again.
|
# ? Aug 19, 2016 15:26 |
|
joebuddah posted:That worked thank you. one other thing from your snippet, you should use python's context managers('with' statements) for file I/O instead of remembering to try->do thing->finally close everywhere: code:
|
# ? Aug 19, 2016 16:27 |
|
mkdirs will make all the parent folders though!
|
# ? Aug 19, 2016 16:35 |
|
baka kaba posted:mkdirs will make all the parent folders though! i should really read docs more often, i never knew this was a thing, ta
|
# ? Aug 19, 2016 20:21 |
|
Hey, this is probably old news to most of y'all, but using py.test is a clear winner over the builtin unittest. No imports, classes, or inheritance required, just write functions with name starting with 'test', and use an assert statement in the func. Run with 'py.test filename.py' Compared to builtin unittests, immediate advantages are lack of boilerplate, and not acting finicky about directory structure. I spent a while troubleshooting issues stemming from unittest being picky about relative imports; no issue with py.test. Dominoes fucked around with this message at 20:40 on Aug 19, 2016 |
# ? Aug 19, 2016 20:35 |
|
Today I learned that there's a Python module with a really nice API that can build Powerpoint slides, and that it even works in *nix. It's called pptx. I'm going to give it a spin, this is something that I've wanted for awhile. I've done some automatic powerpoint generation in Matlab before using poorly-documented and somewhat bizarre Windows calls and it was a serious poo poo-show but did wind up saving some time over inserting the images by hand. Fingers crossed that this does what I want it to do, so far it looks awesome
|
# ? Aug 20, 2016 06:27 |
|
What's the easiest way to build a cross platform application with a gui these days? Ideally I'd be able to build the thing for all platforms from my Mac and is just a single app/exe file. I will say for GUI, I've only ever really don't stuff with web dev, but I'm working on something that could be run via coomandline or the GUI. Master_Odin fucked around with this message at 13:13 on Aug 20, 2016 |
# ? Aug 20, 2016 13:06 |
|
In Python? I'd go with something like Electron and Flask, you can use your web dev experience as a bonus too. Your other choice is Qt, using PySide or PyQt.
|
# ? Aug 20, 2016 13:31 |
|
ArcticZombie posted:In Python? I'd go with something like Electron and Flask, you can use your web dev experience as a bonus too. This type of thing is the best idea nowadays. The tools available to you to do web dev are just so much better than native GUIs.
|
# ? Aug 20, 2016 17:33 |
|
Thermopyle posted:This type of thing is the best idea nowadays. The tools available to you to do web dev are just so much better than native GUIs. That's what I figured, but of course I cannot find any sort of information or tutorial on it beyond one blog post and then Hacker News people all complaining about how awful doing this would be. Found a bit on using thrust + python, but again it was mainly a hacker news piece from a few years ago where people talked about it that makes me a bit apprehensive about how exactly usable said solutions might be, though electron does seem super easy to use in conjunction with flask which is attractive as it basically just requires an additional server.js and then the rest of my process remains the same.
|
# ? Aug 21, 2016 04:12 |
|
Don't listen to Hacker News
|
# ? Aug 21, 2016 06:29 |
|
Are you intending to make a GUI program that will be high-end and compete partially on the basis of having a nice, smooth GUI after years of development? If so don't do the web technologies based method. Atom, the text editor which is why that framework exists has a poo poo GUI that looks superficially pretty but has all sorts of GUI-based annoyances in my opinion. On the other hand if your alternative is a hacked together Qt GUI made by one person who has never done it before, the web framework GUI you come up will be way better in every way and come together way faster.
|
# ? Aug 21, 2016 15:35 |
|
OnceIWasAnOstrich posted:Atom, the text editor which is why that framework exists has a poo poo GUI that looks superficially pretty but has all sorts of GUI-based annoyances in my opinion.
|
# ? Aug 21, 2016 15:39 |
|
|
# ? Jun 13, 2024 06:31 |
|
Dominoes posted:What, in particular? Are my annoyances? Honestly I can't think of that many so maybe I should take some of the vehemence back. I know it feels less responsive, especially dropdown menus, even on my 2500k. I have it installed on all my Windows computers and every time I've tried to use it seriously there is something about it that annoys me enough to go back to Notepad++. That said it's possible most of the problems I remember were just teething problems and it has been improved.
|
# ? Aug 21, 2016 16:17 |