[Tutor] MySQLdb : I finally got it to work.
Hello list It seems that true understanding must , at times, be painful. Danny Yoo thank you for not just giving me the answer but rather making me work for it. Here is how I got the code to run. 1. With my configuration, I need quotes around the values that are to be placed into the database, otherwise an error is raised example: ( n= blue --> Error 1054:n Unknown column 'blue' in 'field list' ) n = raw_input("Please enter a Name: ") c =raw_input("Please enter a Color: ") cursor.execute("INSERT INTO horses(name,color) VALUES('%s','%s')"%(n,c)) 2. I can not simply pass variables in the SQL query. Interpolation is necessary. Otherwise an error is raised. n = raw_input("Please enter a Name: ") c =raw_input("Please enter a Color: ") cursor.execute("INSERT INTO horses(name,color) VALUES(n,c)" ) Error 1054:n Unknown column 'n' in 'field list' 3 To update the database I needed an .commit() ( http://www.python.org/peps/pep-0249.html ) I added db.commit() after the INSERT statement and all was well. Once again thanks to all. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] MySQLdb: at a complete loss
w chun wrote: > On 2/18/06, Servando Garcia <[EMAIL PROTECTED]> wrote: > >> Hello List >> I am at a complete loss. Here is a recap, just to be clear, I have >> been unable insert into a database using MySQLdb. I can only view the >> database. >> > > > servando, > > sorry to hear about these problems. it seems highly unlikely that it > is your script that is not working (esp since you have it running on > Ubuntu and MacOSX). > > have you tried to do a manual insert from the msql cmd from a DOS > command window? i'm curious as to whether that works. if it does, > then i would further pinpoint that the problem lies in the mySQLdb > adapter somewhere, otherwise we're still at the same place. > > hope this helps, > -- wesley > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > "Core Python Programming", Prentice Hall, (c)2006,2001 > http://corepython.com > > wesley.j.chun :: wescpy-at-gmail.com > cyberweb.consulting : silicon valley, ca > http://cyberwebconsulting.com > > Yes, I can insert from a mysql command line. I was thinking that it may be the lack of a Microsoft c++ compiler. I read some where on the Internet that MySQLdb needed Microsoft C++ ( http://mail.zope.org/pipermail/zope-db/2002-August/000826.html ). Surely this could not be the problem. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] MySQLdb: at a complete loss
Hello List I am at a complete loss. Here is a recap, just to be clear, I have been unable insert into a database using MySQLdb. I can only view the database. My current configuration: 1. Windows XP 2. Python 2.4.2 3 MySQLdb current version 4. mysql 5.0.18-nt 5. DEV-c++ current version. My last script was very sloppy here is my current version #!/usr/bin/python import MySQLdb,pdb #pdb.set_trace() try: db=MySQLdb.connect(host='localhost',user='root',passwd='081300',db='tut') cursor=db.cursor() name = raw_input("Please enter a Name: ") color =raw_input("Please enter a Color: ") cursor.execute("""INSERT INTO horses(name,color) VALUES("%s","%s")"""%(name,color)) cursor.close() except MySQLdb.OperationalError,message: errorMessage ='Error %d:n %s'%(message[0],message[1]) print errorMessage this script runs without error and does not affect the database in any manner. The database does exist. User/Password are valid. I have run the above script , unchanged, on both Macintosh and Ubuntu with success. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] MySQLdb update
Here is an update concerning my MySQLdb issue.( unable to insert data into database using Python and MySQLdb) I have tested the scripts that I posted here on both my Mac and Linux machines the script functioned as expected, ran without error and inserted data into database. It is my conclusion that there is something wrong with my python/MySQLdb configuration on my windows machine. My present course of action is to uninstall python and MySQldb. Reinstall both and try again. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Once again I am in error
Hello list Seems once again unknowingly I have violated the rules of this list. I posted a request for help with working with a database. A few members of this list were kind enough to reply. When I answered their emails. I simply hit the reply button which sent out a personal email and not a reply to the list. Please forgive this error it will not happen again. Servando Garcia ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] unable to insert data into database
Hello to all I have been trying to insert data into a database using MySQLdb with no success. I have no idea why this script is not working. I took it from a tutorial from DEV Shed. #!/usr/bin/python import MySQLdb # connect db = MySQLdb.connect(host="localhost", user="root", passwd="**",db="tutorial") # create a cursor cursor = db.cursor() #User Input name = raw_input("Please enter a name: ") color = raw_input("Please enter a color: ") #Insert data into table "Horses" cursor.execute("INSERT INTO horses(Names,Color) VALUE (%s,%s)",(name,color)) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] pylibpcap
Hello List I need to use pylibpcap. I am looking for any documentation at all, tutorial would be nice. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Thanks
My thanks to the list. With your help each day I convert another C++ die hard to python. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] convert binary to ascii
Hello List it has been a long time. Here is my question : sam in binary is 01110011 0111 01101101. if given 01110011 0111 01101101 how would I go back to ascii. I guess am asking is there a module that will do this conversion for me. I have looked at binascii but have been up able to found a good example to work from. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] regular expressions
Hello Using regular expressions how do I represent Floats. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] regular expressions
Hello List I am working on creating a Domain Specific Language that will solve partial differential equations. The user will enter a equation in pseudo code format. I will need to parse the equation. Here is the BNF for the equation := :=Do :=() :=, | := = :=A() :=() := , | := | | := :=<0-9> :=+ :=+| :=A(+) It was decided to use Spark for the base for the compiler. To use Spark all that is need is to just add a new class with the above BNF to parse the equation. There is a good paper called "Charming the Python" that was used as a template. The problem I am having is, how do I code the Non-Terminals of the BNF. Terminal states like are easy to code using regular expression. Here is my function for state def t_Letter(self,s): r"[A-Za-z]+" self.rv.append(Token('Letter',s)) Servando Garcia 251 Highway 46 N Sheridan,Ar.72150 (870)942-1854 Home (870)917-8963 Cell (866) 228-8794 Fax___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] reading comments
Hello list How do I read the comments attached to a zipfile or for any file .? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] increment operator
Hello Is there a increment operator in python similar to c++ like so "SomeVariable++" ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] main()
if __name__ == '__main__': what is the meaning and importance of this code line. I have been able to glean some information. When you call a script __name__ is set to the "Name" of the script called. example: python Hope.py __name__ = Hope but why would I want to do this if __name__ == '__main__': here a code snippet that I am trying to work through # # MAIN # if __name__ == '__main__': import sys filename = sys.argv[1] f = open(filename) generate(semantic(parse(scan(f f.close() I feel that if I am calling the script Hope.py than the above code should never get to run because __name__ is equal to "Hope" so why even write it. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] URLLIB
Hello list I am on challenge 5. I think I need to some how download a file. I have been trying like so X=urllib.URLopener(name,proxies={'http':'URL').distutils.copy_file('SomeFileName') but with no luck. Servando Garcia John 3:16 For GOD so loved the world..___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] following the chain
Thanks to the many hints from the list I have made it to level four, of the python challenges. Many thanks to all. I truly have been looking for a solid example to follow on the use of the URL module. I don't feel am using it correctly or I am not understanding/using the clue correctly. Here is how I have been trying to use urlopen() import urllib name="some URL" X = urllib.urlopen(name) print X the output of X in very strange to me. I have include the exact output: > Have I used the urlopen() correctly? What is the meaning of the output? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] need a example of translate or maketrans
Hello list As you can guess I am working on the riddles. I have looked in vain for a simple example and or a explanation of the string function "translate" or even "maketrans" Can someone please send me a working example,please. thanks ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] input() : part two
Hello everyone Thank you for the quick response to my last request. Here is an update, the program I am writing takes three values from the user than produces the source code for another program. THE PROBLEM: I needed to prompt the user for three values. I used input() like so M= input("Matrix=") The IDE for Macpython works great. It works to well, it handled the GUI interfaces automatically. By using Macpython a input window was created for user input. User entered code then the source code was generated in the output window. I needed to redirect the output so the user could run the new program. I was unable to redirect the output so I decided to use a terminal to run the program like this Python Meta.py > comp.py By redirecting the output the user could now run the program but there was problems. My nice input window was gone and only a blank line was present. When I entered the the data the outputted file looked like this Matrix=error=alpha I found a work around for the terminal it appears that the message in the input("message") was being assigned to the next variable making Matrix=error=alpha So I created a variable with the input() blank Matrix= input() error= input() alpha= input() print Matrix print error print alpha When I use the terminal to redirect the output it works fine so the user can now run the other program like this Python meta.py > comp.py python comp.py once again thanks to everyone for the ideas. It was the brain storming of this group that lead me down the path I took to solve this problem___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] input()
Hello and thanks in advance. I am trying to prompt the user for some input. I need three values from the user so,I used input() like so; Matrix = input("Matrix=") error=input("error=") alpha= input("alpha=") using Macpython it works fine but when I use a terminal all I get is a blank line. When I try to enter at the command line I get this Matrix=error=alpha= Also I need to redirect any output from the program into another file, which is why I used the terminal in the first place. So, I guess I have two problems 1. How do I redirect output using Macpython? 2. How do I use input() while using a terminal? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor