Hi everyone im making a program to keep track of your movies just keeping it simple !

but im having a problem i am writing what movies you have to a text file but i cant append to it every time i write to the text file it overwrites everything here is what i have to far im using easygui to make a multenterbox to get 3 enter boxes

import easygui
import sys
import os
from easygui import *
textfile = file('movies.txt','wt')
msgbox(msg='This program is to keep track of all the movies you own',title='Movie Catalog',ok_button='OK',image=None,root=None)
wouldyou = choicebox(msg='Would you like to enter a movie or view the movies you already own?',title='',choices=('Enter a movie', 'View my movies'))
if wouldyou == "Enter a movie":
	msg='Please enter the name of the movie'
	title='Movie Catalog'
	fieldNames=("Name of movie", "Genre", "Movie description")
	fieldValues = []
	fieldValues = multenterbox(msg, title, fieldNames)
	if fieldValues == None:
		sys.exit(0);
		
myString = "".join(fieldValues)

doc = open('movies.txt', 'a')
doc.write(myString + "\n")




	


raw_input("press any key to exit")

oh and i was wondering how i would go about taking the input out of the text file and identifie it as Movietitle, Genre, Description

Edited 5 Years Ago by huntaz556: n/a

You open movies.txt twice and don't close either one. Delete line #5, the first open is not used. It would work better if you open the file in a function.

def view_existing():
    all_movies = open("movies.txt", "r").readlines()
    ## print the all_movies list and allow the user to select one
    ## something like this, although this is simplified
    for ctr, rec in all_movies:
        name, genre, desc = rec.strip().split("**")
        print "%5d  %-20, %-20s %-s" % (name, genre, desc)


def add_new_movie():
    fp_out = open("movies.txt", "a")

    enter_another = True
    while enter_another:
        msg='Please enter the name of the movie'
        # etc.
        myString = "**".join(fieldValues)  ## the fields require a delimiter for reading
        fp_out.write("%s\n" % (myString))

        msg="Enter another movie?"
        # etc.

    fp_out.close()

Edited 5 Years Ago by woooee: n/a

Comments
this helped alot ! thanks

now im getting error when im trying to view my movies

for ctr, rec in all_movies:
ValueError too many values to unpack

what do you suggest i do here?

Edited 5 Years Ago by huntaz556: n/a

My mistake, that should be
for ctr, rec in enumerate(all_movies):

And this line
print "%5d %-20, %-20s %-s" % (name, genre, desc)
should be
print "%5d %-20, %-20s %-s" % (ctr, name, genre, desc)

Edited 5 Years Ago by woooee: n/a

That got rid of the error but now i get unsupported charecter format ',' (0x2c) at index 8
removing the comma then gives me the error unsupported character format '' (0x2c) at index 8

Edited 5 Years Ago by huntaz556: n/a

This article has been dead for over six months. Start a new discussion instead.