Re: [Tutor] Writing a csv from a dictionary

2009-06-23 Thread Kent Johnson
On Tue, Jun 23, 2009 at 1:08 AM, Mark Tolonen wrote: > import csv > > dyc = { > 'a50' : ['textfield', 50, 40], > 'k77' : ['othertext', 60, 10] > } > > myfile = open('csv-test.csv', 'w') > mywriter = csv.writer(myfile, dialect='excel') > > for k,[a,b,c] in dyc.items(): >   mywriter.writerow([k,a,b,

Re: [Tutor] filtering NaN values

2009-06-23 Thread Kent Johnson
On Tue, Jun 23, 2009 at 1:53 AM, Alan Gauld wrote: > Interesting! How is a NaN stored in Python? > ie. How do you get to the point of having one in the first place? Google 'python nan' for lots of interesting discussion... Kent ___ Tutor maillist - Tu

Re: [Tutor] Writing a csv from a dictionary

2009-06-23 Thread Mark Tolonen
"Kent Johnson" wrote in message news:1c2a2c590906230415q351c7c74kebc591907ce0e...@mail.gmail.com... On Tue, Jun 23, 2009 at 1:08 AM, Mark Tolonen wrote: import csv dyc = { 'a50' : ['textfield', 50, 40], 'k77' : ['othertext', 60, 10] } myfile = open('csv-test.csv', 'w') mywriter = csv.writ

Re: [Tutor] Writing a csv from a dictionary

2009-06-23 Thread Lie Ryan
Mark Tolonen wrote: > It's a good idea to cut-and-paste actual code and actual output. Your > above code doesn't work. I'd just like to clarify, in case someone misunderstood, it isn't a really good idea to simply cut-and-paste actual code and actual output for 2 reasons: 1) cut-and-paste means

Re: [Tutor] extracting lines in large file

2009-06-23 Thread Lie Ryan
Bryan Fodness wrote: > tried both again, they both return the same 9 lines, when i expect > 492. it dies on a blank line, but the if i_line takes care of the > previous ones. > Can you give a sample input that should, but not passed by the code? Unrelated Tips: You can rely on python's short-c

[Tutor] Trouble with passing commands / variables to os.system()

2009-06-23 Thread Charlie Reddington
Hi, I'm very very green when it comes to python. I know bash better than python, so I figured a good way to learn things was covert my bash stuff to python. So here goes... Here's a quick example of the code I have that is broken. import os username = 'charlie' private_key = '/path/to/key

Re: [Tutor] Trouble with passing commands / variables to os.system()

2009-06-23 Thread vince spicer
os.system is not the best way to handle this you may want to look into the subprocess module however: import os username = 'charlie' private_key = '/path/to/key' ssh = '/usr/bin/ssh' command = 'hostname && df -h && exit' servers = ['172.16.1.1', '172.16.12.2', '172.16.1.3'] for host in servers

Re: [Tutor] Trouble with passing commands / variables to os.system()

2009-06-23 Thread Charlie Reddington
Thanks, Your code works as expected! Can you tell me what your code is doing different than mine? Charlie On Jun 23, 2009, at 3:06 PM, vince spicer wrote: os.system is not the best way to handle this you may want to look into the subprocess module however: import os username = 'charlie'

Re: [Tutor] Trouble with passing commands / variables to os.system()

2009-06-23 Thread Alan Gauld
"Charlie Reddington" wrote Your code works as expected! Can you tell me what your code is doing different than mine? os.system needs the command to be a string so you have to build up the string by passing in your variables using the string format operator(%) or building it bit by bit outs

Re: [Tutor] Trouble with passing commands / variables to os.system()

2009-06-23 Thread Charlie Reddington
On Jun 23, 2009, at 4:50 PM, Alan Gauld wrote: "Charlie Reddington" wrote Your code works as expected! Can you tell me what your code is doing different than mine? os.system needs the command to be a string so you have to build up the string by passing in your variables using the string f

Re: [Tutor] Trouble with passing commands / variables to os.system()

2009-06-23 Thread David
Charlie Reddington wrote: Thanks for all the replies, I'll definitely look into it all. Charlie Something else for your consideration; http://commandline.org.uk/python/sftp-python-really-simple-ssh/ -- Powered by Gentoo GNU/Linux http://linuxcrazy.com __

Re: [Tutor] Trouble with passing commands / variables to os.system()

2009-06-23 Thread David
David wrote: Charlie Reddington wrote: Thanks for all the replies, I'll definitely look into it all. Charlie Something else for your consideration; http://commandline.org.uk/python/sftp-python-really-simple-ssh/ almost forgot pexpect #!/usr/bin/python import pexpect child = pexpect.sp