2018-06-05から1日間の記事一覧

pythonの関数で返り値2つ以上返す

カンマ区切りでreturnするだけ def test(): return "str", 100配列で返ってくる result = test() print(type(result)) # <type 'tuple'> print(result) # ('str', 100) print(result[0]) # 'str' print(result[1]) # 100 print(result[2]) # IndexError: tuple index out o</type>…

pythonで小数点切り上げはmath.ceil

n = 123.987654 math.ceil(n) ネタ元 http://ll.just4fun.biz/?Python/%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AB/%E5%B0%8F%E6%95%B0%E7%82%B9%E4%BB%A5%E4%B8%8B%E3%81%AE%E5%80%A4%E3%81%AE%E6%93%8D%E4%BD%9C%E3%83%BB%E5%9B%9B%E6%8D%A8%E4%BA%94%E5%85%A5%…

pythonですべての例外をキャッチして詳細を表示

import traceback traceback.print_exc() def f1(a, b): return f2(a) + f2(b) def f2(x): return 1.0 / x try: f1(1.0, 0.0) except: import traceback traceback.print_exc() ネタ元 https://ja.stackoverflow.com/questions/6972/python%E3%81%A7%E3%81%9…

BitMEXのAPI叩きすぎ 注意。BitMEXのレートリミットは5分で150回 

エラー内容に You are being rate limitedとか HTTPError: 429 Client Error: Too Many Requests があったら叩きすぎ。限界超えると1時間BANされる。 短時間で何回もBANされると1週間BANされるbitMEXにログインしてればレートリミット300回だそうですが、bot…