Skip to main content
codesue

Printing “Hello, World!”

I’ve been programming for two years now. There’s still a lot for me to learn, but I’ve come a long way since deciding to learn how to code and since writing my first program.

I’d always been reluctant about programming. Everything about it felt so esoteric: arbitrary punctuation, use of characters I’d always considered decorative (like backticks, vertical bars, backslashes, angle brackets), words like “static,” “public,” “private,” “var,” whimsically strewn across some oddly formatted text. Yikes!

Programming looked scary and seemed like something only certain people could do. But even scarier was the feeling that I’d be left out and left behind.

I mustered up the courage to get started and asked my software developer (at the time) boyfriend to teach me how to program. “Okay,” he responded. “Write a program that prints “Hello, World!”. I assumed he meant print as we generally use it in the non-techie sense, as in, send to the printer. The thought of another definition never even occurred to me. And, foolishly, instead of asking him what he meant, I assumed he expected too much of me or that he simply didn’t want to help me.

It wasn’t until months later, when I tried a Codecademy Python tutorial, that I realized how easy this task was! Print, in this context, meant something entirely different from what I thought it meant. My boyfriend was actually trying to encourage me by recommending this meaningful little task as my first program. I should have asked for clarification, and I shouldn’t have given up so quickly.

Today, I decided to slay this dragon, to complete this task that so perfectly represented my fear and my stubborn belief that becoming a programmer was out of my reach. I was going to write a program that prints “Hello, World!” in the general non-techie sense, and I was going to dedicate my whole morning to this!

It took less than 5 minutes.

import os

filename = "helloworld.txt"

with open(filename, "w") as file:
file.write("Hello, World!")

os.startfile(filename, "print")

NOTE: Using os.startfile only works on Windows. To run this on a Mac, replace os.startfile(filename, "print") with os.system(f"lp {filename}").