Home / Blog / SIEM and Tools
Python Lesson 01: Install Python and Run Your First Script
Python Lesson 1 of 26: install Python 3 and VS Code, run your first script, and print the date, time and computer name. A beginner step by step start to the series.
Python Lesson 01 of 26, Month 1: First steps. By the end of this lesson you will have Python 3 and VS Code installed and a script that prints the date, time and computer name.
Why this matters on shift
- Handover notes need exact times and machine names. Typing them by hand invites mistakes.
- Small checks come up again and again on shift. A script answers them the same way every time.
- Every later lesson builds on this one, so a working setup now saves frustration later.
The idea in plain English
A script is a text file of instructions that a computer follows in order. Python is a popular scripting language, and the program that reads and runs your script is called the interpreter. VS Code (Visual Studio Code) is a free editor for writing scripts. A comment is a note for humans: Python ignores any line that starts with #.
Version note, as far as I could verify in November 2026: the official Python downloads page lists Python 3.15.2 as the latest release, with an installer for Windows and macOS. For Linux it points to source downloads, so check your distribution's own guidance. Your version may be newer. Newer is fine.
Safety: practise on your own computer or a lab virtual machine, never on a work system without permission, and never run scripts copied from unknown websites. This is an illustrative example with made up data, not a real incident.
Try it step by step
- Install Python 3 from the official downloads page.
- Install Visual Studio Code, which its page describes as free.
- Follow the VS Code Python guide to add the Python extension. It notes that you must install the Python interpreter separately from the extension, which is why step 1 comes first.
- Open a terminal and check the install.
First, ask Python for its version:
python --version
pythonstarts the interpreter and--versionis an option that prints the version and stops.- On Linux and macOS the command is often
python3. On some Windows setups it ispy.
What you should see: a line such as Python 3.15.2.
- In VS Code, create a file called hello.py and type the code below. The VS Code guide says to click the Run Python File play button at the top right of the editor to run it.
Your first script:
# My first SOC script
print("Hello, SOC")
print("Shift check starting")
- Line 1 is a comment. It explains the file and does nothing when run.
- Lines 2 and 3 use
print, a built in Python function that shows text on the screen. Text goes inside quotes.
What you should see: two lines in the terminal: Hello, SOC and Shift check starting.
- Now add the date, time and computer name. Save this as shift_info.py.
Print the date, time and computer name:
from datetime import datetime
import socket
print("Date:", datetime.now().strftime("%Y-%m-%d"))
print("Time:", datetime.now().strftime("%H:%M:%S"))
print("Computer:", socket.gethostname())
- Lines 1 and 2 are imports. An import takes a ready made tool from Python's standard library, like taking a tool out of a toolbox. The datetime and socket pages document them.
datetime.now()gets the current local date and time.strftimeturns it into text using a pattern: %Y is the year, %m the month, %d the day, %H the hour, %M the minute and %S the second.printcan take two things separated by a comma. It shows them with a space between.socket.gethostname()returns the name of the computer. The socket page says it does not always give the fully qualified name.
What you should see: three lines such as Date: 2026-11-26, Time: 09:30:05 and Computer: WS-114.
Your small task (5 to 15 minutes)
Write a script that prints your first name on one line and today's date, in the form year-month-day only, on the next line. A correct result is two lines, for example Ben and then 2026-11-26.
Additional Learning: https://codepython.net (30 to 60 minutes daily)
Mini project (30 to 60 minutes)
Start your toolkit. Create a folder called soc-toolkit-py in your home folder using your file manager, and save shift_info.py inside it.
- The script prints the date, time and computer name, one per line.
- It has a comment at the top saying what it does.
- You can run it from VS Code and from a terminal.
Hint: in the terminal, change into the folder first, then run the script with python shift_info.py (or python3 on Linux and macOS).
Check your answer
from datetime import datetime
print("Ben")
print(datetime.now().strftime("%Y-%m-%d"))
- Line 1 imports the datetime tool. Swap Ben for your own name.
- Line 3 prints your name as text.
- Line 4 prints today's date. It has no time codes in the pattern, so only the date appears.
Progress check
- You can now install Python 3 and VS Code and check the version.
- You can now write and run a script that uses comments and print.
- You can now print the date, time and computer name with datetime and socket.
Next lesson: Python Lesson 02: Variables and data types.
Written by Ben, Cybersecurity Student, member of Cyber Talent Incubator Network (CTIN) Cohort