0

I want to show the graph using the python code below, but I am getting a syntax error as seen on the image. Please help to correct this error. I am using Python 3

import os
import sys
import fnss
import networkx as nx
import fnss
import cvxopt
import numpy as np
import codecs
import random
import matplotlib.pyplot as plt
topo_str = 'topo_peter.xml'
topology = fnss.read_topology(topo_str)
topology_directed = topology.to_directed(topology)
print nx.info(topology_directed)
nx.draw(topology_directed)
plt.show()

and this is the am getting

File "<ipython-input-1-fa7157dd7268>", line 14
print nx.info(topology_directed)
      ^
SyntaxError: invalid syntax
gehbiszumeis
  • 3,525
  • 4
  • 24
  • 41
  • 2
    It's generally a better idea to include your code directly in your post than to post an image of it. Remember that you can use the built-in formatting tools to make the code snippet show up as a snippet. Make sure to only include the parts of your code that are relevant to the error you're seeing! – aaaaaa123456789 Nov 09 '18 at 07:03
  • Are you using python 2.7 or 3.x? – Joel Nov 09 '18 at 07:42
  • @joel python 3.7 –  Nov 09 '18 at 07:50
  • 1
    Change `print nx.info(topology_directed)` to `print(nx.info(topology_directed))`. – swatchai Nov 09 '18 at 09:50
  • Possible duplicate of [brackets around print in python](https://stackoverflow.com/questions/13415181/brackets-around-print-in-python) – Joel Nov 10 '18 at 08:12

1 Answers1

0

Based on the information provided:

Python version: 3
Error message: invalid syntax on line 14 -> print nx.info(topology_directed)

It is clearly a simple syntax error for people using Python 3 to execute a Python 2 statement.

print "something"  # is valid for Python 2, but not Python 3

For Python 3, use

print("something", "and more", "even more")

So changing print nx.info(topology_directed) to print(nx.info(topology_directed)) solves the problem.

swatchai
  • 17,400
  • 3
  • 39
  • 58