Beginners question

boltar2003 at boltar.world boltar2003 at boltar.world
Thu Aug 30 08:50:41 EDT 2012


On Thu, 30 Aug 2012 13:14:57 +0100
MRAB <python at mrabarnett.plus.com> wrote:
>On 30/08/2012 12:54, boltar2003 at boltar.world wrote:
>> Hello
>>
>> I'm slowly teaching myself python so apologies if this is a dumb question.
>> but something has confused me with the os.stat() function:
>>
>>>>> s = os.stat(".")
>>>>> print s
>> posix.stat_result(st_mode=16877, st_ino=2278764L, st_dev=2053L, st_nlink=2,
>st_u
>> id=1000, st_gid=100, st_size=4096L, st_atime=1346327745,
>st_mtime=1346327754, st
>> _ctime=1346327754)
>>
>> What sort of object is posix.stat_result? Its not a dictionary or list or a
>> class object as far as I can tell. Thanks for any help.
>>
>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.

>>> s = os.stat(".")
>>> print s
posix.stat_result(st_mode=16877, st_ino=2278764L, st_dev=2053L, st_nlink=2, st_u
id=1000, st_gid=100, st_size=4096L, st_atime=1346327745, st_mtime=1346327754, st
_ctime=1346327754)
>>> type(s) 
<type 'posix.stat_result'>

Which isn't terrible helpful.

>In other words, it's an instance of the class "stat_result" as defined
>in the file "posix.py".

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'>

B2003




More information about the Python-list mailing list