How to avoid repetitive naming in python packages?

Private

Say I am building a python project that models bananas, how would I structure it? I usually start with

mkdir bananas

then I code in bananas.py which is file until I start adding README, LICENSE, CONTRIBUTORS, and more and the python files are just lost in meta files. Then I do the same again

mkdir bananas
mv *.py* bananas

in order to have the actual code separated from the meta. Now I have a double, repetitive dir structure,

$ ls /path/to/bananas
README
LICENSE
CONTRIBUTORS
bananas/banana.py

So this ends up in

bananas/bananas/banana.py

This just feels wrong to me. The code I touch most is hidden away too far. Also I hate imports like

from bananas.bananas import Banana

I just want to do

from bananas import Banana

Any thoughts? What am I missing? I quote HGP:

Repetitive paths are confusing for both your tools and your developers. Unnecessary nesting doesn’t help anybody (unless they’re nostalgic for monolithic SVN repos).

Harper04

Sometimes this is unavoidable. Just look at the datetime module of the standard lib.

datetime.datetime datetime.datetime.today().date()

You can do relative imports. A file in bananas only has to do

from bananas import Banana  # or
from .bananas import Banana

Which is recommended anyway to make your module reusable by making it movable m)

Some folks import the module, not the class

from bananas import bananas as bananaModule
bananaModule.banana()

You could also give your project a fancy codename so it becomes:

from fancyish.bananas import bananas as bananaModule

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Avoid repetitive answer in python

From Dev

Avoid repetitive answer in python

From Dev

How to avoid repetitive XAML?

From Dev

How to avoid repetitive codes in cypress

From Dev

How to avoid repetitive JUnit tests

From Dev

How to avoid repetitive code in HTML?

From Dev

How to avoid repetitive codes in cypress

From Dev

How to avoid repetitive JUnit tests

From Dev

How to avoid naming unused variables from method return statement in python

From Dev

How to avoid naming unused variables from method return statement in python

From Java

How to avoid repetitive long generic constraints in Rust

From Java

How to avoid reinstalling packages when building Docker image for Python projects?

From Dev

Are there rules for naming single-module Python packages?

From Dev

if-not one-liners to avoid repetitive blocks, a matter of python style

From Dev

Should protected methods be unit-tested? How to avoid repetitive testing?

From Dev

How can I avoid the repetitive function call in Haskell

From Dev

How to avoid repetitive CASE statements in SQL WHILE loop doing INSERT

From Dev

How do I avoid repetitive code in this event handler?

From Dev

How to avoid multiple node processes doing repetitive things?

From Dev

Loop to avoid repetitive code

From Dev

Loop to avoid repetitive code

From Dev

Avoid repetitive xml code

From Dev

How to avoid unlist() modification of list naming

From Dev

How to avoid unlist() modification of list naming

From Dev

How to simplify repetitive list comprehensions in python?

From Java

Avoid repetitive values for @Secured annotation

From Dev

How to avoid new packages on dist-upgrade?

From Dev

Naming convention for packages and projects

From Dev

Naming convention for packages and projects

Related Related

  1. 1

    Avoid repetitive answer in python

  2. 2

    Avoid repetitive answer in python

  3. 3

    How to avoid repetitive XAML?

  4. 4

    How to avoid repetitive codes in cypress

  5. 5

    How to avoid repetitive JUnit tests

  6. 6

    How to avoid repetitive code in HTML?

  7. 7

    How to avoid repetitive codes in cypress

  8. 8

    How to avoid repetitive JUnit tests

  9. 9

    How to avoid naming unused variables from method return statement in python

  10. 10

    How to avoid naming unused variables from method return statement in python

  11. 11

    How to avoid repetitive long generic constraints in Rust

  12. 12

    How to avoid reinstalling packages when building Docker image for Python projects?

  13. 13

    Are there rules for naming single-module Python packages?

  14. 14

    if-not one-liners to avoid repetitive blocks, a matter of python style

  15. 15

    Should protected methods be unit-tested? How to avoid repetitive testing?

  16. 16

    How can I avoid the repetitive function call in Haskell

  17. 17

    How to avoid repetitive CASE statements in SQL WHILE loop doing INSERT

  18. 18

    How do I avoid repetitive code in this event handler?

  19. 19

    How to avoid multiple node processes doing repetitive things?

  20. 20

    Loop to avoid repetitive code

  21. 21

    Loop to avoid repetitive code

  22. 22

    Avoid repetitive xml code

  23. 23

    How to avoid unlist() modification of list naming

  24. 24

    How to avoid unlist() modification of list naming

  25. 25

    How to simplify repetitive list comprehensions in python?

  26. 26

    Avoid repetitive values for @Secured annotation

  27. 27

    How to avoid new packages on dist-upgrade?

  28. 28

    Naming convention for packages and projects

  29. 29

    Naming convention for packages and projects

HotTag

Archive