user19047: I am working on a simple cheat detection script to find if a user used one of the  top engine moves in a game, so I found this great python-chess library
Additionally, I found this example to getting the moves score. But that topic is an old version of the lib so I tried to update the script. However, I keep getting errors, and I don't know how to get the scores in the right way.
import asyncio
import chess
#import chess.uci
import chess.engine
import chess.pgn
import io
#Let's try our code with the starting position of chess:

fen = 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1'
board = chess.Board(fen)


#Now make sure you give the correct location for your stockfish engine file
#...in the line follows: e.g., /home/.../stockfish_6_x64


engine = chess.engine.SimpleEngine.popen_uci('/home/shar/Desktop/cheat detect python/stockfish-10-linux/Linux/stockfish_10_x64')

if board.turn: print( 'White to move');
else: print( 'black to move');

for el in board.legal_moves:



    pgn = io.StringIO(board.san(el))

    thnwpgntofen = chess.pgn.read_game(pgn);
    nwinfo = engine.analysis(thnwpgntofen.board());



    print(nwinfo["score"])


    print("-------------------------");

I get this error after running my code:

Traceback (most recent call last):   File "prntengmv.py", line 37, in
  
      print(nwinfo["score"]) TypeError: 'SimpleAnalysisResult' object is not subscriptable


user10075: As per: https://python-chess.readthedocs.io/en/latest/engine.html#indefinite-or-infinite-analysis
engine.analysis(board) now returns an AnalysisResult object, which has the property info that you want.
So instead of:
nwinfo = engine.analysis(...)
print(nwinfo["score"])

You would loop over info in the AnalysisResult, and print the score property from each element:
with engine.analysis(...) as analysis:
    for info in analysis:
        print(info.get("score"))

However, your use case looks like it may benefit from engine.analyse more than engine.analysis.

19047: <p>I am working on a simple cheat detection script to find if a user used one of the  top engine moves in a game, so I found this great python-chess library
Additionally, <a href="https://chess.stackexchange.com/questions/15723/returning-scores-for-all-possible-moves-from-a-chess-engine/15734#comment39098_15734">I found this example</a> to getting the moves score. But that topic is an old version of the lib so I tried to update the script. However, I keep getting errors, and I don't know how to get the scores in the right way.</p>

<pre><code>import asyncio
import chess
#import chess.uci
import chess.engine
import chess.pgn
import io
#Let's try our code with the starting position of chess:

fen = 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1'
board = chess.Board(fen)


#Now make sure you give the correct location for your stockfish engine file
#...in the line follows: e.g., /home/.../stockfish_6_x64


engine = chess.engine.SimpleEngine.popen_uci('/home/shar/Desktop/cheat detect python/stockfish-10-linux/Linux/stockfish_10_x64')

if board.turn: print( 'White to move');
else: print( 'black to move');

for el in board.legal_moves:



    pgn = io.StringIO(board.san(el))

    thnwpgntofen = chess.pgn.read_game(pgn);
    nwinfo = engine.analysis(thnwpgntofen.board());



    print(nwinfo["score"])


    print("-------------------------");
</code></pre>

<p>I get this error after running my code:</p>

<blockquote>
  <p>Traceback (most recent call last):   File "prntengmv.py", line 37, in
  
      print(nwinfo["score"]) TypeError: 'SimpleAnalysisResult' object is not subscriptable</p>
</blockquote>
 10075: <p>As per: <a href="https://python-chess.readthedocs.io/en/latest/engine.html#indefinite-or-infinite-analysis" rel="nofollow noreferrer">https://python-chess.readthedocs.io/en/latest/engine.html#indefinite-or-infinite-analysis</a></p>

<p><code>engine.analysis(board)</code> now returns an <code>AnalysisResult</code> object, which has the property <code>info</code> that you want.</p>

<p>So instead of:</p>

<pre><code>nwinfo = engine.analysis(...)
print(nwinfo["score"])
</code></pre>

<p>You would loop over <code>info</code> in the <code>AnalysisResult</code>, and print the score property from each element:</p>

<pre><code>with engine.analysis(...) as analysis:
    for info in analysis:
        print(info.get("score"))
</code></pre>

<p>However, your use case looks like it may benefit from <a href="https://python-chess.readthedocs.io/en/latest/engine.html#analysing-and-evaluating-a-position" rel="nofollow noreferrer"><code>engine.analyse</code></a> more than <code>engine.analysis</code>.</p>
