Speeding up Python Code

tmonteit
tmonteit used Ask the Experts™
on
I have some rather messy python code that does what it is supposed to but takes forever to run.

The code is often run as a script from the command line.  

The code does some batch xml processing and pushes  (sometimes) some data up through the google code API.

When I run the command, it takes about 15 seconds for the program to load before it even executes.  How can I make this all load faster?  

I tried eliminating some of the libraries and it seems to run much faster if I comment out the xml libraries, but then it doesn't do what I need.
import cgi
import os, sys
import base64 
import date, time, datetime
import getpass
import pdb
import pickle
import getopt
import sys
import commands
import os
import pdb
import re
import easygui
import feedparser
from optparse import OptionParser

# XML Parsing
from xml.etree.ElementTree import ElementTree, SubElement, dump
from xml.dom.minidom import parseString
from xml.sax import saxutils
import xml.dom.minidom
import xml.utils.iso8601
from xml.sax import saxutils

# Google G-data
import gdata.gauth
import gdata.contacts.client
import gdata.docs.client
from google.appengine.ext.remote_api import remote_api_stub 
from google.appengine.ext import db 
from google.appengine.api import users

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Software Engineer
Commented:
There might be a way to delay the loading of libraries until they are actually needed, but this can't be done without the complete program source code.

Author

Commented:
the first thing the code does is open an xml file and parse for data.  if that helps any.  So xml is right away.

Author

Commented:
the first thing the code does is open an xml file and parse for data.  if that helps any.  So xml is right away.
HonorGodSoftware Engineer

Commented:
Thanks for the grade & points.

Good luck & have a great day.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial