Use dot notation to call a function without using parentheses

2020-12-22 Thread Walk More
I am trying to use dot notation to call a function without using parentheses, 
see code section with ***
I have looked into SimpleNamespace, namedTuple, dataclass... but no luck.
Below is my sample code to date.
Any suggestions?



class MyTest:
def __init__(self):
self.page1 = Page()
self.page1.top = Counts()
#self.page1.middle = Layout()
#self.page1.bottom = Layout()

# access of variables created on the fly using dot notation work.
self.page1.top.item1 = 5
self.page1.top.name1 = "Harry"
print ("Variables created on the fly: ", self.page1.top.item1, 
self.page1.top.name1)


# access of a predefined class variable using dot notation work.
print ("Start of predefined class variable access: ", 
self.page1.top.totalCount)
self.page1.top.totalCount = 22
self.page1.top.totalCount = self.page1.top.totalCount + 3
print ("End of predefined class variable access: ", 
self.page1.top.totalCount)


# function calls using parentheses using dot notation work.
print ("Start of function calls: ", self.page1.top.getRunningSum())
self.page1.top.addRunningSum(5)
self.page1.top.addRunningSum(200)
endValue = self.page1.top.getRunningSum()
print ("End of function calls: ", endValue) 


# *** This is the syntax I would like to use. ***
# function calls not using parentheses DO NOT WORK using dot notation.
self.page1.top.addRunningSum = 6
t = self.page1.top.getRunningSum
print (t)


class Page ():
def __init__ (self):
pass


class Counts():
def __init__ (self):
self.totalCount = 0

def addRunningSum(self, indata):
self.totalCount = self.totalCount + indata

def getRunningSum (self):
return self.totalCount


if __name__ == "__main__":
MyTest()

#end of program
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Use dot notation to call a function without using parentheses

2020-12-22 Thread Walk More
On Tuesday, December 22, 2020 at 6:31:08 AM UTC-5, Python wrote:
> Walk More wrote: 
> > I am trying to use dot notation to call a function without using 
> > parentheses, see code section with *** 
> > I have looked into SimpleNamespace, namedTuple, dataclass... but no luck. 
> > Below is my sample code to date. 
> > Any suggestions?
> accessors. 
> 
> class myClass: 
> @property 
> def data(self): 
> print('read data attribute') 
> return self._data 
> @data.setter 
> def data(self, value): 
> print('write data attribute') 
> self._data = value 
> def __init__(self, data=None): 
> self.data = data 
> 
> o = myClass('spam') 
> 
> print(o.data) 
> 
> o.data = 'ham' 
> 
> output: 
> 
> write data attribute 
> read data attribute 
> spam 
> write data attribute


Python,
Thank you very much for your solution.



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


Re: Use dot notation to call a function without using parentheses

2020-12-22 Thread MRAB

On 2020-12-22 11:16, Walk More wrote:

I am trying to use dot notation to call a function without using parentheses, 
see code section with ***
I have looked into SimpleNamespace, namedTuple, dataclass... but no luck.
Below is my sample code to date.
Any suggestions?



class MyTest:
 def __init__(self):
 self.page1 = Page()
 self.page1.top = Counts()
 #self.page1.middle = Layout()
 #self.page1.bottom = Layout()
 
 # access of variables created on the fly using dot notation work.

 self.page1.top.item1 = 5
 self.page1.top.name1 = "Harry"
 print ("Variables created on the fly: ", self.page1.top.item1, 
self.page1.top.name1)
 
 
 # access of a predefined class variable using dot notation work.

 print ("Start of predefined class variable access: ", 
self.page1.top.totalCount)
 self.page1.top.totalCount = 22
 self.page1.top.totalCount = self.page1.top.totalCount + 3
 print ("End of predefined class variable access: ", 
self.page1.top.totalCount)
 
 
 # function calls using parentheses using dot notation work.

 print ("Start of function calls: ", self.page1.top.getRunningSum())
 self.page1.top.addRunningSum(5)
 self.page1.top.addRunningSum(200)
 endValue = self.page1.top.getRunningSum()
 print ("End of function calls: ", endValue)


 # *** This is the syntax I would like to use. ***
 # function calls not using parentheses DO NOT WORK using dot notation.
 self.page1.top.addRunningSum = 6
 t = self.page1.top.getRunningSum
 print (t)
 
 
class Page ():

 def __init__ (self):
 pass
 
 
class Counts():

 def __init__ (self):
 self.totalCount = 0
 
 def addRunningSum(self, indata):

 self.totalCount = self.totalCount + indata
 
 def getRunningSum (self):

 return self.totalCount
 


if __name__ == "__main__":
 MyTest()

#end of program

It would be simpler just to access the totalCount attribute directly, 
but, in answer to your question, you can make it a property:


 @property
 def getRunningSum(self):
 return self.totalCount

and you'll then need to remove the parenthese where you're calling it.
--
https://mail.python.org/mailman/listinfo/python-list


Installing Python (2.7) 'by hand' on Ubuntu - possible?

2020-12-22 Thread Chris Green
I have (as discussed here) a printer utility that uses Python 2 and I
can't update it to Python 3 because it has a .so library file which is
compiled for Python 2.  I think I have exhausted all the possibilities
for converting it to Python 3 so now I'm looking at how to keep it
working on my [x]ubuntu Linux systems as Python 2.7 becomes unsupported.

How realistic/possible would it be to run the utility in a separate
environment with its own copies of Python2 and any modules and
libraries needed?  I would install these 'by hand', i.e. not using
'apt' so they would stay as installed even as my system gets upgraded. 

There would obviously be *some* dependencies on the system libraries
but I think they'd be pretty low level and thus their interfaces would
be very unlikely to change for a long time so I should be able to run
my old Python2.7 and the Python modules needed for the utility for
quite a few years anyway (the printer it supports will wear out
eventually!).

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Installing Python (2.7) 'by hand' on Ubuntu - possible?

2020-12-22 Thread Michael Torrie
On 12/22/20 8:10 AM, Chris Green wrote:
> I have (as discussed here) a printer utility that uses Python 2 and I
> can't update it to Python 3 because it has a .so library file which is
> compiled for Python 2.  I think I have exhausted all the possibilities
> for converting it to Python 3 so now I'm looking at how to keep it
> working on my [x]ubuntu Linux systems as Python 2.7 becomes unsupported.
> 
> How realistic/possible would it be to run the utility in a separate
> environment with its own copies of Python2 and any modules and
> libraries needed?  I would install these 'by hand', i.e. not using
> 'apt' so they would stay as installed even as my system gets upgraded. 
> 
> There would obviously be *some* dependencies on the system libraries
> but I think they'd be pretty low level and thus their interfaces would
> be very unlikely to change for a long time so I should be able to run
> my old Python2.7 and the Python modules needed for the utility for
> quite a few years anyway (the printer it supports will wear out
> eventually!).

Probably your best bet is to build a container image (perhaps a snap)
around with a distro that has Python 2.7 in it to house your app. That
way you've got everything you need including the required system
libraries.  Right now you could build a image of it based on Ubuntu
20.04 which has python 2.7 as an optional installable package.

Sure you could build Python 2.7 for as long as the compatible compilers
and other dependent libraries are available.  I expect RHEL to keep
building python 2.7 for another 10 years.  Ubuntu 20.04 will continue to
ship python 2.7 as an optional package for another 5 years at least.

There are ways even besides containers that work. With some scripts to
set up custom library paths and trees of custom libraries, you can run
old binary software on newer distros even. With some help from the
interwebs, I am able to run WordPerfect 8 for Linux on my Fedora 32 box.
 That was released back in the kernel 2.0 days, before the transition to
glibc.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Installing Python (2.7) 'by hand' on Ubuntu - possible?

2020-12-22 Thread Grant Edwards
On 2020-12-22, Chris Green  wrote:
> I have (as discussed here) a printer utility that uses Python 2 and I
> can't update it to Python 3 because it has a .so library file which is
> compiled for Python 2.  I think I have exhausted all the possibilities
> for converting it to Python 3 so now I'm looking at how to keep it
> working on my [x]ubuntu Linux systems as Python 2.7 becomes unsupported.
>
> How realistic/possible would it be to run the utility in a separate
> environment with its own copies of Python2 and any modules and
> libraries needed?

That depends on the modules and libraries needed. If it's just
python2, it should be pretty easy. If it needs things like GTK or Qt,
it gets a _lot_ harder.

-- 
Grant

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


Re: Installing Python (2.7) 'by hand' on Ubuntu - possible?

2020-12-22 Thread Chris Green
Michael Torrie  wrote:
> On 12/22/20 8:10 AM, Chris Green wrote:
> > I have (as discussed here) a printer utility that uses Python 2 and I
> > can't update it to Python 3 because it has a .so library file which is
> > compiled for Python 2.  I think I have exhausted all the possibilities
> > for converting it to Python 3 so now I'm looking at how to keep it
> > working on my [x]ubuntu Linux systems as Python 2.7 becomes unsupported.
> > 
> > How realistic/possible would it be to run the utility in a separate
> > environment with its own copies of Python2 and any modules and
> > libraries needed?  I would install these 'by hand', i.e. not using
> > 'apt' so they would stay as installed even as my system gets upgraded. 
> > 
> > There would obviously be *some* dependencies on the system libraries
> > but I think they'd be pretty low level and thus their interfaces would
> > be very unlikely to change for a long time so I should be able to run
> > my old Python2.7 and the Python modules needed for the utility for
> > quite a few years anyway (the printer it supports will wear out
> > eventually!).
> 
> Probably your best bet is to build a container image (perhaps a snap)
> around with a distro that has Python 2.7 in it to house your app. That
> way you've got everything you need including the required system
> libraries.  Right now you could build a image of it based on Ubuntu
> 20.04 which has python 2.7 as an optional installable package.
> 
I have it running on 20.04 (with a couple of compatibility packages
from a PPA) but I know I start hitting problems as soon as I move to
20.10.  So that does sound like an excellent idea.  Where can I find
information about building container type things like snap?

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Installing Python (2.7) 'by hand' on Ubuntu - possible?

2020-12-22 Thread Michael Torrie
On 12/22/20 9:44 AM, Chris Green wrote:
> I have it running on 20.04 (with a couple of compatibility packages
> from a PPA) but I know I start hitting problems as soon as I move to
> 20.10.  So that does sound like an excellent idea.  Where can I find
> information about building container type things like snap?

Good question.  A quick search reveals this potential starting place:
https://ubuntu.com/tutorials/create-your-first-snap

Also
https://snapcraft.io/docs/python-plugin
https://snapcraft.io/docs/python-apps

That's all I know. Sorry I suggested a solution I know nothing about!


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


Re: Installing Python (2.7) 'by hand' on Ubuntu - possible?

2020-12-22 Thread Grant Edwards
On 2020-12-22, Chris Green  wrote:
> [...]
>
> How realistic/possible would it be to run the utility in a separate
> environment with its own copies of Python2 and any modules and
> libraries needed?  I would install these 'by hand', i.e. not using
> 'apt' so they would stay as installed even as my system gets upgraded.

If you do have it running on a Linux system, then there are tools to
"bundle" it with all the required libraries. The one that I've used
most recently is cx_freeze (I generally use it to create bundles for
Windows):

https://cx-freeze.readthedocs.io/en/latest/index.html

If you want to use it for a 2.7 app, you'd need to use 5.1

--
Grant


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


Re: Installing Python (2.7) 'by hand' on Ubuntu - possible?

2020-12-22 Thread Chris Angelico
On Wed, Dec 23, 2020 at 2:21 AM Chris Green  wrote:
>
> I have (as discussed here) a printer utility that uses Python 2 and I
> can't update it to Python 3 because it has a .so library file which is
> compiled for Python 2.  I think I have exhausted all the possibilities
> for converting it to Python 3 so now I'm looking at how to keep it
> working on my [x]ubuntu Linux systems as Python 2.7 becomes unsupported.
>
> How realistic/possible would it be to run the utility in a separate
> environment with its own copies of Python2 and any modules and
> libraries needed?  I would install these 'by hand', i.e. not using
> 'apt' so they would stay as installed even as my system gets upgraded.
>

It shouldn't be too hard to grab the source code for Python 2.7 and
install it that way. The first step would be to ask apt to install all
the build dependencies of Python 3; the same libraries will be
important for building Python 2 (bar a couple that got added more
recently, but that won't affect anything).

Once you get it built, you can either just install it as is, or build
yourself a package (with checkinstall or something) to be able to
uninstall later. Personally, I'd just install it directly, but that's
me.

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


Re: Installing Python (2.7) 'by hand' on Ubuntu - possible?

2020-12-22 Thread Chris Green
Grant Edwards  wrote:
> On 2020-12-22, Chris Green  wrote:
> > [...]
> >
> > How realistic/possible would it be to run the utility in a separate
> > environment with its own copies of Python2 and any modules and
> > libraries needed?  I would install these 'by hand', i.e. not using
> > 'apt' so they would stay as installed even as my system gets upgraded.
> 
> If you do have it running on a Linux system, then there are tools to
> "bundle" it with all the required libraries. The one that I've used
> most recently is cx_freeze (I generally use it to create bundles for
> Windows):
> 
> https://cx-freeze.readthedocs.io/en/latest/index.html
> 
> If you want to use it for a 2.7 app, you'd need to use 5.1
> 
That looks a good approach, thank you.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Installing Python (2.7) 'by hand' on Ubuntu - possible?

2020-12-22 Thread Grant Edwards
On 2020-12-22, Chris Green  wrote:
> Grant Edwards  wrote:
>> On 2020-12-22, Chris Green  wrote:
>> > [...]
>> >
>> > How realistic/possible would it be to run the utility in a separate
>> > environment with its own copies of Python2 and any modules and
>> > libraries needed?  I would install these 'by hand', i.e. not using
>> > 'apt' so they would stay as installed even as my system gets upgraded.
>> 
>> If you do have it running on a Linux system, then there are tools to
>> "bundle" it with all the required libraries. The one that I've used
>> most recently is cx_freeze (I generally use it to create bundles for
>> Windows):
>> 
>> https://cx-freeze.readthedocs.io/en/latest/index.html
>> 
>> If you want to use it for a 2.7 app, you'd need to use 5.1
>
> That looks a good approach, thank you.

I should have mentioned that bundlers like cx_freeze require that you
have the Python source for the main app. I don't remember if you
mentioned source or not...

--
Grant



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


Re: Installing Python (2.7) 'by hand' on Ubuntu - possible?

2020-12-22 Thread Chris Green
Grant Edwards  wrote:
> On 2020-12-22, Chris Green  wrote:
> > Grant Edwards  wrote:
> >> On 2020-12-22, Chris Green  wrote:
> >> > [...]
> >> >
> >> > How realistic/possible would it be to run the utility in a separate
> >> > environment with its own copies of Python2 and any modules and
> >> > libraries needed?  I would install these 'by hand', i.e. not using
> >> > 'apt' so they would stay as installed even as my system gets upgraded.
> >> 
> >> If you do have it running on a Linux system, then there are tools to
> >> "bundle" it with all the required libraries. The one that I've used
> >> most recently is cx_freeze (I generally use it to create bundles for
> >> Windows):
> >> 
> >> https://cx-freeze.readthedocs.io/en/latest/index.html
> >> 
> >> If you want to use it for a 2.7 app, you'd need to use 5.1
> >
> > That looks a good approach, thank you.
> 
> I should have mentioned that bundlers like cx_freeze require that you
> have the Python source for the main app. I don't remember if you
> mentioned source or not...
> 
Yes, I do have the Python source.  The only thing I don't have the
source for is a .so file and that's why I can't simply migrate the
program(s) from Python 2 to Python 3.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Installing Python (2.7) 'by hand' on Ubuntu - possible?

2020-12-22 Thread Grant Edwards
On 2020-12-22, Chris Green  wrote:
> Grant Edwards  wrote:
>
>> I should have mentioned that bundlers like cx_freeze require that you
>> have the Python source for the main app. I don't remember if you
>> mentioned source or not...
>
> Yes, I do have the Python source.  The only thing I don't have the
> source for is a .so file and that's why I can't simply migrate the
> program(s) from Python 2 to Python 3.

I think cx_freeze should be able to do the job. It tries to
auto-detect what libraries and Python modules are needed, but
sometimes you have manually add one or two to the list.

--
Grant

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


Re: Installing Python (2.7) 'by hand' on Ubuntu - possible?

2020-12-22 Thread Mirko via Python-list
On 22.12.2020 at 20:24 Chris Green wrote:

> Yes, I do have the Python source.  The only thing I don't have the
> source for is a .so file and that's why I can't simply migrate the
> program(s) from Python 2 to Python 3.
> 

If it's just one .so and that library is compatible with basic libs
such as glibc and has no further big dependencies, then there may be
a simpler way than cx_freeze or even snap/docker/etc.

Python 2 will likely be available for quite some more years as an
optional package. But even with a self-compiled version, you should
be able to put the required libraries somewhere and set
LD_LIBRARY_PATH or maybe LD_PRELOAD accordingly. For a few depending
libs, this works well, but it gets really nasty if glibc or big
frameworks such as GTK are involved.
-- 
https://mail.python.org/mailman/listinfo/python-list


sqlalchemy blows up and puts in addresses instead of data when mixing fields from different dataframes

2020-12-22 Thread Rhett Prince
sqlalchemy blows up  and puts in addresses instead of data when mixing
fields from different dataframes

 

when composing a class derived from model, 

populating fields from different dataframes blows up.fields from one data
frame are corrupted after 

session add and session commit 

fields from another dataframe are fine. 

 

building final class object with single dataframe from data frame with the
issue alone is just fine. 

data from the data frame survives session.add and session.commit 

 

data is only corrupted when data comes from two different data frame sources


field 1 comes from data frame a 

field 2 comes from dataframe b

after session.add session.commit 

first field from source 1 is corrupted. 

data from source 2 is fine. 

 

again 

when data source 1 is used by itself with out a second source 

data from dataframe 1 survives 

session.add and session.commit. 

 

is this a defect in sqlalchemy or in pandas. 

o

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


pexpect with kadmin

2020-12-22 Thread Joseph L. Casale
Anyone ever used pexpect with tooling like kadmin and have
insight into how to manage interacting with it?

After setting up debug logging, I was able to adjust the expect
usage to get the input and output logs to at least appear correct
when setting a password for a principal, however even with a
successful return code from kadmin, there is some discrepancy
and the credential is not being set right.

When run manually, the credentials work fine, it's almost as if
kadmin is swallowing the newline from pexpect within the password.

I am using python 3.5 from Windows, over plink.exe, onto a rhel
7 server. Unfortunately, I am stuck with all the levels of indirection.

Thanks,
jlc
-- 
https://mail.python.org/mailman/listinfo/python-list