python script error: pls help
I have a Zcatalogue that store id of Dtml docs as part of the meta_data, then i want to iterate over it and see if at least there will be one id that equal to tday and return the value assigned to tday or else to store the value of yday to tday and return it as tday. Then my major problem is how to access the id from the Zcat_New1_Dtml_doc; The code below is giving me Error Type: NameError Error Value: global name 'id' is not defined tday=DateTime().toZone('GMT+1').strftime('%d%m%y') yday=(DateTime()-1).toZone('GMT+1').strftime('%d%m%y') for i in context.Zcat_New1_Dtml_doc(): if tday==id: return tday else: tday=yday return tday ===== Hamzat kamaldeen Ishola Dnet Systems Limited. 223 Ikorodu Road, Lagos. Nigeria. 234 1 7749381, 234 08033011305 --- If Mistake is an opportunity to see better, then it is not a problem but readiness to admit it. Sentimental decisions are not mistakes but failures !!! __________________________________________________ Do You Yahoo!? HotJobs - Search Thousands of New Jobs http://www.hotjobs.com
Maybe try: if tday==i.id: If you are trying to access the id from the metadata. It might be clearer with a more descriptive iterator variable, such as "doc" or something. hth, -Casey On Tuesday 20 August 2002 01:07 pm, Sir K wrote:
I have a Zcatalogue that store id of Dtml docs as part of the meta_data, then i want to iterate over it and see if at least there will be one id that equal to tday and return the value assigned to tday or else to store the value of yday to tday and return it as tday.
Then my major problem is how to access the id from the Zcat_New1_Dtml_doc;
The code below is giving me Error Type: NameError Error Value: global name 'id' is not defined
tday=DateTime().toZone('GMT+1').strftime('%d%m%y') yday=(DateTime()-1).toZone('GMT+1').strftime('%d%m%y') for i in context.Zcat_New1_Dtml_doc(): if tday==id: return tday else: tday=yday return tday
On Tue, Aug 20, 2002 at 10:07:37AM -0700, Sir K wrote:
I have a Zcatalogue that store id of Dtml docs as part of the meta_data, then i want to iterate over it and see if at least there will be one id that equal to tday and return the value assigned to tday or else to store the value of yday to tday and return it as tday.
Then my major problem is how to access the id from the Zcat_New1_Dtml_doc;
The code below is giving me Error Type: NameError Error Value: global name 'id' is not defined
tday=DateTime().toZone('GMT+1').strftime('%d%m%y') yday=(DateTime()-1).toZone('GMT+1').strftime('%d%m%y') for i in context.Zcat_New1_Dtml_doc(): if tday==id:
Well, you haven't mentioned "id" before this point, so of course it's not defined. Python doesn't do that <dtml-in> voodoo. Assuming Zcat_New1_Dtml_doc is a ZCatalog, then calling it will give you a list of objects. I think you want to test the id *of each object*, right? So just do: for item in context.Zcat_New1_Dtml_doc(): if tday==item.id: ... -- Paul Winkler "Welcome to Muppet Labs, where the future is made - today!"
Patch in your script below... It's untested but should work HTH --Gilles ----- Original Message ----- From: "Sir K" <k_hamzat@yahoo.com> To: <zope@zope.org> Sent: Tuesday, August 20, 2002 7:07 PM Subject: [Zope] python script error: pls help [SNIP]
tday=DateTime().toZone('GMT+1').strftime('%d%m%y') yday=(DateTime()-1).toZone('GMT+1').strftime('%d%m%y') for i in context.Zcat_New1_Dtml_doc():
# Should be correct (untested) id = i.getObject().getId()
if tday==id: return tday else: tday=yday return tday
tday=DateTime().toZone('GMT+1').strftime('%d%m%y') yday=(DateTime()-1).toZone('GMT+1').strftime('%d%m%y') for i in context.Zcat_New1_Dtml_doc(): # Should be correct (untested) id = i.getObject().getId() if tday==id: return tday else: tday=yday return tday
I tried it but no result. When it is obvious that tday=id, it refuses to return tday but follow the else part. Then I later tried without else part; tday=DateTime().toZone('GMT+1').strftime('%d%m%y') for i in context.Zcat_New1_Dtml_doc(): id = i.getObject().getId() if tday==id: return tday This is the error: Error Type: AttributeError Error Value: 'None' object has no attribute 'getId' Thanks. ===== Hamzat kamaldeen Ishola Dnet Systems Limited. 223 Ikorodu Road, Lagos. Nigeria. 234 1 7749381, 234 08033011305 --- If Mistake is an opportunity to see better, then it is not a problem but readiness to admit it. Sentimental decisions are not mistakes but failures !!! __________________________________________________ Do You Yahoo!? HotJobs - Search Thousands of New Jobs http://www.hotjobs.com
participants (4)
-
Casey Duncan -
Gilles Lenfant -
Paul Winkler -
Sir K