我正在尝试将数据库名称从一个名为 /etc/oratab 的文件中分离出来:#CommendsDBNAME1:/opt/oracle/product/19000/db:NDBNAME2:/opt/oracle/product/19000/db:N以下代码仅返回 DBNAME1:def oratab(): dblist=[] flag=False with open('/etc/oratab', 'r') as oratab: for line in oratab: if line and line[0].isalpha(): flag=True if flag: dblist.append(line) return ''.join(dblist).split(':')[0]如何更改脚本以获取 DBName 的完整列表?
1 回答
白衣非少年
TA贡献1155条经验 获得超0个赞
您dblist是列表,lines并且您想从splitnot 行返回第一个元素dblist。
','.join(dbline.split(':')[0] for bdline in dblist)
我认为你需要返回列表中的listofdatabase names如果是这样删除join并返回return dblist
更好的:
def oratab():
dblist=[]
with open('/etc/oratab', 'r') as oratab:
for line in oratab:
if line and line[0].isalpha():
dblist.append(line.split(':')[0])
return ','.join(dblist)
或者更短
def oratab():
dblist = []
with open('/etc/oratab', 'r') as oratab:
dblist = [line.split(':')[0] in oratab if line and line[0].isalpha()]
return ','.join(dblist)
添加回答
举报
0/150
提交
取消