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
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
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
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
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