0
나는 다음과 같은 스크립트를 실행하기 위해 노력하고있어 : 쉘에 기록 파이썬 2.7 수입 혼란
#Contents of logging.py
import sys
import os
global gLogfile
global gLogFileFlag
#-----------------------------------------------------------------------------------------
def initLogging():
global gLogFileFlag
try:
glogFile = 'D:\logggggging.log'
print gLogFile
fileObject = open(gLogFile, 'w')
gLogFileFlag = True
fileObject.close()
except:
gLogFileFlag = False
#-----------------------------------------------------------------------------------------
def logIt(text):
sys.stdout.write(text)
if(gLogFileFlag):
hFile = open(gLogFile, 'a')
hFile.write(text)
hFile.close()
#-----------------------------------------------------------------------------------------
#contents of test_defualt.py
from logging import initLogging
from logging import logIt
def main():
initLogging()
logIt("log something")
main()
나는 F5 키를 사용하여, 위의 코드를 실행
는, 결과는 "뭔가를 기록"하지만,이 이미 생성 된 파일이 없으며 이미 존재하는 경우 파일에 아무 것도 기록되지 않습니다.도와주세요.
, 나는 오류를 실현했습니다. 변수를 편집하는 동안 이름 지정과 전역 키워드를 사용하지 않았습니다. 그것의 일 벌금. 고맙습니다. – Vinayaka