How to make pylint a part of setup.py test process?

I'm trying to add pylint checking of all .py files to the test process of setuptools (maybe I'm doing something wrong, please correct me). This is what I'm doing in setup.py : class MyTest(test): def run_tests(self): import pytest import pylint if (pylint.run_pylint()): sys.exit(-1) if (pytest.main(self.test_args)): sys.exit(-1) setup( tests_requi

如何使pylint成为setup.py测试过程的一部分?

我试图将所有.py文件的pylint检查添加到pylint的test过程中(也许我做错了什么,请纠正我)。 这就是我在setup.py所做的: class MyTest(test): def run_tests(self): import pytest import pylint if (pylint.run_pylint()): sys.exit(-1) if (pytest.main(self.test_args)): sys.exit(-1) setup( tests_require = ['pytest', 'pylint'], cmdclass = {'test': MyTest}, ... ) 当我

character in SQLite FTS3 queries?

I'm using Python and SQLAlchemy to query a SQLite FTS3 (full-text) store and I would like to prevent my users from using the - as an operator. How should I escape the - so users can search for a term containing the - (enabled by changing the default tokenizer) instead of it signifying "does not contain the term following the -"? From elsewhere on the internet it seems it may be p

SQLite FTS3查询中的字符?

我正在使用Python和SQLAlchemy来查询SQLite FTS3(全文)存储,并且我想阻止我的用户使用 - 作为操作符。 我应该如何逃避 - 因此用户可以搜索包含 - (通过更改默认标记器启用)的术语而不是它表示“不包含 - - ”之后的术语? 在互联网上的其他地方,似乎可能用双引号“some-term”来包围每个搜索词。 因为我们不需要减法运算,我的解决办法是更换连字符-用下划线_填充搜索索引和执行搜索时的时候。 从这个文档看来,这是不

pandas dtype conversion from object to string

I have a csv file that has a few columns which are numbers and few that are string. When I try myDF.dtypes it shows me all the string columns as object . Someone asked a related question before here about why this is done. Is it possible to recast the dtype from object to string? Also, in general, is there any easy way to recast the dtype from int64 and float64 to int32 and float32 and save

从对象到字符串的熊猫dtype转换

我有一个csv文件,其中有几列是数字,很少是字符串。 当我尝试myDF.dtypes它将所有字符串列显示为object 。 在这之前有人问了一个相关的问题,为什么这样做。 是否有可能重新从对象到字符串的dtype ? 另外,一般来说,有没有简单的方法可以将dtype从int64和float64重新转换为int32和float32并保存数据的大小(在内存中/磁盘上)? 所有字符串都表示为可变长度(这是dtype所持有的object )。 如果你愿意,你可以做seri

creating stream to iterate over from string in Python

I want to create a stream from a string in Python so that it's equivalent to reading the string as if it's read from a text file. something like: for line in open('myfile.txt'): print line except the contents of 'myfile.txt' are stored in a string s . Is this the correct/best way to do it? s = StringIO.StringIO("atbnctdn") for line in s: print line I want to create a stream

创建流来从Python中的字符串迭代

我想从Python中的一个字符串创建一个流,以便它像阅读文本文件一样读取字符串。 就像是: for line in open('myfile.txt'): print line 除非'myfile.txt'的内容存储在字符串s 。 这是否是正确/最好的方式? s = StringIO.StringIO("atbnctdn") for line in s: print line 我想从Python中的一个字符串创建一个流,以便它像阅读文本文件一样读取字符串。 这是否是正确/最好的方式? 是的,除非你真的想把它列入

Set Cover or Hitting Set; Numpy, Least element combinations to make up full set

My goal is to find the least possible number of sub sets [af] to make up the full set A. A = set([1,2,3,4,5,6,7,8,9,10]) # full set #--- below are sub sets of A --- a = set([1,2]) b = set([1,2,3]) c = set([1,2,3,4]) d = set([4,5,6,7]) e = set([7,8,9]) f = set([5,8,9,10]) In reality the parent set A that I'm dealing with contains 15k unique elements, with 30k subsets and these sub sets ra

设置封面或击中设置; Numpy,Least元素组合来弥补整套

我的目标是找到尽可能少的子集[af]来组成整套A. A = set([1,2,3,4,5,6,7,8,9,10]) # full set #--- below are sub sets of A --- a = set([1,2]) b = set([1,2,3]) c = set([1,2,3,4]) d = set([4,5,6,7]) e = set([7,8,9]) f = set([5,8,9,10]) 实际上,我正在处理的父集A包含15k个独特元素,其中包含30k个子集,这些子集的范围从单个独特元素到1.5k个独特元素。 截至目前,我正在使用的代码看起来或多或少像下面这样,

#!/usr/bin/python (sha

I have the following contents in the file demo.py:- // executable bit set #!/usr/bin/python import os i have used the command bash demo.py in the terminal and expecting that the first line is interpreted by the bash and it handles the file to python interpreter. But it calls the binary "/usr/bin/import"(figured using strace). The same is with sh demo.py . However running ./demo.p

#!/ usr / bin / python(sha

我在文件中有以下内容 demo.py:- //可执行位设置 #!/usr/bin/python import os 我在终端中使用了命令bash demo.py ,并期望第一行由bash解释,并且它将文件处理为python解释器。 但它调用二进制“/ usr / bin / import”(使用strace来计算)。 sh也是一样的demo.py。 然而运行./demo.py的作品。 男人bash说 “如果程序是以#!开头的文件,则第一行的其余部分指定程序的解释器。” 这没有发生。 使用bash版本 $ bas

Vim w/Python: Make ":make" take me to the error

If I have a python file like: def Bar(): raise NotImplementedError def Foo(): Bar() if __name__ == '__main__': Foo() And I type :make in vim, it nicely builds me a :cwindow filled with the relevant areas to move up the traceback. However, it defaults my cursor to the first frame of the call (in name == ' main '). Can I somehow change the default behaviour, s

Vim w / Python:使“:make”带我到错误

如果我有一个Python文件,如: def Bar(): raise NotImplementedError def Foo(): Bar() if __name__ == '__main__': Foo() 然后我输入:make在vim中,它很好地构建了我:cwindow填充了相关区域以提升回溯。 但是,它将我的光标默认为调用的第一帧( 名称 ==' main ')。 我可以以某种方式更改默认行为,因此它会将我带到实际的异常调用? - 更新 - 回答Ingo的问题: :makeprg / e

resize a 2D numpy array excluding NaN

I'm trying to resize a 2D numpy array of a given factor, obtaining a smaller array in output. The array is read from an image file and some of the values should be NaN (Not a Number, np.nan from numpy): it is the result of remote sensing measurements from satellite and simply some pixels weren't measured. The suitable package I found for this is scypy.misc.imresize, but each pixel in

调整不包含NaN的二维numpy阵列的大小

我正在尝试调整给定因子的2D numpy数组的大小,以便在输出中获得更小的数组。 该阵列从图像文件中读取,其中一些值应该是NaN(不是来自numpy的数字,np.nan):它是来自卫星的遥感测量结果,并且仅测量了一些像素。 我发现的适合的包是scypy.misc.imresize,但是包含NaN的输出数组中的每个像素都被设置为NaN,即使原始像素中有一些有效数据被内插在一起。 我的解决方案附在这里,我所做的基本上是: 根据原始数组形状和

How to flatten a nested list in python?

How can I convert: THIS = ['logging', ['logging', 'loggers', ['logging', 'loggers', 'MYAPP', ['logging', 'loggers', 'MYAPP', '-handlers'], ['logging', 'loggers', 'MYAPP', 'propagate'] ] ], ['logging', 'version'] ] into: THAT = [ ['logging'], ['logging', 'version'], ['logging', 'loggers'], ['logging', 'loggers', 'MYAPP'], ['logging', 'loggers', 'MYAPP', '-handl

如何在python中拼合一个嵌套列表?

我如何转换: THIS = ['logging', ['logging', 'loggers', ['logging', 'loggers', 'MYAPP', ['logging', 'loggers', 'MYAPP', '-handlers'], ['logging', 'loggers', 'MYAPP', 'propagate'] ] ], ['logging', 'version'] ] 成: THAT = [ ['logging'], ['logging', 'version'], ['logging', 'loggers'], ['logging', 'loggers', 'MYAPP'], ['logging', 'loggers', 'MYAPP', '-handlers'],

Efficient ways to duplicate array/list in Python

Note: I'm a Ruby developer trying to find my way in Python. When I wanted to figure out why some scripts use mylist[:] instead of list(mylist) to duplicate lists, I made a quick benchmark of the various methods to duplicate range(10) (see code below). EDIT: I updated the tests to make use of Python's timeit as suggested below. This makes it impossible to directly compare it to Ruby,

在Python中复制数组/列表的有效方法

注意:我是一位Ruby开发人员,试图用Python找到我的方式。 当我想知道为什么有些脚本使用mylist[:]而不是list(mylist)来复制列表时,我对各种方法进行了快速测试,以复制range(10) (请参阅下面的代码)。 编辑:我更新了测试以利用Python的timeit ,如下所示。 这使得直接将它与Ruby进行比较是不可能的,因为在Ruby的Benchmark中timeit没有考虑循环,所以Ruby代码仅供参考。 Python 2.7.2 Array duplicating. Tests run