I'm not really to sure with using python and its object oriented features as Im better with java.

Im not sure whether to put the functions inside the classes as i can't really seeing this making a difference. I will apply my code and any changes or guidence would be great (just to be told if im on the right path etc)

def main():
    user = menu(username)
    class Film(object):

        def __init__(self, year, fans):
            self.year = year
            self.fans = fans

    class Drama(Film):

        def __init__(self, film, director, actor):
            Film.__init__(self, year, fans)
            self.film = film 
            self.director = director
            self.actor = actor
            self.year = year
            self.fans = fans

    class Documentary(Film):

        def __init__(self, narrator, subject, year, fans):
            Film.__init__(self, year, fans)
            self.narrator = narrator
            self.subject = subject

def menu(userName)

    print "Hello, welcome."
    userName = raw_input("What is your name?: ")
    while exit = 0
        print "Please select an option. 1. Add a Film 2. List Films 3. Find film by release date"
        inputCommand = input("Enter here: ")
        if inputCommand == 1
            filmType = input("Press 1 for Drama . Press 2 for Documentary: ")
            if filmType == 1
                addDrama(film, director, actor, year)
                addDoc(narrator, subject, year)
        elif inputCommand == 2
            listFilms(film, director, actor, year)
        elif inputCommand == 3
        elif inputCommand == 8
            exit = 1
def addDrama(film, director, actor, year):
            film = raw_input("Enter name of film: ")
            director = raw_input("Enter name of director: ")
            actor = raw_input("Enter name of actor: ")
            year = input("Enter year of film: ")
            file = open("database.txt", "w")
            dram = Drama(film, director, actor, year)
            file.write(film, director, actor, year)

def addDoc(narrator, subject, year):
            narrator = raw_input("Enter name of narrator: ")
            subject = raw_input("Enter subject of documentary: ")
            year = input("Enter year of film: ")
            file = open("database.txt", "w")
            doc = Documentary(narrator, subject, year)
            file.write(narrator, subject, year)
7 Years
Discussion Span
Last Post by jlm699

No, you should never be declaring classes inside a function... Your class definitions should go out on the main level and then call them from within the functions...

Also, get rid of your calls to input as it's not safe. You should always use raw_input and then convert to a numerical object. How about you try firing up your interpreter and use input() then type in 4 * 5 + 10 ... It's a flaw that is being removed in Python 3.0

Votes + Comments
good advice
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.