There is no methods or functions to check the attribute of result from ZSQL ?_? Right?
Hello friends, It had spend days on Google, Zope Site, and ask question on the list (Many thanks to people on the list) ? But It's infructuous.(I came from Perl,PHP , the origin web script langage background, I try to enjoy the fun you guys already had.) I just hope to solve a easy question. I really couldn't find any method or function in Python Script to check a attribute exist or not. I couldn't just simply to ckeck the attribute in Python Script. if test(result_object_from_ZSQL[0].ph_id): if result_object_from_ZSQL[0].ph_id: #My Python Script########### results=script.sql_Get_News(ar_id=ar_id,ar_publish='Y') # get article from MySQL photo=script.sql_Photo(ar_id=ar_id) # get photo's datd from MySQL pull=script.sql_Pull(ar_id=ar_id) # get pull box=script.sql_Box(ar_id=ar_id) # get box print results.names(),'<p>' print photo.names(),'<p>' print pull.names(),'<p>' print box.names(),'<p>' ############################## I mix photo , pull , and box to one list, temp_glue[]. then I would process the temp_glue[] , so I have to knew each item originally came from which table. So I use the following lins to check. ####### Check each item for i in range(len(temp_glue)): if temp_glue[i].ph_id: print "This item came from Photo Table" if temp_glue[i].pl_id: print "This item came from Pull Table" if temp_glue[i].bx_id: print "This item came from Box Table" ###################### Terry
I just hope to solve a easy question. I really couldn't find any method or function in Python Script to check a attribute exist or not. I couldn't just simply to ckeck the attribute in Python Script.
There is a hasattr somewhere. But I cannot remember from the top of my head how it's called from a Python script. But one of the following should work ;-) _.hasattr(obj, 'attr') context.hasattr(obj, 'attr') context._.hasattr(obj, 'attr') regards Max M Terry wrote:
Thanks a lot , Max I try this. ############### if hasattr(item,'some_fieldname_dont_exist'): print "I got some_fieldname_dont_exis t" ################### And no Attribute error. Thanks a lot , Max Terry Max M wrote:
I just hope to solve a easy question. I really couldn't find any method or function in Python Script to check a attribute exist or not. I couldn't just simply to ckeck the attribute in Python Script.
There is a hasattr somewhere. But I cannot remember from the top of my head how it's called from a Python script.
But one of the following should work ;-)
_.hasattr(obj, 'attr') context.hasattr(obj, 'attr') context._.hasattr(obj, 'attr')
regards Max M
Terry wrote:
participants (2)
-
Max M -
Terry