Is there anyway, having been passed a file handle, to get the
filename?
I am assuming not, but thought I would ask
|
|
0
|
|
|
|
Reply
|
jldunn2000797 (48)
|
2/17/2009 8:21:38 AM |
|
loial <jldunn2000@googlemail.com> wrote:
> Is there anyway, having been passed a file handle, to get the
> filename?
>
> I am assuming not, but thought I would ask
>
>
If you mean a Python file object then file.name (but it may not exist on
all file objects).
If you mean a system file handle, then which filename would you like? On
many filesystems the file exists independantly from the filenames, so a
single file can have many names or none at all. On Linux you can use
os.fstat() to get the inode number for the file but I think you would have
to scan the relevant directories to find the names associated with the
inode.
--
Duncan Booth http://kupuguy.blogspot.com
|
|
0
|
|
|
|
Reply
|
duncan.booth (1718)
|
2/17/2009 8:55:54 AM
|
|
On Feb 17, 9:21=A0am, loial <jldunn2...@googlemail.com> wrote:
> Is there anyway, having been passed a file handle, to get the
> filename?
>
> I am assuming not, but thought I would ask
If by file handle you mean the object returned by 'file' and 'open'
functions, it has a name attribute.
If by file handle you mean the file descriptor, i.e. the integer used
for low level I/O, then there is no
way I know of. I believe that number is an index in an array of 'file
descriptors' somewhere inside the
C library ( below python interpreter level ), but I don't know if/how
an user program can access it.
Ciao
----
FB
|
|
0
|
|
|
|
Reply
|
bieffe62 (89)
|
2/17/2009 9:15:40 AM
|
|