【发布时间】:2015-12-10 21:42:29
【问题描述】:
我需要在文件夹中打开一个文件,这应该可以,但是 \ 会导致字符串关闭,因此当 Me 变量不应该是我时,它是绿色的。我该如何解决它,我需要能够阻止 \ 关闭字符串或直接进入文件夹而不使用 \ 符号。我使用的大多数变量看起来都是随机的,这是因为我不希望它与真实函数相似,从而混淆我或其他人。
Me = Jacob #Variable me with Jacob in it
def God():#creates function called god
File = open ("Test\" + Me + ".txt","r")#opens the Jacob file in the test folder.
Door = ""#creates door variable
Door = File.read().splitlines()#sets what is in Jacob file to be in Door variable
print (Door)#prints the varible door
God()#does go function
【问题讨论】:
-
在文件路径中使用正斜杠。它会让事情变得更容易。
标签: python file python-3.4 definition