Re: Closures in leu of pointers?
On Sunday, June 30, 2013 10:38:01 AM UTC+5:30, Chris Angelico wrote: > On Sun, Jun 30, 2013 at 2:32 PM, Terry Reedy wrote: > > One of the reasons I switched to Python was to not have to do that, or > > hardly ever. For valid code, an new declaration is hardly needed. Parameters > > are locals. If the first use of another name binds it (and that includes > > import, class, and def), it is local. If the first use of does not bind it, > > it had better not be local (because if it is, there well be an exception). > > If there are branches, each should be consistent with the others. One should > > only need two readings to understand and fix unbound local errors. > > > This is strictly a matter of opinion, and one on which mine differs > from yours. I think explicit declarations are better than implicit > "you've assigned to this name" local creations; the declarations help > to catch typos. Also, I like the consistency of C-style declarations - > where-ever you declare something, it's valid from there "in", and not > "out". Without declarations, there's a magical scope boundary at a > function definition that's different from the non-boundary at a loop, > for instance. > > > But that's just my opinion. and as Teresa says, I'm only one, and > possibly I'm wrong. Getting scoping right has been -- history-wise -- exceptionally difficult. Lisp started with dynamic scoping -- the word and the consequences of that hardly being conceivable in 1960. It took 25 years to correct half that error in scheme and common-lisp viz. dynamic to static scoping. The other half still persists in common lisp though not scheme http://en.wikipedia.org/wiki/Lisp-1_vs._Lisp-2#The_function_namespace. Its taken another 25 years to get the mistake out of the most ubiquitous lisp -- Emacs-lisp https://en.wikipedia.org/wiki/Emacs_Lisp#From_dynamic_to_lexical_scoping I believe perl started with 'local' and later added 'my', repeating the same mistake. Even python needed to modify the LEGB rule (was it 2.2??) for similar reasons, got comprehension scoping wrong by having variables leak out -- corrected from 2 -> 3, and still gets it wrong from one element to the next. And finally, the founders of lambda-calculus -- Church, Curry, Rosser -- screwed up (I believe) in the initial definitions of free and bound variables. -- http://mail.python.org/mailman/listinfo/python-list
Re: Closures in leu of pointers?
On Sunday, June 30, 2013 2:23:35 AM UTC+5:30, Terry Reedy wrote: > > > > If, in the general case, the compiler requires two passes to understand > a function body, then *so do people*#. This requirement is what trips up > people who are either not used to the idea of two-pass compilation or do > not cognize that the language requires it. > > # The alternative for either program or people is a 1-pass + > backtracking process where all understandings are kept provisional until > the end of the body and revised as required. 2 passes are simpler. Well languages like C have half a dozen such passes! They are called, preprocessing, compiling, assembling, linking, dynamic linking etc. And then we have that a variable at one stage becomes a constant at another, eg a macro. All of which adds up to making scoping/variables an arcane craft. Now having such passes is one thing. Defining the language in terms of them quite another... > (Python) is compiled, and the compilation of functions is a two pass > affair. The first pass classifies all names. The second pass generates > code based on the classification of the first pass. This is not part of > the grammar, but implied (required) by the semantic description. So if understanding a language in terms of machine states -- a so called operational definition -- is unsatisfactory, understanding it in terms of the machine-states of the implementation is doubly so -- we may call it a meta-operational definition. Now, thanks to Joel Spolsky we know that abstractions in general will leak including our primary abstractions viz programming languages. So, no completely banning operational understanding is generally impossible. However when it is avoidable it should be avoided. I documented the hell that teachers have teaching operational/meta-operational langauges like C 25 years ago http://www.the-magus.in/Publications/chor.pdf And I would wish that python at least tries not to repeat C's mistakes! -- http://mail.python.org/mailman/listinfo/python-list
Re: Stupid ways to spell simple code
On 30Jun2013 16:06, Chris Angelico wrote: | So, here's a challenge: Come up with something really simple, and | write an insanely complicated - yet perfectly valid - way to achieve | the same thing. Bonus points for horribly abusing Python's clean | syntax in the process. _Must_ you turn this into comp.lang.perl? Once I was JAPH... -- Cameron Simpson Yes, sometimes Perl looks like line-noise to the uninitiated, but to the seasoned Perl programmer, it looks like checksummed line-noise with a mission in life.- The Llama Book -- http://mail.python.org/mailman/listinfo/python-list
Re: Closures in leu of pointers?
Op 29-06-13 21:23, Ian Kelly schreef: On Sat, Jun 29, 2013 at 11:02 AM, Antoon Pardon wrote: Op 29-06-13 16:02, Michael Torrie schreef: The real problem here is that you don't understand how python variables work. And in fact, python does not have variables. It has names that bind to objects. I don't understand why members of this list keep saying this. Sure the variables in python behave differently than those in C and algol But they behave similarly as those in smalltalk and lisp and I haven't seen anyone claim that smalltalk and lisp don't have variables. Perhaps because that is the terminology used by the language documentation: http://docs.python.org/3/reference/executionmodel.html#naming-and-binding I don't think this reference is as strong as you think it is. Here is a paragraph somewhat lower: ] If a name is bound in a block, it is a local variable of that block, ] unless declared as nonlocal. If a name is bound at the module level, ] it is a global variable. (The variables of the module code block are ] local and global.) If a variable is used in a code block but not ] defined there, it is a free variable. So the language documentation mentions these names as being variables. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
python3 import idlelib.PyShell fails
Hi, I have a strange error. When I try import idlelib.PyShell from Python3.3 it fails with Python 3.3.2+ (3.3:68ff68f9a0d5+, Jun 30 2013, 12:59:15) [GCC 4.7.3] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import idlelib.PyShell Traceback (most recent call last): File "", line 1, in File "/usr/lib64/python3.3/idlelib/PyShell.py", line 29, in from idlelib.EditorWindow import EditorWindow, fixwordbreaks File "/usr/lib64/python3.3/idlelib/EditorWindow.py", line 11, in import webbrowser File "/usr/lib64/python3.3/webbrowser.py", line 7, in import shlex File "./shlex.py", line 56 print 'shlex: reading from %s, line %d' \ ^ SyntaxError: invalid syntax Looking at shlex.py from /usr/lib64/python3.3 there is no print statement in line 56. But, looking at /usr/lib/python2.7/shlex.py there is this print statement in line 56. Why does idlelib.PyShell when imported from Python3 import shlex from Python2 ? What's going on here? Many thanks for a hint, Helmut. -- http://mail.python.org/mailman/listinfo/python-list
Re: python3 import idlelib.PyShell fails
Helmut Jarausch wrote: > Hi, > > I have a strange error. When I try import idlelib.PyShell from Python3.3 > it fails with > > Python 3.3.2+ (3.3:68ff68f9a0d5+, Jun 30 2013, 12:59:15) > [GCC 4.7.3] on linux > Type "help", "copyright", "credits" or "license" for more information. import idlelib.PyShell > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib64/python3.3/idlelib/PyShell.py", line 29, in > from idlelib.EditorWindow import EditorWindow, fixwordbreaks > File "/usr/lib64/python3.3/idlelib/EditorWindow.py", line 11, in > > import webbrowser > File "/usr/lib64/python3.3/webbrowser.py", line 7, in > import shlex > File "./shlex.py", line 56 > print 'shlex: reading from %s, line %d' \ > ^ > SyntaxError: invalid syntax > > > Looking at shlex.py from /usr/lib64/python3.3 there is no print > statement in line 56. > > But, looking at /usr/lib/python2.7/shlex.py there is this print statement > in line 56. > > Why does idlelib.PyShell when imported from Python3 import shlex from > Python2 ? > > What's going on here? > > Many thanks for a hint, > Helmut. Look at the traceback again. There's a shlex.py in your working directory. That takes precendence over the one belonging to Python 3.3: $ ls $ python3.3 -c 'import idlelib.PyShell' $ cp /usr/lib/python2.7/shlex.py . $ python3.3 -c 'import idlelib.PyShell' Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.3/idlelib/PyShell.py", line 28, in from idlelib.EditorWindow import EditorWindow, fixwordbreaks File "/usr/local/lib/python3.3/idlelib/EditorWindow.py", line 11, in import webbrowser File "/usr/local/lib/python3.3/webbrowser.py", line 7, in import shlex File "./shlex.py", line 56 print 'shlex: reading from %s, line %d' \ ^ SyntaxError: invalid syntax $ -- http://mail.python.org/mailman/listinfo/python-list
Re: Closures in leu of pointers?
On Sun, 30 Jun 2013 01:56:25 -0700, rusi wrote: [...] > All of which adds up to making scoping/variables an arcane craft. > > Now having such passes is one thing. Defining the language in terms of > them quite another... I don't believe that Python's behaviour is defined in terms of the number of passes. It is defined in terms of a condition "if you assign to a name, it is local unless declared global". Parsing the function twice just happens to be the simplest way for the compiler to implement that rule, but it's not strictly necessary. A skilled human reader, for example, may read the function once, and re-interprete what's already seen on the basis of what they've just seen. For a human reader, such backtracking is probably easier than a two-pass process explicitly memorizing which variables are local and which are global. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Closures in leu of pointers?
On Sunday, June 30, 2013 4:52:24 PM UTC+5:30, Steven D'Aprano wrote: > On Sun, 30 Jun 2013 01:56:25 -0700, rusi wrote: > > Now having such passes is one thing. Defining the language in terms of > > them quite another... > > > I don't believe that Python's behaviour is defined in terms of the number > of passes. It is defined in terms of a condition "if you assign to a Yeah sure, I dont believe that python is nearly as bad as C where for example one commonly has to run the preprocessor standalone to debug f---ed up macros. I was responding to Terry's > This is not part of the grammar, but implied (required) by the semantic > description. Now in the case of C one would not be able to give a non-operational semantics even with a battalion of denotational semantics PhDs. Python is clearly not so bad, though in some cases the praxis of a certain aspect may be better dealt with operationally than the language spec even if that is non-operational. A clear case of this is that of mutable default parameters. Understanding that the def statement is an imperative statement in python and the consequences of that understanding, solves that issue. However the cost implicit in this is that the semantics has been operationalized. -- http://mail.python.org/mailman/listinfo/python-list
Re: python3 import idlelib.PyShell fails
On Sun, 30 Jun 2013 13:20:24 +0200, Peter Otten wrote: Thanks a lot! Helmut. -- http://mail.python.org/mailman/listinfo/python-list
Twisted 13.1.0 released
On behalf of Twisted Matrix Laboratories, I am pleased to announce the release of Twisted 13.1. Highlights for this release include: * trial now has an --exitfirst flag which stops the test run after the first error or failure. * twisted.internet.ssl.CertificateOptions now supports chain certificates. * twisted.conch.endpoints.SSHCommandClientEndpoint is a new IStreamClientEndpoint which supports connecting a protocol to the stdio of a command running on a remote host via an SSH connection. * twisted.web.xmlrpc.QueryProtocol now generates valid Authorization headers for long user names and passwords. * twisted.internet.endpoints.connectProtocol allows connecting to a client endpoint using only a protocol instance, rather than requiring a factory. For more information, see the NEWS file here: http://twistedmatrix.com/Releases/Twisted/13.1/NEWS.txt Download it now from: http://pypi.python.org/packages/source/T/Twisted/Twisted-13.1.0.tar.bz2 or http://pypi.python.org/packages/2.7/T/Twisted/Twisted-13.1.0.win32-py2.7.msi Many thanks to Tom Prince and Thomas Hervé, whose work on release-process and answers to numerous questions made this release possible. Thanks also to the supporters of the Twisted Software Foundation and to the many contributors for this release. -Ashwini -- http://mail.python.org/mailman/listinfo/python-list
Re: Stupid ways to spell simple code
On Sunday, June 30, 2013 1:06:35 AM UTC-5, Chris Angelico wrote: > So, here's a challenge: Come up with something really simple, and > write an insanely complicated - yet perfectly valid - way to achieve > the same thing. Bonus points for horribly abusing Python's clean > syntax in the process. Chris, i'm sorry, but your challenge is decades too late. If you seek amusement you need look no further than the Python stdlib. If you REALLY want to be amused, peruse the "idlelib" -- not only is the code obfuscated, it also breaks PEP8 and the PYTHON ZEN many times over. -- http://mail.python.org/mailman/listinfo/python-list
Re: Stupid ways to spell simple code
On 30 June 2013 15:58, Rick Johnson wrote: > Chris, i'm sorry, but your challenge is decades too late. If you seek > amusement you need look no further than the Python stdlib. If you REALLY want > to be amused, peruse the "idlelib" -- not only is the code obfuscated, it > also breaks PEP8 and the PYTHON ZEN many times over. To translate: Not only is the code impossible to read, inefficient and unmaintainable whilst being only shallowly correct, but, *GASP* it sometimes *breaks* semi-arbitrary code *style* *suggestions*! How dare it!‽ -- http://mail.python.org/mailman/listinfo/python-list
Re: Stupid ways to spell simple code
On Mon, Jul 1, 2013 at 1:08 AM, Joshua Landau wrote: > On 30 June 2013 15:58, Rick Johnson wrote: >> Chris, i'm sorry, but your challenge is decades too late. If you seek >> amusement you need look no further than the Python stdlib. If you REALLY >> want to be amused, peruse the "idlelib" -- not only is the code obfuscated, >> it also breaks PEP8 and the PYTHON ZEN many times over. > > To translate: Not only is the code impossible to read, inefficient and > unmaintainable whilst being only shallowly correct, but, *GASP* it > sometimes *breaks* semi-arbitrary code *style* *suggestions*! How dare it!‽ Yeah, I cannot seriously imagine that the stdlib does anything like the example I gave :) Pity nobody else is offering further examples, I thought this might be a fun thread. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Issues compiling hunspell from source on windows
Hi I am trying to compile a python module called hunspell from the following [source](https://pypi.python.org/pypi/hunspell). But I get the following error message. C:\Users\KURO\Desktop\hunspell-0.1>setup.py install running install running build running build_ext building 'hunspell' extension C:\mingw\bin\gcc.exe -mno-cygwin -mdll -O -Wall -D_LINUX -I/usr/include/hunspell -IC:\Python27\include -IC:\Python27\PC -c hunspell.c -o build\temp.win-amd64-2. 7\Release\hunspell.o -Wall writing build\temp.win-amd64-2.7\Release\hunspell.def C:\mingw\bin\gcc.exe -mno-cygwin -shared -s build\temp.win-amd64-2.7\Release\hun spell.o build\temp.win-amd64-2.7\Release\hunspell.def -LC:\Python27\libs -LC:\Py thon27\PCbuild\amd64 -lhunspell-1.2 -lpython27 -lmsvcr90 -o build\lib.win-amd64- 2.7\hunspell.pyd c:/mingw/bin/../lib/gcc/mingw32/4.3.3/../../../../mingw32/bin/ld.exe: cannot fin d -lhunspell-1.2 collect2: ld returned 1 exit status error: command 'gcc' failed with exit status 1 I tried downloading libhunspell-1.2-0.dll and put it into my system. But I still get the same error message. How do I deal with this? I have Windows 7 and [mingw](http://www.develer.com/oss/GccWinBinaries) -- http://mail.python.org/mailman/listinfo/python-list
Re: Issues compiling hunspell from source on windows
On Sunday, June 30, 2013 9:24:46 PM UTC+5:30, Akshay Kayastha wrote: > Hi I am trying to compile a python module called hunspell from the following > [source](https://pypi.python.org/pypi/hunspell). > According to http://docs.python.org/2/extending/windows.html you need to use the same compiler for the extension as used to compile python. That means one of 1. Use the MSC version used for your python 2. Recompile python from source using mingw 3. Switch to linux :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking for a name for a deployment framework...
On Sunday, June 30, 2013 7:08:51 AM UTC+5:30, Chris Angelico wrote: > On Wed, Jun 26, 2013 at 9:40 PM, Roy Smith wrote: > > for host in hosts: > >deploy(the_code).remote() > > For further hack delight, require a patch > Submitted for this code restrict itself > To five feet, neither more nor less; iambs. > But how should all those colons be pronounced? Hear Hear I say! Thou causest sweet delight Chris with Roy; poets of this assembly -- http://mail.python.org/mailman/listinfo/python-list
Re: Issues compiling hunspell from source on windows
Haha... nooo I already use Linux. But I am currently doing a project that required me to run my script on Windows as well as Linux. TO be precise I am supposed to create a stand alone executable for my script which runs great on Linux, but to create one for Windows I need to be able to run the script first. My script runs fine on Linux as its hella easy to install the module, but on windows I cant seem to be able to get the module working :( -- http://mail.python.org/mailman/listinfo/python-list
Re: Closures in leu of pointers?
On Sun, Jun 30, 2013 at 4:07 AM, Antoon Pardon wrote: > I don't think this reference is as strong as you think it is. Here is > a paragraph somewhat lower: > > ] If a name is bound in a block, it is a local variable of that block, > ] unless declared as nonlocal. If a name is bound at the module level, ] it > is a global variable. (The variables of the module code block are ] local > and global.) If a variable is used in a code block but not > ] defined there, it is a free variable. > > So the language documentation mentions these names as being variables. It seems to refer to "local" and "global" variables as a short hand for talking about specific types of name binding, which is the dominant nomenclature of the documentation. You asked why people talk about Python binding names instead of assigning variables, and I think the reference material is a clear source for that, even if it does also use the word "variable". There is also the section on assignment statements, where it again refers to names being bound, not variables being assigned: http://docs.python.org/3/reference/simple_stmts.html#assignment-statements -- http://mail.python.org/mailman/listinfo/python-list
Re: Closures in leu of pointers?
On Sun, Jun 30, 2013 at 11:13 AM, Ian Kelly wrote: > On Sun, Jun 30, 2013 at 4:07 AM, Antoon Pardon > wrote: >> I don't think this reference is as strong as you think it is. Here is >> a paragraph somewhat lower: >> >> ] If a name is bound in a block, it is a local variable of that block, >> ] unless declared as nonlocal. If a name is bound at the module level, ] it >> is a global variable. (The variables of the module code block are ] local >> and global.) If a variable is used in a code block but not >> ] defined there, it is a free variable. >> >> So the language documentation mentions these names as being variables. > > It seems to refer to "local" and "global" variables as a short hand > for talking about specific types of name binding, which is the > dominant nomenclature of the documentation. You asked why people talk > about Python binding names instead of assigning variables, and I think > the reference material is a clear source for that, even if it does > also use the word "variable". There is also the section on assignment > statements, where it again refers to names being bound, not variables > being assigned: > > http://docs.python.org/3/reference/simple_stmts.html#assignment-statements Actually, looking back at your earlier post, I think I misunderstood your question. You weren't asking "why do people talk about binding names instead of assigning variables in Python", but more strongly "why do people claim there are no variables in Python"? If the latter is a common claim, then I haven't really taken notice of it, but I'll take your word that you have. I don't agree with that -- saying that Python has no variables is just an argument of semantics. -- http://mail.python.org/mailman/listinfo/python-list
Re: python adds an extra half space when reading from a string or list
Στις 29/6/2013 8:00 μμ, ο/η Mark Lawrence έγραψε: Why this when the approach to Nick the Incompetant Greek has been to roll out the red carpet? Your mother is incompetent who raised a brat like you. -- What is now proved was at first only imagined! -- http://mail.python.org/mailman/listinfo/python-list
Re: Stupid ways to spell simple code
On Sun, Jun 30, 2013 at 9:20 AM, Chris Angelico wrote: > Yeah, I cannot seriously imagine that the stdlib does anything like > the example I gave :) Pity nobody else is offering further examples, I > thought this might be a fun thread. Well, there is the "this" module. But its code is not *that* obfuscated, and maintainability is not really an issue there since it is short and does nothing of actual importance. -- http://mail.python.org/mailman/listinfo/python-list
Re: Don't feed the troll...
Op 28-06-13 19:20, Ian Kelly schreef: On Thu, Jun 27, 2013 at 12:13 PM, Antoon Pardon wrote: So what do you think would be a good approach towards people who are behaving in conflict with this wish of yours? Just bluntly call them worse than the troll or try to approach them in a way that is less likely to antangonize them? Inform them that their behavior is damaging the list atmosphere, and ask them to please knock it off. Shaming the behavior works too, but I'd prefer to go with the former. That is a bit odd. Rurpy seemed to consider it a big nono if others used methods that would coerce him to change his behaviour. But here you see shaming as an option which seems a coercive method. So if some group views the response to trollish behaviour as too willing in cooperating with bad behaviour and as such damaging to the list, this group can then inform the cooperators that their behaviour is damaging the list atmosphere and ask to please knock it off. And they can consider more coercive methods too? The collective experience of theachers is that punishment for bad performance works, despite research showing otherwise. Flaming a troll is not punishing to them. I see I didn't make my point clear. This was my response to your remark about the collective experience going back decades. The collective experience often enough doesn't carry over wisdom but myth. To illustrate that, I gave the example of teachers whose collective experience is contradicted by the research. So if the only thing you can rely on is the collective experience of the group your knowledge isn't very relyable. I also find it somewhat odd that you talk about a troll here. AFAIU the people who are most annoyed by those flaming/protesting Nikos, don't seem to consider Nikos a troll. But if Nikos is not a troll then protesting Nikos's behaviour can't be protested against on the ground that it would be troll feeding. I am implying nothing. I'm just pointing out the difference between how rurpy explains we should behave towards Nikos and how he behaved towards the flamers. If there is some sort of implication it is with rurpy in that difference and not with me in me pointing it out. Your statement "I just don't understand why you think you should be so careful to Nikos" implies that somebody thinks we should be careful to Nikos, i.e. be careful to not hurt his feelings. At least that is how I read it, and I don't think it is true. What Rurpy's motivation would be for being careful to Nikos, you have to ask him. I'm only pointing out that in contrast to the blunt statement he made about those flaming/protesting Nikos, how he explained we should behave towards Nikos can accurately be described as careful. ... Do you think being blunt is a good way in keeping a welcoming and postive atmosphere in this group? I think it's better than being openly hostile. And speaking for myself, if somebody has a problem with my own behavior then I would prefer that they be blunt about it than cover it up with a false friendliness. Sure, but there is a difference between telling people you have a problem with their behaviour and telling people their behaviour is wrong or damaging. Yet when you have trouble with particular behaviour you go for the latter instead for the former. I am not so sure it would be counter-productive. A joint flaming of a troll can be an effective way to increase coherence in a group. Well, if flaming ever becomes the prevailing culture of the list, then I'm out. Sure, I can understand that. But doesn't this contradict somewhat that this is about others damaging this group. Increasing coherence would IMO be positive for a group, but you would still not like it. So it seems more about keeping an atmosphere that you prefer. There is nothing qrong with that, but if you can keep that in mind, your approach is more likely to be fruitful. -- Antoon Pardon. -- http://mail.python.org/mailman/listinfo/python-list
Re: Stupid ways to spell simple code
On Sun, 30 Jun 2013 16:06:35 +1000, Chris Angelico wrote: > So, here's a challenge: Come up with something really simple, and write > an insanely complicated - yet perfectly valid - way to achieve the same > thing. Bonus points for horribly abusing Python's clean syntax in the > process. Here's a trivially stupid way to find the length of an iterable: sum(1 for obj in iterable) (except it isn't actually stupid, if the iterable is an iterator, and you don't mind consuming it to find out home many items it had). This leads to an obvious obfuscation: sum(('.' for obj in iterable), '').count('.') but sadly Python, in a rare case of protecting you from shooting your own foot off, doesn't allow this. Never mind, we can defeat the safety catch on sum() and complicate the code at the same time: sum(('.' for obj in iterable), type('S', (), {'__add__': lambda self, o: o})()).count('.') Obfuscated *and* quadratic performance. Do I win? Wait, I can beat that. Sorting is too trivial in Python: alist.sort() Pfft! Where's the challenge in that? Let's use an O(n!) algorithm for sorting -- yes, n factorial -- AND abuse a generator expression for its side effect. As a bonus, we use itertools, and just for the lulz, I obfuscate as many of the names as I can: from random import shuffle as OOO00O from itertools import takewhile as OO0O0O, count as O0OO0O OO0O00 = range(5) list(OO0O0O(lambda O: any(O[O0] < O[O0-1] for O0 in range(1, sum(('O' for O in O), type('O', (), {'__add__': lambda O0O, OO0: OO0})()).count('O'))), (OOO00O(OO0O00) or OO0O00 for O in O0OO0O([0] -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Stupid ways to spell simple code
In article <51d06cb6$0$2$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > On Sun, 30 Jun 2013 16:06:35 +1000, Chris Angelico wrote: > > > So, here's a challenge: Come up with something really simple, and write > > an insanely complicated - yet perfectly valid - way to achieve the same > > thing. Bonus points for horribly abusing Python's clean syntax in the > > process. > > Here's a trivially stupid way to find the length of an iterable: > > sum(1 for obj in iterable) That's how you would do it in a map-reduce environment :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Don't feed the troll...
On Sun, Jun 30, 2013 at 11:25 AM, Antoon Pardon wrote: >>> So what do you think would be a good approach towards people >>> who are behaving in conflict with this wish of yours? Just >>> bluntly call them worse than the troll or try to approach them >>> in a way that is less likely to antangonize them? >> >> >> Inform them that their behavior is damaging the list atmosphere, and >> ask them to please knock it off. Shaming the behavior works too, but >> I'd prefer to go with the former. > > > That is a bit odd. Rurpy seemed to consider it a big nono if others > used methods that would coerce him to change his behaviour. But here > you see shaming as an option which seems a coercive method. Well, if it didn't work the first time, I wouldn't keep at it. I don't consider that coercive. -- http://mail.python.org/mailman/listinfo/python-list
Re: password protect file
On Sat, 29 Jun 2013 10:28:47 -0700 (PDT), gmsid...@gmail.com wrote: > I was wondering if there was a couple of words or things i > could add to the top of my python script to password > protect it so that it asks user for the password and then > after three tries it locks them out or says "access > denied" and closes/ends the script but if they get it > wright it proceeds on to the next line of the script total > noob here any help appreciated You can do this with just a couple lines of Python (and I'm sure this group's experts can show you how better than I), but more importantly, are you aware that doing this doesn't actually make anything secure, unless you also take precautions that are much more complicated than a few lines of Python? If you frankly state that you're only after a kid-sister level of security, readers might feel less conflicted about helping. -- To email me, substitute nowhere->spamcop, invalid->net. -- http://mail.python.org/mailman/listinfo/python-list
math functions with non numeric args
Hello, print max(-10, 10) 10 print max('-10', 10) -10 My guess max converts string to number bye decoding each of the characters to it's ASCII equivalent? Where can i read more on exactly how the situations like these are dealt with? Thank you AZ -- http://mail.python.org/mailman/listinfo/python-list
Re: math functions with non numeric args
On 2013.06.30 13:46, Andrew Z wrote: > Hello, > > print max(-10, 10) > 10 > print max('-10', 10) > -10 > > My guess max converts string to number bye decoding each of the characters to > it's ASCII equivalent? > > Where can i read more on exactly how the situations like these are dealt with? This behavior is fixed in Python 3: >>> max('10', 10) Traceback (most recent call last): File "", line 1, in TypeError: unorderable types: int() > str() Python is strongly typed, so it shouldn't magically convert something from one type to another. Explicit is better than implicit. -- CPython 3.3.2 | Windows NT 6.2.9200 / FreeBSD 9.1 -- http://mail.python.org/mailman/listinfo/python-list
Re: math functions with non numeric args
On 30-6-2013 20:46, Andrew Z wrote: > Hello, > > print max(-10, 10) > 10 > print max('-10', 10) > -10 > > My guess max converts string to number bye decoding each of the characters to > it's ASCII > equivalent? > > Where can i read more on exactly how the situations like these are dealt with? > > Thank you > AZ > Use Python 3.x instead. >>> max('-10',10) Traceback (most recent call last): File "", line 1, in TypeError: unorderable types: int() > str() >>> Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: math functions with non numeric args
On Sun, Jun 30, 2013 at 12:46 PM, Andrew Z wrote: > Hello, > > print max(-10, 10) > 10 > print max('-10', 10) > -10 > > My guess max converts string to number bye decoding each of the characters > to it's ASCII equivalent? No, it leaves the types as they are but simply considers strings to be "greater than" numbers. As another poster stated, this is fixed in Python 3, where strings and numbers are considered inorderable. -- http://mail.python.org/mailman/listinfo/python-list
Re: math functions with non numeric args
On 30/06/2013 19:53, Andrew Berg wrote: On 2013.06.30 13:46, Andrew Z wrote: Hello, print max(-10, 10) 10 print max('-10', 10) -10 My guess max converts string to number bye decoding each of the characters to it's ASCII equivalent? Where can i read more on exactly how the situations like these are dealt with? This behavior is fixed in Python 3: max('10', 10) Traceback (most recent call last): File "", line 1, in TypeError: unorderable types: int() > str() Python is strongly typed, so it shouldn't magically convert something from one type to another. Explicit is better than implicit. It doesn't magically convert anyway. In Python 2, comparing objects of different types like that gives a consistent but arbitrary result: in this case, bytestrings ('str') are greater than integers ('int'): >>> max('-10', 10) '-10' >>> max('10', -10) '10' -- http://mail.python.org/mailman/listinfo/python-list
Re: password protect file
On Sat, 29 Jun 2013 10:28:47 -0700 (PDT), gmsid...@gmail.com wrote: > I was wondering if there was a couple of words or things i > could add to the top of my python script to password > protect it so that it asks user for the password and then > after three tries it locks them out or says "access > denied" and closes/ends the script but if they get it > wright it proceeds on to the next line of the script total > noob here any help appreciated How to correctly implement such features depends on what are you are protecting. Are you trying to protect another file on the same machine, the script itself? Is this a server-side script trying to authenticate a web client? Is this 'kid-sister' level protection or national security level of protection? We would need more details on what you're trying to accomplish. Also, good (i.e. real) security is notoriously difficult to get right. There are usually pre-built solutions you should make use of instead. >From your subject line it sounds like you're interested in access control. If this is on a controlled system you should instead make use of the pre-built operating systems access control features such as user accounts, file permission bits, group policies or Access Control Lists. If this is in an uncontrolled environment or you just want to protect a file on a USB stick from prying eyes you can encrypt the file with a strong symmetric cipher like AES. There are existing tools for doing this. Your Python script could be a wrapper around one of these. (There are certain security implications to be aware of when doing this.) There's also AES implementations available in various pure Python modules. (However these generally are not FIPS certified.) If you are a "total noob" attempting (real) security programming is a bad idea. -Modulok- -- http://mail.python.org/mailman/listinfo/python-list
Re: Issues compiling hunspell from source on windows
It appears you are using a 32 bit compiler with a 64-bit python. Install a 32 bit python. On Sun, Jun 30, 2013 at 11:54 AM, Akshay Kayastha wrote: > Hi I am trying to compile a python module called hunspell from the following > [source](https://pypi.python.org/pypi/hunspell). > > But I get the following error message. > > C:\Users\KURO\Desktop\hunspell-0.1>setup.py install > running install > running build > running build_ext > building 'hunspell' extension > C:\mingw\bin\gcc.exe -mno-cygwin -mdll -O -Wall -D_LINUX > -I/usr/include/hunspell > -IC:\Python27\include -IC:\Python27\PC -c hunspell.c -o > build\temp.win-amd64-2. > 7\Release\hunspell.o -Wall > writing build\temp.win-amd64-2.7\Release\hunspell.def > C:\mingw\bin\gcc.exe -mno-cygwin -shared -s > build\temp.win-amd64-2.7\Release\hun > spell.o build\temp.win-amd64-2.7\Release\hunspell.def > -LC:\Python27\libs -LC:\Py > thon27\PCbuild\amd64 -lhunspell-1.2 -lpython27 -lmsvcr90 -o > build\lib.win-amd64- > 2.7\hunspell.pyd > c:/mingw/bin/../lib/gcc/mingw32/4.3.3/../../../../mingw32/bin/ld.exe: > cannot fin > d -lhunspell-1.2 > collect2: ld returned 1 exit status > error: command 'gcc' failed with exit status 1 > > I tried downloading libhunspell-1.2-0.dll and put it into my system. But I > still get the same error message. How do I deal with this? I have Windows 7 > and [mingw](http://www.develer.com/oss/GccWinBinaries) > -- > http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: python adds an extra half space when reading from a string or list
On 2013-06-30 18:24, Νίκος wrote: Στις 29/6/2013 8:00 μμ, ο/η Mark Lawrence έγραψε: Why this when the approach to Nick the Incompetant Greek has been to roll out the red carpet? Your mother is incompetent who raised a brat like you. That is not acceptable behavior on this list. Please keep the gratuitous insults offlist. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: python adds an extra half space when reading from a string or list
Στις 30/6/2013 10:58 μμ, ο/η Robert Kern έγραψε: On 2013-06-30 18:24, Νίκος wrote: Στις 29/6/2013 8:00 μμ, ο/η Mark Lawrence έγραψε: Why this when the approach to Nick the Incompetant Greek has been to roll out the red carpet? Your mother is incompetent who raised a brat like you. That is not acceptable behavior on this list. Please keep the gratuitous insults offlist. Ι'm sorry but please put yourself into my shows, where in multiple threads i'm still discussed and being insulted as a troll and as an idiot and incompetent and stuff like that by lots of people who instead of actually replying to my posts they deviate and have endless conversation about me. Enough is enough. Iam not a troll, neither incompetent. Period. -- What is now proved was at first only imagined! -- http://mail.python.org/mailman/listinfo/python-list
Re: python adds an extra half space when reading from a string or list
On 2013-06-30 21:14, Νίκος wrote: Στις 30/6/2013 10:58 μμ, ο/η Robert Kern έγραψε: On 2013-06-30 18:24, Νίκος wrote: Στις 29/6/2013 8:00 μμ, ο/η Mark Lawrence έγραψε: Why this when the approach to Nick the Incompetant Greek has been to roll out the red carpet? Your mother is incompetent who raised a brat like you. That is not acceptable behavior on this list. Please keep the gratuitous insults offlist. Ι'm sorry but please put yourself into my shows, where in multiple threads i'm still discussed and being insulted as a troll and as an idiot and incompetent and stuff like that by lots of people who instead of actually replying to my posts they deviate and have endless conversation about me. Enough is enough. Iam not a troll, neither incompetent. Period. You may ask people to stop their insulting comments. Do not engage by returning insults yourself. Not on the list at least. I don't care what you send by private email. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: Stupid ways to spell simple code
On 30 June 2013 18:36, Steven D'Aprano wrote: > Pfft! Where's the challenge in that? Let's use an O(n!) algorithm for > sorting -- yes, n factorial -- AND abuse a generator expression for its > side effect. As a bonus, we use itertools, and just for the lulz, I > obfuscate as many of the names as I can: > > > from random import shuffle as OOO00O > from itertools import takewhile as OO0O0O, count as O0OO0O > > OO0O00 = range(5) > > list(OO0O0O(lambda O: any(O[O0] < O[O0-1] for O0 in > range(1, sum(('O' for O in O), type('O', (), > {'__add__': lambda O0O, OO0: OO0})()).count('O'))), > (OOO00O(OO0O00) or OO0O00 for O in O0OO0O([0] I've got to say -- that last line got me for quite a while, especially as the list of lists was returning a list of sorted lists! For obfuscation, though, you want unicode. It's much harder to reason about code that you can't read. from itertools import count as æ, permutations as Æ, starmap as ð [globals().setdefault("%c"%sum(ø.encode()),ß)for ø,ß in vars(__builtins__).items()if ø!="vars"] sorted = lambda ħ:ƿ(ƞ for ı in φ(ƴ(lambda:ħ,æ),ń(0,ń(ħ)**(len(ħ)*2-1)*len(ħ)))for ƞ in Æ(ħ)if ǂ(()).__eq__((ŕ(ð(ǂ(Ƽ(ƞ).pop()).__rpow__,φ(ŕ(œ(ƞ,ƴ(lambda:0,ħ)),()),1))),ħ),ı))[::-1] print(sorted([4, -3, 4, 2, -1])) This only works for integers (including negatives) and some things that seem to do nothing but slow it down are needed to cover special cases. This one takes about 3½ minutes on my computer -- it's got a runtime efficiency of something along the lines of O( (L!) * ((L)**i) ) for i being related to the elements in the list and L being the length of the list. That said, it's rather OK at sorting [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]. I know this is more oriented towards obfuscation of code than obfuscation of technique, but --as I said-- I'm writing a library for that. I'll be back when it's ready. -- http://mail.python.org/mailman/listinfo/python-list
Re: python adds an extra half space when reading from a string or list
On 30 June 2013 20:58, Robert Kern wrote: > On 2013-06-30 18:24, Νίκος wrote: >> >> Στις 29/6/2013 8:00 μμ, ο/η Mark Lawrence έγραψε: >> >>> Why this when the approach to Nick the Incompetant Greek has been to >>> roll out the red carpet? >> >> >> Your mother is incompetent who raised a brat like you. > > > That is not acceptable behavior on this list. Please keep the gratuitous > insults offlist. As much as you are right, this argument was started by Mark. If you reprimand anyone (other threads being ignored) it should be him. Reacting only to Nick, even though what Nick said was undue, implies that you agree with Mark's actions. Remember that Nick is as much a human as all of us, he is bound to have his feelings hurt when so many people pick on him -- whether they are justified or not. -- http://mail.python.org/mailman/listinfo/python-list
Re: python adds an extra half space when reading from a string or list
On 2013-06-30 22:57, Joshua Landau wrote: On 30 June 2013 20:58, Robert Kern wrote: On 2013-06-30 18:24, Νίκος wrote: Στις 29/6/2013 8:00 μμ, ο/η Mark Lawrence έγραψε: Why this when the approach to Nick the Incompetant Greek has been to roll out the red carpet? Your mother is incompetent who raised a brat like you. That is not acceptable behavior on this list. Please keep the gratuitous insults offlist. As much as you are right, this argument was started by Mark. If you reprimand anyone (other threads being ignored) it should be him. Reacting only to Nick, even though what Nick said was undue, implies that you agree with Mark's actions. Remember that Nick is as much a human as all of us, he is bound to have his feelings hurt when so many people pick on him -- whether they are justified or not. I hereby reprimand both Mark and Nikos. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: password protect file
On Sunday, June 30, 2013 2:25:51 PM UTC-5, Modulok wrote: > On Sat, 29 Jun 2013 10:28:47 -0700 (PDT), gmsi...@gmail.com wrote: > > > I was wondering if there was a couple of words or things i > > could add to the top of my python script to password > > > protect it so that it asks user for the password and then > > after three tries it locks them out or says "access > > > denied" and closes/ends the script but if they get it > > wright it proceeds on to the next line of the script total > > > noob here any help appreciated > > > > > How to correctly implement such features depends on what are you are > > protecting. Are you trying to protect another file on the same machine, the > script itself? Is this a server-side script trying to authenticate a web > > client? Is this 'kid-sister' level protection or national security level > of protection? We would need more details on what you're trying to accomplish. > > > > Also, good (i.e. real) security is notoriously difficult to get right. There > are usually pre-built solutions you should make use of instead. > > > > From your subject line it sounds like you're interested in access control. If > this is on a controlled system you should instead make use of the pre-built > > operating systems access control features such as user accounts, file > permission bits, group policies or Access Control Lists. > > > > If this is in an uncontrolled environment or you just want to protect a file > on > a USB stick from prying eyes you can encrypt the file with a strong symmetric > > cipher like AES. There are existing tools for doing this. Your Python script > could be a wrapper around one of these. (There are certain security > > implications to be aware of when doing this.) There's also AES implementations > available in various pure Python modules. (However these generally are not > FIPS > > certified.) > > > If you are a "total noob" attempting (real) security programming is a bad > idea. > > -Modulok- i just want something simple that basicly asks for a password and then replies to u if you are wrong nothing hevay just for learning exsperience -- http://mail.python.org/mailman/listinfo/python-list
Re: password protect file
On Mon, Jul 1, 2013 at 8:17 AM, wrote: > > i just want something simple that basicly asks for a password and then > replies to u if you are wrong nothing hevay just for learning exsperience > -- Then your task is pretty easy. Look up these things in the Python docs: * input (or raw_input if you use Python 2) * if * sys.exit You can do it with those three. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Python, meet Turtle
http://jugad2.blogspot.com/2013/07/python-meet-turtle.html -- http://mail.python.org/mailman/listinfo/python-list
settrace doesn't trace builtin functions
Hi, I've been using the settrace function to write a tracer for my program, which is working great except that it doesn't seem to work for built-in functions, like open('filename.txt'). This doesn't seem to be documented, so I'm not sure if I'm doing something wrong or that's the expected behavior. If settrace's behavior in this regard is fixed, is there any way to trace calls to open()? I don't want to use Linux's strace, as it'll run for whole program (not just the part I want) and won't show my python line numbers/file names, etc. The other option I considered was monkey-patching the open function through a wrapper, like: def wrapped_open(*arg,**kw): print 'open called' traceback.print_stack() f = __builtin__.open(*arg,**kw) return f open = wrapped_open but that seemed very brittle to me. Could someone suggest a better way of doing this? thank you, imran -- http://mail.python.org/mailman/listinfo/python-list
Re: Closures in leu of pointers?
On 30/06/2013 3:46 PM, Ian Kelly wrote: In general I agree, although when reading code I would definitely prefer if the locals were declared. If you import the code into the interpreter as an adjunct to reading it you can see the locals with: >>> somefunc.func_code.co_varnames # 2.x >>> somefunc.__code__.co_varnames # 3.x On a related note, I think that generator functions should in some way be explicitly marked as such in the declaration, rather than needing to scan the entire function body for a yield statement to determine whether it's a generator or not. >>> inspect.isgenerator(somefunc) However, a dedicated code reader built around the inspect module could be a handy tool. -- http://mail.python.org/mailman/listinfo/python-list
Re: python adds an extra half space when reading from a string or list
Op 30-06-13 22:14, Νίκος schreef: Στις 30/6/2013 10:58 μμ, ο/η Robert Kern έγραψε: On 2013-06-30 18:24, Νίκος wrote: Στις 29/6/2013 8:00 μμ, ο/η Mark Lawrence έγραψε: Why this when the approach to Nick the Incompetant Greek has been to roll out the red carpet? Your mother is incompetent who raised a brat like you. That is not acceptable behavior on this list. Please keep the gratuitous insults offlist. Ι'm sorry but please put yourself into my shows, Why should we? You, yourself have shown no willingness to put yourself in the shoes of others. When it was pointed out your behaviour was unacceptable, you continued just the same with no consideration of how much you were antagonising the members of this group. where in multiple threads i'm still discussed and being insulted as a troll and as an idiot and incompetent and stuff like that by lots of people who instead of actually replying to my posts they deviate and have endless conversation about me. What did you expect? That you could just keep asking to be helped in obnoxious ways without people commenting on that? Enough is enough. Iam not a troll, neither incompetent. Period. No not period. You have by your behaviour made yourself a reputation of being an incompetent inconsiderate jerk. You don't lose such a repuation by simply claiming you are not. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: python adds an extra half space when reading from a string or list
Op 30-06-13 23:57, Joshua Landau schreef: On 30 June 2013 20:58, Robert Kern wrote: On 2013-06-30 18:24, Νίκος wrote: Στις 29/6/2013 8:00 μμ, ο/η Mark Lawrence έγραψε: Why this when the approach to Nick the Incompetant Greek has been to roll out the red carpet? Your mother is incompetent who raised a brat like you. That is not acceptable behavior on this list. Please keep the gratuitous insults offlist. As much as you are right, this argument was started by Mark. If you reprimand anyone (other threads being ignored) it should be him. Reacting only to Nick, even though what Nick said was undue, implies that you agree with Mark's actions. I don't agree Mark started this argument. That he gave a negative appraisal of Nikos is not starting an argument in itself. Remember that Nick is as much a human as all of us, he is bound to have his feelings hurt when so many people pick on him -- whether they are justified or not. So? Should we particularly care about Nikos's feelings? Nikos is not the victim, he is the instigator. And should his feelings get hurt when it is pointed out what picture people got from him through his own behaviour, I say good. May that way he'll learn that if he doesn't want to be considered an incompetent inconsiderate jerk, he shouldn't behave like one. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list