Wednesday, August 05, 2009

Input and Output in Python

恥ずかしながら、いつも忘れるので...。

% python
Python 2.5.1 (r251:54863, Feb 6 2009, 19:02:12)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> f = open('/tmp/workfile', 'w')
>>> print f
<open file '/tmp/workfile', mode 'w' at 80a0960>
>>> f.write('This is a test\n')
>>> value = ('the answer', 42)
>>> print value
('the answer', 42)
>>> s = str(value)
>>> f.write(s)
>>> f.close()

No comments: