Faking stdlib

2020-10-01 Thread Antoon Pardon

I'm playing with the following idea.

Have the main program do some kind of preparations so that all further 
modules can import the standard modules via stdlib. So instead of


import sys
from itertools import chain

I could do

import stdlib.sys
from stdlib.itertools import chain

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


Re: Interference tkinter and plot from matplotlib

2020-10-01 Thread Pierre Bonville
Thank you, Mr. Gollwitzer. I understand the problem. I'll see what I can do.
Regards,
P.Bonville


Le mer. 30 sept. 2020 à 17:02, Christian Gollwitzer  a
écrit :

> Am 30.09.20 um 15:46 schrieb Pierre Bonville:
> >   Hi everybody,
>
> > Interference tkinter and plot from matplotlib
>
>
> You are mixing different ways of control flow. In a GUI program, don't
> call input(). Use the mainloop() as the very last of your calls, and
> only work in the callbacks. That means you would integrate a "Next"
> button in your GUI which switches the plots - or even show them side by
> side.
>
> Concerning matplotlib, you'll need to tell it to integrate with Tk
> properly.
>
> https://matplotlib.org/3.3.1/gallery/user_interfaces/embedding_in_tk_sgskip.html
>
>
> If you want a simple solution instead of full-blown GUI programming, use
> IPython https://ipython.readthedocs.io/en/stable/config/eventloops.html
> or jupyter notebooks.
>
>
> Christian
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Faking stdlib

2020-10-01 Thread Chris Angelico
On Thu, Oct 1, 2020 at 5:02 PM Antoon Pardon  wrote:
>
> I'm playing with the following idea.
>
> Have the main program do some kind of preparations so that all further
> modules can import the standard modules via stdlib. So instead of
>
>  import sys
>  from itertools import chain
>
> I could do
>
>  import stdlib.sys
>  from stdlib.itertools import chain
>

My first thought was __getattr__ on a package, but that doesn't seem to work:

# stdlib/__init__.py
def __getattr__(name):
return __import__(name)

>>> import stdlib.math
Traceback (most recent call last):
  File "", line 1, in 
ModuleNotFoundError: No module named 'stdlib.math'
>>> from stdlib import math
>>> math


It may be necessary to use an import hook.

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


Re: Faking stdlib

2020-10-01 Thread Abdur-Rahmaan Janhangeer
The last time this was raised, it seemed that folks in here don't have a
clear idea of what the standard library is ^^

https://mail.python.org/archives/list/python-id...@python.org/thread/XSYEVRPJQUX7VBTPNIJMUFZQIZ7WLOQU/

A summary:

https://lwn.net/Articles/794458/

Kind Regards,


Abdur-Rahmaan Janhangeer

https://www.github.com/Abdur-RahmaanJ

Mauritius

sent from gmail client on Android, that's why the signature is so ugly.
-- 
https://mail.python.org/mailman/listinfo/python-list


Pip users: big change coming this month

2020-10-01 Thread Sumana Harihareswara
Changes are coming to pip, Python's package installation tool, in 
October 2020. Please read and share this migration guide: 
https://pip.pypa.io/en/latest/user_guide/#changes-to-the-pip-dependency-resolver-in-20-2-2020 
.


We're working on improving the Python packaging toolchain, foundational 
work that will (in the long run) make the whole Python package 
installation experience way less confusing.


The pip team made a 2-minute video to explain what's up:

https://youtu.be/B4GQCBBsuNU

We are also doing user experience studies, and want you to sign up if 
you ever do anything with Python (whatever your level of 
skill/experience): 
http://www.ei8fdb.org/thoughts/2020/03/pip-ux-study-recruitment/


https://mastodon.social/@brainwane/104950044427849411 is a good toot to 
boost, and https://twitter.com/ThePSF/status/1311038036013199363 is a 
good tweet to retweet, if you want to help us get the word out.


MORE DETAILS: at the migration guide at 
https://pip.pypa.io/en/latest/user_guide/#changes-to-the-pip-dependency-resolver-in-20-2-2020 
.


On 7/30/20 10:58 AM, Sumana Harihareswara wrote:
On behalf of the Python Packaging Authority, I am pleased to announce 
that we have just released pip 20.2, a new version of pip. You can 
install it by running python -m pip install --upgrade pip.


--
Sumana Harihareswara
Changeset Consulting
https://changeset.nyc
--
https://mail.python.org/mailman/listinfo/python-list


Hot reload Flask app?

2020-10-01 Thread sjeik_appie
   Hi,
   I would like to create a "/reload" view in my Flask app, so I could easily
   and safely reload it when code, templates etc change. Similar to what
   happens when running the app with the debug server. I am using Nginx and
   Gevent on a recent Ubuntu system with Python 3.6.
   My strategy would be to gracefully stop Gevent [1], then do
   os.kill(os.getpid(), signal.SIGHUP). I have not yet tried this (not
   working today!). Just wondering if there are best practices.
   Thanks!
   Albert-Jan
   [1]
   
http://www.gevent.org/api/gevent.baseserver.html#gevent.baseserver.BaseServer.stop
-- 
https://mail.python.org/mailman/listinfo/python-list


Why is Python deleting every time

2020-10-01 Thread Sai Shubham Ray
Sometimes when I try to run python program it says that python is not
installed and I have to repair it. Thank god there is a repair option in
python but still do something to get rid of this problem

Regards
Sai Shubham Ray
-- 
https://mail.python.org/mailman/listinfo/python-list


SQLObject 3.8.1

2020-10-01 Thread Oleg Broytman
Hello!

I'm pleased to announce version 3.8.1, the first bugfix release of branch
3.8 of SQLObject.


What's new in SQLObject
===

The contributor for this release is Neil Muller.

Documentation
-

* Use conf.py options to exclude sqlmeta options.

Tests
-

* Fix ``PyGreSQL`` version for Python 3.4.

CI
--

* Run tests with Python 3.8 at AppVeyor.


For a more complete list, please see the news:
http://sqlobject.org/News.html


What is SQLObject
=

SQLObject is an object-relational mapper.  Your database tables are described
as classes, and rows are instances of those classes.  SQLObject is meant to be
easy to use and quick to get started with.

SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite,
Firebird, Sybase, MSSQL and MaxDB (also known as SAPDB).

Python 2.7 or 3.4+ is required.


Where is SQLObject
==

Site:
http://sqlobject.org

Development:
http://sqlobject.org/devel/

Mailing list:
https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss

Download:
https://pypi.org/project/SQLObject/3.8.1a0.dev20191208/

News and changes:
http://sqlobject.org/News.html

StackOverflow:
https://stackoverflow.com/questions/tagged/sqlobject


Example
===

Create a simple class that wraps a table::

  >>> from sqlobject import *
  >>>
  >>> sqlhub.processConnection = connectionForURI('sqlite:/:memory:')
  >>>
  >>> class Person(SQLObject):
  ... fname = StringCol()
  ... mi = StringCol(length=1, default=None)
  ... lname = StringCol()
  ...
  >>> Person.createTable()

Use the object::

  >>> p = Person(fname="John", lname="Doe")
  >>> p
  
  >>> p.fname
  'John'
  >>> p.mi = 'Q'
  >>> p2 = Person.get(1)
  >>> p2
  
  >>> p is p2
  True

Queries::

  >>> p3 = Person.selectBy(lname="Doe")[0]
  >>> p3
  
  >>> pc = Person.select(Person.q.lname=="Doe").count()
  >>> pc
  1

Oleg.
-- 
Oleg Broytmanhttps://phdru.name/p...@phdru.name
   Programmers don't die, they just GOSUB without RETURN.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Hot reload Flask app?

2020-10-01 Thread Roland Müller via Python-list



On 2020-10-01 16:33, sjeik_ap...@hotmail.com wrote:

Hi,
I would like to create a "/reload" view in my Flask app, so I could easily
and safely reload it when code, templates etc change. Similar to what
happens when running the app with the debug server. I am using Nginx and
Gevent on a recent Ubuntu system with Python 3.6.
My strategy would be to gracefully stop Gevent [1], then do
os.kill(os.getpid(), signal.SIGHUP). I have not yet tried this (not
working today!). Just wondering if there are best practices.
Thanks!
Albert-Jan
[1]

http://www.gevent.org/api/gevent.baseserver.html#gevent.baseserver.BaseServer.stop


Running flask app.run(debug=True) will make the Flask server watching 
the filesystem for source code changes and re-deploy your app.


https://pythonhosted.org/Flask-Debug/

-Roland

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


Re: A library that converts a type-annotated function into a webpage with HTML forms?

2020-10-01 Thread Dieter Maurer
James Lu wrote at 2020-9-30 16:45 -0400:
>Is there a python library available that converts a type-annotated Python
>function into a webpage with HTML forms?
>
>Something like:
>
>
>def foo(name: str, times: int):
>return f"Hello {name}!" * times
>
>serve_from(foo, host="0.0.0.0", port=3000)
>
>Turning into a server that serves something like this:
>
>
>name
>
>
>
>
>And hitting the submit button executes the function.

You could have a look at "pydoc" ("the Python documentation tool").

As the name indicates, it is for documentation not for the
execution of funtions (which may be **VERY** dangerous).
But it can show you how to integrate an HTTP server
and how to use Python's `inpect` module to determine
function signatures.
You would need to create the forms yourself and the function
execution actions (and again: executing arbitrary functions is
really dangerous -- do not do it!).
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why is Python deleting every time

2020-10-01 Thread Terry Reedy

On 10/1/2020 7:29 AM, Sai Shubham Ray wrote:

Sometimes when I try to run python program it says that python is not
installed and I have to repair it.


Because you are running the Python installer instead of Python itself 
after having it installed.



Thank god there is a repair option in
python but still do something to get rid of this problem


Delete the Python installer and you cannot run it. If you ever do need 
to repair, you can redownload.  Or rename the installation program (if 
you can) to something like 'Install Python x.y'.


--
Terry Jan Reedy

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


Re: List of All Error Menssages

2020-10-01 Thread Luis Gustavo Araujo
  Hi,
Is it possible to get the list of all error messages that display in
Python? I want the full message -> type error: additional message.

Examples:
NameError: name 'x' is not defined
IndentationError: unindent does not match any outer indentation level

In this webpage (ttps://docs.python.org/3/library/exceptions.html) I only
can check the type error.

[]s


Em qui., 1 de out. de 2020 às 15:59, Luis Gustavo Araujo <
luisaraujo.i...@gmail.com> escreveu:

> Hi,
> Is it possible to get the list of all error messages that display in
> Python? I want the full message -> type error: additional message.
>
> Examples:
> NameError: name 'x' is not defined
> IndentationError: unindent does not match any outer indentation level
>
> In this webpage (ttps://docs.python.org/3/library/exceptions.html) I only
> can check the type error.
>
> []s
>
>
> --
>
> [image: Prefeitura Municipal de Amélia Rodrigues]
> 
>
> LUIS GUSTAVO ARAUJO
> *Amélia Rodrigues Prefecture - Brazil  (*
>
> *Teacher of Computer Science) UNIFACS - Laureate International
> Universities (Professor Assistant I)*
>
> Degree in Computer Science (IFBA) - 2015
> Master Degrees in Computer Applied (UEFS) - 2018
> PhD  Student in Computer Science (UFBA)
> *http://dgp.cnpq.br/dgp/espelhorh/8431672735528634
> *
>
> [image: Twitter]   [image: Facebook]
>  [image: Github]
> 
>
>
>
>
> 
>  Livre
> de vírus. www.avast.com
> .
> <#m_-2814426795322638799_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>


-- 

[image: Prefeitura Municipal de Amélia Rodrigues]


LUIS GUSTAVO ARAUJO
*Amélia Rodrigues Prefecture - Brazil  (*

*Teacher of Computer Science) UNIFACS - Laureate International Universities
(Professor Assistant I)*

Degree in Computer Science (IFBA) - 2015
Master Degrees in Computer Applied (UEFS) - 2018
PhD  Student in Computer Science (UFBA)
*http://dgp.cnpq.br/dgp/espelhorh/8431672735528634
*

[image: Twitter]   [image: Facebook]
 [image: Github]

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


Regex Group case change

2020-10-01 Thread Raju
Hello Everyone,

I want to change the case on input string i was able to match using python 
regex but couldn't find the way to change the case.

For example string: 
Input: 7Section Hello Jim 
output: 7Section hello Jim

I was doing if statment with regex

if re.match("(\d+\w* )(Hello)( \w+)",string)):
   print(r"(\d+\w* )(Hello)( \w+)","\1\2.lower()\3",string)

Output was
7Section \2.lower() Jim
Above one is one of the regex i have in function, i have total 6 regex patterns 
and i want to keep all in this if elif else statment. It is matching, but can 
someone advise how to replace Hello to hello?

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


Re: Problem

2020-10-01 Thread Mirko via Python-list
Am 30.09.2020 um 23:44 schrieb Chris Angelico:
> On Thu, Oct 1, 2020 at 7:33 AM Mirko via Python-list

>> We are seeing these troubles from newcomers on Windows all of the
>> time -- and that for years. Isn't it time to ask if the way Python
>> installs itself on Windows-Systems is appropriate?
>>
> 
> The problem is that there isn't "the way". Did the person:
> 
> 1) Download an MSI file from python.org?
> 2) Install ActiveState?
> 3) Install Enthought?
> 4) Install Anaconda?
> 5) Get Python from the Microsoft Store?
> 6) Something else?
> 
> They're all different, they all behave differently, they all have
> different defaults. And then there's the question of "did you install
> it for everyone or just you?", and so on.
> 
> The core Python devs have control of the first option, and some
> control over the fifth, but none of the others.

Yes, but usability improvements for the one from python.org could be
later adopted by the other distributors.

I think, that you are jumping from "How to improve the current
situation?" to "How to make it absolutely perfect?"

That's a sure path into the incapacity to act. I'm not talking about
solving all the problems that newcomers have, but reducing them.

Eryk Sun suggested to rename the installer to a more explicit
filename. Will that solve all the problems? No. But it reduces the
troubles by solving one particular case. Renaming "IDLE" to "Python
IDE" (or similar) might also. Adding desktop icons for it or have a
"Start the Python Editor (IDLE) now" button/checkbox at the end of
the installation also.

> So, go ahead, ask if it's appropriate good luck getting a useful response 
> :|

Well, I am not the one who needs to answer those beginner questions
time and time again. ;-)

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


Re: Problem

2020-10-01 Thread Chris Angelico
On Fri, Oct 2, 2020 at 6:11 AM Mirko via Python-list
 wrote:
>
> Am 30.09.2020 um 23:44 schrieb Chris Angelico:
> > On Thu, Oct 1, 2020 at 7:33 AM Mirko via Python-list
>
> >> We are seeing these troubles from newcomers on Windows all of the
> >> time -- and that for years. Isn't it time to ask if the way Python
> >> installs itself on Windows-Systems is appropriate?
> >>
> >
> > The problem is that there isn't "the way". Did the person:
> >
> > 1) Download an MSI file from python.org?
> > 2) Install ActiveState?
> > 3) Install Enthought?
> > 4) Install Anaconda?
> > 5) Get Python from the Microsoft Store?
> > 6) Something else?
> >
> > They're all different, they all behave differently, they all have
> > different defaults. And then there's the question of "did you install
> > it for everyone or just you?", and so on.
> >
> > The core Python devs have control of the first option, and some
> > control over the fifth, but none of the others.
>
> Yes, but usability improvements for the one from python.org could be
> later adopted by the other distributors.

Maybe those usability improvements have already been done. I know that
both the python.org downloads and the MS store download have been
significantly improved over the past few years. But frequently, when
these kinds of questions come up, it turns out that someone's
installed *multiple* Pythons. There's not a lot we can do about that.

> I think, that you are jumping from "How to improve the current
> situation?" to "How to make it absolutely perfect?"
>
> That's a sure path into the incapacity to act. I'm not talking about
> solving all the problems that newcomers have, but reducing them.

No, I never said anything of the sort.

> Eryk Sun suggested to rename the installer to a more explicit
> filename. Will that solve all the problems? No. But it reduces the
> troubles by solving one particular case. Renaming "IDLE" to "Python
> IDE" (or similar) might also. Adding desktop icons for it or have a
> "Start the Python Editor (IDLE) now" button/checkbox at the end of
> the installation also.

Renaming Idle to "Python IDE" would be a very bad idea, since there
are many other Python IDEs.

Starting something immediately after installation completes might
help, but would probably just defer the issue to the *second* time
someone wants something.

Last I checked, the Start menu entries DO have the name Python in them
(I think they were in a submenu called "Python X.Y"), so anything
involving changing names in the Start menu is unlikely to help
further.

There is no simple foolproof solution. That's why people still get confused.

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


Re: Hot reload Flask app?

2020-10-01 Thread sjeik_appie
   On 1 Oct 2020 17:58, Roland Müller via Python-list
wrote:

 On 2020-10-01 16:33, sjeik_ap...@hotmail.com wrote:
 > Hi,
 > I would like to create a "/reload" view in my Flask app, so I
 could easily
 > and safely reload it when code, templates etc change. Similar to
 what
 > happens when running the app with the debug server. I am using
 Nginx and
 > Gevent on a recent Ubuntu system with Python 3.6.
 > My strategy would be to gracefully stop Gevent [1], then do
 > os.kill(os.getpid(), signal.SIGHUP). I have not yet tried this
 (not
 > working today!). Just wondering if there are best practices.
 > Thanks!
 > Albert-Jan
 > [1]
 >
 
http://www.gevent.org/api/gevent.baseserver.html#gevent.baseserver.BaseServer.stop

 Running flask app.run(debug=True) will make the Flask server watching
 the filesystem for source code changes and re-deploy your app.

 https://pythonhosted.org/Flask-Debug/ 

   ==》 Hi,
   Thanks. I was aware of running it in debug mode, but I was looking for
   domething to use in production. I checked how werkzeug does it, see line
   160: 
https://github.com/pallets/werkzeug/blob/master/src/werkzeug/_reloader.py
   I'll study this in more detail tomorrow.
   Best wishes,
   Albert-Jan
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem

2020-10-01 Thread Hexamorph
Am 01.10.2020 um 22:17 schrieb Chris Angelico:

> Maybe those usability improvements have already been done.

Haven't doubted that. Maybe they are just not enough yet.

> Renaming Idle to "Python IDE" would be a very bad idea, since there
> are many other Python IDEs.

You missed the "(or similar)" addition. ;-)

Call it "IDLE - Python IDE" or "Python Editor (IDLE)" or whatever.
Something that gives the newcomer a better clue than "IDLE".

> Starting something immediately after installation completes might
> help, but would probably just defer the issue to the *second* time
> someone wants something.

Probably not if they once have seen that there is some GUI editor
and can barely recall it was something like "IDE", "Python Editor"
or so. Again, will it help in *all* cases? No, but in some.

> There is no simple foolproof solution. That's why people still get confused.

That's what I mean. You dismiss suggestions on the grounds of "no
simple foolproof solution" ie. a perfect solution. I'm not talking
about solutions that will work in every case and solve all possible
problems. I'm talking about incremental improvements which reduce
some -- not remove all -- those troubles,

But again, I'm not the one who has to deal with all this. :-)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem

2020-10-01 Thread Mirko via Python-list
Am 01.10.2020 um 22:17 schrieb Chris Angelico:

> Maybe those usability improvements have already been done.

Haven't doubted that. Maybe they are just not enough yet.

> Renaming Idle to "Python IDE" would be a very bad idea, since there
> are many other Python IDEs.

You missed the "(or similar)" addition.

Call it "IDLE - Python IDE" or "Python Editor (IDLE)" or whatever.
Something that gives the newcomer a better clue than "IDLE".

> Starting something immediately after installation completes might
> help, but would probably just defer the issue to the *second* time
> someone wants something.

Probably not if they once have seen that there is some GUI editor
and can barely recall it was something like "IDE", "Python Editor"
or so. Again, will it help in *all* cases? No, but in some.

> There is no simple foolproof solution. That's why people still get confused.

That's what I mean. You dismiss suggestions on the grounds of "no
simple foolproof solution" ie. a perfect solution. I'm not talking
about solutions that will work in every case and solve all possible
problems. I'm talking about incremental improvements which reduce
some -- not remove all -- those troubles,

But again, I'm not the one who has to deal with all this.


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


Re: Problem

2020-10-01 Thread Chris Angelico
On Fri, Oct 2, 2020 at 7:06 AM Hexamorph  wrote:
>
> Am 01.10.2020 um 22:17 schrieb Chris Angelico:
>
> > Maybe those usability improvements have already been done.
>
> Haven't doubted that. Maybe they are just not enough yet.
>
> > Renaming Idle to "Python IDE" would be a very bad idea, since there
> > are many other Python IDEs.
>
> You missed the "(or similar)" addition. ;-)
>
> Call it "IDLE - Python IDE" or "Python Editor (IDLE)" or whatever.
> Something that gives the newcomer a better clue than "IDLE".

How about "IDLE (Python 3.8 32-bit)" in a submenu called "Python 3.8"?
Seems pretty good to me.

Calling something "Python IDE" or "Python Editor" isn't any better.
People will still be confused, and it's now become *less* clear what
it actually is. (Or more verbose, if you put all the different words
in. And that has its own problems.)

> > There is no simple foolproof solution. That's why people still get confused.
>
> That's what I mean. You dismiss suggestions on the grounds of "no
> simple foolproof solution" ie. a perfect solution. I'm not talking
> about solutions that will work in every case and solve all possible
> problems. I'm talking about incremental improvements which reduce
> some -- not remove all -- those troubles,
>

On the contrary, I'm not dismissing the solutions because they're not
perfect - I'm dismissing them because they're already done, and we
have proof that they don't solve the problem. You're suggesting
virtually the same things that are already the case. If they were to
offer any benefit, we already have it.

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


Re: Regex Group case change

2020-10-01 Thread Cameron Simpson
On 01Oct2020 12:41, Raju  wrote:
>I want to change the case on input string i was able to match using 
>python regex but couldn't find the way to change the case.
>
>For example string:
>Input: 7Section Hello Jim
>output: 7Section hello Jim
>
>I was doing if statment with regex
>
>if re.match("(\d+\w* )(Hello)( \w+)",string)):
>   print(r"(\d+\w* )(Hello)( \w+)","\1\2.lower()\3",string)
>
>Output was
>7Section \2.lower() Jim
>Above one is one of the regex i have in function, i have total 6 regex 
>patterns and i want to keep all in this if elif else statment. It is 
>matching, but can someone advise how to replace Hello to hello?

Please paste the _exact_ code you're using to produce the problem. I do 
not believe the code above generates the output you show. I imagine 
there's som kind of regexp replacement call in the real code.

There's a few things going on in the code above which will cause 
trouble:

Be consistent using "raw strings", which look like r"...". Normal 
Python string recognise a variety of backslash escaped things, like \n 
for a newline character. The purpose of a raw string is to disable that, 
which is important with regular expressions because they also use 
backslash escapes such as \d for a digit. Try to _always_ use raw 
strings when working with regular expressions.

Your print() call _looks_ like it should be printing the result of a 
regexp substitute() function call, based on the "\1\2.lower()\3" in the 
second field. The substitute() syntax does not support embedding str 
methods in the result, so the .lower() will just be written out 
directly. To do more complicated things you need to pull out the matched 
groups and work with them separately, then assemble your desired result.

You do not keep the result of the re.match call here:

if re.match("(\d+\w* )(Hello)( \w+)",string)):

Traditionally one would write:

m = re.match("(\d+\w* )(Hello)( \w+)",string))
if m:

and in recent Python (3.8+) you can write:

if m := re.match("(\d+\w* )(Hello)( \w+)",string)):

This preserves the result fo the match in the variable "m", which you 
will require if you want to do any work with the result, such as 
lowercasing something.

The matches components of the regexp are available via the .group() 
method of the match result. So:

m.group(1) == "7Section"
m.group(2) == "Hello"

and to print "Hello" lowercased you might write:

m.group(2).lower()

Since this looks much like homework we will leave it to you to apply 
this approach to your existing code.

Cheers,
Cameron Simpson 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Regex Group case change

2020-10-01 Thread Raju
import re
import os
import sys

#word = "7 the world" # 7 The world
#word = "Brian'S" # Brian's
#word = "O'biran"# O'Brian
#word = "Stoke-On-Trent" # Stoke-on-Trent; here i need to lower the case of 
middle word(i.e -On-)
def wordpattern(word):
 output = ''
 if re.match("^\d+|w*$",word):
output = word.upper()
 elif re.match("\w+\'\w{1}$",word):
output = word.capitalize()
 elif re.match("(\d+\w* )(Hello)( \w+)",word))
group(1)group(2).title()group(3)
 else:
output.title()


On Thursday, October 1, 2020 at 10:53:16 PM UTC+1, cameron...@gmail.com wrote:
> On 01Oct2020 12:41, Raju  wrote: 
> >I want to change the case on input string i was able to match using 
> >python regex but couldn't find the way to change the case. 
> > 
> >For example string: 
> >Input: 7Section Hello Jim 
> >output: 7Section hello Jim 
> > 
> >I was doing if statment with regex 
> > 
> >if re.match("(\d+\w* )(Hello)( \w+)",string)): 
> > print(r"(\d+\w* )(Hello)( \w+)","\1\2.lower()\3",string) 
> > 
> >Output was 
> >7Section \2.lower() Jim 
> >Above one is one of the regex i have in function, i have total 6 regex 
> >patterns and i want to keep all in this if elif else statment. It is 
> >matching, but can someone advise how to replace Hello to hello?
> Please paste the _exact_ code you're using to produce the problem. I do 
> not believe the code above generates the output you show. I imagine 
> there's som kind of regexp replacement call in the real code. 
> 
> There's a few things going on in the code above which will cause 
> trouble: 
> 
> Be consistent using "raw strings", which look like r"...". Normal 
> Python string recognise a variety of backslash escaped things, like \n 
> for a newline character. The purpose of a raw string is to disable that, 
> which is important with regular expressions because they also use 
> backslash escapes such as \d for a digit. Try to _always_ use raw 
> strings when working with regular expressions. 
> 
> Your print() call _looks_ like it should be printing the result of a 
> regexp substitute() function call, based on the "\1\2.lower()\3" in the 
> second field. The substitute() syntax does not support embedding str 
> methods in the result, so the .lower() will just be written out 
> directly. To do more complicated things you need to pull out the matched 
> groups and work with them separately, then assemble your desired result. 
> 
> You do not keep the result of the re.match call here:
> if re.match("(\d+\w* )(Hello)( \w+)",string)):
> Traditionally one would write: 
> 
> m = re.match("(\d+\w* )(Hello)( \w+)",string)) 
> if m: 
> 
> and in recent Python (3.8+) you can write: 
> 
> if m := re.match("(\d+\w* )(Hello)( \w+)",string)): 
> 
> This preserves the result fo the match in the variable "m", which you 
> will require if you want to do any work with the result, such as 
> lowercasing something. 
> 
> The matches components of the regexp are available via the .group() 
> method of the match result. So: 
> 
> m.group(1) == "7Section" 
> m.group(2) == "Hello" 
> 
> and to print "Hello" lowercased you might write: 
> 
> m.group(2).lower() 
> 
> Since this looks much like homework we will leave it to you to apply 
> this approach to your existing code. 
> 
> Cheers, 
> Cameron Simpson 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Regex Group case change

2020-10-01 Thread Cameron Simpson
It is good to see a nice small piece of code which we can run. Thank 
you.

So there are a number of things to comment about in the code below; 
comments inline under the relevant piece of code (we prefer the "inline 
reply" style here, it reads like a conversation):

On 01Oct2020 15:15, Raju  wrote:
>import re
>import os
>import sys
>
>#word = "7 the world" # 7 The world
>#word = "Brian'S" # Brian's
>#word = "O'biran"# O'Brian
>#word = "Stoke-On-Trent" # Stoke-on-Trent; here i need to lower the case of 
>middle word(i.e -On-)

There is an opinion often held that regexp are overused. To lowercase 
the "on" I would reach for str.split, for example:

left, middle, right = word.split('-', 2)
middle = middle.lower()
modified_word = '-'.join([left, middle, right])

I have broken that out for readability, and it is hardwired for a 3 part 
word. See the docs for str.split and str.join:

https://docs.python.org/3/library/stdtypes.html#str.join
https://docs.python.org/3/library/stdtypes.html#str.split

So: no regexps, which I'm sure you now realise can be tricky to get 
correct, and are hard to read.

>def wordpattern(word):
> output = ''
> if re.match("^\d+|w*$",word):
>output = word.upper()
> elif re.match("\w+\'\w{1}$",word):
>output = word.capitalize()
> elif re.match("(\d+\w* )(Hello)( \w+)",word))
>group(1)group(2).title()group(3)
> else:
>output.title()

First off, please try to use raw strings for regular expressions, it 
avoids many potential accidents to do with backslash treatment by Python 
and regexps. So rewritten:

>def wordpattern(word):
> output = ''
> if re.match(r"^\d+|w*$",word):
>output = word.upper()
> elif re.match(r"\w+\'\w{1}$",word):
>output = word.capitalize()
> elif re.match(r"(\d+\w* )(Hello)( \w+)",word))
>group(1)group(2).title()group(3)
> else:
>output.title()

First up, this function does not return a value - it has no return 
statement. You probably want:

return output

at the end. Also, your default output seems to be ''; would it not be 
better to return word unchanged? So I'd start with:

output = word

up the front.

Then there's a bunch of small issues in the main code:

> if re.match(r"^\d+|w*$",word):
>output = word.upper()

You probably want "\w", not "w" (missing backslash). A plain "w" matches 
the letter "w". Also, you probabloy want "\w+", not "\w*" - meaning "at 
least one" instead of "zero or more" aka "at least 0". With the "*" it 
can match zero character (the empty string).

> elif re.match(r"\w+\'\w{1}$",word):

The "\w{1}" can just be written "\w" - the default repetition for a 
subpattern is "exactly once", which is what "{1}" means. So not 
incorrect, just more complicated than required.

>output = word.capitalize()
> elif re.match(r"(\d+\w* )(Hello)( \w+)",word))

Typically people put the whitepsace outside the group, because they 
usually want the word and not the spaces around it. Of course, the cost 
of that s that you would need to put the spaces back in later. So in 
fact this works for your use case.

>group(1)group(2).title()group(3)

You need to join these together, and assign the result to output:

 output = group(1) + group(2).title() + group(3)

> else:
>output.title()

You need to assign the result to output:

 output = output.title()

Cheers,
Cameron Simpson 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem

2020-10-01 Thread boB Stepp

On Thu, Oct 01, 2020 at 01:34:35AM -0400, Dennis Lee Bieber wrote:


I'm pretty certain the Python.org downloads for Windows also put IDLE
on the start menu. I believe these newcomers aren't even looking at the
start menu for things -- if it isn't cluttering up the desktop they
probably don't know it exists. And the only thing they know about is the
file they downloaded.


Maybe this suggests the "incremental improvement" needed:  Have the
installer, by default, add a shortcut icon for IDLE to the user's desktop.
Perhaps this will get noticed.  If it does it would put the new user into a
program where they might actually start doing something useful.  The person who 
does
not want such a desktop shortcut can uncheck that default option.

--
Wishing you only the best,

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