I'm trying to call a function using a name of a var dynamically, but I don't know if this is possible, something like that:
fight_movies = list() # var how I want to use in function call
win_movies = list() # var how I want to use in function call
knowledge_movies = list() # var how I want to use in function call
biography_movies = list() # var how I want to use in function call
for genre in genres:
.... Ommited #\/\/\/\/\/\/ Here is where I call the function
write_jsonl(genre + '_movies', genre, rating, title, genre) #here is the call of the function
def write_jsonl(movie_list, genre, rating, title, json_name):
dict = {'title': title, 'genre': genre, 'rating': rating}
movie_list.append(dict)
# print(action_movies)
with jsonlines.open(json_name+'.jsonl', mode='w') as writer:
writer.write(movie_list)
I'm trying to pass the variable name as a list dynamically, but I'm not sure if that's possible in python, any suggestions?
Error: Traceback (most recent call last):
File "bucky.py", line 58, in <module>
web_crawling()
File "bucky.py", line 34, in web_crawling
write_jsonl(genre + '_movies', genre, rating, title, genre)
File "bucky.py", line 52, in write_jsonl
movie_list.append(dict)
AttributeError: 'str' object has no attribute 'append'