How to write a custom solution using a python package, modules etc

I am writing a packacge foobar which consists of the modules alice, bob, charles and david. From my understanding of Python packages and modules, this means I will create a folder foobar, with the following subdirectories and files (please correct if I am wrong) foobar/ __init__.py alice/alice.py bob/bob.py charles/charles.py david/david.py The package should be executable, so that

如何使用python包,模块等编写自定义解决方案

我正在写一个packacge foobar,它由模块alice,bob,charles和david组成。 根据我对Python包和模块的理解,这意味着我将创建一个文件夹foobar,包含以下子目录和文件(如果我错了,请更正) foobar/ __init__.py alice/alice.py bob/bob.py charles/charles.py david/david.py 该软件包应该是可执行的,这样除了使模块alice,bob等可以作为'库'使用之外,我还应该能够在这样的脚本中使用foobar: python

What are the differences between json and simplejson Python modules?

I have seen many projects using simplejson module instead of json module from the Standard Library. Also, there are many different simplejson modules. Why would use these alternatives, instead of the one in the Standard Library? json is simplejson , added to the stdlib. But since json was added in 2.6, simplejson has the advantage of working on more Python versions (2.4+). simplejson is al

json和simplejson Python模块有什么区别?

我看到很多使用simplejson模块的项目,而不是标准库中的json模块。 此外,还有许多不同的simplejson模块。 为什么会使用这些替代品,而不是标准库中的那个? json是simplejson ,添加到stdlib中。 但是由于json是在2.6中添加的,所以simplejson的优势在于可以使用更多的Python版本(2.4+)。 simplejson也比Python更新更频繁,所以如果你需要(或者想要)最新版本的话,如果可能的话,最好使用simplejson本身。 在我看

Textually diffing JSON

As part of my release processes, I have to compare some JSON configuration data used by my application. As a first attempt, I just pretty-printed the JSON and diff'ed them (using kdiff3 or just diff). As that data has grown, however, kdiff3 confuses different parts in the output, making additions look like giant modifies, odd deletions, etc. It makes it really hard to figure out what is di

在文本上区分JSON

作为我的发布过程的一部分,我必须比较我的应用程序使用的一些JSON配置数据。 作为第一次尝试,我只是打印了JSON并对它们进行了区分(使用kdiff3或diff)。 然而,随着数据的增长,kdiff3会混淆输出中的不同部分,使得增加看起来像是巨大的修改,奇怪的删除等等。这使得很难弄清楚什么是不同的。 我也尝试了其他差异工具(meld,kompare,diff和其他几个),但它们都有同样的问题。 尽管我尽了最大的努力,但似乎无法通过d

Checking file type with django form: 'application/octet

I'm using django validators and python-magic to check the mime type of uploaded documents and accept only pdf, zip and rar files. Accepted mime-types are: 'application/pdf', 'application/zip', 'multipart/x-zip', 'application/x-zip-compressed', 'application/x-compressed', 'application/rar', 'application/x-rar' 'application/x-rar-com

使用django格式检查文件类型:'application / octet

我使用django验证器和python-magic来检查上传文件的MIME类型,并只接受pdf,zip和rar文件。 接受的MIME类型是:'application / pdf','application / zip','multipart / x-zip','application / x-zip-compressed','application / x-compressed','application / rar', 'application / x-rar''application / x-rar-compressed','compressed / rar

Using PyPDF2 to merge files into multiple output files

Here is the code block that is causing the issue. The loop will append the new file each time, which is not what I am trying to accomplish. For example, outputfile1 is input1.pdf, outputfile2 is input1.pdf + input2.pdf... I am trying to merge file 1x.pdf with files 1a.pdf + 1b.pdf + 1c.pdf into the output file1.pdf and then loop through and do the same thing for 2, 3, and 4. The end result sh

使用PyPDF2将文件合并到多个输出文件

这是导致问题的代码块。 循环将每次追加新文件,这不是我想要完成的。 例如,outputfile1是input1.pdf,outputfile2是input1.pdf + input2.pdf ... 我试图将文件1x.pdf与文件1a.pdf + 1b.pdf + 1c.pdf合并到输出file1.pdf中,然后循环并为2,3和4执行相同的操作。最终结果应该是4个独立的文件。 我错过了什么? 清除泥浆? 预先感谢您的帮助。 i = 1 while i < 5: # files to be merged input1 = open(Path1+

Getting file extension using pattern matching in python

I am trying to find the extension of a file, given its name as a string. I know I can use the function os.path.splitext but it does not work as expected in case my file extension is .tar.gz or .tar.bz2 as it gives the extensions as gz and bz2 instead of tar.gz and tar.bz2 respectively. So I decided to find the extension of files myself using pattern matching. print re.compile(r'^.*[.](?P<e

在python中使用模式匹配获取文件扩展名

我试图找到一个文件的扩展名,因为它的名字是一个字符串。 我知道我可以使用函数os.path.splitext但它不能像预期的那样工作,因为我的文件扩展名是.tar.gz或.tar.bz2因为它给出的扩展名为gz和bz2而不是tar.gz和tar.bz2分别。 所以我决定使用模式匹配来自己找到文件的扩展名。 print re.compile(r'^.*[.](?P<ext>tar.gz|tar.bz2|w+)$').match('a.tar.gz')group('ext') >>> gz # I want this to come

Fitting a pareto distribution with (python) Scipy

I have a data set that I know has a Pareto distribution. Can someone point me to how to fit this data set in Scipy? I got the below code to run but I have no idea what is being returned to me (a,b,c). Also, after obtaining a,b,c, how do I calculate the variance using them? import scipy.stats as ss import scipy as sp a,b,c=ss.pareto.fit(data) Here's a quickly written version, taking som

用(python)Scipy装配一个pareto发行版

我有一个我知道有帕累托分布的数据集。 有人能指出我如何在Scipy中适合这个数据集吗? 我得到了下面的代码运行,但我不知道什么是返回给我(a,b,c)。 另外,获得a,b,c后,如何使用它们计算方差? import scipy.stats as ss import scipy as sp a,b,c=ss.pareto.fit(data) 这是一个快速写入的版本,从鲁珀特给出的参考页面提供了一些提示。 这在scipy和statsmodels目前正在进行中,并要求MLE提供一些固定或冻结的参

High Dimension Nearest Neighbor Search and Locality Sensitivity Hashing

Here is the main problem. I have very large database (25,000 or so) of 48 dimensional vectors, each populated with values ranging from 0-255. The specifics are not so important but I figure it might help give context. I don't need a nearest neighbor, so approximate neighbor searches that are within a degree of accuracy are acceptable. I've been toying around with Locality Sensitivity

高维最近邻搜索和局部灵敏度散列

这是主要的问题。 我有非常大的数据库(25,000左右)的48维向量,每个数据库的值都在0-255之间。 具体细节并不那么重要,但我认为这可能有助于提供背景。 我不需要最近的邻居,因此在一定精确度内的近似邻居搜索是可以接受的。 我一直在玩局部敏感哈希,但我非常失落。 我尽可能写了一篇散列函数,详见“稳定分布”一文中的文章。 这是代码。 def lsh(vector, mean, stdev, r = 1.0, a = None, b = None): if not a: a

How to determine content type of a string

I receive some data as a string. I need to write the data to a file, but the problem is that sometimes the data is compressed/zipped and sometimes it's just plain text. I need to determine the content-type so I know whether to write it to a .txt file or a .tgz file. Any ideas on how to accomplish this? Can I use mime type somehow even though my data is a string, not a file? Thanks. Bo

如何确定字符串的内容类型

我以字符串的形式接收一些数据。 我需要将数据写入文件,但问题是有时数据会被压缩/压缩,有时候它只是纯文本。 我需要确定内容类型,以便知道是将它写入.txt文件还是.tgz文件。 任何想法如何实现这一目标? 即使我的数据是字符串,而不是文件,我可以以某种方式使用MIME类型吗? 谢谢。 压缩数据之前,gzip和zip都使用不同的标头,而对于人类可读的字符串则不太可能。 如果选择仅在这些之间进行,则可以比mimetypes提

magic module' object has no attribute 'open'

I am trying to use python-magic package, a wrapper class for libmagic. I install using "pip install python-magic" but when I test it: import magic ms = magic.open(magic.MAGIC_NONE) ms.load() it shows that module' object has no attribute 'open'. I searched on google and somebody said that one cause is I do not have a __init__.py file. so I checked my peronsal site-packa

魔法模块'对象没有属性'打开'

我正在尝试使用python-magic软件包,libmagic的包装类。 我使用“pip install python-magic”来安装,但是当我测试它时: import magic ms = magic.open(magic.MAGIC_NONE) ms.load() 它显示模块'对象没有'打开'属性。 我在谷歌搜索和有人说,一个原因是我没有__init__.py文件。 所以我检查了我的peronsal site-packages目录。 我发现magic.py,magic.pyc和一个包含一些文本文件的文件夹python_magic-0.4.3-py2