#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2016
    Posts
    13
    Rep Power
    0

    Simple iteration code is not writing multiple items


    Basically, I'm working on a script that will pull emp id numbers from users.csv (filtered to show just the empid).
    Then search exuser.csv and if that number is in the exuser list, write it out. Then go back and open users.csv file again, and compare
    the iterated terminated item to show the full emp name and ID again that was terminated. It works, but it only will print the last item...
    Thanks in advance...

    Code:
    import time
    
    filen = "users.csv"
    d=open(filen, "r")
    
    fob = d.readlines()
    fob = [i.split(":")[1] for i in fob]
    fob = [i.split("\n")[0] for i in fob]
    #print fob
    filec = "exuser.csv"
    r = open(filec, "r")
    fob1 = r.readlines()
    save = "term.csv"
    
    for i in fob:
        if i in fob1:
            jake = "users.csv"
            d=open(jake, "r")
            jake = d.readlines()
            for j in jake:
                if i in j:
                    print j
                    doc = open(save, "a")
                    doc.writelines("\n"+"\n" + j + " is Terminated...")
                    doc.close()
                else:
                    pass
    
        else:
            pass
    
    ti = time.strftime("%x")
    
    print ti
    Here's a list of my 3 files I use to generate the info...

    users.csv (list of user names and emp id)
    john doe:WT1000913
    George Washington:WT1000561
    Adam Lavine:WT1000388
    Pete Carroll:WT1503436
    Don Mattingly:WT1000442

    exuser.csv (HR file with term users)
    WT1000913
    WT1000442

    term.csv (resultant terminate emp doc)
    Don Mattingly:WT1000442
    is Terminated...
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2016
    Posts
    13
    Rep Power
    0
    Found the problem. The lines in the exuser.csv was placing a \n onto all the items in there. I had to split the variable in the list to not include the \n. Once that was done, can now find all of the items and print accordingly.
  4. #3
  5. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Posts
    5,735
    Rep Power
    507
    glad you found the answer. Disliked "Don Mattingly is Terminated"
    [code]Code tags[/code] are essential for python code and Makefiles!
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2016
    Posts
    13
    Rep Power
    0
    Lol

IMN logo majestic logo threadwatch logo seochat tools logo