Extract lines from file, add to new files

2024-01-11 Thread Rich Shepard via Python-list
It's been several years since I've needed to write a python script so I'm asking for advice to get me started with a brief script to separate names and email addresses in one file into two separate files: salutation.txt and emails.txt. An example of the input file: Calvin cal...@example.com Hob

Re: Extract lines from file, add to new files

2024-01-11 Thread Rich Shepard via Python-list
On Thu, 11 Jan 2024, MRAB via Python-list wrote: From the look of it: 1. If the line is empty, ignore it. 2. If the line contains "@", it's an email address. 3. Otherwise, it's a name. MRAB, Thanks. I'll take it from here. Regards, Rich -- https://mail.python.org/mailman/listinfo/python-lis

Re: Extract lines from file, add to new files

2024-01-11 Thread Rich Shepard via Python-list
On Thu, 11 Jan 2024, Mats Wichmann via Python-list wrote: 4. Don't assume it's going to be "plain text" if the email info is harvested from external sources (like incoming emails) - you'll end up stumbling over a 誰かのユーザー from somewhere. Process as bytes, or be really careful about which encoding

Re: Extract lines from file, add to new files

2024-01-11 Thread Rich Shepard via Python-list
On Thu, 11 Jan 2024, Piergiorgio Sartor via Python-list wrote: Why not to use bash script for all? Piergiorgio, That's certainly a possibility, and may well be better than python for this task. Thank you, Rich -- https://mail.python.org/mailman/listinfo/python-list

RE: Extract lines from file, add to new files

2024-01-12 Thread Rich Shepard via Python-list
On Fri, 12 Jan 2024, AVI GROSS via Python-list wrote: But is the solution a good one for some purpose? The two output files may end up being out of sync for all kinds of reasons. One of many "errors" can happen if multiple lines in a row do not have an "@" or a person's name does, for example. W

RE: Extract lines from file, add to new files

2024-01-29 Thread Rich Shepard via Python-list
On Fri, 12 Jan 2024, 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,

RE: Extract lines from file, add to new files

2024-01-29 Thread Rich Shepard via Python-list
On Mon, 29 Jan 2024, dieter.mau...@online.de wrote: Have you read "https://docs.python.org/3/library/io.html#module-io";? Dieter, No, I hadn't ... but I am reading it now. Many thanks, Rich -- https://mail.python.org/mailman/listinfo/python-list

RE: Extract lines from file, add to new files

2024-01-29 Thread Rich Shepard via Python-list
On Mon, 29 Jan 2024, Rich Shepard via Python-list wrote: No, I hadn't ... but I am reading it now. Perhaps I missed the answer to my question when reading the io module. It explains how to open/write/read files of text and binary data, not passing a variable's value from one file

RE: Extract lines from file, add to new files [RESOLVED]

2024-01-29 Thread Rich Shepard via Python-list
On Mon, 29 Jan 2024, Rich Shepard via Python-list wrote: I'll keep searching for a solution. IIRC, someone here pointed me to <https://realpython.com/python-send-email/> and I forgot about it ... until now. Regards, Rich -- https://mail.python.org/mailman/listinfo/python-list

RE: Extract lines from file, add to new files

2024-01-29 Thread Rich Shepard via Python-list
On Mon, 29 Jan 2024, avi.e.gr...@gmail.com wrote: There are several general solutions that may apply. Some involve reading in both files into data structures and perhaps linking them together in some way such as a data.frame or binary tree. You can then process individual request in memory/ Av

Re: Extract lines from file, add to new files

2024-01-30 Thread Rich Shepard via Python-list
On Mon, 29 Jan 2024, Thomas Passin via Python-list wrote: 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

Re: Extract lines from file, add to new files

2024-01-30 Thread Rich Shepard via Python-list
On Tue, 30 Jan 2024, Thomas Passin via Python-list wrote: Fine, my toy example will still be applicable. But, you know, you haven't told us enough to give you help. Do you want to replace text from values in a file? That's been covered. Do you want to send the messages using those libraries? You

RE: Extract lines from file, add to new files

2024-01-30 Thread Rich Shepard via Python-list
On Tue, 30 Jan 2024, AVI GROSS via Python-list wrote: 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 u

Re: Aw: Re: Extract lines from file, add to new files

2024-01-30 Thread Rich Shepard via Python-list
On Tue, 30 Jan 2024, Karsten Hilbert wrote: Why not foxus on just the part you think you are better off using python, namely personalization ? Create personalized files and send them with your trusted mailx solution ? Karsten, Too much time. And while mailx accepts the '-a' option for attach

Re: Aw: Re: Re: Extract lines from file, add to new files

2024-01-30 Thread Rich Shepard via Python-list
On Tue, 30 Jan 2024, Karsten Hilbert wrote: It doesn't need to. It just sends the (pre-personalized-by-Python) mail files. Karsten, In which case, I might as well have Python format and send the messages. :-) Regards, Rich -- https://mail.python.org/mailman/listinfo/python-list

Re: Extract lines from file, add to new files

2024-01-31 Thread Rich Shepard via Python-list
On Tue, 30 Jan 2024, Thomas Passin via Python-list wrote: If I had a script that's been working for 30 years, I'd probably just use Python to do the personalizing and let the rest of the bash script do the rest, like it always has. The Python program would pipe or send the personalized messages