Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why is this code giving an unterminated string error?

The error points to line 1 saying F-string: unterminated string (pyflakes E)

  
        Query = f"""SET NOCOUNT ON 

        DECLARE @StartDate DateTime 

        DECLARE @EndDate DateTime 

        SET @StartDate =  '{BEGINDATE}' 

        SET @EndDate =  '{ENDDATE}'

        SET NOCOUNT OFF 

        SELECT  * FROM ( 

        SELECT History.TagName, DateTime, Value, StartDateTime 

         FROM History 

         WHERE History.TagName IN ({str(stat_tags_final[j])[1:-1]}, '{(ft_tags_final[i][j])') 

         AND wwRetrievalMode = 'Cyclic' 

         AND wwResolution = 1800000 

         AND wwVersion = 'Latest' 

         AND DateTime >= @StartDate 

         AND DateTime <= @EndDate) temp WHERE temp.StartDateTime >= @StartDate"""

Previously, I did it without f-strings as shown below and it worked fine but looked much more messy. The error occurs when I edit the line "WHERE History.TagName IN(…. I don’t see any unclosed parentheses or quotes here so can anyone point out what’s wrong with the syntax here?

    Query = """SET NOCOUNT ON 

        DECLARE @StartDate DateTime 

        DECLARE @EndDate DateTime 

        SET @StartDate =  """+"'"+(BEGINDATE)+"'"""" 

        SET @EndDate =  """+"'"+(ENDDATE)+"'"""" 

        SET NOCOUNT OFF 

        SELECT  * FROM ( 

        SELECT History.TagName, DateTime, Value, StartDateTime 

         FROM History 

         WHERE History.TagName IN (""" + str(stat_tags_final[j])[1:-1] + ", '" + (ft_tags_final[i][j]) + "'" + """) 

         AND wwRetrievalMode = 'Cyclic' 

         AND wwResolution = 1800000 

         AND wwVersion = 'Latest' 

         AND DateTime >= @StartDate 

         AND DateTime <= @EndDate) temp WHERE temp.StartDateTime >= @StartDate"""

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Your error is probably in this line:

     WHERE History.TagName IN ({str(stat_tags_final[j])[1:-1]}, '{(ft_tags_final[i][j])') 

You have an opening { but no closing } where you use ft_tags_final.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading