In Revit Python Shell, why does one piece of code work directly from console but not if it is in a module?

20 Views Asked by At

I am using Revit Python Shell with Iron Python to create a complex program but at the moment, I am working on logging. I have a piece of code - shown below - which works if entered directly into RPS but not if the code is put into a module and the module is then imported.

Does anyone know what is going on?

Here is the code that I am trying execute:

import logging
import sys

import os
sys.path.append (os.path.expanduser ("~") + "\\Desktop\\Revit Access To DWG\\_ScriptStructure\\(AUE)_Python_Revit_Lib\\")

log = logging.Logger("d")
k = log.handlers.Count  #Code fails here in ModuleC
print "handler count: " + str(k)
h = logging.StreamHandler (sys.stdout )
f = logging.Formatter ("%(levelname)s: Module: %(module)s, Function: %(funcName)s, MSG: %(message)s")
h.formatter = f
log.addHandler(h)
k = log.handlers.Count
print "handler count: " + str(k)

print "-----------"

def aa():
  log.debug("FG")

aa()

Again this works fine if I put the code here: RPS Image

However if I put the above code into a module (ModuleC.py) and use the code below to import it, it does not work.

import logging
import sys

import os
sys.path.append (os.path.expanduser ("~") + "\\Desktop\\Revit Access To DWG\\_ScriptStructure\\(AUE)_Python_Revit_Lib\\")

logging.basicConfig (format = "%(levelno)s: Module: %(module)s, Function: %(funcName)s, MSG: %(message)s", stream = sys.stdout, level = logging.DEBUG )
logging.debug ("F")
from hat.ModuleC import *

The error returned is:

Exception : System.MissingMemberException: 'list' object has no attribute 'Count'

Hoping someone can help... Sincerely; Michelle

0

There are 0 best solutions below