[Zope] How to identy a fieldname exist or not?
Terry
terry@taipeitimes.com
Tue, 29 Jan 2002 23:31:46 +0800
Thanks for you help, and sugusstion,
It's a long story. Actually I store my data on MySQL, and use a Python to
get the news from one table.
There are also some relative data stored in other table. ex: photos,
chars,relative links.
So I cut the article body to pieces, then place different item in properly
position along the article.
If one article. len(article) = 5000. and have 2 photos , 2 chars
Then the news article would build like
If I set each slice about 600 characters.
paragraph 1 .\ about 600 character
paragraph 2 /
photo1
paragraph 3
paragraph 4
paragraph 5
char 1
paragraph 6
paragraph 7
photo2
.........
......
So I have to render the different item.
Any way, Thanks a lot
Terry
----- Original Message -----
From: e-Musty <emusty@mailbox.hu>
To: Terry <terry@taipeitimes.com>; <zope@zope.org>
Sent: Tuesday, January 29, 2002 9:07 PM
Subject: RE: [Zope] How to identy a fieldname exist or not?
> ZSQL methods return with a list of records where fields corresponds to the
> column names you have defined in the SELECT query. What you have tried to
do
> is to acces the value of the user_id method, not to determine whether it
has
> or has not such an attribute.
>
> To workaround the problem staying in the way you started to go on, the
> simplest is to embed the last, "filed-existence-investigator" piece of
code
> in to a try block. If an AttributeError exception is thrown, you can be
sure
> no user_id attribute exists.
>
> try:
> if result:
> for i in result:
> if i.user_id:
> print "This table have fieldname named user_id"
> except (AttributeError):
> print "there's no such a field"
>
> If it would not work, check out the Python/Zope docus to find out the
exact
> name of the exception to be caught.
>
> By the way, in my opinion you should employ a Python database API to find
> out which tables have what fields or to have a ZSQL method submitting a
> query on some system tables holding info on another table.
>
> -----Original Message-----
> From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Terry
> Sent: 2002. január 29. 11:29
> To: zope@zope.org
> Subject: [Zope] How to identy a fieldname exist or not?
>
>
> Hello friends,
>
> I have a table1 in database. Have fieldnames like
> "book_id","bookname",table2 has "user_id","username"
>
> I use a Python Script call a ZSQL Method and get result from that ZSQL
> Method.
> There is not any fieldname like "phone".
> Why I couldn't check this in Python Script?
> Zope said this on my browser
> """
>
>
> Site Error
>
> An error was encountered while publishing this resource.
>
> *Error Type: AttributeError*
> *Error Value: user_id*
>
> """
>
> ###My Python Script
> result1 =some_ZSQL_Method_table1
> result2 =some_ZSQL_Method_table2
>
> result =[]
> for i in range(len(result1)):
> result.append(result1[i])
> if len(result2) >= i+1:
> result.append(result2[i])
> if result:
> for i in result:
> if i.user_id:
> print "This table have fieldname named user_id"
>
> return printed
> #################
>
> Any idea ?
>
> Terry
>
>
>
>
>
> _______________________________________________
> Zope maillist - Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> ** No cross posts or HTML encoding! **
> (Related lists -
> http://lists.zope.org/mailman/listinfo/zope-announce
> http://lists.zope.org/mailman/listinfo/zope-dev )
>
>
>
>
>
>