无法安装json模块.据我所知,我不应该使用sudo.怎么了?
pip install json
The directory '/home/snow/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/snow/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want …Run Code Online (Sandbox Code Playgroud) 我正在使用Google Appengine和Python 2.5,我有一个导致瓶颈的功能.我传递了一个从数据存储中检索到的200个模型实例的列表,然后以json格式返回它,然后传递给客户端.
我最初使用+ =将所有值连接在一起,但服务器用JSON响应大约需要30秒.我运行了一些检查和代码,然后在一秒钟内运行此函数.这是服务器响应JSON之前的最后一条语句,以及在1秒内(在我的本地网络上)达到客户端平均值所需的时间.此功能平均需要30秒才能执行.
我读了这篇文章并尝试使用该cStringIO方法(我也使用了列表连接方法,但它花了相同的时间并cStringIO使用更少的内存,所以我坚持使用它).但是,这与+ =连接(有时更长)的时间大致相同.任何人都可以看到我的代码有任何问题,可能会使它变慢?
编辑:老板说它必须这样做.没有json图书馆(与他一起接受).
编辑2: LastName模型:
class LastName(db.Model):
entry = db.ReferenceProperty(AlumniEntry, collection_name='last_names')
last_name = db.StringProperty(indexed=False)
last_name_search = db.StringProperty()
Run Code Online (Sandbox Code Playgroud)
AlumniEntry是Model被查询的.我将从ds返回的列表传递给get_json_from_alumnus()(alumnus参数).
def get_json_from_alumnus(alumnus, search, total=0):
if len(alumnus) > 0:
from cStringIO import StringIO
concat_file = StringIO()
concat_file.write('{ "alumnus": [')
i = 0
for alumni in alumnus:
if alumni.author:
author = alumni.author.nickname()
else:
author = 'Anonymous'
concat_file.write('{ ')
concat_file.write('"author": "')
concat_file.write(author)
concat_file.write('", ')
concat_file.write('"title": "')
concat_file.write(alumni.title)
concat_file.write('", …Run Code Online (Sandbox Code Playgroud) python google-app-engine concatenation string-concatenation python-2.5