[Tutor] int("10**6")

2012-08-01 Thread Albert-Jan Roskam
Hi I want the user to be able to specify "10**6" as arguments. How can I cast this string value (it's from sys.argv) to an int value?. Simply doing int("10**6") won't work. The code below works, but seems overly complicated.   import re POW = lambda x, y=1: pow(x, y) convert = lambda n: POW(*map

Re: [Tutor] int("10**6")

2012-08-01 Thread Steven D'Aprano
On Wed, Aug 01, 2012 at 01:37:00AM -0700, Albert-Jan Roskam wrote: > Hi > I want the user to be able to specify "10**6" as arguments. How can I cast > this string value (it's from sys.argv) to an int value?. > Simply doing int("10**6") won't work. The code below works, but seems overly > complic

Re: [Tutor] int("10**6")

2012-08-01 Thread Albert-Jan Roskam
Aaaahhh *slap against forehead*, of course eval! Thanks!! This is perfect for my needs. Regards, Albert-Jan ~~ All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh

[Tutor] __new__ and __init__

2012-08-01 Thread rail shafigulin
Hello everyone. I'm trying to understand how to use the two methods. I know that __new__ is used to create an object, while __init__ to initialize. But I'm not sure what happens when I create an object. I found the following code in the book (Python 3 Object Oriented Programming by Dusty Phillips

Re: [Tutor] __new__ and __init__

2012-08-01 Thread Hugo Arts
On Wed, Aug 1, 2012 at 4:28 PM, rail shafigulin wrote: > Hello everyone. > > I'm trying to understand how to use the two methods. I know that __new__ > is used to create an object, while __init__ to initialize. But I'm not sure > what happens when I create an object. > > I found the following code

Re: [Tutor] __new__ and __init__

2012-08-01 Thread Steven D'Aprano
On 02/08/12 00:28, rail shafigulin wrote: Hello everyone. I'm trying to understand how to use the two methods. I know that __new__ is used to create an object, while __init__ to initialize. But I'm not sure what happens when I create an object. I found the following code in the book (Python 3 O

Re: [Tutor] __new__ and __init__

2012-08-01 Thread Steven D'Aprano
On 02/08/12 01:10, Hugo Arts wrote: * small caveat: I'm entirely unsure of this, but I *think* if you create CarModel with a metaclass that overrides __call__ you can change the way __new__ and __init__ work? If anyone can confirm this, be my guest. Correct. Metaclasses can essentially change

Re: [Tutor] __new__ and __init__

2012-08-01 Thread eryksun
On Wed, Aug 1, 2012 at 11:10 AM, Hugo Arts wrote: > On Wed, Aug 1, 2012 at 4:28 PM, rail shafigulin > > * small caveat: I'm entirely unsure of this, but I *think* if you create > CarModel with a metaclass that overrides __call__ you can change the way > __new__ and __init__ work? If anyone can co