KeyError: '13'

2012-06-06 Thread Phanindra Ramesh Challa
I am trying to run a python program. It is giving the KeyError: '13'. I
have no clue regarding this error.
 this is the python code relevant to the error:

dpi = 100
bold = 0
italic = 0
mono = 0
comment = 
dbname = font.db

for o, a in opts:
if o == '-b': bold = 1
if o == '-i': italic = 1
if o == '-m': mono = 1
if o == '-d': dpi = int (a)
if o == '-c': comment = string.join (string.split (a),  )
if o == '-g': dbname = a

fontname = args[0]
pixel_size = int (args[1])

point_size = int (pixel_size * 72.27 / dpi + 0.5)

# Approximate average glyph width.
avg_width = pixel_size * 17 / 24

db = anydbm.open (dbname, r)
codes = loads (db [str (pixel_size)])

And the error is :
python2 ../../../mk_bdf.py -c Converted from fonts of Computer Modern
family (C) 1979-1985 Donald E. Knuth and others. -b  'TeX Sans' 13 
tex09sb.bdf
Traceback (most recent call last):
  File ../../../mk_bdf.py, line 108, in module
codes = loads (db [str (pixel_size)])
  File /usr/lib/python2.7/bsddb/__init__.py, line 270, in __getitem__
return _DeadlockWrap(lambda: self.db[key])  # self.db[key]
  File /usr/lib/python2.7/bsddb/dbutils.py, line 68, in DeadlockWrap
return function(*_args, **_kwargs)
  File /usr/lib/python2.7/bsddb/__init__.py, line 270, in lambda
return _DeadlockWrap(lambda: self.db[key])  # self.db[key]
KeyError: '13'



 Anybody please help me in running the program.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: KeyError: '13'

2012-06-06 Thread Peter Otten
Phanindra Ramesh Challa wrote:

 I am trying to run a python program. It is giving the KeyError: '13'. I
 have no clue regarding this error.
  this is the python code relevant to the error:
 
 dpi = 100
 bold = 0
 italic = 0
 mono = 0
 comment = 
 dbname = font.db
 
 for o, a in opts:
 if o == '-b': bold = 1
 if o == '-i': italic = 1
 if o == '-m': mono = 1
 if o == '-d': dpi = int (a)
 if o == '-c': comment = string.join (string.split (a),  )
 if o == '-g': dbname = a
 
 fontname = args[0]
 pixel_size = int (args[1])

pixel_size is now 13
 
 point_size = int (pixel_size * 72.27 / dpi + 0.5)
 
 # Approximate average glyph width.
 avg_width = pixel_size * 17 / 24
 
 db = anydbm.open (dbname, r)

The above line opens a database (a Berkeley DB as the traceback reveals).

 codes = loads (db [str (pixel_size)])

str(pixel_size) converts 13 back to the string 13

db[some_key]

looks up the record with some_key, 13 in this case. There is no record 
with the key 13 in the font.db database, and therefore the script fails 
with the aptly named KeyError. (The database interface is modeled after 
Python's dictionary, so the handling is similar)
 
 And the error is :
 python2 ../../../mk_bdf.py -c Converted from fonts of Computer Modern
 family (C) 1979-1985 Donald E. Knuth and others. -b  'TeX Sans' 13 
 tex09sb.bdf
 Traceback (most recent call last):
   File ../../../mk_bdf.py, line 108, in module
 codes = loads (db [str (pixel_size)])
   File /usr/lib/python2.7/bsddb/__init__.py, line 270, in __getitem__
 return _DeadlockWrap(lambda: self.db[key])  # self.db[key]
   File /usr/lib/python2.7/bsddb/dbutils.py, line 68, in DeadlockWrap
 return function(*_args, **_kwargs)
   File /usr/lib/python2.7/bsddb/__init__.py, line 270, in lambda
 return _DeadlockWrap(lambda: self.db[key])  # self.db[key]
 KeyError: '13'

  Anybody please help me in running the program.

For now you can ignore the code in the traceback which may be a bit 
intimidating to a newbie. It contains lines from the implementation of the 
database interface. Instead have a look at the keys that are in the database 
with

db = anydb.open(font.db)
for key in db: 
print key

and then decide if you to need to change the lookup key or to add records to 
the database.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: KeyError: '13'

2012-06-06 Thread Peter Otten
Phanindra Ramesh Challa wrote:

[Please hit reply-all in you email client when you answer a post. That way 
it will appear on the mailing list and give more people a chance to answer]

 output of the is just the line
 sizes.

 and then decide if you to need to change the lookup key or to add records
 to the database.

 How can I add recors to the database?

The Python part of the answer is 

db[some_key] = some_value

but I fear that won't help. Google suggests you are struggling with the 
metatype project If so, there seems to be a corresponding mk_db.py that you 
can use. I don't know anything about metatype, but the comment in mk_db.py 
at 
http://metatype.cvs.sourceforge.net/viewvc/metatype/metatype/mk_db.py?revision=1.3view=markup

tells to run it like so:

find . -name '*.ugs' | python mk_db.py -a glyphlist -o dbmfile

Perhaps you ran it, but there weren't any *.ugs files?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: KeyError: '13'

2012-06-06 Thread Phanindra Ramesh Challa
I got metatype compiled. Thanks for your help

On Wed, Jun 6, 2012 at 6:44 PM, Peter Otten __pete...@web.de wrote:

 Phanindra Ramesh Challa wrote:

 [Please hit reply-all in you email client when you answer a post. That
 way
 it will appear on the mailing list and give more people a chance to answer]

  output of the is just the line
  sizes.

  and then decide if you to need to change the lookup key or to add
 records
  to the database.
 
  How can I add recors to the database?

 The Python part of the answer is

 db[some_key] = some_value

 but I fear that won't help. Google suggests you are struggling with the
 metatype project If so, there seems to be a corresponding mk_db.py that you
 can use. I don't know anything about metatype, but the comment in mk_db.py
 at

 http://metatype.cvs.sourceforge.net/viewvc/metatype/metatype/mk_db.py?revision=1.3view=markup

 tells to run it like so:

 find . -name '*.ugs' | python mk_db.py -a glyphlist -o dbmfile

 Perhaps you ran it, but there weren't any *.ugs files?

 --
 http://mail.python.org/mailman/listinfo/python-list

-- 
http://mail.python.org/mailman/listinfo/python-list