#πŸ”’ please help below is my code

116 messages Β· Page 1 of 1 (latest)

atomic cosmos
#

#HTR subset scramble generator

import subprocess

import random

subset = input("Input subset: ")

#generate halfturns

moves = "RLUDFB"

i = 1

halfturns1 = ""

while i < random.randint(500,1000):

halfturns1 = halfturns1 + moves[random.randint(0,5)] + "2 "

i = i+1

i = 1

halfturns2 = ""

while i < random.randint(500,1000):

halfturns2 = halfturns2 + moves[random.randint(0,5)] + "2 "

i = i+1

#create scramble and command

scramble_full = halfturns1 + subset + " " + halfturns2

command = ["solve -M 20 " + scramble_full]

#clean up scramble

path = r"C:\Users\oraga\OneDrive\Desktop\New folder\nissy-2.0.6.exe"
nissy_output = subprocess.run([path] + command, capture_output=True, text=True)

i = 5

while nissy_output[-i-4] != ")":

i = i + 1

while nissy_output[i+1] != "(":

scramble = scramble + nissy_output[i]

i = i + 1

#print result

print(scramble)

gloomy daggerBOT
#

Hey @atomic cosmos!

It looks like you're trying to paste code into this channel.

Discord has support for Markdown, which allows you to post code with full syntax highlighting. Please use these whenever you paste code, as this helps improve the legibility and makes it easier for us to help you.

To do this, use the following method:
```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
You can **edit your original message** to correct your code block.
#

@atomic cosmos

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

atomic cosmos
#

the subprocess not work

#

please help me

#

idk why there is an error

frozen axle
#

subprocess.run returns more than just the string output - it returns a process, with the status code (whether it was run successfully), the stdin/stdout/stderr,
the stdout being what you want - the text printed by the program, so you'd get the .stdout of the process
or you could just use subproces.check_output if you only need the output

atomic cosmos
#

ok thanks

atomic cosmos
frozen axle
#

or add .stdout to the current thing
either will be fine

atomic cosmos
#

thanks a lot

#

its gonna be useufl for my cubing

atomic cosmos
# frozen axle or add `.stdout` to the current thing either will be fine

Traceback (most recent call last):
File "C:/Users/oraga/Downloads/htr subset generator.py", line 52, in <module>
nissy_output = subprocess.check_output([path] + command, capture_output=True, text=True)
File "C:\Users\oraga\Downloads\lib\subprocess.py", line 420, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "C:\Users\oraga\Downloads\lib\subprocess.py", line 496, in run
raise ValueError('stdout and stderr arguments may not be used '
ValueError: stdout and stderr arguments may not be used with capture_output.

#

it says this error

#

path = r"C:\Users\oraga\OneDrive\Desktop\New folder\nissy-2.0.6.exe"
nissy_output = subprocess.check_output([path] + command, capture_output=True, text=True)

#

my code

frozen axle
#

you dont need capture_output with check_output
its entire point is to capture the output, you dont need to say that again
what you got is basically an implementation issue thingy, it forwarded the arguments and they got reused in an incompatible way

atomic cosmos
#

ok thanks

#

path = r"C:\Users\oraga\OneDrive\Desktop\New folder\nissy-2.0.6.exe"
nissy_output = subprocess.check_output([path] + command)

#

like this?

frozen axle
#

yeah
that'll give you bytes so you probally still want the text=True or a .decode()

atomic cosmos
#

OK

#

#HTR subset scramble generator

 

import subprocess

import random

 

subset = input("Input subset: ")

 

#generate halfturns

moves = "RLUDFB"

i = 1

halfturns1 = ""

while i < random.randint(500,1000):

  halfturns1 = halfturns1 + moves[random.randint(0,5)] + "2 "

  i = i+1

i = 1

halfturns2 = ""

while i < random.randint(500,1000):

  halfturns2 = halfturns2 + moves[random.randint(0,5)] + "2 "

  i = i+1

 

#create scramble and command

scramble_full = halfturns1 + subset + " " + halfturns2

command = ["solve -M 20 " + scramble_full]

 

#clean up scramble

path = r"C:\Users\oraga\OneDrive\Desktop\New folder\nissy-2.0.6.exe"
nissy_output = subprocess.check_output([path] + command, text=True)

i = 5

while nissy_output[-i-4] != ")":

  i = i + 1

while nissy_output[i+1] != "(":

  scramble = scramble + nissy_output[i]

  i = i + 1

 

#print result

print(scramble)
#

I think this a new error

frozen axle
#

well, yeah
check the output perhaps, figure out why you could be going out of bounds with the index

plain bluff
#

(backticks for markdown, not regular quotes)

atomic cosmos
#

oh ok

frozen axle
#

if you're doing some parsing of the output like get thing between parens you could use str.index or str.partition maybe
or regex

atomic cosmos
#

wdym

#

i just made it print the output

frozen axle
#

why are the loops there then? what are they doing?

atomic cosmos
#

does the extra line mean it outputted nothing

frozen axle
#

likely
you could print(repr(nissy_output)) to see it as you'd write it as a string

atomic cosmos
#

OHHH

#

usually there are multiple solutions like
R2 F2 U L2 D2 (5)
F2 D F2 F2 F2 (5)
which is why i used the first while loop

#

but sometimes theres only 1

#

i added or

#

but it doesnt work

frozen axle
#

so yep, it was an empty string
if you run the program yourself, without subprocess, does it produce any output?

#

i think

command = ["solve -M 20 " + scramble_full]

might be the source of the problem
this is not how you pass command line arguments
each argument should be a separate element in the list, so like, ["solve", "-M", "20"]

atomic cosmos
#

oh ok thanks

#

let me check

#

it definetly works if i run nissy normally

#

would it be ["solve", "-M", "20", scramble_full]?

frozen axle
#

depends on what is scramble_full

atomic cosmos
#

its a string variable

frozen axle
#

i know, but what does the string contain?

atomic cosmos
#

something like R2 F2 L2 D2 R2 U2 F2 B2 D2 F2 L2 U R2 U R2 U B2 D2 U2 R2 L2 F2 D2 L2 but with 1000-2000 moves

frozen axle
#

okay, and does nissy actually accept those each as separate arguments? or you do something like nissy "R2 F2 L2", putting all of the moves in a single string?

atomic cosmos
#

this is what i would type into nissy

frozen axle
#

so each move is a separate argument

atomic cosmos
#

yeah

frozen axle
#

then you could do something like ["solve", "-M", "20"] + scramble_full.split()

atomic cosmos
#

ok thanks

#

should i copy and paste

#

like just use ["solve", "-M", "20"] + scramble_full.split()

#

oops it doesnt work

frozen axle
#

what happens?

atomic cosmos
#

it has an error

#

ill send it

#

i had to use word doc because i cant snip it as its too big to fit in one screen and the message is too long

#

it opened terminal

frozen axle
#

maybe its "too much" for it? does it work with fewer moves?

atomic cosmos
#

ok let me try

#

Traceback (most recent call last):
File "C:/Users/oraga/Downloads/htr subset generator.py", line 52, in <module>
nissy_output = subprocess.check_output([path] + command, text=True)
File "C:\Users\oraga\Downloads\lib\subprocess.py", line 420, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "C:\Users\oraga\Downloads\lib\subprocess.py", line 524, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['C:\Users\oraga\OneDrive\Desktop\New folder\nissy-2.0.6.exe', 'solve', '-M', '20', 'F2', 'B2', 'L2', 'U2', 'B2', 'U2', 'R2', 'U2', 'U2', 'F2', 'R2', 'L2', 'U', 'R2', 'U', 'R2', 'U', 'L2', 'D2', 'L2', 'R2', 'F2', 'U2', 'R2', 'B2', 'D2', 'R2', 'U2']' returned non-zero exit status 3221225477.

#

it still doesnt work

frozen axle
#

if you just type C:\Users\oraga\OneDrive\Desktop\New folder\nissy-2.0.6.exe solve -M 20 F2 B2 L2 U2 B2 U2 R2 U2 U2 F2 R2 L2 U R2 U R2 U L2 D2 L2 R2 F2 U2 R2 B2 D2 R2 U2 in a terminal, does the same thing happen?

atomic cosmos
#

C:\Users\oraga\OneDrive\Desktop\New : The term 'C:\Users\oraga\OneDrive\Desktop\New' is not recognized as the name of
a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included,
verify that the path is correct and try again.
At line:1 char:1

  • C:\Users\oraga\OneDrive\Desktop\New folder\nissy-2.0.6.exe solve -M 2 ...
  •   + CategoryInfo          : ObjectNotFound: (C:\Users\oraga\OneDrive\Desktop\New:String) [], CommandNotFoundExceptio
     n
      + FullyQualifiedErrorId : CommandNotFoundException
#

this error

frozen axle
#

oh, right, since it has a space in the path you'd need to quote it, otherwise it treats them as 2 separate things

atomic cosmos
#

oh so do i add speech marks around the path

atomic cosmos
#

let me try

#

it does

frozen axle
#

you should not need it in your python code - the string is a single thing, it will be passed as that by subprocess, i mean when you try to run it in the terminal yourself, if you do thing/new folder/something its actually like (thing/new) (folder/something)

atomic cosmos
#

maybe i have to type #nissy at the start

#

its automatically there when i do nissy nomrally

#

normally

frozen axle
#

no, the #nissy is not part of your command, its just text printed by it

atomic cosmos
#

ok

#

what does it mean by unexpected token

frozen axle
# atomic cosmos

i think you might need a & at the start
im not on windows so cant even test

atomic cosmos
#

oh it works

#

nice

#

but there is an error

#

not really an error

#

the pruning tables take hours to generate

#

ive already generated them

#

and when i press windows r and the path to nissy it works and i dont need to gen the pruning tables cuz ive done it

frozen axle
#

perhaps it looks for them in the current working directory? which is different in this case

atomic cosmos
#

should i change the position of the tables?

frozen axle
#

if its like a file and you know where it is you could try to move it and see if that works yeah

atomic cosmos
#

ok

#

where should i move it

frozen axle
#

see the C:\Users\oraga at the start of your prompt? thats your "current working directory" in the terminal, its like the directory you're in in a file explorer
if a program tries to look for something like data.txt with a relative path, it'd therefore look at C:\Users\oraga\data.txt
you can change your directory with the cd command (change directory)

atomic cosmos
#

ok

#

ive put them there

frozen axle
#

since you've put them in here - right now just check if running the same command now finds those table files
if it does - that confirms that it uses a relative path to find them

atomic cosmos
#

it doesnt work

#

it still wants to gen the tables

frozen axle
atomic cosmos
#

no it doesnt work

gloomy daggerBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.