First time here? Check our help page!
3

Are there any method we can extract idf content in memory space from eppy?

I have code which can generate idf content using eppy.
Those content can be exported as idf file using save method referring to their web site. However, what I want to do is to manipulate further that text data in python.
Are there any method we can extract idf content as text data and store into some variable for further processing in python?

katsuya.obara's avatar
2.1k
katsuya.obara
asked 2019-01-15 02:31:37 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

1 Answer

4

TL;DR: use the IDF::idfstr() method to get the string, then output that to a file once you're done.


I doubt you are going to be critically bound with I/O here, so the quickest workaround is to save to a file then read it with python. Otherwise, the code use to save is pretty simple and located modeleditor.py#L907:L953. You can easily modify that to only keep the string via IDF::idfstr() method, do stuff on it, and still save ultimately in the same format that eppy does.

Let's load some dummy data, and two system modules we will optionally need to encode:

import platform
import os
from eppy import modeleditor
from eppy.modeleditor import IDF

# Set Idd
iddfile = r'/usr/local/EnergyPlus-9-0-1/Energy+.idd'
IDF.setiddname(iddfile)

# Load example file
p = r'/usr/local/EnergyPlus-9-0-1/ExampleFiles/1ZoneUncontrolled.idf'
idf1 = IDF(p)

Now here's the thing:

# Get the idf as a string
s = idf1.idfstr()

# **Do stuff here**

# Optional Encoding like eppy would do by default (lineendings = 'default', encoding='latin-1') 
encoding = 'latin-1'
system = platform.system()
s = '!- {} Line endings \n'.format(system) + s
slines = s.splitlines()
# Make it a single string
s = os.linesep.join(slines)
s = s.encode(encoding)
# s is your idf enconded string ready to write

with open('myfile.idf', 'wb') as idf_out:
    idf_out.write(s)
Julien Marrec's avatar
29.7k
Julien Marrec
answered 2019-01-15 03:18:45 -0500, updated 2019-01-15 03:21:41 -0500
edit flag offensive 0 remove flag delete link

Comments

add a comment see more comments