#导入模块
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的更多相关文章

  1. Python Standard Library

    Python Standard Library "We'd like to pretend that 'Fredrik' is a role, but even hundreds of vo ...

  2. [译]The Python Tutorial#11. Brief Tour of the Standard Library — Part II

    [译]The Python Tutorial#Brief Tour of the Standard Library - Part II 第二部分介绍更多满足专业编程需求的高级模块,这些模块在小型脚本中 ...

  3. [译]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模块为与操作系统 ...

  4. Python入门之面向对象module,library,package之间区别

    背景 Python中有一些基本的名词,很多人,尤其是一些初学者,可能听着就很晕. 此处,简单总结一下,module,library,package之间的大概区别. Python中的module的简介 ...

  5. The Python Standard Library

    The Python Standard Library¶ While The Python Language Reference describes the exact syntax and sema ...

  6. Python语言中对于json数据的编解码——Usage of json a Python standard library

    一.概述 1.1 关于JSON数据格式 JSON (JavaScript Object Notation), specified by RFC 7159 (which obsoletes RFC 46 ...

  7. Python自定义Module中__init__.py文件介绍

    ./pyModuleTest/├── addutil│   ├── add.py│   ├── add.pyc│   ├── __init__.py│   ├── __init__.pyc│   └─ ...

  8. C++ Standard Library

    C++ Standard Library *注:内容主要是对參考1的学习记录.知识点与图片大都来源于该书, 部分知识点与图片来源于參考2. 详细參考信息,见最下方參考. * C++98中新支持的语言特 ...

  9. C++11新特性——The C++ standard library, 2nd Edition 笔记(一)

    前言 这是我阅读<The C++ standard library, 2nd Edition>所做读书笔记的第一篇.这个系列基本上会以一章一篇的节奏来写,少数以C++03为主的章节会和其它 ...

随机推荐

  1. T1008 选数 codevs

    http://codevs.cn/problem/1008/ 题目描述 Description 已知 n 个整数 x1,x2,…,xn,以及一个整数 k(k<n).从 n 个整数中任选 k 个整 ...

  2. T2639 约会计划 codevs

    http://codevs.cn/problem/2639/ 题目描述 Description cc是个超级帅哥,口才又好,rp极高(这句话似乎降rp),又非常的幽默,所以很多mm都跟他关系不错.然而 ...

  3. (入门SpringBoot)SpringBoot项目数据源以及整合mybatis(二)

    1.配置tomcat数据源: #   数据源基本配置spring.datasource.url=jdbc:mysql://localhost:3306/shoptest?useUnicode=true ...

  4. Angular2.X 笔记

    本文为原创,转载请注明出处: cnzt       文章:cnzt-p http://www.cnblogs.com/zt-blog/p/7762590.html 前提: angular-cli (前 ...

  5. GeoServer发布Heatmap

    转自原文 GeoServer发布Heatmap 百度等热力图是使用开源的heatmap.js做的,但是这种解决方案的缺陷是: 1 数据量大的话,从前端通过后台查询比较费时,比如arcserver默认设 ...

  6. MyReport报表引擎1.2.0.1新功能

    一维码(Code128B)转换显示.  多联标题. 修正BugSum统计函数问题报表编辑器保存时没有生成新加入的单元格相关的xml数据 相关链接MyReport演示.产品站点 相关文章MyReport ...

  7. 基于MNIST数据的softmax regression

    跟着tensorflow上mnist基本机器学习教程联系 首先了解sklearn接口: sklearn.linear_model.LogisticRegression In the multiclas ...

  8. booth乘法器原理

    在微处理器芯片中,乘法器是进行数字信号处理的核心,同一时候也是微处理器中进行数据处理的wd=%E5%85%B3%E9%94%AE%E9%83%A8%E4%BB%B6&hl_tag=textli ...

  9. vue - 前置工作 - 目录功能介绍

    一个DEMOS的完整目录(由于GWF问题,我就不一一打开网站一个个去搜索并且解释了)可以去关注:https://www.cnblogs.com/ye-hcj build build.js(本文来自ht ...

  10. Python基础二--基本控制语句

    基本接触每一种语言,都须要做的:1.print 一个"Hello world!" 2.了解主要的数据类型 3.学习控制语句. 当我们学习控制语句,一般都离不开if,for ,whi ...