I'm looking to replace a variable with a parameter in a function
Basically, I want to replace 'country' with 'aus' in this function. headline_aus is a value predefined elsewhere, I just want to be able to replace the word 'country' with 'aus', so I can use the function with other countries (I've got a variable called headline_usa which I want to retrieve using the same code)
def print_stories(country):
Headline1 = headline_country[0]
print(Headline1)
print_stories('aus')
I've been recommended a dictionary, but essentially want to use it like this, tho idk if that's how dictionaies work:
def print_stories(country):
d = {'aus' : country = 'aus',
'usa' : country = 'usa',
'france': country ='france'}
for i in range(3):
Headline[i+1] = headline_country[i]
Image[i+1] = image_country[i]
Description[i+1] = Description_country[i]
pubDate[i+1] = pubDate_country[i]
For context, I have a webscraper that uses the .xml feeds of 3 different news sources from 3 different countries (aus, france and usa). This webscraper function outputs global variables, for aus:
headline_aus
description_aus
image_aus
pubDate_aus
For usa and france, the variables are followed by _usa and _france respectively.
I wish to create a function (print_stories()
), that can access these variables through a parametised function. I want to feed print_stories()
either aus, usa, or france, and it will give me headline_aus
, headline_usa
, or headline_france
.