Re: From JoyceUlysses.txt -- words occurring exactly once

2024-06-08 Thread Larry Martell via Python-list
On Sat, Jun 8, 2024 at 10:39 AM Mats Wichmann via Python-list <
python-list@python.org> wrote:

> On 6/5/24 05:10, Thomas Passin via Python-list wrote:
>
> > Of course, we see this lack of clarity all the time in questions to the
> > list.  I often wonder how these askers can possibly come up with
> > acceptable code if they don't realize they don't truly know what it's
> > supposed to do.
>
> Fortunately, having to explain to someone else why something is giving
> you trouble can help shed light on the fact the problem statement isn't
> clear, or isn't clearly understood. Sometimes (sadly, many times it
> doesn't).


The original question struck me as homework or an interview question for a
junior position. But having no clear requirements or specifications is good
training for the real world where that is often the case. When you question
that, you are told to just do something, and then you’re told it’s not what
is wanted. That frustrates people but it’s often part of the process.
People need to see something to help them know what they really want.

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


Re: Serializing pydantic enums

2024-05-29 Thread Larry Martell via Python-list
On Wed, May 29, 2024 at 12:27 PM Larry Martell  wrote:
>
> On Tue, May 28, 2024 at 11:46 AM Left Right via Python-list
>  wrote:
> >
> > Most Python objects aren't serializable into JSON. Pydantic isn't
> > special in this sense.
> >
> > What can you do about this? -- Well, if this is a one-of situation,
> > then, maybe just do it by hand?
> >
> > If this is a recurring problem: json.dumps() takes a cls argument that
> > will be used to do the serialization. Extend json.JSONEncoder and
> > implement the encode() method for the encoder class you are passing. I
> > believe that the official docs have some information about this too.
>
> Yeah, I know I can do this, but I seem to recall reading that pydantic
> handled serialization.  Guess not.

Actually it's as simple as adding this to any model that uses an enum model:

class Config:
use_enum_values = True


> > On Tue, May 28, 2024 at 2:50 PM Larry Martell via Python-list
> >  wrote:
> > >
> > > Just getting started with pydantic. I have this example code:
> > >
> > > class FinishReason(Enum):
> > > stop = 'stop'
> > >
> > > class Choice(BaseModel):
> > > finish_reason: FinishReason = Field(...)
> > >
> > >
> > > But I cannot serialize this:
> > >
> > > json.dumps(Choice(finish_reason=FinishReason.stop).dict())
> > > *** TypeError: Object of type FinishReason is not JSON serializable
> > >
> > >
> > > I get the object not the value:
> > >
> > > (Pdb) Choice(finish_reason=FinishReason.stop)
> > > Choice(finish_reason=)
> > >
> > >
> > > Also tried it with .value, same result.
> > >
> > > What am I missing here?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Serializing pydantic enums

2024-05-29 Thread Larry Martell via Python-list
On Tue, May 28, 2024 at 11:46 AM Left Right via Python-list
 wrote:
>
> Most Python objects aren't serializable into JSON. Pydantic isn't
> special in this sense.
>
> What can you do about this? -- Well, if this is a one-of situation,
> then, maybe just do it by hand?
>
> If this is a recurring problem: json.dumps() takes a cls argument that
> will be used to do the serialization. Extend json.JSONEncoder and
> implement the encode() method for the encoder class you are passing. I
> believe that the official docs have some information about this too.

Yeah, I know I can do this, but I seem to recall reading that pydantic
handled serialization.  Guess not.

> On Tue, May 28, 2024 at 2:50 PM Larry Martell via Python-list
>  wrote:
> >
> > Just getting started with pydantic. I have this example code:
> >
> > class FinishReason(Enum):
> > stop = 'stop'
> >
> > class Choice(BaseModel):
> > finish_reason: FinishReason = Field(...)
> >
> >
> > But I cannot serialize this:
> >
> > json.dumps(Choice(finish_reason=FinishReason.stop).dict())
> > *** TypeError: Object of type FinishReason is not JSON serializable
> >
> >
> > I get the object not the value:
> >
> > (Pdb) Choice(finish_reason=FinishReason.stop)
> > Choice(finish_reason=)
> >
> >
> > Also tried it with .value, same result.
> >
> > What am I missing here?
-- 
https://mail.python.org/mailman/listinfo/python-list


Serializing pydantic enums

2024-05-28 Thread Larry Martell via Python-list
Just getting started with pydantic. I have this example code:

class FinishReason(Enum):
stop = 'stop'

class Choice(BaseModel):
finish_reason: FinishReason = Field(...)


But I cannot serialize this:

json.dumps(Choice(finish_reason=FinishReason.stop).dict())
*** TypeError: Object of type FinishReason is not JSON serializable


I get the object not the value:

(Pdb) Choice(finish_reason=FinishReason.stop)
Choice(finish_reason=)


Also tried it with .value, same result.

What am I missing here?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PyCon

2024-05-17 Thread Larry Martell via Python-list
LOn Fri, May 17, 2024 at 8:57 PM Larry Martell 
wrote:

> I’m at PyCon in Pittsburgh and I’m haven’t an amazing time!


s/haven’t/having/
-- 
https://mail.python.org/mailman/listinfo/python-list


PyCon

2024-05-17 Thread Larry Martell via Python-list
I’m at PyCon in Pittsburgh and I’m haven’t an amazing time!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Version of NymPy

2024-05-15 Thread Larry Martell via Python-list
On Wed, May 15, 2024 at 2:43 PM Popov, Dmitry Yu via Python-list
 wrote:
>
> What would be the easiest way to learn which version of NumPy I have with my 
> Anaconda distribution?

>>> import numpy
>>> numpy.__version__
'1.24.4'
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Extract lines from file, add to new files

2024-01-30 Thread Larry Martell via Python-list
On Tue, Jan 30, 2024 at 1:13 AM AVI GROSS via Python-list
 wrote:
>
> It can be quite frustrating figuring out what someone wants, Grant,
> especially when they just change it.
>
> It is worse when instead of starting a new thread with an appropriate
> subject line, it continues and old one that was also frustrating to
> understand.

Is it worse than top posting?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Running a subprocess in a venv

2023-10-21 Thread Larry Martell via Python-list
On Sat, Oct 21, 2023 at 12:10 PM Johannes Findeisen  wrote:
>
> On Sat, 21 Oct 2023 11:32:03 -0400
> Larry Martell  wrote:
>
> > On Sat, Oct 21, 2023 at 9:49 AM Johannes Findeisen
> >  wrote:
> > >
> > > On Sat, 21 Oct 2023 09:01:18 -0400
> > > Larry Martell via Python-list  wrote:
> > >
> > > > I have a python script, and from that I want to run another
> > > > script in a subprocess in a venv. What is the best way to do
> > > > that? I could write a file that activates the venv then runs the
> > > > script, then run that file, but that seems messy. Is there a
> > > > better way?
> > >
> > > How do you do that?
> >
> > How? Open a file and write the commands I need then invoke that.
> >
> > > It sounds messy but not wrong...
> > >
> > > I would activate the venv and then run my Python script. In the
> > > Python script you can call another python script in a subprocess
> > > like this:
> > >
> > > import sys
> > > import subprocess
> > >
> > > #
> > > https://docs.python.org/3/library/subprocess.html#popen-constructor
> > > proc = subprocess.Popen([sys.executable,
> > > "/path/to/an/otherscript.py"])
> > >
> > > # https://docs.python.org/3/library/subprocess.html#popen-objects
> > > # Do your process communication/handling... proc.communicate(),
> > > # proc.wait(), proc.terminate(), proc.kill() etc.
> > >
> > > Is this the answer you are looking for?
> > >
> > > Detailed docs: https://docs.python.org/3/library/subprocess.html
> >
> > I know how to use Popen. What I was missing was running the script
> > using sys.executable. Thanks.
>
> sys.executable is the path to the actual Python binary, e.g.
> "/usr/bin/python". You could add "/usr/bin/python" there manually but
> this is not portable to Windows for example.
>
> When you add a shebang line to your other script and the file is
> executable, you may not need to add sys.executable as first argument to
> Popen but using sys.executable is the most reliable way to do this... ;)

I need the path to whichever venv is being used so sys.executable works for me.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Running a subprocess in a venv

2023-10-21 Thread Larry Martell via Python-list
On Sat, Oct 21, 2023 at 9:49 AM Johannes Findeisen  wrote:
>
> On Sat, 21 Oct 2023 09:01:18 -0400
> Larry Martell via Python-list  wrote:
>
> > I have a python script, and from that I want to run another script in
> > a subprocess in a venv. What is the best way to do that? I could write
> > a file that activates the venv then runs the script, then run that
> > file, but that seems messy. Is there a better way?
>
> How do you do that?

How? Open a file and write the commands I need then invoke that.

> It sounds messy but not wrong...
>
> I would activate the venv and then run my Python script. In the Python
> script you can call another python script in a subprocess like this:
>
> import sys
> import subprocess
>
> # https://docs.python.org/3/library/subprocess.html#popen-constructor
> proc = subprocess.Popen([sys.executable, "/path/to/an/otherscript.py"])
>
> # https://docs.python.org/3/library/subprocess.html#popen-objects
> # Do your process communication/handling... proc.communicate(),
> # proc.wait(), proc.terminate(), proc.kill() etc.
>
> Is this the answer you are looking for?
>
> Detailed docs: https://docs.python.org/3/library/subprocess.html

I know how to use Popen. What I was missing was running the script
using sys.executable. Thanks.
-- 
https://mail.python.org/mailman/listinfo/python-list


Running a subprocess in a venv

2023-10-21 Thread Larry Martell via Python-list
I have a python script, and from that I want to run another script in
a subprocess in a venv. What is the best way to do that? I could write
a file that activates the venv then runs the script, then run that
file, but that seems messy. Is there a better way?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: path to python in venv

2023-09-27 Thread Larry Martell via Python-list
On Wed, Sep 27, 2023 at 12:53 PM Niktar Lirik  wrote:
>
> Hi Larry,
>
> You could just create venv with option '—copies'
>
>
>
> For example:
>
> python -m venv -–copies .venv

Thanks! That is just what I was looking for.

> From: Larry Martell via Python-list
> Sent: 27 сентября 2023 г. 22:48
> To: Jon Ribbens
> Cc: python-list@python.org
> Subject: Re: path to python in venv
>
>
>
> On Wed, Sep 27, 2023 at 12:42 PM Jon Ribbens via Python-list
>
>  wrote:
>
> >
>
> > On 2023-09-27, Larry Martell  wrote:
>
> > > I was under the impression that in a venv the python used would be in
>
> > > the venv's bin dir. But in my venvs I see this in the bin dirs:
>
> > >
>
> > > lrwxrwxrwx 1 larrymartell larrymartell7 Sep 27 11:21 python -> python3
>
> > > lrwxrwxrwx 1 larrymartell larrymartell   16 Sep 27 11:21 python3 ->
>
> > > /usr/bin/python3
>
> > ...
>
> > > Not sure what this really means, nor how to get python to be in my venv.
>
> >
>
> > WHy do you want python to be "in your venv"?
>
>
>
> Isn't that the entire point of a venv? To have a completely self
>
> contained env? So if someone messes with the system python it will not
>
> break code running in the venv.
>
> --
>
> https://mail.python.org/mailman/listinfo/python-list
>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: path to python in venv

2023-09-27 Thread Larry Martell via Python-list
On Wed, Sep 27, 2023 at 12:42 PM Jon Ribbens via Python-list
 wrote:
>
> On 2023-09-27, Larry Martell  wrote:
> > I was under the impression that in a venv the python used would be in
> > the venv's bin dir. But in my venvs I see this in the bin dirs:
> >
> > lrwxrwxrwx 1 larrymartell larrymartell7 Sep 27 11:21 python -> python3
> > lrwxrwxrwx 1 larrymartell larrymartell   16 Sep 27 11:21 python3 ->
> > /usr/bin/python3
> ...
> > Not sure what this really means, nor how to get python to be in my venv.
>
> WHy do you want python to be "in your venv"?

Isn't that the entire point of a venv? To have a completely self
contained env? So if someone messes with the system python it will not
break code running in the venv.
-- 
https://mail.python.org/mailman/listinfo/python-list


path to python in venv

2023-09-27 Thread Larry Martell via Python-list
I was under the impression that in a venv the python used would be in
the venv's bin dir. But in my venvs I see this in the bin dirs:

lrwxrwxrwx 1 larrymartell larrymartell7 Sep 27 11:21 python -> python3
lrwxrwxrwx 1 larrymartell larrymartell   16 Sep 27 11:21 python3 ->
/usr/bin/python3

Googling this I read:

The presence of symbolic links like python and python3 in the bin
directory of your virtual environment pointing to the system Python
executable (/usr/bin/python) suggests that the virtual environment was
created using the system Python interpreter rather than a standalone
Python installation.

This can happen if you create a virtual environment using a
system-wide Python interpreter, and the virtual environment inherits
some of the symbolic links or shortcuts from the system Python
installation. In this case, your virtual environment is not fully
isolated because it still relies on the system Python interpreter.

Not sure what this really means, nor how to get python to be in my venv.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why do I always get an exception raised in this __init__()?

2023-08-31 Thread Larry Martell via Python-list
On Thu, Aug 31, 2023 at 3:19 PM Chris Green via Python-list
 wrote:
>
> I'm obviously doing something very silly here but at the moment I
> can't see what.
>
> Here's the code:-
>
> #!/usr/bin/python3
> #
> #
> # GPIO
> #
> import gpiod
> #
> #
> # Simple wrapper class for gpiod to make set and clearing outputs
> easier
> #
> class Gpiopin:
>
> def __init__(self, pin):
> #
> #
> # scan through the GPIO chips to find the line/pin we want
> #
> for c in ['gpiochip0', 'gpiochip1', 'gpiochip2', 'gpiochip3']:
>
> chip = gpiod.Chip(c)
> for l in range(32):
> line = chip.get_line(l)
> if pin in line.name():
> print("Found: ", line.name())
> return
> else:
> raise ValueError("Can't find pin '" + pin + "'")
>
> def print_name(self):
> print (self.line.name())
>
> def set(self):
> self.line.set_value(1)
>
> def clear(self):
> self.line.set_value(0)
>
>
> This is by no means the final code, the print() in the __init__() is
> just a diagnostic for example. However I really can't understand why I
> see the following when I try it:-
>
> >>> import ngp
> >>> ngp.Gpiopin("P9_23")
> Found:  P9_23
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "/home/chris/.cfg/hosts/bbb/bin/ngp.py", line 24, in __init__
> return
> ValueError: Can't find pin 'P9_23'
> >>>
>
> Does a return in __init__() not do what I think it does?
>
> How else could/should I do this?

Change the return to a break
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pip-sync

2023-07-24 Thread Larry Martell via Python-list
On Fri, Jul 21, 2023 at 11:08 AM Larry Martell  wrote:
>
> I am trying to set up and maintain a venv with pip-sync. On my bare
> metal I have the apparmor python package installed, but it is not
> installed in my venv and it's not in my requirements file. When I run
> pip-sync I get:
>
> Found existing installation: apparmor 2.13.3
> ERROR: Cannot uninstall 'apparmor'. It is a distutils installed
> project and thus we cannot accurately determine which files belong to
> it which would lead to only a partial uninstall.
>
> Since it's not installed in the venv why does it want to uninstall it?

Found out what was going on - I had pip-sync installed on the bare
metal and when I ran it from within the venv it was picking that one
up, which then looked at packages outside the venv. After I
uninstalled it from the bare metal it was then working as expected.
-- 
https://mail.python.org/mailman/listinfo/python-list


pip-sync

2023-07-21 Thread Larry Martell via Python-list
I am trying to set up and maintain a venv with pip-sync. On my bare
metal I have the apparmor python package installed, but it is not
installed in my venv and it's not in my requirements file. When I run
pip-sync I get:

Found existing installation: apparmor 2.13.3
ERROR: Cannot uninstall 'apparmor'. It is a distutils installed
project and thus we cannot accurately determine which files belong to
it which would lead to only a partial uninstall.

Since it's not installed in the venv why does it want to uninstall it?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: TypeError: can only concatenate str (not "int") to str

2023-02-26 Thread Larry Martell
On Sun, Feb 26, 2023 at 5:46 PM Chris Angelico  wrote:

> On Mon, 27 Feb 2023 at 12:44, MRAB  wrote:
> > Oh dear. An example of Godwin's Law.
>
> Yeah, is that finally enough to get this user banned ?


I hope so

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


Re: Rob Cliffe should stop sending me rude email messages.

2023-02-26 Thread Larry Martell
On Sun, Feb 26, 2023 at 3:49 PM Hen Hanna  wrote:

>
> Rob Cliffe should stop sending me rude email messages.


You should stop spamming this lists with with meaningless posts.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: flattening lists

2022-10-11 Thread Larry Martell
On Tue, Oct 11, 2022 at 12:48 PM SquidBits _  wrote:
>
> Does anyone else think there should be a flatten () function, which just 
> turns a multi-dimensional list into a one-dimensional list in the order it's 
> in. e.g.
>
> [[1,2,3],[4,5,6,7],[8,9]] becomes [1,2,3,4,5,6,7,8,9].
>
> I have had to flatten lists quite a few times and it's quite tedious to type 
> out. It feels like this should be something built in to python, anyone else 
> think this way?

x = [[1,2,3],[4,5,6,7],[8,9]]
[i for j in x for i in j]
[1, 2, 3, 4, 5, 6, 7, 8, 9]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Function to Print a nicely formatted Dictionary or List?

2022-06-09 Thread Larry Martell
On Thu, Jun 9, 2022 at 11:44 AM Dave  wrote:
>
> Hi,
>
> Before I write my own I wondering if anyone knows of a function that will 
> print a nicely formatted dictionary?
>
> By nicely formatted I mean not all on one line!

>>> import json
>>> d = {'John': 'Cleese', 'Eric': "Idle", 'Micheal': 'Palin'}
>>> print(json.dumps(d, indent=4))
{
"John": "Cleese",
"Eric": "Idle",
"Micheal": "Palin"
}
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: terminate called after throwing an instance of 'boost::python::error_already_set

2022-05-27 Thread Larry Martell
On Fri, May 27, 2022 at 5:51 PM dn  wrote:

> On 28/05/2022 08.14, Larry Martell wrote:
> > I have a script that has literally been running for 10 years.
> > Suddenly, for some runs it crashes with the error:
> >
> > terminate called after throwing an instance of
> 'boost::python::error_already_set
> >
> > No stack trace. Anyone have any thoughts on what could cause this
> > and/or how I can track it down?
>
> 1 a change to Python interpreter being used
>
> 2 a change to the boost library being used
>
> 3 a change to lower levels in 'the s/w stack' or h/w
>
> 4 a change to the data being passed-across


Definitely not 1. 4 is always the case - every run is with different data.
2 and 3 I don’t know. What is boost and how does Python use it? None of my
code is importing it. How can get a stack trace when it crashes with just
that message?

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


terminate called after throwing an instance of 'boost::python::error_already_set

2022-05-27 Thread Larry Martell
I have a script that has literally been running for 10 years.
Suddenly, for some runs it crashes with the error:

terminate called after throwing an instance of 'boost::python::error_already_set

No stack trace. Anyone have any thoughts on what could cause this
and/or how I can track it down?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why no list as dict key?

2022-04-20 Thread Larry Martell
On Wed, Apr 20, 2022 at 2:23 PM Abdur-Rahmaan Janhangeer
 wrote:
>
> Greetings list,
>
> Using Python3.9, i cannot assign a list [1, 2] as key
> to a dictionary. Why is that so? Thanks in advanced!

Dict keys cannot be mutable. Use a tuple instead.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: calling a function asynchronously

2022-03-30 Thread Larry Martell
On Wed, Mar 30, 2022 at 2:40 PM Kirill Ratkin via Python-list
 wrote:
>
> Hi again,
>
> I changed a bit your example and it works as you expected I hope.
>
> import asyncio
>
>
> async def long():
>  for i in range(100):
>  await asyncio.sleep(10)
>  print("long is done")
>
>
> loop = asyncio.get_event_loop()
>
> task = loop.create_task(long())
> print('after asyncio.run')
> loop.run_until_complete(asyncio.gather(task))
>
>
> But how I wrote before ... if you are in big Django project just look at
> existent django libraries for long task running. One of it I sent you.
> There is 'celery' as well.
>
> It's more pragmatic way ...

Appreciate the reply. I did not know about django-background-tasks -
thanks. I've been trying to make use of that. I do not get the errors
I was getting before but it does not appear that my long running task
is running at all. Still debugging. But concerting asyncio - doesn't
run_until_complete block until long() completes?

>
> 30.03.2022 19:10, Larry Martell пишет:
> > import asyncio
> > import time
> >
> > async def long():
> >  for i in range(100):
> > time.sleep(10)
> >
> > asyncio.run(long())
> > print('after asyncio.run')
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


calling a function asynchronously

2022-03-30 Thread Larry Martell
I have a django app, and for a certain request I need to kick off a
long running task. I want to do this asynchronously and immediately
return a response. I tried using subprocess.Process() but the forked
process does not have a django database connection. I then tried
posting a request using ajax but that does not have a django session
so it's not authorized. Tried using asyncio but I am finding the
caller of the async function does not return until the async function
returns - maybe I am doing something wrong, as it does appear to be
actually asynchronous. I tried this test:

import asyncio
import time

async def long():
for i in range(100):
   time.sleep(10)

asyncio.run(long())
print('after asyncio.run')

The final print does not come out until after long() completes.

Is there any way to do this?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: All permutations from 2 lists

2022-03-03 Thread Larry Martell
On Wed, Mar 2, 2022 at 9:42 PM Avi Gross via Python-list
 wrote:
>
> Larry,
>
> i waited patiently to see what others will write and perhaps see if you 
> explain better what you need. You seem to gleefully swat down anything 
> offered. So I am not tempted to engage.

But then you gave in to the temptation.

> And it is hard to guess as it is not clear what you will do with this.

In the interests of presenting a minimal example I clearly
oversimplified. This is my use case: I get a dict from an outside
source. The dict contains key/value pairs that I need to use to query
a mongodb database. When the values in the dict are all scalar I can
pass the dict directly into the query, e.g.:
self._db_conn[collection_name].find(query). But if any of the values
are lists that does not work. I need to query with something like the
cross product of all the lists. It's not a true product since if a
list is empty it means no filtering on that field, not no filtering on
all the fields.  Originally I did not know I could generate a single
query that did that. So I was trying to come up with a way to generate
a list of all the permutations and was going to issue a query for each
individually.  Clearly that would become very inefficient if the lists
were long or there were a lot of lists. I then found that I could
specify a list with the "$in" clause, hence my solution.

> def query_lfixer(query):
> for k, v in query.items():
> if type(v)==list:
> query[k] = {"$in": v}
> return query
>
> self._db_conn[collection_name].find(query_lfixer(query))
>
>
> So why did so many of us bother?

Indeed - so why did you bother?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: All permutations from 2 lists

2022-03-02 Thread Larry Martell
On Wed, Mar 2, 2022 at 5:31 PM Joel Goldstick  wrote:
>
> On Wed, Mar 2, 2022 at 5:07 PM Larry Martell  wrote:
> >
> > On Wed, Mar 2, 2022 at 5:00 PM Cameron Simpson  wrote:
> > >
> > > On 02Mar2022 08:29, Larry Martell  wrote:
> > > >On Tue, Mar 1, 2022 at 7:32 PM Rob Cliffe  
> > > >wrote:
> > > >> I think itertools.product is what you need.
> > > >> Example program:
> > > >>
> > > >> import itertools
> > > >> opsys = ["Linux","Windows"]
> > > >> region = ["us-east-1", "us-east-2"]
> > > >> print(list(itertools.product(opsys, region)))
> > > >
> > > >This does not work if region = []. I wrote in question that either
> > > >list could be empty.
> > >
> > > What do you want to get if a list is empty? You haven't said. My
> > > personal expectation would be an empty result.
> > >
> > > Alternatively, if you expect an empty list to imply some single default
> > > the the experession:
> > >
> > > the_list or (the_default,)
> > >
> > > might be of use.
> >
> > I've solved the issue.
> > --
> > https://mail.python.org/mailman/listinfo/python-list
>
> Would you be so kind as to show the results of your solution?

I posted it at 10:49am Eastern time.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: All permutations from 2 lists

2022-03-02 Thread Larry Martell
On Wed, Mar 2, 2022 at 5:00 PM Cameron Simpson  wrote:
>
> On 02Mar2022 08:29, Larry Martell  wrote:
> >On Tue, Mar 1, 2022 at 7:32 PM Rob Cliffe  wrote:
> >> I think itertools.product is what you need.
> >> Example program:
> >>
> >> import itertools
> >> opsys = ["Linux","Windows"]
> >> region = ["us-east-1", "us-east-2"]
> >> print(list(itertools.product(opsys, region)))
> >
> >This does not work if region = []. I wrote in question that either
> >list could be empty.
>
> What do you want to get if a list is empty? You haven't said. My
> personal expectation would be an empty result.
>
> Alternatively, if you expect an empty list to imply some single default
> the the experession:
>
> the_list or (the_default,)
>
> might be of use.

I've solved the issue.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: All permutations from 2 lists

2022-03-02 Thread Larry Martell
On Wed, Mar 2, 2022 at 10:26 AM Antoon Pardon  wrote:
>
>
>
> Op 2/03/2022 om 15:58 schreef Larry Martell:
> > On Wed, Mar 2, 2022 at 9:37 AM Antoon Pardon  wrote:
> >>
> >>>>> If one list is empty I want just the other list. What I am doing is
> >>>>> building a list to pass to a mongodb query. If region is empty then I
> >>>>> want to query for just the items in the os list. I guess I can test
> >>>>> for the lists being empty, but I'd like a solution that handles that
> >>>>> as down the road there could be more than just 2 lists.
> >>>> How about the following: Keep a list of your lists you want to permute 
> >>>> over.
> >>>> Like the following:
> >>>>
> >>>> permutation_elements = [["Linux","Windows"],["us-east-1", "us-east-2"]]
> >>>>
> >>>> permutation = itertools.product(*permutation_elements)
> >>>>
> >>>> If you don't include the empty list, you will get more or less what you
> >>>> seem to want.
> >>> But I need to deal with that case.
> >> What does that mean? How does using the above method to produce the 
> >> permutations
> >> you want, prevent you from dealing with an empty list however you want 
> >> when you
> >> encounter them? Just don't add them to the permutation_elements.
> > I need to know what items are in which position. If sometimes the
> > regions are in one index and sometimes in another will not work for
> > me.
>
> I am starting to suspect you didn't think this through. What you are telling 
> here
> contradicts what you told earlier that if either list was empty, you just 
> wanted
> the other list. Because then you wouldn't know what items were in that list.
>
> The only solution I can see now is that if a list is empty, you either add 
> [None] or
> [""] to the permutation_elements (whatever suits you better) and then use
> itertools.product

I found a way to pass this directly into the query:

def query_lfixer(query):
for k, v in query.items():
if type(v)==list:
query[k] = {"$in": v}
return query

self._db_conn[collection_name].find(query_lfixer(query))
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: All permutations from 2 lists

2022-03-02 Thread Larry Martell
On Wed, Mar 2, 2022 at 9:37 AM Antoon Pardon  wrote:
>
>
>
> Op 2/03/2022 om 15:29 schreef Larry Martell:
> > On Wed, Mar 2, 2022 at 9:10 AM Antoon Pardon  wrote:
> >> Op 2/03/2022 om 14:44 schreef Larry Martell:
> >>> On Wed, Mar 2, 2022 at 8:37 AM Antoon Pardon   
> >>> wrote:
> >>>> Op 2/03/2022 om 14:27 schreef Larry Martell:
> >>>>> On Tue, Mar 1, 2022 at 7:21 PM<2qdxy4rzwzuui...@potatochowder.com>
> >>>>> wrote:
> >>>>>> On 2022-03-01 at 19:12:10 -0500,
> >>>>>> Larry Martellwrote:
> >>>>>>
> >>>>>>> If I have 2 lists, e.g.:
> >>>>>>>
> >>>>>>> os = ["Linux","Windows"]
> >>>>>>> region = ["us-east-1", "us-east-2"]
> >>>>>>>
> >>>>>>> How can I get a list of tuples with all possible permutations?
> >>>>>>>
> >>>>>>> So for this example I'd want:
> >>>>>>>
> >>>>>>> [("Linux", "us-east-1"), ("Linux", "us-east-2"), ("Windows",
> >>>>>>> "us-east-1"), "Windows", "us-east-2')]
> >>>>>>>
> >>>>>>> The lists can be different lengths or can be 0 length. Tried a few
> >>>>>>> different things with itertools but have not got just what I need.
> >>>>>> [(o, r) for o in os for r in region]
> >>>>> This does not work if region = []. I wrote in my question that either
> >>>>> list could be empty.
> >>>> What do you mean it doesn't work? The result seems to be an empty list,
> >>>> which IMO is a perfectly valid result.
> >>>>
> >>>> All possible permutations over two collections where one collection is
> >>>> empty, should IMO give you an empty collection.
> >>> If one list is empty I want just the other list. What I am doing is
> >>> building a list to pass to a mongodb query. If region is empty then I
> >>> want to query for just the items in the os list. I guess I can test
> >>> for the lists being empty, but I'd like a solution that handles that
> >>> as down the road there could be more than just 2 lists.
> >> How about the following: Keep a list of your lists you want to permute 
> >> over.
> >> Like the following:
> >>
> >> permutation_elements = [["Linux","Windows"],["us-east-1", "us-east-2"]]
> >>
> >> permutation = itertools.product(*permutation_elements)
> >>
> >> If you don't include the empty list, you will get more or less what you
> >> seem to want.
> > But I need to deal with that case.
>
> What does that mean? How does using the above method to produce the 
> permutations
> you want, prevent you from dealing with an empty list however you want when 
> you
> encounter them? Just don't add them to the permutation_elements.

I need to know what items are in which position. If sometimes the
regions are in one index and sometimes in another will not work for
me.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: All permutations from 2 lists

2022-03-02 Thread Larry Martell
On Wed, Mar 2, 2022 at 9:10 AM Antoon Pardon  wrote:
>
> Op 2/03/2022 om 14:44 schreef Larry Martell:
> > On Wed, Mar 2, 2022 at 8:37 AM Antoon Pardon  wrote:
> >>
> >> Op 2/03/2022 om 14:27 schreef Larry Martell:
> >>> On Tue, Mar 1, 2022 at 7:21 PM<2qdxy4rzwzuui...@potatochowder.com>   
> >>> wrote:
> >>>> On 2022-03-01 at 19:12:10 -0500,
> >>>> Larry Martell   wrote:
> >>>>
> >>>>> If I have 2 lists, e.g.:
> >>>>>
> >>>>> os = ["Linux","Windows"]
> >>>>> region = ["us-east-1", "us-east-2"]
> >>>>>
> >>>>> How can I get a list of tuples with all possible permutations?
> >>>>>
> >>>>> So for this example I'd want:
> >>>>>
> >>>>> [("Linux", "us-east-1"), ("Linux", "us-east-2"), ("Windows",
> >>>>> "us-east-1"), "Windows", "us-east-2')]
> >>>>>
> >>>>> The lists can be different lengths or can be 0 length. Tried a few
> >>>>> different things with itertools but have not got just what I need.
> >>>> [(o, r) for o in os for r in region]
> >>> This does not work if region = []. I wrote in my question that either
> >>> list could be empty.
> >> What do you mean it doesn't work? The result seems to be an empty list,
> >> which IMO is a perfectly valid result.
> >>
> >> All possible permutations over two collections where one collection is
> >> empty, should IMO give you an empty collection.
> > If one list is empty I want just the other list. What I am doing is
> > building a list to pass to a mongodb query. If region is empty then I
> > want to query for just the items in the os list. I guess I can test
> > for the lists being empty, but I'd like a solution that handles that
> > as down the road there could be more than just 2 lists.
>
> How about the following: Keep a list of your lists you want to permute over.
> Like the following:
>
> permutation_elements = [["Linux","Windows"],["us-east-1", "us-east-2"]]
>
> permutation = itertools.product(*permutation_elements)
>
> If you don't include the empty list, you will get more or less what you
> seem to want.

But I need to deal with that case.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: All permutations from 2 lists

2022-03-02 Thread Larry Martell
On Wed, Mar 2, 2022 at 8:54 AM Joel Goldstick  wrote:
>
> On Wed, Mar 2, 2022 at 8:46 AM Larry Martell  wrote:
> >
> > On Wed, Mar 2, 2022 at 8:37 AM Antoon Pardon  wrote:
> > >
> > >
> > > Op 2/03/2022 om 14:27 schreef Larry Martell:
> > > > On Tue, Mar 1, 2022 at 7:21 PM<2qdxy4rzwzuui...@potatochowder.com>  
> > > > wrote:
> > > >> On 2022-03-01 at 19:12:10 -0500,
> > > >> Larry Martell  wrote:
> > > >>
> > > >>> If I have 2 lists, e.g.:
> > > >>>
> > > >>> os = ["Linux","Windows"]
> > > >>> region = ["us-east-1", "us-east-2"]
> > > >>>
> > > >>> How can I get a list of tuples with all possible permutations?
> > > >>>
> > > >>> So for this example I'd want:
> > > >>>
> > > >>> [("Linux", "us-east-1"), ("Linux", "us-east-2"), ("Windows",
> > > >>> "us-east-1"), "Windows", "us-east-2')]
> > > >>>
> > > >>> The lists can be different lengths or can be 0 length. Tried a few
> > > >>> different things with itertools but have not got just what I need.
> > > >> [(o, r) for o in os for r in region]
> > > > This does not work if region = []. I wrote in my question that either
> > > > list could be empty.
> > >
> > > What do you mean it doesn't work? The result seems to be an empty list,
> > > which IMO is a perfectly valid result.
> > >
> > > All possible permutations over two collections where one collection is
> > > empty, should IMO give you an empty collection.
> >
> > If one list is empty I want just the other list. What I am doing is
> > building a list to pass to a mongodb query. If region is empty then I
> > want to query for just the items in the os list. I guess I can test
> > for the lists being empty, but I'd like a solution that handles that
> > as down the road there could be more than just 2 lists.
> > --
> > https://mail.python.org/mailman/listinfo/python-list
>
> Does this help you out:
>
> >>> [(o,r) for o in opsys for r in region or "x"]
> [('Linux', 'x'), ('Window', 'x')]

That doesn't work if opsys = [] - either list could be empty.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: All permutations from 2 lists

2022-03-02 Thread Larry Martell
On Wed, Mar 2, 2022 at 8:37 AM Antoon Pardon  wrote:
>
>
> Op 2/03/2022 om 14:27 schreef Larry Martell:
> > On Tue, Mar 1, 2022 at 7:21 PM<2qdxy4rzwzuui...@potatochowder.com>  wrote:
> >> On 2022-03-01 at 19:12:10 -0500,
> >> Larry Martell  wrote:
> >>
> >>> If I have 2 lists, e.g.:
> >>>
> >>> os = ["Linux","Windows"]
> >>> region = ["us-east-1", "us-east-2"]
> >>>
> >>> How can I get a list of tuples with all possible permutations?
> >>>
> >>> So for this example I'd want:
> >>>
> >>> [("Linux", "us-east-1"), ("Linux", "us-east-2"), ("Windows",
> >>> "us-east-1"), "Windows", "us-east-2')]
> >>>
> >>> The lists can be different lengths or can be 0 length. Tried a few
> >>> different things with itertools but have not got just what I need.
> >> [(o, r) for o in os for r in region]
> > This does not work if region = []. I wrote in my question that either
> > list could be empty.
>
> What do you mean it doesn't work? The result seems to be an empty list,
> which IMO is a perfectly valid result.
>
> All possible permutations over two collections where one collection is
> empty, should IMO give you an empty collection.

If one list is empty I want just the other list. What I am doing is
building a list to pass to a mongodb query. If region is empty then I
want to query for just the items in the os list. I guess I can test
for the lists being empty, but I'd like a solution that handles that
as down the road there could be more than just 2 lists.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: All permutations from 2 lists

2022-03-02 Thread Larry Martell
On Tue, Mar 1, 2022 at 7:32 PM Rob Cliffe  wrote:
>
> I would not use `os` as an identifier, as it is the name of an important
> built-in module.

This is part of a much larger data structure, I created a simplified
example. It is not actually called os.

> I think itertools.product is what you need.
> Example program:
>
> import itertools
> opsys = ["Linux","Windows"]
> region = ["us-east-1", "us-east-2"]
> print(list(itertools.product(opsys, region)))

This does not work if region = []. I wrote in question that either
list could be empty.

> Output:
>
> [('Linux', 'us-east-1'), ('Linux', 'us-east-2'), ('Windows',
> 'us-east-1'), ('Windows', 'us-east-2')]
>
> itertools.product returns an iterator (or iterable, I'm not sure of the
> correct technical term).
> If you only want to use the result once you can write e.g.
>
>  for ops, reg in itertools.product(opsys, region):
>  etc.
>
> If you need it more than once, you can convert it to a list (or tuple),
> as above.
> Best wishes
> Rob Cliffe
>
> On 02/03/2022 00:12, Larry Martell wrote:
> > If I have 2 lists, e.g.:
> >
> > os = ["Linux","Windows"]
> > region = ["us-east-1", "us-east-2"]
> >
> > How can I get a list of tuples with all possible permutations?
> >
> > So for this example I'd want:
> >
> > [("Linux", "us-east-1"), ("Linux", "us-east-2"), ("Windows",
> > "us-east-1"), "Windows", "us-east-2')]
> >
> > The lists can be different lengths or can be 0 length. Tried a few
> > different things with itertools but have not got just what I need.
> >
> > TIA!
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: All permutations from 2 lists

2022-03-02 Thread Larry Martell
On Tue, Mar 1, 2022 at 7:21 PM <2qdxy4rzwzuui...@potatochowder.com> wrote:
>
> On 2022-03-01 at 19:12:10 -0500,
> Larry Martell  wrote:
>
> > If I have 2 lists, e.g.:
> >
> > os = ["Linux","Windows"]
> > region = ["us-east-1", "us-east-2"]
> >
> > How can I get a list of tuples with all possible permutations?
> >
> > So for this example I'd want:
> >
> > [("Linux", "us-east-1"), ("Linux", "us-east-2"), ("Windows",
> > "us-east-1"), "Windows", "us-east-2')]
> >
> > The lists can be different lengths or can be 0 length. Tried a few
> > different things with itertools but have not got just what I need.
>
> [(o, r) for o in os for r in region]

This does not work if region = []. I wrote in my question that either
list could be empty.
-- 
https://mail.python.org/mailman/listinfo/python-list


All permutations from 2 lists

2022-03-01 Thread Larry Martell
If I have 2 lists, e.g.:

os = ["Linux","Windows"]
region = ["us-east-1", "us-east-2"]

How can I get a list of tuples with all possible permutations?

So for this example I'd want:

[("Linux", "us-east-1"), ("Linux", "us-east-2"), ("Windows",
"us-east-1"), "Windows", "us-east-2')]

The lists can be different lengths or can be 0 length. Tried a few
different things with itertools but have not got just what I need.

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


Re: SQLALchemy: update with in clause from kwargs

2021-08-04 Thread Larry Martell
On Tue, Aug 3, 2021 at 7:26 PM dn via Python-list
 wrote:
>
> On 04/08/2021 13.08, Larry Martell wrote:
> > I am trying to write a function that takes kwargs as a param and
> > generates an update statement where the rows to be updated are
> > specified in an in clause.
> >
> > Something like this:
> >
> > def update_by_in(self, **kwargs):
> > filter_group = []
> > for col in kwargs['query_params']:
> > # obviously this line does not work as col is a string,
> > but this is the intent
> > filter_group.append(col.in_(tuple(kwargs['query_params'][col])))
> >
> > 
> > self._session.query(self.model_class).filter(*filter_group).update(kwargs['values'])
> >
> > self.update_by_in(
> > **{'query_params': {'companyCode': ['A', 'B', 'C']},
> > 'values': {'portfolioName': 'test'}}
> >  )
> >
> > Is there a way to do this? I think I need to use setattr in building
> > up the filter_group list, but I'm not quite sure how to do it.
>
>
> When feeling bamboozled by a problem, particularly when using
> sophisticated tools such as SQLAlchemy, the trick is often to simplify
> the problem.
>
> Step 1 (using the sample data provided)
> Write the query on paper - and as constant-values.
>
> Step 2
> Compare the two input dicts with that requirement.
>
> Step 3
> Work-out the transformation(s) required...
>
>
> One complexity is that the parameter to update_by_in() is formed by
> joining two dicts. However, the function later tries to treat them in
> distinct fashions. Why the join/why not two parameters?
>
> companyCode = ['A', 'B', 'C']
> values = {'portfolioName': 'test'}
>
> leading to:
>
> self.update_by_in( companyCode, values )
>
> and:
>
> def update_by_in(self, company_code, portfolio_type ):
> 
>
>
> As to the core of the question-asked, I'm a little confused (which may
> be my fuzzy head). Do you want the update(s) - portrayed as a list -
> like this:
>
> [('A', 'test'), ('B', 'test'), ('C', 'test')]
>
> like this:
>
> [('A', 'portfolioName'), ('B', None), ('C', None)]
>
> or only:
>
> [('A', 'portfolioName')]
>
>
> You will find a friend in the itertools (PSL) library:
>
> import itertools as it
>
> list( it.product( companyCode, values.values() ) )
> [('A', 'test'), ('B', 'test'), ('C', 'test')]
>
> list( it.zip_longest( companyCode, values.values() ) )
> [('A', 'test'), ('B', None), ('C', None)]
>
> list( zip( companyCode, values ) )
> [('A', 'portfolioName')]
>
>
> Now, have we simplified things to the point of being able to more-easily
> code the update and filter?

I appreciate the reply, but it does not address my issue, which was
how to get at the column object. Turned out that was simple enough:

for col in kwargs['query_params']:
attr = getattr(self.model_class, col)
filter_group.append(attr.in_(tuple(kwargs['query_params'][col])))

Unfortunately that is causing something to change the query_params, as
filter group ends up like:

print(type(filter_group[0]))



print(filter_group[0])

dbo."Portfolio"."companyCode" IN (:companyCode_1, :companyCode_2,
:companyCode_3)

Which then fails with:

sqlalchemy.orm.evaluator.UnevaluatableError: Cannot evaluate
clauselist with operator 

This has now become more of a sqlalchemy question than a python one.
-- 
https://mail.python.org/mailman/listinfo/python-list


SQLALchemy: update with in clause from kwargs

2021-08-03 Thread Larry Martell
I am trying to write a function that takes kwargs as a param and
generates an update statement where the rows to be updated are
specified in an in clause.

Something like this:

def update_by_in(self, **kwargs):
filter_group = []
for col in kwargs['query_params']:
# obviously this line does not work as col is a string,
but this is the intent
filter_group.append(col.in_(tuple(kwargs['query_params'][col])))


self._session.query(self.model_class).filter(*filter_group).update(kwargs['values'])

self.update_by_in(
**{'query_params': {'companyCode': ['A', 'B', 'C']},
'values': {'portfolioName': 'test'}}
 )

Is there a way to do this? I think I need to use setattr in building
up the filter_group list, but I'm not quite sure how to do it.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is there a conference in the US that is similar to EuroPython?

2021-07-19 Thread Larry Martell
On Mon, Jul 19, 2021 at 10:01 AM Schachner, Joseph
 wrote:
>
> I am not going to fly to Europe for a Python conference.  But, would consider 
> going if in the U.S.A.   Especially if drivable ... NYC area would be ideal.
>
> I ask because I have seen ads for EuroPython over several years, and I don't 
> remember seeing similar ads for something similar in the U.S.A.

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


Re: creating raw AWS log event

2021-06-24 Thread Larry Martell
On Thu, Jun 24, 2021 at 10:38 AM Larry Martell  wrote:
>
> On Thu, Jun 24, 2021 at 12:20 AM Peter Otten <__pete...@web.de> wrote:
> >
> > On 23/06/2021 19:42, Larry Martell wrote:
> > > When an AWS cloudwatch event is passed to a consumer it looks like this:
> > >
> > > {
> > >  "awslogs": {
> > >   "data": "ewogICAgIm1l..."
> > >   }
> > > }
> > >
> > > To get the actual message I do this:
> > >
> > > def _decode(data):
> > >  compressed_payload = b64decode(data)
> > >  json_payload = zlib.decompress(compressed_payload, 16+zlib.MAX_WBITS)
> > >  return json.loads(json_payload)
> > >
> > > message = _decode(json.dumps(event['awslogs']['data']))
> > >
> > > This returns the log message as a string.
> > >
> > > For my unit tests I need to reverse this - given a message as a string
> > > I want to generate the compressed, encoded event structure.
> > >
> > > I have not been able to get this to work. I have this:
> > >
> > > message  = b'test message'
> > > compressed= zlib.compress(message)
> > > event['awslogs']['data'] = str(compressed)
> > >
> > > message = _decode(json.dumps(event['awslogs']['data']))
> > > Traceback (most recent call last):
> > >File "", line 1, in 
> > >File "", line 3, in _decode
> > > zlib.error: Error -3 while decompressing data: incorrect header check
> > >
> > > Anyone see how to make this work?
> >
> > The json/bas64 parts are not involved in the problem:
> >
> >  >>> zlib.decompress(zlib.compress(b"foo"), 16 + zlib.MAX_WBITS)
> > Traceback (most recent call last):
> >File "", line 1, in 
> >  zlib.decompress(zlib.compress(b"foo"), 16 + zlib.MAX_WBITS)
> > zlib.error: Error -3 while decompressing data: incorrect header check
> >
> > whereas:
> >
> >  >>> zlib.decompress(zlib.compress(b"foo"))
> > b'foo'
> >
> > Unfortunately compress() doesn't accept the flags you seem to require.
> > However, reading around a bit in the zlib docs turns up the compressobj
> > which does. So
> >
> >  >>> def mycompress(data):
> > obj = zlib.compressobj(wbits=16 + zlib.MAX_WBITS)
> > result = obj.compress(data)
> > result += obj.flush()
> > return result
> >
> >  >>> zlib.decompress(mycompress(b"foo"), 16 + zlib.MAX_WBITS)
> > b'foo'
>
> Thanks. Turns out I don't need this after all.

Well I did need this after all and this works perfectly. Thanks so much!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: creating raw AWS log event

2021-06-24 Thread Larry Martell
On Thu, Jun 24, 2021 at 12:20 AM Peter Otten <__pete...@web.de> wrote:
>
> On 23/06/2021 19:42, Larry Martell wrote:
> > When an AWS cloudwatch event is passed to a consumer it looks like this:
> >
> > {
> >  "awslogs": {
> >   "data": "ewogICAgIm1l..."
> >   }
> > }
> >
> > To get the actual message I do this:
> >
> > def _decode(data):
> >  compressed_payload = b64decode(data)
> >  json_payload = zlib.decompress(compressed_payload, 16+zlib.MAX_WBITS)
> >  return json.loads(json_payload)
> >
> > message = _decode(json.dumps(event['awslogs']['data']))
> >
> > This returns the log message as a string.
> >
> > For my unit tests I need to reverse this - given a message as a string
> > I want to generate the compressed, encoded event structure.
> >
> > I have not been able to get this to work. I have this:
> >
> > message  = b'test message'
> > compressed= zlib.compress(message)
> > event['awslogs']['data'] = str(compressed)
> >
> > message = _decode(json.dumps(event['awslogs']['data']))
> > Traceback (most recent call last):
> >File "", line 1, in 
> >File "", line 3, in _decode
> > zlib.error: Error -3 while decompressing data: incorrect header check
> >
> > Anyone see how to make this work?
>
> The json/bas64 parts are not involved in the problem:
>
>  >>> zlib.decompress(zlib.compress(b"foo"), 16 + zlib.MAX_WBITS)
> Traceback (most recent call last):
>File "", line 1, in 
>  zlib.decompress(zlib.compress(b"foo"), 16 + zlib.MAX_WBITS)
> zlib.error: Error -3 while decompressing data: incorrect header check
>
> whereas:
>
>  >>> zlib.decompress(zlib.compress(b"foo"))
> b'foo'
>
> Unfortunately compress() doesn't accept the flags you seem to require.
> However, reading around a bit in the zlib docs turns up the compressobj
> which does. So
>
>  >>> def mycompress(data):
> obj = zlib.compressobj(wbits=16 + zlib.MAX_WBITS)
> result = obj.compress(data)
> result += obj.flush()
> return result
>
>  >>> zlib.decompress(mycompress(b"foo"), 16 + zlib.MAX_WBITS)
> b'foo'

Thanks. Turns out I don't need this after all.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: creating raw AWS log event

2021-06-23 Thread Larry Martell
On Wed, Jun 23, 2021 at 7:05 PM Dennis Lee Bieber  wrote:
>
> On Wed, 23 Jun 2021 10:42:42 -0700, Larry Martell 
> declaimed the following:
>
> >def _decode(data):
> >compressed_payload = b64decode(data)
> >json_payload = zlib.decompress(compressed_payload, 16+zlib.MAX_WBITS)
> >return json.loads(json_payload)
> >
>
> >message  = b'test message'
> >compressed= zlib.compress(message)
> >event['awslogs']['data'] = str(compressed)
>
> Where do you perform a B64 ENCODE operation?
>
> str() doesn't do that, it just converts the argument to a string which
> may mean using escapes for non-printable bytes. B64 converts everything to
> printable characters.

Copy/paste fail. This is actually the code I tried:

message = b'test message'
compressed= zlib.compress(message)
encoded = b64encode(compressed)
event['awslogs']['data'] = str(encoded)
message = _decode(json.dumps(event['awslogs']['data']))
-- 
https://mail.python.org/mailman/listinfo/python-list


creating raw AWS log event

2021-06-23 Thread Larry Martell
When an AWS cloudwatch event is passed to a consumer it looks like this:

{
"awslogs": {
 "data": "ewogICAgIm1l..."
 }
}

To get the actual message I do this:

def _decode(data):
compressed_payload = b64decode(data)
json_payload = zlib.decompress(compressed_payload, 16+zlib.MAX_WBITS)
return json.loads(json_payload)

message = _decode(json.dumps(event['awslogs']['data']))

This returns the log message as a string.

For my unit tests I need to reverse this - given a message as a string
I want to generate the compressed, encoded event structure.

I have not been able to get this to work. I have this:

message  = b'test message'
compressed= zlib.compress(message)
event['awslogs']['data'] = str(compressed)

message = _decode(json.dumps(event['awslogs']['data']))
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 3, in _decode
zlib.error: Error -3 while decompressing data: incorrect header check

Anyone see how to make this work?

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


Best practices regarding PYTHONPATH

2021-03-09 Thread Larry Martell
Which is considered better? Having a long import path or setting PYTHONPATH?

For example, in a project where 50% of the imports come from the same top
level directory is it better to add that dir to the path or reference it in
the import statements?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: yield from () Was: Re: weirdness with list()

2021-03-02 Thread Larry Martell
On Tue, Mar 2, 2021 at 2:16 PM Chris Angelico  wrote:
>
> On Tue, Mar 2, 2021 at 5:51 AM Alan Gauld via Python-list
>  wrote:
> >
> > On 28/02/2021 00:17, Cameron Simpson wrote:
> >
> > > BUT... It also has a __iter__ value, which like any Box iterates over
> > > the subboxes. For MDAT that is implemented like this:
> > >
> > > def __iter__(self):
> > > yield from ()
> >
> > Sorry, a bit OT but I'm curious. I haven't seen
> > this before:
> >
> > yield from ()
> >
> > What is it doing?
> > What do the () represent in this context?
> >
>
> It's yielding all the elements in an empty tuple. Which is none of
> them, meaning that - for this simple example - iterating over the
> object will produce zero results.

I discovered something new (to me) yesterday. Was writing a unit test
for generator function and I found that none of the function got
executed at all until I iterated on the return value. It was blowing
my mind as I was debugging the test and had a BP set in the first line
of the function but it was not hit when I called the function.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: comparing two lists

2021-02-24 Thread Larry Martell
On Wed, Feb 24, 2021 at 4:45 PM Davor Levicki  wrote:
>
> i have two lists
>
> list1 = ['01:15', 'abc', '01:15', 'def', '01:45', 'ghi' ]
> list2 =  ['01:15', 'abc', '01:15', 'uvz', '01:45', 'ghi' ]
>
> and when I loop through the list
>
>
> list_difference = []
> for item in list1:
>
>   if item not in list2:
> list_difference.append(item)
>
>
> and I managed to get the difference, but I need time as well
> because it is a separate item and 'uvz' does not mean to me anything in the 
> list with a few thousand entries.
> I tried to convert it to the dictionary, but it overwrites with last 
> key:value {'01:15' : 'def'}

Instead of a list you could have a set of tuples and then just subtract them.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do you find what exceptions a class can throw?

2020-12-21 Thread Larry Martell
On Sun, Dec 20, 2020 at 9:36 PM Chris Angelico  wrote:
>
> On Mon, Dec 21, 2020 at 1:11 PM Julio Di Egidio  wrote:
> > > Gathering evidence is indeed part of science, and computer science is
> > > indeed mathematics, but alas programmering is just a craft and software
> > > engineering often ... isn't.
> >
> > Programming is a *discipline*
>
> It's a discipline, a science, AND an art. I love programming :)


I love it too. But I think it’s a craft not an art. I think of art as
totally unconstrained, and a craft as having to functionally work.

I really like this quote: "Debugging is like being the detective in a
crime movie where you are also the murderer." - Filipe Fortes
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: list of dictionaries search using kwargs

2020-12-07 Thread Larry Martell
On Mon, Dec 7, 2020 at 5:42 PM Matt Wheeler  wrote:
>
> for item in self.data:
> if all(item[k] == v for k,v in kwargs.items()):
> return item
>
> Or
>
> return [item for item in self.data if all(item[k] == v for k,v in 
> kwargs.items())]
>
> to return all matches
>
> Beware though that either of these will be slow if your list of dicts is 
> large.
> If the list is large enough that this becomes slow, consider using a database 
> (e.g. sqlite or other SQL DB) instead.

Thanks! Works perfectly.

> On 7 Dec 2020, 22:06 +, Larry Martell , wrote:
>
> I have a class that has an object that contains a list of dicts. I
>
> want to have a class method that takes a variable number of key/value
>
> pairs and searches the list and returns the item that matches the
>
> arguments.
>
>
> If I know the key value pairs I can do something like this:
>
>
> instance = next(item for item in data] if\
>
> item["appCode"] == 1 and\
>
> item["componentCode"] == "DB" and\
>
> item["environmentEnumID"] == 12 and\
>
> item["serverName"] == 'foo', None)
>
>
> But in my class method if I have:
>
>
> def find_data_row(self, **kwargs):
>
>
> and I call it:
>
>
> find_data_row(appCode=1, componentCode='DB', ...)
>
>
> How can I do the search in a pythonic way?
>
> --
>
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: list of dictionaries search using kwargs

2020-12-07 Thread Larry Martell
On Mon, Dec 7, 2020 at 5:29 PM Marco Sulla  wrote:
>
> You can return dictionaries that returns True if
>
> (a.items() & kwargs.items()) == kwargs.items()
>
> when `a` is one of your dicts.

But what is passed in kwargs will not necessarily have values for all
of the keys and I only want to check for matches with the ones passed
in.
-- 
https://mail.python.org/mailman/listinfo/python-list


list of dictionaries search using kwargs

2020-12-07 Thread Larry Martell
I have a class that has an object that contains a list of dicts. I
want to have a class method that takes a variable number of key/value
pairs and searches the list and returns the item that matches the
arguments.

If I know the key value pairs I can do something like this:

instance = next(item for item in data] if\
   item["appCode"] == 1 and\
   item["componentCode"] == "DB" and\
   item["environmentEnumID"] == 12 and\
   item["serverName"] == 'foo', None)

But in my class method if I have:

def find_data_row(self, **kwargs):

and I call it:

find_data_row(appCode=1, componentCode='DB', ...)

How can I do the search in a pythonic way?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Time Date Conversion?

2020-11-04 Thread Larry Martell
On Wed, Nov 4, 2020 at 6:21 PM Steve  wrote:
>
> The text File entry is:
>BPd 2020-11-04 17:28:03.352027  66
>
> I bring it into the program using:
> with open("_TIME-DATE.txt" , 'r') as infile:
>  for lineEQN in infile: # loop to find each line in the file for that
> dose
> and set it in a variable as follows:
> ItemDateTime = lineEQN[7:36].strip()
>
> When I print ItemDateTime, it looks like:
>   2020-11-04 17:28:03.352027
>
> How do I display it as "Wednesday, November 4, 2020 5:28pm" ?

Look at strptime/strftime
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python mariadb & html tables

2020-09-15 Thread Larry Martell
On Tue, Sep 15, 2020 at 1:35 PM SS  wrote:
>
> On Tuesday, September 15, 2020 at 2:52:35 PM UTC-4, larry.mart...@gmail.com 
> wrote:
> > On Tue, Sep 15, 2020 at 11:45 AM SS  wrote:
> > >
> > > I'm trying to create an table in html from a Maria DB table, from a 
> > > python script. I'm getting some unexpected results.
> > >
> > > The environment is Centos 7, I'm using Python3 with apache.
> > >
> > > Here is copy of the script I'm using:
> > >
> > > *** SCRIPT START *
> > >
> > > import mysql.connector
> > > import cgitb
> > > cgitb.enable()
> > >
> > > mydb = mysql.connector.connect(
> > > host="localhost",
> > > user="root",
> > > password="somepassword",
> > > database="somedb"
> > > )
> > >
> > > mycursor = mydb.cursor()
> > >
> > > mycursor.execute("select name, provisioned_space, used_space, 
> > > memory_size, cpus, ip_address, host_cpu, host_mem from projecttable where 
> > > name like '%newproject%'")
> > >
> > > myresult = mycursor.fetchall()
> > >
> > > print "Content-type: text/plain:charset=utf-8"
> > > print
> > > for x in myresult:
> > > print(x)
> > >
> > >
> > > *** SCRIPT STOPS *
> > >
> > > It works. But I get alot of extraneous data I don't need or want. Here is 
> > > an example of the output:
> > >
> > > * OUTPUT STARTS ***
> > >
> > > Content-type: text/plain:charset=utf-8
> > >
> > > (u'host1.mydomain.com', u'106.11 GB', u'32.72 GB', u'1 GB', u'1', 
> > > u'172.18.33.62', u'Running', u'16 MHz')
> > > (u'hopst2.mydomain.com', u'106.08 GB', u'56.87 GB', u'1 GB', u'1', 
> > > u'172.17.4.82', u'Running', u'0 Hz')
> > >
> > > * OUTPUT STOPS ***
> > >
> > > Is this typical of Python? Do I need create another script to clean up 
> > > the output? Or is there a better way to extract data from a MariaDB 
> > > instance, and put it in an HTML table? Any advise would be appreciated.
> > What is the extraneous data?
>
> The extraneous data is:
>
> (u'host1.mydomain.com', u'106.11 GB', u'32.72 GB', u'1 GB', u'1', 
> u'172.18.33.62', u'Running', u'16 MHz')
>
> It is all the u characters, the single quotes, and the parenthesis.  
> Ultimately, I would like to create an html table in an html page, from a a 
> MariaDB table.

That is how the data is printed - those things are not part of the
data. To generate HTML you will have to iterate over the result set
and create the needed markup. E.g.:

html = ""
for row in myresult:
html += ""
for item in row:
html += "%s" % item
html += ""
html += ""
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python mariadb & html tables

2020-09-15 Thread Larry Martell
On Tue, Sep 15, 2020 at 11:45 AM SS  wrote:
>
> I'm trying to create an table in html from a Maria DB table, from a python 
> script.  I'm getting some unexpected results.
>
> The environment is Centos 7, I'm using Python3 with apache.
>
> Here is copy of the script I'm using:
>
> *** SCRIPT START *
>
> import mysql.connector
> import cgitb
> cgitb.enable()
>
> mydb = mysql.connector.connect(
>   host="localhost",
>   user="root",
>   password="somepassword",
>   database="somedb"
> )
>
> mycursor = mydb.cursor()
>
> mycursor.execute("select name, provisioned_space, used_space, memory_size, 
> cpus, ip_address, host_cpu, host_mem from projecttable where name like 
> '%newproject%'")
>
> myresult = mycursor.fetchall()
>
> print "Content-type: text/plain:charset=utf-8"
> print
> for x in myresult:
>   print(x)
>
>
> *** SCRIPT STOPS *
>
> It works.  But I get alot of extraneous data I don't need or want.  Here is 
> an example of the output:
>
> * OUTPUT STARTS ***
>
> Content-type: text/plain:charset=utf-8
>
> (u'host1.mydomain.com', u'106.11 GB', u'32.72 GB', u'1 GB', u'1', 
> u'172.18.33.62', u'Running', u'16 MHz')
> (u'hopst2.mydomain.com', u'106.08 GB', u'56.87 GB', u'1 GB', u'1', 
> u'172.17.4.82', u'Running', u'0 Hz')
>
> * OUTPUT STOPS ***
>
> Is this typical of Python?  Do I need create another script to clean up the 
> output?  Or is there a better way to extract data from a MariaDB instance, 
> and put it in an HTML table? Any advise would be appreciated.

What is the extraneous data?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: grouping and sorting within groups using another list

2020-09-02 Thread Larry Martell
On Wed, Sep 2, 2020 at 11:22 AM David Raymond  wrote:
>
> Would it be something as simple as:
>
> rows.sort(key = lambda x: (x[0], x[3], x[4], sort_list.index(x[6])))

This is perfect - thanks!


> -Original Message-
> From: Python-list  
> On Behalf Of Larry Martell
> Sent: Wednesday, September 2, 2020 1:55 PM
> To: Python 
> Subject: grouping and sorting within groups using another list
>
> I have a list of tuples, and I want to group them by 3 items (0, 3, 4)
> and then within each group sort the data by a 4th item (6) using a
> sort order from another list. The list is always ordered by the 3
> grouping items.
>
> For example, if I have this list:
> rows =
> [('a', 'b', 'c', 'd', 'e', 'f', 'blue', ),
>  ('a', 'x', 'y', 'd', 'e', 'f', 'green', ),
>  ('a', 'q', 'w', 'd', 'e', 'f', 'white', ),
>  ('p', 'x', 'y', 'd', 'e', 'f', 'white', ),
>  ('p', 'x', 'y', 'd', 'e', 'f', ' 'blue', ...),
>  ('p', 'x', 'y', 'd', 'e', 'f', ' 'green', ...),
>  ('z', 'x', 'y', 'm', 'n', 'o', 'green, ...),
>  ('z', 'x', 'y', 'm', 'n', 'o', 'white, ...),
>  ('z', 'x', 'y', 'm', 'n', 'o', 'blue, ...),
> ]
>
> and I have a list:
>
> sort_list = ['blue', 'white', 'green']
>
> Then the result list would be:
>
> [('a', 'b', 'c', 'd', 'e', 'f', 'blue', ),
>  ('a', 'x', 'y', 'd', 'e', 'f', 'white', ),
>  ('a', 'q', 'w', 'd', 'e', 'f', 'green', ),
>  ('p', 'x', 'y', 'd', 'e', 'f', 'blue', ),
>  ('p', 'x', 'y', 'd', 'e', 'f', ' 'white', ...),
>  ('p', 'x', 'y', 'd', 'e', 'f', ' 'green', ...),
>  ('z', 'x', 'y', 'm', 'n', 'o', 'blue, ...),
>  ('z', 'x', 'y', 'm', 'n', 'o', 'white, ...),
>  ('z', 'x', 'y', 'm', 'n', 'o', 'green, ...),
> ]
>
> Been trying to do with using groupby but have not been successful.
-- 
https://mail.python.org/mailman/listinfo/python-list


grouping and sorting within groups using another list

2020-09-02 Thread Larry Martell
I have a list of tuples, and I want to group them by 3 items (0, 3, 4)
and then within each group sort the data by a 4th item (6) using a
sort order from another list. The list is always ordered by the 3
grouping items.

For example, if I have this list:
rows =
[('a', 'b', 'c', 'd', 'e', 'f', 'blue', ),
 ('a', 'x', 'y', 'd', 'e', 'f', 'green', ),
 ('a', 'q', 'w', 'd', 'e', 'f', 'white', ),
 ('p', 'x', 'y', 'd', 'e', 'f', 'white', ),
 ('p', 'x', 'y', 'd', 'e', 'f', ' 'blue', ...),
 ('p', 'x', 'y', 'd', 'e', 'f', ' 'green', ...),
 ('z', 'x', 'y', 'm', 'n', 'o', 'green, ...),
 ('z', 'x', 'y', 'm', 'n', 'o', 'white, ...),
 ('z', 'x', 'y', 'm', 'n', 'o', 'blue, ...),
]

and I have a list:

sort_list = ['blue', 'white', 'green']

Then the result list would be:

[('a', 'b', 'c', 'd', 'e', 'f', 'blue', ),
 ('a', 'x', 'y', 'd', 'e', 'f', 'white', ),
 ('a', 'q', 'w', 'd', 'e', 'f', 'green', ),
 ('p', 'x', 'y', 'd', 'e', 'f', 'blue', ),
 ('p', 'x', 'y', 'd', 'e', 'f', ' 'white', ...),
 ('p', 'x', 'y', 'd', 'e', 'f', ' 'green', ...),
 ('z', 'x', 'y', 'm', 'n', 'o', 'blue, ...),
 ('z', 'x', 'y', 'm', 'n', 'o', 'white, ...),
 ('z', 'x', 'y', 'm', 'n', 'o', 'green, ...),
]

Been trying to do with using groupby but have not been successful.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python database compatibility

2020-06-12 Thread Larry Martell
On Fri, Jun 12, 2020 at 5:03 PM Siddharth Joshi  wrote:
>
> All,
>
> I am new in Python world and would like to use it for one of the our
> purpose . Before that, I would like to ask if Python has compatibility with
> ENSCRIBE database .
>
> Enscribe database (file structured) is the native database of HP NonStop
> (Tandem) server, mainly used in applications running on nonStop Tandem .
> Almost all the applications which runs on Tandem using enscribe are Tier 0
> applications (often critical once).
>
> Would be good if anyone let me know on Python and Enscribe compatibility.

If you can use ODBC with it then you can use python with it.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: exiting a while loop

2020-05-22 Thread Larry Martell
On Fri, May 22, 2020 at 7:51 AM John Yeadon via Python-list
 wrote:
>
> Am I unreasonable in expecting this code to exit when required?
>
>
> # Add up the powers of 2 starting with 2**0 until 2 million is met.
> n = 1
> target = 200
> sum = 0
>
> while True:
>  x = 2 ** (n - 1)
>  sum += x
>  print(n, sum)
>  if sum >= target:
>  print("Target met.")
>  exit
>  n += 1
>
> print("\n", n, "terms are required.")

exit()
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Display, EasyProcess

2020-05-21 Thread Larry Martell
On Thu, May 21, 2020 at 3:44 AM Peter Otten <__pete...@web.de> wrote:
>
> Larry Martell wrote:
>
> > I have some code that uses the pyvirtualdisplay package and it works fine.
> >
> > pyvirtualdisplay,Display calls EasyProcess like this:
> >
> >@classmethod
> >def check_installed(cls):
> >EasyProcess([PROGRAM, '-help'], url=URL,
> >ubuntu_package=PACKAGE).check_installed()
> >
> > I made a branch and made some changes. In the branch, when I
> > instantiate Display and it gets to this point it fails with:
> >
> > TypeError: __init__() got an unexpected keyword argument 'url'
>
> I took a look at the source, and the code causing the error was removed back
> in december:
>
> https://github.com/ponty/PyVirtualDisplay/commit/37613e36cf311bf855ac0af7850ffc85ac0635c6#diff-cdb8c67ac0a9554cd28f4f4bfc06fcf4
>
> I suggest that you update your version of the pyvirtualdisplay package.

Thanks. That did the trick!
-- 
https://mail.python.org/mailman/listinfo/python-list


Display, EasyProcess

2020-05-20 Thread Larry Martell
I have some code that uses the pyvirtualdisplay package and it works fine.

pyvirtualdisplay,Display calls EasyProcess like this:

   @classmethod
   def check_installed(cls):
   EasyProcess([PROGRAM, '-help'], url=URL,
   ubuntu_package=PACKAGE).check_installed()

I made a branch and made some changes. In the branch, when I
instantiate Display and it gets to this point it fails with:

TypeError: __init__() got an unexpected keyword argument 'url'

There are no changes in my branch related to using Display. What's
very odd is that the __init__() function for EasyProcess has this
signature, and the call to it from Display is the same in my master
branch and it works:

def __init__(
self, cmd, cwd=None, use_temp_files=True, env=None,
):

So that url param must be getting passed to something else.

I did some googling and found a post on SO where someone was having
the same issue, and the answer was that they overrode the EasyProcess
__init__ with their own init. If I am doing that I have no clue how
that could be. I did inspect EasyProcess just before the call and it
was the correct code.

Here is the end of the stack trace:

-> display = Display(visible=0, size=(800, 600))
> /usr/local/lib/python3.7/site-packages/pyvirtualdisplay/display.py(33)__init__()
-> self._obj = self.display_class(
  
/usr/local/lib/python3.7/site-packages/pyvirtualdisplay/display.py(51)display_class()
-> cls.check_installed()
  
/usr/local/lib/python3.7/site-packages/pyvirtualdisplay/xvfb.py(38)check_installed()
-> ubuntu_package=PACKAGE).check_installed()



Anyone have any thoughts on what could be causing this or how I can
debug it further?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can one make 'in' ungreedy?

2020-05-18 Thread Larry Martell
On Mon, May 18, 2020 at 7:05 AM Chris Green  wrote:
>
> I have a strange/minor problem in a Python program I use for mail
> filtering.
>
> One of the ways it classifies messages is by searching for a specific
> string in square brackets [] in the Subject:, the section of code that
> does this is:-
>
> #
> #
> # copy the fields from the filter configuration file into better named 
> variables
> #
> nm = fld[0] # name/alias
> dd = fld[1] + "/"   # destination directory
> tocc = fld[2].lower()   # list address
> sbstrip = '[' + fld[3] + ']'# string to match in and/or strip out 
> of subject
> #
> #
> # see if the filter To/CC column matches the message To: or Cc: or if 
> sbstrip is in Subject:
> #
> if (tocc in msgcc or tocc in msgto or sbstrip in msgsb):
> #
> #
> # set the destination directory
> #
> dest = mldir + dd + nm
> #
> #
> # Strip out list name (4th field) from subject if it's there
> #
> if sbstrip in msgsb:
> msg.replace_header("Subject", msgsb.replace(sbstrip, ''))
> #
> #
> # we've found a match so assume we won't get another
> #
> break
>
>
> So in the particular case where I have a problem sbstrip is "[Ipswich
> Recycle]" and the Subject: is "[SPAM] [Ipswich Recycle] OFFER:
> Lawnmower (IP11)".  The match isn't found, presumably because 'in' is
> greedy and sees "[SPAM] [Ipswich Recycle]" which isn't a match for
> "[Ipswich Recycle]".
>
> Other messages with "[Ipswich Recycle]" in the Subject: are being
> found and filtered correctly, it seems that it's the presence of the
> "[SPAM]" in the Subject: that's breaking things.
>
> Is this how 'in' should work, it seems a little strange if so, not
> intuitively how one would expect 'in' to work.  ... and is there any
> way round the issue except by recoding a separate test for the
> particular string search where this can happen?

>>> sbstrip = "[Ipswich Recycle]"
>>> subject = "[SPAM] [Ipswich Recycle] OFFER:Lawnmower (IP11)"
>>> sbstrip in subject
True

Clearly something else is going on in your program. I would run it in
the debugger and look at the values of the variables in the case when
it fails when you think it should succeed. I think you will see the
variables do not hold what you think they do.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pyodbc slowness

2020-03-04 Thread Larry Martell
On Wed, Mar 4, 2020 at 3:20 PM Larry Martell  wrote:
>
> I have some Python code that uses pyodbc to talk to a SQL Server database. In 
> that code I do an  INSERT INTO  SELECT * FROM 
>
> That query takes around 3 times longer to run when invoked from Python with 
> pyodbc than when run with direct SQL.
>
> On one system we have 1,667 rows and the timings are direct sql 1.7s pyodbc 
> 4.6s. On another system we have 15,000 rows and it's 15s vs 48s
>
> In both cases, I am running from the same machine over the same network 
> talking to the same SQL Server.
>
> The only difference I can find is the driver. When I run the direct SQL the 
> client I have uses the driver net.sourceforge.jtds.jdbc.Driver jtds12.jar 
> where as pyodbc uses {ODBC Driver 17 for SQL Server}.
>
> Could this be the cause of the difference? Is there a different driver I can 
> use with pyodbc that would be faster?

I discovered the issue is that I am selecting from a view. When
selecting from a table the time is the same. So what about a view
would make it take longer when accessed from pyodbc?
-- 
https://mail.python.org/mailman/listinfo/python-list


pyodbc slowness

2020-03-04 Thread Larry Martell
I have some Python code that uses pyodbc to talk to a SQL Server database.
In that code I do an  INSERT INTO  SELECT * FROM 

That query takes around 3 times longer to run when invoked from Python with
pyodbc than when run with direct SQL.

On one system we have 1,667 rows and the timings are direct sql 1.7s pyodbc
4.6s. On another system we have 15,000 rows and it's 15s vs 48s

In both cases, I am running from the same machine over the same network
talking to the same SQL Server.

The only difference I can find is the driver. When I run the direct SQL the
client I have uses the driver net.sourceforge.jtds.jdbc.Driver jtds12.jar
where as pyodbc uses {ODBC Driver 17 for SQL Server}.

Could this be the cause of the difference? Is there a different driver I
can use with pyodbc that would be faster?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A small quiz

2020-01-23 Thread Larry Martell
On Thu, Jan 23, 2020 at 3:56 AM Z  wrote:
>
> what is PLR?

Past Life Regression
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: TechRepublicDEVELOPERCXO JPMorgan's Athena has 35 million lines of Python code, and won't be updated to Python 3 in time

2019-09-14 Thread Larry Martell
On Fri, Sep 13, 2019 at 1:37 PM Skip Montanaro 
wrote:

> >
> https://www.techrepublic.com/google-amp/article/jpmorgans-athena-has-35-million-lines-of-python-code-and-wont-be-updated-to-python-3-in-time/
>
> I doubt this is unusual, and presume JP Morgan is big enough to handle
> the change of status, either by managing security releases in-house or
> relying on third-party releases (say, Anaconda). When I retired from
> Citadel recently, most Python was still 2.7 (though the group I worked
> in was well on the way to converting to 3.x, and no new applications
> were written against 2.7). Bank of America has an enterprise-wide
> system called Quartz. I wouldn't be surprised if it was still running
> Python 2.7 (though I don't know for sure).



Yes Quartz is 2.7. As I’ve said before here, I know a lot of companies
running large apps in 2.7 and they have no intention of moving to 3.

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


TechRepublicDEVELOPERCXO JPMorgan's Athena has 35 million lines of Python code, and won't be updated to Python 3 in time

2019-09-13 Thread Larry Martell
https://www.techrepublic.com/google-amp/article/jpmorgans-athena-has-35-million-lines-of-python-code-and-wont-be-updated-to-python-3-in-time/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: MySQLdb for 3.6 on RHEL7

2019-08-13 Thread Larry Martell
On Tue, Aug 13, 2019 at 2:16 PM Chris Angelico  wrote:
>
> On Wed, Aug 14, 2019 at 1:48 AM Larry Martell  wrote:
> >
> > On Tue, Aug 13, 2019 at 9:59 AM Chris Angelico  wrote:
> > >
> > > On Tue, Aug 13, 2019 at 11:33 PM Larry Martell  
> > > wrote:
> > > >
> > > > I am trying to install MySQLdb (https://pypi.org/project/mysqlclient/)
> > > > for python3.6 on RHEL7.
> > > >
> > > > When I import it, it fails:
> > > >
> > > > # python3.6
> > > > Python 3.6.8 (default, Jun 11 2019, 15:15:01)
> > > > [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
> > > > Type "help", "copyright", "credits" or "license" for more information.
> > > > >>> import MySQLdb
> > > > Traceback (most recent call last):
> > > >   File "", line 1, in 
> > > >   File 
> > > > "/usr/local/lib64/python3.6/site-packages/mysqlclient-1.4.4-py3.6-linux-x86_64.egg/MySQLdb/__init__.py",
> > > > line 18, in 
> > > > from . import _mysql
> > > > ImportError: 
> > > > /usr/local/lib64/python3.6/site-packages/mysqlclient-1.4.4-py3.6-linux-x86_64.egg/MySQLdb/_mysql.cpython-36m-x86_64-linux-gnu.so:
> > > > undefined symbol: mysql_kill
> > > >
> > > > Has anyone seen and resolved this?
> > >
> > > Not specifically, but that looks like a versioning conflict. Most
> > > likely, your mysqlclient is too old for MySQLdb to connect to.
> > >
> > > Did you get one of them from your system package manager and the other
> > > from pip? If so, try to get both from the same place.
> >
> > So I have MySQL from the system package manager, but mysqlclient is
> > not available there.
>
> That seems very odd. The mysqlclient binary might be just under a
> different name? I'm not familiar with RHEL, but on my Debian, there
> are packages like "mysql-server-5.7" and corresponding
> "mysql-client-5.7". Or do you mean the Python client?

Yes, the python client, which is called mysqlclient but imported as
MySQLdb (https://pypi.org/project/mysqlclient/).

> > And I was not able to get that from pip either,
> > as the install failed. I had to download the source, edit the site.cfg
> > file and build it. But I just found python36-mysql.x86_64 as a package
> > so I uninstalled mysqlclient and installed that from the repo.

The reason that would not install from pip was because the path to
mysql_config was not correct in site.cfg - once I changed that I was
able to build it, but then it gave the other error.

> Based on this, I'm thinking possibly you meant the Python client. It
> may still be that you need to install the C client for the Python one
> to connect to. Although if you got python36-mysql from your system
> repo, that ought to drag in the appropriate mysqlclient. So now I'm
> very confused.
>
> > That did not get the above error, but now I get this:
> >
> > raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is
> > required; you have %s.' % Database.__version__)
> > django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or
> > newer is required; you have 1.3.12.
>
> This claims to be a Django error, though, so maybe the issue here
> isn't with MySQLdb but with Django?? Maybe everything up above is
> actually correctly matched, but too old?

I got around that by changing the code in django to not require that version.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: MySQLdb for 3.6 on RHEL7

2019-08-13 Thread Larry Martell
On Tue, Aug 13, 2019 at 9:59 AM Chris Angelico  wrote:
>
> On Tue, Aug 13, 2019 at 11:33 PM Larry Martell  
> wrote:
> >
> > I am trying to install MySQLdb (https://pypi.org/project/mysqlclient/)
> > for python3.6 on RHEL7.
> >
> > When I import it, it fails:
> >
> > # python3.6
> > Python 3.6.8 (default, Jun 11 2019, 15:15:01)
> > [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
> > Type "help", "copyright", "credits" or "license" for more information.
> > >>> import MySQLdb
> > Traceback (most recent call last):
> >   File "", line 1, in 
> >   File 
> > "/usr/local/lib64/python3.6/site-packages/mysqlclient-1.4.4-py3.6-linux-x86_64.egg/MySQLdb/__init__.py",
> > line 18, in 
> > from . import _mysql
> > ImportError: 
> > /usr/local/lib64/python3.6/site-packages/mysqlclient-1.4.4-py3.6-linux-x86_64.egg/MySQLdb/_mysql.cpython-36m-x86_64-linux-gnu.so:
> > undefined symbol: mysql_kill
> >
> > Has anyone seen and resolved this?
>
> Not specifically, but that looks like a versioning conflict. Most
> likely, your mysqlclient is too old for MySQLdb to connect to.
>
> Did you get one of them from your system package manager and the other
> from pip? If so, try to get both from the same place.

So I have MySQL from the system package manager, but mysqlclient is
not available there. And I was not able to get that from pip either,
as the install failed. I had to download the source, edit the site.cfg
file and build it. But I just found python36-mysql.x86_64 as a package
so I uninstalled mysqlclient and installed that from the repo. That
did not get the above error, but now I get this:

raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is
required; you have %s.' % Database.__version__)
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or
newer is required; you have 1.3.12.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: MySQLdb for 3.6 on RHEL7

2019-08-13 Thread Larry Martell
On Tue, Aug 13, 2019 at 9:43 AM Inada Naoki  wrote:
>
> Why do you use RHEL?

That is not my choice.

> I believe people use RHEL to get support from Red Hat, instead of community 
> support.

I do not believe Red Hat supports this package.

>
> 2019年8月13日(火) 22:32 Larry Martell :
>>
>> I am trying to install MySQLdb (https://pypi.org/project/mysqlclient/)
>> for python3.6 on RHEL7.
>>
>> When I import it, it fails:
>>
>> # python3.6
>> Python 3.6.8 (default, Jun 11 2019, 15:15:01)
>> [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
>> Type "help", "copyright", "credits" or "license" for more information.
>> >>> import MySQLdb
>> Traceback (most recent call last):
>>   File "", line 1, in 
>>   File 
>> "/usr/local/lib64/python3.6/site-packages/mysqlclient-1.4.4-py3.6-linux-x86_64.egg/MySQLdb/__init__.py",
>> line 18, in 
>> from . import _mysql
>> ImportError: 
>> /usr/local/lib64/python3.6/site-packages/mysqlclient-1.4.4-py3.6-linux-x86_64.egg/MySQLdb/_mysql.cpython-36m-x86_64-linux-gnu.so:
>> undefined symbol: mysql_kill
>>
>> Has anyone seen and resolved this?
>> --
>> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


MySQLdb for 3.6 on RHEL7

2019-08-13 Thread Larry Martell
I am trying to install MySQLdb (https://pypi.org/project/mysqlclient/)
for python3.6 on RHEL7.

When I import it, it fails:

# python3.6
Python 3.6.8 (default, Jun 11 2019, 15:15:01)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
Traceback (most recent call last):
  File "", line 1, in 
  File 
"/usr/local/lib64/python3.6/site-packages/mysqlclient-1.4.4-py3.6-linux-x86_64.egg/MySQLdb/__init__.py",
line 18, in 
from . import _mysql
ImportError: 
/usr/local/lib64/python3.6/site-packages/mysqlclient-1.4.4-py3.6-linux-x86_64.egg/MySQLdb/_mysql.cpython-36m-x86_64-linux-gnu.so:
undefined symbol: mysql_kill

Has anyone seen and resolved this?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: py2 to 3 base64 issues

2019-08-09 Thread Larry Martell
On Fri, Aug 9, 2019 at 3:17 PM MRAB  wrote:
>
> On 2019-08-09 19:21, Larry Martell wrote:
> > On Fri, Aug 9, 2019 at 12:23 PM Chris Angelico  wrote:
> >>
> >> On Sat, Aug 10, 2019 at 2:09 AM Larry Martell  
> >> wrote:
> >> >
> >> > I have some python 2 code:
> >> >
> >> > def decode(key, string):
> >> >decoded_chars = []
> >> >string = base64.urlsafe_b64decode(string)
> >> >for i in range(len(string)):
> >> >key_c = key[i % len(key)]
> >> >encoded_c = chr(abs(ord(string[i]) - ord(key_c) % 256))
> >> >decoded_chars.append(encoded_c)
> >> >decoded_string = "".join(decoded_chars)
> >> >return decoded_string
> >> >
> >> > and if I call it like this in py2 it works as expected:
> >> >
> >> > s = 
> >> > 'V3NYVY95iImnnJWCmqphWFFzU1qvqsV6x83Mxa7HipZitZeMxbe709jJtbfW6Y6blQ=='
> >> > key = '!@#$VERYsecRet)('
> >> > decode(key, s)
> >> >
> >> > In py3 it fails with
> >> >
> >> > TypeError: ord() expected string of length 1, but int found
> >> >
> >> > I know that in py3 base64.urlsafe_b64decode is returning bytes not
> >> > chars and that is what that is happening, and I thought the solution
> >> > would be to decode it, but what codec would I use for this?
> >>
> >> Should be safe to decode it as ASCII, since Base 64 uses strictly
> >> ASCII characters. But since you're working with bytes, possibly all
> >> you need to do is remove the ord calls, since ord(u"x") is the same as
> >> b"x"[0]. You'll then need to change the join() at the end to be just
> >> "decoded_string = bytes(decoded_chars)", or possibly that followed by
> >> a decode-to-text, depending on how your data works.
> >
> > That doesn't work:
> >
> > -> encoded_c = chr(abs(string[i] - ord(key_c) % 256))
> > (Pdb) n
> > TypeError: "unsupported operand type(s) for -: 'str' and 'int'"
> > (Pdb) string
> > 'WsXU\x8fy\x88\x89\xa7\x9c\x95\x82\x9a\xaaaXQsSZ\xaf\xaa\xc5z\xc7\xcd\xcc\xc5\xae\xc7\x8a\x96b\xb5\x97\x8c\xc5\xb7\xbb\xd3\xd8\xc9\xb5\xb7\xd6\xe9\x8e\x9b\x95'
> > (Pdb) string[i]
> > '\x8f'
> > (Pdb) bytes(string[i])
> > '\x8f'
> > (Pdb) type(string[i])
> > 
> >
> 'string' is a 'str' (in Python 2 that would've been 'unicode'), so
> string[i] is also a 'str' and you need 'ord':
>
> encoded_c = chr(abs(ord(string[i]) - ord(key_c) % 256))

My bad - I was mistakenly running it in 2.7 - in 3.7 it's working like this:

def decode(key, string):
decoded_chars = []
string = base64.urlsafe_b64decode(string)
for i in range(len(string)):
key_c = key[i % len(key)]
encoded_c = chr(abs(string[i] - ord(key_c) % 256))
decoded_chars.append(encoded_c)
decoded_string = "".join(decoded_chars)
return decoded_string

Thanks all!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: py2 to 3 base64 issues

2019-08-09 Thread Larry Martell
On Fri, Aug 9, 2019 at 12:23 PM Chris Angelico  wrote:
>
> On Sat, Aug 10, 2019 at 2:09 AM Larry Martell  wrote:
> >
> > I have some python 2 code:
> >
> > def decode(key, string):
> >decoded_chars = []
> >string = base64.urlsafe_b64decode(string)
> >for i in range(len(string)):
> >key_c = key[i % len(key)]
> >encoded_c = chr(abs(ord(string[i]) - ord(key_c) % 256))
> >decoded_chars.append(encoded_c)
> >decoded_string = "".join(decoded_chars)
> >return decoded_string
> >
> > and if I call it like this in py2 it works as expected:
> >
> > s = 'V3NYVY95iImnnJWCmqphWFFzU1qvqsV6x83Mxa7HipZitZeMxbe709jJtbfW6Y6blQ=='
> > key = '!@#$VERYsecRet)('
> > decode(key, s)
> >
> > In py3 it fails with
> >
> > TypeError: ord() expected string of length 1, but int found
> >
> > I know that in py3 base64.urlsafe_b64decode is returning bytes not
> > chars and that is what that is happening, and I thought the solution
> > would be to decode it, but what codec would I use for this?
>
> Should be safe to decode it as ASCII, since Base 64 uses strictly
> ASCII characters. But since you're working with bytes, possibly all
> you need to do is remove the ord calls, since ord(u"x") is the same as
> b"x"[0]. You'll then need to change the join() at the end to be just
> "decoded_string = bytes(decoded_chars)", or possibly that followed by
> a decode-to-text, depending on how your data works.

That doesn't work:

-> encoded_c = chr(abs(string[i] - ord(key_c) % 256))
(Pdb) n
TypeError: "unsupported operand type(s) for -: 'str' and 'int'"
(Pdb) string
'WsXU\x8fy\x88\x89\xa7\x9c\x95\x82\x9a\xaaaXQsSZ\xaf\xaa\xc5z\xc7\xcd\xcc\xc5\xae\xc7\x8a\x96b\xb5\x97\x8c\xc5\xb7\xbb\xd3\xd8\xc9\xb5\xb7\xd6\xe9\x8e\x9b\x95'
(Pdb) string[i]
'\x8f'
(Pdb) bytes(string[i])
'\x8f'
(Pdb) type(string[i])

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


py2 to 3 base64 issues

2019-08-09 Thread Larry Martell
I have some python 2 code:

def decode(key, string):
   decoded_chars = []
   string = base64.urlsafe_b64decode(string)
   for i in range(len(string)):
   key_c = key[i % len(key)]
   encoded_c = chr(abs(ord(string[i]) - ord(key_c) % 256))
   decoded_chars.append(encoded_c)
   decoded_string = "".join(decoded_chars)
   return decoded_string

and if I call it like this in py2 it works as expected:

s = 'V3NYVY95iImnnJWCmqphWFFzU1qvqsV6x83Mxa7HipZitZeMxbe709jJtbfW6Y6blQ=='
key = '!@#$VERYsecRet)('
decode(key, s)

In py3 it fails with

TypeError: ord() expected string of length 1, but int found

I know that in py3 base64.urlsafe_b64decode is returning bytes not
chars and that is what that is happening, and I thought the solution
would be to decode it, but what codec would I use for this?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: AttributeError: module 'itertools' has no attribute 'imap'

2019-08-08 Thread Larry Martell
On Thu, Aug 8, 2019 at 1:33 PM Peter Otten <__pete...@web.de> wrote:
>
> Larry Martell wrote:
>
> >> Pyke has been ported to py3. Here is the code that returns the data I
> >> am trying to process:
> >>
> >> return map(self.doctor_answer, it)
> >>
> >> I don't see anything calling imap.
> >
> > I grepped through the entire pyke code and imap is not in there.
>
> Fire up the python3 interpreter that you use to run your script:
>
> >>> import pyke
> >>> pyke.__file__
> '/somewhere/pyke/__init__.py'
>
> Then grep starting in the directory shown above and be enlightened ;)
>
> If I'm wrong here's an alternative guess (I know nothing about pyke):
>
> knowledge_engine.engine((rule_base_source_folder,
> (compiled_rule_base_folder)))
>
> Are the rules "compiled" into Python? Then Make sure that you use separate
> `compiled_rule_base_folder`s for Python 2 and 3.

I figured it out - pyke creates python code and the code created by
the py2 version of pyke was still there and being used. Once I deleted
those the p3y pyke recreated them and it worked. Thanks!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: AttributeError: module 'itertools' has no attribute 'imap'

2019-08-08 Thread Larry Martell
On Thu, Aug 8, 2019 at 12:34 PM Rhodri James  wrote:
>
> On 08/08/2019 17:16, Larry Martell wrote:
> > On Thu, Aug 8, 2019 at 11:30 AM Peter Otten <__pete...@web.de> wrote:
> >>
> >> Larry Martell wrote:
> [snip]
> >>> But in py3 that fails with: AttributeError: module 'itertools' has no
> >>> attribute 'imap'
> >>
> >> In Python 3 the map() builtin is "lazy", so you can use that instead.
> >>
> >>> I tried converting presentationGen to a list but get the same error.
> >>>
> >>> How can I make this work in py3?
> >>
> >> The problem is in the project rather than in your code -- you have to port
> >> pyke to Python 3 before you can use it.
> [snip]
> >
> > Pyke has been ported to py3. Here is the code that returns the data I
> > am trying to process:
> >
> > return map(self.doctor_answer, it)
> >
> > I don't see anything calling imap.
>
> That suggests you aren't calling the code you think you're calling.  I
> think a little poking with pdb or some strategic prints is in order...

I traced through the code with pdb. It is running from
/usr/local/lib/python3.5/dist-packages/pyke and I grepped that for
imap. Nothing
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: AttributeError: module 'itertools' has no attribute 'imap'

2019-08-08 Thread Larry Martell
On Thu, Aug 8, 2019 at 12:16 PM Larry Martell  wrote:
>
> On Thu, Aug 8, 2019 at 11:30 AM Peter Otten <__pete...@web.de> wrote:
> >
> > Larry Martell wrote:
> >
> > > I have some code that is using the pyke package
> > > (https://sourceforge.net/projects/pyke/). That project seems fairly
> > > dead, so asking here.
> > >
> > > There is a pyke function that returns a context manager with an
> > > iterable map. In py2.7 I did this:
> > >
> > > from pyke import knowledge_engine
> > > vasculopathy_engine =
> > > knowledge_engine.engine((rule_base_source_folder,
> > > (compiled_rule_base_folder)))
> > > with vasculopathy_engine.prove_goal(...) as presentationGen:
> > > for vals, plan in presentationGen:
> > >
> > > But in py3 that fails with: AttributeError: module 'itertools' has no
> > > attribute 'imap'
> >
> > In Python 3 the map() builtin is "lazy", so you can use that instead.
> >
> > > I tried converting presentationGen to a list but get the same error.
> > >
> > > How can I make this work in py3?
> >
> > The problem is in the project rather than in your code -- you have to port
> > pyke to Python 3 before you can use it. If you want to go that route you may
> > give the 2to3 tool a try:
> >
> > $ cat demo.py
> > import itertools
> >
> > for i in itertools.imap(abs, [-1, 1]):
> > print i
> > $ 2to3 -w demo.py
> > [...]
> > $ cat demo.py
> > import itertools
> >
> > for i in map(abs, [-1, 1]):
> > print(i)
> > $
>
> Pyke has been ported to py3. Here is the code that returns the data I
> am trying to process:
>
> return map(self.doctor_answer, it)
>
> I don't see anything calling imap.

I grepped through the entire pyke code and imap is not in there.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: AttributeError: module 'itertools' has no attribute 'imap'

2019-08-08 Thread Larry Martell
On Thu, Aug 8, 2019 at 11:30 AM Peter Otten <__pete...@web.de> wrote:
>
> Larry Martell wrote:
>
> > I have some code that is using the pyke package
> > (https://sourceforge.net/projects/pyke/). That project seems fairly
> > dead, so asking here.
> >
> > There is a pyke function that returns a context manager with an
> > iterable map. In py2.7 I did this:
> >
> > from pyke import knowledge_engine
> > vasculopathy_engine =
> > knowledge_engine.engine((rule_base_source_folder,
> > (compiled_rule_base_folder)))
> > with vasculopathy_engine.prove_goal(...) as presentationGen:
> > for vals, plan in presentationGen:
> >
> > But in py3 that fails with: AttributeError: module 'itertools' has no
> > attribute 'imap'
>
> In Python 3 the map() builtin is "lazy", so you can use that instead.
>
> > I tried converting presentationGen to a list but get the same error.
> >
> > How can I make this work in py3?
>
> The problem is in the project rather than in your code -- you have to port
> pyke to Python 3 before you can use it. If you want to go that route you may
> give the 2to3 tool a try:
>
> $ cat demo.py
> import itertools
>
> for i in itertools.imap(abs, [-1, 1]):
> print i
> $ 2to3 -w demo.py
> [...]
> $ cat demo.py
> import itertools
>
> for i in map(abs, [-1, 1]):
> print(i)
> $

Pyke has been ported to py3. Here is the code that returns the data I
am trying to process:

return map(self.doctor_answer, it)

I don't see anything calling imap.
-- 
https://mail.python.org/mailman/listinfo/python-list


AttributeError: module 'itertools' has no attribute 'imap'

2019-08-08 Thread Larry Martell
I have some code that is using the pyke package
(https://sourceforge.net/projects/pyke/). That project seems fairly
dead, so asking here.

There is a pyke function that returns a context manager with an
iterable map. In py2.7 I did this:

from pyke import knowledge_engine
vasculopathy_engine =
knowledge_engine.engine((rule_base_source_folder,
(compiled_rule_base_folder)))
with vasculopathy_engine.prove_goal(...) as presentationGen:
for vals, plan in presentationGen:

But in py3 that fails with: AttributeError: module 'itertools' has no
attribute 'imap'

I tried converting presentationGen to a list but get the same error.

How can I make this work in py3?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do you insert an item into a dictionary (in python 3.7.2)?

2019-06-28 Thread Larry Martell
On Fri, Jun 28, 2019 at 11:10 AM CrazyVideoGamez
 wrote:
>
> How do you insert an item into a dictionary? For example, I make a dictionary 
> called "dictionary".
>
> dictionary = {1: 'value1', 2: 'value3'}
>
> What if I wanted to add a value2 in the middle of value1 and value3?

Dicts are not ordered. If you need that use an OrderedDict
(https://docs.python.org/3.7/library/collections.html#collections.OrderedDict)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Friday Filosofical Finking: Import protections

2019-04-17 Thread Larry Martell
On 2019-04-17 21:20, DL Neil wrote:
> Do you bother with exception handling for import statements?

I often have to do something like this:

try:
from settings import SITE_WAFER_DIAMETER
except ImportError:
SITE_WAFER_DIAMETER = 300
-- 
https://mail.python.org/mailman/listinfo/python-list


python book

2019-04-16 Thread Larry Martell
https://www.reddit.com/r/Python/comments/bc2606/just_found_the_best_python_bookcover/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Might be doing this wrong? (Turtle graphics)

2019-03-25 Thread Larry Martell
On Mon, Mar 25, 2019 at 3:45 PM CrazyVideoGamez  wrote:
> wait no nevermind im such an idiot

Every programmer I have ever known has said that.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can my python program send me a text message?

2019-03-19 Thread Larry Martell
On Tue, Mar 19, 2019 at 3:30 PM Steve  wrote:
>
> I have a program that triggers a reminder timer.  When that timer is done, I 
> would like to receive a text message on my phone to tell me that it is time 
> to reset the experiment.
>
> Can this be done using Python?

You can send a text with email if you know the carrier:

Alltel [insert 10-digit number]@message.alltel.com
AT [insert 10-digit number]@txt.att.net
Boost Mobile [insert 10-digit number]@myboostmobile.com
Cricket Wireless [insert 10-digit number]@mms.cricketwireless.net
Sprint [insert 10-digit number]@messaging.sprintpcs.com
T-Mobile [insert 10-digit number]@tmomail.net
U.S. Cellular [insert 10-digit number]@email.uscc.net
Verizon [insert 10-digit number]@vtext.com
Virgin Mobile [insert 10-digit number]@vmobl.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: 3D visualizations in Python

2019-03-12 Thread Larry Martell
On Tue, Mar 12, 2019 at 6:55 PM Jakub Bista  wrote:
>
> Hello. I want to do 3D visualization in Python. Which framework do you 
> recommend me for creating such a Interface?

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


Re: OT - need help with PHP

2019-02-01 Thread Larry Martell
On Fri, Feb 1, 2019 at 10:30 AM Bob Gailer  wrote:
> I can't even figure out how to sign up for a PHP email list.

http://php.net/manual/en/faq.mailinglist.php
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Pythonic Y2K

2019-01-18 Thread Larry Martell
On Fri, Jan 18, 2019 at 4:56 PM Avi Gross  wrote:
>
> Larry,
>
> I keep hearing similar things about the Flu Vaccine. It only works 40% of
> the time or whatever. But most of the people that get the flu get a
> different strain they were not vaccinated against!

That seems like a complete non-sequitur. What does that have to do with Y2K?

But I will tell you something: I've never had a flu vaccine in my life
and I've never had the flu.

And I will tell you something else: I have proof that worrying works -
99% of the things I worry about never happen, so it must work.

And please stop top posting.

> There are hundreds of strains out there and by protecting the herd against
> just a few, others will flourish. So was it worth it?
>
> Your argument would be that your work found lots of things related to Y2000
> that could have been a problem and therefore never got a chance to show. I
> wonder if anyone did a case study and found an organization that refused to
> budge and changed nothing, not even other products that were changed like
> the OS? If such organizations had zero problems, that would be interesting.
> If they had problems and rapidly had their software changed or fixed, that
> would be another and we could ask if the relative cost and consequence made
> such an approach cheaper.
>
> But in reality, I suspect that many of the vendors supplying products made
> the change for all their clients. I bet Oracle might have offered some
> combination of new and improved products to replace old ones or tools that
> could be used to say read in a database in one format and write it out again
> with wider date fields.
>
> The vast difference some allude to is realistic. Y2K swept the globe in
> about 24 hours. No easy way to avoid it for many applications. Someone
> running python 2.X on their own machines may be able to continue living in
> their bubble for quite a while. If you sell or share a product with python
> frozen into an app, it makes no difference. But asking some clients to
> maintain multiple copies of python set up so one app keeps running as all
> others use the newer one, may not remain a great solution indefinitely.
>
> Has anyone considered something that may be at the edges. How well do
> cooperating programs work together? I mean if program one processes and
> saves some data structures using something like pickle, and program two is
> supposed to read the pickle back in and continue processing, then you may
> get anomalies of many kinds if they use different pythons. Similarly,
> processes that start up other scripts and communicate with them, may need to
> start newer programs that use the 3.X or beyond version as no back-ported
> version exists. The bubble may enlarge and may eventually burst.
>
> -Original Message-
> From: Python-list  On
> Behalf Of Larry Martell
> Sent: Friday, January 18, 2019 10:47 AM
> To: Python 
> Subject: Re: Pythonic Y2K
>
> On Fri, Jan 18, 2019 at 10:43 AM Michael Torrie  wrote:
> >
> > On 01/16/2019 12:02 PM, Avi Gross wrote:
> > > I recall the days before the year 2000 with the Y2K scare when
> > > people worried that legacy software might stop working or do
> > > horrible things once the clock turned. It may even have been scary
> > > enough for some companies to rewrite key applications and even switch
> from languages like COBOL.
> >
> > Of course it wasn't just a scare.  The date rollover problem was very
> > real. It's interesting that now we call it the Y2K "scare" and since
> > most things came through that okay we often suppose that the people
> > who were warning about this impending problem were simply being
> > alarmist and prophets of doom.  We often deride them.  But the fact
> > is, people did take these prophets of doom seriously and there was a
> > massive, even heroic effort, to fix a lot of these critical backend
> > systems so that disaster was avoided (just barely).  I'm not talking
> > about PCs rolling over to 00.  I'm talking about banking software,
> > mission critical control software.  It certainly was scary enough for
> > a lot of companies to spend a lot of money rewriting key software.
> > The problem wasn't with COBOL necessarily.
>
> I had one client, a hedge fund, that I fixed literally 1000's of Y2K issues
> for. When Y2K came and there were no problems, the owner said to me "You
> made such a big deal about the Y2K thing, and nothing happened."
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Pythonic Y2K

2019-01-18 Thread Larry Martell
On Fri, Jan 18, 2019 at 10:43 AM Michael Torrie  wrote:
>
> On 01/16/2019 12:02 PM, Avi Gross wrote:
> > I recall the days before the year 2000 with the Y2K scare when people
> > worried that legacy software might stop working or do horrible things once
> > the clock turned. It may even have been scary enough for some companies to
> > rewrite key applications and even switch from languages like COBOL.
>
> Of course it wasn't just a scare.  The date rollover problem was very
> real. It's interesting that now we call it the Y2K "scare" and since
> most things came through that okay we often suppose that the people who
> were warning about this impending problem were simply being alarmist and
> prophets of doom.  We often deride them.  But the fact is, people did
> take these prophets of doom seriously and there was a massive, even
> heroic effort, to fix a lot of these critical backend systems so that
> disaster was avoided (just barely).  I'm not talking about PCs rolling
> over to 00.  I'm talking about banking software, mission critical
> control software.  It certainly was scary enough for a lot of companies
> to spend a lot of money rewriting key software.  The problem wasn't with
> COBOL necessarily.

I had one client, a hedge fund, that I fixed literally 1000's of Y2K
issues for. When Y2K came and there were no problems, the owner said
to me "You made such a big deal about the Y2K thing, and nothing
happened."
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Pythonic Y2K

2019-01-16 Thread Larry Martell
On Wed, Jan 16, 2019 at 9:35 PM Avi Gross  wrote:
>
> Chris,
>
> The comparison to Y2K was not a great one. I am not sure what people did in
> advance, but all it took was to set the clock forward on a test system and
> look for anomalies. Not everything would be found but it gave some hints.

Clearly you did not live through that. I did and I got over 2 years of
real work from it. Companies hired me to check their code and find
their Y2K exposures. Things like a hard coded '19' being added to a 2
digit year. Or code that only allocated 2 bytes for the year. I could
go on and on. At one client I had I found over 4,000 places in their
code that needed to be modified. And there was no widespread use of
VMs that you could easily and quickly spin up for testing. It was a
real problem but because of many people like me, it was dealt with.
Now the next thing to deal with is the Jan. 19, 2038 problem. I'll be
80 then, but probably still writing code. Call me if you need me.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: the python name

2019-01-02 Thread Larry Martell
On Wed, Jan 2, 2019 at 8:04 PM Avi Gross  wrote:
>
> Challenge: Can we name any computer language whose name really would suggest 
> it was a computer language?

COBOL (Common Business-Oriented Language)
FORTRAN (Formula Translation)
PL/1 (Programming Language 1)
ALGOL (Algorithmic Language)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: mouse click automation

2019-01-01 Thread Larry Martell
On Tue, Jan 1, 2019 at 12:10 PM Siddha 2305  wrote:
>
> Hello All,
>
> I am trying to write a script to emulate mouse clicks.
> The script launches Google chrome, navigates to the website. But after that 
> the script does not go to the specified coordinates.
>
> Also, I noticed that the screen coordinate is different every time I tried to 
> check it.
>
> Could someone please help me fix this?
>
> PS : I am a complete beginner and this is my first attempt at this
>
> from pynput.mouse import Button, Controller
>
> import webbrowser
>
> mouse = Controller()
>
> chromedir= 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'
>
> webbrowser.get(chromedir).open("https://lnkd.in/fT4AKq8;)
>
> time.sleep(30) # to let the link load
>
> mouse.position = (43, 483) # everytime I tried to check the coordinates of 
> the pace I wanted to do a left click, it was different.
>
> mouse.click(Button.left, 1)

I have done this work both Selenium and Cypress. Check those out.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Overwhelmed by the Simplicity of Python. Any Recommendation?

2018-11-04 Thread Larry Martell
On Sun, Nov 4, 2018 at 11:56 AM Mike C  wrote:
>
> Same here. Debugging in Python is annoying, I like to step through my code 
> line by line, it's impossible to do it with object-oriented programming 
> language.
>
> Also, there's no good REPL IDE.
>
> Spyder barely works with some basic features. PyCharm, the most popular, 
> takes too long to start, and you have to setup folders and directories EVERY 
> SINGLE TIME at startup.

I use pdb and I have no issues debugging nor stepping through my code
line-by-line when needed. What does it being OO have to do with it?

But then again, I also know better then to top post.

> Rhodri James wrote:
> ...
> > I completely agree.  I too have come from a background in C, and still
> > do most of my day job in C or assembler.  It took a while before I was
> > writing idiomatic Python, never mind efficient Python (arguably I still
> > don't, but as Rob says, who cares?).  Don't worry about it; at some
> > point you will discover that the "obvious" Python you are writing looks
> > a lot like the code you are looking at now and thinking "that's really
> > clever, I'll never be able to to that."
>
>   at this stage of my own process in learning, i'm
> trying to read the FAQs i can find, any tutorials,
> answers to specific questions on stackoverflow on
> particular topics to see if i can understand the
> issues, etc.
>
>   as for my own code, yes, it's horrible at the
> moment, but to me working code is always the
> final arbitor.  i much prefer simple and stepwise
> refinement if speed isn't the issue i think clarity
> and simplicity is more important.
>
>   speed is only more important for large projects
> that process a ton of data.
>
>   in 3-5yrs i expect to understand more of what
> the theory and more conceptual things going on as
> i read more of the history and how the language
> has developed.
>
>   i won't consider myself fluent until i start
> "thinking" in it and can visualise the data
> structures/objects in my head and such as i
> currently do for C.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: check whether a process is still running on remote hosts

2018-10-16 Thread Larry Martell
On Tue, Oct 16, 2018 at 5:15 PM tina_zy_qian--- via Python-list
 wrote:
>
> I newly learned Python, and I need to wrap up a script to do following.
>
> Env:
> 1: One launcher Linux VM (from where to run the Python script)
> 2. 100+ Linux VM
>
> requirement:
> In general, run a remote_script on remote 100 VMs and get the log files 
> generated to remote hosts back to launcher.
>
> steps
> 1. cp (pexpect.spawn('scp  ')) supporting files including the remote_script 
> to remotehost:/remote_folder
> 2. run remote_script on remote host  ( pexpect.spawn('ssh %s@%s "%s"' % 
> (user,host,cmd))
> 3. wait and check until the remote_script was run on remote host. (to check 
> "ps -ef" result on remote hosts)
> 4. collect data from remote hosts -- reverse to step 1.
>
>
> I briefly implemented other steps expect step 3. Two options are below.
>
> option 1: run another script "ps -ef|grep remote_script and output result to 
> a local file, then collected the files to launcher.
>
> option 2: run pexect.spawn('ssh' 'ps -e') to get the result directly to 
> laucher console.
> But how I can get only the output for "ps -ef" command only?
>
> I must use the (users, passwords, and hosts) way to do ssh and scp because I 
> may not be allowed to use ssh key on some hosts. Any suggestions or sample 
> code for step 3 or the whole script are appreciated. Thanks.

This looks amazingly similar to a pre interview programming assignment
was given once.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Observations on the List - "Be More Kind"

2018-10-10 Thread Larry Martell
On Fri, Oct 5, 2018 at 6:54 AM Bruce Coram  wrote:
>
> I will declare at the outset, I am a lurker.  I don't know enough about
> Python to give advice that I could 100% guarantee would be helpful.
>
> There have been two recent threads that summarise for me where the
> Python Mailing List has lost its way (and this started before Trump
> arrived as a new role model for how to treat your fellow man):

I do not think a Trump reference is approprate here at all. I could
start a political rant here, but I won't.

If you think this list is harsh you must not have been on the internet
very long.

This is a post that was going around back in 1996:

Welcome to the Internet.

No one here likes you.

We're going to offend, insult, abuse, and belittle the living hell out
of you. And when you rail against us with "FUCK YOU YOU GEEK WIMP
SKATER GOTH LOSER PUNK FAG BITCH!1!!", we smile to ourselves. We laugh
at you because you don't get it. Then we turn up the heat, hoping to
draw more entertainment from your irrational fuming.

We will judge you, and we will find you unworthy. It is a trial by
fire, and we won't even think about turning down the flames until you
finally understand.

Some of you are smart enough to realize that, when you go online, it's
like entering a foreign country ... and you know better than to
ignorantly fuck with the locals. You take the time to listen and think
before speaking. You learn, and by learning are gladly welcomed.

For some of you, it takes a while, then one day it all dawns on you -
you get it, and are welcomed into the fold.

Some of you give up, and we breathe a sigh of relief - we didn't want
you here anyway. And some of you just never get it. The offensively
clueless have a special place in our hearts - as objects of ridicule.
We don't like you, but we do love you.

You will get mad. You will tell us to go to hell, and call us "nerds"
and "geeks". Don't bother ... we already know exactly what we are.
And, much like the way hardcore rap has co-opted the word "nigger",
turning an insult around on itself to become a semiserious badge of
honor, so have we done.

"How dare you! I used to beat the crap out of punks like you in high
school/college!" You may have owned the playing field because you were
an athlete. You may have owned the student council because you were
more popular. You may have owned the hallways and sidewalks because
you were big and intimidating. Well, welcome to our world.

Things like athleticism, popularity, and physical prowess mean nothing
here. We place no value on them ... or what car you drive, the size of
your bank account, what you do for a living or where you went to
school.

Allow us to introduce you to the concept of a "meritocracy" - the
closest thing to a form of self-government we have. In The United
Meritocratic nation-states of the Internet, those who can do, rule.
Those who wish to rule, learn. Everyone else watches from the stands.

You may posses everything in the off-line world. We don't care. You
come to the Internet penniless, lacking the only thing of real value
here: knowledge.

"Who cares? The Internet isn't real anyway!" This attitude is
universally unacceptable. The Internet is real. Real people live
behind those handles and screen names. Real machines allow it to
exist. It's real enough to change government policy, real enough to
feed the world's hungry, and even, for some of us, real enough to earn
us a paycheck. Using your own definition, how "real" is your job? Your
stock portfolio? Your political party? What is the meaning of "real",
anyway?

Do I sound arrogant? Sure ... to you. Because you probably don't get it yet.

If you insist on staying, then, at the very least, follow this advice:

1) No one, ESPECIALLY YOU, will make any law respecting an
establishment of religion, or prohibiting the free exercise thereof;
or abridging the freedom of speech, or of the press; or the right of
the people peaceably to assemble, and to petition the government for a
redress of grievances.

2) Use your brain before ever putting fingers to keys.

3) Do you want a picture of you getting anally raped by Bill Clinton
while you're performing oral sex on a cow saved to hundreds of
thousands of people's hard drives? No? Then don't put your fucking
picture on the Internet. We can, will, and probably already HAVE
altered it in awful ways. Expect it to show up on an equally offensive
website.

4) Realize that you are never, EVER going to get that, or any other,
offensive web page taken down. Those of us who run those sites LIVE to
piss off people like you. Those of us who don't run those sites
sometimes visit them just to read the hatemail from fools like you.

5) Oh, you say you're going to a lawyer? Be prepared for us to giggle
with girlish delight, and for your lawyer to laugh in your face after
he explains current copyright and parody law.

6) The Web is not the Internet. Stop referring to it that way.

7) We have already received the e-mail you are 

Re: Querying MariaDB from python

2018-10-02 Thread Larry Martell
On Tue, Oct 2, 2018 at 12:09 PM Tony van der Hoff  wrote:
>
> On 02/10/18 16:47, Ervin Hegedüs wrote:
> > hi,
> >
> > now rows will looks like this:
> > ({'id':...,...},{'id':...,}...)
>
> Thanks Ervin, but:
>
>cursor = cnx.cursor(pymysql.cursors.DictCursor)
> NameError: name 'pymysql' is not defined
>
> I have been using the mysql.connector module, which seems to be the
> "official" python interface.

That also supports the cursordict:

https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlcursordict.html
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Querying MariaDB from python

2018-10-02 Thread Larry Martell
On Tue, Oct 2, 2018 at 11:34 AM Tony van der Hoff  wrote:
>
> I'm writing a database application, in python 3,5 under Debian9.
>
> My code:
>
> def get_albums(self, parent_id = 0 ):
> cursor = self.cnx.cursor()
> sql =(  "select"
> "id"
> ",   parent_id"
> ",   title"
> ",   ifnull( description, '' )"
> ",   path"
> ",   date( from_unixtime( date_created ) ) as date"
> " from album"
> " where parent_id = %(parent_id)s"
> " order by date_created"
>  )
> cursor.execute( sql, {'parent_id': parent_id } )
> rows = cursor.fetchall()
>
> # return result as a list of dicts
> result = []
>
> for row in rows:
> result.append({ 'id':row[0],
> 'parent_id':row[1],
> 'title':row[2],
> 'description':row[3],
> 'path':row[4],
> 'date':row[5],
> }
> )
> return result
>
> This works OK, but looks inelegant. Having to iterate through the
> returned data to get it into a dictionary is error-prone if the query
> changes. I would have expected the connector to be able to return a
> dictionary.
>
> Can anyone suggest a better way of doing this?

https://pymysql.readthedocs.io/en/latest/modules/cursors.html#pymysql.cursors.DictCursor
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [OT] master/slave debate in Python

2018-09-26 Thread Larry Martell
On Wed, Sep 26, 2018 at 4:41 AM, Brian Oney via Python-list
 wrote:
> "I have a vewwy great fwiend in Wome called 'Biggus Dickus'"
> ...
> "Can I go now, sir?"

He has a wife, you know. You know what she's called? She's called...
'Incontinentia'. 'Incontinentia Buttocks'.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Broken pip

2018-08-28 Thread Larry Martell
On Tue, Aug 28, 2018 at 2:10 PM, Michael F. Stemper
 wrote:
>
> I'm trying to upgrade my pip on Ubuntu 16.04. I appear to have
> buggered things up pretty well. (Details follow) Any suggestions
> on how to undo this and get everything back to proper operation?
>
> Based on the information that I found at:
> , I did the following:
>
> user@host$ pip --version
> pip 9.0.1 from /home/user/.local/lib/python2.7/site-packages (python 2.7)
> user@host$ pip install --upgrade pip
> Collecting pip
>   Downloading
> https://files.pythonhosted.org/packages/5f/25/e52d3f31441505a5f3af41213346e5b6c221c9e086a166f3703d2ddaf940/pip-18.0-py2.py3-none-any.whl
> (1.3MB)
> 100% || 1.3MB 453kB/s
> Installing collected packages: pip
>   Found existing installation: pip 9.0.1
> Uninstalling pip-9.0.1:
>   Successfully uninstalled pip-9.0.1
>   Rolling back uninstall of pip
> Exception:
> Traceback (most recent call last):
>  [snip error traceback]
> mkdir(name, mode)
> OSError: [Errno 13] Permission denied:
> '/usr/local/lib/python2.7/dist-packages/pip'
> You are using pip version 9.0.1, however version 18.0 is available.
> You should consider upgrading via the 'pip install --upgrade pip' command.
> user@host$ pip --version
> SError: [Errno 13] Permission denied:
> '/usr/local/lib/python2.7/dist-packages/pip'
> You are using pip version 9.0.1, however version 18.0 is available.
> You should consider upgrading via the 'pip install --upgrade pip' command.
> user@host$ pip --version
> pip 9.0.1 from /home/user/.local/lib/python2.7/site-packages (python 2.7)
> user@host$
>
> Sure enough, no change. Given the file permission error, I figured
> that I needed root privileges, so I tried again:
>
> user@host$ sudo pip install --upgrade pip
> [sudo] password for user:
> The directory '/home/user/.cache/pip/http' or its parent directory is
> not owned by the current user and the cache has been disabled. Please
> check the permissions and owner of that directory. If executing pip with
> sudo, you may want sudo's -H flag.
> The directory '/home/user/.cache/pip' or its parent directory is not
> owned by the current user and caching wheels has been disabled. check
> the permissions and owner of that directory. If executing pip with sudo,
> you may want sudo's -H flag.
> Collecting pip
>   Downloading
> https://files.pythonhosted.org/packages/5f/25/e52d3f31441505a5f3af41213346e5b6c221c9e086a166f3703d2ddaf940/pip-18.0-py2.py3-none-any.whl
> (1.3MB)
> 100% || 1.3MB 442kB/s
> Installing collected packages: pip
>   Found existing installation: pip 9.0.1
> Uninstalling pip-9.0.1:
>   Successfully uninstalled pip-9.0.1
> Successfully installed pip-18.0
> user@host$ pip --version
> Traceback (most recent call last):
>   File "/usr/bin/pip", line 9, in 
> from pip import main
> ImportError: cannot import name main
> user@host$
>
> Well, even though it said "Successfully installed", it appears to
> not have done so.
>
> Trying again with sudo's -H option:
>
> user@host$ sudo -H pip install --upgrade pip
> Requirement already up-to-date: pip in
> /usr/local/lib/python2.7/dist-packages (18.0)
> user@host$ pip --version
> Traceback (most recent call last):
>   File "/usr/bin/pip", line 9, in 
> from pip import main
> ImportError: cannot import name main
> user@host$

Try doing this:

sudo python -m pip uninstall pip
sudo apt remove python-pip
sudo apt install python-pip
source .bashrc
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Module not found

2018-08-27 Thread Larry Martell
On Mon, Aug 27, 2018 at 11:20 AM, Sharan Basappa
 wrote:
> I am running a program that I got as reference from GitHub.
> I am running on windows OS.
>
> Here is a snippet of the code (initial few lines).
>
> #!/usr/bin/env python
> # -*- coding: utf-8 -*-
> __author__ = 'Shilin He'
>
> import sys
> sys.path.insert(0, 'D:\Projects\Initiatives\machine 
> learning\loglizer-master\loglizer-master\utils\evaluation')
> sys.path.insert(0, 'D:\Projects\Initiatives\machine 
> learning\loglizer-master\loglizer-master\utils\evaluation')
> print sys.path
> import numpy as np
> import math
> from scipy.special import expit
> from numpy import linalg as LA
> from scipy.cluster.hierarchy import linkage
> from scipy.cluster.hierarchy import fcluster
> from scipy.spatial.distance import pdist
> import utils.evaluation as ev
>
> Here is the error:
> D:\Projects\Initiatives\machine 
> learning\loglizer-master\loglizer-master\models\log_clustering.py in 
> ()
>  14 from scipy.cluster.hierarchy import fcluster
>  15 from scipy.spatial.distance import pdist
> ---> 16 import utils.evaluation as ev
>  17
>  18
> ImportError: No module named utils.evaluation
>
>
> In the utils directory, I clearly can see evaluation file.
>
> Can someone give some directions?

Is there an __init__.py file in the utils dir?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: New books by O’Reilly

2018-08-20 Thread Larry Martell
On Mon, Aug 20, 2018 at 10:06 AM, Abdur-Rahmaan Janhangeer
 wrote:
> some accompanying explanations appreciated with the link.

That would ruin the joke.

>
> yours,
>
> Abdur-Rahmaan Janhangeer
> https://github.com/Abdur-rahmaanJ
> Mauritius
>
> On Sun, 19 Aug 2018, 09:00 Larry Martell,  wrote:
>>
>> https://imgur.com/gallery/tW1lwEl
>> --
>> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


New books by O’Reilly

2018-08-18 Thread Larry Martell
https://imgur.com/gallery/tW1lwEl
-- 
https://mail.python.org/mailman/listinfo/python-list


  1   2   3   4   5   >