2017-02-22 8 views
-3

Pythonで応答Trueの後にファイルにデータを保存しようとしています。Trueの場合は、Pythonを使用してデータをファイルに保存します。

例えば

a = 1 
if a = 1 save to file.txt 

callotherfunctionた後、私は応答を取得し、trueの場合、ファイルに保存チェックしたい:EXAMPLE.SQLの

任意のアイデア!

よろしくお願いいたします。

+0

ので、あなたはそれが価値だ場合は、ファイルへのデータ文字を書きたいのは本当ですか? –

+3

[ask]と[MCVE]をお読みください。現在、コードスニペットは正しいPythonではありません( '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

ありがとう、これは私が必要なものです。宜しくお願いします –

関連する問題