473,598 Members | 3,409 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

iteration over non-sequence ,how can I resolve it?

at line "for j in linkReturned:" , raise an error:
File "C:\pythonProgr am\test.py", line 308, in main
for j in linkReturned:
TypeError: iteration over non-sequence
how can I get a list from the return of thread.start() ?
below is the codes:

class PrintThread(thr eading.Thread):
def __init__(self, urlList):
threading.Threa d.__init__(self )
urllist=[]
self.urllist=ur lList
def run(self):
urllink=[]
......
return urllink
for i in range(0,2):
thread=PrintThr ead(links)
threadList.appe nd(thread)
linkReturned=[]
for i in threadList:
linkReturned=i. start()
for j in linkReturned:
links.append(j)

May 28 '06 #1
4 10890
On 28 May 2006 06:20:20 -0700, python <do***********@ hotmail.com> wrote:
at line "for j in linkReturned:" , raise an error:
File "C:\pythonProgr am\test.py", line 308, in main
for j in linkReturned:
TypeError: iteration over non-sequence
how can I get a list from the return of thread.start() ?
You can't. thread.start() always return None.
class PrintThread(thr eading.Thread):
def __init__(self, urlList):
threading.Threa d.__init__(self )
urllist=[]
self.urllist=ur lList
def run(self):
urllink=[]
......
return urllink
for i in range(0,2):
thread=PrintThr ead(links)
threadList.appe nd(thread)
linkReturned=[]
for i in threadList:
linkReturned=i. start()
for j in linkReturned:
links.append(j) From the looks of this code it seems like you want a sub-routine not a

thread. You can simulate returning a value from a thread by adding a
"return value" attribute to the PrintThread class that the run()
method writes to. Then you would have to add some form of
synchronizing so that your main program does not try to read the
"return value" of the thread before the thread actually has written
the "return value."

--
mvh Björn
May 28 '06 #2
To BJörn Lindqvist :
thank you . how to write the code specifically ?Could you give a
example?

May 28 '06 #3
To BJörn Lindqvist :
thank you . how to write the code specifically ?Could you give an
example?

May 28 '06 #4
python wrote:
To BJörn Lindqvist :
thank you . how to write the code specifically ?Could you give a
example?


Use Queue module:

import threading
from Queue import Queue

class PrintThread(thr eading.Thread):
def __init__(self, urlList, results_queue):
threading.Threa d.__init__(self )
urllist=[]
self.urllist=ur lList
self.results_qu eue = results_queue
def run(self):
urllink=[self.urllist] * 2
self.results_qu eue.put(urllink )

results = Queue()
threadList = []
for i in range(0,2):
thread=PrintThr ead("Thread"+st r(i), results)
threadList.appe nd(thread)
thread.start()

for i in threadList:
linkReturned = results.get()
for j in linkReturned:
print j

May 29 '06 #5

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

Similar topics

35
3722
by: Raymond Hettinger | last post by:
Here is a discussion draft of a potential PEP. The ideas grew out of the discussion on pep-284. Comments are invited. Dart throwing is optional. Raymond Hettinger ------------------------------------------------------------- PEP: 323
59
4285
by: Raymond Hettinger | last post by:
Please comment on the new PEP for reverse iteration methods. Basically, the idea looks like this: for i in xrange(10).iter_backwards(): # 9,8,7,6,5,4,3,2,1,0 <do something with i> The HTML version is much more readable than the ReST version. See: http://www.python.org/peps/pep-0322.html
31
2970
by: Raymond Hettinger | last post by:
Based on your extensive feedback, PEP 322 has been completely revised. The response was strongly positive, but almost everyone preferred having a function instead of multiple object methods. The updated proposal is at: www.python.org/peps/pep-0322.html In a nutshell, it proposes a builtin function that greatly simplifies reverse iteration. The core concept is that clarity comes from specifying a sequence in a forward direction and...
2
2072
by: Abdullah Khaidar | last post by:
Is there any iteration style we must use to get faster processing time? I've tried with some style to concat number in list. But I still don't know which one is the recommended style. >>> def useListIteration(): list = result = "" for item in list: result += item return result
3
5179
by: Bryant Huang | last post by:
Hi, Is it possible to perform iteration within the re.sub() function call? For example, if I have a string like: str = "abbababbabbaaa" and I want to replace all b's with an integer that increments from 0, could I do that with re.sub()?
3
11542
by: Tjerk Wolterink | last post by:
Hello, I want to create m elements in this form: <element index="n"/> Where n = 1 2 .. m Can is do this with an xsl:for loop?? And if so how
20
1393
by: Crirus | last post by:
I have a 20x16 array of objects. I need a way to iterate through the array and only consider few rows and few columns. To be clearer, sometimes I need only first 2 rows and last 3 columns to be considered in loop Another time, I whould need only first 3 columns and last 4 rows to be considered... Anyhow, I will not have separate rows or columns in the same iteration...
28
7366
by: robert | last post by:
In very rare cases a program crashes (hard to reproduce) : * several threads work on an object tree with dict's etc. in it. Items are added, deleted, iteration over .keys() ... ). The threads are "good" in such terms, that this core data structure is changed only by atomic operations, so that the data structure is always consistent regarding the application. Only the change-operations on the dicts and lists itself seem to cause problems...
75
5593
by: Sathyaish | last post by:
Can every problem that has an iterative solution also be expressed in terms of a recursive solution? I tried one example, and am in the process of trying out more examples, increasing their complexity as I go. Here's a simple one I tried out: #include<stdio.h> /* To compare the the time and space cost of iteration against
23
3898
by: anon.asdf | last post by:
Hello! In the following code-snippet, is it possible to initialize each element of arr, with STRUCT_INIT? struct mystruct { int a; char b; };
0
7991
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8395
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...
0
8398
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8265
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...
0
6719
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5438
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
3939
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2412
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
1
1504
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.