提问人:Don Cheadle 提问时间:11/4/2023 最后编辑:Don Cheadle 更新时间:11/5/2023 访问量:62
来自条件的矛盾控制台消息和其他奇怪的行为
Contradictory console messages and other weird behavouirs from conditionals
问:
我的 Notepad++ 脚本遍历每个文件,并检查可用于相应地调整文件的可能正则表达式模式。
# encoding=utf-8
from Npp import *
import re
import os
history_files = 'C:/Program Files (x86)/Steam/steamapps/common/Europa Universalis IV/history/countries'
base_tech = 3
def replace(percentage):
amount = float((100 - percentage) * 0.01)
editor.rereplace(r'(?<=adm_tech = )(\d+)|(?<=dip_tech = )(\d+)|(?<=mil_tech = )(\d+)', str(int(round(base_tech * ((((float(value.group(0)) / base_tech) - 1) * amount) + 1)))));
notepad.save()
def adjust():
notepad.open(history_files+'\\'+country_file)
colonial = re.search(r'(?<=.)(is_former_colonial_nation = yes)|(?<=.)(is_colonial_nation = yes)', editor.getText())
tech_group = re.search(r'(?<=technology_group = )(\w+)', editor.getText())
notepad.close()
if tech_group.group(0) == 'western' or colonial:
notepad.close()
console.write('\nClosed: "' + filename + '" because of "western" or "colonial"')
elif tech_group.group(0) == 'eastern':
replace(20)
for (filename, bufferID, index, view) in notepad.getFiles():
notepad.activateBufferID(bufferID)
pattern = re.compile(r'(?<=adm_tech = )(\d+)|(?<=dip_tech = )(\d+)|(?<=mil_tech = )(\d+)')
value = pattern.search(editor.getText())
mission_tag = re.search(r'\s*potential = \{[\s\S]*(?<=tag = )(\w+)', editor.getText())
religion_group = re.search(r'\s*potential = \{[\s\S]*(?<=religion_group = )(\w+)', editor.getText())
for country_file in os.listdir(history_files):
if mission_tag and re.match(mission_tag.group(1), country_file):
adjust()
console.write('\nMatched mission_tag and country_file for: "' + filename + '"')
if religion_group and not mission_tag:
if religion_group.group(1) == 'christian':
notepad.close()
console.write('\nClosed: "' + filename + '" because of "christian"')
elif religion_group.group(1) == 'dharmic':
replace(40)
elif mission_tag:
console.write('\nCould not match "' + filename + '" to any country_file')
elif not religion_group and not mission_tag:
console.write('\nNo identifiers found in: ' + filename)
在其他奇怪的行为中,为什么我在控制台中收到这样的矛盾消息?
Closed: "C:\Users\JB452503\Documents\files test\missions\DOM_French_Missions.txt" because of "western" or "colonial"
Matched mission_tag and country_file for: "C:\Users\JB452503\Documents\files test\missions\DOM_French_Missions.txt"
Could not match "C:\Users\JB452503\Documents\files test\missions\DOM_French_Missions.txt" to any country_file
如果它只是关闭文件,它如何匹配文件的内容?它怎么可能有匹配,也没有匹配?
每次出现竞争条件后,我都尝试过,但没有任何作用。我几乎可以肯定我的逻辑有问题。time.sleep(0.5)
notepad.close()
答: 暂无答案
评论
\n
Matched mission_tag and country_file for:
Notepad.close()
Notepad.close()