为什么函数的主体不能从从 txt 文件中读取的变量工作?

Why doesn't the body of the function work from a variable read from a txt file?

提问人:John Stendreen 提问时间:10/19/2023 更新时间:10/19/2023 访问量:34

问:

我有一个为字符串着色的函数

def hightlight_multy(row): 
    ret = ["" for _ in row.index]
    if row.row_1 == 1: 
        ret[row.index.get_loc("date_1")] = "background-color: blue" 
    return ret

我将函数中的一行放入 txt 文件中。我正在读取一个 txt 文件并将此行分配给变量self.func_text

def __init__(self,
             func_text
             ):
    self.func_text = func_text

当我运行下面的更正函数时,该函数不会为行着色。该命令打印文本:if row.row_1 == 1: ret[row.index.get_loc("date_1")] = "background-color: blue"

def hightlight_multy(row): 
    ret = ["" for _ in row.index]
    self.func_text
    print(str(self.func_text))
    return ret

为什么函数的主体不能从从 txt 文件中读取的变量工作?

def hightlight_multy(row): 
    ret = ["" for _ in row.index]
    self.func_text
    print(str(self.func_text))
    return ret
python-3.x 字符串 函数 变量 init

评论

0赞 Ignatius Reilly 10/19/2023
您在代码中的哪个位置从 txt 文件中读取?或者将该文件中的任何内容分配给函数?什么是,方法在做什么?请发布您的问题的最小可重现示例row.row_1

答: 暂无答案