Reputation: 327
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.
Upvotes: 10
Views: 44850
Reputation: 23293
use the os.path
module to manipulate path string (you need to import os
)
os.path.abspath(os.curdir)
os.path.join(dirname, filename)
: this will take care of inserting the right path separator ('\' or '/', depending on the operating system) for building the pathUpvotes: 0
Reputation: 141840
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')
Upvotes: 8