Testing if a variable is an integer or a string; exceptions in __del__

Ben Gertzfield che at debian.org
Sun May 2 14:57:44 EDT 1999


I'm brand spanking new to Python, but I couldn't find an answer to
this in the tutorial or the FAQ.

I'm writing a module to manipulate Id3 tags on mp3 files; I've gotten
it pretty much done, but there are some sections of the code I'm
unsatisfied with, as this is my very first Python code I've written.

My first question is:

What's the best way to test if a variable is numeric or a string?
I'd like to be able to test my Id3 module with some command-line
options, one of which denotes the genre of the file.

The genre can either be an integer from 0 to 254 or a string. As
it is, I'm using

if re.match('^\d+$', options['genre']):

to test if the option is an integer or not. Is this the best way to do
it?

Next:

I'm running Python 1.5.1; it seems that in these later versions, if an
exception is thrown in an object's __del__ method, a warning is
printed to STDOUT. However, this warning is not terribly helpful.

My Id3 class originally had a small bug in it, where a certain value
that the destructor tested would not be initialized if an IOError
exception occurred in the constructor. When it had this bug, a bizarre
looking warning was printed when the __del__ method tried to access
this uninitialized variable:

Exception exceptions.AttributeError: <exceptions.AttributeError
instance at 80cd930> in <method Id3.__del__ of Id3 instance at
80cd738> ignored

Is there any way to get these __del__ exception warnings to be a
little more, well, verbose?

As it is, this completely worthless to me as a debugging tool. I
eventually figured out what my problem was, but it would have been a
lot clearer if it had told me I had an uninitialized variable instead
of an exceptions.AttributeError with a nice message of
<exceptions.AttributeError instance at 80cd930>! It didn't even tell
me what line my problem was on. Sheesh.

Finally:

When this module is done, I'd love to submit it to the Python
community so everyone can have an interface to manipulating Id3 tags
on MP3 files. What's the accepted way of doing this? Is there an
equivalent of Perl's CPAN for Python?

Thanks,

Ben

-- 
Brought to you by the letters E and S and the number 14.
"It's all just a little bit of history repeating."
Debian GNU/Linux maintainer of Gimp and GTK+ -- http://www.debian.org/
I'm on FurryMUCK as Che, and EFNet/Open Projects IRC as Che_Fox.




More information about the Python-list mailing list