Skip to main content

jj Inline files - "not so pythonic" files inside your code

Project description

Inline Files

This Python package to allow inline files -- files inside the program.

An inline file is a file stored within another file. This parent file can be any kind of file, but a .py file is preferred due to how an inline file is defined.

Synopsis

from jjinline_files import *
print(message, message2)

"""ILF
==> message
Hello World!

==> message2
And this is all for now.
"""

Definition

We use the following syntax to define an inline file:

r"""ILF
==> ID1
Hello World!

==> ID2:json
{
    "hello": "world"
}
"""

Inline files are defined inside a multiline comment or docstring. Each "file" starts with ==> ID or ==> ID:type, where ID is the inline file's name. In the example above, there are two inline files, "ID1" and "ID2". ID2 has a type json.

If a "file" has an explicit type, the "file" will be processed accordingly. For example, a JSON file will be processed using the json module importer. Default type is text file. Currently, the module supports the following types:

  • text files (default) -- a (multiline) string
  • json -- any
  • yaml -- any
  • jj2 -- jinja2 template -- defines a function(dict, **args)
  • f -- a f-string -- defines a function(dict, **args)
  • csv, tsv -- list(list(str))
  • lines -- list(str)

File types and their importers

yaml and json

  • typical uses: configuration files, knowledge representation
  • perform yaml-parse(text);
  • return a python value (list, dict, etc)
r"""ILF
from jjinline_files import *

print(f["filename"])

==> f:json
{
    "filename": "calendar",
    "extension": "json"
}

==> g:yaml
filename: file1
extension: yaml
"""

lines

  • perform text.splitlines()
  • return a list of strings

csv and tsv

  • performs csv-parse(txt)
  • return a list(list(strings))

templates : f (fstrings) and jinja2

  • return a function. Parameter:(d:dict or **args) → string
from jjinline_files import *
print( ppname(name="James Bont") )

"""ILF
==> ppname:f
surname {name.split()[-1]}  fullname {name}

"""

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

jjinline_files-0.1.4.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

jjinline_files-0.1.4-py2.py3-none-any.whl (3.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file jjinline_files-0.1.4.tar.gz.

File metadata

  • Download URL: jjinline_files-0.1.4.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.25.1

File hashes

Hashes for jjinline_files-0.1.4.tar.gz
Algorithm Hash digest
SHA256 ab31b4b3b2e9b01ee3287ac6799f1e63ebfa3103cc811c0e6ce42e0bd0662e15
MD5 068e297c372abf3f97fef3f7d28cd6d7
BLAKE2b-256 acacf4d15d0c71581f9faac0c2fab98c02679bfdc462b20970b54a87a726ae21

See more details on using hashes here.

File details

Details for the file jjinline_files-0.1.4-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for jjinline_files-0.1.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 264b8005142e27e1ebc2e80fca125d5c02037170a940632e6f9768c45a81ce23
MD5 9497f89b59596838bf7727025435d22e
BLAKE2b-256 b14702a06d89ebe1001dc13c5578604d3f132c2a13269b59935f2d550b1138a8

See more details on using hashes here.

Supported by

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