[FIXED] Can't make my python package print output

Issue

I recently created and published my own hello_world package for learning purposes, since I'm new to this I am having some issue getting the hello_world output. The link of the repo is:

https://github.com/fanik041/fsa_hello_world_package

In the cli.py file I wrote two functions for hello_world:

from __future__ import print_function

def hello():
    """ Returns a Hello, World! """
    return("Hello, World!")


def say_hello():
    """Prints Hello, World again! """
    print(hello())

But when I try to call the function hello() or say_hello() (after installing the package) the IDE can't find the functions. I tried calling it using:

from fsa_test import print_function

print_function.say_hello()

Can anyone help me out with this?


Solution

You have to import the file that contains the functions.

import fsa_test import cli

cli.say_hello()
cli.hello()

There are ways you can import those functions into the root of the package so they are more readily available.

BTW, from __future__ import print_function is only necessary if you are running Python 2.



Answered By - Tim Roberts
Answer Checked By - David Goodson (Python.Easybugfix Volunteer)

Related Posts

Post a Comment