1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
|
# TreeLib Examples
This directory contains comprehensive examples demonstrating all aspects of the TreeLib library. These examples are designed to help you learn TreeLib from basics to advanced usage.
## ๐ Quick Start
**New to TreeLib?** Start here:
1. [`getting_started.py`](#getting_started) - Complete beginner's tutorial
2. [`family_tree.py`](#family_tree) - Real-world tree operations
3. [`save_tree2file.py`](#save_tree2file) - Export and save trees
## ๐ Example Overview
### ๐ฑ Getting Started
**File:** `getting_started.py`
**Perfect for:** Complete beginners to TreeLib
A comprehensive tutorial covering all the basics:
- Creating trees and nodes
- Tree navigation and traversal
- Searching and filtering
- Tree modifications
- Working with custom data
- Display and export options
**Run it:**
```bash
python examples/getting_started.py
```
### ๐จโ๐ฉโ๐งโ๐ฆ Family Tree
**File:** `family_tree.py`
**Perfect for:** Understanding real-world tree operations
Demonstrates TreeLib features using a family tree:
- Different display formats
- Tree traversal methods
- Filtering and searching
- Subtree operations
- Tree modifications
- Advanced features (JSON, paths, etc.)
**Run it:**
```bash
python examples/family_tree.py
```
### ๐พ Save Tree to File
**File:** `save_tree2file.py`
**Perfect for:** Learning export and persistence
Shows different ways to export trees:
- Text file export
- JSON export
- Dictionary conversion
- Custom formatting
- Graphviz DOT format
**Run it:**
```bash
python examples/save_tree2file.py
```
### ๐ Folder Tree Scanner
**File:** `folder_tree.py`
**Perfect for:** Real file system applications
Advanced file system scanner with:
- Command-line interface
- Real directory scanning
- File filtering by patterns
- Performance optimization
- Multiple export formats
- Error handling
**Run it:**
```bash
# Demo mode
python examples/folder_tree.py --demo
# Scan current directory for Python files
python examples/folder_tree.py . "*.py" --max-depth 3
# Scan with file sizes
python examples/folder_tree.py /path/to/scan "*" --show-sizes --limit 100
# Export to JSON
python examples/folder_tree.py . "*.txt" --export json --output my_tree.json
```
### ๐ณ Recursive Directory Generator
**File:** `recursive_dirtree.py`
**Perfect for:** Understanding programmatic tree creation
Simulates directory structures programmatically:
- Recursive tree generation
- Custom node data (files, sizes, etc.)
- Tree analysis and statistics
- Performance testing
- Large tree handling
**Run it:**
```bash
python examples/recursive_dirtree.py
```
### ๐ JSON Trees
**File:** `json_trees.py`
**Perfect for:** API integration and data exchange
Comprehensive JSON integration:
- Export trees to JSON
- Import trees from JSON
- Custom JSON schemas
- Real-world API data integration
- File operations with JSON
**Run it:**
```bash
python examples/json_trees.py
```
### ๐งฎ Tree Algorithms
**File:** `tree_algorithms.py`
**Perfect for:** Advanced tree operations and algorithms
Advanced algorithmic operations:
- Tree traversal algorithms (DFS, BFS, custom)
- Tree analysis and metrics
- Path finding algorithms
- Tree transformations
- Tree comparison
- Performance analysis
**Run it:**
```bash
python examples/tree_algorithms.py
```
## ๐ Example Categories
### ๐ฐ Beginner Examples
- `getting_started.py` - Complete tutorial
- `family_tree.py` - Basic operations
- `save_tree2file.py` - Export basics
### ๐๏ธ Real-World Applications
- `folder_tree.py` - File system scanner
- `json_trees.py` - API integration
- `recursive_dirtree.py` - Programmatic generation
### ๐ Advanced Topics
- `tree_algorithms.py` - Algorithms and analysis
## ๐ฏ Use Case Guide
### I want to...
**Learn TreeLib basics**
โ Start with `getting_started.py`
**Build a file/folder visualizer**
โ Check out `folder_tree.py`
**Work with JSON/API data**
โ See `json_trees.py`
**Export trees to files**
โ Look at `save_tree2file.py`
**Implement tree algorithms**
โ Study `tree_algorithms.py`
**Create large test trees**
โ Use `recursive_dirtree.py`
**Understand all features**
โ Run `family_tree.py`
## ๐ Running Examples
### Prerequisites
Make sure TreeLib is in your Python path:
```bash
# If running from the treelib directory
PYTHONPATH=. python examples/example_name.py
# Or if TreeLib is installed
python examples/example_name.py
```
### Interactive Learning
Each example includes:
- โจ **Rich output** with emojis and formatting
- ๐ **Explanatory comments** throughout the code
- ๐ฏ **Focused demonstrations** of specific features
- ๐ก **Tips and best practices**
## ๐ง Customization
All examples are designed to be:
- **Modifiable** - Easy to adapt for your needs
- **Educational** - Clear, commented code
- **Practical** - Real-world applicable patterns
Feel free to modify any example to experiment with different:
- Tree structures
- Data types
- Algorithms
- Export formats
- Display options
## ๐ Learning Path
**Recommended order for learning:**
1. **`getting_started.py`** - Learn the fundamentals
2. **`family_tree.py`** - See practical usage
3. **`save_tree2file.py`** - Understand export options
4. **`folder_tree.py`** - Real-world application
5. **`json_trees.py`** - Data integration
6. **`recursive_dirtree.py`** - Programmatic creation
7. **`tree_algorithms.py`** - Advanced algorithms
## ๐ Need Help?
- **๐ Documentation:** Check the main TreeLib documentation
- **๐ Issues:** Report bugs in the main repository
- **๐ก Questions:** Look at the example code comments
- **๐ง Customization:** Modify examples to fit your needs
## ๐ Contributing
Found an issue or want to improve an example?
- Fix bugs in existing examples
- Add new example use cases
- Improve documentation
- Enhance code clarity
Remember: Examples should be **educational**, **practical**, and **easy to understand**!
---
**Happy tree building! ๐ณ**
|