我正在开发一些依赖于其中一个的应用程序.我看到pip可以创建捆绑包.我的所有项目都来自一个目录.
如何为这些项目创建捆绑包然后安装在其他Ubuntu系统中?可能我应该使用virtualenv.是否有可能为他们所有人提供一个virtualenv?
我创建了一些python应用程序autobahn并使用它打包baazar builddeb.在python setup.py文件中,我添加了requires包含所有必需依赖项的标记.是否有可能告诉debian软件包安装程序安装这些软件包?
我添加了一些deps debian/control>Depends但是:
dpkg -i my_package不安装依赖项.只显示错误,我需要手动安装这些代码.
标准的Ubuntu repos中不存在某些包.例如高速公路.一般来说,我想安装所有python依赖项pip/easy_install
我正在使用DistUtilsExtra.auto.setup个性化的install行动.所以我想我可以去easy_install packages那儿.这是好主意吗?
谢谢.
我的Python Pyramid应用程序中有一些HTML表单.我希望他们在启用JavaScript和禁用JavaScript时通过AJAX工作.现在我对AJAX和普通表单帖子使用不同的视图,但这些函数的代码看起来几乎相同,除了响应.我使用像这样的视图类(类体):
def ajax_ok(self, msg):
return Response(body=msg)
def ajax_error(self, msg):
return HTTPInternalServerError(body=msg)
@action(xhr=True, renderer='json', name='ftp')
def ftp_ajax(self):
log.debug('View: %s', 'ftp (ajax)')
if 'form.submitted' in self.params:
try:
self.config.save(self.params)
except:
return self.ajax_error('some error')
else:
return self.ajax_ok('ok')
@action()
def ftp(self):
if 'form.submitted' in self.params:
try:
self.config.save(self.params)
except:
self.request.session.flash('error; ' + msg)
else:
self.request.session.flash('success; ' + msg)
return {'content': render('templates/ftp.pt', {'ftp':
self.config.ftp})}
Run Code Online (Sandbox Code Playgroud)
我需要处理错误,如果有的话,并在html中显示它们.也许我应该使用finished_callback或我自己的渲染器,它会针对不同的请求类型发送不同的响应?
我想用菜单创建交互式Python脚本(可能使用curses?),用户可以使用键盘箭头在菜单上导航.实现此类功能的最简单方法是什么?任何简单的用法/教程?谢谢!
我正在编写Python Pyramid项目,我使用jQuery和jquery.form.js.我希望我的观点能够处理HTTP和AJAX帖子(我不确定它是否是最好的主意,但这可能是另一个问题的内容).
现在self.request.session.flash(),当发送HTTP POST并发生错误时,我用于错误通知.但是当发布Ajax时,我返回HTTPOk()或HTTPServerError()响应,这样我就可以轻松地向用户显示错误消息:
$('.ajax_form').ajaxForm({
error: function(xhr, textStatus, err){
$('.ajax_messages>.alert').hide().siblings('.alert-error').show().children('p').text(xhr.responseText);
},
success: function(responseText, statusText, xhr){
$('.ajax_messages>.alert').hide().siblings('.alert-success').show().children('p').text(xhr.responseText);
}
});
Run Code Online (Sandbox Code Playgroud)
但正如LoïcFaure-Lacroix建议我可以为Ajax和HTTP请求发送dict,这样可以简化代码.
什么是更好的主意?抛出异常时我应该从视图中返回什么?
转换Python dict的最简单方法是什么,例如:
a = {'a': 'value', 'b': 'another_value', ...}
Run Code Online (Sandbox Code Playgroud)
使用用户格式的字符串,例如:
'%s - %s\n'
Run Code Online (Sandbox Code Playgroud)
所以它给了我:
a - value
b - another_value
Run Code Online (Sandbox Code Playgroud)
这可行,但也许有更短/更好的使用地图(没有迭代集合)
''.join(['%s %s\n' % o for o in a.items()])
Run Code Online (Sandbox Code Playgroud) 我用C编写简单的程序,我看不出原因:
printf("%d\n", 1 == 1 == 1);
printf("%d\n", 1 == 1);
printf("%d\n", 0 == 0 == 0);
printf("%d\n", 0 == 0);
Run Code Online (Sandbox Code Playgroud)
得到:
1
1
0
1
Run Code Online (Sandbox Code Playgroud)
我已经习惯了Python,所以这对我来说都很新奇.
(作为发明者的旁白?)
python ×6
forms ×2
installation ×2
pyramid ×2
ajax ×1
autobahn ×1
boolean ×1
bundle ×1
c ×1
comparison ×1
curses ×1
deb ×1
dictionary ×1
distribution ×1
distutils ×1
interactive ×1
join ×1
jquery ×1
pip ×1
post ×1
string ×1