some helper functions from nic's gist
Project description
Helpers
various helpers from nic gist
from nicHelper.wrappers import add_method
Install
pip install nicHelper
How to use
method module
add method to a class
class A:
pass
@add_method(A)
def printHello(self):
print('hello')
A().printHello()
hello
Dict utilities
from nicHelper.dictUtil import printDict
printDict({'key':'sjfhdkljhafsdlkjhdfaslkjhkljfadshklhfa', 'nestedKey':{'nestedKey2':'938023840843', 'nested3':{'nested4':'hello'}}})
key : sjfhdkljha
nestedKey
nestedKey2 : 9380238408
nested3
nested4 : hello
Exception module
from nicHelper.exception import errorString
try:
error
except:
print(f'error is \n{errorString()}')
error is
Traceback (most recent call last):
File "<ipython-input-5-86083feec525>", line 3, in <module>
error
NameError: name 'error' is not defined
Image utils
from nicHelper.images import imageFromUrl, imageToS3, showImgS3, resizeImage
from s3bz.s3bz import S3
## test variables
key = 'testCat.png'
path = '/tmp/testCat.png'
bucket = 'villa-remove-bg-small-output'
url = 'https://sites.google.com/site/funnycatmeawww/_/rsrc/1422326075261/home/6997052-funny-cat.jpg?height=675&width=1200'
Resize images
resizeImage(url, 400)
load image from url
img = imageFromUrl(url)
type(img)
PIL.JpegImagePlugin.JpegImageFile
save Image to S3
imageToS3(img, bucket, key)
S3.exist(key,bucket)
saving image to villa-remove-bg-small-output/testCat.png
True
display image from s3
## full test
showImgS3(bucket, key)
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.
Source Distribution
nicHelper-0.0.5.tar.gz
(13.1 kB
view hashes)
Built Distribution
nicHelper-0.0.5-py3-none-any.whl
(13.2 kB
view hashes)
Close
Hashes for nicHelper-0.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52c644631e0f68e6be76f113458bb560fd8f9b56bec867b6381f0a5e30bedd5f |
|
MD5 | f99021d46ed81180a5fb0771f784082c |
|
BLAKE2b-256 | d718849af72d29889a25669f85372d26a569e3cc9e9beab1ceb3eeec747970ba |