I'm trying to copy either an integer or a dictionary, using the same line of code. I need 2 instances of the integer/dict.
My line of code is something like:
dict['item1'] = dict['item2'].copy
However, when it's an integer, I get this:
AttributeError: 'int' object has no attribute 'copy'
Any idea what the cause is?
use the copy
method from the copy
module rather than a method access on the item.
import copy
dict['item1'] = copy.copy(dict['item2'])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With