[Tutor] How to call mysqlcommand in Python , "mysqldump for backup "
Hi I am trying to execute some MySQL commands using some python scripts I want to do a mysqldump of my database john to a file backup.date.sql the normal command to take a dump is mysqldump john> backup.sql I tried python , by importing import os but I am stuck in how to call mysqldump in python and execute it Help and guidance requested Thanks Joseph ___ NEW Yahoo! Cars - sell your car and browse thousands of new and used cars online! http://uk.cars.yahoo.com/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to call mysqlcommand in Python , "mysqldump for backup "
--- nephish <[EMAIL PROTECTED]> wrote: > ooh ooh, i know this one, i have python do this for > me every day ! > > target_dir = '/path/to/where/you/want/to/dump' > > os.system("mysqldump --add-drop-table -c -u user > -ppassword database > table > "+target_dir+"/table.bak.sql") > > dont forget the p in front of your password ! > > hope this helps > > Hi it helped me a lot , I did my script like this for backing my zabbix database import os, time # difine the target directory target_dir = '/home/john/backup/z-b-weekly/zabbix' # in the formar year-month-day-hours-minute-secound # uses time module today = time.strftime('%Y-%m-%d-%H-%M-%S') # For testing purpose only I had kept %M %S , we can remove it later now = target_dir + today os.system("mysqldump -u root -pjohn zabbix > "+now+" " ) Thanks A LOT Joseph ___ To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] SyntaxError while defining tuple : Guidance requested
Hi I am trying out learning python , using the book Python Programming for the absolute beginner by Michael Dawson I get File "page114.py", line 12 inventory = ("Sword","Armor","Shield","Healing Potion") ^ SyntaxError: invalid syntax when I run the program which I copied from the text , tried a lot to find the reason , I thought of sending it to the list , so that I get feed back on where I had gone worng ** inventory() # treat the tuple as condition if not inventory: print "U are empty Handed." raw_input("\nPress the enter key to continue." #Create a tuple with some items inventory = ("Sword","Armor","Shield","Healing Potion") #print the tuple print "\n The Tuple inventory is: \n", inventory # print each element in the tuple print "\nYour Items:" for item in inventory: print item, ___ To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] SyntaxError while defining tuple : Guidance requested
--- Brian van den Broek <[EMAIL PROTECTED]> wrote: > Hi John, > > sometimes the syntax error indicator isn't quite > pointing to the > problem. In your case, the place it points was where > Python worked out > there was a problem, but the difficulty with your > code is several > lines up (I've indicated where in the code below). > Once this happens a > few times, you will get used to looking back for > unclosed brackets. > Thanks Brian , it saved my time , saved me from getting stuck thanks Joseph John ___ Yahoo! Exclusive Xmas Game, help Santa with his celebrity party - http://santas-christmas-party.yahoo.net/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] TypeError: object doesn't support item assignment [ Trying to learn how to enter value in array ]
Hi All I am trying to write a program in which I enter the no of students and then for the students I enter the marks and later on Display the marks The script which I wrote is given below , when I run the program I get error TypeError: object doesn't support item assignment , my aim in doing this program is to learn how to enter values in a array , please advice how can I avoid this error Guidance requested Thanks Joseph ## # This program is to learn how u enter entry to the array # And how u print it , print " \nFirst Enter the No of Students ... " print "\n Then No of marks " # defining empty array a a = () # defining i i = 0 # n is the No of students which I have to enter the marks n = int(raw_input("Enter the no: of students : \n")) # m is the Marks of the students which I have to enter while i < n: m = int(raw_input("Enter the Marks for the students : \n")) a[i] = m print "Marks are ", m i = i+1 #print "Array Marks ", a[i] ___ To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Thanks , Now able to do Marks entry and display it using Histogram
Hi All Thanks to Shantanoo,Brian,Alan,Owen Now I am able to enter the marks for each students , and display the results the frequency of marks in histogram Even though I am able to display the histogram of the marks with students , I would like to modify it further as I learn more , I am adding the program which I had done Thanks to the list , I am getting more encouragement here ,it is fun over here Thanks Joseph John *** # This program is to see how can we see how many students got particular mark # And how u print it print " \nFirst Enter the No of Students ... " print "\n Then No of marks " # defining empty array array array = [] # defining i i = 0 # n is the NO of students which I have to enter the marks n = int(raw_input("Enter the no: of students : \n")) # m is the Marks of the students which I have to enter while i < n: marks = int(raw_input("Enter the Marks for the students : \n")) array.append(marks) print "Marks are ", marks i = i+1 #print "Array Marks ", array # Now to display How many students got the same marks j = 0 ## #To Display the histograph of the students Marks #25 is the Max marks # for j in range(25): #print j , "is ",array.count(j) print j,"x" * array.count(j) j += 1 ___ To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] How to make to exit the loop, while typing Enter
Hi I am trying to write a program in which it ask for entries for the list , But if I press Enter it should exit the while loop without giving errors ,I have problem in making it work , right now if I press enter to exit , the program terminates showing error I am added my script which I wrote Advice requested Thanks Joseph # # How to exit , when user Press Enter # While Entering Data # # define array array = [] m = 0 print "Enter to exit" m = int(raw_input("Enter the Values for The Array : ")) array.append(m) print array while m != "": m = int(raw_input("Enter the Values for The Array : ")) array.append(m) print array ___ Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to make to exit the loop, while typing Enter
Hi All I was able to exit the while loop , using sys module also I was able to find the maximum no of marks entered , I am adding my code , for comments and suggestions Thanks for the support Joseph John * """ This progorm was to learn 1> How to find which is the maximum mark in list 2> How to exit the while loop, while typing enter """ import sys maxmark = [] counter = 0 while 1: try: mark = int(raw_input("Enter the Values for The Array: ")) maxmark.append(mark) print maxmark except ValueError: #print "From Here to Where " counter = 0 length = len(maxmark) #print length max = maxmark[counter] #print max for counter in range(length): if maxmark[counter] > max: max = maxmark[counter] # print " Ya U are in the if loop and the maximum no is ", max #else: #print "The ", length print "At last the Maximum Marks U got is ", max sys.exit() ~ ~ ~ --- Adam <[EMAIL PROTECTED]> wrote: > > array = [] > > m = 0 > > print "Enter to exit" > > m = int(raw_input("Enter the Values for The > Array : > > ")) > > array.append(m) > > print array > > while m != "": > > m = int(raw_input("Enter the Values for > The > > Array : ")) > > array.append(m) > > print array > > > The problem is that if a value is entered that can't > be converted to an > integer type, like "" or a letter then an exception > is raised. What you > could do is use a try, except. > while 1: > try: > m = int(raw_input("Enter the Values for > The Array: ")) > array.append(m) > print array > except ValueError: > sys.exit() > > alternatively you could do something like this: > m=raw_input("Enter the Values for The Array: ") > if m == "": sys.exit() > try: > int(m) > array.append(m) > print array > except ValueError: > print "Only integer values can be entered into > the array, or press the > enter key to exit." > ___ To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] IndexError: list index out of range [ Program work fine , but gives this message , guidance requested ]
Hi All I am trying to find out the duplicates in a list , as for beginning I wanted to compare the adjacent elements in list , for this purpose I wrote a script for checking the adjacent elements in a list, if same , it prints the result that , the adjacent numbers are same , it not it will print adjacent numbers are same My program works , but at the end of the program execution it throws error Traceback (most recent call last): File "arrayduplinital.py", line 27, in ? if seats[j] <> seats[j+1]: IndexError: list index out of range I tried my best to find the logic , why this error is coming , I was not able to find the reason , I request your guidance for the reason for this error and how to avoid it I am adding the code which I wrote for this program ** """ find duplicates in a list (1) Sort the array (2) counter i = 0 j = 0 (3) for j <= length if seats[j] <> seats[j+1] ==> print value j and j+1 are not same else ===> print value j , j +1 are same """ seats = [] i = 0 length = int(raw_input("Enter The Lenght of the array : ")) while i < length: num = int(raw_input("Enter the Seats : ")) seats.append(num) i += 1 print seats seats.sort() j = 0 for j in range(length): if seats[j] <> seats[j+1]: print " The Seat", j , "And the seat", j+1 , "value, which are", seats[j]," and", seats[j+1], "are not same" else: print "The Seats ",j ,"And the seats", j+1, "Values,", seats[j], "and", seats[j+1], "are same" ~ ___ To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] IndexError: list index out of range [ Program work fine , but gives this message , guidance requested ]
--- Guillermo Fernandez Castellanos <[EMAIL PROTECTED]> wrote: > Hi, > > Look at this: > >>> i=[1,2,3] > >>> i[len(i)] > Traceback (most recent call last): >File "", line 1, in ? > IndexError: list index out of range > > > This means that I have tried to access an element > that is out of the > list, in this case i[3], that is, the 4th element of > the list. > > You are doing the same. You do a > j in range(len(seats)) > and then you are accessing your list with seats[j] > and seats[j+1]. What > happens when j = len(seats)-1 and you call > seats[j+1]? :-) > > It happens indeed the same that in the example I > gave you first. > > Hope it helps. Good luck, > Thanks for the advice But I need to display the results What should I do in the for loop for this message to go my for loop is as for j in range(length) : if seats[j] <> seats[j+1]: print " The Seat", j , "And the seat", j+1 , "value, which are", seats[j]," and", seats[j+1], "are not same" else: print "The Seats ",j ,"And the seats", j+1, "Values,", seats[j], "and", seats[j+1], "are same" Thanks Joseph John ___ Yahoo! Exclusive Xmas Game, help Santa with his celebrity party - http://santas-christmas-party.yahoo.net/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] IndexError: list index out of range [ Program work fine , but gives this message , guidance requested ]
Hi Brian It was a excellent tutorial, Thanks a lot for the advice I got my concepts of def of functions , sort functions , count , cleared for me I was able to do and understand all the function example , except item_comparison function I get the error for set >>> set((1,1,1,2,2,2,2,2,3,4,4,5)) Traceback (most recent call last): File "", line 1, in ? NameError: name 'set' is not defined my python versrion is Python 2.3.4 (#1, Nov 4 2004, 14:06:56) [GCC 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)] on linux2 THANKS Joseph John --- Brian van den Broek <[EMAIL PROTECTED]> wrote: > John Joseph said unto the world upon 08/01/06 06:36 We no longer need the continue clause, as converting to set ensures we won't ever deal with the same item twice: >>> set((1,1,1,2,2,2,2,2,3,4,4,5)) set([1, 2, 3, 4, 5]) And, preventing us from dealing with the same item twice is what makes this better. To see that, consider: >>> def iteration_comparison(sequence): list_count = 0 set_count = 0 for i in list(sequence): list_count += 1 for i in set(sequence): set_count += 1 print list_count, set_count === message truncated === ___ Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Complete programming newbie requires tutorial.
--- Chris Andrew <[EMAIL PROTECTED]> wrote: > Hi, all. > > I wonder whether you can help. I've just subscribed > to the list, so look > forward to participating. I have been using GNU/ > Linux since about 1999, > but am a complete newbie when it comes to > programming. > > I bought the O'Reilly "Learning Python" book, but > have struggled with it. I > note that resources on the python.org website, but > was wondering whether > anyone on the list could recommend a tutorial. > I liked this book "Python Programming for the absolute beginner " by Michael Dawson , I am following it , now doing OOP chapters Also I like Byte of Python by Swaroop check the link http://www.byteofpython.info/read/index.html Also this list is of great help , to people like me ___ Yahoo! Photos NEW, now offering a quality print service from just 8p a photo http://uk.photos.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] IndexError: list index out of range [ Program work fine , but gives this message , guidance requested ]
--- Danny Yoo <[EMAIL PROTECTED]> wrote: > >I get the error for set > > >>> set((1,1,1,2,2,2,2,2,3,4,4,5)) > > Traceback (most recent call last): > > File "", line 1, in ? > > NameError: name 'set' is not defined > > Hi John, > > For Python 2.3.4, you'll need to add the line: > > ## > from sets import Set as set > ## > > before trying to use 'set'. Sets weren't so built > into Python until > Hi Thanks to all , I was able to do the script for removing the dupes from the list , I had pasted my script along with this mail Thanks a Lot Joseph John *** """This program was to teach u (a)How to remove the dupes from the list (b) How to use try and except in case the input is wrong a_biglist => is the list which we enter i_counter = > counter in for loop length => length of the list / No of list members """ import sys from sets import Set as set a_biglist = [] i_counter = " " length = " " try: length = int(raw_input("Enter the Length of the List : ")) except: print "U should Have Enterd a integer, Now Try again " #length = int(raw_input("Enter the Length of the List : ")) sys.exit() for i_counter in range(length): try: num = int(raw_input("Enter the Number for the list : ")) a_biglist.append(num) except: print " U are not entering integer , please do enter integer" sys.exit() def dupe_detector(sequence): ''' returns a list of sequence that are duplicated''' sequence = list(sequence) seen_dupes = [] for item in set(sequence): if sequence.count(item) > 1: seen_dupes.append(item) return seen_dupes def print_dupe_report(sequence): '''prints a report of items in sequence that are duplicated''' dupes = dupe_detector(sequence) dupes.sort() for d in dupes: print "%s was duplicated" %d print "The List of Dupe No are " print "" print dupe_detector(a_biglist) print "" print "\t\t The Dupe record is \n \t \t It Prints which all numbers got duplicated" print_dupe_report(a_biglist) print "" print "Now We should print only , once All the duplication number are removed " print set(a_biglist) ___ Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] "while" loop for satisfing two conditions , advice requested
Hi I am trying to use while loop , here I want while loop to check for two conditions , I am not getting an idea how to use while loop for checking two conditions I used "&" condition , but it is not giving me the expected results I used in this way while (condition no 1) & (condition no2): print Results I request guidance Thanks Joseph John ___ NEW Yahoo! Cars - sell your car and browse thousands of new and used cars online! http://uk.cars.yahoo.com/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Links for programming using MySQL
Hi I wanted to try out python with MySQL databases , I would like to get info about the link to sites , which gives you examples on how to do python programming by using MySQL database Please guide Thanks Joseph John ___ To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Python + MySQL , my first simple program does not gives results
Hi I tried out my first Pyhton program with MySQL I was trying to get the some result , eg describe table, select * from table but my program does not give the expected results , nor it gives any error I am adding my code in this mail Please guide me , why I am not getting any results displayed Thanks Joseph John ***8 """ For learning for To connect to a database "learnpython" , with mysql user name "john" password "asdlkj" To describe a table "contact" To get result of SQL statement """ import MySQLdb class learnpython_db: def __init__(self): db = MySQLdb.connect(host="localhost",user = "john",password = "asdlkj", db = learnpython) cursor = db.cursor() cursor.execute(" describe contact" ) cursor.execute(" SELECT * from contact" ) ___ Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Searching for email id in MySQL giving wrong results
Hi Thanks to Allan,Danny,Pujo I did my simple python script for MySQL , the scripts add the data , and search for the data and display I have problem in searching email id ,ie If search for the [EMAIL PROTECTED] , I will not get any result , Guidance and advice needed for the reason for this behavior I had added my script in this mail Thanks Joseph John * """ This program is for to learn how to enter data to MySQL using python How to search not using OOP Have problem in searching email-id Why I do not get correct results when searching email id "@" string search containg "@" gives empty results """ import MySQLdb def selecter(): choice = None while choice != "0": print \ """ Data Base Entry for the Testing Env 0 - Quit 1 - Enter the Data 2 - Display The data 3 - Search The Company """ choice = raw_input("Choice :") print if choice == "0": print "Good Bye ..." elif choice == "1": dataentry() elif choice == "2": datashow() elif choice == "3": datasearch() def dataentry(): name = raw_input("Enter the name of the company ") email_id = raw_input("\n Enter the email ID : ") phone_no = raw_input("Enter the Phone No : ") fax_no = raw_input("\n Enter the fax no : ") db = MySQLdb.connect(host="localhost",user = "john", passwd = "asdlkj", db = 'learnpython') entry = db.cursor() #entry.execute("""INSERT INTO contact """,(name,email_id,phone_no,fax_no,)) entry.execute("""INSERT INTO contact(name,email_id,phone_no,fax_no) VALUES (%s,%s,%s,%s)""",(name,email_id,phone_no,fax_no,)) print name , email_id , fax_no, phone_no def datashow(): db = MySQLdb.connect(host="localhost",user = "john", passwd = "asdlkj", db = 'learnpython') entry = db.cursor() entry.execute("SELECT * from contact") p = entry.fetchall() print p def datasearch(): print "Do U want to search by Name , email id , phone or fax " choice = None while choice != "0": print \ """ U want to search the contacts by 0 - Quit 1 - Name 2 - email_id 3 - phone 4 - fax """ choice = raw_input("Choice :") print if choice == "0": print "Good Bye ..." elif choice == "1": searchbyname() elif choice == "2": searchbyemail() elif choice == "3": searchbyphone() elif choice == "4": searchbyfax() def searchbyname(): s_name = raw_input("Enter the name to be searched ") db = MySQLdb.connect(host="localhost",user = "john", passwd = "asdlkj", db = 'learnpython') entry = db.cursor() entry.execute("""SELECT * FROM contact WHERE name = %s""", (s_name,)) p = entry.fetchall() print p def searchbyemail(): s_email = raw_input("Enter the Email to be searched ") db = MySQLdb.connect(host="localhost",user = "john", passwd = "asdlkj", db = 'learnpython') entry = db.cursor() entry.execute("""SELECT * FROM contact WHERE email_id = %s""", (s_email,)) p = entry.fetchall() print p def searchbyphone(): s_phone= raw_input("Enter the Phone no to be searched ") db = MySQLdb.connect(host="localhost",user = "john", passwd = "asdlkj", db = 'learnpython') entry = db.cursor() entry.execute("""SELECT * FROM contact WHERE phone_no = %s""", (s_phone,)) p = entry.fetchall() print p def searchbyfax(): s_fax = raw_input("Enter the FAX no to be searched ") db = MySQLdb.connect(host="localhost",user = "john", passwd = "asdlkj", db = 'learnpython') entry = db.cursor() entry.execute("""SELECT * FROM contact WHERE fax_no = %s""", (s_fax,)) p = entry.fetchall() print p selecter() ___ Yahoo! Photos NEW, now offering a quality print service from just 8p a photo http://uk.photos.yahoo.com ___
Re: [Tutor] Searching for email id in MySQL giving wrong results [ Try out pattern Search ]
Hi Thanks for the tip now I am trying to do pattern matching for MySQL , but I am not getting the result on MySQL , to select for all email starting with jos we do select * from contact where email_id like "jos%"; but I get confused how to use it , while executing it in python , how to call the pattern matching inside mysql query I had added my code Thanks Joseph John *** import MySQLdb s_email= raw_input("Enter the some part of the Email to be searched ") db = MySQLdb.connect(host="localhost",user = "john", passwd = "asdlkj", db = 'learnpython') entry = db.cursor() #entry.execute('''SELECT * FROM contact WHERE email_id like %s''', (s_email,)) #s = entry.fetchall() #print s entry.execute('''SELECT * FROM contact WHERE email_id like %s''', (s_email,)) s = entry.fetchall() print s ~ ~ --- "ZIYAD A. M. AL-BATLY" <[EMAIL PROTECTED]> wrote: > On Sun, 2006-01-22 at 12:43 +, John Joseph > wrote: > > Hi > Hi John... > > Most of your problems in your code seems to be > caused by a single > mistake. Compare the following two strings and you > should figure out > what's wrong by yourself: > > email_id = '[EMAIL PROTECTED]' > > wrong_string = '''SELECT s FROM t WHERE > id=%s''' , (email_id) > right_string = '''SELECT s FROM t WHERE > id=%s''' % (email_id) > > print "Wrong:", wrong_string > print "Right:", right_string > > This is the output: > Wrong: ('SELECT s FROM t WHERE id=%s', > '[EMAIL PROTECTED]') > Right: SELECT s FROM t WHERE > [EMAIL PROTECTED] > > Now, which one is the right one? And which one is > the one you want? > > > I suggest you study strings more, especially > concatenation and '%'. > > If you need more help, just post to the mailing list > again. > Ziyad. > > ___ To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Searching for email id in MySQL giving wrong results
Hi I am sending the code of the function "searchbyemail" and the output of the program when I run I am trying to search and display the results , even if we give a part of the email_id thanks Joseph John SEARCH by email _id function def searchbyemail(): s_email = raw_input("Enter the Email to be searched ") db = MySQLdb.connect(host="localhost",user = "john", passwd = "asdlkj", db = 'learnpython') entry = db.cursor() entry.execute("""SELECT * FROM contact WHERE email_id = %s """, (s_email,)) p = entry.fetchall() print p ### *** Output of the short run * [EMAIL PROTECTED] experiement]$ python mysqlentry.py Data Base Entry for the Testing Env 0 - Quit 1 - Enter the Data 2 - Display The data 3 - Search The Company 4 - Delete Some info Choice :2 (('Joseph', '[EMAIL PROTECTED]', '1234', '4321'), ('John', '[EMAIL PROTECTED]', '4567', '7654'), ('CityBank', '[EMAIL PROTECTED]', '987', '789'), ('ABN amro', '[EMAIL PROTECTED]', '456', '654')) Data Base Entry for the Testing Env 0 - Quit 1 - Enter the Data 2 - Display The data 3 - Search The Company 4 - Delete Some info Choice :3 Do U want to search by Name , email id , phone or fax U want to search the contacts by 0 - Quit 1 - Name 2 - email_id 3 - phone 4 - fax Choice :2 Enter the Email to be searched [EMAIL PROTECTED] (('ABN amro', '[EMAIL PROTECTED]', '456', '654'),) U want to search the contacts by 0 - Quit 1 - Name 2 - email_id 3 - phone 4 - fax Choice :2 Enter the Email to be searched loan () U want to search the contacts by 0 - Quit 1 - Name 2 - email_id 3 - phone 4 - fax Choice : --- Kent Johnson <[EMAIL PROTECTED]> wrote: > John Joseph wrote: > > Hi > >Thanks to Allan,Danny,Pujo > >I did my simple python script for MySQL , > the > > scripts add the data , and search for the data and > > display > > I have problem in searching email id > ,ie > > If search for the [EMAIL PROTECTED] , I will not get > any > > result , Guidance and advice needed for the > reason > > for this behavior > > Does it work when you search for other data such as > name or phone? > > Can you show the output from a short run where you > add a contact, > display the data and search for an email? > > Kent > > > I had added my script in this mail > > Thanks > > Joseph John > > > > > * > > > > """ This program is for to learn > > how to enter data to MySQL using python > > How to search > > not using OOP > > > > Have problem in searching email-id > > Why I do not get correct results when > > searching email id > >"@" string search containg "@" gives empty > > results > > > > """ > > > > > > > > import MySQLdb > > > > def selecter(): > > choice = None > > while choice != "0": > > print \ > > """ > > Data Base Entry for the Testing Env > > 0 - Quit > > 1 - Enter the Data > > 2 - Display The data > > 3 - Search The Company > >
Re: [Tutor] Searching for email id in MySQL giving wrong results
--- Danny Yoo <[EMAIL PROTECTED]> wrote: > > Hi John, > > Ok; because the question you're asking looks a > little homework-y, we have > to be a little bit more cautious in our answers. > What part are you > getting stuck on? > > > Do you understand how SQL wildcards work? There's a > good number of SQL > tutorials on the web. For example, we can take a > look at the queries > section on Phil Greenspuns "SQL for Web Nerds" page: > > http://philip.greenspun.com/sql/queries.html > > (In fact, the examples he uses to talk about > wildcards there seems very > pertinant to your question!) > > > Or are you getting stuck about constructing such a > query using string > operations? If so, you might find something like: > > > http://diveintopython.org/native_data_types/formatting_strings.html > > useful. > > > If you can give us more details on where you're > having difficulty, we'll > try to point you in a good direction. > > Hi Danny Thanks for the link , I understood strings formating and use of “%s” Also I read the link for basic SQL statements Now after this , I am getting lost when I do the python program let me try to explain my experience 1>From MySQL command mode , the command to check all the email id which starts with “j” is select * from contact where email_id like 'j%'; 2>Now when I want to select command in python I get confused , since I want to use SELECT statement to display the contacts which email id begins or contains the searched strings My script I am adding , Guidance requested Thanks Joseph John * import MySQLdb s_email = raw_input("Enter the Email to be searched ") db = MySQLdb.connect(host="localhost",user = "john", passwd = "asdlkj", db = 'learnpython') entry = db.cursor() """ I get confused here , in the SQL statement we use %s for the searched string , here I also need to use another % for pattern matching , I get lost over here """ entry.execute("""SELECT * FROM contact WHERE email_id = %s """, (s_email,)) #entry.execute("""SELECT * FROM contact WHERE email_id like %s% """, (s_email,)) p = entry.fetchall() print p ___ Yahoo! Photos NEW, now offering a quality print service from just 8p a photo http://uk.photos.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Searching for email id in MySQL giving wrong results
--- Danny Yoo <[EMAIL PROTECTED]> wrote: > > the email id which starts with j is > > select * from contact where email_id like 'j%'; > > Hi John, > > Ok, looks good so far. So in a Python program, we > might try something > like this: > > ## > ## assuming cursor is set up > properly: > cursor.execute("select * from coutact where email_id > like %s", >("j%",)) > print cursor.fetchone() > ## > > Try an example off the interactive interpreter > prompt. Do you get the > results you expect? > Hi It gives me the correct result , but I have problem in running a program in which it ask for which email to be searched , I am lost and confused there , I had marked it in my code *** import MySQLdb s_email = raw_input("Enter the Email to be searched ") db = MySQLdb.connect(host="localhost",user = "john", passwd = "asdlkj", db = 'learnpython') entry = db.cursor() """ I get confused here , in the SQL statement we use %s for the searched string , here I also need to use another % for pattern matching , I get lost over here """ entry.execute("""SELECT * FROM contact WHERE email_id = %s """, (s_email,)) #entry.execute("""SELECT * FROM contact WHERE email_id like %s% """, (s_email,)) p = entry.fetchall() print p > > Best of wishes to you! > > ___ To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Cannot run .py file from apache web server , Guidance requested
Hi I am trying to execute .py scripts from my apache web server , but it is not giving the results as how I run php files , it just displays the contents of the script , I am able to run and get results of PHP from the same loaction my sample-test.py file is as follows import cgi reshtml = '''Content-Type: text/html\n Friends CGI Demo (dynamic screen) Friends list for: Joseph Your name is: John You have 20 friends. ''' When I access this script from the url http://192.168.20.99/~john/ sample-test.py in the browser I see the contents of the file , not the result Is there any function similar to phpino() in python , so that I can test Guidance requested , Joseph John ___ To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor