Re: Discerning "Run Environment"

2022-05-18 Thread Eryk Sun
On 5/18/22, Chris Angelico  wrote:
>
> Real solution? Set the command prompt to codepage 65001. Then it
> should be able to handle all characters. (Windows-65001 is its alias
> for UTF-8.)

I suggest using win_unicode_console for Python versions prior to 3.6:

https://pypi.org/project/win_unicode_console

This package uses the console's native 16-bit character support with
UTF-16 text, as does Python 3.6+. Compared to the console's incomplete
and broken support for UTF-8, the console's support for UTF-16 (or
just UCS-2 prior to Windows 10) is far more functional and reliable
across commonly used versions of Windows 7, 8, and 10.

Reading console input as UTF-8 is still limited to ASCII up to and
including Windows 11, which for me is a showstopper. Non-ASCII
characters are read as null bytes, which is useless. Support for
writing UTF-8 to the console screen buffer is implemented correctly in
recent builds of Windows 10 and 11, and mostly correct in Windows 8.
Prior to Windows 8, writing UTF-8 to the console is badly broken. It
returns the number of UTF-16 codes written instead of the number of
bytes written, which confuses buffered writers into writing a lot of
junk to the screen.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python & nmap

2022-05-18 Thread Jon Ribbens via Python-list
On 2022-05-18, ^Bart  wrote:
> THE INPUT
> -
> import nmap
> nm.scan(hosts='192.168.205.0/24', arguments='-n -sP -PE -PA21,23,80,3389')
> hosts_list = [(x, nm[x]['status']['state']) for x in nm.all_hosts()]
> for host, status in hosts_list:
>   print('{0}:{1}'.host)
>
> THE OUTPUT
> -
> Traceback (most recent call last):
>File "/home/gabriele/Documenti/Python/nmap.py", line 1, in 
>  import nmap
>File "/home/gabriele/Documenti/Python/nmap.py", line 2, in 
>  nm.scan(hosts='192.168.205.0/24', arguments='-n -sP -PE 
> -PA21,23,80,3389')
> NameError: name 'nm' is not defined

You forgot the second line (after 'import nmap' and before 'nm.scan()'):

nm = nmap.PortScanner()

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


Python & nmap

2022-05-18 Thread ^Bart

Hi guys,

i need to copy some files from a Debian client to all linux embedded 
clients.


I know the linux commands like:

# scp "my_file" root@192.168.205.x/my_directory

But... I have to upload 100 devices, I have a lan and a dhcp server just 
for this work and I'd like to make a script by Python which can:


1) To scan the lan
2) To find which ips are "ready"
3) To send files to all of the "ready" clients
4) After I see on the display of these clients the successfully update I 
remove from the lan them and I put them to the box to send them to our 
customers.


I found https://pypi.org/project/python-nmap/ and I followed the line 
"To check the network status" but... it doesn't work.


THE INPUT
-
import nmap
nm.scan(hosts='192.168.205.0/24', arguments='-n -sP -PE -PA21,23,80,3389')
hosts_list = [(x, nm[x]['status']['state']) for x in nm.all_hosts()]
for host, status in hosts_list:
 print('{0}:{1}'.host)

THE OUTPUT
-
Traceback (most recent call last):
  File "/home/gabriele/Documenti/Python/nmap.py", line 1, in 
import nmap
  File "/home/gabriele/Documenti/Python/nmap.py", line 2, in 
nm.scan(hosts='192.168.205.0/24', arguments='-n -sP -PE 
-PA21,23,80,3389')

NameError: name 'nm' is not defined

Regards.
^Bart
--
https://mail.python.org/mailman/listinfo/python-list


Re: Convert the decimal numbers expressed in a `numpy.ndarray` into a matrix representing elements in fractional form

2022-05-18 Thread Cousin Stanley

#!/usr/bin/env python3

'''
NewsGroup  comp.lang.python

Subject .. Convert the decimal numbers
   expressed in a numpy.ndarray
   into a matrix representing elements
   in fractiona

Date . 2022-05-16

Post_By .. hongy...

Edit_By .. Stanley C. Kitching
'''

import numpy as np

from fractions import Fraction

b = [
  [ 0.0 , -1.0 , 0.0 , 0.25 ] ,
  [ 1.0 ,  0.0 , 0.0 , 0.25 ] ,
  [ 0.0 ,  0.0 , 1.0 , 0.25 ] ,
  [ 0.0 ,  0.0 , 0.0 , 1.0  ] ]

a = [ ]

print( '\n  b  \n' )

for row in b :
arow = []
print( '' , row )

for dec_x in row :
frac_x = Fraction( dec_x )
arow.append( frac_x )

a.append( arow )


# using f-string format

print( '\n  a  \n' )

for row in a :

for item in row :

print( f'{item} ' , end = '' )

print()

# --

--
Stanley C. Kitching
Human Being
Phoenix, Arizona
--
https://mail.python.org/mailman/listinfo/python-list


[Python-announce] ANN: SciPy 1.8.1

2022-05-18 Thread Tyler Reddy
Hi all,

On behalf of the SciPy development team, I'm pleased to announce the
release of SciPy 1.8.1, which is a bug fix release that restores
Pythran usage on Windows.

Sources and binary wheels can be found at:
https://pypi.org/project/scipy/ and at:
https://github.com/scipy/scipy/releases/tag/v1.8.1

One of a few ways to install this release with pip:
pip install scipy==1.8.1

=
SciPy 1.8.1 Release Notes
=

SciPy 1.8.1 is a bug-fix release with no new features
compared to 1.8.0. Notably, usage of Pythran has been
restored for Windows builds/binaries.

Authors
==

* Henry Schreiner
* Maximilian Nöthe
* Sebastian Berg (1)
* Sameer Deshmukh (1) +
* Niels Doucet (1) +
* DWesl (4)
* Isuru Fernando (1)
* Ralf Gommers (4)
* Matt Haberland (1)
* Andrew Nelson (1)
* Dimitri Papadopoulos Orfanos (1) +
* Tirth Patel (3)
* Tyler Reddy (46)
* Pamphile Roy (7)
* Niyas Sait (1) +
* H. Vetinari (2)
* Warren Weckesser (1)

A total of 17 people contributed to this release.
People with a "+" by their names contributed a patch for the first time.
This list of names is automatically generated, and may not be fully
complete.

Issues closed for 1.8.1
---

* `#15258 `__: BUG: sparse
\`dot\` method should accept scalars
* `#15433 `__: BUG: optimize:
minimize: \`ValueError\` when \`np.all(lb==ub)\`
* `#15539 `__: BUG:
Questionable macOS wheel contents
* `#15543 `__: REL: list
contributors using GitHub handles
* `#15552 `__: BUG: MacOS
universal2 wheels have two gfortran shared libraries,...
* `#15636 `__: BUG: DOCS
incorrect \`source\` link on docs
* `#15678 `__: BUG:
scipy.stats.skew does not work with scipy.stats.bootstrap
* `#16174 `__: Failure of
\`TestCorrelateComplex.test_rank0\` in CI with NumPy...


Pull requests for 1.8.1
--

* `#15167 `__: CI: make sure CI
stays on VS2019 unless changed explicitly
* `#15306 `__: Revert "BLD
Respect the --skip-build flag in setup.py"
* `#15504 `__: MAINT: np.all(lb
== ub) for optimize.minimize
* `#15530 `__: REL: prep for
SciPy 1.8.1
* `#15531 `__: [BUG] Fix
importing scipy.lib._pep440
* `#15558 `__: CI: re-enable
Pythran in Azure Windows CI jobs
* `#15566 `__: BUG: fix error
message
* `#15580 `__: BUG: Avoid C
Preprocessor symbol in _hypotests_pythran.py.
* `#15614 `__: REL: filter out @
in authors name and add count
* `#15637 `__: DOC, MAINT: fix
links to wrapped functions and SciPy's distributions
* `#15669 `__: BUG: stats: fix a
bug in UNU.RAN error handler
* `#15691 `__: MAINT: stats:
bootstrap: fix bug with \`method="BCa"\` when \`statistic\`...
* `#15798 `__: MAINT,BUG: stats:
update to UNU.RAN 1.9.0
* `#15870 `__: TST: signal:
Convert a test with 'assert_array_less' to 'less...
* `#15910 `__: make sure CI
stays on VS2019 unless changed explicitly
* `#15926 `__: MAINT: 1.8.1
backports/prep
* `#16035 `__: BUG: allow scalar
input to the \`.dot\` method of sparse matrices
* `#16041 `__: MAINT: add
include dir explicitly for PROPACK to build with classic...
* `#16139 `__: WIP, BLD, MAINT:
git security/version shim
* `#16152 `__: TST: Fortify
invalid-value warning filters to small changes in...
* `#16155 `__: MAINT: correct
wrong license of Biasedurn
* `#16158 `__: MAINT: better
UNU.RAN licensing information
* `#16163 `__: MAINT: update
UNU.RAN copyright information
* `#16172 `__: CI: pin Pip to
22.0.4 to avoid issues with \`--no-build-isolation\`
* `#16175 `__: TST: fix test
failure due to changes in numpy scalar behavior.


Checksums
=

MD5
~~~


Re: tail

2022-05-18 Thread Cameron Simpson
On 17May2022 22:45, Marco Sulla  wrote:
>Well, I've done a benchmark.
 timeit.timeit("tail('/home/marco/small.txt')", globals={"tail":tail}, 
 number=10)
>1.5963431186974049
 timeit.timeit("tail('/home/marco/lorem.txt')", globals={"tail":tail}, 
 number=10)
>2.5240604374557734
 timeit.timeit("tail('/home/marco/lorem.txt', chunk_size=1000)", 
 globals={"tail":tail}, number=10)
>1.8944984432309866

This suggests that the file size does not dominate uour runtime. Ah.  
_Or_ that there are similar numbers of newlines vs text in the files so 
reading similar amounts of data from the end. If the "line desnity" of 
the files were similar you would hope that the runtimes would be 
similar.

>small.txt is a text file of 1.3 KB. lorem.txt is a lorem ipsum of 1.2
>GB. It seems the performance is good, thanks to the chunk suggestion.
>
>But the time of Linux tail surprise me:
>
>marco@buzz:~$ time tail lorem.txt
>[text]
>
>real0m0.004s
>user0m0.003s
>sys0m0.001s
>
>It's strange that it's so slow. I thought it was because it decodes
>and print the result, but I timed

You're measuring different things. timeit() tries hard to measure just 
the code snippet you provide. It doesn't measure the startup cost of the 
whole python interpreter. Try:

time python3 your-tail-prog.py /home/marco/lorem.txt

BTW, does your `tail()` print output? If not, again not measuring the 
same thing.

If you have the source of tail(1) to hand, consider getting to the core 
and measuring `time()` immediately before and immediately after the 
central tail operation and printing the result.

Also: does tail(1) do character set / encoding stuff? Does your Python 
code do that? Might be apples and oranges.

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


Re: Issue sending data from C++ to Python

2022-05-18 Thread Christian Gollwitzer

Am 18.05.22 um 16:08 schrieb Pablo Martinez Ulloa:

I have been using your C++ Python API, in order to establish a bridge from
C++ to Python. We want to do this, as we have a tactile sensor, which only
has a library developed in C++, but we want to obtain the data in real time
in Python to perform tests with a robotic arm and gripper. The problem we
are facing is with transmitting the data into Python. We are using the
function Py_BuildValue, and it seems to be working, but only for sending
one value at a time, and we want to transmit 54 numbers


The usual way to pass an array of numbers into Python is by means of a 
Numpy Array. In order to do that, you need to include arrayobject.h and 
then use PyArray_SimpleNew to create an array of numbers as a Python 
object which you can return 
https://numpy.org/devdocs/reference/c-api/array.html#c.PyArray_SimpleNew



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


Re: Issue sending data from C++ to Python

2022-05-18 Thread MRAB

On 2022-05-18 15:08, Pablo Martinez Ulloa wrote:

Hello,

I have been using your C++ Python API, in order to establish a bridge from
C++ to Python. We want to do this, as we have a tactile sensor, which only
has a library developed in C++, but we want to obtain the data in real time
in Python to perform tests with a robotic arm and gripper. The problem we
are facing is with transmitting the data into Python. We are using the
function Py_BuildValue, and it seems to be working, but only for sending
one value at a time, and we want to transmit 54 numbers. When
transmitting a single value retrieved from the sensor into Python in a
double or string format, it works, but when we make the string bigger it
gives us an error with the utf-8 encoding. Also when sending a tuple of
doubles or strings, it works when the tuple is composed of a single
element, but not when we send 2 or more values. Is there any way of fixing
this issue? Or is it just not possible to transmit such a large amount of
data?


I find it easier if I have some code in front of me to 'criticise'!

Have you thought about building and returning, say, a list instead?

/* Error checking omitted. */
PyObject* list;
list = PyList_New(0);
PyList_Append(list, PyLong_FromSsize_t(1));
PyList_Append(list, PyFloat_FromDouble(2.0));
...
--
https://mail.python.org/mailman/listinfo/python-list


Re: Request for assistance (hopefully not OT)

2022-05-18 Thread Loris Bennett
Chris Angelico  writes:

> On Wed, 18 May 2022 at 04:05, Loris Bennett  
> wrote:
>>
>> [snip (26 lines)]
>>
>> > I think you had a problem before that.  Debian testing is not an
>> > operating system you should be using if you have a fairly good
>> > understanding of how Debian (or Linux in general) works.
>>
>> Should be
>>
>>   I think you had a problem before that.  Debian testing is not an
>>   operating system you should be using *unless* you have a fairly good
>>   understanding of how Debian (or Linux in general) works.
>>
>> [snip (62 lines)]
>>
>
> Oh! My bad, didn't see this correction, sorry. With this adjustment,
> the comment is a bit more reasonable, although I'd still say it's
> generally fine to run Debian Testing on a personal desktop machine;
> there are a number of distros that base themselves on Testing.
>
> But yes, "unless" makes much more sense there.

It's lucky I never got "if" and "unless" mixed up when I used to program
in Perl ;-)

Yes, there are a number of distros based on Debian Testing, but those
tend to be aimed more at sysadmins (e.g. Kali and Grml) than people just
starting out with Linux.  However, with plain old Debian Testing you
need to be able to deal with things occasionally not working properly.
As the Debian people say about Testing: "If it doesn't work for you,
then there's a good chance it's broken."  And that's even before you
delete part of the OS with 'rm'.

Cheers,

Loris

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


Re: Convert the decimal numbers expressed in a `numpy.ndarray` into a matrix representing elements in fractional form

2022-05-18 Thread Dennis Lee Bieber
On Tue, 17 May 2022 17:20:54 +0100, MRAB 
declaimed the following:

>As it's just a simple replacement, I would've thought that the 'obvious' 
>solution would be:
> a = a.replace("'", "")

Mea culpa...

Guess it's time for me to review the library reference for basic data
types again. I'm so used to the .join(.split()) (usually for other purposes
-- like a quick TSV/CSV formatting without importing the csv module).
The only firm item is that I do not look at any regular expression module
if I can come up with something using native data type methods -- and using
the overhead of re with just simple text [ie; nothing that might be called
an "expression" designed to match /varying/ content) seems really
inefficient.


-- 
Wulfraed Dennis Lee Bieber AF6VN
wlfr...@ix.netcom.comhttp://wlfraed.microdiversity.freeddns.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: tail

2022-05-18 Thread Marco Sulla
Well, I've done a benchmark.

>>> timeit.timeit("tail('/home/marco/small.txt')", globals={"tail":tail}, 
>>> number=10)
1.5963431186974049
>>> timeit.timeit("tail('/home/marco/lorem.txt')", globals={"tail":tail}, 
>>> number=10)
2.5240604374557734
>>> timeit.timeit("tail('/home/marco/lorem.txt', chunk_size=1000)", 
>>> globals={"tail":tail}, number=10)
1.8944984432309866

small.txt is a text file of 1.3 KB. lorem.txt is a lorem ipsum of 1.2
GB. It seems the performance is good, thanks to the chunk suggestion.

But the time of Linux tail surprise me:

marco@buzz:~$ time tail lorem.txt
[text]

real0m0.004s
user0m0.003s
sys0m0.001s

It's strange that it's so slow. I thought it was because it decodes
and print the result, but I timed

timeit.timeit("print(tail('/home/marco/lorem.txt').decode('utf-8'))",
globals={"tail":tail}, number=10)

and I got ~36 seconds. It seems quite strange to me. Maybe I got the
benchmarks wrong at some point?
-- 
https://mail.python.org/mailman/listinfo/python-list


Issue sending data from C++ to Python

2022-05-18 Thread Pablo Martinez Ulloa
Hello,

I have been using your C++ Python API, in order to establish a bridge from
C++ to Python. We want to do this, as we have a tactile sensor, which only
has a library developed in C++, but we want to obtain the data in real time
in Python to perform tests with a robotic arm and gripper. The problem we
are facing is with transmitting the data into Python. We are using the
function Py_BuildValue, and it seems to be working, but only for sending
one value at a time, and we want to transmit 54 numbers. When
transmitting a single value retrieved from the sensor into Python in a
double or string format, it works, but when we make the string bigger it
gives us an error with the utf-8 encoding. Also when sending a tuple of
doubles or strings, it works when the tuple is composed of a single
element, but not when we send 2 or more values. Is there any way of fixing
this issue? Or is it just not possible to transmit such a large amount of
data?

Thank you.
Best regards,

*Pablo Martinez Ulloa*
PhD Candidate,
School of Electrical and Electronic Engineering, R324A
University College Dublin, Belfield, Dublin 4, Ireland
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Discerning "Run Environment"

2022-05-18 Thread Chris Angelico
On Wed, 18 May 2022 at 19:40, Stephen Tucker  wrote:
>
> Hi,
>
> I am a Windows 10 user still using Python 2.x (for good reasons, I assure
> you.)
>
> I have a Python 2.x module that I would like to be able to use in a variety
> of Python 2.x programs. The module outputs characters to the user that are
> only available in the Unicode character set.
>
> I have found that the selection of characters in that set that are
> available to my software depends on whether, for example, the program is
> being run during an IDLE session or at a Command Prompt.

Real solution? Set the command prompt to codepage 65001. Then it
should be able to handle all characters. (Windows-65001 is its alias
for UTF-8.)

> I am therefore needing to include logic in this module that (a) enables it
> to output appropriate characters depending on whether it is being run
> during an IDLE session or at a command prompt, and (b) enables it to
> discern which of these two "run environments" it is running in.
>
> Goal (a) is achieved easily by using string.replace to replace unavailable
> characters with available ones where necessary.
>
> The best way I have found so far to achieve goal (b) is to use sys.modules
> and ascertain whether any modules contain the string "idlelib". If they do,
> that I assume that the software is being run in an IDLE session.
>
> I suspect that there is a more Pythonic (and reliable?) way of achieving
> goal (b).
>
> Can anyone please tell me if there is, and, if there is, what it is?

Ultimately, it's going to depend on where your text is going: is it
going to the console, or to a Tk widget? I don't have a Windows system
handy to check, but I would suspect that you can distinguish these by
seeing whether sys.stdout is a tty, since Idle pipes stdout into its
own handler. That won't be a perfect check, as it would consider
"piped into another command" to be UTF-8 compatible, but that's
probably more right than wrong anyway.

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


Discerning "Run Environment"

2022-05-18 Thread Stephen Tucker
Hi,

I am a Windows 10 user still using Python 2.x (for good reasons, I assure
you.)

I have a Python 2.x module that I would like to be able to use in a variety
of Python 2.x programs. The module outputs characters to the user that are
only available in the Unicode character set.

I have found that the selection of characters in that set that are
available to my software depends on whether, for example, the program is
being run during an IDLE session or at a Command Prompt.

I am therefore needing to include logic in this module that (a) enables it
to output appropriate characters depending on whether it is being run
during an IDLE session or at a command prompt, and (b) enables it to
discern which of these two "run environments" it is running in.

Goal (a) is achieved easily by using string.replace to replace unavailable
characters with available ones where necessary.

The best way I have found so far to achieve goal (b) is to use sys.modules
and ascertain whether any modules contain the string "idlelib". If they do,
that I assume that the software is being run in an IDLE session.

I suspect that there is a more Pythonic (and reliable?) way of achieving
goal (b).

Can anyone please tell me if there is, and, if there is, what it is?

Thanks.

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