0

My code

# Import class Parser from parser.py
from parser import Parser 

from multiprocessing.pool import Pool

def main(id):
    ... 
    url = 'test_url.com'
    Parser = Parser()
    Parser.get_response(url)
    Parser.get_beautifulsoup()
    ...

ids = [id for id in range(1, 100)]

p = Pool(20)
p.map(main, ids)

Problem

I need to call the class Parser within the main() function, but I have an error UnboundLocalError: local variable 'Parser' referenced before assignment.

Question

How can I correctly call the Parser class inside the main()?

1
  • 2
    You are overriding the class with the instance, rename Parser to parser Commented Aug 4, 2022 at 11:00

1 Answer 1

1

Hmm...don't name your instance the same as the class. Do something like:

my_Parser = Parser()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.