Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Printing data
#1
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?
Reply
#2
This page in the link might help;

http://timgolden.me.uk/python/win32_how_do_i/print.html
Reply
#3
Thank you!

I actually went to that link and ran the code and got an error message.
Reply
#4
(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!
Reply
#5
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Extracting and printing data ajitnayak1987 0 1,408 Jul-28-2021, 09:30 AM
Last Post: ajitnayak1987
  printing selected item with Sqlite data whacky7 13 4,900 Jan-26-2020, 01:25 AM
Last Post: whacky7

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020