title: How to detect duplicate between input and output file and prevent adding duplicate items into output file by csv in python?
body: <p>I am writing a python program to manage the user accounts in FreeRadius server.If I don't want to add any duplicate accounts in the output file (users.conf).How can I change the code in adduser command(for creating single account) and au command(for importing files to create multiple accounts)? </p>
  
  <p>The username consists of 5-digit numbers in the first word in the rows.I kdon't want it being duplicated in output file after creating user account.As a changed it to be imported by csv file,how can I check the createuserentry.get() has or has not duplicated with existing username in
  users.conf and stop the process if found duplicate when adding the users?</p>
  
  <p>Also how to check duplicate username in csv file with comparison to users.conf and prevent adding duplicate usernames into users.conf when I import csv file to create multiple accounts?</p>
  
  <ul>
  <li>Preferred Output file:</li>
  <li>81045 User-Password == "81045"</li>
  <li>56811 User-Password == "56811"</li>
  <li>56287 User-Password == "56287"</li>
  <li>65654 User-Password == "65654"</li>
  <li>99737 User-Password == "99737"</li>
  <li>56185 User-Password == "56185"</li>
  <li>I don't want this output happen:</li>
  <li>81045 User-Password == "81045"</li>
  <li>81045 User-Password == "56811"</li>
  <li>65654 User-Password == "56287"</li>
  <li>65654 User-Password == "65654"</li>
  <li>99737 User-Password == "99737"</li>
  <li><p>56185 User-Password == "56185"</p>
  
  <pre><code>def adduser():
  with open('C:/FreeRADIUS.net/etc/raddb/users.conf', "r+") as fh:
  completed_lines = set()
  for line in open('C:/FreeRADIUS.net/etc/raddb/users.conf', "r"):
      if createuserentry.get() not in completed_lines:
          fh.write('\n')
          fh.write(createuserentry.get() + "     " + "User-Password == "  + '"' + createuserpwd.get() + '"')
         fh.write('\n')
         fh.close()
         tkMessageBox.showinfo("success", "Account created")
      else: continue
      fh.close()
      tkMessageBox.showinfo("Failure", "Username is duplicated")
  
  
  
   def au():
      au.filename = tkFileDialog.askopenfilename(initialdir = "/",title = "Select file to open",filetypes = (("csv","*.csv"),("all files","*.*")))
      print(au.filename)
      with open(au.filename) as input_file:
      reader = csv.DictReader(input_file)
      f = open('C:/FreeRADIUS.net/etc/raddb/users.conf', "a+")
      seen = set()
      for row in reader:
      rows = tuple(row)
      f.write(row.get("username") + "      " + "User-Password == " + '"' + row.get("password") + '"' + "\n")
   f.close()
   tkMessageBox.showinfo("success", "Accounts created and all duplicate items are ignored")
  
  
   def deleteuser():
     with open('C:/FreeRADIUS.net/etc/raddb/users.conf', "r") as fh:
     lines = fh.readlines()
     with open('C:/FreeRADIUS.net/etc/raddb/users.conf', "w") as fh:
     for line in lines:                  
         if deleteuserentry.get() in line and  deleteuserpwd.get() == "Pa$$w0rd123" :
         tkMessageBox.showinfo("success", "Account Deleted")
         end()
  
  
  
    def du():
     du.filename = tkFileDialog.askopenfilename(initialdir = "/",title = "Select file",filetypes = (("csv","*.csv"),("all files","*.*")))
     print(du.filename)
     with open(du.filename) as input_file:
     reader = csv.DictReader(input_file)
     f = open('C:/FreeRADIUS.net/etc/raddb/users.conf', 'r+')
   for row in reader:
      rows = tuple(row)
      if row.get("delete") == "y":
         f.write(row + '\n')
   f.close()
   tkMessageBox.showinfo("success", "Accounts deleted")
  </code></pre></li>
  </ul>