From: Vincenzo M. <v.m...@ya...> - 2015-06-17 14:52:02
|
Dear all,I have imported a new version of eppy library Eppy Tutorial — eppy 0.4.6.4a documentation santoshphilip/eppy | | | | | | | | | | | santoshphilip/eppyeppy - scripting language for E+, Energyplus | | | | Visualizza su github.com | Anteprima per Yahoo | | | | | | | | | | | | | | | | Eppy Tutorial — eppy 0.4.6.4a documentationEppy Tutorial¶ Authors: Santosh Philip, Leora Tanjuatco Eppy is a scripting language for E+ idf files, and E+ output files. Eppyis written in the programmin... | | | | Visualizza su pythonhosted.org | Anteprima per Yahoo | | | | | in a Java Web Application and when I doing this iddfile = request.getContextPath() + '/Energy+V7_2_0.idd'fname1 = request.getContextPath() + '/smallfile.idf'IDF.setiddname(iddfile)idf1 = IDF(fname1) I have this error: Traceback (most recent call last): File "/Users/vincenzo/NetBeansProjects/ProvaPython/build/web/serv.py", line 18, in doPost idf1 = IDF(fname1) File "/Users/vincenzo/NetBeansProjects/ProvaPython/build/web/eppy/modeleditor.py", line 615, in __init__ super(IDF3, self).__init__(idfname) File "/Users/vincenzo/NetBeansProjects/ProvaPython/build/web/eppy/modeleditor.py", line 560, in __init__ super(IDF2, self).__init__(idfname) File "/Users/vincenzo/NetBeansProjects/ProvaPython/build/web/eppy/modeleditor.py", line 488, in __init__ super(IDF1, self).__init__(idfname) File "/Users/vincenzo/NetBeansProjects/ProvaPython/build/web/eppy/modeleditor.py", line 442, in __init__ self.read() File "/Users/vincenzo/NetBeansProjects/ProvaPython/build/web/eppy/modeleditor.py", line 472, in read readout = idfreader1(self.idfname, self.iddname, File "/Users/vincenzo/NetBeansProjects/ProvaPython/build/web/eppy/idfreader.py", line 148, in idfreader1 versiontuple = iddversiontuple(iddfile) File "/Users/vincenzo/NetBeansProjects/ProvaPython/build/web/eppy/idfreader.py", line 35, in iddversiontuple line1 = fhandle.readline() AttributeError: 'unicode' object has no attribute 'readline' Why? Many thanks. |
From: Jim B. <jim...@py...> - 2015-06-17 16:52:44
|
FWIW, this really is a question for the jython-users mailing list - you are more likely to have users who have experience with this specific package. However, let's see what we can do: On Wed, Jun 17, 2015 at 7:51 AM, Vincenzo Molendini <v.m...@ya...> wrote: > Dear all, > I have imported a new version of eppy library > Eppy Tutorial — eppy 0.4.6.4a documentation > <http://pythonhosted.org/eppy/Main_Tutorial.html> > .. > in a Java Web Application and when I doing this > > iddfile = request.getContextPath() + '/Energy+V7_2_0.idd' > So these are paths, not files. Specifically the result of request.getContextPath() will be a unicode object; when you concat with a str ('/Energy+V7_2_0.idd'), it remains unicode. > fname1 = request.getContextPath() + '/smallfile.idf' > IDF.setiddname(iddfile) > idf1 = IDF(fname1) > > I have this error: > > Traceback (most recent call last): > File "/Users/vincenzo/NetBeansProjects/ProvaPython/build/web/serv.py", line 18, in doPost > idf1 = IDF(fname1) > File "/Users/vincenzo/NetBeansProjects/ProvaPython/build/web/eppy/modeleditor.py", line 615, in __init__ > super(IDF3, self).__init__(idfname) > File "/Users/vincenzo/NetBeansProjects/ProvaPython/build/web/eppy/modeleditor.py", line 560, in __init__ > super(IDF2, self).__init__(idfname) > File "/Users/vincenzo/NetBeansProjects/ProvaPython/build/web/eppy/modeleditor.py", line 488, in __init__ > super(IDF1, self).__init__(idfname) > File "/Users/vincenzo/NetBeansProjects/ProvaPython/build/web/eppy/modeleditor.py", line 442, in __init__ > self.read() > File "/Users/vincenzo/NetBeansProjects/ProvaPython/build/web/eppy/modeleditor.py", line 472, in read > readout = idfreader1(self.idfname, self.iddname, > File "/Users/vincenzo/NetBeansProjects/ProvaPython/build/web/eppy/idfreader.py", line 148, in idfreader1 > versiontuple = iddversiontuple(iddfile) > File "/Users/vincenzo/NetBeansProjects/ProvaPython/build/web/eppy/idfreader.py", line 35, in iddversiontuple > line1 = fhandle.readline()*AttributeError: 'unicode' object has no attribute 'readline'* > > Although I haven't tried to reproduce your code here, it looks like you were trying to treat the above unicode path as it's an already open file. Do one more step, by opening the file for that path: with open(request.getContextPath() + '/Energy+V7_2_0.idd') as iddfile: # use this file in your code It's important that you close the file, otherwise you will immediately have a resource leak. Using the `with open(...)` idiom is the standard approach. - Jim |