weird dict problem, how can this even happen?

2008-12-15 Thread Joel Hedlund
I'm having a very hard time explaining why this snippet *sometimes* raises KeyError: snippet: print type(self.pool) for frag in self.pool.keys(): if frag is fragment_info: print "the fragment_info *is* in the pool", hash(frag), hash(fragment_info), hash(frag) == hash(fragment_info)

Insatlling python on compute-node-linux (Cray).

2008-12-15 Thread Rahul
Has anyone tried installing Python on Compute Node Linux (on a cray)? I was having trouble getting it running. I see that CNL does not support dynamic libraries but I am not sure what the best way then is to get Python running. Any tips? -- Rahul -- http://mail.python.org/mailman/listinfo/pyt

Re: Removing None objects from a sequence

2008-12-15 Thread J. Cliff Dyer
On Mon, 2008-12-15 at 02:11 +, Lie Ryan wrote: > On Fri, 12 Dec 2008 22:55:20 +, Steven D'Aprano wrote: > > > On Fri, 12 Dec 2008 21:18:36 +, Lie Ryan wrote: > >> Personally, I'd prefer VB's version: > >> foo IsNot bar > >> > >> or in pseudo-python > >> foo isnot bar > >> > >> since

Re: weird dict problem, how can this even happen?

2008-12-15 Thread Duncan Booth
Joel Hedlund wrote: > I would very much like an explanation to this that does not involve > threads, because I haven't made any that I'm aware of. I can't even > understand how this could happen. How do I even debug this? > It could happen quite easily if the hash value of the object has chang

Re: %s place holder does not let me insert ' in an sql query with python.

2008-12-15 Thread Bruno Desthuilliers
Joe Strout a écrit : On Dec 15, 2008, at 6:46 AM, Krishnakant wrote: in this case, I get a problem when there is ' in any of the values during insert or update. That's because ' is the SQL string literal delimiter. But any SQL-compliant database allows you to "escape" an apostrophe within a

Re: tricky nested list unpacking problem

2008-12-15 Thread Scott David Daniels
Kirk Strauser wrote: At 2008-12-15T19:06:16Z, Reckoner writes: The problem is that I don't know ahead of time how many lists there are or how deep they go. In other words, you could have: Recursion is your friend. Write a function to unpack one "sublist" and call itself again with the new l

OpenOpt 0.21 (free optimization framework)

2008-12-15 Thread dmitrey
Hi all, OpenOpt 0.21, free optimization framework (license: BSD) with some own solvers and connections to tens of 3rd party ones, has been released. All details here: http://openopt.blogspot.com/2008/12/openopt-release-021.html Regards, OpenOpt developers. -- http://mail.python.org/mailman/listi

Re: Need help improving number guessing game

2008-12-15 Thread feba
Spent a bit more time looking over suggestions and working out some annoyances. import random def customrange(game, lowunsafe=True): game['defrang'] = False #Keeps setup from changing range to defaults while lowunsafe: #makes sure that the low number is positive picklow = int(inp

Re: alt.possessive.its.has.no.apostrophe

2008-12-15 Thread Lie Ryan
On Mon, 15 Dec 2008 11:53:40 -0800, Carl Banks wrote: > > (...For that matter, if the rule had been, "Never augment your words > spelling with an apostrophe", it would have really simplified > things) Th next dae, wee aul wil bee speling liek this -- http://mail.python.org/mailman/listinfo/

Re: Need help improving number guessing game

2008-12-15 Thread Bruno Desthuilliers
feba a écrit : Alright! This is feeling more like it. #!/usr/bin/python #Py3k, UTF-8 import random (snip) def youwin(game): if game['pnum'] == 1: print("CONGRATULATIONS! IT TOOK YOU %s GUESSES" % game ['gcount']) else: if game['player'] == game['player1']:

Re: Problem Python 2.6.1 vs 2.6 & pyWin32

2008-12-15 Thread Pekka Klärck
2008/12/15 "Martin v. Löwis" : >> I am very disappointed. Help me, please. > > Try installing Python 2.6.1 "for all users". Could you clarify why that's needed? Link to a relevant bug report or something similar is enough. We've got some weird problems installing Python packages (win32.exe) on Wi

Re: Problem Python 2.6.1 vs 2.6 & pyWin32

2008-12-15 Thread Martin v. Löwis
>> Try installing Python 2.6.1 "for all users". > > Could you clarify why that's needed? I didn't say it's needed. I said that he should try that, perhaps it helps. > One thing we noticed (I'm not sure has this been yet submitted to > bugs.python.org yet) was that installing packages created wit

Re: tricky nested list unpacking problem

2008-12-15 Thread bearophileHUGS
Arnaud Delobelle: > Here is a not thought out solution: >... I was waiting to answer because so far I have found a bad-looking solution only. Seeing there's only your solution, I show mine too. It seems similar to your one. def xflatten(seq): if isinstance(seq, list): stack = [iter(se

Re: Problem Python 2.6.1 vs 2.6 & pyWin32

2008-12-15 Thread Michel Claveau - NoSpam SVP ; merci
Hi! Thank you very much for your answer. I appreciate many to receive an answer of somebody as you. But I, always, install Python 2.6.1 "for all users" (and, on Vista, UAC is always deactivated). After some tests, the problem seems a bit more complex: call the Python-COM-servers run OK, fr

parse C expression?

2008-12-15 Thread Torsten Mohr
Hi, i found some examples when googling for the subject but nothing really matched. Is there a standard module available that lets me parse a syntax like "C" with numbers, operators, braces, variables and function calls? I'd like to use this to parse an own kind of configuration language and pre

Re: Problem Python 2.6.1 vs 2.6 & pyWin32

2008-12-15 Thread Michel Claveau - NoSpam SVP ; merci
Hi! I noted, also, than, in some cases, Python26.dll is not copied in %WINDIR%\system32 After that, external softs don't find the DLL. But it's a detail, because it's easy to copy the DLL with install scripts. @-salutations -- Michel Claveau -- http://mail.python.org/mailman/listinfo/pytho

Re: parse C expression?

2008-12-15 Thread James Mills
On Tue, Dec 16, 2008 at 9:48 AM, Torsten Mohr wrote: > Hi, > > i found some examples when googling for the subject but nothing really > matched. > > Is there a standard module available that lets me parse a syntax like "C" > with numbers, operators, braces, variables and function calls? Try pypar

Re: Bidrectional Subprocess Communication

2008-12-15 Thread Gabriel Genellina
En Sun, 14 Dec 2008 06:03:26 -0200, greg escribió: Gabriel Genellina wrote: (Pipes don't work the same as sockets, although unix-like systems try hard to hide the differences...) BSD-based unixes implement pipes using socketpair(), so pipes actually *are* sockets (or at least they used to

Re: Problem Python 2.6.1 vs 2.6 & pyWin32

2008-12-15 Thread Martin v. Löwis
> I noted, also, than, in some cases, Python26.dll is not copied in > %WINDIR%\system32 > After that, external softs don't find the DLL. Right. Only in "for all users" installations, python26.dll is put into system32. In a "just for me" installation, the user is not expected to have permissions to

Re: OpenOpt 0.21 (free optimization framework)

2008-12-15 Thread Neal Becker
Is it easy_install able? I got: sudo easy_install -U openopt Searching for openopt Reading http://pypi.python.org/simple/openopt/ Couldn't find index page for 'openopt' (maybe misspelled?) Scanning index of all packages (this may take a while) Reading http://pypi.python.org/simple/ Reading http:/

Re: Need help improving number guessing game

2008-12-15 Thread feba
> .strip() returns a copy of the string without leading and ending whitespaces (inlcuding newlines, tabs etc). Ahh. I had removed it because it didn't seem to do anything, but I've readded it. And I understand your dictionary stuff correctly now, I think, and I worked it in. Currently, I have:

Re: Insatlling python on compute-node-linux (Cray).

2008-12-15 Thread skip
Rahul> Has anyone tried installing Python on Compute Node Linux (on a Rahul> cray)? I was having trouble getting it running. I see that CNL Rahul> does not support dynamic libraries but I am not sure what the Rahul> best way then is to get Python running. In the Modules directory

Re: Structure using whitespace vs logical whitespace

2008-12-15 Thread Дамјан Георгиевски
> In most languages, I'll do something like this > > xmlWriter.BeginElement("parent"); > xmlWriter.BeginElement("child"); > --xml.Writer.Characters("subtext"); > xmlWriter.EndElement(); > xmlWriter.EndElement(); > > Where the dashes are indentation (since some newsgroup handlers d

Re: Removing None objects from a sequence

2008-12-15 Thread bearophileHUGS
Scott David Daniels: > If you want to keep the original's method, but do it in a more Pythonic > way, I would suggest: > >      def deNone4(alist): >          j = 0 >          for val in alist: >              if val is not None: >                  alist[j] = val >                  j += 1 >        

Re: tricky nested list unpacking problem

2008-12-15 Thread Chris Rebert
On Mon, Dec 15, 2008 at 12:24 PM, Kirk Strauser wrote: > At 2008-12-15T20:03:14Z, "Chris Rebert" writes: > >> You just need a recursive list-flattening function. There are many >> recipes for these. Here's mine: > > flattened = flatten([1,2,3,[5,6,[10, 11]],7,[9,[1, 2, 3, 4, 5 ]]]) > flat

Re: parse C expression?

2008-12-15 Thread Chris Rebert
On Mon, Dec 15, 2008 at 3:48 PM, Torsten Mohr wrote: > Hi, > > i found some examples when googling for the subject but nothing really > matched. > > Is there a standard module available that lets me parse a syntax like "C" > with numbers, operators, braces, variables and function calls? > > I'd li

Re: parse C expression?

2008-12-15 Thread Miki
> Is there a standard module available that lets me parse a syntax like "C" > with numbers, operators, braces, variables and function calls? There is a C compiler implemented with PLY somewhere. > I'd like to use this to parse an own kind of configuration language > and preferred would be just sta

Re: How can I return a non-zero status result from a python script?

2008-12-15 Thread Miki
Hello, > How can I return a non-zero status result from the script? Just do a > return 1? at the end? raise SystemExit(1) HTH, -- Miki http://pythonwise.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

ethical questions about global variables

2008-12-15 Thread Giampaolo Rodola'
Hi, in a module of mine (ftpserver.py) I'd want to add a (boolean) global variable named "use_gmt_times" to decide whether the server has to return times in GMT or localtime but I'm not sure if it is a good idea because of the "ethical" doubts I'm gonna write below. In first place I've never liked

socket and subprocess problem

2008-12-15 Thread goatold
Hi all, Here is my problem, see if any one else met this before In my python code I use subprocess.Popen to run and external program who will listen to a TCP port. And I also create a socket to connect to the TCP port that the external program is listening. I will get 'Connection refused, errno=11

Copying files in directory

2008-12-15 Thread pacsciadmin
I'm writing a project management system, and I need the ability to accept a directory name and move its contents to another directory. Can someone give me a code sample that will handle this? I can't find any "copying" functions in os or os.path. Regards, LeafStorm -- http://mail.python.org/mailma

Re: ethical questions about global variables

2008-12-15 Thread James Mills
On Tue, Dec 16, 2008 at 12:45 PM, Giampaolo Rodola' wrote: > Hi, > in a module of mine (ftpserver.py) I'd want to add a (boolean) global > variable named "use_gmt_times" to decide whether the server has to > return times in GMT or localtime but I'm not sure if it is a good idea > because of the "e

Re: Copying files in directory

2008-12-15 Thread James Mills
On Tue, Dec 16, 2008 at 12:49 PM, wrote: > I'm writing a project management system, and I need the ability to > accept a directory name and move its contents to another directory. > Can someone give me a code sample that will handle this? I can't find > any "copying" functions in os or os.path.

Re: socket and subprocess problem

2008-12-15 Thread Bryan Olson
goat...@gmail.com wrote: In my python code I use subprocess.Popen to run and external program who will listen to a TCP port. And I also create a socket to connect to the TCP port that the external program is listening. I will get 'Connection refused, errno=111' when I try to socket.connect ().

Re: Python is slow

2008-12-15 Thread Tomasz Rola
On Fri, 12 Dec 2008, bearophileh...@lycos.com wrote: > In the next years people that use low-level languages like C may need > to invent a new language fitter for multi-core CPUs, able to be used > on GPUs too (see the OpenCL), less error-prone than C, able to use the > CPU vector instructions eff

Re: socket and subprocess problem

2008-12-15 Thread Roy Smith
In article <6d3291c3-4e12-4bdd-884a-21f15f38d...@a12g2000pro.googlegroups.com>, goat...@gmail.com wrote: > In my python code I use subprocess.Popen to run and external program > who will listen to a TCP port. And I also create a socket to connect > to the TCP port that the external program is li

Re: tricky nested list unpacking problem

2008-12-15 Thread Reckoner
On Dec 15, 1:28 pm, Arnaud Delobelle wrote: > Reckoner writes: > > Hi, > > > I have lists of the following type: > > > [1,2,3,[5,6]] > > > and I want to produce the following strings from this as > > > '0-1-2-3-5' > > '0-1-2-3-6' > > > That was easy enough. The problem is that these can be nested.

Re: socket and subprocess problem

2008-12-15 Thread goatold
Guys thanks to point it out. Yes, it's a race problem. I tried sleep long enough, then I can connect to the socket. I should add code to try to connect to the socket for a given time out. Roy Smith wrote: > In article > <6d3291c3-4e12-4bdd-884a-21f15f38d...@a12g2000pro.googlegroups.com>, > goat..

Re: socket and subprocess problem

2008-12-15 Thread James Mills
On Tue, Dec 16, 2008 at 3:30 PM, wrote: > Guys thanks to point it out. > Yes, it's a race problem. I tried sleep long enough, then I can > connect to the socket. I should add code to try to connect to the > socket for a given time out. This is where event-driven approaches become really useful :

Re: ethical questions about global variables

2008-12-15 Thread rurpy
On Dec 15, 7:45 pm, "Giampaolo Rodola'" wrote: > in a module of mine (ftpserver.py) I'd want to add a (boolean) global > variable named "use_gmt_times" to decide whether the server has to > return times in GMT or localtime but I'm not sure if it is a good idea > because of the "ethical" doubts I'm

Re: parse C expression?

2008-12-15 Thread eliben
On Dec 16, 1:48 am, Torsten Mohr wrote: > Hi, > > i found some examples when googling for the subject but nothing really > matched. > > Is there a standard module available that lets me parse a syntax like "C" > with numbers, operators, braces, variables and function calls? > > I'd like to use thi

Re: ethical questions about global variables

2008-12-15 Thread rurpy
On Dec 15, 11:00 pm, ru...@yahoo.com wrote: > #my_module > class Config: pass > config = Config() > > def func1(state): > config.A = 1 > def func2(state) > config.A = 2 > def func3(state) > print config.A That of course should have been: def func1(config): config.A = 1 def func2(c

Re: ethical questions about global variables

2008-12-15 Thread Michele Simionato
On Dec 16, 3:45 am, "Giampaolo Rodola'" wrote: > Hi, > in a module of mine (ftpserver.py) I'd want to add a (boolean) global > variable named "use_gmt_times" to decide whether the server has to > return times in GMT or localtime but I'm not sure if it is a good idea > because of the "ethical" doub

Re: socket and subprocess problem

2008-12-15 Thread Bryan Olson
goat...@gmail.com wrote: Guys thanks to point it out. Yes, it's a race problem. I tried sleep long enough, then I can connect to the socket. I should add code to try to connect to the socket for a given time out. As Roy noted, that's "the cheesy way". Are the kind of programmers who accept che

tutorial on parser

2008-12-15 Thread John Fabiani
Hi, I'm attempting to learn how to convert MsSQl Transact-SQL to postgres pgsql. So far my readings have led me to finding a parser. I'm looking for a tutorial on how to get it done. I did find a commercial product but they want over $10,000 us. This way beyond my means. Therefore, I need to ge

Re: Thread Locking issue - Can't allocate lock (sem_init fail)

2008-12-15 Thread Bryan Olson
jams...@googlemail.com wrote: [...] > The program is multithreaded to speed up the processing...there are > input and output Queues. It's not the major point here, but are you aware of Python's GIL? > Now, each domain entry is an class object containing various bits of > info. Each domain class

Re: How can I return a non-zero status result from a python script?

2008-12-15 Thread Taskinoor Hasan
sys.exit() raise SystemExit() exception which could be caught and if not caught, terminate only the current thread. If your program is multi-threaded and you want to terminate the process, i.e all threads, immediately then use os._exit(1) On Tue, Dec 16, 2008 at 7:52 AM, Miki wrote: > Hello, > >

Re: os.environ.get('SSH_ORIGINAL_COMMAND') returns None

2008-12-15 Thread Tim Roberts
Tzury Bar Yochay wrote: > >added to ~/.ssh/authorized_keys the command="my_parder" parameter >which point to a python script file named 'my_parser' and located in / >usr/local/bin (file was chmoded as 777) > >in that script file '/usr/local/bin/my_parser' I got the following >lines: > >#!/usr/bin

<    1   2