[英]Why is my function skipping lines of code in Python?
在此函數內部,在循環“ for j,我枚舉(數據)”內部,我有一個循環“ for g in reversed(range(j)):”,並且此循環追加到listx。
為了測試我得到的是有意義的數據,我將print(listx)
現在在附加循環的正下方,我有print(listx),但是它不起作用。 它根本不打印。 我也嘗試過print(“ Hello”)刪除任何變量,但也沒有打印“ Hello”。
是什么原因造成的?
def filter_json(input):
global d
global t
# open input file & load json data
content = open(input, "r").read()
data = np.array([json.loads(str(i)) for i in content.strip().split('\n')
if i.strip()])
# first extract D & T from the first line of data
d = int(data[0]['D'])
t = int(data[0]['T'])
listx = []
for j, i in enumerate(data):
try:
if i['event_type'] == 'purchase':
listx = []
l = Graph()
l.network = set()
l.IDDFS(i['id'], d)
network_list = l.network
for g in reversed(range(j)):
# if data[g]['id'] in network_list
listx.append(data[g]['amount'])
print(listx)
print('Hello')
elif i['event_type'] == 'befriend':
addEdge(i['id1'], i['id2'])
elif i['event_type'] == 'unfriend':
removeEdge(i['id1'], i['id2'])
except KeyError:
continue
這意味着您在代碼中得到了KeyError
,然后在except
忽略了它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.