Re: list to tuple and vice versa

2009-10-20 Thread David C Ullrich
On Sun, 18 Oct 2009 14:33:17 +1100, Ben Finney wrote: > Jabba Laci writes: > >> Hi, >> >> I have some difficulties with list -> tuple conversion: >> >> t = ('a', 'b') >> li = list(t) # tuple -> list, works print li # ['a', 'b'] >> >> tu = tuple(li) # list -> tuple, error print tu # what

Re: list to tuple and vice versa

2009-10-17 Thread StarWing
On 10月18日, 下午1时32分, Ben Finney wrote: > StarWing writes: > > On 10月18日, 下午12时19分, Ben Finney wrote: > > > Jabba Laci writes: > > > > Right, it was my bad. After removal the tuple() function works > > > > perfectly. > > > > Note that, though it is callable, ‘tuple’ is not a function but a > > >

Re: list to tuple and vice versa

2009-10-17 Thread Ben Finney
StarWing writes: > On 10月18日, 下午12时19分, Ben Finney wrote: > > Jabba Laci writes: > > > Right, it was my bad. After removal the tuple() function works > > > perfectly. > > > > Note that, though it is callable, ‘tuple’ is not a function but a > > type: > > A type is always callable. Yes (modulo

Re: list to tuple and vice versa

2009-10-17 Thread StarWing
On 10月18日, 下午12时19分, Ben Finney wrote: > Jabba Laci writes: > > Right, it was my bad. After removal the tuple() function works > > perfectly. > > Note that, though it is callable, ‘tuple’ is not a function but a type: > >     >>> tuple >     >     >>> len >     > > You can use the built-in ‘typ

Re: list to tuple and vice versa

2009-10-17 Thread Ben Finney
Jabba Laci writes: > Right, it was my bad. After removal the tuple() function works > perfectly. Note that, though it is callable, ‘tuple’ is not a function but a type: >>> tuple >>> len You can use the built-in ‘type’ type to get the type of any object: >>> foo = 12

Re: list to tuple and vice versa

2009-10-17 Thread Jabba Laci
>> The error message is: "TypeError: 'tuple' object is not callable". > > You created a variable named "tuple" somewhere, which is shadowing the > built-in type. Rename that variable to something else. Right, it was my bad. After removal the tuple() function works perfectly. Thanks, Laszlo -- h

Re: list to tuple and vice versa

2009-10-17 Thread Ben Finney
Jabba Laci writes: > Hi, > > I have some difficulties with list -> tuple conversion: > > t = ('a', 'b') > li = list(t) # tuple -> list, works > print li # ['a', 'b'] > > tu = tuple(li) # list -> tuple, error > print tu # what I'd expect: ('a', 'b') Works fine for me: Python 2.5.4 (r

Re: list to tuple and vice versa

2009-10-17 Thread Chris Rebert
On Sat, Oct 17, 2009 at 8:24 PM, Jabba Laci wrote: > Hi, > > I have some difficulties with list -> tuple conversion: > > t = ('a', 'b') > li = list(t)   # tuple -> list, works > print li   # ['a', 'b'] > > tu = tuple(li)   # list -> tuple, error > print tu   # what I'd expect: ('a', 'b') > > The e