Execute code depending on import success [on hold]
up vote
-1
down vote
favorite
I'm using a library that provided me with a class that I can use. Additionally I created my special version of this class with some additional functionality (different output formatting, it is backward compatible). The idea is that it may or may not be available, if not - use standard version. Currently I'm checking if I can use it like that:
try:
from my_modiication import my_class
if isinstance(value, my_class):
self._init = deepcopy(value.format_me())
else:
self._init = deepcopy(value)
except ImportError:
self._init = deepcopy(value)
Is it safe to check for import success that way? Maybe there is a simpler way to achieve the same effect.
python
New contributor
corwin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
put on hold as off-topic by Gareth Rees, πάντα ῥεῖ, Zeta, BCdotWEB, 200_success 13 hours ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – Gareth Rees, πάντα ῥεῖ, Zeta, BCdotWEB, 200_success
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
up vote
-1
down vote
favorite
I'm using a library that provided me with a class that I can use. Additionally I created my special version of this class with some additional functionality (different output formatting, it is backward compatible). The idea is that it may or may not be available, if not - use standard version. Currently I'm checking if I can use it like that:
try:
from my_modiication import my_class
if isinstance(value, my_class):
self._init = deepcopy(value.format_me())
else:
self._init = deepcopy(value)
except ImportError:
self._init = deepcopy(value)
Is it safe to check for import success that way? Maybe there is a simpler way to achieve the same effect.
python
New contributor
corwin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
put on hold as off-topic by Gareth Rees, πάντα ῥεῖ, Zeta, BCdotWEB, 200_success 13 hours ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – Gareth Rees, πάντα ῥεῖ, Zeta, BCdotWEB, 200_success
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I'm using a library that provided me with a class that I can use. Additionally I created my special version of this class with some additional functionality (different output formatting, it is backward compatible). The idea is that it may or may not be available, if not - use standard version. Currently I'm checking if I can use it like that:
try:
from my_modiication import my_class
if isinstance(value, my_class):
self._init = deepcopy(value.format_me())
else:
self._init = deepcopy(value)
except ImportError:
self._init = deepcopy(value)
Is it safe to check for import success that way? Maybe there is a simpler way to achieve the same effect.
python
New contributor
corwin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I'm using a library that provided me with a class that I can use. Additionally I created my special version of this class with some additional functionality (different output formatting, it is backward compatible). The idea is that it may or may not be available, if not - use standard version. Currently I'm checking if I can use it like that:
try:
from my_modiication import my_class
if isinstance(value, my_class):
self._init = deepcopy(value.format_me())
else:
self._init = deepcopy(value)
except ImportError:
self._init = deepcopy(value)
Is it safe to check for import success that way? Maybe there is a simpler way to achieve the same effect.
python
python
New contributor
corwin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
corwin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
corwin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 15 hours ago
corwin
1
1
New contributor
corwin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
corwin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
corwin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
put on hold as off-topic by Gareth Rees, πάντα ῥεῖ, Zeta, BCdotWEB, 200_success 13 hours ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – Gareth Rees, πάντα ῥεῖ, Zeta, BCdotWEB, 200_success
If this question can be reworded to fit the rules in the help center, please edit the question.
put on hold as off-topic by Gareth Rees, πάντα ῥεῖ, Zeta, BCdotWEB, 200_success 13 hours ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – Gareth Rees, πάντα ῥεῖ, Zeta, BCdotWEB, 200_success
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes