10

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.

d-cubed
  • 1,034
  • 5
  • 30
  • 58
newbie pisan
  • 327
  • 3
  • 5
  • 11

2 Answers2

8

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')
johnsyweb
  • 136,902
  • 23
  • 188
  • 247
0

use the os.path module to manipulate path string (you need to import os)

  • the current directory is os.path.abspath(os.curdir)
  • join 2 parts of a path with os.path.join(dirname, filename): this will take care of inserting the right path separator ('\' or '/', depending on the operating system) for building the path
Adrien Plisson
  • 22,486
  • 6
  • 42
  • 73