On Tue, Jan 21, 2020 at 12:15 PM Christopher Barker <[email protected]>
wrote:

> You *may* be able to do something directly with strings, but most likely
> you'll pass it off to something else: a template renderer, JSON parser,
> what have you. And I can’t think of a single instance where you would just
> want the bytes in a file without processing them into a Python object.
> Given that you have to do that next step anyway, I don't see much gain here.


I've gotten in the habit of putting resources inside modules, moderately
often.  But what I've been doing lately is developing training materials,
which I think has a different use case. I'm not sure I'd want to do that
nearly so much in production code.

I absolutely do not get the desire to have the import mechanism create
string objects, let alone stick them in f-strings.  That just seems strange
and unnatural to me.

The sort of thing I find myself doing is:

from resources import data1, data2, data3

Then later in the training notebooks, I'll demonstrate doing various things
with the datasets.  but the data objects are not raw string objects, they
are NumPy arrays, or Pandas DataFrames, or nested dictionaries, or some
other more complex data that is relevant to what I am teaching.

Underneath that are steps like:

# resources.py
import special_lib
data1 = special_lib.reader(src, option1=foo, option2=bar)
touch_up(data1, with_=this, also=that)

Where special_lib is something like numpy, or simplejson, or xarray, or
whatever.  The actual data may or may not live inside the same resources.py
file.  Even if I was showing off text processing on a string, this same
pattern works fine.  One of those data objects can be a string or bytes
object.

But again, I mostly do this because *for a particular lesson*, I want to
draw attention to working with that particular data rather than to the
specifics of the loading mechanism.  In "real code" I'd still put those few
lines in the context where the data was processed, usually.

-- 
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons.  Intellectual property is
to the 21st century what the slave trade was to the 16th.
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/QRWSOCQ3USVZLIV7ON7TOMFAT2X4MRKI/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to