Problem to calculate the mean in version 3.4

2015-09-24 Thread Michel Guirguis
Good morning, I have downloaded the version 3.4 and I have a problem to calculate the mean. The software does not recognise the function mean(). I am getting the following error. >>> mean([1, 2, 3, 4, 4]) Traceback (most recent call last): File "", line 1, in mean([1, 2, 3, 4, 4]) NameEr

Re: Modifying signature of ctor in class

2015-09-24 Thread gal kauffman
Sorry, you really can't give FunctionType an argument list. Maybe you can wrap the function with a callable object, this way you can change the argument list returned, and doest have to eval or compile code. On Sep 25, 2015 12:46 AM, "Joseph L. Casale" wrote: > > I don't think you can easily chan

Re: Modifying signature of ctor in class

2015-09-24 Thread gal kauffman
You can use the FunctionType class found in the types module (and its friends) to create functions on the run. And you can use the 'inspect' module to inspect existing functions, if you need to base the new function on an existing one. On Sep 24, 2015 11:28 PM, "Joseph L. Casale" wrote: > I have

Re: ConnectionError handling problem

2015-09-24 Thread shiva upreti
On Friday, September 25, 2015 at 10:55:45 AM UTC+5:30, Cameron Simpson wrote: > On 24Sep2015 20:57, shiva upreti wrote: > >Thank you Cameron. > >I think the problem with my code is that it just hangs without raising any > >exceptions. And as mentioned by Laura above that when I press CTRL+C, it

Re: ConnectionError handling problem

2015-09-24 Thread shiva upreti
On Thursday, September 24, 2015 at 4:09:04 PM UTC+5:30, Laura Creighton wrote: > In a message of Wed, 23 Sep 2015 19:49:17 -0700, shiva upreti writes: > >Hi > >If my script hangs because of the reasons you mentioned above, why doesnt it > >catch ConnectionError? > >My script stops for a while and

Re: ConnectionError handling problem

2015-09-24 Thread shiva upreti
On Thursday, September 24, 2015 at 4:09:04 PM UTC+5:30, Laura Creighton wrote: > In a message of Wed, 23 Sep 2015 19:49:17 -0700, shiva upreti writes: > >Hi > >If my script hangs because of the reasons you mentioned above, why doesnt it > >catch ConnectionError? > >My script stops for a while and

Re: ConnectionError handling problem

2015-09-24 Thread Cameron Simpson
On 24Sep2015 20:57, shiva upreti wrote: Thank you Cameron. I think the problem with my code is that it just hangs without raising any exceptions. And as mentioned by Laura above that when I press CTRL+C, it just catches that exception and prints ConnectionError which is definitely a lie in th

Re: ConnectionError handling problem

2015-09-24 Thread shiva upreti
Thank you Cameron. I think the problem with my code is that it just hangs without raising any exceptions. And as mentioned by Laura above that when I press CTRL+C, it just catches that exception and prints ConnectionError which is definitely a lie in this case as you mentioned. As my code doesnt

Re: ConnectionError handling problem

2015-09-24 Thread shiva upreti
Thank you. I didnt know about keyboard interrupt exception. It means my code hangs without raising any exceptions, what should i do in this case? -- https://mail.python.org/mailman/listinfo/python-list

Re: Idiosyncratic python

2015-09-24 Thread Steven D'Aprano
On Thu, 24 Sep 2015 04:54 pm, Ben Finney wrote: > Steven D'Aprano writes: > >> On Thursday 24 September 2015 16:16, Paul Rubin wrote: >> >> > Steven D'Aprano writes: >> >> for k, v in mydict.items(): >> >> del(k) >> >> […] The obvious intent is to iterate over the *values* of the >> diction

Re: Idiosyncratic python

2015-09-24 Thread Steven D'Aprano
On Fri, 25 Sep 2015 06:46 am, Ned Batchelder wrote: > On Thursday, September 24, 2015 at 2:02:38 AM UTC-4, Steven D'Aprano > wrote: >> What are your favorite not-wrong-just-weird Python moments? > > I've seen this a number of times: > > dict_of_values.update({'key': some_value}) > > why not

Re: ConnectionError handling problem

2015-09-24 Thread Cameron Simpson
On 24Sep2015 12:38, Laura Creighton wrote: In a message of Wed, 23 Sep 2015 19:49:17 -0700, shiva upreti writes: If my script hangs because of the reasons you mentioned above, why doesnt it catch ConnectionError? My script stops for a while and when I press CTRL+C, it shows ConnectionError wi

Re: Idiosyncratic python

2015-09-24 Thread Steven D'Aprano
On Fri, 25 Sep 2015 02:54 am, Todd wrote: > Using list indexing with booleans in place of a ternary operator. > > a = False > b = [var2, var1][a] > > Instead of: > > b = var1 if a else var2 Ah, you youngsters... :-) Using a bool to index into a list used to be the standard idiom, before the

Re: Idiosyncratic python

2015-09-24 Thread Akira Li
Mark Lawrence writes: > On 24/09/2015 07:02, Steven D'Aprano wrote: >> I was looking at an in-house code base today, and the author seems to have a >> rather idiosyncratic approach to Python. For example: >> >> for k, v in mydict.items(): >> del(k) >> ... >> >> instead of the more obvio

Re: Idiosyncratic python

2015-09-24 Thread Mark Lawrence
On 24/09/2015 07:02, Steven D'Aprano wrote: I was looking at an in-house code base today, and the author seems to have a rather idiosyncratic approach to Python. For example: for k, v in mydict.items(): del(k) ... instead of the more obvious for v in mydict.values(): ... What a

Re: Modifying signature of ctor in class

2015-09-24 Thread Ian Kelly
On Thu, Sep 24, 2015 at 5:01 PM, Joseph L. Casale wrote: >> py> from inspect import Signature, Parameter >> py> def foo(*args, **kwargs): pass >> ... >> py> foo.__signature__ = Signature([Parameter('x', >> Parameter.POSITIONAL_OR_KEYWORD), Parameter('y', >> Parameter.KEYWORD_ONLY)]) >> py> help(fo

Re: Modifying signature of ctor in class

2015-09-24 Thread Joseph L. Casale
> py> from inspect import Signature, Parameter > py> def foo(*args, **kwargs): pass > ... > py> foo.__signature__ = Signature([Parameter('x', > Parameter.POSITIONAL_OR_KEYWORD), Parameter('y', > Parameter.KEYWORD_ONLY)]) > py> help(foo) > Help on function foo in module __main__: > > foo(x, *, y)

Re: Idiosyncratic python

2015-09-24 Thread sohcahtoa82
On Wednesday, September 23, 2015 at 11:02:38 PM UTC-7, Steven D'Aprano wrote: > I was looking at an in-house code base today, and the author seems to have a > rather idiosyncratic approach to Python. For example: > > > for k, v in mydict.items(): > del(k) > ... > > > instead of the mo

Re: Modifying signature of ctor in class

2015-09-24 Thread Chris Angelico
On Fri, Sep 25, 2015 at 8:19 AM, Ian Kelly wrote: > Quick and dirty example: > > py> from inspect import Signature, Parameter > py> def foo(*args, **kwargs): pass > ... > py> foo.__signature__ = Signature([Parameter('x', > Parameter.POSITIONAL_OR_KEYWORD), Parameter('y', > Parameter.KEYWORD_ONLY)]

Re: Modifying signature of ctor in class

2015-09-24 Thread Ian Kelly
On Thu, Sep 24, 2015 at 4:10 PM, Ian Kelly wrote: > On Thu, Sep 24, 2015 at 2:28 PM, Joseph L. Casale > wrote: >> I have a class factory where I dynamically add a constructor to the class >> output. >> The method is a closure and works just fine, however to accommodate the >> varied >> input it

Re: Modifying signature of ctor in class

2015-09-24 Thread Ian Kelly
On Thu, Sep 24, 2015 at 2:28 PM, Joseph L. Casale wrote: > I have a class factory where I dynamically add a constructor to the class > output. > The method is a closure and works just fine, however to accommodate the varied > input its signature is (*args, **kwargs). > > While I modify the doc st

Re: Modifying signature of ctor in class

2015-09-24 Thread Chris Angelico
On Fri, Sep 25, 2015 at 7:45 AM, Joseph L. Casale wrote: >> I don't think you can easily change the function's own definition, >> other than by using eval (or equivalent shenanigans, like crafting >> your own bytecode); but as of Python 3.something, the help() function >> looks for a __wrapped__ a

Re: Idiosyncratic python

2015-09-24 Thread Chris Angelico
On Fri, Sep 25, 2015 at 7:08 AM, Laura Creighton wrote: > In a message of Thu, 24 Sep 2015 13:46:27 -0700, Ned Batchelder writes: >>On Thursday, September 24, 2015 at 2:02:38 AM UTC-4, Steven D'Aprano wrote: >>> What are your favorite not-wrong-just-weird Python moments? >> >>I've seen this a numb

Re: Modifying signature of ctor in class

2015-09-24 Thread Joseph L. Casale
> I don't think you can easily change the function's own definition, > other than by using eval (or equivalent shenanigans, like crafting > your own bytecode); but as of Python 3.something, the help() function > looks for a __wrapped__ attribute and will take function args from > that instead of th

Re: Modifying signature of ctor in class

2015-09-24 Thread Joseph L. Casale
> You can use the FunctionType class found in the types module (and its > friends) to create functions on the run. > And you can use the 'inspect' module to inspect existing functions, if you > need to base the new function on an existing one. Hi Gal, Seems the types module docs do not even have

Re: Modifying signature of ctor in class

2015-09-24 Thread Chris Angelico
On Fri, Sep 25, 2015 at 6:28 AM, Joseph L. Casale wrote: > I have a class factory where I dynamically add a constructor to the class > output. > The method is a closure and works just fine, however to accommodate the varied > input its signature is (*args, **kwargs). > > While I modify the doc st

Re: Idiosyncratic python

2015-09-24 Thread Laura Creighton
In a message of Thu, 24 Sep 2015 13:46:27 -0700, Ned Batchelder writes: >On Thursday, September 24, 2015 at 2:02:38 AM UTC-4, Steven D'Aprano wrote: >> What are your favorite not-wrong-just-weird Python moments? > >I've seen this a number of times: > >dict_of_values.update({'key': some_value})

Re: Idiosyncratic python

2015-09-24 Thread Ned Batchelder
On Thursday, September 24, 2015 at 2:02:38 AM UTC-4, Steven D'Aprano wrote: > What are your favorite not-wrong-just-weird Python moments? I've seen this a number of times: dict_of_values.update({'key': some_value}) why not: dict_of_values['key'] = some_value I've considered writing a P

Re: Learning Modules, Arguments, Parameters (imma noob)

2015-09-24 Thread Larry Hudson via Python-list
On 09/24/2015 11:45 AM, codyw...@gmail.com wrote: I seem to be having a problem understanding how arguments and parameters work, Most likely why my code will not run. Can anyone elaborate on what I am doing wrong? ''' Cody Cox 9/16/2015 Programming Exercise 1 - Kilometer Converter Design a modu

Modifying signature of ctor in class

2015-09-24 Thread Joseph L. Casale
I have a class factory where I dynamically add a constructor to the class output. The method is a closure and works just fine, however to accommodate the varied input its signature is (*args, **kwargs). While I modify the doc strings, the ctor sig is not optimal. Without building this a string an

Re: Idiosyncratic python

2015-09-24 Thread Mark Lawrence
On 24/09/2015 18:50, Laurent Pointal wrote: wxjmfa...@gmail.com wrote: Le jeudi 24 septembre 2015 08:02:38 UTC+2, Steven D'Aprano a écrit : What are your favorite not-wrong-just-weird Python moments? Showing how to make Python 3.5.0 crash by just using an "é", U+00E9. Would you like to

Re: Learning Modules, Arguments, Parameters (imma noob)

2015-09-24 Thread John Gordon
In <7ad8941d-04aa-42c5-82e9-10cdf02ab...@googlegroups.com> codyw...@gmail.com writes: > I seem to be having a problem understanding how arguments and parameters > work, Most likely why my code will not run. Can anyone elaborate on what > I am doing wrong? > def get_input(kilo): >kilo = floa

Re: Learning Modules, Arguments, Parameters (imma noob)

2015-09-24 Thread MRAB
On 2015-09-24 19:45, codyw...@gmail.com wrote: I seem to be having a problem understanding how arguments and parameters work, Most likely why my code will not run. Can anyone elaborate on what I am doing wrong? ''' Cody Cox 9/16/2015 Programming Exercise 1 - Kilometer Converter Design a modular

Re: Learning Modules, Arguments, Parameters (imma noob)

2015-09-24 Thread Joel Goldstick
On Thu, Sep 24, 2015 at 2:45 PM, wrote: > I seem to be having a problem understanding how arguments and parameters > work, Most likely why my code will not run. > Can anyone elaborate on what I am doing wrong? > > ''' > Cody Cox > 9/16/2015 > Programming Exercise 1 - Kilometer Converter > Design

Learning Modules, Arguments, Parameters (imma noob)

2015-09-24 Thread codywcox
I seem to be having a problem understanding how arguments and parameters work, Most likely why my code will not run. Can anyone elaborate on what I am doing wrong? ''' Cody Cox 9/16/2015 Programming Exercise 1 - Kilometer Converter Design a modular program that asks the user to enter a distance

Re: Idiosyncratic python

2015-09-24 Thread Todd
On Sep 24, 2015 18:59, "Chris Angelico" wrote: > > On Fri, Sep 25, 2015 at 2:54 AM, Todd wrote: > > Using list indexing with booleans in place of a ternary operator. > > > > a = False > > b = [var2, var1][a] > > > > Instead of: > > > > b = var1 if a else var2 > > Be careful - these are not semant

Re: Idiosyncratic python

2015-09-24 Thread Ian Kelly
On Thu, Sep 24, 2015 at 12:04 PM, jmp wrote: > I'm not an expert but I think this "return by value thing" is only for C++. > In vintage C, you can only return something that fits within a register. If that was true at one time, it was before ANSI C. $ cat test.c #include struct foo { int a;

Re: Idiosyncratic python

2015-09-24 Thread jmp
On 09/24/2015 04:26 PM, Ian Kelly wrote: On Thu, Sep 24, 2015 at 8:07 AM, jmp wrote: result = getResult() For the later, the original weird form come from a C habit to allocate returned structures within the caller and provide a pointer to it so the function can fill the data in, otherwise the

Re: Idiosyncratic python

2015-09-24 Thread Laurent Pointal
wxjmfa...@gmail.com wrote: > Le jeudi 24 septembre 2015 08:02:38 UTC+2, Steven D'Aprano a écrit : >> >> >> What are your favorite not-wrong-just-weird Python moments? >> >> > Showing how to make Python 3.5.0 crash by > just using an "é", U+00E9. Like this ? Python 3.5.0 (default, Sep 24 201

Re: Idiosyncratic python

2015-09-24 Thread Chris Angelico
On Fri, Sep 25, 2015 at 2:54 AM, Todd wrote: > Using list indexing with booleans in place of a ternary operator. > > a = False > b = [var2, var1][a] > > Instead of: > > b = var1 if a else var2 Be careful - these are not semantically identical. The first one evaluates both var1 and var2, while the

Re: Idiosyncratic python

2015-09-24 Thread Todd
Using list indexing with booleans in place of a ternary operator. a = False b = [var2, var1][a] Instead of: b = var1 if a else var2 On Sep 24, 2015 8:06 AM, "Steven D'Aprano" < steve+comp.lang.pyt...@pearwood.info> wrote: > I was looking at an in-house code base today, and the author seems to h

Re: Python, convert an integer into an index?

2015-09-24 Thread Lorenzo Sutton
On 23/09/2015 17:32, Denis McMahon wrote: On Tue, 22 Sep 2015 14:43:55 -0700, Chris Roberts wrote: results = 134523 #(Integer) This appears to be an integer expressed (presumably) in base 10 with 6 digits Desired: results = [1, 2, 3, 4, 5, 2, 3] #(INDEX) This appears to be a pyth

Re: Re: Installing pywin32.

2015-09-24 Thread Zachary Ware
Two notes about local etiquette: 1) Please reply to the list rather than to me directly. I only include your address in the cc: in case you aren't subscribed (which you should be, unless you're reading via the newsgroup), since I don't recognize you as a regular poster. I'll soon stop doing so.

Re: Installing pywin32.

2015-09-24 Thread Zachary Ware
On Thu, Sep 24, 2015 at 8:58 AM, wrote: > Hi Sir/Madam > > > When I try to run my python program where I am using the pywin32 module I am > getting the error as win32api module not found so how to install this module > please let me know ASP. Have you already installed or tried to install pywin3

Re: Python, convert an integer into an index?

2015-09-24 Thread paul.hermeneutic
Good idea. >>> [int(x) for x in str(results)] [1, 2, 3] -- https://mail.python.org/mailman/listinfo/python-list

Re: Idiosyncratic python

2015-09-24 Thread Ian Kelly
On Thu, Sep 24, 2015 at 8:07 AM, jmp wrote: > result = getResult() > > For the later, the original weird form come from a C habit to allocate > returned structures within the caller and provide a pointer to it so the > function can fill the data in, otherwise the structure is lost as the stack > i

Installing pywin32.

2015-09-24 Thread ashwath
Hi Sir/Madam When I try to run my python program where I am using the pywin32 module I am getting the error as win32api module not found so how to install this module please let me know ASP. Thank You Ashwath B H -- https://mail.python.org/mailman/listinfo/python-list

Re: Python, convert an integer into an index?

2015-09-24 Thread jmp
On 09/24/2015 03:45 PM, paul.hermeneu...@gmail.com wrote: >> I'm suprised. Why not just: >> >> list(str(results)) >> >> In other words, is there something else the list constructor should do >> with a string other than convert it to a list? >> > The OP wanted the result to be a list of in

Re: Idiosyncratic python

2015-09-24 Thread jmp
On 09/24/2015 02:50 PM, paul.hermeneu...@gmail.com wrote: > A lot of our in base weird python comes from heavily C-wired people: > > The classic > for i in range(len(alist)): > print alist[i] > > with its twin brother > > i=0 > while i < len(alist): > print alist[i] > i += 1 >

querying hive database using python

2015-09-24 Thread heenameena1234
I have server A and Server B. Server B is a hadoop cluster which has hive database and etc.. Server A has python 2.7. I would like to write a hive query using python on Server A to pull data from Server B. Server A and B has connectivity and no issues with network etc.. I have installed all nec

Re: Python, convert an integer into an index?

2015-09-24 Thread paul.hermeneutic
>> I'm suprised. Why not just: >> >> list(str(results)) >> >> In other words, is there something else the list constructor should do >> with a string other than convert it to a list? >> > The OP wanted the result to be a list of ints, not a list of strings. [int(x) for x in list(str(results))] --

Re: Python, convert an integer into an index?

2015-09-24 Thread MRAB
On 2015-09-23 10:01, Anssi Saari wrote: Dennis Lee Bieber writes: On Wed, 23 Sep 2015 00:21:22 +0200, Laura Creighton declaimed the following: You need to convert your results into a string first. result_int=1234523 result_list=[] for digit in str(result_int): result_list.append(int(

Re: Python, convert an integer into an index?

2015-09-24 Thread Anssi Saari
Dennis Lee Bieber writes: > On Wed, 23 Sep 2015 00:21:22 +0200, Laura Creighton > declaimed the following: > > >> >>You need to convert your results into a string first. >> >>result_int=1234523 >>result_list=[] >> >>for digit in str(result_int): >>result_list.append(int(digit)) >> > >

Re: Sending a python argument to a Boost.Python function

2015-09-24 Thread Laura Creighton
Try that question here: https://mail.python.org/mailman/listinfo/cplusplus-sig Laura -- https://mail.python.org/mailman/listinfo/python-list

Re: Idiosyncratic python

2015-09-24 Thread Mark Lawrence
On 24/09/2015 13:50, paul.hermeneu...@gmail.com wrote: > A lot of our in base weird python comes from heavily C-wired people: > > The classic > for i in range(len(alist)): > print alist[i] > > with its twin brother > > i=0 > while i < len(alist): > print alist[i] > i += 1 > >

Re: Idiosyncratic python

2015-09-24 Thread paul.hermeneutic
> A lot of our in base weird python comes from heavily C-wired people: > > The classic > for i in range(len(alist)): > print alist[i] > > with its twin brother > > i=0 > while i < len(alist): > print alist[i] > i += 1 > > And the even more annoying > > result = Result() > getResult(result) >

Re: PyInstaller+ Python3.5 (h5py import error)

2015-09-24 Thread Laura Creighton
In a message of Thu, 24 Sep 2015 02:58:35 -0700, Heli Nix writes: >Thanks Christian, > >It turned out that h5py.defs was not the only hidden import that I needed to >add. > >I managed to get it working with the follwoing command adding 4 hidden >imports. > > >pyinstaller --hidden-import=h5py.d

Re: ConnectionError handling problem

2015-09-24 Thread Laura Creighton
In a message of Wed, 23 Sep 2015 19:49:17 -0700, shiva upreti writes: >Hi >If my script hangs because of the reasons you mentioned above, why doesnt it >catch ConnectionError? >My script stops for a while and when I press CTRL+C, it shows ConnectionError >without terminating the process, and the

Re: PyInstaller+ Python3.5 (h5py import error)

2015-09-24 Thread Heli Nix
Thanks Christian, It turned out that h5py.defs was not the only hidden import that I needed to add. I managed to get it working with the follwoing command adding 4 hidden imports. pyinstaller --hidden-import=h5py.defs --hidden-import=h5py.utils --hidden-import=h5py.h5ac --hidden-import=h5

Re: Idiosyncratic python

2015-09-24 Thread jmp
On 09/24/2015 08:02 AM, Steven D'Aprano wrote: I was looking at an in-house code base today, and the author seems to have a rather idiosyncratic approach to Python. For example: for k, v in mydict.items(): del(k) ... instead of the more obvious for v in mydict.values(): ...