Welcome to WEAP's Website WEAP
WEAP is an initiative of the Stockholm Environment Institute.


About WEAP

Home
Why WEAP?
Features
What's New?
Sample Screens
Demonstration
Publications
History and Credits

Using WEAP
Download
Licensing
User Guide
Tutorial
Videos (YouTube)

User Forum
Discussions
Members List
Edit Profile

Additional Support
Training
University Courses
Collaboration

About Us
SEI-US Water Resources Program
Please Contact Us

LEAP
Interested in Energy?
Read about LEAP: SEI's software for energy planning.

Link WEAP and LEAP for combined Water-Energy planning.
Watch a video demo!
   

User Forum

All Topics | Topic "Error in reading variable's value via Python"
Log in to post new messages or reply to existing messages.
 
Author Message
Mr. Mostafa Fard

Subject: Error in reading variable's value via Python   
Posted: 2/1/2018 Viewed: 10562 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: 4823 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: 4803 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"