alissong 1 Report post Posted November 23, 2008 Pessoal, Sou novato nessa linguagem, mas construir esse código: #!/usr/bin/python print #Declaracao das variaveis codigo = 0 #Programa codigo = int(raw_input('Digite o código do produto: ')) import MySQLdb # Conecta db = MySQLdb.connect(host="localhost", user="root", passwd="root", db="estoque") # Cria um cursor cursor = db.cursor() # Executa o SQL cursor.execute("SELECT * FROM produto WHERE cod_produto = %s", (codigo)) numrows = int(cursor.rowcount) # Lista uma linha de cada vez for x in range(0,numrows): row = cursor.fetchone() print "código:", "-", "Nome:", "-", "Preço Venda:" print row[0],"-",row[1],"-",row[4] E salvei com o nome mysql.py, mas quando peço para importá-lo assim: import mysql.py exibe esse erro: Traceback (most recent call last): File "<pyshell#5>", line 1, in <module> import mysql.py File "C:\Python25\curso\mysql.py", line 8 SyntaxError: Non-ASCII character '\xf3' in file C:\Python25\curso\mysql.py on line 8, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details (mysql.py, line 8) Qual é erro de sintaxe que estou cometendo. Um abraço. Alissong Share this post Link to post Share on other sites
_Isis_ 202 Report post Posted November 24, 2008 O módulo não leva extensão no import. SyntaxError: Non-ASCII character '\xf3' in file C:\Python25\curso\mysql.py on line 8, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details (mysql.py, line 8) O arquivo .py só "reconhece" caracteres ASCII (sem cedilha, sem tl, sem acento). P/ você escrever normalmente, coloque a linha #coding=UTF-8 depois do pybang. Share this post Link to post Share on other sites
alissong 1 Report post Posted November 25, 2008 import java.Isis, Pode-me explicar melhor, pois não entendi nada. Um abraço. Alissong Share this post Link to post Share on other sites
_Isis_ 202 Report post Posted November 25, 2008 Não coloque .py no import. Share this post Link to post Share on other sites
alissong 1 Report post Posted November 28, 2008 Import java.Isis, Estou fazendo assim, mas está exbindo esse erro: Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. **************************************************************** Personal firewall software may warn about the connection IDLE makes to its subprocess using this computer's internal loopback interface. This connection is not visible on any external interface and no data is sent to or received from the Internet. **************************************************************** IDLE 1.2.2 >>> import mysql Traceback (most recent call last): File "<pyshell#0>", line 1, in <module> import mysql ImportError: No module named mysql >>> Um abraço. Alissong Share this post Link to post Share on other sites
_Isis_ 202 Report post Posted November 28, 2008 Já viu se o módulo existe ou se ele está na pasta certa? Share this post Link to post Share on other sites
alissong 1 Report post Posted November 29, 2008 Import java.Isis, Acho que não estou fazendo confusão. Então, o módulo é esse: #!/usr/bin/python print #Declaracao das variaveis codigo = 0 #Programa codigo = int(raw_input('Digite o código do produto: ')) import MySQLdb # Conecta db = MySQLdb.connect(host="localhost", user="root", passwd="root", db="estoque") # Cria um cursor cursor = db.cursor() # Executa o SQL cursor.execute("SELECT * FROM produto WHERE cod_produto = %s", (codigo)) numrows = int(cursor.rowcount) # Lista uma linha de cada vez for x in range(0,numrows): row = cursor.fetchone() print "código:", "-", "Nome:", "-", "Preço Venda:" print row[0],"-",row[1],"-",row[4] E está salvo na pasta C:\Python25\curso\mysql.py Um abraço. Alissong Share this post Link to post Share on other sites
_Isis_ 202 Report post Posted December 1, 2008 E está salvo na pasta C:\Python25\curso\mysql.py Afinal, é mysql.py ou mysqldb.py ? Decida-se, homem... Share this post Link to post Share on other sites
giesta 29 Report post Posted January 25, 2009 Tira o acento da palavra 'código' em codigo = int(raw_input('Digite o código do produto: ')) Share this post Link to post Share on other sites
JLNTL 0 Report post Posted January 28, 2009 SyntaxError: Non-ASCII character '\xf3' in file C:\Python25\curso\mysql.py on line 8, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details (mysql.py, line 8) como o import.java.isis disse esse erro é em função dos acentos para solucionar esse problema add na 1 ou 2 linha esse comando # -*- coding: UTF-8 -*- aqui tem uma pagina explicando melhor por que isso acontece. http://www.pythonbrasil.com.br/moin.cgi/Pe...obreProgramacao Share this post Link to post Share on other sites
João Luiz MJ 0 Report post Posted January 28, 2009 o codigo ficaria assim #!/usr/bin/python # -*- coding: UTF-8 -*- print #Declaracao das variaveis codigo = 0 #Programa codigo = int(raw_input('Digite o código do produto: ')) import MySQLdb # Conecta db = MySQLdb.connect(host="localhost", user="root", passwd="root", db="estoque") # Cria um cursor cursor = db.cursor() # Executa o SQL cursor.execute("SELECT * FROM produto WHERE cod_produto = %s", (codigo)) numrows = int(cursor.rowcount) # Lista uma linha de cada vez for x in range(0,numrows): row = cursor.fetchone() print "código:", "-", "Nome:", "-", "Preço Venda:" print row[0],"-",row[1],"-",row[4] como voce tah usando o windows voce tem que baixa o modulo mysqldb o link está aqui: http://sourceforge.net/project/showfiles.p...lease_id=491012 aqui tem outro link que fala muito sobre banco de dados em python http://www.pythonbrasil.com.br/moin.cgi/BancosDeDadosSql Share this post Link to post Share on other sites