ããã©ã¡ã¼ã¿ãã½ã¼ããï¼URIã¨ã³ã³ã¼ããã key=value ã®å½¢ã«ã㦠& ã§ç¹ãã¾ãã ã®æ¸ãæ¹
http://d.hatena.ne.jp/Yoshiori/20100929/1285727199
ãã®è¨äºã§
åãæ¸ããã³ã¼ã
params_str = '&'.join(['%s=%s' % (urllib.quote(key, ''),urllib.quote(params[key], '')) for key in sorted(params)])
ã§ãããã ãããã¯ãã³ã¡ã³ã
id:agricola Python, ããã ãªã¹ãå å ã®ä½¿ãæ¹ã«ç¾ããªããªãâ¦â¦ãè¾æ¸ã®ãã¼ã¨å¤ãããã¼ã§ä¸¦ã¹æ¿ãã¦åãåºãã¦=ã§é£çµãããªã
['='.join((k, v)) for k, v in sorted(d.items(), key = lambda x: x[0])]ã¨ãæ¸ãæ°ãããã
http://b.hatena.ne.jp/agricola/20100929#bookmark-25281496
id:nishiohirokazu ããã©ãã¼ããã¦ãããè¨äºããã
http://d.hatena.ne.jp/nishiohirokazu/20100929/1285762532
ã§ãããã®ãã¯ãã³ã¡ã³ã
Python, ãã»ã urllib.quote()ã§ã¯ã©ã¼ãããæååã=ã§é£çµãã¦ãã®ã«%使ãã°æåå以å¤ãOKã¨ã¯çå¤ããªãå ã³ã¼ãã®æ義ã¯å¦å®ããªããããªã¹ãå å ã§å¯èªæ§ãä½ä¸ããã¦æå·§ã«èµ°ã£ãã®ã«ç¾ãç¡ãã®ã¯ããã ããªãã
http://b.hatena.ne.jp/agricola/20100930#bookmark-25295008
ã§ãid:nishiohirokazu ã®è©²å½ãããã¤ã³ããæç²ããã¨
æåã¯100%ã¤ã³ã¼ã«ã¨ããããã§ã¯ãªãã¦ã"%s=%s"ã®æ¹ã¯è¾æ¸ã®å¤ãstrã§ãªãã¦ãã¨ã©ã¼ã«ãªããªãã
http://d.hatena.ne.jp/nishiohirokazu/20100929/1285762532
"æåã®èª¬æ"ããã¦ãã ãã ã
ããä¸åº¦è¨ãã
"æåã®èª¬æ"ããã¦ãã ãã ã
ãªã®ã«èªå㧠urllib.quote() ãçããã³ã¼ããæ¸ãã¦ããã¦ã
ãã®ã³ã¼ãã«åè«ããããããã»ããã£ã¦ã¿ã°ã¾ã§ä»ãã¦è¦å½éãã®åè«ãããã®ã¯ã©ããªã®ããªã
ã¡ãªã¿ã«ãæåã®ä»¶ã"åã®ä¸»è¦³"ã§è¨ãã°
# ãã©ã¡ã¼ã¿ãã½ã¼ããï¼ for key in sorted(params) #URIã¨ã³ã³ã¼ããã (urllib.quote(key, ''),urllib.quote(params[key], '') #key=value ã®å½¢ã«ã㦠'%s=%s' # & ã§ç¹ãã¾ã '&'.join
ã¨ãã風ã«ã³ã¡ã³ãã®æç« ã©ããã«æ¸ãã¦ãã¤ãããªã®ã§ã
æå·§ã«èµ°ã£ãã¤ããããªããã ãã©ãªãâ¦â¦
ããããd.items() ã® 0 çªç®ã®è¦ç´ ããã¼ã«ããããã« lambda 使ã£ã¦ãæ¹ãæå·§ã«èµ°ã£ã¦ãæ°ããããã ãã©ãªã
ã¾ãããã®ã¸ãã¯å®æ§çãªãã®ãªã®ã§ãèªè»¢è»ç½®å ´ã®è°è«ã«ãªããããªã®ã§ããã¾ã好ããããªããã©ã
ãç¾ãç¡ããã¯ã¾ã ããããã»ããã¨ãè¨ãããã¨ãã¡ãã£ã¨ããã¯éãããããªãããªãã¨æã£ã¦æ¸ãã¦ã¿ã¾ããã