[Tutor] error message
Steven Buck
sbuck at are.berkeley.edu
Wed Jul 8 18:13:31 CEST 2009
I'm running a for loop which returns an error message after the third
iteration (see out[4] at the bottom as evidence). I don't understand the
error message. Although I'll continue to do my own digging to debug, I
thought I'd give you all a shot. Thanks, -steve
Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)]
Type "copyright", "credits" or "license" for more information.
IPython 0.9.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.
In [1]: import psid
In [2]: age = {}
In [3]: for i in range(len(psid.psid)):
...: age[(i)] = psid.psid[i][20]
...:
...:
---------------------------------------------------------------------------
error Traceback (most recent call last)
C:\Documents and Settings\Steve\<ipython console> in <module>()
C:\Python26\lib\site-packages\StataTools.pyc in __getitem__(self, k)
85 if self._file.tell() != loc:
86 self._file.seek(loc)
---> 87 return self._next()
88
89 ### PyDTA private methods
C:\Python26\lib\site-packages\StataTools.pyc in _next(self)
167 else:
168 data[i] = self._unpack(typlist[i],
self._file.read(s
elf._col_size(i)))
169 return data
170 else:
--> 171 return map(lambda i: self._unpack(typlist[i],
self._file.rea
d(self._col_size(i))), range(self._header['nvar']))
C:\Python26\lib\site-packages\StataTools.pyc in <lambda>(i)
167 else:
168 data[i] = self._unpack(typlist[i],
self._file.read(s
elf._col_size(i)))
169 return data
170 else:
--> 171 return map(lambda i: self._unpack(typlist[i],
self._file.rea
d(self._col_size(i))), range(self._header['nvar']))
C:\Python26\lib\site-packages\StataTools.pyc in _unpack(self, fmt, byt)
148
149 def _unpack(self, fmt, byt):
--> 150 d = unpack(self._header['byteorder']+fmt, byt)[0]
151 if fmt[-1] in self.MISSING_VALUES:
152 nmin, nmax = self.MISSING_VALUES[fmt[-1]]
error: unpack requires a string argument of length 1
In [4]: age
Out[4]: {0: 22, 1: 51, 2: 42}
In [5]:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090708/e752e17f/attachment.htm>
More information about the Tutor
mailing list