0

Im my program, In fileA i ask the user to enter there username and if they say yes itll save their username to a .env file if not i want it to only be saved until the program is either closed or stopped. Then the program in fileB runs a script. If theyve said yes to storing their password itll get it from the .env. if not i want it to somehow get it from the other file somehow.

i tryed from fileA import username in fileB but it ran fileA instead of getting the username variable. Which kinda makes sense to me but i would of assumed it would of just returned nothing as the username variable hasnt been set to anything in that instance of fileA.

I also found this Passing data between separately running Python scripts but none of the anwsers work as i dont have both of the files running at the same time.

Lexi
  • 9
  • 4
  • You misspelled `fileA` in your import statement – BokiX Nov 09 '22 at 19:06
  • Can't you create one .txt file for data transaction between these 2 files if it is needed? Then you can create a thread for parallel while loop searching for data and deleting after reading so it is ready for more. You can also do that for writing. (you do this only if you want it do be dynamic) – BokiX Nov 09 '22 at 19:07
  • 1
    sounds like you want a database. – juanpa.arrivillaga Nov 09 '22 at 19:11
  • @juanpa.arrivillaga I think he need a temp file for data transfer. But if database is the case he can use SQLite database for small projects like this. – BokiX Nov 09 '22 at 19:13
  • It would help if you provided actual code you're using to get the user input and saving it out to your env file. Right now, though, it's unclear what you mean by 'file' when you are 'passing' a variable. Are you saying you want code in fileB to get values from fileA? Or are you writing that value to disk and then reading it again? – Nathaniel Ford Nov 09 '22 at 19:16

1 Answers1

0
  • add an extra field to the data you store in the file.
  • use the field to indicate whether the user wants it to be permanent
  • always store the info but periodically delete impermanent usernames.
wwii
  • 23,232
  • 7
  • 37
  • 77