How to read a file without newlines?

前端 未结 9 1446
广开言路
广开言路 2020-11-21 21:03

In Python, calling

temp = open(filename,\'r\').readlines()

results in a list in which each element is a line in the file. It\'s a little st

9条回答
  •  眼角桃花
    2020-11-21 21:11

    def getText():
        file=open("ex1.txt","r");
    
        names=file.read().split("\n");
        for x,word in enumerate(names):
            if(len(word)>=20):
                return 0;
                print "length of ",word,"is over 20"
                break;
            if(x==20):
                return 0;
                break;
        else:
            return names;
    
    
    def show(names):
        for word in names:
            len_set=len(set(word))
            print word," ",len_set
    
    
    for i in range(1):
    
        names=getText();
        if(names!=0):
            show(names);
        else:
            break;
    

提交回复
热议问题