23,239 questions
2452
votes
36
answers
3.4m
views
What's the simplest way to print a Java array?
In Java, arrays don't override toString(), so if you try to print one directly, you get the className + '@' + the hex of the hashCode of the array, as defined by Object.toString():
int[] intArray = ...
1636
votes
14
answers
1.2m
views
How can I flush the output of the print function?
How do I force Python's print function to flush the buffered output to the screen?
See also: Disable output buffering if the goal is to change the buffering behaviour generally. This question is ...
851
votes
13
answers
1.5m
views
How to print instances of a class using print()?
When I try to print an instance of a class, I get an output like this:
>>> class Test():
... def __init__(self):
... self.a = 'foo'
...
>>> print(Test())
<__main__....
703
votes
23
answers
743k
views
How to use HTML to print header and footer on every printed page of a document?
Is it possible to print HTML pages with custom headers and footers on each printed page?
I'd like to add the word "UNCLASSIFIED" in Red, Arial, size 16pt to the top and bottom of every printed page, ...
567
votes
37
answers
1.0m
views
Print <div id="printarea"></div> only?
How do I print the indicated div (without manually disabling all other content on the page)?
I want to avoid a new preview dialog, so creating a new window with this content is not useful.
The page ...
528
votes
16
answers
813k
views
The difference between sys.stdout.write and print?
Are there situations in which sys.stdout.write() is preferable to print?
(Examples: better performance; code that makes more sense)
425
votes
30
answers
1.9m
views
How can I write to the console in PHP?
Is it possible write a string or log into the console?
What I mean
Just like in JSP, if we print something like system.out.println("some"), it will be there at the console, not at a page.
394
votes
14
answers
1.3m
views
How can I print multiple things (fixed text and/or variable values) on the same line, all at once?
I have some code like:
score = 100
name = 'Alice'
print('Total score for %s is %s', name, score)
I want it to print out Total score for Alice is 100, but instead I get Total score for %s is %s Alice ...
374
votes
10
answers
509k
views
Show DataFrame as table in iPython Notebook
I am using iPython notebook. When I do this:
df
I get a beautiful table with cells. However, if i do this:
df1
df2
it doesn't print the first beautiful table. If I try this:
print df1
print df2
...
324
votes
18
answers
573k
views
Landscape printing from HTML
I have a HTML report, which needs to be printed landscape because of the many columns. It there a way to do this, without the user having to change the document settings?
And what are the options ...
321
votes
13
answers
514k
views
How to deal with page breaks when printing a large HTML table
I have a project which requires printing an HTML table with many rows.
My problem is the way the table is printed over multiple page. It will sometimes cut a row in half, making it unreadable because ...
309
votes
7
answers
149k
views
Need to remove href values when printing in Chrome
I'm attempting to customize the print CSS, and finding that it prints links out with the href value as well as the link.
This is in Chrome.
For this HTML:
<a href="http://www.google.com">...
289
votes
18
answers
755k
views
How can I print bold text in Python?
E.g:
print "hello"
What should I do to make the text "hello" bold?
269
votes
13
answers
596k
views
Print JSON parsed object?
I've got a javascript object which has been JSON parsed using JSON.parse I now want to print the object so I can debug it (something is going wrong with the function). When I do the following...
for (...
257
votes
10
answers
489k
views
Pretty Printing a pandas dataframe
How can I print a pandas dataframe as a nice text-based table, like the following?
+------------+---------+-------------+
| column_one | col_two | column_3 |
+------------+---------+-------------+
...
250
votes
9
answers
684k
views
Print string and variable contents on the same line in R
Is there a way to print text and variable contents on the same line? For example,
wd <- getwd()
print("Current working dir: ", wd)
I couldn't find anything about the syntax that would allow me to ...
244
votes
15
answers
316k
views
How do I keep Python print from adding newlines or spaces? [duplicate]
In python, if I say
print 'h'
I get the letter h and a newline. If I say
print 'h',
I get the letter h and no newline. If I say
print 'h',
print 'm',
I get the letter h, a space, and the letter ...
216
votes
22
answers
318k
views
How to print binary tree diagram in Java?
How can I print a binary tree in Java so that the output is like:
4
/ \
2 5
My node:
public class Node<A extends Comparable> {
Node<A> left, right;
A data;
public ...
210
votes
7
answers
89k
views
Why is printing to stdout so slow? Can it be sped up?
I've always been amazed/frustrated with how long it takes to simply output to the terminal with a print statement. After some recent painfully slow logging I decided to look into it and was quite ...
203
votes
10
answers
300k
views
Disabling browser print options (headers, footers, margins) from page?
I have seen this question asked in a couple of different ways on SO and several other websites, but most of them are either too specific or out-of-date. I'm hoping someone can provide a definitive ...
194
votes
11
answers
412k
views
How can I print the contents of a hash in Perl?
I keep printing my hash as # of buckets / # allocated.
How do I print the contents of my hash?
Without using a while loop would be most preferable (for example, a one-liner would be best).
175
votes
7
answers
417k
views
Margin while printing html page
I am using a separate style-sheet for printing.
Is it possible to set right and left margins in the style-sheet which set the print margin? (i.e. margin on paper)
165
votes
9
answers
304k
views
How to create a printable Twitter-Bootstrap page
I'm using Twitter-Bootstrap and I need to be able to print the page the way it looks on the browser. I'm able to print other pages made with Twitter-Bootstrap just fine but I can't seem to print my ...
161
votes
6
answers
870k
views
How to print HTML content on click of a button, but not the page? [duplicate]
I want to print some HTML content, when the user clicks on a button. Once the user clicks on that button, the print dialog of the browser will open, but it will not print the webpage. Instead, it will ...
157
votes
9
answers
381k
views
TypeError: cannot concatenate 'str' and 'int' objects [duplicate]
I have this python program that adds strings to integers:
a = raw_input("Enter a: ")
b = raw_input("Enter b: ")
print "a + b as strings: " + a + b
a = int(a)
b = int(b)
c ...