0

I have to files- one file holding all of my sql queries held in variables and the other file executing them. Is there any way to call the queries from my first file from the second file?

Example:

File1-

query1='select * from users'

File2-

import file1
c = conn.cursor()
c.execute(getattribute(query1))

This is the logic I am trying to do. I am new to this so any help would be appreciated.

Coder123
  • 334
  • 6
  • 26

1 Answers1

0

Depending on how your code is structured, you could probably import the variables you need by adding the following line in File2:

from file1 import query1, query2, query3

That will directly import the variables and you can use them as if they were declared in the second file.

Another option is to keep the import file1 line and refer to your queries as file1.query1.

For more info see this thread: Importing variables from another file?

Luka Mesaric
  • 657
  • 6
  • 9