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

Ben Gertzfield che at debian.org
Sun May 2 20:11:14 EDT 1999


>>>>> "Tim" == Tim Peters <tim_one at email.msn.com> writes:

    Ben> What's the best way to test if a variable is numeric or a string?
    Ben> if re.match('^\d+$', options['genre']):

    Tim> It's *a* way to do it.  Does something about it bother you?

No, I was just wondering if there was a more standard Pythonesque
way of doing it.

It seems like a rather common thing to do, is why I asked. :) 

I guess my way works fine. I was thinking in Perl terms, which
ended up working well.

    Tim> "exception ignored" msgs are unique to exceptions raised at
    Tim> system shutdown time, when the order of module content
    Tim> destruction can't magically ensure that whatever the heck you
    Tim> happen to reference in your __del__ methods still exists at
    Tim> the time __del__ is called.  Since the system is shutting
    Tim> down, it has no choice but to ignore these exceptions and
    Tim> carry on regardless.

Ah, okay. So what I should have done was put the work done by __del__
in another function and tested that *before* system shutdown time.

Makes sense. Although I wish the messages were just a tiny bit more
helpful!

    Ben> When this module is done, I'd love to submit it to the Python
    Ben> community so everyone can have an interface to manipulating Id3 tags
    Ben> on MP3 files.

    Tim> Get familiar with

    Tim> http://www.python.org/download/Contributed.html
    Tim> and
    Tim> http://www.python.org/ftp/python/contrib/

Okay. Too bad there isn't a more organized way of doing it.

Thanks!

Ben

-- 
Brought to you by the letters Y and A and the number 1.
"Two thousand people in a seething, roaring, shouting mass."
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