Re: dict.get_deep()
Hello, Yes, I misunderstood as well because started to think about pattern matching which is good but this is not subject the question was about. Sorry for my mistake. Because question was about 'builtin' function which means stdlib function implemented in python itself or even in C. It seems, maybe I miss again, but we are talking about similar ideas behind 'xpath' or 'jsonpath' or even 'LINQ'. We want to find some 'dsl' which give us simple and safe way to get deeply nested values from dict. There are several similar solutions on pypi (https://pypi.org/project/dpath/, https://pypi.org/project/path-dict/). But maybe (and maybe I miss again) we talk about language embedded solution like operator ? or ??. For example deep dict extraction could look like: street = data["users"]?[0]?["address"]?["street"]?. // BR 04.04.2022 2:24, Avi Gross via Python-list пишет: I may have misunderstood something. The original post in this subject sounded to ME likethey had nested dictionaries and wanted to be ableto ask a method in the first dictionary totake an unspecified number of arguments thatwould be successive keys and return the results. I mean if A was a dictionary containing saycities and it had an alphabetical index of lettersA to Z and those contained dictionaries ofsay last names as additional dictionaries andso on, then they wanted to perhaps say; A.getdeep("Boston", "S", "Smith", "Address", default="None") But the replies I am seeing look so different that I mayhave missed something as it seems more about usingpattern matching on the data used to make the dictionariesor something. So I was happy to see Marco suggesting a function alongthe lines of my thought process. But I have another thought.A stand-alone function along his lines might be fine. Buta method built into a general Dictionary class is anotherthing as it asks a method in one dictionary to march aroundinto other dictionaries. So I wonder if a better methodis sort of recursive. If you had a class like dictionary that had a getdeep function,and it got called with N arguments, and perhaps a namedargument supplying a default, then would it make sensefor the function checking to see if the FIRST argument canbe found as a key to the current dictionary. If arguments remain then it should expect to finda result that is a dictionary (or perhaps some otherobject that supports the getdeep() protocol and ask thatobject to operate on the N-1 remaining arguments, passingthe default along too. If the request is valid, after some iterations an object willhave a method invoked with a single argument (plus default)and a value passed back up the chain. For any errors alongthe way, the default would be returned. Is this closer to the spirit of the request? I view this versionof nested dictionaries as a sort of tree structure with variablebranches along the way. So an approach like this could makesense and perhaps Python could be updated eventually to havesome objects support such a protocol. Of course you could sort of do it yourself by subclassing somethingand making changes but that may not work for what is already asort of built-in data structure but could work for one of many variantsalready implemented in modules. -Original Message- From: Marco Sulla To: Peter J. Holzer Cc: python-list@python.org Sent: Sun, Apr 3, 2022 5:17 pm Subject: Re: dict.get_deep() On Sun, 3 Apr 2022 at 21:46, Peter J. Holzer wrote: data.get_deep("users", 0, "address", "street", default="second star") Yep. Did that, too. Plus pass the final result through a function before returning it. I didn't understand. Have you added a func parameter? I'm not sure whether I considered this when I wrote it, but a function has the advantage of working with every class which can be indexed. A method must be implemented on any class (so at least dict and list to be useful). You're right, but where to put it? I don't know if an iterableutil package exists. If included in the stdlib, I don't know where to put it. In collections maybe? PS: if you're interested, here is my implementation: def get_deep(self, *args, default=_sentinel): r""" Get a nested element of the dictionary. The method accepts multiple arguments or a single one. If a single argument is passed, it must be an iterable. This represents the keys or indexes of the nested element. The method first tries to get the value v1 of the dict using the first key. If it finds v1 and there's no other key, v1 is returned. Otherwise, the method tries to retrieve the value from v1 associated with the second key/index, and so on. If in any point, for any reason, the value can't be retrieved, the `default` parameter is returned if specified. Otherwise, a KeyError or an IndexError is raised. """ if len(args) == 1: single = True it_tpm = args[0] try: len(it_tpm)
Re: googletrans in python
On 4/12/21 15:24, Karsten Hilbert wrote: Am Mon, Apr 12, 2021 at 12:48:23PM -0400 schrieb Quentin Bock: Can someone explain the basics of googletrans in python? I want to make a program that translates stories into English, but I'm not sure how to get a translation printed. Also, is this needed to be done in an HTML file inside python? If so can someone provide basic code for a translation and how that should be written and work? You might want to post the entire homework assignment verbatim. That way people might better understand which part of it to help you with in what way. As to your description of what you want to achieve -- what did you already try ? Karsten -- GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B A quick google run turns up a lot of stuff with various interfaces, Pypi being one of the more consistent. However, if the more technical theorist or stoic documentation sites don't help you, this one seems to at least take a more 'tutorial' approach - https://medium.com/mlearning-ai/translate-famous-quotes-one-language-to-another-for-fun-using-googletrans-644956e3313a Do post an update to how you are getting on. Many more people will be responsive to the work once you dig in... Jack -- https://mail.python.org/mailman/listinfo/python-list
Re: dict.get_deep()
Kirill, There are many related needs and issues and solutions such as how to parse XML content and do all kinds of tree searches for "patterns" that multiple modules have been created to deal with. My impression here was of a simpler request to allow a list of keys to be applied in sequence. The example wanted the list to be successive arguments in a call to a method, but obvious variants would be for a single argument containing atuple or list or any interator that would probe a tree of possibilities while anchored to the top. This is a much easier task with many solutions offered. -Original Message- From: Kirill Ratkin via Python-list To: python-list@python.org Sent: Mon, Apr 4, 2022 3:40 am Subject: Re: dict.get_deep() Hello, Yes, I misunderstood as well because started to think about pattern matching which is good but this is not subject the question was about. Sorry for my mistake. Because question was about 'builtin' function which means stdlib function implemented in python itself or even in C. It seems, maybe I miss again, but we are talking about similar ideas behind 'xpath' or 'jsonpath' or even 'LINQ'. We want to find some 'dsl' which give us simple and safe way to get deeply nested values from dict. There are several similar solutions on pypi (https://pypi.org/project/dpath/, https://pypi.org/project/path-dict/). But maybe (and maybe I miss again) we talk about language embedded solution like operator ? or ??. For example deep dict extraction could look like: street = data["users"]?[0]?["address"]?["street"]?. // BR 04.04.2022 2:24, Avi Gross via Python-list пишет: > I may have misunderstood something. > The original post in this subject sounded to ME likethey had nested > dictionaries and wanted to be ableto ask a method in the first dictionary > totake an unspecified number of arguments thatwould be successive keys and > return the results. > I mean if A was a dictionary containing saycities and it had an alphabetical > index of lettersA to Z and those contained dictionaries ofsay last names as > additional dictionaries andso on, then they wanted to perhaps say; > A.getdeep("Boston", "S", "Smith", "Address", default="None") > But the replies I am seeing look so different that I mayhave missed something > as it seems more about usingpattern matching on the data used to make the > dictionariesor something. > So I was happy to see Marco suggesting a function alongthe lines of my > thought process. But I have another thought.A stand-alone function along his > lines might be fine. Buta method built into a general Dictionary class is > anotherthing as it asks a method in one dictionary to march aroundinto other > dictionaries. So I wonder if a better methodis sort of recursive. > If you had a class like dictionary that had a getdeep function,and it got > called with N arguments, and perhaps a namedargument supplying a default, > then would it make sensefor the function checking to see if the FIRST > argument canbe found as a key to the current dictionary. > If arguments remain then it should expect to finda result that is a > dictionary (or perhaps some otherobject that supports the getdeep() protocol > and ask thatobject to operate on the N-1 remaining arguments, passingthe > default along too. > If the request is valid, after some iterations an object willhave a method > invoked with a single argument (plus default)and a value passed back up the > chain. For any errors alongthe way, the default would be returned. > Is this closer to the spirit of the request? I view this versionof nested > dictionaries as a sort of tree structure with variablebranches along the way. > So an approach like this could makesense and perhaps Python could be updated > eventually to havesome objects support such a protocol. > Of course you could sort of do it yourself by subclassing somethingand making > changes but that may not work for what is already asort of built-in data > structure but could work for one of many variantsalready implemented in > modules. > > > > -Original Message- > From: Marco Sulla > To: Peter J. Holzer > Cc: python-list@python.org > Sent: Sun, Apr 3, 2022 5:17 pm > Subject: Re: dict.get_deep() > > On Sun, 3 Apr 2022 at 21:46, Peter J. Holzer wrote: data.get_deep("users", 0, "address", "street", default="second star") >> Yep. Did that, too. Plus pass the final result through a function before >> returning it. > I didn't understand. Have you added a func parameter? > >> I'm not sure whether I considered this when I wrote it, but a function >> has the advantage of working with every class which can be indexed. A >> method must be implemented on any class (so at least dict and list to be >> useful). > You're right, but where to put it? I don't know if an iterableutil package > exists. If included in the stdlib, I don't know where to put it. In > collections maybe? > > PS: if you're interested, here is my implementatio
ANN: eGenix Antispam Bot for Telegram 0.2.0
ANNOUNCING eGenix Antispam Bot for Telegram Version 0.2.0 A simple, yet effective bot implementation to address Telegram signup spam. This announcement is also available on our web-site for online reading: https://www.egenix.com/company/news/eGenix-Antispam-Bot-for-Telegram-0.2.0-GA.html INTRODUCTION eGenix has long been running a local user group meeting in Düsseldorf called Python Meeting Düsseldorf and we are using a Telegram group for most of our communication. In the early days, the group worked well and we only had few spammers joining it, which we could well handle manually. More recently, this has changed dramatically. We are seeing between 2-5 spam signups per day, often at night. Furthermore, the signups accounts are not always easy to spot as spammers, since they often come with profile images, descriptions, etc. With the bot, we now have a more flexible way of dealing with the problem. Please see our project page for details and download links: https://www.egenix.com/library/telegram-antispam-bot/ FEATURES * Low impact mode of operation: the bot tries to keep noise in the group to a minimum * Several challenge mechanisms to choose from, more can be added as needed * Flexible and easy to use configuration * Only needs a few MB of RAM, so can easily be put into a container or run on a Raspberry Pi * Can handle quite a bit of load due to the async implementation * Works with Python 3.9+ * MIT open source licensed NEWS The 0.2.0 release is the first public release of the bot. It has been battle-tested in production for more than a month already and is proving to be a really useful tool to help with Telegram group administration. ___ INFORMATION About eGenix (http://www.egenix.com/): eGenix is a database focused software project, consulting and product company delivering expert services and professional quality products for companies, Python users and developers. About Python (http://www.python.org/): Python is an object-oriented Open Source programming language which runs on all modern platforms. By integrating ease-of-use, clarity in coding, enterprise application connectivity and rapid application design, Python establishes an ideal programming platform for today's IT challenges. Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Experts (#1, Apr 04 2022) >>> Python Projects, Coaching and Support ...https://www.egenix.com/ >>> Python Product Development ...https://consulting.egenix.com/ ::: We implement business ideas - efficiently in both time and costs ::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 https://www.egenix.com/company/contact/ https://www.malemburg.com/ -- https://mail.python.org/mailman/listinfo/python-list
The Cython compiler is 20 years old today !
Dear Python community, it's now 20 years since Greg Ewing posted his first announcement of Pyrex, the tool that is now known and used under the name Cython. https://mail.python.org/pipermail/python-list/2002-April/126661.html It was a long way, and I've written up some of it in a blog post: http://blog.behnel.de/posts/cython-is-20/ Today, if you're working on any kind of larger application in Python, you're likely to have some piece of code downloaded into your venv that was built with Cython. Or many of them. I'm proud of what we have achieved. And I'm happy to see and talk to the many, many users out there whom we could help to help their users get their work done. Happy anniversary, Cython! Stefan PS: The list of Cython implemented packages on PyPI is certainly incomplete, so please add the classifier to yours if it's missing. With almost 3000 dependent packages on Github (and almost 100,000 related repos), I'm sure we can crack the number of 1000 Cython built packages on PyPI as a birthday present. (No Spam, please, just honest classifiers.) https://pypi.org/search/?q=&o=-created&c=Programming+Language+%3A%3A+Cython https://github.com/cython/cython/network/dependents?dependent_type=PACKAGE -- https://mail.python.org/mailman/listinfo/python-list
Re: ANN: eGenix Antispam Bot for Telegram 0.2.0
On Mon, 4 Apr 2022 14:40:57 +0200, eGenix Team wrote: > > > ANNOUNCING > > eGenix Antispam Bot for Telegram > > Version 0.2.0 > >A simple, yet effective bot implementation > to address Telegram signup spam. > > This announcement is also available on our web-site for online reading: > https://www.egenix.com/company/news/eGenix-Antispam-Bot-for- Telegram-0.2.0-GA.html > > > > INTRODUCTION > > eGenix has long been running a local user group meeting in Düsseldorf > called Python Meeting Düsseldorf and we are using a Telegram group for > most of our communication. > > In the early days, the group worked well and we only had few spammers > joining it, which we could well handle manually. > > More recently, this has changed dramatically. We are seeing between 2-5 > spam signups per day, often at night. Furthermore, the signups accounts > are not always easy to spot as spammers, since they often come with > profile images, descriptions, etc. > > With the bot, we now have a more flexible way of dealing with the > problem. > > Please see our project page for details and download links: > > https://www.egenix.com/library/telegram-antispam-bot/ > > > > FEATURES > > * Low impact mode of operation: the bot tries to keep noise in the >group to a minimum > > * Several challenge mechanisms to choose from, more can be added as >needed > > * Flexible and easy to use configuration > > * Only needs a few MB of RAM, so can easily be put into a container or >run on a Raspberry Pi > > * Can handle quite a bit of load due to the async implementation > > * Works with Python 3.9+ > > * MIT open source licensed > > > > NEWS > > The 0.2.0 release is the first public release of the bot. > > It has been battle-tested in production for more than a month already > and is proving to be a really useful tool to help with Telegram group > administration. > > ___ > > INFORMATION > > About eGenix (http://www.egenix.com/): > > eGenix is a database focused software project, consulting and > product company delivering expert services and professional quality > products for companies, Python users and developers. > > About Python (http://www.python.org/): > > Python is an object-oriented Open Source programming language which > runs on all modern platforms. By integrating ease-of-use, clarity in > coding, enterprise application connectivity and rapid application > design, Python establishes an ideal programming platform for today's > IT challenges. > > Enjoy, > -- > Marc-Andre Lemburg eGenix.com > > Professional Python Services directly from the Experts (#1, Apr 04 2022) Python Projects, Coaching and Support ...https://www.egenix.com/ Python Product Development ...https://consulting.egenix.com/ > > > ::: We implement business ideas - efficiently in both time and costs ::: > >eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 > D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg >Registered at Amtsgericht Duesseldorf: HRB 46611 >https://www.egenix.com/company/contact/ > https://www.malemburg.com/ Classic, spam a news group with an add for anti spam software can you even spell irony? -- The mosquito exists to keep the mighty humble. -- https://mail.python.org/mailman/listinfo/python-list
Marshmallow: json-to-schema helper?
Hi, I'm looking for a convenience function to convert a Marshmallow schema into a valid Python class definition. That is, I want to generate python code (class MySchema.. etc) that I could write to a .py file. Does this exist? I tried the code below, but that is not the intended use of marshmallow.Schema.from_dict or inspect.getsource. from inspect import getsource from marshmallow import Schema d = dict(something='potentially', very='complicated') schema = Schema.from_dict(d) python_class_def_as_str = getsource(schema()) # OSError https://marshmallow.readthedocs.io/en/stable/api_reference.html#marshmallow.Schema.from_dict https://docs.python.org/3/library/inspect.html#inspect.getsource Thanks! Albert-Jan -- https://mail.python.org/mailman/listinfo/python-list
Fwd: dict.get_deep()
-- Forwarded message -- From: Marco Sulla Date: Apr 2, 2022 22:44 Subject: dict.get_deep() To: Python List <> Cc: A proposal. Very often dict are used as a deeply nested carrier of data, usually decoded from JSON. data["users"][0]["address"]["street"] I have been using jsonpath expressions for that kind of stuff lately. Works really well. https://pypi.org/project/jsonpath-ng/ -- https://mail.python.org/mailman/listinfo/python-list
Re: flask app convert sql query to python plotly.
On Apr 2, 2022 20:50, Abdellah ALAOUI ISMAILI wrote: i would like to convert in my flask app an SQL query to an plotly pie chart using pandas. this is my code : def query_tickets_status() : query_result = pd.read_sql (""" SELECT COUNT(*)count_status, status FROM tickets GROUP BY status""", con = mydc_db) return query_result labels_statut = query_tickets_status['status'] values_statut = query_tickets_status['count_status'] == I think you mean: labels_statut = query_tickets_status()['status'] values_statut = query_tickets_status()['count_status'] -- https://mail.python.org/mailman/listinfo/python-list
pyinstaller is not a internal or external command
I ran pip install pyinstaller fine but after then I type in pyinstaller and it says pyinstaller is not a internal or external command Sent from [1]Mail for Windows References Visible links 1. https://go.microsoft.com/fwlink/?LinkId=550986 -- https://mail.python.org/mailman/listinfo/python-list
Re: pyinstaller is not a internal or external command
On 2022-04-04 20:28, Andrew Pierson wrote: I ran pip install pyinstaller fine but after then I type in pyinstaller and it says pyinstaller is not a internal or external command Have you tried using the Python launcher? py pyinstaller ... -- https://mail.python.org/mailman/listinfo/python-list
Re: dict.get_deep()
On 03Apr2022 21:45, Peter J. Holzer wrote: >Yup. I need something like this quite frequently, so I wrote a little >utility function (which I copy and paste into lots of code - I probably >should package that up, but a package with a single short function feels >weird). Start with one with a slightly generic name. It will grow. I've got a cs.seq module with sequence(ish) related utility functions in it. It started with very few functions and now has several. I've also got a cs.mappings module which started with a couple of mapping classes and now has a grab bag of mapping utility stuff. Incremental growth. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list
Re: The Cython compiler is 20 years old today !
On Mon, Apr 4, 2022 at 7:42 AM Stefan Behnel wrote: > Dear Python community, > > it's now 20 years since Greg Ewing posted his first announcement of Pyrex, > the tool that is now known and used under the name Cython. > > https://mail.python.org/pipermail/python-list/2002-April/126661.html > That's a cool anniversary. I often shake my head in wonder when I see people still writing extension modules in C instead of Cython. -- https://mail.python.org/mailman/listinfo/python-list