Hiện tại, viết một hàm cho một chương trình và một thành phần là tìm kiếm xem một biến duy nhất có đang được sử dụng trong tệp python hay không.LoạiError: liên kết với Unicode, cần chuỗi hoặc bộ đệm, NoneType tìm thấy
CHỨC NĂNG:
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
Khi tôi sử dụng các chức năng của bản thân - các chức năng hoạt động đúng. Tuy nhiên khi tôi kêu gọi các chương trình như một toàn thể - tôi nhận được thông báo lỗi sau:
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 "lint_2.py", line 65, in total_error_list
single_char_var_list = SINGLE_CHAR_VAR(python_filename)
File "lint_2.py", line 33, in SINGLE_CHAR_VAR
file = open(python_filename)
TypeError: coercing to Unicode: need string or buffer, NoneType found
Tôi hoàn toàn không có ý tưởng - nơi tôi sẽ sai - bất kỳ trợ giúp sẽ được rất, rất, rất yêu mến !! !
cảm ơn.
Có thể liên quan: [ép buộc sang Unicode: cần chuỗi hoặc đệm, NoneType tìm thấy khi render trong Django admin] (http: // stackoverflow. com/q/16169035/608639) và [TypeError: liên kết với Unicode: cần chuỗi hoặc bộ đệm, NoneType được tìm thấy] (http://stackoverflow.com/q/24506928/608639). – jww