On 2/19/2023 6:10 PM, Mats Wichmann wrote:
On 2/19/23 14:06, Dieter Maurer wrote:
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
On 2/19/23 14:06, Dieter Maurer wrote:
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
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
On 2/19/2023 2:31 PM, Chris Angelico wrote:
On Mon, 20 Feb 2023 at 06:24, Thomas Passin wrote:
On 2/19/2023 1:53 PM, Chris Angelico wrote:
On Mon, 20 Feb 2023 at 03:41, Azizbek Khamdamov
wrote:
Example 1 (works as expected)
file =
On 2023-02-19 19:31, Chris Angelico wrote:
On Mon, 20 Feb 2023 at 06:24, Thomas Passin wrote:
On 2/19/2023 1:53 PM, Chris Angelico wrote:
> On Mon, 20 Feb 2023 at 03:41, Azizbek Khamdamov
> wrote:
>>
>> Example 1 (works as expected)
>>
>> file =
On Mon, 20 Feb 2023 at 06:24, Thomas Passin wrote:
>
> On 2/19/2023 1:53 PM, Chris Angelico wrote:
> > On Mon, 20 Feb 2023 at 03:41, Azizbek Khamdamov
> > wrote:
> >>
> >> Example 1 (works as expected)
> >>
> >> file = open("D:\Programming\Python\working_with_files\cities.txt",
> >> 'r+') ##
On 2023-02-19 12:59:43 -0500, Thomas Passin wrote:
> On 2/19/2023 11:57 AM, Axy via Python-list wrote:
> > Looks like the data to be written is buffered, so actual write takes
> > place after readlines(), when close() flushes buffers.
> >
> > See io package documentation, BufferedIOBase.
> >
> >
On 2/19/2023 1:53 PM, Chris Angelico wrote:
On Mon, 20 Feb 2023 at 03:41, Azizbek Khamdamov
wrote:
Example 1 (works as expected)
file = open("D:\Programming\Python\working_with_files\cities.txt",
'r+') ## contains list cities
Side note: You happened to get lucky with P, w, and c, but for
On Mon, 20 Feb 2023 at 03:41, Azizbek Khamdamov
wrote:
>
> Example 1 (works as expected)
>
> file = open("D:\Programming\Python\working_with_files\cities.txt",
> 'r+') ## contains list cities
Side note: You happened to get lucky with P, w, and c, but for the
future, I recommend using forward
On 2/19/2023 11:57 AM, Axy via Python-list wrote:
Looks like the data to be written is buffered, so actual write takes
place after readlines(), when close() flushes buffers.
See io package documentation, BufferedIOBase.
The solution is file.flush() after file.write()
Another possibility,
On 2023-02-19 14:03, Azizbek Khamdamov wrote:
Example 1 (works as expected)
file = open("D:\Programming\Python\working_with_files\cities.txt",
'r+') ## contains list cities
# the following code adds new record to the beginning of the file,
expected behaviour
file.write("new city\n")
On 2023-02-19 16:57:02 +, Axy via Python-list wrote:
> Looks like the data to be written is buffered, so actual write takes place
> after readlines(), when close() flushes buffers.
>
> See io package documentation, BufferedIOBase.
>
> The solution is file.flush() after file.write()
Or
Looks like the data to be written is buffered, so actual write takes
place after readlines(), when close() flushes buffers.
See io package documentation, BufferedIOBase.
The solution is file.flush() after file.write()
Can't deny, such a behaviour looks utterly weird. Try to avoid designing
13 matches
Mail list logo