[{"user_id": 1152, "stars": [], "topic_id": 9343, "date_created": 1298812649.2896969, "message": "Share with me your short code examples of Python's awesome powers. Python 2, 3 - it doesn't matter. I want examples that make you go \"wow, Python *is* awesome\"", "group_id": 292, "id": 217156}, {"user_id": 257, "stars": [{"date_created": 1298817025.2660091, "user_id": 5639}, {"date_created": 1298827791.739892, "user_id": 261}, {"date_created": 1298922113.520782, "user_id": 38}], "topic_id": 9343, "date_created": 1298813887.704036, "message": "I've really come to love the bound methods. Where in other languages you would have to use reflection to pass along instance methods to apply for callbacks or in dispatch tables (e.g. callback=(obj, method_name), in Python you can just pass the method, and call it directly.", "group_id": 292, "id": 217189}, {"user_id": 3354, "stars": [{"date_created": 1299082342.2503829, "user_id": 1376}], "topic_id": 9343, "date_created": 1298827686.5807011, "message": "In Python 3 that's python -m http.server N (where N is the port you want to serve on)", "group_id": 292, "id": 218382}, {"user_id": 3354, "stars": [{"date_created": 1298828764.7821109, "user_id": 11592}, {"date_created": 1298831997.391438, "user_id": 16058}, {"date_created": 1298877376.2290599, "user_id": 5582}, {"date_created": 1299082335.178344, "user_id": 1376}, {"date_created": 1299250287.6289821, "user_id": 7376}], "topic_id": 9343, "date_created": 1298827651.0414219, "message": "I like the one-line Python web server command: python -m SimpleHTTPServer", "group_id": 292, "id": 218375}, {"user_id": 16058, "stars": [{"date_created": 1298832657.1362531, "user_id": 11592}, {"date_created": 1298883592.5137839, "user_id": 5195}, {"date_created": 1298953828.8728261, "user_id": 3751}, {"date_created": 1299250287.667923, "user_id": 7376}], "topic_id": 9343, "date_created": 1298832065.625829, "message": "yep, there's also an SMTP server: python -m smtpd -n -c DebuggingServer localhost:25", "group_id": 292, "id": 218984}, {"user_id": 16058, "stars": [], "topic_id": 9343, "date_created": 1298833093.398973, "message": "and my one-liner: https://gist.github.com/548282", "group_id": 292, "id": 219171}, {"user_id": 13893, "stars": [{"date_created": 1298853775.2510459, "user_id": 8391}, {"date_created": 1298872065.993922, "user_id": 7451}, {"date_created": 1298873309.44314, "user_id": 11592}, {"date_created": 1298914798.728148, "user_id": 16058}, {"date_created": 1298914802.794081, "user_id": 6415}, {"date_created": 1298987577.0384669, "user_id": 927}], "topic_id": 9343, "date_created": 1298853354.2103269, "message": "List comprehension and generator expressions are always a good showcase of how awesome python is. Once, I showed list comprehension to a Java developer, his head exploded.", "group_id": 292, "id": 223001}, {"user_id": 207, "stars": [], "topic_id": 9343, "date_created": 1298860064.5603859, "message": "i still love how python makes it so stupidly simple to implement a plugin framework: http://martyalchin.com/2008/jan/10/simple-plugin-framework/ :)", "group_id": 292, "id": 223351}, {"user_id": 6894, "stars": [], "topic_id": 9343, "date_created": 1298869945.953125, "message": "metaclasses and decorators", "group_id": 292, "id": 223599}, {"user_id": 6894, "stars": [], "topic_id": 9343, "date_created": 1298869991.0555949, "message": "A bunch of examples of useful decorators http://wiki.python.org/moin/PythonDecoratorLibrary", "group_id": 292, "id": 223602}, {"user_id": 14957, "stars": [], "topic_id": 9343, "date_created": 1298961551.468868, "message": "a == zip(zip(*a))", "group_id": 292, "id": 232394}, {"user_id": 7, "stars": [{"date_created": 1298987583.980485, "user_id": 927}, {"date_created": 1299027994.103642, "user_id": 4156}, {"date_created": 1299201139.1768839, "user_id": 3617}], "topic_id": 9343, "date_created": 1298961824.5904961, "message": "the fact that 99% of your data structure needs are in the box: for full coverage see my pycon talk", "group_id": 292, "id": 232428}, {"user_id": 14957, "stars": [], "topic_id": 9343, "date_created": 1298961955.296423, "message": "multiline re + findall + matchdict + generator expression = AST from structured text.", "group_id": 292, "id": 232451}, {"user_id": 1944, "stars": [{"date_created": 1299514582.861239, "user_id": 14578}], "topic_id": 9343, "date_created": 1298979624.2412751, "message": "Python is boring, that is its strength.", "group_id": 292, "id": 233891}, {"user_id": 1152, "stars": [], "topic_id": 9343, "date_created": 1298986155.527863, "message": "dag: Disagreed that python is boring :)", "group_id": 292, "id": 234451}, {"user_id": 12619, "stars": [], "topic_id": 9343, "date_created": 1299015792.3748281, "message": "Also, the easy way to create a dictionary with a simple delimiter is quite nice. Perhaps this is similarly simple in other languages, and if so, all the better.", "group_id": 292, "id": 239213}, {"user_id": 12619, "stars": [], "topic_id": 9343, "date_created": 1299015722.584923, "message": "I'm only twiddling, but I just came across a simple way to have a very strong multidimensional array-like structure that takes advantage of different objects' strengths. For instance, I am developing, as my first project, a text adventure engine. I need to allow for two-dimensional travel. I also will be creating, as the source file, a text file with key-value pairs delimited by a colon. I'll create a list of lists of dicts, such that the index of the first list is either the x- or y-axis, the index of the second list is the other axis. Then, I call my various location-specific information (e.g., description, available exits, etc.) by, for indices m, n, \"listOne(m)(n)['desc']\" returns the description of the location at (m, n) [or (n, m), depending on how I mapped dimensions to indices]. There are probably much more efficient ways to do this, but I'm allowing myself lots of room to do things interestingly even if they're not efficient.", "group_id": 292, "id": 239203}, {"user_id": 3094, "stars": [], "topic_id": 9343, "date_created": 1299039036.041893, "message": "I'm a fan of self.__dict__.update(locals()) in the __init__ method of a class", "group_id": 292, "id": 243206}, {"user_id": 1736, "stars": [], "topic_id": 9343, "date_created": 1299040845.6956179, "message": "@parlar That sounds terrible.", "group_id": 292, "id": 243563}, {"user_id": 7, "stars": [], "topic_id": 9343, "date_created": 1299040758.25597, "message": "-1", "group_id": 292, "id": 243541}, {"user_id": 14957, "stars": [{"date_created": 1299046488.1401839, "user_id": 4156}, {"date_created": 1299047508.2716441, "user_id": 5778}, {"date_created": 1299056826.121711, "user_id": 5582}, {"date_created": 1299071986.142767, "user_id": 12404}, {"date_created": 1299100822.0303111, "user_id": 927}, {"date_created": 1299157827.0431261, "user_id": 5639}], "topic_id": 9343, "date_created": 1299045747.8321819, "message": "@parlar yeowch! do you work on web2py?", "group_id": 292, "id": 245227}, {"user_id": 7, "stars": [], "topic_id": 9343, "date_created": 1299046243.4334879, "message": "@dougn ugh I know people who do that with django `render_to_response(\"tmpl.html\", locals()) drives me batty", "group_id": 292, "id": 245259}, {"user_id": 7, "stars": [], "topic_id": 9343, "date_created": 1299048139.3483491, "message": "@odwyerrob method on regex matches", "group_id": 292, "id": 245397}, {"user_id": 15162, "stars": [], "topic_id": 9343, "date_created": 1299047790.9340301, "message": "@dougn matchdict? I'm curious about this AST trick", "group_id": 292, "id": 245369}, {"user_id": 1944, "stars": [], "topic_id": 9343, "date_created": 1299051234.9853361, "message": "@jessenoller Tongue in cheek :P", "group_id": 292, "id": 245533}, {"user_id": 5582, "stars": [{"date_created": 1299076931.8830149, "user_id": 12404}, {"date_created": 1299084809.8714459, "user_id": 2376}, {"date_created": 1299090349.374507, "user_id": 4156}, {"date_created": 1299094039.150537, "user_id": 5778}, {"date_created": 1299157865.209605, "user_id": 5639}, {"date_created": 1299221462.6383591, "user_id": 4858}, {"date_created": 1299514599.818372, "user_id": 14578}], "topic_id": 9343, "date_created": 1299076920.0466311, "message": "@parlar \"explicit is better than implicit\" ?", "group_id": 292, "id": 247247}, {"user_id": 3094, "stars": [], "topic_id": 9343, "date_created": 1299076841.0151911, "message": "@coderanger @dougn Really? Everyone hates it? If you have an __init__ method that takes a couple of args, and all you're planning on doing is assigning them to instance variables in the class with the same name as the args, then what's so bad about it? Maybe it's just me letting my occasional laziness get the best of me :)", "group_id": 292, "id": 247225}, {"user_id": 3094, "stars": [], "topic_id": 9343, "date_created": 1299077009.850625, "message": "@0chris I know, but I always thought that my one-liner was so obvious that it was explicit. Guess I was wrong", "group_id": 292, "id": 247265}, {"user_id": 12133, "stars": [{"date_created": 1299740751.778194, "user_id": 5069}], "topic_id": 9343, "date_created": 1299080803.357178, "message": "the zen of python", "group_id": 292, "id": 248012}, {"user_id": 4156, "stars": [], "topic_id": 9343, "date_created": 1299090444.889462, "message": "I'd say it becomes more excusable the more kwargs you have in your constructor, but once you get past, I dunno, a half dozen, that's usually a sign you need to re-examine your API anyways.", "group_id": 292, "id": 250643}, {"user_id": 4156, "stars": [], "topic_id": 9343, "date_created": 1299090458.5238969, "message": "(says the guy who routinely writes functions with 6+ kwargs...sigh)", "group_id": 292, "id": 250652}, {"user_id": 4156, "stars": [], "topic_id": 9343, "date_created": 1299090411.6618631, "message": "I feel @parlar's pain, but until there's a nicer looking / more specific way of effecting the same result, I think being explicit is more Pythonic.", "group_id": 292, "id": 250629}, {"user_id": 207, "stars": [], "topic_id": 9343, "date_created": 1299105784.810571, "message": "but it seems the vast majority of mine work that way :)", "group_id": 292, "id": 254253}, {"user_id": 207, "stars": [], "topic_id": 9343, "date_created": 1299105776.0177031, "message": "i'd settle for writing more functions that don't accept *args and **kwargs", "group_id": 292, "id": 254252}, {"user_id": 14957, "stars": [{"date_created": 1299132477.367269, "user_id": 214}], "topic_id": 9343, "date_created": 1299131813.9141071, "message": "@parlar it adds 'self' as a member on the instance, unless you are very careful, it will overwrite methods, and other class attributes implicitly. By implicit, I mean you cant search the code to see where myclass.mymethod is being overwritten by self.mymethod=, or obj.mymethod=, because it is implicitly being overwritten because it is a local in __init__.", "group_id": 292, "id": 258406}, {"user_id": 14957, "stars": [], "topic_id": 9343, "date_created": 1299132578.1970961, "message": "@odwerrob You build a large regular expression with named matches '(?Pexpression)'. You have many conditional names expressions, with some as sentinels. That is break down the large re into sections. If the section is matched then a sentinel named match will contain some data. Check the groupdict from the match objects for the sentinels triggered, and build a tree. Will try to get an example.", "group_id": 292, "id": 258465}, {"user_id": 14957, "stars": [], "topic_id": 9343, "date_created": 1299131931.482605, "message": "@parlar gee who is overwriting my foo() method with the number 3? I grepped the entire code for 'foo' and nothing is setting it!!! OOOHHH... some dork is messing with the instance's __dict__ and not by name.", "group_id": 292, "id": 258425}, {"user_id": 14957, "stars": [{"date_created": 1299132466.352077, "user_id": 214}, {"date_created": 1299157984.54265, "user_id": 5639}], "topic_id": 9343, "date_created": 1299132063.507179, "message": "@parlar Then there is the issue with descriptors and properties! By modifying the __dict__ directly, you bypass the property/descriptor call, and remove it where the '.' expansion hits the MRO, and finds the property. Oh and if you are using __slots__, then setting __dict__ directly, disables the __slots__! Touching __dict__ is bad unless you really _really_ know what you are doing. Modifying it implicitly is downright EVIL.", "group_id": 292, "id": 258435}, {"user_id": 3094, "stars": [], "topic_id": 9343, "date_created": 1299207006.101876, "message": "Yeah yeah, I get it, it's a horrible idea that I obviously didn't think about enough :) I hereby swear never to do it again", "group_id": 292, "id": 266112}, {"user_id": 3094, "stars": [], "topic_id": 9343, "date_created": 1299207245.678889, "message": "Doing a quick google for \"self.__dict__.update(locals())\" unfortunately shows a lot of people suggesting this technique (and I know I originally read it somewhere else, many years ago). Guess it's something everyone should keep an eye out for", "group_id": 292, "id": 266131}, {"user_id": 3094, "stars": [{"date_created": 1299220552.732264, "user_id": 15162}, {"date_created": 1299243213.4956269, "user_id": 11592}, {"date_created": 1299761680.041997, "user_id": 16058}], "topic_id": 9343, "date_created": 1299214276.0730031, "message": "One that shouldn't get me in trouble: Using pyserial and the interactive interpreter to aid in developing embedded devices. So easy to connect over RS232, send a few bytes, receive some, do some checks, play around, all on-the-fly. I've spent *many* hours doing this", "group_id": 292, "id": 266675}, {"user_id": 15162, "stars": [], "topic_id": 9343, "date_created": 1299220723.7241549, "message": "@dougn I'm with you as far as the sentinel expressions. Is this done with nested capturing groups?", "group_id": 292, "id": 267237}, {"user_id": 15162, "stars": [], "topic_id": 9343, "date_created": 1299220627.2245729, "message": "@parlar +1 for pyserial and talking to hardware. It's almost scary how easy it is to make a simple driver for a serial protocol too", "group_id": 292, "id": 267215}, {"user_id": 7376, "stars": [], "topic_id": 9343, "date_created": 1299250431.425158, "message": "@dougn example of your AST from structured text parser?", "group_id": 292, "id": 269849}, {"user_id": 14957, "stars": [], "topic_id": 9343, "date_created": 1299266955.7811921, "message": "@odwyerrob yes.", "group_id": 292, "id": 272082}, {"user_id": 14957, "stars": [], "topic_id": 9343, "date_created": 1299266972.9668109, "message": "@ericmoritz too busy with PyCon planning to get it up today", "group_id": 292, "id": 272086}, {"user_id": 18539, "stars": [], "topic_id": 9343, "date_created": 1299278731.0710659, "message": "I find that I only find these things when I stop using Python for a while -- I've been greenfielding for quite some time now so I keep taking so much for granted.", "group_id": 292, "id": 273617}, {"user_id": 18972, "stars": [], "topic_id": 9343, "date_created": 1299383288.339411, "message": "beware of directory traversal vulnerabilities when running that one line python web server to share something...", "group_id": 292, "id": 278479}, {"user_id": 3617, "stars": [], "topic_id": 9343, "date_created": 1299387739.060605, "message": "@gpshead You'd have to be an idiot to run that in production though, there's a reason web servers are usually large applications.", "group_id": 292, "id": 278613}, {"user_id": 18972, "stars": [{"date_created": 1299458419.956749, "user_id": 3617}], "topic_id": 9343, "date_created": 1299389102.674093, "message": "agreed. mostly mentioning it because people use it on unsecured networks to quickly share something.", "group_id": 292, "id": 278677}]