Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python merge file

# Python program to mail merger
# Names are in the file names.txt
# Body of the mail is in body.txt

# open names.txt for reading
with open("names.txt", 'r', encoding='utf-8') as names_file:

    # open body.txt for reading
    with open("body.txt", 'r', encoding='utf-8') as body_file:

        # read entire content of the body
        body = body_file.read()

        # iterate over names
        for name in names_file:
            mail = "Hello " + name.strip() + "
" + body

            # write the mails to individual files
            with open(name.strip()+".txt", 'w', encoding='utf-8') as mail_file:
                mail_file.write(mail)
Comment

PREVIOUS NEXT
Code Example
Python :: Source code: Matrix Addition using Nested Loop 
Python :: Abstract Model inherit from another model django 
Python :: django orm filter equal insensitive 
Python :: tkinter window not responding during progress bar 
Python :: remove from list python by index 
Python :: generator expression python 
Python :: how to save the command result with ! in python 
Python :: dataframe no names from file 
Python :: how to minimisze python console 
Python :: string times python 
Python :: una esfera solida de radio 40 cm tiene una carga positiva 
Python :: a guide to numpy and pandas 
Python :: cos2x 
Python :: python beacon 
Python :: fibonacci 10th 
Python :: create loading in pyqt 
Python :: can data scientists become software developer 
Python :: how to element into the first index python 
Python :: python itérer dictionnaire 
Python :: python local variable 
Python :: Python Deleting Attributes and Objects 
Python :: python zahl abrunden 
Python :: comment analyser la différence de pixel entre deux images python 
Python :: bee swarm plot 
Python :: NLP text summarization preprocess and tokenization 
Python :: get list values in b/w indexes python 
Python :: proclus python 
Python :: convert matlab code to python 
Python :: Understand the most appropriate graph to use for your dataset visualization 
Python :: looping through models and plotting their performance 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =