Save text into a seperate file, as an integer instead of a string. PYTHON












-3















I'm writing some code for a class, and I can't seem to figure out for the life of me how to get this to work. I'm using mod to find the remainder of a large range of numbers, and taking those numbers that only have the remainder to do the same thing repeatedly. For example:
I have 100 apples, and I want a rem of 1
6 % 6 = 0 so that doesn't fit, but
7 % 6 = 1 so it fits. I do that for every # from 1-100, and take that list and do the same thing with a different remainder. I've been trying to find a decent method of storing all of the numbers that fit the criteria, because the program will search 10s - 100s of thousands of numbers. I settled on taking the first list of #s that fit the mod1, and creating an output file to store them all.
Now all I need to do is reference the output file for the next revision of a different mod, but the output file is stored as a string (says "write() arg must be str, not int") but when I open it back up I can't figure out how to convert it back to all ints so I can use mod again to find a different rem. Heres some code:



enter image description here



With the mod = apple % 8 and if statement commented out, it prints out the whole list that was created in the first part. (I also commented out the line under outputFile on the second part that didn't work)I can't seem to edit that list. ANY help would be appreciated, or perhaps a different method of storing these numbers would be appreciated as well. Thanks! :)










share|improve this question























  • Images of code are not welcome; images can't be indexed, copy/pasted, or read out loud or rerendered as braille.

    – tripleee
    Dec 12 '18 at 5:52
















-3















I'm writing some code for a class, and I can't seem to figure out for the life of me how to get this to work. I'm using mod to find the remainder of a large range of numbers, and taking those numbers that only have the remainder to do the same thing repeatedly. For example:
I have 100 apples, and I want a rem of 1
6 % 6 = 0 so that doesn't fit, but
7 % 6 = 1 so it fits. I do that for every # from 1-100, and take that list and do the same thing with a different remainder. I've been trying to find a decent method of storing all of the numbers that fit the criteria, because the program will search 10s - 100s of thousands of numbers. I settled on taking the first list of #s that fit the mod1, and creating an output file to store them all.
Now all I need to do is reference the output file for the next revision of a different mod, but the output file is stored as a string (says "write() arg must be str, not int") but when I open it back up I can't figure out how to convert it back to all ints so I can use mod again to find a different rem. Heres some code:



enter image description here



With the mod = apple % 8 and if statement commented out, it prints out the whole list that was created in the first part. (I also commented out the line under outputFile on the second part that didn't work)I can't seem to edit that list. ANY help would be appreciated, or perhaps a different method of storing these numbers would be appreciated as well. Thanks! :)










share|improve this question























  • Images of code are not welcome; images can't be indexed, copy/pasted, or read out loud or rerendered as braille.

    – tripleee
    Dec 12 '18 at 5:52














-3












-3








-3


0






I'm writing some code for a class, and I can't seem to figure out for the life of me how to get this to work. I'm using mod to find the remainder of a large range of numbers, and taking those numbers that only have the remainder to do the same thing repeatedly. For example:
I have 100 apples, and I want a rem of 1
6 % 6 = 0 so that doesn't fit, but
7 % 6 = 1 so it fits. I do that for every # from 1-100, and take that list and do the same thing with a different remainder. I've been trying to find a decent method of storing all of the numbers that fit the criteria, because the program will search 10s - 100s of thousands of numbers. I settled on taking the first list of #s that fit the mod1, and creating an output file to store them all.
Now all I need to do is reference the output file for the next revision of a different mod, but the output file is stored as a string (says "write() arg must be str, not int") but when I open it back up I can't figure out how to convert it back to all ints so I can use mod again to find a different rem. Heres some code:



enter image description here



With the mod = apple % 8 and if statement commented out, it prints out the whole list that was created in the first part. (I also commented out the line under outputFile on the second part that didn't work)I can't seem to edit that list. ANY help would be appreciated, or perhaps a different method of storing these numbers would be appreciated as well. Thanks! :)










share|improve this question














I'm writing some code for a class, and I can't seem to figure out for the life of me how to get this to work. I'm using mod to find the remainder of a large range of numbers, and taking those numbers that only have the remainder to do the same thing repeatedly. For example:
I have 100 apples, and I want a rem of 1
6 % 6 = 0 so that doesn't fit, but
7 % 6 = 1 so it fits. I do that for every # from 1-100, and take that list and do the same thing with a different remainder. I've been trying to find a decent method of storing all of the numbers that fit the criteria, because the program will search 10s - 100s of thousands of numbers. I settled on taking the first list of #s that fit the mod1, and creating an output file to store them all.
Now all I need to do is reference the output file for the next revision of a different mod, but the output file is stored as a string (says "write() arg must be str, not int") but when I open it back up I can't figure out how to convert it back to all ints so I can use mod again to find a different rem. Heres some code:



enter image description here



With the mod = apple % 8 and if statement commented out, it prints out the whole list that was created in the first part. (I also commented out the line under outputFile on the second part that didn't work)I can't seem to edit that list. ANY help would be appreciated, or perhaps a different method of storing these numbers would be appreciated as well. Thanks! :)







python






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 14 '18 at 2:11









Jacob SmithJacob Smith

615




615













  • Images of code are not welcome; images can't be indexed, copy/pasted, or read out loud or rerendered as braille.

    – tripleee
    Dec 12 '18 at 5:52



















  • Images of code are not welcome; images can't be indexed, copy/pasted, or read out loud or rerendered as braille.

    – tripleee
    Dec 12 '18 at 5:52

















Images of code are not welcome; images can't be indexed, copy/pasted, or read out loud or rerendered as braille.

– tripleee
Dec 12 '18 at 5:52





Images of code are not welcome; images can't be indexed, copy/pasted, or read out loud or rerendered as braille.

– tripleee
Dec 12 '18 at 5:52












1 Answer
1






active

oldest

votes


















0














Check this post




I can't figure out how to convert it back to all ints so I can use mod again to find a different rem




What I understood is that you want to convert the strings read from Output.txt to integers. So to do that you can use int() to convert str to int. To check the type, use type().



#print("type(apple) is ", type(apple))
#print("type(int(apple)) is ", type(int(apple)))
for apple in outputFile:
mod = int(apple) % 8


Source



I hope this helps!






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%2f53292210%2fsave-text-into-a-seperate-file-as-an-integer-instead-of-a-string-python%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









    0














    Check this post




    I can't figure out how to convert it back to all ints so I can use mod again to find a different rem




    What I understood is that you want to convert the strings read from Output.txt to integers. So to do that you can use int() to convert str to int. To check the type, use type().



    #print("type(apple) is ", type(apple))
    #print("type(int(apple)) is ", type(int(apple)))
    for apple in outputFile:
    mod = int(apple) % 8


    Source



    I hope this helps!






    share|improve this answer






























      0














      Check this post




      I can't figure out how to convert it back to all ints so I can use mod again to find a different rem




      What I understood is that you want to convert the strings read from Output.txt to integers. So to do that you can use int() to convert str to int. To check the type, use type().



      #print("type(apple) is ", type(apple))
      #print("type(int(apple)) is ", type(int(apple)))
      for apple in outputFile:
      mod = int(apple) % 8


      Source



      I hope this helps!






      share|improve this answer




























        0












        0








        0







        Check this post




        I can't figure out how to convert it back to all ints so I can use mod again to find a different rem




        What I understood is that you want to convert the strings read from Output.txt to integers. So to do that you can use int() to convert str to int. To check the type, use type().



        #print("type(apple) is ", type(apple))
        #print("type(int(apple)) is ", type(int(apple)))
        for apple in outputFile:
        mod = int(apple) % 8


        Source



        I hope this helps!






        share|improve this answer















        Check this post




        I can't figure out how to convert it back to all ints so I can use mod again to find a different rem




        What I understood is that you want to convert the strings read from Output.txt to integers. So to do that you can use int() to convert str to int. To check the type, use type().



        #print("type(apple) is ", type(apple))
        #print("type(int(apple)) is ", type(int(apple)))
        for apple in outputFile:
        mod = int(apple) % 8


        Source



        I hope this helps!







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 14 '18 at 3:14

























        answered Nov 14 '18 at 3:08









        FhdFhd

        13




        13






























            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%2f53292210%2fsave-text-into-a-seperate-file-as-an-integer-instead-of-a-string-python%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

            Xamarin.iOS Cant Deploy on Iphone

            Glorious Revolution

            Dulmage-Mendelsohn matrix decomposition in Python