Python Forum

Full Version: Syntax error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hi. Im studing. I need to help. I will connect mysql from python in vscode. Im write cmd pip install mysql-connector. And im write vscode terminal pip install mysql-connector. And im write :

import mysql.connector


mydb = mysql.connector.connect(
    host="localhost",
    user="root",
    passwd=""
)

mycursor = mydb.cursor()

mycursor.execute("show database")

for x in mycursor:
    print(x) 
But i see error : import mysql.connector
^
SyntaxError: invalid character in identifier
did you install it?
python -m pip install mysql-connector
You should use BBcode to post an error message. Perhaps we would then be able to see at which postion the caret (^) points. But "invalid caracter" means most of the time an invisible character, only to be found with a hex-editor or so. Best is to remove the entire line and then type it again.
What editor or IDE are you using? Some of them automatically insert a BOM (Byte Order Mark) at the beginning of a text file.
(Mar-06-2020, 10:27 AM)Larz60+ Wrote: [ -> ]did you install it?
python -m pip install mysql-connector

Yes. terminal write and extra cmd write.
Sorry my english bad im Turkish...

(Mar-06-2020, 10:48 AM)ibreeden Wrote: [ -> ]You should use BBcode to post an error message. Perhaps we would then be able to see at which postion the caret (^) points. But "invalid caracter" means most of the time an invisible character, only to be found with a hex-editor or so. Best is to remove the entire line and then type it again.
What editor or IDE are you using? Some of them automatically insert a BOM (Byte Order Mark) at the beginning of a text file.
Visual Studio Code
Ibreeden şunu yazdı:

Quote:Bir hata mesajı göndermek için BBcode kullanmalısınız. Belki de, düzeltme (^) işaretinin hangi konumda olduğunu görebiliriz. Ancak "geçersiz karakter" çoğu zaman görünmez bir karakter anlamına gelir, yalnızca onaltılık düzenleyici ile bulunur. En iyisi tüm satırı kaldırmak ve tekrar yazmaktır.
Hangi editör veya IDE'yi kullanıyorsunuz? Bazıları otomatik olarak bir metin dosyasının başına bir Malzeme Listesi (Byte Order Mark) ekler.

BBcode, bir Markdown dilidir, IDE'nizin bir parçası değildir
Read this: Visual Studio UTF8 BOM support. BOM must be switched off.
Pls help. I can't bind sql Python in Vscode


result :
import mysql.connector
^
SyntaxError: invalid character in identifier
+help
Quote:
result :
import mysql.connector
^
  • What is the upcarat on line 3? try removing it
  • Try again
  • If you still get error after fixing that, delete the import statement and retype manually and save
  • Try again
(Mar-16-2020, 08:49 PM)Larz60+ Wrote: [ -> ]What is the upcarat on line 3? try removing it
The upcarat is the pointer that points to the place where the error is detected. So I believe there are invisible characters at the beginning of the file.
Pages: 1 2