Re: IDLE in Jython
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 Machine) for the Palm? http://pippy.sourceforge.net/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Dictionary sorting problem
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: How remove directories with the content in the platform independent way?
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
Re: Lexicographical sort for numarray
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: Lexicographical sort for numarray
It does what the OPs example does, but with numeric types. -- http://mail.python.org/mailman/listinfo/python-list
Re: Lexicographical sort for numarray
Ah, okay, I didn't remember correctly what arr.tolist did. My mistake. -- http://mail.python.org/mailman/listinfo/python-list
Re: Shutting down twisted reacotr
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/mailman/listinfo/python-list
Re: Trying to write CGI script with python...
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 what's failing (e.g. wrap the call to mplayer in a try/except use the traceback module to format a traceback if your CGI server is swallowing it). -- http://mail.python.org/mailman/listinfo/python-list
Re: Shutting down twisted reacotr
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: Modify the local scope inside a function
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 unless you are specifically creating a system allows arbitrary code execution. What's wrong with using a dictionary? It's much safer than allowing arbitrary names to be injected into a namespace. -- http://mail.python.org/mailman/listinfo/python-list
Re: Trying to write CGI script with python...
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" unless you intentionally want to clobber the name of the built-in file object. > traceback.print_exc(file=file) > print "" > print cgi.escape(file.getvalue()) > print "" > > > I haven't got access to error logs so I can't look at it that way. > > -- http://mail.python.org/mailman/listinfo/python-list
Re: annonymous functions -- how to
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 anonymous. -- http://mail.python.org/mailman/listinfo/python-list
Re: properties vs. eval()
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: properties vs. eval()
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. The constructs eval/exec/compile all have their purposes (for example: a remote python shell) but they weren't intended to be broken replacements for setattr. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Pseudo-Switch
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", > "D" : lambda x: do_something(x) } > class CaseThing: def pref_A (self, x): return x["bob"] def pref_B (self, x): return x["carol"] def pref_C (self, x); return "Ted" def pref_D (self, x) return do_something(x) def getThing (self, x): attr = getattr(self, 'pref_%s' % (x,)) if attr is not None: return attr else: raise SomeError("Thing %s does not exist" % (x,)) my_thing = CaseThing().getThing(get_value_from_thin_air)(adict) You can do something similar with method decorators for more complex strings than what's allowed for python method names. > my_thing = do_case[get_value_from_thin_air()](adict) > > > How to handle this kind of thing when lambda is removed from the language, > beside the obvious def'ing those tiny little functions? > > James > > -- > James Stroud > UCLA-DOE Institute for Genomics and Proteomics > Box 951570 > Los Angeles, CA 90095 > > http://www.jamesstroud.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Pseudo-Switch
# -*- 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 = sys.exc_info()[2].tb_frame.f_back.f_locals if sw not in defs: defs[sw] = {} table = defs[sw] def _(meth): table[target] = meth return meth return _ class SwitchMixin (object): def __init__ (self): self.__switch_table__ = self.__switch_table__.copy() def switchOn (self, target, *args, **kw): return self.__switch_table__[target](self, *args, **kw) if __name__ == '__main__': class SwitchTest(SwitchMixin): @switchFor("foo") def switch (self, arg): print arg * 3 @switchFor("bar") def switch (self, arg): print "__%s__" % (arg,) @switchFor("baz") def switch (self, arg): print arg + ''.join(reversed(arg)) st = SwitchTest() st.switchOn("foo", "oof") st.switchOn("bar", "rab") st.switchOn("baz", "zab") -- http://mail.python.org/mailman/listinfo/python-list
Re: Safe eval, or how to get list from string
[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 unrepr import unrepr >>> unrepr("[ 'filea', 'fileb', ]") ['filea', 'fileb'] -- http://mail.python.org/mailman/listinfo/python-list