小编Van*_*Gez的帖子

TypeError:强制转换为Unicode,需要字符串或缓冲区,找到NoneType

目前为程序编写函数,一个组件是搜索python文件中是否正在使用单个变量.

功能:

def SINGLE_CHAR_VAR(python_filename):
    file = open(python_filename)
    lines = [0]
    SINGLE_CHAR_VAR = []
    for line in file:
        stripped = line.strip('\n\r')
        lines.append(stripped)

    from utils import vars_indents
    variable_list = (vars_indents(python_filename))[0]
    for i in range(1, len(variable_list)):
        if len(variable_list[i][0][0]) == 1:
            SINGLE_CHAR_VAR.append(['SINGLE_CHAR_VAR', i, variable_list[i][0][1], variable_list[i][0][0], lines[i]])      
    return SINGLE_CHAR_VAR?
Run Code Online (Sandbox Code Playgroud)

当我单独使用该功能时 - 该功能正常工作.但是,当我作为一个整体调用该程序时 - 我收到以下错误消息:

Traceback (most recent call last):
  File "<web session>", line 1, in <module>
  File "lint_2.py", line 141, in lint
    sorted_error_list = sorted_list(list_of_file_errors)
  File "lint_2.py", line 84, in sorted_list
    error_list = total_error_list(python_filename)
  File …
Run Code Online (Sandbox Code Playgroud)

python function typeerror traceback nonetype

5
推荐指数
1
解决办法
3万
查看次数

标签 统计

function ×1

nonetype ×1

python ×1

traceback ×1

typeerror ×1