-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?

DeepSpace
  • 153
  • 1
  • 2
  • 11
  • hi DeepSpace welcome to Stackoverflow, can you post the code that you have written so far. Also read [this](https://stackoverflow.com/help/mcve) to help you improve the way you formulate your question, which in turn will help you attract more positive responses – Stephan Hogenboom May 09 '19 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. – furas May 09 '19 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 – DeepSpace May 09 '19 at 11:14
  • Rename to `tbl.py` and then from main Python file do `from tbl import SpeedFM` – tonypdmtr May 09 '19 at 14:38

1 Answers1

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.

Aki
  • 2,818
  • 1
  • 15
  • 23