Adding Content to a File
So far, you have created a Python file, but there is nothing in it. So next I want you, without opening any external editor, create some content in this file, Like a
print("Hello, Terminal!") function. Okay.
Usually I don’t do this, but you can do it in a very similar way to on Linux systems as well. It’s where you
echo, was it
"print('Hello, Terminal')"? Yeah.
00:27 I just need to be careful here with the quotation marks.
That’s true. So you are starting with a double quotation mark and then are careful that inside of the
print() function that your argument there is in one quotation mark.
Right. If I started doing stuff like this, you can see with the syntax highlighting that it’s getting a bit confused, and it’s printing—
echo just means print this to the terminal, as you can see it’s done here, but it’s done in a bit of a weird way.
00:56 So we’ll just replace the inner quotation marks with single quotation marks, and now you’ll see that it prints in a way that’s much more expected.
01:07 And it’s basically similar to how it works with strings in Python. Right. If you want to have a quotation mark inside of a string, you have to use the other quotation mark, basically. Yeah. Yeah, absolutely.
01:19 Yeah. Except Python will probably give you an error, whereas in this case, it seemed that PowerShell was able to recover this in … any way— Do something— Yeah.
Yeah. All right. Then after this, you can put this
> (right-facing chevron), and then you can put in the filename, which was
hello_terminal, I believe.
.py. Yep. Now the line
print('Hello, Terminal!') will be in
Okay, so now the terminal itself didn’t output anything because you redirected this
echo command into the file. Right, yes. I was hesitant of how much detail to go into with this because, again, it’s not something I usually do—use this redirect chevron—because it sort of redirects the output of this first command into wherever I want. I could redirect it into another command or into a file, for instance, like I have here.
02:24 And so this can be hard to understand exactly what’s going on. To be honest, I usually just open a code editor and do it manually, yeah. You would be allowed to do, but not in this course, so
Become a Member to join the conversation.