python - Do datetime objects need to be deep-copied? -
so noticed other week through running experiment, that, despite being high-level language, while can make copies of variables assigning them this:
a = 5 b = print(b) # 5 b = 3 print(b) # 3 print(a) # 5
...if treat dictionaries or possibly lists same way, comes unstuck! created bug in code other week thinking dictionaries worked same way.. found out make proper, deep copy need go:
b = dict(a)
anyway, i'm busy datetime objects , i'm manipulating them around if integers, starting bit nervous whether okay. seems bit arbitrary works , doesn't, have run experiment every time check behaviour? can guess strings work integers not sure behaviour changes.
can see has asked about php python i'm inclined think assignment of datetime object proper, deep copy , never mess accidentally original variable. know sure?
since available types in datetime
module documented being immutable (right after documentation of classes stated):
objects of these types are immutable.
you shouldn't worry this.
operations on datetime instance return new instance thereby not affecting other names refer previous one.
you might want take @ link provided pm 2ring explains facts , myths how names , values work. should shed light on confusions have names.
Comments
Post a Comment