How to make visible functions at package level in python?

Posted on 2009-04-23
Last Modified: 2012-05-06
I have package that contains several modules. I would like to expose some functions from a module to the package level.

How to do that?

package that contains function

So ...
# example

import package


# here the function definition is in the

# how to avoid this:

import package.module


Open in new window

Question by:koleto115
    LVL 39

    Expert Comment

    by:Roger Baklund
    Use this syntax:

    from package import function

    ... or:

    from package.module import function

    Author Comment

    I want to keep the package name as a root name and to expose the function defined in the module at package level. What I need is suppose the package name is effects and it contain module and the function delay() is defined inside the module so I need to do this:

    import effects



    import effects.echo

    I would like to keep the root name of the package.

    LVL 39

    Accepted Solution

    Within effects/, do:

    from echo import delay

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    Sequence is something that used to store data in it in very simple words. Let us just create a list first. To create a list first of all we need to give a name to our list which I have taken as “COURSE” followed by equals sign and finally enclosed …
    The purpose of this article is to demonstrate how we can use conditional statements using Python.
    Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
    Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now