Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cannot find reference
#1
Hello,
I have imported the module named 'module' and I am trying to use the members in another file, I have installed packages as well, why do I still get 'Cannot find reference'? I will get correct output though.

from module import add as a, name as name, death as death, product as p
print(name)
print(death)
a(10, 20)
print("the product of num is",p(10, 20))

When googled, it says, it is a bug in Pycharm. Thank you.
Reply
#2
Is module in your module search path?
Reply
#3
It is in the same location. I am getting output as well. But I see red underscropes, when hovered over, it says, cannot find reference. I googled it, it says a bug in Pycharm. Thank you so much for trying to help me.
Reply
#4
Is the module named "module.py"? And what are you doing naming something "module"?
Reply
#5
The module name is module.py itself. name and and everything are members of module.py
Reply
#6
I need to look a the post more carefully. The problem is that you cannot do from module import add as a. You can import module as a and you can do from module import a, but you cannot do both. You are only allowed to rename namespaces, not items in the namespace.
Reply
#7
Various possibilities of import:
import module1
import module1, module2, module3
import module1 as m1
import module1 as m1, module2 as m2, module3 as m3
from module1 import member1
from module1 import member1, member2, member3
from module1 import *
from module1 import member1 as m1
from module1 import member1 as m1, member2 as m2, member3 as m3
Reply
#8
I was wrong. You can rename things that you import. This works fine for me:
from module import x as b, y as c
print(b)
There is no reason to do from module import name as name as it does exactly the same thing as from module import name

What was the error? The entire error message.
Reply
#9
'''module'''
name = "suman"
death = "not yet"
def add(x, y):
    print("The sum of two numbers is",x + y)

def product(x, y):
    return x * y
This file is my main file
'''test.py'''
'''member aliasing'''
from module import add as a, name as name, death as death, product as p
print(name)
print(death)
a(10, 20)
print("the product of num is",p(10, 20))
Reply
#10
Don't try to import and name chance all at once,all can be access from module.
>>> import module

>>> module.name
'suman'
>>> module.death
'not yet'

>>> module.add(10, 20)
The sum of two numbers is 30
>>> module.product(5, 5)
25
Alternative.
>>> from module import name, death, add, product

>>> name
'suman'

>>> add(4, 9)
The sum of two numbers is 13
If think product is to long to write.
>>> from module import product as pr

>>> pr(5, 8)
40
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Pass by object reference when does it behave like pass by value or reference? mczarnek 2 2,513 Sep-07-2020, 08:02 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020