|
I'm guessing that Python was still processing and wouldn't give you a ">>> " prompt until it was done. You asked it to calculate some pretty big numbers. You also can't "undo" anything in the interactive interpreter; as I recall Ctrl-z is "end of file" on Windows and sends a job into the background on Linux. Ctrl-c is what you use to interrupt some operation (which is implemented as raising the KeyboardInterrupt exception).
|
# ? Apr 4, 2013 00:44 |
|
|
# ? May 8, 2024 20:56 |
|
Bigup DJ posted:What's happening? You are making Python try to calculate a number with over 10^30 digits (plus a few somewhat smaller but still ridiculously large numbers). When I run your code I get a MemoryError on Windows.
|
# ? Apr 4, 2013 00:58 |
|
Bigup DJ posted:So I'm learning Python and I was fiddling with list comprehensions: Because you are trying to calculate a list of retardedly large numbers. why are you doing a power of a power of a power edit: oops didn't see this page anyways the upper bound in that one would be 10^(2^(9^2)) The resulting number would have 2417851639229258349412353 decimal digits. peepsalot fucked around with this message at 02:34 on Apr 4, 2013 |
# ? Apr 4, 2013 02:23 |
|
Ok, thanks everyone! Does python have a way to test whether or not one equation equals another equation? eg. Something like [x**y = x**x if x = y] returning "True" or "False".
|
# ? Apr 4, 2013 03:46 |
|
What on earth does that even mean? An equation doesn't equal anything.
|
# ? Apr 4, 2013 04:28 |
|
Bigup DJ posted:Ok, thanks everyone! Does python have a way to test whether or not one equation equals another equation? eg. Something like [x**y = x**x if x = y] returning "True" or "False". You're looking for a proof assistant of some kind. Unfortunately, it's probably undecidable depending on what x and y are quantified over. Look into SMT solvers, z3 has python bindings. But no, python doesn't have it "built in".
|
# ? Apr 4, 2013 04:56 |
|
Thanks! Sorry if my questions aren't making sense, I'm new to complicated maths and coding in general.
|
# ? Apr 4, 2013 06:10 |
|
I'm trying to make a simple script which takes an IP address via raw_input, then splits it and then does something based on the last octet. Thus far I've got: code:
EDIT: Never mind, I sussed it. octet[-1] did it for me Experto Crede fucked around with this message at 23:24 on Apr 4, 2013 |
# ? Apr 4, 2013 23:14 |
|
Hi guys, I just wanted to throw out that the videos of tutorials and talks from our latest PyData conference are up on vimeo now: http://vimeo.com/pydata/videos I think the keynotes are still missing, but everything else (about 30 videos, including my talk! but which one is it?) is available There are great talks and tutorials on tools: numpy, matplotlib, pandas, scikit-learn, as well as a variety of specific data analysis examples involving python. Hope you might find something interesting or useful!
|
# ? Apr 4, 2013 23:56 |
|
Experto Crede posted:I'm trying to make a simple script which takes an IP address via raw_input, then splits it and then does something based on the last octet. When doing anything involving user input and IP addresses, please note that all of the following are perfectly legal IP addresses: (for the same host, even!)
|
# ? Apr 5, 2013 00:37 |
|
Better yet, just find an IP parsing module someone else wrote and import it.
|
# ? Apr 5, 2013 02:53 |
|
BeefofAges posted:Better yet, just find an IP parsing module someone else wrote and import it. Python code:
|
# ? Apr 5, 2013 04:18 |
|
Wow, those are crappy function names.
|
# ? Apr 5, 2013 07:56 |
|
BeefofAges posted:Wow, those are crappy function names. It's pretty similar to the old atoi and atof functions that C has
|
# ? Apr 5, 2013 10:07 |
|
QuarkJets posted:It's pretty similar to the old atoi and atof functions that C has This is how php names its functions. Do you really want to draw that comparison?
|
# ? Apr 5, 2013 10:48 |
|
Ipaddress was included in 3.3 and it is awesome. I haven't checked some of those address variants, though.
|
# ? Apr 5, 2013 11:36 |
|
I'm in the process of learning Python to replace my work's batch file scripts with something more powerful. I use the subprocess module for calling external programs and grabbing their stdout and stderr return codes. Some of the example code that I've found had things like this: code:
Also, why would you want to shorten subprocess? So you have less to type in very large scripts? Doesn't that get confusing when you have a 500 line script and you can't remember what the hell you shortened subprocess to?
|
# ? Apr 5, 2013 16:04 |
|
Dammit, Edit not Quote
|
# ? Apr 5, 2013 16:05 |
|
Risket posted:I'm in the process of learning Python to replace my work's batch file scripts with something more powerful. You might want to use the from statement to reduce the amount of typing or to prevent python from doing a lookup on the module every time it goes to access subprocess.call(). There actually is a performance penalty there. In the interest of readability I lean toward "don't rename stuff on import and mostly don't use import ... from". It's easier for other people to know what your symbols are if you fully qualify them. If you feel that you must import ... from, consider doing it right above the code that needs the symbol instead of at the top of the file so that others don't have to look far to find the meaning of the symbol.
|
# ? Apr 5, 2013 16:16 |
|
Risket posted:I'm in the process of learning Python to replace my work's batch file scripts with something more powerful. I usually like to import the complete module because that way I don't have to worry about potential naming conflicts, but sometimes it is nice to shorten names because they are long, and used frequently. For example, import matplotlib.pyplot as plt is a convention for importing the pyplot module of matplotlib. There is also import numpy as np. Here the shortening is used because there might be a number of numpy methods called on a single line.
|
# ? Apr 5, 2013 16:16 |
|
Risket posted:I'm in the process of learning Python to replace my work's batch file scripts with something more powerful. read this http://bytebaker.com/2008/07/30/python-namespaces/
|
# ? Apr 5, 2013 16:24 |
|
Bigup DJ posted:Thanks! Sorry if my questions aren't making sense, I'm new to complicated maths and coding in general. Just a quick guess, but reading your questions, you may wanna look into whether your school has a site license for Mathematica. Mathematica is great for solving some hard questions, especially when you need a analytical solution. As with everything, don't trust the black box, and make sure you're getting the correct answer though. accipter posted:I usually like to import the complete module because that way I don't have to worry about potential naming conflicts, but sometimes it is nice to shorten names because they are long, and used frequently. For example, import matplotlib.pyplot as plt is a convention for importing the pyplot module of matplotlib. There is also import numpy as np. Here the shortening is used because there might be a number of numpy methods called on a single line. Yup. I also use import subprocess as subp. Subp is non-standard though, and you should probably use sp if you're planning on giving the code to people outside your group. And I never forget what np, or plt, or sp/subp mean because I use them all the time. Yeah, when you shorten libraries you don't use as much, you can sometimes forget, but that's why you just quickly scroll to the top and find out. Collections is a good example of a library I use occasionally that I will sometimes forget what I shorten it to. While were on the topic, I get really frustrated at coding guides that use: from blah import * or whatever the analog is. (For example using namespace std in C++ beginner's guides.) I used to do it when first learning python, and it's a colossal mistake. It bothers me when people encourage others to do it. Namespace pollution is bad enough, but when you don't even know what functions belong to what library, that's downright bad practice. It's the biggest reason why I am so against using pylab. It encourages people to forget what functions are in numpy and what are in pyplot. If you're using matplotlib on a regular basis, chances are the work you do will always need numpy. You'll NOT always need pyplot.
|
# ? Apr 5, 2013 16:45 |
|
Dren posted:You might want to use the from statement to reduce the amount of typing or to prevent python from doing a lookup on the module every time it goes to access subprocess.call(). There actually is a performance penalty there. Nice article, thanks!
|
# ? Apr 5, 2013 16:49 |
|
edit: again: just kidding it actually appears to be Twisted's fault Real Question Mk 2: I replaced their calendar example with something that just generates a page holding "SUCCESS". If I try to generate a page whose name is something like "1 2 3 4" (and I know for a fact spaces are fine in URLs) it will give me the error: quote:No Such Resource what the heck? Smarmy Coworker fucked around with this message at 17:04 on Apr 5, 2013 |
# ? Apr 5, 2013 16:49 |
|
Well, that's obviously not your real code because you wrote print passed instead of print "passed". I really don't know what else it would be — just try having a path component without colons?
|
# ? Apr 5, 2013 16:54 |
|
When you have multiple nested modules "from" makes a lot more sense. I use qt so most of the modules are prefixed with Qt anyway and it's a lot easier to do from pyqt4 import QtCore, QtGui and not end up with constructions like pyqt4.QtCore.QThread everywhere. I think the real advantage is that when you do it that way it only imports the submodules you asked for and not the whole library, but the interpreter might be smarter than that.
|
# ? Apr 5, 2013 16:56 |
|
edit: For some dumbass reason http://localhost:8880/x works but http://localhost:8880/x/ doesn't. Thanks Twisted hooray Smarmy Coworker fucked around with this message at 18:18 on Apr 5, 2013 |
# ? Apr 5, 2013 17:06 |
|
ARACHNOTRON posted:edit: That's pretty standard for web frameworks that use regex-based pattern routing, though I'm not sure how twisted does it. In Django you'd have to make the route something like '^/fart/?$' which would match with or without a trailing slash.
|
# ? Apr 5, 2013 18:02 |
|
twisted.web does not use regex routing, but it's really not the best thing in the world. Twisted is a great networking stack for other protocols, and it's pretty OK at being an HTTP client. It's really not the greatest web server out there. Try one of Pyramid or Flask?
|
# ? Apr 5, 2013 18:10 |
|
So, what it's doing is calling getChild('') on the resource that you returned. You can work-around the issue by special-casing the empty string in getChild, or calling self.putChild('', self) in your resource constructor. EDIT: or just set isLeaf on the leaf resource. I'll contact the Twisted docs guys about this.
|
# ? Apr 5, 2013 18:19 |
|
Suspicious Dish posted:twisted.web does not use regex routing, but it's really not the best thing in the world. Twisted is a great networking stack for other protocols, and it's pretty OK at being an HTTP client. It's really not the greatest web server out there. Try one of Pyramid or Flask? My unsolicited advice on these after trying them out myself: Flask is pretty cool, though I haven't found a way to scale into larger things with it elegantly yet. If you have lots of routes, it can be a pain to find your views if you're using the decorators for routing. You'll also end up with circular module dependencies really quickly if you start breaking your app out into modules. There also doesn't seem to be a counterpart to tastypie/django-rest-framework if you want a full REST framework with auth, throttling, and pagination while still being able to define your own routes or customize your endpoints. Flask-Restless works great if you just want to expose SQLAlchemy models via REST, though, and has auth hooks as well as pagination and throttling. Simple REST views are easy to whip up with MethodViews. Could never get into Pyramid, seemed to have all the cruft of Django without any of the batteries included. It's a bunch of interfaces and you do the wiring yourself, unless there was a page detailing all the standard 'give me a CRUD app with SQLAlchemy' recipes/plugins that I missed.
|
# ? Apr 5, 2013 18:24 |
|
Unfortunately we use Twisted at work for everything so I pretty much have to learn twisted.web and stick with it. For anything personal heck no I'm not using it.Suspicious Dish posted:So, what it's doing is calling getChild('') on the resource that you returned. You can work-around the issue by special-casing the empty string in getChild, or calling self.putChild('', self) in your resource constructor. I figured this out when I was trying to understand why my images weren't loading. /img/x was trying to get the x child resource from the other child resource and yeah whatever I just did putChild to set up a static file structure.
|
# ? Apr 5, 2013 18:24 |
|
You might be interested in klein, which hooks up Werkzeug routes to twisted.web. The twisted.web simple Site/Resource system isn't really the best thing in the world, but thankfully, it's easily swappable.
|
# ? Apr 5, 2013 18:40 |
|
Gaukler posted:Flask is pretty cool, though I haven't found a way to scale into larger things with it elegantly yet. If you have lots of routes, it can be a pain to find your views if you're using the decorators for routing. You'll also end up with circular module dependencies really quickly if you start breaking your app out into modules. I haven't encountered any reason to want to import a Flask blueprint from another blueprint, so I'm not sure how you'd end up with circular dependencies other than putting way too much into them.
|
# ? Apr 5, 2013 19:12 |
|
Suspicious Dish posted:You might be interested in klein, which hooks up Werkzeug routes to twisted.web. The twisted.web simple Site/Resource system isn't really the best thing in the world, but thankfully, it's easily swappable. This just looks... so... good. Simple, clean. Wow. I will look into using this
|
# ? Apr 5, 2013 19:34 |
|
I'm trying to capture and display the stdout from subprocess.popen(). This is on Python 3.3 using Windows 7.Python code:
quote:The output of SetDevice is: b'Board ID 1\r\nBoard Variant 0\r\nBoardSerial 231\r\nHW Flags 0000' quote:Board ID 1
|
# ? Apr 5, 2013 20:41 |
|
Plorkyeran posted:I prefer Rails' approach of a single routes file (with nothing but the routes), but I haven't found finding views in Flask to be a major issue. Is your module structure completely unrelated to your URL structure or something? You don't HAVE to use the decorator-based routing and could create a routes.py or urls.py (using app.add_url_rule()), which may help that. The circular imports/dependencies issue is mainly just "feels wrong", they even explicitly call out this scenario in the docs as not a bad thing (Bottom of this page), but it feels like there could be a cleaner solution.
|
# ? Apr 5, 2013 20:48 |
|
Risket, http://docs.python.org/3/library/stdtypes.html#binaryseq
|
# ? Apr 5, 2013 20:51 |
|
That was spot on, thank you.
|
# ? Apr 5, 2013 21:17 |
|
|
# ? May 8, 2024 20:56 |
|
Another CSV / memory vs drive write question. If I want to download a CSV from a url, is there a way I can put the file information directly into a variable in memory? I've tried many combinations using list(), read(), csv.reader() etc, but can't find a working solution that skips writing the csv to disk, and reading it. Code like this works: Python code:
Python code:
|
# ? Apr 6, 2013 01:40 |