Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: importing python modules  (Read 2712 times)

0 Members and 1 Guest are viewing this topic.

jhuns

  • Guest
importing python modules
« on: December 01, 2009, 12:29:06 PM »
I am just learning python (as of today), and I am having an issue with 'import'
I am writing two scripts inputGen.py and frequency.py:

Code: [Select]
# inputGen.py
import sys

def readInputWords():
    while 1:
        line = sys.stdin.readline()
        if line=='': return
        words = line[:-1].split()
        for word in words:
            yield word

for word in readInputWords():
  print word


Code: [Select]
# frequency.py
import inputGen

def countInputWords():
    for word in inputGen.readInputWords():
         # the rest of countInputWords()

countInputWords()

The problem is that the moment I import inputGen, the entire script is run.  Is there some way that I can use readInputWords() in frequency.py without running inputGen.py?