0

New to python and self-taught so I'm probably going about this horribly wrong but I'm trying to find the best way to list out objects while also placing them in a list. I was advised to find a way to do this by a friend to avoid double entry of creating my object then typing my object's name in. I'm open to any critiques and advice, thanks!

The way I have it set up now is giving me the error

line 16, in <module>
 Starters.append(Botamon = Digi("Botamon",0,1,1,1,1,[""]))
TypeError: list.append() takes no keyword arguments"
#Class
class Digi:
 def __init__(self,mon,age,offense,defense,speed,brains,evo):
 self.mon = mon
 self.age = age
 self.offense = offense
 self.defense = defense
 self.speed = speed
 self.brains = brains
 self.evo = evo
#Digilist
Starters = []
Starters.append(Botamon = Digi("Botamon",0,1,1,1,1,[""]))
Starters.append(Poyomon = Digi("Poyomon",0,1,1,1,1,[""]))
Starters.append(Punimon = Digi("Punimon",0,1,1,1,1,[""]))
Starters.append(Yuramon = Digi("Yuramon",0,1,1,1,1,[""]))
Digilist = []
Digilist.append(Koromon = Digi("Koromon",1,3,3,3,3,["Botamon"]))
Digilist.append(Tokomon = Digi("Tokomon",1,3,3,3,3,["Poyomon"]))
Digilist.append(Tsunomon = Digi("Tsunomon",1,3,3,3,3,["Punimon"]))
Digilist.append(Tanemon = Digi("Tanemon",1,3,3,3,3,["Yuramon"]))
#Starter
self = random.choice(Starters)
name = self.mon
asked Jun 21, 2021 at 14:22
1
  • You should just use Starters.append(Digi("Botamon",0,1,1,1,1,[""])), without Botamon =, etc. Commented Jun 21, 2021 at 14:26

1 Answer 1

1

The problem is you are naming your variables while appending them. If you are never going to access them by their name just do it like so:

Starters = []
Starters.append(Digi("Botamon",0,1,1,1,1,[""]))
Starters.append(Digi("Poyomon",0,1,1,1,1,[""]))
Starters.append(Digi("Punimon",0,1,1,1,1,[""]))
Starters.append(Digi("Yuramon",0,1,1,1,1,[""]))

If you have to access them by name later on, create them then append them:

Botamon = Digi("Botamon",0,1,1,1,1,[""])
Starters.append(Botamon)

and so on... However in the code example you have provided it looks like you will not have to access them by their variable name.

answered Jun 21, 2021 at 14:35
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.