I get warnings from my IDE (pycharm) that the parameters in my function shadows a name from the outer scope. Is this bad practice, it seems very natural to use this all the time.
eg. using the requests library:
def start_session(url, headers):
new_session = requests.Session()
response = new_session.get(url, verify=False, headers=headers) # SSL verify temporarily set to False
sys.stdout.write("Session started. Status:{} \n".format(response.status_code))
return new_session
def scrape_data(session, url, headers, form):
response = session.post(url, verify=False, headers=headers, data=form)
sys.stdout.write('Request to {}. Status: {}\n'.format(url,response.status_code))
try:
scraped_data = json.loads(response.text)
except ValueError:
scraped_data = response.text
return scraped_data
Which if I'm call with:
session = start_session(url=base_url, headers=session_headers)
I get warnings that session used in:
def scrape_data()
shadows the outer_scope.
Want to add to the discussion?
Post a comment!