Go中的函數與Python中的urllib.quote(string)相同嗎?謝謝!
爲urllib.quote文檔頁面():https://docs.python.org/2/library/urllib.htmlurllib.quote()在Go?
1
A
回答
1
http://play.golang.org/p/yNZZT-Xmfs
func main() {
fmt.Println(url.QueryEscape("/Hello, playground"))
}
// %2FHello%2C+playground
0
urllib.quote旨在引用一個URL的路徑部分。 Go的淨/ URL包不直接公開此功能,但你可以在它以一種迂迴的方式獲得:
func quote(s string) string {
return (&url.URL{Path: s}).RequestURI()
}
因爲Python函數逃脫超過它需要,這裏的報價功能和urllib.quote會並不總是給出相同的結果。
Go的QueryEscape提供和Python的urlib.quote_plus一樣的功能。
0
由於version 1.8,Go有url.PathEscape引用了URL的路徑部分,就像urllib.quote(string
)對Python所做的那樣。
相關問題
- 1. Python編碼與urllib.quote字符
- 2. urllib.quote在Python中的DOT字符(。)
- 3. 在Go
- 4. 在Go
- 5. Go是否存在Go? (像在Python中)
- 6. 遍歷在Go
- 7. 上在Go
- 8. DEAST_EXCEEDED在Go Bigquery
- 9. Python的urllib.quote()和urllib.unquote()的等效Javascript函數
- 10. 是否有與urllib.quote和urllib.unquote相當的Javascript?
- 11. go build vs go build file.go
- 12. 在Go服務websocket
- 13. Json解組在GO
- 14. Go go-gl OpenGL渲染問題
- 15. Go前端與HTML和Go的互動
- 16. Go使用Go來解析它自己?
- 17. 運行go go使用golang exec.Command
- 18. GOPATH和Go Web服務器:'go run myserver.go'
- 19. 在OS X(+ MacPorts)上構建一個帶portaudio-go的go項目
- 20. Go(Golang) - 檢查文件擴展名在Go中不工作
- 21. 在Windows中編譯.go ...&可以python連接到Go嗎?
- 22. 在Go中實現承諾
- 23. 在Go Martini中的Auth0
- 24. 在Go中解壓縮包
- 25. Dirname在Go中的等效
- 26. AppAssertionCredentials for Go在哪裏?
- 27. 是什麼`追加()...`在Go
- 28. Razor Code Go在哪裏?
- 29. 在Go中實現ICMP ping
- 30. 在Go中使用接口
例如:quote('/〜connolly /')產生'/%7econnolly /'。 – lkkeepmoving 2014-12-18 22:30:41
heh。看起來Go的'url'模塊是硬編碼的,根據[RFC-3986§2.3](https://tools.ietf.org/html)永遠不會轉義'〜','_','''或'-' /rfc3986#section-2.3),它表示他們的轉義形式*「不應該由URI生產者創建」*。 @lkkeepmoving你確定你需要逃避'〜'嗎? – 2014-12-18 22:51:09
@JeremyBanks是的,我希望能夠逃避〜而不是默認情況下。基本上,一個函數與urllib.quote(string [,safe])相同。 – lkkeepmoving 2014-12-18 23:00:16