PageRenderTime 81ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/userfile.py

https://bitbucket.org/jcsims/book
Python | 33 lines | 16 code | 8 blank | 9 comment | 1 complexity | b003b8271147024fdd020abedec857bc MD5 | raw file
  1. # userfile.py
  2. # Program to create a file of usernames in batch mode.
  3. import string
  4. def main():
  5. print "This program creates a file of usernames"
  6. print "from a file of names."
  7. # Get the file names
  8. inFileName = raw_input("What file are the names in? ")
  9. outFileName = raw_input("What file should the usernames go in? ")
  10. # open the files
  11. inFile = open(inFileName, 'r')
  12. outFile = open(outFileName, 'w')
  13. # Process each line of the output file
  14. for line in inFile:
  15. # get the first and last names from inFile
  16. first, last = string.split(line)
  17. # Create the username
  18. uname = string.lower(first[0]+last[:7])
  19. # write it to the output file
  20. outFile.write(uname+'\n')
  21. # Close both files
  22. inFile.close()
  23. outFile.close()
  24. print "Usernames have been written to", outFileName+'.'
  25. main()