i'm learning python currently, coming from c++ and i realized that i can't do certain things like in C++

anyways, i created a class call Object_refs:

#attempt to make a structure like class using INIT
#to define all common variables.
class Object_refs:
	def __INIT__(self, descriptor_type, type, reference_count, flags):
		self.desctype = descriptor_type
		self.type = type
		self.refcount = reference_count
		self.flags = flags

now, i can do this:

OBJREF = Object_refs #i'm tying to define the class as another variable, like a typedef in c++

in the python terminal it shows:

<class __MAIN__.Object_refs at 0x0000000001E3F888>

however, i cannot do this:

>> OBJREF.type = '\u01'
AttributeError: Object_refs has no attribute type

maybe i'm not understanding python classes correctly. could somebody help me try to understand this better?

5 Years
Discussion Span
Last Post by LdaXy

You can look at this,and type is a reserved word in python.

class Object_refs(object):
    def __init__(self, descriptor_type, my_type, reference_count, flags=None):
        '''initializer method can be compared with constructor C++,but are not the same'''
        self.desctype = descriptor_type
        self.my_type = my_type
        self.refcount = reference_count
        self.flags = flags

Use class.

>>> descriptor_type = 1
>>> my_type = 'string'
>>> reference_count = 10
>>> obj = Object_refs(descriptor_type,my_type,reference_count)
>>> obj.my_type
>>> obj.my_type = '\u01'
>>> obj.my_type

oh. had no idea type was reserved. thanks for the info. this makes things much clearer.

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.