IndentationError running python script
<p>Im very new to python and Im trying to run this script but keep getting indentation errors in this part:</p>

<pre><code>while (time.time()-self.time) &amp;lt; self.limit
</code></pre>

<p>I have tried to remove all indentation and then ree-indent in different ways but nothing seems to work. Does anyone have an idea? Im using Spyder to run this.</p>

<pre><code>start_time = time.time() #grabs the system time
keyword_list = ['twitter'] #track list

from pymongo import MongoClient
import json

class listener(StreamListener):

    def __init__(self, start_time, time_limit=60):

        self.time = start_time
        self.limit = time_limit

def on_data(self, data):

while (time.time()-self.time) &amp;lt; self.limit:
    try:

    client = MongoClient('localhost', 27017)
    db = client['twitter_db']
    collection = db['twitter_collection']
    tweet = json.loads(data)
    collection.insert(tweet)

    return True


    except BaseException, e:
    print 'failed ondata,', str(e)
    time.sleep(5)
    pass

exit()

def on_error(self, status):
print statuses
</code></pre>

<p>you need to fix your syntax for the while condition statement.</p>

<p>first, as several others have mentioned <code>&amp;lt</code> is not a python operator. nor do you want a semicolon after it. The proper syntax would be <code>while (time.time()-self.time) &lt; self.limit:</code></p>

<p>The semicolon is not specifically necessary in any python code ever. It finds use only occasionally in specific cases where it becomes easier to read if multiple statements are on one line. These statements should not however contain keywords like <code>while</code>, <code>if</code>, or <code>for</code> etc. For now (while you are learning python) I would recommend completely avoiding semicolons.</p>

<p>Lastly, (and this may have been stackOverflow not formatting correctly) your functions <code>on_data</code>, and <code>on_error</code> have improper indentation. It is good practice in python 2.7 and mandatory in 3.x to not mix tabs and spaces (really just use spaces) as for indentation rules, see <a href="https://www.python.org/dev/peps/pep-0008/" rel="nofollow">the official style guide</a> or <a href="https://en.wikipedia.org/wiki/Python_syntax_and_semantics#Indentation" rel="nofollow">wikipedia's explanation</a></p>

python