2010-11-12 572 views

回答

5

請參閱Reading and Writing FilesPython Tutorial,這是一個開始爲新手的好地方。

一定要逃脫你反斜線在Windows上,

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

或使用"raw" strings

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

原始字符串更適合Windows路徑 - 'f = open(r'\\ SERVER \ share \ file.ext','r')' – 2010-11-12 10:49:12

+0

@Chris:好點。謝謝。 – Johnsyweb 2010-11-12 10:59:48

0

使用os.path模塊操作路徑字符串(你需要import os

  • 當前目錄是os.path.abspath(os.curdir)
  • 加入2份的通路與os.path.join(dirname, filename):這將需要插入右路徑分隔的護理(「\」或「/」,這取決於操作系統)用於構建路徑
相關問題