Re: Extract all words between two keywords in .txt file (Python)

2019-12-12 Thread Ben Bacarisse
A S  writes:

> On Thursday, 12 December 2019 02:28:09 UTC+8, Ben Bacarisse  wrote:
>> A S  writes:
>> 
>> > I would like to extract all words within specific keywords in a .txt
>> > file. For the keywords, there is a starting keyword of "PROC SQL;" (I
>> > need this to be case insensitive) and the ending keyword could be
>> > either "RUN;", "quit;" or "QUIT;". This is my sample .txt file.
>> >
>> > Thus far, this is my code:
>> >
>> > with open('lan sample text file1.txt') as file:
>> > text = file.read()
>> > regex = re.compile(r'(PROC SQL;|proc sql;(.*?)RUN;|quit;|QUIT;)')
>> > k = regex.findall(text)
>> > print(k)
>> 
>> Try
>> 
>>   re.compile(r'(?si)(PROC SQL;.*(?:QUIT|RUN);)')
 
>
> Hey Ben, this works for my sample .txt file! Thanks:) but it wont
> work, if I have other multiple text files to parse through that, are
> similar but have some variations, strangely enough.

No one can help without details.  Maybe need the non-greedy .*? rather
than the .* I put in there.  That was not a deliberate change.

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


Re: Python3 - How do I import a class from another file

2019-12-12 Thread Rhodri James

On 11/12/2019 21:32, mus...@posteo.org wrote:

On Tue, 10 Dec 2019 14:56:10 -0500
Dennis Lee Bieber  wrote:


It is called when the language IMPLEMENTATION decides to call
it. That time is not specified in the language description/reference
manual.

Yes it is:

"Note: del x doesn’t directly call x.__del__() — the former decrements
the reference count for x by one, and the latter is only called when
x’s reference count reaches zero."

Plain and simple: When the refcount reaches zero.
You are assuming that "when" implies "immediately on the occurence."  It 
doesn't.  This happens to be the behaviour in CPython, but other 
implementations vary as Chris has explained several times now.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python3 - How do I import a class from another file

2019-12-12 Thread Musbur

Hi Chris,


The most important distinction, which that note is emphasizing, is
that the "del" statement removes just one reference, and if there are
other references, then __del__ will not be called.


No argument there, that's how reference counting works, and it's clear 
from the docs. What is not clear from the documentation is not if or why 
or how but *when* the __del__ method is eventually called. The doc says: 
"when [an object's] reference count reaches zero." Initially I read that 
to mean "immediately upon the reference count hitting zero," but a 
couple paragraphs down we find this: "In particular:  __del__() can be 
invoked when arbitrary code is being executed, including from any 
arbitrary thread. [...]"


I used to believe that the __del__ method was called immediately after 
refcount = zero, and that only the memory management system's functions 
(typically called from __del__) could take their time doing their 
things. Not true, it seems: Calling __del__() can be deferred, and 
PyMem_Free() et. al. migh not immediately "do"  anything as well.


I've come to see the __del__ method as a tool to get rid of an object 
(and its resources) which can be used by the Python interpreter at its 
own discretion when and if it feels the need to do so, which may be 
anything between immediately after ob_refcnt == 0 and not at all. That 
said, I can't think of any reason to explicitly define __del__() in a 
pure Python class. Do you have an example?

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


mysqlclient==1.4.6 none wheel doesn't work on ubuntu 18

2019-12-12 Thread Mitesh Patel
I’m using pantsbuild to create a pex with SQLAlchemy==1.3.11 and 
mysqlclient==1.4.6. I’m going to run the pex on ubuntu 14 trusty and ubuntu 18 
bionic.

To first build the wheel, I went to each ubuntu machine and ran this:

pip wheel —no-cache-dir —wheel-dir=./ mysqlclient==1.4.6

On the trusty machine, it created 
https://s3.amazonaws.com/aiq-public/ubuntu14/index.html. However on the bionic 
machine it created https://s3.amazonaws.com/aiq-public/ubuntu18/index.html.

I was very confused, but I just kept the “none” wheel since that should be OS 
independent. I built the pex locally on each box, and it worked fine on trusty, 
however on bionic I saw this error:

  File 
"/home/ubuntu/.pex/install/SQLAlchemy-1.0.11-cp27-none-linux_x86_64.whl.2ad4de6e38cfa6e6073ca829b9a827ab4c9a46d8/SQLAlchemy-1.0.11-cp27-none-linux_x86_64.whl/sqlalchemy/engine/strategies.py",
 line 75, in create
dbapi = dialect_cls.dbapi(**dbapi_args)
  File 
"/home/ubuntu/.pex/install/SQLAlchemy-1.0.11-cp27-none-linux_x86_64.whl.2ad4de6e38cfa6e6073ca829b9a827ab4c9a46d8/SQLAlchemy-1.0.11-cp27-none-linux_x86_64.whl/sqlalchemy/dialects/mysql/mysqldb.py",
 line 92, in dbapi

return __import__('MySQLdb')
  File 
"/home/ubuntu/.pex/install//mysqlclient-1.4.6-cp27-none-linux_x86_64.whl/MySQLdb/__init__.py",
 line 19, in 

import _mysql
ImportError: libmysqlclient.so.18: cannot open shared object file: No such file 
or directory

That seemed very strange to me, so then I changed the bionic build to point to 
the os-specific wheel, and then it started working.

Is there some reason the “none” wheel does not work on bionic? Somehow it 
seemed to be picking up the wrong libmysqlclient library? Note I have 
“libmysqlclient.so” installed on both trusty (mysql 5.6) and bionic (mysql 
5.7). They are different versions, but I didn’t think it mattered, if using a 
“none” wheel then it should build on the box using whatever libraries the OS 
has, right?

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


Transfer a file to httpserver via POST command from curl

2019-12-12 Thread Karthik Sharma
I have written a python server app (actually copied from somewhere) using
Flask, that I want to act as a http server. I expect this server to recieve
a POST command (of a file) from CURL and save that file on the server. And
I should be able to download that file when required.

My python scripts are shown below.

app.py



from flask import Flask

UPLOAD_FOLDER = 'home/user/uploads'

app = Flask(__name__)
#app.secret_key = "secret key"
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024


main.py


import os
import urllib.request
from app import app
from flask import Flask, request, redirect, jsonify
from werkzeug.utils import secure_filename


ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])


def allowed_file(filename):
 return '.' in filename and filename.rsplit('.', 1)[1].lower() in
 ALLOWED_EXTENSIONS


@app.route('/file-upload', methods=['POST'])
def upload_file():
 # check if the post request has the file part
 if 'file' not in request.files:
 resp = jsonify({'message' : 'No file part in the request'})
 resp.status_code = 400
 return resp
 file = request.files['file']
 if file.filename == '':
 resp = jsonify({'message' : 'No file selected for uploading'})
 resp.status_code = 400
 return resp
 if file and allowed_file(file.filename):
 filename = secure_filename(file.filename)
 file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
 resp = jsonify({'message' : 'File successfully uploaded'})
 resp.status_code = 201
 return resp
 else:
 resp = jsonify({'message' : 'Allowed file types are txt, pdf, png, jpg,
jpeg, gif'})
 resp.status_code = 400
 return resp


if __name__ == "__main__":
app.run()

I am doing a POST using curl as follows.

curl -X POST --data-binary @/home/user/testfile.txt http://
127.0.0.1:5000/file-upload

Is it really possible to transfer a large binary file from my machine to
the above httpserver via POST command and download it again? If yes, is the
above Flask app enough for that and what am I doing wrong?

Kindly Reply,
Regards,
Karthik.


I am getting 400 Bad Request error from the server. I am new to Flask.
What am I doing wrong. Is it possible to transfer a binary file
(large) from my computer to the above http server via POST command.?
For that purpose is my above code enought? What am I doing wrong?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Transfer a file to httpserver via POST command from curl

2019-12-12 Thread Chris Angelico
On Fri, Dec 13, 2019 at 3:44 AM Karthik Sharma  wrote:
> I am doing a POST using curl as follows.
>
> curl -X POST --data-binary @/home/user/testfile.txt http://
> 127.0.0.1:5000/file-upload
>
> Is it really possible to transfer a large binary file from my machine to
> the above httpserver via POST command and download it again? If yes, is the
> above Flask app enough for that and what am I doing wrong?

I think your Flask code is okay (haven't checked in detail, but at
first glance it looks fine), but for file uploads to be recognized in
request.files, you'll need to change the way you run curl.

Try this:

curl -F 'file=@/home/user/testfile.txt' http://127.0.0.1:5000/file-upload

The word "file" in there ends up as the key in request.files (so if
you used "spam=", you'd get request.files["spam"]), and you can add
other form data as well if you choose.

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


Troubleshooting

2019-12-12 Thread catherine morris
Good evening,

My son is trying to download python 3.8.0 on my PC, which has Windows 10,
and it won't install properly. I'm not tech savvy and have no idea where to
start.

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


Re: Troubleshooting

2019-12-12 Thread Michael Torrie
On 12/12/19 5:40 PM, catherine morris wrote:
> Good evening,
> 
> My son is trying to download python 3.8.0 on my PC, which has Windows 10,
> and it won't install properly. I'm not tech savvy and have no idea where to
> start.
> 
> Catherine Morris

I just learned today that Python is officially available in the
Microsoft Store app in Windows 10.  If you run the Windows Store and
search for Python, you should find Python 3.8.0 and it will be listed as
free.  Click install (if it asks you to log in, click no thanks).  After
it downloads and installs you should find "Idle" in the start menu,
which is probably where your son will want to start.  Idle is a code
editor and and an environment in which to run the python programs.  See
this url for an introduction to Idle.  https://realpython.com/python-idle/

Hope this helps!

Michael

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


Re: Troubleshooting

2019-12-12 Thread Python

catherine morris wrote:

Good evening,

My son is trying to download python 3.8.0 on my PC, which has Windows 10,
and it won't install properly. I'm not tech savvy and have no idea where to
start.


What happened exactly? Did you download the official installer from
python.org, then click on next, next, next, checking the box (if it's
still there about updating PATH)? There is nothing more to do.


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


Re: Troubleshooting

2019-12-12 Thread Michael Torrie
On 12/12/19 6:33 PM, Python wrote:
> catherine morris wrote:
>> Good evening,
>>
>> My son is trying to download python 3.8.0 on my PC, which has Windows 10,
>> and it won't install properly. I'm not tech savvy and have no idea where to
>> start.
> 
> What happened exactly? Did you download the official installer from
> python.org, then click on next, next, next, checking the box (if it's
> still there about updating PATH)? There is nothing more to do.

I communicated more with the original poster off list and will try to
relate what is happening here.  This type of thing I've never
encountered before and is hard to describe in just plain text,
especially for a non-technical person.  Essentially trying to launch the
official, downloaded installer from Python.org causes a message to pop
up warning about installing third-party applications and opens the
Microsoft Store and apparently points at the Python installation there.
Unfortunately installing through the store fails for some reason.

I've seen github bug reports about Windows launching the store when
trying to run Python, but those appear to be after a successful
installation, and the solution there is making sure the installed
version of Python is set in the $PATH.  It's possible this is the issue
here.  If so she'll have to get someone locally to take a look at her
machine. Not sure about talking her through debugging the PATH.

Another possibility is that she's running a laptop with Windows 10S,
which limits what can be installed. That would explain why the Windows
Store installation fails.  But I don't know.

Just when I think Windows 10 is a pretty decent system, I encounter
something inexplicable like this.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Troubleshooting

2019-12-12 Thread Python

Le 13/12/2019 à 03:53, Michael Torrie a écrit :

On 12/12/19 6:33 PM, Python wrote:

catherine morris wrote:

Good evening,

My son is trying to download python 3.8.0 on my PC, which has Windows 10,
and it won't install properly. I'm not tech savvy and have no idea where to
start.


What happened exactly? Did you download the official installer from
python.org, then click on next, next, next, checking the box (if it's
still there about updating PATH)? There is nothing more to do.


I communicated more with the original poster off list and will try to
relate what is happening here.  This type of thing I've never
encountered before and is hard to describe in just plain text,
especially for a non-technical person.  Essentially trying to launch the
official, downloaded installer from Python.org causes a message to pop
up warning about installing third-party applications and opens the
Microsoft Store and apparently points at the Python installation there.
Unfortunately installing through the store fails for some reason.

I've seen github bug reports about Windows launching the store when
trying to run Python, but those appear to be after a successful
installation, and the solution there is making sure the installed
version of Python is set in the $PATH.  It's possible this is the issue
here.  If so she'll have to get someone locally to take a look at her
machine. Not sure about talking her through debugging the PATH.

Another possibility is that she's running a laptop with Windows 10S,
which limits what can be installed. That would explain why the Windows
Store installation fails.  But I don't know.


Oh dear...


Just when I think Windows 10 is a pretty decent system, I encounter
something inexplicable like this.


We've gone through that before, haven't we?



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


Re: Troubleshooting

2019-12-12 Thread Michael Torrie
On 12/12/19 8:03 PM, Python wrote:
>> Just when I think Windows 10 is a pretty decent system, I encounter
>> something inexplicable like this.
> 
> We've gone through that before, haven't we?

Yup, Several times.  The good news is her son finally got it installed
by launching the installer from explorer.  So must have been some stupid
MS Edge thing interfering with running the installer. Trying to be
intelligent I'm sure.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: datetime gotcha

2019-12-12 Thread Frank Millman

On 2019-12-11 10:51 PM, Skip Montanaro wrote:

Why is a dtm instance also an instance of dt?


The datetime type is, in fact, a subclass of the date type:


import datetime
datetime.date.__bases__

(,)

datetime.datetime.__bases__

(,)

datetime.time.__bases__

(,)

Skip



Thanks for that.

I found a workaround.

>>> from datetime import date as dt, datetime as dtm
>>> type(dtm.now()) is dtm
True
>>> type(dtm.now()) is dt
False
>>>

I will run with this.

Frank


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


Re: mysqlclient==1.4.6 none wheel doesn't work on ubuntu 18

2019-12-12 Thread Inada Naoki
Hi, mysqlclient maintainer is here.

On Fri, Dec 13, 2019 at 1:44 AM Mitesh Patel  wrote:
>
> I was very confused, but I just kept the “none” wheel since that should be OS 
> independent.

Why do you think it is OS independent?
libmysqlclient.so doesn't keep ABI compatibility.
You need to rebuild mysqlclient when the binary of the
libmysqlclient.so is different.

That's why I don't provide binary wheels for macOS and Linux.
Some people install MySQL from apt, brew, or mysql.com.
Some people use MariaDB instead of MySQL.
mysqlclient should be built on each own environment.

Regards,

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


Re: Zipapp can't find sqlite db

2019-12-12 Thread Abdur-Rahmaan Janhangeer
Packaging in this case means converting a folder into a zipapp archive.

Yours,

Abdur-Rahmaan Janhangeer
pythonmembers.club  | github

Mauritius

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


Re: Zipapp can't find sqlite db

2019-12-12 Thread Abdur-Rahmaan Janhangeer
Do you have a data files tuto link?

Yours,

Abdur-Rahmaan Janhangeer
pythonmembers.club  | github

Mauritius

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


Re: Troubleshooting

2019-12-12 Thread Karsten Hilbert
On Thu, Dec 12, 2019 at 06:40:32PM -0600, catherine morris wrote:

> Good evening,
>
> My son is trying to download python 3.8.0 on my PC, which has Windows 10,
> and it won't install properly. I'm not tech savvy and have no idea where to
> start.

No offense, but, how old is your son ?

Karsten
--
GPG  40BE 5B0E C98E 1713 AFA6  5BC0 3BEA AC80 7D4F C89B
-- 
https://mail.python.org/mailman/listinfo/python-list