python源程序只是个特殊格式的文本文件,可以使用任意文本文件编辑软件做python开发。
执行python 的三种方式:
- 在终端中直接使用python的解释器,加载一个python的源程序就可以了:python/python3
$ python 01.py
交互式运行就是直接在终端中运行解释器,而不输入要执行的文件名。在Python的Shell中直接输入Python的代码,会立即看到程序执行结果。
bogon:~ apple$ cd ML1
bogon:ML1 apple$ python3 #进入默认的python shell
Python 3.6.5 |Anaconda, Inc.| (default, Apr 26 2018, 08:42:37)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> #这里可开始输入python代码
>>> exit()
bogon:ML1 apple$
适合学习/验证Python语法或局部代码。但不能保存或运行太大的代码。
>>> exit()
或者按ctrl d可以退出python解释器
- 交互式软件:ipython
支持自动补全和缩进,支持bash shell命令即可直接输入Linux命令。
bogon:ML1 apple$ ipython
Python 3.6.5 |Anaconda, Inc.| (default, Apr 26 2018, 08:42:37)
Type 'copyright', 'credits' or 'license' for more information
IPython 6.4.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: #这里可以输入python或Linux命令
按ctrl d或者直接输入exit退出shell
- 集成开发环境:PyCharm(以图形界面的方式快速编写和调试代码)
IDE:Integrated Development Environment 集成了开发软件需要的所有工具,一般包括:
- 图形用户界面
- 代码编辑器(支持 代码补全/自动缩进)
- 编译器/解释器
- 调试器 (断点/单步执行)
- ……
所谓打上断点,就是程序仍然正常执行,但是一旦执行到设置了断点的位置,程序就会暂停下来,并且提示程序的相关信息,辅助 代码调试 的工作。
常用IDE:PyCharm
适合大型项目开发
- 一个大项目通常包含很多源文件
- 每个源文件的代码行数是有限的、通常在几百行之内
- 每个源文件各司其职,共同完成复杂的业务功能
debug
- 手误
NameError: name 'pirnt' is not defined
名称错误:
pirnt名字没有定义
- 每行代码只能负责完成一个动作,否则
SytaxError: invalid sytax
语法错误:语法无效
3.缩进错误
IndentationError: unexpected indent
缩进错误:不期望出现的缩进
4.Python2.x默认不支持中文
SytaxError: Non-ASCII character '\xe4' in file 1.py on line 3, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
语法错误:在1.py中第3行出现了非ASCII字符 '\xe4' ,但是没有声明文件编码,请访问 http://python.org/dev/peps/pep-0263/了解详细信息