TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: How do you structure your Python programs?

7 点作者 augustflanagan超过 14 年前
I've been teaching myself to code for about 6 months now, and am finally starting to see the efforts pay off (I can actually do stuff). I first started learning to code with Python, and then switched to Ruby on Rails for a project I am working on about 3 months ago. The thing that I, as a noob, love most about Rails is the rigid structure that it provides. It totally makes sense to me, and I feel like it keeps my code organized very well.<p>However, I had an idea for a small coding project the other day, and for a couple of reasons it really made sense to build it on Google App Engine. So...I dove back into Python after several months of being away. It's amazing how much better I understand the fundamentals now, but I'm looking at my code base (&#60;500 lines) and realizing that I have a mess on my hands.<p>So, my questions is: How do you structure your code in Python? Do you have any recommendations for tutorials or suggested readings? Any quick tips to help me clean up a mess?<p>Thanks.

3 条评论

lfborjas超过 14 年前
I guess that what you miss about rails is the MVC architectural layout, but that's not specific to RoR and you can use it wherever you want, even in the webapp microframework for google app engine: have a file or module for models, another for controllers and another for views and get them together in a main module; you can also use django (I've used django 1.1 in gae with no problem) or use Jruby on appengine (there's a whole project for that: <a href="http://code.google.com/p/appengine-jruby/" rel="nofollow">http://code.google.com/p/appengine-jruby/</a>) to run ruby on rails, padrino or sinatra, if you really miss ruby. I've also run ruby projects on app-engine (in sinatra, which is the coolest microframework out there, IMO) and it's been easy, I actually felt it easier to set up that a django project, as it was hack free.
评论 #1726281 未加载
aberkowitz超过 14 年前
Read and follow PEP 8<p><a href="http://www.python.org/dev/peps/pep-0008/" rel="nofollow">http://www.python.org/dev/peps/pep-0008/</a>
评论 #1722414 未加载
jaddison超过 14 年前
Try a Python framework - there's enough of them to work with. The good ones (like Django) have a structure and standards that make sense - and have great tutorials, for the most part.