Comments (4)
Happy to accept a PR for this!
from tableprint.
You can already pass a custom object for IO using the out
keyword argument to table
and TableContext
. By default, this is sys.stdout
, but it can be a file handle or any other object that has a write(str)
method and a flush
method. (This is exactly like the output_stream
argument in tf.print
).
I don't really want to add in custom logic for TensorFlow, but if you want the output to go through a tf.print
call you can use a shim class like follows:
class TFWriter:
def write(self, s):
tf.print(s)
def flush(self):
pass
tp.table(data, headers, out=TFWriter())
from tableprint.
Thanks—the shim you wrote is pretty clever; I didn't think of that!
To be honest, I don't remember if I knew about the out
argument—regardless, I should've mentioned that since I want to progressively print, I can't use out
, as I need to use tp.header
and tp.row
, neither of which accept an out
argument.
If you're okay with header
and row
accepting the out
argument, I may be able to write a PR for this within the next two weeks.
from tableprint.
Currently, header
and out
both return strings, which need to be printed by the user. If we want to add the out
argument, it makes sense to return None
, like the other methods, and print using out
. However, I'd consider this a breaking change.
We can:
- make
out
default to None, and ifout
is not None, then useout
to print; else, don't print anything and return a string. This avoids a breaking change, as users who currently don't use theout
argument won't experience any problems, and I'll be able to use the shim you wrote. However, I'm not a fan of this—IMO, these functions should either print or return a string in all cases, to avoid user confusion. - make
out
default tosys.stdout
, like the other functions. This means we should not return anything, and print usingout
. I like this behavior, as IMO it's more intuitive than the first option, but causes a breaking change, since users who don't currently use theout
argument will be printing None along with tableprint's output.
What do you think? Honestly, I think tableprint is ready for a 1.x release, so I don't have a problem with causing a breaking change and bumping the major version.
from tableprint.
Related Issues (12)
- ANSI escape not supported HOT 1
- No width validation HOT 1
- str(array) is not stable for table print HOT 2
- Auto-width HOT 3
- feature request: print multiple items in a column (group by) HOT 3
- Feature request: Horizontal alignment HOT 2
- Simple style csv or json or yaml HOT 1
- Error executing on windows HOT 2
- Irregular Table Width HOT 6
- add tests for international languages
- Drop Numpy as a hard requirement HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tableprint.