Re: Exercize to understand from three numbers which is more high

2019-01-28 Thread ^Bart

Excellent! Glad I could help.


Thank you! :) I'm studying Python everyday and I try to do the best! :)

1. The last two lines appear to be indented under the 'if number3 < ' 
line. I think you want them to be unindented so that they run every time.


I'm sorry but I didn't completely understand what you wrote about the 
last two lines, please could you write how my code could be fixed?



2. When you have lines such as -

    if a == 1:
    do something
    if a == 2:
    do something else

then if 'a' is equal to 1, there is no need to check for 'a' equal to 2.

Python allows you to shortcut this as follows -

    if a == 1:
    do something
    elif a == 2:
    do something else


Finally I understood the differences between if and elif! Lol! :D


Frank


Thank you very much for your patience! :)
^Bart
--
https://mail.python.org/mailman/listinfo/python-list


Re: Exercize to understand from three numbers which is more high

2019-01-28 Thread Frank Millman

"^Bart"  wrote in message news:q2mghh$ah6$1...@gioia.aioe.org...


> 1. The last two lines appear to be indented under the 'if number3 < ' 
> line. I think you want them to be unindented so that they run every 
> time.


I'm sorry but I didn't completely understand what you wrote about the last 
two lines, please could you write how my code could be fixed?




The last four lines of your program look like this -

if number3 < number2 and number3 < number1:
numbermin = number3

print("Number min is: ",numbermin)

numbermiddle = (number1+number2+number3)-(numbermax+numbermin)

print("Number middle is: ",numbermiddle)

The last three lines all fall under the 'if number3 < number2' line, so they 
will only be executed if that line evaluates to True.


I think that you want the last two lines to be executed every time. If so, 
they should be lined up underneath the 'if', not the 'print'.




> if a == 1:
> do something
> elif a == 2:
> do something else

Finally I understood the differences between if and elif! Lol! :D



It is actually short for 'else if', but I guess it is not obvious if you 
have not seen it before!


Frank


--
https://mail.python.org/mailman/listinfo/python-list


Re: preferences file

2019-01-28 Thread songbird
DL Neil wrote:
> On 25/01/19 4:22 PM, Bill Campbell wrote:
>> On Thu, Jan 24, 2019, 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?
>> 
>> Generally I put them in the user's $HOME or $HOME/etc directory
>> with appropriate permissions unless working in a virtual
>> environement.
>
> Good idea.
>
> What about running a multi-tenant application (for multiple users who 
> are not also system-users) - cf them logging-on to run their own. It is 
> appropriate, possibly even "required" to keep Fred's config file, 
> reports, graphs, logs, etc; separate from Barney's. Ideally they will 
> not be sub-dirs of the application/package.

  if it is per user defined then $HOME/.config/, 
$HOME/.local/share/ and any temporary data can go 
in $HOME/.cache/ will do it for posix on Windows 
there is the per user app stuff which i haven't sorted out
yet.

  $HOME changes per user login name change.


  songbird
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: preferences file

2019-01-28 Thread Karsten Hilbert
On Mon, Jan 28, 2019 at 07:02:47AM -0500, songbird wrote:

> > What about running a multi-tenant application (for multiple users who 
> > are not also system-users) - cf them logging-on to run their own. It is 
> > appropriate, possibly even "required" to keep Fred's config file, 
> > reports, graphs, logs, etc; separate from Barney's. Ideally they will 
> > not be sub-dirs of the application/package.
> 
>   if it is per user defined then $HOME/.config/, 
> $HOME/.local/share/ and any temporary data can go 
> in $HOME/.cache/ will do it for posix on Windows 
> there is the per user app stuff which i haven't sorted out
> yet.
> 
>   $HOME changes per user login name change.

$HOME/.config///
$HOME/.cache///

Karsten
-- 
GPG  40BE 5B0E C98E 1713 AFA6  5BC0 3BEA AC80 7D4F C89B
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: preferences file

2019-01-28 Thread songbird
Karsten Hilbert wrote:
> On Mon, Jan 28, 2019 at 07:02:47AM -0500, songbird wrote:
>
>> > What about running a multi-tenant application (for multiple users who 
>> > are not also system-users) - cf them logging-on to run their own. It is 
>> > appropriate, possibly even "required" to keep Fred's config file, 
>> > reports, graphs, logs, etc; separate from Barney's. Ideally they will 
>> > not be sub-dirs of the application/package.
>> 
>>   if it is per user defined then $HOME/.config/, 
>> $HOME/.local/share/ and any temporary data can go 
>> in $HOME/.cache/ will do it for posix on Windows 
>> there is the per user app stuff which i haven't sorted out
>> yet.
>> 
>>   $HOME changes per user login name change.
>
>   $HOME/.config///
>   $HOME/.cache///

  that makes no sense as you already have unique
user name covered by $HOME so why repeat again?


  songbird
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: preferences file

2019-01-28 Thread Karsten Hilbert
On Mon, Jan 28, 2019 at 10:23:31AM -0500, songbird wrote:

> Karsten Hilbert wrote:
> > On Mon, Jan 28, 2019 at 07:02:47AM -0500, songbird wrote:
> >
> >> > What about running a multi-tenant application (for multiple users who 
> >> > are not also system-users) - cf them logging-on to run their own. It is 
> >> > appropriate, possibly even "required" to keep Fred's config file, 
> >> > reports, graphs, logs, etc; separate from Barney's. Ideally they will 
> >> > not be sub-dirs of the application/package.
> >> 
> >>   if it is per user defined then $HOME/.config/, 
> >> $HOME/.local/share/ and any temporary data can go 
> >> in $HOME/.cache/ will do it for posix on Windows 
> >> there is the per user app stuff which i haven't sorted out
> >> yet.
> >> 
> >>   $HOME changes per user login name change.
> >
> > $HOME/.config///
> > $HOME/.cache///
> 
>   that makes no sense as you already have unique
> user name covered by $HOME so why repeat again?

Because you seemed to imply that the login user is different
from the app user:

"the per user app stuff")

Apparently you meant something else ?

Karsten
-- 
GPG  40BE 5B0E C98E 1713 AFA6  5BC0 3BEA AC80 7D4F C89B
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: preferences file

2019-01-28 Thread DL Neil

On 29/01/19 1:29 AM, Karsten Hilbert wrote:

On Mon, Jan 28, 2019 at 07:02:47AM -0500, songbird wrote:


What about running a multi-tenant application (for multiple users who
are not also system-users) - cf them logging-on to run their own. It is
appropriate, possibly even "required" to keep Fred's config file,
reports, graphs, logs, etc; separate from Barney's. Ideally they will
not be sub-dirs of the application/package.


   if it is per user defined then $HOME/.config/,
$HOME/.local/share/ and any temporary data can go
in $HOME/.cache/ will do it for posix on Windows
there is the per user app stuff which i haven't sorted out
yet.

   $HOME changes per user login name change.


$HOME/.config///
$HOME/.cache///



+1

The latter for tmp/intermediate files (without hassles, eg creating 
unique fileNMs!). - and which can be wiped with a single command at the 
end of the run!


The former for 'valuable stuff'. With the opportunity, to separate 
output presentations and inputs using sub-dirs!


(noticed in one such implementation, the need to separate different 
'runs' of the same app, by the same client, using alternate hypotheses - 
that required another 'layer' of sub-dirs!)


Thanks!
--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: preferences file

2019-01-28 Thread songbird
Karsten Hilbert wrote:
> On Mon, Jan 28, 2019 at 10:23:31AM -0500, songbird wrote:
>> Karsten Hilbert wrote:
>> > On Mon, Jan 28, 2019 at 07:02:47AM -0500, songbird wrote:
>> >
>> >> > What about running a multi-tenant application (for multiple users who 
>> >> > are not also system-users) - cf them logging-on to run their own. It is 
>> >> > appropriate, possibly even "required" to keep Fred's config file, 
>> >> > reports, graphs, logs, etc; separate from Barney's. Ideally they will 
>> >> > not be sub-dirs of the application/package.
>> >> 
>> >>   if it is per user defined then $HOME/.config/, 
>> >> $HOME/.local/share/ and any temporary data can go 
>> >> in $HOME/.cache/ will do it for posix on Windows 
>> >> there is the per user app stuff which i haven't sorted out
>> >> yet.
>> >> 
>> >>   $HOME changes per user login name change.
>> >
>> >$HOME/.config///
>> >$HOME/.cache///
>> 
>>   that makes no sense as you already have unique
>> user name covered by $HOME so why repeat again?
>
> Because you seemed to imply that the login user is different
> from the app user:
>
>   "the per user app stuff")
>
> Apparently you meant something else ?

  sorry for being unclear.

  each user is taken care of by $HOME and for me there
is no other complication.


  songbird
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: preferences file

2019-01-28 Thread songbird
DL Neil wrote:
> On 29/01/19 1:29 AM, Karsten Hilbert wrote:
>> On Mon, Jan 28, 2019 at 07:02:47AM -0500, songbird wrote:
>> 
 What about running a multi-tenant application (for multiple users who
 are not also system-users) - cf them logging-on to run their own. It is
 appropriate, possibly even "required" to keep Fred's config file,
 reports, graphs, logs, etc; separate from Barney's. Ideally they will
 not be sub-dirs of the application/package.
>>>
>>>if it is per user defined then $HOME/.config/,
>>> $HOME/.local/share/ and any temporary data can go
>>> in $HOME/.cache/ will do it for posix on Windows
>>> there is the per user app stuff which i haven't sorted out
>>> yet.
>>>
>>>$HOME changes per user login name change.
>> 
>>  $HOME/.config///
>>  $HOME/.cache///
>
>
> +1
>
> The latter for tmp/intermediate files (without hassles, eg creating 
> unique fileNMs!). - and which can be wiped with a single command at the 
> end of the run!
>
> The former for 'valuable stuff'. With the opportunity, to separate 
> output presentations and inputs using sub-dirs!
>
> (noticed in one such implementation, the need to separate different 
> 'runs' of the same app, by the same client, using alternate hypotheses - 
> that required another 'layer' of sub-dirs!)
>
> Thanks!

  oh, well i don't need anything that complicated but
usually there is a way of generating unique file names
and managing temporary files.

  if you are running an application by a login user
which does not log out then eventually you may need
to use some other method of cleaning up the application's
files somehow but to me that is a whole different topic
from the issue of where to put them. 


  songbird
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: preferences file

2019-01-28 Thread DL Neil

On 29/01/19 7:11 AM, songbird wrote:

DL Neil wrote:

On 29/01/19 1:29 AM, Karsten Hilbert wrote:

On Mon, Jan 28, 2019 at 07:02:47AM -0500, songbird wrote:


What about running a multi-tenant application (for multiple users who
are not also system-users) - cf them logging-on to run their own. It is
appropriate, possibly even "required" to keep Fred's config file,
reports, graphs, logs, etc; separate from Barney's. Ideally they will
not be sub-dirs of the application/package.


if it is per user defined then $HOME/.config/,
$HOME/.local/share/ and any temporary data can go
in $HOME/.cache/ will do it for posix on Windows
there is the per user app stuff which i haven't sorted out
yet.

$HOME changes per user login name change.


$HOME/.config///
$HOME/.cache///



...The latter for tmp/intermediate files (without hassles, eg creating
unique fileNMs!). - and which can be wiped with a single command at the
end of the run!
...


   oh, well i don't need anything that complicated but
usually there is a way of generating unique file names
and managing temporary files.


=if the directory is dedicated to a user (and thus the files therein 
driven by his/her/their particular config file), then the issue of 
unique fileNMs no longer exists. Less complexity = more happiness 
(potential)...




   if you are running an application by a login user
which does not log out then eventually you may need
to use some other method of cleaning up the application's
files somehow but to me that is a whole different topic
from the issue of where to put them.


=(a) context managers

=(b) when the intermediate files (from an 'inherited system') are 
over-large (see also Backlog list!), this can become an issue.


Yes, it appears some way from the OP's intent (apologies to him, if 
appropriate).


However, K's comment encouraged a re-think:
- whilst re-developing the app into a multi-tenant possibility, using 
config files to separate the individuals/project teams/departments (back 
to the original question), my thought was that the intermediate files 
"belonged to" the app. Hence they were re-sited under (Linux) /tmp 
(considerations per above).
- if the consideration of "separation" between the multiple 'tenants' is 
important (not in my case), then a generalised drop-zone, eg /tmp, is 
NOT acceptable, eg security/privacy.
- hence the conclusion that any intermediate files should also be 
separated 'under' , ie that they 'belong to' the user and NOT 
to the app!
- this naturally leads to another convenience: unlike concerns for 
over-filling /tmp, there is no need to keep track of what has/not been 
created in $HOME/.cache/// because at the end of the 
run, all contents of the directory (incl/excl) can?should be deleted! (a 
context manager?)


Obvious when you think about it, but wasn't 'at the time'. Ideas 
appended to Project's Backlog...


Again, thanks!
--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


time.strftime question on 0 as argument

2019-01-28 Thread David Raymond
https://docs.python.org/3.7/library/time.html#time.strftime

In the docs there is
"0 is a legal argument for any position in the time tuple; if it is normally 
illegal the value is forced to a correct one."

and yet if given 0 for the year/first item in the tuple it raises a ValueError.

Is that a bug in the code, the documentation, or my understanding?


Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit 
(AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> time.strftime("%b", (0, 1, 0, 0, 0, 0, 0, 0, 0))
Traceback (most recent call last):
  File "", line 1, in 
ValueError: strftime() requires year in [1; ]
>>>


Looks like it works in 2, so maybe an incorrect documentation carryover?

Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:30:26) [MSC v.1500 64 bit 
(AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> time.strftime("%b", (0, 1, 0, 0, 0, 0, 0, 0, 0))
'Jan'
>>>
-- 
https://mail.python.org/mailman/listinfo/python-list


How do I get a python program to work on my phone?

2019-01-28 Thread Steve
This is my first message to this forum, I am not sure how to submit it so
please correct me if I am not doing this properly.
 ===

Being new to python as of a year ago December and have extensive programming
experience: C++, VBasic, HTML etc...  I installed Python and wrote a program
that documents my blood readings enough that my A1c results went from 9.1 to
6.4 in about two months and have had low numbers since.

I now want to run it on my MotoG phone.  The program accepts keyed in data
and will access two text files to keep data and I would like to have the
program chime my phone to remind me to take the next reading.

First step is to get it running in my phone
How do I do it?  What software do I need to make the transfer?

Steve

= 
Footnote:
Zamboni locks up after running into a large patch of loose teeth.

-- 
https://mail.python.org/mailman/listinfo/python-list


List of methods affected by 'Special method lookup'

2019-01-28 Thread Roberto Martínez
Hi,

the documentation about Special method lookup

claims:
"For custom classes, implicit invocations of special methods are only
guaranteed to work correctly if defined on an object’s type, not in the
object’s instance dictionary. "

Does this statement holds for every special method mentioned in section 3.3
Special method names
?

Best regards,
Roberto
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I get a python program to work on my phone?

2019-01-28 Thread Michael Torrie
On 2019-01-28 8:29 a.m., Steve wrote:
> I now want to run it on my MotoG phone.  The program accepts keyed in data
> and will access two text files to keep data and I would like to have the
> program chime my phone to remind me to take the next reading.
> 
> First step is to get it running in my phone
> How do I do it?  What software do I need to make the transfer?

You might want to check into Kivy[1], which is a framework for making
apps that can run on Android using Python (and also iOS and desktop
operating systems as well).

[1] https://kivy.org/#home

-- 
https://mail.python.org/mailman/listinfo/python-list


meta protocol protocol

2019-01-28 Thread Avi Gross
I brought up a topic earlier and am now taking a different slant.

 

I am thinking of the wisdom of having a protocol on announcing what
protocols you implement.

 

Python has many protocols that are now part of the language and I suspect
many more will arise. Python already has a series of variables stored in
classes or instances that store lists or dictionaries of THINGS and I won't
mention them in details as they are numerous and often mysterious. 

 

So I wondered what people thought of the general idea of adding one more
with some name like __PROTOCOLS__ that could be stored at something like the
class level.

 

Here are  examples of one person listing what they consider protocols:

 

https://ref.readthedocs.io/en/latest/understanding_python/interfaces/existin
g_protocols.html

https://stephensugden.com/crash_into_python/Protocols.html

 

When an object implements a protocol such as being callable, that generally
means they provide a method in the name __call__ which is simple enough to
check for if you know where to look. But the sequence protocol may require
quite a few such methods to be fully implemented and testing for dunders
len, getitem, setitem, delitem, reversed, contains, getslice, setslice, and
delslice may be a bit much.

 

So what if the powers that be that determine the fate of python come up with
a meta protocol. All protocols would be given a NAME for official purposes.
The two examples might become "callable" and "sequence" and the meaning of
saying you properly provide a protocol would be well documented.

 

So if someone creates an object, part of the process might be to add entries
for each protocol you declare you properly support to something like the
__PROTOCOLS__ variable. How to do so is an implementation decision but it
could be as easy as adding a method to the top class "object" than any
subclass can inherit and use to declare one or more protocols in use. You
might also add another method like has_protocol(name) that returns True if
it is registered.

 

As a programmer, you might no longer need to know the details to see if
something is in some category. Rather than checking for the presence of
various dunderheads, you simply ask if a protocol is implemented and then
use it.

 

I am not sure anything like this is wanted or practical and am asking if
people have already suggested something along these lines or whether it
would even be something worth doing or practical.

 

I can think of many complications starting with what happens if someone lies
and continuing with what happens if a class inherits from multiple other
classes but some methods are over-ridden or no longer the first one found in
the MRO search.

 

Of course, it would also be nice if there was also a tool that could be used
by developers to validate claims to implement a protocol before run-time
either in a shallow way (the right names are defined) or a deeper way by
exercising the functionality to see it does what is expected. That, too,
leads to me wondering how this could work as the above reference suggests
the copy protocol contains both a __copy__() and a __deepcopy__() and I can
imagine having just the first.

 

When I say PROTOCOL, I mean it in a very broad sense. For example, what
makes an object type IMMUTABLE? What makes the contents of an object
INVISIBLE as in you use techniques so the only way to gain access to the
hidden internals of an object is through various kinds of proxies that keep
you from actually seeing what is going on. Such aspects may not have an
exact protocol but if you want to use something as a key in a dictionary
maybe it will be happy to allow it if it thinks you are of an immutable
type. Other functionality may refuse to work with objects not deemed
invisible for privacy concerns.

 

Again. Not a serious proposal just wondering if my thought process is flawed
deeply or am I just shallow.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: time.strftime question on 0 as argument

2019-01-28 Thread eryk sun
On 1/28/19, David Raymond  wrote:
>
> In the docs there is
> "0 is a legal argument for any position in the time tuple; if it is normally
> illegal the value is forced to a correct one."

The POSIX specification for strftime only states that "[i]f any of the
specified values are outside the normal range, the characters stored
are unspecified" [1]. Python tries to bring some semblance of order
across the various implementations of this function.

For tm_year, it was eventually decided circa Python 3.2 to support the
full signed range on most platforms, even if isn't a normal date, such
as year 0 and negative year values. For example, in 3.6.7 in Linux:

>>> time.strftime("%Y = %C * 100 + %y", (0, 0, 0, 0, 0, 0, 0, 0, 0))
'0 = 0 * 100 + 00'

>>> time.strftime("%Y = %C * 100 + %y", (-10, 0, 0, 0, 0, 0, 0, 0, 0))
'-10 = -1 * 100 + 90'

2.7.15 in Linux has different behavior, especially if
time.accept2dyear is true (set by default unless the environment
variable PYTHONY2K is defined).

>>> time.accept2dyear
1

>>> time.strftime("%Y = %C * 100 + %y", (0, 0, 0, 0, 0, 0, 0, 0, 0))
'2000 = 20 * 100 + 00'

>>> time.strftime("%Y = %C * 100 + %y", (-10, 0, 0, 0, 0, 0, 0, 0, 0))
Traceback (most recent call last):
  File "", line 1, in 
ValueError: year out of range

The magical year value of 2000 comes from code to support pre-Y2K
scripts that assume years 69-99 are 1969-1999 and years 0-68 are
2000-2068. If we force time.accept2dyear to false, we see that Python
2 actually requires the year to be at least 1900.

>>> time.accept2dyear = 0

>>> time.strftime("%Y = %C * 100 + %y", (0, 0, 0, 0, 0, 0, 0, 0, 0))
Traceback (most recent call last):
  File "", line 1, in 
ValueError: year >= 1900 required

> and yet if given 0 for the year/first item in the tuple it raises a
> ValueError.
>
> Is that a bug in the code, the documentation, or my understanding?

It's not a bug. However, in recent versions of the Windows C runtime,
"%y" does support year values down to 0 (but not negative years), so
the check [2] can be relaxed down to 0 (whatever year 0 is supposed to
be), and the additional check for "%y" can be removed [3].

[1]: http://pubs.opengroup.org/onlinepubs/9699919799/functions/strftime.html
[2]: https://github.com/python/cpython/blob/v3.7.2/Modules/timemodule.c#L721
[3]: https://github.com/python/cpython/blob/v3.7.2/Modules/timemodule.c#L760
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: List of methods affected by 'Special method lookup'

2019-01-28 Thread Terry Reedy

On 1/28/2019 11:14 AM, Roberto Martínez wrote:

Hi,

the documentation about Special method lookup

claims:
"For custom classes, implicit invocations of special methods are only
guaranteed to work correctly if defined on an object’s type, not in the
object’s instance dictionary. "

Does this statement holds for every special method mentioned in section 3.3
Special method names
?


You should generally take such statements at face value.  Unless you 
find specific exceptions mentioned elsewhere, 'no guarantee' means just 
that, regardless of how any particular implementation behaves today.

--
Terry Jan Reedy


--
https://mail.python.org/mailman/listinfo/python-list