'Output is not showing in python

I am using python 3.7 on my window 10 and having problem with code. I have created a test.py file and running following code in that file :-

 person = {'name': 'Jemm', 'age': '23'}
 sentence = 'My name is ' + person['name'] + 'and i am' + person['age'] + 'years old.'

print(sentence)

and when i print import test then output is not showing blank(no output).

Edit: when i print hello world then output is showing.



Solution 1:[1]

>>> import test
>>> print(test)
<module 'test' from '/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/test/__init__.py'>

There is a test module in Python itself. Be sure you are running your module. You must be in the same directory as your file test.py to import your file instead of the Python one.

Update: Python uses a search path list mechanism for finding modules when importing. The "current working directory" is usually at the first place in this list (the empty string). See PYTHONPATH and sys.path.

You can add your own path(s) into PYTHONPATH (in shell/command line) or sys.path (in Python).

Solution 2:[2]

I guess the problem is that you didn't save the file after you did all the code in test.py, what happens if save it then run import test somewhere else, that's what i think

Also as Messa said, "There is a test module in Python itself. Be sure you are running your module. You must be in the same directory as your file test.py to import your file instead of the Python one." that's also useful information, have to be same directory as test.py (your file)

If you're not in the same directory, do:

__import__('whole filepath')

For it.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 U12-Forward