Question: filename.txt contains

```
a = [1, 2, 3]

```

The python file has the following lines:

```
my_file = open("filename.txt", "r")
content_list = my_file.readlines()
print (content_list)

```

when following the above I get ['a = [1, 2, 3]'] as an output
How to input the the list in python so that I can use 'a' in the code.

Thank you.
Basem

Answer: 
rather that naming the file .txt, name it .py, Once you have done it, you can access the variable by import the file in the beginning of the program.

If you dont want to make all the above mess you can remove the a variable 'a' from the txt file and leave the list like this:-,

in filename.txt:-

```
[1,2,3]

```

and then in your main .py file, you can assign the readline to a variable say 'a'. You can now access the variable in other parts of your program. It goes something like this:-

in .py file:-

```
with open ('fiename.txt','r') as f #using a context manager(its better)
    a = f.read()
print(a)

```

Since the open and read command actually reads it as string rather than a list or any other data type, you will get your output, where the above code will generate the following output:-

```
[1,2,3]

```
Either [exec()](https://docs.python.org/3/library/functions.html#exec) the content of the file after reading it, but it's generally not recommended to exec arbitrary code like this. Or you can [import](https://docs.python.org/3/reference/simple_stmts.html#the-import-statement) the file (need to change it to .py).