Posts

Showing posts with the label python

S3 Functions in Python using Boto

 1.  Copy from one folder in a bucket to another using Boto. Configure Boto AWS as mentioned in the documentation  here import boto3 import os,sys bucketName= "YOUR BUCKET NAME" # set this to True if you want the objects in copyToPathDirectory to be deleted first # set to False if the object being copied has the same name deleteObjectsFirst = False # Assuming Boto is setup s3 = boto3.resource( 's3' ) s3Client = boto3.client( 's3' ) bucket = s3.Bucket(bucketName) copyToPathDirectory = "the/directory/youwant/to/copyto/" copyFromPathNames = [ "path1/to/copyfrom/" , "path2/to/copyfrom/" , "and/so/on/" ] # WARNING: This will delete all objects in your folder # Please check your path before running if deleteObjectsFirst: delete_key_list = [] for copyFromPath in copyFromPathNames: for obj in bucket.objects. filter (Prefix = copyFromPath): deleteKey = copyToPathDirectory + obj.key delete_key_list...

Finding the version of a python package

pip list | grep [package name]

Finding the location of all pip installed packages

We all agree that it is convenient to install packages using pip . But where do these packages get installed? Which directory? You can find this in many ways, but two of the quickest include using the inspect module or pip show . inspect module: import inspect from class import classname inspect(classname) The third line will give you the full path pip show: pip show [package name] will do the trick too.