Non blocking read from stdin on windows.
Hi Can any one help. I am trying to write a python scipt that takes input as args and/or as piped input ( possibly the output of another program). I want to read stdin ( the piped in stuuff ) whcih might be empty without the script blocking if it is empty. I understand it is possible to do under unix with the select call. Can some one please explain how to do this in windows. thanks in advance. Barr -- http://mail.python.org/mailman/listinfo/python-list
HELP Non-Blocking reads from sys.stdin in Windows.
Hi I am in real need of a way to perform non blocking reads from sys.stdin on windows. I have looked every where for an answer but but with no luck. I beleive there there must be a way of doing this, can some one please help asap. Thanks in advance, Barr -- http://mail.python.org/mailman/listinfo/python-list
Re: HELP Non-Blocking reads from sys.stdin in Windows.
hi Do you mean something like the following. class inputReader(Thread): def __init__(self): Thread.__init__(self) def run(self): buffer = sys.readline() thread = inputReader() thread.start() Thanks Kwame "Paul Rubin" <http://[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > "barr" <[EMAIL PROTECTED]> writes: > > I am in real need of a way to perform non blocking reads from sys.stdin on > > windows. I have looked every where for an answer but but with no luck. I > > beleive there there must be a way of doing this, can some one please help > > asap. > > Use a separate thread. -- http://mail.python.org/mailman/listinfo/python-list
Beginners Query - Simple counter problem
I am brand new to Python (this is my second day), and the only experience I have with programming was with VBA. Anyway, I'm posting this to see if anyone would be kind enough to help me with this (I suspect, very easy to solve) query. The following code is in a file which I am running through the interpreter with the execfile command, yet it yeilds no results. I appreciate I am obviously doing something really stupid here, but I can't find it. Any help appreciated. def d6(i): roll = 0 count = 0 while count <= i: roll = roll + random.randint(1,6) count += 1 return roll print d6(3) -- http://mail.python.org/mailman/listinfo/python-list
Re: Beginners Query - Simple counter problem
Scott David Daniels wrote: > David Barr wrote: >> I am brand new to Python (this is my second day), and the only >> experience I have with programming was with VBA. Anyway, I'm posting >> this to see if anyone would be kind enough to help me with this (I >> suspect, very easy to solve) query. >> >> The following code is in a file which I am running through the >> interpreter with the execfile command, yet it yeilds no results. I >> appreciate I am obviously doing something really stupid here, but I >> can't find it. Any help appreciated. >> >> >> def d6(i): >> roll = 0 >> count = 0 >> while count <= i: >> roll = roll + random.randint(1,6) >> count += 1 >> >> return roll >> >> print d6(3) > A) your direct answer: by using <=, you are rolling 4 dice, not 3. > B) Much more pythonic: > > import random > > def d6(count): > result = 0 > for die in range(count): > result += random.randint(1, 6) > return result > > -Scott David Daniels > [EMAIL PROTECTED] I was surprised by the speed and number of posts. Thanks for the solutions provided! >>> def roll(times=1, sides=6): ... return random.randint(times, times*sides) Although this would probably be quicker than the other approaches, I'm not using the dice to generate numbers per say, I actually want to emulate the rolling of dice, bell-curve (normal distribution) as well as the range. Thanks again, I already like what (very) little I can do in Python and it seems to have a great community too. Cheers, Dave. -- http://mail.python.org/mailman/listinfo/python-list
Bug in python!? persistent value of an optional parameter in function!
Help! Have I found a serious bug? This seems like highly undesired behaviour to me. From the program below, I get output: call1: ['sdf'] call2: ['Set within test for call2'] call3: ['Set within test for call2'] instead of what I should get, call1: ['sdf'] call2: ['Set within test for call2'] call3: ['Set within test for call3'] I'm using Python 2.4.4c1 (#2, Oct 11 2006, 21:51:02). The code is below. #!/usr/bin/python def testPersistence(anarg,twooption=[]): #print anarg if not twooption: twooption.append('Set within test for '+anarg) print anarg +': '+str(twooption) testPersistence('call1',twooption=['sdf']); testPersistence('call2'); testPersistence('call3'); -- http://mail.python.org/mailman/listinfo/python-list
Re: Bug in python!? persistent value of an optional parameter in function!
Oh, oops! Of course... :) A great and sensible feature if you're expecting it. Thanks very much, everyone, for the links and discussion! Chris -- http://mail.python.org/mailman/listinfo/python-list
Mapping in python? Transforming shapefile so that basemap can read them?
I'm trying to get started with plotting maps in python. I need to read "shape files" (.shp) and make maps. There seem to be many efforts but none is complete? I'm looking for suggestions and troubleshooting. The basemap package is obviously at an impressive stage and comes with some data: http://www.scipy.org/Cookbook/Matplotlib/Maps but it cannot read shapefiles when their coordinates are not in geographic projection. min are in a lambert, so the readshapefile fails. Apparently there is a utility that can convert a .shp file to lat/lon coordinates, but it fails for me. “You can convert the shapefile to geographic - coordinates using the shpproj utility from the shapelib tools - (http://shapelib.maptools.org/shapelib-tools.html)" For me, this gives: “unable to process projection, exiting...” Has anyone overcome these problems? Thanks! Chris -- http://mail.python.org/mailman/listinfo/python-list