Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
1 vote
2 answers
1k views

Ordering keyword arguments in a function call

In some languages such as Python, the order of keyword arguments in function calls does not matter. But is there a best practice for it? For instance, suppose that a function's signature is def foo(...
Scarabee's user avatar
  • 121
0 votes
1 answer
2k views

Dynamic Variables from JSON Parameter File

I want to assign Python variables imported from a JSON file. This question had an interesting answer using a classmethod, but I couldn't get it to work and I'm not allowed to comment... So, let's ...
Liz Livingston's user avatar
0 votes
5 answers
284 views

Should I "modularize" my configuration file into different files?

I have a simulation in Python which reads its configuration from a toml file. Since I have tons of parameters, the toml file can grow quite large. This is an example file, similar in structure to my ...
jfaccioni's user avatar
  • 516
3 votes
3 answers
2k views

Using python context managers instead of passing arguments: Is it an anti pattern?

We have an input flag in our API which indicates whether we should keep the mid level resources involved in fulfilling current request or not. I've decided to use some context managers at interface ...
Mehraban's user avatar
  • 269
1 vote
1 answer
2k views

Design Patterns for Passing Large Quantity of Parameters in Machine Learning

I am looking to better understand best practices for handling large quantity of parameters. I am particularly interested in the types of parameters involved in machine learning code bases and ...
sccrthlt's user avatar
  • 127
3 votes
2 answers
622 views

Best practices for testing settings file with many parameters in simulation code

I'm conflicted as to what is the best way to approach this problem. I am writing a simulation in Python, which is parametrized by ~ 50 parameters. I have a JSON file where these parameters are set, ...
jfaccioni's user avatar
  • 516
-2 votes
1 answer
92 views

method taking a class parameter

I have recently begun studying UML. All is going fine so far until I saw the following: This is a class Called Point2D It has 2 attributes which are x, type float and y, type float. It has 3 methods ...
CCG's user avatar
  • 193
2 votes
1 answer
1k views

Should callbacks be called with named or positional arguments?

The question is asked in the context of Python, but it is also relevant for any languages with named parameters support. If some entity in my code (e.g. a pubsub implementation) or even a simple ...
interphx's user avatar
  • 123
1 vote
1 answer
950 views

How to document **kwargs in python? [closed]

I have a function which has a large number of arguments. I want to have the names of the arguments available in the help() function, but I want the results as a dict. At the moment, I have the ...
AMADANON Inc.'s user avatar
8 votes
2 answers
4k views

How to handle singular and plural parameters for functions

Often when I'm writing a set of utility functions, I find myself wanting a function that applies some logic to multiple items, as well as a function that does the same with just a single item. There ...
JStaab's user avatar
  • 209
3 votes
1 answer
80 views

Should I be taking these as arguments or define them in a sub class?

So I am making a mario clone in pygame and I have a base class Character and two sub classes, Mario and Luigi. The methods that the Character class defines require a significant amount of attributes ...
Robbie's user avatar
  • 222
4 votes
1 answer
448 views

Should I use exceptions to control the range of parameters in Python?

For example for the following method signature: def genClusters(n_clusters, n_nodes, cluster_distribution): n_clusters should be an integer of more than 1. n_nodes should be an integer of more ...
dwjohnston's user avatar
  • 2,733
3 votes
2 answers
2k views

Inform caller or just let them deal with exception?

I'm not sure how to proceed in the following situation. say we have a function as so: def runsATask(codes): myDicts = [helperFunc(code) for code in codes] for item in myDicts: # some ...
c-o-d's user avatar
  • 247
0 votes
2 answers
531 views

Factory for arrays of objects in python

Ok, the title might be a little misleading. I have a Window class that draws widgets inside itself in the constructor. The widgets are all of the same type. So I pass a list of dictionaries, which ...
Vorac's user avatar
  • 7,179