Tenho um arquivo de texto com cinco linhas. Abro e leio as linhas em um array e, em seguida, imprimo o array com sucesso, mas quando imprimo um único item do array, ele imprime caracteres individuais. Preciso usar as cinco linhas de entrada como strings individuais no código.
#!/usr/bin/python3
# read the configuration file (from setup.py)
try:
f = open('interface.txt', encoding="utf-8")
vars = f.read()
f.close()
except IOError:
print("oops cant open interface.txt")
exit ()
# debug
print ('\nthis works prints five items\n')
print (vars)
print ('\nthis prints every individual character in the file\n')
for xx in vars:
print (xx)
saída:
jbh@junkbox-2:~/Desktop/Athens/Volume1/Chapter00$ ./readInterface.py
this works prints five items
Chapter 00 - Introduction
index.html
../Chapter10/index.html
../Chapter01/index.html
Chapter00.csv
this prints every individual character in the file
C
h
a
p
t
e
r
0
0
-
I
n
t
r
o
d
u
c
t
i
o
n
-- etc. ---