Hi there.

I am trying write a module that can be executed at the command line and for some reason it's not working. Does anyone know why?

import sys

def fibonacci(N):
	a,b =0,1
	while b < N:
		a,b = b, a+b
		print b

N=sys.argv[1]

Does it matter that I'm running it on a windows command prompt?

Try this:
sys.argv[0]
or
sys.argv[-1]
that should work.

Thank you all very much! This worked for me:

import sys

N = int(sys.argv[1])

a,b =0,1
while b < N:
	a,b = b, a+b
	print b

I would prefer to call your nice, little code script, not module. Module I call code, which is imported to other Python code to call useful functions from it. Script is something traditional C coding like stdin to stdout input/output or using command arguments from invocation.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.