Python Forum
Syntax error - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Syntax error (/thread-24828.html)

Pages: 1 2


Syntax error - oguzcan - Mar-06-2020

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


RE: Syntax error - Larz60+ - Mar-06-2020

did you install it?
python -m pip install mysql-connector


RE: Syntax error - ibreeden - Mar-06-2020

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.


RE: Syntax error - oguzcan - Mar-06-2020

(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


RE: Syntax error - Larz60+ - Mar-06-2020

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


RE: Syntax error - ibreeden - Mar-07-2020

Read this: Visual Studio UTF8 BOM support. BOM must be switched off.


RE: Syntax error - oguzcan - Mar-15-2020

Pls help. I can't bind sql Python in Vscode


result :
import mysql.connector
^
SyntaxError: invalid character in identifier


RE: Syntax error - oguzcan - Mar-16-2020

+help


RE: Syntax error - Larz60+ - Mar-16-2020

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



RE: Syntax error - ibreeden - Mar-17-2020

(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.