Iteration with linspace through For loop within class












1















I have created a class capacity, which makes some calculation by iterating valuex through a for-loop. There is nothing wrong with the calculation process. I only need to break or stop equation, when this condition is matched.



self.Nrd= Ned


To obtain the above result, I create the following condition,



e=float(Nrd)-Ned
if e>= 0 and e<=1:
break


But that does not yield a good and satisfactory result, and better saying not really working properbly.



I hope you could help me with this, to stop the equation when Nrd = Ned condition is reached.



And the second issue, I do not really get anything back by using __str__ method. How do the values return?



The code:



import numpy as np
from PyQt5 import QtCore, QtGui, QtWidgets

class capacity:
def __init__(self,b,h,y,ecu,cb,ct,fyd,fcd,Esd,Ned):
d = h - cb
ds = ct
Ast = int(3.1416/4*(y)**2*6.67)
Asb = int(3.1416/4*(y)**2*6.67)

for x in np.linspace(1,h,10000):

esc=ecu/x*(ds-x)
es=ecu/x*(d-x)

sisc=Esd*esc
sis=min(Esd*es,fyd)

if sisc <= -fyd:
sisc=-fyd
elif sisc >= -fyd and sisc < 0:
sisc= sisc
else:
sisc=min(sisc,fyd)

self.Nrd=int((0.8*x*b*fcd+Ast*sisc-Asb*sis)/1000)
self.Mrd=(0.8*x*b*fcd*(h/2-0.4*x)+Ast*sisc*(h/2-ds)+Asb*sis*(d-h/2))/1000000

self.x = x
e=float(Nrd)-Ned

if e>= 0 and e<=1:
break
if x==h and Nrd != Ned:
print('Errors','Compression over whole section', sep=' ')
app = QtWidgets.QApplication()
error_dialog = QtWidgets.QErrorMessage()
error_dialog.showMessage('Increase size of column, compressed reinforced column!!')
app.exec_()

def __str__(self):
return print(self.x , self.Nrd, self.Mrd)

foo = capacity(b= 300,h=300,y=12,ecu= 0.0035,cb=35,ct=35,fyd=435,fcd=20,Esd=2e5,Ned=1000)


I appreciate any help, and you are welcome to improve the code. Thanks



Update of code:



According to recent argument on the code above, I manage to define a function which does the calculation, but the question I want to ask, how can I implement it as a class in python. Getting the same print as display by function.



def capacity(b,h,y,ecu,cb,ct,fyd,fcd,Esd,Ned):
d = h - cb
ds = ct
Ast = int(3.1416/4*(y)**2*6.67)
Asb = int(3.1416/4*(y)**2*6.67)

for x in np.linspace(1,h,10000):

try:
esc=ecu/x*(ds-x)
es=ecu/x*(d-x)
except (ZeroDivisionError, RuntimeWarning):
esc = 0
es = 0

sisc=Esd*esc
sis=min(Esd*es,fyd)

if sisc <= -fyd:
sisc=fyd
elif sisc >= -fyd and sisc < 0:
sisc= sisc
else:
sisc=min(sisc,fyd)


Nrd=int((0.8*x*b*fcd+Ast*sisc-Asb*sis)/1000)
Mrd=(0.8*x*b*fcd*(h/2-0.4*x)+Ast*sisc*(h/2-ds)+Asb*sis*(d-h/2))/1000000

e=float(Nrd)-float(Ned)

if e>= 0 and e<=0.5:
return print('n','x value:', x,'n' ,'Normalforce: ', Nrd,'n','Moment capacity :', Mrd,'n','Bottom steel strain :',es,'n',
'Top steel strain :', esc,'n', 'Bottom steel stress :', sisc,'n','Top steel stress :' ,sis )
break
if x==h and Nrd != Ned:
print('Errors','Tryk over hele tværsnit', sep=' ')
app = QtWidgets.QApplication()
error_dialog = QtWidgets.QErrorMessage()
error_dialog.showMessage('Increase size of column, compressed reinforced column!!')
app.exec_()

return print(x, Nrd, Mrd)


foo = Capacity(b= 300,h=250,y=12,ecu= 0.0035,cb=50,ct=50,fyd=435,fcd=20,Esd=2e5,Ned=800)


Result:



enter image description here










share|improve this question

























  • print() doesn't return anything. __str__ needs to return a formatted string, something like {}, {}.format(self.Nrd, self.Mrd)` (I omitted x which isn't an argument or attribute. __init__ should set some attributes, like this Nrd. Define another method to actually do the calculation. On further thought, maybe you don't even need to define a class; define a function instead.

    – hpaulj
    Nov 16 '18 at 23:33













  • I thought the same as you thought to define a function and return values. You are right, __str__ returns string. But those values are int. regarding x value I have fixed in above code. Does __int__ method exists in python?

    – Pavel.D
    Nov 16 '18 at 23:42











  • I don't understand why you're constructing your break condition in this way. Nrd and Ned appear to both be integers. What's wrong with if Nrd==Ned: break?

    – John
    Nov 16 '18 at 23:56











  • If Nrd = Ned : break, sometime do not stop or break, for instance if Ned = 800, Nrd would reach 800,0023 or 800,1000 wont break, reason i prefer decimals because x value wants to be exact accurate.

    – Pavel.D
    Nov 17 '18 at 0:08











  • When you break, set some sort of flag variable, so it's clear that you quit early. That way you won't have to test x==h after.

    – hpaulj
    Nov 17 '18 at 1:08
















1















I have created a class capacity, which makes some calculation by iterating valuex through a for-loop. There is nothing wrong with the calculation process. I only need to break or stop equation, when this condition is matched.



self.Nrd= Ned


To obtain the above result, I create the following condition,



e=float(Nrd)-Ned
if e>= 0 and e<=1:
break


But that does not yield a good and satisfactory result, and better saying not really working properbly.



I hope you could help me with this, to stop the equation when Nrd = Ned condition is reached.



And the second issue, I do not really get anything back by using __str__ method. How do the values return?



The code:



import numpy as np
from PyQt5 import QtCore, QtGui, QtWidgets

class capacity:
def __init__(self,b,h,y,ecu,cb,ct,fyd,fcd,Esd,Ned):
d = h - cb
ds = ct
Ast = int(3.1416/4*(y)**2*6.67)
Asb = int(3.1416/4*(y)**2*6.67)

for x in np.linspace(1,h,10000):

esc=ecu/x*(ds-x)
es=ecu/x*(d-x)

sisc=Esd*esc
sis=min(Esd*es,fyd)

if sisc <= -fyd:
sisc=-fyd
elif sisc >= -fyd and sisc < 0:
sisc= sisc
else:
sisc=min(sisc,fyd)

self.Nrd=int((0.8*x*b*fcd+Ast*sisc-Asb*sis)/1000)
self.Mrd=(0.8*x*b*fcd*(h/2-0.4*x)+Ast*sisc*(h/2-ds)+Asb*sis*(d-h/2))/1000000

self.x = x
e=float(Nrd)-Ned

if e>= 0 and e<=1:
break
if x==h and Nrd != Ned:
print('Errors','Compression over whole section', sep=' ')
app = QtWidgets.QApplication()
error_dialog = QtWidgets.QErrorMessage()
error_dialog.showMessage('Increase size of column, compressed reinforced column!!')
app.exec_()

def __str__(self):
return print(self.x , self.Nrd, self.Mrd)

foo = capacity(b= 300,h=300,y=12,ecu= 0.0035,cb=35,ct=35,fyd=435,fcd=20,Esd=2e5,Ned=1000)


I appreciate any help, and you are welcome to improve the code. Thanks



Update of code:



According to recent argument on the code above, I manage to define a function which does the calculation, but the question I want to ask, how can I implement it as a class in python. Getting the same print as display by function.



def capacity(b,h,y,ecu,cb,ct,fyd,fcd,Esd,Ned):
d = h - cb
ds = ct
Ast = int(3.1416/4*(y)**2*6.67)
Asb = int(3.1416/4*(y)**2*6.67)

for x in np.linspace(1,h,10000):

try:
esc=ecu/x*(ds-x)
es=ecu/x*(d-x)
except (ZeroDivisionError, RuntimeWarning):
esc = 0
es = 0

sisc=Esd*esc
sis=min(Esd*es,fyd)

if sisc <= -fyd:
sisc=fyd
elif sisc >= -fyd and sisc < 0:
sisc= sisc
else:
sisc=min(sisc,fyd)


Nrd=int((0.8*x*b*fcd+Ast*sisc-Asb*sis)/1000)
Mrd=(0.8*x*b*fcd*(h/2-0.4*x)+Ast*sisc*(h/2-ds)+Asb*sis*(d-h/2))/1000000

e=float(Nrd)-float(Ned)

if e>= 0 and e<=0.5:
return print('n','x value:', x,'n' ,'Normalforce: ', Nrd,'n','Moment capacity :', Mrd,'n','Bottom steel strain :',es,'n',
'Top steel strain :', esc,'n', 'Bottom steel stress :', sisc,'n','Top steel stress :' ,sis )
break
if x==h and Nrd != Ned:
print('Errors','Tryk over hele tværsnit', sep=' ')
app = QtWidgets.QApplication()
error_dialog = QtWidgets.QErrorMessage()
error_dialog.showMessage('Increase size of column, compressed reinforced column!!')
app.exec_()

return print(x, Nrd, Mrd)


foo = Capacity(b= 300,h=250,y=12,ecu= 0.0035,cb=50,ct=50,fyd=435,fcd=20,Esd=2e5,Ned=800)


Result:



enter image description here










share|improve this question

























  • print() doesn't return anything. __str__ needs to return a formatted string, something like {}, {}.format(self.Nrd, self.Mrd)` (I omitted x which isn't an argument or attribute. __init__ should set some attributes, like this Nrd. Define another method to actually do the calculation. On further thought, maybe you don't even need to define a class; define a function instead.

    – hpaulj
    Nov 16 '18 at 23:33













  • I thought the same as you thought to define a function and return values. You are right, __str__ returns string. But those values are int. regarding x value I have fixed in above code. Does __int__ method exists in python?

    – Pavel.D
    Nov 16 '18 at 23:42











  • I don't understand why you're constructing your break condition in this way. Nrd and Ned appear to both be integers. What's wrong with if Nrd==Ned: break?

    – John
    Nov 16 '18 at 23:56











  • If Nrd = Ned : break, sometime do not stop or break, for instance if Ned = 800, Nrd would reach 800,0023 or 800,1000 wont break, reason i prefer decimals because x value wants to be exact accurate.

    – Pavel.D
    Nov 17 '18 at 0:08











  • When you break, set some sort of flag variable, so it's clear that you quit early. That way you won't have to test x==h after.

    – hpaulj
    Nov 17 '18 at 1:08














1












1








1








I have created a class capacity, which makes some calculation by iterating valuex through a for-loop. There is nothing wrong with the calculation process. I only need to break or stop equation, when this condition is matched.



self.Nrd= Ned


To obtain the above result, I create the following condition,



e=float(Nrd)-Ned
if e>= 0 and e<=1:
break


But that does not yield a good and satisfactory result, and better saying not really working properbly.



I hope you could help me with this, to stop the equation when Nrd = Ned condition is reached.



And the second issue, I do not really get anything back by using __str__ method. How do the values return?



The code:



import numpy as np
from PyQt5 import QtCore, QtGui, QtWidgets

class capacity:
def __init__(self,b,h,y,ecu,cb,ct,fyd,fcd,Esd,Ned):
d = h - cb
ds = ct
Ast = int(3.1416/4*(y)**2*6.67)
Asb = int(3.1416/4*(y)**2*6.67)

for x in np.linspace(1,h,10000):

esc=ecu/x*(ds-x)
es=ecu/x*(d-x)

sisc=Esd*esc
sis=min(Esd*es,fyd)

if sisc <= -fyd:
sisc=-fyd
elif sisc >= -fyd and sisc < 0:
sisc= sisc
else:
sisc=min(sisc,fyd)

self.Nrd=int((0.8*x*b*fcd+Ast*sisc-Asb*sis)/1000)
self.Mrd=(0.8*x*b*fcd*(h/2-0.4*x)+Ast*sisc*(h/2-ds)+Asb*sis*(d-h/2))/1000000

self.x = x
e=float(Nrd)-Ned

if e>= 0 and e<=1:
break
if x==h and Nrd != Ned:
print('Errors','Compression over whole section', sep=' ')
app = QtWidgets.QApplication()
error_dialog = QtWidgets.QErrorMessage()
error_dialog.showMessage('Increase size of column, compressed reinforced column!!')
app.exec_()

def __str__(self):
return print(self.x , self.Nrd, self.Mrd)

foo = capacity(b= 300,h=300,y=12,ecu= 0.0035,cb=35,ct=35,fyd=435,fcd=20,Esd=2e5,Ned=1000)


I appreciate any help, and you are welcome to improve the code. Thanks



Update of code:



According to recent argument on the code above, I manage to define a function which does the calculation, but the question I want to ask, how can I implement it as a class in python. Getting the same print as display by function.



def capacity(b,h,y,ecu,cb,ct,fyd,fcd,Esd,Ned):
d = h - cb
ds = ct
Ast = int(3.1416/4*(y)**2*6.67)
Asb = int(3.1416/4*(y)**2*6.67)

for x in np.linspace(1,h,10000):

try:
esc=ecu/x*(ds-x)
es=ecu/x*(d-x)
except (ZeroDivisionError, RuntimeWarning):
esc = 0
es = 0

sisc=Esd*esc
sis=min(Esd*es,fyd)

if sisc <= -fyd:
sisc=fyd
elif sisc >= -fyd and sisc < 0:
sisc= sisc
else:
sisc=min(sisc,fyd)


Nrd=int((0.8*x*b*fcd+Ast*sisc-Asb*sis)/1000)
Mrd=(0.8*x*b*fcd*(h/2-0.4*x)+Ast*sisc*(h/2-ds)+Asb*sis*(d-h/2))/1000000

e=float(Nrd)-float(Ned)

if e>= 0 and e<=0.5:
return print('n','x value:', x,'n' ,'Normalforce: ', Nrd,'n','Moment capacity :', Mrd,'n','Bottom steel strain :',es,'n',
'Top steel strain :', esc,'n', 'Bottom steel stress :', sisc,'n','Top steel stress :' ,sis )
break
if x==h and Nrd != Ned:
print('Errors','Tryk over hele tværsnit', sep=' ')
app = QtWidgets.QApplication()
error_dialog = QtWidgets.QErrorMessage()
error_dialog.showMessage('Increase size of column, compressed reinforced column!!')
app.exec_()

return print(x, Nrd, Mrd)


foo = Capacity(b= 300,h=250,y=12,ecu= 0.0035,cb=50,ct=50,fyd=435,fcd=20,Esd=2e5,Ned=800)


Result:



enter image description here










share|improve this question
















I have created a class capacity, which makes some calculation by iterating valuex through a for-loop. There is nothing wrong with the calculation process. I only need to break or stop equation, when this condition is matched.



self.Nrd= Ned


To obtain the above result, I create the following condition,



e=float(Nrd)-Ned
if e>= 0 and e<=1:
break


But that does not yield a good and satisfactory result, and better saying not really working properbly.



I hope you could help me with this, to stop the equation when Nrd = Ned condition is reached.



And the second issue, I do not really get anything back by using __str__ method. How do the values return?



The code:



import numpy as np
from PyQt5 import QtCore, QtGui, QtWidgets

class capacity:
def __init__(self,b,h,y,ecu,cb,ct,fyd,fcd,Esd,Ned):
d = h - cb
ds = ct
Ast = int(3.1416/4*(y)**2*6.67)
Asb = int(3.1416/4*(y)**2*6.67)

for x in np.linspace(1,h,10000):

esc=ecu/x*(ds-x)
es=ecu/x*(d-x)

sisc=Esd*esc
sis=min(Esd*es,fyd)

if sisc <= -fyd:
sisc=-fyd
elif sisc >= -fyd and sisc < 0:
sisc= sisc
else:
sisc=min(sisc,fyd)

self.Nrd=int((0.8*x*b*fcd+Ast*sisc-Asb*sis)/1000)
self.Mrd=(0.8*x*b*fcd*(h/2-0.4*x)+Ast*sisc*(h/2-ds)+Asb*sis*(d-h/2))/1000000

self.x = x
e=float(Nrd)-Ned

if e>= 0 and e<=1:
break
if x==h and Nrd != Ned:
print('Errors','Compression over whole section', sep=' ')
app = QtWidgets.QApplication()
error_dialog = QtWidgets.QErrorMessage()
error_dialog.showMessage('Increase size of column, compressed reinforced column!!')
app.exec_()

def __str__(self):
return print(self.x , self.Nrd, self.Mrd)

foo = capacity(b= 300,h=300,y=12,ecu= 0.0035,cb=35,ct=35,fyd=435,fcd=20,Esd=2e5,Ned=1000)


I appreciate any help, and you are welcome to improve the code. Thanks



Update of code:



According to recent argument on the code above, I manage to define a function which does the calculation, but the question I want to ask, how can I implement it as a class in python. Getting the same print as display by function.



def capacity(b,h,y,ecu,cb,ct,fyd,fcd,Esd,Ned):
d = h - cb
ds = ct
Ast = int(3.1416/4*(y)**2*6.67)
Asb = int(3.1416/4*(y)**2*6.67)

for x in np.linspace(1,h,10000):

try:
esc=ecu/x*(ds-x)
es=ecu/x*(d-x)
except (ZeroDivisionError, RuntimeWarning):
esc = 0
es = 0

sisc=Esd*esc
sis=min(Esd*es,fyd)

if sisc <= -fyd:
sisc=fyd
elif sisc >= -fyd and sisc < 0:
sisc= sisc
else:
sisc=min(sisc,fyd)


Nrd=int((0.8*x*b*fcd+Ast*sisc-Asb*sis)/1000)
Mrd=(0.8*x*b*fcd*(h/2-0.4*x)+Ast*sisc*(h/2-ds)+Asb*sis*(d-h/2))/1000000

e=float(Nrd)-float(Ned)

if e>= 0 and e<=0.5:
return print('n','x value:', x,'n' ,'Normalforce: ', Nrd,'n','Moment capacity :', Mrd,'n','Bottom steel strain :',es,'n',
'Top steel strain :', esc,'n', 'Bottom steel stress :', sisc,'n','Top steel stress :' ,sis )
break
if x==h and Nrd != Ned:
print('Errors','Tryk over hele tværsnit', sep=' ')
app = QtWidgets.QApplication()
error_dialog = QtWidgets.QErrorMessage()
error_dialog.showMessage('Increase size of column, compressed reinforced column!!')
app.exec_()

return print(x, Nrd, Mrd)


foo = Capacity(b= 300,h=250,y=12,ecu= 0.0035,cb=50,ct=50,fyd=435,fcd=20,Esd=2e5,Ned=800)


Result:



enter image description here







python python-3.x class numpy for-loop






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 23:06







Pavel.D

















asked Nov 16 '18 at 23:04









Pavel.DPavel.D

851111




851111













  • print() doesn't return anything. __str__ needs to return a formatted string, something like {}, {}.format(self.Nrd, self.Mrd)` (I omitted x which isn't an argument or attribute. __init__ should set some attributes, like this Nrd. Define another method to actually do the calculation. On further thought, maybe you don't even need to define a class; define a function instead.

    – hpaulj
    Nov 16 '18 at 23:33













  • I thought the same as you thought to define a function and return values. You are right, __str__ returns string. But those values are int. regarding x value I have fixed in above code. Does __int__ method exists in python?

    – Pavel.D
    Nov 16 '18 at 23:42











  • I don't understand why you're constructing your break condition in this way. Nrd and Ned appear to both be integers. What's wrong with if Nrd==Ned: break?

    – John
    Nov 16 '18 at 23:56











  • If Nrd = Ned : break, sometime do not stop or break, for instance if Ned = 800, Nrd would reach 800,0023 or 800,1000 wont break, reason i prefer decimals because x value wants to be exact accurate.

    – Pavel.D
    Nov 17 '18 at 0:08











  • When you break, set some sort of flag variable, so it's clear that you quit early. That way you won't have to test x==h after.

    – hpaulj
    Nov 17 '18 at 1:08



















  • print() doesn't return anything. __str__ needs to return a formatted string, something like {}, {}.format(self.Nrd, self.Mrd)` (I omitted x which isn't an argument or attribute. __init__ should set some attributes, like this Nrd. Define another method to actually do the calculation. On further thought, maybe you don't even need to define a class; define a function instead.

    – hpaulj
    Nov 16 '18 at 23:33













  • I thought the same as you thought to define a function and return values. You are right, __str__ returns string. But those values are int. regarding x value I have fixed in above code. Does __int__ method exists in python?

    – Pavel.D
    Nov 16 '18 at 23:42











  • I don't understand why you're constructing your break condition in this way. Nrd and Ned appear to both be integers. What's wrong with if Nrd==Ned: break?

    – John
    Nov 16 '18 at 23:56











  • If Nrd = Ned : break, sometime do not stop or break, for instance if Ned = 800, Nrd would reach 800,0023 or 800,1000 wont break, reason i prefer decimals because x value wants to be exact accurate.

    – Pavel.D
    Nov 17 '18 at 0:08











  • When you break, set some sort of flag variable, so it's clear that you quit early. That way you won't have to test x==h after.

    – hpaulj
    Nov 17 '18 at 1:08

















print() doesn't return anything. __str__ needs to return a formatted string, something like {}, {}.format(self.Nrd, self.Mrd)` (I omitted x which isn't an argument or attribute. __init__ should set some attributes, like this Nrd. Define another method to actually do the calculation. On further thought, maybe you don't even need to define a class; define a function instead.

– hpaulj
Nov 16 '18 at 23:33







print() doesn't return anything. __str__ needs to return a formatted string, something like {}, {}.format(self.Nrd, self.Mrd)` (I omitted x which isn't an argument or attribute. __init__ should set some attributes, like this Nrd. Define another method to actually do the calculation. On further thought, maybe you don't even need to define a class; define a function instead.

– hpaulj
Nov 16 '18 at 23:33















I thought the same as you thought to define a function and return values. You are right, __str__ returns string. But those values are int. regarding x value I have fixed in above code. Does __int__ method exists in python?

– Pavel.D
Nov 16 '18 at 23:42





I thought the same as you thought to define a function and return values. You are right, __str__ returns string. But those values are int. regarding x value I have fixed in above code. Does __int__ method exists in python?

– Pavel.D
Nov 16 '18 at 23:42













I don't understand why you're constructing your break condition in this way. Nrd and Ned appear to both be integers. What's wrong with if Nrd==Ned: break?

– John
Nov 16 '18 at 23:56





I don't understand why you're constructing your break condition in this way. Nrd and Ned appear to both be integers. What's wrong with if Nrd==Ned: break?

– John
Nov 16 '18 at 23:56













If Nrd = Ned : break, sometime do not stop or break, for instance if Ned = 800, Nrd would reach 800,0023 or 800,1000 wont break, reason i prefer decimals because x value wants to be exact accurate.

– Pavel.D
Nov 17 '18 at 0:08





If Nrd = Ned : break, sometime do not stop or break, for instance if Ned = 800, Nrd would reach 800,0023 or 800,1000 wont break, reason i prefer decimals because x value wants to be exact accurate.

– Pavel.D
Nov 17 '18 at 0:08













When you break, set some sort of flag variable, so it's clear that you quit early. That way you won't have to test x==h after.

– hpaulj
Nov 17 '18 at 1:08





When you break, set some sort of flag variable, so it's clear that you quit early. That way you won't have to test x==h after.

– hpaulj
Nov 17 '18 at 1:08












2 Answers
2






active

oldest

votes


















1





+50









There's a live version online of the Capacity class from this answer that you can try for yourself



Your code is on the right track. There's a bunch of little stuff that can be cleaned up (for example, you can check if your loop didn't break by using a for... else construct). You also need a proper implementation of __str__. Here's a complete working implementation of the Capacity class that does all of that stuff:



import numpy as np
from PyQt5 import QtCore, QtGui, QtWidgets

class Capacity:
labels = (
('x', 'x value'),
('Nrd', 'Normal force'),
('Mrd', 'Moment capacity'),
('es', 'Bottom steel strain'),
('esc', 'Top steel strain'),
('sisc', 'Bottom steel stress'),
('sis', 'Top steel stress')
)

def __init__(self, *args, **kwargs):
# most recent values of interest
self.x = None
self.Nrd = None
self.Mrd = None
self.es = None
self.esc = None
self.sisc = None
self.sis = None

# if any args are passed to init, try to use them to run .check
if args or kwargs:
self.check(*args, **kwargs)

def check(self, b, h, y, ecu, cb, ct, fyd, fcd, Esd, Ned):
d = h - cb
ds = ct
Ast = int(3.1416/4*(y)**2*6.67)
Asb = int(3.1416/4*(y)**2*6.67)
Nrd = None

for x in np.linspace(1,h,10000):
try:
esc = ecu/x*(ds-x)
es = ecu/x*(d-x)
except (ZeroDivisionError, RuntimeWarning):
esc = 0
es = 0

sisc = Esd*esc
sis = min(Esd*es,fyd)

if sisc <= -fyd:
sisc=fyd
elif sisc >= -fyd and sisc < 0:
sisc = sisc
else:
sisc = min(sisc,fyd)

Nrd = int((0.8*x*b*fcd+Ast*sisc-Asb*sis)/1000)
Mrd = (0.8*x*b*fcd*(h/2-0.4*x)+Ast*sisc*(h/2-ds)+Asb*sis*(d-h/2))/1000000

# record values of interest for later printing
self.x = x
self.Nrd = Nrd
self.Mrd = Mrd
self.es = es
self.esc = esc
self.sisc = sisc
self.sis = sis

if 0 <= (float(Nrd) - Ned) <= 0.5:
# the return statement breaks the loop
return True
else:
# the else clause executes if the end of the for loop is reached without a break
if Nrd != Ned:
print('Errors','Tryk over hele tværsnit', sep=' ')
print(self)
app = QtWidgets.QApplication()
error_dialog = QtWidgets.QErrorMessage()
error_dialog.showMessage('Increase size of column, compressed reinforced column!!')
app.exec_()

return False

def __str__(self):
strs =
for attr,label in self.labels:
# loop through the labels and get the value of the corresponding attribute from self
val = getattr(self, attr)
strs.append('{}: {}'.format(label, val))

# join all the labeled attribute strings with newline characters and return the result
return 'n'.join(strs)


You can then use the Capacity class like this:



capacity = Capacity(b=300, h=300, y=12, ecu=0.0035, cb=35, ct=35, fyd=435, fcd=20, Esd=2e5, Ned=1000)
print(capacity)


which will output:



x value: 186.3985398539854
Normal force: 1000
Moment capacity: 130.8115324251227
Bottom steel strain: 0.0014758973472997895
Top steel strain: -0.0028428060107339903
Bottom steel stress: 435
Top steel stress: 295.1794694599579





share|improve this answer


























  • Great, your class solution is excellent. That's exactly what I'm looking for. Thanks a lot.

    – Pavel.D
    Nov 22 '18 at 7:56



















1














You might be looking for something like bellow, Create your class attrs empty and call a class method that populates them as part of __init__ you can then use the overloading of __str__ to get your desired output. f-strings might be cleaner also. (I didn't have time to collect your code and test it so you might need to do some massaging)



import numpy as np
from PyQt5 import QtCore, QtGui, QtWidgets

class Capacity():
def __init__(self,b,h,y,ecu,cb,ct,fyd,fcd,Esd,Ned):
self.filename = b

self.x_value = None
self.nrm_frc = None
self.mom_cap = None
self.bsstress = None
self.tsstress = None
self.bsstrain = None
self.tsstrain = None
self.parse_file(b,h,y,ecu,cb,ct,fyd,fcd,Esd,Ned)

def parse_file(self,b,h,y,ecu,cb,ct,fyd,fcd,Esd,Ned):
#all the code for calculation where:
self.x_value = 'value'
self.nrm_frc = 'value'
self.mom_cap = 'value'
self.bsstress = 'value'
self.tsstress = 'value'
self.bsstrain = 'value'
self.tsstrain = 'value'

def __str__(self):
return ('nx value: {0} nNormalforce: {1} nMoment capacity : {2} nBottom steel strain : {3} '
'nTop steel strain : {4} nBottom steel stress :{5} nTop steel stress : {6}'
.format(self.x_value, self.nrm_frc, self.mom_cap, self.bsstress, self.tsstress, self.bsstrain, self.tsstrain))


foo = Capacity(b= 300,h=250,y=12,ecu= 0.0035,cb=50,ct=50,fyd=435,fcd=20,Esd=2e5,Ned=800)
print foo





share|improve this answer
























  • Perfect. Indeed your provided solution is simple and professional, it works and integrates with the my function. Thanks a lot.

    – Pavel.D
    Nov 22 '18 at 7:54











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53346519%2fiteration-with-linspace-through-for-loop-within-class%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1





+50









There's a live version online of the Capacity class from this answer that you can try for yourself



Your code is on the right track. There's a bunch of little stuff that can be cleaned up (for example, you can check if your loop didn't break by using a for... else construct). You also need a proper implementation of __str__. Here's a complete working implementation of the Capacity class that does all of that stuff:



import numpy as np
from PyQt5 import QtCore, QtGui, QtWidgets

class Capacity:
labels = (
('x', 'x value'),
('Nrd', 'Normal force'),
('Mrd', 'Moment capacity'),
('es', 'Bottom steel strain'),
('esc', 'Top steel strain'),
('sisc', 'Bottom steel stress'),
('sis', 'Top steel stress')
)

def __init__(self, *args, **kwargs):
# most recent values of interest
self.x = None
self.Nrd = None
self.Mrd = None
self.es = None
self.esc = None
self.sisc = None
self.sis = None

# if any args are passed to init, try to use them to run .check
if args or kwargs:
self.check(*args, **kwargs)

def check(self, b, h, y, ecu, cb, ct, fyd, fcd, Esd, Ned):
d = h - cb
ds = ct
Ast = int(3.1416/4*(y)**2*6.67)
Asb = int(3.1416/4*(y)**2*6.67)
Nrd = None

for x in np.linspace(1,h,10000):
try:
esc = ecu/x*(ds-x)
es = ecu/x*(d-x)
except (ZeroDivisionError, RuntimeWarning):
esc = 0
es = 0

sisc = Esd*esc
sis = min(Esd*es,fyd)

if sisc <= -fyd:
sisc=fyd
elif sisc >= -fyd and sisc < 0:
sisc = sisc
else:
sisc = min(sisc,fyd)

Nrd = int((0.8*x*b*fcd+Ast*sisc-Asb*sis)/1000)
Mrd = (0.8*x*b*fcd*(h/2-0.4*x)+Ast*sisc*(h/2-ds)+Asb*sis*(d-h/2))/1000000

# record values of interest for later printing
self.x = x
self.Nrd = Nrd
self.Mrd = Mrd
self.es = es
self.esc = esc
self.sisc = sisc
self.sis = sis

if 0 <= (float(Nrd) - Ned) <= 0.5:
# the return statement breaks the loop
return True
else:
# the else clause executes if the end of the for loop is reached without a break
if Nrd != Ned:
print('Errors','Tryk over hele tværsnit', sep=' ')
print(self)
app = QtWidgets.QApplication()
error_dialog = QtWidgets.QErrorMessage()
error_dialog.showMessage('Increase size of column, compressed reinforced column!!')
app.exec_()

return False

def __str__(self):
strs =
for attr,label in self.labels:
# loop through the labels and get the value of the corresponding attribute from self
val = getattr(self, attr)
strs.append('{}: {}'.format(label, val))

# join all the labeled attribute strings with newline characters and return the result
return 'n'.join(strs)


You can then use the Capacity class like this:



capacity = Capacity(b=300, h=300, y=12, ecu=0.0035, cb=35, ct=35, fyd=435, fcd=20, Esd=2e5, Ned=1000)
print(capacity)


which will output:



x value: 186.3985398539854
Normal force: 1000
Moment capacity: 130.8115324251227
Bottom steel strain: 0.0014758973472997895
Top steel strain: -0.0028428060107339903
Bottom steel stress: 435
Top steel stress: 295.1794694599579





share|improve this answer


























  • Great, your class solution is excellent. That's exactly what I'm looking for. Thanks a lot.

    – Pavel.D
    Nov 22 '18 at 7:56
















1





+50









There's a live version online of the Capacity class from this answer that you can try for yourself



Your code is on the right track. There's a bunch of little stuff that can be cleaned up (for example, you can check if your loop didn't break by using a for... else construct). You also need a proper implementation of __str__. Here's a complete working implementation of the Capacity class that does all of that stuff:



import numpy as np
from PyQt5 import QtCore, QtGui, QtWidgets

class Capacity:
labels = (
('x', 'x value'),
('Nrd', 'Normal force'),
('Mrd', 'Moment capacity'),
('es', 'Bottom steel strain'),
('esc', 'Top steel strain'),
('sisc', 'Bottom steel stress'),
('sis', 'Top steel stress')
)

def __init__(self, *args, **kwargs):
# most recent values of interest
self.x = None
self.Nrd = None
self.Mrd = None
self.es = None
self.esc = None
self.sisc = None
self.sis = None

# if any args are passed to init, try to use them to run .check
if args or kwargs:
self.check(*args, **kwargs)

def check(self, b, h, y, ecu, cb, ct, fyd, fcd, Esd, Ned):
d = h - cb
ds = ct
Ast = int(3.1416/4*(y)**2*6.67)
Asb = int(3.1416/4*(y)**2*6.67)
Nrd = None

for x in np.linspace(1,h,10000):
try:
esc = ecu/x*(ds-x)
es = ecu/x*(d-x)
except (ZeroDivisionError, RuntimeWarning):
esc = 0
es = 0

sisc = Esd*esc
sis = min(Esd*es,fyd)

if sisc <= -fyd:
sisc=fyd
elif sisc >= -fyd and sisc < 0:
sisc = sisc
else:
sisc = min(sisc,fyd)

Nrd = int((0.8*x*b*fcd+Ast*sisc-Asb*sis)/1000)
Mrd = (0.8*x*b*fcd*(h/2-0.4*x)+Ast*sisc*(h/2-ds)+Asb*sis*(d-h/2))/1000000

# record values of interest for later printing
self.x = x
self.Nrd = Nrd
self.Mrd = Mrd
self.es = es
self.esc = esc
self.sisc = sisc
self.sis = sis

if 0 <= (float(Nrd) - Ned) <= 0.5:
# the return statement breaks the loop
return True
else:
# the else clause executes if the end of the for loop is reached without a break
if Nrd != Ned:
print('Errors','Tryk over hele tværsnit', sep=' ')
print(self)
app = QtWidgets.QApplication()
error_dialog = QtWidgets.QErrorMessage()
error_dialog.showMessage('Increase size of column, compressed reinforced column!!')
app.exec_()

return False

def __str__(self):
strs =
for attr,label in self.labels:
# loop through the labels and get the value of the corresponding attribute from self
val = getattr(self, attr)
strs.append('{}: {}'.format(label, val))

# join all the labeled attribute strings with newline characters and return the result
return 'n'.join(strs)


You can then use the Capacity class like this:



capacity = Capacity(b=300, h=300, y=12, ecu=0.0035, cb=35, ct=35, fyd=435, fcd=20, Esd=2e5, Ned=1000)
print(capacity)


which will output:



x value: 186.3985398539854
Normal force: 1000
Moment capacity: 130.8115324251227
Bottom steel strain: 0.0014758973472997895
Top steel strain: -0.0028428060107339903
Bottom steel stress: 435
Top steel stress: 295.1794694599579





share|improve this answer


























  • Great, your class solution is excellent. That's exactly what I'm looking for. Thanks a lot.

    – Pavel.D
    Nov 22 '18 at 7:56














1





+50







1





+50



1




+50





There's a live version online of the Capacity class from this answer that you can try for yourself



Your code is on the right track. There's a bunch of little stuff that can be cleaned up (for example, you can check if your loop didn't break by using a for... else construct). You also need a proper implementation of __str__. Here's a complete working implementation of the Capacity class that does all of that stuff:



import numpy as np
from PyQt5 import QtCore, QtGui, QtWidgets

class Capacity:
labels = (
('x', 'x value'),
('Nrd', 'Normal force'),
('Mrd', 'Moment capacity'),
('es', 'Bottom steel strain'),
('esc', 'Top steel strain'),
('sisc', 'Bottom steel stress'),
('sis', 'Top steel stress')
)

def __init__(self, *args, **kwargs):
# most recent values of interest
self.x = None
self.Nrd = None
self.Mrd = None
self.es = None
self.esc = None
self.sisc = None
self.sis = None

# if any args are passed to init, try to use them to run .check
if args or kwargs:
self.check(*args, **kwargs)

def check(self, b, h, y, ecu, cb, ct, fyd, fcd, Esd, Ned):
d = h - cb
ds = ct
Ast = int(3.1416/4*(y)**2*6.67)
Asb = int(3.1416/4*(y)**2*6.67)
Nrd = None

for x in np.linspace(1,h,10000):
try:
esc = ecu/x*(ds-x)
es = ecu/x*(d-x)
except (ZeroDivisionError, RuntimeWarning):
esc = 0
es = 0

sisc = Esd*esc
sis = min(Esd*es,fyd)

if sisc <= -fyd:
sisc=fyd
elif sisc >= -fyd and sisc < 0:
sisc = sisc
else:
sisc = min(sisc,fyd)

Nrd = int((0.8*x*b*fcd+Ast*sisc-Asb*sis)/1000)
Mrd = (0.8*x*b*fcd*(h/2-0.4*x)+Ast*sisc*(h/2-ds)+Asb*sis*(d-h/2))/1000000

# record values of interest for later printing
self.x = x
self.Nrd = Nrd
self.Mrd = Mrd
self.es = es
self.esc = esc
self.sisc = sisc
self.sis = sis

if 0 <= (float(Nrd) - Ned) <= 0.5:
# the return statement breaks the loop
return True
else:
# the else clause executes if the end of the for loop is reached without a break
if Nrd != Ned:
print('Errors','Tryk over hele tværsnit', sep=' ')
print(self)
app = QtWidgets.QApplication()
error_dialog = QtWidgets.QErrorMessage()
error_dialog.showMessage('Increase size of column, compressed reinforced column!!')
app.exec_()

return False

def __str__(self):
strs =
for attr,label in self.labels:
# loop through the labels and get the value of the corresponding attribute from self
val = getattr(self, attr)
strs.append('{}: {}'.format(label, val))

# join all the labeled attribute strings with newline characters and return the result
return 'n'.join(strs)


You can then use the Capacity class like this:



capacity = Capacity(b=300, h=300, y=12, ecu=0.0035, cb=35, ct=35, fyd=435, fcd=20, Esd=2e5, Ned=1000)
print(capacity)


which will output:



x value: 186.3985398539854
Normal force: 1000
Moment capacity: 130.8115324251227
Bottom steel strain: 0.0014758973472997895
Top steel strain: -0.0028428060107339903
Bottom steel stress: 435
Top steel stress: 295.1794694599579





share|improve this answer















There's a live version online of the Capacity class from this answer that you can try for yourself



Your code is on the right track. There's a bunch of little stuff that can be cleaned up (for example, you can check if your loop didn't break by using a for... else construct). You also need a proper implementation of __str__. Here's a complete working implementation of the Capacity class that does all of that stuff:



import numpy as np
from PyQt5 import QtCore, QtGui, QtWidgets

class Capacity:
labels = (
('x', 'x value'),
('Nrd', 'Normal force'),
('Mrd', 'Moment capacity'),
('es', 'Bottom steel strain'),
('esc', 'Top steel strain'),
('sisc', 'Bottom steel stress'),
('sis', 'Top steel stress')
)

def __init__(self, *args, **kwargs):
# most recent values of interest
self.x = None
self.Nrd = None
self.Mrd = None
self.es = None
self.esc = None
self.sisc = None
self.sis = None

# if any args are passed to init, try to use them to run .check
if args or kwargs:
self.check(*args, **kwargs)

def check(self, b, h, y, ecu, cb, ct, fyd, fcd, Esd, Ned):
d = h - cb
ds = ct
Ast = int(3.1416/4*(y)**2*6.67)
Asb = int(3.1416/4*(y)**2*6.67)
Nrd = None

for x in np.linspace(1,h,10000):
try:
esc = ecu/x*(ds-x)
es = ecu/x*(d-x)
except (ZeroDivisionError, RuntimeWarning):
esc = 0
es = 0

sisc = Esd*esc
sis = min(Esd*es,fyd)

if sisc <= -fyd:
sisc=fyd
elif sisc >= -fyd and sisc < 0:
sisc = sisc
else:
sisc = min(sisc,fyd)

Nrd = int((0.8*x*b*fcd+Ast*sisc-Asb*sis)/1000)
Mrd = (0.8*x*b*fcd*(h/2-0.4*x)+Ast*sisc*(h/2-ds)+Asb*sis*(d-h/2))/1000000

# record values of interest for later printing
self.x = x
self.Nrd = Nrd
self.Mrd = Mrd
self.es = es
self.esc = esc
self.sisc = sisc
self.sis = sis

if 0 <= (float(Nrd) - Ned) <= 0.5:
# the return statement breaks the loop
return True
else:
# the else clause executes if the end of the for loop is reached without a break
if Nrd != Ned:
print('Errors','Tryk over hele tværsnit', sep=' ')
print(self)
app = QtWidgets.QApplication()
error_dialog = QtWidgets.QErrorMessage()
error_dialog.showMessage('Increase size of column, compressed reinforced column!!')
app.exec_()

return False

def __str__(self):
strs =
for attr,label in self.labels:
# loop through the labels and get the value of the corresponding attribute from self
val = getattr(self, attr)
strs.append('{}: {}'.format(label, val))

# join all the labeled attribute strings with newline characters and return the result
return 'n'.join(strs)


You can then use the Capacity class like this:



capacity = Capacity(b=300, h=300, y=12, ecu=0.0035, cb=35, ct=35, fyd=435, fcd=20, Esd=2e5, Ned=1000)
print(capacity)


which will output:



x value: 186.3985398539854
Normal force: 1000
Moment capacity: 130.8115324251227
Bottom steel strain: 0.0014758973472997895
Top steel strain: -0.0028428060107339903
Bottom steel stress: 435
Top steel stress: 295.1794694599579






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 22 '18 at 0:30

























answered Nov 21 '18 at 23:55









teltel

7,38621431




7,38621431













  • Great, your class solution is excellent. That's exactly what I'm looking for. Thanks a lot.

    – Pavel.D
    Nov 22 '18 at 7:56



















  • Great, your class solution is excellent. That's exactly what I'm looking for. Thanks a lot.

    – Pavel.D
    Nov 22 '18 at 7:56

















Great, your class solution is excellent. That's exactly what I'm looking for. Thanks a lot.

– Pavel.D
Nov 22 '18 at 7:56





Great, your class solution is excellent. That's exactly what I'm looking for. Thanks a lot.

– Pavel.D
Nov 22 '18 at 7:56













1














You might be looking for something like bellow, Create your class attrs empty and call a class method that populates them as part of __init__ you can then use the overloading of __str__ to get your desired output. f-strings might be cleaner also. (I didn't have time to collect your code and test it so you might need to do some massaging)



import numpy as np
from PyQt5 import QtCore, QtGui, QtWidgets

class Capacity():
def __init__(self,b,h,y,ecu,cb,ct,fyd,fcd,Esd,Ned):
self.filename = b

self.x_value = None
self.nrm_frc = None
self.mom_cap = None
self.bsstress = None
self.tsstress = None
self.bsstrain = None
self.tsstrain = None
self.parse_file(b,h,y,ecu,cb,ct,fyd,fcd,Esd,Ned)

def parse_file(self,b,h,y,ecu,cb,ct,fyd,fcd,Esd,Ned):
#all the code for calculation where:
self.x_value = 'value'
self.nrm_frc = 'value'
self.mom_cap = 'value'
self.bsstress = 'value'
self.tsstress = 'value'
self.bsstrain = 'value'
self.tsstrain = 'value'

def __str__(self):
return ('nx value: {0} nNormalforce: {1} nMoment capacity : {2} nBottom steel strain : {3} '
'nTop steel strain : {4} nBottom steel stress :{5} nTop steel stress : {6}'
.format(self.x_value, self.nrm_frc, self.mom_cap, self.bsstress, self.tsstress, self.bsstrain, self.tsstrain))


foo = Capacity(b= 300,h=250,y=12,ecu= 0.0035,cb=50,ct=50,fyd=435,fcd=20,Esd=2e5,Ned=800)
print foo





share|improve this answer
























  • Perfect. Indeed your provided solution is simple and professional, it works and integrates with the my function. Thanks a lot.

    – Pavel.D
    Nov 22 '18 at 7:54
















1














You might be looking for something like bellow, Create your class attrs empty and call a class method that populates them as part of __init__ you can then use the overloading of __str__ to get your desired output. f-strings might be cleaner also. (I didn't have time to collect your code and test it so you might need to do some massaging)



import numpy as np
from PyQt5 import QtCore, QtGui, QtWidgets

class Capacity():
def __init__(self,b,h,y,ecu,cb,ct,fyd,fcd,Esd,Ned):
self.filename = b

self.x_value = None
self.nrm_frc = None
self.mom_cap = None
self.bsstress = None
self.tsstress = None
self.bsstrain = None
self.tsstrain = None
self.parse_file(b,h,y,ecu,cb,ct,fyd,fcd,Esd,Ned)

def parse_file(self,b,h,y,ecu,cb,ct,fyd,fcd,Esd,Ned):
#all the code for calculation where:
self.x_value = 'value'
self.nrm_frc = 'value'
self.mom_cap = 'value'
self.bsstress = 'value'
self.tsstress = 'value'
self.bsstrain = 'value'
self.tsstrain = 'value'

def __str__(self):
return ('nx value: {0} nNormalforce: {1} nMoment capacity : {2} nBottom steel strain : {3} '
'nTop steel strain : {4} nBottom steel stress :{5} nTop steel stress : {6}'
.format(self.x_value, self.nrm_frc, self.mom_cap, self.bsstress, self.tsstress, self.bsstrain, self.tsstrain))


foo = Capacity(b= 300,h=250,y=12,ecu= 0.0035,cb=50,ct=50,fyd=435,fcd=20,Esd=2e5,Ned=800)
print foo





share|improve this answer
























  • Perfect. Indeed your provided solution is simple and professional, it works and integrates with the my function. Thanks a lot.

    – Pavel.D
    Nov 22 '18 at 7:54














1












1








1







You might be looking for something like bellow, Create your class attrs empty and call a class method that populates them as part of __init__ you can then use the overloading of __str__ to get your desired output. f-strings might be cleaner also. (I didn't have time to collect your code and test it so you might need to do some massaging)



import numpy as np
from PyQt5 import QtCore, QtGui, QtWidgets

class Capacity():
def __init__(self,b,h,y,ecu,cb,ct,fyd,fcd,Esd,Ned):
self.filename = b

self.x_value = None
self.nrm_frc = None
self.mom_cap = None
self.bsstress = None
self.tsstress = None
self.bsstrain = None
self.tsstrain = None
self.parse_file(b,h,y,ecu,cb,ct,fyd,fcd,Esd,Ned)

def parse_file(self,b,h,y,ecu,cb,ct,fyd,fcd,Esd,Ned):
#all the code for calculation where:
self.x_value = 'value'
self.nrm_frc = 'value'
self.mom_cap = 'value'
self.bsstress = 'value'
self.tsstress = 'value'
self.bsstrain = 'value'
self.tsstrain = 'value'

def __str__(self):
return ('nx value: {0} nNormalforce: {1} nMoment capacity : {2} nBottom steel strain : {3} '
'nTop steel strain : {4} nBottom steel stress :{5} nTop steel stress : {6}'
.format(self.x_value, self.nrm_frc, self.mom_cap, self.bsstress, self.tsstress, self.bsstrain, self.tsstrain))


foo = Capacity(b= 300,h=250,y=12,ecu= 0.0035,cb=50,ct=50,fyd=435,fcd=20,Esd=2e5,Ned=800)
print foo





share|improve this answer













You might be looking for something like bellow, Create your class attrs empty and call a class method that populates them as part of __init__ you can then use the overloading of __str__ to get your desired output. f-strings might be cleaner also. (I didn't have time to collect your code and test it so you might need to do some massaging)



import numpy as np
from PyQt5 import QtCore, QtGui, QtWidgets

class Capacity():
def __init__(self,b,h,y,ecu,cb,ct,fyd,fcd,Esd,Ned):
self.filename = b

self.x_value = None
self.nrm_frc = None
self.mom_cap = None
self.bsstress = None
self.tsstress = None
self.bsstrain = None
self.tsstrain = None
self.parse_file(b,h,y,ecu,cb,ct,fyd,fcd,Esd,Ned)

def parse_file(self,b,h,y,ecu,cb,ct,fyd,fcd,Esd,Ned):
#all the code for calculation where:
self.x_value = 'value'
self.nrm_frc = 'value'
self.mom_cap = 'value'
self.bsstress = 'value'
self.tsstress = 'value'
self.bsstrain = 'value'
self.tsstrain = 'value'

def __str__(self):
return ('nx value: {0} nNormalforce: {1} nMoment capacity : {2} nBottom steel strain : {3} '
'nTop steel strain : {4} nBottom steel stress :{5} nTop steel stress : {6}'
.format(self.x_value, self.nrm_frc, self.mom_cap, self.bsstress, self.tsstress, self.bsstrain, self.tsstrain))


foo = Capacity(b= 300,h=250,y=12,ecu= 0.0035,cb=50,ct=50,fyd=435,fcd=20,Esd=2e5,Ned=800)
print foo






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 21 '18 at 23:39









bisonbison

463211




463211













  • Perfect. Indeed your provided solution is simple and professional, it works and integrates with the my function. Thanks a lot.

    – Pavel.D
    Nov 22 '18 at 7:54



















  • Perfect. Indeed your provided solution is simple and professional, it works and integrates with the my function. Thanks a lot.

    – Pavel.D
    Nov 22 '18 at 7:54

















Perfect. Indeed your provided solution is simple and professional, it works and integrates with the my function. Thanks a lot.

– Pavel.D
Nov 22 '18 at 7:54





Perfect. Indeed your provided solution is simple and professional, it works and integrates with the my function. Thanks a lot.

– Pavel.D
Nov 22 '18 at 7:54


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53346519%2fiteration-with-linspace-through-for-loop-within-class%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Guess what letter conforming each word

Port of Spain

Run scheduled task as local user group (not BUILTIN)