All Topics | Topic: “Error in reading variable's value via Python”
Author Message
Mr. Mostafa Fard
Subject: Error in reading variable's value via Python   
Posted: 2/1/2018 Viewed: 13274 times

Hi,
When I run the following code in JScript, I see the result
JScript Code:
var WEAP = new ActiveXObject("WEAP.WEAPApplication");
WEAP.ActiveArea = "Tutorial";
var V = WEAP.Branch("\\Demand Sites\\City").Variables("Annual Activity Level");
var Temp = V.Value(2011, 1, "No LEAP Link");
print("Done. Value = " + Temp);

But when I run the equivalent code in python (following code) I get an error
Python Code:
import win32com.client
WEAP = win32com.client.Dispatch('WEAP.WEAPApplication')
v = WEAP.Branch('\\Demand Sites\\demand').Variables('Monthly Variation').Value(2015, 1)
print('Done. {}'.format(v))

Error: TypeError: 'float' object is not callable

Note) If I use Value without any parameter (like a property), it works but just return the first value (for example when I use MonthlyValues for its Expression {I mean using WEAP.Branch('\\Demand Sites\\demand').Variables('Monthly Variation').Value}

What should I do to read values of a variable (for individual timesteps) in Python?!?
Dr. Yilin Chen
Subject: Re: Error in reading variable's value via Python   
Posted: 5/19/2022 Viewed: 7528 times

Hi,

Have you solved this problem? I used the function named "ResultValue" instead.

v = WEAP.Branch('\\Demand Sites\\demand').Variables('Monthly Variation').ResultValue(2015, 1)

Do you have any advanced methods to read a large portion of data?
Mr. Dinh Ty Nguyen
Subject: Re: Error in reading variable's value via Python   
Posted: 5/26/2022 Viewed: 7503 times

Hi all,

You can use "expression" function to export or assign data you want. If you want export data for individual timesteps, then use "for" loop.

This is an example to export 'Monthly Variation' for whole time:

v = [] #create empty list to save data
for i in range(WEAP.BaseYear, WEAP.EndYear+1):
for j in range(1,13):
v.append(WEAP.Branch('demand').Variables('Annual Activity Level')).expression

Topic: “Error in reading variable's value via Python”