Avatar ·

Relative import in Python

📁 Advanced Python Topics, question, Help

For some time now (since relative imports were removed), I haven't been able to properly solve this issue:

Suppose the program structure is

app/    __init__.py    foo/        __init__.py        handler.py

How can I load something from the foo package from the handler.py module?

The thing is that the name of the foo package is initially unknown, I load it using importlib.

So far I've found this workaround: I truncate the __name__ variable, which in handler.py equals 'foo.handler', like this

foo_name = __name__.rsplit('.', 1)[0]

and then load

Avatar ·

Pay attention to the Python package .

This library was specifically written to quickly download large volumes from Bitrix24 in one line of code, using parallel requests and batching requests.

To download all leads:

import fast_bitrix24# insert your webhook belowb = fast_bitrix24.Bitrix('your_webhook_goes_here')leads = b.get_all('crm.lead.list')

You will get a list of all your leads. 30000 leads will load in about 10-20 seconds.

Log in to leave an answer

Blogs