Python Forum

Full Version: Printing data
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm new at python. I know the code to print a text file to the printer but how do you print a variable or text within your program? Thank you.

The following code prints a text file called "hello.txt"

import os

os.startfile("hello.txt", "print")
But how do you print just a word or variable from within the program?
Thank you!

I actually went to that link and ran the code and got an error message.
(Nov-03-2019, 02:36 PM)scratchmyhead Wrote: [ -> ]how do you print a variable or text within your program?
Output:
$ python3 Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 26 2018, 23:26:24) [Clang 6.0 (clang-600.0.57)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> variable = "Hello, world!" >>> print(variable) Hello, world!
Only way I know to print variables or output text to a printer is to write it to a text file then print the text file through the method you show above.