title: How To read/iterate through a Datastream in Python
body: <p>I have a stream created at port 9999 of my computer.
       <a href="https://i.stack.imgur.com/OS4Xk.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OS4Xk.jpg" alt="enter image description here"></a></p>
  
  <p>I have to implement DGIM Algorithm on it.
  However I am not able to read the bits in the Data stream one by one.
  Below is my code:</p>
  
  <pre><code>from pyspark import SparkContext
  from pyspark.streaming import StreamingContext
  import math
  sc = SparkContext("local[2]", "NetworkWordCount")
  ssc = StreamingContext(sc, 1)
  </code></pre>
  
  <p>when I use the following command I am able to print the stream in batches:</p>
  
  <pre><code>lines.pprint()
  ssc.start()             # Start the computation
  ssc.awaitTermination()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/AThGA.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AThGA.jpg" alt="enter image description here"></a></p>
  
  <p>But when I try to print each bit it gives an error:</p>
  
  <pre><code>for l in lines.iter_lines():
     print l
  ssc.start()             # Start the computation
  ssc.awaitTermination()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/ukGMC.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ukGMC.jpg" alt="DataStream error"></a></p>
  
  <p><strong>Can someone tell me how can I read each bit from the stream so that I could 
   implement the algorithm on it?</strong></p>