Selenium + Python · Lesson 7 of 43

0/43 done

Module 7: Modules & Packages

7. Python Modules, Packages & Project Organization

14 minlesson

Your task

Implement safe_convert_price(raw_price: str) -> float:

  1. Strip leading/trailing whitespace.
  2. Remove any "$" character.
  3. Convert and return as float. Return 0.0 if empty or invalid.

Write it in the editor, then press Check answer (Ctrl + Enter).

Modules & Package Structure

python
# Reusable helper module: utils/string_helper.py
def clean_currency(raw_price: str) -> float:
    return float(raw_price.replace("$", "").strip())

# Importing in page or test files:
from utils.string_helper import clean_currency
import datetime as dt

price = clean_currency(" $49.99 ")

Key Takeaways & Walkthrough Summary

Organizing automation suites into clean modules and packages ensures easy imports and zero circular dependency issues. In this lesson, you will master import, from ... import, aliases, and __init__.py. Let's organize our modules!

Part of the Selenium + Python course (Selenium with Python). Practice this concept live in the Selenium Online Compiler or explore our free automation practice form.

Common Doubts & Lesson Q&A

Why do folders in Python test frameworks contain __init__.py?

__init__.py signals to Python that the folder is a package, allowing other test files to import modules from that folder cleanly.

Ready? Solve the task in the editor

Use Check answer to mark it complete. Hints are there if you need them.

Python
Skip