473,241 Members | 1,780 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,241 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 1501
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Svens | last post by:
Hey everyone! I'm a math student working on a short script involving logs. I have a function on my scientific calculator, and was wondering if there was a similar funtion in python. For example:...
3
by: jvax | last post by:
Hi all, I hope I'm posting in the right NG... I have a data text file I want to read from a c++ program. the data file goes like this: 90 # number of balls 33 42 13
1
by: Mike Malter | last post by:
I am just starting to work with reflection and I want to create a log that saves relevant information if a method call fails so I can call that method again later using reflection. I am...
14
by: z_learning_tester | last post by:
But I can't seem to find the answer. The question is how do you reverse the words in a string? Or how do you reverse the numbers listed in a string? The example is usually something like: Turn...
12
by: Blaze | last post by:
I am doing the first walk through on the Visual Studio .Net walkthrough book to learn a little about programming. I am having issues with the first tutorial not running correctly. It seems that...
5
by: optimistx | last post by:
As a beginner in javascript I had a question. I was reading FAQ and posts here. I became very unhappy: Obviously this group is mainly for wise, pedantic, unkind etc people, who already know...
10
by: Roman Zeilinger | last post by:
Hi I have a beginner question concerning fscanf. First I had a text file which just contained some hex numbers: 0C100012 0C100012 ....
4
by: a | last post by:
Dear all vb.net developer I want to know the time I need to master vb.net? I'm beginner
3
by: Ben Keshet | last post by:
I have a probably simple beginner's question - I have a script that I am currently able to print its output. instead, i want to write it into a file - I tried different versions of write() but...
2
by: roanhn | last post by:
Hello. I've to to write a master's thesis. Currently I deal with php, mysql, ajax. Fate decreed that I've to choose one of this subjects: 1.gdi+ library in .net technology 2.ado.net technology...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.