Gary
Thanks for stepping in and letting Tom enjoy his break!! The missing $ was
a posting typo. Blowed if I can work out why it refuses to work!!
Andrew
On Friday, 11 August 2017 05:08:34 UTC+3, gjr80 wrote:
> Andrew,
>
> I know Tom has been enjoying the good weather... You are correct that each
> python line needs to start with #, "r" is the default so it will work with
> or without it. You will also need to put a $ in front of intemp, so
> something like:
>
> #set $fd = open("path to file", "r")
> #set $intemp = $fd.readline()
> #$fd.close()
>
> then just use $intemp in your template as you would with any other tag.
> If you want to be real slick could create a ValueHelper object from intemp
> and then you would have all the standard weeWX dot codes available for
> formatting/unit conversion, though that is starting to get complex with
> imports etc, probably best for an SLE.
>
> Gary
>
>
> On Friday, 11 August 2017 03:18:00 UTC+10, Andrew Milner wrote:
>>
>> Tom
>> I've got
>> #set $fd = open("path to file", "r")
>> #set intemp = $fd.readline()
>> #$fd.close()
>>
>> should it work?? Not sure from your answer where # is needed and whether
>> one just uses open or need to use open and specify the mode
>>
>>
>>
>> On Thursday, 10 August 2017 19:37:03 UTC+3, Tom Keffer wrote:
>>
>>> Super easy.
>>>
>>> #set $fd = open('myfile.txt)
>>> $fd.read()
>>> $fd.close()
>>>
>>> -tk
>>>
>>> On Thu, Aug 10, 2017 at 9:00 AM, Andrew Milner <[email protected]>
>>> wrote:
>>>
>>>> I'm sure I can be done - but how?? I want to add some python code to a
>>>> template to read a data file when the html page is being created to
>>>> override a field currently obtained from the archive. How do I change the
>>>> template to do this simple piece of python code???
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "weewx-user" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to [email protected].
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>>
--
You received this message because you are subscribed to the Google Groups
"weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.