Extract lines from file, add to new files

Thomas Passin list1 at tompassin.net
Mon Jan 29 19:47:15 EST 2024


On 1/29/2024 11:15 AM, Rich Shepard via Python-list wrote:
>> For my use 1) the salutation and email address (always with an '@') are
>> sequential and 2) I'm developing the script to extract both from the same
>> file.
> 
> I've looked at my Python books "Python Crash Course," "Effective Python,"
> and "Python Tricks The Book" as well as web pages in my searches without
> finding the answer to what may be a simple question: how to specify a
> variable in one file that has its values in another file.
> 
> Specifically, how to I designate the salutation holder in the message file
> and pass it the name value from the name/email address file?
> 
> If this explanation is not sufficiently clear I'll re-write it. :-)
> 
> TIA,
> 
> Rich

I'm assuming this is a continuation of a previous thread about working 
with alternate lines with salutation and address, and I assume you've 
got that worked out.

If you aren't going to use one or another existing template system, 
perhaps the easiest is to use unique strings in the message file.  For 
example:

Dear __##so-and-so##__:
    Please don't write this message off as mere spam.
    Respectfully, Rich

Then you just do a replace of the unique string by the salutation. Don't 
change the original (i.e., template), make the changes to a copy that 
you will output.



More information about the Python-list mailing list