|
Stabby McDamage posted:With a data format that simple, it may be easier just to read line-by-line and use split and/or a regex. If I was writing it, I never would even have considered using a parsing library for space-based key-value pairs. Even when the values could be a dict of dicts of dicts of lists of dicts of lists containing floats? IE: One k/v pair in my normal test is: code:
code:
Hughlander fucked around with this message at 16:46 on Jun 29, 2010 |
# ? Jun 29, 2010 16:43 |
|
|
# ? May 9, 2024 16:19 |
|
The reason it is so slow is that pyparsing is a parsing framework, not a parser itself. Hand written parsers will normally go much faster than a parser-interpreter written in python. Personally: i'd write a simple tokenizer and a top down parser myself, as it has embedded values in lists or pairs. alternatively, i'd tokenize it into key-value and use an existing library like simplejson to parse the value. edit: if you're using py2.6 : http://docs.python.org/library/json.html
|
# ? Jun 29, 2010 18:32 |
|
EDIT: In hindsight, ignore this post and treat it like poo poo. The problem was just division by zero. I am having a small problem with floating point numbers here, and I know I am doing something terribly wrong - I just need help to point out the error. Below is a small function for generating a crude approximation of eulers number, where a fraction of (1/n) is added for each iteration. I may be even wrong with my approach, but the point is the error I get during interpretation. code:
When I run the function, I get this error: File "/Applications/WingIDE.app/Contents/MacOS/src/debug/tserver/_sandbox.py", line 6, in e ZeroDivisionError: float division clearly not a horse fucked around with this message at 23:28 on Jun 29, 2010 |
# ? Jun 29, 2010 23:24 |
|
range(N) returns a list starting at 0 with N elements in it. Try: for n in range(1, depth+1)
|
# ? Jun 29, 2010 23:28 |
|
Hughlander posted:Even when the values could be a dict of dicts of dicts of lists of dicts of lists containing floats? I'm sorry, I didn't read closely enough. I didn't see that lists and dicts were among the data types. Nevermind.
|
# ? Jun 30, 2010 02:36 |
|
clearly not a horse posted:EDIT: In hindsight, ignore this post and treat it like poo poo. The problem was just division by zero. You may want to double check your math. Summing 1/n doesn't give you what you think it gives you. You shouldn't get division by zero even when n = 0.
|
# ? Jun 30, 2010 16:40 |
|
Could someone please point me in the direction of a good dictionary tutorial in python 3? Something that would be geared more towards a beginner if possible. Thanks.
|
# ? Jun 30, 2010 19:29 |
|
Mr. Clark2 posted:Could someone please point me in the direction of a good dictionary tutorial in python 3? Something that would be geared more towards a beginner if possible. Thanks. it's not loading on my network for some reason, but this may be helpful: http://diveintopython3.org/native-datatypes.html
|
# ? Jun 30, 2010 19:37 |
|
Mr. Clark2 posted:Could someone please point me in the direction of a good dictionary tutorial in python 3? Something that would be geared more towards a beginner if possible. Thanks. Dive into Python is pretty good: http://diveintopython3.org/native-datatypes.html#dictionaries It's not a horrendously hard concept, really, but if there's a particular problem you're facing do ask. e: welp. I guess we have consensus then.
|
# ? Jun 30, 2010 19:38 |
|
Thanks guys. I'm trying to learn python (I have 0 prior programming experience), I've bought 2 separate books designed for beginners, but in each one as soon as the book starts to delve into dictionaries, I come to a dead end and find it impossible to do the assignments and activities at the ends of the chapters. I'm hoping that by reading about dictionaries from as many different sources as possible, it will begin to 'click' in my head.
|
# ? Jun 30, 2010 19:51 |
|
Mr. Clark2 posted:Thanks guys. I'm trying to learn python (I have 0 prior programming experience), I've bought 2 separate books designed for beginners, but in each one as soon as the book starts to delve into dictionaries, I come to a dead end and find it impossible to do the assignments and activities at the ends of the chapters. I'm hoping that by reading about dictionaries from as many different sources as possible, it will begin to 'click' in my head. What do you think dictionaries are? If you don't have a clear mental model of what they represent, you're bound to have trouble doing stuff with them.
|
# ? Jun 30, 2010 19:55 |
|
Mr. Clark2 posted:Thanks guys. I'm trying to learn python (I have 0 prior programming experience), I've bought 2 separate books designed for beginners, but in each one as soon as the book starts to delve into dictionaries, I come to a dead end and find it impossible to do the assignments and activities at the ends of the chapters. I'm hoping that by reading about dictionaries from as many different sources as possible, it will begin to 'click' in my head. You get lists, right? A rough and tumble way of looking at dictionaries is as though they were lists that can be indexed by objects (like strings) instead of just integers. Yes, slicing et al doesn't really apply, but it's a reasonable mental model for them until you get into the nitty gritty.
|
# ? Jun 30, 2010 20:00 |
|
Dicionaries are just lists that are not ordered and accessible by a key, ala { key : value }. Just play with them, they're fairly simple to use and you can do some python tricks to extract the data into lists or get values using a string name etc etc.
|
# ? Jun 30, 2010 20:35 |
|
LuckySevens posted:Dicionaries are just lists that are not ordered and accessible by a key, ala { key : value }. Just play with them, they're fairly simple to use and you can do some python tricks to extract the data into lists or get values using a string name etc etc. And hey, once he's comfortable with Dictionaries, there's a bonus in 2.7/3.1 http://docs.python.org/dev/py3k/whatsnew/3.1.html#pep-372-ordered-dictionaries http://docs.python.org/dev/whatsnew/2.7.html#pep-372-adding-an-ordered-dictionary-to-collections
|
# ? Jun 30, 2010 20:42 |
|
fourwood posted:You may want to double check your math. Summing 1/n doesn't give you what you think it gives you. You shouldn't get division by zero even when n = 0. I think he's looking for sum([1.0/math.factorial(n) for n in range(N)]). (If using Python < 2.6, then math.factorial isn't available, but def factorial(x): return x*factorial(x-1) if x>1 else 1 will do.)
|
# ? Jun 30, 2010 23:00 |
|
Chris Awful posted:I can't figure out how to solve this intermittent error, and I've failed to find a solution. I just ignored it; thinking I could solve it later, but now I've created another object that uses vertex arrays and so this error is occurring more often. I think I resolved the issue. While searching Google for the symptoms, I came along this blog and found useful information in the comment section. There was talk about a flashing/flickering issue which was resolved by decreasing the count argument of glDrawArrays. This led me to reexamine glDrawArrays. Apparently, I misunderstood the index and count argument to mean range. So I changed glDrawArrays(GL_QUADS, 4, 8) to glDrawArrays(GL_QUADS, 4, 4) and the flickering and blending garbage has ceased.
|
# ? Jul 1, 2010 00:42 |
|
Has anyone watched the MIT OpenCourseWare link in the OP? Can anyone attest to the quality and if its worth the time for a complete beginner?
|
# ? Jul 1, 2010 02:32 |
|
Hughmoris posted:Has anyone watched the MIT OpenCourseWare link in the OP? Can anyone attest to the quality and if its worth the time for a complete beginner? If it's the one I'm thinking of, I watched the first few a while back to gain some ideas (I recently had to TA for a similar course at a different institution) and remember thinking they were pretty good.
|
# ? Jul 1, 2010 03:24 |
|
Regarding the discussion of ipython going on, I'm currently at the SciPy conference in Austin, and I noticed that everyone uses ipython instead of the regular default Python shell (in this part of the community at least), and I've learned a few tricks in it as well that I'll share: Besides the already-mentioned ls, dir, rm, etc. magic commands and the ? and ?? to show docstrings and source, it has other magic commands such as (which can be used with or without the leading %): %run - for running a script in the current dir, e.g., %run myscript.py; the variables/modules from that script can then be used interactively %logstart - logs the previous and future inputs to a file, which I've been using in the tutorials to record the history %timeit - used to benchmark a command or script some number of times (100, 1000, etc.; this is determined by how long the function takes to run) and returns the best of 3 loops: code:
Also, this shorthand "_" for the previous output (can be a value or an instance or whatever is returned): code:
code:
The developers of ipython mentioned that they have overhauled most of ipython in the last 9 months, and that they plan to release a big update "soon". Overall, it seems to be a really powerful tool, and GUIs such as Spyder (http://packages.python.org/spyder/) are currently implementing IPython as their Python shell instead of the standard one, which is apparently very difficult to do. I'll definitely be using ipython more in my own work, and I can't wait for it to be implemented in Spyder.
|
# ? Jul 1, 2010 05:58 |
|
Ipython is amazing For all you debug whores ipdb brings some of that awesome to debugging, just replace your import pdb with import ipdb and you're good to go. How was SciPy, by the way? Was David Beazley's keynote any good?
|
# ? Jul 1, 2010 06:21 |
|
SciPy has been very cool so far, although this was my first time at SciPy, the talks have been awesome. There is one more day of talks tomorrow (including mine!, which details my use of Python in my research). There were about 190 attendees this year, up from 120 last year. And Beazley's keynote was good stuff - funny, informative, and good demos (SimpleXMLRPCserver, multiprocessing, and logging - he ran a demo logging script that tweeted its status when the job was "complete"). Travis' keynote is in the morning and should be good as well. I know they are going to post the slides soon, the proceedings come out in August, and I think they are going to post videos as well, so I'll post those links here whenever they make those available in case anyone is interested.
|
# ? Jul 1, 2010 06:35 |
|
I've been experimenting with ipython recently, however neither the autoindent nor the tab key works for me. The tab key just displays the "Do you really want to display all 291 possibilities?". For the record, this is on OSX 10.6, if anyone has any advice.
|
# ? Jul 2, 2010 02:28 |
|
Captain Capacitor posted:I've been experimenting with ipython recently, however neither the autoindent nor the tab key works for me. The tab key just displays the "Do you really want to display all 291 possibilities?". Press tab again or enter or something. Anyway, autocomplete is only good if you type part of the word first. Have you never used a shell before?
|
# ? Jul 2, 2010 02:53 |
|
Jonnty posted:Press tab again or enter or something. Anyway, autocomplete is only good if you type part of the word first. Have you never used a shell before? Perhaps I didn't make myself clear. When trying to tab over as part of normal indentation, and having not typed anything on the currently line, it attempts the autocomplete behavior.
|
# ? Jul 2, 2010 03:38 |
|
Captain Capacitor posted:Perhaps I didn't make myself clear. When trying to tab over as part of normal indentation, and having not typed anything on the currently line, it attempts the autocomplete behavior. Oh, I see. Tab is used for autocomplete, so you can't indent with it. Are you sure autoindent isn't working? Have you tried typing something like "if True: <newline> print "a"" and seeing if it works? Also remember that to unident, you have to press enter twice.
|
# ? Jul 2, 2010 03:51 |
|
Jonnty posted:Oh, I see. Tab is used for autocomplete, so you can't indent with it. Are you sure autoindent isn't working? Have you tried typing something like "if True: <newline> print "a"" and seeing if it works? I think that autoindent is working, but it doesn't display. I say this because when I scroll back through my input history the lines are displayed with the tabs. The Control-I/Control-O for indent/unindent don't seem to work either.
|
# ? Jul 2, 2010 14:06 |
|
I don't know if this still matters in 10.6/the current version of ipython, but at least a year ago, the default Apple install of readline in 10.5 didn't work with ipython, so you had to download the GNU version and compile it yourself. Maybe google around and see if that's still a problem?
|
# ? Jul 2, 2010 14:10 |
|
I'm trying to use the sqlite module but I'm having a problem with the double column type. Some of the data has decimal places, but when those cells are read from the database and turned into machine floating points, errors are introduced, so I thought to try to make it return strings since I don't want to manipulate the numbers, anyway. I tried registering a data converter, but it doesn't seem to be used. Can anyone tell me what I'm doing wrong here:code:
code:
I also tried registering the converter on the name of the column: code:
Munkeymon fucked around with this message at 18:50 on Jul 3, 2010 |
# ? Jul 3, 2010 06:07 |
|
You know what would be nice? Having, code:
code:
|
# ? Jul 4, 2010 02:14 |
|
Haystack posted:You know what would be nice? >>> type([1,2,3]) is list True >>> type({1:2}) is dict True
|
# ? Jul 4, 2010 02:17 |
|
ATLbeer posted:>>> type([1,2,3]) is list Yes, but, code:
|
# ? Jul 4, 2010 02:28 |
|
Haystack posted:Yes, but, code:
|
# ? Jul 4, 2010 02:32 |
|
Yes but,Haystack posted:Yes, but, code:
|
# ? Jul 4, 2010 02:35 |
|
Jonnty posted:
That'll teach me to be lazy with the interactive interpreter.
|
# ? Jul 4, 2010 02:36 |
|
Yeah, but it still wouldn't work for subclasses. Having some kind of shorthand for isinstance would still be nice.
|
# ? Jul 4, 2010 03:06 |
|
isa = isinstance
|
# ? Jul 4, 2010 03:12 |
|
This was discussed on comp.lang.python a while ago, no one was really enthusiastic about it.
|
# ? Jul 4, 2010 03:19 |
|
http://www.python.org/download/releases/2.7/quote:
http://docs.python.org/dev/whatsnew/2.7.html Now, if I can only get our OPs team to upgrade production from 2.4...
|
# ? Jul 4, 2010 19:12 |
|
ATLbeer posted:Set literals Ooooh! I've been doing lots of work with sets lately. Actually, it says here it was backported from v3, which is weird, because I'm using v3 and it doesn't appear in the documentation.
|
# ? Jul 5, 2010 16:58 |
|
|
# ? May 9, 2024 16:19 |
|
How do I use non scrolling output? For instance, if I want to draw a progress bar in the terminal? Is there something I should be using other than print and sys.stdout.write()?
|
# ? Jul 6, 2010 04:44 |