Python name mangling

后端 未结 11 2145
天命终不由人
天命终不由人 2020-11-22 05:31

In other languages, a general guideline that helps produce better code is always make everything as hidden as possible. If in doubt about whether a variable should be privat

11条回答
  •  难免孤独
    2020-11-22 06:03

    #EXAMPLE PROGRAM FOR Python name mangling

    class Demo:
        __any_name = "__any_name"
        __any_other_name_ = "__any_other_name_"
    
    
    [n for n in dir(Demo) if 'any' in n]   # GIVES OUTPUT AS ['_Demo__any_name', 
                                           #    '_Demo__any_other_name_']
    

提交回复
热议问题