Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
error conditional
#1
Hello I want to write the file's content in only one but It doesn't work. I have two types of files: .txt and .doc. If not exist in a1 and a2, the file is written in a1...
alli=['a.txt','b.txt','c.doc',...]
a1=['a.txt']
b2['b.txt','f.txt']

       if file.endswith('.txt'):         
            f = open(file,'r')
            fl=f.read()                       
            
            if alli[i] in a1:  
                b=open('txt1.txt','a')
                b.write(fl)                 
                b.close()         
            elif alli[i] in a2:
                c=open('txt2.txt','a')  
                c.write(fl)                
                c.close()        
            
        if file.endswith('.doc'): 
              f = open(file,'r')
            fl=f.read()                       
            
            if alli[i] in a1:  
                b=open('txt1.txt','a')
                b.write(fl)                 
                b.close()         
            elif alli[i] in a2:
                c=open('txt2.txt','a')  
                c.write(fl)                
                c.close()        
            
Reply
#2
Quote:but It doesn't work
please elaborate!
Include any error output unaltered, verbatim!
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020