Py Postcode

by admin

In the UK, postcodes are a crucial part of someone's address, as they narrow addresses down to the street of the desired location (in countries like France, however, a postcode only tells you which city or town the address is located). It can be handy to make sure your users provide a valid UK postcode in a form. To do this, we'll need to match the postcode to a regexp... but what is a valid UK postcode, and what regexp can we use to make sure a postcode is indeed valid ? Wikipedia tells us UK postcodes can use the following formats ('A' stands for any letter, and '9' for any digit):

  1. Phy Port Code
  2. Pe Postcode Tier
  • AA9A 9AA
  • A9A 9AA
  • A9 9AA
  • A99 9AA
  • AA9 9AA
  • AA99 9AA

To match any of these patterns, we can use the following regular expression: /^[a-zA-Z]{1,2}([0-9]{1,2} [0-9][a-zA-Z])s*[0-9][a-zA-Z]{2}$/ Let's decompose this so we know what it's doing:

PyPostcode consists of a single file (pyPostcode.py) that you can put in your python search path or in site-packages (or dist-packages depending on the platform) You can also simply run it by putting it in the same directory as you main script file or start a python interpreter in the same directory. PyPostcode works with Python 2.7.x and 3.5.x. This postcode has support for Ultrafast broadband at one or more premises. Ultrafast broadband is the latest high-speed standard, generally taken to mean fixed line broadband at a potential speed of 300Mbps or more - more than enough for even the most demanding household gaming, video calling, video and internet browsing needs.

  • We start by making sure our postcode isn't surrounded by anything else in our field, so we encase it between a beginning of input boundary (^) and an end of input boundary ($).
  • Then, we accept one or two letters [a-zA-Z]{1,2}
  • Followed by either one digit and a letter, or between one and two digits: ([0-9]{1,2} [0-9][a-zA-Z])
  • An optional space s*
  • Finally, a digit followed by two letters: [0-9][a-zA-Z]{2}

What have I missed? Is there a better way to write this? How hard is it to get UK addresses from a postcode using an external API? Let me know !

Coordinates: 49°27′58″N2°32′46″W / 49.466°N 2.546°W

  • In this tutorial, we will learn how to do both with the help of GeoPy library in Python. GeoPy is a Python client that provides several popular geocoding web services, it makes it easy for Python developers to locate the coordinates of an address, a city, or a country and vice-versa. To get started, let's install it.
  • A library that provides a Python interface to the postcodesio API. 0.0.4 fixed packaging issues for python 2; 0.0.3 added suport for python 2.
Coordinates: 49°27′58″N2°32′46″W / 49.466°N 2.546°W
CountryUnited Kingdom
Postcode area
Postcode area name
Guernsey
Post towns1
Postcode districts10
Postcode sectors16
Postcodes (live)3,344
Postcodes (total)3,374
Statistics as at May 2020[1]

The GY postcode area, also known as Guernsey postcode area,[2] its post town, is a group of 10 consecutive postal districts covering Guernsey, Alderney, Sark, Herm and the two inhabited lesser islets in that region of the Channel Islands. It was established in 1993 as an extension of the United Kingdom postcode system.[3]

Coverage[edit]

Postcode

The approximate coverage of the postal districts. The post town is GUERNSEY for all postcode districts

Postcode districtSector(s)Unit codesParish or island
GY11, 2, 3, 4, 6, 7Saint Peter Port
3HRHerm in the above parish[4]
4ABJethou in the above parish[4]
GY2allSaint Sampson
GY3allVale
GY4allSaint Martin
GY5allCastel
GY68AA – QZVale
RA – ZZSaint Andrew
GY79Saint Pierre du Bois
Saint Saviour
GY80AA – JZForest
KA – ZZTorteval
GY93Alderney
GY101Sark
Py PostcodePostcode

Phy Port Code

In March 2009, Royal Mail had 'agreed in principle' for the creation of the last district that would cover all addresses on the island of Alderney, to reduce confusion with those of smaller Sark to be left in GY9.[5] The States of Alderney opposed that way round,[6] and Sark changed from sector GY9 0 to acquire coding of GY10 1 on 5 January 2011.

See also[edit]

References[edit]

  1. ^'ONS Postcode Directory Version Notes'(ZIP). National Statistics Postcode Products. Office for National Statistics. May 2020. Table 2. Retrieved 19 June 2020.
  2. ^Royal Mail, Address Management Guide, (2004)
  3. ^Written Answer [87341], House of Commons Hansard, London, 17 December 2002, column 739W.
  4. ^ abhttp://www.guernseypost.com/postcode_finder – GY1 3HR
  5. ^Island FM (3 March 2009). 'Alderney postcodes could soon change to GY10'. Guernsey Insight. Jersey: Wave Telecom. Archived from the original on 11 July 2011. Retrieved 20 January 2010.
  6. ^States of Alderney (27 April 2009 (signed)). 'Minute 22/2009 Any other business: 22.1 Change of postcode for Alderney'. Minutes of Policy and Finance Committee 23 March 2009. Alderney. Archived from the original on 26 September 2011. Retrieved 20 January 2010.Check date values in: date= (help)

External links[edit]

Pe Postcode Tier

Retrieved from 'https://en.wikipedia.org/w/index.php?title=GY_postcode_area&oldid=1000965974'