0

I have a Python Script (with .py extension) and it was created by makepy.py. Is there a way to view and copy the codes inside that script and load them into my Jupyter Notebook?

I have done a Google search but strangely, I can't find this mentioned anywhere.

Do I need a specific software to do this? Or can it be done at the Python command prompt level?

user3115933
  • 4,303
  • 15
  • 54
  • 94

3 Answers3

2

You can just edit the file with a text editor. Right click and select open with. Then you can copy the code.

  • Just did that with Notepad but it is so tough to make sense out of the loads of text that appear in the window! It seems there are tags all over the place and it is very difficult to understand where a line of code starts and ends. – user3115933 Mar 26 '17 at 12:34
  • @user3115933 You probably have weird line endings. Either use a IDE like IDLE that came with the Python installation, or download Notepad++. That notepad that comes with Windows is terrible. – Carcigenicate Mar 26 '17 at 12:40
  • @Carcigenicate Thanks, I'll have a look at what you suggested. – user3115933 Mar 26 '17 at 12:41
  • @user3115933 If you have python installed, just use IDLE. It's meant for writing/viewing Python. Just search for it in the windows start menu. – Carcigenicate Mar 26 '17 at 12:42
  • Digging further, I came across this post: http://stackoverflow.com/questions/21034373/how-to-load-edit-run-save-text-files-py-into-an-ipython-notebook-cell I'll try it and post the outcome back here! – user3115933 Mar 26 '17 at 12:42
1

All that can be done directly from the Jupyter Notebook or any IPython console.

  1. to view the contents of the script

    !cat myscript.py

  2. to run the script as a program use this built-in magic command

    %run myscript.py

Community
  • 1
  • 1
Juan
  • 26
  • 2
1

You can load file in Jupyter notebook cell by:

%load your_file.py

You can do changes to it and than save it back by

%%writefile your_file.py

or

%%file your_file.py
Vlad Bezden
  • 83,883
  • 25
  • 248
  • 179