Get path from open file in Python

后端 未结 4 1294
囚心锁ツ
囚心锁ツ 2020-12-02 17:54

If I have an opened file, is there an os call to get the complete path as a string?

f = open(\'/Users/Desktop/febROSTER2012.xls\')
4条回答
  •  心在旅途
    2020-12-02 18:45

    The key here is the name attribute of the f object representing the opened file. You get it like that:

    >>> f = open('/Users/Desktop/febROSTER2012.xls')
    >>> f.name
    '/Users/Desktop/febROSTER2012.xls'
    

    Does it help?

提交回复
热议问题