Documents/PythonCodingStandards

Python Coding Guidelines

   1 """
   2 Master script to process MIDAS-W incoherent scatter data.
   3 
   4 This script assumes that data is divided into subdirectories,
   5 which each contain (self-consistently) all relevant
   6 information necessary for processing.  Consistency checks are made to
   7 ensure that all data is available before processing begins.
   8 
   9 $Id$
  10 """
  11 
  12 import os, os.path, sys
  13 import urllib2
  14 
  15 class URIFilenameParser:
  16     """URIFilenameParser is the public class used to discover filenames.
  17 
  18     It uses a fnmatch string to find files from a URI pointing to a directory .
  19 
  20     Usage example::
  21 
  22         filenameParser = URIFilenameParser('http://anubis/event/2002-03-26', '[0-9]*xml')
  23         filenameList = filenameParser.getFilenamesList()
  24         for filename in filenameList:
  25             print filename
  26 
  27     Public attributes:  
  28            self.filecount - number of files found
  29 
  30     Non-standard Python modules used: None
  31 
  32     Written by "Bill Rideout":mailto:wrideout@haystack.mit.edu  Apr. 3, 2002
  33     """
  34 
  35     def __init__(self, URI, fnmatchStr):
  36         """__init__ gathers a list of filenames with the given extension from the URI string.
  37 
  38         Inputs:
  39             URI - a string representing a uri to a directory
  40             fnmatchStr - a string to match file names against. 
  41         
  42         Returns: void.
  43 
  44         Affects: initializes self.__filenameList, self.filecount
  45 
  46         Algorithm: Use urllib2 to read page.  Parse for filenames, then use fnmatch
  47                    module to see if they match fnmatchStr.
  48 
  49         Exceptions: throws NoStatusDataFound if any problems loading data.
  50         """
  51         # initialize attributes
  52         self.filecount = 0
  53         self.__filenameList = []
  54 
  55 if __name__ == '__main__':
  56 
  57     # test this module
  58     filenameParser = URIFilenameParser('http://anubis/event/2002-03-26', '[0-9]*xml')
  59     filenameList = filenameParser.getFilenamesList()
  60     for filename in filenameList:
  61         print filename

Other Python Coding Guidelines

[WWW] PEP0008

[WWW] PEP0257

[WWW] PEP0020

[WWW] PEP0328

last edited 2010-09-28 14:20:53 by BillRideout