Re: Has anone seen or know of a CFFI wrapper for PDCurses?

2021-06-14 Thread Dan Stromberg
On Sun, Jun 13, 2021 at 10:42 PM  wrote:

> > From: Dan Stromberg 
> > Sent: Monday, June 14, 2021 12:36 AM
> > To: pjfarl...@earthlink.net
> > Cc: Python List 
> > Subject: Re: Has anone seen or know of a CFFI wrapper for PDCurses?
> >
> > > On Sun, Jun 13, 2021 at 12:50 AM 
> wrote:
> > > Hi All,
> > >
> > > I have been investigating the possibility of wrapping the PDCurses DLL
> on
> > > Windows (or even better the PDCursesMod fork) using cffi instead of
> ctypes.
> > > The unicurses project tried this using ctypes 11 years ago but
> unicurses
> > > hasn't been worked on since 2010, and it shows its age.
> >
> > An option for your consideration: Maybe port Python's included curses
> module to PDCursesMod?
>
> An interesting idea, to be sure, and one I have looked at to some extent.
> One thing that I've never quite learned is whether the included curses and
> curses_panel modules statically link a copy of the ncurses library on *ix
> systems or whether they invoke the ncurses.so library dynamically.
>
Why would it matter?

Anyway, if I start up a CPython 3.9, import curses, and lsof the
interpreter, I can see:
$ lsof -p 26258 | grep curses
below cmd output started 2021 Mon Jun 14 07:04:25 AM PDT
python3 26258 dstromberg  memREG  254,1   231360 25167676
/usr/lib/x86_64-linux-gnu/libncursesw.so.6.1
python3 26258 dstromberg  memREG  254,1   546400  1316749
/usr/local/cpython-3.9/lib/python3.9/lib-dynload/_
curses.cpython-39-x86_64-linux-gnu.so

...which would seem to say that curses is brought into the interpreter on
demand, from a shared object (dll).

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


Re: Tkinter8.6: date picker

2021-06-14 Thread Alan Gauld via Python-list
On 11/06/2021 22:20, Rich Shepard wrote:
> I need a date picker 

+1


-- 
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: Python

2021-06-14 Thread Michael F. Stemper

On 12/06/2021 01.25, Adarsh Kumar wrote:

How to  run python file in normal laptop
actually when i run python it is showing error pls tell me how to add python 
extension  in xammp


Are you trying to run a python program, as the first line suggests,
or are you trying to run python itself, as the second line says?

How are you trying to do this?

What error do you get? This is important. Do not paraphrase the error
message, copy and paste it directly. (Do not try to send a screenshot,
as it will be stripped off of your message.)

Also, in what environment are you doing this? Windows, MacOS, Linux,
something else? Specific version.


--
Michael F. Stemper
You can lead a horse to water, but you can't make him talk like Mr. Ed
by rubbing peanut butter on his gums.
--
https://mail.python.org/mailman/listinfo/python-list


curses apps on MS Windows?

2021-06-14 Thread Grant Edwards
There's been a surprising amount of discussion lately about using
curses libraries on Windows OS. I'm surprised by this, because I don't
think I've ever even seen a Windows curses application.

Are there examples of popular curses applications for Windows?

Does windows have a terminfo/termcap subsystem to deal with different
terminal types? Or do the apps only work with the built-in terminal
windows implemented by command.com/cmd.exe?

Can windows curses apps be used via real serial terminals? Is that
even "a thing" under Windows?

Is there such a thing as a Windows ssh server with some sort of shell
in which one can run console-mode applications?

--
Grant



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


Cant find sorcecode

2021-06-14 Thread Madden



   Hi so I've been trying to find my sorcecode files so I can 7zip them to
   get to the ovl_tool_gui so I can add mods but I haven't been able to find
   them could you help?





   Sent from [1]Mail for Windows 10



References

   Visible links
   1. https://go.microsoft.com/fwlink/?LinkId=550986
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Behaviour of pop() for dictionaries

2021-06-14 Thread Greg Ewing

On 14/06/21 4:19 am, BlindAnagram wrote:
Am I missing the obvious way to obtain the value (or the key) from a 
dictionary that is known to hold only one item?


v = d.popitem()[1]

More importantly, is there a good reason why we don't have d.pop() for 
dictionaries?


My guess is because it's not generally useful to get an arbitrary
value from a dict without its corresponding key. Hence the existence
of popitem().

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


Python

2021-06-14 Thread Adarsh Kumar
How to  run python file in normal laptop
actually when i run python it is showing error pls tell me how to add python 
extension  in xammp
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: optimization of rule-based model on discrete variables

2021-06-14 Thread Greg Ewing

On 14/06/21 4:15 am, Elena wrote:

Given a dataset of X={(x1... x10)} I can calculate Y=f(X) where f is this
rule-based function.

I know an operator g that can calculate a real value from Y: e = g(Y)
g is too complex to be written analytically.

I would like to find a set of rules f able to minimize e on X.


There must be something missing from the problem description.
From what you've said here, it seems like you could simply find
a value k for Y that minimises g, regardless of X, and then f
would consist of a single rule: y = k.

Can you tell us in more concrete terms what X and g represent?

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


Why the list creates in two different ways? Does it cause by the mutability of its elements? Where the Python document explains it?

2021-06-14 Thread Jach Feng
>>> n = [(1,2) for i in range(3)]
>>> n
[(1, 2), (1, 2), (1, 2)]
>>> id(n[0]) == id(n[1])  == id(n[2])
True
>>> m = [[1,2] for i in range(3)]
>>> m
[[1, 2], [1, 2], [1, 2]]
>>> id(m[0]) == id(m[1])  == id(m[2])
False
>>>

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


Re: Terminology: EU language skills, and Master to Main (or ...)

2021-06-14 Thread Greg Ewing

On 13/06/21 3:21 pm, dn wrote:

Will referring to
skilled professionals as 'masters (of their profession/craft)'
transgress (international or at least US-instigated) 'Political
Correctness'?


And what about all the university degrees with the word
"master" in their names?

Worst of all, will episodes of Doctor Who featuring the
Master be banned?

--
Greg

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


Where did the message go?

2021-06-14 Thread Grimble
I have two machines running Mageia 8 and Python 2.8.9, They use the same 
Python script to maintain a list of changed packages from dnf update and 
dnf install. In addition the script sends a short email message to my 
main email address. The problem is: the message from machine B arrives, 
the message from machine H does not.

The part of the script that sends the message is:
   with open('email.txt') as fmail:
msg = EmailMessage()
msg.set_content(fmail.read())

msg['Subject'] = 'System update'
msg['From'] = sysname
msg['To'] = 'gra...@.' (details removed to protect the 
innocent)


# Send the message via our own SMTP server.
s = smtplib.SMTP('localhost')
s.set_debuglevel(True)
s.send_message(msg)
s.quit()

The last lines of s.set_debuglevel are
reply: retcode (250); Msg: b'2.0.0 Ok: queued as B57B42C042F'
data: (250, b'2.0.0 Ok: queued as B57B42C042F')
send: 'quit\r\n'
reply: b'221 2.0.0 Bye\r\n'
reply: retcode (221); Msg: b'2.0.0 Bye'

The SMTP part of the system is working (hence this message).
The message from machine B correctly interprets "sysname" as
sysn...@sysname.. i.e a valid addr4ess.

Where do I look now, please?
--
Grimble
Machine 'Haydn' running Plasma 5.20.4 on 5.10.41-desktop-1.mga8 kernel.
Mageia release 8 (Official) for x86_64
--
https://mail.python.org/mailman/listinfo/python-list


Re: Behaviour of pop() for dictionaries

2021-06-14 Thread Stestagg
You can do the following:

_,v = d.popitem()

Or:

key, value = d.popitem()

Steve

On Mon, 14 Jun 2021 at 20:10, Greg Ewing 
wrote:

> On 14/06/21 4:19 am, BlindAnagram wrote:
> > Am I missing the obvious way to obtain the value (or the key) from a
> > dictionary that is known to hold only one item?
>
> v = d.popitem()[1]
>
> > More importantly, is there a good reason why we don't have d.pop() for
> > dictionaries?
>
> My guess is because it's not generally useful to get an arbitrary
> value from a dict without its corresponding key. Hence the existence
> of popitem().
>
> --
> Greg
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Terminology: EU language skills, and Master to Main (or ...)

2021-06-14 Thread Alan Gauld via Python-list
On 13/06/2021 04:21, dn via Python-list wrote:

> What do you think a professionally-recognisable series of skill-levels
> for programmers?

This has been done or attempted many times, with perhaps the most
complete scheme being the British Computer Society's
"Industry Standard Model" which breaks jobs/skills in the industry
into many categories(30 or so?) and within each category there
are up to 6 levels of achievement. (Some skills don't have
the lowest levels(e.g. architect) while some only have lower
levels. The theory being a level 6 practitioner in and skill
is equally "good" as a level 6 in any other skill. One of
the skills is programming, and significantly, it is language independent.

I don't know if the ISM is still in use, it is many years
since I worked with the BCS as the training officer for our
office. But there used to be a comprehensive set of web pages
describing the requirements for each level for each skill.
A quick search for BCS ISM didn't throw up a link, sorry.

-- 
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


Is there a way to get the following result in Python?

2021-06-14 Thread Jach Feng
>>> def foo():
... # do something
...
>>> a = []
>>> for i in range(3):
... a.append(foo())
...
>>> a
[]
>>>

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


Fwd: Unable to uninstall Python 3.8.7

2021-06-14 Thread Rudraksh Nanavaty
I previously uninstalled to python install directory which was:
“C:\Users\{username}\Python\Python 3.8.4”

Then I went to programs and features in the control panel and clicked
uninstall.

Wizard said uninstall successful, but it didn’t remove python from the
programs list.

I left it as is. Ignored it, and installed python 3.9.2

But VSCode says I have no python installed.
Please Help
-- 
https://mail.python.org/mailman/listinfo/python-list


Tree library that allows conditions on nodes and will return the node

2021-06-14 Thread Veek M
LibreOffice has a huge class tree and I need to familiarize myself with
it - trouble is, it won't fit on A4 because it has a flat hierarchy with
loads of leaf nodes.

I wanted to shove all the leaf nodes > x into a subgraph and style that
differently using Graphviz.

I tried treelib but while i can build and print a tree, AND figure out
the size for each level of the Tree, it won't give me the parent node
for a particular size.. So I know that level 3 has 7 children too much
but which is the jackass parentID responsible - no idea.

Graphviz has nice plotting and subgraphs and such but same problem - I
checked pydot which is a clone of Graphviz and I'm not sure what exactly
it does different from Graphviz..

Anyway I don't want to spend another two days checking out Plotly or
Pygraphviz.. can someone point me in the right direction?
-- 
https://mail.python.org/mailman/listinfo/python-list


optimization of rule-based model on discrete variables

2021-06-14 Thread Elena via Python-list
Hi, I have, say 10 variables (x1 ... x10) which can assume discrete finite 
values, for instance [0,1 or 2].
I need to build a set of rules, such as:

1) if x1==0 and x2==1 and x10==2 then y = 1
2) if x2==1 and x3==1 and x4==2 and x6==0 then y = 0
3) if x2==0 and x3==1 then y = 2
4) if x6==0 and x7==2 then y = 0
...
...
(actually it can be seen as a decision tree classifier).

y can assume the same discrete value [0,1 or 2]
I don't know a-priori anything about the number of rules and the 
combinations of the tested inputs.

Given a dataset of X={(x1... x10)} I can calculate Y=f(X) where f is this 
rule-based function.

I know an operator g that can calculate a real value from Y: e = g(Y)
g is too complex to be written analytically.

I would like to find a set of rules f able to minimize e on X.

I know the problem can become NP-hard, but I would be fine also with a 
suboptimal solution.

What's the best way to approach the problem?
In case, does something already exist in python?


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


Re: Why the list creates in two different ways? Does it cause by the mutability of its elements? Where the Python document explains it?

2021-06-14 Thread Chris Angelico
On Tue, Jun 15, 2021 at 5:12 AM Jach Feng  wrote:
>
> >>> n = [(1,2) for i in range(3)]
> >>> n
> [(1, 2), (1, 2), (1, 2)]
> >>> id(n[0]) == id(n[1])  == id(n[2])
> True

This is three tuples. Tuples are immutable and you get three
references to the same thing.

> >>> m = [[1,2] for i in range(3)]
> >>> m
> [[1, 2], [1, 2], [1, 2]]
> >>> id(m[0]) == id(m[1])  == id(m[2])
> False
> >>>
>

These are lists. Each one is distinct. You could change one of them
and the other two would remain as they are.

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


Behaviour of pop() for dictionaries

2021-06-14 Thread BlindAnagram
The pop() method exists for five mainstream data items and shows a range 
of different behaviours for each of them.


But, of the five, pop for dictionaries is the only one for which the 
first parameter is required and this makes d.pop() for dictionaries an 
error rather than doing something useful.


I came across this in trying to use this sequence for a dictionary :

  if len(d.keys()) == 1:
v = d.pop()

I found it surprising that this failed given how the pops for the other 
types work.


So I then tried:

  v = d.values()[0]

and this doesn't work either since dict_keys items don't accept 
indexing. So I was driven to use:


  v = list(d.values())[0]

which seems to me a lot less intuitive (and messier) than d.pop().

These:

  v = next(iter(d.values()))
  v, = d.values()

also seem poor substitutes for giving d.pop() for dictionaries a useful 
and intuitive purpose.


Am I missing the obvious way to obtain the value (or the key) from a 
dictionary that is known to hold only one item?


More importantly, is there a good reason why we don't have d.pop() for 
dictionaries?


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


Re: Behaviour of pop() for dictionaries

2021-06-14 Thread BlindAnagram

On 14/06/2021 08:29, Greg Ewing wrote:

On 14/06/21 4:19 am, BlindAnagram wrote:
Am I missing the obvious way to obtain the value (or the key) from a 
dictionary that is known to hold only one item?


v = d.popitem()[1]


Thanks, Greg, I missed that.


More importantly, is there a good reason why we don't have d.pop() for 
dictionaries?


My guess is because it's not generally useful to get an returns the value 
arbitrary
value from a dict without its corresponding key. Hence the existence
of popitem().


However, d.pop(key, [default]) returns the value (or the default) and 
consistency with other pops (a good thing in my view) would suggest that 
d.pop() could return a random value, which would serve my purpose when 
there is only one element.



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


Re: optimization of rule-based model on discrete variables

2021-06-14 Thread Elena via Python-list
Il Mon, 14 Jun 2021 19:39:17 +1200, Greg Ewing ha scritto:

> On 14/06/21 4:15 am, Elena wrote:
>> Given a dataset of X={(x1... x10)} I can calculate Y=f(X) where f is
>> this rule-based function.
>> 
>> I know an operator g that can calculate a real value from Y: e = g(Y)
>> g is too complex to be written analytically.
>> 
>> I would like to find a set of rules f able to minimize e on X.
> 
> There must be something missing from the problem description.
>  From what you've said here, it seems like you could simply find
> a value k for Y that minimises g, regardless of X, and then f would
> consist of a single rule: y = k.
> 
> Can you tell us in more concrete terms what X and g represent?

I see what you mean, so I try to explain it better: Y is a vector say [y1, 
y2, ... yn], with large (n>>10), where yi = f(Xi) with Xi = [x1i, x2i, ... 
x10i] 1<=i<=n. All yi and xji assume discrete values.

I already have a dataset of X={Xi} and would like to find the rules f able 
to minimize a complicated-undifferenciable Real function g(f(X)).
Hope this makes more sense.

x1...x10 are 10 chemical components that can be absent (0), present (1), 
modified (2). yi represent a quality index of the mixtures and g is a 
global quality of the whole process.

Thank you in advance

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


Re: Is there a way to get the following result in Python?

2021-06-14 Thread Chris Angelico
On Tue, Jun 15, 2021 at 5:23 AM Jach Feng  wrote:
>
> >>> def foo():
> ... # do something
> ...
> >>> a = []
> >>> for i in range(3):
> ... a.append(foo())
> ...
> >>> a
> []
> >>>
>

Barring shenanigans like messing with globals, no, there is no way for
a function to return a lack of value. Fundamentally, EVERY expression
in Python has to have a value, and that value must be a single object.
The only exception - pun intended - is if the function doesn't return
at all, eg if "# do something" is "raise Exception". But if that
happens, you won't have the output you're looking for either, unless
you wrap the append in a try/except.

So, no. There is no "return emptiness" concept. You can be 100%
confident that "a.append(foo())" will always append exactly one value,
if the following line of code is indeed executed.

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


Re: Behaviour of pop() for dictionaries

2021-06-14 Thread Chris Angelico
On Tue, Jun 15, 2021 at 5:41 AM BlindAnagram  wrote:
> However, d.pop(key, [default]) returns the value (or the default) and
> consistency with other pops (a good thing in my view) would suggest that
> d.pop() could return a random value, which would serve my purpose when
> there is only one element.
>

Is this actually important or are you just looking for a meaningless
"inconsistency"? Dictionaries are fundamentally different from lists.
Is it really that hard to use popitem?

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


Php vs Python gui (tkinter...) for small remote database app

2021-06-14 Thread Pascal B via Python-list
Hi,
I would like to know if for a small app for instance that requires a connection 
to a remote server database if php is more suitable than Python mainly 
regarding security.
Php requires one port for http and one port for the connection to the database 
open. If using Python with a tkinter gui, I understand a small app can connect 
to a database so only one port to the database would need to be accessed/open 
listening to connection. So I would need to worry less about security if using 
Python over Php for something small, like a small python app that I give over 
to users.

Am I missing something in this assertion?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Where did the message go?

2021-06-14 Thread dn via Python-list
On 15/06/2021 01.00, Grimble wrote:
> I have two machines running Mageia 8 and Python 2.8.9, They use the same
> Python script to maintain a list of changed packages from dnf update and
> dnf install. In addition the script sends a short email message to my
> main email address. The problem is: the message from machine B arrives,
> the message from machine H does not.
> The part of the script that sends the message is:
>    with open('email.txt') as fmail:
>     msg = EmailMessage()
>     msg.set_content(fmail.read())
> 
>     msg['Subject'] = 'System update'
>     msg['From'] = sysname
>     msg['To'] = 'gra...@.' (details removed to protect the
> innocent)
> 
>     # Send the message via our own SMTP server.
>     s = smtplib.SMTP('localhost')
>     s.set_debuglevel(True)
>     s.send_message(msg)
>     s.quit()
> 
> The last lines of s.set_debuglevel are
> reply: retcode (250); Msg: b'2.0.0 Ok: queued as B57B42C042F'
> data: (250, b'2.0.0 Ok: queued as B57B42C042F')
> send: 'quit\r\n'
> reply: b'221 2.0.0 Bye\r\n'
> reply: retcode (221); Msg: b'2.0.0 Bye'
> 
> The SMTP part of the system is working (hence this message).
> The message from machine B correctly interprets "sysname" as
> sysn...@sysname.. i.e a valid addr4ess.
> 
> Where do I look now, please?

That's machine B, but the issue is with machine H.
Have you compared the contents of the two machines' /var/log/maillog?
-- 
Regards,
=dn
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Php vs Python gui (tkinter...) for small remote database app

2021-06-14 Thread dn via Python-list
On 15/06/2021 07.17, Pascal B via Python-list wrote:
> Hi,
> I would like to know if for a small app for instance that requires a 
> connection to a remote server database if php is more suitable than Python 
> mainly regarding security.
> Php requires one port for http and one port for the connection to the 
> database open. If using Python with a tkinter gui, I understand a small app 
> can connect to a database so only one port to the database would need to be 
> accessed/open listening to connection. So I would need to worry less about 
> security if using Python over Php for something small, like a small python 
> app that I give over to users.
> 
> Am I missing something in this assertion?

Yes - or maybe I'm missing the point of your question?

There are two connections to consider: the database and the GUI.


Database:

In each case, the programming-language must make a connection to the
Database Management System. The API, the manner for doing-so may vary
slightly between DBMS-es, but will not particularly between languages.
Thus, if we talk about MySQL/MariaDB, the data which must be exchanged
between language and DBMS is identical (even if the code, and appearance
of the 'variables' differs).

As far as security goes, the different DBMS-publishers have decided, in
their wisdom, to select different IP-ports for communication with their
products (see
https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers). Please
refer to (their, cf Python's) specific documentation to ascertain
security and encryption options.


GUI:

There's a bit of 'chalk and cheese' in this question. PHP is built
around HTML. HTML requires an HTTP server (ignoring the interpreter
built-in to a web-browser). Thus, PHP or Python (likely Python plus
Flask or some other framework) will need to connect to
httpd/Apache/NGINX/etc, in similar fashion to the above. In this case,
the choice of IP-port is more standard - 80 for http and 443 for https.

Whereas tkinter is a module which can be import-ed into a Python
program(me). There is no separate server. Thus no need for an
IP-connection between application and front-end.


The (Internet-connected) world runs on TLS. If you wish to
secure/encrypt communications between application and server, this is
accepted by most. If you wish to 'secure' by reducing inter-connections,
then using tkinter and its tight-linkage to Python removes the need for
the (http) web-server.
-- 
Regards,
=dn
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why the list creates in two different ways? Does it cause by the mutability of its elements? Where the Python document explains it?

2021-06-14 Thread Rob Cliffe via Python-list

This puzzled me, so I played around with it a bit (Python 3.8.3):

n = []
for i in range(3):
    n.append((1,7,-3,None,"x"))
for i in range(3):
    n.append((1,7,-3,None,"x"))
print([id(x) for x in n])

a = 4
n = []
for i in range(3):
    n.append((1,7,-3,a,None,"x"))
for i in range(3):
    n.append((1,7,-3,a,None,"x"))
print([id(x) for x in n])

Output:

[27164832, 27164832, 27164832, 27164832, 27164832, 27164832]
[30065208, 30065496, 30237192, 30239976, 30240024, 30343928]

Evidently the compiler is clever enough to pick out a constant tuple and 
create (or cause to get created) a single instance of it which is used 
when required.  Indeed disassembling the code shows that LOAD_CONST is 
used to get the tuple.  But it obviously can't do that when the tuple 
contains a variable.

Rob Cliffe


On 14/06/2021 20:35, Chris Angelico wrote:

On Tue, Jun 15, 2021 at 5:12 AM Jach Feng  wrote:

n = [(1,2) for i in range(3)]
n

[(1, 2), (1, 2), (1, 2)]

id(n[0]) == id(n[1])  == id(n[2])

True

This is three tuples. Tuples are immutable and you get three
references to the same thing.


m = [[1,2] for i in range(3)]
m

[[1, 2], [1, 2], [1, 2]]

id(m[0]) == id(m[1])  == id(m[2])

False

These are lists. Each one is distinct. You could change one of them
and the other two would remain as they are.

ChrisA


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


Re: Why the list creates in two different ways? Does it cause by the mutability of its elements? Where the Python document explains it?

2021-06-14 Thread Chris Angelico
On Tue, Jun 15, 2021 at 7:11 AM Rob Cliffe via Python-list
 wrote:
>
> This puzzled me, so I played around with it a bit (Python 3.8.3):
>
> n = []
> for i in range(3):
>  n.append((1,7,-3,None,"x"))
> for i in range(3):
>  n.append((1,7,-3,None,"x"))
> print([id(x) for x in n])
>
> a = 4
> n = []
> for i in range(3):
>  n.append((1,7,-3,a,None,"x"))
> for i in range(3):
>  n.append((1,7,-3,a,None,"x"))
> print([id(x) for x in n])
>
> Output:
>
> [27164832, 27164832, 27164832, 27164832, 27164832, 27164832]
> [30065208, 30065496, 30237192, 30239976, 30240024, 30343928]
>
> Evidently the compiler is clever enough to pick out a constant tuple and
> create (or cause to get created) a single instance of it which is used
> when required.  Indeed disassembling the code shows that LOAD_CONST is
> used to get the tuple.  But it obviously can't do that when the tuple
> contains a variable.

Correct. In theory, Python could intern the tuples (as can be done
with strings), noticing that it's constructing one that is identical
to one it already has, but the effort of doing that is hard to
justify. Simpler to just build a brand new tuple every time.

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


Re: Behaviour of pop() for dictionaries

2021-06-14 Thread BlindAnagram

On 14/06/2021 20:43, Chris Angelico wrote:

On Tue, Jun 15, 2021 at 5:41 AM BlindAnagram  wrote:

However, d.pop(key, [default]) returns the value (or the default) and
consistency with other pops (a good thing in my view) would suggest that
d.pop() could return a random value, which would serve my purpose when
there is only one element.



Is this actually important or are you just looking for a meaningless
"inconsistency"? Dictionaries are fundamentally different from lists.
Is it really that hard to use popitem?


No I am not looking for meaningless inconsistency - just the opposite in 
fact - meaningful consistency.


I believe that consistency in how methods common to different types work 
is useful since it adds to the coherence of the language as a whole and 
avoids the need to remember special cases.


No it isn't hard to use popitem() but it evidently proved hard for me to 
remember that it was there.


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


Re: Behaviour of pop() for dictionaries

2021-06-14 Thread dn via Python-list
On 15/06/2021 09.18, BlindAnagram wrote:
> On 14/06/2021 20:43, Chris Angelico wrote:
>> On Tue, Jun 15, 2021 at 5:41 AM BlindAnagram
...

> No it isn't hard to use popitem() but it evidently proved hard for me to
> remember that it was there.

If that's a problem, you're going to love using deques with their
'popping from the left' and 'popping from the right' concepts!


I don't know if you are ComSc student or not, but there isn't even
consistency at the theoretical level. I first arrived at the concept of
"queuing" and "dequeuing" (NB the latter is not the same as the Python
Collections module "deque" library) whilst studying Queue Theory in
Operations Research. At about the same time, my ComSc studies took me
into "stacks".

Queues are known as FIFO constructs - "first-in, first-out".
Stacks are somewhat the opposite: LIFO - "last-in, first-out".

The "pop" operation was defined as taking the "next" item from the queue
or the "last" item from a stack (the opposite of "push"). However,
between queue and stack, the term "next" refers to opposite ends of the
(implementing in Python) list!

In fact, coming from a Burroughs mainframe, which ran on "stack
architecture" (cf IBM's multiplicity of "ALU registers"), it came as
something of a surprise when programming languages started allowing me
to "pop" elements that weren't at the LIFO-end of the 'list', eg
list.pop( 3 ) where len( list ) > 4!


Next consider how the terms "next" and "element" factor into the
thinking. If we consider a (Python) list there is an implied sequence of
elements based upon their relative position. Notice also that the basic
implementation of list.pop() is LIFO! Whereas, the definition of a set
involves no concept of sequence or order - only of membership (and that
the elements are "hashable"). Accordingly, a pop() operation returns an
"arbitrary value", cf 'next please'.

Similarly, a dict's keys are referred-to as hashable, with the idea of
"random access" to an element via its key (cf the "sequential access" of
a list). Thus, we can ask to pop() a dict, but only if we provide a key
- in which case, pop( key ) is the same as dict[ key ] except that the
key-value pair is also removed from the dict!

Recall though, it is possible to use list.pop() without any argument.
So, consistency has been thrown-out-the-window there as well.

Also, with LIFO in-mind, Python v3.7 brought a concept of 'sequence'
(population order) to dicts, and thus we now have this "guarantee" in
popitem() - and thus a memory-confusion for those of us who learned the
original "arbitrary" definition - confusion both of dict behavior and of
dict.popitem() specifically!


Worse confusion awaits (and referring to a conversation 'here' last
week) Python's pop() exhibits elements of both an "expression" and of a
"statement", ie it not only returns a value, but it affects
(?"side-effects") the underlying collection. Thus, no pop() for strings,
tuples, etc, because they are immutable collections!


The action of pop() is clearly inconsistent across types of collection.
It's effect is data-structure dependent because the purposes of those
structures are inherently different. "Consistency" would aid memory, but
"polymorphism" can only deliver functionality according to the
characteristics of the specific data-type!


Having entered the queue-of-life a long time ago, and shuffling ever
closer to 'the end of the line', this memory-challenged 'silver-surfer'
prefers to reserve pop() for straightforward stacks and lists, which
implies quite enough inconsistency, without trying to convolute my mind
to pop()-ing dicts, sets (or 'worse'!).

That said, whether I actually use dict.pop() or not, these 'features'
which are consistent in name but not necessarily in arguments or
effects, contribute to Python's great flexibility and power! Thank
goodness for help() and the Python docs...
-- 
Regards,
=dn
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: optimization of rule-based model on discrete variables

2021-06-14 Thread Richard Damon
On 6/13/21 12:15 PM, Elena via Python-list wrote:
> Hi, I have, say 10 variables (x1 ... x10) which can assume discrete finite 
> values, for instance [0,1 or 2].
> I need to build a set of rules, such as:
>
> 1) if x1==0 and x2==1 and x10==2 then y = 1
> 2) if x2==1 and x3==1 and x4==2 and x6==0 then y = 0
> 3) if x2==0 and x3==1 then y = 2
> 4) if x6==0 and x7==2 then y = 0
> ...
> ...
> (actually it can be seen as a decision tree classifier).
>
> y can assume the same discrete value [0,1 or 2]
> I don't know a-priori anything about the number of rules and the 
> combinations of the tested inputs.
>
> Given a dataset of X={(x1... x10)} I can calculate Y=f(X) where f is this 
> rule-based function.
>
> I know an operator g that can calculate a real value from Y: e = g(Y)
> g is too complex to be written analytically.
>
> I would like to find a set of rules f able to minimize e on X.
>
> I know the problem can become NP-hard, but I would be fine also with a 
> suboptimal solution.
>
> What's the best way to approach the problem?
> In case, does something already exist in python?
>
>
> thank you

My first feeling is that this doesn't have a lot of structure to do a
lot of optimizations, and just brute forcing might be the answer.

Of course, one option is just sort the rules by Y, then iterate through
the rules and see if any data matches, for that putting the dataset into
something like an SQLite database with indexes on the various X columns
might work (with 10 columns, the 45 indexes on each column pair might
make things reasonably efficient.)

The biggest gain would happen if you could look at the rule set and find
patterns in it. The big question is making sure that the rule set covers
every value in the data array, and never gives one input value two
different y values.

-- 
Richard Damon

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


Re: optimization of rule-based model on discrete variables

2021-06-14 Thread Greg Ewing

On 15/06/21 12:51 am, Elena wrote:

I see what you mean, so I try to explain it better: Y is a vector say [y1,
y2, ... yn], with large (n>>10), where yi = f(Xi) with Xi = [x1i, x2i, ...
x10i] 1<=i<=n. All yi and xji assume discrete values.

I already have a dataset of X={Xi} and would like to find the rules f able
to minimize a complicated-undifferenciable Real function g(f(X)).
Hope this makes more sense.


Hmmm, so the problem breaks down into two parts:
(1) find a vector Y that minimises g
(2) find a set of rules that will allow you to predict each component
of Y from its corresponding X values

Is that right?

x1...x10 are 10 chemical components that can be absent (0), present (1), 
modified (2). yi represent a quality index of the mixtures and g is a 
global quality of the whole process.


I ztill don't really understand. What are you going to do with this
function f once you have it?

I would have thought the idea was that if someone gives you a new
mixture X[n+1] you can use f to predict how well it will work.
But that will just give you a y[n+1], and it's not clear what to
do with that. Do you append it to Y and feed an n+1 component
vector into g?

I think I still need more information about the underlying problem
before I can help you much.

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


Re: curses apps on MS Windows?

2021-06-14 Thread Terry Reedy

On 6/13/2021 1:44 PM, Grant Edwards wrote:


Does windows have a terminfo/termcap subsystem to deal with different
terminal types? 


No. AFAIK


Or do the apps only work with the built-in terminal
windows implemented by command.com/cmd.exe?


The windows console is implemented by separate code.  It is used Command 
Prompt, Powershell, Python, and other test-mode console applications.


I can't answer other questions.  I imagine that *nix-like operations, 
one best use WSL? (Windows Subsystem for Linux?) or a Windows Bash 
imitation (Git bash, for instance).  I believe git bash uses the same 
console as its interface.


--
Terry Jan Reedy

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


Re: curses apps on MS Windows?

2021-06-14 Thread jak

Il 13/06/2021 19:44, Grant Edwards ha scritto:

There's been a surprising amount of discussion lately about using
curses libraries on Windows OS. I'm surprised by this, because I don't
think I've ever even seen a Windows curses application.

Are there examples of popular curses applications for Windows?

Does windows have a terminfo/termcap subsystem to deal with different
terminal types? Or do the apps only work with the built-in terminal
windows implemented by command.com/cmd.exe?

Can windows curses apps be used via real serial terminals? Is that
even "a thing" under Windows?

Is there such a thing as a Windows ssh server with some sort of shell
in which one can run console-mode applications?

--
Grant




https://winaero.com/enable-openssh-server-windows-10/
--
https://mail.python.org/mailman/listinfo/python-list


Re: Behaviour of pop() for dictionaries

2021-06-14 Thread Terry Reedy

On 6/14/2021 5:18 PM, BlindAnagram wrote:

I believe that consistency in how methods common to different types work 
is useful since it adds to the coherence of the language as a whole and 
avoids the need to remember special cases.


Each collection class *is* a special case, and pop has to be adjusted to 
each.  However, you seem to have missed an essential commonality.


Lists and dicts are both subscripted classes.  So the basic API is 
col.pop(sub), which removes and returns the sub item, whereas col[sub] 
leaves and returns.


Lists have a special index, -1, the most commonly used, so that is the 
default.  In fact, when I proposed list.pop(), I only proposed that, as 
I wanted pop to be the inverse of append, so a list could be used as a 
stack.


Bad list subscripts are an error (unless one is slicing), whereas where 
dicts allow a default (when subscripted with the get method).  Hence the 
optional default only for dicts.


At one time, dicts, like sets, were unordered collections (of functional 
item pairs). dict.pop(), with no arg, could have been used to return a 
random 2-ple, but Guido is generally against having return types depend 
on arguments. So a new popxxx name was added.  Note that deques have a 
popleft in addition to pop (right).


--
Terry Jan Reedy

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


Re: curses apps on MS Windows?

2021-06-14 Thread Michael Torrie
On 6/13/21 11:44 AM, Grant Edwards wrote:
> There's been a surprising amount of discussion lately about using
> curses libraries on Windows OS. I'm surprised by this, because I don't
> think I've ever even seen a Windows curses application.
> 
> Are there examples of popular curses applications for Windows?

None that I know of, but then again the Windows console was horrible.
With the advent of the new Windows Terminal, Windows 10 now has a
first-class terminal system with all the capabilities of any Unix
terminal. So who knows, maybe curses might actually find a use on
Windows!  MS seems to be giving the idea of terminal applications a bit
of love.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: optimization of rule-based model on discrete variables

2021-06-14 Thread Martin Di Paola
From what I'm understanding it is an "optimization problem" like the 
ones that you find in "linear programming".


But in your case the variables are not Real (they are Integers) and the 
function to minimize g() is not linear.


You could try/explore CVXPY (https://www.cvxpy.org/) which it's a solver 
for different kinds of "convex programming". I don't have experience 
with it however.


The other weapon in my arsenal would be Z3 
(https://theory.stanford.edu/~nikolaj/programmingz3.html) which it's 
a SMT/SAT solver with a built-in extension for optimization problems.


I've more experience with this so here is a "draft" of what you may be 
looking for.



from z3 import Integers, Optimize, And, If

# create a Python array X with 3 Z3 Integer variables named x0, x1, x2
X = Integers('x0 x1 x2')
Y = Integers('y0 y1')

# create the solver
solver = Optimize()

# add some restrictions like lower and upper bounds
for x in X:
  solver.add(And(0 <= x, x <= 2)) # each x is between 0 and 2
for y in Y:
  solver.add(And(0 <= y, y <= 2))

def f(X):
  # Conditional expression can be modeled too with "If"
  # These are *not* evaluated like a normal Python "if" but
  # modeled as a whole. It'll be the solver which will "run it"
  return If(
And(x[0] == 0, x[1] == 0),  # the condition
Y[0] == 0,  # Y[0] will *must* be 0 *if* the condition holds
Y[0] == 2   # Y[0] will *must* be 2 *if* the condition doesn't hold
)

solver.add(f(X))

# let's define the function to optimize
g = Y[0]**2
solver.maximize(g)

# check if we have a solution
solver.check() # this should return 'sat'

# get one of the many optimum solutions
solver.model()


I would recommend you to write a very tiny problem with 2 or 3 variables 
and a very simple f() and g() functions, make it work (manually and with 
Z3) and only then build a more complex program.


You may find useful (or not) these two posts that I wrote a month ago 
about Z3. These are not tutorials, just personal experience with 
a concrete example.


Combine Real, Integer and Bool variables:
https://book-of-gehn.github.io/articles/2021/05/02/Planning-Space-Missions.html

Lookup Tables (this may be useful for programming a f() "variable" 
function where the code of f() (the decision tree) is set by Z3 and not 
by you such f() leads to the optimum of g())

https://book-of-gehn.github.io/articles/2021/05/26/Casting-Broadcasting-LUT-and-Bitwise-Ops.html


Happy hacking.
Martin.


On Mon, Jun 14, 2021 at 12:51:34PM +, Elena via Python-list wrote:

Il Mon, 14 Jun 2021 19:39:17 +1200, Greg Ewing ha scritto:


On 14/06/21 4:15 am, Elena wrote:

Given a dataset of X={(x1... x10)} I can calculate Y=f(X) where f is
this rule-based function.

I know an operator g that can calculate a real value from Y: e = g(Y)
g is too complex to be written analytically.

I would like to find a set of rules f able to minimize e on X.


There must be something missing from the problem description.
 From what you've said here, it seems like you could simply find
a value k for Y that minimises g, regardless of X, and then f would
consist of a single rule: y = k.

Can you tell us in more concrete terms what X and g represent?


I see what you mean, so I try to explain it better: Y is a vector say [y1,
y2, ... yn], with large (n>>10), where yi = f(Xi) with Xi = [x1i, x2i, ...
x10i] 1<=i<=n. All yi and xji assume discrete values.

I already have a dataset of X={Xi} and would like to find the rules f able
to minimize a complicated-undifferenciable Real function g(f(X)).
Hope this makes more sense.

x1...x10 are 10 chemical components that can be absent (0), present (1),
modified (2). yi represent a quality index of the mixtures and g is a
global quality of the whole process.

Thank you in advance

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

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


Re: curses apps on MS Windows?

2021-06-14 Thread Eryk Sun
On 6/13/21, Grant Edwards  wrote:
>
> Are there examples of popular curses applications for Windows?

I don't think are any popular examples. The port of the "nano" editor
uses ncurses.

https://github.com/lhmouse/nano-win

IIRC, PDCurses has better support -- e.g. 256 colors and blinking
under Windows 10 or ConEmu. The Windows ports of Python's curses
module that I know of are based on PDCurses.

> Does windows have a terminfo/termcap subsystem to deal with different
> terminal types?

No, but in Windows 10 the virtual-terminal mode of the console
emulates xterm256-color:

https://github.com/microsoft/terminal/issues/2958
https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences

The console host (i.e. conhost.exe, or the open-source build
OpenConsole.exe) supports a headless mode (ConPTY / pseudconsole),
which is what Windows Terminal and the sshd server use. Terminal
support is handled by the host, which defaults to enabling
virtual-terminal mode in a headless session.

The console host process sits in the middle between client
applications and the terminal application or service that created the
console session. For example, each tab in Windows Terminal is a
headless console session that's hosted by a separate instance of
OpenConsole.exe.

Applications are unaware that it's a headless session. They request
the normal read/write/IOCTL operations on console files, which are
provided by the console driver, i.e. condrv.sys in the kernel. The
driver in turn talks to the attached console host. If it's a ConPTY
session, the host talks to the service or terminal application that
created the console session, e.g. WindowsTerminal.exe.

Classically, or without ConPTY, the console host provides a builtin
terminal/console interface, which is what most people are used to in
Windows and what many people confuse with cmd.exe.

Alternate terminals such as ConEmu have existed for a long time, but
prior to ConPTY support their implementation was a pile of hacks. The
terminal had to attach to the console host to read the console's input
and screen buffers and poll the screen for changes, and even inject a
DLL in client applications to hook various API calls.

> Is there such a thing as a Windows ssh server with some sort of shell
> in which one can run console-mode applications?

I've used third-party SSH servers in the past, but Windows 10 includes
an ssh server and client. The sshd.exe server launches a headless
console session, which by default runs an instance of the cmd.exe
shell.

Installation:
https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse

> Or do the apps only work with the built-in terminal
> windows implemented by command.com/cmd.exe?

cmd.exe is a shell that uses standard I/O. It's not a terminal or
console. It's fundamentally no different from the REPL shell that's
implemented by python.exe, except the cmd.exe shell and batch
scripting language make it relatively easier to administrate the
machine and run programs.

COMMAND.COM is a 16-bit DOS shell from the 1980s and 1990s. Most
people may as well forget about COMMAND.COM, unless they're fascinated
with relics from the 80s.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cant find sorcecode

2021-06-14 Thread Dan Stromberg
I don't know where your source code is specifically, but here's an example
of looking up where a file lives:

$ python3
below cmd output started 2021 Mon Jun 14 09:05:54 PM PDT
Python 3.7.3 (default, Jan 22 2021, 20:04:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import heapq
>>> heapq.__file__
'/usr/lib/python3.7/heapq.py'
>>>


On Mon, Jun 14, 2021 at 12:04 PM Madden  wrote:

>
>
>Hi so I've been trying to find my sorcecode files so I can 7zip them to
>get to the ovl_tool_gui so I can add mods but I haven't been able to
> find
>them could you help?
>
>
>
>
>
>Sent from [1]Mail for Windows 10
>
>
>
> References
>
>Visible links
>1. https://go.microsoft.com/fwlink/?LinkId=550986
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is there a way to get the following result in Python?

2021-06-14 Thread Cameron Simpson
On 11Jun2021 19:02, Jach Fong  wrote:
 def foo():
>... # do something
>...
 a = []
 for i in range(3):
>... a.append(foo())
>...
 a
>[]


Chris has explained that what you've written will never do it. But if 
instead you wanted to filter out None results, getting an empty list 
from the filter, then the filter() builtin function will do you.

First, as Chris alluded to, all functions return values. Those with a 
"bare" return (no expression) or which just fall off the end of the 
function body actaully return None.

There's the obvious:

a = []
for i in range(3):
item = foo()
if item is not None:
a.append(item)

Using a filter...  "help(filter)" says:

>>> help(filter)
Help on class filter in module builtins:

class filter(object)
 |  filter(function or None, iterable) --> filter object
 |
 |  Return an iterator yielding those items of iterable for which 
function(item)
 |  is true. If function is None, return the items that are true.
 |
 |  Methods defined here:
 |
 |  __getattribute__(self, name, /)
 |  Return getattr(self, name).
 |
 |  __iter__(self, /)
 |  Implement iter(self).
 |
 |  __next__(self, /)
 |  Implement next(self).
 |
 |  __reduce__(...)
 |  Return state information for pickling.
 |
 |  --
 |  Static methods defined here:
 |
 |  __new__(*args, **kwargs) from builtins.type
 |  Create and return a new object.  See help(type) for accurate 
signature.

which is more that I expected. Usage:

a = list(filter(lambda item: item is not None, items))

where items is the various returns from foo().

Or you could just write a list comprehension directly:

a = [ item for item in items if items is not None ]

You want items to be your calls to foo(). Eg:

a = [ item for item in (foo() for _ in range(3)) if items is not None ]

The (expression for name in iterable) is a generator expression. Like a 
list comprehension but it is a generator - it only runs as it is 
consumed. A list comprehension makes an actual list (stores all the 
results in the list).

Cheers,
Cameron Simpson 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is there a way to get the following result in Python?

2021-06-14 Thread Peter Otten

On 12/06/2021 04:02, Jach Feng wrote:


def foo():

... # do something
...

a = []
for i in range(3):

... a.append(foo())
...

a

[]


The most natural way to achieve something similar is to replace append() 
with extend():


>>> def foo(): return ()

>>> a = []
>>> for i in range(3):
a.extend(foo())


>>> a
[]



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