Cross Platform Screen capture using Python MSS

mss is a cross-platform screenshots module for python that supports multiple monitor setups. The mss module also has a bundle command line version of mss for taking screenshots Installing mss # Install mss module globally pip install mss # Install mss in a virtualenv with pipenvn mkdir mss-test cd mss-test pipenv install mss pipenv shell Use mss from the command line $ mss # Output C:\Dev\playground\winscreencap\monitor-1.png Call mss cli as a python modulee $ python -m mss # Output C:\Dev\playground\winscreencap\monitor-1. Read More →

validate phone numbers in python

If you need to validate phone numbers in python the phonenumbers module is a great library Installation Instructions pip install phonenumbers Example import phonenumbers x = phonenumbers.parse("+442083661177", None) print(x) type(x) y = phonenumbers.parse("020 8366 1177", "GB") print(y) print(x == y) # as dialed from GB, not a GB number z = phonenumbers.parse("00 1 650 253 2222", "GB") print(z) z = phonenumbers.parse("+120012301", None) phonenumbers.is_valid_number(z) # output Country Code: 44 National Number: 2083661177 Country Code: 44 National Number: 2083661177 True Country Code: 1 National Number: 6502532222 False As you type phone number validation Read More →

get a random item from a python list

import random # Define a new list using [] square brackets. fruits = ['banana', 'apple', 'orange', 'lemon', 'lime', 'strawberry', 'kiwi', 'peach', 'grape', 'pineapple', 'mango'] # Randomly select an item from a list print('=== Get a random item ===') print(random.choice(fruits)) # output run 1 === Get a random item === lime # output run 2 === Get a random item === pineapple # output run 3 === Get a random item === kiwi Read More →

iterate over a list with access to index and value

# Define a new list using [] square brackets. fruits = ['banana', 'apple', 'orange', 'lemon', 'lime', 'strawberry', 'kiwi', 'peach', 'grape', 'pineapple', 'mango'] # iterate over a list with access to index and value print('=== Iterate and print index and value of items in a list ===') for key, val in enumerate(fruits): print(key, ":", val) # output === Iterate and print index and value of items in a list === 0 : banana 1 : apple 2 : orange 3 : lemon 4 : lime 5 : strawberry 6 : kiwi 7 : peach 8 : grape 9 : pineapple 10 : mango Read More →

itertools permutations example

Perumatation can be done for strings and list also, below is the example.. import itertools x = [1, 2, 3, 4, 5, 6] # output all permutations of x print(list(itertools.permutations(x, 2))) # output [(1, 2), (1, 3), (1, 4), (1, 5), (1, 6), (2, 1), (2, 3), (2, 4), (2, 5), (2, 6), (3, 1), (3, 2), (3, 4), (3, 5), (3, 6), (4, 1), (4, 2), (4, 3), (4, 5), (4, 6), (5, 1), (5, 2), (5, 3), (5, 4), (5, 6), (6, 1), (6, 2), (6, 3), (6, 4), (6, 5)] Reference itertools docs on python. Read More →

conda upgrade all packages

conda is an alternative package management tool bundled with the Anaconda python distribution. In some ways conda is a replacement for pip. Here is how you upgrade all conda installed python packages with one command. Read More →