If condition with variables not working, but working with the actual values of the same variables

Viewed 29

I have a class with multiple instances, I pass these class instance as parameter to a function which calls the instance attributes and performs an if condition. Here the if condition is not performing with variables in place and neither is it throwing an error. But it works fine when I pass in actual values.

core.py

import execution as ex

class Everything():
    all = []

    def __init__(self):
        self.margin = 0
        self.profit_amount = 0
        self.target = 0

users = [{margin: 28000, profit_amount: 0, target:0.03}, {margin: 30000, profit_amount: 0, target:0.03}]

for x in users:
    Everything(x)

for y in Everything.all:
    ex.test(y)

execution.py

def test(ins):
    print(f'printing the values separately, margin = {ins.margin}, 
    profit amount = {ins.profit_amount}, 
    target = {ins.target}')
    if (ins.profit_amount/ins.margin) < ins.target:
        print("Steps further")

Here when I run core.py, the program runs till the 'printing the values separately' statement within execution file, but won't proceed any further.

0 Answers
Related