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
Here is my initial code
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')But it isn't working, the code return this error:
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 ?