python tarfile and go strings

main
Nguyen Tran Hau 2020-07-10 17:57:16 +07:00
parent 83029df884
commit 99c556307f
4 changed files with 26 additions and 4 deletions

View File

@ -1,9 +1,9 @@
# Go
| Distribution | Package |
| ------------ | ----------------------------------------------- |
| Arch Linux | `go`, `go-tools` |
| Ubuntu | [See](https://github.com/golang/go/wiki/Ubuntu) |
| Distribution | Package |
| ------------ | ---------------- |
| Arch Linux | `go`, `go-tools` |
| Snap | `go` |
Add to `~/.bashrc`:

View File

@ -0,0 +1,9 @@
# [strings](https://golang.org/pkg/strings/)
Replace list of strings by using Replacer:
```go
template := "My city is {city} and my country is {country}"
r := strings.NewReplacer("{city}", "Sai Gon", "{country}", "Viet Nam")
fmt.Println(r.Replace(template))
```

View File

@ -0,0 +1,11 @@
# [tarfile](https://docs.python.org/3/library/tarfile.html)
```python
# Read then extract
with tarfile.open(path_to_tarfile) as tar:
tar.extractall(path_to_extract)
# Create a gzipped archive from file
with tarfile.open(path_to_archive, "w:gz") as tar:
tar.add(path_to_file, arcname=filename_inside_archive)
```

View File

@ -42,6 +42,7 @@
- [ANTLR](Development/ANTLR/README.md)
- [Condition](Development/ANTLR/Condition.md)
- [Go](Development/Go/README.md)
- [strings](Development/Go/strings.md)
- [testing](Development/Go/testing.md)
- [time](Development/Go/time.md)
- [Python](Development/Python/README.md)
@ -49,6 +50,7 @@
- [black](Development/Python/black.md)
- [subprocess](Development/Python/subprocess.md)
- [venv](Development/Python/venv.md)
- [tarfile](Development/Python/tarfile.md)
- [Services](Development/Services/README.md)
- [Consul](Development/Services/Consul.md)
- [Grafana](Development/Services/Grafana.md)