zoukankan      html  css  js  c++  java
  • python文件类型

    /* 1. python 源码文件以"py"为扩展名 */
    [root@localhost ~]# mkdir test1
    [root@localhost ~]# cd test1/
    [root@localhost test1]# vi 1.py
    //ADD
    #!/usr/bin/python
    
    print 'hello world'
    
    [root@localhost test1]# python 1.py
    hello world
    [root@localhost test1]# ls -l
    总用量 4
    -rw-r--r--. 1 root root 39 9月   3 01:22 1.py
    
    /* 加执行权限后,可以直接执行 */
    [root@localhost test1]# chmod +x 1.py
    [root@localhost test1]# ls -l
    总用量 4
    -rwxr-xr-x. 1 root root 39 9月   3 01:22 1.py
    [root@localhost test1]# ./1.py
    hello world
    /* 2. 源码经过编译后生成 扩展名为 "pyc" 的文件 */
    [root@localhost test1]# vi 2.py
    //ADD
    #!/usr/bin/python
    
    import py_compile
    
    py_compile.compile('1.py')
    
    //执行后,没有反应。但是产生了 1.pyc --〉对1.py的字符编译
    //1.pyc -〉 二进制 ,无法看懂
    [root@localhost test1]# python 2.py
    [root@localhost test1]# ls
    1.py  1.pyc  2.py
    [root@localhost test1]# file 1.pyc
    1.pyc: python 2.6 byte-compiled
    [root@localhost test1]# python 1.pyc
    hello world
    
    //如果把源码移走了,编译后的文件还是可以被执行
    [root@localhost test1]# mv 1.py /tmp/
    [root@localhost test1]# ls
    1.pyc  2.py
    [root@localhost test1]# python 1.pyc
    hello world
    /* 3.经过优化的源码文件,扩展名为"pyo" */
    
    //先把文件移回来
    [root@localhost test1]# mv /tmp/1.py .
    [root@localhost test1]# ls
    1.py  1.pyc  2.py
    
    //test
    [root@localhost test1]# python -O -m py_compile 1.py
    [root@localhost test1]# ls
    1.py  1.pyc  1.pyo  2.py
    [root@localhost test1]# ls -l
    总用量 16
    -rwxr-xr-x. 1 root root  39 9月   3 01:22 1.py
    -rw-r--r--. 1 root root 112 9月   3 01:27 1.pyc
    -rw-r--r--. 1 root root 112 9月   3 01:32 1.pyo
    -rw-r--r--. 1 root root  65 9月   3 01:27 2.py
    [root@localhost test1]# python 1.pyo
    hello world
    /* 如果想把一个源码写好后,不想要别人看,则可以将它编译成pyo 或 pyc */
  • 相关阅读:
    mysql timestamp字段定义的
    mybatis的Selective接口和普通接口的区别
    intllij IDE 中git ignore 无法删除target目录下的文件
    maven的单元测试中没有
    java volatile关键字
    RestExpress response中addHeader 导致stackOverflow
    log4j配置后行号乱码显示为?问号
    软件研发人员的职业发展规划
    CPU与内存互联的架构演变
    windows系统安装
  • 原文地址:https://www.cnblogs.com/frankielf0921/p/5834292.html
Copyright © 2011-2022 走看看