|
| 1 | +[⬅ Back to Table of Contents](../index.md) |
| 2 | + |
| 3 | +# Includes and Namespaces |
| 4 | + |
| 5 | +## The Easy Way (Recommended) |
| 6 | + |
| 7 | +Just include the main header—this pulls in everything under the `Pythonic` (or `py`) namespace: |
| 8 | + |
| 9 | +```cpp |
| 10 | +#include "pythonic/pythonic.hpp" |
| 11 | + |
| 12 | +using namespace Pythonic; |
| 13 | +// or |
| 14 | +using namespace py; |
| 15 | +``` |
| 16 | + |
| 17 | +## The Manual Way |
| 18 | + |
| 19 | +Or, pick exactly what you need: |
| 20 | + |
| 21 | +```cpp |
| 22 | +#include "pythonicVars.hpp" // var, list, dict, set |
| 23 | +#include "pythonicPrint.hpp" // print(), pprint() |
| 24 | +#include "pythonicLoop.hpp" // range(), enumerate(), zip() + macros |
| 25 | +#include "pythonicFunction.hpp" // map, filter, comprehensions |
| 26 | +#include "pythonicFile.hpp" // File I/O |
| 27 | +#include "pythonicMath.hpp" // Math functions (trig, logarithms, etc.) |
| 28 | + |
| 29 | +using namespace pythonic::vars; |
| 30 | +using namespace pythonic::print; |
| 31 | +using namespace pythonic::loop; |
| 32 | +using namespace pythonic::math; |
| 33 | +using namespace pythonic::file; |
| 34 | +using namespace pythonic::func; |
| 35 | +using namespace pythonic::graph; |
| 36 | +using namespace pythonic::fast; |
| 37 | +using namespace pythonic::overflow; |
| 38 | +using namespace pythonic::error; |
| 39 | +``` |
| 40 | +
|
| 41 | +> **Caution:** |
| 42 | +> If you import namespaces globally, be careful with `std` and other namespaces—they might clash or cause ambiguity. We recommend using `std::` explicitly if you make the `pythonic` namespace global. |
| 43 | +
|
| 44 | +--- |
| 45 | +
|
| 46 | +## About Namespaces |
| 47 | +
|
| 48 | +- `pythonic::vars` – Core `var` type, containers, type conversion |
| 49 | +- `pythonic::print` – Printing and formatting (`print()`, `pprint()`) |
| 50 | +- `pythonic::loop` – Iteration helpers (`range()`, `enumerate()`, `zip()`, `reversed()`) |
| 51 | +- `pythonic::func` – Functional programming (`map()`, `filter()`, comprehensions) |
| 52 | +- `pythonic::file` – File I/O |
| 53 | +- `pythonic::math` – Comprehensive math library (`trig`, `logarithms`, `random`, etc.) |
| 54 | +- `pythonic::graph` – Graph data structure and algorithms |
| 55 | +- `pythonic::error` – Exception hierarchy and error handling |
| 56 | +- `pythonic::fast` – Hot-loop optimizations |
| 57 | +- `pythonic::overflow` – Checked arithmetic helpers |
| 58 | +
|
| 59 | +You can use them all at once with: |
| 60 | +
|
| 61 | +```cpp |
| 62 | +using namespace Pythonic; |
| 63 | +// or |
| 64 | +using namespace py; |
| 65 | +``` |
| 66 | + |
| 67 | +--- |
| 68 | + |
| 69 | +> **Note:** |
| 70 | +> We highly recommend including the whole library at once, as many parts have dependencies on others (e.g., the math library depends on `var`). If you try to use the math library without including `pythonicVar.hpp` and the `var` namespace, your code may not work as expected. |
| 71 | + |
| 72 | +--- |
| 73 | + |
| 74 | +## Next |
| 75 | + |
| 76 | +- [Print](../Print/print.md) |
0 commit comments