Jump to content

User:Msiddalingaiah/Python snippets

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Msiddalingaiah (talk | contribs) at 16:03, 24 August 2005 (+reading from file). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

A short collection of Python code snippets

Main function

if __name__ == "__main__":
    main()

Command line arguments

import sys
for arg in sys.argv:
    print arg

sys.argv[0] is the command, sys.argv[1] is the first argument proper.

Reading from a file

f = open('attach.rtf', 'rt')
template = f.read()
f.close()