Metadata-Version: 2.1
Name: htutil
Version: 3.1.0
Summary: HaoTian's Python Util
Home-page: https://github.com/117503445/htutil
Author: 117503445
Author-email: t117503445@gmail.com
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
Classifier: Operating System :: OS Independent
Description-Content-Type: text/markdown
License-File: LICENSE

# htutil

HaoTian's Python Util

![version](https://img.shields.io/pypi/v/htutil)
![downloads](https://img.shields.io/pypi/dm/htutil)
![format](https://img.shields.io/pypi/format/htutil)
![implementation](https://img.shields.io/pypi/implementation/htutil)
![pyversions](https://img.shields.io/pypi/pyversions/htutil)
![license](https://img.shields.io/pypi/l/htutil)

## Install

```sh
pip install htutil
```

## Usage

### file

```python
from htutil import file
```

Refer to C# System.IO.File API, very simple to use.

```python
    s = 'hello'
    write_text('1.txt', s)
    # hello in 1.txt
    append_text('1.txt', 'world')
    # helloworld in 1.txt
    s = read_text('1.txt')
    print(s)  # helloworld

    s = ['hello', 'world']
    write_lines('1.txt', s)
    # hello\nworld in 1.txt
    append_lines('1.txt',['\npython'])
    # hello\nworld\npython in 1.txt
    s = read_lines('1.txt')
    print(s)  # ['hello', 'world', 'python']
```

### cache

cache def result by pickle file.

```python
from htutil import cache
@cache.file_cache
def get_1():
    time.sleep(3)
    return 1
```

### counter

a simple counter based on dict.

```python
    c = Counter()
    c.add('1')
    c.add('1')
    c.add('2')

    print(c.to_dict()) # {'1': 2, '2': 1}

    c.dump() # same as print(c.to_dict())
```
