A Python problem?

Colin J. Williams Colin.J..Williams at p98.f112.n480.z2.fidonet.org
Wed Jun 30 07:56:16 EDT 1999


From: "Colin J. Williams" <cjw at connection.com>

This script below illustrates what appears to be a problem with the
identification of a module in a package.

The example is borrowed from the linbot material.

Colin W.
''' A Python problem?   .

  '''
def main():
  import sys
  print 'Start:',dir()
  s0= sys.modules
  import plugins.rptlib
  s1= sys.modules
  if s0 == s1:
    print 'sys.modules is unchanged'
  print 'After attempt to import plugins.rptlib:', dir()
  try:
    print dir(plugins.rptlib)
  except AttributeError:
    import sys
    print sys.exc_info()
  from plugins.rptlib import *
  print 'rptlib names now available:', dir()
main()

'''
------------------------ Resulting Display ----------------------------
>>> Start: ['sys']
sys.modules is unchanged
After attempt to import plugins.rptlib: ['plugins', 's0', 's1', 'sys']
(<class exceptions.AttributeError at 76bbc0>, <exceptions.AttributeError
instance at daa0e0>, <traceback object at dab2b0>)
rptlib names now available: ['Link', 'add_problem', 'check_and_warn', 'config',
'debugio', 'doBotMain', 'doTopMain', 'get_title', 'linbot', 'linkList',
'main_index', 'make_link', 'nav_bar', 'open_file', 'opener', 'os', 'plugins',
'problem_db', 'proxies', 'read_registry', 's0', 's1', 'sort_by_age',
'sort_by_author', 'sort_by_rev_age', 'sort_by_size', 'string', 'stylesheet',
'sys', 'urllib', 'version']

  '''




More information about the Python-list mailing list