#๐Ÿ”’ What's wrong with the import Syntax?

29 messages ยท Page 1 of 1 (latest)

velvet trail
#

I'm a beginner at Python and am wracking my brain for this. Why is the import not working?
(Ran on Pydroid 3)

candid flaxBOT
#

@velvet trail

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

velvet trail
#

Already messed it up.

#

import hmd

#

I just want it to say program finished. Nothing else. But it says it can't find the module I made

manic shore
#

from . import hmd and save the file to the same folder as the module

velvet trail
#

Oop

#

Ok, that worked, but now it is printing the hmd.py def functions. Is that supposed to happen, or do I do something about that?

#

@manic shore ?

manic shore
velvet trail
#

def hmd(): print("Happy Mothers Day!") print("") print(" [][] [][]") print(" [][][][][][][]") print(" [][][][][][][]") print(" [][][][][]") print(" [][][]") print(" []") print("I'll make something for you! Food, Crafts, Whatever you want!") hmd()
Making something for my mom

humble skiff
velvet trail
#

Oh wait I just realized

#

No I'm not deleting it

humble skiff
#

is hmd something you created?

velvet trail
#

I just realized it has prints in it

#

Sorry, I'm a new coder

humble skiff
#

no worries, everybody started somewhere

velvet trail
#

Thanks for believing in me

humble skiff
#

I missed context so didn't realize you wrote hmd.py. There's also a Python module called hmd

#

!pip hmd

candid flaxBOT
#

Simple markdown language and processor for write and render document similar to man pages, from command line or from Python

Released on <t:1598793730:D>.

manic shore
#

btw, if there's a module that runs something when run independently, and shouldn't when imported, there's a check for it

# functions and stuff for when the module is imported


if __name__ == "__main__":
  # stuff that needs to run when the module is directly run
velvet trail
velvet trail
humble skiff
candid flaxBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.