def ip2num(ip):#ip to int num lp = [int(x) for x in ip.split('.')] return lp[0] << 24 | lp[1] << 16 | lp[2] << 8 | lp[3] def num2ip(num):# int num to ip ip = ['', '', '', ''] ip[3] = (num & 0xff) ip[2] = (num & 0xff00) >> 8…
python遍历一个目录,输出所有文件名 python os模块 os import os def GetFileList(dir, fileList): newDir = dir if os.path.isfile(dir): fileList.append(dir.encode('gbk')) elif os.path.isdir(dir): for s in os.listdir(dir): #如果需要忽略某些文件夹,使用以下代码 #if s == "xxx":…
[python]python 遍历一个list 的小例子: mlist=["aaa","bbb","ccc"]for ss in enumerate(mlist): print ss 验证一下运行结果: In [34]: mlist=["aaa","bbb","ccc"] In [35]: for ss in enumerate(mlist): ....: print ss ....:…
获取计算机名 # 获取计算机名,常用的方法有三种 import os import socket # method one name = socket.gethostname() print(name) # DESKTOP-S3BGVQN # method two name = os.popen("hostname").read() print(name) # DESKTOP-S3BGVQN # method three name = os.environ.get("COMP…