Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

If a train station is a place where a train stops, what's a workstation?


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

SubjectAuthor
* Extract lines from file, add to new filesRich Shepard
+* Re: Extract lines from file, add to new filesPiergiorgio Sartor
|+- Re: Extract lines from file, add to new filesRich Shepard
|+- Re: Extract lines from file, add to new filesMirko
|`- Re: Extract lines from file, add to new filesdn
`- Re: Extract lines from file, add to new filesStefan Ram

1
Extract lines from file, add to new files

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!fu-berlin.de!uni-berlin.de!not-for-mail
From: rshep...@appl-ecosys.com (Rich Shepard)
Newsgroups: comp.lang.python
Subject: Extract lines from file, add to new files
Date: Thu, 11 Jan 2024 10:08:09 -0800 (PST)
Lines: 27
Message-ID: <mailman.3.1704996908.15798.python-list@python.org>
References: <5a6d88e-46b1-a3ea-333-d053cbe5654d@appl-ecosys.com>
Reply-To: Rich Shepard <rshepard@appl-ecosys.com>
Mime-Version: 1.0
Content-Type: text/plain; format=flowed; charset=US-ASCII
X-Trace: news.uni-berlin.de Rdz9DpqtsXMs74mh/s+WGAs6JSddL33DNb8f/x8zjpGw==
Cancel-Lock: sha1:g8RefZfwNNbgHhc+2GEGdNaTLa8= sha256:lceU3gA6iOU2ChZbgyVAWiEC74/Dcjee6SIHkk2B2wk=
Return-Path: <rshepard@appl-ecosys.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.017
X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'subject:add': 0.07;
'subject:files': 0.09; 'unsure': 0.09; 'bash': 0.16; 'email
addr:example.com': 0.16; 'from:addr:appl-ecosys.com': 0.16;
'from:addr:rshepard': 0.16; 'from:name:rich shepard': 0.16;
'received:50.126': 0.16; 'received:50.126.108': 0.16;
'received:50.126.108.78': 0.16; 'received:appl-ecosys.com': 0.16;
'received:mail.appl-ecosys.com': 0.16; 'tia,': 0.16; 'python':
0.16; 'addresses': 0.19; 'to:addr:python-list': 0.20; 'input':
0.21; "i've": 0.22; 'subject:file': 0.22; 'associate': 0.32;
"i'm": 0.33; "i'll": 0.33; 'script': 0.33; 'subject:from': 0.37;
'using': 0.37; "it's": 0.37; 'received:192.168': 0.37; 'file':
0.38; 'two': 0.39; 'file:': 0.40; 'lack': 0.60; 'brief': 0.62;
'email': 0.63; 'years': 0.65; 'files:': 0.69; 'nancy': 0.69;
'experience.': 0.70; 'header:Reply-To:1': 0.79; 'extracted': 0.84
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: <5a6d88e-46b1-a3ea-333-d053cbe5654d@appl-ecosys.com>
 by: Rich Shepard - Thu, 11 Jan 2024 18:08 UTC

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
calvin@example.com

Hobbs
hobbs@some.com

Nancy
nancy@herown.com

Sluggo
sluggo@another.com

Having extracted salutations and addresses I'll write a bash script using
sed and mailx to associate a message file with each name and email address.

I'm unsure where to start given my lack of recent experience.

TIA,

Rich

Re: Extract lines from file, add to new files

<4ao57k-bca.ln1@lazy.lzy>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: piergior...@nexgo.REMOVETHIS.de (Piergiorgio Sartor)
<piergiorgio.sartor.this.should.not.be.used@nexgo.REMOVETHIS.de>
Newsgroups: comp.lang.python
Subject: Re: Extract lines from file, add to new files
Date: Thu, 11 Jan 2024 19:23:32 +0100
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <4ao57k-bca.ln1@lazy.lzy>
References: <5a6d88e-46b1-a3ea-333-d053cbe5654d@appl-ecosys.com>
<mailman.3.1704996908.15798.python-list@python.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="8e98a234644481a99840dee5dd2a2423";
logging-data="3257326"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18MVbPV451H6JRGvrnvkSHd"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:59mDgaLZP5kbgXrU7zqVopAdUjc=
Content-Language: it
In-Reply-To: <mailman.3.1704996908.15798.python-list@python.org>
 by: Piergiorgio Sartor - Thu, 11 Jan 2024 18:23 UTC

On 11/01/2024 19.08, Rich Shepard wrote:
> 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
> calvin@example.com
>
> Hobbs
> hobbs@some.com
>
> Nancy
> nancy@herown.com
>
> Sluggo
> sluggo@another.com
>
> Having extracted salutations and addresses I'll write a bash script using
> sed and mailx to associate a message file with each name and email address.

Why not to use bash script for all?

bye,

--

piergiorgio

Re: Extract lines from file, add to new files

<split-20240111194050@ram.dialup.fu-berlin.de>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!nntp.comgw.net!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: Extract lines from file, add to new files
Date: 11 Jan 2024 18:41:52 GMT
Organization: Stefan Ram
Lines: 22
Expires: 1 Dec 2024 11:59:58 GMT
Message-ID: <split-20240111194050@ram.dialup.fu-berlin.de>
References: <mailman.3.1704996908.15798.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de pg/lkq91XrPMFbrtDJoIkwlBDgjZTefJZGQcnUBK3b1YW7
Cancel-Lock: sha1:wR92z3+alJ6G/ziteCdyxbeYrfU= sha256:yUOMqhYB8FVtEpsv1hGsmu7EQKX7l3bbEBTQYNkjTvI=
X-Copyright: (C) Copyright 2024 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE-1901, en-US, it, fr-FR
 by: Stefan Ram - Thu, 11 Jan 2024 18:41 UTC

Rich Shepard <rshepard@appl-ecosys.com> writes:
>separate names and email addresses

(Warning: execution of the following script will overwrite
[DELETE!] files opened with 'w'!)

# create source
data = '''Calvin\ncalvin@example.com\nHobbs\nhobbs@some.com
Nancy\nnancy@herown.com\nSluggo\nsluggo@another.com'''
fn = "data20240111192219+0100"
with open( fn, "w" )as sink: print( data, file=sink )

# split source into two files
with open( fn )as source: file = source.read()
lines = file.split( '\n' )[ :-1 ]
with open( 'salutation.txt', 'w' )as f: print( lines[ 0::2 ], file=f )
with open( 'emails.txt', 'w' )as f: print( lines[ 1::2 ], file=f )

# show the two result files
with open( 'salutation.txt' )as file: print( file.read() )
with open( 'emails.txt' )as file: print( file.read() )

Re: Extract lines from file, add to new files

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!fu-berlin.de!uni-berlin.de!not-for-mail
From: rshep...@appl-ecosys.com (Rich Shepard)
Newsgroups: comp.lang.python
Subject: Re: Extract lines from file, add to new files
Date: Thu, 11 Jan 2024 11:53:20 -0800 (PST)
Lines: 12
Message-ID: <mailman.8.1705002803.15798.python-list@python.org>
References: <5a6d88e-46b1-a3ea-333-d053cbe5654d@appl-ecosys.com>
<mailman.3.1704996908.15798.python-list@python.org> <4ao57k-bca.ln1@lazy.lzy>
<e3f12f-516c-3859-8d40-8f91bffea740@appl-ecosys.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII; format=flowed
X-Trace: news.uni-berlin.de gMg2NoOe9KdzuYYkuThgcwWts/sB2iKQEc2PllCDTgMA==
Cancel-Lock: sha1:ju9KcmAirgRLPEbv8E5HH8ipR+0= sha256:VH8ylwJJxkBchdlcnaSb0zYxxV2IlxQgj410mY47odU=
Return-Path: <rshepard@appl-ecosys.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.001
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:add': 0.07;
'task.': 0.07; 'subject:files': 0.09; 'bash': 0.16; 'from:addr
:appl-ecosys.com': 0.16; 'from:addr:rshepard': 0.16;
'from:name:rich shepard': 0.16; 'possibility,': 0.16;
'received:50.126': 0.16; 'received:50.126.108': 0.16;
'received:50.126.108.78': 0.16; 'received:appl-ecosys.com': 0.16;
'received:mail.appl-ecosys.com': 0.16; 'wrote:': 0.16; 'python':
0.16; 'thu,': 0.19; 'to:addr:python-list': 0.20; 'subject:file':
0.22; 'python-list': 0.32; 'script': 0.33; 'header:In-Reply-To:1':
0.34; 'subject:from': 0.37; 'received:192.168': 0.37; 'use': 0.39;
'well': 0.65
In-Reply-To: <4ao57k-bca.ln1@lazy.lzy>
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: <e3f12f-516c-3859-8d40-8f91bffea740@appl-ecosys.com>
X-Mailman-Original-References: <5a6d88e-46b1-a3ea-333-d053cbe5654d@appl-ecosys.com>
<mailman.3.1704996908.15798.python-list@python.org> <4ao57k-bca.ln1@lazy.lzy>
 by: Rich Shepard - Thu, 11 Jan 2024 19:53 UTC

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

Re: Extract lines from file, add to new files

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: mirkok.l...@googlemail.com (Mirko)
Newsgroups: comp.lang.python
Subject: Re: Extract lines from file, add to new files
Date: Thu, 11 Jan 2024 21:25:26 +0100
Lines: 20
Message-ID: <mailman.9.1705004730.15798.python-list@python.org>
References: <5a6d88e-46b1-a3ea-333-d053cbe5654d@appl-ecosys.com>
<mailman.3.1704996908.15798.python-list@python.org> <4ao57k-bca.ln1@lazy.lzy>
<e3f12f-516c-3859-8d40-8f91bffea740@appl-ecosys.com>
<5eb229c2-164e-193a-06a5-3b92e9ad8ead@googlemail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de /XG+4jfECDvBOdJVfN9xRweFlCO1kawQxtMoEIyN5hTg==
Cancel-Lock: sha1:v0x14WTxGRNRtvxnuoNuR4o/yA8= sha256:Z167WPdXwggtSh6dAm8suCxqpb1G3BCRkstRbHrdMK4=
Return-Path: <mirkok.lists@googlemail.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=googlemail.com header.i=@googlemail.com header.b=Jnel5PtU;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.000
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'received:mail-
lj1-x230.google.com': 0.05; ';-)': 0.07; 'subject:add': 0.07;
'task.': 0.07; 'from:addr:googlemail.com': 0.09; 'message-
id:@googlemail.com': 0.09; 'schrieb': 0.09; 'subject:files': 0.09;
'bash': 0.16; 'possibility,': 0.16; 'shepard': 0.16; 'skip:> 20':
0.16; 'wrote:': 0.16; 'python': 0.16; 'thu,': 0.19; 'to:addr
:python-list': 0.20; 'subject:file': 0.22; 'header:User-Agent:1':
0.30; 'python-list': 0.32; 'script': 0.33; 'header:In-Reply-To:1':
0.34; 'received:google.com': 0.34; 'subject:from': 0.37; 'use':
0.39; 'well': 0.65; 'received:37': 0.78
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=googlemail.com; s=20230601; t=1705004728; x=1705609528; darn=python.org;
h=content-transfer-encoding:in-reply-to:from:references:to
:content-language:subject:user-agent:mime-version:date:message-id
:from:to:cc:subject:date:message-id:reply-to;
bh=9Uko3lU9uZDPz730lCeR4+3TDweQ+RV7H9EDiB5zCRY=;
b=Jnel5PtUUN1prqB+yaLvTJQXmAanm6BRBU3LYQY1db+F1ghqpF/T3dR8bEFHLHd6BG
FPeGpZTn7B7V7ml5Tr7K6tjEOgDTxY9NtvaEnsZU3MWhVgGOk4QZay/rQH5NULMG0IgV
r4ZCUeQDRPvDZ9Pe8lmXcKJjkrI38HXShflueMyA9+gIfGhtTCtCvifvn/GcwYGt5LT9
9RQtfuW6XRb5gspLQNqfNztrZeVqNQZ7y5hPMek7AeOReWvsGd0sTVjrkUFv67b58+ET
oqWsrrNemLCovRGM6qAET3Ra6dmWteY2YLaKyNqFvpBW3E/IJWMDGK0x4CXzBEUJay/Y
1uNQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20230601; t=1705004728; x=1705609528;
h=content-transfer-encoding:in-reply-to:from:references:to
:content-language:subject:user-agent:mime-version:date:message-id
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
bh=9Uko3lU9uZDPz730lCeR4+3TDweQ+RV7H9EDiB5zCRY=;
b=EWmpJR2AUd4VwS9jY1r5SKIhsVgj4EApuwiwaDSFVB38uycwc4vpfa4QxoU+zr4G81
axeY60Tz4YprNuC1l7qIVx9UpBsgAfBX90rbRHT7OFWs/jmO0JeRZAZa9mJCDeXK/eyl
h5Crd508hI+F5diDdmeuDqeZZdY6CrAwMP1sELz06izLecHy2BbQQ29ZjI3nYoFyWpXG
Pknr2BW/uZ8qU3wBP20qEbWwXaXukq6/ctyeCq4NxrydyqiLZqSrP9BmzoxuprwwCpIi
HzSDjUn+AoYbbh8zd0smI68uzIQcaFn3i5y8sEaddUCGJgmOVUnFHnErvsid6werEONx
i4WA==
X-Gm-Message-State: AOJu0Yw6KkxU/MW3BAvfzWY0Y+kg+OjxXN+uKXpvkdFLiAKhJQtXvnCI
G7KC/ferCb5XCFCuVrgW4GF+tYME7TQ=
X-Google-Smtp-Source: AGHT+IHN8YrVhyyOGEzH0+bBpFVCRq83AyIpMHiLWogYvaZqZdrav0qPDr8BDWqz3KrTZ05NgTrvmA==
X-Received: by 2002:a2e:880f:0:b0:2cc:7b19:1b05 with SMTP id
x15-20020a2e880f000000b002cc7b191b05mr164016ljh.48.1705004727960;
Thu, 11 Jan 2024 12:25:27 -0800 (PST)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.13.0
Content-Language: de-DE
In-Reply-To: <e3f12f-516c-3859-8d40-8f91bffea740@appl-ecosys.com>
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: <5eb229c2-164e-193a-06a5-3b92e9ad8ead@googlemail.com>
X-Mailman-Original-References: <5a6d88e-46b1-a3ea-333-d053cbe5654d@appl-ecosys.com>
<mailman.3.1704996908.15798.python-list@python.org> <4ao57k-bca.ln1@lazy.lzy>
<e3f12f-516c-3859-8d40-8f91bffea740@appl-ecosys.com>
 by: Mirko - Thu, 11 Jan 2024 20:25 UTC

Am 11.01.24 um 20:53 schrieb 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

awk '/@/ {print >>"emails.txt";next};NF{print >>"salutation.txt"}'
input.txt

SCNR ;-)

Re: Extract lines from file, add to new files

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.neodome.net!fu-berlin.de!uni-berlin.de!not-for-mail
From: PythonL...@DancesWithMice.info (dn)
Newsgroups: comp.lang.python
Subject: Re: Extract lines from file, add to new files
Date: Sun, 14 Jan 2024 11:01:12 +1300
Organization: DWM
Lines: 93
Message-ID: <mailman.29.1705183285.15798.python-list@python.org>
References: <5a6d88e-46b1-a3ea-333-d053cbe5654d@appl-ecosys.com>
<mailman.3.1704996908.15798.python-list@python.org> <4ao57k-bca.ln1@lazy.lzy>
<e3f12f-516c-3859-8d40-8f91bffea740@appl-ecosys.com>
<47a3d257-a97a-4acf-a721-fe2b7fce12bd@DancesWithMice.info>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de VY6yBVGZdczLBGsNP3caQQn5zaZeaevYD10L6GH6HJWA==
Cancel-Lock: sha1:+HrK5s0GM/oh0/cgSSevEFxSxWA= sha256:v/I6h+1ht9xLOYHs+dHORgMb7C2c0w7nHSF18EysMik=
Return-Path: <PythonList@DancesWithMice.info>
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=danceswithmice.info header.i=@danceswithmice.info
header.b=DzKYlmxz; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.002
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; "python's": 0.05; 'string':
0.07; 'subject:add': 0.07; 'task.': 0.07; 'python.': 0.08; '"""':
0.09; '=dn': 0.09; 'from:addr:danceswithmice.info': 0.09;
'from:addr:pythonlist': 0.09; 'neat': 0.09;
'received:192.168.1.64': 0.09; 'subject:files': 0.09; 'import':
0.15; '"gnu': 0.16; 'assuming': 0.16; 'bash': 0.16; 'captured':
0.16; 'case:': 0.16; 'elsewhere': 0.16; 'email addr:example.com':
0.16; 'impossible': 0.16; 'message-id:@DancesWithMice.info': 0.16;
'occupy': 0.16; 'possibility,': 0.16; 'print(': 0.16;
'received:51.254': 0.16; 'received:51.254.211': 0.16;
'received:51.254.211.219': 0.16; 'received:cloud': 0.16;
'received:rangi.cloud': 0.16; 'shepard': 0.16; 'splitting': 0.16;
'whilst': 0.16; 'wrote:': 0.16; 'python': 0.16; 'thu,': 0.19;
'to:addr:python-list': 0.20; 'input': 0.21; 'skip:_ 10': 0.22;
'subject:file': 0.22; 'code': 0.23; 'lines': 0.23; 'idea': 0.24;
'solution.': 0.26; 'task': 0.26; 'creating': 0.27; 'output': 0.28;
'suggestions': 0.28; 'header:User-Agent:1': 0.30; 'whole': 0.30;
'header:Organization:1': 0.31; 'concept': 0.32; 'format,': 0.32;
'half': 0.32; 'python-list': 0.32; 'unless': 0.32;
'received:192.168.1': 0.32; 'there': 0.33; 'script': 0.33; 'header
:In-Reply-To:1': 0.34; 'question.': 0.35; 'subject:from': 0.37;
'hard': 0.37; 'received:192.168': 0.37; 'file': 0.38; 'could':
0.38; 'put': 0.38; 'two': 0.39; 'quite': 0.39; 'mentioned': 0.39;
'use': 0.39; 'sample': 0.61; 'mode': 0.62; 'involved': 0.63;
'true': 0.63; 'skip:b 10': 0.63; 'public': 0.63; 'our': 0.64;
'involve': 0.64; 'license': 0.64; 'received:51': 0.64; 'came':
0.65; 'well': 0.65; 'back': 0.67; 'choose': 0.67; 'before,': 0.69;
'content.': 0.70; 'little': 0.73; 'name,': 0.75; '....': 0.76;
'guarantee': 0.76; 'identifying': 0.76; '(we': 0.84; 'maintain,':
0.84; 'spamming': 0.84; 'task,': 0.84; 'mind,': 0.93
DKIM-Filter: OpenDKIM Filter v2.11.0 vps.rangi.cloud 74F0521A0
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=danceswithmice.info;
s=staff; t=1705183278;
bh=78Zsjs9ZCvGPb4ka8upG/COBT3rvM/g81p9VS4P4hTY=;
h=Date:From:Subject:To:References:In-Reply-To:From;
b=DzKYlmxz9iSsv1hU75n6tiEIuzltmERBtmPGsXx2iu+chwXr1CB6spzoa8Wn3rmXg
P/9cabG8XSNMXyR2SXQQjs7xKhHJz6Rk7AVr3iPpMOsIg7+NZaCr9r3B77eE+1nkz2
nk2yLxSYiR4tDHijZu+IjvB+zIoUuY9aFnwquig736yKcLfgVPoYRxgBmu7IrICuEh
CXHI/MpeJsc3S7aAyX+oFXgo2pVYgr1dbG09IEt1YH0yYfESJfgb0bBhNbN9f+b3rM
wID+RKDBFDzZ/YbimRhXva5F9I/ykUvNDVJh1FIihCCnzJFVzkuPbv+smIClDvK0NI
HP/ty+viqPJyg==
User-Agent: Mozilla Thunderbird
Content-Language: en-US
In-Reply-To: <e3f12f-516c-3859-8d40-8f91bffea740@appl-ecosys.com>
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: <47a3d257-a97a-4acf-a721-fe2b7fce12bd@DancesWithMice.info>
X-Mailman-Original-References: <5a6d88e-46b1-a3ea-333-d053cbe5654d@appl-ecosys.com>
<mailman.3.1704996908.15798.python-list@python.org> <4ao57k-bca.ln1@lazy.lzy>
<e3f12f-516c-3859-8d40-8f91bffea740@appl-ecosys.com>
 by: dn - Sat, 13 Jan 2024 22:01 UTC

On 12/01/24 08:53, Rich Shepard via Python-list wrote:
> 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.

(sitting in a meeting with little to occupy my mind, whilst tidying
email-InBox came back to this conversation)

In the bare-description of the task, I might agree to sticking with
BASH. The OP did say that the output from this will become input to a
sed/mailx task!
(we trust, does not involve spamming innocent folk)

However, that task could also be accomplished in Python. So, unless
there is an existing script (perhaps) quite why one would choose to do
half in Python and half in BASH (or...) is a question.

Because this is a Python forum, do the whole thing in one mode - our mode!

Previous suggestions involved identifying a line by its content.

Could use a neat state-transition solution.

However, there is no need to consider the input-data as lines because of
the concept of "white-space", well-utilised by some of Python's built-in
string-functions. See code-sample, below.

As mentioned before, the idea of splitting the one file (data-items
related by serial-progression) and creating two quite-separate
data-constructs (in this case: one holding the person's name in one file
and the other the person's email-address in another) which are related
'across', ie line-by-line, is an architectural error?horror. Such would
be hard to maintain, and over-time impossible to guarantee integrity.
Assuming this is not a one-off exercise, see elsewhere for advice to
store the captured data in some more-useful format, eg JSON, CSV, or
even put into a MongoDB or RDBMS.

****** code

""" PythonExperiments:rich.py
Demonstrate string extraction.
"""

__author__ = "dn, IT&T Consultant"
__python__ = "3.12"
__created__ = "PyCharm, 14 Jan 2024"
__copyright__ = "Copyright © 2024~"
__license__ = "GNU General Public License v3.0"

# PSL
import more_itertools as it

DATA_FILE = "rich_data_file"
READ_ONLY = "r"
AS_PAIRS = 2
STRICT_PAIRING = True

if __name__ == "__main__":
print("\nCommencing execution\n")

with open( DATA_FILE, READ_ONLY, ) as df:
data = df.read()

data_as_list = data.split()
paired_data = it.chunked( data_as_list, AS_PAIRS, STRICT_PAIRING, )

for name, email_address in paired_data:
# replace this with email-function
# and/or with storage-function
print( name, email_address, )

print("\nTerminating")

****** sample output

Calvin calvin@example.com
Hobbs hobbs@some.com
....

******

--
Regards,
=dn

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor