Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #28107

Re: Beginners question

Date 2012-08-30 08:25 -0400
From Dave Angel <d@davea.name>
Subject Re: Beginners question
References <k1nk8s$3l4$1@speranza.aioe.org>
Newsgroups comp.lang.python
Message-ID <mailman.3965.1346329560.4697.python-list@python.org> (permalink)

Show all headers | View raw


On 08/30/2012 07:54 AM, boltar2003@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.
>

posix.stat_result is a  class, and s is an instance of that class.  You
can see that by typing  type(s).

But you're wondering how print generated all that stuff about the s
instance.  You can start to learn that with dir(s), which shows the
available attributes.  All those attributes that have leading and
trailing double-underscores are called "special attributes," or "special
methods."  In particular notice __str__(), which is  a method provided
for your convenience.  print will call that if it's available, when you
try to print an instance.    It also masquerades as a tuple using
__getitem__() and other special methods.

Normal use of the instance is done by the attributes like   s.st_atime 
and s.st_size, or by using the object as a tuple.  (using the square
brackets to fetch individual items or a range of items)

You can get more documentation directly from s by simply typing  
help(s)  and/or  help(os.stat)

Or you can go to the web docs, http://docs.python.org/library/os.html  
and search downward for os.stat  (this link is currently for Python 2.7.3)

-- 

DaveA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Beginners question boltar2003@boltar.world - 2012-08-30 11:54 +0000
  Re: Beginners question MRAB <python@mrabarnett.plus.com> - 2012-08-30 13:14 +0100
    Re: Beginners question Roy Smith <roy@panix.com> - 2012-08-30 08:23 -0400
    Re: Beginners question boltar2003@boltar.world - 2012-08-30 12:50 +0000
      Re: Beginners question Chris Angelico <rosuav@gmail.com> - 2012-08-30 23:06 +1000
        Re: Beginners question boltar2003@boltar.world - 2012-08-30 13:16 +0000
      Re: Beginners question Dave Angel <d@davea.name> - 2012-08-30 09:23 -0400
      Re: Beginners question Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-08-30 14:30 +0100
      Re: Beginners question Terry Reedy <tjreedy@udel.edu> - 2012-08-30 14:22 -0400
  Re: Beginners question Dave Angel <d@davea.name> - 2012-08-30 08:25 -0400
    Re: Beginners question boltar2003@boltar.world - 2012-08-30 12:53 +0000
  Re: Beginners question Chris Angelico <rosuav@gmail.com> - 2012-08-30 22:32 +1000
  Re: Beginners question Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2012-08-30 14:49 +0200
    Re: Beginners question Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2012-08-30 16:41 +0200
    Re: Beginners question Hans Mulder <hansmu@xs4all.nl> - 2012-08-30 17:38 +0200
  Re: Beginners question charvigroups@gmail.com - 2012-09-04 23:28 -0700
    Re: Beginners question Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-09-05 09:03 +0100
    Re: Beginners question Dave Angel <d@davea.name> - 2012-09-05 09:21 -0400

csiph-web