Re: How well do you know Python?

2016-07-04 Thread Chris Angelico
On Tue, Jul 5, 2016 at 4:33 PM, Steven D'Aprano wrote: > What happens in this code snippet? > > L = [1] > t = (L,) > t[0] += 1 > > Explain what value t has, and why. Not sure you have that question right, because it simply gives a TypeError. You can't add an integer to a list. ChrisA

Re: How well do you know Python?

2016-07-04 Thread Steven D'Aprano
On Tuesday 05 July 2016 14:02, Chris Angelico wrote: > After some discussion with a Ruby on Rails programmer about where Ruby > ends and where Rails begins (and it's definitely not where I'd have > expected... Rails does a ton of monkey-patching, including of built-in > types, to provide functiona

Re: py2exe crashes on simple program

2016-07-04 Thread Steven D'Aprano
On Tuesday 05 July 2016 14:06, John Nagle wrote: > I'm trying to create an executable with py2exe. > The program runs fine in interpretive mode. But > when I try to build an executable, py2exe crashes with > an assertion error. See below. [...] > Building shared code archive 'dist\library.zip'.

Re: Namespaces are one honking great idea

2016-07-04 Thread Steven D'Aprano
On Tuesday 05 July 2016 13:47, Chris Angelico wrote: > On Tue, Jul 5, 2016 at 1:35 PM, Steven D'Aprano wrote: >>> If you push your code into a separate .py file, you can reference the >>> original module by importing it. Is that also the normal way to use >>> "outer" functions etc from inside a n

Re: How well do you know Python?

2016-07-04 Thread Steven D'Aprano
On Tuesday 05 July 2016 14:02, Chris Angelico wrote: > After some discussion with a Ruby on Rails programmer about where Ruby > ends and where Rails begins (and it's definitely not where I'd have > expected... Rails does a ton of monkey-patching, including of built-in > types, to provide functiona

Re: Nested class doesn't see class scope

2016-07-04 Thread Steven D'Aprano
On Tuesday 05 July 2016 14:41, Ian Kelly wrote: > Class definitions don't create closures like functions do. When Python > executes a class definition, the metaclass creates a dict, and then > the interpreter execs the class body using that dict as the locals. > The body of class A has one locals

Re: Making Classes Subclassable

2016-07-04 Thread Michael Selik
On Mon, Jul 4, 2016, 4:36 AM Lawrence D’Oliveiro wrote: > On Monday, July 4, 2016 at 7:58:07 PM UTC+12, dieter wrote: > > --> "type(obj)" or "obj.__class__" (there are small differences) > > give you the type/class of "obj". > > When would it not be the same? > Old-style classes. > -- https://

Re: Nested class doesn't see class scope

2016-07-04 Thread Ian Kelly
On Mon, Jul 4, 2016 at 10:41 PM, Ian Kelly wrote: > On Mon, Jul 4, 2016 at 9:20 PM, Steven D'Aprano wrote: >> I got this in Python 3.6: >> >> >> py> class A: >> ... var = 999 >> ... print(var) # succeeds >> ... class B: >> ... x = var >> ... >> 999 >> Traceback (most recent c

Re: Nested class doesn't see class scope

2016-07-04 Thread Ian Kelly
On Mon, Jul 4, 2016 at 9:20 PM, Steven D'Aprano wrote: > I got this in Python 3.6: > > > py> class A: > ... var = 999 > ... print(var) # succeeds > ... class B: > ... x = var > ... > 999 > Traceback (most recent call last): > File "", line 1, in > File "", line 3, in A >

Re: Nested class doesn't see class scope

2016-07-04 Thread Ian Kelly
On Mon, Jul 4, 2016 at 9:42 PM, Paul Rubin wrote: > Steven D'Aprano writes: >> ... class B: >> ... x = var > > x = A.var Nope. A doesn't exist yet at this point. -- https://mail.python.org/mailman/listinfo/python-list

py2exe crashes on simple program

2016-07-04 Thread John Nagle
I'm trying to create an executable with py2exe. The program runs fine in interpretive mode. But when I try to build an executable, py2exe crashes with an assertion error. See below. This is an all-Python program; no binary modules other than ones that come with the Python 3.5.2 distribution.

How well do you know Python?

2016-07-04 Thread Chris Angelico
After some discussion with a Ruby on Rails programmer about where Ruby ends and where Rails begins (and it's definitely not where I'd have expected... Rails does a ton of monkey-patching, including of built-in types, to provide functionality that is strangely absent from the core language), I tried

Re: Namespaces are one honking great idea

2016-07-04 Thread Chris Angelico
On Tue, Jul 5, 2016 at 1:35 PM, Steven D'Aprano wrote: >> If you push your code into a separate .py file, you can reference the >> original module by importing it. Is that also the normal way to use >> "outer" functions etc from inside a namespace? > > Good question! > > With the current implement

Re: Nested class doesn't see class scope

2016-07-04 Thread Paul Rubin
Steven D'Aprano writes: > ... class B: > ... x = var x = A.var -- https://mail.python.org/mailman/listinfo/python-list

Re: Namespaces are one honking great idea

2016-07-04 Thread Steven D'Aprano
On Tue, 5 Jul 2016 12:58 pm, Chris Angelico wrote: > On Tue, Jul 5, 2016 at 12:34 PM, Steven D'Aprano > wrote: >> *** IF *** you are willing to push the code out into its own separate .py >> file, you can use a module and write your code in a more natural form: >> >> >> # module example.py >> var

Re: Nested class doesn't see class scope

2016-07-04 Thread Rustom Mody
On Tuesday, July 5, 2016 at 8:50:57 AM UTC+5:30, Steven D'Aprano wrote: > I got this in Python 3.6: > > > py> class A: > ... var = 999 > ... print(var) # succeeds > ... class B: > ... x = var > ... > 999 > Traceback (most recent call last): > File "", line 1, in > File "

Nested class doesn't see class scope

2016-07-04 Thread Steven D'Aprano
I got this in Python 3.6: py> class A: ... var = 999 ... print(var) # succeeds ... class B: ... x = var ... 999 Traceback (most recent call last): File "", line 1, in File "", line 3, in A File "", line 4, in B NameError: name 'var' is not defined I expected that `va

Re: Namespaces are one honking great idea

2016-07-04 Thread Chris Angelico
On Tue, Jul 5, 2016 at 12:34 PM, Steven D'Aprano wrote: > *** IF *** you are willing to push the code out into its own separate .py > file, you can use a module and write your code in a more natural form: > > > # module example.py > var = 999 > > def spam(arg): > return eggs(arg) + var > > def

Re: Namespaces are one honking great idea

2016-07-04 Thread Steven D'Aprano
On Mon, 4 Jul 2016 09:23 pm, jmp wrote: > On 07/01/2016 04:13 PM, Steven D'Aprano wrote: >> But classes are not like the others: they must be instantiated before >> they can be used, and they are more than just a mere namespace grouping >> related entities. Classes support inheritance. Classes sho

Re: Structure of program development

2016-07-04 Thread Michael Torrie
On 07/04/2016 01:50 PM, BartC wrote: > On 04/07/2016 17:55, Chris Warrick wrote: > >>> A second question of the basic design. If I write a program, can I move it >>> to a computer that is without any Python software, or does that machine >>> have to download the Python software? Does Python prod

Re: Structure of program development

2016-07-04 Thread Chris Angelico
On Tue, Jul 5, 2016 at 9:56 AM, Lawrence D’Oliveiro wrote: > On Tuesday, July 5, 2016 at 7:51:18 AM UTC+12, BartC wrote: > >> However the Linuxes I've seen tend to have Python pre-installed. > > Some are even dropping Python 2, and only having Python 3 by default. Yes, so your best bet is to aim

Re: Structure of program development

2016-07-04 Thread Lawrence D’Oliveiro
On Tuesday, July 5, 2016 at 7:51:18 AM UTC+12, BartC wrote: > However the Linuxes I've seen tend to have Python pre-installed. Some are even dropping Python 2, and only having Python 3 by default. -- https://mail.python.org/mailman/listinfo/python-list

RE: Gzip module does not support Unix compressed .Z files [SEC=UNOFFICIAL]

2016-07-04 Thread Owen Brandon
That's actually the module that I wrote for this purpose (adapted Mark Adler's C code) - I haven't optimised it very much. Brandon Owen GNSS Network Operator  |  Geodesy and Seismic Monitoring Group Community Safety and Earth Monitoring Division  |  GEOSCIENCE AUSTRALIA _

Re: Running yum/apt-get from a virtualenv

2016-07-04 Thread Matt Wheeler
On Fri, 24 Jun 2016, 03:32 Tiglath Suriol, wrote: > Let us say that I install PostgreSQL from an activated virtualenv using > yum or apt-get, will PostgrSQL be local or global? > Global I understand that virtualenv isolates the Python environment only, so I > surmise that it will make no differ

Re: Namespaces are one honking great idea

2016-07-04 Thread Lawrence D’Oliveiro
On Tuesday, July 5, 2016 at 10:10:04 AM UTC+12, I wrote: > > On Monday, July 4, 2016 at 11:37:44 PM UTC+12, Chris Angelico wrote: > > > Functions within the namespace can't call other functions within the > > same namespace using unqualified names. This was a stated requirement. > > Doesn’t my @n

Re: Namespaces are one honking great idea

2016-07-04 Thread Lawrence D’Oliveiro
On Monday, July 4, 2016 at 11:37:44 PM UTC+12, Chris Angelico wrote: > Functions within the namespace can't call other functions within the > same namespace using unqualified names. This was a stated requirement. Doesn’t my @namespace decorator provide that? -- https://mail.python.org/mailman/li

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

2016-07-04 Thread Christian Heimes
On 2016-07-04 17:48, Marco Buttu wrote: > Hi all, > > if I open a file in text mode, do you know why file.seek() returns the > number of bytes, and file.tell() takes the number of bytes? I was > expecting the number of characters, like write() does: Your expectations are not correct. tell() and s

Re: Structure of program development

2016-07-04 Thread BartC
On 04/07/2016 17:55, Chris Warrick wrote: A second question of the basic design. If I write a program, can I move it to a computer that is without any Python software, or does that machine have to download the Python software? Does Python products contain all parts of a developed program or i

Need help compiling Python-devel

2016-07-04 Thread TM
Hi, I have successfully compiled Python-2.7.12 on AIX 6.1 TL09, using steps below. However I need the python-devel library/headers. How do I compile Python, so that I can use this? # ./configure --with-gcc="gcc" --with-cxx="gcc" --disable-ipv6 # make Any help is greatly appreciated. Thanks, Ton

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

2016-07-04 Thread MRAB
On 2016-07-04 16:48, Marco Buttu wrote: Hi all, if I open a file in text mode, do you know why file.seek() returns the number of bytes, and file.tell() takes the number of bytes? I was expecting the number of characters, like write() does: >>> f = open('myfile', 'w') >>> f.write('aè') 2 It s

Re: Structure of program development

2016-07-04 Thread Jussi Piitulainen
Michael Smolen writes: > Folks: > > I am new to this programming adventure. I've gotten past the > introductory chapters in 'How to..." books and now want to start > developing a much more complicated program that I will use repeated > for different applications. When I worked in Perl there was an

Re: Structure of program development

2016-07-04 Thread Alan Evangelista
I am new to this programming adventure. I've gotten past the introductory chapters in 'How to..." books and now want to start developing a much more complicated program that I will use repeated for different applications. When I worked in Perl there was an option to write a program in a text

Re: Structure of program development

2016-07-04 Thread BartC
On 04/07/2016 17:07, Michael Smolen wrote: Folks: I am new to this programming adventure. I've gotten past the introductory chapters in 'How to..." books and now want to start developing a much more complicated program that I will use repeated for different applications. When I worked in Perl

Re: Structure of program development

2016-07-04 Thread Chris Warrick
On 4 July 2016 at 18:07, Michael Smolen <8smo...@tds.net> wrote: > Folks: > > I am new to this programming adventure. I've gotten past the introductory > chapters in 'How to..." books and now want to start developing a much more > complicated program that I will use repeated for different applica

Re: Well, I finally ran into a Python Unicode problem, sort of

2016-07-04 Thread Marko Rauhamaa
BartC : > Usually anything that is defined can be changed at run-time so that the > compiler can never assume anything. The compiler can't assume anything permanent, but it could heuristically make excellent guesses at runtime. It needs to verify its guesses at the boundaries of compiled code and

Structure of program development

2016-07-04 Thread Michael Smolen
Folks: I am new to this programming adventure. I've gotten past the introductory chapters in 'How to..." books and now want to start developing a much more complicated program that I will use repeated for different applications. When I worked in Perl there was an option to write a program in a

Re: Well, I finally ran into a Python Unicode problem, sort of

2016-07-04 Thread BartC
On 04/07/2016 15:46, Ned Batchelder wrote: On Monday, July 4, 2016 at 10:36:54 AM UTC-4, BartC wrote: On 04/07/2016 13:47, Ned Batchelder wrote: This is a huge change. I've used a kind of 'weak' import scheme elsewhere, corresponding to C's '#include'. I think that could work in Python p

Re: Namespaces are one honking great idea

2016-07-04 Thread jmp
On 07/04/2016 01:37 PM, Chris Angelico wrote: On Mon, Jul 4, 2016 at 9:23 PM, jmp wrote: On 07/01/2016 04:13 PM, Steven D'Aprano wrote: But classes are not like the others: they must be instantiated before they can be used, and they are more than just a mere namespace grouping related entitie

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

2016-07-04 Thread Marco Buttu
Hi all, if I open a file in text mode, do you know why file.seek() returns the number of bytes, and file.tell() takes the number of bytes? I was expecting the number of characters, like write() does: >>> f = open('myfile', 'w') >>> f.write('aè') 2 It seems to me not consistent, and maybe cou

Re: Well, I finally ran into a Python Unicode problem, sort of

2016-07-04 Thread Ned Batchelder
On Monday, July 4, 2016 at 10:36:54 AM UTC-4, BartC wrote: > On 04/07/2016 13:47, Ned Batchelder wrote: > > On Monday, July 4, 2016 at 6:05:20 AM UTC-4, BartC wrote: > >> On 04/07/2016 03:30, Steven D'Aprano wrote: > > >>> You're still having problems with the whole Python-as-a-dynamic-language >

Re: Well, I finally ran into a Python Unicode problem, sort of

2016-07-04 Thread BartC
On 04/07/2016 13:47, Ned Batchelder wrote: On Monday, July 4, 2016 at 6:05:20 AM UTC-4, BartC wrote: On 04/07/2016 03:30, Steven D'Aprano wrote: You're still having problems with the whole Python-as-a-dynamic-language thing, aren't you? :-) Most Pythons seem to pre-compile code before exec

Re: Gzip module does not support Unix compressed .Z files [SEC=UNOFFICIAL]

2016-07-04 Thread Robert Kern
On 2016-07-04 09:00, dieter wrote: "Owen Brandon" writes: I have a query regarding the support of decompression for Unix compressed .Z files in Python's gzip module. The gzip system utility supports this using the '-d' switch, but the python module does not. When I am right, then the "zipf

EuroPython 2016: Please configure your tickets

2016-07-04 Thread M.-A. Lemburg
The EuroPython website supports buying tickets for other people (friends, colleagues, etc.). As a result, it is necessary to assign the tickets you buy to either yourself or someone else. The assignment process is explained below. Please tell us your preferences --- T

Re: Spot the bug: getoptquestion.py

2016-07-04 Thread Chris Angelico
On Mon, Jul 4, 2016 at 10:38 PM, Oscar wrote: > But is this not at least a bit unexpected behaviour from getopt? On one > hand, if I want to have trailing spaces in my longoptions, why not just > play along and allow them? On the other hand, a space is a delimiter on > the commandline. Does it mak

Re: Well, I finally ran into a Python Unicode problem, sort of

2016-07-04 Thread Ned Batchelder
On Monday, July 4, 2016 at 6:05:20 AM UTC-4, BartC wrote: > On 04/07/2016 03:30, Steven D'Aprano wrote: > > On Mon, 4 Jul 2016 10:17 am, BartC wrote: > > > >> On 04/07/2016 01:00, Lawrence D’Oliveiro wrote: > >>> On Monday, July 4, 2016 at 11:47:26 AM UTC+12, eryk sun wrote: > Python lacks a m

Re: Spot the bug: getoptquestion.py

2016-07-04 Thread Oscar
In article , Chris Angelico wrote: >On Mon, Jul 4, 2016 at 9:24 PM, Oscar wrote: >> Is this: >> >> a) a bug in getopt.getopt >> b) a bug in my code >> c) a great way to keep me busy for a while >> d) all of the above? >> >> >> #!/usr/bin/python >> >> from __future__ import print_function >> from

Re: Well, I finally ran into a Python Unicode problem, sort of

2016-07-04 Thread Rustom Mody
On Monday, July 4, 2016 at 3:56:43 PM UTC+5:30, BartC wrote: > On 04/07/2016 02:15, Lawrence D’Oliveiro wrote: > > On Monday, July 4, 2016 at 12:40:14 PM UTC+12, BartC wrote: > >> The structure of such a parser doesn't need to exactly match the grammar > >> with a dedicated block of code for each o

Re: Namespaces are one honking great idea

2016-07-04 Thread Chris Angelico
On Mon, Jul 4, 2016 at 9:23 PM, jmp wrote: > On 07/01/2016 04:13 PM, Steven D'Aprano wrote: >> >> But classes are not like the others: they must be instantiated before they >> can be used, and they are more than just a mere namespace grouping related >> entities. Classes support inheritance. Class

Re: Spot the bug: getoptquestion.py

2016-07-04 Thread Chris Angelico
On Mon, Jul 4, 2016 at 9:24 PM, Oscar wrote: > Is this: > > a) a bug in getopt.getopt > b) a bug in my code > c) a great way to keep me busy for a while > d) all of the above? > > > #!/usr/bin/python > > from __future__ import print_function > from getopt import getopt, GetoptError > import sys >

Re: Namespaces are one honking great idea

2016-07-04 Thread jmp
On 07/01/2016 04:13 PM, Steven D'Aprano wrote: But classes are not like the others: they must be instantiated before they can be used, and they are more than just a mere namespace grouping related entities. Classes support inheritance. Classes should be used for "is-a" relationships, not "has-a"

Spot the bug: getoptquestion.py

2016-07-04 Thread Oscar
Is this: a) a bug in getopt.getopt b) a bug in my code c) a great way to keep me busy for a while d) all of the above? #!/usr/bin/python from __future__ import print_function from getopt import getopt, GetoptError import sys try: opts, args = getopt(sys.argv[1:], 'b', ['bug ']) except Ge

Re: Creating a calculator

2016-07-04 Thread Antoon Pardon
Op 01-07-16 om 15:52 schreef Steven D'Aprano: > On Fri, 1 Jul 2016 10:25 pm, Christopher Reimer wrote: > >> For my BASIC interpreter, each line of BASIC is broken this way into >> tokens. > [...] >> By using * to unpack the split line, my program no longer crashes and no >> try/except block is need

Re: Well, I finally ran into a Python Unicode problem, sort of

2016-07-04 Thread Jussi Piitulainen
BartC writes: > A simpler approach is to treat user-defined operators as aliases for > functions: > > def myadd(a,b): > return a+b > > operator ∇: >(myadd,2,+3) # map to myadd, 2 operands, prio 3, LTR > > x = y ∇ z > > is then equivalent to: > > x = myadd(y,z) > > However you will usua

Re: Well, I finally ran into a Python Unicode problem, sort of

2016-07-04 Thread BartC
On 04/07/2016 02:15, Lawrence D’Oliveiro wrote: On Monday, July 4, 2016 at 12:40:14 PM UTC+12, BartC wrote: The structure of such a parser doesn't need to exactly match the grammar with a dedicated block of code for each operator precedence. It can be table-driven so that an operator precedence

Re: Special attributes added to classes on creation

2016-07-04 Thread Xiang Zhang
On Monday, July 4, 2016 at 12:02:41 AM UTC+8, Steven D'Aprano wrote: > I have some code which can preprocess (using a metaclass) or postprocess > (using a decorator) a class: > > @process > class K: > pass > > > class K(metaclass=process): > pass > > > Both should give the same result,

Re: Well, I finally ran into a Python Unicode problem, sort of

2016-07-04 Thread Jussi Piitulainen
Lawrence D’Oliveiro writes: > On Monday, July 4, 2016 at 6:08:51 PM UTC+12, Jussi Piitulainen wrote: >> Something could be done, but if the intention is to allow >> mathematical notation, it needs to be done with care. > > Mathematics uses single-character variable names so that > multiplication c

Re: Well, I finally ran into a Python Unicode problem, sort of

2016-07-04 Thread BartC
On 04/07/2016 03:30, Steven D'Aprano wrote: On Mon, 4 Jul 2016 10:17 am, BartC wrote: On 04/07/2016 01:00, Lawrence D’Oliveiro wrote: On Monday, July 4, 2016 at 11:47:26 AM UTC+12, eryk sun wrote: Python lacks a mechanism to add user-defined operators. (R has this capability.) Maybe this feat

Re: Creating a calculator

2016-07-04 Thread Pierre-Alain Dorange
DFS wrote: > > 2 lines? Love it! > > But apparently eval==evil. > > http://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html > > I bet you get hammered about it here on clp. It was a software to be deploy, it was just for educational purpose. -- Pierre-Alain Dorange

ANN: Python Meeting Düsseldorf - 06.07.2016

2016-07-04 Thread eGenix Team: M.-A. Lemburg
[This announcement is in German since it targets a local user group meeting in Düsseldorf, Germany] ANKÜNDIGUNG Python Meeting Düsseldorf http://pyddf.de/ Ein Tref

Re: Well, I finally ran into a Python Unicode problem, sort of

2016-07-04 Thread Marko Rauhamaa
Lawrence D’Oliveiro : > Mathematics uses single-character variable names so that > multiplication can be implicit. I don't think anybody developed mathematical notation systematically. Rather, over the centuries, various masters came up with personal abbreviations and shorthand, which spread amon

Re: Making Classes Subclassable

2016-07-04 Thread Lawrence D’Oliveiro
On Monday, July 4, 2016 at 7:58:07 PM UTC+12, dieter wrote: > --> "type(obj)" or "obj.__class__" (there are small differences) > give you the type/class of "obj". When would it not be the same? -- https://mail.python.org/mailman/listinfo/python-list

Re: Well, I finally ran into a Python Unicode problem, sort of

2016-07-04 Thread Lawrence D’Oliveiro
On Monday, July 4, 2016 at 6:08:51 PM UTC+12, Jussi Piitulainen wrote: > Something could be done, but if the intention is to allow > mathematical notation, it needs to be done with care. Mathematics uses single-character variable names so that multiplication can be implicit. An old, stillborn la

Re: Gzip module does not support Unix compressed .Z files [SEC=UNOFFICIAL]

2016-07-04 Thread dieter
"Owen Brandon" writes: > I have a query regarding the support of decompression for Unix compressed .Z > files in Python's gzip module. The gzip system utility supports this using > the '-d' switch, but the python module does not. When I am right, then the "zipfile" module handles ".Z" compress

Re: Making Classes Subclassable

2016-07-04 Thread dieter
Lawrence D’Oliveiro writes: > Some of the classes in Qahirah, my Cairo binding > I found handy to reuse elsewhere, for > example in my binding for Pixman . > Subclassing is easy, but then you need to ensure that operations