2021年5月1日星期六

Reversing a global variable within function -- Python

closes = []    def check_indicator():      global closes      closes.reverse()      print(closes)      connection = psycopg2.connect(      host='localhost',      database='postgres',      user='postgres',      password='pass'  )  connection.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)  cur = connection.cursor()    cur.execute('select closeprice from candles order by datetime desc limit 54')  closes.extend(cur.fetchall())    check_indicator()  

When running the code above I get an unreversed list of closes what causes that to occur? I have already declared global closes inside the function. However, when I declare a variable that depends on closes inside the function like this one reversed_closes = closes.reverse() this returns with None

https://stackoverflow.com/questions/67332391/reversing-a-global-variable-within-function-python April 30, 2021 at 06:32PM

没有评论:

发表评论