Re: Still the __new__ hell ...

2007-03-23 Thread Paulo da Silva
Gabriel Genellina escreveu: > En Wed, 21 Mar 2007 07:51:32 -0300, Bruno Desthuilliers > <[EMAIL PROTECTED]> escribió: > >> Paulo da Silva a écrit : >>> As a relatively inexperient >>> in python, how could I know that a 'string' is an instance of >>> basestring? >> >> By reading this newsgroup ?-)

Re: Still the __new__ hell ...

2007-03-22 Thread Gabriel Genellina
En Wed, 21 Mar 2007 07:51:32 -0300, Bruno Desthuilliers <[EMAIL PROTECTED]> escribió: > Paulo da Silva a écrit : >> As a relatively inexperient >> in python, how could I know that a 'string' is an instance of >> basestring? > > By reading this newsgroup ?-) Or asking Python itself: >>> type("a

Re: Still the __new__ hell ...

2007-03-21 Thread Duncan Booth
Paulo da Silva <[EMAIL PROTECTED]> wrote: > As a relatively inexperient > in python, how could I know that a 'string' is an instance of > basestring? I think a good tip for anyone learning Python (or upgrading from an earlier version) is to do: dir(__builtins__) at the interactive prompt a

Re: Still the __new__ hell ...

2007-03-21 Thread Bruno Desthuilliers
Paulo da Silva a écrit : > Bruno Desthuilliers escreveu: >> Paulo da Silva a écrit : > ... > >>> class MyDate(date): >>> def __new__(cls,year,month=None,day=None): >>> if type(year) is str: >> And what if it's a unicode string ? >> The correct idiom here is: >> if isin

Re: Still the __new__ hell ...

2007-03-20 Thread Alex Martelli
Aahz <[EMAIL PROTECTED]> wrote: > In article <[EMAIL PROTECTED]>, > Alex Martelli <[EMAIL PROTECTED]> wrote: > >Steve Holden <[EMAIL PROTECTED]> wrote: > >> > >> basestring is a *type*. > >> > >> >>> basestring > >> > >> > >> It's the base class of which both str and unicode are subclasses.

Re: Still the __new__ hell ...

2007-03-20 Thread Gabriel Genellina
En Tue, 20 Mar 2007 10:16:30 -0300, Aahz <[EMAIL PROTECTED]> escribió: > In article <[EMAIL PROTECTED]>, > Alex Martelli <[EMAIL PROTECTED]> wrote: >> Steve Holden <[EMAIL PROTECTED]> wrote: >>> >>> basestring is a *type*. >> >> I believe it used to be a tuple back in Python 2.2 (sorry, don't have

Re: Still the __new__ hell ...

2007-03-20 Thread Aahz
In article <[EMAIL PROTECTED]>, Alex Martelli <[EMAIL PROTECTED]> wrote: >Steve Holden <[EMAIL PROTECTED]> wrote: >> >> basestring is a *type*. >> >> >>> basestring >> >> >> It's the base class of which both str and unicode are subclasses. > >I believe it used to be a tuple back in Python 2.2

Re: Still the __new__ hell ...

2007-03-19 Thread greg
Steve Holden wrote: > >>> basestring > You're right, I'm not sure what made me think it was a tuple. Maybe because people used to write isinstance(x, (str, unicode)) before basestring existed. -- Greg -- http://mail.python.org/mailman/listinfo/python-list

Re: Still the __new__ hell ...

2007-03-19 Thread Alex Martelli
Steve Holden <[EMAIL PROTECTED]> wrote: > greg wrote: > > Paulo da Silva wrote: > >> As a relatively inexperient > >> in python, how could I know that a 'string' is an instance of > >> basestring? > > > >isinstance(x, basestring) > > > > This works because basestring is defined as the > > tu

Re: Still the __new__ hell ...

2007-03-19 Thread Steve Holden
greg wrote: > Paulo da Silva wrote: >> As a relatively inexperient >> in python, how could I know that a 'string' is an instance of >> basestring? > >isinstance(x, basestring) > > This works because basestring is defined as the > tuple (str, unicode) and isinstance accepts a > tuple of types

Re: Still the __new__ hell ...

2007-03-19 Thread greg
Paulo da Silva wrote: > As a relatively inexperient > in python, how could I know that a 'string' is an instance of > basestring? isinstance(x, basestring) This works because basestring is defined as the tuple (str, unicode) and isinstance accepts a tuple of types as well as just a single type

Re: Still the __new__ hell ...

2007-03-19 Thread Paulo da Silva
Bruno Desthuilliers escreveu: > Paulo da Silva a écrit : ... >> class MyDate(date): >> def __new__(cls,year,month=None,day=None): >> if type(year) is str: > > And what if it's a unicode string ? > The correct idiom here is: > if isinstance(year, basestring): > Than

Re: Still the __new__ hell ...

2007-03-19 Thread Jean-Paul Calderone
On Mon, 19 Mar 2007 15:39:49 +0100, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: >Jean-Paul Calderone a écrit : >> On Mon, 19 Mar 2007 13:17:11 +0100, Bruno Desthuilliers >>> >>> [snip] >>> >>> And what if it's a unicode string ? >>> The correct idiom here is: >>> if isinstance(

Re: Still the __new__ hell ...

2007-03-19 Thread Bruno Desthuilliers
Jean-Paul Calderone a écrit : > On Mon, 19 Mar 2007 13:17:11 +0100, Bruno Desthuilliers >> >> [snip] >> >> And what if it's a unicode string ? >> The correct idiom here is: >> if isinstance(year, basestring): >> >>> year,month,day=map(int,string.split(year,'-')) >>

Re: Still the __new__ hell ...

2007-03-19 Thread Jean-Paul Calderone
On Mon, 19 Mar 2007 13:17:11 +0100, Bruno Desthuilliers > > [snip] > >And what if it's a unicode string ? >The correct idiom here is: > if isinstance(year, basestring): > >> year,month,day=map(int,string.split(year,'-')) > year, month,

Re: Still the __new__ hell ...

2007-03-19 Thread Bruno Desthuilliers
Paulo da Silva a écrit : (snip) Not an answer to your question, just a couple advices: > from datetime import date > import cPickle,string The string module is mostly deprecated. You should use str type methods whenever possible (cf below) > class MyDate(date): > def __new__(cls,year,mon

Re: Still the __new__ hell ...

2007-03-18 Thread Paulo da Silva
Arnaud Delobelle escreveu: > On Mar 17, 11:48 pm, Paulo da Silva <[EMAIL PROTECTED]> wrote: >> Arnaud Delobelle escreveu:> On Mar 17, 9:31 pm, Paulo da Silva <[EMAIL >> PROTECTED]> wrote: > > [snip] > >> Thanks. This works exactly the way you wrote. >> Yet I am misunderstanding something. Can't

Re: Still the __new__ hell ...

2007-03-18 Thread Arnaud Delobelle
On Mar 17, 11:48 pm, Paulo da Silva <[EMAIL PROTECTED]> wrote: > Arnaud Delobelle escreveu:> On Mar 17, 9:31 pm, Paulo da Silva <[EMAIL > PROTECTED]> wrote: [snip] > Thanks. This works exactly the way you wrote. > Yet I am misunderstanding something. Can't pickle "see" that being > MyDate derive

Re: Still the __new__ hell ...

2007-03-17 Thread Paulo da Silva
Arnaud Delobelle escreveu: > On Mar 17, 9:31 pm, Paulo da Silva <[EMAIL PROTECTED]> wrote: ... >> I used __new__ to >> subclass date class but now cPickle/pickle loads >> does not work. >> >> from datetime import date >> import cPickle,string >> >> class MyDate(date): >> def __new__(cls,ye

Re: Still the __new__ hell ...

2007-03-17 Thread Paul McGuire
On Mar 17, 4:31 pm, Paulo da Silva <[EMAIL PROTECTED]> wrote: > Sorry to put here too many questions about __init__ __new__ > stuff but I always found a new problem when using them. > I have searched for simple __new__ docs on how to do the > basic things but find none. > > After trying the solutio

Re: Still the __new__ hell ...

2007-03-17 Thread Arnaud Delobelle
On Mar 17, 9:31 pm, Paulo da Silva <[EMAIL PROTECTED]> wrote: > Sorry to put here too many questions about __init__ __new__ > stuff but I always found a new problem when using them. > I have searched for simple __new__ docs on how to do the > basic things but find none. > > After trying the solutio

Still the __new__ hell ...

2007-03-17 Thread Paulo da Silva
Sorry to put here too many questions about __init__ __new__ stuff but I always found a new problem when using them. I have searched for simple __new__ docs on how to do the basic things but find none. After trying the solutions people gently posted here (thanks) I run into new trouble when I go wi