Feb-16-2018, 07:37 PM
Good afternoon folks :) I have a question that's going to require a fairly deep technical review but as I am new to python (2 weeks) and getting further than my previous attempts at object oriented programming and did I mention I have a brain injury :) So I will ask kind of a general question to which I will get all righteously indignant if you yell at me that I need specific examples! :) I get it. Bear with me. Thanks in advance.
I have a class to represent a singular object - although this isn't my example, we'll just say "character"
Obviously, the character can have equipment.
Some of that equipment can be containers.
The contents of the containers can be a variety of objects.
My code currently instantiates the character object and creates an object attribute that is for example items{} in the constructor for the object.
My code also populates the character object with the rows of items{} successfully
Some of the character.items rows need character.items.contents
What I am struggling with is the notation necessary to create character.items.container.(attributes here)
In general what I am doing is
defining the character class
defining the items class
defining the containers
populating a new character object
getting the list of items in inventory
storing them as character.items{}
getting the contents of the containers
printing out the contents of the container
breaking down trying to store it
my method of adding a new object is to do addItemToInventory passing the parameter of the item object and then addingContentsToItem. The methods for adding define a new object set the attributes and returns an object :
(this is my example, obviously not RPG characters)
self.planets[_planetID]=Planet.addPlanetToChar(_solarSystemID, _planetID, _planetType, _ownerID, _lastUpdate, _upgradeLevel, _numPins)
This works and populate myChar.planets{}
So I iterate through the planets{} attempt to put a second iteration to add to the planets a "pin" record (a physical location on a map with equipment) so that I end up with myChar.planets{}.pins{]
This is where I bomb:
self.planets[row].planetID[row2]=Pin.addPinToPlanet(_pinID, _typeID, _lon, _lat, self.planets[row].planetID)
TypeError: 'int' object does not support item assignment
Again, thanks ahead of time and I will answer all questions just please don't mock my coding style, it's older than you.
I have a class to represent a singular object - although this isn't my example, we'll just say "character"
Obviously, the character can have equipment.
Some of that equipment can be containers.
The contents of the containers can be a variety of objects.
My code currently instantiates the character object and creates an object attribute that is for example items{} in the constructor for the object.
My code also populates the character object with the rows of items{} successfully
Some of the character.items rows need character.items.contents
What I am struggling with is the notation necessary to create character.items.container.(attributes here)
In general what I am doing is
defining the character class
defining the items class
defining the containers
populating a new character object
getting the list of items in inventory
storing them as character.items{}
getting the contents of the containers
printing out the contents of the container
breaking down trying to store it
my method of adding a new object is to do addItemToInventory passing the parameter of the item object and then addingContentsToItem. The methods for adding define a new object set the attributes and returns an object :
(this is my example, obviously not RPG characters)
self.planets[_planetID]=Planet.addPlanetToChar(_solarSystemID, _planetID, _planetType, _ownerID, _lastUpdate, _upgradeLevel, _numPins)
This works and populate myChar.planets{}
So I iterate through the planets{} attempt to put a second iteration to add to the planets a "pin" record (a physical location on a map with equipment) so that I end up with myChar.planets{}.pins{]
This is where I bomb:
print("\n===>Pin data for planet: ", self.planets[row].planetID," has ", self.planets[row].numPins," rows\n") newFormatString = "\t{0:^10}\t{1:^10}\t{2:>2.2f}\t{3:>2.2f}" #print(self.planets[row].planetID) for row2 in range(0,len(new_planetPins)): _pinID = new_planetPins[row2]['pin_id'] _typeID = new_planetPins[row2]['type_id'] _lon = new_planetPins[row2]['longitude'] _lat = new_planetPins[row2]['latitude'] print(newFormatString.format(_pinID, _typeID, _lon, _lat)) self.planets[row].planetID[row2]=Pin.addPinToPlanet(_pinID, _typeID, _lon, _lat, self.planets[row].planetID)And as expected, I bomb trying to treat the integer index as an object and I'm not sure how to code around this
self.planets[row].planetID[row2]=Pin.addPinToPlanet(_pinID, _typeID, _lon, _lat, self.planets[row].planetID)
TypeError: 'int' object does not support item assignment
Again, thanks ahead of time and I will answer all questions just please don't mock my coding style, it's older than you.