Hello all I have been a hobbiest programmer for quite some time now and recently got back into it. I'm starting with a pretty simple program that will track inventory for my moms buisness. I've worked through most the common problems but can't seem to figure out why im getting extra spaces when displaying my list. I have been tempted to believe its because of the \n being carried along, but cannot prove it to myself by common debugging. Here is the code.
#display contents of the inventory file def display(): tmpc = 0 counter = 0 contents =  temp =  #open inventory and add contents to contents list newfile = open("inventory.txt", "rt") for item in newfile: contents.append(item) newfile.close() #open counter file and update counter variable cfile = open("counter.txt", "rt") counter = cfile.read() cfile.close() counter = int(counter) if counter == 0: return print("list empty") else: #check counter and length of contents to confirm #there is data in the inventory file #display a numbered list by combinding the counter file #and inventory file information if not counter > len(contents) and not counter < 0: while tmpc < counter: print(repr(tmpc) + "." + contents[tmpc]) tmpc = tmpc + 1 else: return print("Error inventory and counter files do not match.")
Then I simply call the function from a menu within the actual program. Thanks an can't wait to get some replies. :)