How to edit and save text files (.py) in Google Colab?












13















I cloned a github repo using !git clone https://github.com/llSourcell/Pokemon_GAN.git. I wanted to modify a .py file inside Colab. So i used %load filename.py as suggested here (How to load/edit/run/save text files (.py) into an IPython notebook cell?). But whenever i run this command, i get disconnected after some time. I was wondering if there is some other way to edit .py file without undergoing the hassle of downloading it to pc,editing and then re uploading it. Thanks in advance.










share|improve this question


















  • 1





    There's no particularly good way to edit directly in colab right now. Can you file an issue with repro steps for the hang on %load at github.com/googlecolab/colabtools?

    – Craig Citro
    Feb 9 '18 at 5:35













  • Thanks for the clarification.

    – randomName
    Feb 9 '18 at 12:32
















13















I cloned a github repo using !git clone https://github.com/llSourcell/Pokemon_GAN.git. I wanted to modify a .py file inside Colab. So i used %load filename.py as suggested here (How to load/edit/run/save text files (.py) into an IPython notebook cell?). But whenever i run this command, i get disconnected after some time. I was wondering if there is some other way to edit .py file without undergoing the hassle of downloading it to pc,editing and then re uploading it. Thanks in advance.










share|improve this question


















  • 1





    There's no particularly good way to edit directly in colab right now. Can you file an issue with repro steps for the hang on %load at github.com/googlecolab/colabtools?

    – Craig Citro
    Feb 9 '18 at 5:35













  • Thanks for the clarification.

    – randomName
    Feb 9 '18 at 12:32














13












13








13


1






I cloned a github repo using !git clone https://github.com/llSourcell/Pokemon_GAN.git. I wanted to modify a .py file inside Colab. So i used %load filename.py as suggested here (How to load/edit/run/save text files (.py) into an IPython notebook cell?). But whenever i run this command, i get disconnected after some time. I was wondering if there is some other way to edit .py file without undergoing the hassle of downloading it to pc,editing and then re uploading it. Thanks in advance.










share|improve this question














I cloned a github repo using !git clone https://github.com/llSourcell/Pokemon_GAN.git. I wanted to modify a .py file inside Colab. So i used %load filename.py as suggested here (How to load/edit/run/save text files (.py) into an IPython notebook cell?). But whenever i run this command, i get disconnected after some time. I was wondering if there is some other way to edit .py file without undergoing the hassle of downloading it to pc,editing and then re uploading it. Thanks in advance.







python jupyter-notebook google-colaboratory






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Feb 8 '18 at 13:50









randomNamerandomName

6613




6613








  • 1





    There's no particularly good way to edit directly in colab right now. Can you file an issue with repro steps for the hang on %load at github.com/googlecolab/colabtools?

    – Craig Citro
    Feb 9 '18 at 5:35













  • Thanks for the clarification.

    – randomName
    Feb 9 '18 at 12:32














  • 1





    There's no particularly good way to edit directly in colab right now. Can you file an issue with repro steps for the hang on %load at github.com/googlecolab/colabtools?

    – Craig Citro
    Feb 9 '18 at 5:35













  • Thanks for the clarification.

    – randomName
    Feb 9 '18 at 12:32








1




1





There's no particularly good way to edit directly in colab right now. Can you file an issue with repro steps for the hang on %load at github.com/googlecolab/colabtools?

– Craig Citro
Feb 9 '18 at 5:35







There's no particularly good way to edit directly in colab right now. Can you file an issue with repro steps for the hang on %load at github.com/googlecolab/colabtools?

– Craig Citro
Feb 9 '18 at 5:35















Thanks for the clarification.

– randomName
Feb 9 '18 at 12:32





Thanks for the clarification.

– randomName
Feb 9 '18 at 12:32












6 Answers
6






active

oldest

votes


















6














Unfortunately, it seems, colab do not support %load line magic (yet), and yet, you can see the file content using !cat your_file.py and then manually, copy the output contents, write them to a new cell and write %%writefile your_new_file_name.py at the top of the new cell to save this back to the instance. Note that, this will not be saved to your google drive yet.



Example:
!ls
output: colabData/

%%writefile something.py
print("everything's fine.")

!ls
output: colabData/ something.py

%run something.py
output: everything's fine.





share|improve this answer































    3














    Not a perfect solution but can be useful for someone.



    You can use
    !cat file_name.py to access file_name.py contents, copy the contents in the next cell and now you can run it or edit it.






    share|improve this answer



















    • 5





      After editing how do you save it back?

      – MiloMinderbinder
      Mar 11 '18 at 9:59



















    1














    Solution:



    p = """
    Yadda yadda
    whatever you want just don't use triple quotes.
    """

    c = """text_file = open("text.text", "w+");text_file.write(p);text_file.close()"""

    exec(c)





    share|improve this answer

































      0














      While I don't have a way of editing in the notebook, I will share my pipeline.
      Quite obvious really:




      • fork the repo or create a new one(for a new project)

      • create a branch just for uploading

      • make changes and push

      • evaluate

      • make changes


      Hope that helps.






      share|improve this answer































        0














        There is an app called Python Compiler Editor that you can connect to your Google Drive account, edit files and save them back.






        share|improve this answer































          0














          You can use Ipython magic commands. Use below command

          %pycat code.py


          A pop up will appear displaying the code. You can copy it and edit it locally.

          Remove the file using below command

          !rm code.py


          Copy the edited code to a cell in notebook and add below command at the top of the cell

          %%writefile code.py


          Run the cell. A file will be created with the contents present in the cell.






          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%2f48687091%2fhow-to-edit-and-save-text-files-py-in-google-colab%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            6 Answers
            6






            active

            oldest

            votes








            6 Answers
            6






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            6














            Unfortunately, it seems, colab do not support %load line magic (yet), and yet, you can see the file content using !cat your_file.py and then manually, copy the output contents, write them to a new cell and write %%writefile your_new_file_name.py at the top of the new cell to save this back to the instance. Note that, this will not be saved to your google drive yet.



            Example:
            !ls
            output: colabData/

            %%writefile something.py
            print("everything's fine.")

            !ls
            output: colabData/ something.py

            %run something.py
            output: everything's fine.





            share|improve this answer




























              6














              Unfortunately, it seems, colab do not support %load line magic (yet), and yet, you can see the file content using !cat your_file.py and then manually, copy the output contents, write them to a new cell and write %%writefile your_new_file_name.py at the top of the new cell to save this back to the instance. Note that, this will not be saved to your google drive yet.



              Example:
              !ls
              output: colabData/

              %%writefile something.py
              print("everything's fine.")

              !ls
              output: colabData/ something.py

              %run something.py
              output: everything's fine.





              share|improve this answer


























                6












                6








                6







                Unfortunately, it seems, colab do not support %load line magic (yet), and yet, you can see the file content using !cat your_file.py and then manually, copy the output contents, write them to a new cell and write %%writefile your_new_file_name.py at the top of the new cell to save this back to the instance. Note that, this will not be saved to your google drive yet.



                Example:
                !ls
                output: colabData/

                %%writefile something.py
                print("everything's fine.")

                !ls
                output: colabData/ something.py

                %run something.py
                output: everything's fine.





                share|improve this answer













                Unfortunately, it seems, colab do not support %load line magic (yet), and yet, you can see the file content using !cat your_file.py and then manually, copy the output contents, write them to a new cell and write %%writefile your_new_file_name.py at the top of the new cell to save this back to the instance. Note that, this will not be saved to your google drive yet.



                Example:
                !ls
                output: colabData/

                %%writefile something.py
                print("everything's fine.")

                !ls
                output: colabData/ something.py

                %run something.py
                output: everything's fine.






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered May 31 '18 at 1:10









                b.g.b.g.

                7614




                7614

























                    3














                    Not a perfect solution but can be useful for someone.



                    You can use
                    !cat file_name.py to access file_name.py contents, copy the contents in the next cell and now you can run it or edit it.






                    share|improve this answer



















                    • 5





                      After editing how do you save it back?

                      – MiloMinderbinder
                      Mar 11 '18 at 9:59
















                    3














                    Not a perfect solution but can be useful for someone.



                    You can use
                    !cat file_name.py to access file_name.py contents, copy the contents in the next cell and now you can run it or edit it.






                    share|improve this answer



















                    • 5





                      After editing how do you save it back?

                      – MiloMinderbinder
                      Mar 11 '18 at 9:59














                    3












                    3








                    3







                    Not a perfect solution but can be useful for someone.



                    You can use
                    !cat file_name.py to access file_name.py contents, copy the contents in the next cell and now you can run it or edit it.






                    share|improve this answer













                    Not a perfect solution but can be useful for someone.



                    You can use
                    !cat file_name.py to access file_name.py contents, copy the contents in the next cell and now you can run it or edit it.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Mar 10 '18 at 16:29









                    krishnakrishna

                    1,077418




                    1,077418








                    • 5





                      After editing how do you save it back?

                      – MiloMinderbinder
                      Mar 11 '18 at 9:59














                    • 5





                      After editing how do you save it back?

                      – MiloMinderbinder
                      Mar 11 '18 at 9:59








                    5




                    5





                    After editing how do you save it back?

                    – MiloMinderbinder
                    Mar 11 '18 at 9:59





                    After editing how do you save it back?

                    – MiloMinderbinder
                    Mar 11 '18 at 9:59











                    1














                    Solution:



                    p = """
                    Yadda yadda
                    whatever you want just don't use triple quotes.
                    """

                    c = """text_file = open("text.text", "w+");text_file.write(p);text_file.close()"""

                    exec(c)





                    share|improve this answer






























                      1














                      Solution:



                      p = """
                      Yadda yadda
                      whatever you want just don't use triple quotes.
                      """

                      c = """text_file = open("text.text", "w+");text_file.write(p);text_file.close()"""

                      exec(c)





                      share|improve this answer




























                        1












                        1








                        1







                        Solution:



                        p = """
                        Yadda yadda
                        whatever you want just don't use triple quotes.
                        """

                        c = """text_file = open("text.text", "w+");text_file.write(p);text_file.close()"""

                        exec(c)





                        share|improve this answer















                        Solution:



                        p = """
                        Yadda yadda
                        whatever you want just don't use triple quotes.
                        """

                        c = """text_file = open("text.text", "w+");text_file.write(p);text_file.close()"""

                        exec(c)






                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Oct 29 '18 at 5:53









                        maxymoo

                        19.9k34069




                        19.9k34069










                        answered Oct 29 '18 at 0:53









                        Emmanuel LopezEmmanuel Lopez

                        184




                        184























                            0














                            While I don't have a way of editing in the notebook, I will share my pipeline.
                            Quite obvious really:




                            • fork the repo or create a new one(for a new project)

                            • create a branch just for uploading

                            • make changes and push

                            • evaluate

                            • make changes


                            Hope that helps.






                            share|improve this answer




























                              0














                              While I don't have a way of editing in the notebook, I will share my pipeline.
                              Quite obvious really:




                              • fork the repo or create a new one(for a new project)

                              • create a branch just for uploading

                              • make changes and push

                              • evaluate

                              • make changes


                              Hope that helps.






                              share|improve this answer


























                                0












                                0








                                0







                                While I don't have a way of editing in the notebook, I will share my pipeline.
                                Quite obvious really:




                                • fork the repo or create a new one(for a new project)

                                • create a branch just for uploading

                                • make changes and push

                                • evaluate

                                • make changes


                                Hope that helps.






                                share|improve this answer













                                While I don't have a way of editing in the notebook, I will share my pipeline.
                                Quite obvious really:




                                • fork the repo or create a new one(for a new project)

                                • create a branch just for uploading

                                • make changes and push

                                • evaluate

                                • make changes


                                Hope that helps.







                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered Jul 8 '18 at 10:59









                                aneesh joshianeesh joshi

                                261210




                                261210























                                    0














                                    There is an app called Python Compiler Editor that you can connect to your Google Drive account, edit files and save them back.






                                    share|improve this answer




























                                      0














                                      There is an app called Python Compiler Editor that you can connect to your Google Drive account, edit files and save them back.






                                      share|improve this answer


























                                        0












                                        0








                                        0







                                        There is an app called Python Compiler Editor that you can connect to your Google Drive account, edit files and save them back.






                                        share|improve this answer













                                        There is an app called Python Compiler Editor that you can connect to your Google Drive account, edit files and save them back.







                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered Nov 1 '18 at 2:24









                                        Marafon ThiagoMarafon Thiago

                                        1464




                                        1464























                                            0














                                            You can use Ipython magic commands. Use below command

                                            %pycat code.py


                                            A pop up will appear displaying the code. You can copy it and edit it locally.

                                            Remove the file using below command

                                            !rm code.py


                                            Copy the edited code to a cell in notebook and add below command at the top of the cell

                                            %%writefile code.py


                                            Run the cell. A file will be created with the contents present in the cell.






                                            share|improve this answer




























                                              0














                                              You can use Ipython magic commands. Use below command

                                              %pycat code.py


                                              A pop up will appear displaying the code. You can copy it and edit it locally.

                                              Remove the file using below command

                                              !rm code.py


                                              Copy the edited code to a cell in notebook and add below command at the top of the cell

                                              %%writefile code.py


                                              Run the cell. A file will be created with the contents present in the cell.






                                              share|improve this answer


























                                                0












                                                0








                                                0







                                                You can use Ipython magic commands. Use below command

                                                %pycat code.py


                                                A pop up will appear displaying the code. You can copy it and edit it locally.

                                                Remove the file using below command

                                                !rm code.py


                                                Copy the edited code to a cell in notebook and add below command at the top of the cell

                                                %%writefile code.py


                                                Run the cell. A file will be created with the contents present in the cell.






                                                share|improve this answer













                                                You can use Ipython magic commands. Use below command

                                                %pycat code.py


                                                A pop up will appear displaying the code. You can copy it and edit it locally.

                                                Remove the file using below command

                                                !rm code.py


                                                Copy the edited code to a cell in notebook and add below command at the top of the cell

                                                %%writefile code.py


                                                Run the cell. A file will be created with the contents present in the cell.







                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered Nov 14 '18 at 9:22









                                                rahulrahul

                                                493




                                                493






























                                                    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%2f48687091%2fhow-to-edit-and-save-text-files-py-in-google-colab%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

                                                    Bressuire

                                                    Vorschmack

                                                    Quarantine