-1
파일이없는 경우 문자열을 가져 와서 파일에 기록하려고합니다. 지금까지 코드가 있습니다. 실행하면문자열로 키보드 입력 저장
#!/usr/bin/python
import os.path as path
configFileLocation = "~/.sajan.io-client"
def createConfig():
print "Creating config file\n"
apikey = input("Enter the API key: ")
configFile = open(configFileLocation, "w")
configFile.write(apikey)
configFile.close()
if path.isfile(configFileLocation) == False:
createConfig()
, 나는 Enter the API key:
에 프롬프트를, 나는에 입력 어떤 문자열로 사용하지 않는 것. 다음은 내가 얻은 결과이며, 나는 그것을 이해할 수 없다. 마치 파이썬이 스크립트에서 변수로 입력 한 것을 사용하려고하는 것처럼 보입니다.
당신은 Python2를 사용하는
Enter the API key: somerandomapikey123
Traceback (most recent call last):
File "./new-thought.py", line 15, in <module>
createConfig()
File "./new-thought.py", line 9, in createConfig
apikey = input("Enter the API key: ")
File "<string>", line 1, in <module>
NameError: name 'somerandomapikey123' is not defined
whats your python version? 터미널에서'python --version'을하십시오! – Kasramvd