Jul-18-2020, 08:56 PM
I'm doing a challenge that my code must read lines from a txt file and create others files inside a new directory ,they'll be named with the lines from de first one.
Here is my initial code
But it isn't working, the code return this error:
Here is my initial code
1 2 3 4 5 6 7 8 9 |
import os with open ( 'C:\\Users\\-\\Desktop\\Python.txt' , 'r+' ) as file : countries = list ( file .readlines()) print (countries) print ( len (countries)) os.makedirs( 'C:\\Users\\-\\Documents\\Test' , exist_ok = True ) for lines in countries: with open ( 'C:\\Users\\-\\Documents\\Texto\\here.txt' ) as linhas: os.rename( 'here.txt' , 'oi.txt' ) |
Error:Traceback (most recent call last):
File "C:/Users/-/PycharmProjects/guppe/teste.py", line 54, in <module>
with open('C:\\Users\\-\\Documents\\Texto\\here.txt') as linhas:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\-\\Documents\\Texto\\here.txt'
How Can i use a loop for getting the names from my file and creat others ?