Re: HTML extraction

2021-12-07 Thread Roland Mueller via Python-list
Hello,

ti 7. jouluk. 2021 klo 20.08 Chris Angelico (ros...@gmail.com) kirjoitti:

> On Wed, Dec 8, 2021 at 4:55 AM Julius Hamilton
>  wrote:
> >
> > Hey,
> >
> > Could anyone please comment on the purest way simply to strip HTML tags
> > from the internal text they surround?
> >
> > I know Beautiful Soup is a convenient tool, but I’m interested to know
> what
> > the most minimal way to do it would be.
>
> That's definitely the best and most general way, and would still be my
> first thought most of the time.
>
> > People say you usually don’t use Regex for a second order language like
> > HTML, so I was thinking about using xpath or lxml, which seem like very
> > pure, universal tools for the job.
> >
> > I did find an example for doing this with the re module, though.
> >
> > Would it be fair to say that to just strip the tags, Regex is fine, but
> you
> > need to build a tree-like object if you want the ability to select which
> > nodes to keep and which to discard?
>
> Obligatory reference:
>
>
> https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags
>
> > Can xpath / lxml do that?
> >
> > What are the chief differences between xpath / lxml and Beautiful Soup?
> >
>
> I've never directly used lxml, mainly because bs4 offers all the same
> advantages and more, with about the same costs. However, if you're
> looking for a no-external-deps option, Python *does* include an HTML
> parser in the standard library:
>
>
But isn't bs4 only for SOAP content?
Can bs4 or lxml cope with HTML code that does not comply with XML as the
following fragment?

A
B


BR,
Roland


> https://docs.python.org/3/library/html.parser.html
>
> If your purpose is extremely simple (like "strip tags, search for
> text"), then it should be easy enough to whip up something using that
> module. No external deps, not a lot of code, pretty straight-forward.
> On the other hand, if you're trying to do an "HTML to text"
> conversion, you'd probably need to be aware of which tags are
> block-level and which are inline content, so that (for instance)
> "Hello world" would come out as two separate
> paragraphs of text, whereas the same thing with  tags would become
> just "Hello world". But for the most part, handle_data will probably
> do everything you need.
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Return

2021-12-07 Thread Roland Mueller via Python-list
Hello

ti 7. jouluk. 2021 klo 19.47 vani arul (arulvan...@gmail.com) kirjoitti:

> Hey There,
> Can someone help to understand how a python function can return value with
> using return in the code?
> It is not not about explicit or implicit function call.
>
>
Not sure whether I understood your question: I have a simple example about
return.
  * f() and h() explicitely return something
  * g() and h() return None

BTW, also Python documentation tool pydoc has an article about return.

#!/usr/bin/python

def f():
return 42
def g():
pass
def h():
return

if __name__ == "__main__":
print(f"f(): {f()}")
print(f"g(): {g()}")
print(f"h(): {h()}")

Result:
f(): 42
g(): None
h(): None

Pydoc:
$ pydoc return

BR,
Roland


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


Re: Free OCR package in Python and selecting appropriate widget for the GUI

2021-09-22 Thread Roland Mueller via Python-list
Hello,


ti 21. syysk. 2021 klo 16.53 Mohsen Owzar (mohsen.ow...@gmail.com)
kirjoitti:

> Hi Guys
> Long time ago I've written a program in Malab a GUI for solving Sudoku
> puzzles, which worked not so bad.
> Now I try to write this GUI with Python with PyQt5 or TKinter.
> First question is:
> Is there any free OCR software, packages or code in Python, which I can
> use to recognize the given digits and their positions in the puzzle square.
>

to my knowledge there is no Python package for OCR. Using a free OCR
package that has a command line interface one could integrate this into a
Python script that makes a call to this external OCR e.g. using Python
module subprocess.

BR,
Roland


> Second:
> Because, I can not attach a picture to this post, I try to describe my
> picture of my GUI.
> It is a 3x3 block / matrix (one third of the whole Sudoku 9x9 block).
> This block must be placed three times in row and columns.
> Each square of this 3x3 block has 3x3 digits from 1 to 9 at the
> initialization time. These digits are spread out in 3x3 equal distances.
> These are small fonts and black.
> The values given by the puzzle are red big fonts and not changeable
> The digits typed by the user are black big fonts and changeable
> If there is a big font from the Puzzle / User, these must be removed from
> the neighboring fields from the 3x3 matrix (1-9).
> Now my question is, actually a hint from your side:
> What should I take as widget for one of these small squares to have
> different content as I described above?
> I thought of a QLineEdit in PyQt5 or LineEdit in TKinter, because the user
> must type some values in there and therefore can not be labels. So again,
> for the sake of the clarity.
> •   When the fields are empty, each square has to show digits from 1
> to 9 with small fonts in 3x3 matrix order.
> •   Given values in the puzzle are big fonts and red.
> •   Digits which are typed by the user are big fonts and black.
> Now the question is, can I take only one LineEdit for all these tree
> situations, or I have to implement 9 small squares for small fonts and a
> big one for the big fonts?
> Any help and suggestion is welcome and appreciated.
>
> Best regards
> Mohsen
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Change the display style of the text on the STACKLINE.

2021-09-10 Thread Roland Mueller via Python-list
pe 10. syysk. 2021 klo 17.22 Greg Ewing (greg.ew...@canterbury.ac.nz)
kirjoitti:

> On 10/09/21 6:11 pm, Roland Mueller wrote:
> > When I call  print(s) it even shows ABCD and D is underscored. But
> copying
> > the output to mail looses the underscore ...
>
> If the terminal understands unicode, Combining Low Line: U+0332
> might help
>
>
> The problem was to get the string to this mail. In my terminal it was OK.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Change the display style of the text on the STACKLINE.

2021-09-10 Thread Roland Mueller via Python-list
pe 10. syysk. 2021 klo 8.53 hongy...@gmail.com (hongyi.z...@gmail.com)
kirjoitti:

> On Thursday, September 9, 2021 at 8:57:37 PM UTC+8, Roland Mueller wrote:
> > Hello
> >
> > to 9. syysk. 2021 klo 6.53 hongy...@gmail.com (hongy...@gmail.com)
> > kirjoitti:
> > > I'm using the following code in my forked project [1]:
> > >
> > > percol.view.STACKLINE = 'Fold:F1,F2,F3 Push:C-p Pop:M-p Script:M-s
> Dir:M-d
> > > Dircmd:M-b'
> > >
> > > I would like to change the display style of the text mentioned above,
> for
> > > example, to underline some characters in it, as shown below:
> > >
> > > _D_ir:M-d
> > >
> > >
> > You can use e.g. str.replace() or re.sub()
> >
> > >>> percol.view.STACKLINE = percol.view.STACKLINE.replace('D', '_D_')
> > Result: 'Fold:F1,F2,F3 Push:C-p Pop:M-p Script:M-s _D_ir:M-d
> _D_ircmd:M-b'
> >
> > >>> import re
> >
> > Replace D with _D_
> > >>> percol.view.STACKLINE = re.sub(r'([D])',
> > r'_\1_', percol.view.STACKLINE)
> > Result: 'Fold:F1,F2,F3 Push:C-p Pop:M-p Script:M-s _D_ir:M-d
> _D_ircmd:M-b'
> >
> > Replace D and M with _D_, _M_
> > >>> percol.view.STACKLINE = re.sub(r'([DM])', r'_\1_',
> > percol.view.STACKLINE)
> > 'Fold:F1,F2,F3 Push:C-p Pop:_M_-p Script:_M_-s _D_ir:_M_-d
> _D_ircmd:_M_-b'
> >
> > Regards,
> > Roland
>
> I tried with the following, but failed to achieve the expected effect:
>
> class Term:
> HEADER = '\033[95m'
> OKBLUE = '\033[94m'
> OKGREEN = '\033[92m'
> WARNING = '\033[93m'
> FAIL = '\033[91m'
> ENDC = '\033[0m'
> LIGHTCYAN = '\033[1;36m'
> LIGHTGRAY = '\033[0;37m'
> YELLOW = '\033[0;33m'
> BOLD = '\033[1m'
> UNDERLINE = '\033[4m'
>
> [...]
>
> percol.view.STACKLINE = percol.view.STACKLINE.replace('D', Term.UNDERLINE
> + 'D' + Term.ENDC)
>
> The result will look like this:
>
> Fold:F1,F2,F3 Push:C-p Pop:M-p Script:M-s ?[4mD?[0mir:M-d
> ?[4mD?[0mircmd:M-b
>
> I cannot repeat that. Are you sure that the '?' shown in your output are
not due to your terminal settings that influence how strings printed by
Python or inside used terminal are shown?

Python 3.9.6 (default, Jul 16 2021, 00:00:00)
[GCC 11.1.1 20210531 (Red Hat 11.1.1-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> UL = '\033[4m'
>>> UL
'\x1b[4m'
>>> ENDC =  '\033[0m'
>>> ENDC
'\x1b[0m'

>>> s = UL + 'D' + ENDC
>>> s
'\x1b[4mD\x1b[0m'

>>> s = 'ABCDE'
>>> s = s.replace('D', UL + 'D' + ENDC)
>>> s
'ABC\x1b[4mD\x1b[0mE'

When I call  print(s) it even shows ABCD and D is underscored. But copying
the output to mail looses the underscore ...
[image: image.png]

BR,
Roland






> Regards,
> HY
>
>




> > > How to achieve this purpose?
> > >
> > > [1]
> > >
> https://github.com/hongyi-zhao/ariadne/blob/838179bb4275ac85f5342d9e7d086d6ade3be1de/rc.py#L55
> > >
> > > Regards,
> > > HY
> > > --
> > > https://mail.python.org/mailman/listinfo/python-list
> > >
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Change the display style of the text on the STACKLINE.

2021-09-09 Thread Roland Mueller via Python-list
Hello

to 9. syysk. 2021 klo 6.53 hongy...@gmail.com (hongyi.z...@gmail.com)
kirjoitti:

> I'm using the following code in my forked project [1]:
>
> percol.view.STACKLINE = 'Fold:F1,F2,F3 Push:C-p Pop:M-p Script:M-s Dir:M-d
> Dircmd:M-b'
>
> I would like to change the display style of the text mentioned above, for
> example, to underline some characters in it, as shown below:
>
> _D_ir:M-d
>
>
You can use e.g. str.replace() or re.sub()

>>> percol.view.STACKLINE = percol.view.STACKLINE.replace('D', '_D_')
Result: 'Fold:F1,F2,F3 Push:C-p Pop:M-p Script:M-s _D_ir:M-d _D_ircmd:M-b'

>>> import re

Replace D with _D_
>>> percol.view.STACKLINE = re.sub(r'([D])',
r'_\1_',  percol.view.STACKLINE)
Result: 'Fold:F1,F2,F3 Push:C-p Pop:M-p Script:M-s _D_ir:M-d _D_ircmd:M-b'

Replace D and M with _D_, _M_
>>> percol.view.STACKLINE = re.sub(r'([DM])', r'_\1_',
percol.view.STACKLINE)
'Fold:F1,F2,F3 Push:C-p Pop:_M_-p Script:_M_-s _D_ir:_M_-d _D_ircmd:_M_-b'

Regards,
Roland



> How to achieve this purpose?
>
> [1]
> https://github.com/hongyi-zhao/ariadne/blob/838179bb4275ac85f5342d9e7d086d6ade3be1de/rc.py#L55
>
> Regards,
> HY
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Flask – how to write csv file & save using prefilled value of the filename (response.headers["Content-Disposition"]="attachment; filename=xxx")

2021-08-09 Thread Roland Mueller via Python-list
pe 6. elok. 2021 klo 19.15 MRAB (pyt...@mrabarnett.plus.com) kirjoitti:

> On 2021-08-06 16:50, Suretha Weweje wrote:
> > I am trying to upload a CSV file with flask, read and process one line
> at a
> > time while iterating through all rows of the file and write the results
> > back to a new CSV file.  My python script produces the correct results on
> > its own, but I am not able to get the same results when using Flask. I am
> > new to flask.
> >
> [snip]
>  >
> >  csv_reader = csv.reader(new)
> >
> [snip]
> >
> >  *mywriter = csv.DictWriter('results.csv', fieldnames=headers_new)*
> [snip]
>
> The problem has nothing to do with Flask.
>
> 'csv.reader' and 'csv.DictWriter' expect a file object, but you're
> passing them strings.
> --
> https://mail.python.org/mailman/listinfo/python-list


May be you should use io.StringIO to create a file/stream from an input
string.

from io import StringIO

s = "\n".join(["a","b","c"]) + "\n"

for line in StringIO(s):
print(f"\t{line}")

BR,
Roland
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Where to keep local Python modules?

2021-07-23 Thread Roland Mueller via Python-list
Hello,

pe 23. heinäk. 2021 klo 21.44 Chris Green (c...@isbd.net) kirjoitti:

> This isn't a question about how to set PYTHONPATH so that Python code
> can find imported modules, it's about what is a sensible layout for
> one's home directory - i.e. where to put Python modules.
>
> I'm running Linux and have a number of Python modules that are only
> used by my own code.  My top level Python code is all in ~/bin.  I'd
> prefer to separate the modules so that they don't clutter the name
> space.
>
> Currently I have my Python modules in a subdirectory of ~/bin and my
> Python path is set as:-
>
> PYTHONPATH=/home/chris/bin/pymods
>
> Is this a reasonable approach?  Is there a 'standard' name for the
> directory containing modules, or a standard place for it?  (I don't
> mean a system-wide standard place, I mean a 'my' standard place).
>
> Under recent Linux distros there is $HOME/.local/ containing bin and lib
directories. May be it's ok to use this for user-specific python settings
under Linux.

E.g. in .bashrc
export PYTHONPATH=$HOME/.local/python

Result can be checked then in Python:
python
>>> import sys
>>> sys.path
['', '/home/someuser/.local/lib/python', '/usr/lib64/python39.zip',
'/usr/lib64/python3.9', '/usr/lib64/python3.9/lib-dynload',
'/usr/local/lib/python3.9/site-packages',
'/usr/lib64/python3.9/site-packages', '/usr/lib/python3.9/site-packages']

BR,
Roland




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


Re: pyttsx3 installation error

2021-07-02 Thread Roland Mueller via Python-list
What's about installing?
https://pypi.org/project/pyttsx3/

pe 2. heinäk. 2021 klo 23.41 Nikita Lohale (nikitalohal...@gmail.com)
kirjoitti:

> Traceback (most recent call last):
>   File "f:\Nikita\Python programming\Iron Man Jarvis AL\jarvis.py", line
> 1, in 
> import pyttsx3
> ModuleNotFoundError: No module named 'pyttsx3'
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: is not recognized as an internal or external command, operable program or batch file.

2021-03-02 Thread Roland Mueller via Python-list
Hello,
this is windows setup issue related to the fact that python binary is not
in execution path.

For setting up you may find instructions by searching for "windows 10 put
python to path". One result is following page:
https://superuser.com/questions/143119/how-do-i-add-python-to-the-windows-path





ma 1. maalisk. 2021 klo 20.54 singh.veer9--- via Python-list (
python-list@python.org) kirjoitti:

>Dear Sir/Madam
>
>Sir I am facing the issue from 10 days. And I tried all the ways to
> remove
>this or to come out of this problem
>but as i try to install some PYTEST or OPENPYXL packages using pip it
>gives the notification that there is no writeable path present due to
> that
>I am not “is not recognized as an internal or external command, operable
>program or batch file.”  I am facing problem in running the test cases
> in
>Pycharm for the PYTEST
>please help me pls
>
>
>
>
>
>Sent from [1]Mail for Windows 10
>
>
>
> References
>
>Visible links
>1. https://go.microsoft.com/fwlink/?LinkId=550986
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Troubles with Python imports

2021-02-10 Thread Roland Mueller via Python-list
ke 10. helmik. 2021 klo 5.07 Terry Reedy (tjre...@udel.edu) kirjoitti:

> On 2/9/2021 9:55 AM, Philipp Daher via Python-list wrote:
> > Hello,
> >
> > I’ve just typed „pip install selenium“ into my command prompt on windows
> 10. Although my computer told me that the requirement was already
> satisfied, import selenium did not work. So I tried different methods to
> install it and typed „Python“ in my command prompt and imported selenium.
> It worked fine. Then, I typed it into my shell and got an error. Why is it
> working in the command prompt but not in the actual shell?
>
> One common problem (and answer -- monthy on stackoverflow) is that you
> have more than one python binary installed; do not have module xyz
> installed for all of them; and are running different binaries to get the
> different responses.
>
>
> May be the first thing is to check whether one is using the right pip.
Example output is from Linux box, but in Windows the output should also
show the relevant information:
$ pip -V
pip 19.3.1 from /usr/lib/python3.8/site-packages/pip (python 3.8)
$ python -V
Python 3.8.7


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


Re: Python 3.9. 1 not working

2021-02-10 Thread Roland Mueller via Python-list
Hello,

Please note that this is not a kind of support service rather than a
community where people help each other on voluntary base.

In order to get help from here, you should provide enough information about
your issue with Python 3.9 that others can figure out what happened.

BR,
Roland

ke 10. helmik. 2021 klo 5.10 Martin Lopez (mmllopezmar...@gmail.com)
kirjoitti:

> Where do I inquire about installation support?
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ONE CLICK REST API

2016-04-05 Thread Roland Mueller via Python-list
You may have a look at Django-based REST framework

   - http://www.django-rest-framework.org/

or Flask-RESTful

   - https://pypi.python.org/pypi/Flask-RESTful
   - http://flask-restful-cn.readthedocs.org/en/0.3.4/

Last not least here is some article about implementing a REST API using
Flask for yourself:

   -
   
http://blog.miguelgrinberg.com/post/designing-a-restful-api-with-python-and-flask


BR,
Roland

2016-04-04 9:09 GMT+03:00 David Shi via Python-list 
:

> Eclipse has got one click app for creating REST services.
> What is it equivalent in Python?
> Regards.
> David
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list