Better use a class decorator or a metaclass?(was: super not behaving as I expected)

2020-04-04 Thread Antoon Pardon
Op 29/03/20 om 16:49 schreef Peter Otten:
> Antoon Pardon wrote:
> 
>>
>> I have the following program
>>
>> class slt:
>> __slots__ = ()
>>
...
>>
>> class slt1 (slt):
>> __slots__ = 'fld1', 'fld2'
>>
...
>>
>> class slt2(slt1):
>> __slots__ = 'fld3',
>>

> Anyway, here's my attempt to collect inherited slots:
> 
> @classmethod
> def get_slots(cls):
> all_slots = set()
> for C in cls.__mro__:
> try:
> slots = C.__slots__
> except AttributeError:
> assert C is object
> else:
> all_slots.update(slots)
> return all_slots
> 

I have been thinking about this. AFAIU the slots are static data. So it
seems a bit odd to calculate them with a (class) method.

This seems a reasonable opportunity to use a class decorator or a
metaclass. But I am in doubt about which would be the better solution here.

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


Re: Better use a class decorator or a metaclass?(was: super not behaving as I expected)

2020-04-04 Thread Souvik Dutta
I think this should help
https://stackoverflow.com/questions/1779372/python-metaclasses-vs-class-decorators

On Sat, 4 Apr, 2020, 6:12 pm Antoon Pardon, 
wrote:

> Op 29/03/20 om 16:49 schreef Peter Otten:
> > Antoon Pardon wrote:
> >
> >>
> >> I have the following program
> >>
> >> class slt:
> >> __slots__ = ()
> >>
> ...
> >>
> >> class slt1 (slt):
> >> __slots__ = 'fld1', 'fld2'
> >>
> ...
> >>
> >> class slt2(slt1):
> >> __slots__ = 'fld3',
> >>
> 
> > Anyway, here's my attempt to collect inherited slots:
> >
> > @classmethod
> > def get_slots(cls):
> > all_slots = set()
> > for C in cls.__mro__:
> > try:
> > slots = C.__slots__
> > except AttributeError:
> > assert C is object
> > else:
> > all_slots.update(slots)
> > return all_slots
> >
>
> I have been thinking about this. AFAIU the slots are static data. So it
> seems a bit odd to calculate them with a (class) method.
>
> This seems a reasonable opportunity to use a class decorator or a
> metaclass. But I am in doubt about which would be the better solution here.
>
> --
> Antoon Pardon.
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Exceptions versus Windows ERRORLEVEL

2020-04-04 Thread Luuk

On 3-4-2020 02:08, Stephen Tucker (Stephen Tucker) wrote:

Hi,

I have found that raising an exception in a Python 2.7.10 program running under
Windows does not set ERRORLEVEL.

I realise that Python 2.x is no longer supported.

Does an exception raised by a Python 3.x program on a Windows machine set
ERRORLEVEL?


Yes, it does.


If not, are there plans for it to do so?

Stephen.



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


Adding tkinter modules to notebook tabs

2020-04-04 Thread Rich Shepard

My Python3-3.8.2 application has 8 modules with subject-specific data
entry/editing widgets and I want to display each module on a ttk.Notebook.
Each notebook resource I've found in my reference books and on the web
describe how to create a notebook and tabs and add labels to the tabs; a few
describe how to place individual widgets on a tab. But I've not found how to
place a widget-filled module on a notebook tab.

I am asking for references I can read to learn how to do this.

Thanks in advance ... and stay healthy,

Rich

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


Re: A PDF journey to find all python PDF

2020-04-04 Thread anson freer
Thanks, I'll check them out.
tutor sent "The reason it is being held:

Post by non-member to a members-only list".

could I be on both lists? I did unsubscribe

I am trying learn how to use a PDF text editor

The info I have states I need:

pdfminer PyPI python3 only

 PDFParser

PDFDocument

PDFPageInterpreter

 PDFDevice

They all look the same

If I choose one do I make a new DIR or leave in DLOADS

I have 3 choices

pdfminer,pdfminer3,pdfminer.6

pdfminer.6 is the latest ver.

Stack Overflow has good info for me(more concise)

GitHub is where many get their dnlds

GitHub is for pros so do you think it's OK to get mine also?

Thank you for your time

Anson




On Fri, Apr 3, 2020 at 10:13 PM Souvik Dutta 
wrote:

> Python is not a platform your platform is the os. Choose the newer PDF
> reader it often comprises more features than older ones (might be a bit
> unstable though).  There are lots of books and free online tutorials to
> learn python. Check them out first. If you have problem with English you
> can use your native language. We would still help. Don't try to bite more
> than you can chew.
>
> Souvik flutter dev
>
> On Sat, Apr 4, 2020, 2:26 AM anson freer  wrote:
>
>> This forum mentioned the Tutor forum so I signed up
>> I waited a day or 2 heard nothing so I sent msg
>> got  Post by non-member to a members-only list
>> replied to apologized and
>> received auto msg
>> part of which gave do's and don't's of forum
>> then I realized I asked a really lame question
>> Might take years for a answer
>> When all fails YOUTUBE
>> A youtube 3part vidio said I need a
>> PDFParser= pdfminer or pdf 2020 4.1
>> PDFDocument=a text file like notes???
>> PDFPageInterpreter= no reslts
>> PDFDevice+??
>> Then
>> I found Pycon 2018!
>> Looked at the 30min+ forums and understood 0
>> then little by little learned about REGEX and test and Asychronous
>> So..
>> I needed a PDF text reader
>> found
>> Python Software Foundation [US] pypi.org/project/pdfminer/#files
>> then there is Search Projects
>> I typed pdf and many pop up
>> pdf 2020.4.1 =
>> Python library for parsing PDFs
>> I can find anything PDF
>> It seems like Pdf is a mother with many children all with different
>> fathers
>> But no kid knows or talk to each other
>> There are questions
>> Do I make new DIR just for python and its results?
>> Does the dnload go in my programs like 3.8.2 does
>> warning on Python Software Foundation
>> "Download the file for your platform. If you're not sure which to choose,
>> learn more about installing packages."
>> Is my platform python?
>> pdf 2020 4.1 is newer than pdfminer
>> which one?
>> Best practices for python? short ver
>> The journey
>> All forums want to help
>> I did horse handicapping and Access fourms
>> At first a few gave all the VBA code I needed 40+years ago
>> Then I was reminded I needed to do the work
>> Then I got questions and understood what those kind coders meant
>> AND YET I ASKED A LAME QUESTION!
>> thank you for being patient
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Window and position of figure

2020-04-04 Thread jorge . conforte
 

Hi, 

I already use the IDL software. Now I`m using Python. In IDL I
havethe vector position=(xo,yo,x1,y1) to set where Iwnat to plot my
figure in my window. 

I have an 2d array with x and y dimensition equal
5224. when I plot my figure, using contourtf it takes up a small part of
my window. What can I do to have 

my figure occupy a larger area in my
window.

Thanks,

Conrado

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


Latest python Cheatsheet

2020-04-04 Thread lokender . bhim
Python Cheatsheet - learn the basics of Python without any book and course or 
brush up the basic concepts 

Cheatsheet  link - https://cheatsheets.tutorials24x7.com/programming/python
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Latest python Cheatsheet

2020-04-04 Thread Souvik Dutta
Did you post this on the tutor list? It should be more welcomed there.

Souvik flutter dev

On Sat, Apr 4, 2020, 9:50 PM  wrote:

> Python Cheatsheet - learn the basics of Python without any book and course
> or brush up the basic concepts
>
> Cheatsheet  link -
> https://cheatsheets.tutorials24x7.com/programming/python
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A PDF journey to find all python PDF

2020-04-04 Thread Michael Torrie
On 4/4/20 9:08 AM, anson freer wrote:
> Thanks, I'll check them out.
> tutor sent "The reason it is being held:
> 
> Post by non-member to a members-only list".
> 
> could I be on both lists? I did unsubscribe

Yes you can subscribe to both lists of course. But you have to subscribe
to each list individually.  Always be sure to post to a list from the
same email address that you signed up.

> I am trying learn how to use a PDF text editor

Okay, but what is your goal and purpose? What problem are you trying to
solve.  If you just want to edit a PDF file, I can think of far easier
methods than using any Python module. For example LibreOffice can import
and edit PDFs using the Draw component.

If you want to parse data from a PDF then one of the modules you mention
below could work.

> The info I have states I need:
> 
> pdfminer PyPI python3 only
> 
>  PDFParser
> 
> PDFDocument
> 
> PDFPageInterpreter
> 
>  PDFDevice
> 
> They all look the same

They may all do similar things with PDFs. Which one is appropriate for
your use depends on your needs, which still are not clear.

I also repeat my earlier suggestion that before you can use any of these
modules, you must learn Python first, at least to the degree where you
are comfortable creating code in Python to manipulate variables, if
statements, functions, etc.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Adding tkinter modules to notebook tabs

2020-04-04 Thread Christian Gollwitzer

Am 04.04.20 um 16:59 schrieb Rich Shepard:

My Python3-3.8.2 application has 8 modules with subject-specific data
entry/editing widgets and I want to display each module on a ttk.Notebook.
Each notebook resource I've found in my reference books and on the web
describe how to create a notebook and tabs and add labels to the tabs; a 
few
describe how to place individual widgets on a tab. But I've not found 
how to

place a widget-filled module on a notebook tab.


I'm not sure I fully understand it, because a "module" is not defined in 
the language of tkinter. Is it correct, you want to know how to place 
more than one widget - a arrangement of widgets - onto a notebook tab?


This is achieved by a ttk.Frame() widget, which holds all the other 
stuff, and then you place the frame onto the notebook:


n=ttk.Notebook()
f1=ttk.Frame()
# put all your stuff into f1
n.add(f1, text="Module1")
# repeat for your other "modules"


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


Re: Adding tkinter modules to notebook tabs

2020-04-04 Thread Rich Shepard

On Sat, 4 Apr 2020, Christian Gollwitzer wrote:

I'm not sure I fully understand it, because a "module" is not defined in the 
language of tkinter.


Christian,

True, but it is in Python: a file ending in .py which, in this case,
contains a class of tkinter widgets.


Is it correct, you want to know how to place more than one widget - a
arrangement of widgets - onto a notebook tab?


Yes, as they are defined and laid out in separate files/modules.

This is achieved by a ttk.Frame() widget, which holds all the other stuff, 
and then you place the frame onto the notebook:


n=ttk.Notebook()
f1=ttk.Frame()
# put all your stuff into f1
n.add(f1, text="Module1")
# repeat for your other "modules"


This looks to me like it's adding the text, "Module1" to the tab.

Here:

nb = ttk.Notebook(Main)
...
page3 = ttk.Frame(nb)
...
# add titles to tabs
nb.add(page3, text='Biota')
...

This puts the text on each notebook tab, correct?

If so, how do I add

class BiotaDataForm(Tk.Frame):

which defines all the widgets in the module in views/biota.py into the body
of the notebook's page3?

Thanks,

Rich


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


Re: Adding tkinter modules to notebook tabs

2020-04-04 Thread Christian Gollwitzer

Am 04.04.20 um 22:31 schrieb Rich Shepard:

On Sat, 4 Apr 2020, Christian Gollwitzer wrote:

I'm not sure I fully understand it, because a "module" is not defined 
in the language of tkinter.


Christian,

True, but it is in Python: a file ending in .py which, in this case,
contains a class of tkinter widgets.


Is it correct, you want to know how to place more than one widget - a
arrangement of widgets - onto a notebook tab?


Yes, as they are defined and laid out in separate files/modules.

This is achieved by a ttk.Frame() widget, which holds all the other 
stuff, and then you place the frame onto the notebook:


n=ttk.Notebook()
f1=ttk.Frame()
# put all your stuff into f1
n.add(f1, text="Module1")
# repeat for your other "modules"


This looks to me like it's adding the text, "Module1" to the tab.


Yes and no. It puts the empty frame in the notebook and labels it with 
"Module1" so that when you click the label, the frame is raised. Of 
course, not very interesting, because the frame is empty.




Here:

nb = ttk.Notebook(Main)
     ...
     page3 = ttk.Frame(nb)
     ...
     # add titles to tabs
     nb.add(page3, text='Biota')
     ...

This puts the text on each notebook tab, correct?


It adds an empty frame, as above.



If so, how do I add

class BiotaDataForm(Tk.Frame):

which defines all the widgets in the module in views/biota.py into the body
of the notebook's page3?


Add that thing instead of the frame.

blabla=BioDataForm() # whatever args it needs, maybe parent=nb

nb.add(blabla, text="Biodata")

Christian

PS: I suggest to change all Tk widgets to ttk widgets for optical 
reasons, but that's a side note.


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


Re: Window and position of figure

2020-04-04 Thread DL Neil via Python-list

I already use the IDL software. Now I`m using Python. In IDL I
havethe vector position=(xo,yo,x1,y1) to set where Iwnat to plot my
figure in my window.

I have an 2d array with x and y dimensition equal
5224. when I plot my figure, using contourtf it takes up a small part of
my window. What can I do to have
my figure occupy a larger area in my
window.


Is this a matter of scaling? ie if the figure is only 10-units wide and 
the x-axis is 5224-units, then it will occupy only 0.2% of the 
(positive) width.


(I don't use IDL)
When the axes are also plotted, do they appear in the middle of the 
screen, ie half of each axis is for negative values. If the vector and 
figure lie in positive space (for example), why include either/both 
negative domains?


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


print small DataFrame to STDOUT and read it back into dataframe

2020-04-04 Thread Luca



possibly a stupid question. Let's say I have a (small) dataframe:

import pandas as pd
dframe = pd.DataFrame({'A': ['a0','a1','a2','a3'],
'B': ['b0','b1','b2','b3'],
'C': ['c0','c1','c2','c3'],
'D': ['d0','d1','d2','d3']}, index=[0,1,2,3])

Is there a way that I can ask this dataframe to "print itself" in a way 
that I can copy that output and easily rebuild the original dataframe 
with index, columns and all?


dframe.to_string

gives:



Can I evaluate this string to obtain a new dataframe like the one that 
generated it?


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


Re: A PDF journey to find all python PDF

2020-04-04 Thread Grant Edwards
On 2020-04-04, Michael Torrie  wrote:
> On 4/4/20 9:08 AM, anson freer wrote:
>> Thanks, I'll check them out.
>> tutor sent "The reason it is being held:
>> 
>> Post by non-member to a members-only list".
>> 
>> could I be on both lists? I did unsubscribe
>
> Yes you can subscribe to both lists of course. But you have to subscribe
> to each list individually.  Always be sure to post to a list from the
> same email address that you signed up.
>
>> I am trying learn how to use a PDF text editor
>
> Okay, but what is your goal and purpose? What problem are you trying
> to solve.  If you just want to edit a PDF file, I can think of far
> easier methods than using any Python module. For example LibreOffice
> can import and edit PDFs using the Draw component.

The only real interactive PDF editor I know of for Linux is PDFStudio:

  https://www.qoppa.com/pdfstudio/

I've been using it for many years, and can recommed it highly.  It's
got nothing to do with Python though.

If you want command-line stuff, there's pdf toolkit:

  https://packages.gentoo.org/packages/app-text/pdftk

If, OTOH, you want to programmatically generate PDF from Python,
that's something entirely different.  I'd look at

Reportlab  https://www.reportlab.com/opensource/
pyfpdf https://pyfpdf.readthedocs.io/en/latest/#fpdf-for-python
pypdf  https://pythonhosted.org/PyPDF2/

--
Grant

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


Re: Adding tkinter modules to notebook tabs

2020-04-04 Thread Terry Reedy

On 4/4/2020 10:59 AM, Rich Shepard wrote:

My Python3-3.8.2 application has 8 modules with subject-specific data
entry/editing widgets and I want to display each module on a ttk.Notebook.
Each notebook resource I've found in my reference books and on the web
describe how to create a notebook and tabs and add labels to the tabs; a 
few
describe how to place individual widgets on a tab. But I've not found 
how to

place a widget-filled module on a notebook tab.


IDLE's currently-working Settings dialog uses a  ttl.Notebook with 5 
tabs.  To see it, run IDLE and on the top menu, select Options => 
Configure IDLE.  Each tab displays a ttk.Frame with multiple widgets. 
Where there is a choice, ttk widgets are used.  They make the most 
different on macOS and least difference on Windows (because the tk 
widgets look pretty good there).


The code is in idlelib/configdialog.py.  ConfigDialog creates a window 
and notebook and adds the tab frames.  As Christian indicated, the 
notebook itself takes very little code.  Each of the tab frames is a 
separate Frame subclass in the same file, but they could be in separate 
files.


--
Terry Jan Reedy

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