python 标准库基础学习之开发工具部分1学习
#2个标准库模块放一起学习,这样减少占用地方和空间
#标准库之compileall字节编译源文件
import compileall,re,sys
#作用是查找到python文件,并把它们编译成字节码表示,将结果保存到.pyc,pyo文件中
#编译一个目录
#compile_dirr()递归地扫描一个目录,并对其中文件完成字节编译
compileall.compile_dir(r'b')
#默认情况下,所有子目录都会扫描,直到尝试达到10
#筛选目录,可以使用rx参数提供一个正则表达式来匹配要排除的目录名
compileall.compile_dir(r'b',rx=re.compile(r'c'))
#maxlevels参数控制递归深度:编译指定目录.py文件
compileall.compile_dir(r'b',maxlevels=0,rx=re.compile(r'c/.doc'))
#编译sys.path骼,就可以编译sys.path中找到所有python源文件
sys.path[:]=[r'python.py path']
print sys.path
compileall.compile_path()
#从命令行执行
#win在cmp下面
"""
>>>python -m compileall -h
option -h not recognized
usage: python compileall.py [-l] [-f] [-q] [-d destdir] [-x regexp] [-i list] [d
irectory|file ...]
arguments: zero or more file and directory names to compile; if no arguments giv
en,
           defaults to the equivalent of -l sys.path
options:
-l: don't recurse into subdirectories
-f: force rebuild even if timestamps are up-to-date
-q: output only error messages
-d destdir: directory to prepend to file paths for use in compile-time traceback
s and in
            runtime tracebacks in cases where the source file is unavailable
-x regexp: skip files matching the regular expression regexp; the regexp is sear
ched for
           in the full path of each file considered for compilation
-i file: add all the files and directories listed in file to the list considered
 for
         compilation; if "-", names are read from stdin
"""
#如果要创建之前新例子,跳过指定的目录,可以使用以下命令
#<python -m compileall -x '/path' examples>
#'path'指你要跳过的目录
#compileall官方标准库地址:https://docs.python.org/2.7/library/compileall.html?highlight=compileall#module-compileall
print '-'*100
#标准库之pyclbr类浏览器
import pyclbr
#作用:实现一个适用于源代码编辑器api,可以用来建立一个类浏览器
#注意:在pycharm虽然显示可以用,但运行发现报错:ImportError: No module named pyclbr
"""
它可以扫描python源代码来查找类和独立函数,可以课代表和tokenize收集类,方法和函数名及行号有关信息,不用导入代码
"""
#例子
class a(object):
    pass
class a1(a):pass
class b:
    pass
class c(a,b):
    def m1(self):
        return
    def m2(self):
        return
def func():
    pass
#扫描类,有2个公共函数,第一个是readmodule(),是以模式名作为参数,并返回一个字典
#将类名映射到Class对象,其中包含有关源代码的元数据.
import os
from operator import itemgetter
def show_class(name,cls1):
    print name
    file1=os.path.basename(cls1.file)
    print '{0}.{1}'.format(file1,cls1.lineno)
    show_class(name,cls1)
    show_mode1(name,cls1)
    print
    return
def show_mode1(name,cls1):
    for i,j in sorted(cls1.methods.items(),key=itemgetter(1)):
        print '{0}.{1}'.format(i,j)
    return
def show_super_class(name,cls1):
    super_name=[]
    for c_super in cls1.super:
        if c_super=='object':
            continue
        if isinstance(c_super,basestring):
            super_name.append(c_super)
        else:
            super_name.append(c_super.name)
    if c_super:
        print super_name
    return
data=pyclbr.readmodule('exp')#exp是表示py路径
for a,b in sorted(data.items(),key=lambda x:x[1].lineno):
    show_class(a,b)
#说明:类的源数据包括定义这个类的文件所有行号,还包括超类类名,类方法保存为方法名与行号之间的映射
#输出显示这些类和方法,输出显示这些类和方法(根据它们在源文件中行号的排序)
#扫描函数:使用readmodule_ex()方法,它会完成readmodule()所有全部工作,代码和上面类似
#pyclbr官方标准库地址:https://docs.python.org/2.7/library/pyclbr.html?highlight=pyclbr#module-pyclbr
#inspet模块可以发现有关类和函数更多元数据,不过需要导入此模块
#tokenize模块可以将python源代码解析为toke!
python 标准库基础学习之开发工具部分1学习的更多相关文章
- python标准库基础之mmap:内存映射文件
		
#作用:建立内存映射文件而不是直接读取内容文本信息内容:如下(名称是text.txt) Lorem ipsum dolor sit amet, consectetuer adipiscing elit ...
 - python  linecache标准库基础学习
		
#python标准库基础之:linecacge:高效读取文本文件#说明与作用"""可以从文件或者导入python模块获取文件,维护一个结果缓存,从而可以更高效地从相同文件 ...
 - Python标准库07 信号 (signal包,部分os包)
		
作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 在了解了Linux的信号基础之后,Python标准库中的signal包就很容易学习 ...
 - Python 标准库 urllib2 的使用细节[转]
		
转自[http://zhuoqiang.me/python-urllib2-usage.html] Python 标准库中有很多实用的工具类,但是在具体使用时,标准库文档上对使用细节描述的并不清楚,比 ...
 - Python 标准库 urllib2 的使用细节
		
刚好用到,这篇文章写得不错,转过来收藏. 转载自 道可道 | Python 标准库 urllib2 的使用细节 Python 标准库中有很多实用的工具类,但是在具体使用时,标准库文档上对使用细节 ...
 - Python 标准库 urllib2 的使用细节(转)
		
http://www.cnblogs.com/yuxc/archive/2011/08/01/2123995.html http://blog.csdn.net/wklken/article/deta ...
 - 转Python 标准库 urllib2 的使用细节
		
Python 标准库中有很多实用的工具类,但是在具体使用时,标准库文档上对使用细节描述的并不清楚,比如 urllib2 这个 HTTP 客户端库.这里总结了一些 urllib2 库的使用细节. 1 P ...
 - Python 标准库一览(Python进阶学习)
		
转自:http://blog.csdn.net/jurbo/article/details/52334345 写这个的起因是,还是因为在做Python challenge的时候,有的时候想解决问题,连 ...
 - python标准库学习-SimpleHTTPServer
		
这是一个专题 记录学习python标准库的笔记及心得 简单http服务 SimpleHTTPServer 使用 python -m SimpleHTTPServer 默认启动8000端口 源码: &q ...
 
随机推荐
- android之字体阴影效果
			
今天刚刚好做了个字体阴影的效果,感觉加上了阴影的效果立体感十足啊!写了个简单的demo与大家分享下!主要是以下四个属性 android:shadowColor 阴影的颜色 android:shad ...
 - [shell]Shell经常使用特殊符号
			
符合 含义 && command1 && command2:命令1返回真(命令返回值 $? == 0)后,命令2才干被运行.能够用于if推断. cp 1.txt ../ ...
 - c# winform InvokeRequired 解决跨线程访问控件
			
C#中禁止跨线程直接访问控件,InvokeRequired是为了解决这个问题而产生的,当一个控件的InvokeRequired属性值为真时,说明有一个创建它以外的线程想访问它. Windows 窗体中 ...
 - wpf-DataTemplate应用
			
在WPF中,决定数据外观的是DataTemplate,即DataTemplate是数据内容的表现形式,一条数据显示成什么样子,是简单的文本还是直观的图形,就是由DataTemplate决定的.下面通过 ...
 - bug记录-setTimeout、setInterval之IOS7
			
本篇文章主要讲查找并分析bug的思路,相关的函数不是本文的重点. 众所周知,setTimeout和setInterval是用来做延迟调用以及周期性调用的方法,他们支持的参数都差不多. setTimeo ...
 - 学习okhttp wiki--HTTPS
			
HTTPS OkHttp尝试平衡两个相互竞争的要素: 连通性(Connectivity):连接到尽可能多的服务器.这包括运行最新版本 boringssl 的服务器和不太过时的老版本 OpenSSL 的 ...
 - SQL从入门到基础 - 06 限制结果集范围
			
一.限制结果集行数 1. Select top 5* from T_Employee order by FSalary DESC 2. (*)检索按照工资从高到低排序检索从第六名开始一共四个人的信息: ...
 - Xcode中的iOS模拟器(iOS Simulator)的介绍和使用心得
			
http://www.crifan.com/intro_ios_simulator_in_xcode_and_usage_summary/
 - Swift--基础(二)元组 断言 错误处理
			
元组(tuples) 把多个值组合成一个复合值.元组内的值可以是任意类型,并不要求是相同类型 let http404Error = (404, "Not Found") let ( ...
 - Floyed算法  最短路径
			
#include<iostream>#include<cstdio>int v,e,n; //v是顶点数,e是条数int v1[101][101],path[101][101] ...