Menu

#63 Issue with script: eco2pgn.py

1.0
open
nobody
script (1)
2023-12-26
2023-05-21
ScreenName
No

4 Lines in eco2pgn.py produce and error like this when used with python3.
print '[ECO "%s"]' % eco
^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?

To fix, change these lines

print '[ECO "%s"]' % eco
print '[Variation "%s"]' % variation
print '[Result "*"]'
print cont

To

print ('[ECO "%s"]' % eco)
print ('[Variation "%s"]' % variation)
print ('[Result "*"]')
print (cont)

Regards,

Discussion

  • Steven

    Steven - 2023-05-23

    Thank you, change is committed to subversion.
    FYI i briefly tested on python 2.7 and still works there too.
    Cheers

     
  • Jonathan

    Jonathan - 2023-12-25

    Here is an updated sript that works with Python 3

    #!/usr/bin/env python
    import re
    import sys
    
    if len(sys.argv) < 2:
        sys.stderr.write("usage: eco2pgn file.eco > file.pgn\n")
        sys.stderr.write("eco2pgn takes a Scid openings classification file,\n")
        sys.stderr.write("and writes it in PGN format to standard output.\n")
        sys.exit(1)
    
    fd = open(sys.argv[1], "r")
    
    while 1:
        line = fd.readline()
        if not line: break
        line = line[:-1]
    
        if re.match("\\s*(#|$)", line): continue
    
        match = re.match("(\\S+)\\s+\"([^\\\"]+)\"(\\s+.+)?$", line)
        if match:
            eco, variation, cont = match.groups()
    
            if not cont:
                cont = ''
    
            while not cont or cont[-1] != '*':
                cont = cont + ' ' + fd.readline()[:-1]
    
            if cont[-1] == '*' and cont[-2] != ' ':
                cont = cont[:-1] + ' *'
    
        print('[ECO "%s"]' % eco)
        print('[Variation "%s"]' % variation)
        print('[Result "*"]')
        print()
        print(cont)
        print()
    
     
  • Steven

    Steven - 2023-12-26

    ok

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.