Hi, I must be having a brain freeze. Someone please point out the error of my ways :) When importing the following module called PValidation I get an error. ### begin module PValidation.py from DateTime import DateTime def validateMoney(input): """ Strip leading $ from input and make sure it can be converted to a float datatype otherwise return 0 """ if input == '': input = '0' if input[0] == '$': input = input[1:] try: float(input) except: input = '0' return input def validateDate(input): """ If input can be formated by DateTime return formatted text otherwise return an empty string """ try: results = DateTime(input).strftime('%m/%d/%Y') except: results = '' return results ### End Module I get this traceback error: An exception occurred during the last refresh. Exception type: ImportError Exception value: cannot import name validateDate Traceback (most recent call last): File "C:\Program Files\Zope-2.7.0-b2\lib\python\App\RefreshFuncs.py", line 182, in performSafeRefresh if not performRefresh(jar, productid): File "C:\Program Files\Zope-2.7.0-b2\lib\python\App\RefreshFuncs.py", line 169, in performRefresh Application.reimport_product(productid) File "C:\Program Files\Zope-2.7.0-b2\lib\python\OFS\Application.py", line 767, in reimport_product raise_exc=1, log_exc=0) File "C:\Program Files\Zope-2.7.0-b2\lib\python\OFS\Application.py", line 534, in import_product product=__import__(pname, global_dict, global_dict, silly) File "C:\Zope-PropOrg\Products\PRealEstate\__init__.py", line 5, in ? from PRealEstate import PRealEstate, manage_addPRealEstateForm, manage_addPRealEstate File "C:\Zope-PropOrg\Products\PRealEstate\PRealEstate.py", line 21, in ? from PParcel import PParcel File "C:\Zope-PropOrg\Products\PRealEstate\PParcel.py", line 19, in ? from PStructure import PStructure File "C:\Zope-PropOrg\Products\PRealEstate\PStructure.py", line 18, in ? from PUnitResident import PUnitResident File "C:\Zope-PropOrg\Products\PRealEstate\PUnitResident.py", line 18, in ? from PLeaseResident import PLeaseResident File "C:\Zope-PropOrg\Products\PRealEstate\PLeaseResident.py", line 20, in ? from Products.PUtils.PValidation import validateMoney, validateDate ImportError: cannot import name validateDate
I must be having a brain freeze. Someone please point out the error of my ways :) When importing the following module called PValidation I get an error.
### begin module PValidation.py from DateTime import DateTime
def validateMoney(input): """ Strip leading $ from input and make sure it can be converted to a float datatype otherwise return 0 """
if input == '': input = '0' if input[0] == '$': input = input[1:] try: float(input) except: input = '0' return input
def validateDate(input): """ If input can be formated by DateTime return formatted text otherwise return an empty string """
try: results = DateTime(input).strftime('%m/%d/%Y') except: results = '' return results ### End Module
Unless it's in your first line (the DateTime import), I don't think it has anything to do with that file or the import statement itself, as I was able to do it outside of Zope (which is why I had to get rid of the first line.) Perhaps there's something else named validateDate already? What happens when you split it into two imports? What about renaming the function? --jcc -- "My point and period will be throughly wrought, Or well or ill, as this day's battle's fought."
participants (2)
-
J. Cameron Cooper -
mlong@datalong.com