Re: Default attribute values pattern

2008-01-19 Thread David Tweet
Ah! nice, thanks, knew I was probably missing something. On Jan 19, 2008 5:01 PM, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > On Jan 19, 11:02pm, "David Tweet" <[EMAIL PROTECTED]> wrote: > > > def Grab(argdict, key, default): > > """Li

Re: Default attribute values pattern

2008-01-19 Thread David Tweet
Hello, Seems to me that setattrs sort of assumes that you want to have all your initialization arguments set as attributes of the same name. I would think you'd sometimes want to be able to process the extra arguments inside of each __init__, assign them to attributes with different names, etc.

Re: making all letters Caps/Small Letters

2007-12-14 Thread David Tweet
>>> "THIS IS A STRING".lower() 'this is a string' >>> "THIS IS A STRING".title() 'This Is A String' >>> "this is a string".upper() 'THIS IS A STRING' You can browse all the string methods by doing >>> dir(str) On Dec 14, 2007 1:30 AM, Merrigan <[EMAIL PROTECTED]> wrote: > Hi There, > > I'm sure I

Re: Better way to searching.

2007-12-14 Thread David Tweet
Hello, You might try using os.path.walk, I think it ends up being much more flexible than glob for this. #!/usr/bin/python2.4 import os def Finder(topdir, file_extension=None, levels=None): """Return all filenames in topdir. Args: topdir: Top level directory to search file_extensi

Re: how to pass parameter to a python script when running it in the interactive shell?

2007-12-05 Thread David Tweet
This should work: python -i myscript.py --cl --cs 5 --ce 6 --bw 7 --set 1 On Dec 5, 2007 6:31 PM, wang frank <[EMAIL PROTECTED]> wrote: > > > Hi, > > I am debugging a python script which takes a set of paramters. In the > regular shell, I type: > > myscript.py --cl --cs 5 --ce 6 --bw 7 --se

Re: [OT] minimalist web server

2007-12-01 Thread David Tweet
Running this in Python should create a server running on localhost port 80 that only serves blank pages: import SimpleHTTPServer import SocketServer class MyHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): def do_GET(self): print >> self.wfile, "" server = SocketServer.TCPServer(("", 80

Re: Pickling dictionaries containing dictionaries: failing, recursion-style!

2007-12-01 Thread David Tweet
Are you opening the file in binary mode ("rb") before doing pickle.load on it? On 01 Dec 2007 14:13:33 -0800, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > lysdexia <[EMAIL PROTECTED]> writes: > > self.wordDB[word] = [self.words.count(word), wordsWeights] > > what is self.words.coun

Re: os.access() under windows

2007-12-01 Thread David Tweet
To answer indirectly, usually the EAFP (easier to ask forgiveness than permission) approach works better for this kind of thing. try: f = open('e:\\test\\test', 'a') f.write('abc') f.close() except IOError: print "couldn't write test file, continuing..." On Dec 1, 2007 1:48 AM, Yann Lebou

Re: importing a user file in Python

2007-11-30 Thread David Tweet
You have options: 1) Have the file in your current working directory, in which case it's just "import odbchelper". 2) Change your PYTHONPATH in your shell, adding a line like this to your bashrc perhaps: export PYTHONPATH=$PYTHONPATH:/home/jw/diveintopython-5.4/py ... and do the same

Re: Crackly sound in pygame

2007-11-30 Thread David Tweet
Before calling pygame.init(), you can call pygame.mixer.pre_init. Make sure the sample rate and sample size matches your audio file. But most likely the issue is that the default audio buffer size of 1024 doesn't cut it for some sound cards; try increasing to the next power of two. Ex. pygame.mi