Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

If it's worth hacking on well, it's worth hacking on for money.


devel / comp.lang.python / RE: Extract lines from file, add to new files

SubjectAuthor
o RE: Extract lines from file, add to new files<avi.e.gross

1
RE: Extract lines from file, add to new files

<mailman.31.1706675156.3227.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=24984&group=comp.lang.python#24984

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From:
Newsgroups: comp.lang.python
Subject: RE: Extract lines from file, add to new files
Date: Tue, 30 Jan 2024 23:25:50 -0500
Lines: 101
Message-ID: <mailman.31.1706675156.3227.python-list@python.org>
References: <c9cf741b-9781-8dd6-96df-d270d0ac2@appl-ecosys.com>
<2a5eef2d-3d66-8cea-64eb-602ea5aff946@appl-ecosys.com>
<f1784a5b-662a-47fc-ada0-cc09ea2cfc24@tompassin.net>
<9028bd96-dbc8-fbc1-8584-a965ef7def5d@appl-ecosys.com>
<5cea1ab2-1848-41bd-8e5b-323fe55ba8c9@tompassin.net>
<478e3bbe-db95-9533-595b-7a19a5e2cf@appl-ecosys.com>
<e0c1c61d-2941-452a-8977-ef5c5bfb8bdb@tompassin.net>
<004c01da53fd$9273b9e0$b75b2da0$@gmail.com>
Mime-Version: 1.0
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de 4Z85xYoz7rWOnSGHWdPnTwbVKCnIbl08qud0PRfjvfEw==
Cancel-Lock: sha1:V75Imu6QK6XLDdf+oOV2UuKipKY= sha256:o7sDYDwIeWFwC98l0cAdyiO9JUH8szq6JiVcAMl7Njg=
Return-Path: <avi.e.gross@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=iWfL426V;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.004
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'csv': 0.03; 'fairly':
0.05; 'file?': 0.05; 'architecture': 0.07; 'modules': 0.07;
'subject:add': 0.07; 'tab': 0.07; 'wanting': 0.07; 'pandas': 0.09;
'received:108': 0.09; 'received:209.85.219': 0.09;
'subject:files': 0.09; 'downloaded': 0.13; 'import': 0.15;
'url:mailman': 0.15; '2024': 0.16; 'addresses.': 0.16; 'answer.':
0.16; 'anyway.': 0.16; 'bash': 0.16; 'batch': 0.16; 'categories':
0.16; 'columns': 0.16; 'complexity.': 0.16; 'database.': 0.16;
'else?': 0.16; 'explaining': 0.16; 'exported': 0.16; 'heavily':
0.16; 'mentioned,': 0.16; 'pipe': 0.16; 'script.': 0.16;
'shepard': 0.16; 'somewhat': 0.16; 'tab.': 0.16; 'these.': 0.16;
'toy': 0.16; 'usual,': 0.16; 'ways.': 0.16; 'whatever.': 0.16;
'wrote:': 0.16; 'python': 0.16; 'values': 0.17; 'probably': 0.17;
'message-id:@gmail.com': 0.18; 'addresses': 0.19; "aren't": 0.19;
'pm,': 0.19; 'tue,': 0.19; 'to:addr:python-list': 0.20; 'input':
0.21; "i've": 0.22; 'maybe': 0.22; 'subject:file': 0.22;
'version': 0.23; 'lines': 0.23; "i'd": 0.24; 'skip:- 10': 0.25;
'url-ip:188.166.95.178/32': 0.25; 'url-ip:188.166.95/24': 0.25;
'help.': 0.25; 'url:listinfo': 0.25; 'url-ip:188.166/16': 0.25;
'else': 0.27; 'bit': 0.27; 'done': 0.28; 'example,': 0.28; 'url-
ip:188/8': 0.31; 'program': 0.31; '(as': 0.32; 'collected': 0.32;
'do.': 0.32; 'extract': 0.32; 'formats': 0.32; 'python-list':
0.32; 'split': 0.32; 'structure': 0.32; 'but': 0.32; "i'm": 0.33;
'there': 0.33; 'script': 0.33; 'header:In-Reply-To:1': 0.34;
'received:google.com': 0.34; 'one.': 0.35; 'usual': 0.35;
'from:addr:gmail.com': 0.35; 'files': 0.36; 'pdf': 0.36; 'those':
0.36; 'necessarily': 0.37; 'subject:from': 0.37; 'using': 0.37;
'received:209.85': 0.37; 'file': 0.38; 'way': 0.38; 'could': 0.38;
'read': 0.38; 'received:209': 0.39; 'changes': 0.39; 'quite':
0.39; 'single': 0.39; 'text': 0.39; 'enough': 0.39; 'mentioned':
0.39; 'list': 0.39; 'use': 0.39; 'best': 0.61; 'search': 0.61;
'today': 0.61; 'from:': 0.62; 'me.': 0.62; 'to:': 0.62; 'simply':
0.63; 'email': 0.63; 'send': 0.63; 'once': 0.63; 'providing':
0.63; 'pass': 0.64; 're:': 0.64; 'thus': 0.64; 'your': 0.64;
'his': 0.65; 'top': 0.65; 'years': 0.65; 'let': 0.66; 'improve':
0.66; 'decided': 0.67; 'back': 0.67; 'matter': 0.68; 'chance':
0.71; 'market': 0.71; 'january': 0.71; 'product': 0.71; 'name,':
0.75; 'selecting': 0.76; 'sent:': 0.78; 'major': 0.78; 'database':
0.80; 'out.': 0.80; 'queries': 0.81; 'more.': 0.82; 'points':
0.84; 'choices': 0.84; "people's": 0.84; 'personalized': 0.84;
'recipients.': 0.84; 'schema': 0.84; 'spreadsheets': 0.84;
'tables': 0.84; 'tend': 0.91
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20230601; t=1706675152; x=1707279952; darn=python.org;
h=thread-index:content-language:content-transfer-encoding
:mime-version:message-id:date:subject:in-reply-to:references:to:from
:from:to:cc:subject:date:message-id:reply-to;
bh=POfo9ZFT3NEkdYVblhyS9OLaSeE/6VEsE82ycxkaWFI=;
b=iWfL426V32vwx694Lr+i3wFggM/gN7dequGhmc2DYL/06+u8oM8MbpX5s3V9NuOWtw
eTS6LDQF00DEMAiXSlCWQ+mfIrUFeGM+xrbfqeRBz3OzsOZFMR9pv7G+YRg7uc+JiZyQ
dR8g/YP4aTBgtI3WnXRRIC7+/ry7Xo/rNXVBtXPkgREhfvrhp3462ljzhWEqAXqrOtaa
0RQdXQ/QdbQ/33EY9fs+v5dmplKJ+1ElhPW5Jrzx3vCINd/n8GywFF5wWoKmgQoWXTT2
/OzN8AyVpr32loQkQrg6X0Khu7z+8iTyRGNIuZYbPCGZ8ogIhsPc4mhHF6KDcIi6X4Lc
JcyA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20230601; t=1706675152; x=1707279952;
h=thread-index:content-language:content-transfer-encoding
:mime-version:message-id:date:subject:in-reply-to:references:to:from
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
bh=POfo9ZFT3NEkdYVblhyS9OLaSeE/6VEsE82ycxkaWFI=;
b=cMp2a65OHp8KHtMkvsPrM0Q9539jemnhwtnzOM1LJL9Yf2/FC0vzi1Cz66qSypTKTz
etASjU1nY5FO0YddsElHriPo+txdtnUXiuhyi8FPlMgKVZdfxa1r1hHVHaZ+p2U4xSr0
1xl/w5B/KhZd9HuRH08bS0WRjn2ZA6rqR1GD0TSLvpkumI7Bc4kFSjBMQKQo75vTqpHD
g1ITaU5JA2MPKH83KNpb1U7Mt7e8QonGX602dg1u6gIWqpbmC9bOTkLBp7qZnxrw3OUO
9y/VWWEwP8MHaCl3cgA+4skTHJfYrvMlRxBlCCJQtf5QhdE4F2qe9B+MKIZxOblUUquv
lplw==
X-Gm-Message-State: AOJu0YzpjP57ZOFgQqlBCZskfC8IbFpSgO2ZxNwHGKHPpMD7KlmPBxW/
sO8zOtjiDjWQLy2BE/BcRh0Bei5a9vVSzTaJLrAhdDt9W/h9jUzGbfbRV6RC
X-Google-Smtp-Source: AGHT+IEKVgFpZUCeg+iymuGc+Mfa0w27xwBLfbY9oE9F3SHxmHVxxDuJroxrobHRaIj/MXgeqzKTyA==
X-Received: by 2002:a05:6214:1307:b0:68c:68e8:3314 with SMTP id
pn7-20020a056214130700b0068c68e83314mr604924qvb.63.1706675152525;
Tue, 30 Jan 2024 20:25:52 -0800 (PST)
In-Reply-To: <e0c1c61d-2941-452a-8977-ef5c5bfb8bdb@tompassin.net>
X-Mailer: Microsoft Outlook 16.0
Content-Language: en-us
Thread-Index: AQIT2JcvPaTF6OzWKWXSKdjDn7r16AFWmdGFATvF+R4BtfoyFAHuJswLAl+XZJQBiMgQ/bAvUGTQ
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <004c01da53fd$9273b9e0$b75b2da0$@gmail.com>
X-Mailman-Original-References: <c9cf741b-9781-8dd6-96df-d270d0ac2@appl-ecosys.com>
<2a5eef2d-3d66-8cea-64eb-602ea5aff946@appl-ecosys.com>
<f1784a5b-662a-47fc-ada0-cc09ea2cfc24@tompassin.net>
<9028bd96-dbc8-fbc1-8584-a965ef7def5d@appl-ecosys.com>
<5cea1ab2-1848-41bd-8e5b-323fe55ba8c9@tompassin.net>
<478e3bbe-db95-9533-595b-7a19a5e2cf@appl-ecosys.com>
<e0c1c61d-2941-452a-8977-ef5c5bfb8bdb@tompassin.net>
 by: - Wed, 31 Jan 2024 04:25 UTC

Thomas, on some points we may see it differently.

Some formats can be done simply but are maybe better done in somewhat
standard ways.

Some of what the OP has is already tables in a database and that can
trivially be exported into a CSV file or other formats like your TSV file
and more. They can also import from there. As I mentioned, many spreadsheets
and all kinds of statistical programs tend to support some formats making it
quite flexible.

Python has all kinds of functionality, such as in the pandas module, to read
in a CSV or write it out. And once you have the data structure in memory, al
kinds of queries and changes can be made fairly straightforwardly. As one
example, Rich has mentioned wanting finer control in selecting who gets some
version of the email based on concepts like market segmentation. He already
may have info like the STATE (as in Arizona) in his database. He might at
some point enlarge his schema so each entry is placed in one or more
categories and thus his CSV, once imported, can do the usual tasks of
selecting various rows and columns or doing joins or whatever.

Mind you, another architecture could place quite a bit of work completely on
the back end and he could send SQL queries to the database from python and
get back his results into python which would then make the email messages
and pass them on to other functionality to deliver. This would remove any
need for files and just rely on the DB.

There as as usual, too many choices and not necessarily one best answer. Of
course if this was a major product that would be heavily used, sure, you
could tweak and optimize. As it is, Rich is getting a chance to improve his
python skills no matter which way he goes.

-----Original Message-----
From: Python-list <python-list-bounces+avi.e.gross=gmail.com@python.org> On
Behalf Of Thomas Passin via Python-list
Sent: Tuesday, January 30, 2024 10:37 PM
To: python-list@python.org
Subject: Re: Extract lines from file, add to new files

On 1/30/2024 12:21 PM, Rich Shepard via Python-list wrote:
> 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 haven't said what you don't know how to do.
>> Something
>> else? What is it that you want to do that you don't know how?
>
> Thomas,
>
> For 30 years I've used a bash script using mailx to send messages to a
list
> of recipients. They have no salutation to personalize each one. Since I
> want
> to add that personalized salutation I decided to write a python script to
> replace the bash script.
>
> I have collected 11 docs explaining the smtplib and email modules and
> providing example scripts to apply them to send multiple individual
> messages
> with salutations and attachments.

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 to the rest of the bash program. Something in
that ballpark, anyway.

> Today I'm going to be reading these. They each recommend using .csv input
> files for names and addresses. My first search is learning whether I can
> write a single .csv file such as:
> "name1","address1"
> "mane2","address2"
> which I believe will work; and by inserting at the top of the message
block
> Hi, {yourname}
> the name in the .csv file will replace the bracketed place holder
If the file contents are going to be people's names and email addresses,
I would just tab separate them and split each line on the tab. Names
aren't going to include tabs so that would be safe. Email addresses
might theoretically include a tab inside a quoted name but that would be
extremely obscure and unlikely. No need for CSV, it would just add
complexity.

data = f.readlines()
for d in data:
name, addr = line.split('\t') if line.strip() else ('', '')

> Still much to learn and the batch of downloaded PDF files should educate
> me.
>
> Regards,
>
> Rich

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

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor