Python Forum
Pythonic from a C++ perspective
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pythonic from a C++ perspective
#1
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()
Reply
#2
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
PyDan, Larz60+, carecavoador like this post
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  which is "better" (or more Pythonic)? Skaperen 2 2,084 Feb-01-2020, 03:10 PM
Last Post: Skaperen
  which is "better" (or more Pythonic)? Skaperen 7 3,267 Feb-01-2020, 03:51 AM
Last Post: Skaperen
  which is "better" (or more Pythonic)? Skaperen 8 3,404 Nov-16-2019, 06:46 PM
Last Post: Skaperen
  which is more Pythonic? Skaperen 5 2,902 Jul-16-2019, 01:00 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020