Skip to content

Instantly share code, notes, and snippets.

  • Save T-Bharath/eae33c117baae1d9eb3a8bdb10d60288 to your computer and use it in GitHub Desktop.
Save T-Bharath/eae33c117baae1d9eb3a8bdb10d60288 to your computer and use it in GitHub Desktop.
@JohnSha0
Copy link

Hey, can you explain this line: if len(fname) < 1 : fname = "mbox-short.txt"

it causes the file name to be substituted as "mbox-short.txt" if the length of the given text os less that one. i.e., if nothing is typed i.e., if you pressed enter.
if you press enter, filename will be automatically set. no need to type it in

@JohnSha0
Copy link

fname = input("Enter file name: ")
if len(fname) < 1 : fname = "mbox-short.txt"
file = open(fname)
count = 0
for line in file:
if line.startswith("From"):
piece = line.strip().split()
print(piece[1])

print("There were", count, "lines in the file with From as the first word")

I typed this code but it repeats the the mail id if there's multiple. how can i prevent that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment