Beginner question!

S

SMALLp

Hy! I have error something like this

TypeError: unbound method insert() must be called with insertData
instance as first argument (got str instance instead)

CODE:

File1.py
sql.insertData.insert("files", data)

sql.py

class insertData:
def insert(self, dataTable, data):
conn = self.openConnection.openConnection()
cursor = conn.cursor()
sql ="INSERT INTO "+dataTable+" (user_name, file_name, file_size,
file_path_local, file_path_FTP, curent_location, FTP_valid_time,
uploaded, last_modified, last_verified, file_type, file_category) VLAUES
"+data
cursor.execute(sql)
conn.Close()


Help and advice neaded!
 
K

kyosohma

Hy! I have error something like this

TypeError: unbound method insert() must be called with insertData
instance as first argument (got str instance instead)

CODE:

File1.py
sql.insertData.insert("files", data)

sql.py

class insertData:
def insert(self, dataTable, data):
conn = self.openConnection.openConnection()
cursor = conn.cursor()
sql ="INSERT INTO "+dataTable+" (user_name, file_name, file_size,
file_path_local, file_path_FTP, curent_location, FTP_valid_time,
uploaded, last_modified, last_verified, file_type, file_category) VLAUES
"+data
cursor.execute(sql)
conn.Close()

Help and advice neaded!

I think you need to post the real traceback or the real code since
your error message doesn't look like it has anything to do with the
code above. At least, I do not see a method named "insert".

Which database module are you using?

Mike
 
S

SMALLp

I think you need to post the real traceback or the real code since
your error message doesn't look like it has anything to do with the
code above. At least, I do not see a method named "insert".

Which database module are you using?

Mike

Traceback (most recent call last):
File "/home/pofuk/MzMFIleShare/sharePanel.py", line 130, in share
self.scanDirsAndFiles(dirPath)
File "/home/pofuk/MzMFIleShare/sharePanel.py", line 158, in
scanDirsAndFiles
sql.insertData.insert("files", data)
TypeError: unbound method insert() must be called with insertData
instance as first argument (got str instance instead)



share.py

import wx
import os
import sql
import login
class sharePanel(wx.Panel):
def __init__(self, parent, id):
wx.Panel.__init__(self, parent, id)
sizer = wx.BoxSizer(wx.VERTICAL)

nb = wx.Notebook(self, -1,style=wx.NB_TOP)

self.sheet1 = p1(nb, id)
self.sheet2 = p2(nb, id)
self.sheet3 = p3(nb, id)

nb.AddPage(self.sheet1, 'SEt1')
nb.AddPage(self.sheet2, 'Sheet2')
nb.AddPage(self.sheet3, 'Sheet3')

self.sheet1.SetFocus()

sizer.Add(nb,0, wx.EXPAND | wx.TOP, 20)



self.SetSizerAndFit(sizer)

class pageMenu(wx.Panel):
def __init__(self, parent, id):
wx.Panel.__init__(self, parent, id)
self.SetBackgroundColour("WHITE")

sizer = wx.BoxSizer(wx.HORIZONTAL)
self.links = wx.StaticText(self, -1, "<<< 1 2 3 4 5 6 7 8 9
10 >>>")
sizer.Add(self.links)

class p1(wx.Panel):
def __init__(self, parent, id):
wx.Panel.__init__(self, parent, id, size=(500, 300))
self.SetBackgroundColour("WHITE")

sizer = wx.BoxSizer(wx.VERTICAL)

self.pMenu = pageMenu(self, id)
sizer.Add(self.pMenu,0, wx.LEFT | wx.TOP | wx.RIGHT, 40)

fileList = myFilesList(self, id)
sizer.Add(fileList, 0, wx.LEFT | wx.RIGHT, 10)

shareBox = sharePanelBox(self, id)
sizer.Add(shareBox,0, wx.EXPAND | wx.TOP | wx.LEFT, 20)

sizer.Fit(self)
self.SetSizerAndFit(sizer)

class p2(wx.Panel):
def __init__(self, parent, id):
wx.Panel.__init__(self, parent, id, size=(200, 200))
self.SetBackgroundColour("RED")

class p3(wx.Panel):
def __init__(self, parent, id):
wx.Panel.__init__(self, parent, id, size=(200, 100))
self.SetBackgroundColour("YELLOW")


class myFilesList(wx.Panel):
def __init__(self, parent, id):
wx.Panel.__init__(self, parent, id)
self.SetBackgroundColour("WHITE")

vsizer = wx.BoxSizer(wx.VERTICAL)
data = {'fileName':'My filename',
'filePath':'/home/pofuk/Documents/myfile', 'fileSize':'41223 MB'}


for i in range(10):
d = [myFilesListItem(self, id, data)]
vsizer.Add(d[0],1, wx.EXPAND)

self.SetSizerAndFit(vsizer)



class myFilesListItem(wx.Panel):
def __init__(self, parent, id, data):
wx.Panel.__init__(self, parent, id)
self.SetBackgroundColour("WHITE")

hsizer = wx.BoxSizer(wx.HORIZONTAL)

self.fileName = wx.TextCtrl(self, -1, data['fileName'])
hsizer.Add(self.fileName,1, wx.EXPAND)
self.filePath = wx.StaticText(self, -1, data['filePath'])
hsizer.Add(self.filePath,1, wx.ALIGN_CENTER_VERTICAL | wx.LEFT, 10)
self.fileSize = wx.StaticText(self, -1, data['fileSize'])
hsizer.Add(self.fileSize, 0, wx.ALIGN_CENTER_VERTICAL | wx.LEFT, 30)

self.delete = wx.Button(self, -1, "Delete")
hsizer.Add(self.delete, 0, wx.LEFT, 20)

self.SetSizerAndFit(hsizer)

def setData(text):
self.fileName.Value = text


class sharePanelBox(wx.Panel):
def __init__(self, parent, id):
wx.Panel.__init__(self, parent, id)
self.SetBackgroundColour("WHITE")
sizer = wx.FlexGridSizer(1,3)

self.files = wx.CheckBox(self, -1, 'Share Files')
self.folders = wx.CheckBox(self, -1, 'Share Folders')
shareButton = wx.Button(self, -1, 'Share')

sizer.Add(self.files,0, wx.ALIGN_CENTER_VERTICAL)
sizer.Add(self.folders,0, wx.ALIGN_CENTER_VERTICAL)
sizer.Add(shareButton, 0, wx.LEFT, 20)

self.Bind(wx.EVT_BUTTON, self.share, id=shareButton.GetId())
self.SetSizerAndFit(sizer)

def share(self, event):
if self.files.IsChecked() and self.folders.IsChecked():
dialog = wx.DirDialog(self)
dialog.ShowModal()
dirPath = dialog.GetPath()
print dirPath
self.scanDirsAndFiles(dirPath)
if self.files.IsChecked() and not self.folders.IsChecked():
dialog = wx.FileDialog(self, style=wx.OPEN)
dialog.ShowModal()
if not self.files.IsChecked() and self.folders.IsChecked():
dialog = wx.DirDialog(self)
dialog.ShowModal()

def scanDirsAndFiles(self, dirPath):
for item in os.listdir(dirPath):
if os.path.isdir(os.path.join(dirPath, item)):
scanDirsAndFiles(os.path.join(dirPath, item))
if os.path.isfile(os.path.join(dirPath, item)):
user_name = login.getUserName()
fileName = item
fileSize = os.path.getsize(os.path.join(dirPath, item))
filePathLocal = os.path.join(dirPath, item)
filePathFTP = ""
currentLocation = "Local"
FTP_valid_time = 7
uploaded = ""
lastModified = "NOW()"
lastVerified = "NOW()"
fileType = "file"
fileCategory = "Ostalo"

data = [fileName, fileSize, filePathLocal, filePathFTP,
currentLocation, FTP_valid_time, uploaded, lastModified, lastVerified,
fileType, fileCategory]

sql.insertData.insert("files", data)




sql.py


connectionString = login.initialize()

class openConnection:
def openConnection(self):
conn = mysql.connect(host=connectionString["host"],
user=connectionString["user"], passwd=connectionString["passwd"],
db=connectionString["db"])
return conn


class getData:


def select(self, dataTable, limitOffset, count):
conn = self.openConnection.openConnection()
cursor = conn.cursor()
sql = "SELECT * FROM " + dataTable + " LIMIT " + limitOffset +","+ count
print sql
cursor.execute(sql)
result = []
for i in range(int(count)):
result.append(cursor.fetchone())

conn.close()
return result
def select(self, dataTable, limitOffset, count, filterCol, filterValue):
conn = self.openConnection()
cursor = conn.cursor()
sql = "SELECT FROM " + dataTable + " WHERE
"+filterCol+"="+filerValue+" LIMIT "+limitOffset+","+count
print sql
cursor.execute(sql)
result = []
for i in range(int(count)):
result.append(cursor.fetchone())
conn.close()

class insertData:
def insert(self, dataTable, data):
conn = self.openConnection.openConnection()
cursor = conn.cursor()
sql ="INSERT INTO "+dataTable+" (user_name, file_name, file_size,
file_path_local, file_path_FTP, curent_location, FTP_valid_time,
uploaded, last_modified, last_verified, file_type, file_category) VLAUES
"+data
cursor.execute(sql)
conn.Close()
 
C

Chris Mellon

Hy! I have error something like this

TypeError: unbound method insert() must be called with insertData
instance as first argument (got str instance instead)

CODE:

File1.py
sql.insertData.insert("files", data)

sql.py

class insertData:
def insert(self, dataTable, data):
conn = self.openConnection.openConnection()
cursor = conn.cursor()
sql ="INSERT INTO "+dataTable+" (user_name, file_name, file_size,
file_path_local, file_path_FTP, curent_location, FTP_valid_time,
uploaded, last_modified, last_verified, file_type, file_category) VLAUES
"+data
cursor.execute(sql)
conn.Close()


Help and advice neaded!
--

You are unclear on the distinction between classes and instances of
those classes. Following Python convention and naming your classes in
CapsCase (InsertData not insertData) would help. I recommend taking 2
giant steps backward and working through the python tutorial and dive
into python, then coming back to this project.
 
K

kyosohma

Traceback (most recent call last):
File "/home/pofuk/MzMFIleShare/sharePanel.py", line 130, in share
self.scanDirsAndFiles(dirPath)
File "/home/pofuk/MzMFIleShare/sharePanel.py", line 158, in
scanDirsAndFiles
sql.insertData.insert("files", data)
TypeError: unbound method insert() must be called with insertData
instance as first argument (got str instance instead)

share.py


def scanDirsAndFiles(self, dirPath):
for item in os.listdir(dirPath):
if os.path.isdir(os.path.join(dirPath, item)):
scanDirsAndFiles(os.path.join(dirPath, item))
if os.path.isfile(os.path.join(dirPath, item)):
user_name = login.getUserName()
fileName = item
fileSize = os.path.getsize(os.path.join(dirPath, item))
filePathLocal = os.path.join(dirPath, item)
filePathFTP = ""
currentLocation = "Local"
FTP_valid_time = 7
uploaded = ""
lastModified = "NOW()"
lastVerified = "NOW()"
fileType = "file"
fileCategory = "Ostalo"

data = [fileName, fileSize, filePathLocal, filePathFTP,
currentLocation, FTP_valid_time, uploaded, lastModified, lastVerified,
fileType, fileCategory]

sql.insertData.insert("files", data)



class insertData:
def insert(self, dataTable, data):
conn = self.openConnection.openConnection()
cursor = conn.cursor()
sql ="INSERT INTO "+dataTable+" (user_name, file_name, file_size,
file_path_local, file_path_FTP, curent_location, FTP_valid_time,
uploaded, last_modified, last_verified, file_type, file_category) VLAUES
"+data
cursor.execute(sql)
conn.Close()

It doesn't look like you are instantiating the insertData class. You
would need to do something like:

# untested
foo = insertData()
foo.insert("files", data)


But I agree with Chris. You really do need to go through a tutorial on
using classes and following Python naming conventions. Dive Into
Python and some of the other online resources are very helpful.

This is something that I have trouble with myself since wxPython uses
CamelCase for classes and methods/functions and and most
recommendations for plain Python seem to only want CamelCase for
classes and something like myFunct or myMethod for the other objects.

Mike
 
S

SMALLp

Traceback (most recent call last):
File "/home/pofuk/MzMFIleShare/sharePanel.py", line 130, in share
self.scanDirsAndFiles(dirPath)
File "/home/pofuk/MzMFIleShare/sharePanel.py", line 158, in
scanDirsAndFiles
sql.insertData.insert("files", data)
TypeError: unbound method insert() must be called with insertData
instance as first argument (got str instance instead)

share.py


def scanDirsAndFiles(self, dirPath):
for item in os.listdir(dirPath):
if os.path.isdir(os.path.join(dirPath, item)):
scanDirsAndFiles(os.path.join(dirPath, item))
if os.path.isfile(os.path.join(dirPath, item)):
user_name = login.getUserName()
fileName = item
fileSize = os.path.getsize(os.path.join(dirPath, item))
filePathLocal = os.path.join(dirPath, item)
filePathFTP = ""
currentLocation = "Local"
FTP_valid_time = 7
uploaded = ""
lastModified = "NOW()"
lastVerified = "NOW()"
fileType = "file"
fileCategory = "Ostalo"

data = [fileName, fileSize, filePathLocal, filePathFTP,
currentLocation, FTP_valid_time, uploaded, lastModified, lastVerified,
fileType, fileCategory]

sql.insertData.insert("files", data)



class insertData:
def insert(self, dataTable, data):
conn = self.openConnection.openConnection()
cursor = conn.cursor()
sql ="INSERT INTO "+dataTable+" (user_name, file_name, file_size,
file_path_local, file_path_FTP, curent_location, FTP_valid_time,
uploaded, last_modified, last_verified, file_type, file_category) VLAUES
"+data
cursor.execute(sql)
conn.Close()

It doesn't look like you are instantiating the insertData class. You
would need to do something like:

# untested
foo = insertData()
foo.insert("files", data)


But I agree with Chris. You really do need to go through a tutorial on
using classes and following Python naming conventions. Dive Into
Python and some of the other online resources are very helpful.

This is something that I have trouble with myself since wxPython uses
CamelCase for classes and methods/functions and and most
recommendations for plain Python seem to only want CamelCase for
classes and something like myFunct or myMethod for the other objects.

Mike
Thanks! I solved the problem. And I thing i understand now.
 
C

Carsten Haese

Thanks! I solved the problem. And I thing i understand now.

You may have solved your initial problem, but the above snippet raises
two red flags:

1) Why is the table name coming from a variable? This implies to me that
you a working with a collection of tables with different names that all
have the same column names. If that is the case, that smells of really
bad database design. If at all possible, those tables should be merged
into one table that has an additional column (or set of columns) for
distinguishing which "fragment" each row is in.

2) Sticking literal values into an SQL query string is a bad idea. You
should learn about parametrized queries, e.g. here:
http://informixdb.blogspot.com/2007/07/filling-in-blanks.html

Hope this helps,
 
S

SMALLp

Carsten said:
You may have solved your initial problem, but the above snippet raises
two red flags:

1) Why is the table name coming from a variable? This implies to me that
you a working with a collection of tables with different names that all
have the same column names. If that is the case, that smells of really
bad database design. If at all possible, those tables should be merged
into one table that has an additional column (or set of columns) for
distinguishing which "fragment" each row is in.

2) Sticking literal values into an SQL query string is a bad idea. You
should learn about parametrized queries, e.g. here:
http://informixdb.blogspot.com/2007/07/filling-in-blanks.html

Hope this helps,
Good question. I'm using only one tale and have no idea why i had table
name from variable. But every new knowledge comes handy.

One more question. How does my code looks like. I couldn't find any open
source program written in python to learn from, so i read some tutorials
and I'm not sure about how it looks.
 
K

kyosohma

Good question. I'm using only one tale and have no idea why i had table
name from variable. But every new knowledge comes handy.

One more question. How does my code looks like. I couldn't find any open
source program written in python to learn from, so i read some tutorials
and I'm not sure about how it looks.

You couldn't find any programs written in Python? What the!?

Here's a few:

http://cheeseshop.python.org/pypi/UliPad/3.6/
http://spambayes.sourceforge.net/
http://sourceforge.net/softwaremap/trove_list.php?form_cat=178

Mike
 
B

Bruno Desthuilliers

(e-mail address removed) a écrit :
(snip) (snip)

I think you need to post the real traceback or the real code since
your error message doesn't look like it has anything to do with the
code above. At least, I do not see a method named "insert".

May I suggest a new pair of glasses ?-)
 
B

Bruno Desthuilliers

SMALLp a écrit :
(snip)
One more question. How does my code looks like. I couldn't find any open
source program written in python

You must be jocking ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top