Spyder s environment and other related PDF

Title Spyder s environment and other related
Course Corporate Finance
Institution Kansai University
Pages 6
File Size 376.5 KB
File Type PDF
Total Downloads 5
Total Views 178

Summary

ffdrokdrlvkdflvdlfvkflbflbljmgfbljm fjmdrgmjdrikjmdfk fkesofksoksd kmdvkdvdslm kmsdksdlkdflv lkmfjkldvdflvkm oefkdldfjkdl scksdfkslkvmkdl lmdklvdfjmv klvmfskdlfdslfk ksdlfkdfdslmk lfkdsfkdflvmfdl lkvmdflgmrkvdf lfmjdlkgvmdfklvm ldkfdlrdvldf kfldmvdflkv...


Description

SPYDER’S ENVIRONMENT Spyder is an Integrated Development Environment (IDE) that comes with Anaconda. It includes editing, testing and debugging in a single GUI. You will be presented with the following interface once you run Spyder.

Spyder includes multiple separate windows (marked with red rectangles), each of which has its own tabs (marked with green rectangles). You can change which windows you prefer to have open from the View > Panes option. The default configuration has Editor, Variable explorer, and Console/History log windows open as shown above. The iPython Console is where Anaconda displays the output of Python scripts, which informs it to load data, do math, plot data etc. You can also type individual Python commands into this window, which can be useful if you are testing things out. The Variable/File/Plots explorer is informational. To write Python code, you need to follow some rules. In programming terms, these rules are collectively called syntax. Python’s unique syntax is one of the reasons that novice programmers find it easy to learn and program. Learning the basics You have learned the basics of Spyder if you can: • • • •

Open and edit a file in Spyder’s Editor Run a script in the Editor and see the output in iPython Console. Execute basic commands in iPython console Define variables in the Editor and modify their values in the iPython console. 1

• •

View and interact with the variables in Spyder’s variable explorer Get documentation in the Help pane

Changing the background color of the Editor If you want to change the background color, click on Tools > Preferences > Appearance and then under ‘syntax highlighting theme’ option, you can select different interface themes. Choose IDLE for a white background and ‘Spyder Dark’ for a darker background. Writing a Python program (also known as a script) The left pane, by default, contains the place where you enter your Python script. This is the text editor and this is where you write your program. It is stored as a file on your hard drive. There is a green arrow in the toolbar which runs your script in the console window. Your code will be executed line-by-line, in order. Cells The text editor consists of cells and the code is written inside these cells. A cell is a block of lines that can be easily executed all at once in the current iPython console. You can divide your script into as many cells as needed, or none at all – the choice is yours. You can separate cells by lines starting with #%% (standard cell separator)

Entering data Type ‘x=5’ into a script. This is a command to create a variable named x and give it the value of 5. Run this script using the green arrow button, and then click on the ‘variable explorer’ tab. You will see that x has been added to the list of variables in Python’s memory. You can add ‘print(x)’ into your script to have it print out the value of x. Now type ‘y=4’ and then type ‘print(x+y)’. Notice that this last command does not create a variable, although it does produce an output from the calculation. To execute any code/script, use one of the following options: • • • •

Select ‘Run’ option from the main menu or click the green triangle from the top menu. Press ‘F5’ function key Place the cursor on the line and select the tool ‘Run selection’ or press ‘F9’ function key. You can select a piece of code you want to execute and press CTRL+ENTER from the keyboard.

The output will appear in the console window. iPython console It allows you to execute commands and enter, interact with and visualize data inside any number of fully featured iPython interpreters. Each console is executed in a separate process, allowing you to run scripts, interrupt execution and restart or terminate a shell without affecting the others or Spyder itself, and easily test your code in a clean environment without disrupting your primary session.

2

Spyder can launch new Ipython instances itself, through ‘Open an iPython console’ under the Consoles menu, the iPython Console pane menu or its context menu (Ctrl + T). Each console implements a robust two-process iPython session, with a lightweight front-end interface connected to a full kernel backend. Files pane The files pane is a filesystem and directory browser built right into Spyder. You can view and filter files according to their type and extension, open them with the Editor and perform many common operations. To browse the files on your system, use the arrows at the top of the pane. You can expand/collapse the folders in the pane to display the files and subdirectories hierarchically. Double-clicking a folder will open it, showing the files inside and making it your working directly. REMEMBER THAT YOUR DATA FILES (XLS, CSV etc.) NEED TO BE IN THE WORKING DIRECTORY BEFORE YOU RUN THE PROGRAM. Otherwise, you have to specify a full path in the code in order for Python to locate this data file. To open a file in the Editor from the Files pane, double-click its name. If you right-click over it, you will see a context menu that allows you to access a number of functions, including running scripts, creating, renaming, moving, deleting files etc. The Options menu in the top right of the Files pane offers several ways to customize how your files are displayed. By default, the pane displays the contents of your working directory without filtering. However, it can filter the list to show only files matching the patterns set under ‘Show filenames with these extensions’. Variable explorer This pane allows you to interactively browse and manage the objects generated during your code. It shows the namespace contents (including all global objects, variables, class instances and more) of the currently selected iPython console session, and allows you to add, remove, and edit their values through a variety of GUI-based editors. It gives you information on the name, size, type and value of each object. To modify a scalar variable, like a number, string or Boolean, simply double click it in the pane and type its new value. It offers built-in support for editing lists, strings, dictionaries, NumPy arrays, Pandas dataframes, series and more, as well as being able to plot and visualize them with one click. The options menu in the top right corner of the variable explorer allows you to filter the objects shown by a number of different criteria.

3

4

The context menu, available by right-clicking any variable, provides numerous additional options to interact with objects of various types. These include renaming, removing or editing existing variables, as well as the duplicate option to create a new copy of one of them under a new name you enter in the resulting dialog box. Help pane You can use the Help pane to find, render and display rich documentation for any object with a docstring, including modules, classes, functions, and methods. This allows you to access documentation easily from Spyder, without having to interrupt your workflow.

5

Plots The plots pane shows the static figures and images created during your session. It will show you plots from the iPython Console. The options menu in the top right of the Plots pane offers several ways to customize how your plots are displayed. Mute inline plotting: This option is enabled by default, preventing your plots from appearing in the console. If you deactivate this option, figures will display in both the Plots pane and the Console. Show plot outline: This option, off by default, shows a thin stroke surrounding the area of the figure area, which will also appear in the exported images. Fit plots to window: This option, also enabled by default, sizes the figures to match the pane. Disabling it will display plots at their native size, and allow you to use the zoom buttons at the top of the pane to scale them manually. Toolbar options: The toolbar at the top of the Plots pane provides several useful features that allow you to interact with your figures. For example, you can cycle sequentially through the plot list with the forward and back arrows. You can also save one or all of the plots in the pane to file(s) by clicking the respective ‘save/save all’ icons in the toolbar. Plots are rendered and saved as PNG by default, but SVG can also be selected as an option. Additionally, if you want to use a figure in another document, you can click ‘copy to clipboard’ button and paste your plot wherever you want, such as a Word document. Finally, you can use the ‘remove/remove all’ buttons in the toolbar to clear plots from the list. Debugging and breakpoints Debugging is the process of finding and resolving bugs (defects or problems that prevent correct operation). Debugging in Spyder is supported through integration with the enhanced ipdb debugger in the iPython console. This allows breakpoints and the execution flow to be viewed and controlled right from the Spyder GUI, as well as with all the familiar console commands. You can fully control debugger execution from the Debug menu and the Debug toolbar. The Editor shows the line of code the debugger is currently stopped on with an arrow.

Spyder’s debugger offers syntax highlighting, code completion and command history, which work exactly like they do in the normal interactive interpretor. Generating Matplotlib features is fully supported while the debugger is active, including all the different graphics backends.

For other functionalities of Spyder, please visit https://docs.spyder-ide.org/.

6...


Similar Free PDFs