LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-21-2018, 01:06 AM   #1
yuvi1325
LQ Newbie
 
Registered: Sep 2018
Posts: 3

Rep: Reputation: Disabled
Trying to print the amount from database but it shows error like this : TypeError: 'str' object is not callable


row=0
rows=0
sql='select * from train_details'
cur.execute(sql)
rows = cur.fetchall()
print tabulate(rows)

id1=int(input("Enter the ID mentioned above which you want to travel"))
cur.execute("select count(*) from train_details")
row=cur.fetchone()
for i in range(0,row[0]):
for j in range (0,1):
cur.execute('select id from train_details')
row=cur.fetchall()
if(row[i][j]==id1):
#cur.execute("select * from train_details where id==?",(id1,))
#rows = cur.fetchall()
print(" 1.First Class ")
print(" 2.Second Class ")
print(" 3.Third Class ")

choice=int(input("Enter the class which you want to travel"))
if(choice==1):
cur.execute("select firstclass_amount from train_details where id==?"
(id1))
row=cur.fetchall()
for row in rows:
print(row)
elif(choice==2):
cur.execute("select secondclass_amount from train_details where id==?"
(id1))
row=cur.fetchall()
for row in rows:
print(row)
elif(choice==3):
row=0
rows=0
cur.execute("select thirdclass_amount from train_details where id==?"
(id1))
row=cur.fetchall()
for row in rows:
print(row)
else:
print("Enter the above classes mentioned ")

print("Enter the id mentioned above")

Last edited by yuvi1325; 09-21-2018 at 03:48 AM.
 
Old 09-21-2018, 02:58 AM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Since you didn't format your code, it's not clear if it is indented correctly.

In any case, this looks incorrect:
Code:
cur.execute("select firstclass_amount from train_details where id==?"
(id1,))
Shouldn't there be a comma after the string?

Same for a few lines further down.

By the way, your question has nothing to do with Linux.
 
Old 09-21-2018, 03:45 AM   #3
yuvi1325
LQ Newbie
 
Registered: Sep 2018
Posts: 3

Original Poster
Rep: Reputation: Disabled
when i done with the comma also it dont work PLZ CHECK THIS!!!

Code:
               
                row=0
	   	rows=0
		sql='select * from train_details'
		cur.execute(sql)		
		rows = cur.fetchall()
        		print tabulate(rows)

		id1=int(input("Enter the ID mentioned above which you want to travel"))
		cur.execute("select count(*) from train_details")
    		row=cur.fetchone()
		for i in range(0,row[0]):
      			for j in range (0,1):
				cur.execute('select id from train_details')
				row=cur.fetchall()
				if(row[i][j]==id1):
					#cur.execute("select * from train_details where id==?",(id1,))
					#rows = cur.fetchall()
					print("         1.First Class        ")
					print("         2.Second Class        ")
					print("         3.Third Class        ")
					
					choice=int(input("Enter the class which you want to travel"))
					if(choice==1):
						cur.execute("select firstclass_amount from train_details where id==?"
(id1))				
						row=cur.fetchall()
						for row in rows:
        						print(row)
        				elif(choice==2):
        					cur.execute("select secondclass_amount from train_details where id==?"
(id1))				
						row=cur.fetchall()
						for row in rows:
        						print(row)
        				elif(choice==3):
        					row=0
        					rows=0
        					cur.execute("select thirdclass_amount from train_details where id==?"
(id1))				
						row=cur.fetchall()
						for row in rows:
        						print(row)
        				else:
        					print("Enter the above classes mentioned ")
						
		print("Enter the id mentioned above")

Last edited by yuvi1325; 09-21-2018 at 04:00 AM.
 
Old 09-21-2018, 09:03 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,843

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
you made a change in a commented line. That will have no real effect.

Code:
cur.execute("select firstclass_amount from train_details where id==%s" %
(id1))
probably, but there can be other ways too... (ambiguous)
 
1 members found this post helpful.
Old 09-21-2018, 05:46 PM   #5
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by yuvi1325 View Post
Code:
               
                choice=int(input("Enter the class which you want to travel"))
					if(choice==1):
						cur.execute("select firstclass_amount from train_details where id==?"
(id1))				
						row=cur.fetchall()
						for row in rows:
        						print(row)
        				elif(choice==2):
        					cur.execute("select secondclass_amount from train_details where id==?"
(id1))
Still looks incorrect (commas missing), although I would think this generates a syntax error rather than a runtime one.

At which line does the error occur? Which choice do you enter?
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Trying to write to a file but the this error TypeError: str() takes at most 1 argument (3 given) emmalearner Linux - Newbie 4 02-20-2018 12:35 PM
TypeError: 'NoneType' object is not iterable biplabbijay Programming 5 10-30-2017 07:57 AM
CUPS - Print jobs shows completed, but page doesn't print hikerguy Linux - Software 10 05-12-2017 12:17 PM
[SOLVED] Python: error - TypeError: 'str' object is not callable angel115 Programming 3 06-24-2014 09:10 AM
[SOLVED] python3 - trying to pickle object raises TypeError comp_brad1136 Programming 2 04-06-2011 07:37 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:08 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration