Re: Nice way to cast a homogeneous tuple

2010-08-07 Thread Carl Banks
On Aug 7, 8:18 pm, Dennis Lee Bieber wrote: > On Sat, 7 Aug 2010 13:02:56 -0700 (PDT), Carl Banks > declaimed the following in > gmane.comp.python.general: > > > > > Not really.  Very few people call int(), float(), and company "type > > casts".  They aren't type casts at all, they are constructo

Re: Nice way to cast a homogeneous tuple

2010-08-07 Thread Carl Banks
On Aug 7, 6:54 am, Albert van der Horst wrote: > In article <1pm7i7-473@satorlaser.homedns.org>, > Ulrich Eckhardt   wrote: > > > > >Steven D'Aprano wrote: > >> Perhaps I have been misinformed, but my understanding of C type-casts is > >> that (where possible), a cast like `int(var)` merely te

Re: Nice way to cast a homogeneous tuple

2010-08-07 Thread Albert van der Horst
In article <1pm7i7-473@satorlaser.homedns.org>, Ulrich Eckhardt wrote: >Steven D'Aprano wrote: >> Perhaps I have been misinformed, but my understanding of C type-casts is >> that (where possible), a cast like `int(var)` merely tells the compiler >> to temporarily disregard the type of var and

Re: Nice way to cast a homogeneous tuple

2010-08-05 Thread Lie Ryan
On Wed, 28 Jul 2010 09:15:24 -0400, wheres pythonmonks wrote: A new python convert is now looking for a replacement for another perl idiom. A functional alternative: l = ... seqint = compose(map, int) print f(seqint(l)) -- http://mail.python.org/mailman/listinfo/python-list

Re: Nice way to cast a homogeneous tuple

2010-08-05 Thread Lie Ryan
On Wed, 28 Jul 2010 15:58:29 +0200, Ulrich Eckhardt wrote: wheres pythonmonks wrote: > Thanks ... I thought int was a type-cast (like in C++) so I assumed I > couldn't reference it. Firstly, "int" is a class. Python doesn't make a distinction between builtin types and class types like C++,

Re: Nice way to cast a homogeneous tuple

2010-07-29 Thread Carl Banks
On Jul 28, 7:45 pm, Steven D'Aprano wrote: > On Wed, 28 Jul 2010 08:47:52 -0700, Carl Banks wrote: > > On Jul 28, 7:32 am, Steven D'Aprano > cybersource.com.au> wrote: > >> On Wed, 28 Jul 2010 09:35:52 -0400, wheres pythonmonks wrote: > >> > Thanks ... I thought int was a type-cast (like in C++)

Re: Nice way to cast a homogeneous tuple

2010-07-29 Thread Steven D'Aprano
On Thu, 29 Jul 2010 09:21:37 +0200, Ulrich Eckhardt wrote: > Steven D'Aprano wrote: >> Perhaps I have been misinformed, but my understanding of C type-casts >> is that (where possible), a cast like `int(var)` merely tells the >> compiler to temporarily disregard the type of var and treat it as if

Re: Nice way to cast a homogeneous tuple

2010-07-29 Thread Ulrich Eckhardt
Steven D'Aprano wrote: > Perhaps I have been misinformed, but my understanding of C type-casts is > that (where possible), a cast like `int(var)` merely tells the compiler > to temporarily disregard the type of var and treat it as if it were an > int. In other words, it's a compiler instruction rat

Re: Nice way to cast a homogeneous tuple

2010-07-28 Thread Steven D'Aprano
On Wed, 28 Jul 2010 22:45:19 -0700, John Nagle wrote: [...] >> if you have an instance of class A, you can do this: >> >> a = A() # make an instance of class A >> a.__class__ = B # tell it that it's now class B >> >> and hope that it won't explode when you try to use it :/ [...] > The main u

Re: Nice way to cast a homogeneous tuple

2010-07-28 Thread John Nagle
On 7/28/2010 7:32 AM, Steven D'Aprano wrote: On Wed, 28 Jul 2010 09:35:52 -0400, wheres pythonmonks wrote: Thanks ... I thought int was a type-cast (like in C++) so I assumed I couldn't reference it. Python doesn't have type-casts in the sense of "tell the compiler to treat object of type A a

Re: Nice way to cast a homogeneous tuple

2010-07-28 Thread Steven D'Aprano
On Wed, 28 Jul 2010 08:47:52 -0700, Carl Banks wrote: > On Jul 28, 7:32 am, Steven D'Aprano cybersource.com.au> wrote: >> On Wed, 28 Jul 2010 09:35:52 -0400, wheres pythonmonks wrote: >> > Thanks ... I thought int was a type-cast (like in C++) so I assumed I >> > couldn't reference it. >> >> Pyth

Re: Nice way to cast a homogeneous tuple

2010-07-28 Thread Carl Banks
On Jul 28, 7:32 am, Steven D'Aprano wrote: > On Wed, 28 Jul 2010 09:35:52 -0400, wheres pythonmonks wrote: > > Thanks ... I thought int was a type-cast (like in C++) so I assumed I > > couldn't reference it. > > Python doesn't have type-casts in the sense of "tell the compiler to > treat object of

Re: Nice way to cast a homogeneous tuple

2010-07-28 Thread Steven D'Aprano
On Wed, 28 Jul 2010 09:35:52 -0400, wheres pythonmonks wrote: > Thanks ... I thought int was a type-cast (like in C++) so I assumed I > couldn't reference it. Python doesn't have type-casts in the sense of "tell the compiler to treat object of type A as type B instead". The closest Python has to

Re: Nice way to cast a homogeneous tuple

2010-07-28 Thread Bruno Desthuilliers
wheres pythonmonks a écrit : Thanks ... I thought int was a type-cast (like in C++) so I assumed I couldn't reference it. Python has no C/C++ like "type-cast". "int" is the builtin integer type, and instanciating an object in Python is done by calling it's type. Remember that in Python, every

Re: Nice way to cast a homogeneous tuple

2010-07-28 Thread Tim Chase
On 07/28/10 08:15, wheres pythonmonks wrote: f( *map(lambda x: int(x), struct.unpack('2s2s2s','123456'))) 102 1. There is a way using unpack to get out string-formatted ints? well, you can use >>> s = '123456' >>> [int(s[i:i+2]) for i in range(0, len(s), 2)] [12, 34, 56] >>> f(*_) 102 While

Re: Nice way to cast a homogeneous tuple

2010-07-28 Thread Ulrich Eckhardt
wheres pythonmonks wrote: > Thanks ... I thought int was a type-cast (like in C++) so I assumed I > couldn't reference it. Hopefully somebody correct me if I explain this badly, but I'll take a shot... Firstly, "int" is a class. Python doesn't make a distinction between builtin types and class t

Re: Nice way to cast a homogeneous tuple

2010-07-28 Thread Hexamorph
wheres pythonmonks wrote: A new python convert is now looking for a replacement for another perl idiom. In particular, since Perl is weakly typed, I used to be able to use unpack to unpack sequences from a string, that I could then use immediately as integers. In python, I find that when I use

Re: Nice way to cast a homogeneous tuple

2010-07-28 Thread wheres pythonmonks
Thanks ... I thought int was a type-cast (like in C++) so I assumed I couldn't reference it. On Wed, Jul 28, 2010 at 9:31 AM, Nick Raptis wrote: > Ep, that missing line should be: > > On 07/28/2010 04:27 PM, Nick Raptis wrote: >> >> On 07/28/2010 04:15 PM, wheres pythonmonks wrote: >>> >>> f( *

Re: Nice way to cast a homogeneous tuple

2010-07-28 Thread Duncan Booth
wheres pythonmonks wrote: > 2. There is something like map(lambda x: int(x) without all the > lambda function call overhead. (e.g., cast tuple)? Yes there is: "lambda x: int(x)" is just a roundabout way of writing "int" -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.

Re: Nice way to cast a homogeneous tuple

2010-07-28 Thread Nick Raptis
Ep, that missing line should be: On 07/28/2010 04:27 PM, Nick Raptis wrote: On 07/28/2010 04:15 PM, wheres pythonmonks wrote: f( *map(lambda x: int(x), struct.unpack('2s2s2s','123456'))) 102 But this seems too complicated. Well, you don't need the lambda at all int ===lambda x: int(x

Re: Nice way to cast a homogeneous tuple

2010-07-28 Thread Nick Raptis
On 07/28/2010 04:15 PM, wheres pythonmonks wrote: f( *map(lambda x: int(x), struct.unpack('2s2s2s','123456'))) 102 But this seems too complicated. Well, you don't need the lambda at all int ===lambda x: int(x) So just write It's like writing: def myint(x): return int(x) Nic

Nice way to cast a homogeneous tuple

2010-07-28 Thread wheres pythonmonks
A new python convert is now looking for a replacement for another perl idiom. In particular, since Perl is weakly typed, I used to be able to use unpack to unpack sequences from a string, that I could then use immediately as integers. In python, I find that when I use struct.unpack I tend to get