KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm brand new at python package management, and surely have done something wrong. I was encouraged to create a directory structure as follows: bagoftricks ├── bagoftricks │ ├── bagoftricks │ │ ├── __init__.py │ │ └── bagoftricks.py │ └── __init__.py ├── README.md └── setup.py bagoftricks.py contains two functions, levenshtein() and geofind() . I would like to call these as: import bagoftricks x = bagoftricks.levenshtein(arg1,arg2) Instead, I find I have to do this: import bagoftricks x = bagoftricks.bagoftricks.levenshtein(arg1,arg2) Is there a better way to organize my packages in the first place, without the naming redundancy? UPDATE So, I followed Avichal Badaya's instructions below, and removed one level of nesting. That is, I now have... bagoftricks ├── bagoftricks │ ├── __init__.py │ └── bagoftricks.py ├── README.md └── setup.py However, to call this package, I still have... from bagoftricks.bagoftricks import geofind() or import bagoftricks then >>> bagoftricks.bagoftricks.geofind() Rather than the desired.... from bagoftricks import geofind() or import bagoftricks >>> bagoftricks.geofind() I cannot remove that extra layer of nesting. When I try, by analogy, to remove one more level of nesting, so that my module is flat, as: bagoftricks ├── __init__.py ├── bagoftricks.py ├── README.md └── setup.py I cannot build the package at all... $ python setup.py build running build running build_py error: package directory 'bagoftricks' does not exist What's the secret for natural imports like
Tags (comma-separated)
Save Edits
Cancel