#导入模块
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. CMDB资产管理系统的数据表设计

    Server表: asset = models.OneToOneField('Asset') 主机名(hostname) sn号(sn) 制造商(manufacture) 系统(os_platform ...

  2. BZOJ——3296: [USACO2011 Open] Learning Languages

    http://www.lydsy.com/JudgeOnline/problem.php?id=3296 Time Limit: 5 Sec  Memory Limit: 128 MBSubmit:  ...

  3. Jenkins使用Publish Over FTP Plugin插件上传FTP详解

    一.安装插件[Publish Over FTP] 二.在[系统管理]->[系统设置]->[Publish over FTP]->点击[增加]按钮,增加一个要连接的FTP: FTP S ...

  4. 系统重装 如何转换GPT的磁盘格式为MBR或者反过来

    使用分区助手专业版可以让磁盘在GPT和MBR之间进行转换   一般把磁盘全部格式化并清除分区,剩下的都会是可用空间,还是需要重建MBR来把磁盘转换成MBR格式的   转换会设置操作系统类型    

  5. 创建JDBC模板简化代码、JDBC应用的事务管理以及连接池的作用

    一.创建JDBC模板简化代码 一个简单的查询.要做这么一大堆事情,并且还要处理异常,我们不防来梳理一下: 1.获取connection  2.获取statement  3.获取resultset  4 ...

  6. Codefoces 432 C. Prime Swaps(水)

    思路:从前往后想将1调整好,在调整2....这样平均每次有五次机会调整,并且有相当一部分可能都用不到五次,能够一试.ac 代码: #include<iostream> #include&l ...

  7. Android 平板中 自己定义键盘(popuwindow) 居于屏幕左下方 仿微信的password输入界面

          之前博客中,介绍过使用谷歌提供的键盘的一些api,能够非常好地自己定义键盘,參考我之前的博客链接:android 自己定义键盘 ,这个有一个局限性,仅仅能占满屏幕,无法做到仅仅能占一部分的 ...

  8. 读懂这些spring boot的核心注解,快速配置完成项目搭建

    在spring boot中,摒弃了spring以往项目中大量繁琐的配置,遵循约定大于配置的原则,通过自身默认配置,极大的降低了项目搭建的复杂度.同样在spring boot中,大量注解的使用,使得代码 ...

  9. spark0.9.1集群模式执行graphx測试程序(LiveJournalPageRank,新增Connected Components)

    spark最新版公布了.之前的版本号就已经集成了graphx,这个版本号还改了一些bug. 我做了简单測试,只是网上关于集群模式执行spark资料太少了,仅仅有关于EC2(见參考资料1)的.可是还非常 ...

  10. WM_GETMINMAXINFO的作用 .

    如果想要实现窗口全屏,并且还有状态栏,会出现问题,那就是OnGetMinMaxInfo函数的作用.你可以试一下,如果把这个函数去掉,则当你按下工具栏中的全屏显示按钮时,框架视图确实变大了,但没有想象的 ...