Re: preferences file
On Thu, Jan 24, 2019 at 02:42:59PM -0500, Dave wrote: > I'm doing a small application and want to add user preferences. Did some > googling to see if there are standard Python ways/tools, but it seems not so > much. My specific questions are: > > 1. Best practices for a user preference file/system? Centralize as much as possible - if there's a database consider putting user options into that. Standard library helps in keeping dependencies down (ConfigParser). > 2. File format favored and why - ini, JSON, etc? Stay with something human readable. INI is nice, but doesn't nest well, as was said. And it does not easily lend itself to "list" style options. > 3. File location? I'm using Ubuntu and I believe that the correct location > would be home/.config/ . What about Mac and Windows? pip3 search xdg: xdg (3.0.2) - Variables defined by the XDG Base Directory Specification python-xdgapp (1.0) - Python XDG for Applications mir.xdg (1.0.0) - XDG Base Directory support dirspec (13.08) - XDG Base and User directories implementation xdgspec (0.1.1) - Convenient access to XDG Base Directory Specification variables pyxdg-open (0.2.1) - Opens URL or file in user preferred application (xdg-open replacement). Depending on UI toolkit: https://wxpython.org/Phoenix/docs/html/wx.StandardPaths.html Karsten -- GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B -- https://mail.python.org/mailman/listinfo/python-list
Exercize to understand from three numbers which is more high
number1 = int( input("Insert the first number: ")) number2 = int( input("Insert the second number: ")) number3 = int( input("Insert the third number: ")) if number1 > number2 and number1 > number3: print("Max number is: ",number1) if number2 > number1 and number2 > number3: print("Max number is: ",number2) else: print("Max number is: ",number3) Try to insert numbers 3, 2 and 1 and the result will be number 3 and 1, can you help me to fix it?! :\ ^Bart -- https://mail.python.org/mailman/listinfo/python-list
Re: Exercize to understand from three numbers which is more high
-BEGIN PGP SIGNED MESSAGE- Hash: SHA256 ^Bart wrote: > > if number1 > number2 and number1 > number3: > print("Max number is: ",number1) > > if number2 > number1 and number2 > number3: > print("Max number is: ",number2) > > else: > print("Max number is: ",number3) > > Try to insert numbers 3, 2 and 1 and the result will be number 3 and 1, > can you help me to fix it?! :\ > > ^Bart Should probably be if (num1 > num2) and (num1>num3) [...] *elseif* (num2 > num1) and (num2>num3) [...] else (NOTE -- it's early and I likely crossed syntax from a different language) -BEGIN PGP SIGNATURE- iQEzBAEBCAAdFiEEBcqaUD8uEzVNxUrujhHd8xJ5ooEFAlxK/U4ACgkQjhHd8xJ5 ooHWPQf+PHv6QN8fWFCeYvMwkIs/GUMH9am+4XfUG6KJE6o+6cFiD7kLcLJI8eU6 78r2G/Lgv+zfcF7Tm6hkt+SHzDFTxuSNKeIDZh6zCUwS1RgRg6ormM7UAjkrO+lJ MEY4rVjLbZDuvky6Iy0r8CcPOVH5wZrbSpUjUgXQgV5AP8Pw5zgdjzHTVcl5e9T9 rcWBUgFKZkYCx53rqtLUVnm+ZKmT70VxOCVU/tKLbb6JQAZrPaHzRhi6tBI3GZNM +P9cWJATWQNu4r+bCSWez9EbMgWT2k8Cg35G4XizaWVaTtsj9/gSsnMtFYCzo5Hb JbrSbRJIr7cBjr+gPKhra7IPJDKyOA== =pAVt -END PGP SIGNATURE- -- |_|O|_| |_|_|O| Github: https://github.com/dpurgert |O|O|O| PGP: 05CA 9A50 3F2E 1335 4DC5 4AEE 8E11 DDF3 1279 A281 -- https://mail.python.org/mailman/listinfo/python-list
Re: Exercize to understand from three numbers which is more high
On Fri, Jan 25, 2019 at 7:16 AM Dan Purgert wrote: > > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA256 > > ^Bart wrote: > > > > if number1 > number2 and number1 > number3: > > print("Max number is: ",number1) > > > > if number2 > number1 and number2 > number3: > > print("Max number is: ",number2) > > > > else: > > print("Max number is: ",number3) > > > > Try to insert numbers 3, 2 and 1 and the result will be number 3 and 1, > > can you help me to fix it?! :\ > > > > ^Bart > -- > https://mail.python.org/mailman/listinfo/python-list This looks like homework. What you are asking could be solved a number of ways. I'm guessing your homework wants you to learn about if/else and comparison operators. At any rate, try the python tutor forum, and be more specific to the rules of your assignment -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays -- https://mail.python.org/mailman/listinfo/python-list
Re: Exercize to understand from three numbers which is more high
On Jan 25, 2019 7:00 AM, "^Bart" wrote: > > number1 = int( input("Insert the first number: ")) > > number2 = int( input("Insert the second number: ")) > > number3 = int( input("Insert the third number: ")) > > if number1 > number2 and number1 > number3: > print("Max number is: ",number1) > > if number2 > number1 and number2 > number3: > print("Max number is: ",number2) > > else: > print("Max number is: ",number3) > > Try to insert numbers 3, 2 and 1 and the result will be number 3 and 1, can you help me to fix it?! :\ Suggestion: Pretend that you are the computer. Mentally execute each statement, providing input as required, and write down the results. Something like: Statement Input Result 13 number1 = 3 22 number2 = 2 31 number3 = 1 4 Max number is 3 5 False 6 Max number is 1 Do not guess or assume anything. Just do exactly what each statement says. As an alternative use some kind of debugger that will let you step through the program statement by statement. Most interactive development environments such as IDLE let you do this. You might as well learn to do this now as you will be needing it more and more as you go on. Personally I would not have given any answer to the problem until you had an opportunity to research it more thoroughly. We don't learn by being given answers. Also in the future use tu...@python.org as that's the proper place for this kind of question. Bob Gailer -- https://mail.python.org/mailman/listinfo/python-list
Re: preferences file
Dave wrote: > I'm doing a small application and want to add user preferences. Did > some googling to see if there are standard Python ways/tools, but it > seems not so much. My specific questions are: > > 1. Best practices for a user preference file/system? use as many default parameters as you can so that the user can run it without any configuration changes if possible. what i did was this: config.py which sets the default values used by other modules which then gets imported by any module that needs those values. these can be changed during operation if needed, but are not saved unless specifically desired. if the user desires to save a different configuration than the above default values then that file is saved to $HOME/.config//config_.json i also made sure to upload my app to PyPI making sure the is unique enough there (but also checked it via the packages listing for Debian and Ubuntu to make sure there wasn't a conflict). > 2. File format favored and why - ini, JSON, etc? configuration info and saved user games i've ended up using json. it is easy to load and save and should be universal enough. > 3. File location? I'm using Ubuntu and I believe that the correct > location would be home/.config/ . What about Mac and Windows? yes, user saved info would go into: $HOME/.local/share/ should be ok for any posix system (Debian, Ubuntu, MacOS) if the system doesn't have home directories but does have /usr/local you can put things in there (just check to make sure first that you aren't clobbering someone else's directories or files :) ). > Would like to find a Python library that handles all of this, but so far... every recommendation so far i've seen looks to be either not adopted widely or not actively developed/maintained. songbird -- https://mail.python.org/mailman/listinfo/python-list
Re: Exercize to understand from three numbers which is more high
On 1/25/2019 6:56 AM, ^Bart wrote: number1 = int( input("Insert the first number: ")) number2 = int( input("Insert the second number: ")) number3 = int( input("Insert the third number: ")) if number1 > number2 and number1 > number3: print("Max number is: ",number1) if number2 > number1 and number2 > number3: print("Max number is: ",number2) else: print("Max number is: ",number3) Try to insert numbers 3, 2 and 1 and the result will be number 3 and 1, can you help me to fix it? In my experience based on decades of writing programs... 1. The assignment/exercise/problem should be a write a function with a particular signature. So first decide on the signature. def max3(n1, n2, n3): "Return the max of the three inputs." return None # To be replaced. 2. The next thing to do is to WRITE A TEST. Any course that does not pound this into your head is defective. In this case, use the numbers 1, 2, 3. There are 6 permutations of 3 items, so list them explicitly. (For more than 3, up to some reasonable limit, use itertools.permutations.) trios = ((1,2,3), ..., (3,2,1)) # Replace ... with the other 4. for trio in trios: m = max3(*trio) if m != 3: print(f"Error: max3(*{m}) is {m}, not 3.") print("Test done") Note: after removing '...,' from trios, I followed my advice and tested the above by running it, and caught a couple of typos and improved the error message. Replacing 'None' and '...' is your job. 3. The test will initially fail 6 times. Good. Now edit the body of max3 until there are none. 4. Worrying about external input comes last. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: preferences file
On Fri, Jan 25, 2019 at 11:04:51AM -0500, songbird wrote: > if the system doesn't have home directories but does have > /usr/local you can put things in there (just check to make > sure first that you aren't clobbering someone else's directories > or files :) ). I don't that that's typically writable to for any odd user. Karsten -- GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B -- https://mail.python.org/mailman/listinfo/python-list
More elegant way to avoid this hacky implementation of single line reduce for grouping a collection?
Yesterday, I was pondering how to implement groupby, more in the vein of how Kotlin, Swift, Objc, Smalltalk do it, where order doesn’t matter. For example: def groupby(iterable, groupfunc): result = defaultdict(list) for each in iterable: result[groupfunc(each)].append(each) return result original = [1, 2, 3, 4, 5, 1, 2, 4, 2] groupby(original, lambda x: str(x)) ==> {‘1’: [1, 1], ‘2’: [2, 2, 2], ‘3’: [3], ‘4’: [4, 4], ‘5’: [5]} Easy enough, but I found myself obsessing about doing it with a reduce. At one point, I lost sight of whether that was even a better idea or not (the above is pretty simple); I just wanted to know if I could do it. My naive attempt didn’t work so well: grouped = reduce( lambda grouper, each: grouper[str(each)].append(each), allValues, defaultdict(list)) Since the result of the append() function is None, the second reduction fails, because the accumulator ceases to be a dictionary. I persisted and came up with the following piece of evil, using a tuple to move the dict reference from reduction to reduction, but also force the (ignored) side effect of updating the same dict: grouped = reduce( lambda accum, each: (accum[0], accum[0][str(each)].append(each)), allValues, (defaultdict(list), None))[0] My question, only for the sake of learning python3 fu/enlightenment, is there a simpler way to do this with a reduce? I get there’s lots of way to do a groupby. The pursuit here is what’s the simplest/cleverest/sneakiest way to do it with reduce, especially if the quality that gorupfunc (str() in this example) is only called once per item is persevered. -- https://mail.python.org/mailman/listinfo/python-list
Re: More elegant way to avoid this hacky implementation of single line reduce for grouping a collection?
On 2019-01-25 22:58, Travis Griggs wrote: Yesterday, I was pondering how to implement groupby, more in the vein of how Kotlin, Swift, Objc, Smalltalk do it, where order doesn’t matter. For example: def groupby(iterable, groupfunc): result = defaultdict(list) for each in iterable: result[groupfunc(each)].append(each) return result original = [1, 2, 3, 4, 5, 1, 2, 4, 2] groupby(original, lambda x: str(x)) ==> {‘1’: [1, 1], ‘2’: [2, 2, 2], ‘3’: [3], ‘4’: [4, 4], ‘5’: [5]} Easy enough, but I found myself obsessing about doing it with a reduce. At one point, I lost sight of whether that was even a better idea or not (the above is pretty simple); I just wanted to know if I could do it. My naive attempt didn’t work so well: grouped = reduce( lambda grouper, each: grouper[str(each)].append(each), allValues, defaultdict(list)) Since the result of the append() function is None, the second reduction fails, because the accumulator ceases to be a dictionary. I persisted and came up with the following piece of evil, using a tuple to move the dict reference from reduction to reduction, but also force the (ignored) side effect of updating the same dict: grouped = reduce( lambda accum, each: (accum[0], accum[0][str(each)].append(each)), allValues, (defaultdict(list), None))[0] My question, only for the sake of learning python3 fu/enlightenment, is there a simpler way to do this with a reduce? I get there’s lots of way to do a groupby. The pursuit here is what’s the simplest/cleverest/sneakiest way to do it with reduce, especially if the quality that gorupfunc (str() in this example) is only called once per item is persevered. How about this: grouped = lambda iterable, groupfunc: dict(reduce( lambda accum, each: accum[groupfunc(each)].append(each) or accum, iterable, defaultdict(list))) -- https://mail.python.org/mailman/listinfo/python-list