📜  %%writefile jupyter - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:30.837000             🧑  作者: Mango

代码示例1
# adapted from source link
%%writefile is used at the beginning of a Notebook cell to convert
it into an executable script

Suppose the following lines define a Notebook cell:
  
  >>> %%writefile myfile.py
  >>> def my_function():
        print("Hello from a function")
  >>> my_function()
  
Once you have run the cell, a script named "my_file.py" will be created
in the current directory. 
You can also specify a different path with the usual syntax:
  >>> %%writefile path/to/myfile.py 
where you will have to substitute "path/to/" with the actual path where
the script will be saved