Beyond the Basic Stuff with Python
| C2 | C3 | C4 | C5 | C6 | C7 | C8 | C9 | C10 | C11 | C12 |
|---|---|---|---|---|---|---|---|---|---|---|
| 100 |
Beyond the Basic Stuff with PythonC1 处理错误及请求帮助。1. 三步处理错误:2. 请求帮助C2 环境设置和命令行* 常用命令行--可以查“Linux与Windows命令对比”* 环境变量和路径
C1 处理错误及请求帮助。
python “ZeroDivisionError: division by zero” #搜索时打引号
1. 三步处理错误:
-
Examining Tracebacks
-
Searching for Error Messages
-
Preventing Errors with Linters
-
关于安装linter:
You can install Pyflakes(一种a linter) from https://pypi.org/project/pyflakes/ or by running pip install --user pyflakes.
*On Windows, you can run the* python and pip commands. But on macOS and Linux, these command names are for Python version 2 only, so instead you’ll need to run python3 and pip3*
2. 请求帮助
-
储存代码格式的网站 https://pastebin.com/
-
附上了一个好的问题格式。
C2 环境设置和命令行
内容包括: 文件系统,路径,home目录(系统盘所在的位置),当前工作文件夹,绝对路径,相对路径,程序和进程; 命令行、打开终端窗口、输入命令行运行程序、命令行参数、-c参数来运行python、命令行运行python、运行py.exe.程序、用python模块subprocess运行shell commands、Tab快捷输入、查看命令行历史(W:doskey /history ;咋不管用, history command)
* 常用命令行--可以查“Linux与Windows命令对比”
-
-
切换目录 cd
* home文件夹:
cd ~on macOS and Linux;cd %USERPROFILE%on Windows* 文件夹有空格,要加双引号。
* windows切换盘 用
d:; 返回上一层cd .. -
列出目录dir和ls
ls -al可以出现更多信息: Linux和macOS
-
找文件
* windows:
dir /s *.py遍历父和子文件夹取找py文件* 同样的命令:
find . -name "*.py"注意后面打了引号。 -
复制文件和文件夹
copy [source file or folder] [destination folder]cp[source file or folder] [destination folder] -
移动文件和文件夹
move [source file or folder] [destination folder]mv[source file or folder]``[destination folder] -
使用ren and mv重命名
ren[file or folder] [new name]mv[file or folder] [new name] -
删除文件
del[file or folder]#只删除文件,不删除文件名,不影响子文件夹,del /s /q [file or folder]安静地删除所有文件,包含子文件夹里的文件,非文件夹。rm[file]rd /s /q [folder]#删除windows整个文件夹rm –r[folder]#删除linus/macOS整个文件夹 -
新建文件夹
md[new folder] -
删除文件夹
rd[source folder]: widnowsrmdir[source folder]: macOS and Linux -
找程序的目录
where[program] on Windows ;不知道为什么, 我这个只能用powershell输入gcm查询which[program] on macOS and Linux -
清空终端窗口
clson Windowsclearon macOS
* 环境变量和路径
-
查看环境变量
set(on Windows) orenv(on macOS and Linux)查看home环境变量
echocommand. Runecho %HOMEPATH%on Windows orecho $HOMEon macOS and Linux环境变量的顺序有先后
-
临时变更环境变量
path C:\newFolder;%PATH%PATH=/newFolder:$PATH -
永久变更环境变量
setx /M PATH "C:\newFolder;%PATH%"export PATH=/newFolder:$PATH -
方便运行python的方法
windows:以下文件保存为.bat。
@py.exe C:\path\to\yourScript.py %*
@pauselinux需要保存到home文件夹中,.py文件首行写
#!/usr/bin/env python3(shebang line),输入./yourScript.py运行。chmod u+x yourScript.py

浙公网安备 33010602011771号