473,977 Members | 2,471 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error message <exceptions.Typ eError unpack non-sequence>

Hello All,

I am trying to move an application from python 1.5.2 to 2.3. The code
works fine in 1.5.2 but gives the exception (exceptions.Typ eError
unpack non-sequence) in python 2.3. I did not write this code so I am
not sure what is happening here.

Here is the code snippet:

for (item, agent) in self.lItems:
lItems.append(i nterpolate(self ._ITEM_FMT, id=str(item)))

Note:
self.lItems contains two elements.

Questions:
1) What is the for statement doing?
2) Is this called tuple unpacking or list unpacking?
3) Is there newer syntax?
4) Why does he use the "for" loop like that?

Any help is appreciated.

Thanks
Ahsan
Jul 18 '05 #1
4 8061
I am trying to move an application from python 1.5.2 to 2.3. The code
works fine in 1.5.2 but gives the exception (exceptions.Typ eError
unpack non-sequence) in python 2.3. I did not write this code so I am
not sure what is happening here.

Here is the code snippet:

for (item, agent) in self.lItems:
lItems.append(i nterpolate(self ._ITEM_FMT, id=str(item)))

Note:
self.lItems contains two elements.
Always exactly 2 items?
Questions:
1) What is the for statement doing?
Attempting to assign the names item and agent a pair of values in
self.lItems
2) Is this called tuple unpacking or list unpacking?
list unpacking:
[item, agent] = [1,2]

tuple unpacking:
item, agent = 1,2
(item, agent) = 1,2
item, agent = (1,2)
(item, agent) = (1,2)

I would be willing to bet that the list below is cast into a tuple:
(item, agent) = [1,2]
3) Is there newer syntax?
I wouldn't so much call it newer as more intuitive.
for i,j in [(1,2), (3,4)]: .... print i, j
....
1 2
3 4

4) Why does he use the "for" loop like that?


Because he doesn't realize he could do the below.
item, agent = self.lItems
lItems.append(i nterpolate(self ._ITEM_FMT, id=str(item)))

- Josiah
Jul 18 '05 #2
Josiah Carlson <jc******@nospa m.uci.edu> wrote in message news:<bv******* ***@news.servic e.uci.edu>...
I am trying to move an application from python 1.5.2 to 2.3. The code
works fine in 1.5.2 but gives the exception (exceptions.Typ eError
unpack non-sequence) in python 2.3. I did not write this code so I am
not sure what is happening here.

Here is the code snippet:

for (item, agent) in self.lItems:
lItems.append(i nterpolate(self ._ITEM_FMT, id=str(item)))

Note:
self.lItems contains two elements.


Always exactly 2 items?

What if there are more than 2 items? How can I do something where
element 0 and 1 are assigned to (item, agent) and so on? If this is a
silly question please let me know what I can read.

Thanks
Ahsan
Jul 18 '05 #3

"ahsan Imam" <ah********@new times.com> wrote in message
news:78******** *************** ***@posting.goo gle.com...
Josiah Carlson <jc******@nospa m.uci.edu> wrote in message news:<bv******* ***@news.servic e.uci.edu>...
I am trying to move an application from python 1.5.2 to 2.3. The code
works fine in 1.5.2 but gives the exception (exceptions.Typ eError
unpack non-sequence) in python 2.3. I did not write this code so I am
not sure what is happening here.
I do not know of any change in Python that would make code like the below
invalid. Are you possibly running the program with different input data?
I suggest you insert 'print self.lItems' before the loop to see it *that*
changed (somewhere else in the program).

Here is the code snippet:

for (item, agent) in self.lItems:
lItems.append(i nterpolate(self ._ITEM_FMT, id=str(item)))


self.lItems must contain zero or more (item,agent) *pairs*
What if there are more than 2 items? How can I do something where
element 0 and 1 are assigned to (item, agent) and so on?


Yes and no. You would have to group elements 0 and 1 into a pair, elements
2 and 3 into another (the second), and so on. There is probably something
in itertools that will do this. Otherwise, writing your own generator to
do so should be easy enough. Then write 'for (i,a) in grouper(s.l):' where
grouper is the pair generator.

Terry J. Reedy


Jul 18 '05 #4
> What if there are more than 2 items? How can I do something where
element 0 and 1 are assigned to (item, agent) and so on? If this is a
silly question please let me know what I can read.


If there ever was more than two items, that is, if it was a flat
sequence like this: [1,2,3,4,5,6], then the original for loop couldn't
have worked.

- Josiah
Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2474
by: Alex Vinokur | last post by:
------ foo.cpp ------ #include <vector> using namespace std; int main() { const vector<int> v1 (10); const vector<bool> v2 (10); &v1;
3
3901
by: L Mehl | last post by:
Can someone tell me where to find out what this Call Stack item means? Thank you for any help. Larry Mehl --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com).
4
3054
by: David Lozzi | last post by:
Howdy, I'm using a WYSIWYG editor called TinyMCE. When I edit some text and then save it back to my SQL server using a SQLCommand, all HTML characters are changed to HTML code, i.e. &gt;strong&lt; instead of <strong> and so on. Is this a problem with the editor or something else? Does .Net convert it? I had to disable page validate request because of the tags, is there more? Thanks,
20
2110
by: elderic | last post by:
Hi there, are there other ways than the ones below to check for <type 'function'> in a python script? (partly inspired by wrapping Tkinter :P) def f(): print "This is f(). Godspeed!" 1.: --sort of clumsy and discouraged by the docs as far as I read
7
5113
by: mark | last post by:
Hi All, Apologies for the newbie question but I've searched and tried all sorts for a few days and I'm pulling my hair out ; Please feel free to teach me to suck eggs because it's all new to me :) Thanks in advance, Mark.
1
3174
by: sweetpotatop | last post by:
Hi, I got an pop-up error when I tried to run my window application. However, I have no idea which line of code is causing the problem. Is there a way to figurate that out? In VB, when I do <CTRL+ <BREAK, it will jump to the line where the error occurs, is there a similar feature in C#? Please help. Your suggestion would be greatly appreciated.
11
9426
by: Wojciech Gryc | last post by:
Hi, I recently started using Python and am extremely happy with how productive it's made me, even as a new user. I'm hoping to continue using the language for my research, and have come across a bit of a stumbling block. I'm a seasoned Java programmer and quite a big fan of interfaces... i.e. The idea that if I make a number of distinct classes that implement interface X, I can pass them all as parameters to functions
0
870
by: Utku Altinkaya | last post by:
Hello, I am wrapping the reference container vector as document suggests. typedef std::vector<CUEEntity*EntityContainer; class_<CUEEntity>("Entity", init<CUEEntity*>()); class_<EntityContainer>("EntityContainer") .def(vector_indexing_suite<EntityContainer, true>() )
5
2954
by: Nike1984 | last post by:
I'm fairly new to Javascript and it's more of a guessing game for me... I'm trying to build an app for Google Maps and just had some issues recently. First off I just wanted to say that everything works fine in FF and IE. It's Chrome I'm having issues with. I understand that Chrome is still somewhat in beta stages, so some bugs might occur. However this seems like something I might have done. So... I used a code that I found on Econym as...
1
2547
by: iammilind | last post by:
In one of my code, I was using vector<> for certain class. In one of my struct, I have 'const' member data. However, vector<>::clear() throws compile error with that: =========================================== struct Test { const string Str; Test(const string str) : Str(str) {} }; struct TestWrapper
0
11823
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
11578
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10913
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8464
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7608
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
5158
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4732
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3763
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.