Naming conventions in a Python library

I'm implementing a search algorithm (let's call it MyAlg) in a python package. Since the algorithm is super-duper complicated, the package has to contain an auxiliary class for algorithm options. Currently I'm developing the entire package by myself (and I'm not a programmer), however I expect 1-2 programmers to join the project later. This would be my first project that will involve external programmers. Thus, in order to make their lifes easier, how should I name this class: Options, OptionsMyAlg, MyAlgOptions or anything else?

What would you suggest me to read in this topic except for ?

Thank you Yuri [cross posted from here: will update the answers in both places]

Asked by: Kellan494 | Posted: 28-01-2022

Answer 1

I suggest you read PEP8 (styleguide for Python code).

Answered by: Alford537 | Posted: 01-03-2022

Answer 2

Just naming it Options should be fine. The Python standard library generally takes the philosophy that namespaces make it easy and manageable for different packages to have identically named things. For example, open is both a builtin and a function in the os module, several different modules define an Error exception class, and so on.

This is why it's generally considered bad form to say from some_module import * since it makes it unclear to which open your code refers, etc.

Answered by: Nicole837 | Posted: 01-03-2022

Answer 3

If it all fits in one file, name the class Options. Then your users can write:

import myalg

searchOpts = myalg.Options()

mySearcher = myalg.SearchAlg(searchOpts)"where's waldo?")

Note the Python Style Guide referenced in another answer suggests that packages should be named with all lowercase letters.

Answered by: Sam343 | Posted: 01-03-2022

Similar questions

Library to Tidy Up Python Code using pep8 conventions

Is there any library that takes in your python file as input and does tidy-up (modifies it based on the PEP 8 conventions). To understand what I am talking about, a JavaScript analogy is as follows: Go to this link Press the button TidyUp Any online edito...

naming conventions - Python Notation?

I've just started using Python and I was thinking about which notation I should use. I've read the PEP 8 guide about notation for Python and I agree with most stuff there except function names (which I prefer in mixedCase style). In C++ I use a modified version of the Hungarian notation where I don't include information about type but ...

Newbie to python conventions, is my code on the right track?

I've been reading about python for a week now and just thought I'd try my hand at it by creating a tax bracket calculator. I'm not finished but I wanted to know if I'm on the right track or not as far as python programming goes. I've only done a little C++ programming before, and it feels like it shows (good/bad?) #There are six brackets define by the IRS as of 2009 #Schedule X - Single first_bracket = 83...

naming conventions - is it ever useful to define a class method with a reference to self not called 'self' in Python?

I'm teaching myself Python and I see the following in Dive into Python section 5.3: By convention, the first argument of any Python class method (the reference to the current instance) is called self. ...

python - Naming Conventions for Methods / Classes / Packages

What naming conventions do you use for everyday code? I'm pondering this because I currently have a project in Python that contains 3 packages, each with a unique purpose. Now, I've been putting general-purpose, 'utility' methods into the first package I created for the project, however I'm contemplating moving these methods to a separate package. The question is what would I call it? Utility, Collection, Assorted?

naming conventions - What should I name my global module in Python?

I'm writing an application in Python, and I've got a number of universal variables (such as the reference to the main window, the user settings, and the list of active items in the UI) which have to be accessible from all parts of the program1. I only just realized I've named the module and I'm importing the object which contains those variables with a from globals import globals

Python package name conventions

Is there a package naming convention for Python like Java's Most of the time I see simple, potentially colliding package names like "web". If there is no such convention, is there a reason for it? What do you think of using the Java naming convention in the Python world?

Are there conventions for Python module comments?

It is my understanding that a module docstring should just provide a general description of what a module does and details such as author and version should only be contained in the module's comments. However, I have seen the following in comments and docstrings: __author__ = "..." __version__ = "..." __date__ = "..." Where is the correct location to put items such...

naming conventions - Parameter names in Python functions that take single object or iterable

I have some functions in my code that accept either an object or an iterable of objects as input. I was taught to use meaningful names for everything, but I am not sure how to comply here. What should I call a parameter that can a sinlge object or an iterable of objects? I have come up with two ideas, but I don't like either of them: FooOrManyFoos - This expresses what goes on, but I could imagin...

Python - what's your conventions to declare your attributes in a class?

In Python, I can declare attributes all over the class. For example : class Foo: def __init__(self): self.a = 0 def foo(self): self.b = 0 It's difficult to retrieve all attributes in my class when I have a big class with a lot of attributes. Is it better to have the following code (a) or the next following code (b) : a) Here, it's difficult to loca...

is there a nice "python conventions and best practices" summary anywhere?

I am fairly new to python, and I generally code as a means to an end, as opposed to being a "coder". I like all the power that python contains through libraries, and I enjoy the inherent but invisible strength in python. (E.g., object-oriented, but still relatively scripter-friendly structure for making classes, etc.) But I keep running into cases where I cannot find complete documentation, and I find pointer...

Still can't find your answer? Check out these communities...

PySlackers | Full Stack Python | NHS Python | Pythonist Cafe | Hacker Earth | Discord Python