molshape / CASRegistryNumbers

Python class to manage, check, and sort CAS Registry Numbers.
https://pypi.org/project/casregnum/
MIT License
5 stars 0 forks source link

Syntax error in regular expression check #3

Closed pwrose closed 1 year ago

pwrose commented 1 year ago
if regex_cas := re.match("^(\d{2,7})\-(\d{2})-(\d{1})$", cas_rn):
              ^

SyntaxError: invalid syntax

molshape commented 1 year ago

Hi Peter, thanks for your feedback! This is not really an invalid syntax, but only works with Python 3.8. The := or "walrus" operator for assignment expressions was introduced in Python 3.8. Could you please check whether you are using an older version of Python?

To solve this problem and establish compatibility with older Python versions before 3.8, you can replace this line of code in question with the following two lines:

regex_cas = re.match("^(\d{2,7})\-(\d{2})-(\d{1})$", cas_rn)
if regex_cas :

I hope this helps.

pwrose commented 1 year ago

Thanks, Alex. I learned a new cool feature of Python 3.8!

PS: Do you know a good resource to look up InChIkeys for CAS regnos? PubChem has some, but I'm wondering if there are other complementary resources.

molshape commented 1 year ago

Hi Peter, glad I could show you a new feature in Python 3.8. Unfortunately, I don't have much experience with InChI, so I cannot give you any valuable feedback on this topic - sorry.