[ANN] Leipzig Python User Group - Meeting, March 20, 2012, 08:00 p.m.
=== Leipzig Python User Group === We will meet on Tuesday, March 20 at 8:00 p.m. at the training center of Python Academy in Leipzig, Germany ( http://www.python-academy.com/center/find.html ). Everybody who uses Python, plans to do so or is interested in learning more about the language is encouraged to participate. We will continue to work on our project Python macht Schule [1] creating Python teaching material for kids. While the meeting language will be mainly German, we will provide English translation if needed. Food and soft drinks are provided. Please send a short confirmation mail to i...@python-academy.de, so we can prepare appropriately. Current information about the meetings are at http://www.python-academy.com/user-group . Mike [1] https://bitbucket.org/PySV/python_macht_schule == Leipzig Python User Group === Wir treffen uns am Dienstag, 20.03.2012 um 20:00 Uhr im Schulungszentrum der Python Academy in Leipzig ( http://www.python-academy.de/Schulungszentrum/anfahrt.html ). Willkommen ist jeder, der Interesse an Python hat, die Sprache bereits nutzt oder nutzen möchte. Wir werden weiter an unserem Projekt Python macht Schule [1] arbeiten. Dabei geht es darum Materialien für Kinder zum Erlernen von Python zu erarbeiten. Für das leibliche Wohl wird gesorgt. Eine Anmeldung unter i...@python-academy.de wäre nett, damit wir genug Essen besorgen können. Aktuelle Informationen zu den Treffen sind unter http://www.python-academy.de/User-Group zu finden. Viele Grüße Mike [1] https://bitbucket.org/PySV/python_macht_schule -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
pysandbox 1.5 released
pysandbox is a Python sandbox. By default, untrusted code executed in the sandbox cannot modify the environment (write a file, use print or import a module). But you can configure the sandbox to choose exactly which features are allowed or not, e.g. import sys module and read /etc/issue file. http://pypi.python.org/pypi/pysandbox https://github.com/haypo/pysandbox/ Main changes since pysandbox 1.0.3: - More modules and functions are allowed: math, random and time modules, and the compile() builtin function for example - Drop the timeout feature: it was not effective on CPU intensive functions implemented in C - (Read the ChangeLog to see all changes.) pysandbox has known limitations: - it is unable to limit memory or CPU - it does not protect against bugs (e.g. crash) or vulnerabilities in CPython - dict methods able to modify a dict (e.g. dict.update) are disabled to protect the sandbox namespace, but dict[key]=value is still accepted It is recommanded to run untrusted code in a subprocess to workaround these limitations. pysandbox doesn't provide an helper yet. pysandbox is used by an IRC bot (fschfsch) to evaluate a Python expression. The bot uses fork() and setrlimit() to limit memory and to implement a timeout. https://github.com/haypo/pysandbox/wiki/fschfsch -- The limitation on dict methods is required to deny the modification of the __builtins__ dictionary. I proposed the PEP 416 (frozendict) but Guido van Rossum is going to reject it. I don't see how to fix this limitation without modifying CPython. http://www.python.org/dev/peps/pep-0416/ Victor -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
Eclipse, C, and Python
Hello Forum. I have installed Python comnpiler in Eclipse Classic for Windows. After a while I have installed the C compiler. However, somehow now when I try to run my code in Python it shows me for default Ant Run --Ant Build I switched my workspace but still. Do you know how to solve this?.. Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: urllib.urlretrieve never returns???
Here you can find the example program and the original post. http://code.activestate.com/lists/python-list/617894/ I gather you are running urlretrieve in a separate thread, inside a GUI? Yes. I have learned that whenever I have inexplicable behaviour in a function, I should check my assumptions. In this case, (1) are you sure you have the right urlretrieve, and (2) are you sure that your self.Log() method is working correctly? Just before the problematic call, do this: # was: fpath = urllib.urlretrieve(imgurl)[0] # becomes: print(urllib.__file__, urlretrieve) self.Log(urllib.__file__, urlretrieve) fpath = urllib.urlretrieve(imgurl)[0] I called self.Log() after each line, and also from a general except: clause. Definitely, the line after urlretrieve is not executed, and no exception is raised. Number of threads goes up (visible from task manager). It is true that the program uses another module that uses the socket module and multiple threads. (These are written in pure python.) If I remove the other module, then there is no error, however it renders the application useless. If I start the program with a console (e.g. with python.exe instead of pythonw.exe) then it works. Looks like opening a console solves the problem, although nothing is ever printed on the console. and ensure that you haven't accidentally shadowed them with something unexpected. Does the output printed to the console match the output logged? Well, this cannot be tested. If there is a console, then there is no problem. What happens if you take the call to urlretrieve out of the thread and call it by hand? Then it works. Run urllib.urlretrieve(imgurl) directly in the interactive interpreter. Does it still hang forever? Then it works perfectly. When you say it never returns, do you mean *never* or do you mean I gave up waiting after five minutes? What happens if you leave it to run all day? I did not try that. But I have already set socket timeout to 10 seconds, and definitely it is not waiting for a response from the server. How big are the files you are trying to retrieve? 34 KB Try retrieving a really small file. Then try retrieving a non-existent file. Good point. I'll try to retrieve a nonexistent file when I get home. :) What happens if you call urlretrieve with a reporthook argument? Does it print anything? I'll try this too. I'll also try using pycurl or the low level socket module instead. What happens if you try to browse to imgurl in your web browser? Are you sure the problem is with urlretrieve and not the source? Yes. -- http://mail.python.org/mailman/listinfo/python-list
Re: Currying in Python
On 19 March 2012 23:20, Ian Kelly ian.g.ke...@gmail.com wrote: I hope you don't mind if I critique your code a bit! On Fri, Mar 16, 2012 at 7:21 PM, Kiuhnm kiuhnm03.4t.yahoo...@mail.python.org wrote: Here we go. --- def genCur(f, unique = True, minArgs = -1): It is customary in Python for unsupplied arguments with no default to use the value None, not -1. That's what it exists for. Generates a 'curried' version of a function. def geng(curArgs, curKwargs): def g(*args, **kwargs): nonlocal f, curArgs, curKwargs, minArgs; # our STATIC data I don't know if all the rest of the code is below, but this line above would only be necessary if you want to rebind f, curArgs, minArgs. You don't seem to do it, so I think this line is unnecessary. Also, your naming of variables disagrees with PEP 8 :) if len(args) or len(kwargs): Collections evaluate as true if they are not empty, so this could just be: if args or kwargs: # Allocates data for the next 'g'. We don't want to modify our # static data. newArgs = curArgs[:]; Semicolon to end a statement? newKwargs = dict.copy(curKwargs); # Adds positional arguments. newArgs += args; # Adds/updates keyword arguments. if unique: # We don't want repeated keyword arguments. for k in kwargs.keys(): if k in newKwargs: raise(Exception(Repeated kw arg while unique = True)); newKwargs.update(kwargs); Since you're writing this for Python 3 (as evidenced by the use of the nonlocal keyword), you could take advantage here of the fact that Python 3 dictionary views behave like sets. Also, you should use a more specific exception type: if unique and not kwargs.keys().isdisjoint(newKwargs): raise ValueError(A repeated keyword argument was supplied) # Checks whether it's time to evaluate f. if minArgs = 0 and minArgs = len(newArgs) + len(newKwargs): With minArgs defaulting to None, that would be: if minArgs is not None and minArgs = len(newArgs) + len(newKwargs): return f(*newArgs, **newKwargs); # f has enough args else: return geng(newArgs, newKwargs); # f needs some more args else: return f(*curArgs, **curKwargs); # the caller forced the evaluation return g; return geng([], {}); def cur(f, minArgs = -1): return genCur(f, True, minArgs); def curr(f, minArgs = -1): return genCur(f, False, minArgs); The names cur and curr are terrible. Good names should describe what the function does without being too onerous to type, and the addition of the duplicate r is not an obvious mnemonic for remembering that the first one prohibits duplicate keyword arguments and the second one allows them. Why not more descriptive names like curry and curry_unique? That's all I've got. All in all, it's pretty decent for a Python newbie. Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Distribution
prince.pangeni wrote: Hi all, I am doing a simulation project using Python. In my project, I want to use some short of distribution to generate requests to a server. The request should have two distributions. One for request arrival rate (should be poisson) and another for request mix (i.e. out of the total requests defined in request arrival rate, how many requests are of which type). Example: Suppose the request rate is - 90 req/sec (generated using poisson distribution) at time t and we have 3 types of requests (i.e. r1, r2, r2). The request mix distribution output should be similar to: {r1 : 50 , r2 : 30 , r3 : 10} (i.e. out of 90 requests - 50 are of r1 type, 30 are of r2 type and 10 are of r3 type). As I an new to python distribution module, I am not getting how to code this situation. Please help me out for the same. You don't say what distribution module you're talking of, and I guess I'm not the only one who'd need to know that detail. However, with sufficient resolution and duration the naive approach sketched below might be good enough. # untested DURATION = 3600 # run for one hour RATE = 90 # requests/sec RESOLUTION = 1000 # one msec requests = ([r1]*50 + [r2]*30 + [r3]*10) time_slots = [0]*(RESOLUTION*DURATION) times = range(RESOLUTION*DURATION) for _ in range(DURATION*RATE): time_slots[random.choice(times)] += 1 for time, count in enumerate(time_slots): for _ in range(count): issue_request_at(random.choice(requests), time) -- http://mail.python.org/mailman/listinfo/python-list
Re: Currying in Python
On 3/20/2012 0:20, Ian Kelly wrote: Since you're writing this for Python 3 (as evidenced by the use of the nonlocal keyword), you could take advantage here of the fact that Python 3 dictionary views behave like sets. Also, you should use a more specific exception type: As a side note, nonlocal isn't needed in my code, in fact I removed it right after my first post. Kiuhnm -- http://mail.python.org/mailman/listinfo/python-list
Re: Currying in Python
On 3/20/2012 8:11, Arnaud Delobelle wrote: On 19 March 2012 23:20, Ian Kellyian.g.ke...@gmail.com wrote: I hope you don't mind if I critique your code a bit! On Fri, Mar 16, 2012 at 7:21 PM, Kiuhnm kiuhnm03.4t.yahoo...@mail.python.org wrote: Here we go. --- def genCur(f, unique = True, minArgs = -1): It is customary in Python for unsupplied arguments with no default to use the value None, not -1. That's what it exists for. Generates a 'curried' version of a function. def geng(curArgs, curKwargs): def g(*args, **kwargs): nonlocal f, curArgs, curKwargs, minArgs;# our STATIC data I don't know if all the rest of the code is below, but this line above would only be necessary if you want to rebind f, curArgs, minArgs. You don't seem to do it, so I think this line is unnecessary. What a coincidence. I was just telling that to Ian Kelly. I removed it from the code in my article a few days ago but forgot to update my post on this ng. Also, your naming of variables disagrees with PEP 8 :) if len(args) or len(kwargs): Collections evaluate as true if they are not empty, so this could just be: if args or kwargs: # Allocates data for the next 'g'. We don't want to modify our # static data. newArgs = curArgs[:]; Semicolon to end a statement? As above. Too many years of C++. Kiuhnm -- http://mail.python.org/mailman/listinfo/python-list
Re: Eclipse, C, and Python
On 20/03/2012 06:00, Richard Medina Calderon wrote: Hello Forum. I have installed Python comnpiler in Eclipse Classic for Windows. After a while I have installed the C compiler. However, somehow now when I try to run my code in Python it shows me for default Ant Run --Ant Build I switched my workspace but still. Do you know how to solve this?.. Thanks You might want to install the PyDev plugin and switch to that perspective (after configuring it). Cheers, MArtin -- http://mail.python.org/mailman/listinfo/python-list
Re: pypi and dependencies
Andrea Crotti andrea.crott...@gmail.com writes: When I publish something on Pypi, is there a way to make it fetch the list of dependencies needed by my project automatically? It would be nice to have it in the Pypi page, without having to look at the actual code.. Sadly, no. The metadata available for packages on PyPI does not include information about the dependencies. (I'd love to be wrong about that, but I'm pretty certain that for most, if not all, packages that's the case.) Any other possible solution? All the solutions I've seen involve fetching the full package in order to unpack it and *then* parse it for dependencies. This is very sub-optimal, and I believe people are working on it; but fixing it will at least require adjustment to all existing packages that don't have dependencies in their metadata. -- \ “Some people have a problem, and they think “I know, I'll use | `\ Perl!”. Now they have some number of problems but they're not | _o__) sure whether it's a string or an integer.” —Benno Rice, 2011 | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: Distribution
prince.pangeni prince.ra...@gmail.com writes: I am doing a simulation project using Python. In my project, I want to use some short of distribution to generate requests to a server. What is a distribution? That term already means something in Python jargon, and it doesn't match the rest of your use case. So what do you mean by “distribution”? Maybe we can find a less confusing term. -- \ “I used to think that the brain was the most wonderful organ in | `\ my body. Then I realized who was telling me this.” —Emo Philips | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is readable
In article mailman.795.1332131633.3037.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: On Mon, Mar 19, 2012 at 12:23 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Mon, 19 Mar 2012 09:02:06 +1100, Chris Angelico wrote: On Mon, Mar 19, 2012 at 8:30 AM, John Ladasky lada...@my-deja.com wrote: What I would say is that, when PROGRAMMERS look at Python code for the first time, they will understand what it does more readily than they would understand other unfamiliar programming languages. =A0That has value. This is something that's never truly defined. I'm sorry, I don't understand what part of John's sentence you mean by this. Programmers? Value? Understand? I should have rewritten that into the next paragraph. Anyhow. Further explanation below. Everyone talks of how this language or that language is readable, but if you mean that you can look at a line of code and know what *that line* does then Python suffers badly and assembly language wins out; This is at least the second time you've alleged that assembly language is more readable than Python. I think you're a raving nutter, no offence Chris :-) None taken; guilty as charged. And unashamedly so. With that dealt with, though: My calling assembly readable is a form of argument by drawing to logical, but absurd, conclusion - by the given definition of readability, assembly is readable, ergo the definition sucks. (That's a term all logicians use, you know. Proper and formal jargon.) Assignment (name binding) is close to the absolute simplest thing you can do in a programming language. In Python, the syntax is intuitive to anyone who has gone through high school, or possibly even primary school, and been introduced to the equals sign. x =3D 1234 y =3D Hello Not quite. In mathematics, x =3D 1234 is either a declaration of fact, or a statement that can be either true or false. In mathematics, x =3D x + 1 is absurd and/or simply false. That's why Pascal has its :=3D operator, supposed to be read as becomes and not equals. IMHO this is simply proof of one of the differences between programming and mathematics. I don't know about anyone else, but I wouldn't have guessed that the way to get x=3D1234 was with x dw 1234. Except that it's not quite the same thing. That 8086 Assembly statement is more like the C statement: int x=3D1234; The nearest equivalent of assignment is: mov x,1234 I tried to mentally translate that to my ciasdis assembler syntax and discovered that there is no instruction in the 8086 for that. It would require using a scratch register like AX. In my very precise ciasdis assembler syntax it would be 1] XX: DL 0 MOVI, X| R| AX| 1234 IL, MOV, X| F| R| [AX] XX L, If you were restricted to the 8086, (not 80386 or better) you could not have chosen AX, and you would have used BX instead. [ The first MOVI, could be replaced by a LEA, instruction LEA, AX'| MEM| XX L, (Go figure!) ] So a realistic fragment could have been PUSH|X BX, MOVI, X| R| BX| 1234 IL,, MOV, X| F| R| [BX] XX L, POP|X BX, The real unreadability comes from the fact that the novice would ask herself why on earth the BX register was freed while the AX register was free to use. And she is lucky, because no flags were harmed in this sequence, another pitfall. You can't blame me for the unreadibility of the ciasdis-syntax. It merely reflects the abomination that the 8086/80386/Pentium is. Bottom line. A comparison between a HLL where the goal is abstraction and assembly where the goal is precision and control, is unproductive. And if you insist to do it, you better be a real expert. SNIP And that's where the nub of the question is. How well is sufficiently well? Clearly you do not require your code to be comprehensible to a non-programmer, or you would not write code at all. If you don't demand that the reader learn basic keywords of the language, then it's equally impossible to expect them to comprehend your code. If you're writing production code, I see no reason to avoid language features like Python's list comps, Pike's %{ %} sprintf codes, or C's pointer arithmetic, just because they can confuse people. Learn the language, THEN start hacking on the code. Can we just agree, that it is a compromise? ChrisA 1] ciasdis.html on the site in my sig. Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: Distribution
On 3/20/12 11:21 AM, Ben Finney wrote: prince.pangeniprince.ra...@gmail.com writes: I am doing a simulation project using Python. In my project, I want to use some short of distribution to generate requests to a server. What is a distribution? That term already means something in Python jargon, and it doesn't match the rest of your use case. So what do you mean by “distribution”? Maybe we can find a less confusing term. Judging from the context, he means a probability distribution. -- 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: pypi and dependencies
On 03/20/2012 11:18 AM, Ben Finney wrote: Andrea Crottiandrea.crott...@gmail.com writes: When I publish something on Pypi, is there a way to make it fetch the list of dependencies needed by my project automatically? It would be nice to have it in the Pypi page, without having to look at the actual code.. Sadly, no. The metadata available for packages on PyPI does not include information about the dependencies. (I'd love to be wrong about that, but I'm pretty certain that for most, if not all, packages that's the case.) Any other possible solution? All the solutions I've seen involve fetching the full package in order to unpack it and *then* parse it for dependencies. This is very sub-optimal, and I believe people are working on it; but fixing it will at least require adjustment to all existing packages that don't have dependencies in their metadata. Yes that's not so nice, many projects write clearly the dependencies in the README file, but that's annoying because it might get outdated. And it's also sad that it's not automatically fetched from setuptools, because it's just python setup.py egg-info cat package.egg-info/requirements.txt to actually extract them. Should I file a bug maybe or is completely not feasible? -- http://mail.python.org/mailman/listinfo/python-list
Re: pypi and dependencies
packaging (in 3.3) and distutils2 (2.x-3.2) is a new metadata format for python packages. It gets rid of setup.py and it includes a way to specify the requirements that your package needs. This will show up on PyPI/Crate. On Tuesday, March 20, 2012 at 8:01 AM, Andrea Crotti wrote: On 03/20/2012 11:18 AM, Ben Finney wrote: Andrea Crottiandrea.crott...@gmail.com (mailto:andrea.crott...@gmail.com) writes: When I publish something on Pypi, is there a way to make it fetch the list of dependencies needed by my project automatically? It would be nice to have it in the Pypi page, without having to look at the actual code.. Sadly, no. The metadata available for packages on PyPI does not include information about the dependencies. (I'd love to be wrong about that, but I'm pretty certain that for most, if not all, packages that's the case.) Any other possible solution? All the solutions I've seen involve fetching the full package in order to unpack it and *then* parse it for dependencies. This is very sub-optimal, and I believe people are working on it; but fixing it will at least require adjustment to all existing packages that don't have dependencies in their metadata. Yes that's not so nice, many projects write clearly the dependencies in the README file, but that's annoying because it might get outdated. And it's also sad that it's not automatically fetched from setuptools, because it's just python setup.py egg-info cat package.egg-info/requirements.txt to actually extract them. Should I file a bug maybe or is completely not feasible? -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Distribution
On 3/20/12 4:31 AM, prince.pangeni wrote: Hi all, I am doing a simulation project using Python. In my project, I want to use some short of distribution to generate requests to a server. The request should have two distributions. One for request arrival rate (should be poisson) and another for request mix (i.e. out of the total requests defined in request arrival rate, how many requests are of which type). Example: Suppose the request rate is - 90 req/sec (generated using poisson distribution) Just a note on terminology to be sure we're clear: a Poisson *distribution* models the number of arrivals in a given time period if the events are from a Poisson *process* with a given mean rate. To model the inter-event arrival times, you use an exponential distribution. If you want to handle events individually in your simulation, you will need to use the exponential distribution to figure out the exact times for each. If you are handling all of the events in each second in bulk without regard to the exact times or ordering within that second, then you can use a Poisson distribution. at time t and we have 3 types of requests (i.e. r1, r2, r2). The request mix distribution output should be similar to: {r1 : 50 , r2 : 30 , r3 : 10} (i.e. out of 90 requests - 50 are of r1 type, 30 are of r2 type and 10 are of r3 type). As I an new to python distribution module, I am not getting how to code this situation. Please help me out for the same. I am going to assume that you want to handle each event independently. A basic strategy is to keep a time variable starting at 0 and use a while loop until the time reaches the end of the simulation time. Increment it using a draw from the exponential distribution each loop. Each iteration of the loop is an event. To determine the kind of event, you will need to draw from a weighted discrete distribution. What you want to do here is to do a cumulative sum of the weights, draw a uniform number from 0 to the total sum, then use bisect to find the item that matches. import bisect import random # Use a seeded PRNG for repeatability. Use the methods on the Random # object rather than the functions in the random module. prng = random.Random(1234567890) avg_rate = 90.0 # reqs/sec kind_weights = [50.0, 30.0, 10.0] kind_cumsum = [sum(kind_weights[:i+1]) for i in range(len(kind_weights))] kind_max = kind_cumsum[-1] max_time = 10.0 # sec t = 0.0 # sec events = [] # (t, kind) while t max_time: dt = prng.expovariate(avg_rate) u = prng.uniform(0.0, kind_max) kind = bisect.bisect_left(kind_cumsum, u) events.append((t, kind)) t += dt -- 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: Eclipse, C, and Python
On Mon, 19 Mar 2012 23:00:50 -0700, Richard Medina Calderon wrote: Hello Forum. I have installed Python comnpiler in Eclipse Classic for Windows. After a while I have installed the C compiler. However, somehow now when I try to run my code in Python it shows me for default Ant Run --Ant Build I switched my workspace but still. Do you know how to solve this?.. This is an Eclipse problem, not a Python problem. Most people here don't use Eclipse. You might have better luck asking on a forum for Eclipse. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: s_push parser stack overflow
On Tue, 20 Mar 2012 04:30:51 +, MRAB wrote: On 20/03/2012 03:19, Артём Назаров wrote: Hi. Sorry of my english :-) code: print (((0))) message from python is: s_push parser stack overflow Can i configure phyton to solve this problem without change MAXSTACK in parser.c and re-build the python? A quick look at parser.h tells me that it's a hard-coded limit: typedef struct { stackentry *s_top; /* Top entry */ stackentry s_base[MAXSTACK];/* Array of stack entries */ /* NB The stack grows down */ } stack; But why such an obscure print statement anyway? is it purely to show the issue or is there some actual reason behind it? -- divorce, n: A change of wife. -- http://mail.python.org/mailman/listinfo/python-list
code for computing and printing list of combinations
To All, Can someone help me with the proper code to compute combinations for n=7, r=5 for the following list of numbers: 7, 8, 10, 29, 41, 48, 55. There should be 21 combination. Also once there list is made can a code be written to add (sum) each of the set of five number in the the list. For example list: 8, 10, 29, 48, 55, = 150. Thanks-- http://mail.python.org/mailman/listinfo/python-list
Re: code for computing and printing list of combinations
Joi Mond wrote: Can someone help me with the proper code to compute combinations for n=7, r=5 for the following list of numbers: 7, 8, 10, 29, 41, 48, 55. There should be 21 combination. Also once there list is made can a code be written to add (sum) each of the set of five number in the the list. For example list: 8, 10, 29, 48, 55, = 150. Thanks [sum(x) for x in itertools.combinations([7,8,10,29,41,48,55], 5)] [95, 102, 109, 114, 121, 128, 133, 140, 147, 159, 135, 142, 149, 161, 180, 136, 143, 150, 162, 181, 183] Best wishes to your teacher... -- http://mail.python.org/mailman/listinfo/python-list
Re: code for computing and printing list of combinations
On 03/20/12 09:59, Joi Mond wrote: To All, Can someone help me with the proper code to compute combinations for n=7, r=5 for the following list of numbers: 7, 8, 10, 29, 41, 48, 55. There should be 21 combination. Also once there list is made can a code be written to add (sum) each of the set of five number in the the list. For example list: 8, 10, 29, 48, 55, = 150. Thanks Sounds like you want to read up on itertools.combinations() and the sum() function. http://docs.python.org/library/itertools.html#itertools.combinations or import itertools help(itertools.combinations) This sounds like a homework problem, so I won't hand you the answer, but you pass your list to combinations() with the grouping-size (r). You then iterate over the results of that, and use sum() on the results. -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is readable
Just to troll the discussion a little bit more... On Sun, Mar 18, 2012 at 6:02 PM, Chris Angelico ros...@gmail.com wrote: On Mon, Mar 19, 2012 at 8:30 AM, John Ladasky lada...@my-deja.com wrote: What I would say is that, when PROGRAMMERS look at Python code for the first time, they will understand what it does more readily than they would understand other unfamiliar programming languages. That has value. This is something that's never truly defined. Everyone talks of how this language or that language is readable, but if you mean that you can look at a line of code and know what *that line* does, then Python suffers badly and assembly language wins out; but if you mean that you should be able to glance over an entire function and comprehend its algorithm, then I have yet to see any language in which it's not plainly easy to write bad code. Even with good code, anything more than trivial can't be eyeballed in that way - if you could, what would docstrings be for? I agree, docstrings/code comments are a pretty obvious indication that code (as it exists currently) fails as a human communication medium. I suppose that I could make an exception for elaboration on statement with subtle implications. This seems like something people should think more about fixing. Really, the metric MUST be Python programmers. Intuitiveness is of value, but readability among experienced programmers is far more useful. If I write a whole lot of code today, and next year I'm dead and someone else has replaced me, I frankly don't mind if he has to learn the language before he can grok my code. I _do_ mind if, even after he's learned the language, he can't figure out what my code's doing; and that's where Python's placed itself at about the right level - not so high that it's all in airy-fairy conceptual work, but not so low that it gets bogged down. There's a handful of other languages that are similarly placed, and they're the languages that I would call readable. In mathematics, when you perform global optimization you must be willing to make moves in the solution space that may result in a temporary reduction of your optimality condition. If you just perform naive gradient decent, only looking to the change that will induce the greatest immediate improvement in optimality, you will usually end up orbiting around a solution which is not globally optimal. I mention this because any readability or usability information gained using trained programmers is simultaneously measuring the readability or usability and its conformance to the programmer's cognitive model of programming. The result is local optimization around the current-paradigm minimum. This is why we have so many nearly identical curly brace C-like languages. In my opinion, language readability and usability should be determined based on the following tests: - Given users with no programming experience: -- What is the probability that they can correctly guess the result of a program, and how long does it take? -- What is the probability that they can take a program and correctly modify it to change its output to another specified output, or modify it to support another input representation, and how long does it take? - Given users with no programming experience who are provided with a controlled training period: -- What is the probability that they can produce a program that correctly implements a simple, completely described algorithm for solving a puzzle or winning a game, and how long does it take? - Given users with previous (but not extensive) programming experience who are provided with a controlled training period: -- What is the probability that they can produce a program that correctly implements a simple, partially described algorithm for solving a puzzle or winning a game, and how long does it take? -- What is the probability that they can produce a program that correctly implements a complex, completely described algorithm for solving a puzzle or winning a game, and how long does it take? It would probably also be worth examining user behavior relating to code organization and composition under a variety of circumstances. It seems likely that if proper organization and composition are intuitive, productivity would scale well with program size. Here's an analogy: One statement (aka line of code, etc) corresponds to one sentence in English. Massive one-liners are like some of the sentences in Paul's epistles; assembly language is like The cat sat on the mat. Both are valid; both are hard to read. This is one of my gripes with the dogmatic application of the break it into multiple statements mantra of Python. Not only are you forced to use generators to maintain semantic equivalence in many cases, in some cases a partial statement fragment doesn't have any intuitive meaning. The result is that readers are forced to hold the value of intermediate_variable in their head while reading another statement, then
Fabric Engine v1.0 released under AGPL
Hi everyone - just letting you know that we released v1.0 of Fabric Engine today. We've open-sourced the core under AGPL, so I hope that gives you an incentive to get started with high-performance for Python :) http://fabricengine.com/technology/benchmarks/ - to give you an idea of the kind of performance possible. Most of these are with node, but the core engine is the same - we just bound it to Python. For those of you using Python on the desktop (particularly if you're working with 3D), we've started a closed beta on a PyQt framework - you can see more here: http://fabricengine.com/2012/03/pyqt-framework-for-fabric-engine/ - email b...@fabricengine.com if you'd like to take part in the testing program. Thanks for your time, Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Distribution
Il 20/03/2012 12:21, Ben Finney ha scritto: prince.pangeniprince.ra...@gmail.com writes: I am doing a simulation project using Python. In my project, I want to use some short of distribution to generate requests to a server. I guess scipy is also available in plain python (didn't check), but the following works with Sage : -- | Sage Version 4.8, Release Date: 2012-01-20 | | Type notebook() for the GUI, and license() for information.| -- sage: from scipy import stats sage: X=stats.poisson.rvs sage: X(4) 5 sage: X(4) 2 sage: X(4) 3 Hope it helps Laurent -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is readable
On Tue, 20 Mar 2012 12:55:07 -0400, Nathan Rice wrote: This is one of my gripes with the dogmatic application of the break it into multiple statements mantra of Python. I must admit I don't recognise that one, unless you're talking about not everything needs to be a one liner. Not only are you forced to use generators to maintain semantic equivalence in many cases, in some cases a partial statement fragment doesn't have any intuitive meaning. The result is that readers are forced to hold the value of intermediate_variable in their head while reading another statement, then translate the statement to the conceptually complete form. A statement should be an encoding from a conceptual space to a operation space, and ideally the two should be as similar as possible. If a concept is atomic, it should not be comprised of multiple statements. Perhaps you could give some examples (actual or contrived) of stuff where breaking it into multiple statements is a bad thing? -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is readable
On 3/20/2012 12:55 PM, Nathan Rice wrote: I agree, docstrings/code comments are a pretty obvious indication that code (as it exists currently) fails as a human communication medium. The fact that scientific journal articles start with a documentation string called an abstract does not indicate that scientific English fails as a human communication medium. Function docstrings say what the function does and how to use it without reading the code. They can be pulled out and displayed elsewhere. They also guide the reading of the code. Abstracts serve the same functions. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Enforcing hash randomization (was: [RELEASED] Second release candidates for Python 2.6.8, 2.7.3, 3.1.5, and 3.2.3)
Benjamin Peterson wrote: Hash randomization causes the iteration order of dicts and sets to be unpredictable and differ across Python runs. Python has never guaranteed iteration order of keys in a dict or set, and applications are advised to never rely on it. Historically, dict iteration order has not changed very often across releases and has always remained consistent between successive executions of Python. Thus, some existing applications may be relying on dict or set ordering. Because of this and the fact that many Python applications which don't accept untrusted input are not vulnerable to this attack, in all stable Python releases mentioned here, HASH RANDOMIZATION IS DISABLED BY DEFAULT. There are two ways to enable it. The -R commandline option can be passed to the python executable. It can also be enabled by setting an environmental variable PYTHONHASHSEED to random. (Other values are accepted, too; pass -h to python for complete description.) I wonder how I could enforce hash randomization from within a Python app without too much hassle. I'd like to avoid having to rely on sys-admins doing the right thing when installing my web2ldap. I guess os.environ['PYTHONHASHSEED'] = 'random' before forking a process would be a solution. But is there another way? Ciao, Michael. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is readable
This is one of my gripes with the dogmatic application of the break it into multiple statements mantra of Python. I must admit I don't recognise that one, unless you're talking about not everything needs to be a one liner. ... Perhaps you could give some examples (actual or contrived) of stuff where breaking it into multiple statements is a bad thing? One example is performing a series of transformations on a collection of data, with the intent of finding an element of that collection that satisfies a particular criterion. If you separate out the individual transformations, you need to understand generators or you will waste space and perform many unnecessary calculations. If you only ever do a single transformation with a clear conceptual meaning, you could create a master transformation function, but what if you have a large number of potential permutations of that function? What if you are composing three or four functions, each of which is conditional on the data? If you extract things from a statement and assign them somewhat arbitrary names, you've just traded horizontal bloat for vertical bloat (with a net increase in volume), while forcing a reader to scan back and forth to different statements to understand what is happening. To steal a line from Einstein, Make things as simple as possible, but not simpler I agree, docstrings/code comments are a pretty obvious indication that code (as it exists currently) fails as a human communication medium. The fact that scientific journal articles start with a documentation string called an abstract does not indicate that scientific English fails as a human communication medium. Function docstrings say what the function does and how to use it without reading the code. They can be pulled out and displayed elsewhere. They also guide the reading of the code. Abstracts serve the same functions. A paper, with topic introduction, methods exposition, data/results description and discussion is a poor analog to a function. I would compare the abstract of a scientific paper to the overview section of a program's documentation. The great majority of the docstrings I see are basically signature rehashes with added type information and assertions, followed by a single sentence English gloss-over. If the code were sufficiently intuitive and expressive, that would be redundant. Of course, there will always be morbidly obese functions and coders that like to wax philosophical or give history lessons in comments. Also, because of Sphinx, it is very common in the Python community weave documents and code together in a way that is convenient for authors but irritating for readers. I personally would prefer not to have to scroll past 100 lines of a tutorial with examples, tests and what not in order to go from one function to another. It would be really awesome if everyone used links to that material in docstrings, and the default sphinx theme created an inline collapsible iframe that included that material for the HTML version. Don't get me wrong, I adore Sphinx, the problem here is people who are lazy or don't know the right way to structure docs. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is readable
On 3/20/2012 3:28 PM, Nathan Rice wrote: This is one of my gripes with the dogmatic application of the break it into multiple statements mantra of Python. I must admit I don't recognise that one, unless you're talking about not everything needs to be a one liner. ... Perhaps you could give some examples (actual or contrived) of stuff where breaking it into multiple statements is a bad thing? One example is performing a series of transformations on a collection of data, with the intent of finding an element of that collection that satisfies a particular criterion. If you separate out the individual transformations, you need to understand generators or you will waste space and perform many unnecessary calculations. If you only ever do a single transformation with a clear conceptual meaning, you could create a master transformation function, but what if you have a large number of potential permutations of that function? What if you are composing three or four functions, each of which is conditional on the data? If you extract things from a statement and assign them somewhat arbitrary names, you've just traded horizontal bloat for vertical bloat (with a net increase in volume), while forcing a reader to scan back and forth to different statements to understand what is happening. To steal a line from Einstein, Make things as simple as possible, but not simpler I agree, docstrings/code comments are a pretty obvious indication that code (as it exists currently) fails as a human communication medium. The fact that scientific journal articles start with a documentation string called an abstract does not indicate that scientific English fails as a human communication medium. Function docstrings say what the function does and how to use it without reading the code. They can be pulled out and displayed elsewhere. They also guide the reading of the code. Abstracts serve the same functions. A paper, with topic introduction, methods exposition, data/results description and discussion is a poor analog to a function. I would compare the abstract of a scientific paper to the overview section of a program's documentation. The great majority of the docstrings I see are basically signature rehashes with added type information and assertions, followed by a single sentence English gloss-over. If the code were sufficiently intuitive and expressive, that would be redundant. Of course, there will always be morbidly obese functions and coders that like to wax philosophical or give history lessons in comments. Both abstracts and doc strings are designed to be and are read independently of the stuff they summarize. Perhaps you do not use help(obj) as often as some other people do. Also, because of Sphinx, it is very common in the Python community weave documents and code together in a way that is convenient for authors but irritating for readers. I personally would prefer not to have to scroll past 100 lines of a tutorial with examples, tests and what not in order to go from one function to another. If I understand you, some devs agree. Hence the increasing use of How-to docs with tutorial and example material for a module separate from the reference entries in its section of the Library Reference. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: urllib.urlretrieve never returns???
2012.03.20. 8:08 keltezéssel, Laszlo Nagy írta: Here you can find the example program and the original post. http://code.activestate.com/lists/python-list/617894/ I gather you are running urlretrieve in a separate thread, inside a GUI? Yes. I have learned that whenever I have inexplicable behaviour in a function, I should check my assumptions. In this case, (1) are you sure you have the right urlretrieve, and (2) are you sure that your self.Log() method is working correctly? Just before the problematic call, do this: # was: fpath = urllib.urlretrieve(imgurl)[0] # becomes: print(urllib.__file__, urlretrieve) self.Log(urllib.__file__, urlretrieve) fpath = urllib.urlretrieve(imgurl)[0] I called self.Log() after each line, and also from a general except: clause. Definitely, the line after urlretrieve is not executed, and no exception is raised. Number of threads goes up (visible from task manager). It is true that the program uses another module that uses the socket module and multiple threads. (These are written in pure python.) If I remove the other module, then there is no error, however it renders the application useless. If I start the program with a console (e.g. with python.exe instead of pythonw.exe) then it works. Looks like opening a console solves the problem, although nothing is ever printed on the console. and ensure that you haven't accidentally shadowed them with something unexpected. Does the output printed to the console match the output logged? Well, this cannot be tested. If there is a console, then there is no problem. What happens if you take the call to urlretrieve out of the thread and call it by hand? Then it works. Run urllib.urlretrieve(imgurl) directly in the interactive interpreter. Does it still hang forever? Then it works perfectly. When you say it never returns, do you mean *never* or do you mean I gave up waiting after five minutes? What happens if you leave it to run all day? I did not try that. But I have already set socket timeout to 10 seconds, and definitely it is not waiting for a response from the server. How big are the files you are trying to retrieve? 34 KB Try retrieving a really small file. Then try retrieving a non-existent file. Good point. I'll try to retrieve a nonexistent file when I get home. :) Today I got a different error message printed on console (program started with python.exe) Unhandled exception in thread started by bound method FrameLocEdit.GetThumbnail of locedit.FrameLocEdit; proxy of Swig Object of type 'wxPanel *' at 0x4f85300 Unhandled exception in thread started by bound method FrameLocEdit.GetThumbnail of locedit.FrameLocEdit; proxy of Swig Object of type 'wxPanel *' at 0x4f85300 Unhandled exception in thread started by bound method FrameLocEdit.GetThumbnail of locedit.FrameLocEdit; proxy of Swig Object of type 'wxPanel *' at 0x4f85300 Unhandled exception in thread started by Traceback (most recent call last): Traceback (most recent call last): Traceback (most recent call last): bound method FrameLocEdit.GetThumbnail of locedit.FrameLocEdit; proxy of Swig Object of type 'wxPanel *' at 0x4f85300 File C:\Python\Projects\Warehouserclient_v3\locedit.py, line 917, in GetThumbnail File C:\Python\Projects\Warehouserclient_v3\locedit.py, line 917, in GetThumbnail File C:\Python\Projects\Warehouserclient_v3\locedit.py, line 917, in GetThumbnail sys.excepthook is missing Traceback (most recent call last): I have never seen a traceback like this before. I didn't install any excepthook myself. Program is using wxPython, socket, threads, threading, PIL. Here is something even more strange. If I click on the button three times, then absolutely nothing gets printed on stdout. However, if I close the program with file/exit (actually, calling wx.PySimpleApp.ExitMainLoop) then suddenly three stack traces are printed on stdout, all lines mixed up: Unhandled exception in thread started by bound method FrameLocEdit.GetThumbnail of locedit.FrameLocEdit; proxy of Swig Object of type 'wxPanel *' at 0x4fb530 0 Unhandled exception in thread started by Unhandled exception in thread started by bound method FrameLocEdit.GetThumbnail of locedit.FrameLocEdit; proxy of Swig Object of type 'wxPanel *' at 0x4fb5300 Unhandled exception in thread started by Unhandled exception in thread started by bound method FrameLocEdit.GetThumbnail of locedit.FrameLocEdit; proxy of Swig Object of type 'wxPanel *' at 0x4fb5300 Traceback (most recent call last):bound method FrameLocEdit.GetThumbnail of locedit.FrameLocEdit; proxy of Swig Object of type 'wxPanel *' at 0x4fb5300 Traceback (most recent call last):bound method FrameLocEdit.GetThumbnail of locedit.FrameLocEdit; proxy of Swig Object of type 'wxPanel *' at 0x4fb5300 Traceback (most recent call last): File C:\Python\Projects\Warehouserclient_v3\locedit.py, line 917, in GetThumbnail Traceback (most recent call last): File
Re: urllib.urlretrieve never returns???
On 3/17/2012 9:34 AM, Chris Angelico wrote: 2012/3/18 Laszlo Nagygand...@shopzeus.com: In the later case, log.txt only contains #1 and nothing else. If I look at pythonw.exe from task manager, then its shows +1 thread every time I click the button, and #1 is appended to the file. Does it fail to retrieve on all URLs, or only on some of them? Running a web crawler, I've seen some pathological cases. There are a very few sites that emit data very, very slowly, but don't time out because they are making progress. There are also some sites where attempting to negotiate a SSL connection results in the SSL protocol reaching a point where the host end is supposed to finish the handshake, but it doesn't. The odds are against this being the problem. I see problems like that in maybe 1 in 100,000 URLs. John Nagle -- http://mail.python.org/mailman/listinfo/python-list
Re: Distribution
On 20/03/12 04:31, prince.pangeni wrote: Hi all, I am doing a simulation project using Python. In my project, I want to use some short of distribution to generate requests to a server. The request should have two distributions. One for request arrival rate (should be poisson) and another for request mix (i.e. out of the total requests defined in request arrival rate, how many requests are of which type). Example: Suppose the request rate is - 90 req/sec (generated using poisson distribution) at time t and we have 3 types of requests (i.e. r1, r2, r2). The request mix distribution output should be similar to: {r1 : 50 , r2 : 30 , r3 : 10} (i.e. out of 90 requests - 50 are of r1 type, 30 are of r2 type and 10 are of r3 type). As I an new to python distribution module, I am not getting how to code this situation. Please help me out for the same. Thanks in advance Prince Robert has given you a very good answer. The easiest way is to generate interarrival times using an exponential distribution, then for each event select the type from a categorical probability mass function. Perhaps the easiest and most efficient approach for the latter using your 'mix distribution' above is to create a list containing 5 instances of r1, 3 of r2 and 1 of r3. Then select the type by generating a random index into the list. It is not an ideal solution generally, but good when the parameters do not change and the required list is small. Duncan -- http://mail.python.org/mailman/listinfo/python-list
List comprehension/genexp inconsistency.
One of my coworkers just stumbled across an interesting issue. I'm hoping someone here can explain why it's happening. When trying to create a class with a dual-loop generator expression in a class definition, there is a strange scoping issue where the inner variable is not found, (but the outer loop variable is found), while a list comprehension has no problem finding both variables. Demonstration: class Spam: ... foo, bar = 4, 4 ... baz = dict(((x, y), x+y) for x in range(foo) for y in range(bar)) ... Traceback (most recent call last): File stdin, line 1, in module File stdin, line 3, in Spam File stdin, line 3, in genexpr NameError: global name 'bar' is not defined class Eggs(object): ... foo, bar = 4, 4 ... baz = dict([((x, y), x+y) for x in range(foo) for y in range(bar)]) ... This was discovered in python 2.6. In python 3.2, both versions fail with the same NameError. Obviously, this is easy enough to work around. I'm curious though: What's going on under the hood to cause the nested generator expression to fail while the list comprehension succeeds? Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list
Re: Fabric Engine v1.0 released under AGPL
On 20/03/2012 12:51 PM, Fabric Paul wrote: Hi everyone - just letting you know that we released v1.0 of Fabric Engine today. We've open-sourced the core under AGPL, so I hope that gives you an incentive to get started with high-performance for Python :) http://fabricengine.com/technology/benchmarks/ - to give you an idea of the kind of performance possible. Most of these are with node, but the core engine is the same - we just bound it to Python. For those of you using Python on the desktop (particularly if you're working with 3D), we've started a closed beta on a PyQt framework - you can see more here: http://fabricengine.com/2012/03/pyqt-framework-for-fabric-engine/ - email b...@fabricengine.com if you'd like to take part in the testing program. Thanks for your time, Paul It seems that sing;e dimension arrays are used in KL. How does this compare with Numpy? Colin W. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is readable
The fact that scientific journal articles start with a documentation string called an abstract does not indicate that scientific English fails as a human communication medium. Function docstrings say what the function does and how to use it without reading the code. They can be pulled out and displayed elsewhere. They also guide the reading of the code. Abstracts serve the same functions. A paper, with topic introduction, methods exposition, data/results description and discussion is a poor analog to a function. I would compare the abstract of a scientific paper to the overview section of a program's documentation. The great majority of the docstrings I see are basically signature rehashes with added type information and assertions, followed by a single sentence English gloss-over. If the code were sufficiently intuitive and expressive, that would be redundant. Of course, there will always be morbidly obese functions and coders that like to wax philosophical or give history lessons in comments. Both abstracts and doc strings are designed to be and are read independently of the stuff they summarize. Perhaps you do not use help(obj) as often as some other people do. I find help() to be mostly useless because of the clutter induced by double under methods. I use IPython, and I typically will either use tab name completion with the ? feature or %edit obj if I really need to dig around. I teach Python to groups from time to time as part of my job, and I usually only mention help() as something of an afterthought, since typically people react to the output like a deer in headlights. Some sort of semantic function and class search from the interpreter would probably win a lot of fans, but I don't know that it is possible without a standard annotation format and the addition of a namespace cache to pyc files. -- http://mail.python.org/mailman/listinfo/python-list
Re: urllib.urlretrieve never returns??? [SOLVED] - workaround
I'll be experimenting with pyCurl now. By replacing the GetThumbnail method with this brainless example, taken from the pyCurl demo: def GetThumbnail(self,imgurl): class Test: def __init__(self): self.contents = '' def body_callback(self, buf): self.contents = self.contents + buf self.Log(#1: +repr(imgurl)) try: t = Test() c = pycurl.Curl() c.setopt(c.URL, imgurl) c.setopt(c.WRITEFUNCTION, t.body_callback) self.Log(#2) c.perform() self.Log(#3) c.close() self.Log(#4) fpath = os.path.join(os.environ[TEMP],thumbnail.jpg) fout = open(fpath,wb+) self.Log(#5: +repr(fpath)) try: fout.write(t.contents) finally: fout.close() self.Log(#6) except: self.Log(traceback.format_exc()) return self.Log(#7) wx.CallAfter(self.imgProduct.SetPage,htmlbodyimg src=%s/body/html%fpath) self.Log(#8) Everything works perfectly, in all modes: console, no console, started directly and started in separate thread. So the problem with urllib must be. Maybe wxPython installs some except hooks, or who knows? If somebody feels up to it, I can start narrowing down the problem to the smallest possible application. But only if someone knows how to debug core code because I don't. Otherwise I'll just use pyCURL. Thank you for your help! Laszlo -- http://mail.python.org/mailman/listinfo/python-list
Released: stackprint -- analyze python stack dumps in server logs
Stackprint is a little tool for finding, formatting, and categorizing python stack dumps in server log files. We've found it useful for monitoring the health of our django applications. https://bitbucket.org/roysmith/python-tools. BSD license. -- http://mail.python.org/mailman/listinfo/python-list
RE: urllib.urlretrieve never returns???
Today I got a different error message printed on console (program started with python.exe) Unhandled exception in thread started by bound method FrameLocEdit.GetThumbnail of locedit.FrameLocEdit; proxy of Swig Object of type 'wxPanel *' at 0x4f85300 Unhandled exception in thread started by bound method FrameLocEdit.GetThumbnail of locedit.FrameLocEdit; proxy of Swig Object of type 'wxPanel *' at 0x4f85300 Unhandled exception in thread started by bound method FrameLocEdit.GetThumbnail of locedit.FrameLocEdit; proxy of Swig Object of type 'wxPanel *' at 0x4f85300 Unhandled exception in thread started by Traceback (most recent call last): Traceback (most recent call last): Traceback (most recent call last): bound method FrameLocEdit.GetThumbnail of locedit.FrameLocEdit; proxy of Swig Object of type 'wxPanel *' at 0x4f85300 File C:\Python\Projects\Warehouserclient_v3\locedit.py, line 917, in GetThumbnail File C:\Python\Projects\Warehouserclient_v3\locedit.py, line 917, in GetThumbnail File C:\Python\Projects\Warehouserclient_v3\locedit.py, line 917, in GetThumbnail sys.excepthook is missing Traceback (most recent call last): I have never seen a traceback like this before. I didn't install any excepthook myself. Program is using wxPython, socket, threads, threading, PIL. Here is something even more strange. If I click on the button three times, then absolutely nothing gets printed on stdout. However, if I close the program with file/exit (actually, calling wx.PySimpleApp.ExitMainLoop) then suddenly three stack traces are printed on stdout, all lines mixed up: Maybe in self.Log you should add a sys.stdout.flush and sys.stderr.flush(). I am not very familiar with stdin/out but maybe it will help. Unhandled exception in thread started by bound method FrameLocEdit.GetThumbnail of locedit.FrameLocEdit; proxy of Swig Object of type 'wxPanel *' at 0x4fb530 0 Unhandled exception in thread started by Unhandled exception in thread started by bound method FrameLocEdit.GetThumbnail of locedit.FrameLocEdit; proxy of Swig Object of type 'wxPanel *' at 0x4fb5300 Unhandled exception in thread started by Unhandled exception in thread started by bound method FrameLocEdit.GetThumbnail of locedit.FrameLocEdit; proxy of Swig Object of type 'wxPanel *' at 0x4fb5300 Traceback (most recent call last):bound method FrameLocEdit.GetThumbnail of locedit.FrameLocEdit; proxy of Swig Object of type 'wxPanel *' at 0x4fb5300 Traceback (most recent call last):bound method FrameLocEdit.GetThumbnail of locedit.FrameLocEdit; proxy of Swig Object of type 'wxPanel *' at 0x4fb5300 Traceback (most recent call last): File C:\Python\Projects\Warehouserclient_v3\locedit.py, line 917, in GetThumbnail Traceback (most recent call last): File C:\Python\Projects\Warehouserclient_v3\locedit.py, line 917, in GetThumbnail Traceback (most recent call last): File C:\Python\Projects\Warehouserclient_v3\locedit.py, line 917, in GetThumbnail File C:\Python\Projects\Warehouserclient_v3\locedit.py, line 917, in GetThumbnail File C:\Python\Projects\Warehouserclient_v3\locedit.py, line 917, in GetThumbnail self.Log(traceback.format_exc()) self.Log(traceback.format_exc()) self.Log(traceback.format_exc()) AttributeErrorself.Log(traceback.format_exc()) AttributeErrorself.Log(traceback.format_exc()) AttributeError: AttributeError: AttributeError: C:\Python\Projects\Warehouserclient_v3 And the last attributerror doesn't tell what attribute is missing. Probably I'll have to use a different library (pycurl, for example). But the error itself is getting more interesting. This makes me think self does not have a .Log() or the traceback import is being overridden by something else that does not have .format_exc(). Or possibly this is in a function that does not have a self (maybe a typo in the function def?). Also tried to use an invalid file (that should return with HTTP 404 not found) but the effect is exactly the same. Nothing is printed on stdout until I try to close the program (stop wxPython's mainloop). Then all previously threads throw an AttributeError and all of them print a stack trace (at the same time, lines mixed up). I'll be experimenting with pyCurl now. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: urllib.urlretrieve never returns??? [SOLVED] - workaround
Everything works perfectly, in all modes: console, no console, started directly and started in separate thread. So the problem with urllib must be. Maybe wxPython installs some except hooks, or who knows? If somebody feels up to it, I can start narrowing down the problem to the smallest possible application. But only if someone knows how to debug core code because I don't. Otherwise I'll just use pyCURL. Have you tried urllib2? Have you tried a small program without using wx? To be honest, I doubt the problem is wx or urllib as they are both fairly broadly used. Try to come up with an example that is as minimal as possible. imgurl = http://www.shopzeus.hu/thumbnail.php?width=200image=pyramid/PP0830.jpg; urllib.urlretrieve( imgurl ) ('c:\\[...]\\tmpkhixgt.php', httplib.HTTPMessage instance at 0x0F2D75A8) And I have Windows 7 64 with Python 2.6.6 (32 bit) and wx installed. Your program on ActiveState worked for me which tells me that it might be a network or machine specific problem. You are missing an import which I mentioned in another post. Fixing that should tell what the error you are getting is; you would not be getting the AttributeError without some other error first. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: urllib.urlretrieve never returns??? [SOLVED] - workaround
Everything works perfectly, in all modes: console, no console, started directly and started in separate thread. So the problem with urllib must be. Maybe wxPython installs some except hooks, or who knows? If somebody feels up to it, I can start narrowing down the problem to the smallest possible application. But only if someone knows how to debug core code because I don't. Otherwise I'll just use pyCURL. Have you tried urllib2? Have you tried a small program without using wx? To be honest, I doubt the problem is wx or urllib as they are both fairly broadly used. Try to come up with an example that is as minimal as possible. imgurl = http://www.shopzeus.hu/thumbnail.php?width=200image=pyramid/PP0830.jpg; urllib.urlretrieve( imgurl ) ('c:\\[...]\\tmpkhixgt.php', httplib.HTTPMessage instance at 0x0F2D75A8) And I have Windows 7 64 with Python 2.6.6 (32 bit) and wx installed. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: urllib.urlretrieve never returns???
Traceback (most recent call last): File C:\Python\Projects\Warehouserclient_v3\locedit.py, line 917, in GetThumbnail Traceback (most recent call last): File C:\Python\Projects\Warehouserclient_v3\locedit.py, line 917, in GetThumbnail File C:\Python\Projects\Warehouserclient_v3\locedit.py, line 917, in GetThumbnail File C:\Python\Projects\Warehouserclient_v3\locedit.py, line 917, in GetThumbnail self.Log(traceback.format_exc()) self.Log(traceback.format_exc()) self.Log(traceback.format_exc()) AttributeErrorself.Log(traceback.format_exc()) AttributeErrorself.Log(traceback.format_exc()) AttributeError: AttributeError: AttributeError: C:\Python\Projects\Warehouserclient_v3 And the last attributerror doesn't tell what attribute is missing. Probably I'll have to use a different library (pycurl, for example). But the error itself is getting more interesting. This makes me think self does not have a .Log() or the traceback import is being overridden by something else that does not have .format_exc(). Or possibly this is in a function that does not have a self (maybe a typo in the function def?). Here you can find the example program and the original post. http://code.activestate.com/lists/python-list/617894/ I just looked at your source file on ActiveState and noticed that you do not import traceback. That is why you are getting the AttributeError. Now you should be getting a much better error once you import it :) Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- -Original Message- From: python-list-bounces+ramit.prasad=jpmorgan@python.org [mailto:python-list-bounces+ramit.prasad=jpmorgan@python.org] On Behalf Of Prasad, Ramit Sent: Tuesday, March 20, 2012 3:52 PM To: python-list@python.org Subject: RE: urllib.urlretrieve never returns??? Today I got a different error message printed on console (program started with python.exe) Unhandled exception in thread started by bound method FrameLocEdit.GetThumbnail of locedit.FrameLocEdit; proxy of Swig Object of type 'wxPanel *' at 0x4f85300 Unhandled exception in thread started by bound method FrameLocEdit.GetThumbnail of locedit.FrameLocEdit; proxy of Swig Object of type 'wxPanel *' at 0x4f85300 Unhandled exception in thread started by bound method FrameLocEdit.GetThumbnail of locedit.FrameLocEdit; proxy of Swig Object of type 'wxPanel *' at 0x4f85300 Unhandled exception in thread started by Traceback (most recent call last): Traceback (most recent call last): Traceback (most recent call last): bound method FrameLocEdit.GetThumbnail of locedit.FrameLocEdit; proxy of Swig Object of type 'wxPanel *' at 0x4f85300 File C:\Python\Projects\Warehouserclient_v3\locedit.py, line 917, in GetThumbnail File C:\Python\Projects\Warehouserclient_v3\locedit.py, line 917, in GetThumbnail File C:\Python\Projects\Warehouserclient_v3\locedit.py, line 917, in GetThumbnail sys.excepthook is missing Traceback (most recent call last): I have never seen a traceback like this before. I didn't install any excepthook myself. Program is using wxPython, socket, threads, threading, PIL. Here is something even more strange. If I click on the button three times, then absolutely nothing gets printed on stdout. However, if I close the program with file/exit (actually, calling wx.PySimpleApp.ExitMainLoop) then suddenly three stack traces are printed on stdout, all lines mixed up: Maybe in self.Log you should add a sys.stdout.flushand sys.stderr.flush(). I am not very familiar with stdin/out but maybe it will help. Unhandled exception in thread started by bound method FrameLocEdit.GetThumbnail of locedit.FrameLocEdit; proxy of Swig Object of type 'wxPanel *' at 0x4fb530 0 Unhandled exception in thread started by Unhandled exception in thread started by bound method FrameLocEdit.GetThumbnail of locedit.FrameLocEdit; proxy of Swig Object of type 'wxPanel *' at 0x4fb5300 Unhandled exception in thread started by Unhandled exception in thread started by bound method FrameLocEdit.GetThumbnail of locedit.FrameLocEdit; proxy of Swig Object of type 'wxPanel *' at 0x4fb5300 Traceback (most recent call last):bound method FrameLocEdit.GetThumbnail of locedit.FrameLocEdit; proxy of Swig Object of type 'wxPanel *' at 0x4fb5300 Traceback (most recent call last):bound method FrameLocEdit.GetThumbnail of locedit.FrameLocEdit; proxy of Swig Object of type 'wxPanel *' at 0x4fb5300 Traceback (most recent call last): File C:\Python\Projects\Warehouserclient_v3\locedit.py, line 917, in GetThumbnail Also tried to use an invalid file (that should return with HTTP 404 not found) but the effect is exactly the same. Nothing is printed on stdout
Re: Fabric Engine v1.0 released under AGPL
Hi Colin, Fabric supports multi-dimensional arrays, and also provides support for dictionaries. You can read more here: http://documentation.fabric-engine.com/latest/FabricEngine-KLProgrammingGuide.html In terms of comparison to Numpy - I'm not familiar with that product, but some surface level similarities/differences: - we don't provide high-level functions for scientific computing. This is something we're looking at now. - both products provide methods for including existing libraries (http://documentation.fabric-engine.com/latest/FabricEngine- ExtensionsReference.html) - Fabric is a high-performance framework - http://documentation.fabric-engine.com/latest/FabricEngine-Overview.html - we haven't benchmarked against R, MatLab etc but we run at the same speed as multi-threaded compiled code (since that's essentially what we're doing). Hope that helps, Paul It seems that sing;e dimension arrays are used in KL. How does this compare with Numpy? Colin W. -- http://mail.python.org/mailman/listinfo/python-list
Re: List comprehension/genexp inconsistency.
On Tue, Mar 20, 2012 at 3:16 PM, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: On Tue, 20 Mar 2012 16:23:22 -0400, J. Cliff Dyer j...@sdf.lonestar.org declaimed the following in gmane.comp.python.general: When trying to create a class with a dual-loop generator expression in a class definition, there is a strange scoping issue where the inner variable is not found, (but the outer loop variable is found), while a list comprehension has no problem finding both variables. Read http://www.python.org/dev/peps/pep-0289/ -- in particular, look for the word leak No, this has nothing to do with the loop variable leaking. It appears to have to do with the fact that the variables and the generator expression are inside a class block. I think that it's related to the reason that this doesn't work: class Foo(object): x = 42 def foo(): print(x) foo() In this case, x is not a local variable of foo, nor is it a global. In order for foo to access x, it would have to be a closure -- but Python can't make it a closure in this case, because the variable it accesses is (or rather, will become) a class attribute, not a local variable of a function that can be stored in a cell. Instead, the compiler just makes it a global reference in the hope that such a global will actually be defined when the code is run. For that reason, what surprises me about Cliff's example is that a generator expression works at all in that context. It seems to work as long as it contains only one loop, but not if it contains two. To find out why, I tried disassembling one: class Foo(object): ... x = 42 ... y = 12 ... g = (a+b for a in range(x) for b in range(y)) ... dis.dis(Foo.g.gi_code) 4 0 LOAD_FAST0 (.0) 3 FOR_ITER34 (to 40) 6 STORE_FAST 1 (a) 9 LOAD_GLOBAL 0 (range) 12 LOAD_GLOBAL 1 (y) 15 CALL_FUNCTION1 18 GET_ITER 19 FOR_ITER15 (to 37) 22 STORE_FAST 2 (b) 25 LOAD_FAST1 (a) 28 LOAD_FAST2 (b) 31 BINARY_ADD 32 YIELD_VALUE 33 POP_TOP 34 JUMP_ABSOLUTE 19 37 JUMP_ABSOLUTE3 40 LOAD_CONST 0 (None) 43 RETURN_VALUE So that explains it. Notice that x is never actually accessed in that disassembly; only y is. It turns out that the first iterator [range(x)] is actually created before the generator ever starts executing, and is stored as an anonymous local variable on the generator's stack frame -- so it's created in the class scope, not in the generator scope. The second iterator, however, is recreated on every iteration of the first iterator, so it can't be pre-built in that manner. It does get created in the generator scope, and when that happens it blows up because it can't find the variable, just like the function example above. Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is readable
On 3/19/2012 16:27, Steven D'Aprano wrote: I believe that you are misunderstanding the descriptivist position. There are many sentences which are never said, or perhaps only said once. Most non-trivial spoken or written sentences are unique. That doesn't make them wrong or erroneous because nobody says them. Nobody says hesitant teapots sleep artistically. Let's not mix syntax with semantics. If I'm ok: I'll go. represents all the possible sentences where the if-clause and the then-clause are separated by a colon. I believe that none of those are grammatically correct. Kiuhnm -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is readable
On 3/18/2012 1:57, Steven D'Aprano wrote: On 3/16/2012 21:04, Prasad, Ramit wrote: People spell your name Stephen, sometimes too. Thinking of changing it? Gore Vidal's quote has panache, a valid compensation for breaking the usual rule. How many other uses on that page are similar? He provided common examples and reference links. Seems like a pretty reasonable way of trying to prove a point. If you don't like reference links, what would convince you that the point was correct? I have not seen any counter examples or counter references on your behalf... He's referring to this rule: A colon should not precede a list unless it follows a complete sentence; however, the colon is a style choice that some publications allow. http://www.grammarbook.com/punctuation/colons.asp That is an invented prescriptivist rule and not based on English grammar as it actually is used by native English speakers. It is *bullshit*. Even the author of that page breaks it. Immediately following the above prohibition, she follows it with the sentence fragment: Examples: and then a list -- exactly what she says you may not do. I never said that rule is acceptable. I agree with you on that. People *do* precede lists by a colon following a sentence fragment. This is unremarkable English grammar, with only a tiny number of arse-plugged prescriptivists finding anything to complain about it, and even they break their own bullshit made-up so-called rule. The vast majority of English speakers write things like: TO DO: - mow the lawn - wash the car - take kids to the zoo - write book on grammar and there is nothing wrong with doing so. That's perfectly acceptable. Robert Kern put it very well in his post: don't use a colon to separate a transitive verb from its objects. You can't say TO DO - mow the lawn - ... because TO DO mow the lawn doesn't flow. But why should we break a sentence when there's no need to do so? Why should you write The matrix: is equal to Why the colon? Why break the flow of a sentence without reason? I would generalize Robert Kern's rule a little: don't put a colon into a sentence which is fine already. Example: You should - mow the lawn - do the dishes - walk the dog That's perfectly fine. Commas are conveniently omitted. As a side note, titles of movies, newspapers etc... don't follow common rules. Articles may be omitted, verbs may be missing, etc... They're just titles. Kiuhnm -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is readable
On Tue, 20 Mar 2012 16:34:21 -0400, Nathan Rice wrote: I find help() to be mostly useless because of the clutter induced by double under methods. I feel your pain, but perhaps I've just learned how to skim the output without being bogged down in reading every line, or perhaps because I mostly call it on methods rather than on the class itself, I find help() is absolutely invaluable and would be lost without it. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is readable
On Tue, 20 Mar 2012 15:28:25 -0400, Nathan Rice wrote: This is one of my gripes with the dogmatic application of the break it into multiple statements mantra of Python. I must admit I don't recognise that one, unless you're talking about not everything needs to be a one liner. ... Perhaps you could give some examples (actual or contrived) of stuff where breaking it into multiple statements is a bad thing? One example is performing a series of transformations on a collection of data, with the intent of finding an element of that collection that satisfies a particular criterion. If you separate out the individual transformations, you need to understand generators or you will waste space and perform many unnecessary calculations. If you only ever do a single transformation with a clear conceptual meaning, you could create a master transformation function, but what if you have a large number of potential permutations of that function? I'm sorry, that is far too abstract for me. Do you have a *concrete* example, even an trivial one? What if you are composing three or four functions, each of which is conditional on the data? If you extract things from a statement and assign them somewhat arbitrary names, you've just traded horizontal bloat for vertical bloat (with a net increase in volume), while forcing a reader to scan back and forth to different statements to understand what is happening. First off, vertical bloat is easier to cope with than horizontal bloat, at least for people used to reading left-to-right rather than vertically. There are few anti-patterns worse that horizontal scrolling, especially for text. Secondly, the human brain can only deal with a limited number of tokens at any one time. It's easier to remember large numbers when they are broken up into chunks: 824-791-259-401 versus 824791259401 (three tokens, versus twelve) Likewise for reading code. Chunking code into multiple lines instead of one long expression, and temporary variables, make things easier to understand, not harder. http://en.wikipedia.org/wiki/The_Magical_Number_Seven,_Plus_or_Minus_Two And thirdly, you're not forcing the reader to scan back and forth -- or at least if you are, then you've chosen your functions badly. Functions should have descriptive names and should perform a meaningful task, not just an arbitrary collection of code. When you read: x = range(3, len(sequence), 5) you're not forced to scan back and forth between that line and the code for range and len to understand it, because range and len are good abstractions that make sensible functions. There is a lot of badly written code in existence. Don't blame poor execution of design principles on the design principle itself. [...] Also, because of Sphinx, it is very common in the Python community weave documents and code together in a way that is convenient for authors but irritating for readers. I don't know about very common. I suspect, given the general paucity of documentation in the average software package, it is more like very rare, but memorable when it does happen. I personally would prefer not to have to scroll past 100 lines of a tutorial with examples, tests and what not in order to go from one function to another. Agreed. Docstrings should use a minimal number of examples and tests. Tutorials and extensive tests should be extracted into external documents. It would be really awesome if everyone used links to that material in docstrings, and the default sphinx theme created an inline collapsible iframe that included that material for the HTML version. Don't get me wrong, I adore Sphinx, the problem here is people who are lazy or don't know the right way to structure docs. +1000 -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is readable
On Mar 20, 5:22 pm, Steven D'Aprano steve +comp.lang.pyt...@pearwood.info wrote: On Tue, 20 Mar 2012 15:28:25 -0400, Nathan Rice wrote: What if you are composing three or four functions, each of which is conditional on the data? If you extract things from a statement and assign them somewhat arbitrary names, you've just traded horizontal bloat for vertical bloat (with a net increase in volume), while forcing a reader to scan back and forth to different statements to understand what is happening. First off, vertical bloat is easier to cope with than horizontal bloat, at least for people used to reading left-to-right rather than vertically. There are few anti-patterns worse that horizontal scrolling, especially for text. I agree with Steven that horizontal bloat hurts readability more than vertical bloat. Of course, it's a subjective thing, and I get the fact that the remedy to horizontal bloat often means more volume of code overalls (i.e. introducing locals). My main problem with horizontal bloat is that you often have to read inside-outside or right to left: verb3(verb2(verb1(noun))) verb2(verb1(noun, adverb1), adverb2) The vertical versions tend to be more verbose, but entirely sequential: noun1 = verb1(noun) noun2 = verb2(noun1) verb3(noun2) and noun1 = verb1(noun, adverb1) verb2(noun1, adverb2) There is a bit of an inflection point when the number of lines in the local code exceeds the vertical real estate of your monitor. I feel like vertical real estate is still mostly constrained by the way we build our monitors and our editors, and it's not so much a human brain limitation. With horizontally stretched code, I always feel like my brain is the bottleneck. The one place where I don't mind the horizontal approach is when code is truly laid out in the order of execution: noun.verb1(adverb1).verb2(adverb2).verb3(adverb3).verb4(adverb4) Even then, I'd prefer it to read vertically. Also, while the above idiom puts the verbs in the right order, it is still backward to me to say noun.verb. You don't noun a verb. You verb a noun. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is readable
Steve Howell showel...@yahoo.com writes: Also, while the above idiom puts the verbs in the right order, it is still backward to me to say noun.verb. You don't noun a verb. You verb a noun. When calling a method, the program object is the grammatical subject. You don't verb the noun, and you don't noun a verb. The noun verbs. -- \“Last year I went fishing with Salvador Dali. He was using a | `\ dotted line. He caught every other fish.” —Steven Wright | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is readable
On Mar 20, 7:28 pm, Ben Finney ben+pyt...@benfinney.id.au wrote: Steve Howell showel...@yahoo.com writes: Also, while the above idiom puts the verbs in the right order, it is still backward to me to say noun.verb. You don't noun a verb. You verb a noun. When calling a method, the program object is the grammatical subject. You don't verb the noun, and you don't noun a verb. The noun verbs. I think it's a matter of perspective, so there's no right answer, but I always think of the program object as also being the grammatical object, with the implied subject/actor being Python itself. For example, consider this code: stack.push(item) It's not the stack that's pushing. It's the stack being pushed on to. So stack is the direct object, and item is the indirect object. When you say stack.push(item), I think of it as being that Python pushes an item on to the stack. I suppose you would argue that the stack pushes item on to itself? And even then, isn't it still the grammatical object in the itself case? Also, don't they call those thingies object for a reason? ;) -- http://mail.python.org/mailman/listinfo/python-list
Re: List comprehension/genexp inconsistency.
On Mar 20, 3:50 pm, Ian Kelly ian.g.ke...@gmail.com wrote: On Tue, Mar 20, 2012 at 3:16 PM, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: On Tue, 20 Mar 2012 16:23:22 -0400, J. Cliff Dyer j...@sdf.lonestar.org declaimed the following in gmane.comp.python.general: When trying to create a class with a dual-loop generator expression in a class definition, there is a strange scoping issue where the inner variable is not found, (but the outer loop variable is found), while a list comprehension has no problem finding both variables. Readhttp://www.python.org/dev/peps/pep-0289/-- in particular, look for the word leak No, this has nothing to do with the loop variable leaking. It appears to have to do with the fact that the variables and the generator expression are inside a class block. Interesting. Just for completeness, the code does seem to work fine when you take it out of the class: Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin Type help, copyright, credits or license for more information. foo, bar = 4, 4 g = (((x, y), x+y) for x in range(foo) for y in range(bar)) dict(g) {(0, 1): 1, (1, 2): 3, (3, 2): 5, (0, 0): 0, (3, 3): 6, (3, 0): 3, (3, 1): 4, (2, 1): 3, (0, 2): 2, (2, 0): 2, (1, 3): 4, (2, 3): 5, (2, 2): 4, (1, 0): 1, (0, 3): 3, (1, 1): 2} import dis dis.dis(g.gi_code) 1 0 SETUP_LOOP 57 (to 60) 3 LOAD_FAST0 (.0) 6 FOR_ITER50 (to 59) 9 STORE_FAST 1 (x) 12 SETUP_LOOP 41 (to 56) 15 LOAD_GLOBAL 0 (range) 18 LOAD_GLOBAL 1 (bar) 21 CALL_FUNCTION1 24 GET_ITER 25 FOR_ITER27 (to 55) 28 STORE_FAST 2 (y) 31 LOAD_FAST1 (x) 34 LOAD_FAST2 (y) 37 BUILD_TUPLE 2 40 LOAD_FAST1 (x) 43 LOAD_FAST2 (y) 46 BINARY_ADD 47 BUILD_TUPLE 2 50 YIELD_VALUE 51 POP_TOP 52 JUMP_ABSOLUTE 25 55 POP_BLOCK 56 JUMP_ABSOLUTE6 59 POP_BLOCK 60 LOAD_CONST 0 (None) 63 RETURN_VALUE -- http://mail.python.org/mailman/listinfo/python-list
setup.py for an extension
Hi all. I have a python extension (bindings for a C lib - no swig) and I would like to write a setup.py to build a source distribution pack. The extension consists of 3 files: foo.h foo.c foo.py that are placed in a eclipse directory /home/user/ECLIPSE/workspace/ext/src foo.h+foo.c are to be compiled into _foo.so shared lib. _foo.so is itself a module only called from foo.py. The dir I wrote the setup.py is any arbitrary dir. I don't want to put packaging stuff into the eclipse source. I read the docs but have no idea on how to do this. Some tentatives I did completely failed. Any help? Thanks in advance. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is readable
On Wed, Mar 21, 2012 at 1:44 PM, Steve Howell showel...@yahoo.com wrote: I think it's a matter of perspective, so there's no right answer, but I always think of the program object as also being the grammatical object, with the implied subject/actor being Python itself. For example, consider this code: stack.push(item) It's not the stack that's pushing. It's the stack being pushed on to. In code, though, the push() method is defined in and on the stack object (or more likely, on the class that instantiated it, but near enough). So the stack is being asked to push something onto itself. It is still viably the subject. Yes, the implied subject could be the language interpreter; but it could just as easily be the CPU, or those friendly nanobots, or that guy moving the rocks in XKCD 505. But in the abstraction of the line of code, you don't care how CPython goes about loading globals, calling bound methods, and incrementing object reference counts - you just care that the stack is pushing this item onto itself. Some method names are definitely written as though their primary argument is the object, not the subject. Either option works. Do you think about code as the subject+verb and a data structure as the object, or the object as the subject and the method as the verb? Fundamentally no difference. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is readable
One example is performing a series of transformations on a collection of data, with the intent of finding an element of that collection that satisfies a particular criterion. If you separate out the individual transformations, you need to understand generators or you will waste space and perform many unnecessary calculations. If you only ever do a single transformation with a clear conceptual meaning, you could create a master transformation function, but what if you have a large number of potential permutations of that function? I'm sorry, that is far too abstract for me. Do you have a *concrete* example, even an trivial one? How about a hypothetical log analyzer that parses a log file that is aggregated from multiple event sources with disparate record structures. You will need to perform a series of transformations on the data to convert record elements from text to specific formats, and your function for identifying alarm records is also dependent on record structure (and possibly system state, imagining an intrusion detection system). Of course you could go through a lot of trouble to dispatch and detect alarms over 6-7 statements, however given the description for each log record you receive, convert text elements to native data types based on the value of the first three fields of the record, then trigger an alert if that record meets defined requirements and assuming you have maps from record values to conversion functions for record elements, and a map from record types to alert criteria functions for record types already constructed, it seems like a one liner to me. What if you are composing three or four functions, each of which is conditional on the data? If you extract things from a statement and assign them somewhat arbitrary names, you've just traded horizontal bloat for vertical bloat (with a net increase in volume), while forcing a reader to scan back and forth to different statements to understand what is happening. First off, vertical bloat is easier to cope with than horizontal bloat, at least for people used to reading left-to-right rather than vertically. There are few anti-patterns worse that horizontal scrolling, especially for text. I agree that if a line goes into horizontal scroll buffer, you have a problem. Of course, I often rail on parenthesized function-taking-arguments expression structure for the fact that it forces you to read inside out and right to left, and I'd prefer not to conflate the two issues here. My assertion is that given an expression structure that reads naturally regardless, horizontal bloat is better than larger vertical bloat, in particular when the vertical bloat does not fall along clean semantic boundaries. Secondly, the human brain can only deal with a limited number of tokens at any one time. It's easier to remember large numbers when they are broken up into chunks: 824-791-259-401 versus 824791259401 (three tokens, versus twelve) Likewise for reading code. Chunking code into multiple lines instead of one long expression, and temporary variables, make things easier to understand, not harder. This is true, when the tokens are an abstraction. I read some of the research on chunking, basically it came down to people being able to remember multiple numbers efficiently in an auditory fashion using phonemes. Words versus random letter combinations have the same effect, only with visual images (which is why I think Paul Graham is full of shit with regards to his shorter is better than descriptive mantra in old essays). This doesn't really apply if storing the elements in batches doesn't provide a more efficient representation. Of course, if you can get your statements to read like sensible English sentences, there is definitely a reduction in cognitive load. And thirdly, you're not forcing the reader to scan back and forth -- or at least if you are, then you've chosen your functions badly. Functions should have descriptive names and should perform a meaningful task, not just an arbitrary collection of code. This is why I quoted Einstein. I support breaking compound logical statements down to simple statements, then combining those simple statements. The problem arises when your compound statement still looks like A B C D E F G H I J K L M N, and portions of that compound statement don't have a lot of meaning outside the larger statement. You could say X = A B C D E, Y = F G H I J, Z = K L M N, then say X Y Z, but now you've created bloat and forced the reader to backtrack. When you read: x = range(3, len(sequence), 5) you're not forced to scan back and forth between that line and the code for range and len to understand it, because range and len are good abstractions that make sensible functions. There is a lot of badly written code in existence. Don't blame poor execution of design principles on the design principle itself. I like to be fair and even handed, and I recognize that tool
Re: Python is readable
On Mar 20, 9:16 pm, Chris Angelico ros...@gmail.com wrote: On Wed, Mar 21, 2012 at 1:44 PM, Steve Howell showel...@yahoo.com wrote: I think it's a matter of perspective, so there's no right answer, but I always think of the program object as also being the grammatical object, with the implied subject/actor being Python itself. For example, consider this code: stack.push(item) It's not the stack that's pushing. It's the stack being pushed on to. In code, though, the push() method is defined in and on the stack object (or more likely, on the class that instantiated it, but near enough). [...] The interpretation that the subject is the Stack class itself leads to this coding style: Stack.push(stack, item) The above code takes duck-typing to an extreme--you don't have to assume that stack was instantiated from Stack in order to apply Stack.push to stack (where Stack acts a the subject and stack acts as a grammatical direct object). Of course, 99% of the time, we want some sugar that makes Stack be the implicit subject (given that stack was instantiated from Stack): stack.push(item) # push comes from Stack via stack Yes, the implied subject could be the language interpreter; but it could just as easily be the CPU, or those friendly nanobots, or that guy moving the rocks in XKCD 505. But in the abstraction of the line of code, you don't care how CPython goes about loading globals, calling bound methods, and incrementing object reference counts - you just care that the stack is pushing this item onto itself. Sure, that's all good, but, colloquially, I bet you've probably said at one time in your life, And, here, we are pushing the item on to the stack. The subject is vague (we), but there is no assumption of friendly nanobots (or vigorous hamsters, or CPUs, or any specific mechanisms), just the idea that the stack is the object, not the subject. Some method names are definitely written as though their primary argument is the object, not the subject. Either option works. Do you think about code as the subject+verb and a data structure as the object, or the object as the subject and the method as the verb? Fundamentally no difference. At a certain fundamental level, sure, of course it's all just data structure and code, so we shouldn't be quibbling about syntax or grammar, and we certainly shouldn't be throwing around strained analogies to natural languages. But in this context, we are musing about grammar, so I would propose this question: What's more important, the object or the method? IMHO the method is usually more interesting than the object itself. Of course, the stack itself is important, but on any given line of code, the action is more interesting, so I'd want to lead with push or pop. Verb-first gets a bad rap, because people tend to associate verb-first syntax with early, primitive imperative/functional languages that had no OO syntax. Assembly tends to be very imperative: MOV AX, BX So saying push(stack, item) or push(item, stack) seems very unsophisticated, almost assembly-like in syntax, albeit at a higher level conceptually than assembly. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is readable
On Wed, Mar 21, 2012 at 3:58 PM, Steve Howell showel...@yahoo.com wrote: So saying push(stack, item) or push(item, stack) seems very unsophisticated, almost assembly-like in syntax, albeit at a higher level conceptually than assembly. Perhaps it does, but push(stack, item) and stack.push(item) are so close to identical as makes no odds (in a number of languages, the latter is just syntactic sugar for something like the former) - yet they read quite differently, one with verb first, one with noun first. Code doesn't follow the same grammar as English prose, and forcing it to usually makes it sound odd. Reader.can_comprehend(code) is True. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
[issue14370] enumerate() lead to system crashes
aaron315 guowei1321...@163.com added the comment: Have not been able to respond in a lower performance on the computer running, I restart the computer; On another computer, indeed MemoryError。 -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14370 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Python 2.7 crashed during compilation on HP PA-RISC
Hello, I am compiling Python2.7 on a HP11i PA-RISC machine and received a segmentation fault. Platform Information uname -a = HP-UX hpdev2 B.11.11 U 9000/800 2280874925 unlimited-user license Steps 1) uncompress Python tgz file 2) run configure CC=aCC CXX=aCC 3) make Result: Segmentation fault at library generation time. $ ranlib libpython2.7.a aCC -Ae -Wl,-E -Wl,+s -o python \ Modules/python.o \ libpython2.7.a -lnsl -lrt -ldld -lpthread -lm sh[3]: 15168 Bus error(coredump) *** Error exit code 138 Analysis: core file generated by Python executable $ file python python: PA-RISC2.0 shared executable dynamically linked -not stripped $ file libpython2.7.a libpython2.7.a: archive file -PA-RISC2.0 relocatable library $ strings core|more HP-UX hpdev2 B.11.11 9000/800 2280874925 python Modu xxsu LDSH xsubtype.o -o BCAc runpy (si) path __main__ warn warnall 2.7.2 readline ... There was an issue9178 (http://mail.python.org/pipermail/python-bugs-list/2010-July/104448.html) with a similar topic but the compiler generated segmentation fault instead. In this case the core file seems to be from Python itself. I have attached Makefile for your reference. Thank you for your help! Don # Generated automatically from Makefile.pre by makesetup. # Top-level Makefile for Python # # As distributed, this file is called Makefile.pre.in; it is processed # into the real Makefile by running the script ./configure, which # replaces things like @spam@ with values appropriate for your system. # This means that if you edit Makefile, your changes get lost the next # time you run the configure script. Ideally, you can do: # # ./configure # make # make test # make install # # If you have a previous version of Python installed that you don't # want to overwrite, you can use make altinstall instead of make # install. Refer to the Installing section in the README file for # additional details. # # See also the section Build instructions in the README file. # === Variables set by makesetup === MODOBJS= Modules/threadmodule.o Modules/signalmodule.o Modules/posixmodule.o Modules/errnomodule.o Modules/pwdmodule.o Modules/_sre.o Modules/_codecsmodule.o Modules/_weakref.o Modules/zipimport.o Modules/symtablemodule.o Modules/xxsubtype.o MODLIBS=$(LOCALMODLIBS) $(BASEMODLIBS) # === Variables set by configure VERSION=2.7 srcdir= . CC= aCC -Ae CXX=aCC MAINCC= $(CC) LINKCC= $(PURIFY) $(MAINCC) AR= ar RANLIB= ranlib SVNVERSION= echo Unversioned directory HGVERSION= HGTAG= HGBRANCH= GNULD= no # Shell used by make (some versions default to the login shell, which is bad) SHELL= /bin/sh # Use this to make a link between python$(VERSION) and python in $(BINDIR) LN= ln # Portable install script (configure doesn't always guess right) INSTALL=./install-sh -c INSTALL_PROGRAM=${INSTALL} INSTALL_SCRIPT= ${INSTALL} INSTALL_DATA= ${INSTALL} -m 644 # Shared libraries must be installed with executable mode on some systems; # rather than figuring out exactly which, we always give them executable mode. # Also, making them read-only seems to be a good idea... INSTALL_SHARED= ${INSTALL} -m 555 MAKESETUP= $(srcdir)/Modules/makesetup # Compiler options OPT=-DNDEBUG -O BASECFLAGS= -Olimit 1500 CFLAGS= $(BASECFLAGS) -g $(OPT) $(EXTRA_CFLAGS) # Both CPPFLAGS and LDFLAGS need to contain the shell's value for setup.py to # be able to build extension modules using the directories specified in the # environment variables CPPFLAGS= -I. -IInclude -I$(srcdir)/Include LDFLAGS= LDLAST= SGI_ABI= CCSHARED= +z LINKFORSHARED= -Wl,-E -Wl,+s ARFLAGS=rc # Extra C flags added for building the interpreter object files. CFLAGSFORSHARED= # C flags used for building the interpreter object files PY_CFLAGS= $(CFLAGS) $(CPPFLAGS) $(CFLAGSFORSHARED) -DPy_BUILD_CORE # Machine-dependent subdirectories MACHDEP=hp-ux11 # Install prefix for architecture-independent files prefix= /usr/local # Install prefix for architecture-dependent files exec_prefix=${prefix} # Install prefix for data files datarootdir=${prefix}/share # Expanded directories BINDIR= ${exec_prefix}/bin LIBDIR= ${exec_prefix}/lib MANDIR= ${datarootdir}/man INCLUDEDIR= ${prefix}/include CONFINCLUDEDIR= $(exec_prefix)/include SCRIPTDIR= $(prefix)/lib # Detailed destination directories BINLIBDEST=
[issue14370] enumerate() lead to system crashes
Stefan Krah stefan-use...@bytereef.org added the comment: I can reproduce this with Python 3.2 on Linux-2.4.32/i686 with 512M of RAM. The machine does not crash, it freezes completely in the same manner as with a fork bomb. A hard reboot is required. -- nosy: +skrah type: performance - resource usage ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14370 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14370] list.extend() called on an iterator of the list itself leads to an infinite loop
Petri Lehtinen pe...@digip.org added the comment: This has the same effect: a = list(range(5)) a.extend(iter(a)) So the problem is not in enumerate but in list.extend() -- nosy: +petri.lehtinen title: enumerate() lead to system crashes - list.extend() called on an iterator of the list itself leads to an infinite loop ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14370 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14370] list.extend() called on an iterator of the list itself leads to an infinite loop
Charles-François Natali neolo...@free.fr added the comment: I think you're simply running OOM, and Linux is thrashing to death. If you wait long enough, the process should get nuked by the OOM killer (well, in theory). What happens if you disable swap altogether ('swapoff -a')? You can also change to strict overcommitting ('echo 2 /proc/sys/vm/overcommit_memory'). Anyway, I guess you would get the same effect by simply running list(range(huge number))... -- nosy: +neologix ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14370 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3367] Uninitialized value read in parsetok.c
Kristján Valur Jónsson krist...@ccpgames.com added the comment: bump, what is the status of this? Was it fixed? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue3367 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14198] Backport parts of the new memoryview documentation
Kristján Valur Jónsson krist...@ccpgames.com added the comment: Stefan, I just want to point out this issue, if you are touching 2.7: http://bugs.python.org/issue10538 Do you think it merits being fixed? -- nosy: +krisvale ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14198 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10211] BufferObject doesn't support new buffer interface
Kristján Valur Jónsson krist...@ccpgames.com added the comment: Bumping this. Do we want this fixed as a bug in 2.7 or left alone? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10211 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10212] struct.unpack and cStringIO.StringIO don't support new buffer
Kristján Valur Jónsson krist...@ccpgames.com added the comment: The patch is still there. Any new consensus? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10212 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9787] Release the TLS lock during allocations
Kristján Valur Jónsson krist...@ccpgames.com added the comment: I'll rework this for python 3.x and see where that gets us. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9787 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14198] Backport parts of the new memoryview documentation
Stefan Krah stefan-use...@bytereef.org added the comment: Kristj??n Valur J??nsson rep...@bugs.python.org wrote: Stefan, I just want to point out this issue, if you are touching 2.7: http://bugs.python.org/issue10538 Do you think it merits being fixed? I think so. A patch would be appreciated, since the issue touches the old buffer interface (which I haven't looked at in detail at all). -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14198 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10538] PyArg_ParseTuple(s*) does not always incref object
Changes by Stefan Krah stefan-use...@bytereef.org: -- nosy: +skrah ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10538 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3367] Uninitialized value read in parsetok.c
Stefan Krah stefan-use...@bytereef.org added the comment: It isn't fixed. Also, there's now an additional invalid read in sys_update_path(): $ valgrind --db-attach=yes --suppressions=Misc/valgrind-python.supp ./python ==20258== Memcheck, a memory error detector ==20258== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al. ==20258== Using Valgrind-3.6.1 and LibVEX; rerun with -h for copyright info ==20258== Command: ./python ==20258== Python 3.3.0a1+ (default:0554183066b5, Mar 20 2012, 10:47:41) [GCC 4.4.3] on linux Type help, copyright, credits or license for more information. ==20258== Invalid read of size 8 ==20258==at 0x4C9F6F: sys_update_path (sysmodule.c:1742) ==20258==by 0x4CA268: PySys_SetArgvEx (sysmodule.c:1830) ==20258==by 0x4CA28F: PySys_SetArgv (sysmodule.c:1836) ==20258==by 0x4D9930: Py_Main (main.c:647) ==20258==by 0x41AE1F: main (python.c:63) ==20258== Address 0x5a58048 is 0 bytes after a block of size 8 alloc'd ==20258==at 0x4C27878: malloc (vg_replace_malloc.c:236) ==20258==by 0x41DF90: PyMem_Malloc (object.c:1841) ==20258==by 0x41ACC4: main (python.c:25) ==20258== ==20258== ==20258== Attach to debugger ? --- [Return/N/n/Y/y/C/c] n ==20258== Conditional jump or move depends on uninitialised value(s) ==20258==at 0x52B030: parsetok (parsetok.c:207) ==20258==by 0x52AD51: PyParser_ParseFileFlagsEx (parsetok.c:108) ==20258==by 0x4BFCDA: PyParser_ASTFromFile (pythonrun.c:1973) ==20258==by 0x4BDB5A: PyRun_InteractiveOneFlags (pythonrun.c:1196) ==20258==by 0x4BD83D: PyRun_InteractiveLoopFlags (pythonrun.c:1106) ==20258==by 0x4BD6E2: PyRun_AnyFileExFlags (pythonrun.c:1075) ==20258==by 0x4D9118: run_file (main.c:306) ==20258==by 0x4D9C0B: Py_Main (main.c:720) ==20258==by 0x41AE1F: main (python.c:63) ==20258== -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue3367 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14262] Allow using decimals as arguments to `timedelta`
Ram Rachum r...@rachum.com added the comment: I'm not completly conviced by the need of supporting Decimal in timedelta constructor. Why do you use Decimal if the result should be a timedelta? Why not using timedelta directly? What do you mean, Why not using timedelta directly? How could I use timedelta directly in the timedelta constructor? I'm creating a timedelta, I don't have one ready. I'm getting an `n_hours` variable for some component of my system. And this value happens to come as a `Decimal`. I want to create a `timedelta` out of it. So I'd want to be able to do `timedelta(hours=n_hours)` rather than `timedelta(hours=float(n_hours))`. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14262 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14302] Move python.exe to bin/
Changes by Giampaolo Rodola' g.rod...@gmail.com: -- nosy: +giampaolo.rodola ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14302 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14371] Add support for bzip2 compression to the zipfile module
New submission from Serhiy Storchaka storch...@gmail.com: ZIP File Format Specification (http://www.pkware.com/documents/casestudies/APPNOTE.TXT) supports bzip2 compression since at least 2003. Since bzip2 contained in Python standart library, it would be nice to add support for these method in zipfile. This will allow to process more foreign zip files and create more compact distributives. The proposed patch adds new method ZIP_BZIP2, which is automatically detecting when unpacking and that can be used for packing. -- components: Library (Lib) files: bzip2_in_zip.patch keywords: patch messages: 156394 nosy: storchaka priority: normal severity: normal status: open title: Add support for bzip2 compression to the zipfile module type: enhancement versions: Python 3.3 Added file: http://bugs.python.org/file24956/bzip2_in_zip.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14371 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14366] Supporting bzip2 and lzma compression in zip files
Serhiy Storchaka storch...@gmail.com added the comment: Issue #14371: Add support for bzip2 compression to the zipfile module. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14366 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14262] Allow using decimals as arguments to `timedelta`
STINNER Victor victor.stin...@gmail.com added the comment: I'm getting an `n_hours` variable for some component of my system. And this value happens to come as a `Decimal`. Can't you modify your program to use timedelta instead of Decimal for n_hours? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14262 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14228] It is impossible to catch sigint on startup in python code
Charles-François Natali neolo...@free.fr added the comment: for everybody who is not *programming* python (imagine there is a *real* user) the tracebacks are useless. Even worse, because the error messages are *changing*, because of different library parts not catching the exception. Well, I also use it sometimes ;-) The problem here is that the user is confronted with unwanted output, produced by the interpreter, which is not possible to be caught by a programmer to prevent this situation happening. You can start the interpreter with '-S' to avoid importing the site module, then: import signal signal.signal(signal.SIGINT, signal.SIG_DFL) import site site.main() [...] or try: import site site.main() import signal signal.signal(signal.SIGINT, signal.SIG_DFL) except KeyboardInterrupt: whatever [...] Or we could change Py_InitializeEx() to setup the signal handlers after having imported the site module: --- cpython-93769b8ff40b/Python/pythonrun.c 2012-01-19 10:29:48.0 + +++ cpython/Python/pythonrun.c 2012-03-20 11:27:37.0 + @@ -313,9 +313,6 @@ if (initfsencoding(interp) 0) Py_FatalError(Py_Initialize: unable to load the file system codec); -if (install_sigs) -initsigs(); /* Signal handling stuff, including initintr() */ - initmain(); /* Module __main__ */ if (initstdio() 0) Py_FatalError( @@ -333,6 +330,9 @@ if (!Py_NoSiteFlag) initsite(); /* Module site */ + +if (install_sigs) +initsigs(); /* Signal handling stuff, including initintr() */ Note, however, that there will always be a race window, if the signal is delivered after the signal handlers have been setup and the first line of the user code is executed. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14228 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14370] list.extend() called on an iterator of the list itself leads to an infinite loop
Changes by Giampaolo Rodola' g.rod...@gmail.com: -- nosy: +giampaolo.rodola ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14370 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14262] Allow using decimals as arguments to `timedelta`
Ram Rachum r...@rachum.com added the comment: In some cases we indeed use a timedelta directly, but sometimes we get a number of hours, and in those cases it's more convenient for us to work with number of hours directly. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14262 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14228] It is impossible to catch sigint on startup in python code
Charles-François Natali neolo...@free.fr added the comment: Or we could change Py_InitializeEx() to setup the signal handlers after having imported the site module: Note that I don't really like this solution, because it's better to setup handlers for fatal signals (SIGPIPE, SIGXF...) before executing arbitrary Python code (site). -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14228 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14228] It is impossible to catch sigint on startup in python code
Antoine Pitrou pit...@free.fr added the comment: Or we could change Py_InitializeEx() to setup the signal handlers after having imported the site module: Note that I don't really like this solution, because it's better to setup handlers for fatal signals (SIGPIPE, SIGXF...) before executing arbitrary Python code (site). Agreed. I think we'd better disable SIGINT initialization when a certain environment variable is set. (AFAICT, the issue is only about SIGINT since it's the only one where the default behaviour is overriden) -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14228 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14311] ConfigParser does not parse utf-8 files with BOM bytes
Changes by Łukasz Langa luk...@langa.pl: -- resolution: - duplicate stage: needs patch - committed/rejected status: open - closed superseder: - Python3: guess text file charset using the BOM versions: -Python 2.7, Python 3.2 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14311 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7651] Python3: guess text file charset using the BOM
Changes by Łukasz Langa luk...@langa.pl: -- assignee: - lukasz.langa ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7651 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14372] Fix all invalid usage of borrowed references
New submission from STINNER Victor victor.stin...@gmail.com: I fixed the issues #14211 and #14231. These issues were invalid usage of borrowed reference: the reference can be destroyed before the reference is used. Armin Rigo replied: I will attempt a last time to mention that the docstrings in borrowed_ref_*.py used to say they were *examples*. That means: (1) find any internal or external C function that returns a borrowed reference; (2) find all callers and write down all the places that don't immediately either Py_INCREF() the returned value or immediately forget about it; (3) for each such place, either come up painfully with a complicated explanation of why it's safe in all possible cases, or in doubt, just fix it by adding Py_INCREF()/Py_DECREF(). What I did in writing these two borrowed_ref_*.py was to do instead (3') spend a few hours figuring out how to exploit the issue until we get a segfault. I did it for two examples, but what I'm definitely not going to do is spend N times a few hours for a large number N. If python-dev people just fix the two examples, remove the crashers, and just forget about the issue, then well, the point is missed, but I'm not going to fight it. Sorry Armin, I didn't know that the issue of borrowed was a generic issue and more code need to be fixed. So I'm opening this issue to track of invalid usage of borrowed references. -- components: Interpreter Core, Library (Lib) messages: 156401 nosy: haypo priority: normal severity: normal status: open title: Fix all invalid usage of borrowed references type: crash versions: Python 3.3 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14372 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14372] Fix all invalid usage of borrowed references
Changes by STINNER Victor victor.stin...@gmail.com: -- nosy: +arigo ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14372 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7652] Merge C version of decimal into py3k.
Stefan Krah stefan-use...@bytereef.org added the comment: We need to decide what to do with the different limits of the 64-bit and 32-bit versions: MAX_EMAX default context 10**9-1 64-bit 10**18-1 32-bit42500 I think it would be annoying to have the values in DefaultContext, ExtendedContext and BasicContext depend on the machine. The best thing might be to use Emax=10**8-1 and Emin=-(10**8-1) throughout. I don't think many applications depend on having Emax=10**9-1. If they do, they'll have to use the 64-bit version. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7652 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14372] Fix all invalid usage of borrowed references
STINNER Victor victor.stin...@gmail.com added the comment: (1) find any internal or external C function that returns a borrowed reference Doc/data/refcounts.dat can be used for that: PyCell_GET PyDict_GetItem PyDict_GetItemString PyErr_Occurred PyEval_GetBuiltins PyEval_GetLocals PyEval_GetGlobals PyEval_GetFrame PyFile_Name PyFunction_GetClosure PyFunction_GetCode PyFunction_GetDefaults PyFunction_GetGlobals PyFunction_GetModule Py_InitModule Py_InitModule3 Py_InitModule4 PyImport_AddModule PyImport_GetModuleDict PyList_GET_ITEM PyList_GetItem PyMethod_Class PyMethod_Function PyMethod_GET_CLASS PyMethod_GET_FUNCTION PyMethod_GET_SELF PyMethod_Self PyModule_GetDict PyObject_Init PySequence_Fast_GET_ITEM PySys_GetObject PySys_GetXOptions PyThreadState_GetDict PyTuple_GET_ITEM PyTuple_GetItem PyWeakref_GET_OBJECT PyWeakref_GetObject (this list may be incomplete, it should be checked) Not affected (always return NULL): PyErr_NoMemory PyErr_Set... -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14372 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14369] make __closure__ writable
Andrew Svetlov andrew.svet...@gmail.com added the comment: Please update the doc also. I think changing from 'Read-only' to 'Writable' in Doc/reference/datamodel.rst is enough. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14369 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14373] C implementation of functools.lru_cache
New submission from Matt Joiner anacro...@gmail.com: functools.lru_cache is optimized to the point that it may benefit from a C implementation. -- components: Interpreter Core, Library (Lib) messages: 156405 nosy: anacrolix, rhettinger priority: normal severity: normal status: open title: C implementation of functools.lru_cache type: performance versions: Python 3.3 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14373 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14249] unicodeobject.c: aliasing warnings
Serhiy Storchaka storch...@gmail.com added the comment: What if add more hacking? If long integer already used for buffering and checking, let use it for swapping and splitting too. With my patch (attached) codecs.utf_16_be_decode runs 5% faster (on 32-bit Linux, I was not tested 64-bit). And of cause no pointers -- no aliasing warnings. -- nosy: +storchaka Added file: http://bugs.python.org/file24957/utf16_decoder_shift.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14249 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14249] unicodeobject.c: aliasing warnings
STINNER Victor victor.stin...@gmail.com added the comment: With my patch (attached) codecs.utf_16_be_decode runs 5% faster (on 32-bit Linux, I was not tested 64-bit). And of cause no pointers -- no aliasing warnings. Your patch is wrong: you need to use 0x to get lower 16 bits when reading a UTF-16 unit. For example, (Py_UCS2)(block 32) should be written (Py_UCS2)((block 32) 0x). -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14249 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14373] C implementation of functools.lru_cache
Changes by Matt Joiner anacro...@gmail.com: Added file: http://bugs.python.org/file24958/functools.lru_cache-in-c ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14373 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14249] unicodeobject.c: aliasing warnings
Serhiy Storchaka storch...@gmail.com added the comment: Heh. This was in previous version of my patch. I have removed ' 0xu' and parents for simplicity. GCC produces same binaries for both sources. But you can return it back. It has effect only on plathforms with non-16-bit short, but now Python not supports they (Python is not well portable on exotic plathforms). -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14249 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9787] Release the TLS lock during allocations
Kristján Valur Jónsson krist...@ccpgames.com added the comment: New patch, based on the cpython tip. -- Added file: http://bugs.python.org/file24959/tlspatch.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9787 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14249] unicodeobject.c: aliasing warnings
Changes by Serhiy Storchaka storch...@gmail.com: Added file: http://bugs.python.org/file24960/utf16_decoder_shift_2.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14249 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14302] Move python.exe to bin/
VanL v...@python.org added the comment: As Éric mentioned, there are two proposals here: 1. Move the python exe 2. Change 'Scripts' to 'bin' As for #1, what about letting the location of the python binary be an install option: [ ] Put python.exe into binaries directory and add to PATH? And then make it unchecked by default in 3.3, checked by default in 3.4, and then remove the option for 3.5? As for #2, I don't see a lot of resistance; the issues seem to mostly be with #1. Could #2 move into 3.3? -- nosy: +VanL ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14302 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9787] Release the TLS lock during allocations
Kristján Valur Jónsson krist...@ccpgames.com added the comment: hm, for some reason this patch isn't viewable in side-by-side -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9787 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12684] profile does not dump stats on exception like cProfile does
Changes by Matt Joiner anacro...@gmail.com: Added file: http://bugs.python.org/file24961/profiler-unhandled-exceptions.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12684 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14369] make __closure__ writable
Yury Selivanov yseliva...@gmail.com added the comment: Please update the doc also. I think changing from 'Read-only' to 'Writable' in Doc/reference/datamodel.rst is enough. Updated in writable_closure_03.patch. Thanks. -- Added file: http://bugs.python.org/file24962/writable_closure_03.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14369 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9720] zipfile writes incorrect local file header for large files in zip64
Changes by David Andrzejewski site+python@davidandrzejewski.com: -- nosy: +dandrzejewski ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9720 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14269] SMTPD server does not enforce client starting mail transaction with HELO or EHLO
Jason Killen jsnk...@gmail.com added the comment: I'm adding a patch for test_smtpd.py. This version includes the changes in my previous patch and adds sending HELO before the commands in the test. Works good for me. -- Added file: http://bugs.python.org/file24963/test_smtpd.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14269 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13694] asynchronous connect in asyncore.dispatcher does not set addr
Matt Joiner anacro...@gmail.com added the comment: This patch is a shoo-in, can someone review and commit this? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13694 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com