|
Id4ever posted:I think I've seen all of these in the wild. I prefer the first one, but when I see pros like Mark Summerfield use c) I wonder if there's a good reason to avoid a). For example, using a) you would skip that branch for when x was "", [], or 0.
|
# ¿ Nov 8, 2008 01:05 |
|
|
# ¿ May 10, 2024 16:25 |
|
ATLbeer posted:Anyone know a module that does MIME decoding for email?
|
# ¿ Dec 23, 2008 03:29 |
|
UnNethertrash posted:It's hard to explain but with the print commands it's pretty clear, if you run it, that the list 'numbers' gets smaller even though I never remove anything from it. It's got to be some stupid little mistake, but I can't seem to figure it out. code:
|
# ¿ Dec 28, 2008 11:58 |
|
chemosh6969 posted:Looks cool for small stuff. Works surprisingly well for larger stuff too. SQLite owns.
|
# ¿ Jan 2, 2009 22:40 |
|
functional posted:What does a tuple do that a list won't? Is it useful for anything? (You seem to be able to 'tuple pack' just fine with a list. Why would I switch over?) http://jtauber.com/blog/2006/04/15/python_tuples_are_not_just_constant_lists/ Summary: Tuples are more like "records", and lists are "collections"
|
# ¿ Jan 7, 2009 00:28 |
|
tripwire posted:How do you build a list comprehension that would mimic the functionality of going through every gene in the genome and conditionally applying a mutation if random.random() is greater or less than than some threshold value? code:
|
# ¿ Jan 10, 2009 08:49 |
|
Honestly I forgot you could do the if clause there and not just on the for portion of the list comprehension. That should be fine
|
# ¿ Jan 10, 2009 21:16 |
|
tripwire posted:Has anyone used the multiprocessing module before? I'm trying to use a pool to split up the work in my mona lisa triangle mover thing but it doesn't look like you can call it from an instance of a class and point to an instance method (it raises a pickle error, 'can't pickle instancemethod' or something like that. Do I have to make it use a global function? Is there some idiom or pattern for doing this? I haven't, but I know one poster here has it's m0nk3yz, he was like the main guy who edit: fixed No Safe Word fucked around with this message at 10:02 on Jan 13, 2009 |
# ¿ Jan 13, 2009 02:48 |
|
scanlonman posted:Aha! That got it to work. Thank you so much. super(parent_class, self).__init__()
|
# ¿ Jan 15, 2009 03:35 |
|
I'm guessing he has a space before "for" and it's giving an indentation error.
|
# ¿ Feb 24, 2009 23:54 |
|
Phrog posted:So... what am I doing wrong? It's evaluating the first line, which specifically waits for user input. So it then waits until it sees the next newline (normally the user would type in their name and hit enter) and once it does it stores that into name. So I bet if you just typed name you'd see "print 'Hi', name"
|
# ¿ Mar 26, 2009 16:41 |
|
Captain Lou posted:I've been told that it's better not to use methods named __like_these__ unless you really have to -- this adapter class seems kinda hacky, is it not? __getattr__ is a "special method" that is already defined on objects anyway, Benji is just overriding it. __getattr__ just let's an object know what to do when something uses the dot operator on it, basically. foo.bar could be just as easily expressed: foo.__getattr__('bar') edit: actually you should never use __foo__ (both preceding and succeeding underscores) for a method name unless you're overriding an existing, but you should also "pretty much never" use __foo either, and should instead just use _foo No Safe Word fucked around with this message at 16:40 on Apr 8, 2009 |
# ¿ Apr 7, 2009 23:54 |
|
NightGyr posted:I installed python 3.0 on this system for some reason, and its for / range() syntax seems to hate me: It does say line 2 ... I can't see the highlighting but ...
|
# ¿ Apr 10, 2009 05:44 |
|
Sylink posted:So I have an interesting bug. in digg.py, xml.dom will find xml.py in it first and look for a dom module in it, the current directory is searched first in the python path
|
# ¿ Apr 17, 2009 21:12 |
|
mister_gosh posted:I have a loop which adds entries to a dictionary like so: 2) you don't need that inner loop once you have the id, just do: code:
|
# ¿ Apr 17, 2009 21:17 |
|
LE posted:Okay, here is my first stupid newbie python question. Let there be no mistake about it, I am very green with python. Ho ho, I'm going to catch this one first yet again. Don't name your file curses.py When you do import curses it looks in the current directory first for a file named curses.py and in your case it's finding itself (yes, it can do this) and loading that as the curses module. If you rename your file it won't find something named curses.py in the current directory and it will go ahead and look on the PYTHONPATH for a curses.py to import and it should find the appropriate one. edit: put in the quote and sirens to hope LE didn't miss this right below me... No Safe Word fucked around with this message at 02:03 on Apr 28, 2009 |
# ¿ Apr 28, 2009 01:55 |
|
m0nk3yz posted:D'oh. So painfully obvious. Yeah, but obviously not uncommon since the same thing happened a little over a week ago It used to bite me pretty badly when I'd name my C files test.c and just run make test and try and run it. test is a shell builtin that will get precedence and make test compiles test.c into a binary named test
|
# ¿ Apr 28, 2009 15:33 |
|
Honestly the best choice is to have it exported to CSV and then just use Python's built-in csv module, but that may or may not be an option.
|
# ¿ May 4, 2009 16:12 |
|
CrazyPanda posted:can someone recommend me the appropriate module for python to interface with ms access 2007. im very new to programming and databases but i know some sql. i was trying to use MYSQLdb but i dont know how to create the appropriate connection string for a database on my desktop. please let me know if mysqldb is appropriate. You want some sort of ODBC lib, I forget which one is the best but here's a few: http://wiki.python.org/moin/ODBC
|
# ¿ May 5, 2009 18:44 |
|
ATLbeer posted:wow.... i had no idea you could do that... Only with numpy, as far as I can tell.
|
# ¿ May 11, 2009 23:05 |
|
outlier posted:Something so obvious that I'm sure there must be an obvious solution that I'm missing: lexicographic sorting in Python. http://code.activestate.com/recipes/285264/ I don't know of any "standard" solution but that was the first hit for "python natural sort" and it looks okay enough
|
# ¿ May 26, 2009 15:56 |
|
CrazyPanda posted:hi again guys,
|
# ¿ Jun 10, 2009 05:29 |
|
scrabbleship posted:I am trying to write a python program to manage music and I am thinking about creating a "music library" type mini-database inside of the program. Does anybody know of a good python library that handles this kind of thing or a good approach to this? Absolutely
|
# ¿ Jun 16, 2009 22:17 |
|
supster posted:Is there a good way I can see a summary of changes between Python 2.3 and 2.6? I need to evaluate the effort required to make a script targetted to 2.6 work under 2.3. 2.3 -> 2.4 = http://docs.python.org/whatsnew/2.4.html 2.4 -> 2.5 = http://docs.python.org/whatsnew/2.5.html 2.5 -> 2.6 = http://docs.python.org/whatsnew/2.6.html
|
# ¿ Jul 1, 2009 22:10 |
|
I've found pdb's postmortem pm() to be pretty handy as well, and you don't even have to instrument your code ahead of time necessarily.
|
# ¿ Sep 8, 2009 06:29 |
|
Avenging Dentist posted:Yeah, cuz it's not like the Python standard libraries have completely schizophrenic naming conventions. Oh hello there
|
# ¿ Sep 15, 2009 02:11 |
|
Avenging Dentist posted:This is the problem: Eugh, green.
|
# ¿ Sep 15, 2009 04:09 |
|
Thermopyle posted:Ok, completely different question... code:
|
# ¿ Sep 24, 2009 22:59 |
|
Baruch Obamawitz posted:oh what the christ is this foo is a queryset, it just pretty-prints like a list just check foo.count() I think
|
# ¿ Oct 13, 2009 06:58 |
|
deimos posted:Django protip: This, fixtures rock.
|
# ¿ Oct 20, 2009 20:41 |
|
Kire posted:I come back to Python frequently after a short hiatus, only to find I've forgotten everything. Here's a quick newb question: I want to print a sentence that lists objects in a list, without doing "There is a ['first item', 'second item'] and a third item." How can I make it get rid of the [ and ' for the first items? Two things, you don't need to put the len call in there, [:-1] and [-1] do the same thing to what you want. But the reason it's printing out like that is because you're passing it a list to interpolate and lists that are made into strings look like ['foo', 'bar']. What you want is something more like: code:
Or if you want to steal a utility we wrote for supybot, we wrote the most terribly named function ever, commaAndify: code:
code:
|
# ¿ Oct 21, 2009 23:16 |
|
echinopsis posted:I'm having trouble with the immutable strings.. I'm writing something small and gimmicky, and it relies on changing individual characters in a string.. (many many times over) code:
|
# ¿ Dec 10, 2009 22:13 |
|
GregNorc posted:Ah I see. Because that's where it thought the parentheses were closed for that one and so it really thought that Card(3,3 was unclosed within the other parentheses.
|
# ¿ Jan 2, 2010 21:19 |
|
haywire posted:also, if I create a dictionary like Dictionaries have no inherent order. There are ordered dictionary implementations if you want, and Python 3.1 actually has such a type in it natively.
|
# ¿ Feb 16, 2010 22:11 |
|
nbv4 posted:
Allow me to blow your mind with: code:
|
# ¿ Feb 17, 2010 09:30 |
|
ATLbeer posted:Django book ( http://www.djangobook.com/ ) is a GREAT resource. It still can be but even the "new" version there is kinda old. The regular doc site is pretty amazing in and of itself: http://docs.djangoproject.com/
|
# ¿ Feb 17, 2010 20:40 |
|
And just so Stabby and anyone else curious knows, the common python idiom for ditching an unused variable that's being unpacked is:code:
|
# ¿ Feb 22, 2010 20:11 |
|
MaberMK posted:
Or just list[x:y] = [value] * (y-x)
|
# ¿ Mar 3, 2010 20:58 |
|
Bottle sorta does but yeah why python 3.x?
|
# ¿ Mar 7, 2010 09:20 |
|
|
# ¿ May 10, 2024 16:25 |
|
Mr. Clark2 posted:stuff code:
|
# ¿ May 18, 2010 20:26 |