RE: on writing a while loop for rolling two dice

2021-08-30 Thread David Raymond
> def how_many_times():
>   x, y = 0, 1
>   c = 0
>   while x != y:
> c = c + 1
> x, y = roll()
>   return c, (x, y)

Since I haven't seen it used in answers yet, here's another option using our 
new walrus operator

def how_many_times():
roll_count = 1
while (rolls := roll())[0] != rolls[1]:
roll_count += 1
return (roll_count, rolls)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: on writing a while loop for rolling two dice

2021-08-30 Thread Chris Angelico
On Mon, Aug 30, 2021 at 11:13 PM David Raymond  wrote:
>
> > def how_many_times():
> >   x, y = 0, 1
> >   c = 0
> >   while x != y:
> > c = c + 1
> > x, y = roll()
> >   return c, (x, y)
>
> Since I haven't seen it used in answers yet, here's another option using our 
> new walrus operator
>
> def how_many_times():
> roll_count = 1
> while (rolls := roll())[0] != rolls[1]:
> roll_count += 1
> return (roll_count, rolls)
>

Since we're creating solutions that use features in completely
unnecessary ways, here's a version that uses collections.Counter:

def how_many_times():
return next((count, rolls) for count, rolls in
enumerate(iter(roll, None)) if len(Counter(rolls)) == 1)

Do I get bonus points for it being a one-liner that doesn't fit in
eighty characters?

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


Re: on writing a while loop for rolling two dice

2021-08-30 Thread Peter Otten

On 30/08/2021 15:50, Chris Angelico wrote:


def how_many_times():
 return next((count, rolls) for count, rolls in
enumerate(iter(roll, None)) if len(Counter(rolls)) == 1)



That's certainly the most Counter-intuitive version so far;)



Do I get bonus points for it being a one-liner that doesn't fit in
eighty characters?


Nah, but you'll get an honorable mention when you run it through 
pycodestyle without line break...


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


Re: on writing a while loop for rolling two dice

2021-08-30 Thread Chris Angelico
On Tue, Aug 31, 2021 at 12:28 AM Peter Otten <[email protected]> wrote:
>
> On 30/08/2021 15:50, Chris Angelico wrote:
>
> > def how_many_times():
> >  return next((count, rolls) for count, rolls in
> > enumerate(iter(roll, None)) if len(Counter(rolls)) == 1)
>
>
> That's certainly the most Counter-intuitive version so far;)

Thank you, I appreciate that :)

> > Do I get bonus points for it being a one-liner that doesn't fit in
> > eighty characters?
>
> Nah, but you'll get an honorable mention when you run it through
> pycodestyle without line break...
>

Are there any linters that warn against "unintuitive use of
two-argument iter()"?

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


Re: on writing a while loop for rolling two dice

2021-08-30 Thread Peter Otten

On 30/08/2021 06:17, dn via Python-list wrote:


OTOH the simulation of rolling n-number of dice, as would happen in the
real-world, would be broken by making the computer's algorithm more
efficient (rolling until the first non-equal value is 'found'). Does
that mean the realism of the model dies?


You've got to ask your dietician...

(I'm sure everyone agrees that I should stop here. And stop I will)

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


Setup.py + src: Modules not found

2021-08-30 Thread Abdur-Rahmaan Janhangeer
Greetings list,

I have this project:
https://github.com/pyhoneybot/honeybot

I badly wanted to use setup.cfg but editable mode is not allowed for
now. I then switched back to setup.py.

This is my first time with src/,

my entry point is src/honeybot/manage.py:main

now in editable mode i manage to get everything to work

however, when installing from tar.gz i get

from honeybot.api.main import Bot_core
ModuleNotFoundError: No module named 'honeybot.api'

like i have a hard time getting how exactly to import with src/

i guess everything was working as when i changed to honeybot.x, the package
was installed but on a fresh release, it does not know what exactly is
honeybot
for the first time

Q: In my case in modules what should i write to import from /api?

Kind Regards,

Abdur-Rahmaan Janhangeer
about  | blog

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


Re: configargparse - reading option from config only

2021-08-30 Thread Loris Bennett
Richard Damon  writes:

> On 8/27/21 3:37 AM, Loris Bennett wrote:
>> Richard Damon  writes:
>>
>>> On 8/26/21 6:01 AM, Loris Bennett wrote:
 Hi,

 When using configargparse, it seems that if a value is to be read from a
 config file, it also has to be defined as a command-line argument in
 order to turn up as an attribute in the parser namespace.  

 I can sort of see why this is the case, but there are also some options
 I would like to read just from the config file and not have them
 available as command-line options.  This would be, say, to prevent the
 number of options on the command-line from becoming bloated by
 little-used settings.

 Is there an elegant way to do this?

 Cheers,

 Loris

>>> Look at the read() member function to supply the file name to read. Then
>>> in the config object there will be sections for each section in the
>>> config file. No need for any of these to be 'options'
>> Do you have a link for this?  As far as I can see, the config files are
>> given in the following manner:
>>
>>   p = 
>> configargparse.ArgParser(default_config_files=['/etc/app/conf.d/*.conf', 
>> '~/.my_settings'])
>>
>> I can obviously just read the config file with configparser, but the
>> idea of configargparse is that an option can be specified as an option,
>> in a config file, or as an environment variable,
>>
>> As far as I can tell, configargparse only loads entries from the config
>> file into the appropriate namespace if they have also been defined as
>> long options (i.e. with '--').  I was hoping to access *all* the config
>> file entries, regardless of whether they are also options, since the
>> config is obviously being read.
>>
>> Cheers,
>>
>> Loris
>>
> I misread your question, I thought you were talking about configparse.
>
> Question is, if configargparse doesn't do what you want, then it isn't
> the right tool.
>
> It looks like configargparse is SPECIFICALLY designed to allow the use
> to use a file as a shorthand to present command line arguements. The
> whole parsing structure is based on an enumerated set of options, if
> that isn't what you have, it is the wrong tool.

I am not sure what you mean by using 

  a file as a shorthand to present command line arguements

since the command-line arguments are defined by caling the 'add_argument'
method of the configargparse object.  However, I agree with your
analysis that configargparse is the wrong tool for what I want to do.

I like the idea that a variable can be defined as a command-line option,
an entry in a config file, or as an environment variable.  However, when
I think about it, it seems that command-line options are essentially
different from parameters in a configuration file, not least because the
former need some sort of description for the output of '--help', whereas
the latter do not.

Cheers,

Loris
-- 
This signature is currently under construction.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: code to initialize a sequence

2021-08-30 Thread Dennis Lee Bieber
On Sun, 29 Aug 2021 20:44:53 +0200, joseph pareti 
declaimed the following:

>In the code attached below, the A-variant is from somebody else who knows
>Python better than I. But I do not like to just use any code without having
>a grasp, specifically the line in* bold*, so I wrote the B-variant which
>gives the same results. The C-variant is identical to A and is there for
>verification: after resetting the seed I expect the same sequence. The
>D-variant is closer to the way I code, and it does not work.
>
>
>import random
>from random import randint, seed
>
>def generate_sequence(length, n_unique):
>*return [randint(0, n_unique-1) for k in range(length)]*

This does NOT ensure length_UNIQUE values. With a bad seed, it could be
possible to return length IDENTICAL values. If you really need unique
values, I suggest

return random.sample(range(n_unique), k=length)

which handles both the range of values, and ensures the subset selected is
all unique.

"""
Generate n unique samples (multiple items) from a sequence without
repetition. Here, A seq can be a list, set, string, tuple. Sample without
replacement.
"""

>
>def generate_sequence_JP(length, n_unique):
>   LI = []
>   for k in range(length):
> LI.append(randint(0, n_unique-1))
>   return(LI)

Again, nothing is checking for UNIQUE values...

LI = []
while len(LI) < length: #untested, may need length - 1
ri = randint(0, n_unique-1)
if ri not in LI:
LI.append(ri)

>def generate_sequence_EXPLICIT(length, n_unique):
>   X =[None] * length
>  for i in range(length):
>X[i] = [randint(0, n_unique-1)]
>   return X

Same -- nothing about UNIQUE values. Prefilling a list with None, just
to immediate replace all the values feels "unPythonic".


-- 
Wulfraed Dennis Lee Bieber AF6VN
[email protected]://wlfraed.microdiversity.freeddns.org/

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


urgent

2021-08-30 Thread Hari
i was download ur python software but it is like boring user interface for
me like young student to learn ,can u have any updates?
-- 
https://mail.python.org/mailman/listinfo/python-list


The sqlite3 timestamp conversion between unixepoch and localtime can't be done according to the timezone setting on the machine automatically.

2021-08-30 Thread [email protected]
On Ubuntu 20.04.2 LTS, I use the 
[recent2](https://github.com/dotslash/recent2/blob/master/recent2.py) to log 
and query my bash history, which uses a sqlite3 database to store the history 
information. The `datetime` of running a command is inserted in the sqlite3 
database with [a `unixepoch` 
format](https://github.com/dotslash/recent2/blob/f1018aee228c710cc7d1b8b93bc0228791a54563/recent2.py#L45),
 and it will be converted into `localtime` accordingly when retrieved and 
displayed later.

But I found that it did not perform the correct conversion according to the 
time zone setting on the machine, as shown below:
```shell
werner@X10DAi-00:~$ rm 22
rm: cannot remove '22': No such file or directory
werner@X10DAi-00:~$ recent -fo -w . 2
rm 22  # rtime@ 2021-08-29 10:57:13
werner@X10DAi-00:~$ date 
Sun 29 Aug 2021 06:57:22 PM CST
```
I also filed an issue 
[here](https://discuss.python.org/t/python-sqlite3-datetime-verconsion-between-unixepoch-and-localtime/10382).
 Any hints for this problem?

Regards,
HY
-- 
https://mail.python.org/mailman/listinfo/python-list


software installation problems

2021-08-30 Thread randy darwin lozanovalle
Good morning, when I run the Python program after installing the
latest version, I get this message (attached file), I have already
reinstalled the program several times and the same message keeps
appearing; What solution could you give me, thank you!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: urgent

2021-08-30 Thread Igor Korot
Hi,

On Mon, Aug 30, 2021 at 4:34 PM Hari  wrote:
>
> i was download ur python software but it is like boring user interface for
> me like young student to learn ,can u have any updates?

Can you elaborate a little:
Why do you want python?
What task do you want to solve with python?
Why python? Why not any other language?

Thank you.

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


Re: software installation problems

2021-08-30 Thread Igor Korot
Hi,

On Mon, Aug 30, 2021 at 4:37 PM randy darwin lozanovalle
 wrote:
>
> Good morning, when I run the Python program after installing the
> latest version, I get this message (attached file), I have already
> reinstalled the program several times and the same message keeps
> appearing; What solution could you give me, thank you!

This is "no-attachment" list.
Please copy and paste the error inside the message body.

Thank you.

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


[RELEASE] Python 3.9.7 and 3.8.12 are now available

2021-08-30 Thread Łukasz Langa
Python 3.9.7

Get it here: https://www.python.org/downloads/release/python-397/ 

Python 3.9.7 is the newest major stable release of the Python programming 
language, and it contains many new features and optimizations. There’s been 187 
commits since 3.9.6 which is a similar amount compared to 3.8 at the same stage 
of the release cycle. See the change log 
 for details.

On macOS, we encourage you to use the universal2 binary installer variant 
whenever possible. The legacy 10.9+ Intel-only variant will not be provided for 
Python 3.10 and the universal2 variant will become the default download for 
3.9.8. You may need to upgrade third-party components, like pip, to later 
versions. You may experience differences in behavior in IDLE and other Tk-based 
applications due to using the newer version of Tk. As always, if you encounter 
problems when using this installer variant, please check 
https://bugs.python.org  for existing reports and for 
opening new issues.

The next Python 3.9 maintenance release will be 3.9.8, currently scheduled for 
2021-11-01.

 
The
 Second Security-Only Release of Python 3.8

Get it here: https://www.python.org/downloads/release/python-3812/ 

Security content in this release contains four fixes. There are also four 
additional fixes for bugs that might have lead to denial-of-service attacks. 
Finally, while we’re not providing binary installers anymore, for those users 
who produce installers, we upgraded the OpenSSL version used to 1.1.1l. Take a 
look at the change log 
 for details.

According to the release calendar specified in PEP 569 
, Python 3.8 is now in “security 
fixes only” stage of its life cycle: 3.8 branch only accepts security fixes and 
releases of those are made irregularly in source-only form until October 2024. 
Python 3.8 isn’t receiving regular bug fixes anymore, and binary installers are 
no longer provided for it. Python 3.8.10 was the last full bugfix release of 
Python 3.8 with binary installers.

 
Security
 releases of 3.7.12 and 3.6.15

Those aren’t ready just yet but are soon to follow.

Similarly to 3.8, Python 3.7 and 3.6 are now in “security fixes only” stage of 
their life cycle. Python 3.7 will be providing source archives until June 2023 
while Python 3.6 ends its life in December 2021.

 
We
 hope you enjoy the new releases

Your friendly release team,
Ned Deily @nad 
Steve Dower @steve.dower 
Łukasz Langa @ambv 


signature.asc
Description: Message signed with OpenPGP
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: software installation problems

2021-08-30 Thread Dennis Lee Bieber
On Mon, 30 Aug 2021 10:37:26 -0500, randy darwin lozanovalle
 declaimed the following:

>Good morning, when I run the Python program after installing the
>latest version, I get this message (attached file), I have already
>reinstalled the program several times and the same message keeps
>appearing; What solution could you give me, thank you!

No attachments on this forum -- if it can't be cut&paste TEXT you will
have to put the image on some file server and provide a URL -- note that if
said URL is some nasty numeric string from a shortener, many of us will NOT
click on it -- the URL should be a clear string with the ending telling
WHAT exactly is being accessed (.../screenimage.jpg for example).

However, 99% of the time the matter is very simple... You are clicking
on the INSTALLER file. Python is NOT a GUI IDE. Once you have installed it,
hide that installer file somewhere -- on a USB flash drive say -- and
delete it from where ever you downloaded it to. Python is a command line
interpreter, one edits Python scripts using the editor of their choice (not
a word processor), and runs it from the command shell by entering something
like

python myscript.py

-=-=-
C:\Users\Wulfraed>type Script1.py
from pathlib import Path

def listItems(basepath):
print("Processing: %s" % basepath)
items = list(basepath.iterdir())
files = [x for x in items if x.is_file()]
dirs = [x for x in items if x.is_dir()]
for f in files:
print("\tFile: %s" % f)
for d in dirs:
listItems(d)

if __name__ == "__main__":
p = Path(".")
listItems(p)

C:\Users\Wulfraed>python3 script.py
python3: can't open file 'script.py': [Errno 2] No such file or directory

C:\Users\Wulfraed>python3 script1.py
Processing: .
File: .flexprop.config
File: .gitconfig
File: .kdiff3rc
File: .python_history
File: .RData
File: .Rhistory
File: 2015 Wards Geology Catalog.pdf
File: aCalendar.HTML
File: all_ddl.sql
File: BBBser.py
File: BBBser2.py
File: BBBser3.py
File: clang_ref_cache.db
File: cp.txt
File: D74.pdf
File: default-loc.xml
File: default.gpr
File: demo.bexch
File: demo.c
File: demo.c.stderr
File: demo.c.stdout
File: demo.d
File: demo.exe
File: demo.o
SNIP
-=-=-

Python is packaged by a number of providers, not just python.org (among
other there are ActiveState, AnaConda, and now the Win10 M$ application
store has a python installer). What is included with each package differs
-- many may include a Tkinter script called IDLE as a basic IDE (I don't
use it, and hated it the few times I had to start it at work; ActiveState
Windows installs included PythonWin as an IDE -- but in the last few years
ActiveState has required one to register with them before one can download
their package).



-- 
Wulfraed Dennis Lee Bieber AF6VN
[email protected]://wlfraed.microdiversity.freeddns.org/

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


Re: The sqlite3 timestamp conversion between unixepoch and localtime can't be done according to the timezone setting on the machine automatically.

2021-08-30 Thread Dennis Lee Bieber
On Sun, 29 Aug 2021 19:49:19 -0700 (PDT), "[email protected]"
 declaimed the following:

>On Ubuntu 20.04.2 LTS, I use the 
>[recent2](https://github.com/dotslash/recent2/blob/master/recent2.py) to log 
>and query my bash history, which uses a sqlite3 database to store the history 
>information. The `datetime` of running a command is inserted in the sqlite3 
>database with [a `unixepoch` 
>format](https://github.com/dotslash/recent2/blob/f1018aee228c710cc7d1b8b93bc0228791a54563/recent2.py#L45),
> and it will be converted into `localtime` accordingly when retrieved and 
>displayed later.
>

As I read it, it is interpreting whatever value was provided as
UNIXEPOCH when storing the value -- but stores it as an ISO date/time
string! https://www.sqlite.org/lang_datefunc.html

sqlite> select datetime(1092941466, 'unixepoch');
2004-08-19 18:51:06
sqlite>
sqlite> select datetime('now');
2021-08-30 22:28:58
sqlite>

I can't see anything in that code listing that explicitly manipulates
the date/time when fetched for output. Nor do I see the connection
specifying Python adapter usage:
https://docs.python.org/3/library/sqlite3.html#default-adapters-and-converters
so I'd expect the output to be in ISO UTC format; the native result of
using SQLite3's datetime()..

"""
if not args.hide_time:
cmd_time = row_dict["command_dt"]
if args.time_first:
print(f'{Term.YELLOW}{cmd_time}{Term.ENDC}
{colored_cmd}')
else:
padded_cmd = pad(raw_text=row_dict['command'],
print_text=colored_cmd)
print(f'{padded_cmd} # rtime@
{Term.YELLOW}{cmd_time}{Term.ENDC}')
""" 
>But I found that it did not perform the correct conversion according to the 
>time zone setting on the machine, as shown below:
>```shell
>werner@X10DAi-00:~$ rm 22
>rm: cannot remove '22': No such file or directory
>werner@X10DAi-00:~$ recent -fo -w . 2
>rm 22  # rtime@ 2021-08-29 10:57:13
>werner@X10DAi-00:~$ date 
>Sun 29 Aug 2021 06:57:22 PM CST
>```

Might have helped to mention you were in China... To me, CST is North
America Central Standard Time (and I'd have expected this time of year to
see CDT - Central Daylight Time)... That led me on a weird meaningless side
track...

What documentation do you have that says it will display the date/time
in local timezone? (The README appears to be incorrect -- the utility logs
unix epoch [UTC seconds since 1970] AS ISO UTC string).

sqlite> select datetime(1092941466, 'unixepoch');
2004-08-19 18:51:06
sqlite> select datetime(1092941466, 'unixepoch', 'localtime');
2004-08-19 14:51:06
sqlite>
sqlite> select datetime('now', 'localtime');
2021-08-30 18:50:19
sqlite> select datetime('now');
2021-08-30 22:50:32
sqlite>

I'm in EDT (Eastern Daylight Time) -- so 4 hours behind UTC.


-- 
Wulfraed Dennis Lee Bieber AF6VN
[email protected]://wlfraed.microdiversity.freeddns.org/

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


Python UI (was Re: urgent)

2021-08-30 Thread Alan Gauld via Python-list
On 29/08/2021 11:28, Hari wrote:
> i was download ur python software but it is like boring user interface

I agree it is a boring user interface. Just 3 chevrons: >>>
You can change it a little if you want but ultimately its
just an invitation to type commands.

What kind of interface did you have in mind?

If you want a GUI to develop code there are literally
dozens of those. But ultimately programming is about
typing text into an editor.

> me like young student to learn ,can u have any updates?

There are many tools to help you work with python.
If you tell us what kind of things you want we can tell
you where to find them (if they exist!)

But the basic Python interpreter is primarily there
to run your programs, it's hard to see how you can make
that less boring without also making it very inefficient.
And professional users would hate that!

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: The sqlite3 timestamp conversion between unixepoch and localtime can't be done according to the timezone setting on the machine automatically.

2021-08-30 Thread dn via Python-list
On 31/08/2021 11.07, Dennis Lee Bieber wrote:
> On Sun, 29 Aug 2021 19:49:19 -0700 (PDT), "[email protected]"
>  declaimed the following:
...

>   Might have helped to mention you were in China... To me, CST is North
> America Central Standard Time (and I'd have expected this time of year to
> see CDT - Central Daylight Time)... That led me on a weird meaningless side
> track...
...

>   I'm in EDT (Eastern Daylight Time) -- so 4 hours behind UTC.


Which is correct?

CST in China
https://www.timeanddate.com/time/zones/cst-china

CST in North America
https://www.timeanddate.com/time/zones/cst

and not to mention Cuba
https://www.timeanddate.com/time/zones/


«Time zones are often represented by alphabetic abbreviations such as
"EST", "WST", and "CST", but these are not part of the international
time and date standard ISO 8601 and their use as sole designator for a
time zone is discouraged. Such designations can be ambiguous; for
example, "CST" can mean China Standard Time (UTC+8), Cuba Standard Time
(UTC−5), and (North American) Central Standard Time (UTC−6), and it is
also a widely used variant of ACST (Australian Central Standard Time,
UTC+9:30). Such designations predate both ISO 8601 and the internet era;
in an earlier era, they were sufficiently unambiguous for many practical
uses within a national context (for example, in railway timetables and
business correspondence), but their ambiguity explains their deprecation
in the internet era, when communications more often cannot rely on
implicit geographic context to supply part of the meaning.»
https://en.wikipedia.org/wiki/List_of_time_zone_abbreviations


This is why ISO8601 uses the ±HH:MM numeric suffix to designate a local
time-zone (cf UTC - or as we used to say in the UK, "GMT", and in the
military, "Zulu").


Most of us know about ISO8601 formatting, even if we think of it as
something like the way Unix-time is expressed, rather than it being an
international standard.

Few are aware that "8601" has been extended to cover less-obvious dates,
times, and durations.

For example, do you know that today is (said to be) "the last day of
winter"? Assuming you, dear reader, are in the northern hemisphere,
indeed are living in a temperate zone (cf the tropics or closer to one
of the poles), you reacted by exclaiming "what!?".

Thus, one of the 8601 "extensions" deals with the idea that climatic
seasons have meaning to locations within a narrow range of latitudes,
and that they are six-month inverses between the earth's hemispheres.

So, you couldn't understand/didn't believe me - yet I am completely correct.
(as always - cough, splutter, snort...)

Welcome to the last day of (what may be) your summer!

These things can be tricky...
-- 
Regards,
=dn
-- 
https://mail.python.org/mailman/listinfo/python-list


src layout for projects seems not so popular

2021-08-30 Thread Abdur-Rahmaan Janhangeer
Greetings list,

Just an observation. Out of Github's trending repos for
Python for today, I could find only 2 repos using the src layout.
Matplotlib and another one.
https://github.com/trending/python?since=daily

Kind Regards,

Abdur-Rahmaan Janhangeer
about  | blog

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