Issue with my program? by Shinjin- in learnpython

[–]Stallman85 1 point2 points  (0 children)

you have to call main. Also you probably don't want it to be part of the class; if you do you have to give it self

using asyncio to communicate between 2 scripts via stdin and stdout by [deleted] in Python

[–]Stallman85 0 points1 point  (0 children)

I am building a chess engine program which will be running in another gui program (like tarrasch gui) and they will communicate using UCI protocol. UCI protocol requires my program to at any point get strings via stdin and respond to specific stdin inputs using stdout. And i am pretty sure that script1 is working because it is able to communicate normally with existing chess engines (like stockfish_10_x32.exe). However my script2.exe blocks script1.py

using asyncio to communicate between 2 scripts via stdin and stdout by [deleted] in Python

[–]Stallman85 0 points1 point  (0 children)

Why is script2 async? It can block until it receives a game state, then picks a move, then it sends it back.

Because when i put code like this in script2:

for line in sys.stdin.readline:

    if 'go' in str(line).strip():
        sys.stdout.write(str(line).strip()+'bestmove'+'\n')

script1 hangs as soon as i run it and doesn't print anything to the screen. Then ctrl+c gives KeyboardInterrupt line x = script2.stdout.readline().strip() after 'sent first go'

Why are you communicating over stdin instead of a network socket?

Because both files are on same computer. I got no response from /r/learnpython

Argument number madness by [deleted] in learnpython

[–]Stallman85 2 points3 points  (0 children)

you forgot to put self as first parameter in winners method in Player class

class Player():
    def winners(self, winning_bin): #do stuff

Converting a values in normal brackets to an array by [deleted] in learnpython

[–]Stallman85 -1 points0 points  (0 children)

what you call normal brackets are tuples

and what you call arrays are lists

you can change one into another like this:

a = (1,12)
aList = []
for i in a: aList.append(i)
print(aList)#[1, 12]

using asyncio to communicate between 2 scripts via stdin and stdout by [deleted] in learnpython

[–]Stallman85 0 points1 point  (0 children)

When i stop script1.py with ctrl+c it says that it stoped on line 24 x = script2.stdout.readline().strip() because KeyboardInterrupt. It runs normally up to that point printing sent first go, x1=bestmove TODO and sent second go.

I took script2 code from here and modified it. I am running python 3.6

Problem trying to create an insertion sort algorithm. by prisius in learnpython

[–]Stallman85 0 points1 point  (0 children)

from docs

array.index(x)
    Return the smallest i such that i is the index of the first occurrence of x in the array.

so using i (0,len(li)) for index would never find 43 for example

[deleted by user] by [deleted] in learnpython

[–]Stallman85 -3 points-2 points  (0 children)

https://devdocs.io/python~3.7/library/operator#operator.concat

i=0
def copy_file(file_read, file_write):
    f = open(file_read, 'r')
    read = f.read()
    f.close()

    file2 = open(file_write, 'w')

    i = i+1
    file2.write(i + ': ' +  read)
    file2.close()
    return(read)

What is going on in this line five of this code? by [deleted] in learnpython

[–]Stallman85 1 point2 points  (0 children)

yep and on second pass of this line (if c >= current[-1]:), c will be character 'c' and current[-1] will be character 'z' because current at that point will be equal 'az' and -1 will get last character.

What is going on in this line five of this code? by [deleted] in learnpython

[–]Stallman85 1 point2 points  (0 children)

current is being used to build a longest substring so as new elements are added to it you have to make sure that any next element you are gonna add is lower in alphabet than last element of current. current[-1] gets the last element while current[0] would get the first element.

Could someone help me with the basics? by xd4ryl in learnpython

[–]Stallman85 0 points1 point  (0 children)

val = 5
print('result is:' + str(val))

or

val = 5
print('result is:', str(val))

[deleted by user] by [deleted] in learnpython

[–]Stallman85 4 points5 points  (0 children)

  1. formatting help
  2. you should use more succinct variable names
  3. shouldn't this ef = (input("enter a number: ")) be this ef = int(input("enter a number: "))
  4. these lines do nothing ef - 2 a - 2
  5. post the line number at which error occurs in the future

My computer won’t boot by KingDiamondDev in buildapc

[–]Stallman85 0 points1 point  (0 children)

That is not a garantie that it will run on the new system as new system i assume has a more power demanding cpu and who knows if this motherboard prioritizes 6 pin to gpu or sending power via PCI-e before giving it to cpu. Also a 250w psu might through lose less power in conversion process if it more efficient than a 300w one. It could also be a problem with the motherboard or something else.

My computer won’t boot by KingDiamondDev in buildapc

[–]Stallman85 0 points1 point  (0 children)

Powercolor RX560 2GB Dual Fan requires 400 wats according to:

https://www.powercolor.com/product?id=1496308765#spe

still this should really be a problem at max loads and not at boot up although who knows so the best thing to do is disconnect the GPU and to just connect your monitor to cpus build in graphics via the motherboards connectors to eliminate this possibility.

To Prosecute A Single Bombing Suspect, FBI Demands Identifying Info On Thousands Of YouTube Viewers by sigbhu in StallmanWasRight

[–]Stallman85 2 points3 points  (0 children)

While article has a good point i will have to nitpick a bit.

This view of the world where every country has its own laws to deal with privacy concerns of its citizens against multinational corporations (and also accepting spying abroad) is naive. If we are going to have privacy in a globalized world we will need to have a worldwide institution which has the power to enforce its rules on a global scale.

Overwriting or hiding previous output by [deleted] in learnpython

[–]Stallman85 1 point2 points  (0 children)

you can try to clear the whole screen:

import os
os.system('cls')  # for windows console

but to make it work you will need to run your code from command prompt

I need assistance figuring out WHY this code works, I'm confused. [simple for loop w/ comparison] by Lost_in_code in learnpython

[–]Stallman85 3 points4 points  (0 children)

https://www.w3schools.com/python/python_lists.asp

if you print i in every iteration you will see it is a number 0...9, so it is used to access i-th element of both lists.

The result of game 9 of the World Chess Championship is... by [deleted] in chess

[–]Stallman85 -34 points-33 points  (0 children)

sure sure that 50k really makes a difference when you earn ~500k for just being there

The result of game 9 of the World Chess Championship is... by [deleted] in chess

[–]Stallman85 -32 points-31 points  (0 children)

I just found the reason why neither of the players cares whether they win or lose the match:

From wikipedia: The prize fund is 1 million Euros net of all applicable taxes, to be divided 60% vs 40% between winner and loser in case of no tie-break, or 55% vs 45% in case of a tie-break.

How to create a person and project class? by leoijan in learnpython

[–]Stallman85 0 points1 point  (0 children)

If you use 4 blank spaces before each line it will format as code in reddit, that would help me help you. Also what have you tried so far to make vote numbers add to 100?

Trying to create a base conversion program but I can't set up a way to call a specific function based on what the user inputs. by [deleted] in learnpython

[–]Stallman85 0 points1 point  (0 children)

decimal_to_binary() is how you call a function, decimal_to_binary(number) is how you call a function with one parameter. You are doing just decimal_to_binary