How to write content of one file to another file in Python

0 votes
I have a text file containing 10 lines of data such as maddy:1190, johny:1123 and so on. Now I want another text file with only names such as maddy, johny and so on. How to do it?
Aug 26, 2019 in Python by Arvind
• 3,000 points

1 answer to this question.

0 votes
The following code snippet might solve your problem. Have a look at it.

my_file = open('abc.txt', 'w')
for line in lines:
    var1, var2 = line.split(",");
    my_file.write("%s\n" % var1)

answered Aug 26, 2019 by Neel
• 3,020 points

Related Questions In Python

0 votes
0 answers

i want to ask that how can i run one file of python in another file in jupyter notebook

motion_detection.ipynb # Python program to implement # Webcam ...READ MORE

Dec 16, 2020 in Python by Ramsha
• 120 points
0 votes
1 answer

How do I append one string to another in Python?

If you only have one reference to ...READ MORE

answered Oct 22, 2018 in Python by SDeb
• 13,300 points
0 votes
1 answer

How to check latest change time of each file using glob in python?

You can get the changing time from ...READ MORE

answered Jan 2, 2019 in Python by Omkar
• 69,170 points
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 2,424 views
0 votes
0 answers
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,810 points
0 votes
1 answer

How to get permutations of list or a set in Python?

Permutation is an arrangement of objects in ...READ MORE

answered Jul 11, 2019 in Python by Neel
• 3,020 points
+1 vote
1 answer

How to print a pyramid of asterisks in Python?

This is one of the most frequently ...READ MORE

answered Aug 1, 2019 in Python by Neel
• 3,020 points