1👍
Why that would be a problem? exception would me matched based on class type and it would be same however it is imported e.g.
import exceptions
l=[]
try:
l[1]
except exceptions.IndexError,e:
print e
try:
l[1]
except IndexError,e:
print e
both catch the same exception
you can even assign it to a new name, though not recommended usually
import os
os.myerror = exceptions.IndexError
try:
l[1]
except os.myerror,e:
print e
1👍
“If not, what would be best practices to avoid these name clashes?”
That depends entirely on why they happen. In a normal installation, you can not import from both application.exceptions and somepath.application.exceptions, unless the first case is a relative path from within the module somepath. And in that case Python will understand that the modules are the same, and you won’t have a problem.
You are unclear on if you really have a problem or if it’s theory. If you do have a problem, I’d guess that there is something fishy with your PYTHONPATH. Maybe both a directory and it’s subdirectory is in the PATH?
- [Answered ]-How to make form view with user is foreign key and one model has foreign key relationship with another model?
- [Answered ]-Django generic foreign key field not assigned during construction, but is able to be assigned post-construction
- [Answered ]-Django bootstrap to have both call a view and modal in same anchor tag
- [Answered ]-Django database dynamically chosen based on part of the domain name
0👍
Even if the same module is imported several times and in different ways, the CustomException class is still the same object, so it doesn’t matter how you refer to it.
- [Answered ]-How to store data from html form to postgres database using Django 1.10?
- [Answered ]-Django ModelForm not saving data that is added to request.POST or through form.save(commit=False)
- [Answered ]-How to set up logging on Django + Heroku?
- [Answered ]-Django Forms – Can't raise validation error in tests
0👍
I don’t know if there is a way to handle this inclusion path issue.
My suggestion would be to use the ‘as’ keyword in your import
Something like:
import some.application.exceptions as my_exceptions
or
import application.exceptions as my_exceptions
- [Answered ]-Django: How to update Photo model that uses Imagekit without re-uploading photo on save()
- [Answered ]-In upgrading to Django 1.8, why do I get the AttributeError 'ManyToManyRel' object has no attribute 'rel'?
- [Answered ]-Django forms: could not convert string to float
- [Answered ]-Getting AttributeError while registering my model to Django admin?