Spyder Interface
• Spyder can be opened using the Anaconda Distribution. It can also be installed separately
using .pip.
• After opening Spyder, in case the Interface looks like this, go to View->Window Layouts -
> Spyder Default Layout
1
1
The Spyder Interface comprises three windows: Editor, IPython Console and
Variable/File/Plots/Help Pane
Can be used to view the variables in the code, files in the
Working Directory, access help menu options etc.
Editor Pane: Can be used to
work in the Script Mode
IPython (Interactive Python) Console: Can be used to
work in the Python Interactive Mode. Displays the
Outputs of the Script/Interactive Commands
2
2
Changing the Working Directory in Spyder
• The working directory is just a file path on your computer that sets the default
location of any files you read into Python, or save out of Python.
• There are three ways to set a working directory:
Using the File Folder Icon
Using in-built library os (Operating System)
Using Command cd (Change Directory)
3
3
Changing Working Directory Using the Icon
To choose a working directory, click on the
Icon and Choose the Desired Folder
4
4
Changing Working Directory using os Library
# is used to give comments in a code;
comments are not executed by the
interpreter
Import function is used to import
libraries; os stands for operating system
Note that the file location consists of
forward slashes. chdir is the change
directory library function in the os library
R or r converts stands for raw strings. In
the Raw Strings prefixed with ‘r’ or R,
backslashes are not handled in any
special way, so r"\n" literally means '\'
and 'n', while "\n" means a newline
5
character. 5
Changing Working Directory using the cd function
Changing Working Directory
Working in Interactive Mode in Spyder
• To work in interactive mode on the Spyder IDE, type your command(s) in the
Ipython console pane of Spyder Window.
• It will give you the output of the command there itself.
The IPython console takes
commands in front of In[ ] prompt
and often shows output with
Out[ ]
In order to print both the variable
values together, we give the print
command like this
8
8
Working in Script Mode in Spyder
• To work in script mode in Spyder IDE, type your command(s) in the Editor Pane.
• To start a new script file, click File -> New File
• To save current script, use the command File->Save or File ->Save As.
• Python scripts have file extension as .py
• Make sure to select the file type as Python Files
• After you have typed your script and saved it, you can run your script by:
Clicking at Run icon ( ) on the toolbar
By clicking at Run->Run command
By pressing shortcut key F5
• The Output will be displayed in the Console
9
9
Working in Script Mode in Spyder
10
10