1.

Solve : importing python modules?

Answer»

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?



Discussion

No Comment Found