Alright guys, I'm kinda new to python.

I've made a kind of an organiser program that allows you to make entries with deadlines, write them to a text file and display them in human readable format when I want it to.

I first made it in command line and it worked perfectly there but when I tried to make a GUI for it with Tkinter, I split it into multiple files and classes for easy handling and tried to make it read stuff from a file for a start.

I get the error AttributeError: 'FunctStatements' object has no attribute 'difference' when I run my code.

Here's the initialization of FunctStatements in the module "GUIModule.py"

self.FunctObject = FunctStatements()

and its use in the same module

def WriteToList(self):
        for x in self.FunctObject.readfile(self.path):
            self.StuffDisplayer.insert(END, x)

Here is "FunctModule.py" which does the actual File I/O

from datetime import date
import datetime

class FunctStatements:
    def readfile(self,path):
            self.f = open(path, 'r')
        except IOError:
            print("Cannot open file\n")
        self.line = self.f.readlines()
        self.number = 0
        for x in self.line:
            if(x[0] == '1'):
                self.entering = x
                self.number += 1
            elif(x[0] == '2'):
                self.description = x[2:]
            elif(x[0] == '3'):
                self.deadline = date(int(x[2:6]), int(x[7:9]), int(x[10:12]))
                self.difference = self.deadline - self.now.date()
            if(self.difference.days >= 0): #this line returns the error
                self.output = ("Entry no: " + str(self.number) + "\n" + "Date and time
of entering: "\
                      + str(self.entering) + "Message: " + str(self.description) + \
                          "Deadself.line: " + str(self.deadline) + "\n" + "Days left: " + \
                          str(self.difference.days) + "\n")
            self.outputlines = []
            yield self.outputlines
    def __init__(self):
        self.now = datetime.datetime.now()

Judging by the looks of it, I guess the problem is staring me right in the face.:-/

5 Years
Discussion Span
Last Post by C0deM0nkey

difference is uninitialized from alternatives '1' and '2', do you mean it to be indented inside branch for '3'?


Sorry, Tony already answered. The indent is probably incorrect.

Edited by woooee: n/a


Yeah thx guys ur right, this indent stuff is still kinda confusing, im actually a java programmer

This question has already been answered. 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.