Re: try... except SyntaxError: unexpected EOF while parsing
- From: kyosohma@xxxxxxxxx
- Date: 4 Apr 2007 10:46:21 -0700
On Apr 4, 12:38 pm, "oscartheduck" <oscarthed...@xxxxxxxxx> wrote:
I have a small script for doing some ssh stuff for me. I could have
written it as shell script, but wanted to improve my python skills
some.
RIght now, I'm not catching a syntax error as I'd like to.
Here's my code:
#!/usr/bin/env python
import sys
import os
port = input("Please enter a port to connect on. If you're unsure or
just want the default of port 2024 just hit enter -- ")
try:
if port > 65535:
print "That's not a valid port number, sorry. Between 0 and 65535
is cool."
sys.exit()
else:
cmd = 'su root -c "/usr/sbin/sshd -p %s"' % port
except SyntaxError:
cmd = 'su root -c "/usr/sbin/sshd -p 2024;exit"'
os.system(cmd)
I'm under the impression that the except should catch the syntax error
and execute the "default" command, but hitting enter at the input
value doesn't lead to that. Any ideas what's going wrong?
Try sticking your
port = input("Please enter a port to connect on. If you're unsure or
just want the default of port 2024 just hit enter -- ")
inside your "try" block instead. Or switch to using the "raw_input"
builtin instead of "input".
Mike
.
- References:
- try... except SyntaxError: unexpected EOF while parsing
- From: oscartheduck
- try... except SyntaxError: unexpected EOF while parsing
- Prev by Date: Re: Write to a binary file
- Next by Date: Re: Write to a binary file
- Previous by thread: try... except SyntaxError: unexpected EOF while parsing
- Next by thread: Re: try... except SyntaxError: unexpected EOF while parsing
- Index(es):
Relevant Pages
|
|