python - Can't import local module inside script, like I do in Django shell -



python - Can't import local module inside script, like I do in Django shell -

this error:

traceback (most recent phone call last): file "twitterstream.py", line 3, in <module> tweemo.models import twitterstream importerror: no module named tweemo.models

background:

in django have simple model looks so:

from django.db import models class twitterstream(models.model): text = models.charfield()

from within django shell can next without problems

>>> tweemo.models import twitterstream >>> tweet = twitterstream.objects.create(text = 'hello again') >>> tweet.text 'hello again'

because worked in django shell, thought insert line:

>>> tweemo.models import twitterstream

into regular python script and, example, insert info twitterstream model (and mondo database) form within script.

basically, have script print out twitter live stream onto command line. itried modify including this

>>> tweemo.models import twitterstream

and changing this:

for line in response: print response

into this:

for line in response: tweet = str(tweet) + str(" ") + str(count) tweet = twitterstream.objects.create(text = line.strip()) count += 1

fyi: models.py containing twitterstream class within app 'tweemo' within project, called 'twitter'. python script want send live stream mymongo db with, in same folder models.py file -the tweemo app folder.

i'm new django/mongo imight way off here..

thanks in advance

python automatically check modules in same directory input script, can write

from models import twitterstream

this behaviour different when in django shell, django appends project root path sys.path, python uses when searching modules.

python django mongodb pymongo

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -