Introduction to Computing with Python - Tutorial 1 Directories, Command Prompt and SpyderFile

Today 

  • Paths and Directories

  • Anaconda Command Prompt

  • Python 3

  • Input\Output

  • Spyder IDE

 PATHS AND DIRECTORIES

Operating System (OS) 

  • Every computer must have an operating system, from super computers to personal computers and cellular phones.
  • An Operating System is a Computer Program like any other.
  • It offers various services and “Quality of life” improvements for the human user:
    • Handling files, input/output devices.
    • Multitasking – Running multiple programs and applications at once.
    • Having various built-in utilities: Browser, calculator, sketch board, etc.

Data Organization 

  • Data is stored inside a computer as a sequence of bits.
  • Every file is a sequence of bits.
  • A computer holds large number of different files (hundreds of thousands and more)

How to organize all this data?

Files 

  • A file is addressed by a filename.
  • Filenames are composed of name dot extension: .
  • With what file types are you familiar with?

  • For example: my_file.doc
  • The file extension defines the type of content inside the file:
  • Text and Word files (.txt .doc)
  • Images (.gif .jpg .bmp .png)
  • Media (.avi .mpg .mp3 .mp4 .wav)
  • Programs (.exe)  <-----    A collection of commands stored as Machine Code

Directory Structure 

Path 

 

ANACONDA PROMPT 

  • Press Start
  • Find Anaconda3
  • Find and launch Anaconda Prompt

•The command Prompt is another way to interact with the operating 
system.
• To change color, font size:
•  Alt+Enter for full screen. 

Current Directory 

When opening the command prompt, it is waiting for instructions.
•  The current working directory is always visible:

•  After typing a command, we press Enter for execution. 

Change Directory 

  • To change the current working directory, use the cd name command:
  • “cd” – short for change directory
  • name – the name of the folder

  • To go back one level, use cd.. command:

  • You can go to the root folder by using cd.. 

        command multiple times: 

 Errors  

  • What if we try to change to a directory which doesn’t exist? 

  • We got an Error
  • That’s fine and expected. We can continue typing commands as usual.

Directory Contents 

To view the contents of a directory simply type the command dir:

 Lower/Upper Case?

  • You can type cd, CD, cD, or Cd. Any combination will work.
  • Windows OS doesn’t distinguish between upper-case and lower-case letters.
  • Later in the course we will see that in some cases, it DOES make a difference.

Particularly, in Python: 

 PYTHON 3

What is Python? 

 Python is a high-level general purpose programming language.
• Known for its vast selection of standard and 3rd-party libraries
•  Commonly used for:
•  Scientific uses (Free Matlab\Excel alternative)
•  Data Analysis and Visualization
•  Web Development
•  Computer Vision
•  Machine Learning
• Scripting and Automation

 Python REPL

  • REPL (Read Evaluate Print Loop) – Python command entry and output display.
  • Type python in the Anaconda Prompt to launch the Python REPL:

  • You can experiment freely with Python code inside the REPL.
  • Press CTRL+Z and Enter to return to the Anaconda Prompt.

My First Program 

  • The print function tells the computer to print what is inside the quotes.
  • By default, the function adds a new line after the printed text. 

 Running a Program

  • Instead of running single commands, we can run a whole program through Python.
  • A program is simply a collection of instructions, stored as text.
  • To run a Python program inside the Anaconda Prompt use:

python my_program.py

  • python – run the following program through the Python Interpreter
  • my_program.py – the name of the program you want to run

 INPUT/OUTPUT

Input/Output 

  • A program can receive information from the user as input.
  • A program can display information for the user as output.
  • The keyboard and the display are the default means for input and output.

Input/Output 

Sometimes we want to get 
input from the user.
•  We can use the input()
function in Python.

  • This function can include 
    helpful text to be displayed for 
    the user.

• As seen before, for output 
we can use the print function. 

 

Input/Output Redirection 

It is possible to send/receive input/output to/from a Python program via text files. This is called Input/Output Redirection.
•  You will receive text files which include input to be used in your programs with expected output.
•  After creating the program, you will check if your resulting output matches the expected output.
•  This will help you avoid typing the input every time you want you check your program (especially if the input is long) and save time. 

Input From File 

Consider our simple program:


•  Let’s assume this program is stored inside a file called tut1.py
•  By using input redirection, we can supply input to this program from an external text file. Here is the input file in.txt:


•  You can create this file by using Notepad or any other way. 

  • To redirect the input into our program, we will run our program via the Anaconda Prompt in a specific way:
  • After the name of the program, we will add: < in.txt

  • Similarly, we can redirect output from a program to an external file.
  • After the name of the program, we will add: > out.txt

  • out.txt will be created automatically:

Why Not Both? 

  • We can combine both methods to redirect input/output to/from text files:

Notice that the program ran without typing input or displaying any output. This is due to redirection! 

Input/Output Redirection Summary 

 

 SPYDER

 Spyder

  • Anaconda – A simple installation package for Python.
  • IDE (Integrated Development Environment) – is special software made of tools for building and developing software. Basically, a fancy text-editor.
  • We will use Spyder IDE through the Anaconda platform.

Spyder: Editor 

 The Spyder Editor is where we 
type code or create programs
• It is similar in nature to Notepad or 
Word. Code is nothing more but text!
•  You can work on multiple files at once
The Spyder Editor includes useful functionality:
•   Syntax highlighting
•   Linting – automatic check for errors
•   Debugging – will be discussed later.
•   And more…

Change font size quickly (works also in Anaconda Prompt):
First make sure the editor window is selected. Hold CTRL on the keyboard and rotate the mouse 
wheel (or swipe up/down on the trackpad with two fingers)
• Change themes, colors and design: 

 

Spyder: Console 

The Spyder Console is similar in nature to what we did in the Command Prompt.
•  It acts as an IPython Console and a Command Prompt.
•  You can type various commands, run programs and execute Python code.
•  It is encouraged to experiment as much as you can!

Spyder: Help 

 

 

•  You can search various keywords (functions, commands, modules, etc) 
and receive detailed information.
•  Useful for exploring additional functionality or refresh your memory if 
you forgot something.

 

 

Spyder: Variable Explorer 

 

•  The Variable Explorer keeps track of the current variables that are 
stored in memory.
•  Will help us tremendously with debugging later in the course. 

 

 

 

 

 

 

 

  • 5
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

带带萌新JAMMY BEAR

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值