Write a python program to read contents of a file and copy only the content of odd lines into new file.
Input : Hello World Python Language Output : Hello Python Input : Python Language Is Easy Output : Python Is
Approach to the problem
1) Open file name bcd.txt in read mode and assign it to fn.
2) Open file name nfile.txt in write mode and assign it to fn1.
3) Read the content line by line of the file fn and assign it to cont.
4) Access each element from 0 to length of cont.
5) Check if i is not divisible by 2 then write the content in fn1 else pass.
6) Close the file fn1.
7) Now open nfile.txt in read mode and assign it to fn1.
8) Read the content of the file and assign it to cont1.
9) Print the content of the file and then close the file fn and fn1 .
Output : Python Is
- Python - Reading last N lines of a file
- Count number of lines in a text file in Python
- Python - Get number of characters, words, spaces and lines in a file
- Eliminating repeated lines from a file using Python
- Python | Copy and Paste Images onto other Image using Pillow
- Python program to reverse the content of a file and store it in another file
- Python program to check if a string has at least one letter and one number
- Python | Check if one dictionary is subset of other
- Python | Check if one tuple is subset of other
- Python | Farthest point on horizontal lines in 2D plane
- Python - Find the maximum number of triangles with given points on three lines
- How to remove lines starting with any prefix using Python?
- Python - Append content of one text file to another
- Python | How to copy a nested list
- Python | Move or Copy Files and Directories
- Copy a directory recursively using Python (with examples)
- Python Program to Reverse the Content of a File using Stack
- Python Program to delete a file
- Python Program to merge two files into a third file
- Python program to modify the content of a Binary File
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.