
# loop for all the args passed when this. # if invoke this scrpit with more than 1 argument. # set dir_name's value to current folder by default. When you run list_file_path.py, it will first print out each command-line argument when you invoke it and then show all the file or folder’s absolute path in the folder that you pass to the python file.
Create another python file with the IDLE editor or any text editor, save the python file as list_file_path.py, it is saved in the same directory with list_file.py. #Mac run unix executable file from jupyter notebook code#
Focus on the below line and click the Run button, you can see all files and folders’ names listed under the code line.
Add another line cell and write the below code in it. Now you can find the list_file.py has been created or overwrote in your jupyter notebook webserver started folder. Select the above line cell to make it focus, then click the Run button at the top to run it, then you can see a message is printed, the message is Writing list_file.py ( if list_file.py do not exist ) or Overwriting list_file.py ( if list_file.py exist ). # print out file name in the standard output. # get all the dir_name directory contained files in a list # give the first argument value to a local variable, the argument value should be a directory name. # set dir_name value to current directory by default. # use ipython magic command %%writefile to create a python script file and write below script content to it. If you do not pass any folder name as the command line input arguments when you invoke list_file.py, it will list the files and directories’ names in the current directory. When you run this python script file in jupyter notebook, it will print out all the files and directories’ names in the folder which you pass to it as a command-line input argument. Below ipython code will create a python script file with name list_file.py. Add the first line cell and input below source code. Click file InvokePythonScript.ipynb to edit it. ( There are also 2 python script files list_file.py and list_file_path.py which we will introduce later.
Create a jupyter notebook file with the name InvokePythonScript.ipynb. Invoke Python Script File From Jupyter Notebook.