Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mendelsshop/fstringlt36
python f-strings for before python 3.6
https://github.com/mendelsshop/fstringlt36
f-strings python python2 python3
Last synced: 23 days ago
JSON representation
python f-strings for before python 3.6
- Host: GitHub
- URL: https://github.com/mendelsshop/fstringlt36
- Owner: mendelsshop
- License: mit
- Created: 2021-11-01T05:36:07.000Z (about 3 years ago)
- Default Branch: regex
- Last Pushed: 2022-05-02T06:14:30.000Z (over 2 years ago)
- Last Synced: 2024-12-17T08:54:17.612Z (25 days ago)
- Topics: f-strings, python, python2, python3
- Language: Python
- Homepage:
- Size: 136 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![tests](https://github.com/mendelsshop/fstringlt36/actions/workflows/test.yml/badge.svg?branch=regex)](https://github.com/mendelsshop/fstringlt36/actions/workflows/test.yml)
[![flake8](https://github.com/mendelsshop/fstringlt36/actions/workflows/flake8.yml/badge.svg)](https://github.com/mendelsshop/fstringlt36/actions/workflows/flake8.yml)
[![Upload Python Package](https://github.com/mendelsshop/fstringlt36/actions/workflows/python-publish.yml/badge.svg)](https://github.com/mendelsshop/fstringlt36/actions/workflows/python-publish.yml)
# fstringlt36 Regex Edition
# I might finish this after I finish [UMPL](https://github.com/mendelsshop/UMPL), because making a launguage will help me understand how to do this properly.
## Installation: pip install fstringlt36
## About:
Python f-strings for before Python 3.6. using Regex
This package should try to emulate all f-string features
by using a class that inherits from str.
You can also use it to get newer f-string features in earlier versions of Python.
such as: `h = 'hello'; f'{h = }'`. the ; is just to denonote the end of a line.
This package requires the re (regular expressions, regex) module.
To my knowledge most versions of Python have re, if not you can use the non regex version
So it should be able to install on any Python version.
Although it's not been tested if thats true because it's not working yet.
Once I implement all the features I will test it across multiple python version and platforms.## Features currently working:
### basic variable replacement
```python
>>> from fstringlt36 import f
>>> h = "Hello,"
>>> f("{h} world")
hello world
```
#### using the equal operator (I don't know a better name for this and I'm to lazy to look at the document)
```python
>>> from fstringlt36 import f
>>> h = "Hello,"
>>> # instead of doing print(f("h = {h}"))
>>> # you can do print(f("{h = }"))
>>> print(f("{h = }"))
h = 'Hello,'
```
#### note:
please note to not call `f().f_string_parse()` directly but use the `f()` class.
if you try to `f_string_parse()` to use directly it will ruin your output and fall back to:```python
>>> value = 'error: variable ' + string + ' not found'
```where value is the replacement string to whatever you put in `{}`.
```python
>>> from fstringlt36 import f
>>> var = 'foo'
>>> s = f("{var}")
>>> print(s)
foo
>>> t = s.f_string_parse()
>>> print(t)
error: variable value not found
>>> print(s)
error: variable value not found
# besides for messing up t it will also mess up s because it's a reference to the same object.```
## Version:
Version Number: 0.0.3
Version Stage: alpha