On 2019-02-18 02:46, songbird wrote:

   having worked on some other things for a while i
didn't put much emphasis on working on this until i
had the other bugs taken care of.

   so now back into it we can go...  :)

   what i came up with (sorry, i hate yet another not
invented here thing, but this is just where i ended up
after some pondering).

   simply put.  if i'm running on a computer and i
don't easily know why kind of computer how can i
answer this in a quick way without getting overly
complicated that also will cover most of the easy
cases?

   i came up with this:

   comments?  additions?  clarifications?

   i don't have a windows system to test this on,
does it work?

   thanks  :)


=====
import re
import tempfile


def sysprobe ():

     sysprobetmp = tempfile.gettempdir()

     print ("Temp directory : -->" + sysprobetmp + "<--\n")

     result = re.search("^/(tmp)|(var)|(usr)|(opt)|(home)", sysprobetmp)
     try:
         print ("Result : -->" + result.group(0) + "<--\n")

         return ("posix")
     except:
         pass
result = re.search("^[A-Za-z]:", sysprobetmp)
     try:
         print ("Result : -->" + result.group(0) + "<--\n")
         return ("windows")
     except:
         pass

Don't use a bare except, it'll catch _any_ exception.

If the regex matches, re.search will return a match object; if it doesn't match, it'll return None.

In any case, +1 to Dan's answer.

[snip]
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to