我在一个类中有一个静态方法,由该类的另一个静态方法调用并返回它应该创建的变量,但它似乎正在创建全局变量并在它应该返回时重新返回None < / p>
class LineHandler:
@staticmethod
def file_tocsv(_file):
line_number=0
csv_dict = {}
for linex in _file:
linex_dict = Utils._to_utf(kline)
csv_dict, line_number = LineHandler.line_tocsv(csv_dict, linex_dict, line_number)
@staticmethod
def line_tocsv(csv_dict={}, line={}, current_line=0):
csv_line, current_line = LineHandler.create_csv(current_line, kline)
if current_line in csv_dict:
csv_dict[current_line].update(csv_line)
else:
csv_dict[current_line] = csv_line
return csv_dict
@staticmethod
def create_csv(line_number, kline={}, csv_line={}):
#retval dict
bracket = kline.get('][',None)
text = kline.get('line',None)
star = kline.get('*',None)
at = kline.get('@',None)
string = ''; string2 = ''
if star:
string2, csv_line, is_newline = LineHandler._star( star, string2, csv_line)
line_number += is_newline
if at:
csv_line = LineHandler._effect(at, csv_line)
if bracket and text:
csv_line = LineHandler._text(bracket, csv_line, text)
return csv_line, line_number
正如我所说的那样,只要它进入第三个功能,csv_line var仍然存在而不是成为{} !!