problema de sintaxis

luis miguel morillas morillas en posta.unizar.es
Dom Feb 6 23:03:55 CET 2005


	Asunto: [Python-es] problema de sintaxis
	Fecha: dom, feb 06, 2005 at 02:53:17 -0500


Citando a  Daniel cabrera (cabrerachaparro en gmail.com):
> Hola,
> estoy haciendo una aplicacion de ejemplo para conectarme a una BD de
> MySQL pero cuando la ejecuto me sale un error de sintaxis, que dice:
> 
> CREATE_EMPLOYEE_SQL = """CREATE TABLE EMPLOYEE (
> error de sintaxis.
> 
> No entiendo cual puede ser el error, por si acaso mando todo el codigo gracias. 

el problema está antes, en el diccionario: sobra la última coma.

> 
> Daniel Cabrera
> 
> import MySQLdb
> SoundexDict = { "B":"1","P":"1","F":"1","V":"1",
> 		"C":"2","S":"2","G":"2","J":"2",
> 		"K":"2","Q":"2","X":"2","Z":"2",
> 		"D":"3","T":"3",
> 		"L":"4",		
> 		"M":"5","N":"5",
> 		"R":"6",			
> 		"A":"7","E":"7","I":"7","O":"7","U":"7","Y":"7",
> 		"H":"8","W":"8",}	

"H":"8","W":"8"}

> CREATE_EMPLOYEE_SQL = """CREATE TABLE EMPLOYEE (
> 	EMPLOYEE_ID INT NOT NULL,      	 
> 	FIRST_NAME VARCHAR(20) NOT NULL,
>         LAST_NAME VARCHAR(20) NOT NULL,
>         MANAGER_ID INT
> 	)"""
> DROP_EMPLOYEE_SQL = "DROP TABLE EMPLOYEE"
> INSERT_SQL = "INSERT INTO EMPLOYEE VALUES"
> def SoundexEncoding(str):
> 	"""Return the 4-character SOUNDEX code for a string. Take 
>         first  letter, then encode subsequent consonants as numbers.
> 	Ignore repeated codes (e.g MM codes as 5, not 55), unless
>         separated by vowel (e.g. SOS codes as 22)"""
>         if (str==None or str==""): return None
>             str = str.upper() # ignore case!
>             SoundexCode = str[0]
>             LastCode = SoundexDict[str[0]]
>             for char in str[1:]:
>                 CurrentCode = SoundexDict[char]
>                 if (CurrentCode=="8"):
>                     pass
>                 elif (CurrentCode=="7"):
>                     LastCode = None
>                 elif (CurrentCode!=LastCode):    			
> 			SoundexCode+=CurrentCode
>                 if len(SoundexCode)==4: break
>                		SoundexCode += "0"*(4 - len(SoundexCode))
>                 return SoundexCode
> #Create the EMPLOYEE table
> CreateTable(Conn):
>      	NewCursor=Conn.cursor()
> 	try:
>       		NewCursor.execute(DROP_EMPLOYEE_SQL)
>        		NewCursor.execute(CREATE_EMPLOYEE_SQL)
>         finally:
>   		NewCursor.close()
> # insert a new employee into the table
> def CreateEmployee(Conn.DataValues):
> 	NewCursor=Conn.cursor()
>         try:
>         	NewCursor.execute(INSERT_SQL+DataValues)   finally:
>                 NewCursor.close()
> #Do a sounds-like query on a name
> def PrintUsersLike(Conn.Name):
> 	if (Name==None or Name==""): return
>         	print "Users with last name similar to", Name+":"
>                 SoundexName = SoundexEncoding(Name)
>                 QuerySQL = "SELECT EMPLOYEE_ID, FIRST_NAME, LAST_NAME
> FROM"
> 
> QuerySQL+ = " EMPLOYEE WHERE LAST_NAME LIKE '"+Name[0]+"%'"
>                 NewCursor=Conn.cursor()
>                 try:
>                         NewCursor.execute(QuerySQL)
>                         for EmployeeRow in NewCursor.fetchall():
>                             if
> (SoundexEncoding(EmployeeRow[2])==SoundexName):
> 
>             			print EmployeeRow
>                 finally:
>                         NewCursor.close() if (__name__=="__main__"):       
> 
> Conn=ODBC.Linux.Connect("prueba",clear_auto_commit=0)
> CreateTable(Conn)                   
> CreateEmployee(Conn,'(1,"Bob","Hilbert",Null)')
> CreateEmployee(Conn,'(2,"Sarah","Pfizer",Null)')  
> CreateEmployee(Conn,'(3,"Sandy","Lee",1)')
> 
>           CreateEmployee(Conn,'(4,"Pat","Labor",2)')                    
> 
> CreateEmployee(Conn,'(5,"Larry","Helper",Null)')PrintUsersLike(Conn,"Heilbronn")
> PrintUsersLike(Conn,"Pfizer")PrintUsersLike(Conn,"Washigton")
> PrintUsersLike(Conn,"Lieber")

> _______________________________________________
> Python-es mailing list
> Python-es en aditel.org
> http://listas.aditel.org/listinfo/python-es


-- 

Luis Miguel

No a las patentes de software en Europa
EuropeSwPatentFree
http://EuropeSwPatentFree.hispalinux.es




Más información sobre la lista de distribución Python-es