Replying to Avatar Alexandre B A Villares 🐍

Seems OK to me... #Python

with open(text_file) as f:

items = [line for line in f.read().splitlines()

if line.strip() and not line.startswith('#')]

Context: A txt file with a list of files to process, some are commented out, and there is a first line head comment followed by a blank line.

Avatar
schuelermine; probably → 39C3 1y ago

nostr:npub1mjjwe95dghhw434k4vsvxs5yl6gcr6kupghf5u0dgcvhga0w94sqe7h2pr I'd say this isn't performant because it copies the string unnecessarily.

Reply to this note

Please Login to reply.

Discussion

Avatar
Alexandre B A Villares 🐍 1y ago

nostr:npub1dnc2khknlklurqv25dyzpyh4qcdr3l92tvzm4xh56nuhh3cdtuaq06ycxc I'm more concerned about clarity/legibility than performance as this will tackle a list of a few dozen lines/items only.

Thread collapsed