2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Hummdis
0

Why don't you take all of the content for the "mainPage()" function, put it in a text file, then open and read the lines? There's not a single line of actual Python code and it's basically a waste of space. You're not even performing string replacement, so it brings nothing to the table.

def mainPage():
    s = ''
    for line in open('/path/to/main.txt', 'r'):
        s += line
    return s

That turns 24 lines of code into 5. That also saves a LOT of "s +=" lines.

Try to use loops for repetitive tasks like that.

Edit: You can also drop the "\n" on each line as a result.

Edited by Hummdis: Another idea...

0

Here's another idea to clean your code: stack import commands:

import logging, urllib2, cgi, os, wsgiref.handlers
from google.appengine.ext import webapp
from urllib import urlencode
from urllib2 import urlopen
from BeautifulSoup import BeautifulSoup
from google.appengine.ext.webapp import template
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db

Also, you've already imported the whole module of "urllib2" and therefore it brings nothing to the table to again import "urlopen" from "urllib2".

That brings the import section down:

import logging, urllib2, cgi, os, wsgiref.handlers
from urllib import urlencode
from BeautifulSoup import BeautifulSoup
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db

Another 4 lines down. :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.