-
-
Save T-Bharath/eae33c117baae1d9eb3a8bdb10d60288 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fname = input("Enter file name: ") | |
if len(fname) < 1 : fname = "mbox-short.txt" | |
fh = open(fname) | |
count = 0 | |
for line in fh: | |
x=line.rstrip().split() | |
if 'From' in x: | |
print(x[1]) | |
count+=1 | |
else: | |
continue | |
print("There were", count, "lines in the file with From as the first word") |
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
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