Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python - how to read path file/folder from server

Tags:

python

Using Python, how might one read a file's path from a remote server? This is a bit more clear to me on my local PC.

like image 302
newbie pisan Avatar asked Nov 12 '10 09:11

newbie pisan


People also ask

How do I find the path of a Python server?

getcwd() method is used for getting the Current Working Directory in Python. The absolute path to the current working directory is returned in a string by this function of the Python OS module.

How can I extract the folder path from file path in Python?

dirname() Use os. path. dirname() to get the directory folder (name) from a path string.

How do you call a path in Python?

In order to obtain the Current Working Directory in Python, use the os. getcwd() method. This function of the Python OS module returns the string containing the absolute path to the current working directory.


1 Answers

See Reading and Writing Files in the Python Tutorial, which is a great place to start for a newbie.

Be sure to escape your backslashes on Windows, viz:

f=open('\\\\SERVER\\share\\file.ext', 'r')

or use "raw" strings:

f=open(r'\\SERVER\share\file.ext', 'r')
like image 152
Johnsyweb Avatar answered Nov 01 '22 07:11

Johnsyweb