Updating File Contents
the file contains just one line that says
print("Hello, World!"). So, if you use this character, the
> (greater than) symbol, then it’s going to overwrite whatever is in the file and put in there—replace it, I guess. Okay. So, that’s important to know.
With this one
> sign, you’re basically overwriting whatever is in that file. There’s a—if you wanted to add something, you could use a double of this symbol (
>>), and then it’s going to append it at the bottom of the file. Go for it.
I’m going to replace it again, though. I will only have one
Hello, World!. Is that okay? Okay, yeah. But then let’s emphasize, so this one, you’re using one
> sign there again, and you are replacing the whole content of the file now with what you’re echoing before that, which, again, is just a
print("Hello, World!"). Okay,
Okay. And now I want you also to run the
hello_terminal file in the
hello/ directory. Okay.
hello/hello_terminal.py. There it is. Perfect. Okay, so you don’t have to be in the same directory as the the file that you are running in this case with the
python command, but you can also add a path to it, and if the path is correct and there is a file called
hello_terminal, then it will execute this file. Yep. Okay, so this was everything that I want you to do. So thank you very much, Martin.
One thing that I wanted to talk about to wrap this up is the terminal usually don’t asks you if you really want to perform this action. So, sometimes if you delete a file in Finder, you get this little pop-up like, Do you really want to delete this file? or you have to press Cancel if you don’t want to. But in terminals, basically you put in a command, you overwrite the whole file with this new
print() function, and with the press of Enter, it’s just replacing this file.
Become a Member to join the conversation.