Guest User

UserName.py

a guest
Oct 9th, 2020
1,179
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2. import sys
  3. import os.path
  4.  
  5. if __name__ == "__main__":
  6.     if len(sys.argv) != 2:
  7.         print("usage: {} names.txt".format((sys.argv[0])))
  8.         sys.exit(0)
  9.  
  10.     if not os.path.exists(sys.argv[1]):
  11.         print("{} not found".format(sys.argv[1]))
  12.         sys.exit(0)
  13.  
  14.     for line in open(sys.argv[1]):
  15.         name = ''.join([c for c in line if  c == " " or  c.isalpha()])
  16.  
  17.         tokens = name.lower().split()
  18.  
  19.         # skip empty lines
  20.         if len(tokens) < 1:
  21.             continue
  22.  
  23.         fname = tokens[0]
  24.         lname = tokens[-1]
  25.  
  26.         print(fname + lname)           # johndoe
  27.         print(lname + fname)           # doejohn
  28.         print(fname + "." + lname)     # john.doe
  29.         print(lname + "." + fname)     # doe.john
  30.         print(lname + fname[0])        # doej
  31.         print(fname[0] + lname)        # jdoe
  32.         print(lname[0] + fname)        # djoe
  33.         print(fname[0] + "." + lname)  # j.doe
  34.         print(lname[0] + "." + fname)  # d.john
  35.         print(fname)                   # john
  36.         print(lname)                   # joe
  37.  
RAW Paste Data