IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> Python知识库 -> Introduction to Computing with Python - Tutorial 1 Directories Command Prompt and SpyderFile -> 正文阅读

[Python知识库]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.?

?

?

?

?

?

?

?

  Python知识库 最新文章
Python中String模块
【Python】 14-CVS文件操作
python的panda库读写文件
使用Nordic的nrf52840实现蓝牙DFU过程
【Python学习记录】numpy数组用法整理
Python学习笔记
python字符串和列表
python如何从txt文件中解析出有效的数据
Python编程从入门到实践自学/3.1-3.2
python变量
上一篇文章      下一篇文章      查看所有文章
加:2022-09-13 11:10:10  更:2022-09-13 11:11:12 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年12日历 -2024/12/26 14:06:23-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码
数据统计