Python Packages « Python Conquers The Universe I’ve avoided putting my Python modules into packages. That’s because (like a lot of other folks) I don’t really understand how to create a package. And that’s because (probably like a lot of other folks) I’m too time-constrained and over-worked to be able to grok anything except a very short, clear, and simple explanation of how packages work… and I never found one. That’s all over now. In a post on comp.lang.python Steven D’Aprano has made it all beautifully clear. A package is a special arrangement of folder + modules. To be a package, there must be a file called __init__.py in the folder, e.g parrot/ +-- __init__.py +-- feeding/ +-- __init__.py +-- eating.py +-- drinking.py +-- fighting.py +-- flying.py +-- sleeping.py +-- talking.py This defines a package called parrot which includes a sub-package feeding and modules fighting, flying, sleeping and talking. without needing to manually import sub-packages. And to distribute a collection of modules as a package…. Thank you, Steven!
Creating a list of objects in Python Python: How to return something from a function that makes a dictionary python-iptools - Utilities for dealing with ip addresses A few useful functions and objects for manipulating ip addresses in python. This was all inspired by a desire to be able to use CIDR address notation to designate INTERNAL_IPS in a Django project's settings file. Functions: validate_ip: Validate a dotted quad ip address. ip2long: Convert a dotted quad ip address to a network byte order 32-bit integer. long2ip: Convert a network byte order 32-bit integer to a dotted quad ip address. validate_cidr: Validate a CIDR notation ip address. cidr2block: Convert a CIDR notation ip address into a tuple containing network block start and end addresses. Objects: IpRange: Range of ip addresses providing `in` and iteration. Using with Django The IpRangeList object can be used in a django settings file to allow CIDR notation and/or (start, end) ranges to be used in the INTERNAL_IPS list. Example: #! INTERNAL_IPS = iptools.IpRangeList( '127.0.0.1', # single ip '192.168/16', # CIDR network block ('10.0.0.1', '10.0.0.19'), # inclusive range) Installing or pip:
sort MAN Page Sort text files. Sort, merge, or compare all the lines from the files given (or standard input.) Syntax sort [options] [file...] sort --help sort --version Options sort has three modes of operation: Sort (the default), Merge (-m), and Check(-c) -c Check whether the given files are already sorted: if they are not all sorted, print an error message and exit with a status of 1. The following options affect the ordering of output lines. `-b' Ignore leading blanks when finding sort keys in each line. A pair of lines is compared as follows: if any key fields have been specified, `sort' compares each pair of fields, in the order specified on the command line, according to the associated ordering options, until a difference is found or no fields are left. If any of the global options `Mbdfinr' are given but no key fields are specified, `sort' compares the entire lines according to the global options. Upon any error, `sort' exits with a status of `2'. Examples "We never sit anything out.