zoukankan      html  css  js  c++  java
  • py一些练习实例

    1、目前工作上有一堆的ip地址,ip是ok的,但是需要找出来不在这里面的其他ip

    import os
    
    a = list()
    with open('ip.txt','r') as f:
    	#print(f.readlines())
    	for line in f.readlines():
    		a.append(line.strip())
    
    b = []
    for i in range(170,251):
    	b.append('10.2.17.{}'.format(i))
    
    #比较两个列表的相同元素使用  a&b,比较不同元素使用a^b
    c = list(set(a)^set(b))
    for i in sorted(c):
    	print(i)
    

    2、读取大文件使用readline()函数

    with open('ip.txt','r') as f:
    	while True:
    		line = f.readline()
    		if line:
    			print(line.strip())
    		else:
    			break
    

    3、读取文件时后面带有换行符怎么做?

    def GetData(file):
        linenew = ""
        with open(file,'r') as f:
            line = f.read().splitlines()
            print(line)
    
  • 相关阅读:
    pyinstaller
    screen
    docker
    rsync
    shutil模块
    mysql innodb 理解
    B 树和B+树存储的区别
    B-树原理分析
    mysql 通过mycat 读写分离
    mysql 主从复制
  • 原文地址:https://www.cnblogs.com/FengGeBlog/p/14484655.html
Copyright © 2011-2022 走看看