I find that Dynamo is a better debugging platform for pyRevit Python than the python shell.
Just put the declarations in your Dyanmo python template and run the script in Dynamo for testing. When you have everything working - just copy/paste it all out to a *.py file and away you go.
Note that I’ve referenced both Dynamo and pyRevit so I can use either (Dynamo is a bit of a pain because it needs to be initialized first)
sys.path.append('C:\Program Files\Autodesk\Revit 2020\AddIns\DynamoForRevit')
#Use this for pyRevit. Ok to use inside Dynamo as well if pyRevit is referenced.
#doc = __revit__.ActiveUIDocument.Document
#app = __revit__.Application
#uidoc = __revit__.ActiveUIDocument
#uiapp = __revit__.CurrentUIApplication
#Dynamo - I'll use this if the end product is going to be a dyn rather than a py.
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc = uiapp.ActiveUIDocument