Brython 2.0 (Python in the browser)
Hi, Brython (Browser Python) is an implementation of Python 3 in the browser. Its goal is to be able to write client-side programs in Python instead of Javascript, with code inside tags script type=text/python.../script. As opposed to solutions such as Pyjamas or Py2JS, the translation from Python to Javascript is done in the browser, it doesn't require a precompilation by a Python program Launched late 2012, Brython is attracting a growing community of Python developers. Version 2.0 supports most of the CPython syntax and improves the interaction with Javascript libraries. The complete changelog is detailed below The main entry point is the Brython site at http://www.brython.info, with an online editor and demos Development is hosted by Bitbucket : https://bitbucket.org/olemis/brython/src Join us on the Google group : https://groups.google.com/forum/?fromgroups=#!forum/brython - Pierre Changes in Brython version 2.0-20140209-164925 == Backwards-incompatible change = For the sake of namespace isolation, by default, the name of functions and classes defined in Brython are no more available in Javascript global namespace. As a consequence, functions can't be called as event callbacks from HTML tags. For instance, if a function echo() is defined in a Brython script, the following inline code : button onclick=echo() will result in a Javascript error such as name echo is not defined when the button is clicked The solution is to define the event callback inside Brython code. The button must have an id : button id=echo and the Brython code must include the line doc[echo].bind(click,echo) Alternatively, to force the name echo into the global Javascript namespace, add it as an attribute of the window object : from browser import window window.echo = echo Features - namespace isolation : in previous versions, the names defined in Brython core scripts were included in the global Javascript namespace, raising risks of conflict with names defined in Javascript programs or libraries. In this version, the only names included in the global Javascript namespace are __BRYTHON__ (used internally) and brython(), the function called on page load - implement sys.implementation with values adapted for Brython - allow syntax del (x, y, z) - use Dan McDougall's pyminifier to reduce size of py_VFS.js - make_dist generates a script brython_dist.js that can be used as a standalone distribution on a centralised server. Demos = - add drop files demo (by Glenn Linderman) and French Python course (using module slideshow) to the gallery Imports === - improved version of py_VFS.js by Billy Earney. py_VFS compiles the standard library to make imports faster. Now packs Python source with JSON instead of base64 Built-in modules - browser : add attributes window and document as alias of respectively win and doc - add a module browser/slideshow for PowerPoint-like slideshows in Brython, using a custom file format Bug fixes = - issue #174 : string format character % has wrong precedence - issue #175 : Functions should return None by default - issue #183 : re.findall() broken - issue #198 : operator precedence not defined for and - issue #206 : add noscript in case Javascript is disabled - issue #208 : bug with try / else - issue #209 : bug in ternary operator - function definions must be evaluated only once, upon function definition - bug with del a[:] - bug with dir() called without arguments - bug in map() - bug with func(x=1,) ; return +x ; func(10*-x) - bug in divmod and round - bug in local_storage method keys() - add attribute __doc__ to class and instance methods Documentation = - updated with the changes introduced in this version - add documentation for the built-in module javascript - translation in Spanish updated by Kiko Correoso -- https://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
Re: Can one use Python to learn and even apply Functional Programming?
This made me grin. ;) -- https://mail.python.org/mailman/listinfo/python-list
Re: Explanation of list reference
Marko Rauhamaa ma...@pacujo.net: Conceptually, the everything is a reference and the small/big distinction are equivalent (produce the same outcomes). The question is, which model is easier for a beginner to grasp. Case in point, if everything is a reference, how come: hello.__str__() 'hello' 1.__str__() SyntaxError: invalid syntax Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: Install python 2 and 3 in the wrong order
I should emphasize that this is with the /same/ x.y version... Installing 3.3 when the previous was 3.2 won't overlay. Though I don't see anything in the ActiveState builds (which are all I've ever used) to handle the #! type selection of the desired version. Just got done updating my 2.7, replacing 3.2 with 3.3, and then having to edit my path to make 2.7 primary... No py.exe I need both 2.7 and 3.3. And apparently, py.exe does not work the way it should be. I would happily reinstall 3.3 to solve the problem, but before I do that I would like to check all other related settings. So that after I reinstall 3.3, I will exactly know what was happening. It might be a good idea to change the installer of the 2.x series to detect if 3.x is already installed, and handle assignments of py and pyw files gracefully. -- https://mail.python.org/mailman/listinfo/python-list
Re: Explanation of list reference
On Feb 16, 2014 1:11 AM, Marko Rauhamaa ma...@pacujo.net wrote: Marko Rauhamaa ma...@pacujo.net: Conceptually, the everything is a reference and the small/big distinction are equivalent (produce the same outcomes). The question is, which model is easier for a beginner to grasp. Case in point, if everything is a reference, how come: hello.__str__() 'hello' 1.__str__() SyntaxError: invalid syntax You need parentheses around the 1. Otherwise you confuse the lexer, which thinks you're starting a float literal. (1).__str__() '1' -- https://mail.python.org/mailman/listinfo/python-list
Re: Explanation of list reference
On Sun, Feb 16, 2014 at 1:28 AM, Ian Kelly ian.g.ke...@gmail.com wrote: On Feb 16, 2014 1:11 AM, Marko Rauhamaa ma...@pacujo.net wrote: Case in point, if everything is a reference, how come: hello.__str__() 'hello' 1.__str__() SyntaxError: invalid syntax You need parentheses around the 1. Otherwise you confuse the lexer, which thinks you're starting a float literal. (1).__str__() '1' Or if the parentheses bother you, you can also just toss in some whitespace: 1 .__str__() '1' -- https://mail.python.org/mailman/listinfo/python-list
Re: Explanation of list reference
Marko Rauhamaa ma...@pacujo.net writes: Marko Rauhamaa ma...@pacujo.net: Conceptually, the everything is a reference and the small/big distinction are equivalent (produce the same outcomes). The question is, which model is easier for a beginner to grasp. Case in point, if everything is a reference, how come: hello.__str__() 'hello' 1.__str__() SyntaxError: invalid syntax That's just a clash with number syntax. Once succesfully parsed, there is no such difference: (1).__str__() '1' 1 .__str__() '1' (I'm not saying anything about anything being a reference, just that your example didn't get analyzed to a level where there are things.) -- https://mail.python.org/mailman/listinfo/python-list
Re: Explanation of list reference
Marko Rauhamaa ma...@pacujo.net writes: Case in point, if everything is a reference, how come: hello.__str__() 'hello' 1.__str__() SyntaxError: invalid syntax (1).__str__() '1' 1..__str__() '1.0' -- Alan Bawden -- https://mail.python.org/mailman/listinfo/python-list
Re: Explanation of list reference
On Sun, 16 Feb 2014 10:08:22 +0200, Marko Rauhamaa wrote: Case in point, if everything is a reference, how come: hello.__str__() 'hello' 1.__str__() SyntaxError: invalid syntax Because it is a syntax error, just like the parser tells you. When the parser sees 1. it expects a floating point number, and 1.__str__() is not a legal float. There are three simple ways to get the effect that you want: py x = 1; x.__str__() # don't use a literal '1' py (1).__str__() # parenthesize the literal '1' py 1 .__str__() # offset it from the dot with a space '1' -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: Can one use Python to learn and even apply Functional Programming?
On 2/16/2014 1:38 AM, Devin Jeanpierre wrote: On Sat, Feb 15, 2014 at 8:45 PM, Sam lightai...@gmail.com wrote: I would like to learn and try out functional programming (FP). I love Python and would like to use it to try FP. Some have advised me to use Haskell instead because Python is not a good language for FP. I am sort of confused at the moment. Is Python a dysfunctional programming language to apply FP? Can the more experienced Python users advise? Everything about FP that can be done in, say, Scheme, can be done in Python, with the exception of tail recursion (but that isn't important You can do tail recursion in Python, but it will not be noticed and optimized in the way it is is some functional languages. for real FP). But Scheme is old, and people keep thinking of new things and more interesting variations on the lambda calculus. Haskell is kind of the core of modern functional programming, and involves heavy use of concepts that do not exist or are visibly alien in Python. If you want to learn FP properly, you should learn Haskell. Otherwise you will likely be confused when you overhear functional programmers talking, whether it's about Hindley-Milner or sum types or eta conversion. In some ways, Haskell is more different from Python than Scheme is, so it may stretch your brain more. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: random.sample with large weighted sample-sets?
On 2/15/2014 11:41 PM, Tim Chase wrote: I'm not coming up with the right keywords to find what I'm hunting. I'd like to randomly sample a modestly compact list with weighted distributions, so I might have data = ( (apple, 20), (orange, 50), (grape, 30), ) If you actually start with date in this form, write the few lines needed to produce the form below. import bisect import random data = [ (0, 'apple'), (20, 'orange'), (70, 'grape'), ] for i in range(10): r = random.randrange(0, 100) i = bisect.bisect(data, (r, 'z')) - 1 print(data[i][1]) apple orange orange grape orange apple grape orange grape orange It is just coincidence that the sample has exactly the expected distribution. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: Explanation of list reference
On Sun, Feb 16, 2014 at 7:40 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: There are three simple ways to get the effect that you want: py x = 1; x.__str__() # don't use a literal '1' py (1).__str__() # parenthesize the literal '1' py 1 .__str__() # offset it from the dot with a space '1' Four: 0o1.__str__() # use a literal notation that doesn't allow floats '1' ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Explanation of list reference
Ian Kelly ian.g.ke...@gmail.com: (1).__str__() '1' Fair enough. The syntactic awkwardness, then, explains why numbers don't have an evolved set of methods (unlike strings). Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: Explanation of list reference
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info: On Sat, 15 Feb 2014 23:01:53 +0200, Marko Rauhamaa wrote: I demonstrated a situation where your claim: id(x) == id(y) implies x is y fails. My from-the-hip formulation can obviously be inaccurate, but I was hoping the point was clear. The Python language specification feels the need to introduce the nebulous concept of object lifetime. I believe that concept can be more confusing than useful. Compare that with Common Lisp, whose objects are by definition eternal; there's no garbage collection. Practical implementations do collect garbage, but that's an optimization that doesn't affect the observed output of a program. It is possible to define id() without making any references to the object lifetime. Let's, then, make a more satisfactory attempt at specifying id(): 1. For any argument, the function id returns an integer. 2. For any pair of arguments, the function lambda x, y: (id(x) == id(y)) == (x is y) returns True. That should cover all valid implementations and uses of id(). Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: Explanation of list reference
On Sun, Feb 16, 2014 at 9:52 PM, Marko Rauhamaa ma...@pacujo.net wrote: Ian Kelly ian.g.ke...@gmail.com: (1).__str__() '1' Fair enough. The syntactic awkwardness, then, explains why numbers don't have an evolved set of methods (unlike strings). No; it's more that numbers are more often used with either operators or polymorphic functions. Yes, you can add strings together with +, but with numbers, you also subtract them, multiply them (okay, you can multiply a string by a number, but that kinda counts one to each), and divide them (some languages let you divide a string by a string, but Python does that with the .split() method). There are only two types of string, and arguably one of them is more an array of bytes than it is a string; but with numbers, you have int/float/complex/Fraction/Decimal, and rather than create methods that have to be implemented by each, there are stand-alone functions instead. Strings get methods: a b c d.count( ) 3 asdf.capitalize() 'Asdf' asdf.center(20) 'asdf' Numbers get functions: math.sqrt(100) 10.0 math.sqrt(100.0) 10.0 math.log(1234) 7.1180162044653335 Sometimes the line is blurred: help(math.trunc) Help on built-in function trunc in module math: trunc(x) Truncates x to the nearest Integral toward 0. Uses the __trunc__ magic method. Which could have been done as x.trunc() instead: 0o1.__trunc__ built-in method __trunc__ of int object at 0x1E288A30 1.0.__trunc__ built-in method __trunc__ of float object at 0x012AF400 (1+0j).__trunc__ Traceback (most recent call last): File pyshell#14, line 1, in module (1+0j).__trunc__ AttributeError: 'complex' object has no attribute '__trunc__' math.trunc(1+0j) Traceback (most recent call last): File pyshell#16, line 1, in module math.trunc(1+0j) TypeError: type complex doesn't define __trunc__ method But in a lot of cases, it makes good sense to have a single function that can take many types of number (since, after all, it's possible to define a lot of functions in terms of the basic operators), whereas doing them as methods would entail duplicating code. Partly it's just a matter of expectations. People expect strings to have more methods and numbers to use more operators, so a string method is discoverable and an int method is less so. (When was the last time *you* checked to see what methods an int has?) ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Explanation of list reference
On Sun, 16 Feb 2014 12:52:58 +0200, Marko Rauhamaa wrote: Ian Kelly ian.g.ke...@gmail.com: (1).__str__() '1' Fair enough. The syntactic awkwardness, then, explains why numbers don't have an evolved set of methods (unlike strings). But numbers do have an evolved set of methods. py [name for name in vars(int) if not name.startswith(_)] ['numerator', 'imag', 'to_bytes', 'from_bytes', 'bit_length', 'real', 'conjugate', 'denominator'] py [name for name in vars(float) if not name.startswith(_)] ['fromhex', 'imag', 'as_integer_ratio', 'is_integer', 'hex', 'real', 'conjugate'] py [name for name in vars(complex) if not name.startswith(_)] ['imag', 'real', 'conjugate'] To say nothing of these numbers: py from decimal import Decimal py [name for name in vars(Decimal) if not name.startswith(_)] ['canonical', 'exp', 'to_integral_value', 'logical_xor', 'imag', 'same_quantum', 'log10', 'max_mag', 'is_snan', 'to_eng_string', 'ln', 'is_normal', 'min', 'is_subnormal', 'to_integral_exact', 'is_nan', 'logb', 'is_qnan', 'logical_or', 'radix', 'real', 'max', 'normalize', 'as_tuple', 'is_canonical', 'is_zero', 'copy_negate', 'min_mag', 'next_plus', 'is_finite', 'number_class', 'scaleb', 'is_signed', 'compare_total', 'next_toward', 'adjusted', 'fma', 'rotate', 'logical_and', 'from_float', 'to_integral', 'next_minus', 'remainder_near', 'compare_signal', 'quantize', 'is_infinite', 'copy_sign', 'shift', 'compare_total_mag', 'copy_abs', 'compare', 'conjugate', 'logical_invert', 'sqrt'] That's more methods than strings have: py len([name for name in vars(Decimal) if not name.startswith(_)]) 54 py len([name for name in vars(str) if not name.startswith(_)]) 44 -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: How to turn a package into something pip can install
On Sat, Feb 15, 2014 at 11:35 PM, Roy Smith r...@panix.com wrote: In article roy-8299b9.17014115022...@news.panix.com, Roy Smith r...@panix.com wrote: $ pip install --no-index --quiet --find-links packages metar==1.4.0 [snip] ValueError: unknown url type: packages The path to your cache directory is incorrect. I suggest using absolute paths (eg. /home/user/packages) instead of relative paths, which is likely what caused this issue. No, that's not it. It doesn't work with an absolute path either. OK, I figured this out. The on-line docs (http://www.pip-installer.org/en/latest/reference/pip_wheel.html) say you can give --find-links a path, but it looks like it insists on it being a valid URL. If I prepend file: to the absolute path, it works. Maybe this is something which has changed in newer versions of pip? I've got 1.1 (and python 2.7.3). I'm pretty sure both of these are what came with Ubuntu Precise. -- https://mail.python.org/mailman/listinfo/python-list It’s heavily outdated, and that IS the cause of your problem. pip 1.5 accepts such paths just fine. Please upgrade your pip. -- Chris “Kwpolska” Warrick http://kwpolska.tk PGP: 5EAAEA16 stop html mail | always bottom-post | only UTF-8 makes sense -- https://mail.python.org/mailman/listinfo/python-list
Re: decimal numbers
Without any warranty. def z(r): ... # r: int 0 ... t = log10(r) ... if t = 12.0: ... prefix = '' ... prefix2 = '' ... elif t = 9.0: ... prefix = 'giga' ... prefix2 = 'G' ... r = r / 1.0e9 ... elif t = 6.0: ... prefix = 'mega' ... prefix2 = 'M' ... r = r / 1.0e6 ... elif t = 3.0: ... prefix = 'kilo-' # Netherlands std? ... prefix2 = 'k' ... r = r / 1.0e3 ... else: ... prefix = '' ... prefix2 = '' ... ... # correct for this language (Dutch?) ? ... # kept as illustrative example ... if r = 2: ... suffix = 's' ... else: ... suffix = '' ... ... # '.13g' to cover the ranges while keeping precision ... num = format(r, '.13g') ... s = 'de weerstand is ' + num + ' ' + prefix + 'ohm' + suffix ... s = s + ' , R = ' + num + ' ' + prefix2 + 'Ω' ... return s ... a = [1, 2, 9, 20, 300, 1000 - 1, 1000, 1000 + 1, 2000, \ ... 100 - 1, 100, 100 + 1, \ ... 10 - 1, 10, 10 + 1, 11123456789] for e in a: ... print(e, '-', z(e)) ... 1 - de weerstand is 1 ohm , R = 1 Ω 2 - de weerstand is 2 ohms , R = 2 Ω 9 - de weerstand is 9 ohms , R = 9 Ω 20 - de weerstand is 20 ohms , R = 20 Ω 300 - de weerstand is 300 ohms , R = 300 Ω 999 - de weerstand is 999 ohms , R = 999 Ω 1000 - de weerstand is 1 kilo-ohm , R = 1 kΩ 1001 - de weerstand is 1.001 kilo-ohm , R = 1.001 kΩ 2000 - de weerstand is 2 kilo-ohms , R = 2 kΩ 99 - de weerstand is 999.999 kilo-ohms , R = 999.999 kΩ 100 - de weerstand is 1 megaohm , R = 1 MΩ 101 - de weerstand is 1.01 megaohm , R = 1.01 MΩ 9 - de weerstand is 999.99 megaohms , R = 999.99 MΩ 10 - de weerstand is 1 gigaohm , R = 1 GΩ 11 - de weerstand is 1.1 gigaohm , R = 1.1 GΩ 11123456789 - de weerstand is 11.123456789 gigaohms , R = 11.123456789 GΩ jmf -- https://mail.python.org/mailman/listinfo/python-list
Re: inheriting a large python code base
when I do profiling is it possible to find out if I am spending a lot of time in type conversion? it seems I am not. Also, is it possible to predeclare a type in python? Similar to C: int i=0; On Sat, Feb 15, 2014 at 10:06 PM, Rustom Mody rustompm...@gmail.com wrote: On Sunday, February 16, 2014 4:45:04 AM UTC+5:30, Roy Smith wrote: In article Cameron Simpson wrote: On 15Feb2014 12:10, Rita wrote: i just inherited a large python code base and I would like to optimize the code (run faster). The application is a scientific application so I really don't understand the internal logic. [...] One thing I would keep in mind is that scientific applications generally involve floating point math. That is subject to loss of precision if done the wrong way. Another thing to keep in mind is that scientific applications are often written by {physicists, chemists, astronomers, etc} who have no clue about how floating point math, or indeed much of anything about computers, works :-) Not exactly my experience. Most of the {physicists, chemists, astronomers, etc}s I know grok floating point better than Ive been able to do in 30 years. They dont get much else though! -- Usually called 'Fortran programmers'. The guy who taught me numerical analysis -- a brilliant chemist -- could never understand why anyone should want to use anything other than Fortran. And it was a self-evident God's truth that a variable starting with I-N was integer Rest real. Declarations?? Pshaw! Sissy stuff! I *IS* an integer and no hanky-panky about it -- https://mail.python.org/mailman/listinfo/python-list -- --- Get your facts first, then you can distort them as you please.-- -- https://mail.python.org/mailman/listinfo/python-list
Re: Problem importing libraries installed with PIP in Eclipse
Em sexta-feira, 14 de fevereiro de 2014 01h30min05s UTC-2, Renato escreveu: Hi guys, I'm using Python 2.7.5 64 bits and I have a problem when importing libraries that were installed via PIP when importing them inside Eclipse (version 4.3.1). Outside Eclipse (directly in Python's shell) everything works fine, here is an example: import numpy # installed from repositories from numpy import array import pybrain # installed via PIP from pybrain import Network Everything works outside Eclipse. But inside Eclipse I can't import libraries installed via PIP using from x import y format, it will give an error. The only way I can import libraries installed via PIP is using import x format. Here is an example: import numpy # no errors (installed from repositories) from numpy import array # no errors import pybrain # no errors (installed via PIP) from pybrain import Network # gives the error below Traceback (most recent call last): File /media/arquivos/pybrain_import_test.py, line 4, in module from pybrain import Network ImportError: cannot import name Network I suspected it could be related to virtualenv, but here is a print screen (http://imageshack.com/a/img534/4307/3x0m.png) of my Python's PATH. The directory /usr/lib/python2.7/site-packages where PyBrain is installed is already in Python's PATH inside Eclipse. Could someone help me, please? Fabio, thanks for your reply. I'm using PyDev version 2.7.0.2013032300, the one who comes with Aptana Studio plugin for Eclipse. Here is Eclipse output: /media/arquivos/Documentos/Programacao/Source/workspace_linux/Testes em Python/src /media/arquivos/Documentos/Programacao/Source/workspace_linux/Testes em Python/src/pip_eclipse /usr/lib/python2.7/site-packages /usr/lib/python27.zip /usr/lib64/python2.7 /usr/lib64/python2.7/lib-dynload /usr/lib64/python2.7/lib-old /usr/lib64/python2.7/lib-tk /usr/lib64/python2.7/plat-linux2 /usr/lib64/python2.7/site-packages /usr/lib64/python2.7/site-packages/PIL /usr/lib64/python2.7/site-packages/gtk-2.0 /usr/lib64/python2.7/site-packages/wx-2.8-gtk2-unicode /usr/local/lib/python2.7/site-packages /usr/local/lib/python2.7/site-packages /usr/local/lib64/python2.7/site-packages /usr/local/lib64/python2.7/site-packages And here is Python shell output: /usr/lib/python2.7/site-packages /usr/lib/python27.zip /usr/lib64/python2.7 /usr/lib64/python2.7/lib-dynload /usr/lib64/python2.7/lib-old /usr/lib64/python2.7/lib-tk /usr/lib64/python2.7/plat-linux2 /usr/lib64/python2.7/site-packages /usr/lib64/python2.7/site-packages/PIL /usr/lib64/python2.7/site-packages/gtk-2.0 /usr/lib64/python2.7/site-packages/wx-2.8-gtk2-unicode /usr/local/lib/python2.7/site-packages /usr/local/lib64/python2.7/site-packages They are almost exactly the same, the only difference is that Eclipse includes the directory I'm running the script and print twice the last 2 directories. -- https://mail.python.org/mailman/listinfo/python-list
Re: Can one use Python to learn and even apply Functional Programming?
On 16/02/2014 08:00, Pat Johnson wrote: This made me grin. ;) What did, using google groups? :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com -- https://mail.python.org/mailman/listinfo/python-list
Re: How to turn a package into something pip can install
On Sun, Feb 16, 2014 at 11:18 PM, Chris “Kwpolska” Warrick kwpol...@gmail.com wrote: On Sat, Feb 15, 2014 at 11:35 PM, Roy Smith r...@panix.com wrote: Maybe this is something which has changed in newer versions of pip? I've got 1.1 (and python 2.7.3). I'm pretty sure both of these are what came with Ubuntu Precise. It’s heavily outdated, and that IS the cause of your problem. pip 1.5 accepts such paths just fine. Please upgrade your pip. http://packages.ubuntu.com/precise/python-pip says it's shipping 1.0.1, even older. You get 1.1 with Quantal: http://packages.ubuntu.com/quantal/python-pip and (unsurprisingly) newer versions with newer Ubuntus. Debian's just as bad, incidentally. On Wheezy (current stable), Debian ships 1.1, though Jessie (current testing) has 1.4.1. But neither Ubuntu Trusty nor Debian Sid (unreleased versions of each) ships 1.5. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: inheriting a large python code base
On Sun, Feb 16, 2014 at 11:59 PM, Rita rmorgan...@gmail.com wrote: when I do profiling is it possible to find out if I am spending a lot of time in type conversion? it seems I am not. I would guess that you don't. But in Python, type conversion is like any other function call: value = int(12345) So you can test for it the same way you would any other. Also, is it possible to predeclare a type in python? Similar to C: int i=0; No, because in Python, variables/names don't have types - only objects/values do. You can simply initialize i to 0, in the obvious way: i = 0 And if you never put anything but an integer into i, it'll always be an integer. That's about as close as you'll get to an integer variable like C has. (Python's idea of an integer is rather better than C's, of course; C's 'int' type is a machine word, so it can't store values greater than 2**32 or 2**64 or whatever the limit is, but Python's int can store any integer you have RAM enough to store.) ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Can one use Python to learn and even apply Functional Programming?
On Mon, Feb 17, 2014 at 12:20 AM, Mark Lawrence breamore...@yahoo.co.uk wrote: On 16/02/2014 08:00, Pat Johnson wrote: This made me grin. ;) What did, using google groups? :) Well! I've often seen context without a grin, thought Alice; but a grin without context! It's the most curious thing I ever saw in my life! ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Can one use Python to learn and even apply Functional Programming?
On Sunday, February 16, 2014 10:15:58 AM UTC+5:30, Sam wrote: I would like to learn and try out functional programming (FP). I love Python and would like to use it to try FP. Some have advised me to use Haskell instead because Python is not a good language for FP. I am sort of confused at the moment. Is Python a dysfunctional programming language to apply FP? Can the more experienced Python users advise? For many years I taught programming in which a pure functional language was the 'mother-tongue' and was followed by a multi-paradigm language. In the 90s the pair was Miranda + Scheme; after 2001 it was a haskell (wee-subset) + python. Two of the bedrock items for a FP education is 1. Getting Hindley-Milner* 2. Lambda Calculus 1 python does not have at all and 2 is ok but not great. Once Hindley-Milner is in your bones -- yeah its radioactive and harmless -- you can happily think in pseudo-Haskell and code in(to) python (or C++ or whatever) The syllabus I made and used (well kindof :-) ) http://www.the-magus.in/Publications/ip.pdf I must say I am not personally too happy with haskell's direction today -- its 'progress' looks quite like how C++ 'progresses' C. [Yeah this does not amount to a very helpful direction :-( ] In more abstract, here is a blog-post of mine http://blog.languager.org/2012/10/functional-programming-lost-booty.html which lists out (in very brief) concepts/features that originated from FP and would benefit programmers irrespective of language/paradigm/technology they are currently into. -- https://mail.python.org/mailman/listinfo/python-list
Puzzling PDF
Hi all, Struggling to parse bank statements unavailable in sensible data-transfer formats, I use pdftotext, which solves part of the problem. The other day I encountered a strange thing, when one single figure out of many erroneously converted into letters. Adobe Reader displays the figure 50'000 correctly, but pdftotext makes it into SO'OOO (The letters S as in Susan and O as in Otto). One would expect such a mistake from an OCR. However, the statement is not a scan, but is made up of text. Because malfunctions like this put a damper on the hope to ever have a reliable reader that doesn't require time-consuming manual verification, I played around a bit and ended up even more confused: When I lift the figure off the Adobe display (mark, copy) and paste it into a Python IDLE window, it is again letters (ascii 83 and 79), when on the Adobe display it shows correctly as digits. How can that be? Frederic -- https://mail.python.org/mailman/listinfo/python-list
Re: Explanation of list reference
On Saturday, February 15, 2014 7:14:39 PM UTC+5:30, Marko Rauhamaa wrote: Mark Lawrence: I have no interest in understanding object identity, I can write code quite happily without it. Luckily, what we are now debating is mostly terminology and points of view where the outcomes are unaffected. However, as an example, it is important to know if you should write: if x is not None: ... or if if x != None: ... is more robust. Yes This is my main beef: Not that both are possible but that the first is *recommended* and the second not. Something like a C compiler manual advising: You can write x*8 but its better to drop out into asm and write shl $3, %eax -- https://mail.python.org/mailman/listinfo/python-list
Re: random.sample with large weighted sample-sets?
On 2014-02-16 04:12, Terry Reedy wrote: On 2/15/2014 11:41 PM, Tim Chase wrote: data = ( (apple, 20), (orange, 50), (grape, 30), ) To Ben, yes, this was just some sample data; the original gets built from an external (i.e., client-supplied, thus the need to gracefully support crazy-large numbers) data source and is indeed actually a list rather than a tuple. When entering static data like this, I often default to an outer tuple (rather than list) just as a hint/reminder to myself that I don't expect this to change at runtime (and have Python yell at me if I accidentally try). If you actually start with date in this form, write the few lines needed to produce the form below. import bisect import random data = [ (0, 'apple'), (20, 'orange'), (70, 'grape'), ] for i in range(10): r = random.randrange(0, 100) i = bisect.bisect(data, (r, 'z')) - 1 print(data[i][1]) Trying to read what may be implicit assumptions in your code: 1) your code calculates 100 as sum(item[0] for item in data) 2) the data has to be sorted for bisect to work 3) you meant to write (10, 'apple') rather than 0. With my original example code, a 0-probability shouldn't ever show up in the sampling, where it looks like it might when using this sample code. In my particular use case, I can limit/ensure that 0-probability items never appear in the list, filtering them upon loading. 4) that zz is some arbitrary value that should come after any string that could appear in the data; perhaps using some custom InfinityString class where everything compared to it is always less than it. So it would be class InfinityString: def __gt__(self, other): True __ge__ = __gt__ def __lt__(self, other): False __eq__ = __le__ = __ne__ = __lt__ infinity_string = InfinityString() data = load_data() # list of (quantity, value) tuples data.sort() total = sum(qty for qty, value in data) for i in range(num_to_sample): r = random.randrange(0, total) i = bisect.bisect(data, (r, infinity_string)) - 1 use(data[i][1]) Some long-running testing on this code seems to show that if two items have the same probability, bisect only appears to find the last one. Tested with data = [ (10, apple), (20, banana), # I never get any bananas, even after thousands of iterations (20, grape), (50, orange), ] Thanks, -tkc -- https://mail.python.org/mailman/listinfo/python-list
Re: How to turn a package into something pip can install
In article mailman.7053.1392557013.18130.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: On Sun, Feb 16, 2014 at 11:18 PM, Chris âKwpolskaâ Warrick kwpol...@gmail.com wrote: On Sat, Feb 15, 2014 at 11:35 PM, Roy Smith r...@panix.com wrote: Maybe this is something which has changed in newer versions of pip? I've got 1.1 (and python 2.7.3). I'm pretty sure both of these are what came with Ubuntu Precise. Itâs heavily outdated, and that IS the cause of your problem. pip 1.5 accepts such paths just fine. Please upgrade your pip. http://packages.ubuntu.com/precise/python-pip says it's shipping 1.0.1, even older. You get 1.1 with Quantal: http://packages.ubuntu.com/quantal/python-pip and (unsurprisingly) newer versions with newer Ubuntus. Debian's just as bad, incidentally. On Wheezy (current stable), Debian ships 1.1, though Jessie (current testing) has 1.4.1. But neither Ubuntu Trusty nor Debian Sid (unreleased versions of each) ships 1.5. ChrisA Yup. I just checked around. My dev machine (which is Ubuntu Precise, plus some random upgrade history) has 1.1. Our production boxes (which are much cleaner Precise installs) have 1.0 in /usr/bin; that's only used for bootstrapping deployments. We have 1.4.1 in the virtualenv we run out of. Oh, yeah, we've still got a few Lucid boxes floating around on some back-end machines. They're running: pip 0.3.1 from /usr/lib/python2.6/dist-packages (python 2.6) We tend not to upgrade stuff unless there's a good reason to. You never know what will break (looking furtively in the direction of the Python 3.x mafiosi). -- https://mail.python.org/mailman/listinfo/python-list
Re: random.sample with large weighted sample-sets?
On 2/16/14 9:22 AM, Tim Chase wrote: 3) you meant to write (10, 'apple') rather than 0. With my original example code, a 0-probability shouldn't ever show up in the sampling, where it looks like it might when using this sample code. In my particular use case, I can limit/ensure that 0-probability items never appear in the list, filtering them upon loading. Terry didn't state this explicitly, but he restructured your data to have cumulative probabilities. You had: data = ( (apple, 20), (orange, 50), (grape, 30), ) He turned it into: data = [ (0, 'apple'), (0+20, 'orange'), (0+20+50, 'grape'), ] Each number is the cumulative probability up to but not including the item. -- Ned Batchelder, http://nedbatchelder.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Problem importing libraries installed with PIP in Eclipse
It's solved now, oh my god I was so stupid! I created a package named pybrain for testing PyBrain module, so obviously when I tryed to import something from PyBrain library, Python would import all modules from this personal package I created. The problem was not being reproduced outside Eclipse because only within Eclipse my personal workstation directory (which contained the personal package pybrain) was visible. The solution was simple: I just deleted the personal package named pybrain and now everything is working. Thank you very much for your help! -- https://mail.python.org/mailman/listinfo/python-list
Re: How to turn a package into something pip can install
On 16/02/2014 14:25, Roy Smith wrote: We tend not to upgrade stuff unless there's a good reason to. You never know what will break (looking furtively in the direction of the Python 3.x mafiosi). Yeah, those really unpleasant, nasty, horrible mafiosi who have the audacity to point out that people have only been given seven (ish) years so far to plan and implement their upgrades. Then the mafiosi further complain when people ask if they can have a Python 2.8 to help plan and implement their upgrades. Yep, this mafiosi mob really do have a lot to answer for. Not. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Can one use Python to learn and even apply Functional Programming?
Python*can* do functional programming, but, for learning, Haskell will work better. Sam lightai...@gmail.com wrote: I would like to learn and try out functional programming (FP). I love Python and would like to use it to try FP. Some have advised me to use Haskell instead because Python is not a good language for FP. I am sort of confused at the moment. Is Python a dysfunctional programming language to apply FP? Can the more experienced Python users advise? -- https://mail.python.org/mailman/listinfo/python-list -- Sent from my Android phone with K-9 Mail. Please excuse my brevity.-- https://mail.python.org/mailman/listinfo/python-list
Re: How to turn a package into something pip can install
On 2014-02-16 15:06, Mark Lawrence wrote: On 16/02/2014 14:25, Roy Smith wrote: We tend not to upgrade stuff unless there's a good reason to. You never know what will break (looking furtively in the direction of the Python 3.x mafiosi). Yeah, those really unpleasant, nasty, horrible mafiosi who have the audacity to point out that people have only been given seven (ish) years so far to plan and implement their upgrades. Then the mafiosi further complain when people ask if they can have a Python 2.8 to help plan and implement their upgrades. Yep, this mafiosi mob really do have a lot to answer for. Not. And, what's more, this mafiosi mob cruelly continues to provide the previous releases on its website free of charge, including all the source code. -- https://mail.python.org/mailman/listinfo/python-list
How to answer questions from newbies
We get a lot of newbie questions on this list. People are eager to jump in and answer them (which is wonderful), but sometimes we get off on tangents about trivia and lose sight of the real question, and our audience. The particular one that set me off just now (I'm leaving off the names because it's a generic problem) was somebody asking a basic, how do I code an algorithm to manipulate this data question. They presented some sample data as a tuple of tuples. One of the (otherwise well-written and informative) responses started out with a 20-line treatise on the difference between lists and tuples, and why the OP should have used a list of tuples. Nothing they said was wrong, but it wasn't essential to explaining the algorithm. What I'm asking is that when people answer questions, try to figure out what the core question really is, and answer that first. If there's other suggestions you can make for how things might be further improved, add those later. Also, try to figure out what the experience level of the OP is, and scale your answer to fit their ability. I've seen people who are obviously struggling with basic concepts in an introductory programming class get responses that include list comprehensions, lambdas, map/reduce, etc. These are things people should learn along the road to Python guru-ness, but if you haven't figured out what a for loop is yet, those things are just going to confuse you even more. -- https://mail.python.org/mailman/listinfo/python-list
Re: Puzzling PDF
In article mailman.7056.1392559276.18130.python-l...@python.org, F.R. anthra.nor...@bluewin.ch wrote: Hi all, Struggling to parse bank statements unavailable in sensible data-transfer formats, I use pdftotext, which solves part of the problem. The other day I encountered a strange thing, when one single figure out of many erroneously converted into letters. Adobe Reader displays the figure 50'000 correctly, but pdftotext makes it into SO'OOO (The letters S as in Susan and O as in Otto). One would expect such a mistake from an OCR. However, the statement is not a scan, but is made up of text. Because malfunctions like this put a damper on the hope to ever have a reliable reader that doesn't require time-consuming manual verification, I played around a bit and ended up even more confused: When I lift the figure off the Adobe display (mark, copy) and paste it into a Python IDLE window, it is again letters (ascii 83 and 79), when on the Adobe display it shows correctly as digits. How can that be? Frederic Maybe it's an intentional effort to keep people from screen-scraping data out of the PDFs (or perhaps trace when they do). Is it possible the document includes a font where those codepoints are drawn exactly the same as the digits they resemble? Keep in mind that PDF is not a data transmission format, it's a document format. When you try to scape data out of a PDF, you've made a pact with the devil. Unclear what any of this has to do with Python. Maybe the tie-in is that in the old Snake video game, the snake was drawn as Soo? Anyway, it's S as in Sierra, and O as in Oscar. -- https://mail.python.org/mailman/listinfo/python-list
Re: How to turn a package into something pip can install
On 16/02/2014 15:20, MRAB wrote: On 2014-02-16 15:06, Mark Lawrence wrote: On 16/02/2014 14:25, Roy Smith wrote: We tend not to upgrade stuff unless there's a good reason to. You never know what will break (looking furtively in the direction of the Python 3.x mafiosi). Yeah, those really unpleasant, nasty, horrible mafiosi who have the audacity to point out that people have only been given seven (ish) years so far to plan and implement their upgrades. Then the mafiosi further complain when people ask if they can have a Python 2.8 to help plan and implement their upgrades. Yep, this mafiosi mob really do have a lot to answer for. Not. And, what's more, this mafiosi mob cruelly continues to provide the previous releases on its website free of charge, including all the source code. The obligatory And apart from that, what have the mafiosi ... :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com -- https://mail.python.org/mailman/listinfo/python-list
Re: How to answer questions from newbies
On Sunday, February 16, 2014 8:53:47 PM UTC+5:30, Roy Smith wrote: We get a lot of newbie questions on this list. People are eager to jump in and answer them (which is wonderful), but sometimes we get off on tangents about trivia and lose sight of the real question, and our audience. The particular one that set me off just now (I'm leaving off the names because it's a generic problem) was somebody asking a basic, how do I code an algorithm to manipulate this data question. They presented some sample data as a tuple of tuples. One of the (otherwise well-written and informative) responses started out with a 20-line treatise on the difference between lists and tuples, and why the OP should have used a list of tuples. Nothing they said was wrong, but it wasn't essential to explaining the algorithm. What I'm asking is that when people answer questions, try to figure out what the core question really is, and answer that first. If there's other suggestions you can make for how things might be further improved, add those later. Also, try to figure out what the experience level of the OP is, and scale your answer to fit their ability. I've seen people who are obviously struggling with basic concepts in an introductory programming class get responses that include list comprehensions, lambdas, map/reduce, etc. These are things people should learn along the road to Python guru-ness, but if you haven't figured out what a for loop is yet, those things are just going to confuse you even more. Agreed! Just one WARNING! If you include comprehensions I shall include re's wink -- https://mail.python.org/mailman/listinfo/python-list
Re: random.sample with large weighted sample-sets?
On 16/02/14 05:08, Ben Finney wrote: Tim Chase python.l...@tim.thechases.com writes: I'm not coming up with the right keywords to find what I'm hunting. I'd like to randomly sample a modestly compact list with weighted distributions, so I might have data = ( (apple, 20), (orange, 50), (grape, 30), ) That's not a list, it's a tuple. I think you want a list. When you want a sequence where each position has a semantic meaning, use a tuple (such as ‘(apple, 20)’). Each item has a meaning *because of* the position it's in; if the items were in a different order, they'd mean different things. When you want a sequence where the positions don't have a special meaning – each item means exactly the same no matter if you change the order – that's sometimes called a “homogeneous” sequence, and you want a list. So a “record” should be represented as a tuple, and a “table” of records should be represented as a list of tuples: records = [ (apple, 20), (orange, 50), (grape, 30), ] and I'd like to random.sample() it as if it was a 100-element list. [snip] That's a description of sampling without replacement. The probabilities change as items are sampled. e.g. The probability of the first item being appleis 20/100. But the probability that the second sampled item is apple is either 19/99 or 20/99, depending on the value of the first sampled item. The following (due to Knuth) will generate indices into a notional list of items. def indices(n, pop): # generates indices into a # population list containing # items with frequencies in pop # [(apple, 10), (orange, 50), ...] N = sum(tup[1] for tup in pop) i = m = 0 while m n: u = random.random() if (N-i)*u = n-m: i += 1 else: yield i i += 1 m += 1 list(indices(3, [(apple, 20),(orange, 50),(grape, 30)])) [8, 27, 78] The indices are generated in order, so it could easily be extended to generate items or item count pairs. There might be something more efficient based on the hypergeometric distribution (generate a number of apples, then a number of oranges given the number of sampled apples, then a number of grapes given the number of sampled apples and oranges, etc.). Duncan -- https://mail.python.org/mailman/listinfo/python-list
Re: random.sample with large weighted sample-sets?
Tim Chase wrote: On 2014-02-16 04:12, Terry Reedy wrote: On 2/15/2014 11:41 PM, Tim Chase wrote: data = ( (apple, 20), (orange, 50), (grape, 30), ) To Ben, yes, this was just some sample data; the original gets built from an external (i.e., client-supplied, thus the need to gracefully support crazy-large numbers) data source and is indeed actually a list rather than a tuple. When entering static data like this, I often default to an outer tuple (rather than list) just as a hint/reminder to myself that I don't expect this to change at runtime (and have Python yell at me if I accidentally try). If you actually start with date in this form, write the few lines needed to produce the form below. import bisect import random data = [ (0, 'apple'), (20, 'orange'), (70, 'grape'), ] for i in range(10): r = random.randrange(0, 100) i = bisect.bisect(data, (r, 'z')) - 1 print(data[i][1]) Trying to read what may be implicit assumptions in your code: 1) your code calculates 100 as sum(item[0] for item in data) 2) the data has to be sorted for bisect to work 3) you meant to write (10, 'apple') rather than 0. With my original example code, a 0-probability shouldn't ever show up in the sampling, where it looks like it might when using this sample code. In my particular use case, I can limit/ensure that 0-probability items never appear in the list, filtering them upon loading. 4) that zz is some arbitrary value that should come after any string that could appear in the data; perhaps using some custom InfinityString class where everything compared to it is always less than it. So it would be class InfinityString: def __gt__(self, other): True __ge__ = __gt__ def __lt__(self, other): False __eq__ = __le__ = __ne__ = __lt__ infinity_string = InfinityString() data = load_data() # list of (quantity, value) tuples data.sort() total = sum(qty for qty, value in data) for i in range(num_to_sample): r = random.randrange(0, total) i = bisect.bisect(data, (r, infinity_string)) - 1 use(data[i][1]) Some long-running testing on this code seems to show that if two items have the same probability, bisect only appears to find the last one. Tested with data = [ (10, apple), (20, banana), # I never get any bananas, even after thousands of iterations (20, grape), (50, orange), ] I think it becomes simpler if you make an intermediate list with the cumulated probabilities. You can then avoid the InfinityString gymnastics: import random, bisect def cumulated(probs): sigma = 0 cumprobs = [] for p in probs: sigma += p cumprobs.append(sigma) return cumprobs def pick(cumprobs): return bisect.bisect(cumprobs, random.randrange(cumprobs[-1])) data = [ (10, apple), (20, banana), (20, grape), (50, orange), ] cumprobs = cumulated(p for p, k in data) # check for off-by-one bugs bins = [0] * len(cumprobs) for i in range(cumprobs[-1]): bins[bisect.bisect(cumprobs, i)] += 1 assert bins == [p for p, k in data] # use it bins = [0] * len(cumprobs) for i in range(1): bins[pick(cumprobs)] += 1 for item, bin in zip(data, bins): print({} -- {}.format(item, bin)) -- https://mail.python.org/mailman/listinfo/python-list
Re: How to answer questions from newbies
In article c2078ca1-c85a-4795-8632-6b005436c...@googlegroups.com, Rustom Mody rustompm...@gmail.com wrote: On Sunday, February 16, 2014 8:53:47 PM UTC+5:30, Roy Smith wrote: We get a lot of newbie questions on this list. People are eager to jump in and answer them (which is wonderful), but sometimes we get off on tangents about trivia and lose sight of the real question, and our audience. The particular one that set me off just now (I'm leaving off the names because it's a generic problem) was somebody asking a basic, how do I code an algorithm to manipulate this data question. They presented some sample data as a tuple of tuples. One of the (otherwise well-written and informative) responses started out with a 20-line treatise on the difference between lists and tuples, and why the OP should have used a list of tuples. Nothing they said was wrong, but it wasn't essential to explaining the algorithm. What I'm asking is that when people answer questions, try to figure out what the core question really is, and answer that first. If there's other suggestions you can make for how things might be further improved, add those later. Also, try to figure out what the experience level of the OP is, and scale your answer to fit their ability. I've seen people who are obviously struggling with basic concepts in an introductory programming class get responses that include list comprehensions, lambdas, map/reduce, etc. These are things people should learn along the road to Python guru-ness, but if you haven't figured out what a for loop is yet, those things are just going to confuse you even more. Agreed! Just one WARNING! If you include comprehensions I shall include re's wink Moi? -- https://mail.python.org/mailman/listinfo/python-list
Re: Explanation of list reference
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info: On Sun, 16 Feb 2014 12:52:58 +0200, Marko Rauhamaa wrote: The syntactic awkwardness, then, explains why numbers don't have an evolved set of methods (unlike strings). But numbers do have an evolved set of methods. [...] py from decimal import Decimal py [name for name in vars(Decimal) if not name.startswith(_)] ['canonical', 'exp', 'to_integral_value', 'logical_xor', 'imag', 'same_quantum', 'log10', 'max_mag', 'is_snan', 'to_eng_string', 'ln', 'is_normal', 'min', 'is_subnormal', 'to_integral_exact', 'is_nan', 'logb', 'is_qnan', 'logical_or', 'radix', 'real', 'max', 'normalize', 'as_tuple', 'is_canonical', 'is_zero', 'copy_negate', 'min_mag', 'next_plus', 'is_finite', 'number_class', 'scaleb', 'is_signed', 'compare_total', 'next_toward', 'adjusted', 'fma', 'rotate', 'logical_and', 'from_float', 'to_integral', 'next_minus', 'remainder_near', 'compare_signal', 'quantize', 'is_infinite', 'copy_sign', 'shift', 'compare_total_mag', 'copy_abs', 'compare', 'conjugate', 'logical_invert', 'sqrt'] That's more like it! Alas: (2).sqrt() AttributeError: 'int' object has no attribute 'sqrt' (2.0).sqrt() AttributeError: 'float' object has no attribute 'sqrt' import math math.sqrt(2) 1.4142135623730951 Also, unfortunately: (2.0).hex() '0x1.0p+1' (2).hex() AttributeError: 'int' object has no attribute 'hex' There's still some evolving to do. The smallness of numbers is still shining through. Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: Puzzling PDF
You On 2/16/2014 6:00 AM, F.R. wrote: Hi all, Struggling to parse bank statements unavailable in sensible data-transfer formats, I use pdftotext, which solves part of the problem. The other day I encountered a strange thing, when one single figure out of many erroneously converted into letters. Adobe Reader displays the figure 50'000 correctly, but pdftotext makes it into SO'OOO (The letters S as in Susan and O as in Otto). One would expect such a mistake from an OCR. However, the statement is not a scan, but is made up of text. Because malfunctions like this put a damper on the hope to ever have a reliable reader that doesn't require time-consuming manual verification, I played around a bit and ended up even more confused: When I lift the figure off the Adobe display (mark, copy) and paste it into a Python IDLE window, it is again letters (ascii 83 and 79), when on the Adobe display it shows correctly as digits. How can that be? I've also gotten inconsistent results using various pdf to text converters[1], but getting an explanation for pdf2totext's failings here isn't likely to happen. I'd first try google doc's on-line conversion tool to see if you get better results. If you're lucky it'll do the job and you'll have confirmation that better tools exist. Otherwise, I'd look for an alternate way of getting the bank info than working from the pdf statement. At one site I've scripted firefox to access the bank's web based inquiry to retrieve the new activity overnight and use that to complete a daily bank reconciliation. HTH, Emile [1] I wrote my own once to get data out of a particularly gnarly EDI specification pdf. -- https://mail.python.org/mailman/listinfo/python-list
Re: Explanation of list reference
On 2/16/14 9:00 AM, Rustom Mody wrote: On Saturday, February 15, 2014 7:14:39 PM UTC+5:30, Marko Rauhamaa wrote: Mark Lawrence: I have no interest in understanding object identity, I can write code quite happily without it. Luckily, what we are now debating is mostly terminology and points of view where the outcomes are unaffected. However, as an example, it is important to know if you should write: if x is not None: ... or if if x != None: ... is more robust. Yes This is my main beef: Not that both are possible but that the first is *recommended* and the second not. I'm not sure why you don't like the recommendation, or if you just want people to be more explicit about why it is recommended. My main reason for preferring x is not None is that if x's class defines __ne__ incorrectly, x != None can come out wrong. And yes, I have actually debugged problems where that was the root cause. If you use x is not None, nothing about x's class can interfere with the correct operation. Something like a C compiler manual advising: You can write x*8 but its better to drop out into asm and write shl $3, %eax -- Ned Batchelder, http://nedbatchelder.com -- https://mail.python.org/mailman/listinfo/python-list
Re: random.sample with large weighted sample-sets?
How efficient does this thing need to be? You can always just turn it into a two-dimensional sampling problem by thinking of the data as a function f(x=item), generating a random x=xr in [0,x], then generating a random y in [0,max(f(x))]. The xr is accepted if 0 y = max(f(xr)), or rejected (and another attempt made) if y max(f(xr)). -- https://mail.python.org/mailman/listinfo/python-list
Re: Explanation of list reference
On Sunday, February 16, 2014 9:59:53 PM UTC+5:30, Ned Batchelder wrote: On 2/16/14 9:00 AM, Rustom Mody wrote: On Saturday, February 15, 2014 7:14:39 PM UTC+5:30, Marko Rauhamaa wrote: Mark Lawrence: I have no interest in understanding object identity, I can write code quite happily without it. Luckily, what we are now debating is mostly terminology and points of view where the outcomes are unaffected. However, as an example, it is important to know if you should write: if x is not None: ... or if if x != None: ... is more robust. Yes This is my main beef: Not that both are possible but that the first is *recommended* and the second not. I'm not sure why you don't like the recommendation, or if you just want people to be more explicit about why it is recommended. My main reason for preferring x is not None is that if x's class defines __ne__ incorrectly, x != None can come out wrong. And yes, I have actually debugged problems where that was the root cause. If you use x is not None, nothing about x's class can interfere with the correct operation. Ok But for that Ive to use is And as a teacher Ive to explain is Might as well use C and get on with pointers To me 'is' is a can of worms Mostly I dont need to open that can In the few instances when I need to open it, I am allowed (I hope!) to say Ugh! -- https://mail.python.org/mailman/listinfo/python-list
Re: random.sample with large weighted sample-sets?
On 16/02/14 16:35, Charles Allen wrote: How efficient does this thing need to be? You can always just turn it into a two-dimensional sampling problem by thinking of the data as a function f(x=item), generating a random x=xr in [0,x], then generating a random y in [0,max(f(x))]. The xr is accepted if 0 y = max(f(xr)), or rejected (and another attempt made) if y max(f(xr)). You can avoid rejection by constructing an alias table. A list can be constructed such that each list element contains a pair of values and a cutoff. e.g. [(apple, 20), (orange, 50), (grape, 30)] would become (using one particular algorithm) [((apple, orange), 0.6), ((orange, apple), 1.0), ((grape, orange), 0.9)] Generate a random index, then select one of the values on the basis of the cutoff. For short enough lists you can generate a single 0-1 random variate, u, and use int(n*u) for the index and compare n*u - int(n*u) to the cutoff, where n is the length of the list. It's still sampling with replacement though. Duncan -- https://mail.python.org/mailman/listinfo/python-list
Re: Explanation of list reference
Rustom Mody rustompm...@gmail.com: But for that Ive to use is And as a teacher Ive to explain is Might as well use C and get on with pointers To me 'is' is a can of worms I'm not against is, but it must be carefully defined and taught. As far as x is None is concerned, a key piece of information is presented on URL: http://docs.python.org/3.2/library/constants.html: None The sole value of the type NoneType. Unfortunately the page is a bit confusing. It says: A small number of constants live in the built-in namespace. So an essential characteristic of the None object (uniqueness) is mentioned in the middle of the discussion on the built-in namespace. The index doesn't contain an entry on NoneType. Thus, there might still be a nagging concern that a second NoneType object x such that x == None and x is not None could crop up (from native code, perhaps). Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: Explanation of list reference
On 16/02/2014 18:01, Marko Rauhamaa wrote: Rustom Mody rustompm...@gmail.com: But for that Ive to use is And as a teacher Ive to explain is Might as well use C and get on with pointers To me 'is' is a can of worms I'm not against is, but it must be carefully defined and taught. As far as x is None is concerned, a key piece of information is presented on URL: http://docs.python.org/3.2/library/constants.html: None The sole value of the type NoneType. Unfortunately the page is a bit confusing. It says: A small number of constants live in the built-in namespace. So an essential characteristic of the None object (uniqueness) is mentioned in the middle of the discussion on the built-in namespace. The index doesn't contain an entry on NoneType. Thus, there might still be a nagging concern that a second NoneType object x such that x == None and x is not None could crop up (from native code, perhaps). Marko Patches are always welcome :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Puzzling PDF
On Sun, 16 Feb 2014 10:33:39 -0500, Roy Smith wrote: In article mailman.7056.1392559276.18130.python-l...@python.org, F.R. anthra.nor...@bluewin.ch wrote: Hi all, Struggling to parse bank statements unavailable in sensible data-transfer formats, I use pdftotext, which solves part of the problem. The other day I encountered a strange thing, when one single figure out of many erroneously converted into letters. Adobe Reader displays the figure 50'000 correctly, but pdftotext makes it into SO'OOO (The letters S as in Susan and O as in Otto). One would expect such a mistake from an OCR. However, the statement is not a scan, but is made up of text. Because malfunctions like this put a damper on the hope to ever have a reliable reader that doesn't require time-consuming manual verification, I played around a bit and ended up even more confused: When I lift the figure off the Adobe display (mark, copy) and paste it into a Python IDLE window, it is again letters (ascii 83 and 79), when on the Adobe display it shows correctly as digits. How can that be? Frederic Maybe it's an intentional effort to keep people from screen-scraping data out of the PDFs (or perhaps trace when they do). Is it possible the document includes a font where those codepoints are drawn exactly the same as the digits they resemble? This seems to be the most likely explanation to me although I would like to know why. Assuming these are your bank statements I would change bank Mine are available in a variety of formats (QIF CSV) so that they can be used in my own accounting programs if i desire. I see no reason why the bank would want to prevent me accessing this data -- Without life, Biology itself would be impossible. -- https://mail.python.org/mailman/listinfo/python-list
Re: Explanation of list reference
On Sat, 15 Feb 2014 10:44:39 +0100, Christian Gollwitzer wrote: Am 15.02.14 01:57, schrieb Chris Angelico: Can you give an example of an ambiguous case? Fundamentally, the 'is' operator tells you whether its two operands are exactly the same object, nothing more and nothing less, so I assume your ambiguous cases are ones where it's possible for two things to be either the same object or two indistinguishable ones. What about the thing I posted down in this thread? import numpy as np a=np.array([1, 2, 3, 4]) b=a[:] id(a) 140267900969344 id(b) 140267901045920 So, a and b are different things, right? b[1]=37 b array([ 1, 37, 3, 4]) a array([ 1, 37, 3, 4]) Still they are connected. I can imagin that id() is just a debugging tool for extensions. What useful applications does it have outside of this? Christian try id(a[0]) and id(b[0]) the two tupples are different but they both contain the same list -- If God wanted us to be brave, why did he give us legs? -- Marvin Kitman -- https://mail.python.org/mailman/listinfo/python-list
Re: random.sample with large weighted sample-sets?
On 2/16/2014 9:22 AM, Tim Chase wrote: On 2014-02-16 04:12, Terry Reedy wrote: On 2/15/2014 11:41 PM, Tim Chase wrote: data = ( (apple, 20), (orange, 50), (grape, 30), ) If you actually start with date in this form, write the few lines needed to produce the form below. import bisect import random data = [ (0, 'apple'), (20, 'orange'), (70, 'grape'), ] for i in range(10): r = random.randrange(0, 100) i = bisect.bisect(data, (r, 'z')) - 1 print(data[i][1]) Trying to read what may be implicit assumptions in your code: 0) The frequencies are relative, not absolute, and the selection is with replacement (== selection without replacement from an 'infinite' population) 1) your code calculates 100 as sum(item[0] for item in data) yes 2) the data has to be sorted for bisect to work cumulative sums are automatically sorted. 3) you meant to write (10, 'apple') rather than 0. No (as Ned explained). There are 20 integers in [0, 20), so 20 chances out of 100 to select an apple. 4) that zz is some arbitrary value that should come after any string that could appear in the data; Right. Use \U000F if not using ascii only. perhaps using some custom InfinityString class where everything compared to it is always less than it. Why bother when a good-enough 'top' string is available? Up to you. The issue can be avoided by transposing the n x 2 array into a 2 x n array with separate subarrays of cumulative sums and objects. Do the bisect search in the subarray of cusums and use the returned index to retrieve the object from the object array. Some long-running testing on this code seems to show that if two items have the same probability, bisect only appears to find the last one. Tested with data = [ (10, apple), (20, banana), # I never get any bananas, even after thousands of iterations because 20 - 20 == 0 (20, grape), (50, orange), ] -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: random.sample with large weighted sample-sets? [SOLVED]
On 2014-02-16 14:47, Terry Reedy wrote: 2) the data has to be sorted for bisect to work cumulative sums are automatically sorted. Ah, that they were *cumulative* was the key that I missed in my understanding. It makes sense now and works like a charm. Thanks to all who offered a hand in this thread. -tkc -- https://mail.python.org/mailman/listinfo/python-list
Re: Puzzling PDF
On 02/16/2014 05:29 PM, Emile van Sebille wrote: You On 2/16/2014 6:00 AM, F.R. wrote: Hi all, Struggling to parse bank statements unavailable in sensible data-transfer formats, I use pdftotext, which solves part of the problem. The other day I encountered a strange thing, when one single figure out of many erroneously converted into letters. Adobe Reader displays the figure 50'000 correctly, but pdftotext makes it into SO'OOO (The letters S as in Susan and O as in Otto). One would expect such a mistake from an OCR. However, the statement is not a scan, but is made up of text. Because malfunctions like this put a damper on the hope to ever have a reliable reader that doesn't require time-consuming manual verification, I played around a bit and ended up even more confused: When I lift the figure off the Adobe display (mark, copy) and paste it into a Python IDLE window, it is again letters (ascii 83 and 79), when on the Adobe display it shows correctly as digits. How can that be? I've also gotten inconsistent results using various pdf to text converters[1], but getting an explanation for pdf2totext's failings here isn't likely to happen. I'd first try google doc's on-line conversion tool to see if you get better results. If you're lucky it'll do the job and you'll have confirmation that better tools exist. Otherwise, I'd look for an alternate way of getting the bank info than working from the pdf statement. At one site I've scripted firefox to access the bank's web based inquiry to retrieve the new activity overnight and use that to complete a daily bank reconciliation. HTH, Emile [1] I wrote my own once to get data out of a particularly gnarly EDI specification pdf. Emile, thanks for your response. Thanks to Roy Smith and Alister, too. pdftotext has been working just fine. So much so that this freak incident is all the more puzzling. It smacks of an OCR error, but where does OCR come in, I wonder. I certainly suspected that the font I was looking at had fives and zeroes identical to esses and ohs, respectively, but the suspicion didn't hold up to scrutiny. I attach a little screen shot: At the top, the way it looks on the statement. Next, two words marked with the mouse. (One single marking, doesn't color the space.) Ctl-c puts both words to the clip board. Ctl-v drops them into the python IDLE window between the quotation marks. Lo and behold: they're clearly different! A little bit of code around displays the ascii numbers. Isn't that interesting? Frederic No matter. You're both right. There are alternatives. The best would be to get the data in a CSV format. Alas, I am so lightweight a client that banks don't even bother to find out what I am talking about. I know how to access web pages programmatically, but haven't gotten around to dealing with password-protected log-ins and to sending such data as one writes into templates interactively. Frederic attachment: pdf-weirdness.gif-- https://mail.python.org/mailman/listinfo/python-list
Re: Explanation of list reference
Steven D'Aprano wrote: And indeed numpy arrays do share state. Why? No idea. Somebody thought that it was a good idea. (Not me though...) Probably because they're often large and people don't want to incur the overhead of copying them any more than necessary. So slices are defined to return views rather than independent objects. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Explanation of list reference
Chris Angelico wrote: Because everything in Python is an object, and objects always are handled by their references. beginner_thought So, we have objects... and we have references to objects... but everything is an object... so does that mean references are objects too? /beginner_thought This is the kind of trouble you get into when you make a statement of the form everything is an X[1]. When we say everything is an object, we don't literally mean everything, only... well, those things that *are* objects. Which doesn't really help the beginner much. [1] Mathematicians tried this. Everything is a set! Yeah, right... -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Explanation of list reference
On Mon, Feb 17, 2014 at 9:54 AM, Gregory Ewing greg.ew...@canterbury.ac.nz wrote: Chris Angelico wrote: Because everything in Python is an object, and objects always are handled by their references. beginner_thought So, we have objects... and we have references to objects... but everything is an object... so does that mean references are objects too? /beginner_thought References aren't themselves objects. Names, attributes, etc, etc, etc, all refer to objects. Is it clearer to use the verb refer rather than the noun reference? ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Explanation of list reference
Gregory Ewing greg.ew...@canterbury.ac.nz writes: Chris Angelico wrote: Because everything in Python is an object, and objects always are handled by their references. beginner_thought So, we have objects... and we have references to objects... but everything is an object... so does that mean references are objects too? /beginner_thought My response: No, because references are not things :-) I've never known a programming beginner to express such a question. Have you? Were they beginners at programming, or experienced programmers who were coming to Python with the data models of other languages already in their head? -- \ “Computer perspective on Moore's Law: Human effort becomes | `\ twice as expensive roughly every two years.” —anonymous | _o__) | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list
Re: Explanation of list reference
In article mailman.7074.1392591962.18130.python-l...@python.org, Ben Finney ben+pyt...@benfinney.id.au wrote: Gregory Ewing greg.ew...@canterbury.ac.nz writes: Chris Angelico wrote: Because everything in Python is an object, and objects always are handled by their references. beginner_thought So, we have objects... and we have references to objects... but everything is an object... so does that mean references are objects too? /beginner_thought My response: No, because references are not things :-) I've never known a programming beginner to express such a question. Have you? You make light of Gregory's point, but he's right. That's exactly the kind of thing a beginner would get confused about. -- https://mail.python.org/mailman/listinfo/python-list
Re: Explanation of list reference
In article mailman.7073.1392591754.18130.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: On Mon, Feb 17, 2014 at 9:54 AM, Gregory Ewing greg.ew...@canterbury.ac.nz wrote: Chris Angelico wrote: Because everything in Python is an object, and objects always are handled by their references. beginner_thought So, we have objects... and we have references to objects... but everything is an object... so does that mean references are objects too? /beginner_thought References aren't themselves objects. Names, attributes, etc, etc, etc, all refer to objects. Is it clearer to use the verb refer rather than the noun reference? ChrisA I know functions are objects, but what about statements? Is the body of a for loop an object? It is in some languages. -- https://mail.python.org/mailman/listinfo/python-list
Re: Explanation of list reference
Roy Smith r...@panix.com writes: In article mailman.7074.1392591962.18130.python-l...@python.org, Ben Finney ben+pyt...@benfinney.id.au wrote: Gregory Ewing greg.ew...@canterbury.ac.nz writes: beginner_thought So, we have objects... and we have references to objects... but everything is an object... so does that mean references are objects too? /beginner_thought My response: No, because references are not things :-) I've never known a programming beginner to express such a question. Have you? You make light of Gregory's point, but he's right. That's exactly the kind of thing a beginner would get confused about. That's exactly what I'm asking: What beginners actually do get confused about this? What category of beginner are they, and how di different categories of beginner approach this differently? In other words, rather than asserting based on anecdotes, what *actually* happens? Let's examine what leads them to this confusion, as a starting point for what can be done. -- \“Odious ideas are not entitled to hide from criticism behind | `\ the human shield of their believers' feelings.” —Richard | _o__) Stallman | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list
Re: Explanation of list reference
On Mon, Feb 17, 2014 at 10:46 AM, Roy Smith r...@panix.com wrote: References aren't themselves objects. Names, attributes, etc, etc, etc, all refer to objects. Is it clearer to use the verb refer rather than the noun reference? ChrisA I know functions are objects, but what about statements? Is the body of a for loop an object? It is in some languages. And *that* is an extremely fair question. The best explanation I can come up with is somewhat circular: If it can be named in the code, it's an object. What that really means is that every object is first-class (contrast, for instance, C's arrays and functions), but it doesn't answer the actual question of what's an object and what's not. But my advice would be to try things in the interactive interpreter. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: How to answer questions from newbies
On Sunday, February 16, 2014 9:44:00 PM UTC+5:30, Roy Smith wrote: Moi? See thats the problem with re's -- just 3 letters and completely incomprehensible! It even resembles our resident unicode-troll Oui? -- https://mail.python.org/mailman/listinfo/python-list
Re: Explanation of list reference
On 2/16/14 5:54 PM, Gregory Ewing wrote: Chris Angelico wrote: Because everything in Python is an object, and objects always are handled by their references. beginner_thought So, we have objects... and we have references to objects... but everything is an object... so does that mean references are objects too? /beginner_thought This is the kind of trouble you get into when you make a statement of the form everything is an X[1]. When we say everything is an object, we don't literally mean everything, only... well, those things that *are* objects. Which doesn't really help the beginner much. [1] Mathematicians tried this. Everything is a set! Yeah, right... The correct statement is all values are objects, or all data is objects. When people mistakenly say everything is an object, they are implicitly only thinking about data. That said, all data is objects is really mostly useful in contrast to other languages where some data is objects and some is not. I think Ben Finney's point from nearby in this thread is spot on: there's a huge difference between a beginning programmer and an experienced programmer new to Python. The latter category is sometimes the harder to teach, because you have to undo the things they learned about their earlier language X, but which they mistakenly believe to be true about all programming languages. -- Ned Batchelder, http://nedbatchelder.com -- https://mail.python.org/mailman/listinfo/python-list
Re: How to answer questions from newbies
Rustom Mody rustompm...@gmail.com writes: On Sunday, February 16, 2014 9:44:00 PM UTC+5:30, Roy Smith wrote: Moi? See thats the problem with re's -- just 3 letters and completely incomprehensible! Actually, that's a regexp pattern that matches two *or* three letters. -- \ “If nature has made any one thing less susceptible than all | `\others of exclusive property, it is the action of the thinking | _o__) power called an idea” —Thomas Jefferson | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list
Re: Explanation of list reference
On Mon, Feb 17, 2014 at 12:43 PM, Ned Batchelder n...@nedbatchelder.com wrote: The correct statement is all values are objects, or all data is objects. When people mistakenly say everything is an object, they are implicitly only thinking about data. That said, all data is objects is really mostly useful in contrast to other languages where some data is objects and some is not. Part of the trouble is that some code is (represented by) objects. A function is an object, ergo it's data; a module is an object (though that's different); a class is an object; but no other block of code is. You can't give a name to a while loop, then pick it up and use it somewhere else. x = while input(Guess my number: )!=42: print(Wrong number, try again.) So a while loop isn't data. But wrap it in a function and suddenly it is: def x(): while input(Guess my number: )!=42: print(Wrong number, try again.) y = x func(x) etc So when does code become data? When it's represented by an object. What's an object and what's not? Data is objects, non-data is not. And we're back to being circular again. (Does this mean we're having a circular discussion about circular definitions?) ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: How to answer questions from newbies
On Mon, Feb 17, 2014 at 12:46 PM, Ben Finney ben+pyt...@benfinney.id.au wrote: Rustom Mody rustompm...@gmail.com writes: On Sunday, February 16, 2014 9:44:00 PM UTC+5:30, Roy Smith wrote: Moi? See thats the problem with re's -- just 3 letters and completely incomprehensible! Actually, that's a regexp pattern that matches two *or* three letters. It's worse if you emphasize it. Did you say *re*? But let's not be greedy, here. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Explanation of list reference
In article mailman.7079.1392602374.18130.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: On Mon, Feb 17, 2014 at 12:43 PM, Ned Batchelder n...@nedbatchelder.com wrote: The correct statement is all values are objects, or all data is objects. When people mistakenly say everything is an object, they are implicitly only thinking about data. That said, all data is objects is really mostly useful in contrast to other languages where some data is objects and some is not. Part of the trouble is that some code is (represented by) objects. A function is an object, ergo it's data; a module is an object (though that's different); a class is an object; but no other block of code is. Lambda? So when does code become data? When it's represented by an object. OK, now take somebody who knows lisp and try to explain to him or her why Python's eval() doesn't mean data is code. Yeah, I know that's pushing things a bit, but I'm trying to point out that people come into things with pre-conceived notions that are hard to shake (the psychology of learning people would call this the Law of Primacy). -- https://mail.python.org/mailman/listinfo/python-list
Re: Possibly better stringobject allocator
On Saturday, February 8, 1997 12:00:00 AM UTC-8, Guido van Rossum wrote: I installed modified versions of stringobject.c and stropmodule.c on our web server. They are accessible via http://www.automatrix.com/~skip/python/ Cool. I read your description and am very pleased with your approach. Did you benchmark it with pystone yet? (I'm still waiting for a better benchmark, but nobody has given me one yet... ;-) Warning: This is just a first attempt. I've done some testing, but not a bunch. Use this on an experimental basis only. The code isn't yet properly packaged, and there are some definite warts on it. Feedback is welcome. I immediately went to resizestring (to check that you'd taken care of it properly -- you have) and noticed that there's one easy optimization there: when the new and old sizes fall in the same bucket, you don't need to do anything except change the ob_size field. One thing I haven't yet figured out is this: Given an arbitrary number, n, return the power of two that is equal to or greater than n *without writing a loop*. I can clearly do something like: for (i = 1; i n; i = 1); Can it be done using a single bit-twiddling expression though? For numbers 256 you can do it with a single table lookup, if you can spare 256 bytes for the table. For larger numbers you can quickly find the highest byte in the number that's non-zero and use that to index the table and add 8* the byte number (if you count from the right end ;_) Below is the code for this idea. #include stdio.h int log[256]; int next_power_of_two(int no) { int t, tt, r; if(tt = no 16) { r = (t = tt 8)?24+log[tt]:16+log[t]; } else { r = (t = no 8)?8+log[t]:log[no]; } return r; } void make_table() { int i; log[0] = 0; log[1] = 1; for(i=2;i256;i++) { log[i] = 1 + log[i/2]; } } int main() { int no = 512; make_table(); printf (%d\n, next_power_of_two(no)); } --Guido van Rossum (home page: http://www.python.org/~guido/) -- https://mail.python.org/mailman/listinfo/python-list
Re: Explanation of list reference
Roy Smith r...@panix.com writes: Chris Angelico ros...@gmail.com wrote: Part of the trouble is that some code is (represented by) objects. A function is an object, ergo it's data; a module is an object (though that's different); a class is an object; but no other block of code is. Lambda? The ‘lambda’ syntax creates a function. It doesn't create “a lambda”; there's no distinction between functions that were created with a ‘def’ statement versus a ‘lambda’ expression. -- \ “Generally speaking, the errors in religion are dangerous; | `\those in philosophy only ridiculous.” —David Hume, _A Treatise | _o__) of Human Nature_, 1739 | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list
Re: Explanation of list reference
On Monday, February 17, 2014 8:58:23 AM UTC+5:30, Roy Smith wrote: Chris Angelico wrote: The correct statement is all values are objects, or all data is objects. When people mistakenly say everything is an object, they are implicitly only thinking about data. That said, all data is objects is really mostly useful in contrast to other languages where some data is objects and some is not. Part of the trouble is that some code is (represented by) objects. A function is an object, ergo it's data; a module is an object (though that's different); a class is an object; but no other block of code is. Lambda? So when does code become data? When it's represented by an object. OK, now take somebody who knows lisp and try to explain to him or her why Python's eval() doesn't mean data is code. Yeah, I know that's pushing things a bit, but I'm trying to point out that people come into things with pre-conceived notions that are hard to shake (the psychology of learning people would call this the Law of Primacy). More true than you (probably) know. No Ive not seen a newcomer to python who is an old hand at lisp* What Ive seen is: 25 years ago a 'newcomer' -- like all python objects are objects -- was a newcomer. One of the things I learnt early was that kids were terrified of a beastie that has two modes -- one in which it beeps and the other in which it corrupts the file -- also called 'vi.' Add to that C and pointers and all that and it was just too much. So my first assignment was not programming but just to type a poem. Nowadays the 'newcomers' come with half a dozen computers -- including the phones in their pockets. They know all sorts of technologies that I dont -- Whats a raspberry-pi or an xbox? I frankly dont know more than the names All of them seem to use their phones more savvily than I do! So I cannot even effectively evaluate what percentage of their knowledge is ok, what confused and what balderdash. No -- a clean slate is not a realistic luxury in 2014. * with the exception of yours truly 12 years ago -- https://mail.python.org/mailman/listinfo/python-list
Re: Explanation of list reference
On Sun, 16 Feb 2014 20:01:46 +0200, Marko Rauhamaa wrote: As far as x is None is concerned, a key piece of information is presented on URL: http://docs.python.org/3.2/library/constants.html: None The sole value of the type NoneType. Sole, adj. being the only one; single and isolated from others, e.g. the sole heir, the sole example. In plain English, None is the sole (only, single) instance of its type. In computer science jargon, None is a singleton. Thus, there might still be a nagging concern that a second NoneType object x such that x == None and x is not None could crop up (from native code, perhaps). If that were possible, then None would not be the sole instance of its type. Since None is documented as being a singleton, that would be a bad bug. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: Explanation of list reference
On Mon, 17 Feb 2014 11:40:57 +1300, Gregory Ewing wrote: Steven D'Aprano wrote: And indeed numpy arrays do share state. Why? No idea. Somebody thought that it was a good idea. (Not me though...) Probably because they're often large and people don't want to incur the overhead of copying them any more than necessary. So slices are defined to return views rather than independent objects. I don't have a problem with slices returning views. But they should claim to be views, not claim to be arrays: py from numpy import array py a = array([1, 2, 3, 4]) py b = a[:] py type(a) is type(b) True py b[1] = 99 py a array([ 1, 99, 3, 4]) You can do this to distinguish the two cases: py a.base py b.base is a True but I think a dedicated array_view type would have be better. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Python version problem for rpm
Hi all, I have two version of python 2.4 and 2.7. By default python version is 2.4 . I want to install need to install some rpm which needs python 2.7 interpreter. how can I enable 2.7 interpreter for only those packages which are requiring python 2.7, I don't want to change my default python version(2.4). -- ANJU TIWARI... -- https://mail.python.org/mailman/listinfo/python-list
Re: Explanation of list reference
On Mon, 17 Feb 2014 11:54:45 +1300, Gregory Ewing wrote: Chris Angelico wrote: Because everything in Python is an object, and objects always are handled by their references. beginner_thought So, we have objects... and we have references to objects... but everything is an object... so does that mean references are objects too? /beginner_thought Every *thing* is an object. References aren't *things*. An analogy: there is no thing Greg Ewing which is independent of you, there is you, the thing with an independent existence, and then there is the reference (or name), Greg Ewing, a label for you. But perhaps it is better to say that all *values* are objects. This is the kind of trouble you get into when you make a statement of the form everything is an X[1]. When we say everything is an object, we don't literally mean everything, only... well, those things that *are* objects. Which doesn't really help the beginner much. I don't believe that in Python there are any *things* (values) which aren't objects. Even classes and exceptions are values. That's not the case in all languages. In Java, you have objects, and you have unboxed (native) types, and you have classes which aren't values at all. (Or at least, not first-class values.) So before you ask: for-loops aren't things (values). Neither are while- loops, try...except blocks, pass statements, del statements, etc. Nor are names and other references -- I believe that there is a practice in certain areas of computer science to call them l-values, which despite the name are not values at all -- at least not in Python. Apart from binding and unbinding: ref = something() del ref which are somewhat special, you can't perform computations on *references*, only on the things (values) which references refer to. Contrast this to a hypothetical language which allowed you do perform computations on references, say using a special ! operator: # given x = 23 XY = 42 # then print (!x+Y) would print 42. The expression !x+Y operates on the reference itself, and then print operates on the value referred to by that new reference. [1] Mathematicians tried this. Everything is a set! Yeah, right... No, that's okay. You only get into trouble when you have self-referential sets, like the set of all sets that don't contain themselves. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: Explanation of list reference
On Sun, 16 Feb 2014 18:43:15 -0500, Roy Smith wrote: In article mailman.7074.1392591962.18130.python-l...@python.org, Ben Finney ben+pyt...@benfinney.id.au wrote: Gregory Ewing greg.ew...@canterbury.ac.nz writes: Chris Angelico wrote: Because everything in Python is an object, and objects always are handled by their references. beginner_thought So, we have objects... and we have references to objects... but everything is an object... so does that mean references are objects too? /beginner_thought My response: No, because references are not things :-) I've never known a programming beginner to express such a question. Have you? You make light of Gregory's point, but he's right. That's exactly the kind of thing a beginner would get confused about. I take it that you haven't spent much time around beginners? Perhaps you should spend some time on the tutor mailing list. If you do, you will see very few abstract or philosophical questions such as whether references are themselves things or what identity means. But you will find plenty of questions about: - Will you do my homework for me? - What's this syntax error mean? (very rarely with the syntax error actually shown) - confusion about the fundamentals of sequential algorithms, e.g. asking why this loop always prints the same value forever: var = random.randint(1, 10) while var != 10: print(var) and similar sorts of *concrete* problems. Just about the only abstract question that I've seen from beginners is the question What's object oriented programming? In my experience, people don't start asking abstract questions until they've been programming for a few years. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
select(sock) indicates not-ready, but sock.recv does not block
Hello, I have a problem with using select. I can reliably reproduce a situation where select.select((sock.fileno(),), (), (), 0) returns ((),(),()) (i.e., no data ready for reading), but an immediately following sock.recv() returns data without blocking. I am pretty sure that this is not a race condition. The behavor is 100% reproducible, the program is single threaded, and even waiting for 10 seconds before the select() call does not change the result. I'm running Python 3.3.3 under Linux 3.12. Has anyone an idea what might be going wrong here? Thanks, -Nikolaus -- Encrypted emails preferred. PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C »Time flies like an arrow, fruit flies like a Banana.« -- https://mail.python.org/mailman/listinfo/python-list
Re: Explanation of list reference
On Mon, Feb 17, 2014 at 5:21 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: So before you ask: for-loops aren't things (values). Neither are while- loops, try...except blocks, pass statements, del statements, etc. Nor are names and other references -- I believe that there is a practice in certain areas of computer science to call them l-values, which despite the name are not values at all -- at least not in Python. Usually an l-value is something that can go on the left side of assignment, and an r-value is something that can go on the right side of assignment. (In most languages, every l-value is also an r-value, by definition.) In C, for instance, any simple variable is an l-value, except for those that are constants (you can't assign to an array). A dereferenced pointer is also an l-value, as is a structure element reference. An expression usually isn't (unless it results in a dereferenced pointer). C++ adds references. You can always assign to those (the assignment happens to the referred-to thing). Python says that these things can be assigned to: names, attributes (with dot), and items (with square brackets); I think that's it. Those are Python's l-values. Anything that evaluates to an object reference is an r-value, with the possible exception of function-local names that haven't been assigned to (does it count as not an r-value if trying to read it raises an exception?). Python's statements aren't values at all, and can't be referred to. (Though some of them, like class and def, do result in values or name bindings. But you can't refer to the def statement, only to the function object that it creates.) ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: select(sock) indicates not-ready, but sock.recv does not block
On Mon, Feb 17, 2014 at 5:35 PM, Nikolaus Rath nikol...@rath.org wrote: Hello, I have a problem with using select. I can reliably reproduce a situation ... Can you reproduce it with a reasonably short amount of code? If so, please post it. I'm running Python 3.3.3 under Linux 3.12. Do you mean Linux kernel 3.12 (in which case, which distro?), or is this the version number of a distribution (and if so, which?)? ChrisA -- https://mail.python.org/mailman/listinfo/python-list
How to use logging
Hi folks, i'm new to python i understood the logging mechanism but unable to understand how these are applied in real time examples can any body help me out -- https://mail.python.org/mailman/listinfo/python-list
[issue20621] Issue with zipimport in 3.3.4 and 3.4.0rc1
Georg Brandl added the comment: Paul, could you confirm that backing out the 2807a5f011e4 changeset on the 3.3 branch fixes the problem? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20621 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20621] Issue with zipimport in 3.3.4 and 3.4.0rc1
Paul Moore added the comment: Georg - see http://bugs.python.org/issue20621#msg211209 for what I did. That shows backing out did *not* fix the issue. But I did backout on the default branch, and my backout may not have worked as I explained. I just tried to do hg backout on the 3.3 branch and I got merge errors that I don't know how to fix. I'm going to try hg checkout -r 88337 (that's the parent of the changeset you quoted) as am alternative approach. It'll take some time to set up the build tools I need. But if there's a better way of backing out as you want me to, let me know and I'll try that. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20621 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20621] Issue with zipimport in 3.3.4 and 3.4.0rc1
Georg Brandl added the comment: Yeah, just tried the backout, it doesn't apply cleanly anymore -- Modules/zipimport.c has apparently changed some more afterwards. I think using the parent changeset is the best thing to do at the moment, until Greg comes up with a patch. -- assignee: - gregory.p.smith ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20621 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6143] IDLE - an extension to clear the shell window
Tal Einat added the comment: FYI, with some help from Roger answering various questions, I've cooked up a version of ClearWindow supporting the current version of IDLE. This includes integration with the Squeezer extension. I haven't tested it, however, nor written appropriate tests. I hope to do so in the coming days, and when I have I'll post a patch. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6143 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20638] KeyError building the Python html doc with sphinx
New submission from Xavier de Gaye: Occurs on the tip of the Python default branch on ArchLinux when running 'make html PYTHON=python2' from Doc/. Traceback attached. -- assignee: docs@python components: Documentation files: sphinx-err-DH3qAl.log messages: 211311 nosy: docs@python, georg.brandl, xdegaye priority: normal severity: normal status: open title: KeyError building the Python html doc with sphinx type: behavior versions: Python 3.4 Added file: http://bugs.python.org/file34098/sphinx-err-DH3qAl.log ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20638 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20638] KeyError building the Python html doc with sphinx
Georg Brandl added the comment: Which revision is your tip? In the latest revision, the documentation should refuse being built with 1.0.7. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20638 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20621] Issue with zipimport in 3.3.4 and 3.4.0rc1
Paul Moore added the comment: OK, confirmed. Backing out to just before revision 2807a5f011e4 the problem has disappeared. Re-applying just 2807a5f011e4 causes the issue to appear again. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20621 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20570] Bundle pip 1.5.3 in Python 3.4rc2
Jeroen Ruigrok van der Werven added the comment: Just to confirm that I, indeed, did not run into problems any more with RC1 trying to upgrade setuptools. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20570 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20637] Support key-sharing dictionaries in subclasses
Antoine Pitrou added the comment: Wow, really? Thanks for finding this! -- nosy: +Mark.Shannon, benjamin.peterson, pitrou stage: - patch review ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20637 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20639] pathlib.PurePath.with_suffix() does not allow removing the suffix
July Tikhonov added the comment: Proposed patch attached. -- Added file: http://bugs.python.org/file34100/pathlib-with_suffix.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20639 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20639] pathlib.PurePath.with_suffix() does not allow removing the suffix
New submission from July Tikhonov: The changeset ef2b2ddd27c8 restricted the argument of Path.with_suffix() too much, and caused some strange behavior. Case 1: removing suffix completely is disallowed now. The following code worked before the fix: pathlib.PurePath('a', 'b.c').with_suffix('') PurePosixPath('a/b') but now fails with ValueError: pathlib.PurePath('a', 'b.c').with_suffix('') Traceback (most recent call last): File stdin, line 1, in module File /home/july/source/python/Lib/pathlib.py, line 760, in with_suffix raise ValueError(Invalid suffix %r % (suffix)) ValueError: Invalid suffix '' It was the only one obvious way of removing the suffix, and I think it should remain so. (BTW: There is a XXX note in the code questioning if Path.with_suffix(None) should remove the suffix.) Case 2: while the output is now always a correct Path, the suffix can still contain separator. The following code produced incorrect path before the fix: pathlib.PurePath('a', 'b.c').with_suffix('./.s/.') PurePosixPath('a/b./.s/.') _.parts ('a', 'b./.s/.') Now, the produced path is correct, but the code itself is still allowed: pathlib.PurePath('a', 'b.c').with_suffix('./.s/.') PurePosixPath('a/b.s') while I would expect it to fail with ValueError. Attached: proposed test patch. -- components: Library (Lib) files: pathlib-with_suffix-test.diff keywords: patch messages: 211316 nosy: july, pitrou priority: normal severity: normal status: open title: pathlib.PurePath.with_suffix() does not allow removing the suffix type: behavior versions: Python 3.4, Python 3.5 Added file: http://bugs.python.org/file34099/pathlib-with_suffix-test.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20639 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20570] Bundle pip 1.5.3 in Python 3.4rc2
Nick Coghlan added the comment: Donald, since you haven't been through an RC period before - just a reminder that Larry is going to need time to cherry pick the update into the release clone before rc2 on the 23rd. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20570 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue16728] Missing cross-reference in sequence glossary entry
Changes by A.M. Kuchling a...@amk.ca: -- stage: needs patch - commit review ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16728 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20640] Adds idle test for configHelpSourceEdit
New submission from Saimadhav Heblikar: This patch adds tests for Idle's configHelpSourceEdit.py module. There is however, a minor issue related to this patch,which is an attribute error occurring due to lines 108,115,128,139 on http://hg.python.org/cpython/file/eef7899ea7ab/Lib/idlelib/configHelpSourceEdit.py The error occurring is an attribute error,wherein 'entryMenu' and 'entryPath' attributes are not found. Clearly,the two attributes are created in CreateWidgets() defined on lines 52 and 57. Other attributes defined in the same CreateWidgets() like menu and path dont raise any attribute error. I have asked the same in irc,where i was advised to post this patch with the issue mentioned. Bear with me,i have tried a lot to overcome this issue,but no avail.Please let me know how to fix this. The test other than this issue,should integrate well. -- components: IDLE, Tests files: idle-test-config-help-source.patch keywords: patch messages: 211319 nosy: sahutd, serhiy.storchaka, taleinat, terry.reedy priority: normal severity: normal status: open title: Adds idle test for configHelpSourceEdit versions: Python 3.4 Added file: http://bugs.python.org/file34101/idle-test-config-help-source.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20640 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20637] Support key-sharing dictionaries in subclasses
Mark Shannon added the comment: Well spotted. I don't think that the line COPYVAL(tp_dictoffset); should be removed. inherit_special() is called from PyType_Ready which is used to initialise static TypeObjects. So builtin class B which doesn't set tp_dictoffset, but has builtin class A as its base, will not get its tp_dictoffset initialized from A. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20637 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13663] pootle.python.org is outdated.
Benjamin Peterson added the comment: pootle.python.org has been disabled. -- nosy: +benjamin.peterson resolution: - wont fix status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13663 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20640] Adds idle test for configHelpSourceEdit
Changes by Todd Rovito rovit...@rovitotv.org: -- nosy: +Todd.Rovito ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20640 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12211] Better document math.copysign behavior.
Roundup Robot added the comment: New changeset 3ad7725b5013 by Andrew Kuchling in branch '3.3': #12211: clarify math.copysign() documentation and docstring http://hg.python.org/cpython/rev/3ad7725b5013 -- nosy: +python-dev ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12211 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9009] Improve quality of Python/dtoa.c
Changes by Mark Dickinson dicki...@gmail.com: -- resolution: - wont fix status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9009 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12211] Better document math.copysign behavior.
A.M. Kuchling added the comment: Applied. I added two sentences describing the NaN behaviour. -- nosy: +akuchling resolution: - fixed stage: patch review - committed/rejected status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12211 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com