Handy utilities = Friday Filosofical Finking

DL Neil PythonList at DancesWithMice.info
Mon Apr 1 20:14:24 EDT 2019


Gidday Cameron,

Thanks for this - some thoughts below:-


On 2/04/19 11:57 AM, Cameron Simpson wrote:
> On 29Mar2019 09:32, DL Neil <PythonList at DancesWithMice.info> wrote:
>> How do you keep, use, and maintain those handy snippets, functions, 
>> classes... - units of code, which you employ over-and-over again?
>> Having coded 'stuff' once, most of us will keep units of code,
>> "utilities", which we expect will be useful in-future (DRY principle), 
>> eg functions to rename files, choose unique back-up/new fileNMs, 
>> accessing a DB, journalling (logging) start/stop msgs, building specs 
>> from YAML/JSON/XML/.ini config files (tongue~cheek), etc.
>>
>> Do you 'keep' these, or perhaps next time you need something you've 
>> 'done before' do you remember when/where a technique was last 
>> used/burrow into 'history'?
>> (else, code it from scratch, all over again)
> 
> I put them into modules for import. I've got a tree of Python modules 
> named "cs.this", "cs.that" for various things. Then just import stuff 
> like any other library module.

Agreed - but Python doesn't (natively) like imports from a 
different/parallel/peer-level dir-tree. (see also Apache httpd)


> For personal projects (if they aren't just part of that tree) I just 
> need to symlink the tree into the local Python library as "cs".

I was doing this.

Much of my work is a simple-delivery, ie copying code from my dev m/c to 
the client's PC or server - so I don't 'package it up'* because of the 
(perceived) effort required cf the one-to-one (or maybe a couple) 
machine relationships.

However, during 'delivery' to another machine, have to remember to 
rsync/copy including the symlink, as well as to transfer both dir-trees.


Recently, stopped to organise the code into (more) modules (as also 
suggested here) and moved to adding the 'utilities' directories into 
PYTHONPATH. Now I have to remember to modify that on the/each target m/c!


(and you can guess what happens when I'm asked to remember something! 
Although, in my defence, I know this and (apparently) 
write-down/document a lot more than many/most of my colleagues. (puff, 
puff) )


> If I get something well enough defined and sufficiently cleaned up for 
> use beyond my own code (or just good enough that others might want it), 
> up it goes to PyPI so that it can just be "pip install"ed.
> 
> So I've got this huge suite of modules with stuff in them, and a subset 
> of those modules are published to PyPI for third party reuse.

Am dubious that any of the 'little bits' that I have collected are 
sufficiently worthy, but that's 'proper' F/LOSSy thinking!

*will be interested to hear if you think I should stop 'being lazy' and 
invest some time-and-effort into learning 'packaging' options and do 
things 'properly'?professionally...


> Happy to elaborate on the details.

One of the points which intrigue me is that my colleagues don't keep 
snippets/a library, preferring to remember (hah!) when/where they used 
particular techniques in the past, and copying/duplicating, to fit the 
new system's requirements. Am wondering if this is true beyond our 
little band?

Yet, here on the list, interest was shown in 'being organised' (even if 
few have actually weighed-in)...


Thanks!
-- 
Regards =dn


More information about the Python-list mailing list