0

With Python 3.5, I want to build a new class which is tuple wrapping an association of datastructures in order to perform some operation. It happens that I would also need some attributes. So I wrote this:

class tuplewrapper:
    def __init__(self, dict={}):
        print("initiating")
        data=dict
        self=tuple([dict(),dict()])
        self.keys=iter(self[0])
        self.values=iter(self[1])
        self.put(data)# another function that add data in the dict as self.keys and self.values. *No need to describe, as the problem is in __init__ and mostly about syntax...*

I know this look similar to keys and values of a dict, but I need to do some special processing and this class would be very useful doing it. The problem being that since I define self as tuple([dict(),dict()]); Python is returning AttributeError since tuple has no such keys as keys and values. Which is precisely why I built this class in addition to add functions to this. So what am I doing bad? How to correct this? I don't know how to use "super" as documentation is not pretty explicit about it (and this didn't help), and for me it was pretty much acquired that in init, I could define the things however I wanted because it is the interest of the thing, but It seems I pretty much misunderstood the concept.
So, how do I do this, please?

Community
  • 1
  • 1
Ando Jurai
  • 1,003
  • 2
  • 14
  • 29
  • what is the operation you want to perform? How does the tuple ({}, {}) relate to the data you pass to __init__ as dict? – Henry Heath Nov 24 '16 at 10:34
  • The keys and values in the dict are respectively tuples and nested lists, I have then a put function to convert the dict and add what's relevant to self.keys and self.values. – Ando Jurai Nov 24 '16 at 10:48
  • So given an input dict `{'a': 'A', 'b': 'B'}` what should tuple, keys and values look like? – Henry Heath Nov 24 '16 at 10:57
  • self should return a tuple (dict1('a':processed_value_a,'b':processed_value_b,), dict2('index_calculated_from_a':processed_value_a,'index_calculated_from_b':processed_value_b,). – Ando Jurai Nov 24 '16 at 11:58
  • But how does that help to answer to the problem being: I want to do a tuple derivated class which has additional attributes, how do I do that? It is not even related to this problem/form of the class. I mean, what's just wrong with my syntax, please? The algorithm of my program, I will choose and handle. I only need help for syntax. Not for choosing for myself. Thanks by advance. – Ando Jurai Nov 24 '16 at 12:00

0 Answers0