NEWBIE: What's the instance name?

Dan Bishop danb_83 at yahoo.com
Mon Dec 29 03:36:09 EST 2003


engsolnom at ipns.com wrote in message news:<6q2vuv45lsah3epo9loa7l2tp9517makk4 at 4ax.com>...
> Hi,
> I've been using constructs(?) like the below.
> 
> def display(instance, start = None, end = None):
>     if instance.__class__.__name__ == 'UPCA':

You might want to try the isinstance function.

>         do some UPCA stuff
>     if instance.__class__.__name__ == 'UPCE':
>         do some UPCE stuff
> 
> launched by:
> 
> lx = UPCA(sx), where sx is a string
> then:
> display(lx)
> 
> This all works well.
> 
> What I'd like to do is display is the instance name. Is it hiding
> somewhere?

You mean you'd like display(lx) to print "lx"?

What would you expect the folowing code to do?

a = b = MyClass()
display(a)      # "a" or "b"?
display(a + b)  # Creates an instance without a name.
display(2)      # Literals have no names either.

Now do you see why the functionality you want isn't implemented?
 
> Also, if I have a string 4 chars long, representing two bytes of hex,
> how can I *validate* the string as a *legal* hex string?
> 
> isdigit works until string = '001A', for example
> isalnum works, but then allows 'foob'
> 
> Is there a 'ishexdigit'? I could parse the string, but that seems
> "un-Pythonish"

Unfortunately, no, but you can use "ch in string.hexdigits", at least
until Python 3.0 (or whenever the string module is going away).




More information about the Python-list mailing list