Store User Input Values in File for Another Script












0















I have a script that writes user input values from questions to a txt file. Another script needs to be able to open that file and read in those answers.
Ive been trying to write the values in a x=y format in txt file but when called in the other script it throws an error saying the variable is not defined. This leads me to believe I just dont have my temporary txt file formatted correctly for python to read the information. How would I want to store the multiple variables and values in the txt file for python to be able to read them in as a variable name?



Here is how the first script stores my values. (single line)



timeIn=18 January 2019 11:39:40 supportID=Andy branch=Bristow clientID=Cindy Lou reason=grinch stole christmas



Here is the error I get when trying to read in the values by variable name.



Traceback (most recent call last):
File "script2.py", line 9, in <module>
f.write('[Time In] '+ timeIn)
NameError: name 'timeIn' is not defined


My question is how would I want to format these in the txt file to be read in by another script?



edit 1: Im opening the txt file in the second script this way



t=open("testtmp.txt","r")


edit 2: I am not writing the values just as themselves (x) on individual lines. I am now trying to read those values in to be written to another file.










share|improve this question





























    0















    I have a script that writes user input values from questions to a txt file. Another script needs to be able to open that file and read in those answers.
    Ive been trying to write the values in a x=y format in txt file but when called in the other script it throws an error saying the variable is not defined. This leads me to believe I just dont have my temporary txt file formatted correctly for python to read the information. How would I want to store the multiple variables and values in the txt file for python to be able to read them in as a variable name?



    Here is how the first script stores my values. (single line)



    timeIn=18 January 2019 11:39:40 supportID=Andy branch=Bristow clientID=Cindy Lou reason=grinch stole christmas



    Here is the error I get when trying to read in the values by variable name.



    Traceback (most recent call last):
    File "script2.py", line 9, in <module>
    f.write('[Time In] '+ timeIn)
    NameError: name 'timeIn' is not defined


    My question is how would I want to format these in the txt file to be read in by another script?



    edit 1: Im opening the txt file in the second script this way



    t=open("testtmp.txt","r")


    edit 2: I am not writing the values just as themselves (x) on individual lines. I am now trying to read those values in to be written to another file.










    share|improve this question



























      0












      0








      0








      I have a script that writes user input values from questions to a txt file. Another script needs to be able to open that file and read in those answers.
      Ive been trying to write the values in a x=y format in txt file but when called in the other script it throws an error saying the variable is not defined. This leads me to believe I just dont have my temporary txt file formatted correctly for python to read the information. How would I want to store the multiple variables and values in the txt file for python to be able to read them in as a variable name?



      Here is how the first script stores my values. (single line)



      timeIn=18 January 2019 11:39:40 supportID=Andy branch=Bristow clientID=Cindy Lou reason=grinch stole christmas



      Here is the error I get when trying to read in the values by variable name.



      Traceback (most recent call last):
      File "script2.py", line 9, in <module>
      f.write('[Time In] '+ timeIn)
      NameError: name 'timeIn' is not defined


      My question is how would I want to format these in the txt file to be read in by another script?



      edit 1: Im opening the txt file in the second script this way



      t=open("testtmp.txt","r")


      edit 2: I am not writing the values just as themselves (x) on individual lines. I am now trying to read those values in to be written to another file.










      share|improve this question
















      I have a script that writes user input values from questions to a txt file. Another script needs to be able to open that file and read in those answers.
      Ive been trying to write the values in a x=y format in txt file but when called in the other script it throws an error saying the variable is not defined. This leads me to believe I just dont have my temporary txt file formatted correctly for python to read the information. How would I want to store the multiple variables and values in the txt file for python to be able to read them in as a variable name?



      Here is how the first script stores my values. (single line)



      timeIn=18 January 2019 11:39:40 supportID=Andy branch=Bristow clientID=Cindy Lou reason=grinch stole christmas



      Here is the error I get when trying to read in the values by variable name.



      Traceback (most recent call last):
      File "script2.py", line 9, in <module>
      f.write('[Time In] '+ timeIn)
      NameError: name 'timeIn' is not defined


      My question is how would I want to format these in the txt file to be read in by another script?



      edit 1: Im opening the txt file in the second script this way



      t=open("testtmp.txt","r")


      edit 2: I am not writing the values just as themselves (x) on individual lines. I am now trying to read those values in to be written to another file.







      python






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 18 at 19:24







      FamousAv8er

















      asked Jan 18 at 17:44









      FamousAv8erFamousAv8er

      195




      195
























          2 Answers
          2






          active

          oldest

          votes


















          1














          This kind of key value data would be easier to work with in a json file.



          You can use the the library json to work with it.



          https://docs.python.org/2/library/json.html



          Using a text file you are just working with a string, so you would need to parse data into usable format after reading it.






          share|improve this answer








          New contributor




          ilamaaa is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.




























            0














            THIS IS HOW I SOLVED MY ISSUE (.txt format):



            First, I wrote in the original values with a line break separating them.



            t=open("nbsstmp.txt", "w")
            t.write(timeIn+' n')
            t.write(supportID+' n')
            t.write(branch+' n')
            t.write(clientID+' n')
            t.write(problem+' n')
            t.close()


            Then, I was able to read them back in the following way.



            t=open("nbsstmp.txt","r")
            f=open("Support_Access_Log.txt","a")
            timeIn=(t.readlines((1)))
            a=(str(timeIn))
            supportID=(t.readlines(2))
            b=(str(supportID))
            branch=(t.readlines(3))
            c=(str(branch))
            clientID=(t.readlines(4))
            d=(str(clientID))
            problem=(t.readlines(5))
            e=(str(problem))

            f.write('[Time In] ')
            f.write(a.replace("['","").replace("']","").replace("\n",""))
            f.write(' [Support ID] ')
            f.write(b.replace("['","").replace("']","").replace("\n",""))
            f.write(' [Branch] ')
            f.write(c.replace("['","").replace("']","").replace("\n",""))
            f.write(' [Support Client] ')
            f.write(d.replace("['","").replace("']","").replace("\n",""))
            f.write(' [Reason] ')
            f.write(e.replace("['","").replace("']","").replace("\n",""))
            f.close()
            t.close()





            share|improve this answer























              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54259032%2fstore-user-input-values-in-file-for-another-script%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1














              This kind of key value data would be easier to work with in a json file.



              You can use the the library json to work with it.



              https://docs.python.org/2/library/json.html



              Using a text file you are just working with a string, so you would need to parse data into usable format after reading it.






              share|improve this answer








              New contributor




              ilamaaa is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.

























                1














                This kind of key value data would be easier to work with in a json file.



                You can use the the library json to work with it.



                https://docs.python.org/2/library/json.html



                Using a text file you are just working with a string, so you would need to parse data into usable format after reading it.






                share|improve this answer








                New contributor




                ilamaaa is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.























                  1












                  1








                  1







                  This kind of key value data would be easier to work with in a json file.



                  You can use the the library json to work with it.



                  https://docs.python.org/2/library/json.html



                  Using a text file you are just working with a string, so you would need to parse data into usable format after reading it.






                  share|improve this answer








                  New contributor




                  ilamaaa is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.










                  This kind of key value data would be easier to work with in a json file.



                  You can use the the library json to work with it.



                  https://docs.python.org/2/library/json.html



                  Using a text file you are just working with a string, so you would need to parse data into usable format after reading it.







                  share|improve this answer








                  New contributor




                  ilamaaa is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  share|improve this answer



                  share|improve this answer






                  New contributor




                  ilamaaa is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  answered Jan 18 at 17:54









                  ilamaaailamaaa

                  1165




                  1165




                  New contributor




                  ilamaaa is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.





                  New contributor





                  ilamaaa is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.






                  ilamaaa is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.

























                      0














                      THIS IS HOW I SOLVED MY ISSUE (.txt format):



                      First, I wrote in the original values with a line break separating them.



                      t=open("nbsstmp.txt", "w")
                      t.write(timeIn+' n')
                      t.write(supportID+' n')
                      t.write(branch+' n')
                      t.write(clientID+' n')
                      t.write(problem+' n')
                      t.close()


                      Then, I was able to read them back in the following way.



                      t=open("nbsstmp.txt","r")
                      f=open("Support_Access_Log.txt","a")
                      timeIn=(t.readlines((1)))
                      a=(str(timeIn))
                      supportID=(t.readlines(2))
                      b=(str(supportID))
                      branch=(t.readlines(3))
                      c=(str(branch))
                      clientID=(t.readlines(4))
                      d=(str(clientID))
                      problem=(t.readlines(5))
                      e=(str(problem))

                      f.write('[Time In] ')
                      f.write(a.replace("['","").replace("']","").replace("\n",""))
                      f.write(' [Support ID] ')
                      f.write(b.replace("['","").replace("']","").replace("\n",""))
                      f.write(' [Branch] ')
                      f.write(c.replace("['","").replace("']","").replace("\n",""))
                      f.write(' [Support Client] ')
                      f.write(d.replace("['","").replace("']","").replace("\n",""))
                      f.write(' [Reason] ')
                      f.write(e.replace("['","").replace("']","").replace("\n",""))
                      f.close()
                      t.close()





                      share|improve this answer




























                        0














                        THIS IS HOW I SOLVED MY ISSUE (.txt format):



                        First, I wrote in the original values with a line break separating them.



                        t=open("nbsstmp.txt", "w")
                        t.write(timeIn+' n')
                        t.write(supportID+' n')
                        t.write(branch+' n')
                        t.write(clientID+' n')
                        t.write(problem+' n')
                        t.close()


                        Then, I was able to read them back in the following way.



                        t=open("nbsstmp.txt","r")
                        f=open("Support_Access_Log.txt","a")
                        timeIn=(t.readlines((1)))
                        a=(str(timeIn))
                        supportID=(t.readlines(2))
                        b=(str(supportID))
                        branch=(t.readlines(3))
                        c=(str(branch))
                        clientID=(t.readlines(4))
                        d=(str(clientID))
                        problem=(t.readlines(5))
                        e=(str(problem))

                        f.write('[Time In] ')
                        f.write(a.replace("['","").replace("']","").replace("\n",""))
                        f.write(' [Support ID] ')
                        f.write(b.replace("['","").replace("']","").replace("\n",""))
                        f.write(' [Branch] ')
                        f.write(c.replace("['","").replace("']","").replace("\n",""))
                        f.write(' [Support Client] ')
                        f.write(d.replace("['","").replace("']","").replace("\n",""))
                        f.write(' [Reason] ')
                        f.write(e.replace("['","").replace("']","").replace("\n",""))
                        f.close()
                        t.close()





                        share|improve this answer


























                          0












                          0








                          0







                          THIS IS HOW I SOLVED MY ISSUE (.txt format):



                          First, I wrote in the original values with a line break separating them.



                          t=open("nbsstmp.txt", "w")
                          t.write(timeIn+' n')
                          t.write(supportID+' n')
                          t.write(branch+' n')
                          t.write(clientID+' n')
                          t.write(problem+' n')
                          t.close()


                          Then, I was able to read them back in the following way.



                          t=open("nbsstmp.txt","r")
                          f=open("Support_Access_Log.txt","a")
                          timeIn=(t.readlines((1)))
                          a=(str(timeIn))
                          supportID=(t.readlines(2))
                          b=(str(supportID))
                          branch=(t.readlines(3))
                          c=(str(branch))
                          clientID=(t.readlines(4))
                          d=(str(clientID))
                          problem=(t.readlines(5))
                          e=(str(problem))

                          f.write('[Time In] ')
                          f.write(a.replace("['","").replace("']","").replace("\n",""))
                          f.write(' [Support ID] ')
                          f.write(b.replace("['","").replace("']","").replace("\n",""))
                          f.write(' [Branch] ')
                          f.write(c.replace("['","").replace("']","").replace("\n",""))
                          f.write(' [Support Client] ')
                          f.write(d.replace("['","").replace("']","").replace("\n",""))
                          f.write(' [Reason] ')
                          f.write(e.replace("['","").replace("']","").replace("\n",""))
                          f.close()
                          t.close()





                          share|improve this answer













                          THIS IS HOW I SOLVED MY ISSUE (.txt format):



                          First, I wrote in the original values with a line break separating them.



                          t=open("nbsstmp.txt", "w")
                          t.write(timeIn+' n')
                          t.write(supportID+' n')
                          t.write(branch+' n')
                          t.write(clientID+' n')
                          t.write(problem+' n')
                          t.close()


                          Then, I was able to read them back in the following way.



                          t=open("nbsstmp.txt","r")
                          f=open("Support_Access_Log.txt","a")
                          timeIn=(t.readlines((1)))
                          a=(str(timeIn))
                          supportID=(t.readlines(2))
                          b=(str(supportID))
                          branch=(t.readlines(3))
                          c=(str(branch))
                          clientID=(t.readlines(4))
                          d=(str(clientID))
                          problem=(t.readlines(5))
                          e=(str(problem))

                          f.write('[Time In] ')
                          f.write(a.replace("['","").replace("']","").replace("\n",""))
                          f.write(' [Support ID] ')
                          f.write(b.replace("['","").replace("']","").replace("\n",""))
                          f.write(' [Branch] ')
                          f.write(c.replace("['","").replace("']","").replace("\n",""))
                          f.write(' [Support Client] ')
                          f.write(d.replace("['","").replace("']","").replace("\n",""))
                          f.write(' [Reason] ')
                          f.write(e.replace("['","").replace("']","").replace("\n",""))
                          f.close()
                          t.close()






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Jan 18 at 22:07









                          FamousAv8erFamousAv8er

                          195




                          195






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54259032%2fstore-user-input-values-in-file-for-another-script%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Liquibase includeAll doesn't find base path

                              How to use setInterval in EJS file?

                              Petrus Granier-Deferre