rabbitfoot530's diary

読んだ本と、プログラムに関することのメモです。好きな言語は、C++, Python, Golang, TypeScript。数学・物理・学習理論も好きです。

2014-02-22から1日間の記事一覧

PythonによるLinuxプログラミングインタフェース(5章 mkstemp)

第5章のP115のテンポラリファイル作成のpythonコード。 #/usr/bin/env #-*- encoding: utf-8 -*- import tempfile import os import time # don't use # os.tmpnam (see: http://docs.python.org/2/library/os.html#os.tmpnam) # os.tempnam (see: http://do…

PythonによるLinuxプログラミングインタフェース(5章 truncate)

第5章P109のtruncateについて。 #/usr/bin/env #-*- encoding: utf-8 -*- import os def pythonic(): path = "./p109_truncate.txt" file = open(path, 'w', encoding='utf-8') file.write("abc") # write "abc" and offset move to 3 is end of file. print…

PythonによるLinuxプログラミングインタフェース(5章 pread)

第5章のP105のpreadのサンプル。 #/usr/bin/env #-*- encoding: utf-8 -*- import os def pythonic(): file = open(__file__, encoding='utf-8') orig = file.tell() print("before offset: {0}".format(file.tell())) offset = 10 file.seek(offset) lines …

PythonによるLinuxプログラミングインタフェース(5章 dup)

5章P103のdupのpythonコード。 #/usr/bin/env #-*- encoding: utf-8 -*- import os def pythonic(): def run(): py_dup() py_dup2() def py_dup(): newfd = os.dup(1) print("newfd: " + str(newfd)) os.close(2) newfd = os.dup(1) print("newfd: " + str(n…

PythonによるLinuxプログラミングインタフェース(4章 read, write, lseek)

4章のP90ページのread, write, lseekのプログラム。 #/usr/bin/env #-*- encoding: utf-8 -*- import sys def pythonic(): try: file = open(sys.argv[1], 'r+', encoding='utf-8') except IOError as e: print("err: " + e) else: try: ap = 2 argc = len(s…