Skip to main content

Making access to names easier

Project description

doodad

Making access to names easier.

doodad: A gadget or other object whose name the speaker does not know or cannot recall.

Often, when writing code, you need to specify field names, for example, when writing code that communicates with a database. It's so easy to make a typo in the field name, and you might only know this once you run the code, which may be a lot later...

What doodad wants to do when it grows up, is make it easier to find names, and use the names you meant to use, with tab completion etc.

To install: pip install doodad

Examples

Find all the names (variables, functions, etc.) in a piece of code or data.

>>> from doodad import find_names
>>> mapping = {'c': 1, 'b': {'a': 2, 'd': 3}}
>>> list(find_names(mapping))
['c', 'b', 'a', 'd']
>>> import os
>>> names = list(find_names(os.path.join))
>>> names
['join', 'a', 'a', 'sep', 'path', 'path']

Make an instance whose sole purpose is to contain those names. This allows you to have a ready-to-use collection of names that you can tab complete and catch spelling mistakes early (before, say, you ask for a field name that doesn't exist...)

>>> from doodad import mk_str_attr_obj
>>>
>>> f = mk_str_attr_obj(names)
>>> f.join
'join'
>>> f.path
'path'
>>> f = mk_str_attr_obj('date worker offre success')
>>> f.date
'date'
>>> f.worker
'worker'
>>> f.does_not_exist
Traceback (most recent call last):
...
AttributeError: 'AttrObj' object has no attribute 'does_not_exist'

f is a namedtuple so you can do things like:

>>> list(f)
['date', 'worker', 'offre', 'success']
>>> date, worker, offer, success = f
>>> offer
'offre'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

doodad-0.1.0.tar.gz (8.9 kB view details)

Uploaded Source

File details

Details for the file doodad-0.1.0.tar.gz.

File metadata

  • Download URL: doodad-0.1.0.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.17

File hashes

Hashes for doodad-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2d5a1317cf0ba10ee79da0204125b07c8c075faf9943ec7220021f64487b5b17
MD5 ab3122a5e86ab7bd94b251fef303f6d7
BLAKE2b-256 cf36ea237a9763dc8662f32df979cf1cfa23816386d1054b87e397f33d043ad9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page