1 Star 0 Fork 0

TestDev/PythonTest

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Properties.py 999 Bytes
一键复制 编辑 原始数据 按行查看 历史
TestDev 提交于 2019-02-18 16:20 +08:00 . 格式修复
import os
import platform
# 编写一个类实现文件相对路径读取功能
class Properties:
def __init__(self, filename, isroot):
self.filename = filename
self.isroot = isroot
def getfilepath(self):
if self.isroot:
if platform.system() == "Windows":
return os.path.abspath("..") + "\\" + self.filename
else:
return os.path.abspath("..") + "/" + self.filename
else:
if platform.system() == "Windows":
return os.path.abspath(".") + "\\" + self.filename
else:
return os.path.abspath(".") + "/" + self.filename
def getProperties(self):
properties = {}
filepath = self.getfilepath()
lines = open(filepath, "r").readlines()
for line in lines:
if line.find('=') > 0:
strs = line.replace('\n', '').split('=')
properties[strs[0]] = strs[1]
return properties
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/testdevops/PythonTest.git
git@gitee.com:testdevops/PythonTest.git
testdevops
PythonTest
PythonTest
master

搜索帮助