我正在尝试使用 python-magic 包,它是 libmagic 的包装类。
我使用“pip install python-magic”安装,但是当我测试它时:
import magic
ms = magic.open(magic.MAGIC_NONE)
ms.load()
Run Code Online (Sandbox Code Playgroud)
它表明 module' 对象没有属性 'open'。我在谷歌上搜索,有人说原因之一是我没有 __init__.py 文件。所以我检查了我的个人站点包目录。我找到了 magic.py、magic.pyc 和一个文件夹 python_magic-0.4.3-py2.7.egg-info,其中只包含一些文本文件。
如何获取 __init__.py 文件?我检查了安装的其他软件包,其中一些确实有这样的文件。
谢谢。
我有一个使用子进程调用 unoconv 的 django 应用程序。在我的开发环境中运行时它工作正常,但在生产环境中运行时会出错。
它给出了这个错误
“unoconv:在/usr/lib/libreoffice 中找不到合适的pyuno 库和python 二进制组合错误:没有名为uno 的模块
unoconv:在您的系统上找不到合适的办公安装。错误:请找到您的办公室安装并将您的反馈发送至:http : //github.com/dagwieers/unoconv/issues ”
但是 unoconv 从命令行运行得很好。
由于我将 django 应用程序作为 uwsgi vassal 运行,因此它可能与特权有关,但在我的一生中,我无法弄清楚如何修复它。
PS - django 应用程序不会启动 unoconv 侦听器,它已经在运行。
编辑- 这不是权限问题,而是路径问题,因为 unoconv 是从错误的 Python 解释器(virtualenv 解释器)调用的
我的以下代码:
#!/usr/bin/env python
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.by import By
# Define firefox profile
download_dir = "/Users/pdubois/Desktop/TargetMine_Output/"
fp = webdriver.FirefoxProfile()
fp.set_preference("browser.download.folderList",2)
fp.set_preference("browser.download.manager.showWhenStarting",False)
fp.set_preference("browser.download.dir", download_dir)
#fp.set_preference("browser.helperApps.neverAsk.saveToDisk", "text")
fp.set_preference("browser.helperApps.neverAsk.saveToDisk", "text/plain")
driver = webdriver.Firefox(fp)
driver.implicitly_wait(20)
genes = "Eif2ak2,Pcgf5,Vps25,Prmt6,Tcerg1,Dnttip2,Preb,Polr1b,Gabpb1,Prdm1,Fosl2,Zfp143,Psip1,Kat6a,Tgif1,Txn1,Irf8,Cnot6l,Zfp451,Foxk2,Lpxn,Etv6,Khsrp,Lmo4,Nkrf,Mafk,Mbd1,Cited2,Elp5,Jdp2,Bzw1,Rbm15b,Klf9,Gtf2e2,Dynll1,Klf6,Stat1,Srrt,Gtf2f1,Adnp2,Ikbkg,Mybbp1a,Nup62,Brd2,Chd1,Kctd1,Sap30,Cebpd,Mtf1,Gtf2h2,Fubp1,Tcea1,Irf2bp2,Ezh2,Hnrpdl,Pml,Cebpz,Med7"
targetmine_url = "http://targetmine.nibio.go.jp/targetmine/begin.do"
driver.get(targetmine_url)
# Define type of list to be submitted
gene_select = Select(driver.find_element_by_name("type"))
gene_select.select_by_visible_text(u"Gene")
# Enter list and submit
gene_input = driver.find_element_by_id("listInput")
gene_input.send_keys(genes)
submit = driver.find_element_by_css_selector("input.button.light").click()
# Choose name for list
driver.find_element_by_id("newBagName").clear()
driver.find_element_by_id("newBagName").send_keys("ADX.06.ID.Clust1")
driver.switch_to_frame("__pomme::0")
# Add All
driver.find_element_by_css_selector("span.small.success.add-all.button").click() …Run Code Online (Sandbox Code Playgroud) 我希望能够打开一个给定的文件,并看到"这是一个MP4文件",或"这是一个webm"文件,甚至"这似乎不是一个有效的视频"
我在https://code.google.com/p/pyffmpeg/上看到了FFmpeg包装器,但我没有看到任何类型的get_codec函数.
思考?
我想查找文件名的扩展名,扩展名只能是3个字符.
它是这样的,
filename = str(input("Please enter filename: "))
Run Code Online (Sandbox Code Playgroud)
然后我想执行一个任务来寻找扩展,如果扩展不满足要求(即3个字符长),我将添加打印"无效的扩展名!" 否则,请打印"有效扩展名".
我有一个问题,我从表格上传了zip文件,我想检测这些zip文件中包含的文件的mime类型,我从zip中提取文件没有问题,但问题是如何知道mime这个zip中每个文件的类型?谢谢
在 Centos 中,为什么 python 2.7 预建库 mimetypes.guess_type 不返回 json 文件的 mimetype? https://docs.python.org/2/library/mimetypes.html#
我在 mimetypes 中使用 guess_type,它在 centos/ubuntu 中返回不同的值。在不同操作系统中从文件名推断 mimetype 的 pythonic 方法是什么?
在 ubuntu 14.04 中,它返回正确的 mime 类型
>>> import mimetypes
>>> mimetypes.guess_type('a.json')
('application/json', None)
Run Code Online (Sandbox Code Playgroud)
但是在 Centos7
>>> import mimetypes
>>> mimetypes.guess_type('a.json')
(None, None)
>>> mimetypes.guess_type('a.JSON')
(None, None)
Run Code Online (Sandbox Code Playgroud)
我检查了类似的问题和建议的答案,它只有在给定内容的文件存在时才有效...... 如何在 python 中找到文件的 mime 类型?
我在Python 2.6中使用Bing API编写了一个Web爬虫,它搜索某些文档,然后下载它们以便稍后进行分类.我一直在使用字符串方法并urllib.urlretrieve()下载其URL以.pdf,.ps等结尾的结果,但是当文档被"隐藏"在URL之后时,我遇到了麻烦:
http://www.oecd.org/officialdocuments/displaydocument/?cote=STD/CSTAT/WPNA(2008)25&docLanguage=En
那么,有两个问题.有没有一种方法可以判断一个URL是否有一个pdf/doc等文件,如果它没有这么明确地链接到它(例如www.domain.com/file.pdf)?有没有办法让Python抓住那个文件?
编辑:感谢您的回复,其中一些建议下载文件,看看它是否是正确的类型.唯一的问题是......我不知道该怎么做(见上面的问题#2).urlretrieve(<above url>)只给出一个html文件,其href包含相同的url.
我正在编写python脚本,我想查找有关文件的信息,例如mime-type(或文件包含的任何有用的描述).
我听说过python-magic,但我真的在寻找能让我找到这些信息的解决方案,而无需安装额外的软件包.
我是坚持维护文件扩展名列表,还是python在标准库中有什么东西?我无法在文档中找到它.
我试图保存没有弹出框的csv文件。我点击以下链接找出我的哑剧:
我什至还添加了mimeTypes.rdf文件中的所有NC_values。但是,它似乎不起作用。
profile = webdriver.FirefoxProfile()
profile.set_preference('browser.download.folderList', 2)
profile.set_preference('browser.download.manager.showWhenStarting', False)
profile.set_preference('browser.download.dir', os.getcwd())
profile.set_preference('browser.helperApps.neverAsk.saveToDisk', 'irc,ircs,webcal,application/csv,application/download,application/pdf')
Run Code Online (Sandbox Code Playgroud)
mimeTypes.rdf
<RDF:RDF xmlns:NC="http://home.netscape.com/NC-rdf#"
xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<RDF:Seq RDF:about="urn:schemes:root">
<RDF:li RDF:resource="urn:scheme:webcal"/>
<RDF:li RDF:resource="urn:scheme:ircs"/>
<RDF:li RDF:resource="urn:scheme:mailto"/>
<RDF:li RDF:resource="urn:scheme:irc"/>
</RDF:Seq>
<RDF:Description RDF:about="urn:scheme:mailto"
NC:value="mailto">
<NC:handlerProp RDF:resource="urn:scheme:handler:mailto"/>
</RDF:Description>
<RDF:Description RDF:about="urn:handler:web:https://30boxes.com/external/widget?refer=ff&url=%s"
NC:prettyName="30 Boxes"
NC:uriTemplate="https://30boxes.com/external/widget?refer=ff&url=%s" />
<RDF:Description RDF:about="urn:scheme:irc"
NC:value="irc">
<NC:handlerProp RDF:resource="urn:scheme:handler:irc"/>
</RDF:Description>
<RDF:Description RDF:about="urn:scheme:handler:mailto"
NC:useSystemDefault="true"
NC:alwaysAsk="false">
<NC:possibleApplication RDF:resource="urn:handler:web:https://compose.mail.yahoo.com/?To=%s"/>
<NC:possibleApplication RDF:resource="urn:handler:web:https://mail.google.com/mail/?extsrc=mailto&url=%s"/>
</RDF:Description>
<RDF:Description RDF:about="urn:handler:web:https://mail.google.com/mail/?extsrc=mailto&url=%s"
NC:prettyName="Gmail"
NC:uriTemplate="https://mail.google.com/mail/?extsrc=mailto&url=%s" />
<RDF:Description RDF:about="urn:scheme:handler:webcal"
NC:useSystemDefault="true"
NC:alwaysAsk="true">
<NC:possibleApplication RDF:resource="urn:handler:web:https://30boxes.com/external/widget?refer=ff&url=%s"/>
</RDF:Description>
<RDF:Description RDF:about="urn:mimetype:application/pdf"
NC:value="application/pdf">
<NC:handlerProp RDF:resource="urn:mimetype:handler:application/pdf"/>
</RDF:Description>
<RDF:Description RDF:about="urn:scheme:ircs"
NC:value="ircs">
<NC:handlerProp RDF:resource="urn:scheme:handler:ircs"/>
</RDF:Description> …Run Code Online (Sandbox Code Playgroud) python ×11
firefox ×2
mime-types ×2
selenium ×2
bing-api ×1
centos7 ×1
django ×1
libreoffice ×1
mp4 ×1
python-2.7 ×1
python-3.x ×1
url ×1
web ×1
web-crawler ×1
webm ×1
zip ×1