class Bar_abstract(metaclass=ABCMeta): pass # class Bar_base(Bar_abstract): # pass # c の拡張で実装 class Bar(Bar_base): pass
としているんですが、 bar = Bar() dir(bar) とすると、
#23 0x080719f5 in subtype_dict (obj=0xb73b69c4, context=0x0) at ../Objects/typeobject.c:1756 #24 0x0817670a in getset_get (descr=0x95c46fc, obj=0xb73b69c4, type=0x95acd44) at ../Objects/descrobject.c:148 #25 0x080719f5 in subtype_dict (obj=0xb73b69c4, context=0x0) at ../Objects/typeobject.c:1756 #26 0x0817670a in getset_get (descr=0x95c46fc, obj=0xb73b69c4, type=0x95acd44) at ../Objects/descrobject.c:148
/* Invariants: * ob_sval contains space for 'ob_size+1' elements. * ob_sval[ob_size] == 0. * ob_shash is the hash of the string or -1 if not computed yet. */
Matplotlibを使ってみたくて、http://fonnesbeck.github.com/ScipySuperpack/から、 インストールしました。 動くかどうかのtestとして、 >>> import matplotlib.pyplot as plt を入力したところ No module named dateutil.rrule というエラーがでてきてしまいます。
解決方法がわかる方、教えてください。
35 :名無しさん@いたづらはいやづら:2012/02/16(木) 00:03:08.05
>>33 500 internal server error だから 待ってればそのうち復活するんじゃない
f = lambda x: ''.join([random.choice(''.join([chr(x) for x in xrange(0x20, 0x7f)])) for _ in xrange(x)]) g = lambda x: ''.join([chr(random.randint(0x20, 0x7e)) for _ in xrange(x)])
51 :デフォルトの名無しさん:2012/02/28(火) 13:08:21.86
g = lambda x: ''.join(chr(random.randint(0x20, 0x7e)) for _ in xrange(x)) joinの引数は、リスト内包じゃなくてジェネレータ式で十分。
てきとうに作ったらキモくなった isascii = lambda c: c in u''.join(chr(x) for x in xrange(0x20, 0x7f)) u = u'アあa' '%*s' % (10 - len([x for x in u if not isascii(x)]), u) u' \uff71\u3042a' ちょっと後悔している
元々は print u' name length size %' for r in lst: print u'%8s%8d%6d%4d' % (r.name, r.l, r.s, r.p) みたいなテーブル表示をしてて 名前に日本語が混ざってるとずれてくるので 変だなーと思った次第です 日本語使わなければ済む問題なんですが
83 :デフォルトの名無しさん:2012/02/29(水) 14:56:23.62
east asian widthがambiguousなケースは要注意(キリル文字とか) そのような文字をどう表示するかは本当に環境やソフト次第なので… 「それらの文字を日本語フォントで表示するような環境なら」 全角扱いにすべきだが、例えば端末上で動作するようなソフトウェアは 端末がどのような文字をどのようなフォントでレンダリングするつもりなのか 知りようがない なので、例えばvimのようなソフトウェアは、そうした文字を全角扱い するかどうかをユーザが設定で指定できるようになっている
m = s->ob_type->tp_as_sequence; if (m && m->sq_item) { if (i < 0) { if (m->sq_length) { Py_ssize_t l = (*m->sq_length)(s); if (l < 0) return NULL; i += l; } } return m->sq_item(s, i); }
return type_error("'%.200s' object does not support indexing", s); }
>>> for y in [x for x in ar]: ... for cur in child: ... tmp.append({'idx' : y['idx'] + cur}) ... ... Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'ar' is not defined
>>496 一貫性とれてると思うけど? Pythonでは、はためから見たら条件分岐でかけばいいようなところにもしょっちょうtry-exceptを使う。 たとえば他の言語なら if value.isdigit(): n = int(value) else: n = 0 と書くところでも、Pythonでは try: n = int(value) except: n = 0 と書くのはよくあるし、とがめられるようなことはない。 あるところでは例外処理はなるべく使うなと言い、別のところでは(464のように)例外処理を使え、というのなら一貫性がないと言われても仕方ないけど、 Pythonでは例外処理は積極的に使われているのだから、もとから一貫している。
filenames = [ 'file%d.txt' % n for n in range(10) ] from contextlib import nested with nested(*(open(f) for f in filenames)) as fileobjs: print(fileobjs)
File "/base/python_runtime/python_dist/lib/python2.5/urllib.py", line 1222, in quote_plus return quote(s, safe) File "/base/python_runtime/python_dist/lib/python2.5/urllib.py", line 1214, in quote res = map(safe_map.__getitem__, s) KeyError: u'\xef'
Traceback (most recent call last): File "test.py", line 23, in <module> simplejson.loads(result) File "C:\Python27\lib\site-packages\simplejson-2.6.0-py2.7.egg\simplejson\__init__.py", line 451, in loads return _default_decoder.decode(s) File "C:\Python27\lib\site-packages\simplejson-2.6.0-py2.7.egg\simplejson\decoder.py", line 406, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "C:\Python27\lib\site-packages\simplejson-2.6.0-py2.7.egg\simplejson\decoder.py", line 424, in raw_decode raise JSONDecodeError("No JSON object could be decoded", s, idx) simplejson.decoder.JSONDecodeError: No JSON object could be decoded: line 1 column 0 (char 0)
def newton(f, s, r=1.0e-12): print 'f(x) = %s' % f try: sympy.pprint('solved: %s' % sympy.solve(f)) except NotImplementedError, e: print '''can't sove.''' f1 = sympy.diff(f, x) print '''f'(x) = %s''' % f1 while True: d = {'x': s} q, y, a = s, f(d).evalf(), f1(d).evalf() print d, y, a if sympy.abs(y) <= r: break s -= y / a if sympy.abs(s - q) <= r: break