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 Program to delete a file
- Python | Farthest point on horizontal lines in 2D plane
- Python | How to copy a nested list
- Python | Move or Copy Files and Directories
- Python | Copy and Paste Images onto other Image using Pillow
- How to get the permission mask of a file in Python
- Python | Excel File Comparison
- Rename all file names in your directory using Python
- Python | Scramble words from a text file
- Python | Reading an excel file using openpyxl module
- Python | Count occurrences of each word in given text file (Using dictionary)
- Python | Create an empty text file with current date as its name
- Python | Write multiple files data to master file
- Python Program for Efficient program to print all prime factors of a given number
- Python Program for Program to calculate area of a Tetrahedron
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.