oblalex / lazy-string Goto Github PK
View Code? Open in Web Editor NEWPython library for defining strings with delayed evaluation
Home Page: https://pypi.org/project/lazy-string
License: MIT License
Python library for defining strings with delayed evaluation
Home Page: https://pypi.org/project/lazy-string
License: MIT License
The following code snippet raises a TypeError: 'bytes' object is not callable
from lazy_string import LazyString
def get_abc():
return "abc"
s = LazyString(get_abc)
print(s.encode('UTF-8'))
Here is the traceback from running this
Traceback (most recent call last):
File "testls.py", line 8, in <module>
print(s.encode('UTF-8'))
File "/usr/local/Cellar/[email protected]/3.7.11/Frameworks/Python.framework/Versions/3.7/lib/python3.7/collections/__init__.py", line 1163, in __str__
def __str__(self): return str(self.data)
File "/Users/brian/.virtualenvs/nips3/lib/python3.7/site-packages/lazy_string.py", line 56, in data
return self._func(*self._args, **self._kwargs)
TypeError: 'bytes' object is not callable
Awesome library! I wish I'd thought to google for this when writing dozens of DEBUG
log messages with expensive string formatting, usually pprint
. For example the following is incomplete, the expensive call to pprint.pformat
may still happen for some logging configurations:
if logger.isEnabledFor(logging.DEBUG):
logger.debug("Processing large data shape:\n%s", pprint.pformat(data_dict))
This might make a good example to include in the docs to help potential users imagine why they might use this. Untested, but in this case the expensive call should never happen unless this logging record is actually going to be emitted:
logger.debug(
"Processing large data shape:\n%s",
lazy_string.LazyString(functools.partial(pprint.pformat, data_dict)),
)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.