Python Forum

Full Version: Pythonic from a C++ perspective
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
In C++, entSel would look like

int acedEntSel(const ACHAR * str, ads_name entres, ads_point ptres );

where entres and ptres are out parameters, the return types is a success / fail code

My wrapper, I return a tuple ( enum , ads_name, ads_point)
What is more Pythonic? Should a create a class or is a tuple correct?

sample

#function to select a ref and get it's object ids
def selectRefs()->[Db.ObjectId]:
    
    entSetRes = Ed.Editor.entSel("\nSelect Block:\n ",Db.BlockReference.desc())
    if entSetRes[0] != Ed.PromptStatus.eNormal:
        raise Exception(entSetRes[0]) 
    
    ref = Db.BlockReference(entSetRes[1])
    btr = Db.BlockTableRecord(ref.blockTableRecord())
    return btr.getBlockReferenceIds()
Consider using a namedtuple as a great substitute of creating own class in such context/use case

10 years old, but still great talk by Raymond Hettinger

Transforming Code into Beautiful, Idiomatic Python
Thanks for the reply!
That’s exactly what I need. Now I need to figure out how to generate a named tuple in boost::python
I also learned that I can type annotate tuples, so I have a couple options.