✦ Python Intermediate & OOP Local Python project

L2 · Concept 02 · Modules, Packages & Environments

Your file can be a module.
Use it from another file.

Previously, you imported ready-made modules such as math and random. Now you will create two Python files on your computer and import code from one into the other.

Learning goalCreate two .py files in one local folder, import a function from your own module, run main.py, and explain the two common import styles.
01 Learn02 Build locally03 Check your understanding

Learning as a guest

Learning as a guest? Save your progress!

Create a free account to learn with Sloby AI, check your understanding, and track your progress.

The entire platform is free throughout 2026. Foundations stays free forever.

Your Python file can be a module too.

In the previous lesson, math and random came from Python’s standard library. A file you create, such as kalkulator.py, can also be a module: another Python file can use the functions inside it.

kalkulator.py

def saberi(a, b):
    return a + b

The functions in kalkulator.py can be imported by another file. We do not use packages yet; both files will stay in the same folder.

Splitting related code into modules keeps a project easier to read, reuse, and test. This lesson moves from one browser file to a small local project.

↳

Where do I do this? Browser Playground is useful for short, one-file experiments. A local project is needed when files work together, and later for packages, virtual environments, and installed libraries. This is not different Python—only a real project folder on your computer.

What you need
• Python installed
• VS Code installed
• Sloby Tutor VS Code extension
• One folder for practice

If Python already runs on your computer, use the command that works there. This lesson does not need a separate installation system.

Do not add .py to an import
import kalkulator      # Correct
# import kalkulator.py  # Not valid

Python uses the file name without .py as the module name.

Before you build locally

  1. 1. Make a folderCreate a folder named moj_modul somewhere easy to find, such as Documents or Desktop.
  2. 2. Open the folder in VS CodeStart VS Code, choose File → Open Folder, then select moj_modul. The idea is the same on Windows, macOS, and Linux.
  3. 3. Create two filesIn the Explorer panel create main.py and kalkulator.py. Keep them in this same folder for the first example.
  4. 4. Run the main fileChoose Terminal → New Terminal. In the project folder run python main.py, or python3 main.py if that is the Python command that works on your computer.

If an import does not work

  • The files are in different foldersFor this first example, main.py and kalkulator.py must be in the same folder.
  • The file name or import is misspelledCheck that the file is named kalkulator.py and the import is import kalkulator.
  • The files are not savedSave both files before running main.py.
  • The terminal is in the wrong folderOpen the project folder in VS Code, then open a new terminal there.
  • A file hides a standard moduleDo not name a practice file random.py or math.py. Those names can hide modules from Python’s standard library.

Prepare your Python environment

Start here

From this lesson, you will work with Python on your own computer too. We will prepare everything you need before your first local project.

↳

Working locally means that Python code lives in .py files on your computer, organized into folders and projects. You edit it in VS Code and run it with Python installed on your computer. Python is the same; only the environment changes. Browser Playground remains useful for short examples.

  1. 01 — PythonPython is the interpreter that runs your .py files. Until now, Browser Playground ran Python for you. VS Code is not Python, so your computer needs its own Python installation.Download Python from python.org
    python --version\npython3 --version
    • Install Python from the official website. Installation details can differ slightly by operating system.
    • Open a terminal and run one of the commands above. You should see a Python 3.x version. Use whichever command works on your computer.
  2. 02 — VS CodeVS Code is the editor where you write and organize code. You will open project folders, create .py files, write code, and use the terminal there. It is not a programming language or a replacement for Python.Download VS Code
    • Start VS Code and choose File → Open Folder.
    • Choose or create a project folder. The Explorer on the left shows its files; create new .py files there.
    • Open the built-in terminal with Terminal → New Terminal.
    • For extra Python support, open Extensions, search for Python, and choose the extension published by Microsoft.
  3. 03 — Sloby TutorSloby Tutor is the Python AI Tutor VS Code extension. Use Ask Sloby to discuss code or a concept. Use Check My Code after your own attempt for mentoring feedback.Download Sloby Tutor (.vsix)

      Install Sloby Tutor — step by step

      1. Download Sloby TutorClick the yellow Download Sloby Tutor (.vsix) button. Your browser downloads sloby-tutor-0.0.2.vsix. A .vsix file is an installation package for a VS Code extension, so do not open it by double-clicking.
      2. Open VS CodeStart Visual Studio Code, which you installed in the previous step of this lesson.
      3. Find ExtensionsOn the left side of the VS Code window is a vertical strip of icons called the Activity Bar. Click Extensions, the icon made of four small blocks. Extensions is the part of VS Code where you install add-ons such as Sloby Tutor. You can also open it with Shift + Command + X on macOS or Ctrl + Shift + X on Windows and Linux.
      4. Open the Extensions menuWhen the Extensions panel opens, look in its top title bar for the three-dot ... menu. Click that menu.
      5. Choose Install from VSIX...Choose Install from VSIX.... VS Code opens a file picker. Find sloby-tutor-0.0.2.vsix, usually in Downloads, select it, and confirm.
      6. Wait for installation to finishVS Code installs Sloby Tutor. If it shows Reload, Reload Window, or a similar prompt, click it. This prompt may not always appear.
      7. Connect Sloby Tutor to your Python AI Tutor accountOpen the Sloby Tutor view from the Activity Bar, or open the Command Palette and run Sloby Tutor: Sign In. Your browser opens the Python AI Tutor sign-in and approval flow. Sign in if needed, approve the connection, then return to VS Code when the browser confirms it.

      Sloby is ready

      Ask Sloby is for a concept, an error message, or your next step. Check My Code is for mentoring feedback after you write your own code. Before code is sent, Sloby asks for your confirmation. It analyzes the code you approve, but does not run it or change files on your computer. When Sloby Tutor shows that it is connected, you are ready for the local practice below.

    Everything ready? Continue to your first local project ↓

    Local VS Code practice

    Do this in VS Code

    This practical work happens on your computer, not in the browser Playground. Create and save the files in VS Code before you run them.

    Your first local project
    moj_modul/
    ├── main.py
    └── kalkulator.py

    Both files are in one folder, so main.py can import kalkulator.py as kalkulator.

    Build the two-file example

    1. Create kalkulator.pyAdd one function, then save the file.
      def saberi(a, b):
          return a + b
    2. Create main.pyImport the module without .py and call its function.
      import kalkulator
      
      rezultat = kalkulator.saberi(5, 3)
      print(rezultat)
    3. Try a direct function importThis style imports only saberi, so its call does not start with kalkulator.
      from kalkulator import saberi
      
      print(saberi(10, 4))
    4. Add another related functionModules keep related functions together.
      def pomnozi(a, b):
          return a * b
    A small test inside the module
    def saberi(a, b):
        return a + b
    
    if __name__ == "__main__":
        print(saberi(2, 3))

    When you run kalkulator.py directly, this small demo runs. When main.py imports kalkulator, the demo does not run. The file can therefore contain reusable functions and a small test.

    ↳

    Run locally: python main.py If your computer uses python3 instead, run python3 main.py. The expected first result is 8.

    Check before asking for help

    • Save, then runSave both files and run main.py from the moj_modul folder.
    • Avoid standard-library namesA local random.py or math.py can prevent Python from importing the standard module you expect.

    Which call matches this import?

    Read the import first, then choose the matching function call.

    import kalkulator
    Choose the output

    Build independently in VS Code

    My first module

    This challenge is local: do not load it into the browser Playground.

    Your goalCreate konverter.py with celsius_u_fahrenheit(celsius) and km_u_milje(km). In main.py, import the functions or module, call both with several values, and print the results.
    moj_modul/
    ├── main.py
    └── konverter.py

    Work in your local VS Code folder

    Progressive hints
    • First create the two functions in konverter.py.
    • In main.py, use import konverter or import the functions directly.
    • If import fails, check that both saved files are in the same folder.

    After your own attempt, use Check My Code on the active Python file, confirm that its code will be sent, and read Sloby’s mentoring feedback. Sloby does not run or change your code.

    Sloby, the Python AI Tutor mascot

    Your learning mentor

    Sign in to ask Sloby

    Create a free account or sign in to get AI guidance while you learn.

    Sign in to check your understanding

    Create a free account or sign in to receive AI feedback and save your learning progress.

    Python AI Tutor · Learn by understanding, not just by running code.