Getting a path from a file object

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrew Fong

    Getting a path from a file object

    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
  • bruno.desthuilliers@gmail.com

    #2
    Re: Getting a path from a file object

    On 4 juil, 20:37, Andrew Fong <FongAnd...@gma il.comwrote:
    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

    Comment

    • Ken Starks

      #3
      Re: Getting a path from a file object

      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_functio n(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:



      Comment

      Working...