![]() |
Help with importing a module from a package I created. - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Help with importing a module from a package I created. (/thread-16725.html) |
Help with importing a module from a package I created. - FWendeburg - Mar-12-2019 Hi, I published a package in PyPI and I'm able to import it. The thing is that to use the functions that the package includes which are two functions, one called encrypt_text and another one called decrypt_text, I need to import them like this: from w_encryption.encrypt_text import * print(encrypt_text('Hello'))My question is: How do I change this so I'm able to import them like: from w_encryption import encrypt_textor importing like this: import w_encryptionIf I import the module in those two ways I get this error: Do I have to edit the __init__.py file? Now I have it like this:name = "w_encryption" from w_encryption import encrypt_text from w_encryption import decrypt_textOr do I have to edit the setup.py file outside the folder where the functions files are and where __init__.py is? setup.py: import setuptools with open("README.md", "r") as fh: long_description = fh.read() setuptools.setup( name="w_encryption", version="1.0.1", author="Francisco Wendeburg", author_email="[email protected]", description="w_ncryption is a Python library that can encrypt and decrypt text.", long_description=long_description, long_description_content_type="text/markdown", url="https://github.com/fwendeburg/w_encryption", packages=setuptools.find_packages(), classifiers=[ "Programming Language :: Python :: 3", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Topic :: Utilities", "Topic :: Security :: Cryptography", ], )Thanks in advance for your response. RE: Help with importing a module from a package I created. - snippsat - Mar-12-2019 (Mar-12-2019, 01:57 AM)FWendeburg Wrote: My question is: How do I change this so I'm able to import them like:Yes this is the way it should be done,never make a package that use * . Quote:Do I have to edit the __init__.py file? Now I have it like this:Look a this post,see how i lift the sub modules. look at the . that's needed for doing this.snippsat Wrote:
RE: Help with importing a module from a package I created. - FWendeburg - Mar-12-2019 (Mar-12-2019, 08:43 AM)snippsat Wrote:(Mar-12-2019, 01:57 AM)FWendeburg Wrote: My question is: How do I change this so I'm able to import them like:Yes this is the way it should be done,never make a package that use Thanks! It works now xd. |