Re: Confusing textwrap parameters, and request for RE help

2020-03-25 Thread DL Neil via Python-list

On 25/03/20 11:57 AM, Chris Angelico wrote:

On Wed, Mar 25, 2020 at 9:37 AM DL Neil via Python-list
 wrote:


As you observe, the problem with terminal emulators is the extent of
their emulation and the degree of adoption of their 'extended features'!

My concern grows because of the need (I assume) for the URL to be
'clickable', not merely 'complete' and 'unadorned' (no added hyphen
rendering it useless).


A complete URL is clickable. If I print out the string
"https://example.com/"; then it can be right-clicked and copied, or
sent to a browser, or whatever. (Technically I don't need it to be
"clickable", but the terminal emulator has to recognize it as a link.)
FTR I'm using XFCE and xfce4-terminal, although I think everything
applies to most of the popular terminal emulators.

The problem is that a long URL will wrap. So my options are:

1) Let it wrap, violating the indentation
2) Break it, which stops it from being clickable
3) Get help from the terminal emulator


Despite the almost-irresistible urge to prove that I'm a class-y guy
[albeit with a warped sense of humor], I'm warming to the 'partition'
suggestion:
- the output from textwrap.wrap() is a list of strings,
- we are talking about fixed-length lines denominated in characters,
- locating a[ll] URI (from a sub-set of schemes, eg "http", "https",
...) is a well-worn path.


I'm not bothered too much by specific schemes. If a word matches the
regex ^[a-z]+:// then I'll call it a URL.


Thus (simplified to assume the presence of exactly one URI!!!):
- textwrap the first partition
- len( URI )
- it becomes trivial to ascertain if the URL might append the last line
(of the first 'wrapped' partition)
- failing that, the URI must start a new line (by defn)
- if it is 'too long', ie would be wrapped by textwrap, treat it separately,
- conversely, prepend the URI to the third partition,
- text-wrap the third partition,
- assemble the tweet-display.



Hmm. So, basically, manual reimplementation of parts of textwrap. I'll
hold that thought for later... if it's possible to just change the
regex and keep the code unchanged, I'll prefer that, but this is a
possibility. Thanks.



Thought I'd better buy-in some groceries before the country goes into 
lock-down at midnight, but this problem was amusing me whilst awaiting 
my turn to get into the store, to the check-out,...



1 what features does the terminal offer when a user 'clicks'?
Is it only applicable to URLs and linked to the web-browser within 
"Preferred Applications"? Are you able to 'grab' that click from the 
app? eg MOUSEDOWN*.


2 ultimately, you're on-a-hiding-to-nothing (apologies to 
non-English-English speakers: means 'no hope'!) given that URLs are 
defined by, but not length-limited by, RFC. Any 'limits' are applied by 
implementation/web-browser publishers. Currently in-use editions may 
vary widely, ie from 2K~64K. Any and all of which would blow terminal 
line-lengths right out-of-the-water.
(that was the thought nagging at the back of my mind earlier - but we've 
been talking about 'the terminal', ie outside of the limitations of a 
web-browser environment, so it was insufficiently assertive)



The usual work-around (which I thought was initially/largely motivated 
by the Tweet's 140-character limit) was to use a URL-shortener - gaining 
brevity at the expense of double-handling. In reality, as time has 
gone-by, various ones expressed concerns about (institutionalised) 
bit-rot and raise security issues ('what am I actually clicking on?').


There was actually a W3C "Working Group Note" that has been released 
into the public domain (a small surprise to me), detailing "Curie"-s. 
Sadly, as-yet I don't think any (major) web-browser offers an 
implementation. (mea culpa?) I seriously doubt that Gnome Terminal has 
implemented same/similar!



However, may we return to my earlier question: could the app trap a 
'click'? In which case, the app could store the actual-URI and provide 
its own Curie-like URL-shortening service, by substituting some 
(shorter!) 'click-here' text into the presentation. On the 
return-journey, in capturing the click, the app could substitute 
back-again before passing the full-length URI to the web-browser.


QED?
(smirk - Murphy meets "The best laid plans of mice and men...")


(apologies, I don't use Gnome - it didn't/doesn't offer the 
multi-display control/flexibility I require)



* I've been looking at edX's "Creative Coding" online course. It is 
aimed at artists and animators learning to code, and thus aims to make 
the computer draw (instead of counting dollars-and-cents, per the usual 
course-format). Sadly it is JavaScript-based (the p5.js library). Why do 
things the easy way? Nah! Instead, I've been investigating a 'corner' of 
Python with which I have had no contact to date. The Pygame library 
offers a drawing "canvas", hence it gaining my attention. Plus, without 
the complication of a full-fat GUI, (I think) it will present text AND 
allo

Open Source Maintainer Needed For Our Online Meetup

2020-03-25 Thread Abdur-Rahmaan Janhangeer
Greetings list,

The Python Mauritius User Group is having it's March meetup online.
https://www.meetup.com/MauritiusSoftwareCraftsmanshipCommunity/events/269598174/

We want to have two or more open source maintainers presenting their
projects (core comitters of any python package that's somewhat popular, in
fact we want a walkthrough of either the code base or use of the package it
matters not, no slides needed). Our meetup will be 3/4 hours long with
breaks in between as everybody is fidgeting at home. So, time is not a
problem.

We want to extend the presenters' invitation worldwide to cheer us up
during a period of double/complete lockdown in our country ^^_

Just reply, await your responses!

Else, at the said time on the link in the above meetup event anybody can
join, capacity is 250 presenters and 10k viewers

(info: since last night meetup.com added online location as an option)

Kind Regards,

Abdur-Rahmaan Janhangeer
compileralchemy.com  | github

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


Re: Confusing textwrap parameters, and request for RE help

2020-03-25 Thread Chris Angelico
On Wed, Mar 25, 2020 at 8:31 PM DL Neil via Python-list
 wrote:
> 1 what features does the terminal offer when a user 'clicks'?
> Is it only applicable to URLs and linked to the web-browser within
> "Preferred Applications"? Are you able to 'grab' that click from the
> app? eg MOUSEDOWN*.

In most terminal emulators, and certainly in xfce4-terminal, a URL can
be highlighted and right-clicked on.

Grabbing clicks IS possible, but that has other consequences, and is a
subject for a separate thread (which I may end up raising).

> 2 ultimately, you're on-a-hiding-to-nothing (apologies to
> non-English-English speakers: means 'no hope'!) given that URLs are
> defined by, but not length-limited by, RFC. Any 'limits' are applied by
> implementation/web-browser publishers. Currently in-use editions may
> vary widely, ie from 2K~64K. Any and all of which would blow terminal
> line-lengths right out-of-the-water.

Yeah, that part isn't too bad - what ends up happening is that the URL
doesn't get wrapped. It's not pretty but it's functional.

> However, may we return to my earlier question: could the app trap a
> 'click'? In which case, the app could store the actual-URI and provide
> its own Curie-like URL-shortening service, by substituting some
> (shorter!) 'click-here' text into the presentation. On the
> return-journey, in capturing the click, the app could substitute
> back-again before passing the full-length URI to the web-browser.

Yes, there are two ways that could be done: the hyperlink protocol,
which isn't supported in most terminal applications; or manually
handling all clicks, which quite possibly will end up being what
happens.

> * I've been looking at edX's "Creative Coding" online course. It is
> aimed at artists and animators learning to code, and thus aims to make
> the computer draw (instead of counting dollars-and-cents, per the usual
> course-format). Sadly it is JavaScript-based (the p5.js library). Why do
> things the easy way? Nah! Instead, I've been investigating a 'corner' of
> Python with which I have had no contact to date. The Pygame library
> offers a drawing "canvas", hence it gaining my attention. Plus, without
> the complication of a full-fat GUI, (I think) it will present text AND
> allow keyboard and mouse-key trapping - all from the comfort and glory
> of a terminal-based Python program...
>
> Have you ever poked into this dark corner of the pip-y-verse?
> Would you like a PoC (I'll call it 'coursework')? (tomorrow)
>

Never looked into that. I'm not really into art, sorry. (I once did a
ten-minute art jam on a topic of "video game characters", and my
chosen medium was... matplotlib. I'll let you guess at the details.)
Drawing's never been something I'm any good at.

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


Re: How to create an Excel app that runs Python?

2020-03-25 Thread Gisle Vanem

Grant Edwards wrote:


On 2020-03-24, oliver  wrote:


Use the win32com library to interact with Excel via COM.


Huh?  I thought that the users have no way of running a local Python
app.


Maybe creating a self-contained .exe using PyInstaller?
For me, this:
  pyinstaller.exe --noconfirm --console --onefile file.py

creates a 'dist/file.exe' that depend on nothing but
system libraries. But it's 5 MByte though.


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


Re: How to create an Excel app that runs Python?

2020-03-25 Thread farayao . ds
On Tuesday, 24 March 2020 17:38:11 UTC, Paolo G. Cantore  wrote:
> On Tue, Mar 24, 2020, 4:45 PM  wrote:
> 
> > I have the following scenario:
> >
> > I have created lots of python files that I use to calculate a Cashflow
> > model, when I run these files I get a beautiful pandas DataFrame that
> > contains my final model. My mission is to show this table to the rest of
> > the company in a friendly format ("Excel") and they need to be able to
> > generate this table themselves from Excel, using the Python script I
> > created ("the idea is that they open an excel file that has some type of
> > dashboard and a form that they need to fill in, once they fill it in and
> > press "Go" or "Run" or something like that, these parameters will be sent
> > to the Python script to generate this final pandas DataFrame. Finally this
> > DataFrame needs to be displayed/pasted in the Excel sheet that they
> > initially opened)
> >
> >
> > The problems:
> >
> > The company needs to be able to run this model, but the users, apart from
> > me, use Excel and they can't open up a Jupyter notebook or VSC to run the
> > code. They can't even install Python on their machines (or at least that is
> > not ideal)
> >
> >
> > My Attempts:
> >
> > I am currently using "xlwings" to run Python within Excel, although it
> > requires that the user has Python and xlwings installed and has added the
> > xlwings "Addin", which is not an ideal solution at all.
> >
> > I am thinking about using Dash, I don't know if it is what I need since I
> > haven't looked into it that much yet (I have been trying to make it work on
> > xlwings first)
> >
> >
> >
> > If you have any suggestions on how to do this, I would really appreciate
> > that.
> >
> > Thank you
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> >
> The scenario you describe should be fulfilled by a web application.
> 
> I'm sure your users are also able to use a browser, not only Excel.
> 
> The HTML forms management offers the GUI capabilities to enter the 
> parameters. The processing steps could be as follows:
> 
> 1. Enter the url for the application in question and display the form.
> 2. Enter the needed data in the form.
> 3. Process the data (with lots of your python scripts) and show the 
> result in the browser.
> 4. If all is ok, download the data sheet in Excel format (using 
> DataFrame.to_excel)

Hello Paolo,

Thanks for your reply, indeed now I'm thinking on building a web app, do you 
have any suggestions for this? I am thinking of using Tkinter, the method that 
you describe using HTML is also using Javascript?

Kind Regards
Felipe
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to create an Excel app that runs Python?

2020-03-25 Thread farayao . ds
On Tuesday, 24 March 2020 16:12:00 UTC, Souvik Dutta  wrote:
> You might try pyqt5 if you want to make a custom GUI and also if you have
> tha time to do so.
> 
> On Tue, Mar 24, 2020, 4:45 PM  wrote:
> 
> > I have the following scenario:
> >
> > I have created lots of python files that I use to calculate a Cashflow
> > model, when I run these files I get a beautiful pandas DataFrame that
> > contains my final model. My mission is to show this table to the rest of
> > the company in a friendly format ("Excel") and they need to be able to
> > generate this table themselves from Excel, using the Python script I
> > created ("the idea is that they open an excel file that has some type of
> > dashboard and a form that they need to fill in, once they fill it in and
> > press "Go" or "Run" or something like that, these parameters will be sent
> > to the Python script to generate this final pandas DataFrame. Finally this
> > DataFrame needs to be displayed/pasted in the Excel sheet that they
> > initially opened)
> >
> >
> > The problems:
> >
> > The company needs to be able to run this model, but the users, apart from
> > me, use Excel and they can't open up a Jupyter notebook or VSC to run the
> > code. They can't even install Python on their machines (or at least that is
> > not ideal)
> >
> >
> > My Attempts:
> >
> > I am currently using "xlwings" to run Python within Excel, although it
> > requires that the user has Python and xlwings installed and has added the
> > xlwings "Addin", which is not an ideal solution at all.
> >
> > I am thinking about using Dash, I don't know if it is what I need since I
> > haven't looked into it that much yet (I have been trying to make it work on
> > xlwings first)
> >
> >
> >
> > If you have any suggestions on how to do this, I would really appreciate
> > that.
> >
> > Thank you
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> >

Thank Souvik,

I will check that library out, anything special about that library in 
particular?

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


Re: How to create an Excel app that runs Python?

2020-03-25 Thread farayao . ds
On Wednesday, 25 March 2020 12:13:58 UTC, Gisle Vanem  wrote:
> Grant Edwards wrote:
> 
> > On 2020-03-24, oliver  wrote:
> > 
> >> Use the win32com library to interact with Excel via COM.
> > 
> > Huh?  I thought that the users have no way of running a local Python
> > app.
> 
> Maybe creating a self-contained .exe using PyInstaller?
> For me, this:
>pyinstaller.exe --noconfirm --console --onefile file.py
> 
> creates a 'dist/file.exe' that depend on nothing but
> system libraries. But it's 5 MByte though.
> 
> 
> -- 
> --gv

Hello Gisle,

Thanks for your answer. To do this I assume that first I need to create an app 
with Tkinter or can I just do this .exe simply with the multiple files I 
already have?

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


Re: How to create an Excel app that runs Python?

2020-03-25 Thread farayao . ds
On Tuesday, 24 March 2020 16:26:53 UTC, oliver  wrote:
> Use the win32com library to interact with Excel via COM. Although the
> learning curve is a little steeper it's not too bad and works great. I used
> this technique to control ARENA with Python through its COM API to run a
> whack of simulations (1000-1), then used python to gather the results,
> and used win32com from python to finally inject the data into Excel and get
> it to generate charts and tables that could be used by stakeholders without
> access to python.
> 
> Oliver Schoenborn
>   || Cloud Application Engineer, Owner || Sentian Cloud Computing Inc.
>   || Ottawa, ON, Canada || +1-613-552-4466 (mobile)
>   || [email protected]
> 
> 
> 
> 
> On Tue, Mar 24, 2020 at 7:16 AM  wrote:
> 
> > I have the following scenario:
> >
> > I have created lots of python files that I use to calculate a Cashflow
> > model, when I run these files I get a beautiful pandas DataFrame that
> > contains my final model. My mission is to show this table to the rest of
> > the company in a friendly format ("Excel") and they need to be able to
> > generate this table themselves from Excel, using the Python script I
> > created ("the idea is that they open an excel file that has some type of
> > dashboard and a form that they need to fill in, once they fill it in and
> > press "Go" or "Run" or something like that, these parameters will be sent
> > to the Python script to generate this final pandas DataFrame. Finally this
> > DataFrame needs to be displayed/pasted in the Excel sheet that they
> > initially opened)
> >
> >
> > The problems:
> >
> > The company needs to be able to run this model, but the users, apart from
> > me, use Excel and they can't open up a Jupyter notebook or VSC to run the
> > code. They can't even install Python on their machines (or at least that is
> > not ideal)
> >
> >
> > My Attempts:
> >
> > I am currently using "xlwings" to run Python within Excel, although it
> > requires that the user has Python and xlwings installed and has added the
> > xlwings "Addin", which is not an ideal solution at all.
> >
> > I am thinking about using Dash, I don't know if it is what I need since I
> > haven't looked into it that much yet (I have been trying to make it work on
> > xlwings first)
> >
> >
> >
> > If you have any suggestions on how to do this, I would really appreciate
> > that.
> >
> > Thank you
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> >

Hello Oliver,

Thank for your answer, it sounds like a very sophisticated method, which is 
good, although I don't know what you mean when you refer to COM. What is good 
about the win32com library in particular?

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


Re: Intermittent bug with asyncio and MS Edge

2020-03-25 Thread Barry Scott



> On 25 Mar 2020, at 06:12, Frank Millman  wrote:
> 
> On 2020-03-24 8:39 PM, Barry Scott wrote:
>>> On 24 Mar 2020, at 11:54, Frank Millman  wrote:
>>> 
>>> 
>>> I decided to concentrate on using Wireshark to detect the difference 
>>> between a Python3.7 session and a Python3.8 session. Already I can see some 
>>> differences.
>>> 
>>> There is only one version of my program. I am simply running it with either 
>>> 'py -3.7 ' or 'py -3.8'. And I am ignoring Chrome at this stage, as it is 
>>> only that Edge shows the problem.
>>> 
>>> First point - Python3.7 also shows a lot of [RST, ACK] lines. My guess is 
>>> that this is caused by my 'protocol violation' of sending a 'Keep-Alive' 
>>> header and then closing the connection. Python3.7 does not suffer from 
>>> dropping files, so I now think this is a sidetrack. I will fix my program 
>>> when this is all over, but for now I don't want to touch it.
>> Yes your protocol violation is why you see [RST, ACK].
>> I'm confused you know that the code has a critical bug in it and you have 
>> not fixed it?
>> Just send "Connection: close" and I'd assume all will work.
> 
> Well, the reason is simply that I wanted to understand why my code that 
> worked all the way from 3.4 through 3.7 stopped working in 3.8. I realise 
> that my code is faulty, but I still wanted to know what the trigger was that 
> caused the bug to appear.

Got it, I'd not picked up on you wishes to find the details of why.

> 
> From my testing with Wireshark, I can see that both Edge and Chrome create 20 
> connections to GET 20 files. The difference seems to be that Chrome does not 
> attempt to re-use a connection, even though both client and server have sent 
> Keep-Alive headers. Edge does attempt to re-use the connection.

Chrome will reuse the connections if you load enough files from the same server.
All browser do this to get a page displayed as fast as possible.
Because HTTP is half-duplex its the round trip time rather then bandwidth that 
controls
the time taken get all the asserts needed to render a page most of the time.

> 
> The difference between 3.7 and 3.8 is that 3.7 sends the data in separate 
> packets for the status, each header, and then each chunk, whereas 3.8 sends 
> the whole lot in a single packet.

That will change the timing enough to expose the problem.

I often find with network code bugs that its changes that makes the
timing different that expos bugs in supposed tested and working code.

In this case you could track down what was the cause, but it's often the case 
that it's not practical to do that.
You may not know what changed between when the code worked and when it broke in 
many cases.

> My guess is that 3.7 is slower to send the files, so Edge starts up all 20 
> connections before it has finished receiving the first one, whereas with 3.8, 
> by the time it has opened a few connections the first file has been received, 
> so it tries to re-use the same connection to receive the next one. By then I 
> have closed the connection. If I am right, it is surprising that my program 
> worked *some* of the time.

I have lost count of the number of times when we have found a bug in some code 
that we say "how did it ever work?".

> 
> The same reasoning would explain why it worked when connecting from a remote 
> host. There would be enough delay to force it into the same behaviour as 3.7.

Yep and if there are any middle boxes, routers, man-in-middle-proxies, etc the 
timing/packets get pushed around.

> 
> It has been an interesting ride, and I have learned a lot. I will now look 
> into fixing my program. The easy fix is to just send 'Connection: Close', but 
> I will do it properly and implement 'Keep-Alive'.

Barry

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

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


Re: How to create an Excel app that runs Python?

2020-03-25 Thread Souvik Dutta
It is better than tkinter and also kivy in some way. It uses pure oops
concept so it should be more intuitive and easy to set up. I learnt it in 7
days. Also it has still better community support at
[email protected]

On Wed, Mar 25, 2020, 7:59 PM  wrote:

> On Tuesday, 24 March 2020 16:12:00 UTC, Souvik Dutta  wrote:
> > You might try pyqt5 if you want to make a custom GUI and also if you have
> > tha time to do so.
> >
> > On Tue, Mar 24, 2020, 4:45 PM  wrote:
> >
> > > I have the following scenario:
> > >
> > > I have created lots of python files that I use to calculate a Cashflow
> > > model, when I run these files I get a beautiful pandas DataFrame that
> > > contains my final model. My mission is to show this table to the rest
> of
> > > the company in a friendly format ("Excel") and they need to be able to
> > > generate this table themselves from Excel, using the Python script I
> > > created ("the idea is that they open an excel file that has some type
> of
> > > dashboard and a form that they need to fill in, once they fill it in
> and
> > > press "Go" or "Run" or something like that, these parameters will be
> sent
> > > to the Python script to generate this final pandas DataFrame. Finally
> this
> > > DataFrame needs to be displayed/pasted in the Excel sheet that they
> > > initially opened)
> > >
> > >
> > > The problems:
> > >
> > > The company needs to be able to run this model, but the users, apart
> from
> > > me, use Excel and they can't open up a Jupyter notebook or VSC to run
> the
> > > code. They can't even install Python on their machines (or at least
> that is
> > > not ideal)
> > >
> > >
> > > My Attempts:
> > >
> > > I am currently using "xlwings" to run Python within Excel, although it
> > > requires that the user has Python and xlwings installed and has added
> the
> > > xlwings "Addin", which is not an ideal solution at all.
> > >
> > > I am thinking about using Dash, I don't know if it is what I need
> since I
> > > haven't looked into it that much yet (I have been trying to make it
> work on
> > > xlwings first)
> > >
> > >
> > >
> > > If you have any suggestions on how to do this, I would really
> appreciate
> > > that.
> > >
> > > Thank you
> > > --
> > > https://mail.python.org/mailman/listinfo/python-list
> > >
>
> Thank Souvik,
>
> I will check that library out, anything special about that library in
> particular?
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Confusing textwrap parameters, and request for RE help

2020-03-25 Thread Peter J. Holzer
On 2020-03-23 06:00:41 +1100, Chris Angelico wrote:
> Second point, and related to the above. The regex that defines break
> points, as found in the source code, is:
> 
> wordsep_re = re.compile(r'''
> ( # any whitespace
>   %(ws)s+
> | # em-dash between words
>   (?<=%(wp)s) -{2,} (?=\w)
> | # word, possibly hyphenated
>   %(nws)s+? (?:
> # hyphenated word
>   -(?: (?<=%(lt)s{2}-) | (?<=%(lt)s-%(lt)s-))
>   (?= %(lt)s -? %(lt)s)
> | # end of word
>   (?=%(ws)s|\Z)
> | # em-dash
>   (?<=%(wp)s) (?=-{2,}\w)
> )
> )''' % {'wp': word_punct, 'lt': letter,
> 'ws': whitespace, 'nws': nowhitespace},
> 
> It's built primarily out of small matches with long assertions, eg
> "match a hyphen, as long as it's preceded by two letters or a letter
> and a hyphen".

Do you need that fancy logic? Could you only break on white-space
instead? It won't wrap "tetrabromo-phenolsulfonephthalein" in that case
but since you mentioned its for a twitter client, most users probably
won't mind (and those who do mind will probably insist that the
algorithm should be able to split it into tetrabromo-phenolsulfone-
phthalein, if that's where the line end is, as it was here purely by
lucky accident). A regexp for whitespace is pretty simple.

hp

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


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


Re: Confusing textwrap parameters, and request for RE help

2020-03-25 Thread Peter J. Holzer
On 2020-03-25 10:02:50 +1300, DL Neil via Python-list wrote:
> Today it feels like an anachronism because it is comes from the era of
> fixed-width fonts and line-lengths denominated in characters*. The issue is
> that it was designed to re-define 'white space' and to enable the conversion
> of text 'wrapped' in one (fixed) format, to suit another. With the
> arrival?predominance of proportional-width fonts, the skills of hyphenation
> have started to go the way of cursive hand-writing

That sounds like a non-sequitur to me. Books have always[1] used pro-
portional fonts and of course hand-writing is proportional, too. Both
use hyphenation. Fixed width fonts were only used by typewriters and
later character based terminals and printers. They waned after bitmapped
GUIs and printers became common.

If anything, I think it was fixed-width fonts which contributed to the
decline of hyphenation: With a fixed-width font you can't get a proper
justification anyway, and if your right margin is ragged, hyphenation is
much less important (at least in English, were most words are short -
it's different in German). And given that hyphenation is a really hard
problem even for a single language, it is not very surprising that most
programs don't even try.

hp

[1] Except for a few textbooks from the early 1980s which hit the narrow
window between "I have a computer so I don't need a professional
typesetter" and "My computer now has proportional fonts").


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


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


Module import best practice

2020-03-25 Thread Rich Shepard

I'm writing an application using Python3 and Tkinter. The views/ directory
contain multiple modules, including one called commonDlgs.py. This contains
classes (such as those for validating data entry) used by all the data entry
views. Some classes in commonDlgs imports other modules.

My question is whether to import into each view class those modules needed
by it or import all supporting modules at the top of commonDlgs.py, then
import that module in each view with:

from . import commonDlgs as cd

rather than importing specific classes in each view module?

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


Re: Confusing textwrap parameters, and request for RE help

2020-03-25 Thread Richard Damon
On 3/25/20 3:52 PM, Peter J. Holzer wrote:
> On 2020-03-25 10:02:50 +1300, DL Neil via Python-list wrote:
>> Today it feels like an anachronism because it is comes from the era of
>> fixed-width fonts and line-lengths denominated in characters*. The issue is
>> that it was designed to re-define 'white space' and to enable the conversion
>> of text 'wrapped' in one (fixed) format, to suit another. With the
>> arrival?predominance of proportional-width fonts, the skills of hyphenation
>> have started to go the way of cursive hand-writing
> That sounds like a non-sequitur to me. Books have always[1] used pro-
> portional fonts and of course hand-writing is proportional, too. Both
> use hyphenation. Fixed width fonts were only used by typewriters and
> later character based terminals and printers. They waned after bitmapped
> GUIs and printers became common.
>
> If anything, I think it was fixed-width fonts which contributed to the
> decline of hyphenation: With a fixed-width font you can't get a proper
> justification anyway, and if your right margin is ragged, hyphenation is
> much less important (at least in English, were most words are short -
> it's different in German). And given that hyphenation is a really hard
> problem even for a single language, it is not very surprising that most
> programs don't even try.
>
> hp
>
> [1] Except for a few textbooks from the early 1980s which hit the narrow
> window between "I have a computer so I don't need a professional
> typesetter" and "My computer now has proportional fonts").

Actually, fixed width fonts are easy to justify, you just add additional 
space between words through the line. The varying spaces between words can 
be a bit annoying, but it was done. My thought is that variable width fonts
tend to put more characters per inch. and with wider screens we are no longer
trying as hard to keep to less than 80 characters per line (or less with 
margins),
so with micros-spacing justification the larger variance in natural line width 
isn't
as noticable.






-- 
Richard Damon

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


Re: Confusing textwrap parameters, and request for RE help

2020-03-25 Thread Chris Angelico
On Thu, Mar 26, 2020 at 6:34 AM Peter J. Holzer  wrote:
>
> On 2020-03-23 06:00:41 +1100, Chris Angelico wrote:
> > Second point, and related to the above. The regex that defines break
> > points, as found in the source code, is:
> >
> > wordsep_re = re.compile(r'''
> > ( # any whitespace
> >   %(ws)s+
> > | # em-dash between words
> >   (?<=%(wp)s) -{2,} (?=\w)
> > | # word, possibly hyphenated
> >   %(nws)s+? (?:
> > # hyphenated word
> >   -(?: (?<=%(lt)s{2}-) | (?<=%(lt)s-%(lt)s-))
> >   (?= %(lt)s -? %(lt)s)
> > | # end of word
> >   (?=%(ws)s|\Z)
> > | # em-dash
> >   (?<=%(wp)s) (?=-{2,}\w)
> > )
> > )''' % {'wp': word_punct, 'lt': letter,
> > 'ws': whitespace, 'nws': nowhitespace},
> >
> > It's built primarily out of small matches with long assertions, eg
> > "match a hyphen, as long as it's preceded by two letters or a letter
> > and a hyphen".
>
> Do you need that fancy logic? Could you only break on white-space
> instead? It won't wrap "tetrabromo-phenolsulfonephthalein" in that case
> but since you mentioned its for a twitter client, most users probably
> won't mind (and those who do mind will probably insist that the
> algorithm should be able to split it into tetrabromo-phenolsulfone-
> phthalein, if that's where the line end is, as it was here purely by
> lucky accident). A regexp for whitespace is pretty simple.
>

If I *just* want to break on whitespace, I can do that (set both flags
to False, off it goes). And in fact, that's what I've done so far, and
it's working reasonably well. But I was hoping to be more flexible
than that.

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


Re: Confusing textwrap parameters, and request for RE help

2020-03-25 Thread Vlastimil Brom
22. 3. 2020 v 20:02 Chris Angelico :
>
> When using textwrap.fill() or friends, setting break_long_words=False
> without also setting break_on_hyphens=False has the very strange
> behaviour that a long hyphenated word will still be wrapped. I
> discovered this as a very surprising result when trying to wrap a
> paragraph that contained a URL, and wanting the URL to be kept
> unchanged:
> [...]
>
> Second point, and related to the above. The regex that defines break
> points, as found in the source code, is:
>
> wordsep_re = re.compile(r'''
> ( # any whitespace
>   %(ws)s+
> | # em-dash between words
>   (?<=%(wp)s) -{2,} (?=\w)
> | # word, possibly hyphenated
>   %(nws)s+? (?:
> # hyphenated word
>   -(?: (?<=%(lt)s{2}-) | (?<=%(lt)s-%(lt)s-))
>   (?= %(lt)s -? %(lt)s)
> | # end of word
>   (?=%(ws)s|\Z)
> | # em-dash
>   (?<=%(wp)s) (?=-{2,}\w)
> )
> )''' % {'wp': word_punct, 'lt': letter,
> 'ws': whitespace, 'nws': nowhitespace},
>
> It's built primarily out of small matches with long assertions, eg
> "match a hyphen, as long as it's preceded by two letters or a letter
> and a hyphen". What I want to do is create a *negative* assertion:
> specifically, to disallow any breaking between "\b[a-z]+://" and "\b",
> which will mean that a URL will never be broken ("https://..";
> until the next whitespace boundary). Regex assertions of this form
> have to be fixed lengths, though, so as described, this isn't
> possible. Regexperts, any ideas? How can I modify this to never break
> inside a URL?
> [...]
>
> ChrisA
>
Hi,
I might be missing something obvious, but it seems to me, that the
regex library might help with regard to your originally presented
approach:
https://pypi.org/project/regex/
https://bitbucket.org/mrabarnett/mrab-regex/

It supports variable-length lookaround assertions (beyond many other
extra features);
You could make textwrap or other code use it with a tweaked regex pattern.
However, I can't say whether it is sufficient in order to achieve the
needed functionality.

Regards,
 vbr
-- 
https://mail.python.org/mailman/listinfo/python-list