I don’t seem to understand the following code (lines 4:5):
openfile = open('mbox.txt')
for line in openfile:
line = line.rstrip()
if not line.startswith("From"):
I would understand it if I was to use it without “continue”, to get all lines except the “From” lines. But the example doesn’t work like that.
Thanks in advance!
August 3, 2022, 7:06pm
continue executes, the
print statement doesn’t, it avoids the lines that don’t start with “From”
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (
</>) to add backticks around text.
this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').
Thanks for the reply! I will be more careful with adding code on future posting.
In reference to your answer, doesn’t the code look exclusively for lines that start with “From”?
PS. Is it ok for me to share my “Arithmetic Formatter” code to review issues in another post/section?
August 4, 2022, 11:00am
this means that if the line doesn’t start with “From”, the code will jump to next iteration of the loop
startswith returns true/false, with the
not in front that is inverted. In this case when
startswith return false, the continue is executed.
Sure, open a topic for your Arithmetic Formstter if you need help
I think I get it now, it will print all the lines; skipping those how do not have “From”.
Thankyou for your time and effort!
February 3, 2023, 2:47am
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.