Board logo

標題: python 新手請教問題 [打印本頁]

作者: impotence    時間: 2022-1-10 14:17     標題: python 新手請教問題

本帖最後由 impotence 於 2022-1-10 15:04 編輯

用 pymssql 或者 pyodbc 連接 sql server , 因為 sql default 是 SQL_Latin1_General_CP1_CI_AS , 當有中文資料時, 會出現 'cp950' 的 error.
請問各位 ching 有冇辦法 !
謝謝 !
作者: XML    時間: 2022-1-10 15:52

cp950 unicode?
作者: shal    時間: 2022-1-10 16:35

用 pymssql 或者 pyodbc 連接 sql server , 因為 sql default 是 SQL_Latin1_General_CP1_CI_AS , 當有中文 ...
impotence 發表於 2022-1-10 14:17



    UnicodeEncodeError: ‘cp950’ codec can’t encode character?????

如果系呢個就你個用緊個 terminal 不支援呢個中文character
https://coder.tw/?p=7487
作者: impotence    時間: 2022-1-11 10:27

UnicodeEncodeError: ‘cp950’ codec can’t encode character?????

如果系呢個就你個用緊個 ...
shal 發表於 2022-1-10 16:35


多謝 ching 提示 ! 個結果同我直接喺 pymssql 中 加入 charset = 'cp950' 差唔多 !
如果係個 terminal 唔 support , 唔知有冇邊個 ide/terminal 可以 support ?
作者: shal    時間: 2022-1-11 13:51

多謝 ching 提示 ! 個結果同我直接喺 pymssql 中 加入 charset = 'cp950' 差唔多 !
如果係個 terminal 唔 ...
impotence 發表於 2022-1-11 10:27



    你用windows?
作者: XML    時間: 2022-1-11 14:01

點解唔轉utf8呢?
作者: impotence    時間: 2022-1-12 08:53

你用windows?
shal 發表於 2022-1-11 13:51


係 !!!
作者: impotence    時間: 2022-1-12 08:58

點解唔轉utf8呢?
XML 發表於 2022-1-11 14:01


SQL Server 既 default 係 SQL_Latin1_General_CP1_CI_AS.
已經嘗試 row[0].encode("utf8").decode("cp950","ignore") 及在 pymsmsql.connect 中加入 charset = 'cp950' 或 charset = 'cp1252' 依然在中文資料中顯示亂碼 !
本身用 Windows 及 VsCode 嘗試開發 ! 有冇其他建議 ?
作者: shal    時間: 2022-1-12 11:20

SQL Server 既 default 係 SQL_Latin1_General_CP1_CI_AS.
已經嘗試 row[0].encode("utf8").decode("cp95 ...
impotence 發表於 2022-1-12 08:58



    我DB 用開UTF8 多
如果用mac & osx + vscode 未見過有呢個問題
win下有呢個問提我會常試每次print時都轉一轉 chratset
注: 我用開ORM

import sys
reload(sys)
sys.setdefaultencoding('utf8')
row = User.select().execute()
print( row[0]['cname'].decode('big5').encode('utf8') )
作者: impotence    時間: 2022-1-12 14:03

我DB 用開UTF8 多
如果用mac & osx + vscode 未見過有呢個問題
win下有呢個問提我會常試每次print ...
shal 發表於 2022-1-12 11:20


抱歉 ching , 我係一個剛剛學左 python 幾日既新手 !
當用 reload(sys) 時 , 出現 : NameError: name 'reload' is not defined
作者: KinChungE    時間: 2022-1-12 14:15

抱歉 ching , 我係一個剛剛學左 python 幾日既新手 !
當用 reload(sys) 時 , 出現 : NameError: name 're ...
impotence 發表於 2022-1-12 14:03


佢講既係python 2
而家python 3唔係咁寫

https://blog.csdn.net/qq_36711420/article/details/79382327
import importlib,sys
importlib.reload(sys)
作者: impotence    時間: 2022-1-12 14:42

佢講既係python 2
而家python 3唔係咁寫


import importlib,sys
importlib.reload(sys) ...
KinChungE 發表於 2022-1-12 14:15


多謝 ching 指導 ! 但係都出現亂碼 ! 有冇其他提議 ? 定係直接放棄 python , 找尋其他 solution ?
作者: shal    時間: 2022-1-12 15:10

多謝 ching 指導 ! 但係都出現亂碼 ! 有冇其他提議 ? 定係直接放棄 python , 找尋其他 solution ? ...
impotence 發表於 2022-1-12 14:42



    你系mariadb / mysql / sqlite?
用什麼套件? ORM 定 MySQLdb?
作者: impotence    時間: 2022-1-12 15:22

你系mariadb / mysql / sqlite?
用什麼套件? ORM 定 MySQLdb?
shal 發表於 2022-1-12 15:10


Server : Windows 2019 + MSSQL 2012
PC : Windows 7 + VsCode + Python 3.8
action : 將 某個 db 中 的 某個 table 中的某些 資料 轉為 excel 比其他 application 讀取 !
作者: shal    時間: 2022-1-12 15:28

Server : Windows 2019 + MSSQL 2012
PC : Windows 7 + VsCode + Python 3.8
action : 將 某個 db 中 的 ...
impotence 發表於 2022-1-12 15:22



    XD 我公司都做左呢D 野
你用 pymssql 套件接 MSSQL 2012???
作者: impotence    時間: 2022-1-12 15:42

XD 我公司都做左呢D 野
你用 pymssql 套件接 MSSQL 2012???
shal 發表於 2022-1-12 15:28


係呀 ! 有乜好建議 ?
作者: impotence    時間: 2022-1-12 17:49

XD 我公司都做左呢D 野
你用 pymssql 套件接 MSSQL 2012???
shal 發表於 2022-1-12 15:28


最終結果 , 我可以經 pymssql 攞資料. 之後喺 VsCode 睇就出現亂碼 , 但係經 xlwt 輸出 excel 就可以正常出中文 !
咁即係個 VsCode 唔 support 中文 ?
作者: impotence    時間: 2022-1-12 17:59

各位 ching , 唔好意思 !
我又有新問題 ! 就係點樣可以喺部 windows 2019 server 下 set d python program 做 schedule job , 而且唔可以喺部 server 安裝 python ?
作者: it_jobs    時間: 2022-1-12 20:51

各位 ching , 唔好意思 !
我又有新問題 ! 就係點樣可以喺部 windows 2019 server 下 set d python program  ...
impotence 發表於 2022-1-12 17:59


亂 up:  有無 .py to .exe 嘅 software?
作者: shal    時間: 2022-1-13 08:38

各位 ching , 唔好意思 !
我又有新問題 ! 就係點樣可以喺部 windows 2019 server 下 set d python program  ...
impotence 發表於 2022-1-12 17:59



    in develop pc 下 安裝這個 pip install PyInstaller
https://realpython.com/pyinstaller-python/
作者: shal    時間: 2022-1-13 08:58

最終結果 , 我可以經 pymssql 攞資料. 之後喺 VsCode 睇就出現亂碼 , 但係經 xlwt 輸出 excel 就可以正常 ...
impotence 發表於 2022-1-12 17:49



    VsCode support 中文 呢個系windows cmd問題
作者: impotence    時間: 2022-1-13 09:01

VsCode support 中文 呢個系windows cmd問題
shal 發表於 2022-1-13 08:58


我一直以為 , 喺呢個年代 , 所有 ide 都應該 wysiwyg , 個 ide 顯示亂碼 , export 去 excel 都應該亂碼 !
害我花左好多時間去嘗試解決 ide 顯示中文問題 ......
作者: kennyleunghk    時間: 2022-1-13 16:27

如果寫自己project, 何苦要用sql server 呢?
好地地有mysql/ Postgresq / mongoDB唔用?





歡迎光臨 電腦領域 HKEPC Hardware (https://h0.hkepc.com/forum/) Powered by Discuz! 7.2