Thursday, March 7, 2019

Jordan Fronko-PM-Open LAb-file reading and uploading

Today I had tried to get the EC points on the wrtie a file project. I used these sites for help:

https://overlaid.net/2016/02/08/replace-words-in-files-or-strings-using-python/
https://www.guru99.com/reading-and-writing-files-in-python.html

My base code worked just fine, i was just having trouble with fine-tuning the code to scrap the text that i don't want. Below is the code:
emailList=list()
print(emailList)
fname=input("enter a file...")
fhand=open(fname)
for variableNamedLine in fhand:
    lineListEmail=variableNamedLine.split()
    for i,email in enumerate(lineListEmail):
        if '@' in email:
     #      print('an email was found at list location',i,'and is',lineListEmail[i])
            emailList.append(lineListEmail[i])
            fout.write(variable.replace('<',''))

    fout.write(variable.replace('>',''))
            print(emailList)
fout=open('emailtext.txt','w')
print(fout)

for variable in emailList:
    fout.write(variable)
    fout.write('\n')

fout.close()
#create another loop to look thjrought eh email list then write it into the file
And below this is the text file that was created:
stephen.marquard@uct.ac.za
stephen.marquard@uct.ac.za
stephen.marquard@uct.ac.za
postmaster@collab.sakaiproject.org>
<postmaster@collab.sakaiproject.org
<postmaster@collab.sakaiproject.org>
200801051412.m05ECIaH010327@nakamura.uits.iupui.edu>
<200801051412.m05ECIaH010327@nakamura.uits.iupui.edu
<200801051412.m05ECIaH010327@nakamura.uits.iupui.edu>
source@collab.sakaiproject.org>;
<source@collab.sakaiproject.org;
<source@collab.sakaiproject.org>;
source@collab.sakaiproject.org>;
<source@collab.sakaiproject.org;
<source@collab.sakaiproject.org>;
source@collab.sakaiproject.org>;
<source@collab.sakaiproject.org;
<source@collab.sakaiproject.org>;
apache@localhost)
apache@localhost)
apache@localhost)
source@collab.sakaiproject.org;
source@collab.sakaiproject.org;
source@collab.sakaiproject.org;
stephen.marquard@uct.ac.za
stephen.marquard@uct.ac.za
stephen.marquard@uct.ac.za
source@collab.sakaiproject.org
source@collab.sakaiproject.org
source@collab.sakaiproject.org
stephen.marquard@uct.ac.za
stephen.marquard@uct.ac.za
stephen.marquard@uct.ac.za
stephen.marquard@uct.ac.za
stephen.marquard@uct.ac.za
stephen.marquard@uct.ac.za


The problem was that my code didn't erase all of the characters that were undesired. So i have to create another loop to look through the list that was created.

No comments:

Post a Comment