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):
        try:
            self.f = open(path, 'r')
        except IOError:
            print("Cannot open file\n")
        self.f.seek(0)
    
        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 = []
            self.outputlines.append(self.output)
            
            yield self.outputlines
                
        self.f.close()
    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.:-/

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.

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

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.