Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #6148
| From | Mel <mwilson@the-wire.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Obtaining a full path name from file |
| Followup-To | comp.lang.python |
| Date | 2011-05-24 12:04 -0400 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <irgkum$rle$1@speranza.aioe.org> (permalink) |
| References | <6af58349-43d3-4132-ab0a-a072852e6f3a@g12g2000yqd.googlegroups.com> <mailman.2020.1306252356.9059.python-list@python.org> |
Followups directed to: comp.lang.python
Tim Golden 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
There's trouble there, though:
Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> f = open ('xyzzy.txt')
>>> f.name
'xyzzy.txt'
>>> import os
>>> os.getcwd()
'/home/mwilson'
>>> os.chdir('sandbox')
>>> f.name
'xyzzy.txt'
If you open a file and don't get a full path from os.path.abspath right
away, the name in the file instance can get out-of-date.
Mel.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Obtaining a full path name from file RVince <rvince99@gmail.com> - 2011-05-24 08:36 -0700
Re: Obtaining a full path name from file Tim Golden <mail@timgolden.me.uk> - 2011-05-24 16:52 +0100
Re: Obtaining a full path name from file RVince <rvince99@gmail.com> - 2011-05-24 09:04 -0700
Re: Obtaining a full path name from file Chris Angelico <rosuav@gmail.com> - 2011-05-25 02:08 +1000
Re: Obtaining a full path name from file Tim Golden <mail@timgolden.me.uk> - 2011-05-24 17:10 +0100
Re: Obtaining a full path name from file Jean-Michel Pichavant <jeanmichel@sequans.com> - 2011-05-24 18:13 +0200
Re: Obtaining a full path name from file Mel <mwilson@the-wire.com> - 2011-05-24 12:04 -0400
Re: Obtaining a full path name from file Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2011-05-25 08:36 +0200
Re: Obtaining a full path name from file Tim Golden <mail@timgolden.me.uk> - 2011-05-25 08:29 +0100
Re: Obtaining a full path name from file Dave Angel <davea@ieee.org> - 2011-05-25 07:05 -0400
csiph-web