python学习之三 模块

1、模块

#!/usr/bin/python

# Filename: using_sys.py
import  sys #
print  'The command line arguments are:'
for  in  sys .argv:
    print  i

print '\n\nThe PYTHONPATH is'sys.path, '\n'

记住,脚本的名称总是sys.argv列表的第一个参数。所以,在这里,'using_sys.py'sys.argv[0]'we'sys.argv[1]'are'sys.argv[2]以及'arguments'sys.argv[3]。注意,Python从0开始计数,而非从1开始。


2、此地引用http://forum.ubuntu.org.cn/viewtopic.php?f=63&t=335543,转贴

关于Howto Generate a .pyc From Compiling a Python Program

Howto Generate a .pyc From Compiling a Python Program

In this post, I'll give you an example to demonstrates how to generate a .pyc from compiling a python program.
在本帖中,我将用一个实例演示如何编译Python程序生成.pyc文件。


What is the .pyc? A .pyc file is a compiled python bytecode file, you can visit how do I create a pyc file [1]for more information.
什么是.pyc文件? .pyc文件也就是一个已编译的python 字节码文件,您可以通过访问 how do I create a pyc file 一文获取更多信息。

Fist, I write a python script named hello.py as following:
首先,编写一个python脚本并命名为hello.py,如下所示:

#!/usr/bin/python
#
# File: hello.py
# Date: June 16 th , 2011
# Author: mutse < yyhoo2.young@gmail.com >
#
print “Hello, welcome to python world!”

Then use chmod command to change its file privilege.
接下来,使用chmod命令修改文件权限。

$ chmod a+x hello.py

Now, edit a python script as pycoder.py.
现在,编辑一个名为pycoder.py的python脚本.

#!/usr/bin/python
#
# File: pycoder.py
# Date: June 16 th , 2011
# Author: mutse < yyhoo2.young@gmail.com >
#
import py_compile

file = raw_input("Enter Your File Name: ")
py_compile.compile(file)
print ".pyc of the python script " + file + " is generated."

Then, do the same thing as hello.py.
接下来,做修改hello.py文件权限的同样的工作(修改pycoder.py文件权限)。

$ chmod a+x pycoder.py

At last, please run pycoder.py script, and a pyc bytecode hello.pyc is generated.
最后,请运行pycoder.py脚本,生成 hello.pyc 字节码文件。

$ ./pycoder.py
Enter Your File Name: hello.py
.pyc of the python script hello.py is generated.

3、

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值