Skip to main content

Automation helpers

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for dracodes, version 0.33
Filename, size File type Python version Upload date Hashes
Filename, size dracodes-0.33-py3-none-any.whl (16.5 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size dracodes-0.33.tar.gz (8.8 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page