New Console.print method should use bg/fg=None as a default
See original GitHub issueHey,
So, I’m looking on the new print method and I find the default bg
behaviour weird.
Here is a simple example of what I would expect :
console = Console(width,height)
console.bg[:] = color1
console.print(x,y,value)
# I expect my value to be printed with bg=color1, not what is happening
Instead of having a value with bg=color1
, I have a bg=(0,0,0)
. It’s weird and forced me to do that for every print I want to use :
console = Console(width,height)
console.bg[:] = color1
console.print(x1,y1,value,bg=color1)
console.print(x2,y2,value,bg=color1)
console.print(x3,y3,value,bg=color1)
You have de facto a default color palette here which is white on black. If you use None as default, you don’t have this issue anymore.
In fact, the deprecated default_bg/fg
could still exist, but would never interact with this print
method.
also : see my comment here
Issue Analytics
- State:
- Created 5 years ago
- Comments:7
Top Results From Across the Web
What is the default print method of a class when called in a ...
Is this a class method like I'm hoping, or something built into the console interpreter? If the latter, can it be modified? python...
Read more >JavaScript Console.log() Example – How to Print to the ...
Logging messages to the console is a very basic way to diagnose and ... The first log will print the properties within the...
Read more >Console.Write Method (System) - Microsoft Learn
Writes the text representation of the specified objects to the standard output stream using the specified format information.
Read more >Your Guide to the Python print() Function
In this step-by-step tutorial, you'll learn about the print() function in Python and discover some of its lesser-known features. Avoid common mistakes, take...
Read more >console - Web APIs - MDN Web Docs
Chrome Edge Firefox
console Full support. Chrome1. Toggle history Full support. Edge12. Toggle history Full s...
assert Full support. Chrome1. Toggle history Full support. Edge12....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Casting from any NumPy array to another is often just as fast as copying regardless of type (it’d likely hit a memory speed bottleneck first, so smaller types are faster,) but casting large amounts of Python values to anything is slow. This discourages using Python classes for tiles and such, you’ll want to implement them as a NumPy dtype instead.
Methods like
draw_rect
are still good if you don’t need more functionality. You might prefer python-tcod’s pathfinding and field-of-view algorithms over making your own implementation, and you can profile your code to figure out what you need to improve right at this moment.console_c
is astruct TCOD_console*
type. This struct is initialized once with pointers to the NumPych,fg,bg
arrays which are created and owned by the Python Console itself. Whenconsole_c
is used with a call to C only the pointer to the struct is passed and the C function can interact with the NumPy arrays as if they were managed by C the entire time. The overhead that remains comes from converting all the other Python parameters into a C format, which only adds up when you call the methods too frequently.Re-implementing the methods in NumPy wouldn’t solve the problem since the “Python -> C” step still occurs even when working with NumPy. You’d have to write “NumPy -> NumPy” code to skip that step. Also, only
draw_rect
anddraw_frame
can be vectorised, the printing functions would be much slower written in Python as I learned the hard way when I wrote python-tdl.It’s not always easy but if you can make sure your inputs are arrays then you can vectorise the entire operation once you’re more familiar with NumPy.