Importing functions that require parameters

Matt_D matt.deboard at gmail.com
Mon Dec 10 08:34:20 EST 2007


On Dec 10, 2:46 pm, John Machin <sjmac... at lexicon.net> wrote:
> "requires a parameter from elsewhere in the imported module" is a
> concept I don't understand.
>
> Here is what I think that you need to do in your main script:
>
> import sys
> import otp_encrypt
> the_key = opt_encrypt.get_key(sys.argv[1])
>
> If that isn't what you want, you'll need to explain the sentence that
> starts "Now I understand", with examples of what you have tried.

When I try:

from otp_encrypt import get_key

I get:

-----------------------------------------------
IndexError                                Trace

C:\WINDOWS\system32\<ipython console> in <modul

Q:\python\my pys\otp_encrypt.py in <module>()
     62         cipher += letter
     63     return cipher
     64
---> 65 print final(sys.argv[1])
     66

IndexError: list index out of range

In [13]: from otp_encrypt import get_key()

I know why I'm getting the error -- I'm importing a function from a
module in iPython with a sys.argv parameter. No big mystery there.

> BTW, how is the uppercase function different from string.upper, and
> why aren't you using string methods e.g. otp = otp.upper()
> ?

To be honest, I think I tried it once, but probably left off the ().
When I got an error I more than likely changed it to string.upper(otp)
and since it worked I didn't worry about it. This is like the second
full script I've actually finished so I'm trying to get all my
functionality in first before I start optimizing the script. While I'm
sure things like this are obvious to you, I've only been coding for a
week so any questions like, "Why did you do x when y is much better?"
can probably be answered with, "Stupid newb."

Thanks again.



More information about the Python-list mailing list