Re: [Tutor] Curious dictionary printing

2012-05-07 Thread BRAGA, Bruno
Put it simple, dictionaries do not sort. You can use the dict.keys() to get a list of the dictionary keys, then sort them... there are lots of talks on this, just google a bit, and you will find fancy ways to do key or value sorting. -- *Braga, Bruno* www.brunobraga.net bruno.br...@gmail.com On

Re: [Tutor] summary stats grouped by month year

2012-05-07 Thread Andre' Walker-Loud
Hello anonymous questioner, first comment - you may want to look into hdf5 data structures http://www.hdfgroup.org/HDF5/ and the python tools to play with them pytables - http://www.pytables.org/moin h5py - http://code.google.com/p/h5py/ I have personally used pytables more - but not for any g

[Tutor] summary stats grouped by month year

2012-05-07 Thread questions anon
I would like to calculate summary statistics of rainfall based on year and month. I have the data in a text file (although could put in any format if it helps) extending over approx 40 years: YEAR MONTHMeanRain 1972 Jan12.7083199 1972 Feb14.17007142 1972 Mar14.5659302 1972 Apr1.

Re: [Tutor] IPcount = 0 when used with subprocess.call (use something to convert to integer?)

2012-05-07 Thread Steven D'Aprano
On Mon, May 07, 2012 at 08:09:55PM -0700, Rogelio wrote: > import subprocess > IPcount = subprocess.call(['wc -l file.txt | awk \'{print $1}\''], shell=True) > print "You have",IPcount,"IP addresses that are alive." > > I get the following output > > 46 > You have 0 IP addresses that are alive. >

Re: [Tutor] IPcount = 0 when used with subprocess.call (use something to convert to integer?)

2012-05-07 Thread Kushal Kumaran
On Tue, May 8, 2012 at 8:39 AM, Rogelio wrote: > I am wrapping a Python wrapper script to "wc -l" (count lines) of a > list of IP addresses > > *** > > import subprocess > IPcount = subprocess.call(['wc -l file.txt | awk \'{print $1}\''], shell=True) > print

Re: [Tutor] IPcount = 0 when used with subprocess.call (use something to convert to integer?)

2012-05-07 Thread Rogelio
On Mon, May 7, 2012 at 8:09 PM, Rogelio wrote: > Why does IPcount not equal 46?  Is this what the stout is for? FWIW, I think this seems to fix it and make IPcount an integer. import os IPcount = os.popen("wc -l file.txt | awk '{print $1}'").read() print "You have",IPcount,"IP addresses that ar

[Tutor] IPcount = 0 when used with subprocess.call (use something to convert to integer?)

2012-05-07 Thread Rogelio
I am wrapping a Python wrapper script to "wc -l" (count lines) of a list of IP addresses *** import subprocess IPcount = subprocess.call(['wc -l file.txt | awk \'{print $1}\''], shell=True) print "You have",IPcount,"IP addresses that are alive." **

Re: [Tutor] Curious dictionary printing

2012-05-07 Thread bob gailer
On 5/7/2012 1:16 PM, Cranky Frankie wrote: In 3.2.2 in IDLE I have this dictionary entry: Namath = {"first_name": "Joe", "last_name": "Namath", "phone": "212-222-",\ "email": "joe.nam...@gmail.com", "stadium": "Shea Stadium"} when I print it: print(Namath) I get: {'phone': '21

[Tutor] Console Application - Key Events

2012-05-07 Thread BRAGA, Bruno
Hi tutors, I would like to know if there is any "easy" way to handle events (such as mouse movements, keyboard keys pressed, etc) in console based python applications? More specifically, I am working on a screensaver for terminals ( http://termsaver.info), so I would like to simulate the same beh

Re: [Tutor] How can I have type "function" in my script?

2012-05-07 Thread Alan Gauld
On 07/05/12 21:37, xancorreu wrote: This is the code: OK, But it's not clear from that why you want the type. You are not doing anything meaningful with the type. class Tag: def __init__(self, nom, tipus, valor): self.nom = nom self.tipus = tipus self.valor = valor def __str__(self): retur

Re: [Tutor] How can I have type "function" in my script?

2012-05-07 Thread Dave Angel
On 05/07/2012 04:37 PM, xancorreu wrote: > Al 07/05/12 21:07, En/na Dave Angel ha escrit: >> On 05/07/2012 02:24 PM, xancorreu wrote: >>> Hi, >>> >>> I have this script: >>> >>> from types import * >>> >> Bad idea. Once you do that, you can silently overwrite globals in your >> own module with stu

Re: [Tutor] Curious dictionary printing

2012-05-07 Thread Mark Lawrence
On 07/05/2012 18:16, Cranky Frankie wrote: In 3.2.2 in IDLE I have this dictionary entry: Namath = {"first_name": "Joe", "last_name": "Namath", "phone": "212-222-",\ "email": "joe.nam...@gmail.com", "stadium": "Shea Stadium"} when I print it: print(Namath) I get: {'phone': '21

Re: [Tutor] How can I have type "function" in my script?

2012-05-07 Thread xancorreu
Al 07/05/12 21:07, En/na Dave Angel ha escrit: On 05/07/2012 02:24 PM, xancorreu wrote: Hi, I have this script: from types import * Bad idea. Once you do that, you can silently overwrite globals in your own module with stuff that the current version of types happens to have in it. Besides,

Re: [Tutor] looking for some advice

2012-05-07 Thread Alan Gauld
On 07/05/12 15:19, Chris Hare wrote: Basically, I am trying to imitate a notebook like in Tkinter.ttk, I know Tix has a notebook widget, but that would require people > to download and compile the Tix components. You must be using a very old version of Python. Tix has been in the standard libr

Re: [Tutor] Displaying data in columns

2012-05-07 Thread Alan Gauld
On 07/05/12 14:43, Thomas C. Hicks wrote: I would like to display some of the items in the tuples in columnar format with each column lining up on the left side (below should be three neat columns with location, training type, number trained and date): You need to read up on string formatting.

Re: [Tutor] How can I have type "function" in my script?

2012-05-07 Thread Dave Angel
On 05/07/2012 03:11 PM, Joel Goldstick wrote: > On Mon, May 7, 2012 at 3:07 PM, Dave Angel wrote: >> On 05/07/2012 02:24 PM, xancorreu wrote: >>> Hi, >>> >>> I have this script: >>> >>> from types import * >>> >> Bad idea. Once you do that, you can silently overwrite globals in your >> own module

Re: [Tutor] How can I have type "function" in my script?

2012-05-07 Thread Joel Goldstick
On Mon, May 7, 2012 at 3:07 PM, Dave Angel wrote: > On 05/07/2012 02:24 PM, xancorreu wrote: >> Hi, >> >> I have this script: >> >> from types import * >> > Bad idea.  Once you do that, you can silently overwrite globals in your > own module with stuff that the current version of types happens to

Re: [Tutor] How can I have type "function" in my script?

2012-05-07 Thread Dave Angel
On 05/07/2012 02:24 PM, xancorreu wrote: > Hi, > > I have this script: > > from types import * > Bad idea. Once you do that, you can silently overwrite globals in your own module with stuff that the current version of types happens to have in it. Besides, it then becomes very hard to read your pr

Re: [Tutor] How can I have type "function" in my script?

2012-05-07 Thread Glen Zangirolami
Xan, it's "not defined" because you haven't defined a function called "function" or any variable called "function". Nom: descripci, Tipus: , Valor: primera tasca Nom: unmes, Tipus: , Valor: at 0x10df736e0> str comes back as because str is a built-in method and python and will always be in the n

Re: [Tutor] looking for some advice

2012-05-07 Thread Chris Hare
Thanks Peter - I will give it a look On May 7, 2012, at 1:02 PM, Peter Otten wrote: > Chris Hare wrote: > >> Hello Everyone: >> >> Here is what I am trying to do: >> >> I have a window which has a row of buttons on it. Below the buttons is a >> label frame. Depending upon which button they

[Tutor] How can I have type "function" in my script?

2012-05-07 Thread xancorreu
Hi, I have this script: from types import * class Tag: def __init__(self, nom, tipus, valor): self.nom = nom self.tipus = tipus self.valor = valor def __str__(self): return "Nom: " + str(self.nom) + ", Tipus: " + str(self.tipus) + ", Valor: " + str(se

Re: [Tutor] looking for some advice

2012-05-07 Thread Peter Otten
Chris Hare wrote: > Hello Everyone: > > Here is what I am trying to do: > > I have a window which has a row of buttons on it. Below the buttons is a > label frame. Depending upon which button they push, I want to change the > widgets in the label frame. I can add widgets now with no problem.

Re: [Tutor] Curious dictionary printing

2012-05-07 Thread Walter Prins
Hi, On 7 May 2012 18:16, Cranky Frankie wrote: > In 3.2.2 in IDLE I have this dictionary entry: > > Namath = {"first_name": "Joe", "last_name": "Namath", "phone": " > 212-222-",\ > "email": "joe.nam...@gmail.com", "stadium": "Shea Stadium"} > > Why is it out of order? Python dicti

[Tutor] Curious dictionary printing

2012-05-07 Thread Cranky Frankie
In 3.2.2 in IDLE I have this dictionary entry: Namath = {"first_name": "Joe", "last_name": "Namath", "phone": "212-222-",\ "email": "joe.nam...@gmail.com", "stadium": "Shea Stadium"} when I print it: print(Namath) I get: {'phone': '212-222-', 'first_name': 'Joe', 'last_name':

Re: [Tutor] Displaying data in columns

2012-05-07 Thread Emile van Sebille
On 5/7/2012 6:43 AM Thomas C. Hicks said... I would like to display some of the items in the tuples in columnar format with each column lining up on the left side I am not against reading documentation, just can't find the right module to read about. You'll want to read up on the string int

[Tutor] looking for some advice

2012-05-07 Thread Chris Hare
Hello Everyone: Here is what I am trying to do: I have a window which has a row of buttons on it. Below the buttons is a label frame. Depending upon which button they push, I want to change the widgets in the label frame. I can add widgets now with no problem. Basically, I am trying to

Re: [Tutor] Displaying data in columns

2012-05-07 Thread bob gailer
On 5/7/2012 9:43 AM, Thomas C. Hicks wrote: I have some data that comes out of a database as a list of tuples of integers and strings, one tuple for each row in the ResultProxy from the select operation. The data looks something like this: Where the data comes from is not relevant. Please don't c

[Tutor] Displaying data in columns

2012-05-07 Thread Thomas C. Hicks
I have some data that comes out of a database as a list of tuples of integers and strings, one tuple for each row in the ResultProxy from the select operation. The data looks something like this: [(56, 12, 8, u'2012-02', 10, 12, u'Guangxi Province', u'Guangxi', u'10', 8, u'TOT'), (57, 21, 1, u'201

Re: [Tutor] error when using using subprocess.popen in Python wrapper script

2012-05-07 Thread Peter Otten
Rogelio wrote: > If I want to write this command to a file, would this be the right format? > > * > import subprocess > > (all my variables defined okay) > > perl_script=subprocess.call(['perl',perl_prog,ipfile,cmd,user,timeout,]) > > log=open('/tmp/pythonOutput

Re: [Tutor] error when using using subprocess.popen in Python wrapper script

2012-05-07 Thread Rogelio
If I want to write this command to a file, would this be the right format? * import subprocess (all my variables defined okay) perl_script=subprocess.call(['perl',perl_prog,ipfile,cmd,user,timeout,]) log=open('/tmp/pythonOutput.txt',w) log.write(subprocess.call(p