How to generate powerful tags for your content - SEO
One of the biggest task while writing article or blog is to have right set of…
March 08, 2022
To give some context, I have two python files. (Both in same folder - jira_wrapper)
And, I need to import one into another. I imported them as:
# file retry_helper.py
from jira_wrapper.jira_client import JiraClient
# file jira_client.py
from jira_wrapper import retry_helper
I got this error:
ImportError: cannot import name 'JiraClient' from partially initialized module 'jira_wrapper.jira_client' (most likely due to a circular import) (/jira_wrapper/jira_client.py)
I hope you get the scenario. One is dependent on Two, Two is dependent on One. Kind of a chicken-egg problem. Lets solve it.
When you do simple import XYZ
, it will work fine. By the time the code runs, all the modules will be imported (loaded). When you from ABC import XYZ
syntax, now this module require ABC
module to be fully loaded or imported before it can be imported anywhere.
In Python, import
statements are executable statements.
Lets modify our code a little bit.
# file retry_helper.py
import jira_wrapper.jira_client as jira_client
# file jira_client.py
import jira_wrapper.retry_helper as retry_helper
And, if I need to access a function. I will use it like below:
retry_helper.retry_if_xyz
If you have a class to access:
jira_client.JiraClient
Try running now, it solves the error :)
One of the biggest task while writing article or blog is to have right set of…
Assuming your web application is using oracle, and you are deploying your app on…
Introduction We often require to execute in timed manner, i.e. to specify a max…
Suppose you have two lists, and you want Union and Intersection of those two…
This article shows some of common usages of JIRA rest apis. Note: This article…
Introduction In this guide, we will see git basic commands, and fundamentals of…
Introduction So you have a Django project, and want to run it using docker image…
Introduction It is very important to introduce few process so that your code and…
Introduction In this post, we will see a sample Jenkin Pipeline Groovy script…
Introduction We often require to execute in timed manner, i.e. to specify a max…
Introduction In some of the cases, we need to specify namespace name along with…
Introduction In most of cases, you are not pulling images from docker hub public…