Detect file type from the file contents, not the file name

Possible Duplicate: How to find the mime type of a file in python? I want to detect the type of a file, but I don't want to look at the extension because it may be incorrect. The mimetypes module is filename based. Is there a standard way to peek inside the file? 尝试安装python-magic模块。 >>> mime = magic.Magic(mime=True) >>> mime.from_file("testdata/abc.pdf") 'ap

从文件内容中检测文件类型,而不是文件名

可能重复: 如何在Python中找到文件的MIME类型? 我想检测文件的类型,但我不想看扩展名,因为它可能不正确。 mimetypes模块是基于文件名的。 有没有一种标准的方法来查看文件内部? 尝试安装python-magic模块。 >>> mime = magic.Magic(mime=True) >>> mime.from_file("testdata/abc.pdf") 'application/pdf'

Anaconda Installed MATPLOTLIB Not Recognized by IDLE SHELL

I had installed Anaconda and it had already been embedded with some packages like matplotlib. But in my python idle shell, if I type in "import matplotlib.pyplot as plt" it returns No module named 'matplotlib' I assume the path directory where python calls in matplolib is different from where anaconda installed it. Any hint to solve this situation?

Anaconda安装的MATPLOTLIB未被IDLE SHELL识别

我已经安装了Anaconda,它已经嵌入了一些像matplotlib这样的软件包。 但是在我的python闲置shell中,如果输入“import matplotlib.pyplot as plt”,它将返回No module named'matplotlib' 我假设python在matplolib中调用的路径目录与anaconda安装目录的路径目录不同。 任何暗示来解决这种情况?

I try to run a script through TextWrangler

I have Python 3.6 installed on my Mac OS X. When I wrote my script I wrote the following import datetime as dt import matplotlib.pyplot as plt from matplotlib import style import pandas as pd import pandas_datareader.data as web but then when I run it, I get the following error message: Traceback (most recent call last): File "/Users/YoavPoni/Documents/Python/TextWranglerRunTemp-sen.py‌​

我尝试通过TextWrangler运行脚本

我在我的Mac OS X上安装了Python 3.6。当我编写我的脚本时,我写了以下内容 import datetime as dt import matplotlib.pyplot as plt from matplotlib import style import pandas as pd import pandas_datareader.data as web 但是当我运行它时,我收到以下错误消息: Traceback(最近一次调用最后一次):文件“/Users/YoavPoni/Documents/Python/TextWranglerRunTemp-sen.py”,第4行,导入matplotlib.pyplot为plt ModuleNo

Importing matplotlib.pyplot in atom editor

I am using pyzo to run my python scripts. However I felt the need to switch over to the Atom code editor. I can run my python scripts without any problem. At one point I need to use the library matplotlib . In pyzo I would do: import matplotlib.pyplot as plt But it doesn't work in Atom Error message: Traceback (most recent call last): File "C:UsersivanlDesktoppython tradematpl

在原子编辑器中导入matplotlib.pyplot

我正在使用pyzo来运行我的python脚本。 但是我觉得需要切换到Atom代码编辑器。 我可以运行我的Python脚本没有任何问题。 有一点我需要使用库matplotlib 。 在pyzo中我会这样做: import matplotlib.pyplot as plt 但它在Atom中不起作用 错误信息: Traceback(最近一次调用最后):文件“C: Users ivanl Desktop python trade matplotlib.py”,第1行,在导入matplotlib.pyplot中为plt文件“C: Users ivanl Desk

serve a stringIO (pdf) as download python

I have a cgi python script which saves a matplotlib generated picture as pdf to stringIO and as png to stringIO. The png picture will be shown on a new page which works well. sio = cStringIO.StringIO() pylab.savefig(sio, format='pdf') sio.close() sio =cStringIO.StringIO() print "Content-type:text/htmlrnrn" pylab.savefig(sio, format='png', bbox_inches='tight') print "<html>" ... print "&l

以下载python的形式提供stringIO(pdf)

我有一个cgi python脚本,将matplotlib生成的图片保存为pdf到stringIO和png到stringIO。 png图片将显示在一个新的页面上,效果很好。 sio = cStringIO.StringIO() pylab.savefig(sio, format='pdf') sio.close() sio =cStringIO.StringIO() print "Content-type:text/htmlrnrn" pylab.savefig(sio, format='png', bbox_inches='tight') print "<html>" ... print "<img id='Plot' src='data:image/png;base64,%s'/>

Installation Issue with matplotlib Python

This question already has an answer here: python matplotlib framework under macosx? 8 answers Problem Cause In mac os image rendering back end of matplotlib (what-is-a-backend to render using the API of Cocoa by default). There is Qt4Agg and GTKAgg and as a back-end is not the default. Set the back end of macosx that is differ compare with other windows or linux os. I resolve this issue

matplotlib Python的安装问题

这个问题在这里已经有了答案: macosx下的python matplotlib框架? 8个答案 问题原因在mac os图像渲染matplotlib的后端(默认情况下使用Cocoa的API呈现什么是后端)。 有Qt4Agg和GTKAgg,作为后端不是默认设置。 设置不同于其他窗口或linux操作系统的macosx的后端。 我按照以下方式解决此问题: 我假设你已经安装了pip matplotlib,在你的根目录中有一个名为~/.matplotlib 。 在那里创建一个~/.matplotlib/matplotl

Python matplotlib importError in command prompt but not in python shell

This question already has an answer here: matplotlib not working anymore due to interactive issue 1 answer You still have a file called new.py on your desktop. Somewhere along in the chain of import statements, there is an "import new", which finds your new.py, and everything goes wrong: File "C:Python27libsite-packagesmatplotlibcbook.py", line 34, in <module> import new F

在命令提示符下使用Python matplotlib importError,但不在python shell中

这个问题在这里已经有了答案: 由于交互式问题1的答案,matplotlib不再工作 您的桌面上仍然有一个名为new.py的文件。 在进口报表链的某处,有一个“导入新的”,它发现你的new.py,并且一切都出错了: File "C:Python27libsite-packagesmatplotlibcbook.py", line 34, in <module> import new File "C:UsersRobertDesktopnew.py", line 1, in <module> import matplotlib.pyplot 删除或重命名您的new.py以

How to plot 500 pairs of successive random numbers in python?

I am new to python and one of the problems I am working on is to plot 500 pairs of successive random numbers. I have a formula that generates the numbers seen below: x-axis >>> a=128 >>> c=0 >>> m=509 >>> n=500 >>> seed = 10 >>> for i in range (1,n): new_seed=(a*seed+c)%m seed = new_seed print new_seed y-axis >>> a=2

如何在python中绘制500对连续的随机数字?

我是python的新手,我正在处理的其中一个问题是绘制500对连续的随机数。 我有一个公式可以产生下面显示的数字: x轴 >>> a=128 >>> c=0 >>> m=509 >>> n=500 >>> seed = 10 >>> for i in range (1,n): new_seed=(a*seed+c)%m seed = new_seed print new_seed y轴 >>> a=269 >>> c=0 >>> m=2048 >>> n=500 >>

What's the best library for video capture in Python on linux?

I want to write an application to video capture from web-cams in linux. Is there a python library to do that? You should look at Gstreamer and its Python bindings. Here http://pygstdocs.berlios.de/pygst-tutorial/webcam-viewer.html is some sample code to display video from a webcam. To record the video you would have to change the pipeline definition from autovideosink to an encoder and files

什么是在Linux上的Python视频捕捉最好的库?

我想写一个应用程序来从Linux中的网络摄像头捕获视频。 有没有一个Python库来做到这一点? 你应该看看Gstreamer及其Python绑定。 这里http://pygstdocs.berlios.de/pygst-tutorial/webcam-viewer.html是一些示例代码,用于显示来自网络摄像头的视频。 要记录视频,您必须将管道定义从autovideosink更改为编码器和文件链接。 你可以看看WebCamsPy ,它似乎正在做你在问什么。 此外,请参阅相关问题,该问题更常用于Windo

Can someone show me the "hello world" of Paypal IPN?

我想建立一个PayPal捐款箱,并使用他们的IPN协议来监测捐赠何时到来。文档非常复杂,充满了我不感兴趣的功能。是否有一个简短的代码片段 - 理想情况是在Python中 - 这说明如何连接到PayPal,永久循环,并且每次捐赠时都打印“刚刚获得5美元”? Actually, with IPNs it's the other way around. PayPal posts a notification to your server via HTTP POST when a payment is made. You therefore need to make a CGI script

有人可以告诉我Paypal IPN的“hello world”吗?

我想建立一个PayPal捐款箱,并使用他们的IPN协议来监测捐赠何时到来。文档非常复杂,充满了我不感兴趣的功能。是否有一个简短的代码片段 - 理想情况是在Python中 - 这说明如何连接到PayPal,永久循环,并且每次捐赠时都打印“刚刚获得5美元”? 其实,与IPNs是相反的。 付款后,PayPal会通过HTTP POST向您的服务器发送通知。 因此,您需要制作一个CGI脚本或服务器来接收这些帖子,检查其有效性并对其进行处理。 PHP示例代码可