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
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
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
[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
# -*- 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 =
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",
>
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
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
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
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
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
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
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/
Ah, okay, I didn't remember correctly what arr.tolist did. My mistake.
--
http://mail.python.org/mailman/listinfo/python-list
It does what the OPs example does, but with numeric types.
--
http://mail.python.org/mailman/listinfo/python-list
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
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
17 matches
Mail list logo