Форум сайта python.su
88
py.user.nexthttps://docs.python.org/2/library/functions.html#open
Чего платформозависимо?
…and ‘a’ for appending (which on some Unix systems means that all writes append to the end of the file regardless of the current seek position)Any questions?
Офлайн
857
Shaman
https://docs.python.org/2/library/functions.html#open
ShamanЭто далеко не some, а практически на всех линуксах происходит.
which on some Unix systems
#!/usr/bin/env python3 with open('file.txt', 'a+b') as fout: fout.write(b'a1') fout.seek(0) fout.write(b'a2') fout.seek(0) fout.write(b'a3')
Отредактировано py.user.next (Ноя. 5, 2015 08:03:54)
Офлайн
221
py.user.next
Там же про UNIX написано, а под BSD семейство , Solaris или тп тоже будет работать также? а Другие UNIX подобные системы? в общем есть шанс, что найдется и/или было подобное.
Офлайн
857
У меня под FreeBSD нет питона (надо ставить всё заново), но думаю, там то же самое с append'ом происходит.
Линуксовый системный вызов:
man 2 open
O_APPEND
The file is opened in append mode. Before each write(2), the
file offset is positioned at the end of the file, as if with
lseek(2). O_APPEND may lead to corrupted files on NFS file sys‐
tems if more than one process appends data to a file at once.
This is because NFS does not support appending to a file, so the
client kernel has to simulate it, which can't be done without a
race condition.
...
CONFORMING TO
SVr4, 4.3BSD, POSIX.1-2001.
Отредактировано py.user.next (Ноя. 5, 2015 13:08:45)
Офлайн