colloquial names for types?

Amit Patel amitp at Xenon.Stanford.EDU
Thu Sep 5 12:19:35 EDT 2002


 Inyeol Lee <inyeol_lee at yahoo.com> wrote:
| holger krekel <pyth at devel.trillke.net> wrote in message news:<mailman.1030295978.22776.python-list at python.org>...
| 
| > 
| > I'd try using
| > 
| >     something.__class__.__name__
| 
| Python 2.2.1 (#1, Apr 10 2002, 18:25:16) 
| [GCC 2.95.3 20010315 (release)] on sunos5
| 
| >>> "".__class__.__name__
| 'str'
| >>> [].__class__.__name__
| 'list'
| >>> {}.__class__.__name__
| 'dict'
| >>> 3.__class__.__name__
| SyntaxError: invalid syntax
| >>> dir(3)
| [ ... '__class__', ... ]
| 
| I'm confused. Why 3.__class__ raises exception?

It's a syntax error because  3.  is a valid (float) literal.  So it
gets treated like (3.)__class__, and there's no dot there.

You can either write (3).__class__ or 3..__class__, but the latter is
a float.

  - Amit

-- 
--
Amit J Patel, Computer Science Department, Stanford University
http://www-cs-students.stanford.edu/~amitp/



More information about the Python-list mailing list