[Tutor] Invalid syntax (pyflakes E)

Alan Gauld alan.gauld at yahoo.co.uk
Tue Jul 13 13:26:36 EDT 2021


On 13/07/2021 16:17, Chris Barnes wrote:
> Below is my code.  I'm a student in Programming for Engineers and I'm
> having trouble with some syntax errors.  I've highlighted in yellow where
> I'm having the issue.

This is a text based list and rich text files often get mangled.
So many will not see the yellow.

Its far better to simply copy the full error text into your mail.
Python error messages contain a lot of useful information so
it helps if we can see them in their entirety.

> import pint;
> 
> def GetInputFromArray(promt, choices):
>     print(prompt)
>     for i in range(0, len(choices)):
>         print("Enter {} for {}".format(i, choices[i]))
>     selection = int(input("Enter Value: "))
>     return choices[selection]
> 
> a = GetInput("Select Pressure", ["atm", "in_Hg", "psi"])
> print("You selected: {}".format(a))
> 
> v = 1.0
> 
> from pint import UnitRegsitry
> ureg = UnitRegistry()

> v = v * ureg.parse_expression(a)

I don;t know your lkibrary so will have to assume that
multiplying a float by whatever parse_expression returns
yields a valid object. But so far that  is the most
suspicious line...

> print(" Here is the value with units {}".format(v))
> 
> print(v.to(ureg.atm))
> print(v.dimensionality)
> 
> ureg = UnitRegistry(autoconvert_offset_to_baseunit = True)
> 
> def getPressureInAtm():
>     print("You will input the pressure value and then select the units of
> the input")
>     p = float(input("Enter Pressure:"))

>     choices = ["atm"", "in_Hg", "psi"]
>     print("Youl will now select the units of the value entered")
>     for i in range(0, len(choices)):
>         print("Enter {} for {}".format(i, choices[i]))
>     units = int(input("Enter Value: "))

Why not use your previous function?

units = GetInputFromArray(prompt,choices)

The main reason we create functions is to use
them multiple times.

>     p1 = p * u.parse_expression(choices[units])

Where is u defined? Should it be ureg?

> 
> print(getPressureinAtm())
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list