#๐ Find in text
37 messages ยท Page 1 of 1 (latest)
@sacred grail
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.
When I run the program (.bf) in the interpreter it thinks there is a , when there is none
Hello?
Hello. How do you know the interpreter things there is a comma? Is there an error message you can provide?
There is none thanks to my error checking
It gives me an Argument error 1
Run func:
def run_code(self):
self.code_text = self.codeinput.toPlainText() # Retrieve text from codeinput
self.arg_text = self.arginput.toPlainText()
self.need_arg = False
self.invalid_arg_char = False
self.err_code = None
backend.code = self.code_text
backend.arg = self.arg_text
try:
self.errindex = backend.code.find(",")
self.need_arg = True
except ValueError as error:
self.need_arg = False
print(error)
if self.need_arg and not self.arg_text:
self.outputbox.setText("Argument Error 1: The program requires an argument but has not been given one")
self.err_code = 1
# Check if the argument contains invalid characters
if self.need_arg:
for char in backend.arg:
if char not in backend.ascii_table:
self.outputbox.setText("Argument Error 2: A character in the argument is not a valid character in Brainfuck")
self.err_code = 2
else:
pass
if self.err_code == 1:
print("ERR 1")
elif self.err_code == 2:
print("ERR 2")
else:
self.outputbox.setText("")
backend.run()
self.outputbox.setText(backend.output_result)
I'm using PyQt5
Can you paste the full error?
nm, this one?
Argument Error 1: The program requires an argument but has not been given one
Print out the value of backend.code at this point:
try:
self.errindex = backend.code.find(",")
Worth noting:
https://docs.python.org/3/library/stdtypes.html#str.find
Return the lowest index in the string where substring sub is found within the slice s[start:end]. Optional arguments start and end are interpreted as in slice notation. Return -1 if sub is not found.
-1 will be Truthy for your use.
Before you link the v3 docs
Everything above line 189 is a u'' string
Those don't exist in Python 3, right?
not that the behavior of this particular function would be any different, but just in case
backend.code = self.code_text
backend.arg = self.arg_text
try:
self.errindex = backend.code.find(",")
self.need_arg = True
except ValueError as error:
self.need_arg = False
print(error)
if self.need_arg and not self.arg_text
I'm just looking at the code provided. An assignment of self.code_text to backend.code. Then a try/except that always sets self.need_arg to True. Then a condition that will always fire.
why
Because you told it to
where
What would error in the try/except?
hold on
none
I did this to test:
def test():
p = 1
code = "+++++.[-]."
try:
p = code.find(",")
print("There is a ','")
except Exception as error:
print(error)
print("There is not a ','")
test()
and it returned:
There is a ','
So what are you expecting to error? code.find(",") isn't erroring, it is returning -1.
oooooooh
-1 means that , was not found.
Thank you!
This is the main project
it works now
!CLOSE
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.