Reputation: 139
Im totaly new to python so i am in the absolute beginner stage. I know alot PHP so my mind think in the PHP way when i am trying stuff with Python.
I have a python project that contains a:
test.py
Includes(folder)
- math.py
The test.py contains the code:
import MySQLdb
db = MySQLdb.connect(host="127.0.0.1",
user="root",
passwd="",
db="python")
from Tkinter import *
root = Tk()
root.title("test")
root.geometry("500x500")
window = Frame(root)
window.grid()
label = Label(text="")
label.grid()
def click():
cur = db.cursor()
query = cur.execute("SELECT * FROM names")
result = cur.fetchall()
label["text"] = result[0]
b1 = Button(window, text = "Click me!",command=click)
b1.grid()
root.mainloop()
How do i include the math.py file so i can use the class inside. I know in PHP it's:
include("indcludes/math.py");
But how do you make the same thing in Python, if its posible at all ;)
Ty for your time.
Upvotes: 0
Views: 48
Reputation: 66
Create an empty file called __init__.py in your includes
folder.
$ touch includes/__init__.py
In your client code test.py
, import the math.py class through
from includes import math
Upvotes: 1