Re: Unable to pass dict from json.
On 2020-12-13, Bischoop wrote: > Here https://bpa.st/YBVA Don't do that. Include in your post a short example that illustrates your questions. > I've working code with dictionary only if used dict from the code > [...] -- https://mail.python.org/mailman/listinfo/python-list
Fwd: Fwd: How to specify JSON parameters in CallBack?
From: Caleb Gattegno
Date: Fri, Dec 11, 2020 at 5:02 PM
Subject: How to specify JSON parameters in CallBack?
Please can you suggest where should I look for advice on converting a old style web app which vends whole pages of html
with a cgi-bin/python script invoked bypython3 server.py, into one that only serves callbacks to this Javascript AJAX
async RPC call:
$('#compute').click(function() {
$('#poly').val('Waiting...');
var seq = $('#seq').val();
console.log(seq);
$.post('/compute', seq, function(result) {
$('#poly').val(result.poly);
}, 'json');
});
I don’t want to touch the html/javascript, but I’d like to update the python cgi code module to respond to the RPC call
in the post by returning a json data structure. Poly is a string of variable length.
Many thanks
gattegnPython
--
https://mail.python.org/mailman/listinfo/python-list
Re: Fwd: How to specify JSON parameters in CallBack?
On Mon, Dec 14, 2020 at 4:57 AM Ethan Furman wrote:
>
> From: Caleb Gattegno
> Date: Fri, Dec 11, 2020 at 5:02 PM
> Subject: How to specify JSON parameters in CallBack?
>
>
> Please can you suggest where should I look for advice on converting a old
> style web app which vends whole pages of html
> with a cgi-bin/python script invoked bypython3 server.py, into one that only
> serves callbacks to this Javascript AJAX
> async RPC call:
>
> $('#compute').click(function() {
> $('#poly').val('Waiting...');
>
> var seq = $('#seq').val();
> console.log(seq);
> $.post('/compute', seq, function(result) {
> $('#poly').val(result.poly);
> }, 'json');
> });
>
> I don’t want to touch the html/javascript, but I’d like to update the python
> cgi code module to respond to the RPC call
> in the post by returning a json data structure. Poly is a string of variable
> length.
>
First place to look would be a well-known server framework. I use
Flask, but there are others. Figure out exactly what your front end is
sending; use your web browser's developer tools to inspect the
requests, and then code your back end to match.
Writing a JSON-based API in Flask is pretty straight-forward. Here's an example:
@app.route("/api/widgets")
def list_setups():
return jsonify(database.list_widgets())
@app.route("/api/widgets/")
def get_widget(id):
return jsonify(database.get_widget(id))
@app.route("/api/widgets", methods=["POST"])
def create_widget():
if not request.json: return jsonify({}), 400
missing = {"name", "purpose"} - set(request.json)
if missing:
return jsonify({"error": "Missing: " + ", ".join(sorted(missing))}), 400
widget = database.create_widget(request.json["name"],
request.json["purpose"])
return jsonify(widget)
(For a real example, see
https://github.com/Rosuav/MustardMine/blob/master/mustard.py#L643 -
although that has a lot of other complexities.)
ChrisA
--
https://mail.python.org/mailman/listinfo/python-list
Re: pip 20.3 release (heads-up for potential disruption)
On 11/30/20 8:33 AM, Sumana Harihareswara wrote: On behalf of the Python Packaging Authority, I am pleased to announce that we have just released pip 20.3, a new version of pip. You can install it by running `python -m pip install --upgrade pip`. This is an important and disruptive release -- we explained why in a blog post last year https://pyfound.blogspot.com/2019/12/moss-czi-support-pip.html . We even made a video about it: https://www.youtube.com/watch?v=B4GQCBBsuNU . Blog post with details: https://pyfound.blogspot.com/2020/11/pip-20-3-new-resolver.html Highlights include: * **DISRUPTION**: Switch to the new dependency resolver by default. Watch out for changes in handling editable installs, constraints files, and more: https://pip.pypa.io/en/latest/user_guide/#changes-to-the-pip-dependency-resolver-in-20-3-2020 * **DEPRECATION**: Deprecate support for Python 3.5 (to be removed in pip 21.0) * **DEPRECATION**: pip freeze will stop filtering the pip, setuptools, distribute and wheel packages from pip freeze output in a future version. To keep the previous behavior, users should use the new `--exclude` option. * Support for PEP 600: Future ‘manylinux’ Platform Tags for Portable Linux Built Distributions. * Add support for MacOS Big Sur compatibility tags. The new resolver is now *on by default*. It is significantly stricter and more consistent when it receives incompatible instructions, and reduces support for certain kinds of constraints files, so some workarounds and workflows may break. Please see our guide on how to test and migrate, and how to report issues: https://pip.pypa.io/en/latest/user_guide/#changes-to-the-pip-dependency-resolver-in-20-3-2020 . You can use the deprecated (old) resolver, using the flag `--use-deprecated=legacy-resolver`, until we remove it in the pip 21.0 release in January 2021. In pip 21.0 we will also remove support for Python 2.7. You can find more details (including deprecations and removals) in the changelog https://pip.pypa.io/en/stable/news/ , and you can find thank-yous and instructions on reporting issues at https://pyfound.blogspot.com/2020/11/pip-20-3-new-resolver.html . Thank you, Sumana Harihareswara pip project manager Changeset Consulting https://changeset.nyc Incidentally, I should have mentioned in my previous email: pip 20.3 turned the new resolver on by default for Python 3 users. When users use pip 20.3 in a Python 2 environment, the old dependency resolver is still the default. Python 2 users should also note that pip 21.0 in January will remove Python 2 support: https://pip.pypa.io/en/latest/development/release-process/#python-2-support . -- Sumana Harihareswara -- https://mail.python.org/mailman/listinfo/python-list
Re: Returning from a multiple stacked call at once
In article <[email protected]>, ast wrote: >Le 12/12/2020 à 17:10, Oscar a écrit : >> In article <[email protected]>, ast wrote: >>> Hello >>> >>> In case a function recursively calls itself many times, >>> is there a way to return a data immediately without >>> unstacking all functions ? >> >> If you are referring to your "are you ok?" problem, please read up on >> recursion and when and how to use it. You were doing it completely >> wrong. You only call a function from *whitin itself* if you need >> recursion. It's quite hard to explain in a few words, so just google it. >> I'm sure there are many great explanations around. >> > >not understood. I understand! Sorry... Somehow I mixed you up with another poster that was clearly beginning with programming and wrote an input function that called itself recursively when it received invalid input. Then he was suprised the calling function got the very first (invalid) value. You clearly know your way around recursion. Sorry again! ;-) -- [J|O|R] <- .signature.gz -- https://mail.python.org/mailman/listinfo/python-list
