I deleted the contents of the message so I can avoid both of  the deadly
sins of top posting and bottom posting and chance committing  the sin of
replying without any context.

Of course, I am only replying to Jon wishing a real or feigned good luck to
the OP.

But seriously, the OP, AKA Rich, is making clear that he is making a tool
for his own use. It sounds like he wants to maintain a data repository of
his own with some info about his clients and then have the ability to
specify a name and pop up an email directed to them, or something along
those lines.

Without further info, this sounds like what quite a few popular and even
free mailers already do to some extent as you have an associated address
book. Some start doing possible matches as you type. I hazard Rich is not
using something this simple as he does seem to have some form-letter merge
or similar functionality in mind, such as automating the seemingly mandatory
"Dear XXX" salutation.

But if he is the creator and maintainer of his client data and chooses not
to use one of many available applications, then it seems he already has
reasons he wants a particular design for the data and simply wants us to
help him use it the way he wants. That could be communicated a bit more
clearly but after many messages back and forth, I have not exactly
understood it.

In my opinion, having created all kinds of mailers over the years, sometimes
the hard way, This strikes me as not really being about what mailing
functionality exists at all. As a general rule, you first create supporting
parts for your mail then pass them along to functionality that assembles the
mail as a set of headers and a body and dispatches it.

You as the programmer need to supply a body, tell it who to put on TO/CC/BB
lines, perhaps provide a subject, perhaps specify attachments, and off you
go. The exact methods will differ.

But what Rich presumably needs to do is have his program interact with him
in specifying who he wants to mail to and then looking it up in whatever
file arrangement it contains. If he also wants to use other parts such as a
human name or address inside the body of the text, his program needs to
merge the text he supplies along with extracted parts of the data.

Or is that not what he wants? The above could be quite straightforward and I
recall doing things like this with a simple shell script in UNIX.
Specifically, I created a text file where I recorded info for each person in
some format like

NAME|PHONE|EMAIL|COMMENT

Then to search for someone, you could use something like grep to find a name
by anchoring to the beginning or ending with the "|" so it does not match
the text in another field such as email or address, and use other utilities
ranging from cut to awk and getting the parts you want into variables and
then interpolate them into a message template and so on.

Of course, doing it in python is a good way to go too and should not be hard
once it is decided how to store the data. But again, this is re-inventing
things that others have already done. 

The python modules include many ways to store modular data. The books I have
read mention them all the time. Pick one. And, yes, you can choose to
maintain two files if that design works for you. Consider some storage
method that stores data in sections like:

[NAME one]
First: whatever
Email: whatever

[NAME two]
First: ...
Email: ...

There are specific formats along these lines and you can get python modules
that you ask for "NAME one" and it reads the file until it finds a section
as "[NAME one]" or not. If found, it returns the variables/values right
below it.  So your two step algorithm may consist of two files with one file
containing just names, perhaps to use a grep functionality on. Some of those
names will have a matching section like the above somewhere in the other
file. 

So if you want to send mail to "Jo" then your program may search for all
names starting with "Jo" and offer you "John Smith"  and perhaps also
"Joachim Martillo". The program takes whichever full name(s) you then select
and calls a function that uses that full name to search the second file to
find an exact match and returns what it finds there such as an email
address.

But unless you have lots of contacts, as already discussed, there are far
easier ways to do things in a more brute force way. Take a one-line per
entry format such as a CSV or TSV and extract whatever column contains the
name as needed to do the first search. Yes, this tends to mean reading the
entire file.

And, for the record, I am not a fan of hiding replies at the bottom except
for short messages. I prefer to use some combination of in-line if
addressing many points in the original and mainly the top with perhaps a
preface explaining what is being addressed. The reader is usually capable of
digging below if they want to know more. But this is a more religious war
having nothing to do with python specifically.

My frustration is that I often want to help someone and wish the problem was
stated in a way that made that doable. I do sympathize with Rich as figuring
out which details to focus on or to omit is not trivial. I may well be
wrong, but it sounds like his request could be focused on how to use
supporting files for an email application, or if stated clearly, as he
tried, about how to store data in two files and be able to extract what you
need as if it was all in one file. 

But what may not be easy to get through is the experience of years from when
you often stored data in multiple arrays and had to be careful to update
them all at once, to more modern methods using structs or classes to hold
more or all aspects of a related object as a unit. In this context, some may
simply read in all the data from a single file into something like a list of
objects (or a numpy/pandas variant) and have search and manipulation
abilities to find and change the right ones. The only diddling with files
that is needed is once to read them into the structure (such as JSON) and
perhaps once to write it back out with changes.

Good luck, once you decide on a particular method and flesh that out.




-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to