timedelta is squicking me out

Discussion in 'Python' started by Phlip, Oct 3, 2011.

  1. Phlip

    Phlip Guest

    has anyone invented a system like R*by's ActiveSupport's 5.years.ago,
    42.minutes.since ?

    (Yes, I'm aware the notation will be different!)

    --
    Phlip
    http://zeekland.zeroplayer.com/
     
    Phlip, Oct 3, 2011
    #1
    1. Advertising

  2. Phlip

    Chris Rebert Guest

    Chris Rebert, Oct 3, 2011
    #2
    1. Advertising

  3. Python Migration Error: TypeError: exceptions must be old-styleclasses or derived from BaseException, not str

    Hello guys,

    I am migrating my application from python 1.5.2 to 2.7.1. I encountered an error when I run some commands (I put in debug statement however, not able to trace down to which line of code that cause it to generate a lot of messages in one second until my hard disk space is full. The error log I got inmy log file is as below:-

    Oct 3 14:12:41 ('Encountered exception while processing from', (0, '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'), <type 'exceptions.TypeError'>, TypeError('exceptions must be old-style classes or derived from BaseException, not str',))

    Does it mean in newer python I need to migrate all my Exception to non-string based exception type? That's should be a lot of changes. :p

    Regards,
    Wah Meng
     
    Wong Wah Meng-R32813, Oct 3, 2011
    #3
  4. Re: Python Migration Error: TypeError: exceptions must be old-styleclasses or derived from BaseException, not str

    On Mon, 03 Oct 2011 06:45:25 +0000, Wong Wah Meng-R32813 wrote:


    > Does it mean in newer python I need to migrate all my Exception to
    > non-string based exception type? That's should be a lot of changes. :p


    Yes.

    Python 1.5 is very old. It's over 11 years old.

    You might find it easier to first migrate to Python 2.5, where string
    exceptions are still legal and only generate a warning, and then migrate
    to 2.7.

    Good luck!




    --
    Steven
     
    Steven D'Aprano, Oct 3, 2011
    #4
  5. Phlip

    Chris Rebert Guest

    Re: Python Migration Error: TypeError: exceptions must be old-styleclasses or derived from BaseException, not str

    On Sun, Oct 2, 2011 at 11:45 PM, Wong Wah Meng-R32813
    <> wrote:
    > Hello guys,
    >
    > I am migrating my application from python 1.5.2 to 2.7.1. I encountered an error when I run some commands (I put in debug statement however, not able to trace down to which line of code that cause it to generate a lot of messages in one second until my hard disk space is full. The error log I got in my log file is as below:-
    >
    > Oct  3 14:12:41  ('Encountered exception while processing from', (0, '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'), <type 'exceptions.TypeError'>, TypeError('exceptions must be old-style classes or derived from BaseException, not str',))
    >
    > Does it mean in newer python I need to migrate all my Exception to non-string based exception type?


    Correct. You can no longer do merely `raise "Some error message"`. You
    should instead raise an exception instance of the appropriate type;
    e.g. `raise ValueError("foo must be positive")`.
    It's advisable to read the NEWS / "What's New" documents for the
    intervening versions so you can learn what else has changed.

    > That's should be a lot of changes. :p


    To be fair, v1.5.2 is practically ancient at this point. It's over a
    decade old! And 2 *major* versions behind what's current.
    In a pinch, you could always write a script to mechanically change
    `raise "..."` to `raise StandardError("...")` [or some other fairly
    generic exception type].

    Cheers,
    Chris
     
    Chris Rebert, Oct 3, 2011
    #5
  6. RE: Python Migration Error: TypeError: exceptions must be old-styleclasses or derived from BaseException, not str

    Noted. No choice then, I will convert all my raise statement to use the exception instance. Thanks!

    Regards,
    Wah Meng

    -----Original Message-----
    From: [mailto:] On Behalf Of Chris Rebert
    Sent: Monday, October 03, 2011 3:46 PM
    To: Wong Wah Meng-R32813
    Cc:
    Subject: Re: Python Migration Error: TypeError: exceptions must be old-style classes or derived from BaseException, not str

    On Sun, Oct 2, 2011 at 11:45 PM, Wong Wah Meng-R32813
    <> wrote:
    > Hello guys,
    >
    > I am migrating my application from python 1.5.2 to 2.7.1. I encountered an error when I run some commands (I put in debug statement however, not able to trace down to which line of code that cause it to generate a lot of messages in one second until my hard disk space is full. The error log I got in my log file is as below:-
    >
    > Oct  3 14:12:41  ('Encountered exception while processing from', (0, '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'), <type 'exceptions.TypeError'>, TypeError('exceptions must be old-style classes or derivedfrom BaseException, not str',))
    >
    > Does it mean in newer python I need to migrate all my Exception to non-string based exception type?


    Correct. You can no longer do merely `raise "Some error message"`. You
    should instead raise an exception instance of the appropriate type;
    e.g. `raise ValueError("foo must be positive")`.
    It's advisable to read the NEWS / "What's New" documents for the
    intervening versions so you can learn what else has changed.

    > That's should be a lot of changes. :p


    To be fair, v1.5.2 is practically ancient at this point. It's over a
    decade old! And 2 *major* versions behind what's current.
    In a pinch, you could always write a script to mechanically change
    `raise "..."` to `raise StandardError("...")` [or some other fairly
    generic exception type].

    Cheers,
    Chris
     
    Wong Wah Meng-R32813, Oct 3, 2011
    #6
  7. RE: Python Migration Error: TypeError: exceptions must be old-styleclasses or derived from BaseException, not str

    I see. Thanks for the tips. If I run out of time I shall consider only using 2.5.

    Regards,
    Wah Meng

    -----Original Message-----
    From: python-list-bounces+wahmeng= [mailto:python-list-bounces+wahmeng=] On Behalf Of Steven D'Aprano
    Sent: Monday, October 03, 2011 3:44 PM
    To:
    Subject: Re: Python Migration Error: TypeError: exceptions must be old-style classes or derived from BaseException, not str

    On Mon, 03 Oct 2011 06:45:25 +0000, Wong Wah Meng-R32813 wrote:


    > Does it mean in newer python I need to migrate all my Exception to
    > non-string based exception type? That's should be a lot of changes. :p


    Yes.

    Python 1.5 is very old. It's over 11 years old.

    You might find it easier to first migrate to Python 2.5, where string
    exceptions are still legal and only generate a warning, and then migrate
    to 2.7.

    Good luck!




    --
    Steven
    --
    http://mail.python.org/mailman/listinfo/python-list
     
    Wong Wah Meng-R32813, Oct 3, 2011
    #7
  8. Re: Python Migration Error: TypeError: exceptions must be old-styleclasses or derived from BaseException, not str

    Wong Wah Meng-R32813 wrote:

    > I am migrating my application from python 1.5.2 to 2.7.1.


    > Does it mean in newer python I need to migrate all my Exception to
    > non-string based exception type? That's should be a lot of changes. :p


    'Fraid so. You are leaping quite a lot of versions at once,
    and string exceptions have been considered passe for a *long*
    time. They may already have been deprecated in 1.5, I'm
    not sure.

    Note that in Python 3 the condition is even stricter -- old
    style classes are gone, and exceptions must derive from
    BaseException or some other existing exception type. So you'd
    best do that now for the sake of easing migration to Python 3
    in the future.

    --
    Greg
     
    Gregory Ewing, Oct 3, 2011
    #8
  9. Phlip

    Roy Smith Guest

    Roy Smith, Oct 3, 2011
    #9
  10. Phlip

    rusi Guest

    Re: Python Migration Error: TypeError: exceptions must be old-styleclasses or derived from BaseException, not str

    On Oct 3, 12:45 pm, Chris Rebert <> wrote:
    > On Sun, Oct 2, 2011 at 11:45 PM, Wong Wah Meng-R32813
    >
    > <> wrote:
    > > Hello guys,

    >
    > > I am migrating my application from python 1.5.2 to 2.7.1. I encounteredan error when I run some commands (I put in debug statement however, not able to trace down to which line of code that cause it to generate a lot of messages in one second until my hard disk space is full. The error log I got in my log file is as below:-

    >
    > > Oct  3 14:12:41  ('Encountered exception while processing from', (0, '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'), <type 'exceptions.TypeError'>, TypeError('exceptions must be old-style classes or derived from BaseException, not str',))

    >
    > > Does it mean in newer python I need to migrate all my Exception to non-string based exception type?

    >
    > Correct. You can no longer do merely `raise "Some error message"`. You
    > should instead raise an exception instance of the appropriate type;
    > e.g. `raise ValueError("foo must be positive")`.
    > It's advisable to read the NEWS / "What's New" documents for the
    > intervening versions so you can learn what else has changed.
    >
    > > That's should be a lot of changes. :p

    >
    > To be fair, v1.5.2 is practically ancient at this point. It's over a
    > decade old! And 2 *major* versions behind what's current.
    > In a pinch, you could always write a script to mechanically change
    > `raise "..."` to `raise StandardError("...")` [or some other fairly
    > generic exception type].
    >
    > Cheers,
    > Chris


    I wonder whether 2to3 could help directly or else have a hook to do
    this semi-automatically?

    NOTE: I am not advocating going straight to python 3, just using
    (parts of) the 2to3 'fixes' to aid migration.
     
    rusi, Oct 4, 2011
    #10
  11. Re: Python Migration Error: TypeError: exceptions must be old-styleclasses or derived from BaseException, not str

    I am thinking with the power of python evolving in different versions, if afeature is not desired in the new version, then the new version could alsoprovide some script tools, of course in python, to convert codes in old styles into new styles automatically.
     
    88888 dihedral, Oct 10, 2011
    #11
  12. Re: Python Migration Error: TypeError: exceptions must be old-styleclasses or derived from BaseException, not str

    I am thinking with the power of python evolving in different versions, if afeature is not desired in the new version, then the new version could alsoprovide some script tools, of course in python, to convert codes in old styles into new styles automatically.
     
    88888 dihedral, Oct 10, 2011
    #12
  13. Phlip

    Terry Reedy Guest

    Re: Python Migration Error: TypeError: exceptions must be old-styleclasses or derived from BaseException, not str

    On 10/10/2011 11:13 AM, 88888 dihedral wrote:
    > I am thinking with the power of python evolving in different
    > versions, if a feature is not desired in the new version, then the
    > new version could also provide some script tools, of course in
    > python, to convert codes in old styles into new styles
    > automatically.


    That is what the 2to3 script does. It could use some updating. A 3to2
    script using the same tools is available somewhere. Someone could write
    a 32to33 script for the few things removed in 3.3.

    --
    Terry Jan Reedy
     
    Terry Reedy, Oct 10, 2011
    #13
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Christos TZOTZIOY Georgiou
    Replies:
    3
    Views:
    743
    Christos TZOTZIOY Georgiou
    Sep 13, 2003
  2. Tim Peters
    Replies:
    0
    Views:
    580
    Tim Peters
    Sep 9, 2003
  3. Wil Schultz

    Creating a timedelta counter...

    Wil Schultz, Jul 20, 2004, in forum: Python
    Replies:
    2
    Views:
    436
    Wil Schultz
    Jul 23, 2004
  4. josh
    Replies:
    0
    Views:
    320
  5. time + timedelta

    , Feb 7, 2005, in forum: Python
    Replies:
    0
    Views:
    351
Loading...

Share This Page