2012-07-24 71 views

回答

0

而不是取代你可以做sys.path.insert(0, "./build/lib.linux-x86_64-2.4")这将优先考虑该路径。

1

为此,Python有一些名为.pth的文件。

1

你可以阅读从壳路径:

path = raw_input("Insert path: ") # It will display "Insert path and will return the string entered into variable 'path' 

或使用文件:

f = fopen("<filepath>", "r") #open the file in reading-mode 
list_of_lines = f.readlines() # read all the lines and put them in a list 
f.close() # closes the file 
for i in range(len(list_of_lines)): #cleaning from newline characters 
    list_of_line[i] = list_of_line[i].strip() 

而现在,诠释了list_of_lines列出你拥有所有的线从文件中读取。 ..For例如,现在您可以:

for i in range(len(list_of_lines)): 
    sys.path.append(list_of_lines[i]) 

希望它能帮助:)

+0

我试过path = raw_input(“Insert path:”),其工作正常 – jaysh 2012-07-24 05:13:28

+0

但另一个标记错误NameError:name'list _of_line'未定义 – jaysh 2012-07-24 05:18:49

+0

一个小小的错误list_of_line应该用list_of_lines :-)替换上面的代码's'缺失 – jaysh 2012-07-24 05:31:31