V
V
VitaliySm2015-02-20 19:15:18
Python
VitaliySm, 2015-02-20 19:15:18

How to properly overload a constructor?

How to override the CrawlSpider constructor so that it takes a value as input, do this:

allowed_domains = []

def __init__(self, *args, **kwargs):
        super(CrawlSpider, self).__init__(self, *args, **kwargs)
        if args == True:
            self.start_urls = ['%s' % args]
        else:
            self.start_urls = ['%s' % kwargs]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Huseynov, 2015-02-22
@VitaliySm

Are you asking how to write a constructor to do what it does now? Don't change anything and it will work as you ask.
But, comparing args with True is strange, they have different types and the expression will always be false. It is necessary to write like this:
I.e. use an implicit cast to a boolean variable. Compare as suggested in another comment: if args[0]most likely it is impossible. this code requires a single positional argument and checks for it.
The rest of the code is weird too. Here it is:
forms a list of one line, which will have the first positional argument. Not a list of strings, just one. And only with the first argument, but not with all.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question