0

I have to assign variables from .dat files that are properly formatted 4 line input files. The variables I have to assign are

xc , yc
r
x1, y1
x2 , y2

The .dat files will be formatted so that each line contains the data for each set of those variables.

The problem says this Python statement should be able to evaluate the first line of the input file when redirected to stdin

   xc,yc = eval(input())

But I have tried to do it as so

xc , yc = map(int, input().split(','))
r       = map(int, input().split(','))
x1 , x2 = map(int, input().split(','))
x2 , y2 = map(int, input().split(','))

But this doesn't work, I get an error on line 1 that says:

Invalid literal for integer with base 10 (',').

I would appreciate it if someone could help me with reading these .dat files and assigning them to each of these variables.

MDS18
  • 81
  • 8
  • Possible duplicate of [ValueError: invalid literal for int() with base 10: ''](https://stackoverflow.com/questions/1841565/valueerror-invalid-literal-for-int-with-base-10) – ayrusme Oct 08 '17 at 16:20
  • try `float`, and if you need an `int`, use `int` after `float`, while accounting for your rounding, of course. – JacobIRR Oct 08 '17 at 16:22
  • 2
    How are you connecting your file to standard input? – chepner Oct 08 '17 at 16:23
  • 2
    very strange: you get `,` in the output while splitting with `,`. Can you create a [mcve] without user interaction? – Jean-François Fabre Oct 08 '17 at 16:26
  • What chepner said. And why are you trying to read a file that way, instead of just opening it and reading it? – PM 2Ring Oct 08 '17 at 16:29
  • @chepner I don't really know how to connect my file to standard input. This is the part i'm confused about. I edited my question because the problem says that the python statement: xc,yc = eval(input()) should be able to read the first line of the input file. I'm new to python, and I am not sure how to open a file and read it. – MDS18 Oct 08 '17 at 16:44
  • Please don't use `eval` for this. It sounds like you need to learn some more Python. If you don't already have a good textbook or tutorial, take a look at the ones suggested here: [What tutorial should I read?](https://sopython.com/wiki/What_tutorial_should_I_read%3F). – PM 2Ring Oct 08 '17 at 17:35

0 Answers0