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 in Python by Arvind
• 2,960 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 by Neel
• 3,010 points

Related Questions In Python

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,210 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 in Python by Omkar
• 68,160 points
0 votes
1 answer

How to write data to a file in Python?

Refer to the below code. data=’whatever your data ...READ MORE

answered May 12 in Python by Shaam
+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 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 394 views
+4 votes
6 answers
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 in Python by Neel
• 3,010 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 in Python by Neel
• 3,010 points