TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: How do you structure your Python programs?

7 pointsby augustflanaganover 14 years ago
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 comments

lfborjasover 14 years ago
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 未加载
aberkowitzover 14 years ago
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 未加载
jaddisonover 14 years ago
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.