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

Recommended Answers

All 6 Replies

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()
commented: this helped alot ! thanks +1

thank you !

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?

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)

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

There should be twice %20s in format, typo of posting without running the code first.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.