Re: File Name issue

2020-10-18 Thread dn via Python-list

On 18/10/2020 12:58, Mladen Gogala via Python-list wrote:

On Sat, 17 Oct 2020 22:51:11 +, Mladen Gogala wrote:

On Sat, 17 Oct 2020 18:12:16 -0400, Steve wrote:


with open("HOURLYLOG.txt", 'r') as infile:
works but, when I rename the file, the line:
with open("HOURLY-LOG.txt", 'r') as infile:
does not.  The complaint is: Cannot Assign to operator


>>> with open( "HOURLY-LOG.txt", "r" ) as f:
... print( f.read() )
...
yes
^^^ the entire contents of a magnificent test-file

NB:
Python 3.8.5 (default, Aug 12 2020, 00:00:00)
[GCC 10.2.1 20200723 (Red Hat 10.2.1-1)] on linux



BTW, I used this
cp /var/log/syslog ./in-file.log
#!/usr/bin/env python3
import io
with open("in-file.log","r") as infile:
 for line in infile:
 print(line)
I got a different error:
Traceback (most recent call last):
   File "./test.py", line 4, in 
 for line in infile:
   File "/usr/lib/python3.8/codecs.py", line 322, in decode
 (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd8 in position 897:
invalid continuation byte



@Mladen: is syslog a text file or binary format?
--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


RE: File Name issue

2020-10-18 Thread Steve
I am not sure if what I did to repair it but the problem is gone.
A copy/paste/rename was performed on the original code file and now I do not
get the error. No need for "r" or "\"...

WTH? I hate it when that happens.

Steve


Footnote:
"What rhymes with orange?"
"No it doesn't.."

-Original Message-
From: Python-list  On
Behalf Of MRAB
Sent: Saturday, October 17, 2020 7:31 PM
To: python-list@python.org
Subject: Re: File Name issue

On 2020-10-17 23:12, Steve wrote:
> The line:
> with open("HOURLYLOG.txt", 'r') as infile:
> works but, when I rename the file, the line:
> with open("HOURLY-LOG.txt", 'r') as infile:
> does not.  The complaint is: Cannot Assign to operator
> 
> However, I have:
> BPM_O2s=open("BPM-O2-Readings.txt","a")
> And it works.
> 
> At first, I thought the issue was due to having the - in the filename.
> 
> Is there a fix or explanation for this?
> Steve
> 
I see nothing wrong in those lines as written.

Try reducing it to the smallest complete example that shows the problem.
-- 
https://mail.python.org/mailman/listinfo/python-list

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


Re: File Name issue

2020-10-18 Thread D'Arcy Cain

On 10/18/20 5:55 AM, Steve wrote:

I am not sure if what I did to repair it but the problem is gone.
A copy/paste/rename was performed on the original code file and now I do not
get the error. No need for "r" or "\"...

WTH? I hate it when that happens.


Could that original hyphen have been a unicode character?

--
D'Arcy J.M. Cain
Vybe Networks Inc.
A unit of Excelsior Solutions Corporation - Propelling Business Forward
http://www.VybeNetworks.com/
IM:da...@vybenetworks.com VoIP: sip:da...@vybenetworks.com


OpenPGP_signature
Description: OpenPGP digital signature
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2020-10-18 Thread Shaozhong SHI
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
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2020-10-18 Thread Mats Wichmann
On 10/18/20 5:53 AM, Shaozhong SHI wrote:
> 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
> 

When you "execute" the query, you don't get back the data, just a row
count. You then have to use one of the "fetch" functions to actually
retrieve it.  Is that what you're asking?


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


Re: MERGE SQL in cx_Oracle executemany

2020-10-18 Thread Peter J. Holzer
On 2020-10-18 06:35:03 -, Mladen Gogala via Python-list wrote:
> On Sat, 17 Oct 2020 21:23:40 -0600, Jason Friedman wrote:
> >> I'm looking to insert values into an oracle table (my_table) using the
> >> query below. The insert query works when the PROJECT is not NULL/empty
> >> (""). However when PROJECT is an empty string(''), the query creates a
> >> new duplicate row every time the code is executed (with project value
> >> populating as null). I would like to modify my query so a new row is
> >> not inserted when all column values are matched (including when project
> >> code is null).
[...]
> > Perhaps the issue is that NULL is not equal to anything. Oracle provides
> > the IS NULL function to determine if a value is NULL.
> > 
> > Note also you define "cur" but executemany with "cur3".
> > 
> > And is "rows = [tuple(x) for x in df.values]" what you want? Print it.
> 
> Obviously, the "PROJECT" column is causing the issue. NULL in Oracle 
> database is never equal to anything.

Not only in Oracle. This is standard SQL behaviour. NULL means
"unknown", and if you compare two unknown values, the result is of
course also unknown. 

However, Oracle adds an additional complication because it converts ''
(the empty string) to NULL on insert. 

> If :7 is NULL, your "not matched" 
> condition is satisfied and your MERGE statement will insert a new and 
> exciting row. That has nothing to do with Python. The only solution is
> "ALTER TABLE my_table modify(project not null)" or 
> "ALTER TABLE my_table add constraint project_nn check(project is not null)"  I

Yup. In addition, because that won't accept an empty string, you'll have
to use some non-empty string (e.g. '-' or '(no project)') to signify
that there is no project. (One might argue that this is better design
anyway (explicit rather than implicit).)

> If you already have NULL values in the PROJECT column than use "add 
> constraint" 
> with NOVALIDATE option. Other than that, allowing NULL values in key columns 
> is
> a sign of bad design. Namely, Oracle cannot index NULL columns, so PROJECT IS 
> NULL
> predicate cannot be resolved by an index.

It can with a bitmap index. However, last time I looked (admittedly long
ago) this was an enterprise edition feature.

hp

-- 
   _  | Peter J. Holzer| Story must make more sense than reality.
|_|_) ||
| |   | h...@hjp.at |-- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |   challenge!"


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


EuroPython 2020: Edited videos are online

2020-10-18 Thread M.-A. Lemburg
We’re happy to announce that all edited videos of this year’s conference
are now available on our YouTube channel:

   * EuroPython 2020 Playlist *

https://www.youtube.com/watch?v=CvbQArKEFes&list=PL8uoeex94UhHgMD9GOCbEHWku7pEPx9fW

We have 131 videos available in total, covering a very broad set of
Python topics, so there’s going to be something interesting for
everyone.

We hope to see you all again next year and perhaps even have a few more
people attending EuroPython 2021 Online, now that the format has proven
successful. Stay safe.


Help spread the word


Please help us spread this message by sharing it on your social
networks as widely as possible. Thank you !

Link to the blog post:

https://blog.europython.eu/post/632313693115416577/europython-2020-edited-videos-are-online

Tweet:

https://twitter.com/europython/status/1317793661061615616

Thanks,
--
EuroPython 2020 Team
https://ep2020.europython.eu/
https://www.europython-society.org/

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


Re: File Name issue

2020-10-18 Thread Chris Angelico
On Sun, Oct 18, 2020 at 10:32 PM D'Arcy Cain  wrote:
>
> On 10/18/20 5:55 AM, Steve wrote:
> > I am not sure if what I did to repair it but the problem is gone.
> > A copy/paste/rename was performed on the original code file and now I do not
> > get the error. No need for "r" or "\"...
> >
> > WTH? I hate it when that happens.
>
> Could that original hyphen have been a unicode character?
>

Or it wasn't in quotes. The original complaint from the interpreter
was regarding an operator.

This is why it's ALWAYS best to provide actual code, copied and
pasted, and the corresponding output.

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


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

2020-10-18 Thread Peter J. Holzer
On 2020-10-17 21:03:26 -, Mladen Gogala via Python-list wrote:
> On Thu, 15 Oct 2020 21:30:15 +, Stefan Ram wrote:
> > Tony Flury  writes:
> >> >>> a = r'end' + chr(92)
> > 
> >   Or maybe,
> > 
> > a = r'''
> > end\
> > '''[ 1: -1 ]
> > 
> >   ? The first and the last line are messy, but in the middle,
> >   the intended string is clearly visible.
> 
> 
> You can use perl module for python.

Ah, I see, that the sillyness of Perl's grammar-altering modules (which
let you write Perl in Latin (with proper declensions and conjugations,
of course) or Chinese) has found its way to Python :-)


> It is installable by pip.
> Perl has no problems with handling backslashes.
> 
> https://pypi.org/project/perl/
> 
> What you need is something like this:
> 
> mgogala@umajor:~$ perl -e '$a="abcd";$a=~s/$/\\/; print "$a\n";'
> abcd\
> 
> Python has a problem with backslashes:
> 
> Python 3.8.5 (default, Jul 28 2020, 12:59:40) 
> [GCC 9.3.0] on linux
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import re
> >>> a="abcd"
> >>> b=re.sub('$',chr(28),a)
> >>> b
> 'abcd\x1c'
> 
> >>> b=re.sub('$',chr(0x41),a)
> >>> b
> 'abcdA'
> >>> b=re.sub('$','Z',a)
> >>> b
> 'abcdZ'
> >>> b=re.sub('$',chr(0x1C),a)
> >>> b
> 'abcd\x1c'
> >>> 
> 
> Any other character is shown as it should be, except backslash.

0x1C isn't a backslash, it's a control character (FS - File Separator).

0x5C is a backslash, but of course that doesn't work here either,
because the second argument to re.sub isn't a simple string: It contains
escape sequences to be interpreted, and a single \ isn't well-formed
(note that you doubled the \ in your Perl example, too).

b=re.sub('$', '', a)
or
b=re.sub('$', chr(0x5C)+chr(0x5C), a)

works just fine, as does 

b = a + chr(0x5C)

In all these cases, 
print(b) 
prints
abcd\
(with a single backslash at the end)

But simply typing "b" at the REPL produces
'abcd\\'
because prints the __repr__() of an object. Note that it also prints
single quotes, which are also not part of the string.

hp

-- 
   _  | Peter J. Holzer| Story must make more sense than reality.
|_|_) ||
| |   | h...@hjp.at |-- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |   challenge!"


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: File Name issue

2020-10-18 Thread Mladen Gogala via Python-list
On Sun, 18 Oct 2020 21:00:18 +1300, dn wrote:

> On 18/10/2020 12:58, Mladen Gogala via Python-list wrote:
>> On Sat, 17 Oct 2020 22:51:11 +, Mladen Gogala wrote:
>>> On Sat, 17 Oct 2020 18:12:16 -0400, Steve wrote:
>>>
 with open("HOURLYLOG.txt", 'r') as infile:
 works but, when I rename the file, the line:
 with open("HOURLY-LOG.txt", 'r') as infile:
 does not.  The complaint is: Cannot Assign to operator
> 
>  >>> with open( "HOURLY-LOG.txt", "r" ) as f:
> ... print( f.read() )
> ...
> yes
> ^^^ the entire contents of a magnificent test-file
> 
> NB:
> Python 3.8.5 (default, Aug 12 2020, 00:00:00)
> [GCC 10.2.1 20200723 (Red Hat 10.2.1-1)] on linux
> 
> 
>> BTW, I used this
>> cp /var/log/syslog ./in-file.log
>> #!/usr/bin/env python3
>> import io
>> with open("in-file.log","r") as infile:
>>  for line in infile:
>>  print(line)
>> I got a different error:
>> Traceback (most recent call last):
>>File "./test.py", line 4, in 
>>  for line in infile:
>>File "/usr/lib/python3.8/codecs.py", line 322, in decode
>>  (result, consumed) = self._buffer_decode(data, self.errors, final)
>> UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd8 in position 
897:
>> invalid continuation byte
> 
> 
> @Mladen: is syslog a text file or binary format?

Hi!
Syslog is the system log. It's a text file. This only happens if I use 
infile as iterable. If I use readline, all is well:

#!/usr/bin/env python3
import io
with open("in-file.log","r") as infile:
while True:
line=infile.readline()
if not line:
break
print(line)

I don't particularly like this idiom, but it works. That is probably a bug
in the utf-8 decoder on Ubuntu. It doesn't happen on my Fedora 32 VM. I 
haven't tried with infile.reconfigure(encoding=None)



-- 
Mladen Gogala
Database Consultant
http://mgogala.byethost5.com
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2020-10-18 Thread Mladen Gogala via Python-list
On Sun, 18 Oct 2020 16:13:16 +0200, Peter J. Holzer wrote:

> 
> Ah, I see, that the sillyness of Perl's grammar-altering modules (which
> let you write Perl in Latin (with proper declensions and conjugations,
> of course) or Chinese) has found its way to Python 
>

To tell the truth, I only installed it to test whether it works. I am an
old Perl hack forced to learn Python by the market forces. I learned Perl 
in 1994 which means that it is my first love of a sort. The fundamental 
difference between the two languages is that Perl is procedural while 
Python is a fully OO language. Discussion of Perl vs Python necessarily
devolves into the discussion of procedural vs OO paradigms. And that has 
been decided long time ago, with the advent of Java over COBOL. Market
has spoken and I had to learn Python. So, I stopped worrying and learned 
to love Python. Any resemblance to the subtitle of "Dr. Strangelove" is 
purely accidental.
BTW, Visual Studio Code uses pylint to evaluate my adherence to PEP8 and
there is a "kite" extension with autocompletion. Nothing like that was ever
available for Perl. It certainly is easier to write Python scripts than to
write Perl scripts. I do sort of miss $_, @_ and $!. Python's argparse 
is supreme and much better than Getopt::Long.



-- 
Mladen Gogala
Database Consultant
http://mgogala.byethost5.com
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2020-10-18 Thread Michael Torrie
On 10/18/20 11:07 AM, Mladen Gogala via Python-list wrote:
> The fundamental 
> difference between the two languages is that Perl is procedural while 
> Python is a fully OO language. Discussion of Perl vs Python necessarily
> devolves into the discussion of procedural vs OO paradigms.

Python certainly is procedural.  A script starts at the top and executes
through to the bottom and ends, barring any flow control in the middle.
 Like Perl you can use it in many different ways and paradigms including
OO if you desire.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: File Name issue

2020-10-18 Thread dn via Python-list

On 19/10/2020 05:58, Mladen Gogala via Python-list wrote:

On Sun, 18 Oct 2020 21:00:18 +1300, dn wrote:

On 18/10/2020 12:58, Mladen Gogala via Python-list wrote:

On Sat, 17 Oct 2020 22:51:11 +, Mladen Gogala wrote:
BTW, I used this
cp /var/log/syslog ./in-file.log
#!/usr/bin/env python3
import io
with open("in-file.log","r") as infile:
  for line in infile:
  print(line)
I got a different error:
Traceback (most recent call last):
File "./test.py", line 4, in 
  for line in infile:
File "/usr/lib/python3.8/codecs.py", line 322, in decode
  (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd8 in position

897:

invalid continuation byte



@Mladen: is syslog a text file or binary format?


Hi!
Syslog is the system log. It's a text file. This only happens if I use
infile as iterable. If I use readline, all is well:

#!/usr/bin/env python3
import io
with open("in-file.log","r") as infile:
 while True:
 line=infile.readline()
 if not line:
 break
 print(line)

I don't particularly like this idiom, but it works. That is probably a bug
in the utf-8 decoder on Ubuntu. It doesn't happen on my Fedora 32 VM. I
haven't tried with infile.reconfigure(encoding=None)



[Slightly OT from OP]

Some logging has started to move from simple-text to a more 
compressed?efficient 'binary' - hence my thinking.


Your observation, doubly-interesting.

Fedora uses UTF-8 by default. I would have expected the same of Ubuntu. 
One wonders if different decoder/encoder defaults are set by the 
repo-managers, or some-such explanation.


Using Fedora 32, (as before), and a copy of "/var/log/messages" because 
it doesn't use "syslog", it works happily:


>>> with open( "messages", "r" ) as infile:
...  for line in infile:
...  print(line)
...  break
...
Oct 18 00:01:01 JrBrown systemd[1]: Starting update of the root trust 
anchor for DNSSEC validation in unbound...


However, the decisive-point is the actual data. Have you worked-out 
which line in the log causes the error - and thus the offending string 
of characters?

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


How to expand and flatten a nested of list of dictionaries of varied lengths?

2020-10-18 Thread Shaozhong SHI
Even worse is that, in some cases, an addition called serviceRatings as a
key occur with new data unexpectedly.

How to produce a robust Python/Panda script to coping with all these?

Regards,

David

u'historicRatings': [{u'overall': {u'keyQuestionRatings': [{u'name':
u'Safe', u'rating': u'Requires improvement'}, {u'name': u'Well-led',
u'rating': u'Requires improvement'}], u'rating': u'Requires improvement'},
u'reportDate': u'2019-10-04', u'reportLinkId':
u'63ff05ec-4d31-406e-83de-49a271cfdc43'}, {u'overall':
{u'keyQuestionRatings': [{u'name': u'Safe', u'rating': u'Good'}, {u'name':
u'Well-led', u'rating': u'Good'}, {u'name': u'Caring', u'rating': u'Good'},
{u'name': u'Responsive', u'rating': u'Good'}, {u'name': u'Effective',
u'rating': u'Requires improvement'}], u'rating': u'Good'}, u'reportDate':
u'2017-09-08', u'reportLinkId': u'4f20da40-89a4-4c45-a7f9-bfd52b48f286'},
{u'overall': {u'keyQuestionRatings': [{u'name': u'Safe', u'rating':
u'Requires improvement'}, {u'name': u'Well-led', u'rating': u'Requires
improvement'}, {u'name': u'Caring', u'rating': u'Requires improvement'},
{u'name': u'Responsive', u'rating': u'Requires improvement'}, {u'name':
u'Effective', u'rating': u'Good'}], u'rating': u'Requires improvement'},
u'reportDate': u'2016-06-11', u'reportLinkId':
u'0cc4226b-401e-4f0f-ba35-062cbadffa8f'}, {u'overall':
{u'keyQuestionRatings': [{u'name': u'Safe', u'rating': u'Good'}, {u'name':
u'Well-led', u'rating': u'Good'}, {u'name': u'Caring', u'rating': u'Good'},
{u'name': u'Responsive', u'rating': u'Requires improvement'}, {u'name':
u'Effective', u'rating': u'Good'}], u'rating': u'Good'}, u'reportDate':
u'2015-01-12', u'reportLinkId': u'a11c1e52-ddfd-4cd8-8b56-1b96ac287c96'}]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to expand and flatten a nested of list of dictionaries of varied lengths?

2020-10-18 Thread dn via Python-list

On 19/10/2020 09:09, Shaozhong SHI wrote:

Even worse is that, in some cases, an addition called serviceRatings as a
key occur with new data unexpectedly.


"Even worse" than what?

Do you need to keep a list of acceptable/applicable/available keys?
(and reject or deal with others in some alternate fashion)



How to produce a robust Python/Panda script to coping with all these?



u'historicRatings': [{u'overall': {u'keyQuestionRatings': [{u'name':
u'Safe', u'rating': u'Requires improvement'}, {u'name': u'Well-led',
u'rating': u'Requires improvement'}], u'rating': u'Requires improvement'},
u'reportDate': u'2019-10-04', u'reportLinkId':
u'63ff05ec-4d31-406e-83de-49a271cfdc43'}, {u'overall':
{u'keyQuestionRatings': [{u'name': u'Safe', u'rating': u'Good'}, {u'name':
u'Well-led', u'rating': u'Good'}, {u'name': u'Caring', u'rating': u'Good'},
{u'name': u'Responsive', u'rating': u'Good'}, {u'name': u'Effective',
u'rating': u'Requires improvement'}], u'rating': u'Good'}, u'reportDate':
u'2017-09-08', u'reportLinkId': u'4f20da40-89a4-4c45-a7f9-bfd52b48f286'},
{u'overall': {u'keyQuestionRatings': [{u'name': u'Safe', u'rating':
u'Requires improvement'}, {u'name': u'Well-led', u'rating': u'Requires
improvement'}, {u'name': u'Caring', u'rating': u'Requires improvement'},
{u'name': u'Responsive', u'rating': u'Requires improvement'}, {u'name':
u'Effective', u'rating': u'Good'}], u'rating': u'Requires improvement'},
u'reportDate': u'2016-06-11', u'reportLinkId':
u'0cc4226b-401e-4f0f-ba35-062cbadffa8f'}, {u'overall':
{u'keyQuestionRatings': [{u'name': u'Safe', u'rating': u'Good'}, {u'name':
u'Well-led', u'rating': u'Good'}, {u'name': u'Caring', u'rating': u'Good'},
{u'name': u'Responsive', u'rating': u'Requires improvement'}, {u'name':
u'Effective', u'rating': u'Good'}], u'rating': u'Good'}, u'reportDate':
u'2015-01-12', u'reportLinkId': u'a11c1e52-ddfd-4cd8-8b56-1b96ac287c96'}]


You may find it helpful to use the pprint ("pretty printing" library to 
print data-structures in a more readable/structured format).


To "flatten" a dictionary, you must first be sure that there will be no 
keys that will clash (else the second entry will completely replace the 
first, without trace).


Thus, we will need to understand more about this particular definition 
of "flatten" in relation to the range of incoming data. Perhaps explain 
them in English first...

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


Re: How to expand and flatten a nested of list of dictionaries of varied lengths?

2020-10-18 Thread Mats Wichmann
On 10/18/20 2:09 PM, Shaozhong SHI wrote:
> Even worse is that, in some cases, an addition called serviceRatings as a
> key occur with new data unexpectedly.
> 
> How to produce a robust Python/Panda script to coping with all these?
> 
> Regards,
> 
> David
> 
> u'historicRatings': [{u'overall': {u'keyQuestionRatings': [{u'name':
> u'Safe', u'rating': u'Requires improvement'}, {u'name': u'Well-led',
> u'rating': u'Requires improvement'}], u'rating': u'Requires improvement'},

truncating this to avoid a huge paste...

can you give an example of what it would look like "flattened"?

list flattening is pretty straightforward, and even has a standard
library method, itertools.chain, to help out.

to flatten a dict though, you have to deal with what would happen if the
keys aren't unique. if you look at the above, for example, there are two
places where there's a key 'rating' though they're at different levels
in the data structure, so you have to be clear on what should happen here.

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


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

2020-10-18 Thread Mladen Gogala via Python-list
On Sun, 18 Oct 2020 12:19:18 -0600, Michael Torrie wrote:

> Python certainly is procedural.  A script starts at the top and executes
> through to the bottom and ends, barring any flow control in the middle.
>  Like Perl you can use it in many different ways and paradigms including
> OO if you desire.

That's not the point. In Python, regular expressions are a class. So are 
strings and lists. 
In Perl, there are no classes. Procedural paradigm means that you are modelling 
the real world
with the objects provided by the computer environment: strings, numbers, lists 
or hashes (known 
as "dictionaries" in Python). OO paradigm allows you to create objects and make 
them behave like 
in the real world. In other words, in OO paradighm, data and functions are 
related. The basic 
idea of the OO was to make code sharing much easier. However, things  do not 
always work as 
they should:

https://medium.com/better-programming/object-oriented-programming-the-trillion-dollar-disaster-92a4b666c7c7

https://towardsdatascience.com/object-oriented-programming-is-dead-wait-really-db1f1f05cc44

Of course, not everybody agrees. People never do:

https://techbeacon.com/app-dev-testing/object-oriented-programming-dead-not-long-shot

Sometimes, OO has its funny side:
https://www.wearethemighty.com/articles/that-time-the-australian-air-force-squared-off-against-missile-shooting-kangaroos

-- 
Mladen Gogala
Database Consultant
http://mgogala.byethost5.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to expand and flatten a nested of list of dictionaries of varied lengths?

2020-10-18 Thread dn via Python-list
If I may, a couple of items of list-etiquette (polite behavior), as I 
understand them:
1 please reply to the list (cf only myself) because @Mats (who responded 
earlier) and others on this list are much smarter than me, and might be 
able to help you more quickly
2 top-posting seems to take the form 'answer, then question' which is 
illogical to everyone, except apparently Microsoft. It is better to have 
the conversation 'develop' as it proceeds - all the early information at 
the beginning, and the more detailed towards the 'end'. That is not to 
say that we can't "snip" or 'do some gardening', to remove unnecessary 
or erroneous material, as the conversation progresses. You will notice 
(as below) that this also enables a posting with multiple questions, to 
be discussed point-by-point.



Now to work...


> On Sun, 18 Oct 2020 at 21:48, dn via Python-list  > wrote:
>
> On 19/10/2020 09:09, Shaozhong SHI wrote:
>  > Even worse is that, in some cases, an addition called
> serviceRatings as a
>  > key occur with new data unexpectedly.
>
> "Even worse" than what?
>
> Do you need to keep a list of acceptable/applicable/available keys?
> (and reject or deal with others in some alternate fashion)
>
>
>  > How to produce a robust Python/Panda script to coping with all 
these?


...
[I often use ellipsis to indicate that I have snipped 'stuff in the 
middle', others are more overt and will write "" or similar]



> You may find it helpful to use the pprint ("pretty printing" 
library to

> print data-structures in a more readable/structured format).
>
> To "flatten" a dictionary, you must first be sure that there will 
be no
> keys that will clash (else the second entry will completely 
replace the

> first, without trace).
>
> Thus, we will need to understand more about this particular 
definition
> of "flatten" in relation to the range of incoming data. Perhaps 
explain

> them in English first...

On 19/10/2020 12:14, Shaozhong SHI wrote:

Hi, DN,

This is the result of pprint.


[{u'overall': {u'keyQuestionRatings': [{u'name': u'Safe',
u'rating': u'Requires 
improvement'},

   {u'name': u'Well-led',
u'rating': u'Requires 
improvement'}],

   u'rating': u'Requires improvement'},
  u'reportDate': u'2019-10-04',
  u'reportLinkId': u'63ff05ec-4d31-406e-83de-49a271cfdc43'},
 {u'overall': {u'keyQuestionRatings': [{u'name': u'Safe',
u'rating': u'Good'},
   {u'name': u'Well-led',
u'rating': u'Good'},
   {u'name': u'Caring',
u'rating': u'Good'},
   {u'name': u'Responsive',
u'rating': u'Good'},
   {u'name': u'Effective',
u'rating': u'Requires 
improvement'}],

   u'rating': u'Good'},
  u'reportDate': u'2017-09-08',
  u'reportLinkId': u'4f20da40-89a4-4c45-a7f9-bfd52b48f286'},
 {u'overall': {u'keyQuestionRatings': [{u'name': u'Safe',
u'rating': u'Requires 
improvement'},

   {u'name': u'Well-led',
u'rating': u'Requires 
improvement'},

   {u'name': u'Caring',
u'rating': u'Requires 
improvement'},

   {u'name': u'Responsive',
u'rating': u'Requires 
improvement'},

   {u'name': u'Effective',
u'rating': u'Good'}],
   u'rating': u'Requires improvement'},
  u'reportDate': u'2016-06-11',
  u'reportLinkId': u'0cc4226b-401e-4f0f-ba35-062cbadffa8f'},
 {u'overall': {u'keyQuestionRatings': [{u'name': u'Safe',
u'rating': u'Good'},
   {u'name': u'Well-led',
u'rating': u'Good'},
   {u'name': u'Caring',
u'rating': u'Good'},
   {u'name': u'Responsive',
u'rating': u'Requires 
improvement'},

   {u'name': u'Effective',
u'rating': u'Good'}],
   u'rating': u'Good'},
  u'reportDate': u'2015-01-12',
  u'reportLinkId': u'a11c1e52-ddfd-4cd8-8b56-1b96ac287c96'}]


Well done! This looks so much better, and more to the point, it is 
easier for 'us' to see the structure - but oh 

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

2020-10-18 Thread Michael Torrie
On 10/18/20 5:37 PM, Mladen Gogala via Python-list wrote:
> On Sun, 18 Oct 2020 12:19:18 -0600, Michael Torrie wrote:
> 
>> Python certainly is procedural.  A script starts at the top and executes
>> through to the bottom and ends, barring any flow control in the middle.
>>  Like Perl you can use it in many different ways and paradigms including
>> OO if you desire.
> 
> That's not the point. 

But it is.

Yes I can see why this devolves so quickly for you! :)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Covariance matrix syntax

2020-10-18 Thread Meghna Karkera
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 <
> brunodepau...@yahoo.com.br>
> > 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: Covariance matrix syntax

2020-10-18 Thread Christian Gollwitzer

Am 19.10.20 um 07:23 schrieb Meghna Karkera:

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.



As said, you should click on the link [source] just at the right hand 
side of the page, at the top. There is


numpy.cov(m, y=None, rowvar=True, bias=False, ddof=None, fweights=None, 
aweights=None)


and just next to it there is the link. It takes you there:

https://github.com/numpy/numpy/blob/v1.19.0/numpy/lib/function_base.py#L2270-L2481

Which is the source code of the function.

Best regards,

Christian



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 <

brunodepau...@yahoo.com.br>

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-18 Thread Mladen Gogala via Python-list
On Mon, 19 Oct 2020 02:44:25 +, Stefan Ram wrote:

> Mladen Gogala  writes:
>>In Perl, there are no classes. 
> 
>   If there are no classes in Perl, then what does
> 
> bless REF,CLASSNAME 
> 
>   do?

bless \$ref will make the given reference a reference to the class. And classes 
is Perl
are called "modules". However, Perl classes are not the classes in the  real 
sense. There 
is no inheritance. You can have a similar thing in C: it's called "struct", it 
can do 
similar things like Perl modules. But C isn't object oriented. Inheritance is an
essential characteristic of object orientation.
There were attempts to turn Perl into OO language with Moose 
(https://metacpan.org/pod/Moose)
However, Moose is complex, tedious and rarely used. Perl6 is an OO language, 
but nobody uses 
it. The problem is CPAN and all the Perl5 modules which are not compatible with 
Perl6 or "Roku"
as it is known.



-- 
Mladen Gogala
Database Consultant
http://mgogala.byethost5.com
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2020-10-18 Thread Chris Angelico
On Mon, Oct 19, 2020 at 5:26 PM Mladen Gogala via Python-list
 wrote:
> bless \$ref will make the given reference a reference to the class. And 
> classes is Perl
> are called "modules". However, Perl classes are not the classes in the  real 
> sense. There
> is no inheritance. You can have a similar thing in C: it's called "struct", 
> it can do
> similar things like Perl modules. But C isn't object oriented. Inheritance is 
> an
> essential characteristic of object orientation.

Funny thing about how languages "are" or "are not" object oriented
back in the day, I used to do SOM programming on OS/2, which was
entirely in C, and most definitely had all the features you'd expect
of object orientation. Inheritance, the ability to override your
parent's methods, the ability to call the parent's method during the
implementation of your own, etc, etc, etc. It was all done through
DLLs, so you could subclass someone else's class (a very common thing
was to subclass one of the standard classes and add a small amount of
functionality to it) without having the source code. So, yeah, I don't
think there's any fundamental in any language that says whether or not
you can do OOP.

There are features which make OOP easier, and some languages have more
of them than others do. That's about all you can really say.

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