Re: Meta decorator with parameters, defined in explicit functions

2016-07-01 Thread Lawrence D’Oliveiro
On Saturday, July 2, 2016 at 5:10:06 PM UTC+12, Ian wrote: > You should use functools.wraps instead of clobbering the decorated > function's name and docstring: Where am I doing that? > Just to satisfy my own curiosity, do you have something against > putting the return keyword and the returned ex

Re: Controlling the Mac OSX GUI via Python?

2016-07-01 Thread Christian Gollwitzer
Am 02.07.16 um 05:16 schrieb Lawrence D’Oliveiro: On Friday, July 1, 2016 at 4:59:11 PM UTC+12, Christian Gollwitzer wrote: Yes, simulating mouse clicks with fixed coordinates etc. is prone to such failure, but there are better methods. These mouse clicks and keyboard events usually trigger a me

Re: Meta decorator with parameters, defined in explicit functions

2016-07-01 Thread Ian Kelly
On Fri, Jul 1, 2016 at 11:32 PM, Ben Finney wrote: > Ian Kelly writes: > >> You should use functools.wraps instead of clobbering the decorated >> function's name and docstring: >> >> @functools.wraps(decorator) >> def decorate(*args, **kwargs): >> ... > > Thanks. Can y

Re: Meta decorator with parameters, defined in explicit functions

2016-07-01 Thread Ben Finney
Ian Kelly writes: > You should use functools.wraps instead of clobbering the decorated > function's name and docstring: > > @functools.wraps(decorator) > def decorate(*args, **kwargs): > ... Thanks. Can you write the full implementation with that, so I can be sure of

Re: Meta decorator with parameters, defined in explicit functions

2016-07-01 Thread Ian Kelly
On Fri, Jul 1, 2016 at 4:08 PM, Lawrence D’Oliveiro wrote: > On Tuesday, June 28, 2016 at 5:03:08 PM UTC+12, Ben Finney wrote: >> There is a clever one-line decorator that has been copy-pasted without >> explanation in many code bases for many years:: >> >> decorator_with_args = lambda decorat

View committed code via gitpython

2016-07-01 Thread Jason Bailey
Hi all, I'm trying to essentially replicate "gift grep" functionality with gitpython and am not quite sure how to pull the committed code from the repo using gitpython. I am successfully listing all the commits, so now all I need to do is view the code in each commit to do some regex matching o

View committed code via gitpython

2016-07-01 Thread Jason Bailey
Hi all, I'm trying to essentially replicate "gift grep" functionality with gitpython and am not quite sure how to pull the committed code from the repo using gitpython. I am successfully listing all the commits, so now all I need to do is view the code in each commit to do some regex matching o

Re: Namespaces are one honking great idea

2016-07-01 Thread Random832
On Fri, Jul 1, 2016, at 21:50, Kevin Conway wrote: > I believe the namespace object you are referring to is exactly a > class. IIRC, classes came about as a "module in a module". No, because classes have instances. And conceptually they seem like they *should* have instances. Just using the term "

Re: Descriptor: class name precedence over instance name

2016-07-01 Thread Ben Finney
"Veek. M" writes: > Trying to make sense of this para: At the risk of being ruse, I am trying to make sense of some paragraphs in the messages you write here. Could you take a little more time to write clearly, as a way of communicating in this forum? > Is he say that Descriptors are a special

Re: Descriptor: class name precedence over instance name

2016-07-01 Thread Ian Kelly
On Fri, Jul 1, 2016 at 10:27 PM, Veek. M wrote: > Trying to make sense of this para: > > -- > Also, the attribute name used by the class to hold a descriptor takes > prece- dence over attributes stored on instances. > > In the previous example, > thi

Descriptor: class name precedence over instance name

2016-07-01 Thread Veek. M
Trying to make sense of this para: -- Also, the attribute name used by the class to hold a descriptor takes prece- dence over attributes stored on instances. In the previous example, this is why the descriptor object takes a name parameter and why

Re: problem using pickle

2016-07-01 Thread Ben Finney
"Veek. M" writes: > class Foo(object): > pass > > object is a keyword and you're using it as an identifier Python does not have ‘object’ as a keyword. ‘and’ is a keyword. Here's the difference:: >>> object >>> object = "Lorem ipsum" >>> object 'Lorem ipsum' >>> and

JAR files into python

2016-07-01 Thread Joaquin Alzola
Hi Guys I have the following script which will be used in Spark. #!/usr/bin/env python3 from pyspark_cassandra import CassandraSparkContext, Row from pyspark import SparkContext, SparkConf from pyspark.sql import SQLContext import os os.environ['CLASSPATH']="/mnt/spark/lib" conf = SparkConf().se

Re: problem using pickle

2016-07-01 Thread Rustom Mody
On Saturday, July 2, 2016 at 9:17:01 AM UTC+5:30, Veek. M wrote: > object is a keyword and you're using it as an identifier keyword and builtin are different In this case though the advice remains the same In general maybe not... Just sayin' -- https://mail.python.org/mailman/listinfo/python-list

Re: problem using pickle

2016-07-01 Thread Veek. M
Nicky Mac wrote: > Dear Python team, > I have studied the excellent documentation, and attempted to make use > of pickle thus: > > filename = 'my_saved_adventure' > import pickle > class object: > def __init__(self,i,.t) : > self.id = i > . > > class world

Re: subprocess startup error

2016-07-01 Thread Veek. M
Shweta Dinnimani wrote: > hi > > hello, I'm begineer to python programming.. I had installed python > 3.5.1 version on my windows 7 system. I was fine earlier and now when > i was trying the programs on string i'm facing the subprocess startup > error. IDLE is not connecting. And python shell is

Re: why x is changed in the following program?

2016-07-01 Thread Veek. M
maurice.char...@telecom-paristech.fr wrote: > from numpy import random > x=random.randn(6) > y=x > y[0]=12 > print x[0] > > > random.rand returns a list. x is a label to this list (container). y=x creates another label to the same container/list. y[0[ = 12 alters the 0th position of the conta

Re: Controlling the Mac OSX GUI via Python?

2016-07-01 Thread Lawrence D’Oliveiro
On Friday, July 1, 2016 at 4:59:11 PM UTC+12, Christian Gollwitzer wrote: > Yes, simulating mouse clicks with > fixed coordinates etc. is prone to such failure, but there are better > methods. These mouse clicks and keyboard events usually trigger a method > call inside the GUI program. If there

Re: Namespaces are one honking great idea

2016-07-01 Thread Lawrence D’Oliveiro
On Saturday, July 2, 2016 at 1:50:56 PM UTC+12, Kevin Conway wrote: > Regardless, all use cases you've listed are already satisfied by use of the > static and class method decorators. Except for the need to decorate every such function inside the class. How about: import types def namesp

Re: Namespaces are one honking great idea

2016-07-01 Thread Rustom Mody
On Friday, July 1, 2016 at 8:19:36 PM UTC+5:30, BartC wrote: > On 01/07/2016 15:13, Steven D'Aprano wrote: > > > Sometimes we have a group of related functions and variables that belong > > together, but are not sufficiently unrelated to the rest of the module that > > we want to split them out in

Re: Fear and suspicion of lambdas, was Re: Meta decorator with parameters, defined in explicit functions

2016-07-01 Thread Ben Finney
Ben Bacarisse writes: > By replying I'm not accepting the premise -- I have no idea if there > is widespread fear and suspicion of lambdas among Python users but it > seems unlikely. I can testify, as the person who started this thread, that there is no fear or suspicion of lambda here. I use it

Re: Namespaces are one honking great idea

2016-07-01 Thread Kevin Conway
I believe the namespace object you are referring to is exactly a class. IIRC, classes came about as a "module in a module". Regardless, all use cases you've listed are already satisfied by use of the static and class method decorators. Methods decorated with these do not require an instance initia

Re: Namespaces are one honking great idea

2016-07-01 Thread Steven D'Aprano
On Sat, 2 Jul 2016 05:29 am, Ethan Furman wrote: > On 07/01/2016 10:10 AM, Steven D'Aprano wrote: >> On Sat, 2 Jul 2016 02:00 am, Ethan Furman wrote: > >>> Did you mean for this to go to -Ideas? >> >> Not yet. I wanted some initial feedback to see if anyone else liked the >> idea before taking it

Re: Meta decorator with parameters, defined in explicit functions

2016-07-01 Thread Lawrence D’Oliveiro
On Tuesday, June 28, 2016 at 5:03:08 PM UTC+12, Ben Finney wrote: > There is a clever one-line decorator that has been copy-pasted without > explanation in many code bases for many years:: > > decorator_with_args = lambda decorator: lambda *args, **kwargs: lambda > func: decorator(func, *args

Re: Fear and suspicion of lambdas, was Re: Meta decorator with parameters, defined in explicit functions

2016-07-01 Thread Ben Bacarisse
dieter writes: >> Lawrence D’Oliveiro wrote: >>> I don’t know why this fear and suspicion of lambdas is so widespread among >>> Python users ... former Java/C# programmers, perhaps? By replying I'm not accepting the premise -- I have no idea if there is widespread fear and suspicion of lambdas

Re: Namespaces are one honking great idea

2016-07-01 Thread Ethan Furman
On 07/01/2016 10:10 AM, Steven D'Aprano wrote: On Sat, 2 Jul 2016 02:00 am, Ethan Furman wrote: Did you mean for this to go to -Ideas? Not yet. I wanted some initial feedback to see if anyone else liked the idea before taking it to Bikeshedding Central :-) Besides, I expect Python-Ideas wil

Re: Need help in python program

2016-07-01 Thread Christian Gollwitzer
Am 01.07.16 um 12:26 schrieb Archana Sonavane: Hello Everyone, I am doing python code by using API. My first API giving fields - Itemid, clock and value second API giving fields - Itemid, key, units and delay using for loops for both API. Could you please tell me how to compare both id by usi

Re: Need help in python program

2016-07-01 Thread Bob Gailer
On Jul 1, 2016 6:30 AM, "Archana Sonavane" wrote: > > Hello Everyone, > > I am doing python code by using API. > > My first API giving fields - Itemid, clock and value > second API giving fields - Itemid, key, units and delay > > using for loops for both API. > > Could you please tell me how to co

Re: what the heck this code is doing?

2016-07-01 Thread Basant Dagar
Awesome. Thank you John for the prompt response. -- https://mail.python.org/mailman/listinfo/python-list

Re: what the heck this code is doing?

2016-07-01 Thread Basant Dagar
On Friday, July 1, 2016 at 2:06:28 PM UTC-4, John Gordon wrote: > In <3bbddafc-dcd6-4d5c-84f4-94077b5bc...@googlegroups.com> Basant Dagar > writes: > > > def lookup(d, keyval): > > found = False > > for child in d: > > if found : return child.text > > if child.tag == 'key

Re: what the heck this code is doing?

2016-07-01 Thread John Gordon
In <3bbddafc-dcd6-4d5c-84f4-94077b5bc...@googlegroups.com> Basant Dagar writes: > def lookup(d, keyval): > found = False > for child in d: > if found : return child.text > if child.tag == 'key' and child.text == keyval : > found = True > return None > tra

what the heck this code is doing?

2016-07-01 Thread Basant Dagar
#See below code: def lookup(d, keyval): found = False for child in d: if found : return child.text if child.tag == 'key' and child.text == keyval : found = True return None trackID = lookup(entry, 'Track ID') Below is the main part of input xml file data

Re: Namespaces are one honking great idea

2016-07-01 Thread Steven D'Aprano
On Sat, 2 Jul 2016 12:49 am, BartC wrote: > On 01/07/2016 15:13, Steven D'Aprano wrote: > >> Sometimes we have a group of related functions and variables that belong >> together, but are not sufficiently unrelated to the rest of the module >> that we want to split them out into another file. > >

Re: Creating a calculator

2016-07-01 Thread Jussi Piitulainen
Steven D'Aprano writes: > 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 needed to work around the

Re: Namespaces are one honking great idea

2016-07-01 Thread Steven D'Aprano
On Sat, 2 Jul 2016 02:00 am, Ethan Furman wrote: > On 07/01/2016 07:13 AM, Steven D'Aprano wrote: > > I like the idea, but I have a couple questions about the design choices. Thanks! > Comments below. [...] >> Despite the "class" statement (a limitation of Python's lack of dedicated >> synt

Re: Namespaces are one honking great idea

2016-07-01 Thread Chris Angelico
On Sat, Jul 2, 2016 at 12:49 AM, BartC wrote: > Why not just extend the capabilities of a class? I actually thought this > would work until I tried it and it didn't: > > class C(): > def fn(): > print ("Hi!") > > C.fn() > > The error message suggests Python knows what's going on. So wh

[ANN] pygcgen (github changelog generator)

2016-07-01 Thread topic2k--- via Python-list
Hello, maybe you know "GitHub Changelog Generator" (https://github.com/skywinder/github-changelog-generator). As i came across it, i liked to try it, but wasn't able to get it running. The script is written in Ruby. As i don't know Ruby, i had the idea to convert it to Python. After a few days

Re: Namespaces are one honking great idea

2016-07-01 Thread Ethan Furman
On 07/01/2016 07:13 AM, Steven D'Aprano wrote: I like the idea, but I have a couple questions about the design choices. Comments below. The Zen of Python says: Namespaces are one honking great idea -- let's do more of those! Proposal = Add a new "namespace" object to Python

Re: Can math.atan2 return INF?

2016-07-01 Thread Marko Rauhamaa
Rustom Mody : > There are other more reasonable non-religious non-dualistic notions of > soul possible: Software engineers should have an easy time understanding what a soul is: a sufficiently sophisticated software system in execution. I'd say the minimum requirement for a soul is the capacity t

Re: Creating a calculator

2016-07-01 Thread Christopher Reimer
> On Jul 1, 2016, at 6:52 AM, Steven D'Aprano wrote: > >> 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

Re: Namespaces are one honking great idea

2016-07-01 Thread BartC
On 01/07/2016 15:13, Steven D'Aprano wrote: Sometimes we have a group of related functions and variables that belong together, but are not sufficiently unrelated to the rest of the module that we want to split them out into another file. Here's a proof of concept. I use a class with a custom

Re: Namespaces are one honking great idea

2016-07-01 Thread Random832
On Fri, Jul 1, 2016, at 10:13, Steven D'Aprano wrote: > The biggest limitation is that I have to abuse the class statement to do > this. In an ideal world, there would be syntactic support and a keyword: > > namespace Example: > x = 0 > y = [] > def test(n): ... > > al

Re: Creating a calculator

2016-07-01 Thread alister
On Fri, 01 Jul 2016 23:52:45 +1000, Steven D'Aprano wrote: > 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/excep

super and mix-in class: how exactly is the search order altered?

2016-07-01 Thread Veek. M
I had posted this on StackOverflow - it's an excellent example of why SO sucks (don't want that happening here so please read carefully): http://stackoverflow.com/questions/38145818/super-and-mix-in-class-how-exactly-is-the-search-order-altered?noredirect=1#comment63722336_38145818 I'm reading

Re: Can math.atan2 return INF?

2016-07-01 Thread Rustom Mody
On Thursday, June 30, 2016 at 11:33:58 PM UTC+5:30, Steven D'Aprano wrote: > On Fri, 1 Jul 2016 01:28 am, Rustom Mody wrote: > > > On Thursday, June 30, 2016 at 1:55:18 PM UTC+5:30, Steven D'Aprano wrote: > > > >> you state that Turing "believes in souls" and that he "wishes to > >> put the soul

Namespaces are one honking great idea

2016-07-01 Thread Steven D'Aprano
The Zen of Python says: Namespaces are one honking great idea -- let's do more of those! Proposal = Add a new "namespace" object to Python. Rationale == Sometimes we have a group of related functions and variables that belong together, but are not sufficiently unrelated

Re: Creating a calculator

2016-07-01 Thread 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 needed to work around the crash. A later line of code > wil

Re: Creating a calculator

2016-07-01 Thread Jussi Piitulainen
Christopher Reimer writes: >> On Jul 1, 2016, at 5:46 AM, Jussi Piitulainen wrote: >> >> Christopher Reimer writes: >> >>> For my BASIC interpreter, each line of BASIC is broken this way into >>> tokens. >>> >>> line_number, keyword, *expression = line.split(' ', 2) >>> >>> For a line like 10

Re: Creating a calculator

2016-07-01 Thread Christopher Reimer
> On Jul 1, 2016, at 5:46 AM, Jussi Piitulainen > wrote: > > Christopher Reimer writes: > >> For my BASIC interpreter, each line of BASIC is broken this way into >> tokens. >> >> line_number, keyword, *expression = line.split(' ', 2) >> >> For a line like 10 PRINT "HELLO, WORLD!", this works

Re: Creating a calculator

2016-07-01 Thread Pierre-Alain Dorange
Chris Warrick wrote: > > More reduced : > > -- > > u=raw_input('Enter calculation:") > > print eval(u) > > -- > > works and compute : > > 1+2+3+4-1+4*2 > > 2+3.0/2-0.5 > > > > Perform better and shorter, but less educationnal of cour

Re: Creating a calculator

2016-07-01 Thread Jussi Piitulainen
Christopher Reimer writes: > For my BASIC interpreter, each line of BASIC is broken this way into > tokens. > > line_number, keyword, *expression = line.split(' ', 2) > > For a line like 10 PRINT "HELLO, WORLD!", this works as expected. > > For a line like 20 END, which doesn't have a third elemen

Re: Creating a calculator

2016-07-01 Thread Christopher Reimer
> On Jun 30, 2016, at 11:42 PM, Jussi Piitulainen > wrote: > > DFS writes: > >> Here's a related program that doesn't require you to tell it what type >> of operation to perform. Just enter 'num1 operator num2' and hit >> Enter, and it will parse the entry and do the math. >> >> -

Re: Creating a calculator

2016-07-01 Thread Chris Warrick
On 1 July 2016 at 11:34, Pierre-Alain Dorange wrote: > DFS wrote: > >> Here's a related program that doesn't require you to tell it what type >> of operation to perform. Just enter 'num1 operator num2' and hit Enter, >> and it will parse the entry and do the math. >> >> -

Need help in python program

2016-07-01 Thread Archana Sonavane
Hello Everyone, I am doing python code by using API. My first API giving fields - Itemid, clock and value second API giving fields - Itemid, key, units and delay using for loops for both API. Could you please tell me how to compare both id by using equal operator. My output should be : Item

Re: Creating a calculator

2016-07-01 Thread Pierre-Alain Dorange
DFS wrote: > Here's a related program that doesn't require you to tell it what type > of operation to perform. Just enter 'num1 operator num2' and hit Enter, > and it will parse the entry and do the math. > > --- > ui=raw_input('Enter calculation to p

Re: Creating a calculator

2016-07-01 Thread Chris Warrick
On 1 July 2016 at 05:08, Elizabeth Weiss wrote: > while True: > print("Options:") > print("Enter 'add' to add two numbers") > print("Enter 'subtract' to subtract two numbers") > print("Enter 'multiply' to multiply two numbers") > print("Enter 'divide' to div

Re: Fear and suspicion of lambdas, was Re: Meta decorator with parameters, defined in explicit functions

2016-07-01 Thread dieter
Peter Otten <__pete...@web.de> writes: > Lawrence D’Oliveiro wrote: > >> On Tuesday, June 28, 2016 at 5:03:08 PM UTC+12, Ben Finney wrote: >> >>> I would like to see a more Pythonic, more explicit and expressive >>> replacement with its component parts easily understood. >> >> I don’t know why t