小编Com*_*eer的帖子

python中的有效zip文件

我使用文件输入上传了zip文件夹,但是当我检查此zip是否有效时;结果是:不是有效的pkzip文件,我不知道有效pkzip的规范是什么.我用这段代码来检查:

form = cgi.FieldStorage() 
file_upload = form['file[]']
if zipfile.is_zipfile(file_upload.filename):
    print "%s is a valid pkzip file" % file_upload.filename
else:
    print "%s is not a valid pkzip file" % file_upload.filename
Run Code Online (Sandbox Code Playgroud)

我不知道为什么?例如当我上传test.zip时,o/p将是:test.zip不是有效的pkzip文件,我需要帮助.谢谢

python zip

7
推荐指数
1
解决办法
2996
查看次数

在Python中调整图像大小

我可以在 python 中将图像大小调整为给定的高度和宽度吗,我使用 python 2.5,并且我尝试按照本教程http://effbot.org/imagingbook/introduction.htm,并且我安装了图像的 PIL 库,但是当我尝试写:

import Image
im = Image.open("test.jpg")
Run Code Online (Sandbox Code Playgroud)

我从 import:open 中得到了未定义的变量,尽管import Image没有给出错误?提前致谢。

resize image python-2.5

7
推荐指数
1
解决办法
2万
查看次数

如何在python中检测mime类型的文件?

我有一个问题,我从表格上传了zip文件,我想检测这些zip文件中包含的文件的mime类型,我从zip中提取文件没有问题,但问题是如何知道mime这个zip中每个文件的类型?谢谢

python zip mime-types

2
推荐指数
1
解决办法
4000
查看次数

如何在GAE上过滤图像?

我正在使用python谷歌应用程序引擎应用程序,我正在使用python2.5,我想处理GAE上的图像(过滤器图像),最初我尝试了智能PIL库,我成功安装它,我测试它,它的工作原理正确地在我的计算机上,但是当我在localhost上测试它(在GAE上运行)时,我有一个错误NotImplementedError: Unable to find the Python PIL library,然后我尝试使用Images Python API处理图像,如本教程:https://developers.google.com/appengine/docs/python/images/overview,我测试了调整大小图像服务,它工作正常,但我想要的主要应用是过滤图像,问题是:如果图像支持此服务(图像过滤) GAE中的Python API?如果没有,我如何在GAE上过滤图像?我看到PIL中有这个服务,我测试了它,但是python2.5中GAE不支持这个库

编辑:

我尝试使用python2.7在GAE上使用PIL库作为https://developers.google.com/appengine/docs/python/python27/using27#Configuring_Libraries,我安装了PIL 1.1.7,并配置了app.yaml文件如:

application: app_id
version: 1
runtime: python27
api_version: 1
threadsafe: false
handlers:
- url: /.*
  script: main.py
libraries:
- name: PIL
  version: "1.1.7"
Run Code Online (Sandbox Code Playgroud)

现在我如何在main.py页面中使用这个库?我试过from PIL import Image,但问题仍然是:

No module named PIL 
      args = ('No module named PIL',) 
      message = 'No module named PIL'
Run Code Online (Sandbox Code Playgroud)

提前致谢.

python google-app-engine image

2
推荐指数
1
解决办法
616
查看次数

获取Blobstore密钥

我正在阅读Google App Engine中的Blobstore.以下代码来自示例文档.用户选择要上传的文件并单击"提交"后,如何将密钥转换为javascript变量?我可以在一个页面上显示它,但我只想保留它以供以后使用.显然,我是Web编程的新手.

#!/usr/bin/env python
#

import os
import urllib
from google.appengine.ext import blobstore
from google.appengine.ext import webapp
from google.appengine.ext.webapp import blobstore_handlers
from google.appengine.ext.webapp.util import run_wsgi_app

class MainHandler(webapp.RequestHandler):
  def get(self):
    upload_url = blobstore.create_upload_url('/upload')
    self.response.out.write('<html><body>')
    self.response.out.write('<form action="%s" method="POST" enctype="multipart/form-data">' % upload_url)
    self.response.out.write("""Upload File: <input type="file" name="file"><br> <input type="submit"
    name="submit" value="Submit"> </form></body></html>""")

class UploadHandler(blobstore_handlers.BlobstoreUploadHandler):
  def post(self):
    upload_files = self.get_uploads('file')  # 'file' is file upload     field in the form
    blob_info = upload_files[0]
    self.response.out.write('<html><body>')
    self.response.out.write(str(blob_info.key()))
    self.response.out.write('</body><html>')

def main():
  application = webapp.WSGIApplication(
    [('/', MainHandler),
     ('/upload', …
Run Code Online (Sandbox Code Playgroud)

python google-app-engine blobstore

2
推荐指数
1
解决办法
325
查看次数

Python - 如何在字典中搜索特定字符串?

如果我将字典定义为users = {},并且假设我在该字典中有一些数据,那么我如何搜索字典,并且如果我的搜索字符串与字典中的字符串匹配,则什么也不做。

for socket.user in MyServer.users:
    if ((MyServer.users.has_key(socket.user)) == false):
        MyServer.users[user].send(socket.message)
Run Code Online (Sandbox Code Playgroud)

所以这里是搜索用户字典,发现它存在,所以它应该什么都不做。我知道我的代码是错误的,但是我可以在第二行更改什么?

python dictionary

1
推荐指数
1
解决办法
2万
查看次数

C++中的函数行为

我有以下代码:

int Fun(int x, int y)
{
    if(x<y)
        return 1;
}
int main ()
{

    cout<<Fun(6,2)<<endl;
}
Run Code Online (Sandbox Code Playgroud)

这段代码的输出是6(x的值)!! 我不知道为什么这种行为......任何人都可以向我解释.

提前致谢.

c++ function

1
推荐指数
1
解决办法
90
查看次数

GAE中的处理程序

我想问一下,我试着打电话webapp.RequestHandler,但这个处理程序没有调用:这是compress.py页面:

from __future__ import with_statement
from google.appengine.api import files
import cgi, cgitb ; cgitb.enable()
import StringIO
import zipfile
from google.appengine.ext import blobstore
from google.appengine.ext import webapp
from google.appengine.ext.webapp import blobstore_handlers
from google.appengine.ext.webapp.util import run_wsgi_app
class zip(webapp.RequestHandler):
    def z(self):
        form = cgi.FieldStorage()
        zipstream=StringIO.StringIO()
        zfile = zipfile.ZipFile(file=zipstream,mode="w",compression=zipfile.ZIP_DEFLATED)     
        file_upload = form['file[]']
        data=file_upload.file.read()
        filename2 = file_upload.filename
        zfile.writestr(filename2,data)
        zfile.close()
        zipstream.seek(0)
        zip_file = files.blobstore.create(mime_type='application/zip',_blobinfo_uploaded_filename='test.zip')
        with files.open(zip_file, 'a') as f:
            f.write(zipstream.getvalue())
        files.finalize(zip_file)
        blob_key = files.blobstore.get_blob_key(zip_file)        
        self.response.out.write('<a href="download.py?key=%s">get zip</a>' %blob_key)

def main():
     application = webapp.WSGIApplication( [(r'/compress.py', …
Run Code Online (Sandbox Code Playgroud)

html python google-app-engine

-5
推荐指数
1
解决办法
189
查看次数