| adm | Find | login register |
elleryq joined: 2007-09-27 posted: 117 promoted: 5 bookmarked: 0 Taipei, Taiwan |
今天用 python 寫了兩個 script,配合 dropbox 之類的 syncing service 用的,想說就可以同步詞音的詞庫 程式在 https://github.com/elleryq/sync_gcin_tsin push_gcin_tsin.py 就把詞庫轉成文字檔,其實跟用 tsd2a32 是一樣的,只是更簡化一點點,參數就帶 syncing service 所 sync 路徑的檔案名稱,例如 ~/Dropbox/tsin32.txt merge_gcin_tsin_from.py 則是把文字檔跟目前詞音詞庫裡作比較(先看有無差集),有需要就先用 python 的 set 去做聯集,再用 tsa2d32 轉~用法一樣,就帶檔名。 未來有打算加的:
| |||||||||
elleryq joined: 2007-09-27 posted: 117 promoted: 5 bookmarked: 0 Taipei, Taiwan |
| |||||||||
dowba joined: 2009-08-30 posted: 35 promoted: bookmarked: Taichung |
請問設定好 init.py 並執行之後 出現 print e.reason ^ SyntaxError: invalid syntax 錯誤訊息
請問何解??? 系統環境為WINXP 設定值為: TSD2A32 = "C:\Program Files\gcin\bin\tsd2a32.exe" edited: 2
| |||||||||
elleryq joined: 2007-09-27 posted: 117 promoted: 5 bookmarked: 0 Taipei, Taiwan |
會不會是 indent 的問題啊?? 我用的都是 4 個空白,不是 tab ~ 然後最好加上 r,'\' 才不會被當成 escape 字元 TSD2A32 = r"C:\Program Files\gcin\bin\tsd2a32.exe" edited: 1
| |||||||||
elleryq joined: 2007-09-27 posted: 117 promoted: 5 bookmarked: 0 Taipei, Taiwan |
我補上對 Windows 的支援了,再煩請更新以後,試試看有沒有問題。 還沒加上 exclude 特定詞的功能,另外想到要補上 setup.py,以利於安裝、部署。 | |||||||||
dowba joined: 2009-08-30 posted: 35 promoted: bookmarked: Taichung |
仍有錯誤訊息: init.py line 20 AttributeError: "module" object has no attributes "create_unicode_buffer"
感激不盡! edited: 1
| |||||||||
elleryq joined: 2007-09-27 posted: 117 promoted: 5 bookmarked: 0 Taipei, Taiwan |
咦? 奇怪,我有在我 Windows XP 上試過,是可以的。我 python 版本是 2.6。
補充: 改用乾淨的 python27 (因為我原來的python26有裝pywin32、pygtk 之類的函式庫,怕有影響) 來測試,是沒有問題的。 再補充: 試用了 python3,果然就出現問題了,正在處理中... 才處理完 function 問題,想不到字串的處理也是問題... >_< edited: 2
| |||||||||
dowba joined: 2009-08-30 posted: 35 promoted: bookmarked: Taichung |
感謝辛勞! 使用的版本是 Python 3.2.1
現在的錯誤訊息是: TypeError: sequence item 0:expeted str instance, bytes found edited: 1
| |||||||||
elleryq joined: 2007-09-27 posted: 117 promoted: 5 bookmarked: 0 Taipei, Taiwan |
看來要認真研究 python 3 了,library的名字更換這倒是小事,字串與檔案的處理真的是... ~_~ | |||||||||
elleryq joined: 2007-09-27 posted: 117 promoted: 5 bookmarked: 0 Taipei, Taiwan |
已經完成 python3 的移植,目前 python2/python3 都可以執行,在我這邊的linux下沒問題,windows下還沒測試。煩請再試試看,謝謝。 | |||||||||
dowba joined: 2009-08-30 posted: 35 promoted: bookmarked: Taichung |
沒有出現明顯的ERROR訊息 但是沒有成功 出現的訊息是 You need to install gcin
沒有更改過任何設定 有沒有需要做任何更改呢?
另外,如果我想要追蹤home app_data_dir USER_GCIN_DIR這三個變數 要怎麼樣可以讓他們print出來呢? 謝謝! 謝謝辛勞! edited: 2
| |||||||||
elleryq joined: 2007-09-27 posted: 117 promoted: 5 bookmarked: 0 Taipei, Taiwan |
該死,我忘記 Windows Vista/7 了... 你可以在 line 39 後新增,就設置 USER_GCIN_DIR 後,加上
| |||||||||
dowba joined: 2009-08-30 posted: 35 promoted: bookmarked: Taichung |
忘了講 上面那個不成功訊息是Windows 7的 Windows 7 之下目錄還是錯的 會出現You need to install gcin的錯誤訊息 辛苦了! edited: 1
| |||||||||
elleryq joined: 2007-09-27 posted: 117 promoted: 5 bookmarked: 0 Taipei, Taiwan |
這版改去 registry 取得 gcin 的安裝目錄,並且在 linux/windows 2.6/2.7/3.0 交叉測試過,應該是沒問題了。煩請再試試看,感恩。 | |||||||||
dowba joined: 2009-08-30 posted: 35 promoted: bookmarked: Taichung |
還是有問題@@不是刻意找碴,是真的就有問題…… 錯誤訊息為 WindowsError: [Error 2] The system cannot find the file specified
我的登錄檔中,HKEY_LOCAL_MACHINE 裡面的 gcin_dir 以及 install_dir 落在 HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\gcin(64位元的系統) 除此之外,HKEY_CURRENT_USER 裡面,HKEY_CURRENT_USER\Software\gcin 之下只有一個 Name=(Default),Type=REG_SZ,Data 為空的值,只有目錄,沒有任何值 。 其他有地方可以參考: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run 之下有一個 Name=gcin,Type=REG_SZ,Data="C:\Program Files (x86)\gcin\bin\gcin.exe" 的值 HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Compatibility Assistant\Persisted 之下有一個 Name=C:\Program Files (x86)\gcin\bin\gcin-setup.exe,Type=REG_DWORD,Data=0x0000000(1) 的值
| |||||||||
elleryq joined: 2007-09-27 posted: 117 promoted: 5 bookmarked: 0 Taipei, Taiwan |
沒關係。 因為我手邊沒有 64bit 的 Windows,可以幫我試一下這段程式,然後告訴我執行結果嗎?
from winreg import HKEY_LOCAL_MACHINE, REG_SZ edited: 2
| |||||||||
dowba joined: 2009-08-30 posted: 35 promoted: bookmarked: Taichung |
執行結果為: WindowsError: [Error 2] The system cannot find the file specified
| |||||||||
elleryq joined: 2007-09-27 posted: 117 promoted: 5 bookmarked: 0 Taipei, Taiwan |
那這樣呢? from winreg import HKEY_LOCAL_MACHINE, REG_SZ | |||||||||
dowba joined: 2009-08-30 posted: 35 promoted: bookmarked: Taichung |
抱歉,回覆晚了 仍是出現錯誤訊息如下: [Error 2] The system cannot find the file specified
單獨第一個try的執行結果是 [Error 2] The system cannot find the file specified 單獨第二個try的執行結果是 [Error 5] Access is denied 以administrator身份執行第二個try,其結果為 " key 2 C:\Program Files(x86)\gcin "
用上面的程式碼依樣畫葫蘆去改init.py,並且以administrator身份去執行,已經可以成功了,謝謝前輩辛苦! edited: 3
| |||||||||
elleryq joined: 2007-09-27 posted: 117 promoted: 5 bookmarked: 0 Taipei, Taiwan |
抱歉,可以再請你試一次嗎?看這樣可不可以不需要 Administrator 權限。謝謝~ from winreg import HKEY_LOCAL_MACHINE, REG_SZ | |||||||||
dowba joined: 2009-08-30 posted: 35 promoted: bookmarked: Taichung |
這樣子不用administrator權限也可以成功抓到! 執行結果: key2 C:\Program Files (x86)\gcin
不過照這次的程式碼修改入init.py,使用 merge_gcin_tsin_from.py 會出現 C:\Users\J\Appdata\Roaming\gcin\tsin32 or D:\Documents\Dropbox\tsin32.txt is empty 的錯誤訊息。但是 gcin_install_dir 的值沒有錯誤,且確定這二個檔案都存在。 push_gcin_tsin.py 則是非常順利,成功顯示 Done 的訊息。 以下是已經成功的 init.py
謝謝辛勞! edited: 8
| |||||||||
elleryq joined: 2007-09-27 posted: 117 promoted: 5 bookmarked: 0 Taipei, Taiwan |
我有更新,請再拉回去試試。如果 merge 仍然失敗的話,可以在 merge_gcin_tsin_from.py 的第 18 行之下,新加一行:print( 'len(current)=', len(current), 'len(cloud)=', len(cloud) ) 然後把輸出結果貼上來看看。 | |||||||||
dowba joined: 2009-08-30 posted: 35 promoted: bookmarked: Taichung |
出現的結果是:D:\Documents\Dropbox\tsin32.txt is empty, skip to merge 上述程式碼執行結果為:len(current)= 38892 len(cloud)= 0 不知道是否有誤? | |||||||||
dowba joined: 2009-08-30 posted: 35 promoted: bookmarked: Taichung |
出現的結果是:D:\Documents\Dropbox\tsin32.txt is empty, skip to merge 上述程式碼執行結果為:len(current)= 38892 len(cloud)= 0 不知道是否有誤? | |||||||||
elleryq joined: 2007-09-27 posted: 117 promoted: 5 bookmarked: 0 Taipei, Taiwan |
咦? 你的 D:\Documents\Dropbox\tsin32.txt 是空的嗎? 如果有內容,可否寄給我看看?? elleryq (at) gmail (dot) com , thanks | |||||||||
elleryq joined: 2007-09-27 posted: 117 promoted: 5 bookmarked: 0 Taipei, Taiwan |
謝謝你,我已經修改過程式,現在應該是沒問題了,煩請再試試看。 | |||||||||
dowba joined: 2009-08-30 posted: 35 promoted: bookmarked: Taichung |
這次的結果為: len(current)= 38892 len(cloud)= 38892 應該是沒問題了!感謝辛勞!
|
| adm | Find | login register |