0

I have a two python files I am working with.

In cryp.py I have:

def test():
    test = raw_input("> ")

In cryptek.py I have:

import cryp
What is your name?
cryp.test
print "To be sure your name is: " + test

It errrs out as "test is not defined" How do I make it get the test variable from cryp.py?

SiHa
  • 7,830
  • 13
  • 34
  • 43

2 Answers2

0

(I have Python 3.6.1) So i solved it but not exactly as you asked. Hopefully this gives you a start:

cryptek:

from cryp import *
print("To be sure your name is: " + test)

cryp:

name = input ("> ")
def test():
    pass
test()

Works perfect. The issue is where the definitions come in.

Do you need this to work with definitions?

gmonz
  • 252
  • 1
  • 5
  • 17
  • 1
    I've tried that gmons, it still gives me "test isn't defined" I use import cryp already – TheCryptek Apr 12 '17 at 17:07
  • does these posts help at all? http://stackoverflow.com/questions/14573021/python-using-variables-from-another-file http://stackoverflow.com/questions/2349991/python-how-to-import-other-python-files http://stackoverflow.com/questions/17255737/importing-variables-from-another-file – gmonz Apr 12 '17 at 17:26
  • 1
    No it didn't actually. I looked at that before posting this question, as it is technically one of the rules. – TheCryptek Apr 12 '17 at 17:28
  • Got it. I am going to help you solve this, but it may take until the end of the day as I am at work right now. – gmonz Apr 12 '17 at 17:33
  • 1
    It usually takes a bit to solve issues when coding either way, so I usually take my time, no hurry :P – TheCryptek Apr 12 '17 at 17:33
  • gomz test needs to be input by the user test = raw_input("> ") – TheCryptek Apr 14 '17 at 03:16
  • @TheCryptek ever figure it out? – gmonz Apr 20 '17 at 01:04
0

There are multiple problems here. You added the import statement. The test() function needs to return something. If not, it will return None. Also, cryp.test is a function object, while cryp.test() is a call to the function.

The error message that is not in the question tells about this.

Traceback (most recent call last):
  File "cryptek.py", line 4, in <module>
    print "To be sure your name is: " + cryp.test()
TypeError: cannot concatenate 'str' and 'NoneType' objects

cryp.py

def test():
    test = raw_input("> ")
    return test

cryptek.py

import cryp
print "What is your name?"
cryp.test
print "To be sure your name is: " + cryp.test()

C:>python cryptek.py
What is your name?
> asdf
To be sure your name is: asdf
lit
  • 14,456
  • 10
  • 65
  • 119
  • After adding this, it is now prompting me with test = raw_input("> ") twice, meaning I have to enter a name twice before it continues on ._. – TheCryptek Apr 12 '17 at 17:30
  • That isn't my error... here is my error ` Traceback (most recent call last): File "cryptek.py", line 4, in print "\nTo be sure, your name is: " + name NameError: name 'name' is not defined ` – TheCryptek Apr 12 '17 at 17:32
  • @TheCryptek - Sorry, yes, you had that error message. The `cannot concatenate` message is the one you would get next, until `()` was added to `test` to make it a function call. – lit Apr 12 '17 at 17:35
  • I have it as cryp.test() – TheCryptek Apr 12 '17 at 17:37
  • I'm not worried about the cannot concatenate error, that I can fix easily, right now I'm trying to solve my current easy, pulling test from cryp.py – TheCryptek Apr 12 '17 at 17:37
  • I have, but then I get greeted by two prompts to enter a name, when you should only be asked once ._. run it to see what I'm talking about. – TheCryptek Apr 12 '17 at 17:41