1
1
101-s2015-11-12 18:39:31
Python
101-s, 2015-11-12 18:39:31

How would you change the structure of a program in Python based on OOP?

Dear programmers, I'm starting to learn OOP based on Python and I can't figure out how to make my program simpler and more understandable. There is a procedure with a cycle in which a lot of data is iterated and changed.

###
for X1 in obj():
     X1 = ModifyValueX1(X1)
     Y2 = ModifyValueY1(Y2)
###и т.п.

What program structure would you make if you need to change the ModifyValue1..x data handlers with different input parameters?
the functions ModifyValueX1-X2-X3 are similar, X2 r is based on X1 for example, you just need to change the code a little. Or OOP methods will not work?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Kitaev, 2015-11-12
@101-s

The structure of your program is not at all clear, so it's impossible to say exactly where to shove OOP.
ModifyValueN can be replaced with something like this:

def modify(value, func):
    return func(value)

And use something like this:
PS Read PEP8, I beg you

S
sim3x, 2015-11-12
@sim3x

OOP makes the program more difficult - don't use OOP unless it's necessary
Just make a function

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question