Reputation: 69
the following file is located in this directory: /Users/whiteglider/Documents
name of file: server.py
this is my practice code which i just copied from http://www.tutorialspoint.com/python/python_networking.htm
import socket
s=socket.socket()
host=socket.gethostname()
port=12345
s.bind((host,port))
s.listen(5)
while True:
c, addr = s.accept()
print 'Got connection from', addr
c.send ('Thank you for connecting')
c.close()
when i run it at Terminal, i type
$ python /Users/whiteglider/Documents/server.py
then i get:
File "/Users/whiteglider/Documents/server.py", line 1
{\rtf1\ansi\ansicpg1252\cocoartf949\cocoasubrtf540
^
SyntaxError: unexpected character after line continuation character
even if i change directory going to where the server.py file actually is and run
python server.py
i still get the same result.
(mac leopard 10.5.8)
Upvotes: 4
Views: 1977
Reputation: 176930
You've saved the file as a Rich Text Format file rather than a plain text file.
I don't know what editor you're using, but make sure to save the file as plain text / ASCII text, something like that, not RTF.
Upvotes: 8
Reputation: 11134
The 'line continuation character' is typically a backslash at the end of a line. However, I don't see any in your example.
Can you run a simple 'hello world' app, like the following?
print 'hello world'
(save the above in the file hello.py, and run)
Does python run fine from an interactive prompt?
Possibly related: what kind of line endings does your file have? '\n' or '\r\n'? I don't think it should matter, but who knows...
Upvotes: 0