Getting a path from a file object

Discussion in 'Python' started by Andrew Fong, Jul 4, 2008.

  1. Andrew Fong

    Andrew Fong Guest

    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
     
    Andrew Fong, Jul 4, 2008
    #1
    1. Advertising

  2. Andrew Fong

    Guest

    On 4 juil, 20:37, Andrew Fong <> 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?


    Nope. But:

    > And if not, how would I define
    > it?


    Not sure it's worth defining a function:

    def some_function(f):
    return f.name




    > -- Andrew
     
    , Jul 4, 2008
    #2
    1. Advertising

  3. Andrew Fong

    Ken Starks Guest

    Andrew Fong 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

    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
     
    Ken Starks, Jul 5, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. James
    Replies:
    2
    Views:
    13,925
    Andrew Thompson
    Dec 7, 2004
  2. =?Utf-8?B?ZGVuIDIwMDU=?=

    Getting File Path in Browse File Dialog in ASP.Net

    =?Utf-8?B?ZGVuIDIwMDU=?=, May 5, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    10,593
    =?Utf-8?B?ZGVuIDIwMDU=?=
    May 8, 2006
  3. Replies:
    1
    Views:
    591
    Oliver Wong
    Jul 13, 2006
  4. sug
    Replies:
    7
    Views:
    457
    CBFalconer
    Jun 21, 2005
  5. \A_Michigan_User\

    Various path/path/files.asp all #include this 1 file

    \A_Michigan_User\, Jul 10, 2005, in forum: ASP General
    Replies:
    1
    Views:
    233
    Jeff Cochran
    Jul 10, 2005
Loading...

Share This Page