Getting a path from a file object

Michael Mabin d3vvnull at gmail.com
Fri Jul 4 21:18:09 CEST 2008


f.name will return the path.  But if you want to guarantee getting the
absolute pathname use os.path.abspath

>>> import os
>>> os.path.abspath(f.name)
'/some/path/file.ext'


On Fri, Jul 4, 2008 at 1:37 PM, Andrew Fong <FongAndrew at gmail.com> wrote:

> Newbie question:
>
> Let's say I open a new file for writing in a certain path. How do I
> get that path back?
>
> Example:
>
> >>> f = open('/some/path/file.ext')
> >>> some_function(f)
> '/some/path/file.ext'
>
> Does some_function(f) already exist? And if not, how would I define
> it?
>
> -- Andrew
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
| _ | * | _ |
| _ | _ | * |
| * | * | * |
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080704/422631d8/attachment.html>


More information about the Python-list mailing list