aton.txt
General text operations
This subpackage contains tools for general text operations.
It provides the basic functionality that powers more complex subpackages,
such as aton.api.
Index
aton.txt.find |
Search for specific content from a text file |
aton.txt.edit |
Edit specific content from a text file |
aton.txt.extract |
Extract data from raw text strings |
Examples
The following example shows how to find a value in a text file, extract it and paste it into another file using the txt subpackage:
from aton import txt
# Get an array with all matches
alat_lines = txt.find.lines('relax.out', 'Lattice parameter =')
# Extract the numerical value of the last match
alat = txt.extract.number(alat_lines[-1], 'Lattice parameter')
# Paste it into another file
txt.edit.replace_line('scf.in', 'Lattice parameter =', f'Lattice parameter = {alat}')
Advanced usage such as regular expression matching or additional line extraction is detailed in the API documentation.
1""" 2# General text operations 3 4This subpackage contains tools for general text operations. 5It provides the basic functionality that powers more complex subpackages, 6such as `aton.api`. 7 8 9# Index 10 11| | | 12| --- | --- | 13| `aton.txt.find` | Search for specific content from a text file | 14| `aton.txt.edit` | Edit specific content from a text file | 15| `aton.txt.extract` | Extract data from raw text strings | 16 17 18# Examples 19 20The following example shows how to find a value in a text file, extract it and paste it into another file using the txt subpackage: 21 22```python 23from aton import txt 24# Get an array with all matches 25alat_lines = txt.find.lines('relax.out', 'Lattice parameter =') 26# Extract the numerical value of the last match 27alat = txt.extract.number(alat_lines[-1], 'Lattice parameter') 28# Paste it into another file 29txt.edit.replace_line('scf.in', 'Lattice parameter =', f'Lattice parameter = {alat}') 30``` 31 32Advanced usage such as regular expression matching or 33additional line extraction is detailed in the API documentation. 34 35""" 36 37 38from . import find 39from . import edit 40from . import extract