Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Passing an object as a paramter

$
0
0
I have two classes, called Journal and JournalEntry. The JournalEntry constructor has several parameters that are passed with it is instantiated, like time, date, subject, context. In the Journal class, there is a function called addEntry(self, JournalEntry) that adds an entry to the journal. I'm having trouble getting the addEntry function started...

My problem is that I don't really know how to instantiate the entry...I'm not used to dynamically typed languages like Python.

The actual values are supplied in the JournalEntry class. For example, an entry could be entry1 = journalentry.JournalEntry("1215", "02142013", "My day", "Today was Valentine's Day.").

Class Journal(object):
    def __init__(self):
        journalList = []

    def addEntry(self, entry):
        self.theEntry = entry #is this right?
        self.theEntry = entry(time, date, subject, context) #or is this?
        journalList += entry



The Journal constructor creates an empty list, and then addEntry would add an entry to the list each time. Will this work?

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>