• File write behaviour

    From Stefan Ram@21:1/5 to Azizbek Khamdamov on Sun Feb 19 17:01:02 2023
    Azizbek Khamdamov <azizbek.khamdamov@gmail.com> writes:
    |file = open("D:\Programming\Python\working_with_files\cities.txt", 'r+') |file.write("new city\n")
    |file.readlines()
    |file.close()

    Write operations are buffered. Try, 'file.flush()' directly
    after 'file.write("new city\n")'.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stefan Ram@21:1/5 to MRAB on Sun Feb 19 20:32:47 2023
    MRAB <python@mrabarnett.plus.com> writes:
    |When I build a path, I use os.path.join, so it's only a problem if one
    |of the strings refers to the root of a drive, e.g. "C:\\".

    Or, one also might use "pathlib".

    main.py

    import pathlib

    path = pathlib.Path( 'example' ).joinpath( 'note' ).with_suffix( '.txt' ) print( path )

    output

    example\note.txt

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)