1

Just to be quick: I'm new to python and I'm still learning
Now to the problem: I want to log a variable and then later use it.
This is my code:

import logging
LOG_FILENAME = "users.log"
logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG)

newname = input("Name: ")
logging.info("Username:")
logging.info(newname)
newpwd = input("Password: ")
logging.info("Password:")
logging.info(newpwd)

In my log(users.log) file it says:
(PS: I used carrot in the name input and potato as the password input)
INFO:root:Username:
INFO:root:carrot
INFO:root:Password:
INFO:root:potato

So later in the code, is there any way that I could use the variables that I created and saved to the log file?

2
  • This is just an example, You aren't going to log actual passwords, right? Commented Sep 21, 2013 at 12:57
  • Ofcourse not, in my python class, our teacher just gives us simple tasks, and that was too easy for me, so I made one at home. No, I'm not going to log anyones password, without their knowledge. Commented Sep 21, 2013 at 18:39

1 Answer 1

2

You save strings to log, not variables. Whatever you put in the log is only supposed to be read by a human (maybe also by a log parser). That's pretty much the definition of a log file.

If you want to store some Python objects in a file, look at JSON or pickle.

Sign up to request clarification or add additional context in comments.

Comments

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.