Beginners question

Chris Angelico rosuav at gmail.com
Thu Aug 30 09:06:34 EDT 2012


On Thu, Aug 30, 2012 at 10:50 PM,  <boltar2003 at boltar.world> wrote:
> On Thu, 30 Aug 2012 13:14:57 +0100
> MRAB <python at mrabarnett.plus.com> wrote:
>>What don't you ask Python? I'm sure you'' get something like this:
>>
>> >>> type(s)
>><class 'posix.stat_result'>
>
> Umm , no I don't.
>
>>>> type(s)
> <type 'posix.stat_result'>
>
> Which isn't terrible helpful.

That's actually the same thing, except for a slight difference between
Python 2 and Python 3.

> If its a class , why is it when I create my own class I get a completely
> different output with print and type?
>
>>>>
>>>> class foo(object):
> ..     def __init__(self):
> ..             pass
> ..
>>>> f=foo()
>>>> print f
> <__main__.foo object at 0xb743956c>
>>>> type(f)
> <class '__main__.foo'>

Yep, you're using Python 2. A few things are subtly different. Unless
you have good reason not to, do consider moving to Python 3; all sorts
of things are easier. Python 2 is basically not being developed any
more.

http://www.python.org/dev/peps/pep-0404/

Alternatively, accept that what people are going to quote to you here
may be slightly different from what you see.

In any case, Python's introspection facilities and help() features are
available on both branches, so most of what has been said in this
thread still applies.

ChrisA



More information about the Python-list mailing list