python常用模块初始

简介:

python常用模块初始


1.getpass(密文输入)

1
2
3
4
import  getpass                                     #导入getpass模块,用于密文输入
name = input( "input your name:" )
passwd  = getpass.getpass( "input your passwd:" )     #密文输入
print (name, passwd )

2.OS模块

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/bash/env python
#_*_ coding:utf-8 _*_
 
import  os
1
#直接执行linux命令“df -lh”
os.system( "df -lh" )
 
2
#创建abc目录
os.mkdir( "abc" )
 
3
#打印命令执行结果是否成功,成功返回None;
=  os.system( "df -lh" )
print (a)
 
4
#将linux执行查询到的内容复制给变量
aa  =  os.popen( "df -lh" ).read()
#先用popen读取df-lh 获取的内容读到内存,再用read读出来赋值给aa ;
print (aa)

3.tab模块

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
查找python默认全局环境变量位置:
import  sys
#导入sys模块
print  (sys.path)
#打印python的所有目录,python放模块的目录是/usr/lib/python2.7/dist-packages
#把文件上传到该目录下,名字tab.py
import  tab
#os.就可以tab补全了;注意不能加.py
#tab模块要自己写;
#每一个脚本都可以是一个模块;
 
具体TAB模块内容:
#!/bin/bash/env python
#_*_ coding:utf-8 _*_
 
# python startup file
import  sys
import  readline
import  rlcompleter
import  atexit
import  os
# tab completion
readline.parse_and_bind( 'tab: complete' )
# history file
histfile  =  os.path.join(os.environ[ 'HOME' ],  '.pythonhistory' )
try :
     readline.read_history_file(histfile)
except  IOError:
     pass
atexit.register(readline.write_history_file, histfile)
del  os, histfile, readline, rlcompleter

4.sys模块

1
2
3
4
python查找全局环境变量路径 方法:
import  sys
#导入sys模块
print  (sys.path)




     本文转自506554897 51CTO博客,原文链接:http://blog.51cto.com/506554897/1906413 ,如需转载请自行联系原作者





相关文章
|
2天前
|
Python
【Python进阶(五)】——模块搜索及工作目录
【Python进阶(五)】——模块搜索及工作目录
|
17天前
|
机器学习/深度学习 存储 Python
|
1天前
|
Python
在Python中,利用`os模块`的`path.exists()`函数可判断文件是否存
在Python中,利用`os模块`的`path.exists()`函数可判断文件是否存在,该函数对路径进行检查,存在则返回True,不存在则返回False。示例代码展示了如何检查'example.txt'文件是否存在并相应打印消息。此外,`os.path.isfile()`用于确认路径是否为文件,仅当是文件时返回True,否则返回False,同样配以示例说明其用法。
8 2
|
4天前
|
Python Windows
python中的异常与模块
python中的异常与模块
9 1
|
13天前
|
JSON 数据格式 Python
Python标准库中包含了json模块,可以帮助你轻松处理JSON数据
【4月更文挑战第30天】Python的json模块简化了JSON数据与Python对象之间的转换。使用`json.dumps()`可将字典转为JSON字符串,如`{"name": "John", "age": 30, "city": "New York"}`,而`json.loads()`则能将JSON字符串转回字典。通过`json.load()`从文件读取JSON数据,`json.dump()`则用于将数据写入文件。
17 1
|
14天前
|
Python
Python实现压缩解压---tarfile模块详解
Python实现压缩解压---tarfile模块详解
|
14天前
|
Linux Python Windows
Python中time和datetime模块详解
Python中time和datetime模块详解
|
15天前
|
存储 Linux 数据安全/隐私保护
python的压缩模块zipfile详解
python的压缩模块zipfile详解
|
15天前
|
Linux Python Windows
python的os模块详细解读(二)
python的os模块详细解读(二)
|
15天前
|
移动开发 Linux Shell
python的os模块详细解读(一)
python的os模块详细解读(一)
python的os模块详细解读(一)