471,305 Members | 1,386 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,305 software developers and data experts.

Beginner question!

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!
Dec 21 '07 #1
9 1439
On Dec 21, 9:11 am, SMALLp <po...@email.t-com.hrwrote:
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
Dec 21 '07 #2
On Dec 21, 2007 9:11 AM, SMALLp <po***@email.t-com.hrwrote:
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.
Dec 21 '07 #3
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

<snip>

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)

<snip>

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
Dec 21 '07 #4
ky******@gmail.com wrote:
>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


<snip>

> 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)


<snip>

>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.
Dec 21 '07 #5
On Fri, 2007-12-21 at 18:06 +0100, SMALLp wrote:
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)
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/...in-blanks.html

Hope this helps,

--
Carsten Haese
http://informixdb.sourceforge.net
Dec 21 '07 #6
Carsten Haese wrote:
On Fri, 2007-12-21 at 18:06 +0100, SMALLp wrote:
>>> 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)
>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/...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.
Dec 21 '07 #7
On Dec 21, 1:44 pm, SMALLp <po...@email.t-com.hrwrote:
Carsten Haese wrote:
On Fri, 2007-12-21 at 18:06 +0100, SMALLp wrote:
>> 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)
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/...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.
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/t...p?form_cat=178

Mike
Dec 21 '07 #8
ky******@gmail.com a écrit :
On Dec 21, 9:11 am, SMALLp <po...@email.t-com.hrwrote:
(snip)
>>class insertData:
def insert(self, dataTable, data):
(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 ?-)
Dec 21 '07 #9
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 ?
Dec 21 '07 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Svens | last post: by
3 posts views Thread by jvax | last post: by
14 posts views Thread by z_learning_tester | last post: by
12 posts views Thread by Blaze | last post: by
5 posts views Thread by optimistx | last post: by
10 posts views Thread by Roman Zeilinger | last post: by
4 posts views Thread by a | last post: by
3 posts views Thread by Ben Keshet | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.