python -m

影响sys.path

  1. python xxx.py
  2. python -m xxx.py

这是两种加载py文件的方式:
1叫做直接运行
2把模块当作脚本来启动

直接启动是把脚本所在的目录放到了sys.path属性中。
模块启动是把你输入命令的目录(也就是当前路径),放到了sys.path属性中***

=======================================================

1. python -m json.tool  (2,3)

# echo '{"a":1,"b":2}'|python -m json.tool
{
    "a": 1,
    "b": 2
}

 

# python -m json.tool a.json
{
    "a": 1,
    "b": 2
}

 

2. python -m timeit [-n N] [-r N] [-s S] [-t] [-c] [-h] [statement...]   (2,3)

-n N 执行指定语句的次数
-r N 重复测量的次数(默认3次)
-s S 指定初始化代码活构建环境的导入语句(默认pass)
python 3.3新增
-t 使用time.time() (不推荐)
-c 使用time.clock() (不推荐)
-v 打印原始计时结果
-h 帮助

# python -m timeit '"-".join(str(n) for n in range(100))'
10000 loops, best of 3: 66.6 usec per loop

3. python -m zipfile
Usage:
    zipfile.py -l zipfile.zip        # Show listing of a zipfile
    zipfile.py -t zipfile.zip        # Test if a zipfile is valid
    zipfile.py -e zipfile.zip target # Extract zipfile into target dir
    zipfile.py -c zipfile.zip src ... # Create zipfile from sources

猜你喜欢

转载自www.cnblogs.com/mhc-fly/p/9070872.html