Re: [Tutor] Convert a string of numbers to a list

2009-02-27 Thread Vern Ceder
Kyle Kwaiser wrote: x = ['[335, 180, 201, 241, 199]\r\n'] y = map( int, x[0].strip( '[]\r\n' ).split( ', ' ) ) #need an index here print y [335, 180, 201, 241, 199] I realize it's not totally secure, but if your string really is in that format (i.e., a representation of a list), you COULD j

Re: [Tutor] Convert a string of numbers to a list

2009-02-27 Thread Kyle Kwaiser
Turns out I was close but had not combined everything. I never would have picked up on the map() function. Much more efficient than looping through the whole mess and converting to int. x = ['[335, 180, 201, 241, 199]\r\n'] y = map( int, x[0].strip( '[]\r\n' ).split( ', ' ) ) #need an index

Re: [Tutor] Convert a string of numbers to a list

2009-02-26 Thread Kent Johnson
On Thu, Feb 26, 2009 at 2:00 AM, wrote: > Hi, > > I am trying to convert an output from subprocess.Popen() from a byte string > to a list of numbers.  This is what Popen returns: > > print SAL.stdout.readlines() > > ['[335, 180, 201, 241, 199]\r\n'] For one line: In [11]: s = '[335, 180, 201, 24

Re: [Tutor] Convert a string of numbers to a list

2009-02-26 Thread A.T.Hofkamp
kkwai...@umich.edu wrote: Hi, I am trying to convert an output from subprocess.Popen() from a byte string to a list of numbers. This is what Popen returns: print SAL.stdout.readlines() ['[335, 180, 201, 241, 199]\r\n'] Except the string will be much longer in practice. I've experimented w

[Tutor] Convert a string of numbers to a list

2009-02-26 Thread kkwaiser
Hi, I am trying to convert an output from subprocess.Popen() from a byte string to a list of numbers. This is what Popen returns: print SAL.stdout.readlines() ['[335, 180, 201, 241, 199]\r\n'] Except the string will be much longer in practice. I've experimented with .rstrip and .split and