Skip to content

Commit

Permalink
Adapt print statements in examples for Python 3 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
ysitu committed Jun 25, 2014
1 parent 1157023 commit 8cf2b96
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions examples/algorithms/rcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@
# build low-bandwidth numpy matrix
G=nx.grid_2d_graph(3,3)
rcm = list(reverse_cuthill_mckee_ordering(G))
print "ordering",rcm
print("ordering",rcm)

print("unordered Laplacian matrix")
A = nx.laplacian_matrix(G)
x,y = np.nonzero(A)
#print("lower bandwidth:",(y-x).max())
#print("upper bandwidth:",(x-y).max())
print("bandwidth: %d"%((y-x).max()+(x-y).max()+1))
print A
print(A)

B = nx.laplacian_matrix(G,nodelist=rcm)
print("low-bandwidth Laplacian matrix")
x,y = np.nonzero(B)
#print("lower bandwidth:",(y-x).max())
#print("upper bandwidth:",(x-y).max())
print("bandwidth: %d"%((y-x).max()+(x-y).max()+1))
print B
print(B)

2 changes: 1 addition & 1 deletion examples/drawing/giant_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from networkx import graphviz_layout
layout=nx.graphviz_layout
except ImportError:
print "PyGraphviz not found; drawing with spring layout; will be slow."
print("PyGraphviz not found; drawing with spring layout; will be slow.")
layout=nx.spring_layout


Expand Down
8 changes: 4 additions & 4 deletions examples/drawing/lanl_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def lanl_graph():
try:
fh=open('lanl_routes.edgelist','r')
except IOError:
print "lanl.edges not found"
print("lanl.edges not found")
raise

G=nx.Graph()
Expand Down Expand Up @@ -52,9 +52,9 @@ def lanl_graph():

G=lanl_graph()

print "graph has %d nodes with %d edges"\
%(nx.number_of_nodes(G),nx.number_of_edges(G))
print nx.number_connected_components(G),"connected components"
print("graph has %d nodes with %d edges"\
%(nx.number_of_nodes(G),nx.number_of_edges(G)))
print(nx.number_connected_components(G),"connected components")

import matplotlib.pyplot as plt
plt.figure(figsize=(8,8))
Expand Down
12 changes: 6 additions & 6 deletions examples/pygraphviz/write_dotfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
try:
m=NX.drawing.write_dot.__module__
except:
print
print "pygraphviz or pydot were not found "
print "see https://networkx.lanl.gov/Drawing.html for info"
print
print()
print("pygraphviz or pydot were not found ")
print("see https://networkx.lanl.gov/Drawing.html for info")
print()
raise

print "using module", m
print("using module", m)


G=NX.grid_2d_graph(5,5) # 5x5 grid
NX.write_dot(G,"grid.dot")
print "Now run: neato -Tps grid.dot >grid.ps"
print("Now run: neato -Tps grid.dot >grid.ps")

0 comments on commit 8cf2b96

Please sign in to comment.