python - locals().update(kwargs) is not working -


इस सवाल का पहले से ही एक उत्तर है: < / P>

  • 4 जवाब
      वर्ग फू ( ऑब्जेक्ट): def __init __ (self, x): self.bar (x = x) def बार (स्वयं, ** kwargs): प्रिंट kwargs स्थानीय ()। अद्यतन (kwargs) प्रिंट xf = Foo (12)   

    यह स्पष्ट है, लेकिन यह काम नहीं करता है, पहला प्रिंट आउटपुट {'x': 12} होगा, जो सही है, फिर भी मुझे यह त्रुटि मिलती है: नाम की त्रुटि: वैश्विक नाम 'x' परिभाषित नहीं है

    ऐसा क्यों होता है? धन्यवाद।

    द्वारा दिया गया शब्दकोष केवल पढ़ने के लिए है आप वर्तमान गुंजाइश में गतिशील रूप से चर को जोड़ नहीं सकते।

Comments

Popular posts from this blog

sql - Return Function using Cursor -

javascript - Is there any way to add a new parameter to a function programmatically? -

sql server - How to use pivot in this table -