I'm working on a code for a certain database. I want to create some functions, that will make it easier to write things to the db and get things out of there. Anyway - I want to make some functions.
My first thought was to just open a new .py file, get all the functions in there, and then use:
from FileName import Function
and then use it, and it works. But, it's not that good if have a lot of functions, because I will need to import each function I want manually:
from FileName import Function1
from FileName import Function2
from FileName import Function3
In contrast, when I use import random
I can just use random.func
in the code itself and carry on.
A friend suggested creating a class. I didn't think of that, since I'm not trying to create an object. So for example, In my current class code:
import sqlite3
conn = sqlite3.connect('asfan.db')
c = conn.cursor()
class Manager:
def save_chunk():
c.execute("INSERT INTO DATA_CHUNKS VALUES(234, 'hello', '20190617', 'article')")
conn.commit()
c.close()
conn.close()
and inside the main I just call import Manager from File
and it works fine. But PyCharm doesn't really like the function I've written, because the method has no first parameter (PyCharm suggests "Self") and is static.
So is this the right way to "store" functions? I would love some help and references to learn about what I'm looking for.