Skip to content
Advertisement

Python expression equivalent to include() of PHP

Is there any expression in Python that is equivalent to ‘include()’ of PHP?

To be more specific, I want to make in python a file for database connection and another for queries, but the variable for the connection only exists in the connection file. If it was in PHP I could use ‘include()’ to call the connection variable in another file. The codes in Python are these (both are in the same folder):

Connection:

JavaScript

Query:

JavaScript

Separating these two codes into two distinct folders, I’ll need the ‘db_connection’ variable to execute the query, therefore, I’ll need to call it in the query’s folder. How could I do this?

Advertisement

Answer

In your query file you can import db_connection from your connection file using:

JavaScript

and then use db_connection the way you want.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement