Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: I25 barcode generator?

Reply
Thread Tools

Re: I25 barcode generator?

 
 
Carsten Haese
Guest
Posts: n/a
 
      04-27-2007
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 = (
"NNWWN", "WNNNW", "NWNNW", "WWNNN", "NNWNW",
"WNWNN", "NWWNN", "NNNWW", "WNNWN", "NWNWN"
)
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.

HTH,

Carsten.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Singapore Post 4-State Barcode Support & Postnet Barcode Recognition sherazam Java 0 05-24-2012 09:55 AM
Read Barcode from Specific Area of Img & Create Fixed Size Barcode sherazam Java 0 03-01-2011 08:12 AM
Aztec 2D Barcode Recognition Support is Added in Aspose.BarCode sherazam Java 0 09-16-2010 10:44 AM
Re: I25 barcode generator? Carsten Haese Python 0 04-27-2007 02:12 AM
I25 barcode generator? Gerardo Herzig Python 0 04-26-2007 09:39 PM



Advertisments