Introduction
Chapter 1 - Dealing with Errors and Asking for Help
Chapter 2 - Environment Setup and the Command Line
Chapter 3 - Code Formatting with Black
Chapter 4 - Choosing Understandable Names
Chapter 5 - Finding Code Smells
Chapter 6 - Writing Pythonic Code
Chapter 7 - Programming Jargon
Chapter 8 - Common Python Gotchas
Chapter 9 - Esoteric Python Oddities
Chapter 10 - Writing Effective Functions
Chapter 11 - Comments, Docstrings, and Type Hints
Chapter 12 - Organizing Your Code Projects with Git
Chapter 13 - Measuring Performance and Big O Algorithm Analysis
Chapter 14 - Practice Projects
Chapter 15 - Object-Oriented Programming and Classes
Chapter 16 - Object-Oriented Programming and Inheritance
Chapter 17 - Pythonic OOP: Properties and Dunder Methods
C2 | C3 | C4 | C5 | C6 | C7 | C8 | C9 | C10 | C11 | C12 |
---|---|---|---|---|---|---|---|---|---|---|
100 |
python “ZeroDivisionError: division by zero” #搜索时打引号
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*
官方引导: https://www.python.org/about/help/
https://www.reddit.com/r/learnpython/
储存代码格式的网站 https://pastebin.com/
附上了一个好的问题格式。
内容包括: 文件系统,路径,home目录(系统盘所在的位置),当前工作文件夹,绝对路径,相对路径,程序和进程; 命令行、打开终端窗口、输入命令行运行程序、命令行参数、-c参数来运行python、命令行运行python、运行py.exe.程序、用python模块subprocess运行shell commands、Tab快捷输入、查看命令行历史(W:doskey /history ;咋不管用, history
command)
通配符匹配文件夹和文件名,如dir *.py
切换目录 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]
: widnows
rmdir[source folder]
: macOS and Linux
找程序的目录
where
[program] on Windows ;不知道为什么, 我这个只能用powershell输入gcm查询
which
[program] on macOS and Linux
清空终端窗口
cls
on Windows
clear
on macOS
查看环境变量
set
(on Windows) or env
(on macOS and Linux)
查看home环境变量
echo
command. Run echo %HOMEPATH%
on Windows or echo $HOME
on 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 %* @pause
linux需要保存到home文件夹中,.py文件首行写#!/usr/bin/env python3
(shebang line),输入./yourScript.py
运行。
chmod u+x yourScript.py