|
JoeNotCharles posted:Fixed your variable name for you. Argh, don't do this either :p (I'm sounding like the crotchety old man in this thread). If you want to use a single-letter variable name for a list, use L instead of l. l is a bad variable name in any language because it looks too much like 1 in fixed-width fonts.
|
# ? Apr 3, 2008 15:49 |
|
|
# ? May 11, 2024 14:14 |
|
lst
|
# ? Apr 3, 2008 16:39 |
|
No Safe Word posted:Argh, don't do this either :p (I'm sounding like the crotchety old man in this thread). If you want to use a single-letter variable name for a list, use L instead of l. l is a bad variable name in any language because it looks too much like 1 in fixed-width fonts. Not if you're using a good coding font. Fonts should not affect how you code.
|
# ? Apr 3, 2008 18:35 |
|
deimos posted:Not if you're using a good coding font. Fonts should not affect how you code. Except for the myriad of places that code is seen outside of your preferred editor, such as on pastebin websites. It's silly to do things (or rather, to not do them) which require a particular editor/font choice/keyboard layout/etc, when it's just as easy to do the right thing which won't break everywhere else.
|
# ? Apr 3, 2008 20:57 |
|
deimos posted:Not if you're using a good coding font. Fonts should not affect how you code. PEP 8 posted:Prescriptive: Naming Conventions
|
# ? Apr 4, 2008 03:38 |
|
I think the only time I had an issue with 'l' was when I committed some code to a project with a fairly strict(for a python project) coding style and I broke some naming conventions by naming a method(that required a L/l as its first letter) with a uppercase L to avoid misreading. Someone submitted a 'fix' later that day.
|
# ? Apr 4, 2008 11:01 |
|
Is the smtplib module not thread-safe or something? I have a little monitor script set up to monitor some SQL servers and send out an e-mail if there's a long-running query that's taking up too much time on the server. Everything works fine, but when I added smtplib into the mix, everything went all wrong. As soon as the monitor thread sends an e-mail, the script just seems to stop execution shortly after the server.quit(). It sends that e-mail fine (with some formatting issues, but I'll fix that poo poo later) and I see all the debug output on the terminal from set_debuglevel(), and I see it print "E-mail successful" as well (because I added that after the server.quit() to see if it was hanging on waiting for the connection to time out or something), but it never exits the enclosing elif. It's not using any CPU time or anything... it just doesn't do anything. Here's the relevant code:code:
|
# ? Apr 9, 2008 16:27 |
|
Chutwig Regarding smtplib - did you look at this thread on c.l.p? http://groups.google.com/group/comp...a1de3ed29133546
|
# ? Apr 9, 2008 20:49 |
|
m0nk3yz posted:Chutwig Regarding smtplib - did you look at this thread on c.l.p? After I posted, I went back and googled some more and found that discussion. I'll probably just write another script external to this one to handle e-mailing and invoke it through subprocess, or just invoke sendmail directly, or something.
|
# ? Apr 9, 2008 21:09 |
|
How do I make python print out where it's getting its lib path from? Somehow both 2.5.1 and 2.5.2 got installed on my Macbook Pro and 2.5.2 is pointing to a different lib path from 2.5.1 and I want to know where it's pointing at and how to change it. I tried googling but maybe I didn't look up the right thing? ("python change lib path") edit: ahh, the PYTHONPATH environment variable ashgromnies fucked around with this message at 21:24 on Apr 9, 2008 |
# ? Apr 9, 2008 21:19 |
|
Anyone used any of the numerous python text parsing libraries out there? I'm playing around with pyparsing and having a bit of a time with it and was wondering: a) are there better options, or b) does anyone know pyparsing well enough that I should post questions here? I don't have anything specific yet, but it might be nice to know who has used what.
|
# ? Apr 9, 2008 22:12 |
|
No Safe Word posted:Anyone used any of the numerous python text parsing libraries out there? I'm playing around with pyparsing and having a bit of a time with it and was wondering: a) are there better options, or b) does anyone know pyparsing well enough that I should post questions here? I don't have anything specific yet, but it might be nice to know who has used what. I like pyparsing the best out of all of the python text parsers I've seen. I'm definitely not the best, but I can try to help you with problems. I've been working with for a little over a year. It's pretty slow, though, so you shouldn't use it if speed is a concern. I use it for lexing wiki pages, and it's fast enough to work with caching, but it definitely wouldn't work if the page was lexed every time it was loaded. Habnabit fucked around with this message at 04:43 on Apr 10, 2008 |
# ? Apr 10, 2008 04:40 |
|
Just found this article, well worth the stupid free registration, it's an awesome decorator explanation: http://www.linux-mag.com/id/5377
deimos fucked around with this message at 07:08 on Apr 10, 2008 |
# ? Apr 10, 2008 07:04 |
|
Habnabit posted:I like pyparsing the best out of all of the python text parsers I've seen. I'm definitely not the best, but I can try to help you with problems. I've been working with for a little over a year. It's pretty slow, though, so you shouldn't use it if speed is a concern. I use it for lexing wiki pages, and it's fast enough to work with caching, but it definitely wouldn't work if the page was lexed every time it was loaded. Okay, well I guess this qualifies as a short question and the thread isn't exactly busting with other questions so here goes. I'm trying to write a stat file parser for TF2 (I guess I'm a statwhore ), but it uses some funky JSON-like syntax that should be easy to write a parser for using pyparsing but I'm having a bitch of a time understanding why some of it doesn't work. Here's a cut-down sample file: code:
So, the pseudo-BNF I worked up looks like: code:
code:
pyparsing.ParseException: Expected "}" (at char 132), (line:5, col:5), which refers to the line that starts with "aClassStats". It's like the failure is in the OR'ing of the statItem and statList, though I'm going to try parsing each individual line with all the objects and see if it matches where I expect. But if anything is glaringly wrong let me know.
|
# ? Apr 10, 2008 17:44 |
|
does python not have a do ... while looping structure? If not, is there a way I can emulate it without having to write my code blocks twice?
|
# ? Apr 10, 2008 19:49 |
|
Mighty Germ posted:does python not have a do ... while looping structure? It doesn't have one as far as I'm aware, but PEP 315 proposes one. I guess the equivalent would be: code:
Git fucked around with this message at 20:11 on Apr 10, 2008 |
# ? Apr 10, 2008 20:07 |
|
I have a list that I want to sort. The list would look something likee this: [python] [['/mnt/Local/laura', 'IMG_0001.JPG', 1207277478.0], ['/mnt/Local/laura', 'IMG_0002.JPG', 1207277490.0], ['/mnt/Local/laura', 'IMG_0006.JPG', 1207277830.0], ['/mnt/Local/laura', 'IMG_0005.JPG', 1207277795.0], ['/mnt/Local/laura', 'IMG_0004.JPG', 1207277782.0]] [/python] I want the list sorted by the third value in each item. I know I can do list.sort() with a flat list, but these are lists within lists, and I have no clue how to proceed. Maybe this is just highlighting my lack of skill with python, but I find the documentation much harder to understand than, for example, php.
|
# ? Apr 10, 2008 20:27 |
|
Kaluza-Klein posted:I have a list that I want to sort. The list would look something likee this: code:
Another better example (since sorting these normally produces the same results): code:
|
# ? Apr 10, 2008 20:43 |
|
Kaluza-Klein posted:I want the list sorted by the third value in each item. There may be a better way to do this, but you can do it using your own sort function. code:
e: damnit.
|
# ? Apr 10, 2008 20:53 |
|
No Safe Word posted:
Woah, thank you! I never would have figured that out myself.
|
# ? Apr 10, 2008 21:06 |
|
Writing your own cmp function is depreciated and just plain icky, really. Use a key function, which is much, much cleaner. A key function is passed one parameter multiple times: once for each item in the list to be sorted. The list is then sorted by the returned values.code:
operator.itemgetter(2)(list) -> list[2] (Working on the pyparsing code, will be up in a minute.) Habnabit fucked around with this message at 09:03 on Apr 11, 2008 |
# ? Apr 11, 2008 08:59 |
|
Mighty Germ posted:does python not have a do ... while looping structure? code:
code:
|
# ? Apr 11, 2008 09:58 |
|
Can anyone who has worked with stackless / threads in general for Python give an evaluation of it? From reading its documentation it seems that they are very small in size and fast yet I rarely hear about anyone using them for projects (sans EVE online).
|
# ? Apr 11, 2008 14:18 |
|
I just found out about dabo it's like django for client applications. It wraps wxPython, making it a bit more pythonic and overall nicer to work with. I haven't done an application in it but I think I have something I want to throw at it.
|
# ? Apr 11, 2008 14:45 |
|
I remember coming across a 'website game' (where each page is a riddle leading you to the next page) but all the problems were problems to solve in Python. Anyone know the link?
|
# ? Apr 11, 2008 16:13 |
|
Juomes posted:I remember coming across a 'website game' (where each page is a riddle leading you to the next page) but all the problems were problems to solve in Python. http://www.pythonchallenge.com/
|
# ? Apr 11, 2008 16:48 |
|
deimos posted:http://www.pythonchallenge.com/ Thanks. I knew it was going to be something obvious. Also I'm thankful I remembered about the site because I was out of ideas to practice my newly learned Python knowledge.
|
# ? Apr 12, 2008 14:30 |
|
I'm newish to python, and I've been using TextMate (on OSX) to do most of my editing. However, I'm getting frequent indent errors from code that looks, to my eye, fine. Mostly from code copy/pasted from somewhere. Often I have to delete and whitespace and reinsert the indentation to fix it. Any idea what I'm doing wrong?
|
# ? Apr 13, 2008 21:20 |
|
the talent deficit posted:Any idea what I'm doing wrong? Tell TextMate to use soft tabs, and set the option to re-indent pasted text in its preferences. e: Actually, you probably don't need to use soft tabs, if hard tabs are your thing. Git fucked around with this message at 21:28 on Apr 13, 2008 |
# ? Apr 13, 2008 21:26 |
|
Like Git said its probably a bad mix of spaces*4 and tabs. I know many editors support an optional convert tabs to spaces function(either realtime or upon save) so you might want to check that out in textmate.
|
# ? Apr 13, 2008 21:47 |
|
Looks like Sun's App Engine/AWS-alike will handle python as well: http://research.sun.com/spotlight/2008/2008-04-09_caroline.html (see the graphic)
|
# ? Apr 14, 2008 21:36 |
|
Figured I'd ask - any Boston/Boston Metro area Python people (or people getting into Python) looking around for a Job()?
|
# ? Apr 16, 2008 02:29 |
|
m0nk3yz posted:Figured I'd ask - any Boston/Boston Metro area Python people (or people getting into Python) looking around for a Job()? I will move to Boston for a good python job.
|
# ? Apr 16, 2008 02:47 |
|
Hey, I'm a programmer who's looking to pick up Python. I'm an expert at matlab, and proficient in C, C++, and VB. I'm mainly intersted in Python because I'm tired of how crappy Matlab's oo stuff is. I was thinking of learning python by playing around with Orange and NumPy. Are these good starting points for me (given that I don't care about the web stuff) or should I go for something else like PyGame?
|
# ? Apr 16, 2008 03:07 |
|
I'm making a program for a class where I was told to use the built-in priority queue. However, I was supposed to override the built-in __cmp__ method because because what we are passing into the queue is an array, which python can't compare. The example I was given was:code:
|
# ? Apr 16, 2008 07:11 |
|
Bozart posted:Hey, I'm a programmer who's looking to pick up Python. I'm an expert at matlab, and proficient in C, C++, and VB. I'm mainly intersted in Python because I'm tired of how crappy Matlab's oo stuff is. I was in a similar situation as you (used matlab/shell scripting at work), and just started recently learning Python. I picked up the Programming Python book, along with using the online official Python tutorial and the api for the packages I intended to use. I started converting my old scripts and programs over to Python and got a good grasp of the language.
|
# ? Apr 16, 2008 11:15 |
|
hairacles posted:I'm making a program for a class where I was told to use the built-in priority queue. However, I was supposed to override the built-in __cmp__ method because because what we are passing into the queue is an array, which python can't compare. The example I was given was: I don't think I understand your question, can you provide an example input/output of the data you intend you use?
|
# ? Apr 16, 2008 11:18 |
|
Yeah, no problem. The program is for an AI class, and we're doing an intelligent search to quickly find a solution to an 8-puzzle. http://en.wikipedia.org/wiki/8-puzzleSpecifically, A* search. An example of whats being passed in is [2876549, 8], where the first number represents the puzzle being looked at, and the second number is how close the current state is to the solution. So I would be doing heappush(queue, array). So we are supposed to override the __cmp__ so it examines the second item in the array, since the built in heap functions aren't able to recognize what to do when given an array and not a number. The professor never really explained much about how we were supposed to do this, so I might be missing something obvious. What I have so far-code:
|
# ? Apr 16, 2008 16:48 |
|
Well, you've got two problems here. The first is how to override __cmp__ for an array, and the other is what goes in the __cmp__ routine. The problem is, you can't really override __cmp__ on the "list" class (Python has no separate arrays, you're really using lists) because it's a builtin class and you can't change it. You'll have to make your own class and convert to and from it before you put it on the heap. code:
Most functions that use compare objects using __cmp__ will take an optional parameter so you can pass a standalone function instead (so you could say def compareStates(a, b): ... heappush(pq, [state, distance to coal], comparseStates)), but heappush doesn't seem to have that, which is an annoying oversight. Now that you know where to put the __cmp__ function, it should be easy to change the one you were given for HeapItems to use [1] instead of .rank. ...however, this seems pretty roundabout. Are you sure you weren't supposed to just change astar() to use HeapItems instead of an array?
|
# ? Apr 16, 2008 17:03 |
|
|
# ? May 11, 2024 14:14 |
|
Mighty Germ posted:I was in a similar situation as you (used matlab/shell scripting at work), and just started recently learning Python. I picked up the Programming Python book, along with using the online official Python tutorial and the api for the packages I intended to use. I started converting my old scripts and programs over to Python and got a good grasp of the language. Alright then, cool. I got Learning Python and read the Tutorial, so I think I am good to go. The only annoying thing is that the help for built in classes and methods sucks hard after Matlab's great help system. I'll have to spend time bumming around on the python wiki to see if they have better documentation there. Is the Programming Python book significantly better or more in depth than Learning Python? I figure it has a different focus because it has a different animal on the cover!
|
# ? Apr 16, 2008 18:14 |