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
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
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
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
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++,
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++)
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
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
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
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
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
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
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
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
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
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
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
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( *
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.
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
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
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
22 matches
Mail list logo