A manipulation package to change whole folders.
Project description
File manipulation
Explanation:
The idea is to transform a function that transform one text into another text and call it transforming the desired files with that function.
This is not a package made thinking about being used in a project, rather it's a package made to make a programmer's life easier.
INSTRUCTIONS:
Decorator that transforms an [str] = function( [str]:text, *args, **kwargs ) into an function that apllies itself into a folder.
The default values for the new function can be set at the decorator.
Default values on decorator are set to avoid writting over important files with broken functions.
!! ATENTION !!
MAKE SURE TO ALWAYS TEST YOUR FUNCTIONS BEFORE APPLYING ANY TRUE CHANGES.
Simple functions:
Imagine you want to comment all prints in your project:
from manip import manip
@manip()
def comment_print(text):
return text.replace('print(', '# print(')
Now we can call the function on a folder like:
comment_print(path='./target')
comment_print(path='./target', test=False) # to save changes on original files
If you wanna just call a single line function on the command line you can import manipulate:
from manip import manipulate
manipulate(lambda text: text.replace('print(', '# print('), path='./target', test=False)
up to change whole files with json data, maybe:
from manip import manip
import json
@manip(at='.json$')
def join_props(text, prop1='key', prop2='value', new_prop='new'):
obj = json.loads(text)
obj[new_prop] = (prop1, prop2)
del(obj[prop1])
del(obj[prop2])
return json.dumps(obj)
<style>
p {
font-size: 19px;
}
.params {
display: flex;
flex-direction: column;
margin-left: 3%;
font-size: 17px;
margin-bottom: 15px;
}
</style>
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.