For some reason it comes as false. I used the comparison operator. The file works properly. There seem to be an issue with the comparison.
Asked
Active
Viewed 154 times
-1
-
Does this answer your question? [Performing Breadth First Search recursively](https://stackoverflow.com/questions/2549541/performing-breadth-first-search-recursively) – Cid Sep 14 '20 at 06:31
-
2First we read the documentation - here’s a good place to start to find built-in functions https://docs.python.org/3/library/functions.html and there you will find `open()`. Also see this topic about reading and writing files https://docs.python.org/3/tutorial/inputoutput.html#tut-files - and have a good browse around the documentation because it’s full of useful information about Python. – DisappointedByUnaccountableMod Sep 14 '20 at 07:29
2 Answers
0
You could open the file and load its contents like this:
def open_file():
with open("filename", "r") as f:
lines = f.readlines()
Call the function with all_lines = open_file()
Then read line by line with:
for line in all_lines:
Print(line)

Nick
- 3,454
- 6
- 33
- 56
-
no no I got that, I mean like first line of file with an input string. For some reason when i used the == (they were the same), it comes as false. – Power123 Sep 14 '20 at 14:55
-
@Power123 you need to include the example in your question. Please read the following article on how to ask a good question: https://stackoverflow.com/help/how-to-ask – Nick Sep 15 '20 at 10:52
0
with open(filename, 'r') as fh:
for line in fh:
... do stuff with line ...

Jiří Baum
- 6,697
- 2
- 17
- 17