473,320 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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
Jul 4 '08 #1
2 4410
On 4 juil, 20:37, Andrew Fong <FongAnd...@gmail.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
Jul 4 '08 #2
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
Jul 5 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: travis ray | last post by:
Hi, I have an extension in which a file object is created in python and passed down to a c extension which attempts to read from it or write to it. Writing to the file pointer seems to work...
0
by: John G | last post by:
How can I Programmatically access maximum path, file, and sum of both lengths? I am using VB.NET 2003. The PathTooLongException indicates that a path < 248 characters, filename < 260...
2
by: asad | last post by:
Hello friends, i need some help in getting uploaded file name, i am uploading 2 files and i want to get only the filename of these 2 file not a full path so pls tell me which function or technique...
1
by: LP | last post by:
If you can't seem to eliminate throwing this exception, then the answer is to look for a different file opened previously with an invalid or missing filename. For example, assume the following...
3
by: Grant Schenck | last post by:
Hello, I have a Windows Service developed in C# .NET. I'm making it a remote server and I can, via an IPC Channel, expose methods and call them from a client. However, I now want my remoted...
9
by: cdroulers | last post by:
Hello, I am working on a school project that requires me to get the path of a filename for future treatment. I've tried getting a file with tkFileDialog.askopenfile. ...
2
by: klaash | last post by:
I created a program using VB6 which has many dependency JPG files. All files are installed in the same subfolder folder of Program Files folder using Package and Deployment Wizard. in VB6....
3
by: vellyna | last post by:
how to appear path file name? for example, i have select "books" from list, then i browse the file.. after browse the file, i want to appear the path file name that will save the file in a...
185
by: jacob navia | last post by:
Hi We are rewriting the libc for the 64 bit version of lcc-win and we have added a new field in the FILE structure: char *FileName; fopen() will save the file name and an accessor function will...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.