How to save one list in a text file in Python

0 votes

Hi Guys,

I have one list. I want to save this list in a file. How can I do this?

Jun 25, 2020 in Python by akhtar
• 38,170 points
196 views

1 answer to this question.

0 votes

Hi@akhtar,

There is no inbuilt function available to save one list. But you can use a python script to save one list in a text file. I have attached one python script below.

list =['Hello','How are you?','Bye']
with open("list.txt", "w") as f:
    for s in list:
        f.write(str(s) +"\n")

I hope this will help you.

answered Jun 25, 2020 by MD
• 95,060 points

Related Questions In Python

0 votes
1 answer

How to list only text files in a directory using python?

Well, you are using a complex way. ...READ MORE

answered Feb 3, 2019 in Python by Omkar
• 69,090 points
1,320 views
0 votes
0 answers

How can we read a text file in a list in python?

Can you give the sample code as ...READ MORE

Jun 18, 2019 in Python by Waseem
• 4,540 points
80 views
0 votes
0 answers
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 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,842 views
0 votes
0 answers
0 votes
1 answer

How to transfer multiple lines in a file using python?

Hi@akhtar, I don't know it will help you ...READ MORE

answered Mar 31, 2020 in Python by MD
• 95,060 points
165 views
0 votes
1 answer

How to call a function from another file in Python?

Hi@akhtar, You can use the import keyword to ...READ MORE

answered Jun 24, 2020 in Python by MD
• 95,060 points
1,032 views