Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: 'int' object has no attribute 'copy'

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?

like image 536
User Avatar asked Nov 30 '22 20:11

User


1 Answers

use the copy method from the copy module rather than a method access on the item.

import copy

dict['item1'] = copy.copy(dict['item2'])
like image 185
Andrew Jaffe Avatar answered Dec 04 '22 14:12

Andrew Jaffe