Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Syntax error
#1
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
Reply
#2
did you install it?
python -m pip install mysql-connector
Reply
#3
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.
Reply
#4
(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
Reply
#5
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
Reply
#6
Read this: Visual Studio UTF8 BOM support. BOM must be switched off.
Reply
#7
Pls help. I can't bind sql Python in Vscode


result :
import mysql.connector
^
SyntaxError: invalid character in identifier
Reply
#8
+help
Reply
#9
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
Reply
#10
(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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Syntax error for "root = Tk()" dlwaddel 15 1,007 Jan-29-2024, 12:07 AM
Last Post: dlwaddel
Photo SYNTAX ERROR Yannko 3 333 Jan-19-2024, 01:20 PM
Last Post: rob101
  Syntax error while executing the Python code in Linux DivAsh 8 1,450 Jul-19-2023, 06:27 PM
Last Post: Lahearle
  Code is returning the incorrect values. syntax error 007sonic 6 1,135 Jun-19-2023, 03:35 AM
Last Post: 007sonic
  syntax error question - string mgallotti 5 1,249 Feb-03-2023, 05:10 PM
Last Post: mgallotti
  Syntax error? I don't see it KenHorse 4 1,194 Jan-15-2023, 07:49 PM
Last Post: Gribouillis
  Syntax error tibbj001 2 847 Dec-05-2022, 06:38 PM
Last Post: deanhystad
  Python-for-Android:p4a: syntax error in main.py while compiling apk jttolleson 2 1,777 Sep-17-2022, 04:09 AM
Last Post: jttolleson
  Mysql Syntax error in pymysql ilknurg 4 2,287 May-18-2022, 06:50 AM
Last Post: ibreeden
  Solving equation equal to zero: How to resolve the syntax error? alexfrol86 3 1,894 Feb-21-2022, 08:58 AM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020