dracodes

Automation helpers


License
MIT
Install
pip install dracodes==0.33

Documentation

PyPI

Dracodes

One line solutions to speed up scripting

Installation:

pip3 install dracodes

Examples:

Writing into a file:

aString = 'A normal phrase'
aList = ['jooj', 'cleyton', 'not foo', 'not bar']
aListOfNumbers = list(range(10))
aMixedList = ['hello', 123456789, ['nested1', 'nested2'], {'1': 2}]
aDictionary = {'key1': 1, 'key2': 'valu2', 'key3': [3]}

with open('path/out.txt') as outFile:
	outFile.write(f'{aString}\n')
    for item in aList:
    	outFile.write(f'{line}\n')
    for item in aListOfNumbers :
    	outFile.write(f'{str(line)}\n')
    for item in aMixedList:
    	if isinstance(item, str):
            outFile.write(f'{line}\n')
        if isistance(item, list):
        	for subItem in item:
            	# Ok, we get it

A lazy solution:

from dracodes import saveOutput

output = tuple(aString, aList, aListOfNumbers, aMixedList, aDictionary)
saveOutput('path/out.txt', output) # by default in 'write' mode, but It is possible to set 'append' mode

Iterating over lines in a file:

Instead of:

with open('path/file.txt') as file:
	for line in file:
   		# ...

You can use iterFile:

from dracodes import iterFile

for line in iterFile('path/file.txt'):
	# ...

Indented Documents:

text = """class Jooj(object):
    def __init__(self, message):
        self.message

    def notBar(self):
        print('Not a Bar')

    def notFoo(self):
        print('Not a Foo')"""

doc = IndentedDocument(text)

for line in doc:
    print(f'{line} | Depth: {line.depth}')

Output:

class Jooj(object): | Depth: 1
    def __init__(self, message): | Depth: 2
        self.message | Depth: 3
 | Depth: 3
    def notBar(self): | Depth: 2
        print('Not a Bar') | Depth: 3
 | Depth: 3
    def notFoo(self): | Depth: 2
        print('Not a Foo') | Depth: 3

Lucas Vargas Noronha