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 →

ValueError: Cannot specify ‘,’ with ’s’.

This error is raised when you pass a string to the format() function The format() function can be used to format a long number with commas >>> pop = 4534305483 >>> print(pop) 4534305483 >>> print(format(pop,",")) 4,534,305,483 The ValueError occurs when you attempt to pass a variable of type string to format(). >>> pop="4534305483" >>> type(pop) <class 'str'>>>> print(format(pop,","))Traceback (most recent call last):File "<stdin>", line 1, in <module>ValueError: Cannot specify ',' with 's'. 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 →

error: invalid command ‘egg_info’

This error is encountered when running pip install Distribute has been merged into Setuptools as of version 0.7. If you are using a version <=0.6, upgrade using pip install --upgrade setuptools or easy_install -U setuptools. Reference: https://stackoverflow.com/questions/11425106/python-pip-install-fails-invalid-command-egg-info Read More →

My First post!

This is my first post, how exciting! Lorem ipsum dolor sit amet, consectetur adipiscing elit. Read More →

About

pythonfix.com is a free knowledge resource provided to the python community. Our hope is to make you a better python developer. Our mission is to provide fast and concise answers to your python questions and quality python code examples. This website is design to be fritionless, fast, and ad-free. We will NEVER… Collect personal information about our visitors Use heavy weight analytics tracking Run intrustive ads or ad tracking Read More →