NEWBIE: What's the instance name?

John Roth newsgroups at jhrothjr.com
Sun Dec 28 22:03:04 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':
>         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?
>
> 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"
>
> Thanks in advane....Norm

Instances don't have names. They do have IDs, though, which are
the memory address of the instance objects in the
C Python implementation. See the built-in function id().

John Roth






More information about the Python-list mailing list