python 字符串比较返回相同_Python用fals比较两个相同的字符串返回值

我将在下面介绍我的一些代码来解释这个问题,但基本上我要做的是在一个函数中进行比较-一个字符串&一个只包含该字符串的行。在

我的名单如下:org_tasks = ['general_static ', 'host_general_static ',etc....]

我用文件名(python文件)传递给函数

^{pr2}$

这就叫:def getTransformedDic(prm_fl,dic_name): # transforms string to dictionary

"turns dictionary values from type variable into a string"

newDic = ""

dicToChange = getOldDicAsString(prm_fl,dic_name)

if dicToChange is None: return None

dicToChange = dicToChange[len(dic_name) + 3:] #here i get none for some reason

dicToChange = dicToChange.replace('"', "'")

for line in dicToChange.splitlines():

transformedLine = ''.join(line.split())

transformedLine = transformedLine.strip()

if transformedLine.startswith('#'): continue

IsLineBelongsToDic = transformedLine.split(':')

if len(IsLineBelongsToDic) > 1:

if transformedLine[-1:] == ",":

valueAsString = '"%s",' % transformedLine[len(IsLineBelongsToDic[0]) + 1:-1]

else:

valueAsString = '"%s",' % transformedLine[len(IsLineBelongsToDic[0]) + 1:]

line = ' ' + IsLineBelongsToDic[0] + ' : ' + valueAsString

newDic += '%s' % line + '\n'

try:

value = ast.literal_eval(newDic[:-1])

except SyntaxError:

return None

else:

return value

def getOldDicAsString(prm_fl, dic_name):

"return a string that contains dictionary"

with open(prm_fl) as f:

file_data = f.read()

recordLines = False

dictionary = ""

for line in file_data.splitlines():

transformedLine = ''.join(line.split())

transformedLine = transformedLine.strip()

taskName = transformedLine.split('=')[0]

print taskName ,dic_name # here i can see they are the same

if taskName == dic_name or recordLines:

recordLines = True

dictionary += line + '\n'

if transformedLine == "}":

return dictionary

我使用的文件如下所示(根据我之前提到的列表):...

CurrentTaskParams.general_static = {

'is_enable' : 'true'

}

CurrentTaskParams.host_general_static = {

'is_enable' : 'true'

}

...

在添加了一些指纹之后,我看到了当我比较CurrentTaskParams.general_static

-->作为参数传递

到包含此字符串的行(从空格中分条(&'{&'='后)

我不附加字典字符串(意味着我的'if'返回false)

任何帮助都会很好,

谢谢!在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值