Obtaining a full path name from file

Jean-Michel Pichavant jeanmichel at sequans.com
Tue May 24 12:13:20 EDT 2011


RVince wrote:
> Ha! You;re right -- but is there a way to get it without the filename
> appended at the end?
>
> On May 24, 11:52 am, Tim Golden <m... at timgolden.me.uk> wrote:
>   
>> On 24/05/2011 16:36, RVince wrote:
>>
>>     
>>> s = "C:\AciiCsv\Gravity_Test_data\A.csv"
>>> f = open(s,"r")
>>>       
>>> How do I obtain the full pathname given the File, f? (which should
>>> equal "C:\AciiCsv\Gravity_Test_data"). I've tried all sorts of stuff
>>> and am just not finding it. Any help greatly appreciated !
>>>       
>> You're going to kick yourself:
>>
>> f.name
>>
>> TJG
>>     
>
>   
path, fileName = os.path.split(os.path.abspath(f.name))

JM



More information about the Python-list mailing list