Deepcopy does not work.
Using Thonny Micropython on PICO.
Copy.py is NOT on the UF2 file for PICO - as much as the docs seem to reflect.
Copied Copy.py from site here.
Can not copy Instances :
Error: un(deep)copyable object of type <class 'counterObject'>
Simple examples do NOT work.
If Standard documented Features / Cmds don't work here , then what good is the MicroPython ???
I have invested in using this for Programs for robots that I build.
So far the OOPS Objects Structuring here - is pretty much Trash - without the ability to copy Objects.
- JAVA has no problem with this, what's the Problem here ???
StackOverflow ex :
https://stackoverflow.com/questions/42143461/make-copy-of-object-instance-in-python
class counterObject:
def __init__(self):
self.Value = 0
def incrementValue(self):
self.Value += 1
def printValue(self):
print(self.Value)
A = counterObject()
A.incrementValue()
A.printValue() ##Prints 1
import copy
B = copy.deepcopy(A)
## => Error: un(deep)copyable object of type <class 'counterObject'>
print( id(A), id(B) )
Even the Google example does not work :
https://www.google.com/search?q=micropython+howto+create+object+then+copy+object
This returns :
=> Error: un(deep)copyable object of type <class 'MyClass'>
How to Create an ObjectYou define a class and then create an instance (object) of that class by calling the class name as a function.python
class MyClass:
def __init__(self, name, value):
[self.name](http://self.name/) = name
self.value = value
## Create an object (instance of the class)
original_object = MyClass("example", 100)
- Deep Copy (copy.deepcopy())A deep copy creates a completely independent clone of the original object, including recursively copying all nested objects and data structures. Changes to the copy will not affect the original.
import copy
## Create a deep copy
deep_copied_object = copy.deepcopy(original_object)
## => Error: un(deep)copyable object of type <class 'MyClass'>