如何编写Smart Python程序? [英] How to write Smart Python programs?

查看:54
本文介绍了如何编写Smart Python程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我们刚用TG使用Python执行了一个项目。反馈是

使用更多类似python的编程,而不是在
Python中执行的C风格代码。反馈来自Python纯粹主义者,由于某些原因,我们

无法请求他的帮助。


所以我们想做的就是擦洗代码库和识别位置

代码库需要改进的地方,包括造型以及

设计。是否有任何网站可以为我提供高级提示

而不仅仅是教程,因为它没有多大帮助。


该项目涉及:

1.服务器模块,从数据记录器接收消息以填充

a数据库

2.与UI接口的数据库访问模块


我们使用的技术是TurboGears,SQLAlchemy,CherryPy,Kid

模板。


任何帮助将不胜感激。如果你想参与其中的
for $$(在上面提到的工具中有经验),那就让我知道了。
。我需要帮助,因为截止日期非常短。


谢谢,

Raj。

Hi,

We just executed a project with Python using TG. The feedback was to
use more python like programming rather than C style code executed in
Python. The feedback is from a Python purist and for some reasons we
cannot solicity his help.

So we''d like to do is to scrub through the codebase and identify places
where the codebase needs improvement, both from styling as well as
design. Is there any website that can provide me with advanced tips
rather than just tutorials coz thats not of much help.

The project involves:
1. A server module that receives messages from a datalogger to populate
a database
2. A DB access module that interfaces with the UI

The technologies we use are TurboGears, SQLAlchemy, CherryPy, Kid
templates.

Any help will be greatly appreciated. If you would like to get involved
in it for $$ (experienced in the tools mentioned above) as well do let
me know. I need help asap as the deadlines are very very short.

Thanks,
Raj.

推荐答案

(在上面提到的工具中经验丰富)也让我知道了。我需要帮助,因为截止日期非常短。


谢谢,

Raj。

(experienced in the tools mentioned above) as well do let
me know. I need help asap as the deadlines are very very short.

Thanks,
Raj.


Raj写道:
Raj wrote:




我们刚用TG使用Python执行了一个项目。反馈是

使用更多类似python的编程,而不是在
Python中执行的C风格代码。反馈来自Python纯粹主义者,由于某些原因,我们

无法请求他的帮助。


所以我们想做的就是擦洗代码库和识别位置

代码库需要改进的地方,包括造型以及

设计。是否有任何网站可以为我提供高级提示

而不仅仅是教程,因为它没有多大帮助。
Hi,

We just executed a project with Python using TG. The feedback was to
use more python like programming rather than C style code executed in
Python. The feedback is from a Python purist and for some reasons we
cannot solicity his help.

So we''d like to do is to scrub through the codebase and identify places
where the codebase needs improvement, both from styling as well as
design. Is there any website that can provide me with advanced tips
rather than just tutorials coz thats not of much help.



Google搜索python不是java可能是一个好的开始。此外,这里有2个

常见的C风格气味:


1 /使用显式索引而不是迭代:


C-smell:

我在范围内(len(seq)):

do_something_with(seq [i])


Pythonic:

for seq中的项目:


do_something_with(item)

#或者如果你还需要索引:

for i,item in enumerate(seq):

do_something_with(i,item)


2 /返回a的函数状态代码并修改其参数。

pythonic的方法是让函数返回多个args并在出现问题时提出

异常

-

bruno desthuilliers

python -c" print''@''。join([''。''。join([w [:: - 1] for p in p.split (''''')])

p in''o **** @ xiludom.gro''。split(''''')])"

Googling for "python is not java" may be a good start. Also, here are 2
common C-style smells:

1/ using explicit indexing instead of iteration:

C-smell :
for i in range(len(seq)):
do_something_with(seq[i])

Pythonic:
for item in seq:

do_something_with(item)
# or if you need the index too:
for i, item in enumerate(seq):
do_something_with(i, item)

2/ functions that returns a status code and modify their arguments. The
pythonic way is to have the function return multiple args and raise an
exception if something went wrong
--
bruno desthuilliers
python -c "print ''@''.join([''.''.join([w[::-1] for w in p.split(''.'')]) for
p in ''o****@xiludom.gro''.split(''@'')])"


在10/11/06,Bruno Desthuilliers< on *** @ xiludom.growrote:
On 10/11/06, Bruno Desthuilliers <on***@xiludom.growrote:

2 / function that that that返回状态代码并修改其参数。
2/ functions that returns a status code and modify their arguments.



带有一个项目的列表的参数修改*有时*用于

模拟完整的词法闭包。 (或者至少那个人们就是这样的人来了... $ f $ b freenode #python告诉我)


- Theerasak

Argument modification for lists with one item is *sometimes* used to
emulate full lexical closure. (or at least that''s what the folks on
freenode #python told me)

-- Theerasak


这篇关于如何编写Smart Python程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆