Link to home
Start Free TrialLog in
Avatar of ScriberUK
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 :)
url = 'www.test.com'
 
class Parser(HTMLParser, url):
    print url
 
hParser = Parser(url)

Open in new window

Avatar of HonorGod
HonorGod
Flag of United States of America image

url = 'www.test.com'

class Parser( HTMLParser ) :
  def __init__( self, url ) :
    self.URL = url

hParser = Parser( url )
ASKER CERTIFIED SOLUTION
Avatar of Roger Baklund
Roger Baklund
Flag of Norway image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial