Re: [newbie] tkFileDialog does not show title

2016-03-28 Thread Peter Pearson
On Mon, 28 Mar 2016 14:10:28 -0700 (PDT), jenswaelk...@gmail.com wrote:
> I'm using the tkFileDialog-module in Python 2.7, it works fine except
> for one thing: when I add a title, the title isn't shown.
>
> e.g. I have this line of code:
> inputfilename=tkFileDialog.askopenfilename(defaultextension=".dat", 
>filetypes=(("data file", "*.dat"),("All Files", "*.*") ),
>title='Select input file')
>
> this works fine i.e. the file selector menu opens but I expected that
> the text 'Select input file' would be displayed too. Can anyone here
> explain me how I can achieve this?

On my system (Linux, Python 2.7.3), "Select input file" appears as
the title of the choose-a-file popup window -- that is, it appears on
the window's title bar, along with the maximize, minimize, and close
buttons.  Is that not what you wanted?

-- 
To email me, substitute nowhere->runbox, invalid->com.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: List of Functions

2016-03-28 Thread Steven D'Aprano
On Tue, 29 Mar 2016 08:40 am, Chris Angelico wrote:

> On Tue, Mar 29, 2016 at 12:40 AM, Marko Rauhamaa  wrote:
>> Dan Sommers :
>>
>>> On Mon, 28 Mar 2016 11:58:54 +0300, Marko Rauhamaa wrote:
>>>
 As for Python, I don't feel a great need for anonymous functions.
 However, I keep running into a need for anonymous classes, or,
 rather, classless objects. Not a biggie. I just create a one-off
 inner class and instantiate it, but I do appreciate Java's syntactic
 innovation.

"Classless object" is an oxymoron in Python since all values without
exception have a class. Can you explain what you mean?

Also, for the benefit of those who aren't Java coders, what do you mean
by "Java's syntactic innovation"?


>>> And I always curse Java for having to create an inner class and a
>>> method when all I need is a simple function. :-)
>>>
>>> I think it's Steven D'Aprano who keeps pointing out that you can
>>> always name your tiny helper functions instead of using lambda:
>>>
>>> def some_complex_function():
>>> def f(x) = x + 2
>>> some_library_that_wants_a_callback(f)
>>> some_library_that_wants_a_callback(lambda x: x + 2)
>>>
>>> Both calls to some_library_that_wants_a_callback run the same.
>>
>> Yes, but I've come to realize that I quite often need more than a
>> function: I need an object with behavior. The solution is to use a
>> "helper" class.
> 
> Can you give an example of code that would benefit from a
> "lambda-class" construct? 

That would be called "type" :-)

type(name, bases, namespace) returns a new class:


py> C = type("MyClass", (object,), {'foo': 1})
py> C

py> C.foo
1



-- 
Steven

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Which are best, well-tested ways to create REST services, with Json, in Python?

2016-03-28 Thread justin walters
On Mon, Mar 28, 2016 at 2:06 PM, David Shi via Python-list <
python-list@python.org> wrote:

> Has anyone done a recent reviews of creating REST services, in Python?
> Regards.
> David
> --
> https://mail.python.org/mailman/listinfo/python-list
>

There are a ton of different ways to do this. Can you provide some details
about the application?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: List of Functions

2016-03-28 Thread Chris Angelico
On Tue, Mar 29, 2016 at 9:52 AM, Steven D'Aprano  wrote:
> That would be called "type" :-)
>
> type(name, bases, namespace) returns a new class:
>
>
> py> C = type("MyClass", (object,), {'foo': 1})
> py> C
> 
> py> C.foo
> 1

Yeah, but to do that in a single expression, you need to have all the
functions in the dictionary, so it's no improvement over
SimpleNamespace. The functions get attached to the class, not the
instance, which means they need 'self' - but without assignment, you
wouldn't be able to make much use of self anyway. Hence the call for
an example.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: List of Functions

2016-03-28 Thread Steven D'Aprano
On Mon, 28 Mar 2016 06:51 pm, Jussi Piitulainen wrote:

> Ben Bacarisse writes:
> 
>> It's shame that anonymous functions (for that's what's being returned
>> here -- a function with no name) were born of a subject that used
>> arbitrary Greek letters for things.  We seem stuck with the mysterious
>> but meaningless "lambda" for a very simple and useful idea.

I'm not sure that "lambda" is any more mysterious or meaningless than other
terms used in computing. What's a closure? A trampoline? A future? Mapping?
Thread? Greenlet? Mantissa? Not to mention terms from mathematics that
people simply memorise, like "sin", "cos", "power".

Not to mention "Monad". I don't think *anyone* knows what a Monad is ;-)


> Well said.
> 
> Python should have called it "fun".

As in the 80s pop hit by Cyndia Lauper, "Girls Just Wanna Have Anonymous
Functions"?


> I have heard that the use of lambda for this purpose was originally not
> an arbitrary choice but a typographical accident. A misinterpreted caret
> or something. I also seem to remember that I've seen some discussion on
> whether the story is true or not, but I forget which way it went.

I don't know whether or not it is true, but I've heard the same thing.
Quote:

(Note: it may seem perverse to use lambda to introduce a procedure/function.
The notation goes back to Alonzo Church, who in the 1930's started with
a "hat" symbol; he wrote the square function as "ŷ . y × y". But frustrated
typographers moved the hat to the left of the parameter and changed it to a
capital lambda: "Λy . y × y"; from there the capital lambda was changed to
lowercase, and now we see "λy . y × y" in math books and (lambda (y) (* y
y)) in Lisp. If it were up to me, I'd use fun or maybe ^. ) 

http://norvig.com/lispy2.html



-- 
Steven

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: List of Functions

2016-03-28 Thread Random832
On Mon, Mar 28, 2016, at 19:40, Steven D'Aprano wrote:
> Not to mention "Monad". I don't think *anyone* knows what a Monad is ;-)

A monad is just a monoid in the category of endofunctors; what's the
problem?

Well, someone had to say it.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: List of Functions

2016-03-28 Thread Chris Angelico
On Tue, Mar 29, 2016 at 10:50 AM, Random832  wrote:
> On Mon, Mar 28, 2016, at 19:40, Steven D'Aprano wrote:
>> Not to mention "Monad". I don't think *anyone* knows what a Monad is ;-)
>
> A monad is just a monoid in the category of endofunctors; what's the
> problem?
>
> Well, someone had to say it.

A monad is what you get in front of every Twitch stream. A polyad is
what you get on dodgy torrent sites. Of course, only functional
languages have them; nonfunctional languages use adblockers.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Learning Python (or Haskell) makes you a worse programmer

2016-03-28 Thread Steven D'Aprano
http://lukeplant.me.uk/blog/posts/why-learning-haskell-python-makes-you-a-worse-programmer/



-- 
Steven

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Which are best, well-tested ways to create REST services, with Json, in Python?

2016-03-28 Thread justin walters
On Mon, Mar 28, 2016 at 5:17 PM, David Shi  wrote:

> Hello, Justin,
>
> I am thinking of a fast, responsive, secure way of doing this.  Python at
> server-side.  It provides REST services.  Data exchange with the
> web--page.  Formatted XML or Json.
>
> Ideally, it uses the least code.
>
> Any excellent literature describes this?  I like articles which give
> insight into the nitty-gritty.
>
> Looking forward to hearing from you.
>
> Regards.
>
> Shao
>
>
>
>

David,

Please reply all on this list.

My preferred method is to use Django with Django Rest Framework. Django is
a very mature and robust framework with a ton of features. I use it in
production for several projects and have very few issues. It includes
middleware authentication and security features as well. You can find the
Django documentation here: https://docs.djangoproject.com/en/1.9/. If
you've never used Django before, I recommend going through the official
tutorial. It is also advised to use Python 3.4+.

Django rest framework is probably one of the best documented packages out
there. You can find it's documentation here:
http://www.django-rest-framework.org/. The official tutorial is very
in-depth. I would recommend working through it as well. DRF includes a lot
of functionality and multiple authentication and serialization methods.


There are other options as well depending on the scale of your project you
may choose to use something like flask: http://flask.pocoo.org/ with
flask-restful and sqlalchemy.

Like I said my personal recommendation is Django and DRF as it is easy to
set up, there isn't much overhead, and it scales very well.

Does that answer your question, or were you looking for more information?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: List of Functions

2016-03-28 Thread Rustom Mody
On Tuesday, March 29, 2016 at 5:11:02 AM UTC+5:30, Steven D'Aprano wrote:
> On Mon, 28 Mar 2016 06:51 pm, Jussi Piitulainen wrote:
> 
> > Ben Bacarisse writes:
> > 
> >> It's shame that anonymous functions (for that's what's being returned
> >> here -- a function with no name) were born of a subject that used
> >> arbitrary Greek letters for things.  We seem stuck with the mysterious
> >> but meaningless "lambda" for a very simple and useful idea.
> 
> I'm not sure that "lambda" is any more mysterious or meaningless than other
> terms used in computing. What's a closure? A trampoline? A future? Mapping?
> Thread? Greenlet? Mantissa? Not to mention terms from mathematics that
> people simply memorise, like "sin", "cos", "power".

Its my conjecture/contention that people find λ hard because 98% of material
presenting it is backward: "A λ is an 'anonymous function"

How does "A constant is an anonymous variable"   sound?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: List of Functions

2016-03-28 Thread Ben Bacarisse
Steven D'Aprano  writes:

> On Mon, 28 Mar 2016 06:51 pm, Jussi Piitulainen wrote:
>
>> Ben Bacarisse writes:
>> 
>>> It's shame that anonymous functions (for that's what's being returned
>>> here -- a function with no name) were born of a subject that used
>>> arbitrary Greek letters for things.  We seem stuck with the mysterious
>>> but meaningless "lambda" for a very simple and useful idea.
>
> I'm not sure that "lambda" is any more mysterious or meaningless than other
> terms used in computing. What's a closure? A trampoline? A future? Mapping?
> Thread? Greenlet? Mantissa? Not to mention terms from mathematics that
> people simply memorise, like "sin", "cos", "power".

Well lambda is more arbitrary than those that include helpful hints to
the technical meaning in the plain English meaning.  What's more, though
they express important concepts they are not all part of Python's
syntax.  Lambda has no helpful meaning and yet has to appear in the
program's text.

Anyway, even it is were exactly like all the other examples, is that a
reason to have more?  I'd argue that we should have as few such words as
possible, especially in the syntax.

If functions were defined

  fun f(x): return x * x

then an anonymous function could be written as a function definition but
the name

  fun (x): return x * x

I suppose you could do that even with "def" but it's a bit less
mnemonic.

There's probably a good reason why this was not done -- maybe it stops
the grammar being LL(1)?  And if lambda's arrived late, and a new
keyword is needed to flag a function expression, then lambda is
appealing to the designer since it's less likely to be in use as an
identifier in existing code than many more meaningful keywords.


-- 
Ben.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: List of Functions

2016-03-28 Thread Chris Angelico
On Tue, Mar 29, 2016 at 1:45 PM, Ben Bacarisse  wrote:
> If functions were defined
>
>   fun f(x): return x * x
>
> then an anonymous function could be written as a function definition but
> the name
>
>   fun (x): return x * x
>
> I suppose you could do that even with "def" but it's a bit less
> mnemonic.
>
> There's probably a good reason why this was not done -- maybe it stops
> the grammar being LL(1)?  And if lambda's arrived late, and a new
> keyword is needed to flag a function expression, then lambda is
> appealing to the designer since it's less likely to be in use as an
> identifier in existing code than many more meaningful keywords.

Some languages are exactly like this. I'm not sure what the reason is
for Python's difference, but one possibility is the mess that comes
from having statements inside expressions when indentation is
significant to statements (but free-form in expressions).

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Learning Python (or Haskell) makes you a worse programmer

2016-03-28 Thread Ethan Furman

On 03/28/2016 05:44 PM, Steven D'Aprano wrote:


http://lukeplant.me.uk/blog/posts/why-learning-haskell-python-makes-you-a-worse-programmer/


Beautiful.  And my deepest sympathies for the OP.

--
~Ethan~

--
https://mail.python.org/mailman/listinfo/python-list


Re: Learning Python (or Haskell) makes you a worse programmer

2016-03-28 Thread Michael Torrie
On 03/28/2016 06:44 PM, Steven D'Aprano wrote:
> http://lukeplant.me.uk/blog/posts/why-learning-haskell-python-makes-you-a-worse-programmer/

I have the same problem as the writer.  Working in Python makes me
really dislike working in any other language!

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Which are best, well-tested ways to create REST services, with Json, in Python?

2016-03-28 Thread justin walters
Hi David, once again, please reply all on this list.

I sent you a couple of step by step guides. Pleas look at the links that I
sent.

On Mon, Mar 28, 2016 at 9:12 PM, David Shi  wrote:

> Hello, Justin,
>
> Is there any official step by step guide.
>
> Send me the download link and link to Official tutorial.
>
> Regards.
>
> David
>
>
> On Tuesday, 29 March 2016, 2:35, justin walters <
> walters.justi...@gmail.com> wrote:
>
>
>
>
> On Mon, Mar 28, 2016 at 5:17 PM, David Shi  wrote:
>
> Hello, Justin,
>
> I am thinking of a fast, responsive, secure way of doing this.  Python at
> server-side.  It provides REST services.  Data exchange with the
> web--page.  Formatted XML or Json.
>
> Ideally, it uses the least code.
>
> Any excellent literature describes this?  I like articles which give
> insight into the nitty-gritty.
>
> Looking forward to hearing from you.
>
> Regards.
>
> Shao
>
>
>
>
>
> David,
>
> Please reply all on this list.
>
> My preferred method is to use Django with Django Rest Framework. Django is
> a very mature and robust framework with a ton of features. I use it in
> production for several projects and have very few issues. It includes
> middleware authentication and security features as well. You can find the
> Django documentation here: https://docs.djangoproject.com/en/1.9/. If
> you've never used Django before, I recommend going through the official
> tutorial. It is also advised to use Python 3.4+.
>
> Django rest framework is probably one of the best documented packages out
> there. You can find it's documentation here:
> http://www.django-rest-framework.org/. The official tutorial is very
> in-depth. I would recommend working through it as well. DRF includes a lot
> of functionality and multiple authentication and serialization methods.
>
>
> There are other options as well depending on the scale of your project you
> may choose to use something like flask: http://flask.pocoo.org/ with
> flask-restful and sqlalchemy.
>
> Like I said my personal recommendation is Django and DRF as it is easy to
> set up, there isn't much overhead, and it scales very well.
>
> Does that answer your question, or were you looking for more information?
>
>
>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: List of Functions

2016-03-28 Thread Marko Rauhamaa
Chris Angelico :

> On Tue, Mar 29, 2016 at 12:40 AM, Marko Rauhamaa  wrote:
>> Dan Sommers :
>>
>>> On Mon, 28 Mar 2016 11:58:54 +0300, Marko Rauhamaa wrote:
>>>
 As for Python, I don't feel a great need for anonymous functions.
 However, I keep running into a need for anonymous classes, or,
 rather, classless objects. Not a biggie. I just create a one-off
 inner class and instantiate it, but I do appreciate Java's syntactic
 innovation.
>>>
>>> And I always curse Java for having to create an inner class and a
>>> method when all I need is a simple function. :-)
>>>
>>> I think it's Steven D'Aprano who keeps pointing out that you can
>>> always name your tiny helper functions instead of using lambda:
>>>
>>> def some_complex_function():
>>> def f(x) = x + 2
>>> some_library_that_wants_a_callback(f)
>>> some_library_that_wants_a_callback(lambda x: x + 2)
>>>
>>> Both calls to some_library_that_wants_a_callback run the same.
>>
>> Yes, but I've come to realize that I quite often need more than a
>> function: I need an object with behavior. The solution is to use a
>> "helper" class.
>
> Can you give an example of code that would benefit from a
> "lambda-class" construct?

Here's a recent example:


def process(self, source):
awk = self
class Source(snake.FieldSource):
def emit_fields(self):
for fields in snake.get_fields(
source, awk.encoding, awk.errors,
awk.eol, awk.delim):
if awk.selector is None or awk.selector(fields):
yield [ fields[i] for i in awk.columns ]
return Source(self.encoding, self.errors, self.eol, self.delim)


Here's another, older one:


def __init__(self, server, sock, domain, peer):
super().__init__(server, sock)
conn = self
client_ip = peer[0]

[...]

class SPF_HELO(STATE):
def terminate(self):
conn.resume()
conn.spf_query.cancel()
conn.close()
if conn.timer is not None:
conn.timer.cancel()
conn.timer = None
conn.set_state(ZOMBIE)

def handle_spf_verdict(self, verdict, reason, *capabilities):
conn.resume()
conn.log("verdict {} reason {}".format(verdict, reason))
# RFC 4408 §2.5.5 calls for leniency for SoftFail
#if verdict in [ SPFClient.FAIL, SPFClient.SOFT_FAIL ]:
if verdict in [ SPFClient.FAIL ]:
conn.respond(550, "SPF check failed: {}".format(reason))
conn.set_state(IDLE)
return
conn.respond(250, server.domain, *capabilities)
conn.set_state(IDLE)



Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: List of Functions

2016-03-28 Thread Marko Rauhamaa
Steven D'Aprano :

> On Tue, 29 Mar 2016 08:40 am, Chris Angelico wrote:
>
>> On Tue, Mar 29, 2016 at 12:40 AM, Marko Rauhamaa  wrote:
>>> Dan Sommers :
>>>
 On Mon, 28 Mar 2016 11:58:54 +0300, Marko Rauhamaa wrote:
> As for Python, I don't feel a great need for anonymous functions.
> However, I keep running into a need for anonymous classes, or,
> rather, classless objects. Not a biggie. I just create a one-off
> inner class and instantiate it, but I do appreciate Java's
> syntactic innovation.
>
> "Classless object" is an oxymoron in Python since all values without
> exception have a class. Can you explain what you mean?

In class terms, I mean a closure class that has precisely one instance.
Just like a closure function has precisely one instance.

In object terms, I mean an object that implements an interface but whose
class is not of essence.

> Also, for the benefit of those who aren't Java coders, what do you mean
> by "Java's syntactic innovation"?

HelloWorld frenchGreeting = new HelloWorld() {
String name = "tout le monde";
public void greet() {
greetSomeone("tout le monde");
}
public void greetSomeone(String someone) {
name = someone;
System.out.println("Salut " + name);
}
};

https://docs.oracle.com/javase/tutorial/java/javaOO/anonym
ousclasses.html>


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: List of Functions

2016-03-28 Thread Chris Angelico
On Tue, Mar 29, 2016 at 3:45 PM, Marko Rauhamaa  wrote:
> Chris Angelico :
>
>> On Tue, Mar 29, 2016 at 12:40 AM, Marko Rauhamaa  wrote:
>>> Dan Sommers :
>>>
 On Mon, 28 Mar 2016 11:58:54 +0300, Marko Rauhamaa wrote:

> As for Python, I don't feel a great need for anonymous functions.
> However, I keep running into a need for anonymous classes, or,
> rather, classless objects. Not a biggie. I just create a one-off
> inner class and instantiate it, but I do appreciate Java's syntactic
> innovation.

 And I always curse Java for having to create an inner class and a
 method when all I need is a simple function. :-)

 I think it's Steven D'Aprano who keeps pointing out that you can
 always name your tiny helper functions instead of using lambda:

 def some_complex_function():
 def f(x) = x + 2
 some_library_that_wants_a_callback(f)
 some_library_that_wants_a_callback(lambda x: x + 2)

 Both calls to some_library_that_wants_a_callback run the same.
>>>
>>> Yes, but I've come to realize that I quite often need more than a
>>> function: I need an object with behavior. The solution is to use a
>>> "helper" class.
>>
>> Can you give an example of code that would benefit from a
>> "lambda-class" construct?
>
> Here's a recent example:
>
> 
> def process(self, source):
> awk = self
> class Source(snake.FieldSource):
> def emit_fields(self):
> for fields in snake.get_fields(
> source, awk.encoding, awk.errors,
> awk.eol, awk.delim):
> if awk.selector is None or awk.selector(fields):
> yield [ fields[i] for i in awk.columns ]
> return Source(self.encoding, self.errors, self.eol, 
> self.delim)
> 
>
> Here's another, older one:
>
> 
> def __init__(self, server, sock, domain, peer):
> super().__init__(server, sock)
> conn = self
> client_ip = peer[0]
>
> [...]
>
> class SPF_HELO(STATE):
> def terminate(self):
> conn.resume()
> conn.spf_query.cancel()
> conn.close()
> if conn.timer is not None:
> conn.timer.cancel()
> conn.timer = None
> conn.set_state(ZOMBIE)
>
> def handle_spf_verdict(self, verdict, reason, *capabilities):
> conn.resume()
> conn.log("verdict {} reason {}".format(verdict, reason))
> # RFC 4408 §2.5.5 calls for leniency for SoftFail
> #if verdict in [ SPFClient.FAIL, SPFClient.SOFT_FAIL ]:
> if verdict in [ SPFClient.FAIL ]:
> conn.respond(550, "SPF check failed: {}".format(reason))
> conn.set_state(IDLE)
> return
> conn.respond(250, server.domain, *capabilities)
> conn.set_state(IDLE)
> 

Since those functions have statements in them, there's not going to be
any way to construct this class as an expression (short of stupid
messing around with exec, which would be a bad idea). So the best
you're likely to be able to do is a metaclass or decorator that
short-hands the instantiation - or crafting your other code such that
it takes the class, rather than an instance of the class. The latter
is quite Pythonic, but generally not as well regarded in other
languages, sometimes for obvious reasons like "classes aren't first
class objects". :)

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re-using TCL code from python over network

2016-03-28 Thread sharad1087
Hi

We've a test automation framework written in TCL (including the automated test 
cases). We are evaluating shifting to Python and have a test framework in 
Python (including the automated test cases). Python provides a lot more 3rd 
party libraries that we'd like to make use of.

We use a pretty old version of TCL (8.4.5, 32 bit). It's on FreeBSD and we've 
compiled it in-house. Compiling it to 64 bit or moving to a newer version is a 
massive task (since we've a lot of libraries - written in C and compiled as 
well as pure tcl).

Also, we are evaluating having this Python infrastructure on Linux (CentOS).

I've explored Python's Tkinter but it won't suit our case as it points to 
system installed TCL. I've also explored Python's subprocess (launch an 
interactive TCL shell remotely) and pexpect but none of them worked well for me 
to allow me to use TCL code interactively from Python.

I'd like to gather any ideas/experience around this. If anyone has tried a 
similar stuff before and can share his/her experience, I'd appreciate it.

Regards
Sharad
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: List of Functions

2016-03-28 Thread Rustom Mody
On Tuesday, March 29, 2016 at 8:16:12 AM UTC+5:30, Ben Bacarisse wrote:
> Steven D'Aprano writes:
> 
> > On Mon, 28 Mar 2016 06:51 pm, Jussi Piitulainen wrote:
> >
> >> Ben Bacarisse writes:
> >> 
> >>> It's shame that anonymous functions (for that's what's being returned
> >>> here -- a function with no name) were born of a subject that used
> >>> arbitrary Greek letters for things.  We seem stuck with the mysterious
> >>> but meaningless "lambda" for a very simple and useful idea.
> >
> > I'm not sure that "lambda" is any more mysterious or meaningless than other
> > terms used in computing. What's a closure? A trampoline? A future? Mapping?
> > Thread? Greenlet? Mantissa? Not to mention terms from mathematics that
> > people simply memorise, like "sin", "cos", "power".
> 
> Well lambda is more arbitrary than those that include helpful hints to
> the technical meaning in the plain English meaning.  What's more, though
> they express important concepts they are not all part of Python's
> syntax.  Lambda has no helpful meaning and yet has to appear in the
> program's text.

I am guessing its a long time since you were introduced to computers.
And you've forgotten what the jargon first felt like.

As a student I remember my friends who were doing projects with me
working at my place.
And my mum made the strange remark: "You guys use all the words that I know.
And you make them into sentences that have no meaning at all."

Since you've 'forgotten' that jargonification stage, lets start with 'memory'.
'Memory' is a very old English word, eg. what I did right now -- remembering 
what my Mum told me some 35 years ago: Does it have anything to do with what
memory means in computer-jargon?

Dijkstra liked to point out that CS was backward in America compared to Europe
because in Europe they used 'store' but Americans used anthropomorphism like 
memory

Now given that store can mean -- among other things -- 
- room where I dump stuff
- shop where I buy bread and eggs
- etc
why is Dijkstra's preferred use actually any better?

Or his most famous request: When you make an error please call it an error.
There is no 'mean little bug' crawling out when you were not looking.

Shall we rename 'debugging programs' to 'error-correcting code(s)'?

Likewise
computer has always been a mathematician that computes
and
program is for things like radio-program, concert-program etc

> 
> Anyway, even it is were exactly like all the other examples, is that a
> reason to have more?  I'd argue that we should have as few such words as
> possible, especially in the syntax.

Its a hard question
Take an old word and give it a new related but different meaning
vs
Invent a nonsense word for a genuinely new concept

My own finding is that repurposing old words to new concepts causes more
confusion and misunderstanding than understanding and 'progress'

A record of how sticking to sloppy terminology perpetuates sloppy understanding:

http://blog.languager.org/2011/02/cs-education-is-fat-and-weak-2.html
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Re-using TCL code from python over network

2016-03-28 Thread Christian Gollwitzer

Am 29.03.16 um 07:20 schrieb sharad1...@gmail.com:

We've a test automation framework written in TCL (including the
automated test cases). We are evaluating shifting to Python and have
a test framework in Python (including the automated test cases).
Python provides a lot more 3rd party libraries that we'd like to make
use of.

We use a pretty old version of TCL (8.4.5, 32 bit). It's on FreeBSD
and we've compiled it in-house. Compiling it to 64 bit or moving to a
newer version is a massive task (since we've a lot of libraries -
written in C and compiled as well as pure tcl).


Tcl's API (and ABI) is highly stable. I suspect that you could recompile 
most of the libraries, unless they depend on 3rd party code which is not 
portable. But of course it might be easier to call it from Python.



I've explored Python's Tkinter but it won't suit our case as it
points to system installed TCL. I've also explored Python's
subprocess (launch an interactive TCL shell remotely) and pexpect but
none of them worked well for me to allow me to use TCL code
interactively from Python.

I'd like to gather any ideas/experience around this. If anyone has
tried a similar stuff before and can share his/her experience, I'd
appreciate it.


You can set up a server in Tcl which will run arbitrary code from the 
network. The simplest possible server looks like this:


http://wiki.tcl.tk/15539

A more complete package (which will correctly handle scripts which span 
multiple lines etc.) is the comm package in tcllib:


https://core.tcl.tk/tcllib/doc/trunk/embedded/www/tcllib/files/modules/comm/comm.html

Beware that this is of course a security hole, you should only do it in 
a network restricted by your firewall or by employing a safe interpreter 
on the Tcl side which is sufficiently restricted.


https://www.tcl.tk/man/tcl8.4/TclCmd/interp.htm#M10

Probably the easiest way is using Tkinter from Python to send commands 
via the comm package to the remote site, i.e. tk.eval('package require 
comm') and then sending your commands by tk.eval('comm:comm send ...')


The comm protocol is very simplistic

http://docs.activestate.com/activetcl/8.4/tcllib/comm/comm_wire.html

you could also reproduce it from Python in order to reduce this jumping 
through hoops.


In the end it will always be a messy solution. As an interim solution it 
might work, but you should seriously consider recompiling the code as 64 
bit, migrating all code to Python or watch out for the libraries you 
need in modern Tcl.


Christian
--
https://mail.python.org/mailman/listinfo/python-list


Re: [newbie] tkFileDialog does not show title

2016-03-28 Thread jenswaelkens
Op dinsdag 29 maart 2016 00:29:29 UTC+2 schreef Peter Pearson:
> On Mon, 28 Mar 2016 14:10:28 -0700 (PDT), jenswaelk...@gmail.com wrote:
> > I'm using the tkFileDialog-module in Python 2.7, it works fine except
> > for one thing: when I add a title, the title isn't shown.
> >
> > e.g. I have this line of code:
> > inputfilename=tkFileDialog.askopenfilename(defaultextension=".dat", 
> >filetypes=(("data file", "*.dat"),("All Files", "*.*") ),
> >title='Select input file')
> >
> > this works fine i.e. the file selector menu opens but I expected that
> > the text 'Select input file' would be displayed too. Can anyone here
> > explain me how I can achieve this?
> 
> On my system (Linux, Python 2.7.3), "Select input file" appears as
> the title of the choose-a-file popup window -- that is, it appears on
> the window's title bar, along with the maximize, minimize, and close
> buttons.  Is that not what you wanted?
> 
> -- 
> To email me, substitute nowhere->runbox, invalid->com.

Thanks Peter and Wildman for trying this out on your systems. Now I know at 
least the code is correct but the fact that nothing is displayed on my desktop 
has probably to do with some setting of the LXDE-desktop I'm using. I will 
investigate this further.

kind regards,
jens
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: List of Functions

2016-03-28 Thread Marko Rauhamaa
Rustom Mody :

> And my mum made the strange remark: "You guys use all the words that I
> know. And you make them into sentences that have no meaning at all."

That's what I think when I hear Estonian spoken.

> My own finding is that repurposing old words to new concepts causes
> more confusion and misunderstanding than understanding and 'progress'

I disagree. I think it's absolutely great that we have "charm quarks"
after centuries of "electrostatic equilibria".

Finnish has a long tradition of translating fancy words into proper
Finnish, and that has contributed to more informed democratic debate on,
say, nuclear energy. We have:

   suunnikas for parallelogram
   puolisuunnikas for trapezoid
   suorakaide for rectangle
   suhde for ratio
   muuttuja for variable

   mahahaava for peptic ulcer
   sydänkohtaus for myocardial infarction
   selkäydin for spinal cord
   immuunikato for AIDS

   rattijuoppous for DUI
   ensiapu for CPR

   ydinvoima for nuclear power
   sähkö for electricity
   happi for oxygen
   häkä for carbon monoxide
   vetovoima for attraction
   kiihtyvyys for acceleration

   tietorakenne for data structure
   viite for reference

   etc etc


Here's a funny, somewhat related story. I was wondering about the
etymology of the word "glamour." I thought it must be some old borrowing
from French.

In reality, it was borrowed from Scots English, which borrowed it from
English English. The original words was "grammar," which referred to
what theology students studied in the university, ie, Latin. Only Latin
carried the proper magic, charm. The Catholic priests did their
hocuspocus ("hoc est corpus meum") in proper "grammar," or, in Scotland,
"glamour."

Would software developers be more glamorous if they used more
impenetrable jargon?


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: List of Functions

2016-03-28 Thread Christian Gollwitzer

Am 29.03.16 um 08:21 schrieb Rustom Mody:

Dijkstra liked to point out that CS was backward in America compared to Europe
because in Europe they used 'store' but Americans used anthropomorphism like 
memory

Now given that store can mean -- among other things --
- room where I dump stuff
- shop where I buy bread and eggs
- etc
why is Dijkstra's preferred use actually any better?


The Oxford dictionary lists "store" for "shop" as "chiefly North American"

http://www.oxforddictionaries.com/definition/english/store

Maybe Dijkstra was speaking from his native Dutch perspective? I don't 
know in Dutch, but at least in German we use "Speicher", which means 
"store room" - either a closet or room, typically under the roof, where 
you store things for later use, or a municipal facility to store, e.g. 
water in big amounts, or the big buildings at harbours used to store 
goods, but never a shop.


A room where you store things for later use is a quite good description 
for computer memory, isn't it?


Christian
--
https://mail.python.org/mailman/listinfo/python-list


Re: help with program

2016-03-28 Thread Sibylle Koczian

Am 28.03.2016 um 02:20 schrieb Steven D'Aprano:

On Mon, 28 Mar 2016 01:18 am, Bob Gailer wrote:


The problem with putting input at the end of a program is: if the program
raises an exception you won't see it.


True. But the solution to that is simple: don't make mistakes when
programming :-)

If you have a better solution, please speak up. I don't know Windows very
well and I'm not sure why the console is disappearing in the first place.

Because it was opened only by starting the program, and so it closes 
when the program ends. Wouldn't the same thing happen on Linux, if a 
console application were started from the file manager?


I would always start a console application from an open command prompt, 
in case of exceptions. And if my Python GUI application doesn't appear 
on the screen I do the same, to see the traceback.




--
https://mail.python.org/mailman/listinfo/python-list


Using python heredoc to substitute the external file read by python script.

2016-03-28 Thread Hongyi Zhao
Hi all,

See the following python codes:

import os
from subprocess import check_output

# POSIX: name shall not contain '=', value doesn't contain '\0'
output = check_output("source /home/werner/env-intel-toolchains.sh;
 env -0", shell=True, executable="/bin/bash")


In the above codes, I use the file /home/werner/env-intel-toolchains.sh 
for subprocess.check_output to use for its operation.

If I want to use python heredoc to substitute this external file for the 
above codes.  Is this possible?  

Regards
-- 
.: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.
-- 
https://mail.python.org/mailman/listinfo/python-list


Pyaudio and sockets

2016-03-28 Thread Shiva Upreti
I am trying to send audio using sockets to a different PC, but audio is not 
clear on the other end and I cant understand why.

Here is the code:

import socket
import pyaudio
import wave
import sys
import pickle
import time

HOST=""
PORT=1061
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
CHUNK = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 2
RATE = 44100
RECORD_SECONDS = 3


def record(sock):   
def callback_record(in_data, frame_count, time_info, status):
#print len(in_data)
sock.sendall(in_data)   

return (in_data, pyaudio.paContinue)

p = pyaudio.PyAudio()
stream = p.open(format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
output=False,
stream_callback=callback_record)

stream.start_stream()
return stream   


def play(sock):
def callback_play(in_data, frame_count, time_info, status):
#msg=recv_all(sock)
in_data=sock.recv(5000)
return (in_data, pyaudio.paContinue)

p = pyaudio.PyAudio()
stream = p.open(format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=False,
output=True,
stream_callback=callback_play)

stream.start_stream()
return stream

def recv_all(sock):
data=sock.recv(5000)
return data


if sys.argv[1] == 'server':
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((HOST, PORT))
s.listen(10)
while(True):
print "Listening at:", s.getsockname()
sc, addr=s.accept()
print "Connection established with:", addr

while True:
stream_record=record(sc)
#stream_play=play(sc)
while stream_record.is_active():
#time.sleep(0.0)
pass
#stream_record.stop_stream()
#stream_record.close()
#stream_play.stop_stream()
#stream_play.close()

elif sys.argv[1]=='client':
s.connect((HOST, PORT))
while True: 
stream_play=play(s)
#time.sleep(5)
#stream_record=record(s)

while stream_play.is_active():
#time.sleep(0.0)
pass

#stream_record.stop_stream()
#stream_record.close()
#stream_play.stop_stream()
#stream_play.close()

To run it as server enter this command: 
python audio_chat2.py server
To run it as client enter this command: 
python audio_chat2.py client

I also tried running them on same PC, still voice was not clear.


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem With Embedded Icon and Python 3.4

2016-03-28 Thread Mark Lawrence

On 26/03/2016 02:37, Wildman via Python-list wrote:

On Sat, 26 Mar 2016 01:42:37 +, Mark Lawrence wrote:


On 25/03/2016 05:10, Wildman via Python-list wrote:

I have a program that I have been trying to rewrite so it will
run on Python 2.7 and 3.4.


This http://pythonhosted.org/six/ might come in handy in future.

As I'm also climbing the tkinter cliff at the moment I've found anything
on stackoverflow from Bryan Oakley to be very helpful. In particular,
his answer here
http://stackoverflow.com/questions/17466561/best-way-to-structure-a-tkinter-application
really helped me get a grip on things.

A lot of the examples here http://pyinmyeye.blogspot.co.uk/ were also
useful.

HTH.


Thanks for the links.  Good stuff.  Bookmarked.



One I forgot http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/index.html

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


Re: Using python heredoc to substitute the external file read by python script.

2016-03-28 Thread Ben Finney
Hongyi Zhao  writes:

> If I want to use python heredoc to substitute this external file for
> the above codes. Is this possible?

What do you mean by “Python heredoc”? What Python feature are you
referring to?

-- 
 \   “Anyone who puts a small gloss on [a] fundamental technology, |
  `\  calls it proprietary, and then tries to keep others from |
_o__)   building on it, is a thief.” —Tim O'Reilly, 2000-01-25 |
Ben Finney

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: repeat items in a list

2016-03-28 Thread larudwer

Am 27.03.2016 um 13:13 schrieb Antonio Caminero Garcia:

On Sunday, March 27, 2016 at 11:52:22 AM UTC+2, larudwer wrote:

how about

   sorted(["a", "b"]*3)
['a', 'a', 'a', 'b', 'b', 'b']


that's cooler, less efficient though and do not maintain the original order.
In case such order was important, you should proceed as follows:

If the elements are unique, this would work:

sorted(sequence*nrep, key=sequence.index)

Otherwise you'd need a more complex key function (maybe a method of a class with
> a static variable that tracks the number of times that such method is 
called and
> with a "dynamic index functionality" that acts accordingly (i-th 
nrep-group of value v))

> and imo it does not worth it.





in case you want to mainain order:

 ["a","b"]*3
['a', 'b', 'a', 'b', 'a', 'b']

is completely suffincient.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Using python heredoc to substitute the external file read by python script.

2016-03-28 Thread Hongyi Zhao
On Mon, 28 Mar 2016 21:29:48 +1100, Ben Finney wrote:

>> If I want to use python heredoc to substitute this external file for
>> the above codes. Is this possible?
> 
> What do you mean by “Python heredoc”? What Python feature are you
> referring to?

I find the following methods currently:

import subprocess

subprocess.Popen(
"""
cat < new.txt
Hello World!
EOF""", shell=True)

subprocess.Popen(
"""
cat 

Re: repeat items in a list

2016-03-28 Thread Random832
On Mon, Mar 28, 2016, at 07:36, larudwer wrote:
> in case you want to mainain order:
> 
>   ["a","b"]*3
> ['a', 'b', 'a', 'b', 'a', 'b']
> 
> is completely suffincient.

I think you've completely missed the point of what order he's talking
about. How do you turn ['a', 'c', 'b'] into ['a', 'a', 'a', 'c', 'c',
'c', 'b', 'b', 'b']?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem With Embedded Icon and Python 3.4

2016-03-28 Thread Wildman via Python-list
On Mon, 28 Mar 2016 10:36:44 +0100, Mark Lawrence wrote:

> On 26/03/2016 02:37, Wildman via Python-list wrote:
>> On Sat, 26 Mar 2016 01:42:37 +, Mark Lawrence wrote:
>>
>>> On 25/03/2016 05:10, Wildman via Python-list wrote:
 I have a program that I have been trying to rewrite so it will
 run on Python 2.7 and 3.4.
>>>
>>> This http://pythonhosted.org/six/ might come in handy in future.
>>>
>>> As I'm also climbing the tkinter cliff at the moment I've found anything
>>> on stackoverflow from Bryan Oakley to be very helpful. In particular,
>>> his answer here
>>> http://stackoverflow.com/questions/17466561/best-way-to-structure-a-tkinter-application
>>> really helped me get a grip on things.
>>>
>>> A lot of the examples here http://pyinmyeye.blogspot.co.uk/ were also
>>> useful.
>>>
>>> HTH.
>>
>> Thanks for the links.  Good stuff.  Bookmarked.
>>
> 
> One I forgot http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/index.html

I had already found that one and have it bookmarked.
Thanks tho.

-- 
 GNU/Linux user #557453
The cow died so I don't need your bull!
-- 
https://mail.python.org/mailman/listinfo/python-list


Path when reading an external file

2016-03-28 Thread ast

Hello

In a program "code.py" I read an external file "foo.txt" supposed 
to be located in the same directory that "code.py"


python/src/code.py
python/src/foo.txt

In "code.py": f = open('foo.txt', 'r')

But if I run "python code.py" in an other dir than src/
say in python/, it will not work because file "foo.txt" will be 
searched in dir python/ and not in dir python/src/


I think it is possible to build an absolute path for "foo.txt" 
using __file__ so that the program works wherever you 
launch "python code.py"


Is it the correct way to handle this problem ?

thx




--
https://mail.python.org/mailman/listinfo/python-list


Re: newbie question

2016-03-28 Thread ast


"Matt Wheeler"  a écrit dans le message de 
news:mailman.92.1458825746.2244.python-l...@python.org...

On Thu, 24 Mar 2016 11:10 Sven R. Kunze,  wrote:


On 24.03.2016 11:57, Matt Wheeler wrote:
 import ast
 s = "(1, 2, 3, 4)"
 t = ast.literal_eval(s)
 t
> (1, 2, 3, 4)

I suppose that's the better solution in terms of safety.



It has the added advantage that the enquirer gets to import a module that
shares their name ;)



I had a look at that "ast" module doc, but I must admit that
I didn't understood a lot of things. 


--
https://mail.python.org/mailman/listinfo/python-list


Re: Path when reading an external file

2016-03-28 Thread Martin A. Brown

Greetings,

> In a program "code.py" I read an external file "foo.txt" supposed 
> to be located in the same directory that "code.py"
>
> python/src/code.py
> python/src/foo.txt
>
> In "code.py": f = open('foo.txt', 'r')
>
> But if I run "python code.py" in an other dir than src/ say in 
> python/, it will not work because file "foo.txt" will be searched 
> in dir python/ and not in dir python/src/
>
> I think it is possible to build an absolute path for "foo.txt" 
> using __file__ so that the program works wherever you launch 
> "python code.py"
>
> Is it the correct way to handle this problem ?

Ayup, I would say so.  My suggested technique:

  here = os.path.dirname(os.path.abspath(__file__))
  foo = os.path.join(here, 'foo.txt')
  with open(foo, 'r') as f:
  pass

Good luck,

-Martin

-- 
Martin A. Brown
http://linux-ip.net/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Path when reading an external file

2016-03-28 Thread ast


"Martin A. Brown"  a écrit dans le message de 
news:mailman.108.1459179618.28225.python-l...@python.org...


Greetings,


In a program "code.py" I read an external file "foo.txt" supposed
to be located in the same directory that "code.py"

python/src/code.py
python/src/foo.txt

In "code.py": f = open('foo.txt', 'r')

But if I run "python code.py" in an other dir than src/ say in
python/, it will not work because file "foo.txt" will be searched
in dir python/ and not in dir python/src/

I think it is possible to build an absolute path for "foo.txt"
using __file__ so that the program works wherever you launch
"python code.py"

Is it the correct way to handle this problem ?


Ayup, I would say so.  My suggested technique:

 here = os.path.dirname(os.path.abspath(__file__))
 foo = os.path.join(here, 'foo.txt')
 with open(foo, 'r') as f:
 pass

Good luck,

-Martin

--
Martin A. Brown
http://linux-ip.net/


Ok, this is what I intended to do
Thanks for your answer 


--
https://mail.python.org/mailman/listinfo/python-list


Re: List of Functions

2016-03-28 Thread Jussi Piitulainen
Ben Bacarisse writes:

> It's shame that anonymous functions (for that's what's being returned
> here -- a function with no name) were born of a subject that used
> arbitrary Greek letters for things.  We seem stuck with the mysterious
> but meaningless "lambda" for a very simple and useful idea.

Well said.

Python should have called it "fun".

I have heard that the use of lambda for this purpose was originally not
an arbitrary choice but a typographical accident. A misinterpreted caret
or something. I also seem to remember that I've seen some discussion on
whether the story is true or not, but I forget which way it went.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: List of Functions

2016-03-28 Thread Marko Rauhamaa
Jussi Piitulainen :

> Ben Bacarisse writes:
>> It's shame that anonymous functions (for that's what's being returned
>> here -- a function with no name) were born of a subject that used
>> arbitrary Greek letters for things. We seem stuck with the mysterious
>> but meaningless "lambda" for a very simple and useful idea.
>
> Well said.
>
> Python should have called it "fun".
>
> I have heard that the use of lambda for this purpose was originally
> not an arbitrary choice but a typographical accident. A misinterpreted
> caret or something. I also seem to remember that I've seen some
> discussion on whether the story is true or not, but I forget which way
> it went.

I don't know the etymology of things, but way back when I learned
combinatory logic, the capital letter Λ was used as the name of the
abstraction algorithm.

Combinatory logic was able to express any formula without variables,
which apparently were somewhat of a sore spot for logicians in the early
20th century. So you took your formula with variables and ran it through
the Λ algorithm to get an equivalent combinator expression that didn't
have any variables.

I always thought the λ calculus arose from the abstraction algorithm.
Once the logicians had "tamed" variables with Λ, they no longer felt the
need to avoid them. You could set aside the clumsy combinators and
incorporate the lambda in the language itself.

...

As for Python, I don't feel a great need for anonymous functions.
However, I keep running into a need for anonymous classes, or, rather,
classless objects. Not a biggie. I just create a one-off inner class and
instantiate it, but I do appreciate Java's syntactic innovation.


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Statements as expressions [was Re: Undefined behaviour in C]

2016-03-28 Thread BartC

On 28/03/2016 01:54, Steven D'Aprano wrote:

On Mon, 28 Mar 2016 03:58 am, BartC wrote:


One of Guido's principles in designing Python was to keep it simple,
even where that might mean people could make errors with it.  This part
of the language is no different: any expression can be a statement.


Yeah, but even simpler would be that any statement can also be an
expression! He didn't go that far though.


People say that, but I don't believe it.


Well, some languages work like that. I think Lisp does. And so does the 
more 'normal'-looking Algol-68.


 What does it mean to say that any

statement could also be an expression? If this statement is an expression:


if condition:
 print(1)
 print(2)
else:
 print(3)
 print(4)


what value should it return? Justify your choice.


Each branch of the 'if-else' returns the value of the last 
statement/expression in each block. The if-statement as a whole returns 
one or the other.


Here, it might be the return value of print(); probably None.


What should be the return value of this statement?

while True:
 x += 1
 if condition: break


Many statements such as loops just returned 'void' in A68. The 
interesting statements were if, case-switch and block (where the value 
is that of the last statement/expression).


To make the best use of this, you really need a more free-format syntax 
than Python, and blocks need closure. A68 used the funny-looking 'fi' to 
close an if-statement, and 'od' for a loop:


 while c:=psource[n]; n+:=1; c!=etx do  ... od

 if c then a else b fi := 0  # also written (c|a|b):=0

 return case n in: 10,20,30 out: 90 esac


I don't think that "every statement is an expression" is conceptually
simpler at all. I think it is more difficult to understand. Nearly all
human languages make a distinction between things and actions:

* expressions return a value, which makes them a thing (noun);

* statements do something, which makes them an action (verb).


Yet Python does allow any expression as a statement. Not even the 
potentially useful block statement, where you do x, y and z and then 
have a normal expression as its value.


And Python allows a for-loop inside a lisp-comprehension.

Python also has an if-else statement in the form of a conditional 
expression (which I won't show as I can never remember the syntax).



It's easy to understand the concept of an expression where the result is
dropped. "Hand me that hammer" and then you just drop the hammer on the
floor.

It's harder to understand the concept of functions (doing words, verbs) as
values.


Huh? Functions do things then return results. Yet Python also allows 
procedure calls with no explicit return statement, to act as though they 
return a value:


 def p(): pass

 print (p())

It returns None, just like A68 uses 'void'.

So Python picks and chooses what it wants from the more general and 
conceptually simpler model of a language where expressions and 
statements are interchangeable. Python then is a little more complex 
because you have to consider what is allowed, and what isn't.


>It's being a bit, what's the word
 "First class functions" take a bit of mental effort to understand,

but the payoff it worth it.

But it is even harder to understand what it might mean for a while loop to
be a value, and the benefit of doing so seems significantly less than
compelling. Maybe it is easier for non-English speakers with quite
different linguistic models, but the benefit of adding statements as
expressions seems to me to be well less than the extra difficulty it would
produce.


(I've created several languages based on the Algol-68 model.

With more recent ones I've dropped that model, so that statements and 
expressions are different, and that is strictly enforced. This makes 
implementation simpler, and detects lots more errors.


The few statements that /were/ also useful as expressions, have 
separate, simplified, value-returning versions.)


--
Bartc
--
https://mail.python.org/mailman/listinfo/python-list


Re: Useless expressions [was Re: Undefined behaviour in C]

2016-03-28 Thread Marko Rauhamaa
BartC :

> So no matter how many potentially useful counter-examples you can dig
> up, non-function-call expressions are still going to be highly
> unusual. And suspect.
>
> That's why it's not going to be much loss to disallow them /in that
> form/.

Note that operators are front ends for dunder methods, which can have
side effects. I'm not aware of such an example in Python, but C++
notoriously uses operator overloading in its common I/O idioms:

   cout << "Hello world!" << endl;

It turns out that I am currently creating something exciting in Python
that "abuses" operators similarly, although without side effects -- I
hope to be able to present my results here soonish. So I would be
careful not to throw the baby away with the bathwater.

There was a time when recursion was viewed with great suspicion, and
nested if/else constructs were considered playing with fire. You are
clearly getting similar allergic reactions from Python's elegant degrees
of freedom. And all the while Java, C# and even C++ are painfully trying
to get what Python has had since the beginning.


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: List of Functions

2016-03-28 Thread Dan Sommers
On Mon, 28 Mar 2016 11:58:54 +0300, Marko Rauhamaa wrote:

> As for Python, I don't feel a great need for anonymous functions.
> However, I keep running into a need for anonymous classes, or, rather,
> classless objects. Not a biggie. I just create a one-off inner class
> and instantiate it, but I do appreciate Java's syntactic innovation.

And I always curse Java for having to create an inner class and a method
when all I need is a simple function.  :-)

I think it's Steven D'Aprano who keeps pointing out that you can always
name your tiny helper functions instead of using lambda:

def some_complex_function():
def f(x) = x + 2
some_library_that_wants_a_callback(f)
some_library_that_wants_a_callback(lambda x: x + 2)

Both calls to some_library_that_wants_a_callback run the same.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Statements as expressions [was Re: Undefined behaviour in C]

2016-03-28 Thread Paul Rubin
BartC  writes:
> With more recent ones I've dropped that model, so that statements and
> expressions are different, and that is strictly enforced. This makes
> implementation simpler, and detects lots more errors.

You should try Haskell, where there are only expressions, but the ones
that perform actions can be separated from the other ones through the
type system, so using one in the wrong place raises a compile time type
error.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Statements as expressions [was Re: Undefined behaviour in C]

2016-03-28 Thread Ben Bacarisse
BartC  writes:

> On 28/03/2016 01:54, Steven D'Aprano wrote:

>> What should be the return value of this statement?
>>
>> while True:
>>  x += 1
>>  if condition: break
>
> Many statements such as loops just returned 'void' in A68. The
> interesting statements were if, case-switch and block (where the value
> is that of the last statement/expression).

An alternative would be for a loop to return the last value of its
controlling expression.  This is usually false for a whole loop but
would be true is the loop was exited using break.  In a for loop, the
value would be the last value of its control variable.  This would again
permit you to tell a break from a normal for loop finishing.  This way
you can make the loop variable local and still use its final value
outside the loop.

Both would render some flag variables and some auxiliary variables
redundant though I've not seen a language that does it.  Maybe in
practice it does not work out so well, but it looked useful when I
sketch it out a while back.


-- 
Ben.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: List of Functions

2016-03-28 Thread Marko Rauhamaa
Dan Sommers :

> On Mon, 28 Mar 2016 11:58:54 +0300, Marko Rauhamaa wrote:
>
>> As for Python, I don't feel a great need for anonymous functions.
>> However, I keep running into a need for anonymous classes, or,
>> rather, classless objects. Not a biggie. I just create a one-off
>> inner class and instantiate it, but I do appreciate Java's syntactic
>> innovation.
>
> And I always curse Java for having to create an inner class and a
> method when all I need is a simple function. :-)
>
> I think it's Steven D'Aprano who keeps pointing out that you can
> always name your tiny helper functions instead of using lambda:
>
> def some_complex_function():
> def f(x) = x + 2
> some_library_that_wants_a_callback(f)
> some_library_that_wants_a_callback(lambda x: x + 2)
>
> Both calls to some_library_that_wants_a_callback run the same.

Yes, but I've come to realize that I quite often need more than a
function: I need an object with behavior. The solution is to use a
"helper" class.


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Useless expressions [was Re: Undefined behaviour in C]

2016-03-28 Thread BartC

On 28/03/2016 02:24, Steven D'Aprano wrote:

On Sun, 27 Mar 2016 10:31 pm, BartC wrote:



Whether there are side-effects is not quite as important as picking up
things that are likely to be errors:

f() # Probably OK
g() # Probably OK
f()+g() # Probably not OK


You don't and can't know what's "probably not" okay unless you know what
type of object both f and g return.

Don't think about floats and ints and strings. Think of complex objects with
operator overloading. You're probably thinking of `x + y`. Instead, think
of things like:

graph + node
database + table


There's theory, and there's practice.

Most types of statements start with a keyword.

The ones that don't need a keyword are assignments (including augmented 
assignment), and standalone expressions (I'm sure someone will correct 
me if I'm wrong).


And of standalone expressions, the vast majority that I can see are 
function calls (that is, an expression, of any complexity, ending with 
(...)).


So no matter how many potentially useful counter-examples you can dig 
up, non-function-call expressions are still going to be highly unusual. 
And suspect.


That's why it's not going to be much loss to disallow them /in that form/.

(There are also docstrings, but until yesterday I didn't even know they 
were also expressions. Wikipedia says this:


"Python docstrings appear as a string literal (not an expression) as the 
first statement following the definition of functions..."


so their status is a little unclear. Whatever it is, they don't lead to 
the same head-scratching when they appear as arbitrary expressions that 
are not function calls.)



in a procedural style instead of a functional style. With operator
overloading, we have the ability to write domain-specific little languages.


Sure. But give the reader a warning!

--
Bartc
--
https://mail.python.org/mailman/listinfo/python-list


Re: repeat items in a list

2016-03-28 Thread Rob Gaddi
beliav...@aol.com wrote:

> On Saturday, March 26, 2016 at 7:24:10 PM UTC-4, Erik wrote:
>> 
>> Or, if you want to "import operator" first, you can use 'operator.add' 
>> instead of the lambda (but you _did_ ask for a one-liner ;)).
>> 
>> Out of interest, why the fascination with one-liners?
>
> Thanks for your reply. Sometimes when I program in Python I think I am not 
> using the full capabilities of the language, so I want to know if there are
> more concise ways of doing things.

Concise is only worth so much.  PEP20 tells us "Explicit is better than
implicit", "Simple is better than complex" and "If the implementation is
hard to explain, it's a bad idea".

Python is a beautifully expressive language.  Your goal should not be to
write the minimum number of lines of code to accomplish the task. 
Your goal should be to write the code such that your grandmother can
understand it.  That way, when you screw it up, you'll be able to easily
figure out where and how you did so.  Or failing that, you can get
grangran to show you.

-- 
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order.  See above to fix.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Using python heredoc to substitute the external file read by python script.

2016-03-28 Thread Ben Finney
I don't understand what you're trying to do. But I think you have fixed
your problem:

Hongyi Zhao  writes:

> It seems the above code will do the job for me.

If I understand correctly this sentence, you now have a satisfactory
solution. Good!

-- 
 \ “A man must consider what a rich realm he abdicates when he |
  `\   becomes a conformist.” —Ralph Waldo Emerson |
_o__)  |
Ben Finney

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Useless expressions [was Re: Undefined behaviour in C]

2016-03-28 Thread Terry Reedy

On 3/27/2016 9:26 PM, Steven D'Aprano wrote:

On Mon, 28 Mar 2016 03:39 am, Terry Reedy wrote:



So Bart is proposing


whether 'actually' or 'hypothetically'


I don't think Bart is intending this as an actual proposal to change Python
so much as just a hypothetical to discuss.


I don't remember Bart saying anything of the sort.  I'll let him clarify 
hit meaning.



to either disable an extremely useful feature or
split Python into two slightly different dialects.  I think both are bad
ideas.


I don't think that's quite fair.


I don't think your strained nitpicking of my statement is quite fair. It 
is definitely faulty.



The interactive interpreter is already
slightly different from non-interactive use,


Yes, the extra behavior of interactive mode is specified in the 
Reference in the section on Expression statements.

https://docs.python.org/3/reference/simple_stmts.html#expression-statements
But as far as I can remember, both run the *SAME PYTHON LANGUAGE*. 
Dialects are a property of languages, not of interpreter modes.



in that bare expressions print the result,


Expressions evaluate to objects.  Having the interpreter also display 
the object is at most an added semantic.  It is not a syntax difference 
and in that sense is not a *language* difference*.



while in non-interactive use they just get garbage collected.


Garbage collection is not relevant to this proposal or discussion. 
AFAIK, Objects become eligible for garbage collection at the same time 
in either mode.



It wouldn't be that different to change "print versus ignore" into "print
versus raise error".


Are you serious?  Having the *same code* execute in one mode and raise 
in another, and thereby abort execution of all following code, is quite 
different.  It makes the set of legal statements different and that is 
the basic definition of a language.  It suite fair to call the different 
sets of legal statements 'slightly different dialects'.



I think it is a bit extreme to call that two different
dialects.


Your nitpicking is what is extreme.


If so, then the current interactive interpreter is also a
different dialect.


To repeat, the current interactive interpreter runs the same sequence of 
statements, which is to say, the same language.  It just outputs extra 
information about what is going on.  CPython debug builds display even 
more extra information (about references).


>>> 0
0
[44187 refs]
>>> a=0
[44189 refs]
>>> 0
0
[44189 refs]

This in itself does not mean that the debug interactive interpreter is 
yet a third dialect of Python.


--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list


Sending gmail with no clear password

2016-03-28 Thread zljubisicmob
Hi,

I have a python3 script that runs 24/7 on linux (raspberry pi) server. 
It would be very nice for the script to be able to send an email message about 
certain statuses.

As the linux server is headless, I don't have an option to key in the password 
while starting the script.
Furthermore, from time to time I restart the server remotely, so password 
should be somewhere in the system but kept more secure than hardcoded in the 
python script.

I understand that I can send email by using let's say procedure from the 
https://rajivpandit.wordpress.com/2013/09/19/how-to-send-email-by-python/

On the link above there are two approaches. One with no need for any 
authentication or password, but that approach doesn't work.
It is written for python 2 but that is what I need.

What are my options?

Regards.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why lambda in loop requires default?

2016-03-28 Thread Antoon Pardon
Op 27-03-16 om 03:46 schreef gvim:
> Given that Python, like Ruby, is an object-oriented language why doesn't this:

It has nothing to do with being object-oriented but by how scopes are used

> def m():
>   a = []
>   for i in range(3): a.append(lambda: i)
>   return a

Python doesn't create a new scope for the suite of the for loop. If you want an
intermediate scope, you have to provide it your self. Like the following.

def m():
a = []
for i in range(3):
a.append((lambda i: (lambda : i))(i))
return a

> b = m()
> for n in range(3): print(b[n]())  # =>  2  2  2
> 
> ... work the same as this in Ruby:
> 
> def m
>   a = []
>   (0..2).each {|i| a << ->(){i}}
>   a
> end

I don't know ruby but I guess the block creates a new scope and
thus running the block is like calling an anonymous function.
So the i in each run of the block is a new instantiation of the
variable instead of being the same variable.

-- 
Antoon Pardon

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Sending gmail with no clear password

2016-03-28 Thread Erik

Hi. It's hard to understand what your question is.

On 28/03/16 20:55, zljubisic...@gmail.com wrote:
> I have a python3 script that runs 24/7 on linux (raspberry pi)
> server. It would be very nice for the script to be able to send an
> email message about certain statuses.

Reading between the lines, am I correct in stating that:

1) You preferably want to send an email with no authentication at all.
2) If authentication is /required/ by the server you are contacting then 
you don't want the password to be stored in plain text.
3) The link you pasted does what you want (with no authentication), but 
it doesn't work in Python 3.



What are my options?


If I have understood you correctly, then the obvious thing is to convert 
the code in the link so that it works in Python 3.


If you can't do that and you need to use authentication, then there's 
only so much you can do to protect your password if you don't want to 
type it in.


Why can't the password be stored in plain text? Who are you trying to 
secure it from?


I suspect that the answer is that you can /obscure/ or /obfuscate/ the 
password (i.e., make it difficult to determine - encrypt it using some 
unique key that's obtained from the server's H/W somehow), but it would 
be very hard to actually /secure/ it from anyone with access to your 
Rpi. If your script can determine the password in plain text 
automatically (without some sort of external input), then so can anyone 
who has logged into the device with the appropriate permissions - if 
only by copying the script and making it display the password rather 
than send it to the server.


E.
--
https://mail.python.org/mailman/listinfo/python-list


Meta Data

2016-03-28 Thread Nick
Django has the idea of specifying models using typed Fields. 
The same exists within SQLAlchemy

Are there any tutorials on setting up a similar system.

ie. Declare classes and fields, query the meta data. Fields restricted to 
certain types. 

N.
-- 
https://mail.python.org/mailman/listinfo/python-list


Which are best, well-tested ways to create REST services, with Json, in Python?

2016-03-28 Thread David Shi via Python-list
Has anyone done a recent reviews of creating REST services, in Python?
Regards.
David
-- 
https://mail.python.org/mailman/listinfo/python-list


[newbie] tkFileDialog does not show title

2016-03-28 Thread jenswaelkens
I'm using the tkFileDialog-module in Python 2.7, it works fine except for one 
thing: when I add a title, the title isn't shown.

e.g. I have this line of code:
inputfilename=tkFileDialog.askopenfilename(defaultextension=".dat", 
filetypes=(("data file", "*.dat"),("All Files", "*.*") ),title='Select input 
file')

this works fine i.e. the file selector menu opens but I expected that the text
'Select input file' would be displayed too. Can anyone here explain me how I 
can achieve this?

kind regards,
Jens
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: repeat items in a list

2016-03-28 Thread Chris Angelico
On Tue, Mar 29, 2016 at 4:30 AM, Rob Gaddi
 wrote:
> beliav...@aol.com wrote:
>
>> On Saturday, March 26, 2016 at 7:24:10 PM UTC-4, Erik wrote:
>>>
>>> Or, if you want to "import operator" first, you can use 'operator.add'
>>> instead of the lambda (but you _did_ ask for a one-liner ;)).
>>>
>>> Out of interest, why the fascination with one-liners?
>>
>> Thanks for your reply. Sometimes when I program in Python I think I am not 
>> using the full capabilities of the language, so I want to know if there are
>> more concise ways of doing things.
>
> Concise is only worth so much.  PEP20 tells us "Explicit is better than
> implicit", "Simple is better than complex" and "If the implementation is
> hard to explain, it's a bad idea".
>
> Python is a beautifully expressive language.  Your goal should not be to
> write the minimum number of lines of code to accomplish the task.
> Your goal should be to write the code such that your grandmother can
> understand it.  That way, when you screw it up, you'll be able to easily
> figure out where and how you did so.  Or failing that, you can get
> grangran to show you.

Just out of interest, did you (generic you) happen to notice Mark's
suggestion? It's a one-liner that nicely expresses the intention and
accomplishes the goal:

yy = [aa for aa in xx for _ in range(nrep)]

It quietly went through without fanfare, but I would say this is the
perfect solution to the original problem.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: List of Functions

2016-03-28 Thread Chris Angelico
On Tue, Mar 29, 2016 at 12:40 AM, Marko Rauhamaa  wrote:
> Dan Sommers :
>
>> On Mon, 28 Mar 2016 11:58:54 +0300, Marko Rauhamaa wrote:
>>
>>> As for Python, I don't feel a great need for anonymous functions.
>>> However, I keep running into a need for anonymous classes, or,
>>> rather, classless objects. Not a biggie. I just create a one-off
>>> inner class and instantiate it, but I do appreciate Java's syntactic
>>> innovation.
>>
>> And I always curse Java for having to create an inner class and a
>> method when all I need is a simple function. :-)
>>
>> I think it's Steven D'Aprano who keeps pointing out that you can
>> always name your tiny helper functions instead of using lambda:
>>
>> def some_complex_function():
>> def f(x) = x + 2
>> some_library_that_wants_a_callback(f)
>> some_library_that_wants_a_callback(lambda x: x + 2)
>>
>> Both calls to some_library_that_wants_a_callback run the same.
>
> Yes, but I've come to realize that I quite often need more than a
> function: I need an object with behavior. The solution is to use a
> "helper" class.

Can you give an example of code that would benefit from a
"lambda-class" construct? Since all functions more complicated than
"return this expression" need statement syntax in Python, you'd be
pretty restricted in what you can do, so I'm thinking that maybe a
SimpleNamespace might suffice:

from types import SimpleNamespace
obj = SimpleNamespace(
add2=lambda x: x+2,
squared=lambda x: x*x,
)

But if "behaviour" involves mutable state, it'd be fiddly to squish
that into lambda functions, so a lambda class would be impractical
too.

What you could perhaps do is this:

def one_off(cls): return cls()

@one_off
class obj:
def func1(self):
...
def func2(self):
...

obj.func1()
obj.func2()

It's a statement, with all the costs and benefits thereof, but you
don't have to have "obj = obj()" at the end.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Meta Data

2016-03-28 Thread Joel Goldstick
There is information in Pro Django Models chapter that may be what you
want.  Pro Django, Apress, Marty Alchin

On Mon, Mar 28, 2016 at 4:49 PM, Nick  wrote:

> Django has the idea of specifying models using typed Fields.
> The same exists within SQLAlchemy
>
> Are there any tutorials on setting up a similar system.
>
> ie. Declare classes and fields, query the meta data. Fields restricted to
> certain types.
>
> N.
> --
> https://mail.python.org/mailman/listinfo/python-list
>



-- 
Joel Goldstick
http://joelgoldstick.com/ 
http://cc-baseballstats.info/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Meta Data

2016-03-28 Thread Nick
Thanks Joel, 

A quick look on Amazon shows it is probably relevant. 

N.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: repeat items in a list

2016-03-28 Thread Erik

On 28/03/16 22:25, Chris Angelico wrote:

Just out of interest, did you (generic you)  happen to notice Mark's
suggestion? It's a one-liner that nicely expresses the intention and
accomplishes the goal:

yy = [aa for aa in xx for _ in range(nrep)]

It quietly went through without fanfare, but I would say this is the
perfect solution to the original problem.


I noticed it (and I timed it - it was ~30% faster than my version 
(because mine was creating short transient list objects), but it takes a 
_LOT_ - millions - of iterations of the example case (nrep = 3, xx = 
two-element-list) to even make it measurable on my PC). It would have 
probably been even quicker if he'd cached the range() object.


I'm not convinced it's particularly intuitive, though. That trailing 
"for _ in range(nrep)" looks at first glance like an error - some code 
that's generating a value that is not referenced anywhere else.


It makes perfect sense when one analyses it, but it's not the most 
immediately grokkable construct.


Hmmm. It's almost as if in this instance I'd prefer something like:

  yy = [for aa in xx for _ in range(nrep): aa]

But I know we can't go /there/ ;)

E.
--
https://mail.python.org/mailman/listinfo/python-list


Re: [newbie] tkFileDialog does not show title

2016-03-28 Thread Wildman via Python-list
On Mon, 28 Mar 2016 14:10:28 -0700, jenswaelkens wrote:

> I'm using the tkFileDialog-module in Python 2.7, it works fine except for one 
> thing: when I add a title, the title isn't shown.
> 
> e.g. I have this line of code:
> inputfilename=tkFileDialog.askopenfilename(defaultextension=".dat", 
> filetypes=(("data file", "*.dat"),("All Files", "*.*") ),title='Select input 
> file')
> 
> this works fine i.e. the file selector menu opens but I expected that the text
> 'Select input file' would be displayed too. Can anyone here explain me how I 
> can achieve this?
> 
> kind regards,
> Jens

I copied and pasted your code into a test script and it worked
perfectly as it is.  Sorry but I don't have clue as where to look
for the problem.  Does text show elsewhere in your program such
as the main window titlebar, labels or buttons?  I'm thinking
maybe something to do with font or foreground color.  I'm just
guessing here...

-- 
 GNU/Linux user #557453
May the Source be with you.
-- 
https://mail.python.org/mailman/listinfo/python-list