鱼C论坛

 找回密码
 立即注册
查看: 359|回复: 2

[已解决]关于读取配置文件内容

[复制链接]
发表于 2018-8-3 20:52:04 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
#!/usr/bin/env python3
import sys
import csv

class Args():
        def __init__(self):
               
                self.args = sys.argv[1:]
                #print(self.args)
                index = self.args.index('-c')
                self.configfile = self.args[index+1]
                #print(self.configfile)
                index = self.args.index('-d')
                self.userfile = self.args[index+1]
                index = self.args.index('-o')
                self.gongzifile = self.args[index+1]
                print(self.gongzifile)
               
               
                       
args1 = Args()



class Config(object):
        def __init__(self):
                print(8888)
                self.config = self._read_config()
        def _read_config(self):
                config = {'s',0}
                with open(args1.configfile) as f1:
                       
                        for line in f1.readline():
                                print(line)
                                m = line.split('=')
                                print(m)

config = Config()


我想读取 某个目录下 test.cfg 文件的内容  但是这段代码编译后显示不对  配置文件格式是 100:3000
最佳答案
2018-8-3 21:02:15

  1. #!/usr/bin/env python3
  2. import sys
  3. import csv

  4. class Args():
  5.         def __init__(self):
  6.                
  7.                 self.args = sys.argv[1:]
  8.                 #print(self.args)
  9.                 index = self.args.index('-c')
  10.                 self.configfile = self.args[index+1]
  11.                 #print(self.configfile)
  12.                 index = self.args.index('-d')
  13.                 self.userfile = self.args[index+1]
  14.                 index = self.args.index('-o')
  15.                 self.gongzifile = self.args[index+1]
  16.                 print(self.gongzifile)
  17.                
  18.                
  19.                         
  20. args1 = Args()



  21. class Config(object):
  22.         def __init__(self):
  23.                 print(8888)
  24.                 self.config = self._read_config()
  25.         def _read_config(self):
  26.                 config = {'s',0}
  27.                 with open(args1.configfile) as f1:
  28.                         
  29.                         for line in f1.readline():
  30.                                 print(line)
  31.                                 m = line.split('=')
  32.                                 print(m)

  33. config = Config()
  34. config.config()
复制代码

你好像根本就没有获取嘛。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-8-3 21:02:15 | 显示全部楼层    本楼为最佳答案   

  1. #!/usr/bin/env python3
  2. import sys
  3. import csv

  4. class Args():
  5.         def __init__(self):
  6.                
  7.                 self.args = sys.argv[1:]
  8.                 #print(self.args)
  9.                 index = self.args.index('-c')
  10.                 self.configfile = self.args[index+1]
  11.                 #print(self.configfile)
  12.                 index = self.args.index('-d')
  13.                 self.userfile = self.args[index+1]
  14.                 index = self.args.index('-o')
  15.                 self.gongzifile = self.args[index+1]
  16.                 print(self.gongzifile)
  17.                
  18.                
  19.                         
  20. args1 = Args()



  21. class Config(object):
  22.         def __init__(self):
  23.                 print(8888)
  24.                 self.config = self._read_config()
  25.         def _read_config(self):
  26.                 config = {'s',0}
  27.                 with open(args1.configfile) as f1:
  28.                         
  29.                         for line in f1.readline():
  30.                                 print(line)
  31.                                 m = line.split('=')
  32.                                 print(m)

  33. config = Config()
  34. config.config()
复制代码

你好像根本就没有获取嘛。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-8-3 21:06:03 | 显示全部楼层
无符号整形 发表于 2018-8-3 21:02
你好像根本就没有获取嘛。

谢谢 老师 我竟然 没获取类里面的方法
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-17 16:52

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表