Python Forum
Build class to make a Smart list - trying
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Build class to make a Smart list - trying
#1
Class

import datetime as dt


class Defaults:
    """Storage of Default Values"""

    dbConStr = "pass:Name:Database;"
    baseDate = dt.datetime(2000,12,31)
    baseVal = int(100)


class myStructure:
    """ My custom data structure for arrays """

    def __init__(self, date1=dt.datetime(2000,12,31), num1=0, str1="Nothing"):
        self.date1 = date1
        self.num1 = num1
        self.str1 = str1

        

class MySmartList():
        """ Smart list with field data IDs """

        def __init__(self):
            data = []

        def AddNewRec(self, date1="05/01/1950", num1=0, str1="Nothing"):
            #Accepted date format 05/01/1950
            zDate = dt.datetime.strptime(date1,"%m/%d/%Y")
            k = myStructure(zDate, num1, str1)
            data.append(k)
            
            
trying it out

# Smart List   
myData =[]
my.MySmartList.AddNewRec(myData,date1 = "05/01/1950",num1=100,str1='Test0')
my.MySmartList.AddNewRec(myData,date1 = "05/02/1950",num1=101,str1='Test1')
my.MySmartList.AddNewRec(myData,date1 = "05/03/1950",num1=102,str1='Test2')
Get error on bold line 5 >> data.append(k)

     def AddNewRec(self, date1="05/01/1950", num1=0, str1="Nothing"):
            #Accepted date format 05/01/1950
            zDate = dt.datetime.strptime(date1,"%m/%d/%Y")
            k = myStructure(zDate, num1, str1)
             data.append(k)
Newbie here, what am i doing wrong?
Reply


Messages In This Thread
Build class to make a Smart list - trying - by icm63 - Mar-28-2019, 07:00 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to read module/class from list of strings? popular_dog 1 479 Oct-04-2023, 03:08 PM
Last Post: deanhystad
  Why do I have to repeat items in list slices in order to make this work? Pythonica 7 1,353 May-22-2023, 10:39 PM
Last Post: ICanIBB
  help me to make my password list in python >>> Oktay34riza 0 584 Dec-23-2022, 12:38 PM
Last Post: Oktay34riza
Question Keyword to build list from list of objects? pfdjhfuys 3 1,570 Aug-06-2022, 11:39 PM
Last Post: Pedroski55
  Class-Aggregation and creating a list/dictionary IoannisDem 1 1,926 Oct-03-2021, 05:16 PM
Last Post: Yoriz
  Make Groups with the List Elements quest 2 1,979 Jul-11-2021, 09:58 AM
Last Post: perfringo
  Browse and build a list of folder paths using recursion Ultrainstinct_5 8 5,026 Apr-24-2021, 01:41 PM
Last Post: Ultrainstinct_5
  apendng to a list within a class gr3yali3n 4 2,368 Feb-16-2021, 06:30 AM
Last Post: buran
Question How to make a 3D List of Excel Spreadsheets? chatguy 4 2,755 Jan-24-2021, 05:24 AM
Last Post: buran
  How to append multiple <class 'str'> into a single List ahmedwaqas92 2 2,338 Jan-07-2021, 08:17 AM
Last Post: ahmedwaqas92

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020