module+standard library.py
#导入模块
import sys
sys.path
sys.path.append('D:\program files\Python34\PyWorks') #hello.py文件路径
#不用append PyWorks路径也可以,因为D:\program files\Python34在sys.path中
import hello #第一次导入会执行,路径增加.pyc文件
import hello #第二次不会执行
#执行第二次的方法(假如hello修改后需要再重新导入)
import imp
imp.reload(hello)
'''
#从模块导入函数:
import somemodule
from somemodule import somefunction
from sommodule import function1,function2,functoin3
from somemodule import *
import somemodule as module
from somemodule import somefunction as functoin
''' print('__name__ =',__name__) #__name__ = __main__
print('hello.__name__ =',hello.__name__) #hello.__name__ = hello
hello.hello() #不修改sys.path导入模块的方法
#1,将模块放置在合适的位置
import pprint #如果数据结构过大,不能在一行打印完,可以用pprint
pprint.pprint(sys.path)
#解释器可以从这些目录中找到所需的模块
#site-packages目录是最佳选择,因为它就是用来做这些事的 #2,告诉解释器去哪里找
#不希望将自己的模块填满Python解释器目录
#没有在Python解释器目录中存储文件的权限
#想将模块放在其他地方
#编辑sys.path,这不是通用的方法。标准方法是在PYTHONPATH环境变量中包含模块所在目录 #包
#当模块存储在文件中时(扩展名为.py),包就是模块所在的目录
#为了让Python将其作为包对待,他必须包含一个名为__init__py的文件(模块)
import PyWorks #只有__init__模块可用,hello,if_test不可用
import PyWorks.hello #hello模块可用,但只能通过全名PyWorks.hello 来使用
from PyWorks import if_test #if_test模块可用,可通过短名if_test使用 #dir函数
#查看模块包含的内容,所有函数,类,变量
print(dir(hello))
print([n for n in dir(hello) if not n.startswith('_')]) #__all__
#在模块内部设置的。from module import * 时可以屏蔽不想要的变量,函数,类
#还是可以通过from module import function 或module.function访问
#在模块内部被设置。
__all__=['a','b','c'] #__doc__,help(module)
#查看模块帮助 #__file__
#查看模块文件的位置 #标准库
#sys,os,fileinput,set,heap,deque,time,random
#fileinput
#>>>python some_script.py file1.txt file2.txt file3.txt
#依次对fili1到file3文件中所有行进行遍历。
#函数file.input,filename,lineno,filelineno,isfirstline,isstdin,nextfile,close #shelve P188
#在文件中存储数据,当做字典用
import shelve
db=shelve.open(r'F:\test.dat',writeback=True) #shelve创建一定的是.dat文件
person={}
person['name']=['a','b']
person['age']=[1,2,3]
db['']=person
db['']=person
print(db['']['name'])
db['']['name'].append('c') #这句不会写入shelve
print(db['']['name'])
tmp=db['']['name']
tmp.append('c')
print(tmp)
db['']['name']=tmp
print(db['']['name'])
db.close() #re
#参见regular文件夹
module+standard library.py的更多相关文章
- Python Standard Library
Python Standard Library "We'd like to pretend that 'Fredrik' is a role, but even hundreds of vo ...
- [译]The Python Tutorial#11. Brief Tour of the Standard Library — Part II
[译]The Python Tutorial#Brief Tour of the Standard Library - Part II 第二部分介绍更多满足专业编程需求的高级模块,这些模块在小型脚本中 ...
- [译]The Python Tutorial#10. Brief Tour of the Standard Library
[译]The Python Tutorial#Brief Tour of the Standard Library 10.1 Operating System Interface os模块为与操作系统 ...
- Python入门之面向对象module,library,package之间区别
背景 Python中有一些基本的名词,很多人,尤其是一些初学者,可能听着就很晕. 此处,简单总结一下,module,library,package之间的大概区别. Python中的module的简介 ...
- The Python Standard Library
The Python Standard Library¶ While The Python Language Reference describes the exact syntax and sema ...
- Python语言中对于json数据的编解码——Usage of json a Python standard library
一.概述 1.1 关于JSON数据格式 JSON (JavaScript Object Notation), specified by RFC 7159 (which obsoletes RFC 46 ...
- Python自定义Module中__init__.py文件介绍
./pyModuleTest/├── addutil│ ├── add.py│ ├── add.pyc│ ├── __init__.py│ ├── __init__.pyc│ └─ ...
- C++ Standard Library
C++ Standard Library *注:内容主要是对參考1的学习记录.知识点与图片大都来源于该书, 部分知识点与图片来源于參考2. 详细參考信息,见最下方參考. * C++98中新支持的语言特 ...
- C++11新特性——The C++ standard library, 2nd Edition 笔记(一)
前言 这是我阅读<The C++ standard library, 2nd Edition>所做读书笔记的第一篇.这个系列基本上会以一章一篇的节奏来写,少数以C++03为主的章节会和其它 ...
随机推荐
- Codeforces D. Iahub and Xors
题目大意:给定一个N*N的区间,1:对(x0,y0,x1,y1)每个直 都xor v: 2: 求(x0,y0,x1,y1)区间的 sum xor: http://codeforces.com/blog ...
- Hadoop HDFS 常用命名
HDFS命令基本格式:hadoop fs -cmd < args > ls 命令hadoop fs -ls / 列出hdfs文件系统根目录下的目录和文件 hadoop fs -ls -R ...
- Java中的final关键字(转)
Java中的final关键字非常重要,它可以应用于类.方法以及变量.这篇文章中我将带你看看什么是final关键字?将变量,方法和类声明为final代表了什么?使用final的好处是什么?最后也有一些使 ...
- Go -- 中开启gctrace
godebug是一个跨平台的Go程序调试工具,传统的编译型语言调试器使用底层系统调用并读取二进制文件用于调试各类符号.使用起来很麻烦而且很难移植. godebug使用不同的方法,直接把源码作为目标程序 ...
- BUPT复试专题—哈夫曼树(2010)
https://www.nowcoder.com/practice/162753046d5f47c7aac01a5b2fcda155?tpId=67&tqId=29635&tPage= ...
- codeforces 553 A Kyoya and Colored Balls
这个题.比赛的时候一直在往dp的方向想,可是总有一个组合数学的部分没办法求, 纯粹组合数学撸,也想不到办法-- 事实上,非常显然.. 从后往前推,把第k种颜色放在最后一个,剩下的k球.还有C(剩余的位 ...
- Mysql 数据库中间件
读写分离:简单的说是把对数据库读和写的操作分开对应不同的数据库服务器,这样能有效地减轻数据库压力,也能减轻io压力.主数据库提供写操作,从数据库提供读操作,其实在很多系统中,主要是读的操作.当主数据库 ...
- java设计模式----真实世界的模式
设计模式的定义: 模式是在某情境下,针对某问题的某种解决方案 反模式: 告诉你如何采用一个不好的解决方案解决一个问题 要点: 1.让设计模式自然而然地出现在你的设计中,而不是为了使用而使用 2.设计模 ...
- Highmaps的天津地图数据JSON格式
Highmaps的天津地图数据JSON格式 Highmaps的天津地图数据JSON格式 下载链接: http://pan.baidu.com/s/1eQgxECU password: tjmj 天津地 ...
- 《ASP.NET》数据绑定—DataList
DataList控件是.NET中的一个控件.DataList控件以表的形式呈现数据(在属性生成器中能够编辑),通过该控件,您能够使用不同的布局来显示数据记录(使用模板编辑).比如,将数据记录排成列或行 ...