Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to put a text file into a list python

# name.txt
david
mary
john


with open('names.txt', 'r') as f:
    myNames = [line.strip() for line in f]
    
# Result

['david','mary','john']
Comment

write text in list to text file python

all_sents = ['hey there', 'how are you']
with open('file_name.txt', 'w', encoding='utf-8') as f:
   f.write('
'.join(all_sents)) 
Comment

PREVIOUS NEXT
Code Example
Python :: how to remove numbers from string in python pandas 
Python :: Update all packages using pip on Windows 
Python :: python click buttons on websites 
Python :: plot roc curve for neural network keras 
Python :: autoslugfield django 3 
Python :: numpy documentation 
Python :: python current time 
Python :: python youtube downloader mp3 
Python :: matplotlib plot title font size 
Python :: label encoder python 
Python :: numpy array with random numbers 
Python :: python: change column name 
Python :: pygame how to make a transparent surface 
Python :: python error get line 
Python :: perfect number in python 
Python :: install easygui 
Python :: python code region 
Python :: python messagebox 
Python :: python - give a name to index column 
Python :: run celery on windows 
Python :: how to plot count on column of dataframe 
Python :: how to get random word from text file in python 
Python :: Could not find a version that satisfies the requirement psycopg2=2.8 (from pgcli) (from versions: 2.7.5, 2.7.6, 2.7.6.1, 2.7.7) 
Python :: convert epoch to date time in python 
Python :: how to make a blank window open up in python 
Python :: USB: usb_device_handle_win.cc:1049 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F) 
Python :: how to remove plotly toolbar 
Python :: python Key–value database 
Python :: how to find wifi password using python 
Python :: python - remove scientific notation 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =