Runtime error with ideone ,can anyone explan? - python

when i use https://ideone.com
it gave me Runtime error how can i solve this ?
code :
a = int(raw_input())
b = int(raw_input())
c = int(raw_input())
z = a + b + c
print z

This is because on ideone for raw_input() you need to provide the inputs (click stdin or input to open the input entry box) BEFORE you actually run the program by pressing "Run" or "ideone it".
It is not an interactive shell like the python executable.
Sample: https://ideone.com/MvI72f
The actual runtime error being throw is :
Traceback (most recent call last):
File "prog.py", line 1, in <module>
EOFError: EOF when reading a line

Related

issues running a face_recogition file using editors and cmd

When I run the code below in jupyter, it is excellent, I get the results I want.
real = fr.load_image_file("image.jpg")
unknown = fr.load_image_file("image2.jpg")
# encodings
real_encoding = fr.face_encodings(real)[0]
unk = fr.face_encodings(unknown)[0]
result = fr.compare_faces([real_encoding], unk)
print(result)
but when I copy and paste the same code to an editor(atom the one I am using), and then run it using command prompt, I get an error as shown below
Traceback (most recent call last):
File "face_recognizer.py", line 13, in <module>
real_encoding = fr.face_encodings(real)[0]
IndexError: list index out of range
I activated the environment in which I was running the cmd.
Can someone advise me where I maybe going wrong?
There was no face captured in the photo.
That is why it throws an exception.

Running another python program from python

I am trying to build a test script to test my python code.
The tested code should read from stdin and write to stdout.
The tester code should call the tested code passing the values in a file as stdin, and read stdout to compare with the expected values (stored in another file)
Tested code:
n = int(input())
x1,y1 = list(map(int, input().rstrip().split()))
x2,y2 = list(map(int, input().rstrip().split()))
#what it does is really not importante
if ((min(x1, x2) <= n/2) and (max(x1, x2) > n/2) or
(min(y1, y2) <= n/2) and (max(y1, y2) > n/2)):
print('S')
else :
print ('N')
Tester code:
import os
import subprocess as sp
inputs = os.listdir("./warmup_tests/warmup_B/input")
for ipt in inputs:
with open('./warmup_tests/warmup_B/input/{}'.format(ipt)) as f:
res = (sp.run(['python', 'b.py'], stdin=f, capture_output=True))
I have received multiple of the following error (when disabling capture_output to better visualization):
Traceback (most recent call last):
File "b.py", line 10, in <module>
x1,y1 = list(map(int, input().rstrip().split()))
File "<string>", line 1
5 2
^
SyntaxError: unexpected EOF while parsing
My input file is the following:
10
5 2
5 1
The above works when there is only one input() on the tested code. What am I missing for making it work with multiple input()?
Your code is work for me (with small changes). It works and with capture_output=True, and with capture_output=False
https://drive.google.com/open?id=16NK1_Qfdd98prpmBUqaP894j8uGTNdnf
command to run:
python3 tester.py
For your problem: I suspect in your input files can missing '\n' in some lines (may be editor bug, don't know).
Also try check indents in your module b.py
Can you share your code with input files for detailed analysing?

python 3 NameError

Edit: Thank you for your helpful answers! I downloaded Python 3.7.0 but you are right, my Mac is running Python 2.7. I have homework now :) Figure out how to get it running 3.7. I will come back if I have more questions. Thank you!
Beginner here. I'm getting NameError when executing in Mac with Python Launcher. When testing in Python 3.7.0 Shell it works ok. I've read other answers to NameError questions, but do not understand what I'm doing wrong. Help is appreciated.
Code used
first_name = input ("Hi, what's your first name? ")
print ("Hi," , first_name)
Error received
Traceback (most recent call last):
File "/Users/imperio/Documents/pythonpractice/Name.py", line 1, in <module>
first_name = input ("Hi, what's your first name? ")
File "<string>", line 1, in <module>
NameError: name 'Imperio' is not defined
This is most likely because you are not executing it using Python 3+.
Please check the output of python -V to see which version you are executing your code with.
On mac you may already have both installed, Python 3 is sometimes aliased under python3 file.py
Here's your program converted to valid Python2:
first_name = raw_input ("Hi, what's your first name? ")
print ("Hi, {}".format(first_name))
You're running Python 2. In Python 2, input executes the input. raw_input just returns the string entered.
Here's an example:
>>> x = 1
>>> y = 2
>>> z = 3
>>> print input('variable? ')
variable? x # Note output is the value of the variable
1
>>> print input('variable? ')
variable? w # Variable 'w' doesn't exist
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1, in <module>
NameError: name 'w' is not defined
>>> print raw_input('variable? ') # Raw input just returns the input.
variable? x
x

Function not being defined even though ive saved it

I have a fully working programme that I wish to run. It executes on my friend's laptop, but not mine, (I've saved it to my documents folder) the following is the program:
def DigitCount(n):
#how many decimal digits in integer 'n'
if n<0:
n=-n
digitCount=1
powerOfTen=10
while powerOfTen<=n:
digitCount+=1
powerOfTen*=10
return digitCount
But I keep getting the following error:
>>> DigitCount(100)
Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
DigitCount(100)
NameError: name 'DigitCount' is not defined
Wait, are you saying you do the following from the command line?
$ python DigitCount.py
$ python
>>> DigitCount(100)
That won't work. You have to do this:
$ python
>>> import DigitCount
>>> DigitCount.DigitCount(100)

Does pdb.set_trace() always overwrite an error traceback?

I've got a loop processing sockets, and I've set a pdb.set_trace() breakpoint to stop and inspect the results of the call to select.select() every time through the loop. However, there are also bugs elsewhere in my code, and it seems that the standard traceback is being overwritten by pdb.set_trace. As a result, when the program quits, the traceback points to the line immediately following the set_trace(), not the line that contained the error.
Is there a way to access the actual traceback, or does pdb.set_trace() clobber it?
Here's the relevant code snippet:
while True:
read_socks, write_socks, _ = select.select(all_sockets, all_sockets, '')
pdb.set_trace()
if listen_socket.fileno() in read_socks:
new_socket, address = listen_socket.accept()
id_num = new_socket.fileno()
all_sockets[id_num] = new_socket
for id_num in write_socks:
# do something that triggers an Assertion error
and then I get the traceback as follows:
Traceback (most recent call last):
File "socktactoe_server.py", line 62, in <module>
if listen_sock.fileno() in read_socks:
AssertionError
Here is a short reproducible test case; run it, hit c every time there is a breakpoint, after the second continue the assert raises an exception and it's reported for the wrong line:
import pdb
x = 0
while True:
pdb.set_trace()
y = "line of code not triggering an error"
x += 1
assert x != 3
Output:
Traceback (most recent call last):
File "minimal_pdb_traceback.py", line 7, in <module>
y = "line of code not triggering an error"
AssertionError
It looks like you found a bug in the Python pdb module! I can reproduce your simple case in Python versions 2.7, 3.2 and 3.3, while the problem is not present in Python 2.4, 2.5, 2.6 or 3.1.
At first glance, I don't see a preexisting bug in the python bug tracker. Please report your problem there, with your minimal test case, as well as what python versions it can be reproduced on.

Categories

Resources