Python模块之"prettytable"

1、查看系统是否已经安装prettytable模块

2、下载prettytable模块

登陆:https://pypi.python.org/pypi/PrettyTable

3、安装PrettyTable模块

[[email protected] ~]# wget https://pypi.python.org/packages/source/P/PrettyTable/prettytable-0.7.2.tar.gz
[[email protected] ~]# tar -zxvf prettytable-0.7.2.tar.gz

[[email protected] prettytable-0.7.2]# python setup.py build
running build
running build_py
creating build
creating build/lib
copying prettytable.py -> build/lib

[[email protected] prettytable-0.7.2]# python setup.py install   # 安装prettytable
running install
running bdist_egg
running egg_info
writing prettytable.egg-info/PKG-INFO
writing top-level names to prettytable.egg-info/top_level.txt
writing dependency_links to prettytable.egg-info/dependency_links.txt
reading manifest file ‘prettytable.egg-info/SOURCES.txt‘
reading manifest template ‘MANIFEST.in‘
writing manifest file ‘prettytable.egg-info/SOURCES.txt‘
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
creating build/bdist.linux-x86_64
creating build/bdist.linux-x86_64/egg
copying build/lib/prettytable.py -> build/bdist.linux-x86_64/egg
byte-compiling build/bdist.linux-x86_64/egg/prettytable.py to prettytable.pyc
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying prettytable.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying prettytable.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying prettytable.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying prettytable.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
zip_safe flag not set; analyzing archive contents...
creating dist
creating ‘dist/prettytable-0.7.2-py2.6.egg‘ and adding ‘build/bdist.linux-x86_64/egg‘ to it
removing ‘build/bdist.linux-x86_64/egg‘ (and everything under it)
Processing prettytable-0.7.2-py2.6.egg
creating /usr/lib/python2.6/site-packages/prettytable-0.7.2-py2.6.egg
Extracting prettytable-0.7.2-py2.6.egg to /usr/lib/python2.6/site-packages
Adding prettytable 0.7.2 to easy-install.pth file

Installed /usr/lib/python2.6/site-packages/prettytable-0.7.2-py2.6.egg
Processing dependencies for prettytable==0.7.2
Finished processing dependencies for prettytable==0.7.2

4、测试pretty模块

>>> import tab
>>> from prettytable import PrettyTable
>>> row = PrettyTable()
>>> row.field_names = ["Name", "Age","Country","City"]
>>> row.add_row([‘shaw‘,‘23‘,‘China‘,‘Shanghai‘])
>>> row.add_row([‘charle‘,‘29‘,‘China‘,‘Xuzhou‘])
>>> row.add_row([‘jack‘,‘32‘,‘United States‘,‘Washington‘])
>>> print row
+--------+-----+---------------+------------+
|  Name  | Age |    Country    |    City    |
+--------+-----+---------------+------------+
|  shaw  |  23 |     China     |  Shanghai  |
| charle |  29 |     China     |   Xuzhou   |
|  jack  |  32 | United States | Washington |
+--------+-----+---------------+------------+
时间: 2024-08-09 06:32:37

Python模块之"prettytable"的相关文章

Python模块之"prettytable"

Python模块之"prettytable" 摘要: Python通过prettytable模块可以将输出内容如表格方式整齐的输出.(对于用Python操作数据库会经常用到) 1.查看系统是否已经安装prettytable模块 2.下载prettytable模块 登陆:https://pypi.python.org/pypi/PrettyTable 3.安装PrettyTable模块 [[email protected] ~]# wget https://pypi.python.org

python-学习笔记之-Day5 双层装饰器 字符串格式化 python模块 递归 生成器 迭代器 序列化

1.双层装饰器 #!/usr/bin/env python # -*- coding: utf-8 -*- # author:zml LOGIN_INFO = False IS_ADMIN = False   def check_log(func): def inner(): res = func() if LOGIN_INFO: print('验证成功!') return res else: print('验证失败!') return inner   def check_admin(func)

Python模块的交叉引用问题分析

实际项目中遇到python模块相互引用问题,查资料,说是通过import局部导入的方式可以避免错误,资料如附录所述. 但更改后测试还是会出错,很疑惑!? 如果哪位读者有好的解决方法,敬请留言说明,谢谢. 所以,最好的方法是不进行交叉引用,如果需要就单独分一个模块出来. 附录:Python模块的交叉引用问题解读:How can I have modules that mutually import each other? 有下面两个文件相互引用,Python解释器报错. foo.py: from

python模块以及导入出现ImportError: No module named 'xxx'问题

python模块以及导入出现ImportError: No module named 'xxx'问题 python中,每个py文件被称之为模块,每个具有__init__.py文件的目录被称为包.只要模 块或者包所在的目录在sys.path中,就可以使用import 模块或import 包来使用 如果你要使用的模块(py文件)和当前模块在同一目录,只要import相应的文件名就好,比 如在a.py中使用b.py:  import b 但是如果要import一个不同目录的文件(例如b.py)该怎么做

python模块搜索路径

1.电脑版 (1).python安装目录中\Lib\site-packages\下建立*.pth文件,写入模块路径 (2).添加环境变量:变量名:pythonpath;变量值:模块(文件夹)路径 ,若有多个,用半角分号";"隔开 2.手机版 在resource\site.py文件中添加代码段 import syssys.path.append("模块(文件夹)路径") 发现:第一个参数都是C:\\resource 我的理解: 程序安装盘下的site.py指定模块路径

4.python模块

python 字符串 一.注释 在python中的注释分为单行注释和多行注释    (1)单行注释:为在语句的前边加"#" 例子: #!/usr/bin/env python a = 123 print a #print a #print a #print a 执行结果如下: [[email protected] ~]# python a.py 123  (2)多行注释:可以用3对单引号(比如:''' 注释内容''') 或是3对双引号(比如:"""注释内容

使用 from import方法导入Python模块

比如我们导入一个数学计算的模块 math: >>> import math>>> print math<module 'math' (built-in)>>>>>>> print math.pi #导出圆周率的值3.14159265359>>> 我们导入math模块,在python模块学习中我们会知道,这样做会得到名math的对象,这个模块对象包含了pi这样的常量,以及一些其它的方法. 我们如果直接访问

Python 八、Python模块

一.python文件概述 1.python模块概述 可以将代码量较大的程序分割成多个有组织的.彼此独立但又能互相交互的代码片段,这些自我包含的有组织的代码段就是模块 模块在物理形势上表现为以.py结尾的代码文件 一个文件被看作一个独立的模块,一个模块也可以被看作是一个文件 模块的文件名就是模块的名字加上扩展名(.py) 每个模块都有自己的名称空间 python允许导入其它模块以实现代码重用,从而也实现了将独立的代码文件组织成更大的程序系统 python中,模块也是对象 在一个模块的顶层定义的所有

python 学习第五天,python模块

一,Python的模块导入 1,在写python的模块导入之前,先来讲一些Python中的概念性的问题 (1)模块:用来从逻辑上组织Python代码(变量,函数,类,逻辑:实现一个功能),本质是.py结尾的python文件(文件名:test.py,对应的模块名:test) (2)包:用来从逻辑上组织模块的,本质就是一个目录(必须带有一个__init__.py文件) 2,导入的方法 (1)import module_name导入某个模块 (2)import module_name,module2_