Can't overwrite file on Windows

user164814

Whenever I try to overwrite a file in Python 2.7 this is what happens, code:

a = open('hello.txt')
a.write('my name is mark')

And my error is:

Traceback (most recent call last):
  File "C:\Users\Mark Malkin\Desktop\New folder\opener.py", line 2, in <module>
    a.write('my name is mark')
IOError: File not open for writing
Jared

From docs on open:

If mode is omitted, it defaults to 'r'.

To write instead use,

a = open('hello.txt', 'w')

Or better yet,

with open('hello.txt', 'w') as f:
    f.write('my name is mark')

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Can't overwrite a file wrapped in a using statement

From Dev

Can't Overwrite Text File - PHP

From Dev

On Windows, why can't you overwrite the executable of a running application?

From Dev

Can't overwrite swap

From Dev

Why can't I overwrite a file with processed value?

From Dev

Overwrite line in Windows batch file?

From Dev

Can not overwrite file in virtual directory

From Dev

Overwrite BMP file, can't delete, because it's used by another process - Dispose, using not working

From Dev

Why can't I overwrite an XML file that I read (i think I closed all streams)?

From Dev

Python- Can't overwrite first column of .csv file with new time stamp

From Dev

Find Location of File and Overwrite (Windows 10)

From Dev

How can I overwrite a file in UWP?

From Dev

Python won't overwrite 777 file

From Dev

Symfony 3: can't overwrite repository

From Dev

why I can't "overwrite" a method in javascript?

From Dev

Can't write to a text file in Windows Phone

From Dev

Can't rename a file in Windows 7

From Dev

Can't rename DLL file on Windows

From Dev

Can't open file in ipython in windows

From Dev

Can't use Windows File Explorer

From Java

Find and replace in file and overwrite file doesn't work, it empties the file

From Dev

Overwrite a file?

From Dev

C++ and Windows - how to overwrite exe file of the running program?

From Dev

How can I solve the multiple dots issue and overwrite the original file

From Dev

How can I overwrite an existing file in 7zip?

From Dev

Copy a file, but don't overwrite, without TOCTTOU issues in Python

From Dev

perforce doesn't overwrite file when forcing revision

From Dev

perforce doesn't overwrite file when forcing revision

From Dev

Why can't I overwrite the value of a variable like this?

Related Related

  1. 1

    Can't overwrite a file wrapped in a using statement

  2. 2

    Can't Overwrite Text File - PHP

  3. 3

    On Windows, why can't you overwrite the executable of a running application?

  4. 4

    Can't overwrite swap

  5. 5

    Why can't I overwrite a file with processed value?

  6. 6

    Overwrite line in Windows batch file?

  7. 7

    Can not overwrite file in virtual directory

  8. 8

    Overwrite BMP file, can't delete, because it's used by another process - Dispose, using not working

  9. 9

    Why can't I overwrite an XML file that I read (i think I closed all streams)?

  10. 10

    Python- Can't overwrite first column of .csv file with new time stamp

  11. 11

    Find Location of File and Overwrite (Windows 10)

  12. 12

    How can I overwrite a file in UWP?

  13. 13

    Python won't overwrite 777 file

  14. 14

    Symfony 3: can't overwrite repository

  15. 15

    why I can't "overwrite" a method in javascript?

  16. 16

    Can't write to a text file in Windows Phone

  17. 17

    Can't rename a file in Windows 7

  18. 18

    Can't rename DLL file on Windows

  19. 19

    Can't open file in ipython in windows

  20. 20

    Can't use Windows File Explorer

  21. 21

    Find and replace in file and overwrite file doesn't work, it empties the file

  22. 22

    Overwrite a file?

  23. 23

    C++ and Windows - how to overwrite exe file of the running program?

  24. 24

    How can I solve the multiple dots issue and overwrite the original file

  25. 25

    How can I overwrite an existing file in 7zip?

  26. 26

    Copy a file, but don't overwrite, without TOCTTOU issues in Python

  27. 27

    perforce doesn't overwrite file when forcing revision

  28. 28

    perforce doesn't overwrite file when forcing revision

  29. 29

    Why can't I overwrite the value of a variable like this?

HotTag

Archive