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)
            else
                addDoc(narrator, subject, year)
        elif inputCommand == 2
            listFilms(film, director, actor, year)
        elif inputCommand == 3
            releaseDate(year)
        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: ")
            filedata
            file = open("database.txt", "w")
            dram = Drama(film, director, actor, year)
            file.write(film, director, actor, year)
            file.close()

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: ")
            filedata
            file = open("database.txt", "w")
            doc = Documentary(narrator, subject, year)
            file.write(narrator, subject, year)
            file.close()

Dani AI

Generated

Short version: you’re close, but several structural and syntax issues make the program fail before OOP can help. , treat classes as blueprints (module-level), not nested inside main(). is right to warn about input() — use safe string input and convert, and validate user data.

Below is a minimal, modern pattern to follow (module-level classes, subclassing with super(), and a readable repr). It shows the shape of objects you want without reproducing the original broken code:

class Film:
    def __init__(self, title, year, fans=0):
        self.title = title
        self.year = int(year)
        self.fans = int(fans)

class Drama(Film):
    def __init__(self, title, director, actor, year, fans=0):
        super().__init__(title, year, fans)
        self.director = director
        self.actor = actor

    def __repr__(self):
        return "<Drama {} ({}) by {}>".format(self.title, self.year, self.director)

Practical notes and common fixes you can apply now:

  • Syntax errors: every def and if needs a trailing colon; watch indentation. Use a linter (or run the file in the interpreter) to catch these quickly.
  • Scoping/arguments: when a subclass calls the base __init__, pass actual variables available in that scope (or use super()). Don’t call Film.__init__(self, year, fans) if year and fans are undefined there.
  • Input: in modern Python use input() and int() with try/except for validation; in old Python 2 use raw_input() (note: Python 2 is EOL — prefer Python 3).
  • Persistence: use with open(...) and a structured format (CSV or JSON). w truncates files; a appends. file.write() expects a single string — serialize data before writing.
  • Runtime design: keep a list of film objects while the program runs, implement __repr__ for readable listing, and write the list out at exit.

Checklist to debug quickly: move classes out of functions, fix __init__ signatures and calls, replace dangerous input() usage with safe parsing, stop using file as a variable name, and use a context manager for file I/O.

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

commented: good advice +6
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.