File write, weird behaviour

Chris Angelico rosuav at gmail.com
Sun Feb 19 13:53:25 EST 2023


On Mon, 20 Feb 2023 at 03:41, Azizbek Khamdamov
<azizbek.khamdamov at gmail.com> 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 slashes for your paths:

open("D:/Programming/Python/working_with_files/cities.txt", "r+")

Otherwise, you may run into annoying and hard-to-solve problems. Or
alternatively, you'll upgrade to a newer Python and start getting
warnings, which would at least tell you that there's a problem.

ChrisA


More information about the Python-list mailing list