作者查詢 / stucode

總覽項目: 發文 | 留言 | 暱稱
作者 stucode 在 PTT [ Python ] 看板的留言(推文), 共230則
限定看板:Python
[問題] PIL image.open路徑相關問題
[ Python ]14 留言, 推噓總分: +1
作者: yimean - 發表於 2018/05/14 17:56(7年前)
8Fstucode: 把 \ 都改 \\ 就可以了。05/14 20:47
[問題] 程式碼請益
[ Python ]21 留言, 推噓總分: 0
作者: yimean - 發表於 2018/05/13 18:26(7年前)
1Fstucode: 1. sequence unpacking。在這裡是把 os.walk() 傳回的05/13 19:35
2Fstucode: tuple 拆開並分別指派給三個變數。05/13 19:35
3Fstucode: 2. 放在 if __name__ == '__main__': 區塊裡的程式碼只有05/13 19:35
4Fstucode: 在 script 直接被執行時才會執行。05/13 19:35
19Fstucode: 被 import 的話 if 以下不會執行沒錯,可以試試看:05/13 20:33
20Fstucode: https://repl.it/@csis/pynamedemo05/13 20:33
[問題] 用numpngw/apng儲存成.gif
[ Python ]10 留言, 推噓總分: -1
作者: znmkhxrw - 發表於 2018/04/11 12:11(7年前)
5Fstucode: 實際上還是 apng 沒錯。我之前是用 Pillow 來做,用是04/11 12:59
6Fstucode: 可以用不過針對 gif 的最佳化效果不太好,如果有時間的話04/11 12:59
7Fstucode: 也可以找找看有沒有其他的 library。04/11 13:00
[問題] 正則匹配不包含的符號
[ Python ]19 留言, 推噓總分: +2
作者: sagwow - 發表於 2018/04/01 10:03(7年前)
1Fstucode: r = s if ':' not in s else None # s = '123:abc'04/01 10:36
16Fstucode: 那句的意思是,如果字串 s 中不包含冒號就把 s 賦值給04/01 22:51
17Fstucode: 變數 r,否則就把 r 設為 None。s 是你要搜尋的任意字串04/01 22:51
18Fstucode: 就是文中第三句描述的功能。不過重新看了一下內文,你想04/01 22:51
19Fstucode: 要的是把字串中的冒號去掉嗎?04/01 22:52
[問題] dict問題
[ Python ]32 留言, 推噓總分: +10
作者: st40182 - 發表於 2018/03/18 19:40(7年前)
18Fstucode: 幫樓上 h 大補充,b 可以用 list comprehensions 就好03/19 05:36
19Fstucode: b = [d[v] for v in a]03/19 05:36
20Fstucode: 或是另一種方法:03/19 05:37
21Fstucode: a = list(d) # 等同於 list(d.keys())03/19 05:37
22Fstucode: b = list(d.values())03/19 05:37
29Fstucode: 如果沒有中途修改 dict 的話,dict.keys() 跟03/19 14:34
30Fstucode: dict.values() 順序會是對應的喔,官方文件有提到。03/19 14:36
[問題] 提取txt內文後重命名檔名
[ Python ]55 留言, 推噓總分: +2
作者: s4028600 - 發表於 2017/12/02 00:21(8年前)
3Fstucode: 1. os.walk() 2. os.getcwd() 後 os.walk()12/02 05:02
4Fstucode: 3. input() 或者 os.system('pause')12/02 05:03
5Fstucode: os.walk() 搭配 for ... in 使用。原 PO 如果沒有程式12/02 05:03
6Fstucode: 基礎的話,建議先找個基本教學看到迴圈部分再回來寫。12/02 05:03
8Fstucode: glob 也可以,但它是傳回檔名 list,一樣要搭配 for 迴圈12/02 22:28
9Fstucode: 來走訪每個檔案。12/02 22:29
19Fstucode: 如果不知道現在用的是哪個版本,可以這樣確認:12/02 23:18
20Fstucode: import sys12/02 23:19
21Fstucode: print(sys.version)12/02 23:19
22Fstucode: open(x, ...) # x 不加括號。加括號的話會變成開啟檔名為12/02 23:31
23Fstucode: x 的檔案。另外 f=open() 跟針對檔案處理的每個動作都要12/02 23:32
24Fstucode: 縮排,Python 是以縮排來決定程式碼區塊的。12/02 23:32
25Fstucode: * 抱歉,我是要說不加引號。12/02 23:37
35Fstucode: 檔案佔用是因為開檔讀取後沒有關閉,兩個解決方法:12/03 10:37
36Fstucode: f.close() 或 with open(...) as f:12/03 10:37
37Fstucode: 個人比較推薦後者,但前者對你來說可能比較好理解。12/03 10:37
38Fstucode: readlines() 讀取的字串中包含換行字元 '\n',要用於重新12/03 10:38
39Fstucode: 命名之前記得先裁掉(關鍵字:字串處理),其餘部分就是12/03 10:38
40Fstucode: danny 大提到的檔案系統不接受的字元,這部分依照需求12/03 10:38
41Fstucode: 處理方式不同,但一樣是做字串處理。只讀取最後一個檔案12/03 10:38
42Fstucode: 的問題,請去 google Python 縮排,中文資料也不少。12/03 10:38
55Fstucode: while True: 拿掉,for 前面不要有空格。12/03 22:38
[問題] 有關HTMLParser
[ Python ]5 留言, 推噓總分: 0
作者: lexus7310 - 發表於 2017/11/09 00:04(8年前)
1Fstucode: attrs == [('target', '_blank')] 會找到「只有」11/09 01:16
2Fstucode: target="_blank" 屬性的元素。一直不成立表示該頁面沒有11/09 01:17
3Fstucode: 符合這個條件的元素。如果想找所有包含該屬性的元素,11/09 01:17
4Fstucode: 請用 ('target', '_blank') in attrs。11/09 01:17
[問題] 爬蟲資料格式及處理
[ Python ]11 留言, 推噓總分: +4
作者: unhumanWu - 發表於 2017/10/25 22:12(8年前)
1Fstucode: 看起來是 JSON,Python 有內建函數庫。10/25 22:23
[問題] 怎麼用 Python 寫出 switch 的功能?
[ Python ]39 留言, 推噓總分: +7
作者: henry8168 - 發表於 2017/10/19 14:28(8年前)
6Fstucode: 覺得樓上正解,你需要的應該是 with 沒錯。每個語言特性10/19 18:09
7Fstucode: 不同,照般 C 的作法不見得比較好。10/19 18:09
9Fstucode: 大概像這樣 https://git.io/vd7iE10/19 18:38
15Fstucode: @djshen 不太懂 return 0 跟 finally 之間的關係@@。10/19 20:55
16Fstucode: 原 PO 之所以 return 0 應該是因為走 C 傳統用 return10/19 20:55
17Fstucode: value 判斷錯誤的處理架構,我這邊則是用 exception 做10/19 20:55
18Fstucode: 錯誤處理控制,非要 return 0 不可的話也可以做些修改。10/19 20:55
19Fstucode: 啊,好像懂了。你是指在 init_phase 成功的話,之後就不10/19 21:06
20Fstucode: 會再 call release 的意思嗎?10/19 21:06
27Fstucode: 同 AstralBrain 大看法。如果真的有出 init 就不 release10/20 05:16
28Fstucode: 的需求的話,加個 flag 變數或是自訂 exception 類別也可10/20 05:16
29Fstucode: 以達成。10/20 05:16
33Fstucode: 疊太多 with 的確是個問題。想了一下,原 PO 的 case 也10/20 12:23
34Fstucode: 許真的比較適合用 ExitStack。 https://git.io/vdd2Z10/20 12:23
[問題] 關於regular expression的\b問題
[ Python ]22 留言, 推噓總分: +2
作者: jamesxxx1997 - 發表於 2017/10/11 09:18(8年前)
14Fstucode: 並不是 \b 放在開頭就只會 match 到單字開頭的邊界,10/11 22:41
15Fstucode: 這兩個 re 並不等價,在這個句子只是碰巧產生相同結果。10/11 22:42
16Fstucode: 把句子換成 'Apples on the tree' 或是 'My arm',10/11 22:42
17Fstucode: 就可以明白其中差異。10/11 22:42