-1

I have file tbl.lua with lua table:

SpeedFM={}
SpeedFM[20000101]=0.77566
SpeedFM[20000102]=0.77569
SpeedFM[20000103]=0.7757
SpeedFM[20000104]=0.77569

Using lua I just make dofile('tbl.lua') and get this table to work with it. My question. How can I execute this file in python because this is a valid python dictionary too?

asked May 9, 2019 at 10:53
4
  • hi DeepSpace welcome to Stackoverflow, can you post the code that you have written so far. Also read this to help you improve the way you formulate your question, which in turn will help you attract more positive responses Commented May 9, 2019 at 11:00
  • 1
    if it is valid python code then you can execute it python tbl.lua or you can change name to tbl.py and then you can import tbl in other script. Commented May 9, 2019 at 11:06
  • Thank you but what is exact syntax for it? I mean yours python tbl.lua. It will be a line inside python code Commented May 9, 2019 at 11:14
  • Rename to tbl.py and then from main Python file do from tbl import SpeedFM Commented May 9, 2019 at 14:38

1 Answer 1

1

In other words you are trying to execute external file within python. As long as your tbl.lua file is a valid python file then you can use one of those:

For Python 2 use execfile:

execfile('tbl.lua')

For Python 3 use exec:

exec(open("tbl.lua").read())

Be wary though as you are stepping on a really, really thin ice.

Asking yourself what you are trying to accomplish is often the most reasonable question when you are starting analyzing problem you are facing and would help you finding answers more quickly.

answered May 9, 2019 at 12:13
Sign up to request clarification or add additional context in comments.

1 Comment

It works. Thank you!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.