python keyword string formatting with '%' confusing error : unsupported format character 'p' -


मेरे पास निम्न सेटअप है

  cred_dict = {'admin_id': 'user', 'Admin_password': 'pass'} cred_template = '- id =% (admin_id) -pa =% (admin_password)'  

जब मैं कोशिश करता हूं

  Cred_template% cred_dict  

मुझे मिल

  मान त्रुटि: असमर्थित स्वरूप वर्ण 'p' (0x70) सूचकांक 17 पर  

और मुझे पता नहीं क्यों हो सकता है।

आप एक महत्वपूर्ण तत्व गायब हैं: स्वरूपण प्रकार सूचक:

  cred_template = '- id =% (admin_id) s -pa =% (admin_password) s' # ^ ^  
< P> s इंगित करता है कि आप मान को स्ट्रिंग्स के रूप में प्रारूपित करना चाहते हैं। उन संकेतकों के बिना, पायथन प्रकार की खोज रखता है और अक्षर p ( -pa से) पाता है और यह एक वैध प्रकार सूचक नहीं है।

डेमो :

  & gt; & gt; & gt; Cred_dict = {'admin_id': 'उपयोगकर्ता', 'admin_password': 'pass'}> gt; & gt; & gt; Cred_template = '- id =% (admin_id) s -pa =% (admin_password) s' & gt; & gt; & gt; Cred_template% cred_dict '-id = user -pa = pass'  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -