常用python shell
2017-03-06 20:13
246 查看
路径及文件操作
创建目录
os.mkdir(path_str)
列出当前文件夹中文件,存入string list中
os.listdir(path_str)
判断路径是否存在
os.path.exists(path_str)
判断路径对应的位置是文件吗?
os.path.isfile(path_str)
路径拼接
string1 = '/home' string2 = 'fariver' os.path.join(string1, string2) output: '/home/fariver'
获取当前文件夹路径
pwd = os.getcwd();
change pwd to path
os.chdir(path)
remove directory and its contents, delete all files in path
import shutil shutil.rmtree(‘dirname’)
remove a file
os.remove(‘filename’)
其它目录操作参见
分隔文件名中的后缀与前缀
file_name = '/home/xxx/xxx/xxx.jpg' res = os.path.splitext(file_name) output: type(res) tuple res[0] '/home/xxx/xxx/xxx' res[1] '.jpg'
在文件夹中寻找固定后缀的全部文件
import glob file_list = glob.glob('xx/xx/*.jpg') file = ['/home/xxx/xx1.jpg', '/home/xxx/xx2.jpg']
当前python shell中的变量
dir() #will give you the list of in scope variables: globals() #will give you a dictionary of global variables locals() #will give you a dictionary of local variables
程序执行时等待用户从键盘输入
input()与raw_input()
Input()会根据输入的数据的内容作适当的类型转换,比如说数字串会转换为数字
Raw_input()则是输入什么串都原封不动的保存为相应字符串
相关文章推荐
- shell、javascript、python、tcl 等常用脚本语言
- Python编写shell脚本中常用的文件介绍
- 【编程语言】Python or IPython Shell下常用的键盘快捷键
- Python常用操作集锦
- Python in nutshell 2nd 简明翻译 (6)
- 监控Oracle数据库的常用shell脚本
- 常用Python程序
- shell - Easily call executables from Python
- 监控Oracle数据库的常用shell脚本
- 常用的几个shell脚本_4_更新jsp
- 常用的几个shell脚本_2_查看日志
- python 常用资源与问题
- 我非我同学的python的反弹shell的代码
- Python Tkinter GUI 常用控件(后续整理加入了几个pmw的控件)
- [linux.admin.shell] find命令常用法
- 介绍Python程序员常用的IDE和其它开发工具
- python 写的一个反向连接的shell
- Python function calls from the bash shell or dos prompt
- 近期准备写一系列关于使用python实现常用算法的文章
- shell+sed+awk和perl和python的区别