>> >>> s='1|2|3|4'
>> >>> l=s.split('|')
>> >>> a, l = l[0], l[1:]
>> >>> a
>> '1'
>> >>> l
>> ['2', '3', '4']
i went with the above, or more specifically
aList = line[:-1].split('|')
netName, asList = aList[0], aList[1:]
not gorgeous, but readable
and my instinct for pinning a type
On Tue, 18 Oct 2005, Kent Johnson wrote:
> >l = []
> >a, l = string.split('|')
>
> How about
> >>> s='1|2|3|4'
> >>> l=s.split('|')
> >>> a, l = l[0], l[1:]
> >>> a
> '1'
> >>> l
> ['2', '3', '4']
> ?
Hi Randy,
I think you're expecting Perl behavior. The Perl idiom for partiall
> How about
> >>> s='1|2|3|4'
> >>> l=s.split('|')
> >>> a, l = l[0], l[1:]
> >>> a
> '1'
> >>> l
> ['2', '3', '4']
looks kinda readable. thanks
randy
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
> The string.split sends the list to a, but after that it's looking for
> something to assign to l and there's nothing leftover from the command
> for it to assign.
nope, it does not send the list to a
>>> l = []
>>> s = 'a|b'
>>> t, l = s.split('|')
>>> t
'a'
>>> l
'b'
i believe the problem is
Randy Bush wrote:
> maybe it's that i am actually doing
>
>l = []
>a, l = string.split('|')
How about
>>> s='1|2|3|4'
>>> l=s.split('|')
>>> a, l = l[0], l[1:]
>>> a
'1'
>>> l
['2', '3', '4']
?
Kent
>
> ?
>
> ___
> Tutor maillist -
well that would definitely cause your error.
The string.split sends the list to a, but after that it's looking for
something to assign to l and there's nothing leftover from the command
for it to assign.
On 10/18/05, Randy Bush <[EMAIL PROTECTED]> wrote:
> > >>> l = []
> > >>>a='1|2|3|4'
> > >>>
> >>> l = []
> >>>a='1|2|3|4'
> >>> l=a.split('|')
> >>>l
> ['1', '2', '3', '4']
>> and stupid question of the morning (for me)
>>
>> i want to string.split() into a sequence, a la
>>
>> l = []
>> l = myString.split('|')
>>
>> but, of course it whines about too many values. what is the
>> comm
Works fine for me:
>>> l = []
>>>a='1|2|3|4'
>>> l=a.split('|')
>>>l
['1', '2', '3', '4']
On 10/18/05, Randy Bush <[EMAIL PROTECTED]> wrote:
> and stupid question of the morning (for me)
>
> i want to string.split() into a sequence, a la
>
> l = []
> l = myString.split('|')
>
> but, of cours
and stupid question of the morning (for me)
i want to string.split() into a sequence, a la
l = []
l = myString.split('|')
but, of course it whines about too many values. what is the
common way to do this?
randy
___
Tutor maillist - Tutor@pytho