I run MooseFS CGI Server based on Python in my RedHat server, and I get an weird syntax error:
Traceback (most recent call last):
File "/usr/sbin/mfscgiserv", line 300, in run_cgi
execfile(self.file_name)
File "/usr/share/mfscgi/mfs.cgi", line 129
return "%s%.1f%s" % (("~" if n != rn else ""),rn,s)
^
SyntaxError: invalid syntax
It is just the right file downloaded from moosefs offical site, and I can't find any error about it. My python's version is 2.4.3.
As Abhijit already said you can't use the conditional expression in python<2.5, but you can work around this in two simple ways:
Or:
The first one is safe because
"~"
is consideredTrue
and thus ifr != rn
then it is guaranteed that theand
will succeed and thus theor
will not evaluate the second expression.The second one uses the fact that a string multiplied by
1
(orTrue
) returns the string itself, while the string multiplied by0
(orFalse
) returns""
(the empty string).Edit: Since the error is generated by a file that is not in your control, you shouldn't modify its source code. The fact that the library uses Python's2.5 syntax simply means that it does not support Python 2.4.3 and you either have to change library or to upgrade your python installation.
Since python2.4.x was last released in the 2008, I think it'd a good idea to upgrade your python installation to python2.7.3. This should solve your problem and you'll get all the benefits of the newer version of python.