+ 1
Can we import txt file in this app in python?
If yes, then how??
3 Réponses
+ 2
yes
with open('text_file.txt') as file:
    text = file.read()
    print(text)
# make sure youre in the right directory
+ 5
If you need to do something more than printing the file content, you can read the file line by line, stripping away the "newline" sequence, and putting it then in a list:
lines = []
for i in open('txt3.txt','r'):  # file will be opened for reading
   lines.append(i.strip()) # read line by line and append it to a list
for j in lines:
   print(j)
+ 2
Not without already having it in your code.



