SyntaxError: invalid syntax (windows)

Python Newsgroup chris at
Wed Mar 25 16:39:20 CET 2009

I'm a total newbe to scripting not to mention python. However I was able to 
successfully create a telnet script to initiate login, initiate tftp, exit, 
exit, confirm and close session. Frustrated, possibly causing my own misery. 
I replace the sript the script with the standard example.

import getpass
import sys
import telnetlib

HOST = "remote linux"
user = raw_input("Enter your remote account: ")
password = getpass.getpass()

tn = telnetlib.Telnet(HOST)

tn.read_until("login: ")
tn.write(user + "\n")
if password:
    tn.read_until("Password: ")
    tn.write(password + "\n")


print tn.read_all()

Regardless of the script content, running in windows I constently get this 

C:\Python30>python c:\Python30\scripts\
  File "c:\Python30\scripts\", line 20
    print tn.read_all()
SyntaxError: invalid syntax


The same script works fine from linux.

I have also notices some other slight differences: this is my original 
script that runs and completes but only if I comment out print. Also tried 
to run debug without success in windows again this worked fine in linux. To 
run this script in linux I also had to remove the b syntax in the "b" in the 

import telnetlib
# import pdb

HOST = "HP switch"

tn = telnetlib.Telnet(HOST)

tn.read_until(b'Password: ')


tn.read_until(b'HP switch# ')
tn.write(b' sh time\n')

tn.read_until(b'HP switch# ')

tn.read_until(b'HP switch> ')

tn.read_until(b'Do you want to log out [y/n]? ')

print tn.read_all()

Any guidance would be appreciated.


More information about the Python-list mailing list