小编sso*_*ler的帖子

Python SQL查询字符串格式

我正在尝试找到格式化SQL查询字符串的最佳方法.当我调试我的应用程序时,我想记录所有sql查询字符串,并且正确格式化字符串很重要.

选项1

def myquery():
    sql = "select field1, field2, field3, field4 from table where condition1=1 and condition2=2"
    con = mymodule.get_connection()
    ...
Run Code Online (Sandbox Code Playgroud)
  • 这适用于打印sql字符串.
  • 如果字符串很长并且不符合80个字符的标准宽度,则不是一个好的解决方案.

选项2

def query():
    sql = """
        select field1, field2, field3, field4
        from table
        where condition1=1
        and condition2=2"""
    con = mymodule.get_connection()
    ...
Run Code Online (Sandbox Code Playgroud)
  • 这里的代码很清楚,但是当你打印sql查询字符串时,你会得到所有这些烦人的空白区域.

    从表\n _ ___ 选择field1,field2,field3,field4 \n_ _ ___ ,其中condition1 = 1 \n _ ___ _和 condition2 = 2'

注意:我已经用下划线替换了空格_,因为它们是由编辑器修剪的

选项3

def query():
    sql = """select field1, field2, field3, field4
from table …
Run Code Online (Sandbox Code Playgroud)

python sql string-formatting

79
推荐指数
6
解决办法
9万
查看次数

Python - 将元组列表转换为字符串

哪个是将元组列表转换为字符串的最pythonic方式?

我有:

[(1,2), (3,4)]
Run Code Online (Sandbox Code Playgroud)

而且我要:

"(1,2), (3,4)"
Run Code Online (Sandbox Code Playgroud)

我的解决方案是:

l=[(1,2),(3,4)]
s=""
for t in l:
    s += "(%s,%s)," % t
s = s[:-1]
Run Code Online (Sandbox Code Playgroud)

是否有更多的pythonic方式来做到这一点?

python tuples list string-formatting

17
推荐指数
3
解决办法
5万
查看次数

在Django网站上Python记录RotatingFileHandler的问题

我有一个django支持的网站,我使用标准的日志记录模块来跟踪网络活动.

该日志通过RotatingFileHandler完成,该配置有10个日志文件,每个文件1000000字节.日志系统可以工作,但这是我得到的日志文件:

-rw-r--r-- 1 apache      apache          83 Jul 23 13:30 hr.log
-rw-r--r-- 1 apache      apache      446276 Jul 23 13:03 hr.log.1
-rw-r--r-- 1 apache      apache      999910 Jul 23 06:00 hr.log.10
-rw-r--r-- 1 apache      apache         415 Jul 23 16:24 hr.log.2
-rw-r--r-- 1 apache      apache      479636 Jul 23 16:03 hr.log.3
-rw-r--r-- 1 apache      apache         710 Jul 23 15:30 hr.log.4
-rw-r--r-- 1 apache      apache      892179 Jul 23 15:03 hr.log.5
-rw-r--r-- 1 apache      apache         166 Jul 23 14:30 hr.log.6
-rw-r--r-- 1 apache      apache      890769 Jul …
Run Code Online (Sandbox Code Playgroud)

python django logging

11
推荐指数
3
解决办法
5831
查看次数

单核或多核Solr

我们计划部署Solr来搜索从通用CMS平台发布的多个站点.

每种语言将有单独的网站,其他语言将主要从英语翻译内容.

搜索要求包括 - 关键字突出显示,建议("你的意思是?"),停用词,分面.

我们正在评估使用单核与每种语言的多核Solr选项.这里推荐的方法是什么?

multilingual solr

4
推荐指数
1
解决办法
1848
查看次数

Solr:DIH用于多语言索引和多值字段?

我有一个MySQL表:

CREATE TABLE documents (
    id INT NOT NULL AUTO_INCREMENT,
    language_code CHAR(2),
    tags CHAR(30),
    text TEXT,
    PRIMARY KEY (id)
);
Run Code Online (Sandbox Code Playgroud)

我有2个关于Solr DIH的问题:

1)该langauge_code字段表示该字段所使用的语言text.根据语言,我想索引text不同的Solr字段.

# pseudo code

if langauge_code == "en":
    index "text" to Solr field "text_en"
elif langauge_code == "fr":
    index "text" to Solr field "text_fr"
elif langauge_code == "zh":
    index "text" to Solr field "text_zh"
...
Run Code Online (Sandbox Code Playgroud)

DIH可以处理这样的用例吗?如何配置它?

2)该tags字段需要索引到Solr multiValued字段.多个值存储在字符串中,以逗号分隔.例如,如果tags包含字符串"blue, green, yellow",然后我要编制索引的3个值"blue","green","yellow" …

multilingual solr dataimporthandler

2
推荐指数
1
解决办法
1269
查看次数