国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
每周一題——讀寫配置文件。 Python討論區(qū)/精華帖
下面是我根據(jù)sakulagi的思路改寫的程序:

#! /usr/bin/python

import os
import sys

class Ini:
   """ Assume that property file is "ARG=VALUE" format and no space is allowed on either side of \"=\" """
   def __init__(self, pfile):
       self.items = {}
   
       for line in file(pfile):
           line = line.strip()
           if not line: continue
           if line.startswith(‘#‘): continue
           key, value = line.split(‘=‘, 1)
           self.items[key.strip()] = value.strip()
   
   def getdict(self):
       return self.items


if __name__ == "__main__":
   print "Self Test Begin"
   # Generate the test file
   if len(sys.argv) == 1:
       os.system("echo # Comment > test.properties")
       os.system("echo LOCK=true >> test.properties")
       os.system("echo TEST.config.1=234 >> test.properties")
       pf = Ini("test.properties");
   else:
       pf = Ini(sys.argv[1])
   print pf.getdict()

這里最后我的生成test.properties與原程序不同,因?yàn)榘l(fā)現(xiàn)在里面的雙引號也輸出到文件中去了,因此我去掉了。

下面是我根據(jù)sakulagi的思路改寫的程序:

#! /usr/bin/python

import os
import sys

class Ini:
   """ Assume that property file is "ARG=VALUE" format and no space is allowed on either side of \"=\" """
   def __init__(self, pfile):
       self.items = {}
   
       for line in file(pfile):
           line = line.strip()
           if not line: continue
           if line.startswith(‘#‘): continue
           key, value = line.split(‘=‘, 1)
           self.items[key.strip()] = value.strip()
   
   def getdict(self):
       return self.items


if __name__ == "__main__":
   print "Self Test Begin"
   # Generate the test file
   if len(sys.argv) == 1:
       os.system("echo # Comment > test.properties")
       os.system("echo LOCK=true >> test.properties")
       os.system("echo TEST.config.1=234 >> test.properties")
       pf = Ini("test.properties");
   else:
       pf = Ini(sys.argv[1])
   print pf.getdict()

這里最后我的生成test.properties與原程序不同,因?yàn)榘l(fā)現(xiàn)在里面的雙引號也輸出到文件中去了,因此我去掉了。

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
WINCE 文本讀寫操作總結(jié) .
windows service程序的入門范例(一)
Java中Properties類的使用
PHP 命令行下的世界
php中代碼開始標(biāo)志類型(<?php ?>,<? ?>,<?= ?&g...
Linux創(chuàng)建文件的5種方式
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服