Re: unexpected output while using list(and nested dictionary)
I am sorry for doing what i did (asking question in Stackoverflow and pasting the link here). I will keep this in mind for the future. I am very much new to this list, so was not sure. Do you guys have any suggestion as to what to use if the code is lone, as the formatting gets lost in an email... On Thu, Jul 23, 2015 at 12:36 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Thursday 23 July 2015 08:09, max scalf wrote: Hello List, I have posted a question on stack overflow for better readability ... but is intended for python list Please see question below... If it's intended for here, please ask it here. Consider that there may be people here who are willing and able to answer your question, but either don't have an account on Stackoverflow, have access to SO blocked, or simply don't like the culture and ethos of SO and won't use it. -- Steve -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: unexpected output while using list(and nested dictionary)
On Fri, 24 Jul 2015 12:04 am, max scalf wrote: I am sorry for doing what i did (asking question in Stackoverflow and pasting the link here). I will keep this in mind for the future. I am very much new to this list, so was not sure. Do you guys have any suggestion as to what to use if the code is lone, as the formatting gets lost in an email... Use a tool that doesn't break your emails. If you turn Rich Text or Formatted Text on, your mail will be sent as HTML code. That is a poor choice for formatting text, but it's a standard now, no matter the disadvantages (and there are many). HTML will wreck your formatting. If you turn Rich Text or Formatting off, and send as regular plain text with no bold, italics, inline pictures, dancing paperclips, embedded music or whatever other nonsense people like to stick in their emails these days, then any decent mail client will send *exactly what you type* with no frills or mangling. So if you type: def function(a, b): return a + 2*b # that's four spaces at the start of the line then that's exactly what will be sent, including the four spaces. If your mail program doesn't do that, then it is broken, like a car that can only turn left or a toaster that sets fire to the bread. Use a better email program. Another alternative is to save your code in a .py file, then attach it to the email as an attachment. Even the most obnoxious email program doesn't mangle attachments, at least not deliberately. But that can be inconvenient. Worst case, you can post your code in a pastebin, or some other website. But by doing so, understand that (1) you are limiting the usefulness of your question to others, who might learn from it in the future, and (2) limiting the number of people who are willing and able to answer. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: unexpected output while using list(and nested dictionary)
max scalf oracle.bl...@gmail.com writes: I am sorry for doing what i did (asking question in Stackoverflow and pasting the link here). No harm done. The rule isn't special to this forum; it's best to minimise the fragility of your message by not relying on many sites all staying the same over a long time. Do you guys have any suggestion as to what to use if the code is lone, as the formatting gets lost in an email... First, always post in “plain text”; don't present program code in a “rich text” or “HTML mail” or any other magical formatting tool. Second, don't post long code examples. Work up a small, self-contained, complete compilable example URL:http://sscce.org/ so that there isn't any extraneous material, only the code that demonstrates the behaviour that confuses you. The reason to do that for presentation here is that you want the code to be short enough that people will find it worth their time to volunteer to help you. But an important side benefit is: in stripping the example down so that it doesn't contain anything not needed to demonstrate the behaviour, you may end up understanding it well enough to solve the problem yourself — which is a valuable skill and very much worth your while :-) -- \ “If you always want the latest and greatest, then you have to | `\ buy a new iPod at least once a year.” —Steve Jobs, MSNBC | _o__) interview 2006-05-25 | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list
Re: unexpected output while using list(and nested dictionary)
In a message of Thu, 23 Jul 2015 09:04:38 -0500, max scalf writes: I am sorry for doing what i did (asking question in Stackoverflow and pasting the link here). I will keep this in mind for the future. I am very much new to this list, so was not sure. Do you guys have any suggestion as to what to use if the code is lone, as the formatting gets lost in an email... You need to set up your mailer to send plain text mail. Since you are using a gmail account, I assume you are using gmail. Googling for 'gmail plain text email' gives lots of hits -- apparantly Google has changed how composing email works at least once, and I cannot tell which of these hits is for current gmail and not gmail-of-5-years-ago If you aren't using gmail, you need to google for whatever mailer you are using and plain text email. Laura -- https://mail.python.org/mailman/listinfo/python-list
Re: unexpected output while using list(and nested dictionary)
In a message of Fri, 24 Jul 2015 00:57:42 +1000, Steven D'Aprano writes: On Fri, 24 Jul 2015 12:04 am, max scalf wrote: Another alternative is to save your code in a .py file, then attach it to the email as an attachment. Even the most obnoxious email program doesn't mangle attachments, at least not deliberately. But that can be inconvenient. python.org scrubs all attatchments on some lists. I am not sure if this is one of them -- convincing his email client to send plain text emails is the correct thing to do here. Laura -- https://mail.python.org/mailman/listinfo/python-list
Re: unexpected output while using list(and nested dictionary)
On 2015-07-23, Steven D'Aprano st...@pearwood.info wrote: On Fri, 24 Jul 2015 12:04 am, max scalf wrote: [...] Do you guys have any suggestion as to what to use if the code is lone, as the formatting gets lost in an email... Use a tool that doesn't break your emails. If you turn Rich Text or Formatted Text on, your mail will be sent as HTML code. That is a poor choice for formatting text, but it's a standard now, no matter the disadvantages (and there are many). HTML will wreck your formatting. In theory, code inside a pre/pre tag should be more-or-less OK (most of the time), but people sending HTML e-mail never seem to know how to do that. [Or probably their e-mail client is too broken to even allow such a thing.] If you turn Rich Text or Formatting off, and send as regular plain text with no bold, italics, inline pictures, dancing paperclips, embedded music or whatever other nonsense people like to stick in their emails these days, then any decent mail client will send *exactly what you type* with no frills or mangling. So if you type: def function(a, b): return a + 2*b # that's four spaces at the start of the line then that's exactly what will be sent, including the four spaces. That's definitely, by far, the very best option. If your mail program doesn't do that, then it is broken, like a car that can only turn left or a toaster that sets fire to the bread. Use a better email program. I recomment mutt if you really want to stick with getting everything e-mailed to you (which I personally don't like). Better yet (IMO) point slrn or your favorite NNTP client at comp.lang.python on your friendly local Usenet server or at gmane's nntp server at nntp://news.gmane.org/gmane.comp.python.general. Another alternative is to save your code in a .py file, then attach it to the email as an attachment. Even the most obnoxious email program doesn't mangle attachments, at least not deliberately. But that can be inconvenient. A lot of people are not going to open attachments sent by some random stranger. Some people might (even though they probably should not), but it could be the person who knows the answer to your problem won't bother -- either because of the effor or risk involved. Especially on Windows, opening e-mail attachments seems to be a rather dangerous thing to do. Do attachments sent to the mailing list make it realiably through gateways to places like comp.lang.python or into gmane's view of the mailing list? -- Grant Edwards grant.b.edwardsYow! Let me do my TRIBUTE at to FISHNET STOCKINGS ... gmail.com -- https://mail.python.org/mailman/listinfo/python-list
Re: unexpected output while using list(and nested dictionary)
On 23/07/2015 18:08, Grant Edwards wrote: I recomment mutt if you really want to stick with getting everything e-mailed to you (which I personally don't like). Better yet (IMO) point slrn or your favorite NNTP client at comp.lang.python on your friendly local Usenet server or at gmane's nntp server at nntp://news.gmane.org/gmane.comp.python.general. For those who aren't aware and as a reminder for those who are, there are 387 Python related lists at http://news.gmane.org/index.php?prefix=gmane.comp.python. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: unexpected output while using list(and nested dictionary)
On Thursday, July 23, 2015 at 9:25:46 PM UTC+5:30, Laura Creighton wrote: In a message of Thu, 23 Jul 2015 09:04:38 -0500, max scalf writes: I am sorry for doing what i did (asking question in Stackoverflow and pasting the link here). I will keep this in mind for the future. I am very much new to this list, so was not sure. Do you guys have any suggestion as to what to use if the code is lone, as the formatting gets lost in an email... You need to set up your mailer to send plain text mail. Since you are using a gmail account, I assume you are using gmail. Googling for 'gmail plain text email' gives lots of hits -- apparantly Google has changed how composing email works at least once, and I cannot tell which of these hits is for current gmail and not gmail-of-5-years-ago gmail → Compose → Tiny downward triangle in right bottom of compose window → Select plain text -- https://mail.python.org/mailman/listinfo/python-list
Re: unexpected output while using list(and nested dictionary)
On Wed, 22 Jul 2015 17:09:21 -0500, max scalf wrote: I have posted a question on stack overflow for better readability ... but is intended for python list Please see question below... It's quite obvious that your list and dictionary processing is not doing what you think it is. However, the question you have posted is a long and complex one. Perhaps you could reduce it to a simpler example. Your problem seems to be that in a list of dictionaries that is itself several levels of dictionary deep, you only see a single dictionary when you do the json conversion. perhaps you could try a simpler structure, such as: import json d1 = {'c':'0.0.0.0', 'f':'1', 'p':'icmp', 't':'1'} d2 = {'c':'1.1.1.1', 'f':'22', 'p':'tcp', 't':'22'} l = [d1,d2] d3 = {'g': 'text', 's': l} d4 = {'p': d3} d5 = {'r': d4} print d5 print json.dumps(d5) This correctly gives the following output, so I guess your problem is in how you create the list of dictionaries (l in my example). {'r': {'p': {'s': [{'p': 'icmp', 'c': '0.0.0.0', 't': '1', 'f': '1'}, {'p': 'tcp', 'c': '1.1.1.1', 't': '22', 'f': '22'}], 'g': 'text'}}} {r: {p: {s: [{p: icmp, c: 0.0.0.0, t: 1, f: 1}, {p: tcp, c: 1.1.1.1, t: 22, f: 22}], g: text}}} I would suggest you look closely at your makesg function, and the data that you are actually feeding to it and how it is using that data. makesg expects a collection as the third param, you seem to be passing it a list of one port element. makesg returns a list of sg, with an entry for every port. You then use this as tsg.SecurityGroupIngress. However, the way your code is written, you process all the 'i' in mylist, and for each 'i' overwrite tsg.SecurityGroupIngress with a new single element list sg from makesg. I suspect you've refactored some code from processing a list of things inside a function to processing them in the main body, or vice versa, or have just got confused about what you're processing where. I suggest that you rename your makesg function to makesgr, and have it return the rule appropriate to one entry in mylist. Then you can append the returned rule to tsg.SecurityGroupIngress with: tsg.SecurityGroupIngress.append(mksgr(param,param,param)) Alternatively, pass mylist to makesg, and return the whole list of rules. tsg.SecurityGroupIngress = mksg(mylist) Either method will require some rewriting of both the mksg[r] function and the main code to work together, but as the existing problem is that they don't seem to work together to create the data structure you expect them to create, that's not going to be a bad thing. -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list
Re: unexpected output while using list(and nested dictionary)
On Thursday 23 July 2015 08:09, max scalf wrote: Hello List, I have posted a question on stack overflow for better readability ... but is intended for python list Please see question below... If it's intended for here, please ask it here. Consider that there may be people here who are willing and able to answer your question, but either don't have an account on Stackoverflow, have access to SO blocked, or simply don't like the culture and ethos of SO and won't use it. -- Steve -- https://mail.python.org/mailman/listinfo/python-list
Re: unexpected output while using list(and nested dictionary)
max scalf oracle.bl...@gmail.com writes: I have posted a question on stack overflow for better readability ... but is intended for python list Please see question below... Please post (as a reply to your initial post, if you like) with the full question text in a message. Keep the discussion here in this forum self-contained; linking to context elsewhere is less reliable across time. -- \ “Come on, if your religion is so vulnerable that a little bit | `\ of disrespect is going to bring it down, it's not worth | _o__) believing in, frankly.” —Terry Gilliam, 2005-01-18 | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list