python--脚本语言

来源:互联网 发布:java web api demo 编辑:程序博客网 时间:2024/05/19 08:36

1.进入python

Python,一个解释型、面向对象的、带有动态语义的高级程序设计语言。

1989年阿姆斯特丹,圣诞节,Guido van Rossum第一个python版本。

Python编程语言中的定位:

--脚本语言(scripting language),高阶动态编程语言

Python特征:简单易学,解释性&编译性语言,面向对象,高级语言,可扩展性及可嵌入性,免费、开源,丰富的库。

 

2.搭建python环境

       Linux环境vim编辑和Windows环境

 

3.python文件类型

       源代码—python源代码的文件以”.py”为扩展名,由python程序解释,不需要编译;

字节代码—python源文件经编译后生成的扩展名为”.pyc”文件;

编译方法—import py_compile

                py_compile.compile(“hello.py”)

优化代码—经过优化的源代码,扩展名为”.pyo”

          Python –O –m py_compile hello.py

以上三种均可直接运行


user1@ubuntu:~$ suPassword: root@ubuntu:/home/user1# cd ~root@ubuntu:~# cd csvtpy/root@ubuntu:~/csvtpy# lsroot@ubuntu:~/csvtpy# vim 1.pyroot@ubuntu:~/csvtpy# python 1.pyhello worldroot@ubuntu:~/csvtpy# pythonPython 2.7.3 (default, Apr 10 2013, 06:20:15) [GCC 4.6.3] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> print 'hello world!'hello world!>>> exit()root@ubuntu:~/csvtpy# ls1.pyroot@ubuntu:~/csvtpy# vim 1.pyroot@ubuntu:~/csvtpy# lltotal 12drwxr-xr-x 2 root root 4096 Nov 23 02:48 ./drwx------ 4 root root 4096 Nov 23 02:48 ../-rw-r--r-- 1 root root   39 Nov 23 02:48 1.pyroot@ubuntu:~/csvtpy# chod +x 1.pyNo command 'chod' found, did you mean: Command 'chmod' from package 'coreutils' (main)chod: command not foundroot@ubuntu:~/csvtpy# chmod +x  1.pyroot@ubuntu:~/csvtpy# root@ubuntu:~/csvtpy# root@ubuntu:~/csvtpy# python 1.pyhello worldroot@ubuntu:~/csvtpy# root@ubuntu:~/csvtpy# root@ubuntu:~/csvtpy# ./1.pyhello worldroot@ubuntu:~/csvtpy# ls1.pyroot@ubuntu:~/csvtpy# vim 2.pyroot@ubuntu:~/csvtpy# ls1.py  2.pyroot@ubuntu:~/csvtpy# ./2.pybash: ./2.py: Permission deniedroot@ubuntu:~/csvtpy# python 2.pyTraceback (most recent call last):  File "2.py", line 3, in <module>    py_compile.complie('1.py')AttributeError: 'module' object has no attribute 'complie'root@ubuntu:~/csvtpy# vim 2.pyroot@ubuntu:~/csvtpy# python  2.pyTraceback (most recent call last):  File "2.py", line 3, in <module>    py_compile.complie('1.py')AttributeError: 'module' object has no attribute 'complie'root@ubuntu:~/csvtpy# vim 2.pyroot@ubuntu:~/csvtpy# ls1.py  2.pyroot@ubuntu:~/csvtpy# python  2.pyroot@ubuntu:~/csvtpy# ls1.py  1.pyc  2.pyroot@ubuntu:~/csvtpy# vim 1.pycroot@ubuntu:~/csvtpy# ls1.py  1.pyc  2.pyroot@ubuntu:~/csvtpy# python -o -m py_compile 1.pyUnknown option: -oUnknown option: -ousage: python [option] ... [-c cmd | -m mod | file | -] [arg] ...Try `python -h' for more information.root@ubuntu:~/csvtpy# python -O -m py_compile 1.pyroot@ubuntu:~/csvtpy# ls1.py  1.pyc  1.pyo  2.pyroot@ubuntu:~/csvtpy# vim 1.pyoroot@ubuntu:~/csvtpy# ls1.py  1.pyc  1.pyo  2.pyroot@ubuntu:~/csvtpy# chmod +x *root@ubuntu:~/csvtpy# ls1.py  1.pyc  1.pyo  2.pyroot@ubuntu:~/csvtpy# ./1.pyhello worldroot@ubuntu:~/csvtpy# ./1.pyc./1.pyc: line 1: $'\003\363\r': command not found./1.pyc: line 2: syntax error near unexpected token `('./1.pyc: line 2: `???Rc@sdGHdS(s'                                        hello worldN((((s1.py<module>sroot@ubuntu:~/csvtpy# python 1.pyhello worldroot@ubuntu:~/csvtpy# pthon 1.pycNo command 'pthon' found, did you mean: Command 'python' from package 'python-minimal' (main)pthon: command not foundroot@ubuntu:~/csvtpy# python 1.pychello worldroot@ubuntu:~/csvtpy# python 1.pyohello worldroot@ubuntu:~/csvtpy# vim 1.pyroot@ubuntu:~/csvtpy# cd ~root@ubuntu:~#