Aug-15-2018, 05:09 PM
Hey folks,
I've been trying to dump the contents of my google drive sheet into class instances. My understanding of classes and object oriented programming in python feels a little bit incomplete so if I misuse any terminology feel free to correct me at any point here.
The output of the drive sheet spits the contents into a dictionary contained inside of a list. This is the output here
This is my class here:
To convert the raw output of the drive sheet into a readable format, I have been using this ugly and inefficient function here.
TLDR: I am trying to create a class by calling an specific list item that doesn't exist until the script is run but I don't know how to do it and I cant find how online.
I've been trying to dump the contents of my google drive sheet into class instances. My understanding of classes and object oriented programming in python feels a little bit incomplete so if I misuse any terminology feel free to correct me at any point here.
The output of the drive sheet spits the contents into a dictionary contained inside of a list. This is the output here
This is my class here:
class Turret:
def __init__(self, copyable, turret_name, burst, fire_rate, hull_dmg, shield_dmg, sound_name, random, man_accuracy, life_time, laser_thickness, speed, burst_time_in_between, price, color):
self.copyable = copyable
self.turret_name = turret_name
self.burst = burst
self.fire_rate = fire_rate
self.hull_damage = hull_dmg
self.shield_damage = shield_dmg
self.sound_name = sound_name
self.random = random
self.man_accuracy = man_accuracy
self.life_time = life_time
self.laser_thickness = laser_thickness
self.speed = speed
self.burst_time_in_between = burst_time_in_between
self.price = price
self.color = colorFor the class object/instance name I am trying to use the TurretName value from the sheet output, but I have been unable to do this successfully. To convert the raw output of the drive sheet into a readable format, I have been using this ugly and inefficient function here.
# Take turret sheet output and log it's contents as objects under the Turret class.
def clean_turret_sheet_data(currentTurrets):
i = 0
b = 0
selected_item_list = []
for dict in currentTurrets:
selected_turret = currentTurrets[i]
for key, value in selected_turret.items():
temp = [key, value]
selected_item_list.append(temp)
copyable = selected_item_list[b][1]
b += 1
turret_name = selected_item_list[b][1]
b += 1
burst = selected_item_list[b][1]
b += 1
fire_rate = selected_item_list[b][1]
b += 1
hull_dmg = selected_item_list[b][1]
b += 1
shield_dmg = selected_item_list[b][1]
b += 1
sound_name = selected_item_list[b][1]
b += 1
random = selected_item_list[b][1]
b += 1
man_accuracy = selected_item_list[b][1]
b += 1
life_time = selected_item_list[b][1]
b += 1
laser_thickness = selected_item_list[b][1]
b += 1
speed = selected_item_list[b][1]
b += 1
burst_time_in_between = selected_item_list[b][1]
b += 2
price = selected_item_list[b][1]
b += 2
color= selected_item_list[b][1]
b += 1
turretList[i] = Turret(copyable, turret_name, burst, fire_rate, hull_dmg, shield_dmg, sound_name, random, man_accuracy, life_time, laser_thickness, speed, burst_time_in_between, price, color)
print(turretList[i].turret_name, "logged!")
i += 1It seems like the class instance has to be defined before the script can be run? My question is: is there any way to initiate the class using external variables from outside the code after the script has been run. TLDR: I am trying to create a class by calling an specific list item that doesn't exist until the script is run but I don't know how to do it and I cant find how online.
