|
Dominoes posted:The code I posted is straight from the declarative base page you linked. AttributeError: type object 'Person' has no attribute 'query', and I can't find your syntax on that page, although I've seen it mentioned before. Can you provide an example of querying from the model, without the syntactic sugar I posted? Actually I can't. Apparently what I said is a bunch of poo poo that Flask-SQLAlchemy adds on top of SQLAlchemy to make it more palatable, and I'm so used to writing queries in that way that I didn't know it wasn't a default thing. Sorry for that. Dominoes posted:Regarding queries as generators: Per this article, they're not lazy: I should have said "behaves like" instead of "functions". My point still stands, though. You really shouldn't gobble up the Query object returned by the db.session.query function. Besides, a few database drivers do support database cursors. Postgres' psycopg2 does, for example. Though if SQLAlchemy does take advantage of that or not, I don't know.
|
# ? Mar 12, 2016 02:30 |
|
|
# ? May 8, 2024 12:31 |
Running into an issue with the Kodi plugin Watchdog on Xubuntu 15.04:code:
|
|
# ? Mar 15, 2016 08:53 |
|
That custom Python installation (in /usr/local) seems to be broken. What happens if you run /usr/local/bin/python and try import ctypes at the interactive prompt? Where did this Python installation come from? (Incidentally, Xubuntu 15.04 is no longer receiving security updates, and you should probably consider upgrading to 15.10 very soon.)
|
# ? Mar 15, 2016 13:20 |
Lysidas posted:That custom Python installation (in /usr/local) seems to be broken. What happens if you run /usr/local/bin/python and try import ctypes at the interactive prompt? Where did this Python installation come from? code:
|
|
# ? Mar 16, 2016 07:00 |
|
I need a little help translating a scripta from Python 2 to Python 3, since I haven't really worked with 2. The script is from https://www.csie.ntu.edu.tw/~cjlin/libsvmtools/multilabel/, namely trans_class.py. I know enough about the differences to clean up the print, split, and join statements, but I don't really understand what's going on in line 51 (my edit). Any help?
|
# ? Mar 18, 2016 16:48 |
|
hooah posted:I need a little help translating a scripta from Python 2 to Python 3, since I haven't really worked with 2. The script is from https://www.csie.ntu.edu.tw/~cjlin/libsvmtools/multilabel/, namely trans_class.py. I know enough about the differences to clean up the print, split, and join statements, but I don't really understand what's going on in line 51 (my edit). Any help? Looks like you need to get rid of the brackets around the lambda argument. i.e. "(num)" should be "num" That might be all you need to do.
|
# ? Mar 18, 2016 17:11 |
|
Thanks, worked like a charm.
|
# ? Mar 18, 2016 17:25 |
|
This is a super specific question, but I'm wondering if anyone has any troubleshooting suggestions here. I'm using IPython notebooks to demonstrate visual phenomena in a Perception class I'm teaching (i.e. optical illusions and the like). I usually use ipywidgets to let students play with the stimulus and see how the effect changes. It works great with static stimuli. Getting keypresses, clicks, and typed responses sequentially was a bitch to get working but I've figured that out as well. Now I'm doing motion perception so the displays are animated. Combining matplotlib animations with ipywidgets sliders was a bit tricky, but I thought I got it to work. Let me share my code before continuing. Python code:
The lab where I teach has Macbooks with Anaconda installed. As always I tested it on the instructor laptop to make sure it works there. All good. Come lab time, it didn't work for most anyone else. It worked on the instructor Macbook and two others (out of 16). I called a break and got to work frantically troubleshooting. I could find no differences between the laptops that worked and those that didn't. Same versions of all libraries. I ended up resorting to the osx backend, which worked great but opens up the figure in a new window, so you need to awkwardly rearrange the browser window to see the slider and the figure at the same time. Anyways, the class went fine from there, but I'm still curious on this one. Any idea what was going wrong? Or just stuff to try?
|
# ? Mar 24, 2016 15:32 |
|
GUI development question. This is my first time programming a simple GUI around a small simulation I wrote. The idea is to have one window where people can change the values of various simulation parameters before hitting next and moving on to the second window, a second window where they can press a button to run the model with the new parameters before hitting next and moving on to the third window, and finally a third window where they can see the output of the simulation when it is done. I am using Enaml (http://nucleic.github.io/enaml/docs/index.html) as the GUI framework(?). Here is my code: Python code:
code:
code:
I think the logic should be to close the param_view window and open the run_view window, which is what I have in sim_gui.py, but even if this is correct, I don't know how to achieve it.
|
# ? Mar 25, 2016 17:55 |
|
By "move", you mean that you don't want to just close the previous window and open a new window, but rather have the contents of the new window replacing the contents of the old window? Try using states: http://doc.qt.io/qt-4.8/statemachine-api.html http://doc.qt.io/qt-5/qtwidgets-statemachine-eventtransitions-example.html States allow you to define properties for various widgets that should change depending on which state you're in. So you could hide some widgets in state 1, reveal them and hide other widgets in state 2, and then hide even more widgets and reveal others in state 3. And if you want to get all web2.0 about it then you can define cute animations or whatever as part of those transitions, but as a simple first attempt tutorial you can follow the statemachine-api example and just change the contents of a QLabel when you transition between states.
|
# ? Mar 25, 2016 19:50 |
|
This is with Qt mind you, I don't know what enamel is or whether it might have a simpler way to solve your problem. But Qt States are pretty straightforward on their own, so you could try that since enamel is apparently based on Qt, per your imports
|
# ? Mar 25, 2016 19:52 |
|
Looking for an Anaconda Wizard. I was trying to use Qt5, but now want both Jupyter QTconsole and matplotlib. After installing PyQt5 from a binstar repo and uninstalling pyqt[4]?, PyQt5 works, jupyter qtconsole works, spyder doesn't work, and matplotlib doesn't work. After uninstall PyQt5 and reinstalling pyqt, PyQt4 works, jupyter console's broken, and spyder and matplotlib work. It looks lib/site-packages/qtconsole/qt_loaders.py is having probs; I get a graphical error from that file. Any ideas? I just need matplotlib and qtconsole working at the same time.
|
# ? Mar 27, 2016 07:51 |
|
I don't really know how to fix your problem, but presumably the issue is matplotlib and spyder getting built against a different version of Qt4 than jupyter qtconsole. One solution could be to try installing Qt5, set up your virtual environment normally, and then compile new version of matplotlib and spyder that link against Qt5. Another could be to do the reverse: recompile jupyter notebook with Qt4.
|
# ? Mar 27, 2016 21:00 |
|
Is there a stupid simple unconstrained non-linear solver for python similar to Matlab's fminunc?
|
# ? Mar 28, 2016 05:01 |
|
KernelSlanders posted:Is there a stupid simple unconstrained non-linear solver for python similar to Matlab's fminunc? https://docs.scipy.org/doc/scipy/reference/optimize.html
|
# ? Mar 28, 2016 16:59 |
|
QuarkJets posted:By "move", you mean that you don't want to just close the previous window and open a new window, but rather have the contents of the new window replacing the contents of the old window? Bah, I cannot figure out how to get this to work. Perhaps I should explain what I am trying to do overall and then see what people think is the best way to accomplish it. I have a small simulation written in Python which I would like to have a GUI so that someone can specify the input scenario, run the simulation, and see the output of the simulation without having to muck about with the code. Ideally the user flow through the GUI will be: code:
Also, if there is a better place for this question please let me know.
|
# ? Mar 31, 2016 02:08 |
|
Which part are you having trouble with, specifically? Transitions from one window to the next? Understanding signals and slots? Making any GUI at all? Qt has widgets and tools to do basically everything that you listed, so it's a totally feasible idea.
|
# ? Mar 31, 2016 02:57 |
|
QuarkJets posted:Which part are you having trouble with, specifically? Transitions from one window to the next? Understanding signals and slots? Making any GUI at all? I guess I am running into a few problems: 1. I have never built a GUI before, so I don't quite understand what the "flow" of building one should look like, what things I need to have in order to make the transitions from one window to the next, and I had not heard about signals and slots until you mentioned them. 2. I was trying to use Enaml (http://nucleic.github.io/enaml/docs/) since the pitch for it was its ease of implementation: https://www.youtube.com/watch?v=ycFEwz_hAxk but the documentation leaves something to be desired (perhaps the documentation is good and the pieces are all there, I just don't understand how to put them together?) 3. I am under a time constraint and was looking for the easiest method to have something up and running. I guess the first question is, should I give up on using Enaml and use something else? If so, what?
|
# ? Mar 31, 2016 17:24 |
|
If enaml doesn't have enough documentation to at least get you going, then you should abandon it; ease of implementation is meaningless if you don't adequately inform people on how to use your framework. Try pyside instead. Pyside is based on Qt and officially supported by Qt. There are a million tutorials for it and Qt is well-known for having extensive documentation and a huge community of users. Even if someone is answering a question for the C++ implementation of Qt, it's usually straightforward to translate that C++ answer into a Python answer. PySide itself is pretty easy to use and is usually the thread's go-to recommendation for "how do I make a GUI?" If you're rushed, maybe skip to the Hello World example, figure out how to add buttons and labels to a GUI, figure out how to make multiple windows, and then just A) define all of the windows that you want to use and B) create buttons for each window that unhides each subsequent window while hiding the previous window. That's a simple, easy implementation that doesn't require any weird tricks. https://wiki.qt.io/PySide_Tutorials You don't have to deal with XML or any of that poo poo, you can just write your GUI entirely in Python and have something basic up and running in relatively short order if you're willing to use buttons that literally just hide and reveal various predefined windows.
|
# ? Mar 31, 2016 19:41 |
|
QuarkJets posted:If enaml doesn't have enough documentation to at least get you going, then you should abandon it; ease of implementation is meaningless if you don't adequately inform people on how to use your framework. Thanks! This is what I needed to get started, I have been going through the Zetcode Pyside tutorials. I am sure I will have more specific questions, but for now I can at least moving.
|
# ? Apr 1, 2016 17:49 |
|
WRT Python desktop apps... Another way to go that I quite like (though I've just tinkered with it and haven't done any serious development this way yet), is to build a python web app with Django or Flask or web.py or whatever is needs-suiting, add html/css/js and bundle it with Electron or QTWebKit. It's not for everyone or every situation, but it seems to work very well. You can also skip the Electron or QTWebKit part and just use the users browser.
|
# ? Apr 1, 2016 18:00 |
|
I've never used any of that stuff so I don't know how easy it is to implement, but it sounds pretty complicated compared to just writing a pyside script
|
# ? Apr 1, 2016 23:03 |
|
It all depends on what you're doing and what you're familiar with. One way or the other certainly isn't clearly better in the general case than the other.
|
# ? Apr 2, 2016 01:27 |
|
Thermopyle posted:WRT Python desktop apps... I've looked at that as well. The nice part is that you get access to a ton of nice web ui kits like bootstrap
|
# ? Apr 2, 2016 14:45 |
|
Hubis posted:I've looked at that as well. The nice part is that you get access to a ton of nice web ui kits like bootstrap Yeah, I was going to say something along these lines in my last post but I was phone posting. Qt isn't exactly a hotbed of new UI toolkit development. I mean, you could make the argument that that's because it and it's paradigm has reached the perfect state, but... Generally speaking I'd rather design a UI with the tools available to the web rather than what you've got for developing Qt-ish applications. Again, that all depends on your needs though. If you feel it's very important that your application use native widgets*, or you just need to get the user to answer a couple questions, or whatever, pyside is where it's at. As far as the "extra complexity" argument goes...on the one hand it is more complicated at one level, but on the other hand most of that extra complexity is hid from the developer by the tools available...as long as you're already familiar with developing UI with web technologies. *I question the importance of this. In the age of the web where every site has it's own UI/UX, people seem to manage just fine.
|
# ? Apr 2, 2016 17:08 |
|
I don't use regex that much, and I could use some advice on best practices. I've got a pretty long multiline regex pattern (14 lines, some lines have 400+ characters). Speed isn't a concern, I'm just thinking about readability, PEP8, "doing it right", etc. First of all, am I correct in my observation that if I use a triple-quoted string prefixed with r, then I can't escape newlines to break up the longer lines? If so, then PEP8 is out the window without splitting up the pattern across multiple strings. More generally, I'm wondering if I should compile the pattern in the main module namespace, put it within the function where it's used, or something else. Is it a common practice to put a long regex pattern in a separate file? I've never seen it done but it might make sense here. At least it would stop my editor from getting upset with me for the long lines.
|
# ? Apr 2, 2016 20:53 |
|
SurgicalOntologist posted:First of all, am I correct in my observation that if I use a triple-quoted string prefixed with r, then I can't escape newlines to break up the longer lines? If so, then PEP8 is out the window without splitting up the pattern across multiple strings. I generally use re.VERBOSE. For spaces in the pattern you need to match it with a character class like [ ]. quote:More generally, I'm wondering if I should compile the pattern in the main module namespace, put it within the function where it's used, or something else. Is it a common practice to put a long regex pattern in a separate file? I've never seen it done but it might make sense here. At least it would stop my editor from getting upset with me for the long lines. I tend to put it at the module level if I'm going to pre-compile it at all. Since the compiled patterns get cached you don't need to worry about compiling before a tight loop, just if you have an operation requiring a regex that you can't afford the latency of compiling beforehand.
|
# ? Apr 2, 2016 22:20 |
|
Edison was a dick posted:I generally use re.VERBOSE. Thanks, that's exactly what I needed.
|
# ? Apr 2, 2016 22:40 |
|
Chris (from the video) is a colleague of mine. AFAIK, Enaml is no longer under active development (so I probably wouldn't recommend it). He and his team are spending all their time on PhosphorJS, which is the basis of Jupyter 5.0 and beyond.
|
# ? Apr 3, 2016 01:20 |
|
QuarkJets posted:I've never used any of that stuff so I don't know how easy it is to implement, but it sounds pretty complicated compared to just writing a pyside script So after doing some tutorials and looking at questions on StackOverflow, I finally have the following GUI layout: and the code to produce this is: Python code:
1. The way I am programming this (which is based on examples I have seen), it looks like all my code is going to end up in a single file in a single class (TabbedScreens). Is this the normal/correct way to structure the program, or is there a better way? 2. When do/should you specify the parent of a widget? For instance when I declare a QPushButton I add the parent widget to the initialization (again based on examples I have seen), but when I declared the QTabWidget I did not, and things seemed to work just fine. 3. From what I could find online it seemed like having a QTabWidget would be a good way for me to accomplish the hiding and revealing of new screens. Is this a reasonable approach, or should I switch to something different given what I hope to accomplish? 4. Is there a name/id attribute to a tab that I can use so that the move_to_next_tab() function doesn't rely on the index of the tab? 5. Are there coding issues that you can see with what I have so far?
|
# ? Apr 3, 2016 16:41 |
|
Video criticizing OOP. https://www.youtube.com/watch?v=QM1iUe6IofM What do y'all think? Personally, I rarely create classes. Exceptions being database models, GUI bits, and complex chunks of code that share variables [that might be better off as separate files.]. There's a stock broker API I use that implements a full-blown OOP Java API from Python, and it embodies one of the video's critiques: Objects wrapping objects wrapping objects; everything obfuscated and opaque. The video reminded me of one of the cool things about Python: It's flexible and multi-paradigm. I scoffed the OOP part of it, but love its functional and numerical sides. Dominoes fucked around with this message at 19:37 on Apr 3, 2016 |
# ? Apr 3, 2016 19:07 |
|
Jose Cuervo posted:So after doing some tutorials and looking at questions on StackOverflow, I finally have the following GUI layout: 1. Totally fine for a project of this size, for a larger project you might do one class per screen, one file per class. 2. The most useful part about declaring a parent is that when the parent gets deleted, so do all of its children. This makes memory management way easier, which is really great when writing C++. Python, however, does its own memory management as things fall out of scope, which can result in some interesting bugs when using pyside if you're not using parent-child relationships properly. The best way to prevent problems is to be diligent about making sure that parents are being set. There are also some situations where changing an object (perhaps by resizing a window) will result in all of the children of that object being modified (perhaps resizing them as well), and this only works if you're setting parents properly. For your project, it's small enough and simple enough that you could probably skip setting parents, but it's good practice and incredibly easy to do so you should do it anyway 3. This is a totally reasonable approach so long as you're okay with users possibly going back one or more steps, since they're able to click the tabs themselves. 4. I don't think so. If you wanted to more Pythonic about it you could do something like this: code:
5. Looks fine to me, but I didn't exactly comb through it
|
# ? Apr 3, 2016 19:30 |
|
Dominoes posted:Video criticizing OOP. OOP has plenty of valid uses, the problem is when people go hog wild over trying to apply OOP to everything. That's why I dislike Java; it has a one-size fits all approach and suffers for it. But OOP can be useful in many circumstances, and the people who vehemently oppose OOP in all of its forms are basically the hipsters of the software world and are, frankly, wrong. This is also why I don't like using languages without classes or languages with lovely stapled-on class implementations, like MATLAB. Python and C++ sit in a sweet spot where you can use classes, if you need them, but you don't have to use them for everything.
|
# ? Apr 3, 2016 19:38 |
|
QuarkJets posted:This is also why I don't like using languages without classes or languages with lovely stapled-on class implementations, like MATLAB.
|
# ? Apr 3, 2016 19:42 |
|
Isn't one of the lessons of the success of Python that it can be good to have a language you can use functionally or OO? Most of my personal (scientific analysis) scripting is functional, but my (very limited) dev work (for scientific analysis libraries) is OO. It makes sense to have our brain data as objects, and it makes sense to use functions if I want to do like 3 things with them. And sometimes it makes more sense to do np.mean(), and sometimes np.array().mean().
|
# ? Apr 3, 2016 19:47 |
|
Dominoes posted:I'll sell you on Julia if you'd like! I know all about Julia and played around with it when it was 0.2, and then again when it was 0.3, and then again when it was 0.4. It didn't really suit me in beta form due to poor documentation and some weird undocumented stuff going on some of the time, so I'm hoping to return to Julia once it's in 1.0 and stable and well-documented. In the meantime I mostly write Python for development speed and versatility, and if I need certain bits of code to run faster then I compile them with Numba.
|
# ? Apr 3, 2016 19:54 |
|
Dominoes posted:Video criticizing OOP. he said that oop is about pass by value, not inheritance or polymorphism. then he discussed pros and cons of abstraction, and of global variables
|
# ? Apr 3, 2016 20:25 |
|
Cingulate posted:Isn't one of the lessons of the success of Python that it can be good to have a language you can use functionally or OO? To slightly nitpick here, Python can be used procedurally (a la C or other non-OO imperative languages); it's not particularly good at the functional programming aspect - it's just not where the expressiveness was prioritized in the language.
|
# ? Apr 3, 2016 20:39 |
|
And it doesn't have tail call elimination
|
# ? Apr 3, 2016 21:01 |
|
|
# ? May 8, 2024 12:31 |
|
Asymmetrikon posted:To slightly nitpick here, Python can be used procedurally (a la C or other non-OO imperative languages); it's not particularly good at the functional programming aspect - it's just not where the expressiveness was prioritized in the language.
|
# ? Apr 3, 2016 21:06 |