Advertisement
Guest User

Untitled

a guest
Nov 24th, 2013
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.02 KB | None | 0 0
  1.  
  2. #defines what order to perform the functions, and sorts the list once created.
  3. def main():
  4.     nameList = makeList()
  5.     printList(nameList)
  6.     nameList.sort()
  7.     printList(nameList)
  8.     newOutput(nameList)
  9.     #searchNames(nameList)
  10.  
  11. #creates the list from a text file
  12. def makeList():
  13.     data = open('categories.txt', 'r')
  14.     l = data.readlines()
  15.     data.close()
  16.     for i in l:
  17.         i = i.lstrip('0123456789 ')
  18.     return l
  19.    
  20. #prints the list to the screen
  21. def printList(nameList):
  22.     for n in nameList:
  23.         print(n, end='')
  24.  
  25. #creates a new output file, based on the first but in sorted order.
  26. def newOutput(nameList):
  27.     newList = open('newOutput.txt', 'w')
  28.     newList.writelines(nameList)
  29.     newList.close()
  30.        
  31.  
  32. #search the list for a specific name. Includes a loop to allow a user to search multiple names.
  33. def searchNames(nameList):
  34.     another = 'y'
  35.     while another.lower() == 'y':
  36.         search = input("What name are you looking for? (Use 'Lastname, Firstname', including comma: ") + '\n'
  37.            
  38.         if search in nameList:
  39.             print("The name was found at index", nameList.index(search), "in the list.")
  40.             another = input("Check another name? Y for yes, anything else for no: ")
  41.         else:
  42.             print("The name was not found in the list.")
  43.             another = input("Check another name? Y for yes, anything else for no: ")
  44.  
  45. #Call main function
  46. main()
  47.        
  48.  
  49. The text file I am iterating over is:This is basically the problem-- my i.rstrip isn't working right. What did I do wrong?
  50.  
  51.  
  52.  
  53. #defines what order to perform the functions, and sorts the list once created.
  54. def main():
  55.    nameList = makeList()
  56.    printList(nameList)
  57.    nameList.sort()
  58.    printList(nameList)
  59.    newOutput(nameList)
  60.    #searchNames(nameList)
  61.  
  62. #creates the list from a text file
  63. def makeList():
  64.    data = open('categories.txt', 'r')
  65.    l = data.readlines()
  66.    data.close()
  67.    for i in l:
  68.        i = i.lstrip('0123456789 ')
  69.    return l
  70.    
  71. #prints the list to the screen
  72. def printList(nameList):
  73.    for n in nameList:
  74.        print(n, end='')
  75.  
  76. #creates a new output file, based on the first but in sorted order.
  77. def newOutput(nameList):
  78.    newList = open('newOutput.txt', 'w')
  79.    newList.writelines(nameList)
  80.    newList.close()
  81.        
  82.  
  83. #search the list for a specific name. Includes a loop to allow a user to search multiple names.
  84. def searchNames(nameList):
  85.    another = 'y'
  86.    while another.lower() == 'y':
  87.        search = input("What name are you looking for? (Use 'Lastname, Firstname', including comma: ") + '\n'
  88.            
  89.        if search in nameList:
  90.            print("The name was found at index", nameList.index(search), "in the list.")
  91.            another = input("Check another name? Y for yes, anything else for no: ")
  92.        else:
  93.            print("The name was not found in the list.")
  94.            another = input("Check another name? Y for yes, anything else for no: ")
  95.  
  96. #Call main function
  97. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement