python - functions from a module stating that they are not defined -


so have 2 .py files , trying load functions database_modules.py file main.py when try run program, error:

nameerror: name 'create_table' not defined 

the main.py file in main directory whilst database_modules.py in subdirectory (modules/database_modules.py)

main.py:

import sqlite3 import datetime modules import database_modules  connection = sqlite3.connect('accounts.db') cursor = connection.cursor()  create_table() data_entry(input('please input name:  '), hash(input('please input password:  '))) read_entry() quit() 

database_modules.py:

def create_table():     cursor.execute("create table if not exists accountdetails(name text, password text, datecreation text, accountid int)")  def data_entry(name, password):     datecreation = (datetime.datetime.now().strftime("%y-%m-%d %h:%m"))     accountid = 1     cursor.execute("insert accountdetails (name, password, datecreation, accountid) values (?, ?, ?, ?)", (name, password, datecreation, accountid))     connection.commit()  def read_entry():     cursor.execute("select * accountdetails")     data = cursor.fetchall()     print(data)  def quit():     cursor.close()     connection.close() 

thanks in advance unsure how gain functions, file worked fine until attempted turn code modules.

as commented need specify function wish use imported script: database_modules.create_table. alternatively can directly import functions in database_modules file using from modules.database_modules import *. after can use them name you've done. or import 1 need from modules.database_modules import create_table.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -