1

My class gcb_ip has those attributes:

class gcb_ip:
    ip = None
    country_code = None
    score = None
    asn = None
    records = list()

1) I fill up the records list with a specific method.

2) I can see the records and the rest of my attributes inside the object if I check it my main code.

3) I CAN'T see the records but the rest of my attributes inside the object if I check it into another class method passed by parameters.

I come from C++ and I guess that this is a copy/reference parameter passing issue. ¿What's going on?

Cory Kramer
  • 114,268
  • 16
  • 167
  • 218

1 Answers1

0

Do you have your init function properly defined, and have those parameters set? For example

class gcb_ip(object):
    def __init__(self, IP, country_code, score, asn):
        self.IP = IP
        self.country_code = country_code
        self.score = score
        self.asn = asn
        self.records = list()

This is the equivalent of setting up your explicit constructor in C++, and initializing your member variables.

Then you can reference the parameters of that object as you would expect, for example

myIP = someGcbObject.IP
Cory Kramer
  • 114,268
  • 16
  • 167
  • 218
  • Yes, I've been defined the constructor, and the class works 100% right. It's just that when I pass a class instance through parameter into another class method the 'records' list looks empty, but outside the method is not. – user3412296 Mar 13 '14 at 16:43