Mar-03-2024, 02:25 PM
hi
code:
the code is run truly and creates a file as "memory_graph.gv.pdf"
if I run again the code, because of the presence above file in the same directory, errors appear. because the number of error lines is larger than 30, so I do not include it here.
I want to delete the mentioned file before the memory_graph.show(locals()) line is run, so I write the if block to delete the file. but the below error appears:
thanks
code:
# from:https://pypi.org/project/memory-graph/
'''
custom copy method
We can write our own custom copy function or method in case the
three "copy" options don't do what we want. For example the
copy() method of My_Class in the code below copies the numbers
but shares the letters between the two objects.
'''
import memory_graph
import copy
import os
class My_Class:
def __init__(self):
self.numbers = [1, 2]
self.letters = ['a', 'b']
def copy(self): # custom copy method copies the numbers but shares the letters
c = copy.copy(self)
c.numbers = copy.copy(self.numbers)
return c
a = My_Class()
b = a.copy()
print(a.numbers,b.numbers)
print(a.letters,b.letters)
a.numbers=[100,100]
print(a.numbers,b.numbers)
print(a.letters,b.letters)
a.letters[0]='a_changed'
print(a.numbers,b.numbers)
print(a.letters,b.letters)
myfile="memory_graph.gv.pdf"
if os.path.isfile(myfile):
os.remove(myfile)
memory_graph.show(locals())first, consider the above code and comment on the if condition and its block.the code is run truly and creates a file as "memory_graph.gv.pdf"
if I run again the code, because of the presence above file in the same directory, errors appear. because the number of error lines is larger than 30, so I do not include it here.
I want to delete the mentioned file before the memory_graph.show(locals()) line is run, so I write the if block to delete the file. but the below error appears:
Error:Traceback (most recent call last):
File "D:\akb_python\akb_py_projects\memory_graph\custom_copy.py", line 38, in <module>
os.remove(myfile)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'memory_g
raph.gv.pdf'what can I do to correct the code?thanks
