[EMAIL PROTECTED] wrote: > On Dec 21, 9:11 am, SMALLp <[EMAIL PROTECTED]> wrote: >> 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
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() -- http://mail.python.org/mailman/listinfo/python-list