Mailing List Archive

Dreaded Newbie Question
Hi!

A newbie to Python (though currently coding in Delphi), I'm having a
little difficulty tracking down stuff, although I have the tutorial and
manuals. Where is the best place to get more info, and why is there no
newsgroup for newbies like myself?

For the moment though my grateful thanks goes to anyone who can tell me
how to get a file's size, and where that info is to be found in the
references.

BTW, I'm running PythonWin 1.5.1
--

Dani Epstein
Dreaded Newbie Question [ In reply to ]
This group is as good for newbies as anyone else, IMO, but I believe
that there is also a Python "newbie" list. Also, many common questions
really are answered in the FAQ.

As to your question, I'm really not 100% sure about the "right" way to
do it, but look at the stat function under
http://www.python.org/doc/current/lib/os-file-dir.html for a good
start. Generally the lib documentation is the best place to start
looking for any stuff like this. In this particular case you would have
been looking for section 6.1, "Miscellaneous OS interfaces".

Enjoy!

----
Jess
http://ww.biddin.com/pyPit/

Dani Epstein wrote:
>
> Hi!
>
> A newbie to Python (though currently coding in Delphi), I'm having a
> little difficulty tracking down stuff, although I have the tutorial and
> manuals. Where is the best place to get more info, and why is there no
> newsgroup for newbies like myself?
>
> For the moment though my grateful thanks goes to anyone who can tell me
> how to get a file's size, and where that info is to be found in the
> references.
>
> BTW, I'm running PythonWin 1.5.1
> --
>
> Dani Epstein
Dreaded Newbie Question [ In reply to ]
In article <K4tK+KAA26l3EwvK@epstein.co.uk>,
Dani Epstein <spamkiller@epstein.co.uk> wrote:
>
>A newbie to Python (though currently coding in Delphi), I'm having a
>little difficulty tracking down stuff, although I have the tutorial and
>manuals. Where is the best place to get more info, and why is there no
>newsgroup for newbies like myself?

There's a mailing list. Look on www.python.org for the "tutor list".

>For the moment though my grateful thanks goes to anyone who can tell me
>how to get a file's size, and where that info is to be found in the
>references.

Should be os.stat().
--
--- Aahz (@netcom.com)

Androgynous poly kinky vanilla queer het <*> http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6 (if you want to know, do some research)
Dreaded Newbie Question [ In reply to ]
Dani Epstein wrote:
>
> Hi!
>
> A newbie to Python (though currently coding in Delphi), I'm having a
> little difficulty tracking down stuff, although I have the tutorial and
> manuals. Where is the best place to get more info, and why is there no
> newsgroup for newbies like myself?
>
> For the moment though my grateful thanks goes to anyone who can tell me
> how to get a file's size, and where that info is to be found in the
> references.
>
> BTW, I'm running PythonWin 1.5.1
> --
>
> Dani Epstein

Use os.stat to get a tuple of information about the file. The item at
index 6 (symbolically stat.ST_SIZE) is the size in bytes. The value is
an integer (or a long integer) depending on the particular os.

>>> import os, stat
>>> os.stat('.login')
(33188, 30804640L, 33554464, 1, 27117, 20, 620L, 932451656, 797807295,
925402414)
>>> os.stat('.login')[stat.ST_SIZE]
620L

Documentation is in the "Module os" section.

--
Dr. Gary Herron <gherron@aw.sgi.com>
206-287-5616
Alias | Wavefront
1218 3rd Ave, Suite 800, Seattle WA 98101
Dreaded Newbie Question [ In reply to ]
[Dani Epstein]
[skipping questions well-answered already]
> ...
> For the moment though my grateful thanks goes to anyone who can tell me
> how to get a file's size, and where that info is to be found in the
> references.
>
> BTW, I'm running PythonWin 1.5.1

First download 1.5.2 (1.5.1 is more than a year old, and in ways that count
<wink>).

After that, ignore all the "os.stat" stuff you've been hearing and use

os.path.getsize(filepath)

Or use os.stat if you're more comfortable with obscurity <wink>.

&-keep-a-printout-of-the-library-manual-next-to-the-toilet-ly y'rs - tim
Dreaded Newbie Question [ In reply to ]
From: "Tim Peters" <tim_one@email.msn.com>
Subject: RE: Dreaded Newbie Question

[Dani Epstein]
[skipping questions well-answered already]
> ...
> For the moment though my grateful thanks goes to anyone who can tell me
> how to get a file's size, and where that info is to be found in the
> references.
>
> BTW, I'm running PythonWin 1.5.1

First download 1.5.2 (1.5.1 is more than a year old, and in ways that count
<wink>).

After that, ignore all the "os.stat" stuff you've been hearing and use

os.path.getsize(filepath)

Or use os.stat if you're more comfortable with obscurity <wink>.

&-keep-a-printout-of-the-library-manual-next-to-the-toilet-ly y'rs - tim




--
|Fidonet: UUCP 2:500/3.1
|Internet: UUCP@p1.f3.n500.z2.hccfido.hcc.nl
|
| Standard disclaimer: The views of this user are strictly his own.
Dreaded Newbie Question [ In reply to ]
Dani Epstein wrote:
>
> BTW, I'm running PythonWin 1.5.1

Everybody seems to have missed this. To find a lot of the os
stuff under 1.5.1, you had to look in the docs under the the
particular implementation for your platform: ntpath, posixpath etc.

This has been greatly improved in the recent docs.

- Gordon
Dreaded Newbie Question [ In reply to ]
In article <000701bed4bb$20388360$2c2d2399@tim>, Tim Peters
<tim_one@email.msn.com> writes
>First download 1.5.2 (1.5.1 is more than a year old, and in ways that count
><wink>).

Shall do.

>&-keep-a-printout-of-the-library-manual-next-to-the-toilet-ly y'rs - tim

My throne room is already overflowing with a variety of excellent
documentation that I print out on 40 gsm paper so that it can be reused
once read. Um.

What I have found in the docs at hand (oh dear) is that there is a
definite unix bias to them, which I suppose is understandable, but makes
life terribly complicated for us Windoze fellows (and fellowettes of
course).

I presume this has changed in the latest docs.

Thanks to all for your replies. This adventure looks like its going to
mean good company as well as fun!
--

Dani Epstein
Dreaded Newbie Question [ In reply to ]
Oh wow. I can actually answer one ;-)

I use: fiSize = os.stat(pathin)[6] #...where pathin is full path to
file.

...and:

stat (path) = Perform a stat system call on the given path. The return
value is a tuple of at least 10 integers giving the most important (and
portable) members of the stat structure, in the order st_mode, st_ino,
st_dev, st_nlink, st_uid, st_gid, st_size, st_atime, st_mtime, st_ctime.
More items may be added at the end by some implementations. (On MS-DOS,
some items are filled with dummy values.)

...as found on /python/doc/lib/node105.html



Dani Epstein wrote:

> Hi!
>
> A newbie to Python (though currently coding in Delphi), I'm having a
> little difficulty tracking down stuff, although I have the tutorial and
> manuals. Where is the best place to get more info, and why is there no
> newsgroup for newbies like myself?
>
> For the moment though my grateful thanks goes to anyone who can tell me
> how to get a file's size, and where that info is to be found in the
> references.
>
> BTW, I'm running PythonWin 1.5.1
> --
>
> Dani Epstein
Dreaded Newbie Question [ In reply to ]
[Dani Epstein]
> ...
> What I have found in the docs at hand (oh dear) is that there is a
> definite unix bias to them, which I suppose is understandable, but makes
> life terribly complicated for us Windoze fellows (and fellowettes of
> course).
>
> I presume this has changed in the latest docs.

It's a little less Unix-centric now, but that does go deep. Python was
first written on a Mac! Which is why Unix shows through everywhere <wink>.

It's not really Unix at work here so much as C: The std C library + POSIX
define the only vaguely portable "system level" API there is. Only MS
implements the Win32 API, and only Apple the Mac API. So you go with
C/POSIX and look like Unix, mimic someone else's and get sued, or invent
your own API and scare *everyone* away <0.7 wink>.

> Thanks to all for your replies. This adventure looks like its going to
> mean good company as well as fun!

I found both to be true. Let us know when you get stuck.

c.l.py-is-open-24-hours-a-day-ly y'rs - tim
Dreaded Newbie Question [ In reply to ]
In article <000701bed723$82f0d100$492d2399@tim>, Tim Peters
<tim_one@email.msn.com> writes
>It's a little less Unix-centric now, but that does go deep. Python was
>first written on a Mac! Which is why Unix shows through everywhere <wink>.

How marvellously straightforward this whole computing thing is.

>> Thanks to all for your replies. This adventure looks like its going to
>> mean good company as well as fun!
>
>I found both to be true. Let us know when you get stuck.

I most certainly will - thanks once again.
--

Dani Epstein