timedelta is squicking me out

P

Phlip

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!)
 
W

Wong Wah Meng-R32813

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
 
S

Steven D'Aprano

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!
 
C

Chris Rebert

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
 
W

Wong Wah Meng-R32813

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

Regards,
Wah Meng

-----Original Message-----
From: (e-mail address removed) [mailto:[email protected]] On Behalf Of Chris Rebert
Sent: Monday, October 03, 2011 3:46 PM
To: Wong Wah Meng-R32813
Cc: (e-mail address removed)
Subject: Re: Python Migration Error: TypeError: exceptions must be old-style classes 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 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
 
W

Wong Wah Meng-R32813

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: [email protected] [mailto:p[email protected]] On Behalf Of Steven D'Aprano
Sent: Monday, October 03, 2011 3:44 PM
To: (e-mail address removed)
Subject: Re: Python Migration Error: 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

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!
 
G

Gregory Ewing

Wong said:
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.
 
R

rusi

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.
 
8

88888 dihedral

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.
 
8

88888 dihedral

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.
 
T

Terry Reedy

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top