1

I am using python make some of the SQL queries I have to for my JDBC connections more modular and would like to execute parts of my string literals with print statements.

fh = open("data.txt","w")
print("42 is the answer, but what is the question?", file=fh)
fh.close()

I know I can use this to write to text but I would like to save the outputs of my print in a local variable to call later in other statements.

Is this possible?

1
  • Thank you for the edit Wondercricket. Commented Aug 11, 2017 at 15:08

1 Answer 1

1
output = "42 is the answer, but what is the question?"
with open("data.txt","w") as fh:
    fh.write(output)
Sign up to request clarification or add additional context in comments.

1 Comment

@Flufylobster I don't understand what you mean. Make your question clear.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.