New submission from Joona Mörsky <joonamorsk...@gmail.com>: When creating list of dictionaries and updating datetime objects one by one, all values are set to last one of the list.
Ubuntu Linux 4.10.0-40-generic #44~16.04.1-Ubuntu SMP Thu Nov 9 15:37:44 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux Python 3.5.2 >>>import datetime >>>b = datetime.datetime.utcnow() >>>b = >>>b.replace(hour=0,minute=0,second=0,microsecond=0,tzinfo=datetime.timezone.utc) >>>a = [{}] * 3 >>>for inx in range(3): ... a[inx]['time'] = b + datetime.timedelta(minutes=inx*10) [{'time': datetime.datetime(2017, 12, 1, 0, 20, tzinfo=datetime.timezone.utc)}, {'time': datetime.datetime(2017, 12, 1, 0, 20, tzinfo=datetime.timezone.utc)}, {'time': datetime.datetime(2017, 12, 1, 0, 20, tzinfo=datetime.timezone.utc)}] >>>import datetime >>>b = datetime.datetime.utcnow() >>>b = >>>b.replace(hour=0,minute=0,second=0,microsecond=0,tzinfo=datetime.timezone.utc) >>>a = [ ] >>>for inx in range(3): ... a.append({"time": b + datetime.timedelta(minutes=inx*10)}) [{'time': datetime.datetime(2017, 12, 1, 0, 0, tzinfo=datetime.timezone.utc)}, {'time': datetime.datetime(2017, 12, 1, 0, 10, tzinfo=datetime.timezone.utc)}, {'time': datetime.datetime(2017, 12, 1, 0, 20, tzinfo=datetime.timezone.utc)}] ---------- components: Interpreter Core messages: 307382 nosy: Joona Mörsky priority: normal severity: normal status: open title: When creating list of dictionaries and updating datetime objects one by one, all values are set to last one of the list. type: behavior versions: Python 3.5 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue32194> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com