Re: Simple question - end a raw string with a single backslash ?

2020-10-19 Thread Antoon Pardon



Op 13/10/20 om 15:14 schreef Serhiy Storchaka:

13.10.20 11:52, Tony Flury via Python-list пише:

I am trying to write a simple expression to build a raw string that ends
in a single backslash. My understanding is that a raw string should
ignore attempts at escaping characters but I get this :

     >>> a = r'end\'
       File "", line 1
         a = r'end\'
       ^
    SyntaxError: EOL while scanning string literal

I interpret this as meaning that the \' is actually being interpreted as
a literal quote - is that a bug ?


r'You can\'t end raw string literal with a single "\"'

If backslash be true inner in a raw string, the above literal would end
after \'. It would be very hard to write a raw string containing both \'
and \", and even \''' and \""" (there are such strings in the stdlib).

So you have problem either with trailing backslash, or with inner
backslash followed by quotes. Both problems cannot be solved at the same
time. Python parser works as it works because initially it was easier to
implement, and now this cannot be changed because it would break some
amount of correct code.


IMO the way python does this is broken.

>>> st=r'You can\'t end raw string literal with a single "\"'
>>> print(st)

Now either the \ is special or it is not.

1) If it is special, it should change how the ' is treated but not 
appear itself.


2) If it is not special, it should just appear and not change how the ' 
is treated.


What python does here is a combination of both. The \ appears and it
changes how the ' is treated. That is IMO broken.

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


Re: Simple question - end a raw string with a single backslash ?

2020-10-19 Thread Stephen Tucker
For a neatish way to get a string to end with a single backslash, how about
   mystr = r"abc\ "[:-1]
(Note the space at the end of the rough-quoted string.)



Virus-free.
www.avast.com

<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

On Mon, Oct 19, 2020 at 9:26 AM Antoon Pardon  wrote:

>
>
> Op 13/10/20 om 15:14 schreef Serhiy Storchaka:
> > 13.10.20 11:52, Tony Flury via Python-list пише:
> >> I am trying to write a simple expression to build a raw string that ends
> >> in a single backslash. My understanding is that a raw string should
> >> ignore attempts at escaping characters but I get this :
> >>
> >>  >>> a = r'end\'
> >>File "", line 1
> >>  a = r'end\'
> >>^
> >> SyntaxError: EOL while scanning string literal
> >>
> >> I interpret this as meaning that the \' is actually being interpreted as
> >> a literal quote - is that a bug ?
> >
> > r'You can\'t end raw string literal with a single "\"'
> >
> > If backslash be true inner in a raw string, the above literal would end
> > after \'. It would be very hard to write a raw string containing both \'
> > and \", and even \''' and \""" (there are such strings in the stdlib).
> >
> > So you have problem either with trailing backslash, or with inner
> > backslash followed by quotes. Both problems cannot be solved at the same
> > time. Python parser works as it works because initially it was easier to
> > implement, and now this cannot be changed because it would break some
> > amount of correct code.
>
> IMO the way python does this is broken.
>
>  >>> st=r'You can\'t end raw string literal with a single "\"'
>  >>> print(st)
>
> Now either the \ is special or it is not.
>
> 1) If it is special, it should change how the ' is treated but not
> appear itself.
>
> 2) If it is not special, it should just appear and not change how the '
> is treated.
>
> What python does here is a combination of both. The \ appears and it
> changes how the ' is treated. That is IMO broken.
>
> --
> Antoon Pardon.
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Embedding version in command-line program

2020-10-19 Thread Loris Bennett
Tony Flury  writes:

> On 07/10/2020 12:06, Loris Bennett wrote:
>> Hi,
>>
>> I have written a program, which I can run on the command-line thus
>>
>>mypyprog --version
>>
>> and the get the version, which is currently derived from a variable in
>> the main module file.
>>
>> However, I also have the version in an __init__.py file and in a
>> pyproject.toml (as I'm using poetry, otherwise this would be in
>> setup.py).
>>
>> What's the best way of reducing these three places where the version is
>> defined to a single one?
>>
>> Cheers,
>>
>> Loris

> My top level package always has a version.py file which defines __version__,
> __author__ etc. I am not sure if that helps in your .toml file though - is it
> executed or does it have the ability to read files when it creates the
> distributable ?

The problem is that the .toml file is not by default part of the
distribution, but AFAIU is intended to store the project metadata used
to create the METADATA file in dist-info when the package is built.
Thus, the version defined in the .toml file is not directly available to
the module itself.

It seems to me, as a python novice, that poetry's function 'version'
needs to be extended.  One possibility is that it should not only bump
the version in the .toml file, but also bump the version in a version
file like 'version.py' as well.  Alternatively, the value of the key
'version' in the .toml file, if it is not the version itself,  could be
path to a file, such as a 'version.py', which holds the version.

If that sounds reasonable, I could suggest it to the developers of
poetry.

Cheers,

Loris

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


RE: Are there Python ways to execute queries on PostgreSQL without getting data over?

2020-10-19 Thread David Raymond


> Are there Python ways to execute queries on PostgreSQL without getting data 
> over?
> 
> Are there ways just to fire off PostgreSQL queries and not get data into 
> Python?
> 
> Regards,
> 
> David

What is your use case for this? Normally when you do basic things like an 
UPDATE/DELETE, etc all you get back is a row count of how many records the 
statement updated/deleted. Normally SELECT is the only thing to send a bunch of 
data back to you, and well, why would you run selects if you don't care about 
the output?

Without knowing what you're doing it for, the only other option I could suggest 
might be to use EXPLAIN ANALYZE. That would still send back the EXPLAIN ANALYZE 
output. But it will actually run the query, and if the output would have been 
thousands/millions of rows, then the explain output is going to be a lot 
smaller.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Covariance matrix syntax

2020-10-19 Thread Markos

Hi Meghna,

I organized some tutorials about Machine Learning for Chemistry with Python.

Where you can find some info about the use of Covariance Matrix that may 
help you.


The originals are in Portugueese, but you can read using Google Translator:

https://tinyurl.com/yybazx9n

https://tinyurl.com/y29mule6

https://tinyurl.com/yxtg4tce

Best Regards,
Markos

Em 19-10-2020 02:23, Meghna Karkera escreveu:

Dear Sir

I am unable to find the *formula for covariance* used in np.cov syntax in
PYTHON given in link
https://numpy.org/doc/stable/reference/generated/numpy.cov.html.  Could you
please help me out.

Thanks
Meghna

On Tue, Oct 13, 2020 at 11:46 AM Christian Gollwitzer 
wrote:


Am 13.10.20 um 06:52 schrieb Meghna Karkera:

Could you let me know what is the back end calculation of this covariance
matrix syntax np.cov


You can look it up yourself: Go to the docs
https://numpy.org/doc/stable/reference/generated/numpy.cov.html

At the right hand side, just right of the function signature, there is a
link [source]. Click there and it takes you to the implementation.

Apparently it is done in straightforward Python.

 Christian

PS: Snipped a lot of unrelated citation at the bottom


On Tue, Oct 13, 2020, 10:14 Bruno P. Kinoshita <

[email protected]>

wrote:
[...]

I think the np.cov is from the numpy module (imported/aliased as np?).

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



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


Re: Simple question - end a raw string with a single backslash ?

2020-10-19 Thread Grant Edwards
On 2020-10-19, Stephen Tucker  wrote:

> For a neatish way to get a string to end with a single backslash, how about
>mystr = r"abc\ "[:-1]
> (Note the space at the end of the rough-quoted string.)

That's the first thing I thought of, though I would probably use a
non-space character to avoid convusion when reading:

   mystr = r'abc\_'[:-1]

--
Grant

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


Help with the best practice to learn python

2020-10-19 Thread Azhar Ansari
Hello Python Community,
Kindly help me with the best practice to learn python.
Lots of material over net but its very confusing.

Thanks and Regards,
Azhar Ansari
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help with the best practice to learn python

2020-10-19 Thread Marco Sulla
The first time I started python I simply followed the official tutorial:

https://docs.python.org/3.9/tutorial/introduction.html

PS: Note that this is for Python 3.9. You can change the version in the
page if you have another one.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Simple question - end a raw string with a single backslash ?

2020-10-19 Thread Eryk Sun
On 10/19/20, Grant Edwards  wrote:
> On 2020-10-19, Stephen Tucker  wrote:
>
>> For a neatish way to get a string to end with a single backslash, how
>> about
>>mystr = r"abc\ "[:-1]
>> (Note the space at the end of the rough-quoted string.)
>
> That's the first thing I thought of, though I would probably use a
> non-space character to avoid convusion when reading:
>
>mystr = r'abc\_'[:-1]

But it doesn't actually "end a raw string with a single backslash".
The compiler could be optimized for slicing string literals, but it's
not. For example:

>>> dis.dis(r"r'spam\eggs\_'[:-1]")
  1   0 LOAD_CONST   0 ('spam\\eggs\\_')
  2 LOAD_CONST   1 (None)
  4 LOAD_CONST   2 (-1)
  6 BUILD_SLICE  2
  8 BINARY_SUBSCR
 10 RETURN_VALUE

For comparison:

>>> dis.dis(r"r'spam\eggs' '\\'")
  1   0 LOAD_CONST   0 ('spam\\eggs\\')
  2 RETURN_VALUE
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help with the best practice to learn python

2020-10-19 Thread dn via Python-list

On 20/10/2020 04:12, Azhar Ansari wrote:

Hello Python Community,
Kindly help me with the best practice to learn python.
Lots of material over net but its very confusing.



You are so right - it is very confusing!

Different people have different preferences for 'the best way to learn'. 
Also, we probably have widely-different reasons for wanting to learn 
Python, and/or what we plan to do with such skills 'afterwards'*.


Some people are keen on the (apparent) brevity of a 'code camp' approach 
- rapid learning under pressure, with a view to quickly acquiring the 
skills which will (supposedly) justify a job application. It is 
necessary though, to understand the difference between "job" and 
"career". At the other end of the scale, one can study at a university 
for three/four years.


Some take the simplistic approach of visiting YouTube's web-site and 
'clicking on' anything that looks-likely. I recommend a more structured 
approach that will 'cover the ground' in a logical learning-path, and 
with consistency.


As well as the Python Tutorial (mentioned elsewhere), @Alan over on the 
Python-Tutor discussion list*, also maintains something similar.


A good book or two will provide structure and coverage - again though, 
many texts aim in a particular direction, eg Data Science, which may/not 
suit your own interests/objectives.


I recommend on-line courses using reputable platforms such as Coursera 
and edX*, which can be attempted for $free, or to gain certification, 
paid. These are offered by various educational institutions and include 
discussion lists to enable trainees to 'compare notes' and discuss 
questions that will assist understanding (which a text book cannot do).



*
- most professionals understand that "continuing education" or 
'continual learning' is a feature of this business - there's no such 
thing as 'leaving school' knowing it all!
- the 'Tutor' list is an helpful environment for learners to ask 
questions which might seem 'simple' to professionals and 
skilled-practitioners: https://mail.python.org/mailman/listinfo/tutor

- I use the edX platform (for non-Python training)
--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Pickle in C does not work

2020-10-19 Thread Marco Sulla
I tried this code:

static PyObject *
frozendict_reduce(PyFrozenDictObject* mp, PyObject *Py_UNUSED(ignored))
{
PyObject* args = PyTuple_New(1);

if (args == NULL) {
return NULL;
}

PyTuple_SET_ITEM(args, 0, (PyObject *)mp);

PyObject *d = PyObject_Call((PyObject *)&PyDict_Type, args, NULL);
Py_INCREF(mp);
return Py_BuildValue("O(N)", Py_TYPE(mp), d);
}

but I get:
_pickle.PicklingError: Can't pickle : attribute lookup
frozendict on builtins failed

The identical (?) Python code works:


def __reduce__(self, *args, **kwargs):
return (self.__class__, (dict(self), ))
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help with the best practice to learn python

2020-10-19 Thread Michael Torrie
On 10/19/20 9:12 AM, Azhar Ansari wrote:
> Hello Python Community,
> Kindly help me with the best practice to learn python.
> Lots of material over net but its very confusing.

What is your goal?  Python is a tool.  What do you want to do with it?
If you don't have any particular thing in mind, it's much harder to
learn any language.  But of course if you don't have anything particular
in mind, you could enroll in an on-line courses in Python programming.
The lesson plan would at least provide you with exercises to do.
-- 
https://mail.python.org/mailman/listinfo/python-list