name 'Graph' is not defined
Since I have many of my own functions, I plan to organize them into separate modules according to their functionality for easier reuse. I performed the following test by first creating a file zg.py, which contains:
def create_graph():
G = Graph()
G.add_edges([(0, 1), (1, 2), (2, 3), (3, 0)])
return G
When I create a new Sage file and try to call it, the following error appears. Why is this happening? Can't Sage's own functions be used in zg.py?
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[4], line 2
1 from zg import create_graph
----> 2 create_graph()
File /mnt/d/sage_zhang/new_fun/zg.py:2, in create_graph()
1 def create_graph():
----> 2 G = Graph()
3 G.add_edges([(0, 1), (1, 2), (2, 3), (3, 0)])
4 return G
NameError: name 'Graph' is not defined