Re: [Tutor] Problem with msvcrt

2007-11-01 Thread Alan Gauld
"Ricardo Aráoz" <[EMAIL PROTECTED]> wrote > if msvcrt.kbhit() : > key = msvcrt.getch() > if key == 'h' : > print 'Hello' > > This is XP with 2.5 in Idle. Any ideas? IDLE is a GUI app running under Tkinters event loop. I doubt if msvcrt works under Tkinter. Try running your code in a DOS box. Any

Re: [Tutor] Getting single values of a tuple & storing them

2007-11-01 Thread Alan Gauld
"Trey Keown" <[EMAIL PROTECTED]> wrote > I was wondering, how could I get each value inside of a tuple, say > it's > (2,4) . > The only value I really need is the second one (the tuple will > always have > only two values. Tuples are like any other Python collection or sequence. You can access

Re: [Tutor] sorting variables

2007-11-01 Thread Evert Rol
> i was thinking of doing something like > >objSprites = pygame.sprite.OrderedUpdates((var1, > var2, var3).sort) > > but i don't think thats gunna work It won't indeed, because of 3 things: 1. you're trying to sort a tuple. Tuples don't have a sort() method, use a list instead 2. sort doesn'

Re: [Tutor] Regular Expression help - parsing AppleScript Lists as Strings

2007-11-01 Thread Kent Johnson
Andrew Wu wrote: >pattern3 = ''' > ^{ > ( > %s > | {%s} # Possible to have 1 level of nested lists > ,?)* # Items are comma-delimited, except for the last item > }$ >''' % (pattern2, pattern2) The above doesn't allow comma after the first instance

Re: [Tutor] Regular Expression help - parsing AppleScript Lists as Strings

2007-11-01 Thread Kent Johnson
Kent Johnson wrote: > You might want to look at doing this with pyparsing, I think it will > make it easier to get the data out vs just recognizing the correct pattern. Here is a pyparsing version that correctly recognizes all of your patterns and returns a (possibly nested) Python list in case

Re: [Tutor] Regular Expression help - parsing AppleScript Lists as Strings

2007-11-01 Thread Andrew Wu
Ah - thanks for the correction! I missed the extra grouping and the extra spacing ... doh! Sorry about the HTML-formatted e-mail ... Thanks also for the pyparsing variant as well - I didn't know the module existed before! Andrew On 11/1/07, Kent Johnson <[EMAIL PROTECTED]> wrote: > Andrew Wu

[Tutor] Turning multiple Popen calls into a function

2007-11-01 Thread jay
Hello, If I have multiple Popen calls I need to make, how can I turn these into a function? from subprocess import Popen, PIPE p1 = Popen(['ls', '-l', '-a', '/etc'],stdout=PIPE) p2 = Popen(['grep', 'hosts'], stdin=p1.stdout, stdout=PIPE) p3 = Popen(['awk', '{print $1}'], stdin=p2.stdout, stdout=

Re: [Tutor] Turning multiple Popen calls into a function

2007-11-01 Thread Eric Walstad
Hi Jay... jay wrote: ... > I would be sending an arbitrary number of PIPES with each function call. > > I'm a little stumped as to how to handle the variables. If I have an > arbitrary number of PIPES, how do I declare my variables (p1, p2, p3, > etc...) ahead of time in the function?? > > Tha

Re: [Tutor] Turning multiple Popen calls into a function

2007-11-01 Thread Eric Brunson
jay wrote: > Hello, > > If I have multiple Popen calls I need to make, how can I turn these > into a function? Since you're only interested in the output of the last command on the pipeline, I don't see a reason to keep track of them all. I'd do something like this: def pipeline( *commandlist

[Tutor] sorting / outputting varibales

2007-11-01 Thread ted b
If i input the following in python: var1 = 7 var2 = 9 var3 = 5 args = [var1, var2, var3] args.sort() then if if type: args the output is [5, 7, 9] but i want the output to be [var3, var1, var2] is there a function that will output the variable names in the order they

Re: [Tutor] Turning multiple Popen calls into a function

2007-11-01 Thread Alan Gauld
"jay" <[EMAIL PROTECTED]> wrote > I'm a little stumped as to how to handle the variables. If I have > an > arbitrary number of PIPES, how do I declare my variables (p1, p2, > p3, > etc...) ahead of time in the function?? How about passing a list of pipes? Then you can access them as pipes[0]

Re: [Tutor] sorting / outputting varibales

2007-11-01 Thread Evert Rol
> If i input the following in python: >var1 = 7 >var2 = 9 >var3 = 5 >args = [var1, var2, var3] >args.sort() > > then if if type: > >args > > the output is > >[5, 7, 9] > > but i want the output to be > >[var3, var1, var2] > > is there a function that will output the

Re: [Tutor] Turning multiple Popen calls into a function

2007-11-01 Thread jay
Eric and Eric :-) Thanks both for the suggestions! I learned from each! I believe the small function will work for me. Its simple since I don't have to track each pipe I open with a variable. I had no idea I could do that nifty if/then for the stdin, that makes it so easy. :-) Thanks again! J

[Tutor] Automating operations... os module, mysql operations, more...

2007-11-01 Thread John
I should begin by explaining I am not a sysadmin, I'm merely one trying to use the right tool for the right job, and for my job I believe Python to be that tool. Here is an outline of what I wish to accomplish, pointers to modules, tools of interest, etc. would be greatly appreciated... Below each

Re: [Tutor] sorting / outputting varibales

2007-11-01 Thread Kent Johnson
Evert Rol wrote: > Hm, I don't know directly how to get the name of a variable. I'd > hoped there was a private method (var3.), but looks > like there isn't it. No, the mapping from names to values is one way. It's pretty easy to have a value associated with no name, or more than one name

Re: [Tutor] sorting / outputting varibales

2007-11-01 Thread Kent Johnson
ted b wrote: > If i input the following in python: >var1 = 7 >var2 = 9 >var3 = 5 >args = [var1, var2, var3] >args.sort() > > then if if type: > >args > > the output is > >[5, 7, 9] > > but i want the output to be > >[var3, var1, var2] > > is there a function t

[Tutor] dictionary append

2007-11-01 Thread Dinesh B Vadhia
Hello! I'm creating a dictionary called keywords that has multiple entries each with a variable list of values eg. keywords[1] = [1, 4, 6, 3] keywords[2] = [67,2] keywords[3] = [2, 8, 5, 66, 3, 23] etc. The keys and respective values (both are integers) are read in from a file. For each key,

Re: [Tutor] sorting / outputting varibales

2007-11-01 Thread Evert Rol
> Thanks, i think a dictionary may be the way to go > >> in the end, you're going to use the >> actual values anyway, >> not their names, right? > > yeah, you're right, the way i was thinking about doing > it probably won't work. The way I am doing it now is > actually using attibutes of the var's

Re: [Tutor] sorting / outputting varibales

2007-11-01 Thread Kent Johnson
ted b wrote: > Here's the code i am using, but its a lot of if / > thens and i'm trying to find a better way: > > if var1.value > var2.value > var3.value: > objSprites = pygame.sprite.OrderedUpdates > (var1, var2, var3) Did you see Evert's reply to your original question? It was

Re: [Tutor] sorting / outputting varibales

2007-11-01 Thread ted b
Thanks Kent, and Evert, and everyone, I really appreciate the advice on etiqutte and all your help. I will think through my questions much more thoroughly before any further inquiries and will 'reply to all' as advised. --- Kent Johnson <[EMAIL PROTECTED]> wrote: > ted b wrote: > > > Here's the c

Re: [Tutor] Automating operations... os module, mysql operations, more...

2007-11-01 Thread Michael Langford
> > 1) Maintain a mysql database which contains information, as well as > 'control' variables, pointers to directories, etc. for various shell > scripts / fortran code. ->pyMySQL > You're on the right track > 2) Query various servers to see if there is 'idyl' time/resources... send > a job to t

Re: [Tutor] Turning multiple Popen calls into a function

2007-11-01 Thread Alan Gauld
"Eric Brunson" <[EMAIL PROTECTED]> wrote >last = Popen( command, > stdin=last.stdout if last else None, > stdout=PIPE ) Where does the if/else syntax come from? It doesn't seem to work on my Python 2.4. Is it a new feature in 2.5? Alan G. ___

Re: [Tutor] Automating operations... os module, mysql operations, more...

2007-11-01 Thread John
> > > > > > 2) Query various servers to see if there is 'idyl' time/resources... > > send a job to the server if it's available... > > > > This and 3 can be helped out with ipython > > > > > 3) Use python to check the file system for existing files (glob?) , > > decide which 'jobs' need to be run,

Re: [Tutor] Turning multiple Popen calls into a function

2007-11-01 Thread Jeff Younker
On Nov 1, 2007, at 3:04 PM, Alan Gauld wrote: > Where does the if/else syntax come from? It doesn't > seem to work on my Python 2.4. Is it a new feature in 2.5? Yes, it's a new feature in 2.5. - Jeff Younker - [EMAIL PROTECTED] ___ Tutor maillist -

Re: [Tutor] dictionary append

2007-11-01 Thread Alan Gauld
"Dinesh B Vadhia" <[EMAIL PROTECTED]> wrote keywords[1] = [1, 4, 6, 3] keywords[2] = [67,2] keywords[3] = [2, 8, 5, 66, 3, 23] etc. The keys and respective values (both are integers) are read in from a file. For each key, the value is append'ed until the next key. Here is the code. ..

Re: [Tutor] dictionary append

2007-11-01 Thread bob gailer
Dinesh B Vadhia wrote: > Hello! I'm creating a dictionary called keywords that has multiple > entries each with a variable list of values eg. > > keywords[1] = [1, 4, 6, 3] > keywords[2] = [67,2] > keywords[3] = [2, 8, 5, 66, 3, 23] > etc. > > The keys and respective values (both are integers

Re: [Tutor] Automating operations... os module, mysql operations, more...

2007-11-01 Thread Jeff Younker
On Nov 1, 2007, at 12:15 PM, John wrote: 1) Maintain a mysql database which contains information, as well as 'control' variables, pointers to directories, etc. for various shell scripts / fortran code. ->pyMySQL Look at an object relational mapper like SQLObject or SQLAlchemy. They make

Re: [Tutor] Problem with msvcrt

2007-11-01 Thread Ricardo Aráoz
Alan Gauld wrote: > "Ricardo Aráoz" <[EMAIL PROTECTED]> wrote > >> if msvcrt.kbhit() : >> key = msvcrt.getch() >> if key == 'h' : >> print 'Hello' >> >> This is XP with 2.5 in Idle. Any ideas? > > IDLE is a GUI app running under Tkinters event loop. > I doubt if msvcrt works under Tkinter. > Try

Re: [Tutor] dictionary append

2007-11-01 Thread Kent Johnson
bob gailer wrote: > if key not in keywords: >keywords[key] = [] > keywords[key].append(value) This can be written more succinctly as keywords.setdefault(key, []).append(value) or in Python 2.5: from collections import defaultdict keywords = defaultdict(list) ... keywords[key

Re: [Tutor] Build exe on Vista, have it run on XP?

2007-11-01 Thread O.R.Senthil Kumaran
* Michael Langford <[EMAIL PROTECTED]> [2007-11-01 01:15:31]: > That's not really a working solution. My available development platform is a > Vista machine. I don't have an available XP platform. XP built exes run fine > on Vista, just not vice versa. Then the best possible way would be to ask p