python 重要模块

1,使用字典的特殊字符串替换,基于字典的字符串格式化

圆括号中的信息是键名,值将从字典中得到并替换为字符串,需在圆括号后面指定插入的数据类型;

person[数字序 for tulpper() list[] or keyName for dict{}]

2,string

 Ruiy tips

python模块
使用模块为Python添加功能,通过模块同操作系统及其文件进行交互.

Options and arguments corresponding environment variables;

program passed in as string (terminates option list)
debug output from parser (PYTHONDEBUG = x)
ignore environment variables

3,使用一个以上的进程fork,exec(执行系统调用)

os.fork()

告诉计算机复制关于当前运行的程序的一切信息岛一个新创建的单独程序,复制的程序与原来的程序几乎是完全相同的!

import os

pid = os.fork()

if pid == 0:# This is the child

  print("this is the child")

else:

print("the child is pid %d" % pid)

os.wait()使Python parent id什么都不做;

import os
pid = os.foek()
#fork and exec together
print("second test")
if pid == 0:#This is the child
    print("this is the child")
    print("I'm going to exec another program now")
    os.execl('/bin/cat','cat','/etc/moth')
else:
    print("the child is pid %d" % pid)
os.wait()

4,使用python 通配符筛选有用的python模块私有及共有模块对象

import glob

如果只需要一个新命令的最基本的调用,最简单的方式是使用os.system函数

上面简单说了下使用一个以上的进程(进程分叉),下面来讲讲线程(在相同的进程中完成多个工作)

5,创建模块

模块提供了一种在应用程序之间共享Python代码的便捷方式.
模块中定义函数和类;

导入Python内置模块 or自定义的模块 import moduleName;

仅仅导入模块中的类或是函数from module import item;

6,如果模块被修改,使用imp.reload()函数重新加载模块新定义

import module;

import imp;

imp.reload(module);

6,修改模块搜索路径

 

你可能感兴趣的:(python)