我有一个字符串列表,每个字符串都代表书籍及其一些属性,例如
# each book followed by the price and the name of the genre
book_names = ['love 3 romance',
'rose 6 drama',
'flower 7 nice_story']
我想以某种方式为每本书创建一个新对象,并为其创建字符串描述属性的其他部分。
这是我尝试过的(显然,它不起作用):
class Book_Class():
price=0
genre=''
book_content=[]
for i in book_names:
name=i.split()[0]
name=Book_Class()
name.price=i.split()[1]
name.genre=i.split()[2]
也许有一种简单的方法可以实现我所追求的(请告诉我,因为我对编程还很陌生……)。