By Kodi Learn

2020-05-22 23:34:11 8 Comments

I am new in python and I want to create one program. for that program I need one support. I want to open python file in read mode and append mode only. I want to read the contents of file and add or remove some lines of file. In which mode I should open python file or which code should I use?


@WyattBlue 2020-05-22 23:41:47

You can use 'a' to append text to files. The '\n' represents a breakline.

with open('example.txt', 'a') as file:
    file.write("\nAdded text.")

@Kodi Learn 2020-05-22 23:49:59

Ok, I needed is a+ mode. Thank you for help.

Related Questions

Sponsored Content

21 Answered Questions

[SOLVED] How to install pip with Python 3?

31 Answered Questions

[SOLVED] How do I get time of a Python program's execution?

  • 2009-10-12 23:56:47
  • john2x
  • 1134180 View
  • 974 Score
  • 31 Answer
  • Tags:   python time

17 Answered Questions

[SOLVED] open() in Python does not create a file if it doesn't exist

16 Answered Questions

[SOLVED] "Large data" work flows using pandas

12 Answered Questions

[SOLVED] How to delete a file or folder?

10 Answered Questions

10 Answered Questions

[SOLVED] Why is "1000000000000000 in range(1000000000000001)" so fast in Python 3?

28 Answered Questions

[SOLVED] How to read a file line-by-line into a list?

16 Answered Questions

[SOLVED] What is a mixin, and why are they useful?

18 Answered Questions

[SOLVED] How do I remove/delete a folder that is not empty?

  • 2008-11-19 20:15:38
  • Amara
  • 649675 View
  • 845 Score
  • 18 Answer
  • Tags:   python file

Sponsored Content