ScriberUK
asked on
Python, pass variable into class
Hello all,
I have a class which I define thus: "class Parser(HTMLParser):". I would now like to pass a variable into it as per the pseudocode below but I get the following error "NameError: name 'url' is not defined"
Help :)
I have a class which I define thus: "class Parser(HTMLParser):". I would now like to pass a variable into it as per the pseudocode below but I get the following error "NameError: name 'url' is not defined"
Help :)
url = 'www.test.com'
class Parser(HTMLParser, url):
print url
hParser = Parser(url)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
class Parser( HTMLParser ) :
def __init__( self, url ) :
self.URL = url
hParser = Parser( url )