Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with an iterator
#5
One more "What do you think you are doing?!"
import stockfish
from stockfish import Stockfish
...
stockfish = Stockfish("/Users/User/stockfish_20011801_x64.exe")
As far as I can tell you never use the "import stockfish". You use "from stockfish import Stockfish". If you are thinking you need to import stockfish before you can from stockfish import Stockfish, that is not the case.

But that is not the big question. The big question is why are you hiding your stockfish module by making a variable that has the same name? That is just bad programming practice as it can lead to unexpected and difficult to diagnose errors, and it is just downright confusing. Someone looking at your code will see stockfish as a module. And then they will see it is a variable. But it isn't it a module?

Here's another example where you pick a really bad variable name.
eval = stockfish.get_evaluation()
eval = eval["value"]
eval is a Python command, as in:
print(eval('3+5'))
Avoid using python keywords as variable names. Do not call something a list or a dict or eval or a type or min or max. If I wanted to use eval I could not, because you decided that eval is no longer a function that evaluates an expression, it is something that is returned by stockfish.get_evaluation(). Maybe that is an eval, but it probably isn't the standard eval.

Instead of this:
eval = stockfish.get_evaluation()
eval = eval["value"]
I would write
value = stockfish.get_evaluation()["value"]
grimm1111 likes this post
Reply


Messages In This Thread
Problem with an iterator - by grimm1111 - Feb-06-2021, 02:11 AM
RE: Problem with an iterator - by Larz60+ - Feb-06-2021, 03:28 AM
RE: Problem with an iterator - by grimm1111 - Feb-06-2021, 03:45 AM
RE: Problem with an iterator - by deanhystad - Feb-06-2021, 05:00 AM
RE: Problem with an iterator - by grimm1111 - Feb-06-2021, 05:45 AM
RE: Problem with an iterator - by deanhystad - Feb-06-2021, 05:14 AM
RE: Problem with an iterator - by deanhystad - Feb-06-2021, 05:57 AM
RE: Problem with an iterator - by grimm1111 - Feb-06-2021, 08:28 AM
RE: Problem with an iterator - by deanhystad - Feb-06-2021, 04:44 PM
RE: Problem with an iterator - by grimm1111 - Feb-06-2021, 09:22 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  prime numbers with iterator and generator cametan_001 8 1,953 Dec-17-2022, 02:41 PM
Last Post: cametan_001
  resetting an iterator to full Skaperen 7 7,103 Feb-20-2022, 11:11 PM
Last Post: Skaperen
  popping an iterator Skaperen 11 3,799 Oct-03-2021, 05:08 PM
Last Post: Skaperen
  q re glob.iglob iterator and close jimr 2 2,274 Aug-23-2021, 10:14 PM
Last Post: perfringo
  Multi-class iterator Pedroski55 2 2,420 Jan-02-2021, 12:29 AM
Last Post: Pedroski55
  is a str object a valid iterator? Skaperen 6 5,709 Jan-27-2020, 08:44 PM
Last Post: Skaperen
  discard one from an iterator Skaperen 1 2,024 Dec-29-2019, 11:02 PM
Last Post: ichabod801
  how do i pass duplicates in my range iterator? pseudo 3 2,402 Dec-18-2019, 03:01 PM
Last Post: ichabod801
  looking for a sprcil iterator Skaperen 7 3,412 Jun-13-2019, 01:40 AM
Last Post: Clunk_Head
  last pass of for x in iterator: Skaperen 13 5,959 May-20-2019, 10:05 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020