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为主的章节会和其它 ...
随机推荐
- CODEVS_2144 砝码称重 2 折半搜索+二分查找+哈希
#include<iostream> #include<algorithm> #include<cstring> #include<map> #incl ...
- Chrome常用URL命令(伪URL)
在Chrome地址栏输入chrome://chrome-urls/可以看到所有的Chrome支持的伪RUL 1.chrome://accessibility/ 可达性分析,默认是关闭的,点击acces ...
- ubuntu16.04安装mysql5.7.15
1.在官网下载mysql安装包 直接选择第一个下载好了就行 2.进入你的下载文件夹下面 键入命令: tar -xvf mysql-server_5.7.13-1ubuntu16.04_i386.deb ...
- CSS 居中 可随着浏览器变大变小而居中
关键代码: 外部DIV使用: text-align:center; 内部DIV使用: margin-left:auto;margin-right:auto 例: <div style=" ...
- android 程序退出的对话框
package com.example.yanlei.yl; import android.graphics.Color; import android.support.v7.app.AppCompa ...
- AppCompatActivity
刚开始看HelloWorld的目录结构然后就发现Android Studio中的是 import android support.v7.app.AppcompatActivity; public cl ...
- 杭电1863 畅通project
畅通project Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- BUPT 2012复试机考 3T
97. 二叉排序树 时间限制 1000 ms 内存限制 65536 KB 题目描述 二叉排序树,也称为二叉查找树.可以是一颗空树,也可以是一颗具有如下特性的非空二叉树: 若左子树非空,则左子树上所有节 ...
- 从头认识java-15.5 使用LinkedHashSet须要注意的地方
再接着上一个章节.我们来聊一下使用LinkedHashSet须要注意的地方. LinkedHashSet特点: (1)元素是有顺序的 (2)元素是不反复的 (3)底层数据结构是依照链表的结构存储的 ( ...
- SolidEdge 如何绘制局部视图 局部放大图
创建局部视图(局部放大图),先选择要创建局部放大图的视图,然后绘制一个小圆,然后绘制一个大圆即可. 如果要绘制不规则形状的局部放大图,则点击了局部放大图之后,点击绘制草图的按钮 随后可以用相切 ...