Ask Your Question
1

errors when read a file with symbols

asked 2023-06-02 11:11:00 +0200

lijr07 gravatar image

I am trying to read a file with contents like:

[4/t^4, [[-3, 3, -3], [-1, 1, -3], [1, 1, -1]]]

I use the following codes:

fp1='/Users/jianrongli/Dropbox/Georgios/data/decomposition_of_Lm_tensor_Lm.txt'
with open(fp1, 'r') as fp:
    L = [sage_eval(line) for line in fp.readlines() if line.strip()]

But it has errors:

NameError: name 't' is not defined

Is there some way to fix this? Thank you very much.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-06-02 16:14:54 +0200

Max Alekseyev gravatar image

You need to define t and specify a mapping of that in file to the defined variable t - for example:

t = var('t')
with open(fp1, 'r') as fp:
    L = [sage_eval(line, locals={'t':t}) for line in fp.readlines() if line.strip()]
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2023-06-02 11:11:00 +0200

Seen: 153 times

Last updated: Jun 02 '23