0

I am newbie to python so please ignore if this is stupid. Here, I am getting Invalid syntax while printing the data in some specified format.

with open("ip_services.xyz", "w") as handle:
    for service in sorted(...some functionality...)):
        print("ip_server(\"{}\", {}, {}, {}, {}, {}, {}) # {}, {}".format(
            service.address, service.port, 1 if service.udp else 0,
            service.service_id, service.instance_id,
            service.major_version, service.minor_version,
            service.xyz,
            service.service_name),
              file=handle)

Error is like :-

  File "producer.py", line 220
    print("{} = \"{}\" # {}".format(signal, value, label), file=handle)
                                                               ^
SyntaxError: invalid syntax
3
  • If you are a newbie, probably better to just start with Python3 since that seems to be the code that you maybe copied Commented Oct 18, 2016 at 8:14
  • Not copied but need to run some years old written code. Commented Oct 18, 2016 at 8:23
  • Well, this file=handle syntax is written for Python3 was my point. Python3 was released 8 years ago, so my point still stands Commented Oct 18, 2016 at 8:30

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.