User Input on Python Script












-2















I'm new to python, but I have a script that works as needed. However, some of these fields need to be updated with new data each usage: Filepath, Description, and External-Identifier.



What is the best way to enter this data, short of rewriting the python script each time I need it? I was thinking something like a GUI user-input form, but I'm not sure how to do this.



I'm using the Library of Congress's BagIt tool (Python). Here is the script:



import bagit

# load the bag
bag = bagit.Bag('<FILEPATH>')
# update bag info metadata
bag.info['Source-Organization'] = ['University Archives']
bag.info['Organization-Address'] = ["#"]
bag.info['Contact-Phone'] = ['#']
bag.info['Contact-Email'] = ['#']
bag.info['Description'] = ['#DESCRIPTION#']
bag.info['External-Identifier'] = ['#UUID#']
bag.save(manifests=True)


Any help is greatly appreciated. Thanks!





UPDATE. Thanks to the help, here is a working version of the UDbaginfo.py script. This updates bag-info.txt and updates the bag manifest.



Here is the code to update the bag-info.txt file for LOC Bagit (Python version)



import bagit

fpath = input("Enter the file path:")
bagDes = input("Enter the Description:")
bagUUID = input("Enter the UUID:")

# load the bag
bag = bagit.Bag(fpath)

# update bag info metadata
bag.info['Source-Organization'] = ['University Archives']
bag.info['Organization-Address'] = ["1000 North Ave. Nowhere, State.
33333"]
bag.info['Contact-Phone'] = ['555-555-5555']
bag.info['Contact-Email'] = ['archives@university.edu']
bag.info['Description'] = [bagDes]
bag.info['External-Identifier'] = [bagUUID]
bag.save(manifests=True)









share|improve this question

























  • How do you envision this working? do you want to prompt in the console for user input, or have the inputs passed in as arguments when the script is initiated?

    – G. Anderson
    Nov 20 '18 at 17:47











  • Which ever would be easier. A prompt for user input would be fine though.

    – user2824537
    Nov 20 '18 at 17:50











  • You can prompt for user input with, for example, fpath=input("Enter the file path:") which will save the input as a string to the variable

    – G. Anderson
    Nov 20 '18 at 17:52
















-2















I'm new to python, but I have a script that works as needed. However, some of these fields need to be updated with new data each usage: Filepath, Description, and External-Identifier.



What is the best way to enter this data, short of rewriting the python script each time I need it? I was thinking something like a GUI user-input form, but I'm not sure how to do this.



I'm using the Library of Congress's BagIt tool (Python). Here is the script:



import bagit

# load the bag
bag = bagit.Bag('<FILEPATH>')
# update bag info metadata
bag.info['Source-Organization'] = ['University Archives']
bag.info['Organization-Address'] = ["#"]
bag.info['Contact-Phone'] = ['#']
bag.info['Contact-Email'] = ['#']
bag.info['Description'] = ['#DESCRIPTION#']
bag.info['External-Identifier'] = ['#UUID#']
bag.save(manifests=True)


Any help is greatly appreciated. Thanks!





UPDATE. Thanks to the help, here is a working version of the UDbaginfo.py script. This updates bag-info.txt and updates the bag manifest.



Here is the code to update the bag-info.txt file for LOC Bagit (Python version)



import bagit

fpath = input("Enter the file path:")
bagDes = input("Enter the Description:")
bagUUID = input("Enter the UUID:")

# load the bag
bag = bagit.Bag(fpath)

# update bag info metadata
bag.info['Source-Organization'] = ['University Archives']
bag.info['Organization-Address'] = ["1000 North Ave. Nowhere, State.
33333"]
bag.info['Contact-Phone'] = ['555-555-5555']
bag.info['Contact-Email'] = ['archives@university.edu']
bag.info['Description'] = [bagDes]
bag.info['External-Identifier'] = [bagUUID]
bag.save(manifests=True)









share|improve this question

























  • How do you envision this working? do you want to prompt in the console for user input, or have the inputs passed in as arguments when the script is initiated?

    – G. Anderson
    Nov 20 '18 at 17:47











  • Which ever would be easier. A prompt for user input would be fine though.

    – user2824537
    Nov 20 '18 at 17:50











  • You can prompt for user input with, for example, fpath=input("Enter the file path:") which will save the input as a string to the variable

    – G. Anderson
    Nov 20 '18 at 17:52














-2












-2








-2








I'm new to python, but I have a script that works as needed. However, some of these fields need to be updated with new data each usage: Filepath, Description, and External-Identifier.



What is the best way to enter this data, short of rewriting the python script each time I need it? I was thinking something like a GUI user-input form, but I'm not sure how to do this.



I'm using the Library of Congress's BagIt tool (Python). Here is the script:



import bagit

# load the bag
bag = bagit.Bag('<FILEPATH>')
# update bag info metadata
bag.info['Source-Organization'] = ['University Archives']
bag.info['Organization-Address'] = ["#"]
bag.info['Contact-Phone'] = ['#']
bag.info['Contact-Email'] = ['#']
bag.info['Description'] = ['#DESCRIPTION#']
bag.info['External-Identifier'] = ['#UUID#']
bag.save(manifests=True)


Any help is greatly appreciated. Thanks!





UPDATE. Thanks to the help, here is a working version of the UDbaginfo.py script. This updates bag-info.txt and updates the bag manifest.



Here is the code to update the bag-info.txt file for LOC Bagit (Python version)



import bagit

fpath = input("Enter the file path:")
bagDes = input("Enter the Description:")
bagUUID = input("Enter the UUID:")

# load the bag
bag = bagit.Bag(fpath)

# update bag info metadata
bag.info['Source-Organization'] = ['University Archives']
bag.info['Organization-Address'] = ["1000 North Ave. Nowhere, State.
33333"]
bag.info['Contact-Phone'] = ['555-555-5555']
bag.info['Contact-Email'] = ['archives@university.edu']
bag.info['Description'] = [bagDes]
bag.info['External-Identifier'] = [bagUUID]
bag.save(manifests=True)









share|improve this question
















I'm new to python, but I have a script that works as needed. However, some of these fields need to be updated with new data each usage: Filepath, Description, and External-Identifier.



What is the best way to enter this data, short of rewriting the python script each time I need it? I was thinking something like a GUI user-input form, but I'm not sure how to do this.



I'm using the Library of Congress's BagIt tool (Python). Here is the script:



import bagit

# load the bag
bag = bagit.Bag('<FILEPATH>')
# update bag info metadata
bag.info['Source-Organization'] = ['University Archives']
bag.info['Organization-Address'] = ["#"]
bag.info['Contact-Phone'] = ['#']
bag.info['Contact-Email'] = ['#']
bag.info['Description'] = ['#DESCRIPTION#']
bag.info['External-Identifier'] = ['#UUID#']
bag.save(manifests=True)


Any help is greatly appreciated. Thanks!





UPDATE. Thanks to the help, here is a working version of the UDbaginfo.py script. This updates bag-info.txt and updates the bag manifest.



Here is the code to update the bag-info.txt file for LOC Bagit (Python version)



import bagit

fpath = input("Enter the file path:")
bagDes = input("Enter the Description:")
bagUUID = input("Enter the UUID:")

# load the bag
bag = bagit.Bag(fpath)

# update bag info metadata
bag.info['Source-Organization'] = ['University Archives']
bag.info['Organization-Address'] = ["1000 North Ave. Nowhere, State.
33333"]
bag.info['Contact-Phone'] = ['555-555-5555']
bag.info['Contact-Email'] = ['archives@university.edu']
bag.info['Description'] = [bagDes]
bag.info['External-Identifier'] = [bagUUID]
bag.save(manifests=True)






python






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 1:25







user2824537

















asked Nov 20 '18 at 17:38









user2824537user2824537

11




11













  • How do you envision this working? do you want to prompt in the console for user input, or have the inputs passed in as arguments when the script is initiated?

    – G. Anderson
    Nov 20 '18 at 17:47











  • Which ever would be easier. A prompt for user input would be fine though.

    – user2824537
    Nov 20 '18 at 17:50











  • You can prompt for user input with, for example, fpath=input("Enter the file path:") which will save the input as a string to the variable

    – G. Anderson
    Nov 20 '18 at 17:52



















  • How do you envision this working? do you want to prompt in the console for user input, or have the inputs passed in as arguments when the script is initiated?

    – G. Anderson
    Nov 20 '18 at 17:47











  • Which ever would be easier. A prompt for user input would be fine though.

    – user2824537
    Nov 20 '18 at 17:50











  • You can prompt for user input with, for example, fpath=input("Enter the file path:") which will save the input as a string to the variable

    – G. Anderson
    Nov 20 '18 at 17:52

















How do you envision this working? do you want to prompt in the console for user input, or have the inputs passed in as arguments when the script is initiated?

– G. Anderson
Nov 20 '18 at 17:47





How do you envision this working? do you want to prompt in the console for user input, or have the inputs passed in as arguments when the script is initiated?

– G. Anderson
Nov 20 '18 at 17:47













Which ever would be easier. A prompt for user input would be fine though.

– user2824537
Nov 20 '18 at 17:50





Which ever would be easier. A prompt for user input would be fine though.

– user2824537
Nov 20 '18 at 17:50













You can prompt for user input with, for example, fpath=input("Enter the file path:") which will save the input as a string to the variable

– G. Anderson
Nov 20 '18 at 17:52





You can prompt for user input with, for example, fpath=input("Enter the file path:") which will save the input as a string to the variable

– G. Anderson
Nov 20 '18 at 17:52












1 Answer
1






active

oldest

votes


















1














Assuming you are using Python 3 you could use input(). This would allow you to validate as well, i.e.:



#Validate
validUUID = False
while not (validUUID):
temp_uuid = input("UUID:")
try:
int(temp_uuid)
bag.info['External-Identifier'] = temp_uuid
validUUID = True


Although the above method is only in a terminal context. Alternatively you could just pass arguments to the script






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%2f53398559%2fuser-input-on-python-script%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Assuming you are using Python 3 you could use input(). This would allow you to validate as well, i.e.:



    #Validate
    validUUID = False
    while not (validUUID):
    temp_uuid = input("UUID:")
    try:
    int(temp_uuid)
    bag.info['External-Identifier'] = temp_uuid
    validUUID = True


    Although the above method is only in a terminal context. Alternatively you could just pass arguments to the script






    share|improve this answer




























      1














      Assuming you are using Python 3 you could use input(). This would allow you to validate as well, i.e.:



      #Validate
      validUUID = False
      while not (validUUID):
      temp_uuid = input("UUID:")
      try:
      int(temp_uuid)
      bag.info['External-Identifier'] = temp_uuid
      validUUID = True


      Although the above method is only in a terminal context. Alternatively you could just pass arguments to the script






      share|improve this answer


























        1












        1








        1







        Assuming you are using Python 3 you could use input(). This would allow you to validate as well, i.e.:



        #Validate
        validUUID = False
        while not (validUUID):
        temp_uuid = input("UUID:")
        try:
        int(temp_uuid)
        bag.info['External-Identifier'] = temp_uuid
        validUUID = True


        Although the above method is only in a terminal context. Alternatively you could just pass arguments to the script






        share|improve this answer













        Assuming you are using Python 3 you could use input(). This would allow you to validate as well, i.e.:



        #Validate
        validUUID = False
        while not (validUUID):
        temp_uuid = input("UUID:")
        try:
        int(temp_uuid)
        bag.info['External-Identifier'] = temp_uuid
        validUUID = True


        Although the above method is only in a terminal context. Alternatively you could just pass arguments to the script







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 20 '18 at 17:49









        SpydernazSpydernaz

        2710




        2710






























            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%2f53398559%2fuser-input-on-python-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

            'app-layout' is not a known element: how to share Component with different Modules

            android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

            WPF add header to Image with URL pettitions [duplicate]