/userfile.py
Python | 33 lines | 16 code | 8 blank | 9 comment | 1 complexity | b003b8271147024fdd020abedec857bc MD5 | raw file
- # userfile.py
- # Program to create a file of usernames in batch mode.
- import string
- def main():
- print "This program creates a file of usernames"
- print "from a file of names."
- # Get the file names
- inFileName = raw_input("What file are the names in? ")
- outFileName = raw_input("What file should the usernames go in? ")
- # open the files
- inFile = open(inFileName, 'r')
- outFile = open(outFileName, 'w')
- # Process each line of the output file
- for line in inFile:
- # get the first and last names from inFile
- first, last = string.split(line)
- # Create the username
- uname = string.lower(first[0]+last[:7])
- # write it to the output file
- outFile.write(uname+'\n')
- # Close both files
- inFile.close()
- outFile.close()
- print "Usernames have been written to", outFileName+'.'
- main()