2007年07月11日 星期三 17:11
×Ö·û´®ÖеıäÁ¿Ìæ»» PHP 4 Ìí¼ÓÁËÒ»¸öеĻúÖÆÒÔÌæ»»×Ö·û´®ÖеıäÁ¿¡£ÄúÏÖÔÚ¿ÉÒÔ·ÃÎÊ×Ö·û´®ÖеĶÔÏó³ÉÔ±±äÁ¿ºÍ¶àάÊý×éÔªËØ¡£ Èç¹ûÄúÏëÕâô×ö£¬ÄúÐèҪʹÓôóÀ¨ºÅ½«Ò»¸öÃÀÔª·ûºÅºÍ±äÁ¿ÃûÀ¨ÆðÀ´£¬¾ÍÏñÕâÑù£º{$...}¡£ ÒªÔÚ×Ö·û´®ÖÐǶÈë¶ÔÏó³ÉÔ±±äÁ¿£¬Ö»Òª¼òµ¥µÄд "text {$obj->member} text"¡£¶øÔÚ PHP 3 ÖУ¬ÄúµÃʹÓà "text ".$obj->member." text"¡£ Õâ¸ö¸Ä½ø¿ÉÒÔʹ´úÂë¸üÒ׶Á£¬µ«Õâ¿ÉÄÜ»áÆÆ»µÓà PHP 3 дµÄ´úÂë¡£µ«ÊÇÄúºÜÈÝÒ×ÐÞÕýËü£ºÔÚ´úÂëÖвéÕÒ×Ö·û´®ÖÐµÄ {$£¬Ê¹ÓÃËÑË÷Ìæ»»¹¤¾ß½«ËüÌ滻Ϊ \{$¡£ ÉÏÃæÊÇphpµÄ·½Ê½¡£ -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20070711/dff2369b/attachment.htm
2007年07月11日 星期三 17:26
Ruby Sucks, PEP292 says. 在 07-7-11,longlong<asfnuts在gmail.com> 写道: > 字符串中的变量替换 > > PHP 4 添加了一个新的机制以替换字符串中的变量。您现在可以访问字符串中的对象成员变量和多维数组元素。 > > 如果您想这么做,您需要使用大括号将一个美元符号和变量名括起来,就像这样:{$...}。 > > 要在字符串中嵌入对象成员变量,只要简单的写 "text {$obj->member} text"。而在 PHP 3 中,您得使用 "text > ".$obj->member." text"。 > > 这个改进可以使代码更易读,但这可能会破坏用 PHP 3 写的代码。但是您很容易修正它:在代码中查找字符串中的 {$,使用搜索替换工具将它替换为 > \{$。 > > > > > 上面是php的方式。 > > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to > python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to > python-chinese-request在lists.python.cn > Detail Info: > http://python.cn/mailman/listinfo/python-chinese > 匿名学习 Python 中 ...
2007年07月13日 星期五 14:48
ÊDz»ÊÇ print 'hello, %s' % person.name Õâ¸öÑù×Ó£¿ On 7/11/07, ÉòáË <wileishn在gmail.com> wrote: > > Ruby Sucks, PEP292 says. > > ÔÚ 07-7-11£¬longlong<asfnuts在gmail.com> дµÀ£º > > ×Ö·û´®ÖеıäÁ¿Ìæ»» > > > > PHP 4 Ìí¼ÓÁËÒ»¸öеĻúÖÆÒÔÌæ»»×Ö·û´®ÖеıäÁ¿¡£ÄúÏÖÔÚ¿ÉÒÔ·ÃÎÊ×Ö·û´®ÖеĶÔÏó³ÉÔ±±äÁ¿ºÍ¶àάÊý×éÔªËØ¡£ > > > > Èç¹ûÄúÏëÕâô×ö£¬ÄúÐèҪʹÓôóÀ¨ºÅ½«Ò»¸öÃÀÔª·ûºÅºÍ±äÁ¿ÃûÀ¨ÆðÀ´£¬¾ÍÏñÕâÑù£º{$...}¡£ > > > > ÒªÔÚ×Ö·û´®ÖÐǶÈë¶ÔÏó³ÉÔ±±äÁ¿£¬Ö»Òª¼òµ¥µÄд "text {$obj->member} text"¡£¶øÔÚ PHP 3 ÖУ¬ÄúµÃʹÓà "text > > ".$obj->member." text"¡£ > > > > Õâ¸ö¸Ä½ø¿ÉÒÔʹ´úÂë¸üÒ׶Á£¬µ«Õâ¿ÉÄÜ»áÆÆ»µÓà PHP 3 дµÄ´úÂë¡£µ«ÊÇÄúºÜÈÝÒ×ÐÞÕýËü£ºÔÚ´úÂëÖвéÕÒ×Ö·û´®ÖÐµÄ {$£¬Ê¹ÓÃËÑË÷Ìæ»»¹¤¾ß½«ËüÌ滻Ϊ > > \{$¡£ > > > > > > > > > > ÉÏÃæÊÇphpµÄ·½Ê½¡£ > > > > _______________________________________________ > > python-chinese > > Post: send python-chinese在lists.python.cn > > Subscribe: send subscribe to > > python-chinese-request在lists.python.cn > > Unsubscribe: send unsubscribe to > > python-chinese-request在lists.python.cn > > Detail Info: > > http://python.cn/mailman/listinfo/python-chinese > > > > ÄäÃûѧϰ Python ÖÐ ... > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese -- Zhang Xiao Engineer, Web development Ethos Tech. http://www.ethos.com.cn -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20070713/1c09b6b3/attachment.html
2007年07月13日 星期五 14:59
ÓÐʱÔÚpythonÒªÖ´ÐÐsqlÓï¾ä£¬²ÎÊýÀàÐÍÊÇ×Ö·û´®£¬ÎÒÏëÔÚÕâ¸ö×Ö·û´®ÖмÓÈë±äÁ¿£¬Ôõô×ö£¿ ÔÚ07-7-13£¬Xell Zhang <xellzhang在gmail.com> дµÀ£º > > ÊDz»ÊÇ > print 'hello, %s' % person.name > Õâ¸öÑù×Ó£¿ > > On 7/11/07, ÉòáË <wileishn在gmail.com > wrote: > > > > Ruby Sucks, PEP292 says. > > > > ÔÚ 07-7-11£¬longlong< asfnuts在gmail.com> дµÀ£º > > > ×Ö·û´®ÖеıäÁ¿Ìæ»» > > > > > > PHP 4 Ìí¼ÓÁËÒ»¸öеĻúÖÆÒÔÌæ»»×Ö·û´®ÖеıäÁ¿¡£ÄúÏÖÔÚ¿ÉÒÔ·ÃÎÊ×Ö·û´®ÖеĶÔÏó³ÉÔ±±äÁ¿ºÍ¶àάÊý×éÔªËØ¡£ > > > > > > Èç¹ûÄúÏëÕâô×ö£¬ÄúÐèҪʹÓôóÀ¨ºÅ½«Ò»¸öÃÀÔª·ûºÅºÍ±äÁ¿ÃûÀ¨ÆðÀ´£¬¾ÍÏñÕâÑù£º{$...}¡£ > > > > > > ÒªÔÚ×Ö·û´®ÖÐǶÈë¶ÔÏó³ÉÔ±±äÁ¿£¬Ö»Òª¼òµ¥µÄд "text {$obj->member} text"¡£¶øÔÚ PHP 3 ÖУ¬ÄúµÃʹÓà > > "text > > > ".$obj->member." text"¡£ > > > > > > Õâ¸ö¸Ä½ø¿ÉÒÔʹ´úÂë¸üÒ׶Á£¬µ«Õâ¿ÉÄÜ»áÆÆ»µÓà PHP 3 дµÄ´úÂë¡£µ«ÊÇÄúºÜÈÝÒ×ÐÞÕýËü£ºÔÚ´úÂëÖвéÕÒ×Ö·û´®ÖÐµÄ > > {$£¬Ê¹ÓÃËÑË÷Ìæ»»¹¤¾ß½«ËüÌ滻Ϊ > > > \{$¡£ > > > > > > > > > > > > > > > ÉÏÃæÊÇphpµÄ·½Ê½¡£ > > > > > > _______________________________________________ > > > python-chinese > > > Post: send python-chinese在lists.python.cn > > > Subscribe: send subscribe to > > > python-chinese-request在lists.python.cn > > > Unsubscribe: send unsubscribe to > > > python-chinese-request在lists.python.cn > > > Detail Info: > > > http://python.cn/mailman/listinfo/python-chinese > > > > > > > ÄäÃûѧϰ Python ÖÐ ... > > _______________________________________________ > > python-chinese > > Post: send python-chinese在lists.python.cn > > Subscribe: send subscribe to python-chinese-request在lists.python.cn > > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > > > > -- > Zhang Xiao > > Engineer, Web development > > Ethos Tech. > http://www.ethos.com.cn > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20070713/7b10bd99/attachment.htm
2007年07月13日 星期五 15:31
ÎÒ×Ô¼º·â×°ÁËÒ»¸öÀàÓÃÀ´´¦Àísql¡£ class MySQLConnector: ''' MySQLConnector holds a connection with a MySQL database MySQLConnector instance creates a connection by using parameters passed. The connection will be hold by this instance. When a sql is run this instance will generate a cursor and use it to query. After query cursor will be closed.''' def __init__(self, host, port, user, passwd, db): self.con = MySQLdb.connect( host = host, port = port, user = user, passwd = passwd, db = db ) self.lock = threading.Lock () def query(self, sql, args = ()): self.lock.acquire() cursor = self.con.cursor() cursor.execute(sql, args) result = cursor.fetchall() cursor.execute ('commit') cursor.close() self.lock.release() return result ¿ÉÒÔÕâÑùʹÓ㺠dbCon = MySQLConnector('yourhost', 3306, 'username', 'passwd', 'dbname') dbCon.query('SELECT * FROM user WHERE username = %s', ('xzhang')) dbCon.query('INSERT INTO user (username, age) VALUES (%s, %s)', ('xzhang', 23)) ÎÒ¸Õ¿ªÊ¼Ñ§Ï°£¬²»ÖªµÀÎÒµÄ×ö·¨ÊÇ·ñºÃ¡£ÐèҪעÒâµÄÊDz»¹ÜÄã´«ÈëµÄÊý¾ÝÊÇʲôÀàÐÍ£¬¶¼ÓÃ%s¡£ On 7/13/07, longlong <asfnuts在gmail.com> wrote: > > ÓÐʱÔÚpythonÒªÖ´ÐÐsqlÓï¾ä£¬²ÎÊýÀàÐÍÊÇ×Ö·û´®£¬ÎÒÏëÔÚÕâ¸ö×Ö·û´®ÖмÓÈë±äÁ¿£¬Ôõô×ö£¿ > ÔÚ07-7-13£¬Xell Zhang <xellzhang在gmail.com> дµÀ£º > > > > ÊDz»ÊÇ > > print 'hello, %s' % person.name > > Õâ¸öÑù×Ó£¿ > > > > On 7/11/07, ÉòáË <wileishn在gmail.com > wrote: > > > > > > Ruby Sucks, PEP292 says. > > > > > > ÔÚ 07-7-11£¬longlong< asfnuts在gmail.com> дµÀ£º > > > > ×Ö·û´®ÖеıäÁ¿Ìæ»» > > > > > > > > PHP 4 Ìí¼ÓÁËÒ»¸öеĻúÖÆÒÔÌæ»»×Ö·û´®ÖеıäÁ¿¡£ÄúÏÖÔÚ¿ÉÒÔ·ÃÎÊ×Ö·û´®ÖеĶÔÏó³ÉÔ±±äÁ¿ºÍ¶àάÊý×éÔªËØ¡£ > > > > > > > > Èç¹ûÄúÏëÕâô×ö£¬ÄúÐèҪʹÓôóÀ¨ºÅ½«Ò»¸öÃÀÔª·ûºÅºÍ±äÁ¿ÃûÀ¨ÆðÀ´£¬¾ÍÏñÕâÑù£º{$...}¡£ > > > > > > > > ÒªÔÚ×Ö·û´®ÖÐǶÈë¶ÔÏó³ÉÔ±±äÁ¿£¬Ö»Òª¼òµ¥µÄд "text {$obj->member} text"¡£¶øÔÚ PHP 3 ÖУ¬ÄúµÃʹÓà > > > "text > > > > ".$obj->member." text"¡£ > > > > > > > > Õâ¸ö¸Ä½ø¿ÉÒÔʹ´úÂë¸üÒ׶Á£¬µ«Õâ¿ÉÄÜ»áÆÆ»µÓà PHP 3 дµÄ´úÂë¡£µ«ÊÇÄúºÜÈÝÒ×ÐÞÕýËü£ºÔÚ´úÂëÖвéÕÒ×Ö·û´®ÖÐµÄ > > > {$£¬Ê¹ÓÃËÑË÷Ìæ»»¹¤¾ß½«ËüÌ滻Ϊ > > > > \{$¡£ > > > > > > > > > > > > > > > > > > > > ÉÏÃæÊÇphpµÄ·½Ê½¡£ > > > > > > > > _______________________________________________ > > > > python-chinese > > > > Post: send python-chinese在lists.python.cn > > > > Subscribe: send subscribe to > > > > python-chinese-request在lists.python.cn > > > > Unsubscribe: send unsubscribe to > > > > python-chinese-request在lists.python.cn > > > > Detail Info: > > > > http://python.cn/mailman/listinfo/python-chinese > > > > > > > > > > ÄäÃûѧϰ Python ÖÐ ... > > > _______________________________________________ > > > python-chinese > > > Post: send python-chinese在lists.python.cn > > > Subscribe: send subscribe to python-chinese-request在lists.python.cn > > > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > > > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > > > > > > > > > -- > > Zhang Xiao > > > > Engineer, Web development > > > > Ethos Tech. > > http://www.ethos.com.cn > > _______________________________________________ > > python-chinese > > Post: send python-chinese在lists.python.cn > > Subscribe: send subscribe to python-chinese-request在lists.python.cn > > Unsubscribe: send unsubscribe to > > python-chinese-request在lists.python.cn > > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > > > > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > -- Zhang Xiao Engineer, Web development Ethos Tech. http://www.ethos.com.cn -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20070713/8c5af5aa/attachment.html
2007年07月13日 星期五 16:10
ѧϰÁË ÔÚ07-7-13£¬Xell Zhang <xellzhang在gmail.com> дµÀ£º > > ÎÒ×Ô¼º·â×°ÁËÒ»¸öÀàÓÃÀ´´¦Àísql¡£ > class MySQLConnector: > ''' MySQLConnector holds a connection with a MySQL database > > MySQLConnector instance creates a connection by using > parameters passed. The connection will be hold by this > instance. When a sql is run this instance will generate > a cursor and use it to query. After query cursor will > be closed.''' > > def __init__(self, host, port, user, passwd, db): > self.con = MySQLdb.connect( > host = host, > port = port, > user = user, > passwd = passwd, > db = db > ) > self.lock = threading.Lock () > > def query(self, sql, args = ()): > self.lock.acquire() > cursor = self.con.cursor() > cursor.execute(sql, args) > result = cursor.fetchall() > cursor.execute ('commit') > cursor.close() > self.lock.release() > return result > > ¿ÉÒÔÕâÑùʹÓ㺠> dbCon = MySQLConnector('yourhost', 3306, 'username', 'passwd', 'dbname') > dbCon.query('SELECT * FROM user WHERE username = %s', ('xzhang')) > dbCon.query('INSERT INTO user (username, age) VALUES (%s, %s)', ('xzhang', > 23)) > > ÎÒ¸Õ¿ªÊ¼Ñ§Ï°£¬²»ÖªµÀÎÒµÄ×ö·¨ÊÇ·ñºÃ¡£ÐèҪעÒâµÄÊDz»¹ÜÄã´«ÈëµÄÊý¾ÝÊÇʲôÀàÐÍ£¬¶¼ÓÃ%s¡£ > > On 7/13/07, longlong <asfnuts在gmail.com> wrote: > > > > ÓÐʱÔÚpythonÒªÖ´ÐÐsqlÓï¾ä£¬²ÎÊýÀàÐÍÊÇ×Ö·û´®£¬ÎÒÏëÔÚÕâ¸ö×Ö·û´®ÖмÓÈë±äÁ¿£¬Ôõô×ö£¿ > > ÔÚ07-7-13£¬Xell Zhang <xellzhang在gmail.com> дµÀ£º > > > > > > ÊDz»ÊÇ > > > print 'hello, %s' % person.name > > > Õâ¸öÑù×Ó£¿ > > > > > > On 7/11/07, ÉòáË <wileishn在gmail.com > wrote: > > > > > > > > Ruby Sucks, PEP292 says. > > > > > > > > ÔÚ 07-7-11£¬longlong< asfnuts在gmail.com> дµÀ£º > > > > > ×Ö·û´®ÖеıäÁ¿Ìæ»» > > > > > > > > > > PHP 4 Ìí¼ÓÁËÒ»¸öеĻúÖÆÒÔÌæ»»×Ö·û´®ÖеıäÁ¿¡£ÄúÏÖÔÚ¿ÉÒÔ·ÃÎÊ×Ö·û´®ÖеĶÔÏó³ÉÔ±±äÁ¿ºÍ¶àάÊý×éÔªËØ¡£ > > > > > > > > > > Èç¹ûÄúÏëÕâô×ö£¬ÄúÐèҪʹÓôóÀ¨ºÅ½«Ò»¸öÃÀÔª·ûºÅºÍ±äÁ¿ÃûÀ¨ÆðÀ´£¬¾ÍÏñÕâÑù£º{$...}¡£ > > > > > > > > > > ÒªÔÚ×Ö·û´®ÖÐǶÈë¶ÔÏó³ÉÔ±±äÁ¿£¬Ö»Òª¼òµ¥µÄд "text {$obj->member} text"¡£¶øÔÚ PHP 3 ÖУ¬ÄúµÃʹÓà > > > > "text > > > > > ".$obj->member." text"¡£ > > > > > > > > > > Õâ¸ö¸Ä½ø¿ÉÒÔʹ´úÂë¸üÒ׶Á£¬µ«Õâ¿ÉÄÜ»áÆÆ»µÓà PHP 3 дµÄ´úÂë¡£µ«ÊÇÄúºÜÈÝÒ×ÐÞÕýËü£ºÔÚ´úÂëÖвéÕÒ×Ö·û´®ÖÐµÄ > > > > {$£¬Ê¹ÓÃËÑË÷Ìæ»»¹¤¾ß½«ËüÌ滻Ϊ > > > > > \{$¡£ > > > > > > > > > > > > > > > > > > > > > > > > > ÉÏÃæÊÇphpµÄ·½Ê½¡£ > > > > > > > > > > _______________________________________________ > > > > > python-chinese > > > > > Post: send python-chinese在lists.python.cn > > > > > Subscribe: send subscribe to > > > > > python-chinese-request在lists.python.cn > > > > > Unsubscribe: send unsubscribe to > > > > > python-chinese-request在lists.python.cn > > > > > Detail Info: > > > > > http://python.cn/mailman/listinfo/python-chinese > > > > > > > > > > > > > ÄäÃûѧϰ Python ÖÐ ... > > > > _______________________________________________ > > > > python-chinese > > > > Post: send python-chinese在lists.python.cn > > > > Subscribe: send subscribe to python-chinese-request在lists.python.cn > > > > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > > > > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > > > > > > > > > > > > > > -- > > > Zhang Xiao > > > > > > Engineer, Web development > > > > > > Ethos Tech. > > > http://www.ethos.com.cn > > > _______________________________________________ > > > python-chinese > > > Post: send python-chinese在lists.python.cn > > > Subscribe: send subscribe to python-chinese-request在lists.python.cn > > > Unsubscribe: send unsubscribe to > > > python-chinese-request在lists.python.cn > > > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > > > > > > > > _______________________________________________ > > python-chinese > > Post: send python-chinese在lists.python.cn > > Subscribe: send subscribe to python-chinese-request在lists.python.cn > > Unsubscribe: send unsubscribe to > > python-chinese-request在lists.python.cn > > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > > > > > -- > Zhang Xiao > > Engineer, Web development > > Ethos Tech. > http://www.ethos.com.cn > > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20070713/5229679a/attachment.htm
2007年07月16日 星期一 14:41
On 7/13/07, Xell Zhang <xellzhang在gmail.com> wrote: > 我自己封装了一个类用来处理sql。 > class MySQLConnector: > ''' MySQLConnector holds a connection with a MySQL database > > MySQLConnector instance creates a connection by using > parameters passed. The connection will be hold by this > instance. When a sql is run this instance will generate > a cursor and use it to query. After query cursor will > be closed.''' > > def __init__(self, host, port, user, passwd, db): > self.con = MySQLdb.connect( > host = host, > port = port, > user = user, > passwd = passwd, > db = db > ) > self.lock = threading.Lock () > > def query(self, sql, args = ()): > self.lock.acquire() > cursor = self.con.cursor() > cursor.execute(sql, args) > result = cursor.fetchall() > cursor.execute ('commit') > cursor.close() > self.lock.release() > return result > > 可以这样使用: > dbCon = MySQLConnector('yourhost', 3306, 'username', 'passwd', 'dbname') > dbCon.query('SELECT * FROM user WHERE username = %s', ('xzhang')) > dbCon.query('INSERT INTO user (username, age) VALUES (%s, %s)', ('xzhang', > 23)) > > 我刚开始学习,不知道我的做法是否好。需要注意的是不管你传入的数据是什么类型,都用%s。 > 这样搞很容易被注入吧? -- Best Regards, Leo Jay
2007年07月16日 星期一 17:45
Èç¹ûÊÇÕâÑù×Óд cursor.execute(sql, args) ÊDz»»á×¢ÈëµÄ£¬Ëü»á×Ô¶¯°ÑargsÖÐתÒåµô -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20070716/9f1729ec/attachment.htm
Zeuux © 2025
京ICP备05028076号