简体   繁体   中英

Python module “filename” has no attribute “variable”?

I have a file o.py in which I am importing v.py

**o.py**   **v.py**

import v    `lr=2`
t=v.lr

Inside v.py i am storing some values inside a variable lr but when I am running o.py attribute error is coming that module v has no attribute lr even though I have used lr variable inside v.py. help?

I have tested the code and it should work.

Please ensure that the v.py only contains

lr=2

and not

`lr=2`

Also please ensure that o.py and v.py are in the same directory.

Please also give more attention to your variable and file naming. Understanding one letter variables and file names is difficult. Take the time to name your variables and file names properly to improve maintainability.

Here is some reading material on naming: https://techietweak.wordpress.com/2018/03/10/naming-conventions-from-uncle-bobs-clean-code-philosophy/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM