随笔分类 - Python学习
摘要:# -*- encoding: utf-8 -*- from subprocess import Popen, PIPE, STDOUT import time def Run_Cmd(cmd): # 执行命令 p = Popen(cmd, shell=True, stdin=PIPE, stdou
阅读全文
摘要:# -*- encoding: utf-8 -*- from subprocess import Popen, PIPE, STDOUTimport time def Run_Cmd(cmd): # 执行命令 p = Popen(cmd, shell=True, stdin=PIPE, stdout
阅读全文
摘要:import math i=0 filename='' write='' Rline = '' def writeFile(fileName,line): global filename global write global Rline if filename!=fileName and file
阅读全文
摘要:import math i=0 filename='' write='' Rline = '' def writeFile(fileName,line): global filename global write global Rline if filename!=fileName and file
阅读全文
摘要:编译pyc import py_compile py_compile.compile("test.py") 编译脚本: import py_compile import os import sys file_path_name = sys.argv[1] if file_path_name: jia
阅读全文
摘要:用于生成和修改常见配置文档,当前模块的名称在 python 3.x 版本中变更为 configparser 配置文件信息: [DEFAULT] ServerAliveInterval = 45 Compression = yes CompressionLevel = 9 ForwardX11 = y
阅读全文
摘要:import psutil def get_disk_info(): content = "" for disk in psutil.disk_partitions(): if 'cdrom' in disk.opts or disk.fstype == '': continue disk_name
阅读全文
摘要:import socket def get_host_ip(): """ 查询本机ip地址 :return: """ try: s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM) s.connect(('8.8.8.8',80)) ip=s.getso
阅读全文
摘要:# coding: UTF-8 import psutil import platform import re def get_cpu_used(upu_base, interval=1): percent = psutil.cpu_percent(int(interval)) if float(p
阅读全文
摘要:# _*_coding:utf-8 _*_ import time import requests import json import sys import random import string import datetime def login_device(user_name, passw
阅读全文
摘要:import socket import sys import os,time reload(sys) sys.setdefaultencoding('utf8') def send_cmd(command): try: print "开始连接服务端..." client = socket.sock
阅读全文
摘要:1、由于字典中的 key 是非常关键的数据,而且程序需要通过 key 来访问 value,因此字典中的 key 不允许重复。程序既可使用花括号语法来创建字典,也可使用 dict() 函数来创建字典。实际上,dict 是一种类型,它就是 Python 中的字典类型。在使用花括号语法创建字典时,花括号中
阅读全文
摘要:1、利用shell中执行成功返回0 失败非零 封装成函数 # coding: utf-8 from subprocess import Popen, PIPE, STDOUT import sys def run_cmd(cmd): p = Popen(cmd, shell=True, stdin=
阅读全文
摘要:import psutil def show_process(): '''列出所有当前正在运行的进程pid-name信息''' for proc in psutil.process_iter(): try: pinfo = proc.as_dict(attrs=['pid', 'name']) ex
阅读全文
摘要:1, window上查询服务的状态 from subprocess import Popen, PIPE import sys, re, json, socket from _utils.patrol2 import run_cmd, data_format, report_format impor
阅读全文
摘要:1,MQ的相关命令 查看队列管理器运行状态 # dspmq 显示结果中QMNAME表示MQ队列管理器的名称,STATUS表示当前运行状态。 运行状态有如下几种: Starting 正在启动 Running 正在运行 Ending 正在停止 Ended normally 已经正常终止 Ended im
阅读全文
摘要:import psutil import time import xlwt import platform from subprocess import Popen, PIPE def getoutput(command): print("开始执行命令:%s" %command) comm = Popen(command, stdout=PIPE, stdin=PIPE, stderr=PIPE,
阅读全文
摘要:一、修改原文件内容方式: #!/usr/bin/env python # -*- coding:utf8 -*- old_str = "aaa" #老文件内容字段 new_str = "bbb" #要改成字段 file_data = '' with open('/opt/1.txt', 'r', e
阅读全文
摘要:string 常用属性 生成随机密码:
阅读全文
摘要:Python 生成随机数、随机字符串#!/usr/bin/python # -*- coding: UTF-8 -*- import random import string # 随机整数: print random.randint(1,50) # 随机选取0到100间的偶数: print rand
阅读全文

浙公网安备 33010602011771号