Re: Simple Python script as SMTP server for outgoing e-mails?
On Tue, Jul 23, 2013 at 8:06 PM, Duncan Booth duncan.booth@invalid.invalid wrote: Excellent idea, I'll tell the email forwarding service to rewrite their system immediately. Yes. If they are using your domain in the MAIL FROM command and not using your mail servers, then yes, you should tell them, and use a different service until they fix that. It is not SPF's fault. It is a fundamental error of protocol, which SPF checks are highlighting. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: [OT] SPF - was Re: Simple Python script as SMTP server for outgoing e-mails?
On Wed, Jul 24, 2013 at 1:12 AM, Michael Torrie torr...@gmail.com wrote: On 07/23/2013 03:30 AM, Chris Angelico wrote: On Tue, Jul 23, 2013 at 7:19 PM, Chris Angelico ros...@gmail.com wrote: Ah, there's a solution to this one. You simply use your own envelope-from address; SPF shouldn't be being checked for the From: header. There's an example, by the way, of this exact technique right here - python-list@python.org sends mail to me with an envelope-from of python-list-bounces+rosuav=gmail@python.org - which passes SPF, since python.org has a TXT record designating the sending IP as one of theirs. It doesn't matter that invalid.invalid (your supposed domain) doesn't have an SPF record, nor would it be a problem if it had one that said v=spf1 -all, because that domain wasn't checked. Mailing lists are doing the same sort of forwarding that you're doing. This is good and all, and I think I will modify my local postfix mail server I use for personal stuff, just for correctness' sake. Correctness is a worthwhile reason to do something :) I hadn't spent much time studying SPF in depth before, but after reading your comments (which were insightful) I'm now more convinced that SPF is worthless than ever, at least as a spam prevention mechanism. Spammers can use throwaway domains that publish very non-strict SPF records, and spam to their hearts content with random forged from addresses and SPF checks pass. The only way around that is to enforce SPF on the From: header in the e-mail itself, which we all agree is broken. I've been reading this: http://www.openspf.org/FAQ/SPF_is_not_about_spam There are several things that SPF achieves, but mainly it's a measure of trust. If you receive email from a domain I run, and the SPF record permits the IP that sent it to you, you can have a high degree of confidence that it really is from that domain. Suppose, for instance, that (pick a bank, any bank) has a strict SPF record. Someone tries to send a phishing email purporting to be from that bank. They then have to use a different envelope-from address, which instantly marks the mail as suspicious to anyone who's checking. But more likely, what they'll do is simply ignore SPF and send it anyway. That means that any MTA that checks SPF records is immediately freed of all that bad mail - which is more than just spam, it's a major vulnerability (thinking here of corporate networks where all the company's mail goes through a central server, and then a whole lot of non-technical people read it). In the same way that banks assure us that they will *never* ask for your password, they could also assure us that they will *never* send account information from any other domain. Spammers look for the easy pickings. If your X million addresses become (X-1),999,900 because a few servers are rejecting their mail, what do they care? But those hundred people now haven't seen that spam. Sure, spammers can easily get around SPF checks... but that won't get all that likely until the bulk of MTAs start checking. For now, we can take all the benefit. Later on, the world can look to other solutions. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Converting a list of lists to a single list
On Wed, Jul 24, 2013 at 8:34 AM, Rafael Durán Castañeda rafadurancastan...@gmail.com wrote: In [3]: [ y for y in itertools.chain.from_iterable(x)] Out[3]: ['A0', 'A1', 'A2', 'B0', 'B1', 'B2', 'C0', 'C1', 'C2'] Complete aside, given that this has already been pointed out as solving a different problem: Any time you see a list comp that just does [ x for x in foo ], check to see if it can be replaced by a simple list constructor: [ y for y in itertools.chain.from_iterable(x)] ['A0', 'A1', 'A2', 'B0', 'B1', 'B2', 'C0', 'C1', 'C2'] list(itertools.chain.from_iterable(x)) ['A0', 'A1', 'A2', 'B0', 'B1', 'B2', 'C0', 'C1', 'C2'] A bit simpler and achieves the same. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Strange behaviour with os.linesep
On Wed, Jul 24, 2013 at 5:02 PM, Vincent Vande Vyvre vincent.vandevy...@swing.be wrote: In fact, in my code, the original file is open in binary mode, the line separator is translate to \n and it is parsed by the module tokenise. I'm not a Windows user but my code must be run also on Win, this is the reason of the usage of os.linesep in writting. So, now I found the solution, just write the file in binary mode and now it is correctly open with all the editors. Sounds to me like the problem was double-translation - you in your code turned \n into \r\n, but then the file was written in text mode, doing the same translation, so your lines were terminated with \r\r\n. That would result in what you're seeing (including the oddity that some editors will show the file differently). You may find it easier to write the file in text mode and let the underlying system do the translation for you. Chances are that'll be correct. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: i want to run user specific cronjobs so where to specify user in ubuntu?
On Wed, Jul 24, 2013 at 5:47 PM, navnathgad...@gmail.com wrote: -- http://mail.python.org/mailman/listinfo/python-list Not a Python question. I'm sure Google can help you with this one - just take three words from your question, 'user specific cronjobs', and you'll get plenty of advice. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: RE Module Performance
On Wed, Jul 24, 2013 at 11:40 PM, wxjmfa...@gmail.com wrote: Short example. Writing an editor with something like the FSR is simply impossible (properly). jmf, have you ever written an editor with *any* string representation? Are you speaking from any level of experience at all? ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: RE Module Performance
On Thu, Jul 25, 2013 at 12:17 AM, David Hutto dwightdhu...@gmail.com wrote: I've screwed up plenty of times in python, but can write code like a pro when I'm feeling better(on SSI and medicaid). An editor can be built simply, but it's preference that makes the difference. Some might have used tkinter, gtk. wxpython or other methods for the task. I think the main issue in responding is your library preference, or widget set preference. These can make you right with some in your response, or wrong with others that have a preferable gui library that coincides with one's personal cognitive structure that makes t jmf's point is more about writing the editor widget (Scintilla, as opposed to SciTE), which most people will never bother to do. I've written several text editors, always by embedding someone else's widget, and therefore not concerning myself with its internal string representation. Frankly, Python's strings are a *terrible* internal representation for an editor widget - not because of PEP 393, but simply because they are immutable, and every keypress would result in a rebuilding of the string. On the flip side, I could quite plausibly imagine using a list of strings; whenever text gets inserted, the string gets split at that point, and a new string created for the insert (which also means that an Undo operation simply removes one entire string). In this usage, the FSR is beneficial, as it's possible to have different strings at different widths. But mainly, I'm just wondering how many people here have any basis from which to argue the point he's trying to make. I doubt most of us have (a) implemented an editor widget, or (b) tested multiple different internal representations to learn the true pros and cons of each. And even if any of us had, that still wouldn't have any bearing on PEP 393, which is about applications, not editor widgets. As stated above, Python strings before AND after PEP 393 are poor choices for an editor, ergo arguing from that standpoint is pretty useless. Not that that bothers jmf... ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: RE Module Performance
On Thu, Jul 25, 2013 at 12:47 AM, Michael Torrie torr...@gmail.com wrote: On 07/24/2013 07:40 AM, wxjmfa...@gmail.com wrote: Sorry, you are not understanding Unicode. What is a Unicode Transformation Format (UTF), what is the goal of a UTF and why it is important for an implementation to work with a UTF. Really? Enlighten me. Personally, I would never use UTF as a representation *in memory* for a unicode string if it were up to me. Why? Because UTF characters are not uniform in byte width so accessing positions within the string is terribly slow and has to always be done by starting at the beginning of the string. That's at minimum O(n) compared to FSR's O(1). Surely you understand this. Do you dispute this fact? Take care here; UTF is a general term for Unicode Translation Formats, of which one (UTF-32) is fixed-width. Every other UTF-n is variable width, though, so your point still stands. UTF-32 is the basis for Python's FSR. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: how: embed + extend to control my running app?
On Thu, Jul 25, 2013 at 2:10 AM, David M. Cotter m...@davecotter.com wrote: So: i really want it to go to my own log file (via my Log() function). now, can i specify please output to this FILE* ?, i looked at all the python c headers but found nothing about redirecting the output. Are you able to simply redirect the OS-level stdout handle, or would that disrupt your own code? That might be an easier way to log to a file. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3: dict dict.keys()
On Thu, Jul 25, 2013 at 1:57 AM, Ethan Furman et...@stoneleaf.us wrote: On 07/24/2013 05:51 AM, Oscar Benjamin wrote: What do you mean? Why would you want to create a temporary list just to iterate over it explicitly or implicitly (set, sorted, max,...)? You wouldn't. But you don't need .keys() for that either as you can just use the dict itself. Side point: Why is iterating over a dict equivalent to .keys() rather than .items()? It feels odd that, with both options viable, the implicit version iterates over half the dict instead of all of it. Obviously it can't be changed now, even if .items() were the better choice, but I'm curious as to the reason for the decision. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3: dict dict.keys()
On Thu, Jul 25, 2013 at 3:17 AM, Terry Reedy tjre...@udel.edu wrote: On 7/24/2013 12:34 PM, Chris Angelico wrote: Side point: Why is iterating over a dict equivalent to .keys() rather than .items()? It feels odd that, with both options viable, the implicit version iterates over half the dict instead of all of it. Obviously it can't be changed now, even if .items() were the better choice, but I'm curious as to the reason for the decision. This is coupled with the fact that the default meaning of 'item in collection' is that iterating over 'collection' eventually produces 'item' or a value equal to 'item'. Ahh, that makes sense. I never thought of iteration and 'in' being connected like that, but yes, that's a solid reason for doing it that way. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: RE Module Performance
On Thu, Jul 25, 2013 at 3:52 AM, Terry Reedy tjre...@udel.edu wrote: On 7/24/2013 11:00 AM, Michael Torrie wrote: On 07/24/2013 08:34 AM, Chris Angelico wrote: Frankly, Python's strings are a *terrible* internal representation for an editor widget - not because of PEP 393, but simply because they are immutable, and every keypress would result in a rebuilding of the string. On the flip side, I could quite plausibly imagine using a list of strings; I used exactly this, a list of strings, for a Python-coded text-only mock editor to replace the tk Text widget in idle tests. It works fine for the purpose. For small test texts, the inefficiency of immutable strings is not relevant. Tk apparently uses a C-coded btree rather than a Python list. All details are hidden, unless one finds and reads the source ;-), but but it uses C arrays rather than Python strings. In this usage, the FSR is beneficial, as it's possible to have different strings at different widths. For my purpose, the mock Text works the same in 2.7 and 3.3+. Thanks for that report! And yes, it's going to behave exactly the same way, because its underlying structure is an ordered list of ordered lists of Unicode codepoints, ergo 3.3/PEP 393 is merely a question of performance. But if you put your code onto a narrow build, you'll have issues as seen below. Maybe, but simply thinking logically, FSR and UCS-4 are equivalent in pros and cons, They both have the pro that indexing is direct *and correct*. The cons are different. They're close enough, though. It's simply a performance tradeoff - use the memory all the time, or take a bit of overhead to give yourself the option of using less memory. The difference is negligible compared to... and the cons of using UCS-2 (the old narrow builds) are well known. UCS-2 simply cannot represent all of unicode correctly. Python's narrow builds, at least for several releases, were in between USC-2 and UTF-16 in that they used surrogates to represent all unicodes but did not correct indexing for the presence of astral chars. This is a nuisance for those who do use astral chars, such as emotes and CJK name chars, on an everyday basis. ... this. If nobody had ever thought of doing a multi-format string representation, I could well imagine the Python core devs debating whether the cost of UTF-32 strings is worth the correctness and consistency improvements... and most likely concluding that narrow builds get abolished. And if any other language (eg ECMAScript) decides to move from UTF-16 to UTF-32, I would wholeheartedly support the move, even if it broke code to do so. To my mind, exposing UTF-16 surrogates to the application is a bug to be fixed, not a feature to be maintained. But since we can get the best of both worlds with only a small amount of overhead, I really don't see why anyone should be objecting. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Dihedral
On Thu, Jul 25, 2013 at 4:08 AM, Stefan Behnel stefan...@behnel.de wrote: Fábio Santos, 16.07.2013 00:54: Does this mean he passes the Turing test? I'd say that it appears more correct. Or is there any indication of a specific bot gender? (I sure might have missed it...) Note that being of a specific gender is definitely not required to pass the Turing test. I'm not even sure pretending to have one is required. Gender: [ ] Male [ ] Female [ ] Both [ ] Neither [ ] Robot [ ] Other In absence of specific information to the contrary, I'll usually refer to computers and programs by masculine pronouns; no particular reason for it, just the same sort of convention that has most ships and boats being she. And you're quite right, gender and the pretense thereto are completely optional in a Turing test, even though the Turing test was derived from a similar concept involving gender. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: RE Module Performance
On Thu, Jul 25, 2013 at 8:09 AM, Terry Reedy tjre...@udel.edu wrote: On 7/24/2013 2:15 PM, Chris Angelico wrote: To my mind, exposing UTF-16 surrogates to the application is a bug to be fixed, not a feature to be maintained. It is definitely not a feature, but a proper UTF-16 implementation would not expose them except to codecs, just as with the PEP 393 implementation. (In both cases, I am excluding the sys size function as 'exposing to the application'.) But since we can get the best of both worlds with only a small amount of overhead, I really don't see why anyone should be objecting. I presume you are referring to the PEP 393 1-2-4 byte implementation. Given how well it has been optimized, I think it was the right choice for Python. But a language that now uses USC2 or defective UTF-16 on all platforms might find the auxiliary array an easier fix. I'm referring here to objections like jmf's, and also to threads like this: http://mozilla.6506.n7.nabble.com/Flexible-String-Representation-full-Unicode-for-ES6-td267585.html According to the ECMAScript people, UTF-16 and exposing surrogates to the application is a critical feature to be maintained. I disagree. But it's not my language, so I'm stuck with it. (I ended up writing a little wrapper function in C that detects unpaired surrogates, but that still doesn't deal with the possibility that character indexing can create a new character that was never there to start with.) ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: RE Module Performance
On Thu, Jul 25, 2013 at 8:59 AM, Michael Torrie torr...@gmail.com wrote: I don't fully understand why making strings simply unicode in javascript breaks compatibility with older scripts. What operations are performed on strings that making unicode an abstract type would break? Imagine this in JavaScript and Python (apart from the fact that JS doesn't do backslash escapes past 0x1): a = asdf\U00012345qwer; b = a[[..10]; What will this do? It depends on whether UTF-16 is used or not. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: I have a little problem with Django when I am trying to create a new app
On Thu, Jul 25, 2013 at 12:03 PM, peins0...@gmail.com wrote: Hello everyone I'm watching a tutorial on how to create a project on Django... django-admin.py startproject carabali when I run this code on terminal.. happens : http://nsae01.casimages.net/img/2013/07/25/130725021220676239.png There's a mistake or something but I can't figure out, help me please It's saying that it can't find the zlib module. What Linux distribution is this? You may need to 'apt-get install' / 'yum install' / 'pacman -S' another package to make this work - possibly it'll be called 'zlib' or 'python-zlib' or something. I would recommend a Google search for your Linux distribution and the words 'python importerror zlib'; there's a high chance that'll tell you what you need to install. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: RE Module Performance
On Thu, Jul 25, 2013 at 3:49 PM, Serhiy Storchaka storch...@gmail.com wrote: 24.07.13 21:15, Chris Angelico написав(ла): To my mind, exposing UTF-16 surrogates to the application is a bug to be fixed, not a feature to be maintained. Python 3 uses code points from U+DC80 to U+DCFF (which are in surrogates area) to represent undecodable bytes with surrogateescape error handler. That's a deliberate and conscious use of the codepoints; that's not what I'm talking about here. Suppose you read a UTF-8 stream of bytes from a file, and decode them into your language's standard string type. At this point, you should be working with a string of Unicode codepoints: \22\341\210\264\360\222\215\205 -- \x12\u1234\U00012345 The incoming byte stream has a length of 8, the resulting character stream has a length of 3. Now, if the language wants to use UTF-16 internally, it's free to do so: 0012 1234 d808 df45 When I referred to exposing surrogates to the application, this is what I'm talking about. If decoding the above byte stream results in a length 4 string where the last two are \xd808 and \xdf45, then it's exposing them. If it's a length 3 string where the last is \U00012345, then it's hiding them. To be honest, I don't imagine I'll ever see a language that stores strings in UTF-16 and then exposes them to the application as UTF-32; there's very little point. But such *is* possible, and if it's working closely with libraries that demand UTF-16, it might well make sense to do things that way. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3: dict dict.keys()
On Thu, Jul 25, 2013 at 3:48 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: Dicts aren't sets, and don't support set methods: py d1 - d2 Traceback (most recent call last): File stdin, line 1, in module TypeError: unsupported operand type(s) for -: 'dict' and 'dict' I wouldn't take this as particularly significant, though. A future version of Python could add that support (and it might well be very useful), without breaking any of the effects of views. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: RE Module Performance
On Thu, Jul 25, 2013 at 5:02 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Thu, 25 Jul 2013 00:34:24 +1000, Chris Angelico wrote: But mainly, I'm just wondering how many people here have any basis from which to argue the point he's trying to make. I doubt most of us have (a) implemented an editor widget, or (b) tested multiple different internal representations to learn the true pros and cons of each. And even if any of us had, that still wouldn't have any bearing on PEP 393, which is about applications, not editor widgets. As stated above, Python strings before AND after PEP 393 are poor choices for an editor, ergo arguing from that standpoint is pretty useless. That's a misleading way to put it. Using immutable strings as editor buffers might be a bad way to implement all but the most trivial, low- performance (i.e. slow) editor, but the basic concept of PEP 393, picking an internal representation of the text based on its contents, is not. That's just normal. The only difference with PEP 393 is that the choice is made on the fly, at runtime, instead of decided in advance by the programmer. Maybe I worded it poorly, but my point was the same as you're saying here: that a Python string is a poor buffer for editing, regardless of PEP 393. It's not that PEP 393 makes Python strings worse for writing a text editor, it's that immutability does that. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: RE Module Performance
On Thu, Jul 25, 2013 at 5:15 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Thu, 25 Jul 2013 04:15:42 +1000, Chris Angelico wrote: If nobody had ever thought of doing a multi-format string representation, I could well imagine the Python core devs debating whether the cost of UTF-32 strings is worth the correctness and consistency improvements... and most likely concluding that narrow builds get abolished. And if any other language (eg ECMAScript) decides to move from UTF-16 to UTF-32, I would wholeheartedly support the move, even if it broke code to do so. Unfortunately, so long as most language designers are European-centric, there is going to be a lot of push-back against any attempt to fix (say) Javascript, or Java just for the sake of a bunch of dead languages in the SMPs. Thank goodness for emoji. Wait til the young kids start complaining that their emoticons and emoji are broken in Javascript, and eventually it will get fixed. It may take a decade, for the young kids to grow up and take over Javascript from the old-codgers, but it will happen. I don't know that that'll happen like that. Emoticons aren't broken in Javascript - you can use them just fine. You only start seeing problems when you index into that string. People will start to wonder why, for instance, a 500 character maximum field deducts two from the limit when an emoticon goes in. Example: Type here:brtextarea id=content oninput=showlimit(this)/textarea brYou have span id=limit1500/span characters left (self.value.length). brYou have span id=limit2500/span characters left (self.textLength). script function showlimit(self) { document.getElementById(limit1).innerHTML=500-self.value.length; document.getElementById(limit2).innerHTML=500-self.textLength; } /script I've included an attribute documented here[1] as the codepoint length of the control's value, but in Chrome on Windows, it still counts UTF-16 code units. However, I very much doubt that this will result in language changes. People will just live with it. Chinese and Japanese users will complain, perhaps, and the developers will write it off as whinging, and just say That's what the internet does. Maybe, if you're really lucky, they'll acknowledge that that's what JavaScript does, but even then I doubt it'd result in language changes. To my mind, exposing UTF-16 surrogates to the application is a bug to be fixed, not a feature to be maintained. This, times a thousand. It is *possible* to have non-buggy string routines using UTF-16, but the implementation is a lot more complex than most language developers can be bothered with. I'm not aware of any language that uses UTF-16 internally that doesn't give wrong results for surrogate pairs. The problem isn't the underlying representation, the problem is what gets exposed to the application. Once you've decided to expose codepoints to the app (abstracting over your UTF-16 underlying representation), the change to using UTF-32, or mimicking PEP 393, or some other structure, is purely internal and an optimization. So I doubt any language will use UTF-16 internally and UTF-32 to the app. It'd be needlessly complex. ChrisA [1] https://developer.mozilla.org/en-US/docs/Web/API/HTMLTextAreaElement -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3: dict dict.keys()
On Thu, Jul 25, 2013 at 5:04 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: - Views support efficient (O(1) in the case of keys) membership testing, which neither iterkeys() nor Python2 keys() does. To save me the trouble and potential error of digging through the source code: What's the complexity of membership testing on values/items? Since you're calling it efficient it must be better than O(n) which the list form would be, yet it isn't O(1) or you wouldn't have qualified in the case of keys. Does this mean membership testing of the values and items views is O(log n) in some way, eg a binary search? ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3: dict dict.keys()
On Thu, Jul 25, 2013 at 5:27 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Thu, 25 Jul 2013 16:02:42 +1000, Chris Angelico wrote: On Thu, Jul 25, 2013 at 3:48 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: Dicts aren't sets, and don't support set methods: py d1 - d2 Traceback (most recent call last): File stdin, line 1, in module TypeError: unsupported operand type(s) for -: 'dict' and 'dict' I wouldn't take this as particularly significant, though. A future version of Python could add that support (and it might well be very useful), without breaking any of the effects of views. I don't think dicts can ever support set methods, since *they aren't sets*. Every element consists of both a key and a value, so you have to consider both. Set methods are defined in terms of singleton elements, not binary elements, so before you even begin, you have to decide what does it mean when two elements differ in only one of the two parts? Given dicts {1: 'a'}, {1: 'b'}, what is the union of them? I can see five possibilities: {1: 'a'} {1: 'b'} {1: ['a', 'b']} {1: set(['a', 'b'])} Error Each of the five results may be what you want in some circumstances. It would be a stupid thing for dict.union to pick one behaviour and make it the One True Way to perform union on two dicts. That's true, but we already have that issue with sets. What's the union of {0} and {0.0}? Python's answer: It depends on the order of the operands. i={0} f={0.0} i | f {0} f | i {0.0} I would say that Python can freely pick from the first two options you offered (either keep-first or keep-last), most likely the first one, and it'd make good sense. Your third option would be good for a few specific circumstances, but then you probably would also want the combination of {1:'a'} and {1:'a'} to be {1:['a','a']} for consistency. This would make a good utility function, but isn't what I'd normally see set union doing. Similarly with the fourth option, though there it's a little more arguable. Raising an error would work, but is IMO unnecessary. (Pike has dictionary operations, but has made different choices. For instance, 0 and 0.0 are considered distinct, so a set can contain both. Mappings (dicts) merge by keeping the last, not the first. But the specifics don't much matter.) A Python set already has to distinguish between object value and object identity; a dict simply adds a bit more distinction between otherwise-considered-identical keys, namely their values. a=This is a test. b=This is a test. a is b False id(a) 16241512 id(b) 16241392 id(({a}|{b}).pop()) 16241512 Assuming a and b have different ids, which is true in the above example of Py3.3 on Windows, the set union *must* be different from one of them. Suppose you do a dictionary of id(key) - value, and a set of the keys themselves. You could then do set operations on the keys, and then go and retrieve the values. Sure, maybe the way of doing things won't be exactly what everyone expects... but it works, and it makes plausible sense. And as a theoretical might be implemented in Python 3.5, it still has no impact on views, beyond that there are some operations which must be done with views in =3.3 that could be done on the dicts themselves in future. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: must be dicts in tuple
On Thu, Jul 25, 2013 at 4:58 PM, Tanaya D cool.tanay...@gmail.com wrote: Hi, I am using Python with Bots(EDI translator) But i am getting the following error: MappingFormatError: must be dicts in tuple: get((({'BOTSID': 'HEADER'},),)) The first thing to do is to construct a short piece of code that demonstrates the problem. See http://sscce.org/ for some tips. Once you've done that, run that script and copy and paste its entire output (which will be your exception traceback) into an email. That said, though, I believe the problem you're seeing is going to be Bots-specific. You'll possibly do better on a Bots mailing list rather than a general Python one. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: RE Module Performance
On Thu, Jul 25, 2013 at 7:22 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: What I'm trying to say is that it is possible to use UTF-16 internally, but *not* assume that every code point (character) is represented by a single 2-byte unit. For example, the len() of a UTF-16 string should not be calculated by counting the number of bytes and dividing by two. You actually need to walk the string, inspecting each double-byte Anything's possible. But since underlying representations can be changed fairly easily (relative term of course - it's a lot of work, but it can be changed in a single release, no deprecation required or anything), there's very little reason to continue using UTF-16 underneath. May as well switch to UTF-32 for convenience, or PEP 393 for convenience and efficiency, or maybe some other system that's still mostly fixed-width. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: RE Module Performance
On Thu, Jul 25, 2013 at 7:27 PM, wxjmfa...@gmail.com wrote: A coding scheme works with a unique set of characters (the repertoire), and the implementation (the programming) works with a unique set of encoded code points. The critical step is the path {unique set of characters} -- {unique set of encoded code points} That's called Unicode. It maps the character 'A' to the code point U+0041 and so on. Code points are integers. In fact, they are very well represented in Python that way (also in Pike, fwiw): ord('A') 65 chr(65) 'A' chr(123456) '\U0001e240' ord(_) 123456 In the byte string world, this step is a no-op. In Unicode, it is exactly the purpose of a utf to achieve this step. utf: a confusing name covering at the same time the process and the result of the process. A utf chunk, a series of bits (not bytes), hold intrisically the information about the character it is representing. No, now you're looking at another level: how to store codepoints in memory. That demands that they be stored as bits and bytes, because PC memory works that way. utf32: as a pointed many times. You are already using it (maybe without knowing it). Where? in fonts (OpenType technology), rendering engines, pdf files. Why? Because there is not other way to do it better. And UTF-32 is an excellent system... as long as you're okay with spending four bytes for every character. See https://groups.google.com/forum/#!topic/comp.lang.python/XkTKE7U8CS0 I refuse to click this link. Give us a link to the python-list@python.org archive, or gmane, or something else more suited to the audience. I'm not going to Google Groups just to figure out what you're saying. If you are not understanding my editor analogy. One other proposed exercise. Build/create a flexible iso-8859-X coding scheme. You will quickly understand where the bottleneck is. Two working ways: - stupidly with an editor and your fingers. - lazily with a sheet of paper and you head. What has this to do with the editor? There is a clear difference between FSR and ucs-4/utf32. Yes. Memory usage. PEP 393 strings might take up half or even a quarter of what they'd take up in fixed UTF-32. Other than that, there's no difference. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3: dict dict.keys()
On Thu, Jul 25, 2013 at 7:44 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Thu, 25 Jul 2013 18:15:22 +1000, Chris Angelico wrote: That's true, but we already have that issue with sets. What's the union of {0} and {0.0}? Python's answer: It depends on the order of the operands. That's a side-effect of how numeric equality works in Python. Since 0 == 0.0, you can't have both as keys in the same dict, or set. Indeed, the same numeric equality issue occurs here: py from fractions import Fraction py [0, 2.5] == [0.0, Fraction(5, 2)] True So nothing really to do with sets or dicts specifically. Here's how I imagine set/dict union: 1) Take a copy of the first object 2) Iterate through the second. If the key doesn't exist in the result, add it. This works just fine even when add it means store this value against this key. The dict's value and the object's identity are both ignored, and you simply take the first one you find. Aside: I think the contrary behaviour is, well, contrary. It would be strange and disturbing to do this: for key in some_dict: if key == 0: print(found) print(some_dict[key]) and have the loop print found and then have the key lookup fail, but apparently that's how things work in Pike :-( I agree, that would be very strange and disturbing. I mentioned that aspect merely in passing, but the reason for the difference is not an oddity of key lookup, but a different decision about float and int: in Pike, 0 and 0.0 are not equal. (Nor are 1 and 1.0, in case you thought this was a weirdness of zero.) It's a debatable point; are we trying to say that all numeric types represent real numbers, and are equal if they represent the same real number? Or are different representations distinct, just as much as the string 0 is different from the integer 0? Pike took the latter approach. PHP took the former approach to its illogical extreme, that the string 0001E1 is equal to 10 (both strings). No, the dictionary definitely needs to use object equality to do its lookup, although I could well imagine an implementation that runs orders of magnitude faster when object identity can be used. I would say that Python can freely pick from the first two options you offered (either keep-first or keep-last), most likely the first one, and it'd make good sense. Your third option would be good for a few specific circumstances, but then you probably would also want the combination of {1:'a'} and {1:'a'} to be {1:['a','a']} for consistency. Okay, that's six variations. And no, I don't think the consistency argument is right -- the idea is that you can have multiple values per key. Since 'a' == 'a', that's only one value, not two. Well, it depends what you're doing with the merging of the dicts. But all of these extra ways to do things would be explicitly-named functions with much rarer usage (and quite possibly not part of the standard library, they'd be snippets shared around and put directly in application code). Raising an error would work, but is IMO unnecessary. I believe that's the only reasonable way for a dict union method to work. As the Zen says: In the face of ambiguity, refuse the temptation to guess. Since there is ambiguity which value should be associated with the key, don't guess. There's already ambiguity as to which of two equal values should be retained by the set. Python takes the first. Is that guessing? Is that violating the zen? I don't see a problem with the current set implementation, and I also don't see a problem with using that for dict merging. Object identity is a red herring. It would be perfectly valid for a Python implementation to create new instances of each element in the set union, assuming such creation was free of side-effects (apart from memory usage and time, naturally). set.union() makes no promise about the identity of elements, and it is defined the same way for languages where object identity does not exist (say, old-school Pascal). That still doesn't deal with the which type should the new object be. We're back to this question: What is the union of 0 and 0.0? {0} | {0.0} {0} {0.0} | {0} {0.0} Maybe Python could create a brand new object, but would it be an int or a float? The only way I could imagine this working is with a modified-set class that takes an object constructor, and passes every object through it. That way, you could have set(float) that coerces everything to float on entry, which would enforce what you're saying (even down to potentially creating a new object with a new id, though float() seems to return a float argument unchanged in CPython 3.3). Would that really help anything, though? Do we gain anything by not simply accepting, in the manner of Colonel Fairfax, the first that comes? ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3: dict dict.keys()
On Fri, Jul 26, 2013 at 12:57 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: [ snip lengthy explanation of sets ] The union operator ought to be symmetrical, a ∪ b should be identical to b ∪ a, but isn't. Another leaky abstraction. Right. I agree with all your theory, which is fine and good. If we had a set of real numbers, then each one would be both equal to and indistinguishable from any other representation of itself. But Python doesn't work with real numbers. It works with ints and floats and Fractions and Decimals and Guido-knows-what. (Sorry, I don't normally talk like that, but the expression begged to be said. :) ) So since Python already lets its abstraction leak a bit for usefulness, why not retain the exact same leak when working with a dict? A set is a dict with no values... a dict is a set with extra payload. They're given very similar literal notation; if they were meant to be more distinct, why was no alternative symbol used? (I love how a random side comment can become a topic of its own.) ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: RE Module Performance
On Fri, Jul 26, 2013 at 1:26 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Thu, 25 Jul 2013 14:36:25 +0100, Jeremy Sanders wrote: To conserve memory, Emacs does not hold fixed-length 22-bit numbers that are codepoints of text characters within buffers and strings. Rather, Emacs uses a variable-length internal representation of characters, that stores each character as a sequence of 1 to 5 8-bit bytes, depending on the magnitude of its codepoint[1]. For example, any ASCII character takes up only 1 byte, a Latin-1 character takes up 2 bytes, etc. We call this representation of text multibyte. Well, you've just proven what Vim users have always suspected: Emacs doesn't really exist. ... lolwut? ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Is it that easy to install Python ?
On Fri, Jul 26, 2013 at 2:36 AM, Irmen de Jong irmen.nos...@xs4all.nl wrote: On 25-7-2013 17:11, santiago.d...@caoba.fr wrote: Hi there, I never write any Python program but as a system administrator, I'm often asked to install python on Debian servers. I just finished downloading, configuring, making and installing. The binary is now installed in : /usr/local/Python-2.7.5/bin/python2.7 (the path is a deliberate administrator choice). Why didn't you use the Debian package instead? You now have installed an unsupported, untested custom built Python version on your server. Why not simply $ apt-get install python That'll do fine on Debian 7 (Wheezy, current stable). On Debian 6 (Squeeze, oldstable), that'll get you a 2.6 release IIRC. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: RE Module Performance
On Fri, Jul 26, 2013 at 3:18 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Fri, 26 Jul 2013 01:36:07 +1000, Chris Angelico wrote: On Fri, Jul 26, 2013 at 1:26 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Thu, 25 Jul 2013 14:36:25 +0100, Jeremy Sanders wrote: To conserve memory, Emacs does not hold fixed-length 22-bit numbers that are codepoints of text characters within buffers and strings. Rather, Emacs uses a variable-length internal representation of characters, that stores each character as a sequence of 1 to 5 8-bit bytes, depending on the magnitude of its codepoint[1]. For example, any ASCII character takes up only 1 byte, a Latin-1 character takes up 2 bytes, etc. We call this representation of text multibyte. Well, you've just proven what Vim users have always suspected: Emacs doesn't really exist. ... lolwut? JMF has explained that it is impossible, impossible I say!, to write an editor using a flexible string representation. Since Emacs uses such a flexible string representation, Emacs is impossible, and therefore Emacs doesn't exist. QED. Quad Error Demonstrated. I never got past the level of Canis Latinicus in debating class. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: RE Module Performance
On Fri, Jul 26, 2013 at 5:07 AM, wxjmfa...@gmail.com wrote: Let start with a simple string \textemdash or \texttendash sys.getsizeof('–') 40 sys.getsizeof('a') 26 Most of the cost is in those two apostrophes, look: sys.getsizeof('a') 26 sys.getsizeof(a) 8 Okay, that's slightly unfair (bonus points: figure out what I did to make this work; there are at least two right answers) but still, look at what an empty string costs: sys.getsizeof('') 25 Or look at the difference between one of these characters and two: sys.getsizeof('aa')-sys.getsizeof('a') 1 sys.getsizeof('––')-sys.getsizeof('–') 2 That's what the characters really cost. The overhead is fixed. It is, in fact, almost completely insignificant. The storage requirement for a non-ASCII, BMP-only string converges to two bytes per character. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Help
On Fri, Jul 26, 2013 at 6:06 AM, ty...@familyrobbins.com wrote: I'm a bit new to python and I'm trying to create a simple program which adds words and definitions to a list, and then calls them forward when asked to. One of the most important tidbits of information is: What version of Python are you using? print(Welcome to Digital Dictionary V1.0!\n\n) This looks like Python 3 style, though it would be valid Python 2 too. choice = input(Type 'Entry' to add a word to the Dictionary, 'Search' to find a word, and 'Exit' to quit. ) And I sincerely hope that this is Python 3, otherwise it would be doing some very strange and dangerous things. However, relying on us to guess isn't particularly safe, and works only for the major branch of 2.x vs 3.x. The actual version you're using will be helpful. while finish 1: if True: finish = 1 entry = 0 definition = 0 You're doing a lot with sentinel values, and it's getting a bit confusing. Your problem here seems to be that 'finish' is never reset, so the second time through, your loop is completely skipped. I recommend instead that you use 'break' to exit your loops. In a piece of somewhat amusing irony, you're here trying to implement a dictionary. Python has an object type of that name ('dict' is short for dictionary), which will be extremely useful here. I advise you to explore it - it'll replace your words[] and dictionary[] lists. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Script Hashplings
On Fri, Jul 26, 2013 at 11:37 AM, Devyn Collier Johnson devyncjohn...@gmail.com wrote: On 07/25/2013 09:54 AM, MRAB wrote: On 25/07/2013 14:42, Devyn Collier Johnson wrote: If I execute a Python3 script with this haspling (#!/usr/bin/python3.3) and Python3.3 is not installed, but Python3.2 is installed, would the script still work? Would it fall back to Python3.2? Why don't you try it? I hope Dihedral is listening. I would like to see another response from HIM. Good point, but if it falls back to Python3.2, how would I know? Plus, I have Python3.3, 3.2, and 2.7 installed. I cannot uninstall them due to dependencies. Easy: #!/usr/bin/python3.3 import sys print(sys.version) Now run that on lots of different computers (virtual computers work well for this). ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Script Hashplings
On Fri, Jul 26, 2013 at 2:53 PM, MRAB pyt...@mrabarnett.plus.com wrote: If you want to test what would happen if that version wasn't installed, set the shebang line to a future version, such as Python 3.4. I doubt you have that installed! :-) Be careful, some people DO have a python3.4 binary :) Go for 3.5 for a bit more reliability. rosuav@sikorsky:~$ python3.4 3.4.0a0 (default:da7d97ca1ef6, Jul 13 2013, 14:05:08) [GCC 4.7.2] ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: dump a multi dimensional dictionary
On Fri, Jul 26, 2013 at 9:21 PM, cerr ron.egg...@gmail.com wrote: mylist = [] mydict = {} mylist = '1','2' Side point: mylist is no longer a list, it's a tuple. I don't think pickle has problems with tuples, but it's worth noting that difference. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Cross-Platform Python3 Equivalent to notify-send
On Sat, Jul 27, 2013 at 1:22 PM, Devyn Collier Johnson devyncjohn...@gmail.com wrote: That really sucks. I was hoping Python had some way of doing that. All that it needs to do is display a little box at one of the corners of the screen. I thought someone would have implemented something by now. Thank you anyway. Despite the best efforts of a pretty talented core dev team, Python is not yet capable of magic :) If you browse the python-dev archives, you'll see how much of a nightmare cross-platform compatibility can be (eg the recent discussion on cloexec and passing file descriptors to subprocesses); often, what you might think (from a user's point of view) is fairly trivial will turn out to be quite tricky. That said, though, a lot of GUI toolkits will have a means for you to highlight a window. In GTK, it's called present (as in, Lord User, may I present Sir Window and Mrs Window?). There may be window managers that don't support the feature (and there are certainly those that let the user disable it, which you should respect), but AFAIK all of them should at least accept the command. http://www.pygtk.org/docs/pygtk/class-gtkwindow.html#method-gtkwindow--present So your best bet may be to simply create yourself a small window, then present it. On Windows XP, I think that'll flash the window in the task bar, which is usually enough highlight. On my Debian Wheezy with Xfce, it brings the window to the top of the Z-order, and optionally moves it to the current workspace (user's option, NOT program's). ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Understanding other people's code
On Sat, Jul 27, 2013 at 2:13 PM, Albert van der Horst alb...@spenarnc.xs4all.nl wrote: If the code is really tidy, it is possible to understand a function using only the *documentation* (not the code itself) of any function or data it uses. I'd broaden that slightly to the function's signature, which consists of the declaration line and any associated comments (which in Python should be in the docstring). The docstring kinda violates this concept, but what I generally try to explain is that you should be able to understand a function without reading any of the indented content. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Critic my module
On Sat, Jul 27, 2013 at 2:19 PM, Devyn Collier Johnson devyncjohn...@gmail.com wrote: About the aliases, I have tried setting pwd() as an alias for os.getcwd(), but I cannot type pwd() and get the desired output. Instead, I must type pwd. I tested this in Guake running Python3.3. os.getcwd() '/home/collier' pwd = os.getcwd() pwd() Try: pwd = os.getcwd Otherwise you're calling it immediately. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Critic my module
On Sat, Jul 27, 2013 at 3:53 PM, Devyn Collier Johnson devyncjohn...@gmail.com wrote: Would a Python3 game module be more useful? I plan to make a function that rolls a die and prints the output (You got a 5) and other similar random games. Taking someone else's module and learning to use it has a cost. Plus there's licensing and other issues (if you release your library GPL3, you force anyone who uses it to do the same - though I'm not 100% sure how that goes with Python modules, since they're not 'linked' the way others are), not to mention the time spent finding out that your module even exists. For a module to be useful, all those costs combined have to be lower than the cost of just writing the code yourself when you need it. On the other hand, it's VERY common for a programmer to have his own *personal* utilities module. Stuff stuff in there whenever you think it'll be useful, import it into your applications, et voila. The bar is way lower for that. Your dice-roller is perhaps useful to yourself, without being worth the effort for someone else to learn. Plus, you get to decide exactly how much flexibility you need. Do you only ever need to roll a single six-sider at a time? Then don't bother implementing stuff like I did for Minstrel Hall, where we play Dungeons and Dragons: [ROLL] Rosuav (Gaston crit dmg) rolls 4d8: 7, 3, 6, 1, totalling 17. [ROLL] Rosuav (Gaston crit dmg) rolls d6: 1 (elec) [ROLL] Rosuav (Gaston crit dmg) rolls d10: 6 (burst) [ROLL] Rosuav (Gaston crit dmg) rolls d8: 8 (thunder) [ROLL] For 4d8+12 STR+10 ench+4 specialization+d6 elec+d10 burst+d8 thunder+20 PA, Rosuav (Gaston crit dmg) totals: 78 Okay, that's a somewhat extreme example, but it's common to roll damage as, say, 2d6+13, which means two six-sided dice plus a constant 13. (This will result in damage between 15 and 25, with 20 being significantly more likely than either of the extremes.) And even that is probably a lot more complicated than you'll need for your purposes... yet for a DD system, a dice roller that can only do a single d6 at a time is utterly useless. There's actually a dice roller module on PyPI already [1]; and it's probably of no use to you, because it's as complicated as I described above. I personally wouldn't use it, though, because I can't see a license - which comes back to the issues I listed above. Again, not an issue for your own code; if it's your copyright, you can do with it as you wish. [1] https://pypi.python.org/pypi/diceroll ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Cross-Platform Python3 Equivalent to notify-send
On Sat, Jul 27, 2013 at 4:59 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Sat, 27 Jul 2013 08:22:00 -0400, Devyn Collier Johnson wrote: That really sucks. I was hoping Python had some way of doing that. All that it needs to do is display a little box at one of the corners of the screen. I thought someone would have implemented something by now. Thank you anyway. If it's that simple, how about you do it? Won't take you more than, oh, ten minutes, right? *wink* Don't underestimate the difficulty of trivial code when it has to work on two dozens different platforms with different capabilities That doesn't mean the question shouldn't be asked, of course. Steven isn't (at least, I don't think he is!) scorning you for asking. Sometimes the response is quite the opposite - that it's so utterly trivial that there's no NEED for a library function! Never hurts to throw the question out there... ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: python import module question
On Sun, Jul 28, 2013 at 12:15 AM, syed khalid sy...@pacificloud.com wrote: Syedk@syedk-ThinkPad-T410:~/shogun-2.0.0/src/interfaces/cmdline_static$ shogun | more This implies that you have something called 'shogun', without an extension, in your $PATH. Where is the actual script? You may need to install it by a quite different method, to make it available in Python. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: FSR and unicode compliance - was Re: RE Module Performance
On Sun, Jul 28, 2013 at 4:52 PM, Michael Torrie torr...@gmail.com wrote: Is my understanding of these things wrong? No, your understanding of those matters is fine. There's just one area you seem to be misunderstanding; you appear to think that jmf actually cares about logical argument. I gave up on that theory a long time ago, and now I respond for the benefit of those reading, rather than jmf himself. I've also given up on trying to figure out what he actually wants; the nearest I can come up with is that he's King Gama-esque - that he just wants to complain. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: [Savoynet] GS Opera Co: Pirates of Penzance
On Sun, Jul 28, 2013 at 6:36 PM, David Patterson david.w.patter...@btopenworld.com wrote: By the way, Chris, I think the book that Ruth brought on was probably supposed to be Debretts Peerage. I couldn't see the cover clearly but it would have been a more logical choice in view of the circumstances. Sure. Makes no difference what the book actually is, and I'm not someone who knows these things (people show me caricatures and I have no idea who they're of, largely due to not watching TV). I've edited the post to say Debrett's Peerage, thanks for the tip. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: FSR and unicode compliance - was Re: RE Module Performance
On Sun, Jul 28, 2013 at 6:36 PM, Terry Reedy tjre...@udel.edu wrote: I posted about a week ago, in response to Chris A., a method by which lookup for UTF-16 can be made O(log2 k), or perhaps more accurately, O(1+log2(k+1)), where k is the number of non-BMP chars in the string. Which is an optimization choice that favours strings containing very few non-BMP characters. To justify the extra complexity of out-of-band storage, you would need to be working with almost exclusively the BMP. That would drastically improve jmf's microbenchmarks which do exactly that, but it would penalize strings that are almost exclusively higher-codepoint characters. Its quality, then, would be based on a major survey of string usage: are there enough strings with mostly-BMP-but-a-few-SMP? Bearing in mind that pure BMP is handled better by PEP 393, so this is only of value when there are actually those mixed strings. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: RE Module Performance
On Sun, Jul 28, 2013 at 7:19 PM, Joshua Landau jos...@landau.ws wrote: On 28 July 2013 09:45, Antoon Pardon antoon.par...@rece.vub.ac.be wrote: Op 27-07-13 20:21, wxjmfa...@gmail.com schreef: utf-8 or any (utf) never need and never spend their time in reencoding. So? That python sometimes needs to do some kind of background processing is not a problem, whether it is garbage collection, allocating more memory, shufling around data blocks or reencoding a string, that doesn't matter. If you've got a real world example where one of those things noticeably slows your program down or makes the program behave faulty then you have something that is worthy of attention. Somewhat off topic, but befitting of the triviality of this thread, do I understand correctly that you are saying garbage collection never causes any noticeable slowdown in real-world circumstances? That's not remotely true. If it's done properly, garbage collection shouldn't hurt the *overall* performance of the app; most of the issues with GC timing are when one operation gets unexpectedly delayed for a GC run (making performance measurement hard, and such). It should certainly never cause your program to behave faultily, though I have seen cases where the GC run appears to cause the program to crash - something like this: some_string = buggy_call() ... gc() ... print(some_string) The buggy call mucked up the reference count, so the gc run actually wiped the string from memory - resulting in a segfault on next usage. But the GC wasn't at fault, the original call was. (Which, btw, was quite a debugging search, especially since the function in question wasn't my code.) ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: [Savoynet] GS Opera Co: Pirates of Penzance
On Mon, Jul 29, 2013 at 12:49 AM, Ethan Furman et...@stoneleaf.us wrote: On 07/28/2013 10:57 AM, Chris Angelico wrote: . . . Okay, how did you get confused that this was a Python List question? ;) *sigh* Because I still haven't gotten around to switching mail clients to one that has a Reply-List feature. The post I was replying to was on Savoynet, which is about Gilbert Sullivan. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: programming course
On Sat, Jul 27, 2013 at 1:28 PM, aliencat...@gmail.com wrote: Hi, A good step by step easy book on Python is: Start Here: Python 3x Programming Made Fun and Easier, at http://www.quantum-sight.com This is a Usenet group and a mailing list, not a web forum. You do not need to dig up a dozen ancient threads in order to advertise your wares. And by the way, it's courteous to be up-front about (1) your connection with what you're recommending, and (2) the fact that it's a pay-for book. One post, in a thread of its own, announcing the release of the book, would be appropriate and on-topic. Just please don't reply to heaps of old threads with commercial proposals :) ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: RE Module Performance
On Sun, Jul 28, 2013 at 11:14 PM, Joshua Landau jos...@landau.ws wrote: GC does have sometimes severe impact in memory-constrained environments, though. See http://sealedabstract.com/rants/why-mobile-web-apps-are-slow/, about half-way down, specifically http://sealedabstract.com/wp-content/uploads/2013/05/Screen-Shot-2013-05-14-at-10.15.29-PM.png. The best verification of these graphs I could find was https://blog.mozilla.org/nnethercote/category/garbage-collection/, although it's not immediately clear in Chrome's and Opera's case mainly due to none of the benchmarks pushing memory usage significantly. I also don't quite agree with the first post (sealedabstract) because I get by *fine* on 2GB memory, so I don't see why you can't on a phone. Maybe IOS is just really heavy. Nonetheless, the benchmarks aren't lying. The ultimate in non-managed memory (the opposite of a GC) would have to be the assembly language programming I did in my earlier days, firing up DEBUG.EXE and writing a .COM file that lived inside a single 64KB segment for everything (256-byte Program Segment Prefix, then code, then initialized data, then uninitialized data and stack), crashing the computer with remarkable ease. Everything higher level than that (even malloc/free) has its conveniences and its costs, usually memory wastage. If you malloc random-sized blocks, free them at random, and ensure that your total allocated size stays below some limit, you'll still eventually run yourself out of memory. This is unsurprising. The only question is, how bad is the wastage and how much time gets devoted to it? ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: FSR and unicode compliance - was Re: RE Module Performance
On Mon, Jul 29, 2013 at 12:43 PM, wxjmfa...@gmail.com wrote: Le dimanche 28 juillet 2013 22:52:16 UTC+2, Steven D'Aprano a écrit : 3.2 timeit.timeit(r = dir(list)) 22.300465007102908 3.3 timeit.timeit(r = dir(list)) 27.13981129541519 3.2: len(dir(list)) 42 3.3: len(dir(list)) 45 Wonder if that might maybe have an impact on the timings. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: FSR and unicode compliance - was Re: RE Module Performance
On Mon, Jul 29, 2013 at 3:20 PM, wxjmfa...@gmail.com wrote: c:\python32\pythonw -u timitmod.py 15.258061416225663 Exit code: 0 c:\Python33\pythonw -u timitmod.py 17.052203122286194 Exit code: 0 len(dir(C)) Did you even think to check that before you posted timings? ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Unexpected results comparing float to Fraction
On Mon, Jul 29, 2013 at 5:09 PM, MRAB pyt...@mrabarnett.plus.com wrote: I'm surprised that Fraction(1/3) != Fraction(1, 3); after all, floats are approximate anyway, and the float value 1/3 is more likely to be Fraction(1, 3) than Fraction(6004799503160661, 18014398509481984). At what point should it become Fraction(1, 3)? Fraction(0.3) Fraction(5404319552844595, 18014398509481984) Fraction(0.33) Fraction(5944751508129055, 18014398509481984) Fraction(0.333) Fraction(5998794703657501, 18014398509481984) Fraction(0.333) Fraction(6004798902680711, 18014398509481984) Fraction(0.33) Fraction(6004799502560181, 18014398509481984) Fraction(0.3) Fraction(6004799503160061, 18014398509481984) Fraction(0.3) Fraction(6004799503160661, 18014398509481984) Rounding off like that is a job for a cool library function (one of which was mentioned on this list a little while ago, I believe), but not IMO for the Fraction constructor. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: What do you do when a library is outdated?
On Mon, Jul 29, 2013 at 5:14 PM, Matt mattgrav...@gmail.com wrote: I'm fairly new to python but have experience in other languages. What do you generally do when a library is outdated? I asked a question on a few forums and everyone has been pointing me to Mechanize, but it will not work with 3.3 What do you do? Depends what you mean by outdated. Lots of things don't _need_ to be up-to-date to be useful, and often, using the very latest version of something just makes it hard to deploy (look at Debian and Red Hat, both of which maintain support for a long time). If there's actually a problem with something not being able to cope with current systems (eg something that's designed to communicate with Windows and can't talk to Win 8), then you go looking for a replacement package that can use the latest, or possibly you write it yourself. But my crystal ball tells me you're not asking about that, but rather about a module that was written for Python 2 and hasn't been ported to Python 3. (Usually there won't be other issues; if something breaks between Py3.2 and Py3.3, it'll be easily fixed.) There are a few options: 1) Talk to the author/maintainer. Explain that you want to use his/her code with Python 3 but can't. Often, the only reason something isn't ported is because of a perceived lack of interest. 2) Run the module code through the 2to3 utility. That might even be all you need to do. 3) Port it yourself. Start with 2to3, and then work through any problems you have. I would recommend getting to know the module on Python 2 first, so you have a chance of knowing what it ought to be doing. You aren't the first to inquire about this. A quick Google search for 'mechanize python 3' brought this up: http://web.cecs.pdx.edu/~adevore/mechanize/ Also, poking around a bit shows recommendations for the lxml and requests modules, which may be able to do what you want. So to answer your general question: Work, sometimes lots of work (though not always). But for Mechanize specifically, Requests may be your best bet. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Unexpected results comparing float to Fraction
On Mon, Jul 29, 2013 at 5:40 PM, Ian Kelly ian.g.ke...@gmail.com wrote: On Mon, Jul 29, 2013 at 10:20 AM, Chris Angelico ros...@gmail.com wrote: On Mon, Jul 29, 2013 at 5:09 PM, MRAB pyt...@mrabarnett.plus.com wrote: I'm surprised that Fraction(1/3) != Fraction(1, 3); after all, floats are approximate anyway, and the float value 1/3 is more likely to be Fraction(1, 3) than Fraction(6004799503160661, 18014398509481984). At what point should it become Fraction(1, 3)? At the point where the float is exactly equal to the value you get from the floating-point division 1/3. If it's some other float then the user didn't get there by entering 1/3, so it's not worth trying to pretend that they did. We do a similar rounding when formatting floats to strings, but in that case one only has to worry about divisors that are powers of 10. I imagine it's going to take more time to find the correct fraction when any pair of relatively prime integers can be a candidate numerator and denominator. I imagine it is, and that's where the problem comes in. The true value is somewhere between (X-0.5)/2**n and (X+0.5)/2**n, or whatever the actual range is, and finding a nice fraction in that range isn't an instant and direct translation. It's a useful feature, but not IMO necessary for the constructor. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Bitwise Operations
On Tue, Jul 30, 2013 at 12:34 AM, Devyn Collier Johnson devyncjohn...@gmail.com wrote: I understand the symbols. I want to know how to perform the task in a script or terminal. I have searched Google, but I never saw a command. Typing 101 010 or x = (int(101, 2) int(010, 2)) only gives errors. Your problem here isn't in the bitwise operators, but in your binary literals. Python deliberately and consciously rejects 010 as a literal, because it might be interpreted either as decimal 10, or as octal (decimal 8), the latter being C's interpretation. Fixing that shows up a more helpful error: x = (int(101, 2) int(10, 2)) Traceback (most recent call last): File pyshell#74, line 1, in module x = (int(101, 2) int(10, 2)) TypeError: int() can't convert non-string with explicit base The int() call isn't doing what you think it is, because 101 is already an int. The obvious solution now is to quote the values: x = (int(101, 2) int(010, 2)) x 0 But there's an easier way: x = 0b101 0b010 x 0 I think that might do what you want. Also check out the bin() function, which will turn an integer into a string of digits. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: timing issue: shutil.rmtree and os.makedirs
On Mon, Jul 29, 2013 at 8:16 PM, Tim jtim.arn...@gmail.com wrote: My intent is to pass it a directory name or path and if it exists, use shutil.rmtree to remove whatever is there (if it isn't a directory, try to unlink it); then use os.makedirs to create a new directory or path: def make_clean_dir(directory): if os.path.exists(directory): if os.path.isdir(directory): shutil.rmtree(directory) else: os.unlink(directory) os.makedirs(directory) The last bit of the traceback is: File /develop/myproject/helpers/__init__.py, line 35, in make_clean_dir os.makedirs(directory) File /usr/local/lib/python2.7/os.py, line 157, in makedirs mkdir(name, mode) OSError: [Errno 17] File exists: '/users/tim/testing/testing_html' The directory 'testing_html' existed when I executed the function; First thing I'd check is: Did rmtree succeed? Try removing the makedirs and test it again; then, when your process has completely finished, see if the directory is there. If it is, the problem is in rmtree - for instance: * You might not have permission to remove everything * There might be a messed-up object in the file system * If the directory is a remote share mount point, the other end might have lied about the removal * Something might have been created inside the directory during the removal * Myriad other possibilities As I understand rmtree's docs, any errors *that it detects* will be raised as exceptions (since you haven't told it to suppress or handle them), but possibly there's an error that it isn't able to detect. Worth a test, anyhow. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Bitwise Operations
On Tue, Jul 30, 2013 at 12:48 AM, Devyn Collier Johnson devyncjohn...@gmail.com wrote: Now here is something that confuses me, the binary numbers are numbers not strings, so why are they put in quotes as if they are strings? They aren't numbers at that point, they're strings of digits. A number is represented in various forms: 1234, 0x4d2, 0o2322, 0b10011010010 (1234, 1234, 1234, 1234) The two-argument form of int() takes a string of digits and a base: int(ya,36) 1234 In base 36, y and a are digits. But in Python's base syntax, you can't use them that way, so there's no way to render the number other than as a string. For what you're doing, I think the 0b notation is the best. It's an int literal written in binary. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Pyglet on Python3.x, problems
On Tue, Jul 30, 2013 at 1:47 AM, John Ladasky john_lada...@sbcglobal.net wrote: I'm getting one problem. After a few tests run, I can't close a window. I am normally closing each interactive test with the ESC key. But when that fails I try clicking with the mouse. This also fails. This broken behavior appears to be triggered when the window created by pyglet overlaps my terminal window and thereby steals the focus. Any idea why that might be happening? When you say steals the focus, what exactly do you mean? Do the windows normally get created without focus, but occasionally focus is set to that window? Seems odd. If that's the case, is there any difference if you click outside the window (eg on your terminal) and then back in? Maybe there's something happening on gotfocus that should happen on create. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: SQLite logic error or missing database
On Tue, Jul 30, 2013 at 3:02 AM, CM cmpyt...@gmail.com wrote: If I try additional commits in that same instance of my app being open, it gives me the same error every time. If I close the app and re-open it, it does not give me this error, with the same or very similar data being written in the same routines. So I know that the code as written is correct (a significant--greater than 90%?--of the time I don't see this error). Is it a race between two concurrent instances of the app? I don't know sqlite but that seems like something to consider, at least. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: timing issue: shutil.rmtree and os.makedirs
On Tue, Jul 30, 2013 at 2:10 PM, Tim jtim.arn...@gmail.com wrote: hmm, now that you mention it, this is executing on a remote box with access to the same file system my local calling program is on. That is, there is a local call to an intermediate script that connects to a socket on the remote where the above program actually runs, but the file system is the same place for both local and remote. But even so, since the script that does the rmtree and mkdir is running on the same machine (even though it's remote), I would think the mkdir couldn't execute until the rmtree was completely finished. Hmm. What system is used for the file system sharing? I know quite a few of them lie about whether something's been completely done or not. Can you use inotify to tell you when the directory's been deleted? Seems stupid though. Worst case, all you need is a quick loop at the bottom, eg: for delay in 100,300,600,1000,3000,5000,1: if not os.path.exists(directory): break sleep(delay) That'll sleep a maximum of 20 seconds, tune as required. Of course, if there's a way to tune the FS to guarantee that the removal blocks correctly, that would be way better than sleep()! ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: RE Module Performance
On Tue, Jul 30, 2013 at 3:01 PM, wxjmfa...@gmail.com wrote: I am pretty sure that once you have typed your 127504 ascii characters, you are very happy the buffer of your editor does not waste time in reencoding the buffer as soon as you enter an €, the 125505th char. Sorry, I wanted to say z instead of euro, just to show that backspacing the last char and reentering a new char implies twice a reencoding. You're still thinking that the editor's buffer is a Python string. As I've shown earlier, this is a really bad idea, and that has nothing to do with FSR/PEP 393. An immutable string is *horribly* inefficient at this; if you want to keep concatenating onto a string, the recommended method is a list of strings that gets join()d at the end, and the same technique works well here. Here's a little demo class that could make the basis for such a system: class EditorBuffer: def __init__(self,fn): self.fn=fn self.buffer=[open(fn).read()] def insert(self,pos,char): if pos==0: # Special case: insertion at beginning of buffer if len(self.buffer[0])1024: self.buffer.insert(0,char) else: self.buffer[0]=char+self.buffer[0] return for idx,part in enumerate(self.buffer): l=len(part) if posl: pos-=l continue if posl: # Cursor is somewhere inside this string splitme=self.buffer[idx] self.buffer[idx:idx+1]=splitme[:pos],splitme[pos:] l=pos # Cursor is now at the end of this string if l1024: self.buffer[idx:idx+1]=self.buffer[idx],char else: self.buffer[idx]+=char return raise ValueError(Cannot insert past end of buffer) def __str__(self): return ''.join(self.buffer) def save(self): open(fn,w).write(str(self)) It guarantees that inserts will never need to resize more than 1KB of text. As a real basis for an editor, it still sucks, but it's purely to prove this one point. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: timing issue: shutil.rmtree and os.makedirs
On Tue, Jul 30, 2013 at 3:07 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Tue, 30 Jul 2013 14:27:10 +0100, Chris Angelico wrote: for delay in 100,300,600,1000,3000,5000,1: if not os.path.exists(directory): break sleep(delay) That'll sleep a maximum of 20 seconds, tune as required. Actually, that will sleep a maximum of 5.55 hours, and a minimum of 1.7 minutes (assuming the directory doesn't get deleted instantaneously). time.sleep() takes an argument in seconds. LOL! Whoops. That's what I get for not checking my docs. This is why we have public responses, my errors can be caught by someone else. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Python script help
On Tue, Jul 30, 2013 at 3:49 PM, cool1...@gmail.com wrote: Hello, I am looking for a script that will be able to search an online document (by giving the script the URL) and find all the downloadable links in the document and then download them automatically. I appreciate your help, Thank you. baseurl = http://; options = . os.system(wget +options+ +baseurl) Sometimes the right tool for the job isn't Python. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Python script help
On Tue, Jul 30, 2013 at 4:49 PM, cool1...@gmail.com wrote: I know but I think using Python in this situation is good...is that the full script? That script just drops out to the system and lets wget do it. So don't bother with it. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Share Code: Laptop Lid State
On Tue, Jul 30, 2013 at 3:06 PM, Devyn Collier Johnson devyncjohn...@gmail.com wrote: Aloha everyone! I attached a script that I thought I could share with everyone for your help. This Python3 script only works on Unix systems. It prints the current state of the lid. This can be used to make a script that performs some action when the lid is closed or open. The script is licensed under LGPLv3 and I will soon upload it to my Launchpad account. Enjoy! There's... no Python code in that. Why not simply open(/proc/acpi/button/lid/LID/state) and read from it, instead of using cat and awk? ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: timing issue: shutil.rmtree and os.makedirs
On Tue, Jul 30, 2013 at 4:37 PM, Tim jtim.arn...@gmail.com wrote: Argg, this isn't the first time I've had troubles with the file system. This is FreeBSD and NFS. I will code up a progressive delay as you mentioned (with Steve's correction). I've used several different networked file systems, including NetBIOS/NetBEUI/SMB/Samba/etc, sshfs/cifs, and nfs. Not one of them feels as clean as I'd like, though sshfs comes closest. There always seem to be hacks around. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Python script help
On Tue, Jul 30, 2013 at 5:10 PM, cool1...@gmail.com wrote: What if I want to use only Python? is that possible? using lib and lib2? -- http://mail.python.org/mailman/listinfo/python-list Sure, anything's possible. And a lot easier if you quote context in your posts. But why do it? wget is exactly what you need. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: RE Module Performance
On Tue, Jul 30, 2013 at 8:09 PM, wxjmfa...@gmail.com wrote: Matable, immutable, copyint + xxx, bufferint, O(n) Yes, but conceptualy the reencoding happen sometime, somewhere. The internal ucs-2 will never automagically be transformed into ucs-4 (eg). But probably not on the entire document. With even a brainless scheme like I posted code for, no more than 1024 bytes will need to be recoded at a time (except in some odd edge cases, and even then, no more than once for any given file). And do not forget, in a pure utf coding scheme, your char or a char will *never* be larger than 4 bytes. sys.getsizeof('a') 26 sys.getsizeof('\U000101000') 48 Yeah, you have a few odd issues like, oh, I dunno, GC overhead, reference count, object class, and string length, all stored somewhere there. Honestly jmf, if you want raw assembly you know where to get it. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Share Code: Laptop Lid State
On Wed, Jul 31, 2013 at 4:05 AM, Devyn Collier Johnson devyncjohn...@gmail.com wrote: On 07/30/2013 12:00 PM, Chris Angelico wrote: On Tue, Jul 30, 2013 at 3:06 PM, Devyn Collier Johnson devyncjohn...@gmail.com wrote: Aloha everyone! I attached a script that I thought I could share with everyone for your help. This Python3 script only works on Unix systems. It prints the current state of the lid. This can be used to make a script that performs some action when the lid is closed or open. The script is licensed under LGPLv3 and I will soon upload it to my Launchpad account. Enjoy! There's... no Python code in that. Why not simply open(/proc/acpi/button/lid/LID/state) and read from it, instead of using cat and awk? ChrisA The script returns either open or close instead of printing the whole file contents. I thought some people would find it useful (^_^;). Not having a Linux laptop handy I can't test it, but my point is that text parsing of that nature can be done directly by Python. You can snip out the open or close easily with one, maybe two lines of code at the most, and that without dropping to a shell, a completely superfluous 'cat' process, and awk. You then capture the STDOUT of that and promptly print it to your own STDOUT. Why not either do it truly in Python, or do it directly in a shell script and skip the Python interpreter? ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: RE Module Performance
On Wed, Jul 31, 2013 at 6:45 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: if you care about minimizing every possible byte, you should use a low-level language like C. Then you can give every character 21 bits, and be happy that you don't waste even one bit. Could go better! Since not every character has been assigned, and some are specifically banned (eg U+FFFE and U+D800-U+DFFF), you could cut them out of your representation system and save memory! ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Repository of non-standard modules.
On Wed, Jul 31, 2013 at 11:53 AM, Gabor Urban urbang...@gmail.com wrote: Hi, I am to start a new free-time project in the next couple of weeks. I am ready to use open accessible Python modules not wanting to reinvent the weel :-) Is there any repository where I can find Python modules not being part of the standard distribution? Check out the Python Package Index: http://pypi.python.org/ Lots of stuff there, not all of it actively developed. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: import syntax
On Mon, Jul 29, 2013 at 11:37 PM, Joshua Landau jos...@landau.ws wrote: 2d) Realise that the slow part is not what you thought it was This step is mandatory. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Script that converts between indentation and curly braces in Python code
On Wed, Jul 31, 2013 at 1:39 PM, Beth McNany beth.mcn...@gmail.com wrote: ok, ok, if you *really* want it, you could keep track of how many leading spaces there are (you are using spaces, right?), and insert an open bracket where that number increases and a closing bracket where it decreases. Of course, as with all parsing problems, this is oversimplification... if you have multi-line statements you'll need to check for those (if line starts with or ''', ends with \, or if there's an unclosed bracket or paren...) - but that'd be a reasonable place to start if you're only doing short code snippets. Since the braced version won't run anyway, how about a translation like this: def foo(): print(Hello, world!) for i in range(5): foo() return 42 -- 0-def foo(): 4-print(Hello, 0-world!) 4-for i in range(5): 8-foo() 4-return 42 That's a simple translation that guarantees safe round-tripping, and you can probably do it with a one-liner fwiw... let's see... # Assumes spaces OR tabs but not both # Can't see an easy way to count leading spaces other than: # len(s)-len(s.lstrip()) code = '\n'.join(%d-%s%(len(s)-len(s.lstrip()),s.lstrip()) for s in code.split('\n')) # Recreates with spaces, choose tabs for the multiplication if you prefer code = '\n'.join(' '*int(s.split('-',1)[0])+s.split('-',1)[1] for s in code.split('\n')) These would be better done in a couple of lines, but I like doing one-liners just for fun. :) ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Script that converts between indentation and curly braces in Python code
On Wed, Jul 31, 2013 at 3:07 PM, Rotwang sg...@hotmail.co.uk wrote: # Assumes spaces OR tabs but not both # Can't see an easy way to count leading spaces other than: # len(s)-len(s.lstrip()) How about len(s.expandtabs()) - len(s.lstrip()) instead? Still comes to the same thing. The only diff is that tabs get treated as eight spaces instead of one (and the bug that a tab elsewhere in the line will result in indentation, which is fixed by lstripping the tab-expanded form). It won't perfectly round-trip with a mixture of tabs and spaces; as it is, you can pick one or the other and run with it. Anyway, the main point is that indentation will work. Sure you might have ugly narrow code, but it'll run with one-space indents. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: RE Module Performance
On Wed, Jul 31, 2013 at 9:15 PM, wxjmfa...@gmail.com wrote: ... char never consumes or requires more than 4 bytes ... The integer 5 should be able to be stored in 3 bits. sys.getsizeof(5) 14 Clearly Python is doing something really horribly wrong here. In fact, sys.getsizeof needs to be changed to return a float, to allow it to more properly reflect these important facts. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Editing tabular data [was: PEP8 79 char max]
On Wed, Jul 31, 2013 at 8:02 PM, Grant Edwards invalid@invalid.invalid wrote: On 2013-07-31, Skip Montanaro s...@pobox.com wrote: I don't understand. That just moves them to a different file -- doesn't it? You've still got to deal with editing a large table of data (for example when I want to add instructions to your assembler). My guess is it would be more foolproof to edit that stuff with a spreadsheet. Many years ago, I worked with somebody who used a spreadsheet like that. I tried it and found it to be way too cumbersome. The overhead involved of putting tables in to slew of different files and starting up LibreOffice to edit/view them is huge compared to just editing them with emacs in a file along with the source code. Maybe my computer is too old/slow. Maybe it's just due to how bad I am at Excel/LibreOffice... I'm glad someone else feels that way! At work, we have a number of CSV files (at my boss's insistence; I would much rather they be either embedded in the source, or in some clearer and simpler format) which I like to manipulate in SciTE, rather than OO/LibreOffice. (I'll not distinguish those two. Far as I'm concerned, they're one product with two names.) My boss can't understand why I do this. I can't understand why he objects to having to edit code files to alter internal data. I have pointed him to [1] but to no avail. The one thing I would do, though, is align with tabs rather than spaces. That gives you an 8:1 (if you keep your tabs at eight, which I do) improvement in maintainability, because edits that don't cross a boundary don't require fiddling with the layout. [1] http://thedailywtf.com/Articles/Soft_Coding.aspx ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Using system python vs. updated/current version
On Wed, Jul 31, 2013 at 7:35 PM, memilanuk memila...@gmail.com wrote: Also... in some places in the 'Net I see references to installing everything 'locally' via pip, etc. in virtualenvs and not touching the system installed version of python... yet most linux distros seem to have many/most such packages available in their package repos, which seems like it'd be easier to install via the package manager and let it keep things updated. Could someone touch on what they feel the pros and cons would be either way? I personally like to compile some things from source (CPython, Pike, etc - though not everything, I use a prepackaged PostgreSQL, for instance). There's no harm in installing a new CPython on a Linux box - just type 'sudo make altinstall' (or however you become root), and it'll give you a binary called python3.4 or whatever version, without touching your system Python. That lets you run as many versions as you like, in parallel, though you may have issues running 3.3.0 and 3.3.2 (but there should be no reason to do so - just use 3.3.2). ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Oddity with 'yield' as expression - parentheses demanded
Was playing around with yield inside a lambda and ran into a distinct oddity. Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit (Intel)] on win32 foo=lambda x: yield(x) SyntaxError: invalid syntax def foo(x): return yield(x) SyntaxError: invalid syntax def foo(x): x=yield(x) return x foo=lambda x: (yield x) If yield is an expression, why does it need extra parentheses around it? [1] suggest that (yield x) is an expression that can elide the parens only when it is the sole expression on the right hand side of an assignment statement, and presumably there's a similar rule allowing the non-expression form yield x to omit the parens. Why is this so? Why is it not simply an expression on its own? [1] http://docs.python.org/3.3/reference/expressions.html#grammar-token-yield_expression ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Unexpected results comparing float to Fraction
On Thu, Aug 1, 2013 at 7:20 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: I know this, and that's not what surprised me. What surprised me was that Fraction converts the float to a fraction, then compares. It surprises me because in other operations, Fractions down-cast to float. Adding a float to a Fraction converts the Fraction to the nearest float, then adds: py 1/3 + Fraction(1, 3) 0. Hmm. This is the one that surprises me. That would be like the addition of a float and an int resulting in an int (at least in C; in Python, where floats have limited range and ints have arbitrary precision, the matter's not quite so clear-cut). Perhaps this needs to be changed? ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Unexpected results comparing float to Fraction
On Thu, Aug 1, 2013 at 10:44 AM, Oscar Benjamin oscar.j.benja...@gmail.com wrote: The real dividing line between {int, Fraction} and {float, Decimal, complex} is about (in)exactness. The numeric tower ensures the property that inexactness is contagious which I think is a good thing. *nods slowly* That does make sense, albeit a little oddly. So when you're sorting out different integer sizes (C's short/int/long, Py2's int/long), you go to the better one, but when working with inexact types, you go to the worse one. But I can see the logic in it. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: How to use Python to open Unread message(s) in specific Outlook folder, clicking a hyperlink within the email message to a secure login window, entering password to download .csv file, run Excel m
On Thu, Aug 1, 2013 at 6:31 PM, hamberg...@gmail.com wrote: Details Every morning I receive three emails (three different subject lines) in the same Sub-Folder (POINT) under Folder (Reports) in my Inbox in Outlook. Each email has two secure hyperlinks, one provides me with a site to register and the other provides a window for me to enter my password to download a .csv file. Is there code that will open the Unread emails in the POINT folder, click the appropriate hyperlink, enter my password (the same for all emails), and download the .csv file and then run an Excel macro? I've already created the Excel macro, one for each of the different files I'm downloading. Okay, taking a few steps back here. 1) You receive an email 2) That email has two URLs in it (secure hyperlinks means they begin https:// ?) 3) You choose one of them as being appropriate - is it always the second? 4) You download the document at that URL, which requires a password 5) You then run some sort of alteration on the resulting CSV file. Please correct me on anything I've misunderstood. Python can certainly do all of these steps, with the possible exception of fetching the email. Dividing the problem up into separate steps will make the solving of it easier. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Oddity with 'yield' as expression - parentheses demanded
On Thu, Aug 1, 2013 at 6:35 PM, Ian Kelly ian.g.ke...@gmail.com wrote: yield was a statement before it became an expression, and the syntax yield x, y, z was (and still is) perfectly legal, with all three expressions (technically a single tuple expression) being governed by the yield. That is to say, yield x, y, z and yield (x, y, z) are semantically equivalent. When it became an expression, in order to preserve this equivalence, that meant that the yield expression needed to bind even less tightly than the comma. In terms of the grammar, yield needed to take an expression_list, not just an expression. There are only three places in the grammar where expression_lists are used without enclosing them in brackets: expression statements (in this case analogous to the yield statement), the return statement (not normally used to return a value in a generator), and the assignment statements. So for consistency and clarity the rules for parenthesizing yield statements are basically adopted from the existing rules for parenthesizing expression_lists. Ahh, right. That makes good sense. If this were being created anew now, would yield be made to bind more tightly than the comma? That would mean that yield x, y, z# Yield a tuple would need to be written as: yield (x, y, z) which wouldn't, in my opinion, be a bad thing. (It'd probably catch a few people out, but a linter could notice that a tuple is being created and ignored.) So this is a bit of a wart, but it's for backward compatibility. Right? ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Does Python 'enable' poke and hope programming?
On Thu, Aug 1, 2013 at 6:57 PM, CM cmpyt...@gmail.com wrote: It seems that if I can make a change to the code and then immediately test it by running the Python interpreter and finding out, in a few seconds, if it worked, I am going to be *much* more likely to use this trial-and-error approach than if I had to use a compiled language, since compiling takes so long. E.g. Oh, that doesn't work? Maybe if I add this...no. OK, what about if I increment that? No...OK, wait, maybe this...AH! That worked. (obviously it is not quite that uninformed all the time). I would say that, often, that's a fine way to do things. With two very similar languages I work with (Python and Pike), there's a slight difference in the interpretation of a range subscript: Pike v7.8 release 700 running Hilfe v3.5 (Incremental Pike Frontend) Hello, world![..5]; (1) Result: Hello, Hello, world![5..]; (2) Result: , world! Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit (Intel)] on win32 Hello, world![:5] 'Hello' Hello, world![5:] ', world!' Python counts the boundaries between characters, Pike counts the characters themselves. So using the same number on different sides of the colon yields the exact same string in Python, but in Pike, both strings contain the indexed character. Both ways make sense, and the easiest way to make sure I haven't mucked something up - in either language - is to try it. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: How to use Python to open Unread message(s) in specific Outlook folder, clicking a hyperlink within the email message to a secure login window, entering password to download .csv file, run Excel m
On Thu, Aug 1, 2013 at 7:08 PM, hamberg...@gmail.com wrote: 1) You receive an email 2) That email has two URLs in it (secure hyperlinks means they begin https:// ?) 3) You choose one of them as being appropriate - is it always the second? 4) You download the document at that URL, which requires a password 5) You then run some sort of alteration on the resulting CSV file. Please correct me on anything I've misunderstood. Python can certainly do all of these steps, with the possible exception of fetching the email. Dividing the problem up into separate steps will make the solving of it easier. ChrisA Thanks a lot ChrisA! You are correct with everything except that the login hyperlink is always the first link and the second one is the link to register. Okay! (Digression: You seem to be using Google Groups. Please read http://wiki.python.org/moin/GoogleGroupsPython before posting further, to avoid antagonizing the list's best responders.) The first step is to figure out how to retrieve the email. You may want to tweak your setup to make this easier. The next thing I'd do would be to port the macro to Python. Everything in between is fairly easy. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: LibreOffice (was: Editing tabular data)
On Fri, Aug 2, 2013 at 8:14 AM, Ben Finney ben+pyt...@benfinney.id.au wrote: Chris Angelico ros...@gmail.com writes: […] rather than OO/LibreOffice. (I'll not distinguish those two. Far as I'm concerned, they're one product with two names.) That's simply false. ... Claiming they're the same product is ignoring the transfer of development away from the OpenOffice.org code dump, and to LibreOffice as the actively-developed product. To be sure, they're different; but they're part of one family tree. It's like referring to Debian/Ubuntu when you're discussing something where it makes absolutely zero difference which one you're talking about. The difference between using LibreOffice and using OpenOffice is nothing compared to the difference between working with either of the above and putting a literal in your code. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Python script help
On Fri, Aug 2, 2013 at 10:46 AM, cool1...@gmail.com wrote: I do know some Python programming, I just dont know enough to put together the various scripts I need...I would really really appreciate if some one can help me with that... Be aware that you might be paying money for that. If you know some carpentry but not enough to put together a bookcase, and you ask a professional carpenter to make you a bookcase, you'll have to pay him. The same is true in programming, except that there are more people willing to work for nothing, hence the vague might be rather than the inevitable shall or the mighty must [1]. To get people to work for you for free, you have to make them (us) want to, which in the geeky arts generally means making it an interesting problem. Achieving this is described well in esr's essay on asking smart questions [2], which Ulrich also just pointed you to. We do this sort of thing for fun, for love, so if you make your problem appeal to us, there's a high chance that someone will provide you with code. [1] http://www.youtube.com/watch?v=GVVTYII422k [2] http://www.catb.org/esr/faqs/smart-questions.html ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: outputting time in microseconds or milliseconds
On Fri, Aug 2, 2013 at 1:08 PM, Dave Angel da...@davea.name wrote: matt.doolittl...@gmail.com wrote: Hey everybody, I am using 2.7 on Ubuntu 12.10. and what version of Python are you using? I don't know if it matters, but it's useful to always supply both Python version and OS version. Looks to me like Python 2.7. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Python performance
On Fri, Aug 2, 2013 at 2:16 PM, Schneider j...@globe.de wrote: Queuing the mails for a while is not possible, because the tool should sit between the client and smtp-server. It should act as proxy, not as server. I've written an SMTP proxy (primary purpose: check SPF records; secondary purpose: rate-limit one particular PHP app) that can handle fairly large throughput; it could probably saturate the network connection it's working on (10Mbit) without the proxy making a particularly notable blip on the CPU or RAM usage. Most of the work is elsewhere. How bursty will the mail be? If we're talking 2000 all at once and then an hour of quietness, you may have some issues; but I'd say you could do 100-200 in a second, on reasonable hardware. Of course, this is assuming you're writing your logs to a write-cached volume - which means you'll lose some stats if the power fails. If that's a problem to you, you'll want to record your stats more reliably (personally I'd let PostgreSQL worry about the details, ie store into a database), which will cost throughput. But otherwise, basic stats shouldn't take more than 5-10ms. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP8 revised: max line lengths
On Fri, Aug 2, 2013 at 10:15 PM, wxjmfa...@gmail.com wrote: Le vendredi 2 août 2013 17:19:11 UTC+2, Skip Montanaro a écrit : The solely valid solution, assuming there is some wish, is to define a maximal line width (preferably in SI units ;-) So, 79 * 8 points == 0.22295696 meters, right? :-) Skip You can correct your mistake yourself. In your equation, the unit at the left is [1] * [point] = [point], at the right the unit is [meter], obviously [point] != [meter]. http://en.wikipedia.org/wiki/Point_(typography) A point is one twelfth of a pica, which is one sixth of an inch, which is 0.0254 SI millimeters. Do the arithmetic. Skip is absolutely correct. Problem #1 For a tool which is supposed to be Unicode compliant, a Unicode compliant font has never a constant pitch, so counting a maximal width in number of characters does not make sense. Problem #2 The only valid constraint which makes sense is a maximal size in a length unit. Two possibilities: – if you consider your document is to be viewed as a screen document, pixel comes in mind. – if you condider your document will be printed, retain a physical unit length (cm, inch). Problem #3 cm or inch? The only serious unit is an SI unit. (In scientific publications, only SI units are accepted) The cm is not a primary SI unit either. Hint: Put you code in a pdf. Hint: Put your code in a bitmap for screens *and* a PDF for printing. That's the only way to guarantee that it'll work. Since this is not possible, there is one solution left: Do not view your code on screen, but only print it out. Then you can guarantee that your columns are as you expected. Python could be enhanced to take advantage of this; for instance, instead of requiring the hash character (which may be difficult to type on certain keyboards, including mobile phones), a letter C (U+0043) in column 1 can cause the line to be considered a Comment. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: How to use Python to open Unread message(s) in specific Outlook folder, clicking a hyperlink within the email message to a secure login window, entering password to download .csv file, run Excel m
On Fri, Aug 2, 2013 at 7:18 PM, hamberg...@gmail.com wrote: How should I tweak my setup to make it easier to retrieve my email? I hope I'm doing this reply correctly. The best way is to use email, not the Google Groups interface. Start here: http://mail.python.org/mailman/listinfo/python-list You can use gmail, and it'll thread the conversations for you. (So will many other clients, but you clearly already have gmail.) The usual convention is to use angle brackets with quoted text, and also to wrap your sent text to a reasonable number of characters (about 80 is common; most clients will do this for you - gmail will as long as you send Plain Text rather than formatted, which is a good idea anyway). ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Python performance
On Fri, Aug 2, 2013 at 1:00 PM, Schneider j...@globe.de wrote: Hi list, I have to write a small SMTP-Relay script (+ some statistic infos) and I'm wondering, if this can be done in python (in terms of performance, of course not in terms of possibility ;) ). It has to handle around 2000 mails per hour for at least 8hours a day (which does not mean, that it is allowed not to respond the rest of the day. 2000 an hour is less than one a second. I don't know how much hardware you're going to devote to this or how many other services are going to be on the same computer, but you should be able to do that no problem at all; basic statisticking isn't difficult. The slowest part is likely to be networking (esp if you have to do DNS lookups), so you'll want to make sure everything's done asynchronously - either with threads or with async queries and so on. I'd say this will be fairly easy. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Python: Code is ignoring the if and else
On Sat, Aug 3, 2013 at 2:44 AM, kevin4f...@gmail.com wrote: Yeah, I already know about that. But if I try to change it, I'm not even able to start the program. If I try to change the if statement that it corresponds with, I get a an error saying card is not a global. And if I try to shift it in, for some reason...the program runs through the MISS line multiple times. Okay. Stop, take a step back, and simplify your problems. You're currently exhibiting a technique of shotgun programming that may be getting in your way; you're just trying things without really knowing what you're doing. Play with individual control structures in interactive Python (eg IDLE), and get to know what's really happening. Read the docs. Be sure you're structuring your code the way you think you are. You'll find everything easier once you understand why your code is doing what it's doing. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP8 revised: max line lengths
On Sat, Aug 3, 2013 at 3:21 AM, Joshua Landau jos...@landau.ws wrote: On 2 August 2013 22:34, Chris Angelico ros...@gmail.com wrote: On Fri, Aug 2, 2013 at 10:15 PM, wxjmfa...@gmail.com wrote: Problem #3 cm or inch? The only serious unit is an SI unit. (In scientific publications, only SI units are accepted) The cm is not a primary SI unit either. But it is an SI unit. Sorry. Term I should have used is base SI unit. Instead of using the cm, use the m. Or go three orders of magnitude at a time to the km or the mm. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Correct Way to Write in Python
On Sat, Aug 3, 2013 at 4:59 PM, Sagar Varule punk.sa...@gmail.com wrote: Your explanation for private and public access modifier was awesome as I was having harding time finding why we dont have access modifier for pythonThanks a lot It's a huge saving in time and effort. The C++ convention is: Make everything private, then hand-write getters and setters for them all, just in case you want to put extra code onto them. (I don't know C# but it seems to be pretty much the same.) The Python convention is: We're all consenting adults. Make stuff public, then if you need to add code to something, make a @property that simulates the old behaviour. Personally, I've started to adopt the Python style in my C++ code as well. I use struct instead of class, avoid making anything private, and document the things that must not be done - for instance, I created a class that had one particular pointer that must never be advanced other than by the provided member function, but may be retarded. No reason to fiddle with member privacy even there. (The same technique has benefit in a quite different area, too: separation of code and data. Not in C++, but I have systems that let me load new code into a running process, and there it's extremely helpful to just do everything as a simple structure, and then the new code can slide in and work with the old data structure, happily extending it with whatever it now needs. Again, everything's public.) ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Does Python 'enable' poke and hope programming?
On Sat, Aug 3, 2013 at 6:30 PM, CM cmpyt...@gmail.com wrote: In sum: experimentation is for when you don't know what you're doing and there is no manual; but, after the initial learning time, you *should* know what you're doing and you should have the manual handy, and therefore the time for experimentation is largely over. Yet with fast turnaround interactive languages, the interpreter IS part of the manual. Keeping IDLE (I prefer it to command-line Python on Windows, as the latter lacks GNU readline ergo no tab completion etc) handy is at least as useful as keeping the manual up. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Print word from list
On Sat, Aug 3, 2013 at 11:17 PM, eschneide...@comcast.net wrote: pie='apple keylime pecan meat pot cherry' pie.split() How can I print a word from the list other than this way: print(pie[0:5]) ? The split() method returns a list, it doesn't change the original string. Try: pies = pie.split() print(pie[2]) ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Removing matching items from a list?
On Sun, Aug 4, 2013 at 12:06 AM, Roy Smith r...@panix.com wrote: In article 51fd8635$0$3$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: 2) Then go through those initial letters, and pick out the ones equal to 4 (or should that be four or more?). Assuming my earlier hunch is correct about these being cards in a deck, and the a's being aces, I would hope it's not four or more. See my earlier comment about saloons and gunshot wounds. Unless he's working with multiple decks. There are plenty of games played with a double deck. But we did get a peek at his creation code, which appears to make but a single deck's worth of cards. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Python script help
On Sun, Aug 4, 2013 at 4:57 PM, cool1...@gmail.com wrote: I understand I did not ask the question correctly, but is there any chance you can help me put together this code? I know that you all do this for fun and enjoy it and that is why I asked you guys instead of asking some one who will charge me for a very simple line of code. I would appreciate it, Thank you. There are a million and one projects out there that I could do for fun. Why should I do yours rather than one of theirs? The key is to make your problem look more fun, or more useful, than the others. At the moment, it looks fairly un-fun (just recreating wget with less features), and not particularly useful (you could just use wget). So at the moment, I don't feel inclined to put in several hours of unpaid work for you. I'll give you a few examples of things I *have* put hours of unpaid work into, over the past few weeks: * The Savoynet Performing Group production of The Yeomen of the Guard. It's fun because the music's great and I'm working with awesome people. (Also because the director has come up with an interpretation of the finale that works better than any I've yet seen.) The lead soprano is very close to going insane, the tragic comic sends a shiver up my spine with the way he says Elsie, and we have chocolate at rehearsal (which I provide at my own expense). Fun and useful. * The professional company performing Pirates of Penzance and Iolanthe needs help moving costumes in and out. Again, useful, and working with the best people. When the organizers of an international festival say you're invaluable, that's pretty high praise. * The Gilbert Sullivan Society back home needs someone to manage its domain, web hosting, internal Mailman list, etc, etc, etc. Most of it is fairly mundane and unexciting, but it's useful. * Gypsum is my designated successor to my somewhat popular MUD client RosMud, achieving many of the things that I can't do with RosMud. As a gamer, I like my game clients. Very fun and very useful. * Related to the above, digging through the uncharted waters of mixed metaphors and the Pike programming language, discovering language bugs that probably nobody had ever run into before; and then submitting patches and, again, seeing the approval and appreciation from people I respect highly. * Reading Alice in Wonderland to my eleven-year-old sister who'd never heard it before. (Also to the rest of the family, who frequently 'just happened' to hang around as I was reading.) * Telling people about the Alice: Otherlands Kickstarter campaign [1], which I'd really like to see succeed (if it reaches $250,000 within the next few hours, the original voices of Alice and the Cheshire Cat will be brought in!). These are all projects that tie in with one of my interests or hobbies (Gilbert and Sullivan, MUDding, and Alice in Wonderland). That gives them a huge head-start in the fun and interesting categories. You're trying to get me to donate my time and effort to your project; to do that, you have to make your project look as interesting as one of those. Okay, maybe not quite; each of the above has had MANY dev hours donated to it, and you're just looking for maybe 1-2 hours. But still, that's worth maybe a hundred dollars, so think of your request as soliciting a donation of that amount. How are you going to pitch that? By the way, I am right now donating time towards a meta-cause: your ability to handle yourself on an internet mailing list. I consider that cause to be *extremely* useful, because it empowers the world and you in ways that will make life easier for everyone, most notably people on this list who I respect quite highly. So I'm happy to donate ten or fifteen minutes to explaining exactly what it takes to get something done, because - unless I've completely misread you - you, and the whole world, will benefit that many times over. [1] http://www.kickstarter.com/projects/spicyhorse/alice-otherlands ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP8 revised: max line lengths
On Sun, Aug 4, 2013 at 3:07 PM, Roy Smith r...@panix.com wrote: In article d2e561f1-f5ba-4242-941d-6989abd1a...@googlegroups.com, wxjmfa...@gmail.com wrote: I have always found, computer scientists are funny scientists. I have always found that sciences which contain the word science in their name tend to not be very scientific. Biology, Chemistry, Physics, those are real sciences. Computer Science, Social Science, Political Science, not so much. Right. We use the scientific method only in our worst work, like poking at a black-box system to try to reverse compile it. Our work generally involves examining a problem and figuring out which set of tools will best solve it, which is more of an engineering thing. (Build a bridge. Your chasm is X meters across, your bridge must support Y kg of vehicles traversing it, the terrain is unsuited to pylons, and you must not exceed Z meters of height above the road surface.) And programmers, like engineers, have to deal with the possibility (or certainty) of idiots using their products. This is not a pure science by any means. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP8 revised: max line lengths
On Sun, Aug 4, 2013 at 7:18 PM, Roy Smith r...@panix.com wrote: In article mailman.186.1375639877.1251.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: programmers, like engineers, have to deal with the possibility (or certainty) of idiots using their products. As a programmer, I'm OK with the idea that idiots are using my programs. What bothers me more is when, as a user of a program, I have to deal with the fact that idiots wrote it. Heh. Yeah. Too true. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: stupid simple scope issue
On Sun, Aug 4, 2013 at 7:20 PM, JohnD j...@nowhere.com wrote: #~/usr/bin/python If this is meant to be a Unix-style shebang, the second character needs to be ! not ~. This has no effect on Python though. import random class boys: state={} class boy: state={ 'name':'', 'age':'' } At no time do you actually instantiate any objects from these types. In fact, you may as well drop the class blocks and the .state usage and simply use: boys = {} boy = {'name':'', 'age':''} as this will achieve the exact same thing. def add_names(): global boys The global declaration is needed only if you assign to the name, eg boys = ... - it's superfluous here. for n in names: boy.state['name']=n boy.state['age']=random.randint(1, 1000) boys.state[n]=boy.state print boy.state['name'], boy.state['age'] Each time you do this, you're modifying the same 'boy' mapping, then putting another reference to it in 'boys'. I think possibly what you want here is to construct a new boy() instance for each one. add_names() for n in boys.state: boy.state=boys.state[n] print boy.state['name'], boy.state['age'] I'd look at doing it more like this: class boy: def __init__(self,name,age): self.name=name; self.age=age boys = {} def add_name(n): b = boy(n,random.randint(1, 1000)) boys[n] = b print b.name, b.age for n in 'a','b','c': add_name(n) for n,b in boys.items(): print b.name, b.age Or possibly even dispense with the boy class altogether and simply use a dictionary - or simply map a name to an age, since (as you can see in the final loop) it's easy enough to iterate over the dictionary. (Note that the code above is untested and probably has an egregious bug in it somewhere.) ChrisA -- http://mail.python.org/mailman/listinfo/python-list