P
P
Python Newbie2021-09-06 07:57:57
Python
Python Newbie, 2021-09-06 07:57:57

What's wrong with a list in python?

I read a multiline file:

with open('stcret_file', 'r') as file:
    answers = file.read()
    file.close()
print(answers)


When you type answers, everything is like in a file:
Нормальная
Нет
Да
Нет
Нет
Нет
Нет, не имею
Нет
Да


As I understand it, this is a list.
But when I print the 0 element of the list, nothing happens, and when the first one is displayed, n. What's wrong here?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2021-09-06
@Levman5

1e - if you use with , then you do not need to close the file explicitly, when you exit the with block, it will do it itself.
2e - the read() method returns a string, that is, answers is a string, you can make
print(type(answer))
sure that answer[0] is a space
3e - to get a list, you need to use readlines() instead of read()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question