Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Doubt is not a pleasant condition, but certainty is absurd. -- Voltaire


devel / comp.lang.python / Re: File write, weird behaviour

SubjectAuthor
o Re: File write, weird behaviourDieter Maurer

1
Re: File write, weird behaviour

<mailman.1892.1676842789.20444.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21771&group=comp.lang.python#21771

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: die...@handshake.de (Dieter Maurer)
Newsgroups: comp.lang.python
Subject: Re: File write, weird behaviour
Date: Sun, 19 Feb 2023 22:06:19 +0100
Lines: 25
Message-ID: <mailman.1892.1676842789.20444.python-list@python.org>
References: <CAN14BN5=0sL-d8HQ4hyAYLicvGP4TzhbR=WEr6Ev-tV2TPJqWQ@mail.gmail.com>
<25586.36683.279969.179776@ixdm.fritz.box>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de 2X5X1kU4aqFvNCQ5OfN/2grhD4Xc0PWI7aljkWaJosaQ==
Return-Path: <dieter@handshake.de>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.043
X-Spam-Evidence: '*H*': 0.91; '*S*': 0.00; '(e.g.': 0.05; 'ansi':
0.09; 'cc:addr:python-list': 0.09; 'linux': 0.09; 'cc:no real
name:2**0': 0.14; 'condition.': 0.16; 'doc': 0.16; 'expected.':
0.16; 'skip:> 10': 0.16; 'subject:File': 0.16;
'cc:addr:python.org': 0.20; 'input': 0.21; 'code': 0.23;
'command': 0.23; 'received:de': 0.23; '(and': 0.25; 'anything':
0.25; 'cc:2**0': 0.25; 'behavior': 0.26; 'cities': 0.26; 'output':
0.28; 'effect': 0.31; '(as': 0.32; 'specified': 0.32; 'requires':
0.34; 'header:In-Reply-To:1': 0.34; 'following': 0.35; 'file':
0.38; 'could': 0.38; 'added': 0.39; 'list': 0.39; 'wrote': 0.39;
'beginning': 0.40; 'explain': 0.40; 'should': 0.40; 'above': 0.62;
'between': 0.63; 'operations.': 0.64; 'your': 0.64;
'header:Received:6': 0.67; 'content': 0.72; 'received:88': 0.84;
'violates': 0.84; 'weird': 0.84; 'positioning': 0.93
In-Reply-To: <CAN14BN5=0sL-d8HQ4hyAYLicvGP4TzhbR=WEr6Ev-tV2TPJqWQ@mail.gmail.com>
X-Mailer: VM 8.0.12-devo-585 under 21.4 (patch 24) "Standard C" XEmacs Lucid
(x86_64-linux-gnu)
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <25586.36683.279969.179776@ixdm.fritz.box>
X-Mailman-Original-References: <CAN14BN5=0sL-d8HQ4hyAYLicvGP4TzhbR=WEr6Ev-tV2TPJqWQ@mail.gmail.com>
 by: Dieter Maurer - Sun, 19 Feb 2023 21:06 UTC

Azizbek Khamdamov wrote at 2023-2-19 19:03 +0500:
> ...
>Example 2 (weird behaviour)
>
>file = open("D:\Programming\Python\working_with_files\cities.txt",
>'r+') ## contains list cities
># the following code DOES NOT add new record TO THE BEGINNING of the
>file IF FOLLOWED BY readline() and readlines()# Expected behaviour:
>new content should be added to the beginning of the file (as in
>Example 1)
>file.write("new city\n")
>
>file.readlines()
>file.close()
>
>I could not find anything in documentation to explain this strange
>behaviour. Why is this happening?

The effect of "r+" (and friends) is specified by the C standard.

The Linux doc (of `fopen`) tells us that ANSI C requires that
a file positioning command (e.g. `seek`) must intervene
between input and output operations. Your example above violates
this condition. Therefore, weird behavior is to be expected.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor