[Tutor] Question on List of Dict
Hi all, tes = [{'a': 1, 'b': 'this', 'c': 221}, {'a': 2, 'b': 'this', 'c': 215}, {'a': 1, 'b': 'is', 'c': 875}, {'a': 1, 'b': 'sentence', 'c': 874}, {'a': 2, 'b': 'another', 'c': 754}, {'a': 2, 'b': 'word', 'c': 745}] The above one is the result form the DB. I am trying to convert it to something like result_tes = [{'a': 1, 'b': 'this, is, sentence', 'c': '221, 875, 874'}, {'a': 2, 'b': 'this, another, word', 'c': '215, 754, 744'}] if the value of the 'a' is same, then all those other values of the dict should be merged/clubbed. I tried, but it became complex and complex. please can any one help me to get the result. Thanks, Sunil. G ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Assignment Expression and Callable Expression
On Fri, Sep 19, 2014 at 02:41:31AM +, Wang Lei (ERIAN) wrote: > Hi, everyone: > > I really believe that python is a great language but assignment and callable > are not flexible: > > I wish that I can do this: > > class matrixArray(list): > bla bla bla > def __call__(self, rid, cid): > return self.head[rid][cid] You can. __call__ is used for making objects a callable, function-like object. C++ calls them "functors". (Not the same thing as what Haskell calls functors!) > Once I call mat(1,1), I can get a result. but I want it more a value not a > reference. You want to change the entire execution model of Python? Why? Like most modern languages, such as Ruby, Java (mostly), and Javascript, Python values are references, not unboxed low-level primitive values. > Considering "mat(1,1) = 5" expression, I wish the parser can > dynamically map "mat(1,1)" to reference of value of that "or anonymous > reference" or reference defined in class. I'm afraid I don't understand what you are trying to say, but if you want to assign to individual items in a matrix, use indexing, not function call: mat[1, 1] = 5 will work perfectly once you add a __setitem__ method to your matrix class. > I don't want to modify the > lexical parsing in C++ but failed after trying different method in > pythonic ways: What does C++ have to do with this? > decorator: fun -> object mapping, because it just substitute function > name with new function and cannot read "self" object. > > I wish python developers could think of an idea to update the lexical > parsing method or simply provide us a tool to modify it in python > context. I think that their answer will be: "We will not complicate the language, making our job enormously harder, and Python much harder to learn and use, just because a beginner to Python who doesn't understand what the language can do or how to use it, wants to program in C++ instead of Python. If you want to program in C++, use C++. If you want to program in Python, learn Python." What do you expect to do with: mat(1, 1) = 5 that cannot be done with this instead? mat[1, 1] = 5 -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Assignment Expression and Callable Expression
> I wish python developers could think of an idea to update the lexical > parsing method or simply provide us a tool to modify it in python context. Hi Lei, This is unfortunately out of scope for Python-tutor. We don't have direct influence over the future direction of the language. If you want to contact the developers and the larger community, you may want to check the official general-purpose mailing list: https://mail.python.org/mailman/listinfo/python-list (Be aware that python-list is high-traffic.) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help
On Wed, Sep 17, 2014 at 4:36 PM, Art Pelletier wrote: > > I am a beginner with pythons programming I would like to see if their is a > site that has samples programs that I can practice on. Hi Art, Yes, there are some good resources you can check out. Here's a link to some of them: https://wiki.python.org/moin/BeginnersGuide/NonProgrammers Personally, I like How to Think Like a Computer Scientist: http://openbookproject.net/thinkcs/python/english2e/ but any of the tutorials in the beginner's guide should be helpful. Feel free to ask questions here on this mailing list too. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Assignment Expression and Callable Expression
On 19Sep2014 02:41, Wang Lei (ERIAN) wrote: I really believe that python is a great language but assignment and callable are not flexible: Some flexibilities are too much. But there are ways to do what you ask... I wish that I can do this: class matrixArray(list): bla bla bla def __call__(self, rid, cid): return self.head[rid][cid] Once I call mat(1,1), I can get a result. but I want it more a value not a reference. You're going to need to be less vague. If the result is, for example, an int, in what fashion is it a value instead of an int as far as you are concerned? Please describe this issue more fully. Considering "mat(1,1) = 5" expression, I wish the parser can dynamically map "mat(1,1)" to reference of value of that "or anonymous reference" or reference defined in class. I don't want to modify the lexical parsing in C++ but failed after trying different method in pythonic ways: Define the __setitem__ method on your matrixArray class. Then you can write: mat[1,1] = 5 which is arguably more natural anyway. Assignment and calling are two very different things, and in python they are written differently. That is a good thing. decorator: fun -> object mapping, because it just substitute function name with new function and cannot read "self" object. I must be missing your point here, too. It does just substitute a new function, but that new function can (and generally must) access "self" to do its work. I think you are forgetting that the @decorator action occurs at the time the class is defined, not at the time the function is called. Cheers, Cameron Simpson More computing sins have been committed in the name of performance, without necessariliy achieving it, than for all other reasons combined. - Wulf ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help
Check this guy's youtube channel. He has very basic examples. His username is thenewboston On Wed, Sep 17, 2014 at 4:36 PM, Art Pelletier wrote: > > I am a beginner with pythons programming I would like to see if their is a > site that has samples programs that I can practice on. > Sent from my iPad > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Python Assignment Expression and Callable Expression
Hi, everyone: I really believe that python is a great language but assignment and callable are not flexible: I wish that I can do this: class matrixArray(list): bla bla bla def __call__(self, rid, cid): return self.head[rid][cid] Once I call mat(1,1), I can get a result. but I want it more a value not a reference. Considering "mat(1,1) = 5" expression, I wish the parser can dynamically map "mat(1,1)" to reference of value of that "or anonymous reference" or reference defined in class. I don't want to modify the lexical parsing in C++ but failed after trying different method in pythonic ways: decorator: fun -> object mapping, because it just substitute function name with new function and cannot read "self" object. I wish python developers could think of an idea to update the lexical parsing method or simply provide us a tool to modify it in python context. Regards, Lei Wang CONFIDENTIALITY:This email is intended solely for the person(s) named and may be confidential and/or privileged.If you are not the intended recipient,please delete it,notify us and do not copy,use,or disclose its contents. Towards a sustainable earth:Print only when necessary.Thank you. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Help
I am a beginner with pythons programming I would like to see if their is a site that has samples programs that I can practice on. Sent from my iPad ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] GUI development with Python 3.4.1
El jue, 18 de sep 2014 a las 8:07 AM, Juan Christian escribió: On Wed, Sep 17, 2014 at 2:01 PM, Juan Christian wrote: I need to develop a GUI for my Python pogram, I already read the GuiProgramming page (https://wiki.python.org/moin/GuiProgramming). For me, the best so far was 'gui2py'. The problem is that I need a simple "C#/Java-ish" GUI builder, that is easy and simple, coding all the GUI by hand is boring, I prefer to focus on the logic, on the actual program code, than coding the GUI. Anyone here already used 'gui2py' (https://github.com/reingart/gui2py)? Any other good alternatives? Anyone? I personally like GTK quite a lot. You can use a GUI designer like Gazpacho or Glade to create basic XML UIs, but it's good to get familiar with the APIs of your toolkit of choice. Regards, Sebastian ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Is there any XML lib like the default json lib in terms of usability?
Using the default json lib is easy and straightforward: import json info = json.loads('file.json') # Use dict and list to navigate through 'info' Sadly, I'm working in a script and the only format the server gives is XML, I searched for a good alternative and didn't find anything as easy as the default json lib. Any tips? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Problem getting data using beautifulsoup4 + python 3.4.1
On Thu, Sep 18, 2014 at 6:10 PM, Peter Otten <__pete...@web.de> wrote: > > The doesn't have an href attribute, its child has. Try > > [a.attrs["href"] for a in s.select("div.authorline a")] OMG, I completely forgot about the 'a'... http://goo.gl/A8sRLT Thanks! 100% Working. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Problem getting data using beautifulsoup4 + python 3.4.1
Juan Christian wrote: > My code: > > import requests > import bs4 > > > FORUM_ID = "440" > > response = requests.get(' > http://steamcommunity.com/app/{id}/tradingforum'.format(id = FORUM_ID)) > soup = bs4.BeautifulSoup(response.text) > topics = [a.attrs.get('href') for a in > soup.select('a.forum_topic_overlay')] > > for topic in topics: > r = requests.get(topic) > s = bs4.BeautifulSoup(r.text) > > username = [a.get_text() for a in s.select('div.authorline')] > profile = [a.attrs.get('href') for a in s.select('div.authorline')] > > print(s.select('div.authorline')) > print("\nProfile value: " + str(profile)) > print("\n==\n") > > > Now, let's talk about the problem. The print(s.select('div.authorline')) > prints what I want, that is the part of the page that I need: > > [ > http://steamcommunity.com/id/FrazerJC"; onclick="return Forum_AuthorMenu( > this, event, false, '810938082603415962', '-1', 40662867, 'FrazerJC' );"> > FrazerJC class="forum_author_action_pulldown">http://steamcommunity-a.akamaihd.net/public/images/skin_1/comment_modindicator_moderator.png"; > title="Moderator" width="12"> 14 Oct, 2013 @ > 3:31pm] > > > But, the print("\nProfile value: " + str(profile)) isn't printing what I > want. It's giving me "Profile value: [None]". This should give me the link > to the person's profile, in this example, " > http://steamcommunity.com/id/FrazerJC";. I was following the bs4 doc, and I > did the [a.attrs.get('href') for a in s.select('div.authorline')] in order > to get the value of the href, but it isn't working, of course I made > something wrong, but where? The doesn't have an href attribute, its child has. Try [a.attrs["href"] for a in s.select("div.authorline a")] ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Problem getting data using beautifulsoup4 + python 3.4.1
My code: import requests import bs4 FORUM_ID = "440" response = requests.get(' http://steamcommunity.com/app/{id}/tradingforum'.format(id = FORUM_ID)) soup = bs4.BeautifulSoup(response.text) topics = [a.attrs.get('href') for a in soup.select('a.forum_topic_overlay')] for topic in topics: r = requests.get(topic) s = bs4.BeautifulSoup(r.text) username = [a.get_text() for a in s.select('div.authorline')] profile = [a.attrs.get('href') for a in s.select('div.authorline')] print(s.select('div.authorline')) print("\nProfile value: " + str(profile)) print("\n==\n") Now, let's talk about the problem. The print(s.select('div.authorline')) prints what I want, that is the part of the page that I need: [ http://steamcommunity.com/id/FrazerJC"; onclick="return Forum_AuthorMenu( this, event, false, '810938082603415962', '-1', 40662867, 'FrazerJC' );"> FrazerJChttp://steamcommunity-a.akamaihd.net/public/images/skin_1/comment_modindicator_moderator.png"; title="Moderator" width="12"> 14 Oct, 2013 @ 3:31pm] But, the print("\nProfile value: " + str(profile)) isn't printing what I want. It's giving me "Profile value: [None]". This should give me the link to the person's profile, in this example, " http://steamcommunity.com/id/FrazerJC";. I was following the bs4 doc, and I did the [a.attrs.get('href') for a in s.select('div.authorline')] in order to get the value of the href, but it isn't working, of course I made something wrong, but where? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] GUI development with Python 3.4.1
On 09/18/2014 06:07 AM, Juan Christian wrote: On Wed, Sep 17, 2014 at 2:01 PM, Juan Christian mailto:juan0christ...@gmail.com>> wrote: I need to develop a GUI for my Python pogram, I already read the GuiProgramming page (https://wiki.python.org/moin/GuiProgramming). For me, the best so far was 'gui2py'. The problem is that I need a simple "C#/Java-ish" GUI builder, that is easy and simple, coding all the GUI by hand is boring, I prefer to focus on the logic, on the actual program code, than coding the GUI. Anyone here already used 'gui2py' (https://github.com/reingart/gui2py)? Any other good alternatives? Anyone? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor Dabo has a designer (currently moving to support wxPython 3.x). That said, the link you first provided suggested there was a designer for gui2py? Johnf ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] GUI development with Python 3.4.1
Hi, I used to use wxPython.com Comes with a ton of examples and has many different drag and drop tools. Laszlo http://twitter.com/LZAntal > On Sep 18, 2014, at 6:27, Matthew Ngaha wrote: > > PyQt or PySide offers QtDesigner. Which is a drag and drop builder. > They are both quite complex GUI toolkits so you will need some basic > knowledge on them first, but I Imagine there are good guides on using > QtDesigner if it's your last option. > > On Thu, Sep 18, 2014 at 2:14 PM, Juan Christian > wrote: >> On Thu, Sep 18, 2014 at 10:12 AM, Joel Goldstick >> wrote: >>> >>> I've not used it but Tkinter seems to be well used. >>> >>> I'm not sure what a C#/Java-ish thing is, but python isn't that. >> >> >> "C#/Java-ish" in terms of GUI Builder, drag and drop, like Glade and gui2py. >> >> ___ >> Tutor maillist - Tutor@python.org >> To unsubscribe or change subscription options: >> https://mail.python.org/mailman/listinfo/tutor > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] GUI development with Python 3.4.1
PyQt or PySide offers QtDesigner. Which is a drag and drop builder. They are both quite complex GUI toolkits so you will need some basic knowledge on them first, but I Imagine there are good guides on using QtDesigner if it's your last option. On Thu, Sep 18, 2014 at 2:14 PM, Juan Christian wrote: > On Thu, Sep 18, 2014 at 10:12 AM, Joel Goldstick > wrote: >> >> I've not used it but Tkinter seems to be well used. >> >> I'm not sure what a C#/Java-ish thing is, but python isn't that. > > > "C#/Java-ish" in terms of GUI Builder, drag and drop, like Glade and gui2py. > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] GUI development with Python 3.4.1
On Thu, Sep 18, 2014 at 10:12 AM, Joel Goldstick wrote: > > I've not used it but Tkinter seems to be well used. > > I'm not sure what a C#/Java-ish thing is, but python isn't that. > "C#/Java-ish" in terms of GUI Builder, drag and drop, like Glade and gui2py. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] GUI development with Python 3.4.1
On Thu, Sep 18, 2014 at 9:07 AM, Juan Christian wrote: > On Wed, Sep 17, 2014 at 2:01 PM, Juan Christian > wrote: >> >> I need to develop a GUI for my Python pogram, I already read the >> GuiProgramming page (https://wiki.python.org/moin/GuiProgramming). For me, >> the best so far was 'gui2py'. >> >> The problem is that I need a simple "C#/Java-ish" GUI builder, that is >> easy and simple, coding all the GUI by hand is boring, I prefer to focus on >> the logic, on the actual program code, than coding the GUI. >> >> Anyone here already used 'gui2py' (https://github.com/reingart/gui2py)? >> Any other good alternatives? > > > Anyone? > I've not used it but Tkinter seems to be well used. I'm not sure what a C#/Java-ish thing is, but python isn't that. -- Joel Goldstick http://joelgoldstick.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] GUI development with Python 3.4.1
On Wed, Sep 17, 2014 at 2:01 PM, Juan Christian wrote: > I need to develop a GUI for my Python pogram, I already read the > GuiProgramming page (https://wiki.python.org/moin/GuiProgramming). For > me, the best so far was 'gui2py'. > > The problem is that I need a simple "C#/Java-ish" GUI builder, that is > easy and simple, coding all the GUI by hand is boring, I prefer to focus on > the logic, on the actual program code, than coding the GUI. > > Anyone here already used 'gui2py' (https://github.com/reingart/gui2py)? > Any other good alternatives? > Anyone? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor