national insurance number with python issue

mikedobingmikedobing Posts: 4
edited July 30, 2015 7:41AM in SQL Data Generator
Hi,

I've been following the instructions in the post below, but we're getting an error at data generation time. This doesn't occur when calling the module within the Python gui.

Any ideas why this script is failing? Python isn't my native dialect :-) We're using the "exrex.py" file from the links below. I can send it on if required.

Any help is greatly appreciated.

Error received - An error occured. Python error at line:160: TypeError:sequence item 0:expected bytes or byte array, str found
I got it working in SQL Data Generator 3!
First, install Python 2.7 x86 from http://www.python.org/download/
Then get setuptools for Python 2.7 https://pypi.python.org/pypi/setuptools
Then download setup.py from https://github.com/asciimoo/exrex
Install exrex from the command-line using python setup.py install
In your Python root folder (c:\python27) locate the lib subfolder
Edit exrex.py and locate the line
from re import sre_parse, U
Before this add the line import sre_parse and change the line to read from re import U

Reason this did not work for me, I suppose exrex was written for a different version of python before they moved sre_parse to its' own module.

Now you can use this code
CODE: SELECT ALL
# Basic generator template

def main(config):
import exrex
# config["column_name"] is the column name
# config["column_type"] is the column datatype
# config["column_size"] is the column size
# config["n_rows"] is the number of rows
# config["seed"] is the current random seed
return exrex.getone('^(?!BG|GB|NK|KN|TN|NT|ZZ)[ABCEGHJ-PRSTW-Z][ABCEGHJ-NPRSTW-Z]\d{6}[A-D]$')

Comments

  • Sergio RSergio R Rose Gold 2 Posts: 429 Rose Gold 2
    Hi,

    Thanks for your posting.

    I have tested this in our long and this error appears to occur when using some versions of Python but not others.

    Please try doing this using Python 2.7.6 x86 which we have found to work correctly.

    Thank you,
    Sergio
    Product Support Engineer
    Redgate Software Ltd
    Please see our Help Center for detailed guides on how to use our tools
Sign In or Register to comment.