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?

6
  • Have you tried import cryp? Commented Apr 12, 2017 at 17:06
  • Yes I already have import cryp at the top I'll be editing it in Commented Apr 12, 2017 at 17:07
  • Is test a reserved keyword in Python? Commented Apr 12, 2017 at 17:13
  • I am not sure, I also tried it with the word pizza to make sure, same issue Commented Apr 12, 2017 at 17:13
  • I believe test is a reserved keyword. Cannot guarantee this is correct though. BTW pizza is the best. Commented Apr 12, 2017 at 17:34

2 Answers 2

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
Sign up to request clarification or add additional context in comments.

6 Comments

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 ._.
That isn't my error... here is my error ` Traceback (most recent call last): File "cryptek.py", line 4, in <module> print "\nTo be sure, your name is: " + name NameError: name 'name' is not defined `
@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.
I have it as cryp.test()
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
|
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?

7 Comments

I've tried that gmons, it still gives me "test isn't defined" I use import cryp already
No it didn't actually. I looked at that before posting this question, as it is technically one of the rules.
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.
It usually takes a bit to solve issues when coding either way, so I usually take my time, no hurry :P
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.