My code does the following:
1) Defines a somewhat large dictionary
2) Uses the requests library to send a post request with the dictionary to a webserver.
If I set the dictionary up as a class variable (class is defined within the same .py file) and later reference it through its member function (called by main), it takes significantly longer to execute (about half-one second longer when timed).
However, if I define the dictionary within the scope of the class's member function, it executes half-one second faster.
Can someone explain why this happens? I've asked around and googled; it seems like interpreted languages like Python don't execute like compiled languages in the sense that there's a parsing process that's done by the interpreter that slows down runtime.
EDIT: Some code (of the first method, second method simply moves the dictionary into the scope of myClass.theFunction())
import requests
class myClass():
def __init__(self):
...Other member variables...
self.user_session = requests.Session()
self.myDict = { 'key1': 'value1',
....
'key30': 'value30'
}
def theFunction(self):
....some parsing stuff...
session_post = self.user_session.post(url=self.URL, data=self.myDict,
headers=self.headers)
print session_post.status_code
if __name__ == '__main__':
instance = myClass()
instance.theFunction()