我正在使用Cython完成我的第一步,并且已根据wiki中的说明将其安装在我的机器上.
通过Cython教程我得到了pyximport,它应该让cython编译变得非常简单.但是,当我尝试使用它时,我收到以下错误消息(重新格式化):
ImportError: Building module failed:
DistutilsPlatformError('
Python was built with Visual Studio 2003;
extensions must be built with a compiler than can generate compatible binaries.
Visual Studio 2003 was not found on this system. If you have Cygwin installed,
you can try compiling with MingW32, by passing "-c mingw32" to setup.py.',)
Run Code Online (Sandbox Code Playgroud)
所以我的问题是:有谁知道让pyximport使用mingw的方法?
请注意,mingw似乎安装得很好,制作Cython模块(使用setup.py)的好方法对我来说很有用,而且我甚至创建了distutils.cfg像wiki这样的文件告诉我.
Spring Framework有两个类似的类:JdbcTemplate是旧的Java 1.4类,而SimpleJdbcTemplate是更新的,具有更好的方法.
JdbcTemplate有一个方法setQueryTimeout,它基本上允许我访问基础Statement对象上具有相同名称的方法.
有没有办法用SimpleJdbcTemplate做类似的事情?
解决方案:根据skaffman的回答,我SimpleJdbcTemplate自己创建了一个对象JdbcTemplate,所以现在我可以做任何我想做的事.码:
JdbcTemplate jdbcTemplate = this.getJdbcTemplate();
jdbcTemplate.setQueryTimeout(30);
SimpleJdbcTemplate simpleJdbcTemplate = new SimpleJdbcTemplate(jdbcTemplate);
Run Code Online (Sandbox Code Playgroud)
有点满口,但完成工作.
更新:这确实比必要的更复杂.看到答案.
这是我的表格:
CREATE TABLE `person` (
`id` bigint(10) NOT NULL AUTO_INCREMENT,
`name` varchar(20) DEFAULT NULL,
`age` int(10) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `age` (`age`)
) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=latin1;
Run Code Online (Sandbox Code Playgroud)
这是解释的输出:
mysql> explain select * from person order by age\G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: person
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 10367
Extra: Using filesort
1 row in set (0.00 sec)
Run Code Online (Sandbox Code Playgroud)
这是怎么回事?为什么MySQL不使用age索引进行排序?我试过了analyze table,但它没有任何区别.
仅供参考,这是表中数据的分布:
mysql> …Run Code Online (Sandbox Code Playgroud) 我想找到满足某些条件C(m)的最高值m = a*b,其中
1 <= a <= b <= 1,000,000.
Run Code Online (Sandbox Code Playgroud)
为了做到这一点,我想以a*b的降序迭代所有a,b对.
例如,对于最多5的值,订单将为:
5 x 5 = 25
4 x 5 = 20
4 x 4 = 16
3 x 5 = 15
3 x 4 = 12
2 x 5 = 10
3 x 3 = 9
2 x 4 = 8
2 x 3 = 6
1 x 5 = 5
1 x 4 = 4
2 x 2 = 4
1 x 3 = 3
1 x 2 …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用基于PEG的Python解析器生成器tatsu编写一个简单的int表达式解析器.这是我的代码:
import tatsu
grammar = r'''
start = expression $ ;
expression = add | sub | term ;
add = expression '+' term ;
sub = expression '-' term ;
term = mul | div | number ;
mul = term '*' number ;
div = term '/' number ;
number = [ '-' ] /\d+/ ;
'''
parser = tatsu.compile(grammar)
print(parser.parse('2-1'))
Run Code Online (Sandbox Code Playgroud)
该程序的输出['-', '1']不是预期的['2', '-', '1'].
如果我要么得到正确的输出:
number = /\d+/ ;说我写这个:
from subprocessing import Popen, STDOUT, PIPE
p = Popen(["myproc"], stderr=STDOUT, stdout=PIPE)
Run Code Online (Sandbox Code Playgroud)
现在,如果我这样做
line = p.stdout.readline()
Run Code Online (Sandbox Code Playgroud)
我的程序一直等到子进程输出下一行.
有没有什么魔法可以p.stdout让我可以读取输出,如果它在那里,但只是继续吗?我正在寻找类似的东西Queue.get_nowait()
我知道我可以创建一个读取线程p.stdout,但我们假设我无法创建新线程.
我正在使用一个实用程序(unison,但这不是重点)接受如下参数:
$ unison -path path1 -path path2 -path path3
Run Code Online (Sandbox Code Playgroud)
我想写一个我可以这样运行的sh脚本:
$ myscript path1 path2 path3
Run Code Online (Sandbox Code Playgroud)
我希望有一个符合Posix标准的解决方案,但特定于bash也会很好.
我猜它应该是这样的:
#!/bin/sh
unison ${*/ / -path }
Run Code Online (Sandbox Code Playgroud)
但这不起作用.
编辑:好的,我想我得到了一些东西:
#!/bin/bash
PARAMS=
for arg in "$@"
do
PARAMS+=" -path '$arg'"
done
unison $PARAMS
Run Code Online (Sandbox Code Playgroud)
问题是这只适用于bash,我很确定有更好的方法来引用参数.
我正在使用Play Framework,将Hibernate作为JPA提供程序,我注意到如果一个实体有一个Blob成员,它总会被刷新到DB,即使我没有更改任何内容,即使我不要阅读Blob的价值.
Blob是Play中定义的UserType.这是源代码.该类的基本思想是将实际数据保存在文件系统中,并仅在DB表中保存指针(UUID).
从这个SO答案中,我认为Blob代码中的某些内容必须在从DB加载的时间和Hibernate检查它的时间之间进行更改.还有这个答案表明它可能是别的东西.
如果不进行更改,如何更改Blob类以避免数据库刷新?
GreyBeardedGeek的回答证明是正确的.当前equals实现仅在具有相同标识的对象上返回true,并且始终在null上返回false.
改变这个:
public boolean equals(Object o, Object o1) throws HibernateException {
return o == null ? false : o.equals(o1);
}
Run Code Online (Sandbox Code Playgroud)
对此:
private static boolean equal(Object a, Object b) {
return a == b || (a != null && a.equals(b));
}
public boolean equals(Object a, Object b) throws HibernateException {
if(a instanceof Blob && b instanceof Blob) {
return equal(((Blob)a).UUID, ((Blob)b).UUID) &&
equal(((Blob)a).type, ((Blob)b).type);
}
return equal(a, b);
}
Run Code Online (Sandbox Code Playgroud)
使得所有过多的DB更新都消失了.
在 bash 脚本中,我可以编写:
exec 2>&1
exec someprog
Run Code Online (Sandbox Code Playgroud)
并且 stderr 输出someprog将被重定向到 stdout。
有没有办法使用 python 的os.exec*函数来做类似的事情?
这不必是可移植的,只需在 Linux 上工作即可。
我现在有一个问题,这个是关于 lucene 的。我试图制作一个 lucene 源代码,它可以进行索引并首先使用 RAMDirectory 将它们存储在内存中,然后使用 FSDirectory 将内存中的索引刷新到磁盘中。我对这段代码做了一些修改,但没有效果。也许你们中的一些人可以帮助我一点。
那么,在将 RAMDirectory 放入 FSDirectory 之前,将 RAMDirectory 集成到此源代码中的最佳方法是什么?尽管这里是源代码,但任何帮助将不胜感激。
import org.apache.lucene.analysis.SimpleAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.store.FSDirectory;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
public class SimpleFileIndexer {
public static void main(String[] args) throws Exception {
File indexDir = new File("C:/Users/Raden/Documents/lucene/LuceneHibernate/adi");
File dataDir = new File("C:/Users/Raden/Documents/lucene/LuceneHibernate/adi");
String suffix = "txt";
SimpleFileIndexer indexer = new SimpleFileIndexer();
int numIndex = indexer.index(indexDir, dataDir, suffix);
System.out.println("Total files indexed " + numIndex);
}
private int index(File indexDir, …Run Code Online (Sandbox Code Playgroud)