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