Python Introductory tutorial (i)

Source: Internet
Author: User

We are still not talking about the code, but the command line first.

Why is the command line so important? Previously, the command line is where you talk to your computer. You can send the message to the computer in the form of a sentence, and the computer responds to you in the form of a sentence. In the field of programming, some messages can only be told by the command line--perhaps programmers have been accustomed to, perhaps typing more effective-after all, you and the closed eyes of the person to communicate, certainly more than the ear of the person to communicate with the convenience (you can not use the mouse to write!) )。 In programming, most messages are by saying, not by gestures (drawing is an example of gestures). Uh...... Anyway, you have to understand the command line.

There are command lines in Windows, Linux also, but similar. To understand how the command line works, just imagine that the computer does not have a screen, but can speak. Like--

-"What's on the table?" ”
--"There are 3 folders: Recycle Bin, data, tools; 5 files: note. txt, language philosophy. pdf,.png,antistops.py, Setup. exe"
What's in the E-disk? ”
--"There are 1 folders: Work"
--What's in the work folder? ”
--"There's more than one folder called work on your computer." ”

Immediately embarrassed, after all, there is a work folder, but can not get in. So the person who designed the command line came up with the concept of "current position." We know that the organization of a folder can be seen as a "tree"-(in fact, it can't be used for filenames, I use CS instead of C #)

It's certainly more complicated than that. The current position means that you can only stand on one of the folder nodes of this tree, that is, you cannot be in more than one folder at a time. You can only see the dots around. For example, you want the computer to run Hello.exe, there are two hello.exe on the chart. With the "Current location" concept, you can only open files in the current folder. In the same folder, the filenames cannot be duplicated, guaranteeing that you can uniquely specify a file. Want to run the folder (many people in the folder called Directory, because not a mouthful) C under the Hello.exe, will go to directory C.

But people are going to get lost. This is what the designers are dealing with:

The 1.x disk is fixed, needless to say.
The directory under 2.E disk C is recorded as "e:\c", then the lower hello.c is recorded as E:\C\hello.c

Nested layers. So if you're typing cmd enter in the Run bar (or "Run" in the Start menu), I guess you understand what c:\users\administrator> means, that you're in a folder called Administrator.

In fact, there is no "current location", but also can locate each file. In the example above, no matter where you are, enter E:\C\hello.exe, the computer knows you are looking for not e:\c#\hello.exe. But each time the tree a long string, who would like it? In addition, the directory shown in the command line is called "Current working directory", referred to as the working directory, I believe you can run the command line a few times Python will understand why called "work".

So you can say these things to the command line:

    1. Enter a subdirectory (that is, a folder in the current folder)--CD XXX
    2. Go to the previous level directory (which can be called the parent directory)--CD. (just two points)
    3. Enter E:\C--CD e:\c
    4. Enter into itself ("not useless")--cd. (one point)

CD is the first letter of change directory

(You may find that some commands don't work because the home is fake.) The above command is only useful on the same disk and cannot be swapped with a CD. To switch the drive letter, enter the "drive letter name:" Carriage return, for example e: Carriage return)

The previous article also said that "Python xxx.py" is a command. In fact, the order is divided into two parts, the first word is part, and the rest is the second part. Python is Python.exe, which can be omitted from the command-line. exe (not saved or used, but habitually omitted). Python xxx.py is the boot Python.exe, and tells the program an extra message: xxx.py. This can be confusing, and running the program allows you to add something else (plus one less). CD xxxxx, is to run Cd.exe additional "parameters" xxxxx--although not necessarily cd.exe, but can be considered as having. All the commands, almost all only the first word really did. (EXE file is also a file)

And finally the absolute path and the relative path, the use is, how do you call a file that may have the same name? Still using the example just now, you are located in directory C and want to run the hello.exe of the next-door directory C #. There are currently three ways of doing this:

1.  cd .. 再 cd C# 再 hello (.exe可以省略)2.  E:\C#\hello3.  ..\C#\hello.exe

2 and 3 have done not switch working directory and processed the other directory EXE file. 2 is called absolute positioning, since starting from the disk; 3 is called relative positioning because it starts from itself. The computer only has the letter, if not, it is assumed to start from the working directory. Although it looks like this, it seems that the upper directory is named. subfolder, but it doesn't hurt--it's really fascinating. (You look at the tree chart, you will find that nodes can be regarded as the root node, a little reference to the taste of the system)

Both of these positions are possible. In fact, there is a kind of positioning-you have not thought, where Python.exe?! Remember to install the path of the first step, called "Environment variables", the environment variables are written in a number of directories can be unconditionally referenced (the current directory is also unconditional reference). The computer received your command Python, first in the working directory to find Python.exe, can not find the environment variable in the directory to find, and can not find the error.

Then you can read this: (except for. and.) Use special, and \ means the current disk start, you can use CD \, CD \c, etc.)

* cd xxx (两种定位皆可)* cd \ ——回到本盘起始位置* dir —— 查看当前目录信息(directory 缩写)* dir xxx —— 查看xxx目录(两种定位皆可)* md xxx —— 建立新文件夹(两种定位皆可) (make dir缩写)* rd xxx ——删除【空】文件夹(两种定位皆可)(remove dir 缩写)【请注意!命令行删除不进回收站,是永久删除!】* cls ——清屏(clean screen 缩写)* copy xxx xxx —— 复制文件内容(不包括名称),后面的名字为新的名字(当然,两种定位皆可)* del xxx —— 删除文件,不包括文件夹(可用 del * 删除所有文件,del * .txt 删除所有.txt文件,等等)(delete缩写)* deltree xxx —— <危险操作>删除文件夹以及一切内容* ren xxx xxx —— 重命名(rename 缩写)

The command can have parameters, that is, after the command is finished, it can be followed by something. Before that Python.exe can be followed by a file name, but the argument is just a string, not necessarily a file name. If you enter a command with multiple words, all the words will tell the first word, because that is the only thing that is running, and he will receive all the parameters. For example, the dir command can have more than 2 parameters (in addition to its own dir and regular xxx), such as followed by \a or \s, etc., please Baidu "DOS command"

Python Introductory tutorial (i)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.