Spyder and Command Line

Keith Monreal
5 min readSep 17, 2020

--

Introduction to Spyder and Command Line

1. Spyder

Launch Spyder : You may search it in the Start button or through Anaconda

The user interface of Spyder looks like this

On the left side of the screen, we can see the Code block. This is where all codes will be written.

It is also important to highlight the directory which is located here. We can change the folder in which the data sets will be imported from and in which the code will be saved by clicking the folder icon on the right most side of the highlighted red box in this illustration.

On the upper right of our user interface we can see the variable explorer and file explorer.

a. Variable Explorer: All objects in the environment will be accessible in this window.

b. File explorer shows you all the files in the selected directory/folder.

Lastly, the lower right part is the console. This is where we see the output of the codes.

As with any other beginner in any programming languages, let’s have our first words with Python be “Hello World!” write: print(“Hello World”)

There are few ways to run codes in Spyder

  • F5 for running all lines
  • Ctrl + Enter for running the selected lines

The output will be displayed in the console.

Saving the file: We can press Ctrl + Shift + Enter to save the file to any folder in our local computer.

Creating objects in the environment

Here we stored 7 as the value of the object x. We also stored the value 9 in the object y. We stored the value of their product with z using * multiplication function. The saved objects will be shown in the variable explorer.

The type indicates the structure of the object (integer, string, dataframe etc) and the size tells us the dimension of the object.

First Library: Pandas

This is one of the widely used libraries in Python. We type the following codes to import a csv file and save it as an object df

Running these codes, the df will be saved in the environment and can be viewed in the variable explorer. It is also possible with Spyder to copy this object and paste it in Excel which can be handy if we want to show the data.

Make coding more fun and easier!

Spyder analyses the codes if there are lines that needs attention based on PEP 8 (Python coding standards). We can turn this on by clicking the tool button highlighted in red and selecting Code Analysis.

In this example, I included the code : x = 7 to a comment above it. This displays a warning beside the line number that this needs attention because x will not have a value for the z = x * y to run

We can also change the theme for your user interface

If you want to start over and clear all lines in the console and clear the objects saved in the environment, you can restart the kernel here.

Lines in the console and objects in the variable explorer will be gone.

2. Command Line

Most of the time, command line is faster than working with Graphic User Interface of some applications. We can build scripts here for some applications that are only available through command line.

Windows + R > cmd

Current working directory tells us where we are on our computer. Its corresponding interface is here:

It is easier to move around different directories or folders in this interface. However, in a command line, we can only change the texts.

If we want to change directory , we just type cd (short for change directory) and indicate the folder you want to go to in this folder.

If we want to go to the parent directory, we type cd ..

We can also navigate through multiple directions, and not just back and forward a specific folder with ../..

You can also press Tab button to see suggestions on the file location for the cd command and auto complete.

--

--

Keith Monreal
Keith Monreal

Written by Keith Monreal

A statistician, aspiring to be a unicorn

No responses yet