Re: I25 barcode generator?

Discussion in 'Python' started by Carsten Haese, Apr 27, 2007.

  1. On Thu, 26 Apr 2007 22:12:54 -0400, I wrote
    > On Thu, 26 Apr 2007 18:39:23 -0300, Gerardo Herzig wrote
    > > Hi. Im looking for an I25 barcode generator.[...]

    > [...]it shouldn't be too hard to make one.

    And it wasn't:

    def i25(x):
    """i25(x) -> string

    Encode string of digits into I25 barcode.

    The input string must consist of an even number of digits.
    The output string represents the I25 barcode of the input string
    with N = narrow bar, W = wide bar, n = narrow space, w = wide space.

    alphabet = (
    if not x.isdigit():
    raise ValueError, "Input string must consist of digits."
    if len(x)%2!=0:
    raise ValueError, "Input string must be of even length."

    bars = "".join(alphabet[int(c)] for c in x[0::2])
    spaces = "".join(alphabet[int(c)] for c in x[1::2]).lower()
    interleaved = "".join(t[0]+t[1] for t in zip(bars,spaces))
    return "NnNn"+interleaved+"WnN"

    Rendering the resulting string into the desired graphical format is left as an
    exercise for the reader.


    Carsten Haese, Apr 27, 2007
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gerardo Herzig

    I25 barcode generator?

    Gerardo Herzig, Apr 26, 2007, in forum: Python
    Gerardo Herzig
    Apr 26, 2007
  2. Carsten Haese

    Re: I25 barcode generator?

    Carsten Haese, Apr 27, 2007, in forum: Python
    Carsten Haese
    Apr 27, 2007

Share This Page