Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

Getting a path from a file object

Question posted by: Andrew Fong (Guest) on July 4th, 2008 06:45 PM
Newbie question:

Let's say I open a new file for writing in a certain path. How do I
get that path back?

Example:
Quote:
Originally Posted by
Quote:
Originally Posted by
Quote:
Originally Posted by
>>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
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
bruno.desthuilliers@gmail.com's Avatar
bruno.desthuilliers@gmail.com
Guest
n/a Posts
July 4th, 2008
08:15 PM
#2

Re: Getting a path from a file object
On 4 juil, 20:37, Andrew Fong <FongAnd...@gmail.comwrote:
Quote:
Originally Posted by
Newbie question:
>
Let's say I open a new file for writing in a certain path. How do I
get that path back?
>
Example:
>
Quote:
Originally Posted by
Quote:
Originally Posted by
>f = open('/some/path/file.ext')
>some_function(f)

>
'/some/path/file.ext'
>
Does some_function(f) already exist?


Nope. But:
Quote:
Originally Posted by
And if not, how would I define
it?


Not sure it's worth defining a function:

def some_function(f):
return f.name



Quote:
Originally Posted by
-- Andrew



Ken Starks's Avatar
Ken Starks
Guest
n/a Posts
July 5th, 2008
11:25 AM
#3

Re: Getting a path from a file object
Andrew Fong wrote:
Quote:
Originally Posted by
Newbie question:
>
Let's say I open a new file for writing in a certain path. How do I
get that path back?
>
Example:
>
Quote:
Originally Posted by
Quote:
Originally Posted by
>>>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

Read about f.name which is a kind of read-only attribute with caveats
in the documentation:


http://docs.python.org/lib/bltin-file-objects.html

 
Not the answer you were looking for? Post your question . . .
183,962 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
  • Didn't find the answer you were looking for?
    Post Your Question
  • Top Community Contributors