23,238 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 = ...
1813
votes
17
answers
1.4m
views
How do I print to stderr in Python?
There are several ways to write to stderr:
print >> sys.stderr, "spam" # Python 2 only.
sys.stderr.write("spam\n")
os.write(2, b"spam\n")
from __future__ import ...
1638
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 ...
1044
votes
23
answers
1.8m
views
How do I expand the output display to see more columns of a Pandas DataFrame?
Is there a way to widen the display of output in either interactive or script-execution mode?
Specifically, I am using the describe() function on a Pandas DataFrame. When the DataFrame is five ...
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__....
838
votes
13
answers
736k
views
Print a file, skipping the first X lines, in Bash [duplicate]
I have a very long file which I want to print, skipping the first 1,000,000 lines, for example.
I looked into the cat man page, but I did not see any option to do this. I am looking for a command to ...
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, ...
575
votes
11
answers
626k
views
How do I hide an element when printing a web page?
I have a link on my webpage to print the webpage. However, the link is also visible in the printout itself.
Is there javascript or HTML code which would hide the link button when I click the print ...
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 ...
537
votes
16
answers
994k
views
How to make a HTML Page in A4 paper size page(s)?
Is it possible to make a HTML page behave, for example, like a A4-sized page in MS Word?
Essentially, I want to be able to show the HTML page in the browser, and outline the content in the dimensions ...
528
votes
16
answers
814k
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)
430
votes
32
answers
1.1m
views
Print the contents of a DIV [closed]
Whats the best way to print the contents of a DIV?
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.
413
votes
15
answers
552k
views
Can I force a page break in HTML printing?
I'm making a HTML report that is going to be printable, and it has "sections" that should start in a new page.
Is there any way to put something in the HTML/CSS that will signal to the browser that ...
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 ...
377
votes
22
answers
751k
views
Print in one line dynamically [duplicate]
I would like to make several statements that give standard output without seeing newlines in between statements.
Specifically, suppose I have:
for item in range(1,100):
print item
The result is:
...
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
...
330
votes
23
answers
473k
views
Background color not showing in print preview
I am trying to print a page. In that page I have given a table a background color.
When I view the print preview in chrome its not taking on the background color property...
So I tried this property:
...
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
4
answers
781k
views
CSS to set A4 paper size
I need simulate an A4 paper in web and allow to print this page as it is show on browser (Chrome, specifically). I set the element size to 21cm x 29.7cm, but when I send to print (or print preview) it ...
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 ...
319
votes
2
answers
261k
views
How do I change the string representation of a Python class? [duplicate]
In Java, I can override the toString() method of my class. Then Java's print function prints the string representation of the object defined by its toString(). Is there a Python equivalent to Java's ...
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">...
304
votes
12
answers
239k
views
CSS Printing: Avoiding cut-in-half DIVs between pages?
I'm writing a plug-in for a piece of software that takes a big collection of items and pops them into HTML in a WebView in Cocoa (which uses WebKit as its renderer, so basically you can assume this ...
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?
288
votes
18
answers
651k
views
How can I print multiple things on the same line, one at a time?
I want to run a script, which basically shows an output like this:
Installing XXX... [DONE]
Currently, I print Installing XXX... first and then I print [DONE].
How can I instead print ...
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 (...
265
votes
6
answers
127k
views
How do I flush the PRINT buffer in TSQL?
I have a very long-running stored procedure in SQL Server 2005 that I'm trying to debug, and I'm using the 'print' command to do it. The problem is, I'm only getting the messages back from SQL Server ...
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 |
+------------+---------+-------------+
...
254
votes
18
answers
1.8m
views
How can I print variable and string on same line in Python? [duplicate]
I am using python to work out how many children would be born in 5 years if a child was born every 7 seconds. The problem is on my last line. How do I get a variable to work when I'm printing text ...
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 ...
248
votes
13
answers
107k
views
Suggestions for debugging print stylesheets?
I've recently been working on a print stylesheet for a website, and I realized that I was at a loss for effective ways to tweak it. It's one thing to have a reload cycle for working on the on-screen ...
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 ...
223
votes
19
answers
988k
views
How to print a dictionary line by line in Python?
This is the dictionary
cars = {'A':{'speed':70,
'color':2},
'B':{'speed':60,
'color':3}}
Using this for loop
for keys,values in cars.items():
print(keys)
print(values)...
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 ...
214
votes
12
answers
295k
views
Why doesn't "System.out.println" work in Android?
I want to print something in console, so that I can debug it. But for some reason, nothing prints in my Android application.
How do I debug then?
public class HelloWebview extends Activity {
...
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 ...
210
votes
9
answers
116k
views
In python, why use logging instead of print? [closed]
For simple debugging in a complex project is there a reason to use the python logger instead of print? What about other use-cases? Is there an accepted best use-case for each (especially when you're ...
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 ...
198
votes
3
answers
382k
views
Remove and Replace Printed items [duplicate]
I was wondering if it was possible to remove items you have printed in Python - not from the Python GUI, but from the command prompt.
e.g.
a = 0
for x in range (0,3):
a = a + 1
b = (&...
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).
178
votes
10
answers
119k
views
Why doesn't print work in a lambda?
Why doesn't this work?
lambda: print "x"
Is this not a single statement, or is it something else?
The documentation seems a little sparse on what is allowed in a lambda...
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)
171
votes
14
answers
239k
views
How can I force browsers to print background images in CSS?
This question was asked before but the solution is not applicable in my case. I want to make sure certain background images are printed because they are integral to the page. (They are not images ...
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 ...
162
votes
17
answers
384k
views
Remove header and footer from window.print()
I am using window.print() for printing page, but I got header and footer contains page title, file path, page number and date. How to remove them?
I tried print stylesheet also.
#header, #nav, ....
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 ...
161
votes
6
answers
460k
views
Loop a multidimensional array and only print two specific column values per row
How can I print the filepath and filename values from each row?
Array (
[0] => Array (
[fid] => 14
[list] => 1
[data] => Array (
...
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 ...
156
votes
10
answers
169k
views
GDB print to file instead of stdout
I am running GDB and want to examine one of those unfortunate god objects. It takes many pages (and I have a 24" monitor turned sideways!) to see the whole thing.
For ease of use, I'd like GDB to ...