0

i am learning python and tried to follow the course about logging but i can't use modules:

here's the module i want to import: helper.py

import logging
def helper():
    logging.info('hello from helper')

here is main file: logs.py

import logging
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
                datefmt='%m/%d/%Y %H:%M:%S')
import helper
helper.helper()

and here is what termianl says:

Traceback (most recent call last):
  File "c:\Users\DoggoBeatz\vsc projects\logs.py", line 10, in <module>
    helper.helper()
AttributeError: module 'helper' has no attribute 'helper'
Doggo
  • 1
  • 1
  • 1
    You haven't imported `helper` in `logs.py` – Kemp May 12 '21 at 11:15
  • this has nothing to do with `logging` and all with imports so why haven't You imported `helper` and maybe it has to do that the name of the module and function are the same – Matiiss May 12 '21 at 11:16
  • Please [edit] your question to expand it to a [mcve]. The code as shown would fail with a ``NameError``. – MisterMiyagi May 12 '21 at 11:17
  • Does this answer your question? [Importing installed package from script raises “AttributeError: module has no attribute” or “ImportError: cannot import name”](https://stackoverflow.com/questions/36250353/importing-installed-package-from-script-raises-attributeerror-module-has-no-at) – MisterMiyagi May 12 '21 at 11:19
  • i tried changing name of module and file, still the same error – Doggo May 12 '21 at 11:26
  • I cannot reproduce the issue with the code shown. Have you checked that ``c:\Users\DoggoBeatz\vsc projects\logs.py`` is the path you expect for ``logs``? Have you checked that ``import helper`` imports the code you expect (via a ``print`` in the module or inspecting ``helper.__file__``)? – MisterMiyagi May 12 '21 at 11:27
  • now i changed names of module and main file and terminal shows me: – Doggo May 12 '21 at 11:41
  • i tried running code in pycharm and everything works fine, i don't know why vcs shows error – Doggo May 12 '21 at 11:47
  • so to see exactly waht my problem is i created new module named importf.py in which i just did def FunctOne(): line below print('hello) than in main file i imported the module called importf.FunctOne() and in terminal i have same atributeError – Doggo May 12 '21 at 12:17

0 Answers0