您的位置:首页 > 编程语言 > Python开发

python中字典不自动排序/删除指定类型文件/执行可执行文件的返回值

2017-12-15 19:17 666 查看

1、python 字典的用法

from collections import OrderedDict
dict =OrderedDict()
dict['foo']=3
dcit['aol']=1


2、python中删除指定类型的文件

import sys, csv , operator
import os
import glob

for i in range(0, 10):
path = "C:\\Folder_" + str(i)
for infile in glob.glob( os.path.join(path, '*.csv') ):
os.remove(infile)


3、python执行可执行文件后返回可执行文件的输出值

import subprocess
proc = subprocess.Popen('cmd', shell=True)
cme = proc.communicate()
ret = proc.poll();


or

import subprocess
proc = subprocess.Popen('cmd', shell=True)
proc.communicate()
ret = proc.returncode


or

import subprocess
ret = subprocess.call(cmd, shell=True)

   如果使用shell=True这个参数。这个时候,我们使用一整个字符串,而不是一个表来运行子进程。Python将先运行一个shell,再用这个shell来解释这整个字符串。

  shell=True参数会让subprocess.call接受字符串类型的变量作为命令,并调用shell去执行这个字符串,当shell=False是,subprocess.call只接受数组变量作为命令,并将数组的第一个元素作为命令,剩下的全部作为该命令的参数。

参考网址:https://stackoverflow.com/questions/1872329/storing-python-dictionary-entries-in-the-order-they-are-pushed

参考网址:http://blog.csdn.net/vernice/article/details/46424921

参考网址:http://blog.csdn.net/carolzhang8406/article/details/22286913

参考网址:https://docs.python.org/2/library/subprocess.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: