الفرق بين المراجعتين ل"Python/ConfigParser/sections"

من موسوعة حسوب
اذهب إلى التنقل اذهب إلى البحث
 
سطر 22: سطر 22:
 
User = hg
 
User = hg
  
[topsercret.server.com]
+
[topsecret.server.com]
 
Port = 50022
 
Port = 50022
 
ForwardX11 = no
 
ForwardX11 = no
سطر 33: سطر 33:
 
['config.cfg']
 
['config.cfg']
 
>>> config.sections()
 
>>> config.sections()
['bitbucket.org', 'topsercret.server.com']
+
['bitbucket.org', 'topsecret.server.com']
  
 
</syntaxhighlight>
 
</syntaxhighlight>

المراجعة الحالية بتاريخ 11:46، 30 نوفمبر 2018


يعيد التابع قائمة بالأقسام المتاحة، ولا يكون قسم الإعدادات الافتراضية DEFAULT ضمن هذه القائمة.

البنية العامة

sections()

‎القيمة المعادة

يعيد التابع قائمة بالأقسام المتاحة، ولا يكون قسم الإعدادات الافتراضية DEFAULT ضمن هذه القائمة.

أمثلة

لنفرض أن لدينا ملف الإعدادات التالي:

[DEFAULT]
ServerAliveInterval = 45
Compression = yes
CompressionLevel = 9
ForwardX11 = yes

[bitbucket.org]
User = hg

[topsecret.server.com]
Port = 50022
ForwardX11 = no

يؤدي استدعاء التابع sections()‎ إلى الحصول على المخرجات التالية:

>>> import configparser
>>> config = configparser.ConfigParser()
>>> config.read('config.cfg')
['config.cfg']
>>> config.sections()
['bitbucket.org', 'topsecret.server.com']

انظر أيضًا

  • التابع defaults()‎: يعيد التابع قاموسًا يتضمّن القيم الافتراضية على مستوى نسخة الصنف instance-wide defaults.

مصادر