I have spent 4hrs+ trying to figure out why I can't catch an IOError. Most of the solutions I find, seem to be python-2 specific. I'm using python-3. Take a look at this:

def getfile(cfg):
   try:
      with open(cfg, 'r', encoding='utf-8') as tmp_file:
         tmp = tmp_file.read().strip().split('\')

   except IOError as err:
      print ('Finally, I caught one', err)

That's just about it. I have had different versions of it without success.

You have backslashed ending quote at line 4, replace '\' with r'\'

you mean:

tmp = tmp_file.read().strip().split('\n')

Thanks for spotting that.
I later found the culprit... (not even represented well in my example here). Had the try-except block on a different hierarchy from the code it was meant to watch.

you mean:

tmp = tmp_file.read().strip().split('\n')

Thanks for spotting that.
I later found the culprit... (not even represented well in my example here). Had the try-except block on a different hierarchy from the code it was meant to watch.

....
naaah! On second thoughts, I'll just shift the database section to SQL and use a 'books' as an interface to the database.

Thanks again

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.