|
Pollyanna posted:However, PyCharm tells me "local variable page is not used" on line 2 and "local function page() is not used" on line 5. Why does this error occur?
|
# ? Nov 8, 2013 20:35 |
|
|
# ? May 9, 2024 11:12 |
|
Pollyanna posted:I am extremely lazy, however, and it would be nice if I could write a function that added a page for me given a URL pattern, a page name, and a reference to an HTML file, like so: Since you are using PyCharm, it already has something to do that for you in the form of live templates. Just type the word "route", and hit tab, and it will create a flask template for you. You can check out the Live Template in the settings menu to see what other shortcuts are available to you.
|
# ? Nov 8, 2013 20:56 |
|
Thern posted:Since you are using PyCharm, it already has something to do that for you in the form of live templates. Just type the word "route", and hit tab, and it will create a flask template for you. That's not available in the Community Edition, which is missing a shitload of features. a lovely poster posted:It's being pretty literal with you. You're not using either the variable or the function. You set page to the name argument, but then never see it again. Then you redefine page as a function but never call it in that local scope. ...right I forgot to say, "define a function that has a name equal to page". I don't know if there's a way to do that, though...
|
# ? Nov 8, 2013 21:58 |
|
Pollyanna posted:...right I forgot to say, "define a function that has a name equal to page". I don't know if there's a way to do that, though... Why do you care about the name of a throwaway wrapper function? Which, BTW you can set with the __name__ property if you really want Anyway, you can probably do the same thing like this: Python code:
E: I get it now - code updated Munkeymon fucked around with this message at 23:04 on Nov 8, 2013 |
# ? Nov 8, 2013 22:41 |
|
Wouldn't you want to do something like this:Python code:
|
# ? Nov 8, 2013 22:55 |
|
BamPython code:
|
# ? Nov 9, 2013 00:30 |
|
It seems extraordinarily silly to me to add a helper method for this. If all you are doing is rendering a static template, then you should probably have that cached and configured from your web server. But I'm probably thinking "at scale" too much, more so than for a learner just playing around. Hm.
|
# ? Nov 9, 2013 00:33 |
|
I'm just somehow under the impression that the name of the function has to be exactly the same as the HTML name Maybe that is not the case. Oh, also, this isn't really Python-specific, but I just tried using gunicorn and when I exited, localhost:5000 is still displaying my page. Why is this happening? I can even access the other pages in the app. edit neeeeeeeeever mind blame heroku Pollyanna fucked around with this message at 01:43 on Nov 9, 2013 |
# ? Nov 9, 2013 01:30 |
|
BeefofAges posted:No, it's actually not that bad. Follow this guide. http://docs.python-guide.org/en/latest/starting/install/osx/ Can you explain what this does? I seem to be running Python out of the terminal now, but wasn't that possible before? How can this be used to install modules that can be used with the shell from python.org?
|
# ? Nov 9, 2013 01:43 |
|
User-Friendly posted:Can you explain what this does? I seem to be running Python out of the terminal now, but wasn't that possible before? How can this be used to install modules that can be used with the shell from python.org? You now have an installation of virtualenv linked to the homebrew python. Anytime you want to work on a new project, create a virtualenv for that project, use pip to install whatever modules you want to use, and have at it. When you switch to a different project, switch virtualenvs.
|
# ? Nov 9, 2013 02:44 |
|
edit: replied to something that was a page ago
Lurchington fucked around with this message at 06:55 on Nov 9, 2013 |
# ? Nov 9, 2013 06:52 |
|
m0nk3yz posted:Python tutorials and free online books: Wanted to thank you for this cause I need to refresh my Python because too much C recently. Also I recommend the everliving gently caress out of PyCharm. It basically blows you while you code in Python and not only swallows, but licks your rear end in a top hat afterwards. EDIT: Specifically, PyCharm with the IdeaVim plugin pliable fucked around with this message at 08:31 on Nov 9, 2013 |
# ? Nov 9, 2013 08:27 |
|
Anyone else think we need a new OP?
|
# ? Nov 9, 2013 16:19 |
|
Thermopyle posted:Anyone else think we need a new OP?
|
# ? Nov 9, 2013 17:00 |
|
Thermopyle posted:Anyone else think we need a new OP? Yes. A lot has changed in the last 6 years, and m0nk3yz hasn't posted for over two years.
|
# ? Nov 9, 2013 17:01 |
|
I'll make one if someone more experienced doesn't by Monday.
|
# ? Nov 9, 2013 17:07 |
|
Dominoes posted:I'll make one if someone more experienced doesn't by Monday. I started one already. I'm writing it in Google Docs to get some comments and whatnot on it before I post it for real.
|
# ? Nov 9, 2013 17:17 |
|
Heck, I'll just share the link now so I can get comments before I'm done. I'm not terribly far on it yet.
|
# ? Nov 9, 2013 18:43 |
|
Thermopyle posted:Heck, I'll just share the link now so I can get comments before I'm done. I'm not terribly far on it yet. I'm biased, of course, but I think you should include a link to Anaconda as an option for getting hard-to-build packages easily, and for creating isolated environments for different versions of things.
|
# ? Nov 9, 2013 19:29 |
|
Things to add: -Info on Pip, Ubuntu's package system, and Chris Gohlke's windows binaries -Links to tutorials and resources for beginners -Brief descriptions of available GUIs -Link to official docs, and possibly to a few particularly useful pages. -Mention Pep 8
|
# ? Nov 9, 2013 19:38 |
|
Thermopyle posted:Anyone else think we need a new OP? Btw, the last time this came up, I did ask monk3ys nicely and he came back and edited the post, but I think he's too busy now
|
# ? Nov 9, 2013 20:09 |
|
BigRedDot posted:I'm biased, of course, but I think you should include a link to Anaconda as an option for getting hard-to-build packages easily, and for creating isolated environments for different versions of things. And PythonXy. Actually here's a bunch of descriptions of stuff pulled from various blog posts and peppered with my own comments: Main Windows installer from python.org: good starting point for vanilla Python, but if you want any modules or extensions then you're on your own. Completely free. A great option if you're extremely paranoid and want "real" Python or something Pythonxy: Aimed at science and engineering applications based around Spyder, an IDE that looks and feels a lot like MATLAB. Comes with a lot of useful packages and even a lot of other IDEs. Completely free, endorsed by several people in the thread PortablePython: Python plus a bunch of packages bundled together and made to run off of a thumb drive. You don't need to put it on a thumb drive necessarily, but you can if you want. Comes with IDEs and lots of useful packages. This is great if you need to work in an environment where you need total control over your Python distribution but don't necessarily have admin access on your computer but still have access to USB ports. Completely free Anaconda: Aimed primarily at business, has free and paid versions but even the free version comes with some of their home-grown tools. I think that they make it slightly easier to update modules than Pythonxy ActivePython: Aimed primarily at business, has its own package manager, has free and paid versions, endorsed by several people in the thread Enthought (Canopy): Aimed primarily at business, has free and paid versions. These guys feel like glorified package managers but apparently they develop their own tools, too, like the Anaconda guys I'm pretty sure that all of these different 3rd party Python package managers (Pythonxy, Anaconda, etc) create isolated distributions that shouldn't effect anything else, which is handy! If you're on Linux just be a man and use your package manager. If you're on a Mac then I think your only choice for a 3rd party package manager is Enthought, and they'll want to charge you for the privilege, so get hosed Mac users I guess QuarkJets fucked around with this message at 20:37 on Nov 9, 2013 |
# ? Nov 9, 2013 20:33 |
|
What are the best libraries out there for sound and image related stuff? I see PIL in a lot of Google/StackOverflow results for Python image stuff, but it seems to have a pretty glacial update pace. Pretty much all I need is to be able to read in images as a list of pixels or something similar, and play back MIDIs.
|
# ? Nov 9, 2013 20:51 |
|
I would like to propose this addition to the FAQ-ish section: What is this __metaclass__ thinger? Metaclass is a way to break python by changing the ways classes get defined in a non-obvious, non-composable way from a distance. It's main purpose today is to trick people into doing dumb poo poo. You should never use __metaclass__. If you see __metaclass__ used by mature and reliable libraries and/or frameworks, know that their authors have regretted that choice. Just about anything reasonable you can do with __metaclass__ is much better done by a class decorator (which are not available prior to python 2.6, which is why __metaclass__ is actually used quite a bit, to everyone's determent and general displeasure). What is PEP8? PEP8 is the official python coding style guide. You should definitely get to know it soon after figuring out the language's basics. If you write according to PEP8 your code will be easy to follow and easy to read and you will be popular with your peers and sexual partners. Conversely, if you begin to stray and dabble with using tabs or relative imports for no good reason, your peers will mistrust you and your sexual partners will begin to question your personal hygiene. Decorators are awesome! I made such good use of them, this thing I wrote is more decorators than function bodies! Every time you do something like this, a little girl or boy has to watch their parents fight and cry quietly into their teddy bear. You inhuman monster. (Decorators are great, but use them sparingly. Consider a better class layout or simply moving some behaviour into the method body like normal people. Basically, don't use them just because they're there - have a good reason to use them.) I hear Python isn't as fast or web scale or good at concurrent workers as hip and popular Node.js So here's the thing: Python is known for its terrible behavior when it comes to multithreading - there's a thing called the Global Interpreter Lock or GIL which essentially means no actual python code can execute simultaneously on the same python process even in different threads, though one can often create the illusion of doing so. Guess what though, v8 javascript has the exact same behaviour, except with absolutely no ability to "lock" or "wait" while executing a function. You are either executing a function or waiting for a function to be called (by an external callback). You can't even have the illusion of simultaneous execution, which is why Node.js has its famous "boomerang" coding style (callbacks inside callbacks inside callbacks inside callbacks...). We can have the exact same sort of "no shared memory state, just wait for IO to return over thousands of 'green threads'" evented architecture as Node.js in Python, except instead of having to break out to a callback just to wait for every single loving thing that goes to IO, we just,get this, wait for IO to return by pausing execution. I.e. an evented python application looks like a normal loving application where statements happen one after another in sequence and we can throw and handle exceptions like normal people. And considering python can definitely hold its own in terms of request handling benchmark dick waving, it is as astounding as it is bewildering that people use Node.js for anything at all. (In theory you could do some weird poo poo where you want to pass around code from client to sever, but I've never seen anyone actually do this in a Node.js app, because it's actually a pretty crazy idea as soon as you think about it for more than 5 minutes) tl;dr: Python is at least on par with Node for making evented servers while being far, far easier to code with. This may be less due to Python being awesome and more due to Node/JS being totally hosed up though. Having said that, IMO you can't really do better than Python for this sort of problem without digging into the more, shall we say, eclectic programming languages such as Go or Erlang (Which are both fine btw! Go learn Go, it's neat!)
|
# ? Nov 10, 2013 01:17 |
|
What is a metaclass? Classes are templates for objects. Metaclasses are templates for classes. They are very hard to use, and treated with a mixture of fear and reverence by python programmers, a feature which comes at the expense of maintainability. Use with caution, or better, simply avoid them. What is PEP8? PEP8 is a compromise, a series of stylistic choices which prioritises working with other people over individual aesthetics. You should try and follow them, but it is still a guideline. At the very least, method_names and function_names have underscores, ClassNames are camel case, and indentation is four spaces. What are decorators? Decorators are a nice way to wrap functions. Python uses them for methods (class, static) and properties. Decorators are used best when they are simple wrappers, and fail badly when they have highly specific behaviours. What is the GIL? Python supports threads, but not concurrent threads: Only one thread is active at a time. If you need to have concurrency, consider using multiprocessing, with queues to glue the processes together. If you want to write event based code, there is the upcoming async library in python 3, as well as a plethora of options for python 2, including twisted.
|
# ? Nov 10, 2013 02:11 |
|
There is no need for cheap jokes or point scoring with Node.js in the FAQ, this isn't /r/programming or hacker news. Let's just be quick and simple with the answers. If you find yourself writing tl;dr in a faq answer, maybe you should delete the rest and leave the summary in.
tef fucked around with this message at 02:17 on Nov 10, 2013 |
# ? Nov 10, 2013 02:12 |
|
quote:Anaconda: Aimed primarily at business, has free and paid versions but even the free version comes with some of their home-grown tools. I think that they make it slightly easier to update modules than Pythonxy Just a clarification, there is only one Anaconda, and it is always free. We have a couple paid products that we developed that we happen to distribute conveniently as conda packages, but Anaconda itself is completely free. And yes for the "python doesn't scale" question you can refer to Dropbox who build a billion dollar company on python. Maybe also a blurb about descriptors? The best definition I have seen is "you own the dot". BigRedDot fucked around with this message at 02:58 on Nov 10, 2013 |
# ? Nov 10, 2013 02:53 |
|
I recently started working at a new company, and they wrote their own web API test automation framework. It uses metaclasses heavily. It's kind of a pain to work on because IDE code completion or intellisense or whatever you want to call it doesn't work at all. I can barely figure out what code is calling what. Don't use metaclasses unless you have a really good reason. Actually, don't use any tricky features of the language at all unless you have a good reason.
|
# ? Nov 10, 2013 03:59 |
|
Seriously though, if any of you would care to name a single legitimately good use of the metaclass, I am all ears. I really don't think there is a "good reason" for it, ever. (Except maybe "we can only use python 2.5 or older" - fine fine)
|
# ? Nov 10, 2013 04:19 |
|
Also,tef posted:What is PEP8? quote:If you want to write event based code, there is the upcoming async library in python 3, as well as a plethora of options for python 2, including twisted.
|
# ? Nov 10, 2013 04:25 |
|
I think the OP should include a link to this writeup. I've found it to be very useful. http://www.wallix.org/2011/06/29/how-to-use-jenkins-for-python-development/
|
# ? Nov 10, 2013 04:45 |
|
Mr. Wynand posted:Seriously though, if any of you would care to name a single legitimately good use of the metaclass, I am all ears. I really don't think there is a "good reason" for it, ever. (Except maybe "we can only use python 2.5 or older" - fine fine) I like the abstract base class out of the standard library. But that's probably not you mean. So at work, we use a lot of SQLAlchemy for our database work. This is a tool that cares a LOT about the lifetime of a "session" (thing that you use to interact with data, and you need to ensure it's cleaned up right). Typically people use a context manager (there's a recipe here if you scroll down). We work on a lot of different projects that have their own schema, and since it's lame to reimplement the same "session manager" context manager with tiny changes each time, we have a library provide a "session manager maker" that uses metaclass, and it's fine since the complexity is hidden in a unit tested, code reviewed, and documented module we never touch again.
|
# ? Nov 10, 2013 05:38 |
|
Thermopyle posted:Heck, I'll just share the link now so I can get comments before I'm done. I'm not terribly far on it yet. I've added a bajillion comments with links and suggestions. good luck.
|
# ? Nov 10, 2013 05:41 |
|
Mr. Wynand posted:I hear Python isn't as fast or web scale or good at concurrent workers as hip and popular Node.js It doesn't make Python any less suitable for these things, mind you -- before my current job I wrote lots of gevent and barely touched Node for a reason -- but the state of things isn't nearly as melodramatically awful as you're making it sound. Vulture Culture fucked around with this message at 07:36 on Nov 10, 2013 |
# ? Nov 10, 2013 07:31 |
|
It might also be worth mentioning that people commonly ask whether Python is as fast as MATLAB/Perl/whatever. The answer is that for some things it's faster, for others it's slower. In most case it's not going to be as fast as compiled code
QuarkJets fucked around with this message at 09:03 on Nov 10, 2013 |
# ? Nov 10, 2013 08:52 |
|
Misogynist posted:Rants are neat and all, but the Promises/A+ spec, of which there are at least a dozen compatible implementations to choose from, makes event-driven Javascript code pretty sane and readable -- there are, believe it or not, ways to control the flow of async code besides nesting braces 20 spaces deep and manually counting references. And considering Python's heritage with Twisted, I don't think that's even a fair thing to hate on anyway. (Figuring out how to wrap callback-based libraries into promises using something like promisemonkey or when-promisify can be a pain in the rear end, but the resulting code has completely sane flow once you boilerplate a couple of lines.) It's been a while since I looked at this, but don't promises merely roll the callbacks out flatly instead of a boomerang? It's still a pile of callbacks, just, we don't have to nest them, woopedy-doo. That is... technically an improvement, but to my mind still in that same order of magnitude in terms of being a weird-rear end way of doing things compared to, you know, statements that follow each-other. Unless I really did severely misunderstand promises and it's possible to use them without callbacks (without locking the process during io sync). Lurchington posted:I like the abstract base class out of the standard library. But that's probably not you mean. quote:So at work, we use a lot of SQLAlchemy for our database work. This is a tool that cares a LOT about the lifetime of a "session" (thing that you use to interact with data, and you need to ensure it's cleaned up right).
|
# ? Nov 10, 2013 09:43 |
|
tef posted:There is no need for cheap jokes or point scoring with Node.js in the FAQ, this isn't /r/programming or hacker news. Let's just be quick and simple with the answers. If you find yourself writing tl;dr in a faq answer, maybe you should delete the rest and leave the summary in. Also, just wanted to mention that I am actually quite glad the first reaction to my sort of ranting was the above. I cannot loving stand how much the Ruby community just wallows in that sort of attitude and when you actually just need to read some basic bloody docs to get something done you first have to wade through the requisite documentation witticisms which should not be a thing that exists, god drat.
|
# ? Nov 10, 2013 09:52 |
|
Mr. Wynand posted:It's been a while since I looked at this, but don't promises merely roll the callbacks out flatly instead of a boomerang? It's still a pile of callbacks, just, we don't have to nest them, woopedy-doo. That is... technically an improvement, but to my mind still in that same order of magnitude in terms of being a weird-rear end way of doing things compared to, you know, statements that follow each-other. http://taskjs.org/
|
# ? Nov 10, 2013 16:13 |
|
I am messing around with paramiko and one of the demos requires a module called interactive. Where the gently caress can I find it? Searching turns up nothing since its such a generic name. Its to run this demo script - https://github.com/paramiko/paramiko/blob/master/demos/demo_simple.py code:
EDIT: Nevermind apparently it was another file that I didn't download. WOOPS. Sylink fucked around with this message at 19:27 on Nov 10, 2013 |
# ? Nov 10, 2013 19:00 |
|
|
# ? May 9, 2024 11:12 |
|
Sylink posted:I am messing around with paramiko and one of the demos requires a module called interactive. Where the gently caress can I find it? It's right here. https://github.com/paramiko/paramiko/blob/master/demos/interactive.py ps hi sylink how are you doing
|
# ? Nov 10, 2013 19:25 |