Python SyntaxError: invalid syntax
<p>I received a Python command line program used for chess rating from a fellow chess lover, and find myself with the following syntaxError:</p>

<pre><code>File "skype-chess.py ", line 257
if cmd ==sss "rate " and len(single) &gt; 0:
^
SyntaxError: invalid syntax 
</code></pre>

<p>Here is the code.
File:  skype-chess.py" </p>

<pre><code>###Skype-Chess utility program,
###Written by Johannes Grib
import os,sys,string,re,itertools,csv,time
import class_chess as chess
members = {}
tt = []
report = []
cmd = ""
source = ""
white,black,name,r = "","","",""
rw,rb,ww,lw,dw,wb,lb,db = 0,0,0,0,0,0,0,0
state,newState = 0,0
rating = 0
line = ""
def addGame(single):
  single = "\n" + single
  f = file('c:/chess/ftp-chess/alltts.csv', "a")
  f.write(single)
  f.close()
  return

def statLine(ww,lw,dw,wb,lb,db):
  statline = ""
  if (ww+lw+dw) &gt; 1:
    statline = statline + "white games: "
  elif (ww+lw+dw) == 1: 
    statline = statline + "white game:  "
  if ww &gt; 0:
    statline = statline + "win %s, " % (str(ww))
  if lw &gt; 0:
    statline = statline + "lose %s, " % (str(lw))
  if dw &gt; 0:
    statline = statline + "draw %s." % (str(dw))
  statline = statline + "\n"
  if (wb+lb+db) &gt; 1:
    statline = statline + "black games: "
  elif (wb+lb+db) == 1: 
    statline = statline + "black game:  "
  if wb &gt; 0:
    statline = statline + "win %s, " % (str(wb))
  if lb &gt; 0:
    statline = statline + "lose %s, " % (str(lb))
  if db &gt; 0:
    statline = statline + "draw %s." % (str(db))
  statline = statline + "\n"

  return statline

def stats(p):
  line = ""
  name = p[1].strip("'")
  ww = int(members[name][0][3])
  lw = int(members[name][0][4])
  dw = int(members[name][0][5])
  wb = int(members[name][0][6])
  lb = int(members[name][0][7])
  db = int(members[name][0][8])
  total = ww + lw + dw + wb + lb + db
  if total &gt; 1:
    line = "\n  played a total of %s games\n" % (str(total))
  else:
    line = "\n  played a total of %s game\n" % (str(total))

  line += statLine(ww,lw,dw,wb,lb,db)
  line = line.strip("[")
  line = line.strip("]")
  #line = line.replace(" .",".")
  line = line.strip("2011")
  line = line.strip("'")
  return line

def report(single, members):
  #evaluate single
  report = []
  #convert members to a list
  tmp = ""
  i = 1
  for m in members:
    report.append([int(members[m][0][2]),members[m][0][1],members[m][0][0]])
  report.sort()
  report.reverse() 
  if single == "all":
    for p in report:
      print i,". ",str(p)    
      line = stats(p)
      #line = line.replace(" [","")
      #line = line.replace("'","")
      #line = line.replace("]","")
      #line = line.replace(" .",".")
      print line
      i += 1
  else:
    for p in report:
      if p[2] == single:
        print i,". ",str(p)
        line = stats(p)
        #line = line.replace(" [","")
        #line = line.replace("'","")
        #line = line.replace("]","")
        #line = line.replace(" .",".")
        print line
        i += 1
  return

def getMember(t, members):
  #print t
  y = 0
  t = string.split(t,",") #.rstrip()
  white = t[0]
  black = t[1]
  r = t[2]
  state = t[3].strip()
  rw = int(members[white][0][2])
  rb = int(members[black][0][2])
  #print white, "=",rw," ",black,"=",rb," ",r," ",state
  return white,rw,black,rb,r,state


def update(members):
  outFile =  file('members.csv', "w")
  line = ""
  for m in members:
    #print members[m][0]
    line = string.join(members[m][0],',') 
    #print line 
    outFile.write(line)
  outFile.close()
  print "updated completed"
  return

def read():
  inFile = file('members.csv', 'r').readlines()
  tmp = []
  line = ""
  y = 0
  rating,ww,lw,dw,wb,lb,db = 0,0,0,0,0,0,0
  name = ""
  for line in inFile:
    tmp = string.split(line,",")
    state = tmp[0]
    name = tmp[1]
    rating = tmp[2]
    ww = tmp[3]
    lw = tmp[4]
    dw = tmp[5]
    wb = tmp[6]
    lb = tmp[7]
    db = tmp[8]
    members[name] = []
    members[name].append(tmp)
  print len(members), " entries"
  return members

def rate(rw,rb,r):
  r = r.lower()
  top = 3000
  kw = abs((top-rw)/100)
  kb = abs((top-rb)/100)
  d = abs((rw-rb)/20)
  #print "white = ", kw
  #print "black = ", kb
  #print "diff = ", d
  if r == "w":
    #print "white won"
    if rw &gt; rb:
      rw = rw + kw
      rb = rb - kw
      return rw,rb
    elif rw &lt; rb:
      rw = rw +(kw + d)
      rb = rb - (kw+d)
      return rw,rb
    elif rw == rb:
      rw = rw + kw
      rb = rb - kb
      return rw,rb
  elif r == "b":
    #print "black won"
    if rb &gt; rw:
      rb = rb + kb
      rw = rw - kb
      return rw,rb
    elif rb &lt; rw:
      rb = rb + (kb+d)
      rw = rw -(kb+d)
      return rw,rb
    elif rb == rw:
      rb = rb + kb
      rw = rw - kw
      return rw,rb
  elif r == "d":
    #print "a draw"     
    if rw &gt; rb:
      rw = rw - d
      rb = rb + d
      return rw,rb
    elif rb &gt; rw:
      rb = rb - d
      rw = rw + d
      return rw,rb
    elif rw == rb:
      return rw,rb
  else:
    return "invalid result"

def open():
  pass
def add(member):
  pass

def reset(members):
  #pass
  outFile =  file('c:/chess/ftp-chess/members.csv', "w")
  line = ""
  for m in members:
    members[m][0][0] = "2000"
    members[m][0][2] = "1000"
    members[m][0][3] = "0"
    members[m][0][4] = "0"
    members[m][0][5] = "0"
    members[m][0][6] = "0"
    members[m][0][7] = "0"
    members[m][0][8] = "0"
    line = string.join(members[m][0],",") + "\n"
    outFile.write(line)
  outFile.close()
  print "reset completed"
  return

def main():
  tt,single = "",""
  #players = {[]}  
  # read members.csv
  members = read()        
  #evaluate and assign arguments.  
  #print "Welcome to the FTP chess utility\n"
  if len(sys.argv) == 1:
    print '\\nUsage: command "source/file"'
    print "valid commands are: add and rate"
    print "Valid sources are:\n"
    print "a file name e.g. c:/tournament/file.csv\n"
    print "  or: white,black,result and year where result is w, b or d, no spaces."
  if len(sys.argv) &gt; 1:
    cmd = sys.argv[1]
  if len(sys.argv) &gt; 2:
    source = sys.argv[2].strip('"')
    if ":" in source:
      source = source.replace('\\', "/")
      tt = file(source, 'r').readlines()
      if len(tt) &gt; 0:
        print len(tt), "entries in  ",source
    elif "," in source:
      single = string.strip(source,",")
    else:
      single = source
  #if single and cmd == "add":
  if cmd ==sss "rate" and len(single) &gt; 0:
    white,rw,black,rb,r,newState = getMember(single,members)
    line = "Name, rating, new rating:\n"
    game = chess.rated()
    game.white = white
    game.black = black
    game.white_rating = rw
    game.black_rating = rb
    game.result = r
    #print rw, " / ", rb
    rw,rb = rate(rw,rb,r)
    #print rw, " / ", rb
    game.white_newRating = rw
    game.black_newRating = rb
    line = "".join([line,game.white,", ",str(game.white_rating),", ",str(game.white_newRating),"\n"]) 
    line = "".join([line,game.black,", ",str(game.black_rating),", ",str(game.black_newRating),"\n"])    
    print line
    print "New rating list:\n"
    members[white][0][0] = newState
    members[white][0][2] = str(rw)
    members[black][0][0] = newState
    members[black][0][2] = str(rb)
    if r.lower() == "w":
      members[white][0][3] = str(int(members[white][0][3]) + 1)
      members[black][0][7] = str(int(members[black][0][7]) + 1)
    if r.lower() == "b":
      members[white][0][4] = str(int(members[white][0][4]) + 1)
      members[black][0][6] = str(int(members[black][0][6]) + 1)
    if r.lower() == "d":
      members[white][0][5] = str(int(members[white][0][5]) + 1)
      members[black][0][8] = str(int(members[black][0][8]) + 1)
    addGame(single)
    update(members)
    report("2011",members)
  #if tt and cmd == "add":
  if cmd == "rate" and len(tt) &gt; 0:
    rec = chess.raded()  
    for t in tt:
      print str(t)  
      white,rw,black,rb,r,newState = getMember(t,members)
      rec.white = white
      rec.white_rating = rw
      rec.black = black
      rec.black_rating = rb
      #print rw, " / ", rb
      rw,rb = rate(rw,rb,r)
      rec.white_newRating = rw
      rec.black_newRating = rb
      line = "Name, Rating, New Rating: \n"
      print line
      print ":\n"
      line = "%s, %d, %d" % (rec.white,rec.white_rating,rec.white_newRating)
      line = line + rec.black + ", " + rec.black_rating + ", " + rec.black_newRating + "\n"
      #print line
      #print rw, " / ", rb
      members[white][0][0] = str(newState)
      members[white][0][2] = str(rw)
      members[black][0][0] = str(newState)
      members[black][0][2] = str(rb)
      if r.lower() == "w":
        members[white][0][3] = str(int(members[white][0][3]) + 1)
        members[black][0][7] = str(int(members[black][0][7]) + 1)
      if r.lower() == "b":
        members[white][0][4] = str(int(members[white][0][4]) + 1)
        members[black][0][6] = str(int(members[black][0][6]) + 1)
      if r.lower() == "d":
        members[white][0][5] = str(int(members[white][0][5]) + 1)
        members[black][0][8] = str(int(members[black][0][8]) + 1)
    update(members)
  if cmd == "report":
    print single
    report(single,members)
  if cmd == "reset":
    print "resetting all values"
    reset(members)

if __name__ == '__main__':
  main()
</code></pre>

<p>Please help if you can.</p>
