Re: Proposed new syntax

2017-08-16 Thread Marco Buttu
if x < 5] [1, 2, 3, 4, 5] -- Marco Buttu INAF-Osservatorio Astronomico di Cagliari Via della Scienza n. 5, 09047 Selargius (CA) Phone: 070 711 80 217 Email: mbu...@oa-cagliari.inaf.it -- https://mail.python.org/mailman/listinfo/python-list

Re: Survey: improving the Python std lib docs

2017-05-16 Thread Marco Buttu
hetic and style than the developer of logging, or email, or re, and so on. True story If we had one person who had the authority to make doc-wide decisions, then we might be able to move towards coherent guidelines for the docs to be more uniform. That could be a solution :-) -- Ma

user+sys time bigger than real time (with threads)

2017-02-02 Thread Marco Buttu
5.043s I can expect this result when I run some processes in parallel on different CPUs, but this code uses threads, so the GIL prevents the two task() functions to be executed in parallel. What am I missing? -- Marco Buttu INAF-Osservatorio Astronomico di Cagliari Via della Scienza n. 5, 09047 Sela

Name resolution and the (wrong?) LEGB rule

2016-12-08 Thread Marco Buttu
namespace, it raises a NameError * enclosing scope (LOAD_DEREF): there is a closure, and Python looks for the name in the enclosing namespace Is that right, or am I missing something? Thanks, Marco [1] http://sebastianraschka.com/Articles/2014_python_scope_and_namespaces.html -- Marco B

file.seek() and file.tell() look inconsistent to me

2016-07-04 Thread Marco Buttu
27;) 2 It seems to me not consistent, and maybe could also be error prone: >>> f.seek(2) 2 >>> f.write('c') 1 >>> f.close() >>> open('myfile').read() ... UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc3... -- Marco Buttu -- https://mail.python.org/mailman/listinfo/python-list

Re: The Real-Time Use of Python in Data Science World!

2016-02-27 Thread Marco Buttu
On 27/02/2016 10:13, Steven D'Aprano wrote: I think it would be more acceptable to me if the sender labelled the subject line as "Advertising". +1 -- Marco Buttu INAF-Osservatorio Astronomico di Cagliari Via della Scienza n. 5, 09047 Selargius (CA) Phone: 070 711 80 217 E

Deprecation warning for async and await

2016-01-23 Thread Marco Buttu
I enabled the deprecation warning in Python 3.5.1 and Python 3.6 dev, but I did not get any warning when assigning to async or await: $ python -Wd -c "import sys; print(sys.version); async = 33" 3.5.1 (default, Jan 21 2016, 19:59:28) [GCC 4.8.4] Is it normal? -- Marco Buttu INAF-Os

Re: Deprecation warnings for the future async and await keywords

2016-01-22 Thread Marco Buttu
On 22/01/2016 16:59, Ian Kelly wrote: On Fri, Jan 22, 2016 at 4:12 AM, Marco Buttu wrote: >I enabled the deprecation warnings in Python 3.5.1 and Python 3.6 dev, and I >noticed that assigning to async or await does not issue any deprecation >warning: > >$ python -Wd -c &qu

Deprecation warnings for the future async and await keywords

2016-01-22 Thread Marco Buttu
-c "import sys; print(sys.version); async = 33" 3.6.0a0 (default:4b434a4770a9, Jan 12 2016, 13:01:29) [GCC 4.8.4] Is it normal? -- Marco Buttu -- https://mail.python.org/mailman/listinfo/python-list

Re: how to determine for using c extension or not ?

2015-08-03 Thread Marco Buttu
es, as mentioned by Skip, we say that the term "buit-in function" is also referred to a function written in C: https://docs.python.org/3/library/types.html#types.BuiltinFunctionType By using the same word (built-in) to indicate either objects written in C or objects who live in the

Re: Classic OOP in Python

2015-06-18 Thread Marco Buttu
are that you will not write a test after fixing the bug, i.e. because you may have other priorities, so you will miss a regression test -- Marco Buttu INAF-Osservatorio Astronomico di Cagliari Via della Scienza n. 5, 09047 Selargius (CA) Phone: 070 711 80 217 Email: mbu...@oa-cagliari.inaf.it --

Re: Everything is an object in python - object class and type class

2015-06-03 Thread Marco Buttu
): ... AttributeError: 'tuple' object has no attribute 'foo' -- Marco Buttu INAF-Osservatorio Astronomico di Cagliari Via della Scienza n. 5, 09047 Selargius (CA) Phone: 070 711 80 217 Email: mbu...@oa-cagliari.inaf.it -- https://mail.python.org/mailman/listinfo/python-list

Re: Everything is an object in python - object class and type class

2015-05-31 Thread Marco Buttu
lies every instance of a class is an instance of object. And classes are instance of a class (thier metaclass), so they are instance of objects too -- Marco Buttu INAF-Osservatorio Astronomico di Cagliari Via della Scienza n. 5, 09047 Selargius (CA) Phone: 070 711 80 217 Email: mbu...@oa-cag

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-26 Thread Marco Buttu
parameters far away from the parameter list itself. Then move it to the first line of the docstring... I like this idea, because nevertheless the type hinting is optional, the mypy syntax affects every Python programmer who has to read other code that will use this syntax, while the do

Re: __bases__ misleading error message

2015-01-26 Thread Marco Buttu
s) and non-types (non-classes) objects, instead of between objects and classes. The problem is in the Python documentation there is also a bit of confusion about this... In the descriptor howto: "The details of invocation depend on whether obj is an object or a class" :/ -- Marco Buttu IN

Re: __bases__ misleading error message

2015-01-25 Thread Marco Buttu
e to give a special meaning to the attribute. Given `obj.attr`, we just have to know what kind of object is `obj`: usually, like in this case, we have to differentiate between classes and non-classes objects. In fact __bases__ is not listed by dir(Sub) because Sub is a class, and the distinction between classes and non-classes objects matters, especially for dir() -- Marco Buttu -- https://mail.python.org/mailman/listinfo/python-list

Re: __bases__ misleading error message

2015-01-24 Thread Marco Buttu
Python documentation there is also a bit of confusion about this... In the descriptor howto: "The details of invocation depend on whether obj is an object or a class" :/ -- Marco Buttu -- https://mail.python.org/mailman/listinfo/python-list

Re: __bases__ misleading error message

2015-01-24 Thread Marco Buttu
(MyClass, Foo) True >>> MyClass.foo 33 But an instance of MyClass is not an instance of Foo, and so MyClass() must not have the attribute foo. In fact: >>> m = MyClass() >>> isinstance(m, Foo) False >>> m.foo Traceback (most recent call last): ...

Re: How to "wow" someone new to Python

2015-01-16 Thread Marco Buttu
on is. What do you do? The batteries included: some useful and simple examples with only core data type objects, built-in functions and standard library -- Marco Buttu INAF-Osservatorio Astronomico di Cagliari Via della Scienza n. 5, 09047 Selargius (CA) Phone: 070 711 80 217 Email: mbu.

Re: Most gratuitous comments

2014-11-25 Thread Marco Buttu
o be taken as example for writing good comments and docstrings: https://hg.python.org/cpython/file/3.4/Lib/statistics.py -- Marco Buttu INAF-Osservatorio Astronomico di Cagliari Via della Scienza n. 5, 09047 Selargius (CA) Phone: 070 711 80 217 Email: mbu...@oa-cagliari.inaf.it -- https://mail.python.org/mailman/listinfo/python-list

Muddleheaded use of the "built-in" term

2014-10-07 Thread Marco Buttu
thing like, for instance, `root` namespace, or using the name "core" (inspect.iscore(), types.CoreFunctionType, ecc.) to indicate "written in C or whatever underlying language"? -- Marco Buttu INAF-Osservatorio Astronomico di Cagliari Via della Scienza n. 5, 09047 Selargius (CA) Phone: 070 711 80 217 Email: mbu...@oa-cagliari.inaf.it -- https://mail.python.org/mailman/listinfo/python-list

Muddleheaded use of the "built-in" term

2014-10-07 Thread Marco Buttu
t live in the builtin namespace :/ By using the same word (built-in) to indicate either objects written in C or objects referenced by the builtin namespace could be a bit muddler for everyone, beginner or not. Is it too late for changing the name of the `builtin` namespace in something like, fo

Re: Clearing globals in CPython

2014-10-02 Thread Marco Buttu
t the current session and restart it, but as a challenge, can we recover from this state? >>> [].__class__.__module__ # It is a string... '__builtin__' So, I do not have any idea about how to get a module without importing something. Thanks for sharing :) -- Marco

Re: how to parse standard algebraic notation

2014-10-01 Thread Marco Buttu
implify("x**3 + x**2 + x + 1") >>> equation x**3 + x**2 + x + 1 >>> diff(equation) 3*x**2 + 2*x + 1 -- Marco Buttu -- https://mail.python.org/mailman/listinfo/python-list

Re: how to parse standard algebraic notation

2014-10-01 Thread Marco Buttu
implify("x**3 + x**2 + x + 1") >>> equation x**3 + x**2 + x + 1 >>> diff(equation) 3*x**2 + 2*x + 1 -- Marco Buttu INAF-Osservatorio Astronomico di Cagliari Via della Scienza n. 5, 09047 Selargius (CA) Phone: 070 711 80 217 Email: mbu...@oa-cagliari.inaf.it -- https://mail.python.org/mailman/listinfo/python-list

Re: Compact way to assign values by slicing list in Python

2014-04-03 Thread Marco Buttu
a','b','c','x','y','z'] v1, _, _, v2, v3, _ = bar I also like the solution with itemgetter: v1, v2, v3 = itemgetter(0, 3, 4)(bar) but I think it is less readable than the previous one -- Marco Buttu -- https://mail.python.org/mailman/listinfo/python-list

Re: 3.4 on Windows ImportError: cannot import name 'IntEnum'

2014-01-05 Thread Marco Buttu
an issue on the bug tracker can another Windows user or two please confirm that this is a genuine problem and not my installation being corrupt or whatever. Hi, it works for me (Windows XP, 32) -- Marco Buttu -- https://mail.python.org/mailman/listinfo/python-list

Re: Behavior of staticmethod in Python 3

2013-11-23 Thread Marco Buttu
10) Traceback (most recent call last): ... AttributeError: Must be a positive number But I cannot use the method as a function: >>> Configuration.positiveCheck(-10) Traceback (most recent call last): ... Configuration instance as first argument (got int instance instead). Furthemore, I cannot use the me

Behavior of staticmethod in Python 3

2013-11-23 Thread Marco Buttu
not skip the staticmethod decorator? -- Marco Buttu -- https://mail.python.org/mailman/listinfo/python-list

Re: python33.lib missing for build_ext in venv environment

2013-10-14 Thread Marco Buttu
local/bin include-system-site-packages = false version = 3.4.0 In this case (default), the site-package directory is not included in the PYTHONPATH. If you want to include it, set: include-system-site-packages = true -- Marco Buttu -- https://mail.python.org/mailman/listinfo/python-list

Re: Metaclass/abc hackery

2013-10-11 Thread Marco Buttu
ame, value) ... super().__setattr__(name, value) ... >>> class Foo(metaclass=MetaFoo): ... a = 33 ... In Namespace.__setitem__(): __module__ __main__ do something with __module__ __main__ In Namespace.__setitem__(): __qualname__ Foo do something with __qualname__ Foo In Namespace.__setitem__(): a 33 do something with a 33 >>> Foo.a = 33 In MetaFoo.__setattr__(): a 33 do something with a 33 -- Marco Buttu -- https://mail.python.org/mailman/listinfo/python-list

Re: Debug (sympy-Function; lambdify)

2013-10-10 Thread Marco Buttu
last command (the lambdify 1) I get a syntax error. I think that is because I m using th1 and th2 as Function of t. Can anyone help me on how to solve this? There is just one error for me: array instead of np.array. Once changed this, it works fine (Python 3.3, SymPy 0.7.3) -- Marco Bu

Re: super in Python 3 and variadic arguments

2013-10-10 Thread Marco Buttu
, that works just fine. The compiler sees that super is accessed within the method and creates the closure necessary to make it work. This does fail, however: f = super class X(Y): def method(self, arg): f().method(arg) Very interesting! Thanks :) -- Marco Buttu -- https://mail

Re: super in Python 3 and variadic arguments

2013-10-10 Thread Marco Buttu
27;t want to make a habit of it. ... [1] Which is not necessarily a bad thing! Thanks a lot for this anecdote :) -- Marco Buttu -- https://mail.python.org/mailman/listinfo/python-list

Re: super in Python 3 and variadic arguments

2013-10-10 Thread Marco Buttu
On 10/10/2013 01:04 PM, Ned Batchelder wrote: On 10/10/13 3:22 AM, Marco Buttu wrote: >>> import inspect >>> class B(A): ... def bfoo(*args): ... frame = inspect.currentframe() ... for obj, value in frame.f_locals.items(): ... pri

Re: super in Python 3 and variadic arguments

2013-10-10 Thread Marco Buttu
for obj, value in frame.f_locals.items(): ... print(obj, value, sep=' --> ') ... # super().afoo(*args[1:]) ... >>> B().bfoo(1, 2, 3) args --> (<__main__.B object at 0x7f28c960a590>, 1, 2, 3) frame --> So, why does not super use it? -- Marco Buttu -- https://mail.python.org/mailman/listinfo/python-list

super in Python 3 and variadic arguments

2013-10-09 Thread Marco Buttu
gt;>> class B(A): ... def bfoo(*args): ... super().afoo(*args[1:]) ... >>> B().bfoo(1, 2, 3) Traceback (most recent call last): File "", line 1, in File "", line 3, in bfoo RuntimeError: super(): no arguments How come? -- Marco Buttu -- https://mail.python.org/mailman/listinfo/python-list

Re: class-private names and the Zen of Python

2013-10-08 Thread Marco Buttu
On 10/09/2013 01:00 AM, Oscar Benjamin wrote: > On Tue, 08 Oct 2013 12:13:48 +0200, Marco Buttu wrote: > > > Another question is: where is the place in which this transformation > > occurs? Is it at the parser level, before the dictionary attribute is > > gave as a

Re: class-private names and the Zen of Python

2013-10-08 Thread Marco Buttu
On 10/08/2013 01:07 PM, Ned Batchelder wrote: On 10/8/13 6:13 AM, Marco Buttu wrote: >>> class Foo: ... _Foo__a = 100 ... __a = 33 ... >>> Foo._Foo__a 33 ... You also get a "problem" if you do this: >>> class Foo: ... a = 100

Re: class-private names and the Zen of Python

2013-10-08 Thread Marco Buttu
On 10/08/2013 12:36 PM, Terry Reedy wrote: On 10/8/2013 6:13 AM, Marco Buttu wrote: In the following case: >>> class Foo: ... _Foo__a = 100 ... __a = 33 ... >>> Foo._Foo__a 33 I think this behavior, for a user who does not know the convention, could be a

class-private names and the Zen of Python

2013-10-08 Thread Marco Buttu
://docs.python.org/3/reference/lexical_analysis.html http://docs.python.org/3/reference/expressions.html#atom-identifiers but it is not clear when this transformation happens. -- Marco Buttu -- https://mail.python.org/mailman/listinfo/python-list

Re: Overriding of the type.__call__() method in a metaclass

2013-10-06 Thread Marco Buttu
On 10/07/2013 04:27 AM, Steven D'Aprano wrote: On Sun, 06 Oct 2013 20:17:33 +0200, Marco Buttu wrote: > > >>> class FooMeta(type): >... def __call__(metacls, name, bases, namespace): >...print("FooMeta.__call__()") ... > From what I undes

Overriding of the type.__call__() method in a metaclass

2013-10-06 Thread Marco Buttu
Hi all, I have a question about class creation and the __call__ method. I have the following metaclass: >>> class FooMeta(type): ... def __call__(metacls, name, bases, namespace): ... print("FooMeta.__call__()") From what I undestood, at the end of the class statement happens some

Re: PEP-442 - Python 3.4 and finalizations (__del__)

2013-09-14 Thread Marco Buttu
Does that answer your question? Yes, thanks a lot Steven, I saw the gc.collect() does not call the __del__() method in Python 3.3, so I think I will look at the documentation of gc in order to understand better. Thanks again, Marco -- Marco Buttu -- https://mail.python.org/mailman/listinfo/python-list

PEP-442 - Python 3.4 and finalizations (__del__)

2013-09-14 Thread Marco Buttu
__init__(self): self.b = A(self) # Reference cycle print('In B.__init__()') def __del__(self): print('Goodbye from B()') b = B() del b Regards, Marco -- Marco Buttu -- https://mail.python.org/mailman/listinfo/python-list

Re: Encapsulation unpythonic?

2013-08-30 Thread Marco Buttu
3 STORE_NAME 0 (a) 6 LOAD_CONST 5 (5) 9 STORE_NAME 0 (a) 12 LOAD_CONST 3 (None) 15 RETURN_VALUE Regards, M. -- Marco Buttu -- http://mail.python.org/mailman/listinfo/python-list

Re: How come StopIteration.__base__ is not BaseException?

2013-08-27 Thread Marco Buttu
On 08/27/2013 08:51 PM, Terry Reedy wrote: BaseException was added just so it would be possible to catch nearly everything but a few exceptions. The first two were KeyboardInterrupt and SystemExit (in 2.5). GeneratorExit was switched in 2.6, but I forget the details of why. Maybe in order to d

Re: How come StopIteration.__base__ is not BaseException?

2013-08-27 Thread Marco Buttu
On 08/27/2013 11:22 AM, Steven D'Aprano wrote: What matters is that when you catch "nearly everything", StopIteration is included in the "nearly everything", but SysExit and KeyboardInterrupt should not be. Consider: try: main() except Exception as e: print('an unexpected error occur

Re: How come StopIteration.__base__ is not BaseException?

2013-08-26 Thread Marco Buttu
On 08/26/2013 10:10 PM, random...@fastmail.us wrote: The reason KeyboardInterrupt and SystemExit inherit from BaseException is because you often want them to escape (allowing the program to quit) from code that would otherwise catch them (by catching Exception). On the contrary, StopIteration is

Re: How come StopIteration.__base__ is not BaseException?

2013-08-26 Thread Marco Buttu
On 08/27/2013 08:17 AM, Marco Buttu wrote: But if I want to catch it specifically (except BaseIteration), Sorry, except StopIteration... -- Marco Buttu -- http://mail.python.org/mailman/listinfo/python-list

How come StopIteration.__base__ is not BaseException?

2013-08-26 Thread Marco Buttu
Since StopIteration is not an error, how come does it inherit directly from Exception and not from BaseException? Thanks in advance, Marco -- Marco -- http://mail.python.org/mailman/listinfo/python-list

Re: str.isnumeric and Cuneiforms

2012-05-18 Thread Marco Buttu
On 05/18/2012 05:42 PM, jmfauth wrote: Non official but really practical: http://www.fileformat.info/info/unicode/index.htm Very well ordered, thanks -- Marco -- http://mail.python.org/mailman/listinfo/python-list

Re: str.isnumeric and Cuneiforms

2012-05-18 Thread Marco Buttu
On 05/17/2012 09:32 PM, Marco wrote: Is it normal the str.isnumeric() returns False for these Cuneiforms? '\U00012456' '\U00012457' '\U00012432' '\U00012433' They are all in the Nl category. Marco It's ok, I found that they don't have a number assigned in the ftp://ftp.unicode.org/Public/U

Re: str.isnumeric and Cuneiforms

2012-05-18 Thread Marco Buttu
On 05/18/2012 11:24 AM, jmfauth wrote: Is it normal the str.isnumeric() returns False for these Cuneiforms? > > '\U00012456' > '\U00012457' > '\U00012432' > '\U00012433' > > They are all in the Nl category. Indeed there are, but Unicode (ver. 5.0.0) does not assign numeric values to these

Re: str.isnumeric and Cuneiforms

2012-05-18 Thread Marco Buttu
On 05/18/2012 02:50 AM, Steven D'Aprano wrote: Is it normal the str.isnumeric() returns False for these Cuneiforms? > > '\U00012456' > '\U00012457' > '\U00012432' > '\U00012433' > > They are all in the Nl category. Are you sure about that? Do you have a reference? I I was just playing