Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Is a computer language with goto's totally Wirth-less?


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

SubjectAuthor
o Re: Extract lines from file, add to new filesdn

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

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.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: Tue, 30 Jan 2024 08:10:48 +1300
Organization: DWM
Lines: 79
Message-ID: <mailman.13.1706555464.3227.python-list@python.org>
References: <c9cf741b-9781-8dd6-96df-d270d0ac2@appl-ecosys.com>
<2a5eef2d-3d66-8cea-64eb-602ea5aff946@appl-ecosys.com>
<324c36f6-d44b-4023-90d2-698ace9cdfc8@DancesWithMice.info>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de u77UIbXmE6Xuzlcl+VYSuAQa5CBfBA1nCUlmxOLGH4rw==
Cancel-Lock: sha1:qAMRce8Y3GsvfRBRIo2cunQmY3s= sha256:T0f15Pn/JjfDgxxgBqqRTh+z/FiDUCnE54YQGYxb2m0=
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=nIKSQICx; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.002
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'containing': 0.05;
'file?': 0.05; 'thread': 0.05; 'variable': 0.05; '"python': 0.07;
'explanation': 0.07; 'hopefully': 0.07; 'subject:add': 0.07;
':-)': 0.09; '=dn': 0.09; 'content)': 0.09; 'dives': 0.09;
'from:addr:danceswithmice.info': 0.09; 'from:addr:pythonlist':
0.09; 'json': 0.09; 'question:': 0.09; 'received:192.168.1.64':
0.09; 'responses': 0.09; 'solving': 0.09; 'subject:files': 0.09;
'tricks': 0.09; '(without': 0.16; 'comparing': 0.16;
'corresponds': 0.16; 'databases,': 0.16; 'design.': 0.16;
'labels': 0.16; 'linked.': 0.16; 'message-
id:@DancesWithMice.info': 0.16; 'pertinent': 0.16;
'received:cloud': 0.16; 'received:rangi.cloud': 0.16;
'respective': 0.16; 'shepard': 0.16; 'somewhat': 0.16; 'specify':
0.16; 'unlikely': 0.16; 'unpacking': 0.16; 'whilst': 0.16;
'wrote:': 0.16; 'python': 0.16; 'values': 0.17; 'to:addr:python-
list': 0.20; "i've": 0.22; 'fri,': 0.22; 'maybe': 0.22;
'subject:file': 0.22; "what's": 0.22; 'version': 0.23; 'lines':
0.23; "i'd": 0.24; 'idea': 0.24; '(and': 0.25; 'discussion': 0.25;
'seems': 0.26; 'basics': 0.26; 'cover': 0.26; 'sense': 0.28;
'header:User-Agent:1': 0.30; 'code,': 0.31; 'seem': 0.31;
'looked': 0.31; 'header:Organization:1': 0.31; "doesn't": 0.32;
'(as': 0.32; 'discussions': 0.32; 'extract': 0.32; 'files,': 0.32;
'python-list': 0.32; 'records,': 0.32; 'split': 0.32; 'structure':
0.32; 'received:192.168.1': 0.32; 'but': 0.32; "i'm": 0.33;
"i'll": 0.33; 'there': 0.33; 'script': 0.33; 'same': 0.34; 'header
:In-Reply-To:1': 0.34; 'book': 0.35; 'item': 0.35; 'yes,': 0.35;
'files': 0.36; 'couple': 0.37; 'subject:from': 0.37; 'others':
0.37; 'received:192.168': 0.37; 'file': 0.38; 'way': 0.38;
'could': 0.38; 'read': 0.38; 'two': 0.39; 'use': 0.39; 'finding':
0.39; 'files.': 0.40; 'both': 0.40; 'physical': 0.60; 'provide':
0.60; 'skip:h 10': 0.61; 'showing': 0.62; 'days': 0.62; 'data,':
0.63; 'email': 0.63; 'once': 0.63; 'between': 0.63; 'pass': 0.64;
'skip:r 20': 0.64; 'clear': 0.64; 'operations.': 0.64;
'structure,': 0.64; 'his': 0.65; 'parts': 0.65; 'look': 0.65;
'well': 0.65; 'wish': 0.66; 'earlier': 0.67; 'back': 0.67; 'bad':
0.67; 'technical': 0.67; 'further': 0.69; 'etc,': 0.69; 'ones,':
0.69; 'chapter': 0.70; 'offer': 0.71; 'relevant': 0.73;
'guarantee': 0.76; 'quick': 0.77; 'discuss': 0.78; 'effective':
0.78; 'position': 0.81; 'points': 0.84; 'practical': 0.84;
'address)': 0.84; 'apparent': 0.84; 'strings': 0.84;
'sufficiently': 0.84; 'surprised': 0.84; 'you?': 0.88
DKIM-Filter: OpenDKIM Filter v2.11.0 vps.rangi.cloud 10DF156C6
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=danceswithmice.info;
s=staff; t=1706555454;
bh=MftQblTjlKDP1HjC+ogXpQ+pKRUDZ9Gzfr0Pnc0Mk58=;
h=Date:From:Subject:To:References:In-Reply-To:From;
b=nIKSQICx/BaAeIVGjO+jS5X0yatmExY9Lz3glmX2xBE2O99wiBKu8qCAr7FTQW3c1
IqUzm2j2sYVRYhzM0MTB1yTtQCr7BGRSBYo4XifsbqyMfgLYSLtsYiWeWGVwVfRkFM
8YIWlKO745R62Zi3mwxw6wimskgkTqIAgw6N3yyF55EfCJ+RbIvokT02AOh1fVtpt9
BwqoY/RS4kf+ltcpeHfhskON5qszlSo3XLscnbifYJAbYnA271gMEVSlxiiTmSfRMg
jtqV++MM54Vb+BTJLO285we2qkBSAhFC5WDzO5XHiMhXLsRjJ+Ijy1mGEw9lBjZ/9F
jVsPZdamosV+g==
User-Agent: Mozilla Thunderbird
Content-Language: en-US
In-Reply-To: <2a5eef2d-3d66-8cea-64eb-602ea5aff946@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: <324c36f6-d44b-4023-90d2-698ace9cdfc8@DancesWithMice.info>
X-Mailman-Original-References: <c9cf741b-9781-8dd6-96df-d270d0ac2@appl-ecosys.com>
<2a5eef2d-3d66-8cea-64eb-602ea5aff946@appl-ecosys.com>
 by: dn - Mon, 29 Jan 2024 19:10 UTC

On 30/01/24 05:15, Rich Shepard via Python-list wrote:
> 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," "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. :-)

It seems clear - but maybe we (all) misunderstand?

The books don't cover it - but is there a reason why they don't?

(Thunderbird did not thread this message with earlier ones, and it seems
some time has passed/memory is fading - but hopefully have remembered
content)

As said previously, the idea of two physical-files containing
logically-related data (without any form of cross-reference between) is
bad design.

In the current file, there is one physical structure and each person's
details are logically-related by proximity. A long way from ideal, but
workable (as you've described).

However, once split into two files, there is no way to guarantee that
the two logically-related data-items (name and address) will continue to
be related by their physical position in the respective files. Worse:
whilst it would seem apparent that "Alice" from the names file might be
related to the address "alice@domain.tld", how could one know if "Bob"
actually corresponds to "list-member@domain.tld"?

This is why dicts, databases, etc, offer keys (as labels for
data-items/dependent components)!

After a quick look at Eric's Crash Course, yes, his files-intro example
(digits of pi) is unlikely to have any practical reality (and I work
with statisticians and quants!). However, at the end of that chapter
(10), there is mention of JSON files. A JSON version of the existing
single-file structure will provide human-readable labeling of
data-items, give better separation between individuals' data, and show
how name and address are linked. Recommend solving 'the problem' that
way! (as previously discussed by others 'here', IIRC)

Slatkin's Effective Python doesn't seem to discuss the basics of files
at all (presumes such knowledge of the reader). It dives into important,
but rather technical discussions, comparing strings and bytes - somewhat
beyond the complexity-level of this discussion. That book does however
include discussions such as "Prefer Multiple Assignment Unpacking over
Indexing" (Item 6 - also points to Item 19) where relative-positioning
(indexing in other words) is advised-against.

If you wish to persist with this two-file structure, please see earlier
responses (again, IIRC) and discussion of file-merge operations. As
these date back to mainframes and the days of storing files on mag-tape,
I'd be surprised to see them discussed in 'modern' texts. However, the
principle is: read a record from each file, do-the-business, read the
next 'pair' of physically-related records, rinse-and-repeat.

If you require further assistance: how about showing a couple of
relevant lines of the data-file(s) and the pertinent parts of the code,
along with a description of what's going-wrong or not making sense to you?

--
Regards,
=dn

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor