Convert string in text file into int

ahmad88
Wed, 02 Nov 2022 14:50:02 +0000
General Usage

I have the following textfile:

initial=0
n=39
E=[( 0 ,  8 ), ( 0 ,  13 ), ( 0 ,  20 ), ( 0 ,  22 ), ( 0 ,  26 ), ( 0 ,  36 ), ( 0 ,  5 ), ( 0 ,  10 ), ( 0 ,  17 ), ( 0 ,  27 ), ( 1 ,  18 ), ( 2 ,  5 ), ( 2 ,  8 ), ( 3 ,  4 ), ( 3 ,  21 ), ( 3 ,  25 ), ( 3 ,  32 ), ( 3 ,  5 ), ( 3 ,  20 ), ( 3 ,  24 ), ( 5 ,  10 ), ( 5 ,  11 ), ( 5 ,  17 ), ( 5 ,  19 ), ( 5 ,  22 ), ( 5 ,  23 ), ( 5 ,  24 ), ( 5 ,  27 ), ( 5 ,  28 ), ( 5 ,  32 ), ( 5 ,  33 ), ( 5 ,  36 ), ( 5 ,  8 ), ( 5 ,  14 ), ( 5 ,  15 ), ( 5 ,  20 ), ( 5 ,  21 ), ( 5 ,  25 ), ( 5 ,  26 ), ( 5 ,  35 ), ( 5 ,  37 ), ( 5 ,  38 ), ( 6 ,  12 ), ( 6 ,  16 ), ( 6 ,  30 ), ( 6 ,  31 ), ( 6 ,  34 ), ( 6 ,  25 ), ( 7 ,  29 ), ( 7 ,  36 ), ( 8 ,  10 ), ( 8 ,  20 ), ( 8 ,  26 ), ( 8 ,  36 ), ( 8 ,  27 ), ( 8 ,  38 ), ( 9 ,  17 ), ( 9 ,  19 ), ( 9 ,  22 ), ( 10 ,  17 ), ( 10 ,  26 ), ( 10 ,  20 ), ( 10 ,  27 ), ( 12 ,  16 ), ( 12 ,  25 ), ( 12 ,  30 ), ( 12 ,  31 ), ( 12 ,  34 ), ( 13 ,  22 ), ( 14 ,  15 ), ( 14 ,  26 ), ( 16 ,  30 ), ( 16 ,  31 ), ( 16 ,  34 ), ( 16 ,  25 ), ( 17 ,  19 ), ( 17 ,  26 ), ( 17 ,  36 ), ( 17 ,  20 ), ( 17 ,  22 ), ( 17 ,  27 ), ( 18 ,  22 ), ( 18 ,  28 ), ( 19 ,  20 ), ( 19 ,  22 ), ( 19 ,  28 ), ( 20 ,  24 ), ( 20 ,  26 ), ( 20 ,  27 ), ( 20 ,  32 ), ( 20 ,  21 ), ( 20 ,  22 ), ( 20 ,  25 ), ( 20 ,  28 ), ( 20 ,  36 ), ( 20 ,  37 ), ( 20 ,  38 ), ( 21 ,  25 ), ( 22 ,  28 ), ( 25 ,  30 ), ( 25 ,  34 ), ( 25 ,  31 ), ( 26 ,  27 ), ( 27 ,  36 ), ( 29 ,  36 ), ( 30 ,  34 ), ( 30 ,  31 ), ( 31 ,  34 )]

what I am trying to do is to assign these values as follows

lines = [line for (i, line) in enumerate(eachline("textfile.txt"))]
a=parse(Int64,lines[1])
b=parse(Int64,lines[2])
c=parsetuple(lines[3]::String) = Tuple(Int64(x) for x in lines[3])

it works for a and b but for c it still deal with it as an integer, what is the problem here ?

4 posts - 4 participants