2017-02-22 1 views
-3

파이썬에서 응답 후 True로 파일에 데이터를 저장하려고합니다. example.txtTrue이면 파이썬을 사용하여 데이터를 파일에 저장합니다.

어떤 생각을 예를

내가 반응을 얻을 경우는 true, 그 저장 파일로 확인 할 callotherfunction 후
a = 1 
if a = 1 save to file.txt 

를 들어

!

감사합니다.

+0

그래서 당신이 값이 true의 경우 파일에 데이터 문자를 쓰려는? –

+3

[ask]와 [MCVE]를 읽으십시오. 지금 코드 스 니펫은 올바른 파이썬이 아니기 때문에 (IndentationError를 발생시킵니다). –

+0

심지어 질문은 명확하지 않습니다! –

답변

0

귀하의 질문은 여기, 아주 명확하지만,이 내용을 기반으로하지 않습니다 당신이 시작하는 예입니다

# You stated 'after callotherfunction I want to get response'. 
# This is how you call another function and save the response to a variable. 
# Ensure you swap out `otherfunction` for the actual function name 
result = otherfunction() 

# You said you wanted to check if the result is `True` - this will explicitly check that. 
# However, your example is using the numeric `1`. 
# If you just want to check for a 'positive' (non zero, non empty, non null), 
# You can just do `if result:` 
if result == True: 
    # This is one way of opening a file and writing text to it in python 2.7 
    # There are other ways for more complicated outputs - e.g. the csv module 
    with open('path/to/output/file.txt', 'w') as fout: 
     fout.write('...') 
+0

감사합니다. 내가 필요한 것입니다. 친애하는 –

관련 문제