Re: Modify the local scope inside a function

2006-02-25 Thread Jason Mobarak
Sandra-24 wrote: > Is there a way in python to add the items of a dictionary to the local > function scope? i.e. var_foo = dict['var_foo']. I don't know how many > items are in this dictionary, or what they are until runtime. Why do you want to do this? Exec and eval should -not- be used for this

Re: Dictionary sorting problem

2005-09-16 Thread Jason Mobarak
You can't sort dictionaries (as implemented by hash tables), they are unordered data types, so by definition there's no way to force an order on them. http://en.wikipedia.org/wiki/Hash_tables -- http://mail.python.org/mailman/listinfo/python-list

Re: IDLE in Jython

2005-07-15 Thread Jason Mobarak
Casey Hawthorne wrote: > How about the following: > > - making Jython mostly work up to Python 2.4? http://www.python.org/psf/grants (see the first grant) There's already a grant in place for this. So hopefully someone associated with Jython is working on it. > - making a PVM (Python Virtual

Re: Safe eval, or how to get list from string

2005-05-13 Thread Jason Mobarak
[EMAIL PROTECTED] wrote: > if there is list1 = "[ 'filea', 'fileb', ]", I can get at list by > doing: > reallist = eval(list1) > is there an easier/simpler method of doing the same thing as realstring > and reallist lines above? http://twistedmatrix.com/users/moshez/unrepr.py Example: >>> from u

Re: Python Pseudo-Switch

2005-05-09 Thread Jason Mobarak
# -*- python -*- import sys def switchFor (target): sw = '__switch_table__' # please pretend the frame hack is not here, # it happens to work for classes and messing with # frame stack in a try/except is probably okay try: raise Exception() except: defs =

Re: Python Pseudo-Switch

2005-05-07 Thread Jason Mobarak
James Stroud wrote: > Hello All, > > Because of my poorly designing a database, I have recently found it necessary > to explore the wonders of the Python pseudo-switch: > > do_case = { "A" : lambda x: x["bob"], > "B" : lambda x: x["carol"], > "C" : lambda x: "Ted", >

Re: properties vs. eval()

2005-05-07 Thread Jason Mobarak
Bob Rogers wrote: > So you're saying you don't know the answer? The question wasn't > "should I use setattr?" If what you're doing is wrong and backwards then it doesn't matter what the question is. Best practices are best practices for a reason. There's no reason to use eval to do what you want

Re: properties vs. eval()

2005-05-05 Thread Jason Mobarak
Why are you using eval in the first place? This isn't bash. Use setattr and getattr for dynamic attribute access. -- http://mail.python.org/mailman/listinfo/python-list

Re: annonymous functions -- how to

2005-05-04 Thread Jason Mobarak
What's wrong with: def blah(): def _ (a, b, c): a = a + 2 print "stmt 2" return a+b/c return doSomethingWith(_) It's basically "anonymous", it just uses a name that you don't care about. AFAIK, it can be immediately clobbered later if need be. Otherwise, the function shouldn't be

Re: Trying to write CGI script with python...

2005-04-30 Thread Jason Mobarak
M.E.Farmer wrote: > I found an excellent example that was posted by the F-bot. [...] > try: > import myscript > myscript.main() > except: > print "Content-Type:", "text/html" > print > file = StringIO.StringIO() Note: it's usually a very bad idea to name -anything- "file" unles

Re: Shutting down twisted reacotr

2005-04-28 Thread Jason Mobarak
You might not need threads to get user input from the console. Jp posted this in response to a similar query on the twisted-python mailing list: http://article.gmane.org/gmane.comp.python.twisted/9019 -- http://mail.python.org/mailman/listinfo/python-list

Re: Trying to write CGI script with python...

2005-04-28 Thread Jason Mobarak
Probably going to need more information about how mplayer is not being accessed correctly. CGI uses the shell environment to pass web information to a program... so maybe this is messing up mplayer. You'll need to augment or wrap your partners program in order to give you more information about wh

Re: Shutting down twisted reacotr

2005-04-27 Thread Jason Mobarak
Why do you want to do this in a thread? What's wrong with reactor.callLater? import time from twisted.internet import reactor def shutdown(): time.sleep(3) print "stopping" reactor.callFromThread(reactor.stop) reactor.callInThread(shutdown) reactor.run() -- http://mail.python.org/

Re: Lexicographical sort for numarray

2005-04-27 Thread Jason Mobarak
Ah, okay, I didn't remember correctly what arr.tolist did. My mistake. -- http://mail.python.org/mailman/listinfo/python-list

Re: Lexicographical sort for numarray

2005-04-27 Thread Jason Mobarak
It does what the OPs example does, but with numeric types. -- http://mail.python.org/mailman/listinfo/python-list

Re: Lexicographical sort for numarray

2005-04-27 Thread Jason Mobarak
import numarray as na import random # example array arr = range(100) random.shuffle(arr) arr = na.array(arr) arr = na.reshape(arr, (10,10)) print arr # not rowsort'ed arr.flat.sort() # key line print arr # rowsort'ed -- http://mail.python.org/mailman/listinfo/python-list

Re: How remove directories with the content in the platform independent way?

2005-04-26 Thread Jason Mobarak
There's also the shutil module, which is platform independant. http://docs.python.org/lib/module-shutil.html ...see the rmtree function -- http://mail.python.org/mailman/listinfo/python-list