字符串和%符号失败 - 请帮助 [英] Strings and % sign fails - Help Please

查看:49
本文介绍了字符串和%符号失败 - 请帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我也在Django Users组中发布了这个,但认为它可能与python组更相关




这似乎是一个怪胎问题我。我花了很长时间来跟踪

问题,这里是:


以下语句失败,因为它有'%''符号它。

cursor.execute(" select''%''")


错误是:IndexError:列表索引超出范围


如何解决这个问题?


请注意以下工作就好了:

cursor.execute( " select''x''")


以下内容也会因同样的错误而失败:

cursor.execute(""" ;选择''%''""")

cursor.execute(" select''\%''")


astr =" select''\%''"

cursor.execute(astr)


我非常感谢所有帮助,

问候,

Sia

I also posted this in Django Users group, but figured it probably has
more relevance for python group.

It seems like a freak problem to me. I spent a long hour to track the
problem down and here it is:

The following statement fails because it has the ''%'' sign in it.
cursor.execute("select ''%''")

The error is: IndexError: list index out of range

How do I address this problem?

Please note that the following work just fine:
cursor.execute("select ''x''")

and the following also fails with the same error:
cursor.execute("""select ''%''""")
cursor.execute("select ''\%''")

astr = "select ''\%''"
cursor.execute(astr)

I greatly appreciate all helps,
Regards,
Sia

推荐答案

si ********* @ gmail.com 令状es:
si*********@gmail.com writes:
以下语句失败,因为它中有'%''符号。
cursor.execute(" select''%''")

错误是:IndexError:列表索引超出范围

如何解决这个问题?
The following statement fails because it has the ''%'' sign in it.
cursor.execute("select ''%''")

The error is: IndexError: list index out of range

How do I address this problem?




使用%%。

-

Jorge Godoy< go *** @ ieee.org>


Quidquid latine dictum sit,altum sonatur。

- Qualquer coisa dita em latim soa profundo。

- 用拉丁语说的任何东西听起来很聪明。



Use "%%".
--
Jorge Godoy <go***@ieee.org>

"Quidquid latine dictum sit, altum sonatur."
- Qualquer coisa dita em latim soa profundo.
- Anything said in Latin sounds smart.


呵呵..除了我使用的是psycopg.Binary(somebinarystructure),

之外它我的工作原理并不是真的只是添加额外的% ,并且

psycopg.Binary不会这样做。我想这是psycopg

包的错误。有什么快速的方法可以从怪异的%问题中投射出一个字符串吗?


谢谢,

Sia

Jorge Godoy写道:
heh.. It works except I am using psycopg.Binary(somebinarystructure),
and I am not really doing it by hand to just add the extra %, and
psycopg.Binary doesn''t do it. I''d imagine it''s a bug with psycopg
package. Any quick way to project a string from freak ''%'' problems?

Thanks,
Sia
Jorge Godoy wrote:
si*********@gmail.com 写道:
si*********@gmail.com writes:
以下语句失败,因为它中有'%''符号。
cursor.execute(" select''%''")

错误是:IndexError:列表索引超出范围

如何解决此问题?
The following statement fails because it has the ''%'' sign in it.
cursor.execute("select ''%''")

The error is: IndexError: list index out of range

How do I address this problem?



使用"% %"

-
Jorge Godoy< go *** @ ieee.org>

Quidquid latine dictum sit,altum sonatur。 ;
- Qualquer coisa dita em latim soa profundo。
- 用拉丁语说的任何东西听起来很聪明。



Use "%%".
--
Jorge Godoy <go***@ieee.org>

"Quidquid latine dictum sit, altum sonatur."
- Qualquer coisa dita em latim soa profundo.
- Anything said in Latin sounds smart.






< a href =mailto:si ********* @ gmail.com> si ********* @ gmail.com 写道:
si*********@gmail.com writes:
嘿..除了我使用的是psycopg.Binar之外它还可以y(somebinarystructure),
我并不是真的只是手工添加额外的%,而且
psycopg.Binary不会这样做。我想这是psycopg
包的错误。从错误的''%''问题中投射字符串的任何快速方法?
heh.. It works except I am using psycopg.Binary(somebinarystructure),
and I am not really doing it by hand to just add the extra %, and
psycopg.Binary doesn''t do it. I''d imagine it''s a bug with psycopg
package. Any quick way to project a string from freak ''%'' problems?




尝试使用r" string''%''" ...


-

Jorge Godoy< go *** @ ieee.org>


" Quidquid latine dictum sit ,altum sonatur。

- Qualquer coisa dita em latim soa profundo。

- 用拉丁语说的任何东西听起来很聪明。



Try using r"string ''%''"...

--
Jorge Godoy <go***@ieee.org>

"Quidquid latine dictum sit, altum sonatur."
- Qualquer coisa dita em latim soa profundo.
- Anything said in Latin sounds smart.

这篇关于字符串和%符号失败 - 请帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆