Re: Get a function definition/implementation hint similar to the one shown in pycharm.

2021-10-19 Thread Chris Angelico
On Wed, Oct 20, 2021 at 4:45 AM hongy...@gmail.com wrote: > > On Tuesday, October 19, 2021 at 5:22:25 AM UTC+8, cameron...@gmail.com wrote: > > On 18Oct2021 01:43, Hongyi Zhao wrote: > > >I've written the following python code snippet in pycharm: > > >```python > > >import numpy as np > > >from n

Re: Get a function definition/implementation hint similar to the one shown in pycharm.

2021-10-19 Thread hongy...@gmail.com
On Tuesday, October 19, 2021 at 5:22:25 AM UTC+8, cameron...@gmail.com wrote: > On 18Oct2021 01:43, Hongyi Zhao wrote: > >I've written the following python code snippet in pycharm: > >```python > >import numpy as np > >from numpy import pi, sin > > > >a = np.array([1], dtype=bool) > >if np.

Re: Get a function definition/implementation hint similar to the one shown in pycharm.

2021-10-18 Thread hongy...@gmail.com
On Tuesday, October 19, 2021 at 5:22:25 AM UTC+8, cameron...@gmail.com wrote: > On 18Oct2021 01:43, Hongyi Zhao wrote: > >I've written the following python code snippet in pycharm: > >```python > >import numpy as np > >from numpy import pi, sin > > > >a = np.array([1], dtype=bool) > >if np.

Re: Get a function definition/implementation hint similar to the one shown in pycharm.

2021-10-18 Thread Cameron Simpson
On 18Oct2021 01:43, Hongyi Zhao wrote: >I've written the following python code snippet in pycharm: >```python >import numpy as np >from numpy import pi, sin > >a = np.array([1], dtype=bool) >if np.in|vert(a) == ~a: >print('ok') >``` >When putting the point/cursor in the above code snippet at t

Get a function definition/implementation hint similar to the one shown in pycharm.

2021-10-18 Thread hongy...@gmail.com
I've written the following python code snippet in pycharm: ```python import numpy as np from numpy import pi, sin a = np.array([1], dtype=bool) if np.in|vert(a) == ~a: print('ok') ``` When putting the point/cursor in the above code snippet at the position denoted by `|`, I would like to see i

Re: Syntax Suggestion: Pass Function Definition as Argument

2019-11-11 Thread Rhodri James
On 07/11/2019 13:36, Stephen Waldron wrote: This is how it is at the moment, however it may be more agreeable, especially if that is the only purpose of the function, for python users to be able to define new functions inside of function calls. No, not seeing it. Sorry, I don't think "I don'

Re: Syntax Suggestion: Pass Function Definition as Argument

2019-11-08 Thread Stephen Waldron
Ok firstly, this idea was inspired specifically by a project I'm working on for school concerning linked lists, in which I was trying to create a method that performed a function on elements iteratively without having to navigate the list from the head each time (of course taking the function as

Re: Syntax Suggestion: Pass Function Definition as Argument

2019-11-08 Thread Chris Angelico
On Fri, Nov 8, 2019 at 11:22 PM Antoon Pardon wrote: > > On 8/11/19 13:00, Chris Angelico wrote: > > On Fri, Nov 8, 2019 at 10:57 PM Antoon Pardon wrote: > >> On 7/11/19 18:10, Stephen Waldron wrote: > >>> What I'm aiming for is the ability to, within a function call, pass a > >>> suite that wou

Re: Syntax Suggestion: Pass Function Definition as Argument

2019-11-08 Thread Antoon Pardon
On 8/11/19 13:00, Chris Angelico wrote: > On Fri, Nov 8, 2019 at 10:57 PM Antoon Pardon wrote: >> On 7/11/19 18:10, Stephen Waldron wrote: >>> What I'm aiming for is the ability to, within a function call, pass a suite >>> that would be there automatically defined by the compiler/interpreter. >>

Re: Syntax Suggestion: Pass Function Definition as Argument

2019-11-08 Thread Chris Angelico
On Fri, Nov 8, 2019 at 10:57 PM Antoon Pardon wrote: > > On 7/11/19 18:10, Stephen Waldron wrote: > > What I'm aiming for is the ability to, within a function call, pass a suite > > that would be there automatically defined by the compiler/interpreter. > > Another comment did mention lambda func

Re: Syntax Suggestion: Pass Function Definition as Argument

2019-11-08 Thread Antoon Pardon
On 7/11/19 18:10, Stephen Waldron wrote: > What I'm aiming for is the ability to, within a function call, pass a suite > that would be there automatically defined by the compiler/interpreter. > Another comment did mention lambda functions, which does to some degree > provide that capability, but

RE: Syntax Suggestion: Pass Function Definition as Argument

2019-11-07 Thread David Raymond
Here is it rewritten using the proposal: ``` #Definition def myFoo (str1, str2, foo, str = " "): print( foo(str = str1), foo(str = str2) ) #Call myFoo ("hello", "world!"): str = list(str)[0].upper() + str[1:] return str ``` Are you looking for multi-line l

Re: Syntax Suggestion: Pass Function Definition as Argument

2019-11-07 Thread Stephen Waldron
Thanks Antoon. I do suppose that it is kind of wrong to say the only way is to "reference its [the function's] name" as an argument, however the point I was trying to make was that it isn't possible to pass a function that is either not in some way previously defined or a reference to something

Re: Syntax Suggestion: Pass Function Definition as Argument

2019-11-07 Thread Stephen Waldron
Thanks Antoon. I do suppose that it is kind of wrong to say the only way is to "reference its [the function's] name" as an argument, however the point I was trying to make was that you cannot pass a function that is either not in some way previously defined or a reference to something previously

Re: Syntax Suggestion: Pass Function Definition as Argument

2019-11-07 Thread Antoon Pardon
On 7/11/19 14:36, Stephen Waldron wrote: > Hi, I'm new to the group and to Python, so forgive me if I make any faux-pas > here. As I can tell, the only way to pass a function as an argument is to > reference its name as follows: > > def foo1(message): > print(message) > > def foo2(foo, messag

Syntax Suggestion: Pass Function Definition as Argument

2019-11-07 Thread Stephen Waldron
Hi, I'm new to the group and to Python, so forgive me if I make any faux-pas here. As I can tell, the only way to pass a function as an argument is to reference its name as follows: def foo1(message): print(message) def foo2(foo, message): print("Your function says:") foo(message)

Re: Problem/bug with class definition inside function definition

2018-05-08 Thread Gregory Ewing
Alexey Muranov wrote: x = 42 class C: x = x # Works I'd say it kind of works by accident, and is not really an intended feature. if Python does not allow to refer "simultaneously" to variables from different scopes if they have the same name. It seems perfectly reasonable to

Re: Problem/bug with class definition inside function definition

2018-05-08 Thread Ned Batchelder
On 5/8/18 3:55 AM, Alexey Muranov wrote: Sorry, i was confused.  I would say that this mostly works as expected, though the difference between    x = 42    class C:    x = x  # Works and    def f2(a):    class D:    a = a  # Does not work <    return D is still surpr

Re: Problem/bug with class definition inside function definition

2018-05-08 Thread Alexey Muranov
Sorry, i was confused. I would say that this mostly works as expected, though the difference between x = 42 class C: x = x # Works and def f2(a): class D: a = a # Does not work < return D is still surprising to me. Otherwise, probably the solu

Re: Problem/bug with class definition inside function definition

2018-05-07 Thread Gregory Ewing
Python 3.5.1 (default, Jun 1 2016, 13:15:26) [GCC 4.2.1 (Apple Inc. build 5664)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> def f(a): ... class D: ... pass ... D.a = a ... return D ... >>> c = f(42) >>> c .D'> >>> c.a 42 -- Greg -- https://mail.pyth

Re: Problem/bug with class definition inside function definition

2018-05-07 Thread Alexey Muranov
To be more exact, i do see a few workarounds, for example: def f4(a): b = a class D: a = b # Works return D But this is not what i was hoping for. Alexey. On Tue, 8 May, 2018 at 12:02 AM, Alexey Muranov wrote: I have discovered the following bug or proble

Problem/bug with class definition inside function definition

2018-05-07 Thread Alexey Muranov
I have discovered the following bug or problem: it looks like i am forced to choose different names for class attributes and function arguments, and i see no workaround. Am i missing some special syntax feature ? Alexey. --- x = 42 class C1: y = x # Works class C2: x = x # Works #

Re: python IDE and function definition

2013-09-26 Thread Ben Finney
Chris Friesen writes: > I'm running into issues where my current IDE (I'm playing with Komodo) > can't seem to locate the definition, I suspect because it's too > ambiguous. The feature you're looking for – to start from the statement where a function is called, then jump to the statement where

Re: python IDE and function definition

2013-09-24 Thread Travis Griggs
On Sep 23, 2013, at 8:06 AM, Chris Friesen wrote: > > Hi all, > > I'm looking for a python IDE (for Linux) that can look at code like this: > > class ConductorManager(manager.Manager): >def compute_recover(self, context, instance): >self.compute_api.stop(context, instance, do_cast

Re: python IDE and function definition

2013-09-24 Thread Fabio Zadrozny
On Mon, Sep 23, 2013 at 8:20 PM, Neil Hodgson wrote: > Chris Friesen: > > > where I could highlight the "stop" and ask it to go to the definition. >> (Where the definition is in a different file.) >> >> I'm running into issues where my current IDE (I'm playing with Komodo) >> can't seem to locat

Re: python IDE and function definition

2013-09-23 Thread Neil Hodgson
Chris Friesen: where I could highlight the "stop" and ask it to go to the definition. (Where the definition is in a different file.) I'm running into issues where my current IDE (I'm playing with Komodo) can't seem to locate the definition, I suspect because it's too ambiguous. Some IDEs

Re: python IDE and function definition

2013-09-23 Thread Chris Friesen
On 09/23/2013 09:32 AM, Fabio Zadrozny wrote: On Mon, Sep 23, 2013 at 12:06 PM, Chris Friesen mailto:cbf...@mail.usask.ca>> wrote: Hi all, I'm looking for a python IDE (for Linux) that can look at code like this: class ConductorManager(manager.__Manager): def compute_

Re: python IDE and function definition

2013-09-23 Thread Fabio Zadrozny
On Mon, Sep 23, 2013 at 2:29 PM, Chris Friesen wrote: > On 09/23/2013 09:32 AM, Fabio Zadrozny wrote: > >> On Mon, Sep 23, 2013 at 12:06 PM, Chris Friesen > > wrote: >> >> >> Hi all, >> >> I'm looking for a python IDE (for Linux) that can look at code like >>

Re: python IDE and function definition

2013-09-23 Thread Fabio Zadrozny
On Mon, Sep 23, 2013 at 12:06 PM, Chris Friesen wrote: > > Hi all, > > I'm looking for a python IDE (for Linux) that can look at code like this: > > class ConductorManager(manager.**Manager): > def compute_recover(self, context, instance): > self.compute_api.stop(context, instance, do_

python IDE and function definition

2013-09-23 Thread Chris Friesen
Hi all, I'm looking for a python IDE (for Linux) that can look at code like this: class ConductorManager(manager.Manager): def compute_recover(self, context, instance): self.compute_api.stop(context, instance, do_cast=False) where I could highlight the "stop" and ask it to go to th

Re: recall function definition from shell

2010-05-18 Thread Terry Reedy
On 5/18/2010 2:55 PM, superpollo wrote: yes python does not, but maybe the *shell* does, or so i thought. i just wanted to dump the code for the function in a file, after i tested in the shell... On Windows, you can tell the shell (command window) how many lines to remember. One can sensibly

Re: recall function definition from shell

2010-05-18 Thread René 'Necoro' Neumann
Am 18.05.2010 20:55, schrieb superpollo: > > yes python does not, but maybe the *shell* does, or so i thought. i just > wanted to dump the code for the function in a file, after i tested in > the shell... You might want to have a look at the IPython shell [1]. I personally do not use it myself, b

Re: recall function definition from shell

2010-05-18 Thread Ethan Furman
superpollo wrote: Patrick Maupin ha scritto: On May 18, 1:41 pm, superpollo wrote: Patrick Maupin ha scritto: On May 18, 12:31 pm, superpollo wrote: >>> def myfun(): ... return "WOW" ... >>> myfun() 'WOW' now, i would like to "list" the funcion definition, something like this: >

Re: recall function definition from shell

2010-05-18 Thread superpollo
Peter Otten ha scritto: superpollo wrote: Patrick Maupin ha scritto: On May 18, 1:41 pm, superpollo wrote: Patrick Maupin ha scritto: On May 18, 12:31 pm, superpollo wrote: >>> def myfun(): ... return "WOW" ... >>> myfun() 'WOW' now, i would like to "list" the funcion definition,

Re: recall function definition from shell

2010-05-18 Thread Peter Otten
superpollo wrote: > Patrick Maupin ha scritto: >> On May 18, 1:41 pm, superpollo wrote: >>> Patrick Maupin ha scritto: >>> >>> >>> On May 18, 12:31 pm, superpollo wrote: > >>> def myfun(): > ... return "WOW" > ... > >>> myfun() > 'WOW' > now, i would like to "l

Re: recall function definition from shell

2010-05-18 Thread superpollo
Patrick Maupin ha scritto: On May 18, 1:41 pm, superpollo wrote: Patrick Maupin ha scritto: On May 18, 12:31 pm, superpollo wrote: >>> def myfun(): ... return "WOW" ... >>> myfun() 'WOW' now, i would like to "list" the funcion definition, something like this: >>> myfun.somethinglik

Re: recall function definition from shell

2010-05-18 Thread Patrick Maupin
On May 18, 1:41 pm, superpollo wrote: > Patrick Maupin ha scritto: > > > > > On May 18, 12:31 pm, superpollo wrote: > >>  >>> def myfun(): > >> ...     return "WOW" > >> ... > >>  >>> myfun() > >> 'WOW' > > >> now, i would like to "list" the funcion definition, something like this: > > >>  >>> my

Re: recall function definition from shell

2010-05-18 Thread superpollo
Patrick Maupin ha scritto: On May 18, 12:31 pm, superpollo wrote: >>> def myfun(): ... return "WOW" ... >>> myfun() 'WOW' >>> now, i would like to "list" the funcion definition, something like this: >>> myfun.somethinglikethis() def myfun(): return "WOW" >>> is there something

Re: recall function definition from shell

2010-05-18 Thread Patrick Maupin
On May 18, 12:31 pm, superpollo wrote: >  >>> def myfun(): > ...     return "WOW" > ... >  >>> myfun() > 'WOW' >  >>> > > now, i would like to "list" the funcion definition, something like this: > >  >>> myfun.somethinglikethis() > def myfun(): >      return "WOW" >  >>> > > is there something lik

recall function definition from shell

2010-05-18 Thread superpollo
>>> def myfun(): ... return "WOW" ... >>> myfun() 'WOW' >>> now, i would like to "list" the funcion definition, something like this: >>> myfun.somethinglikethis() def myfun(): return "WOW" >>> is there something like this around? bye -- http://mail.python.org/mailman/listinfo/python-li

Re: Help me on function definition

2008-04-04 Thread Alan Isaac
aeneng wrote: > WHAT IS WRONG WITH MY CODE? > def cross(u,v) Missing colon. hth, Alan Isaac -- http://mail.python.org/mailman/listinfo/python-list

Re: Help me on function definition

2008-03-29 Thread castironpi
gt;> import cross > > > Traceback (most recent call last): > >   File "", line 1, in ? > >   File "cross.py", line 8 > >     ppp2=u[2]*v[0]-u[0]*v[2] > >     ^ > > SyntaxError: invalid syntax > > > WHAT IS WRONG WITH MY CODE? >

Re: Help me on function definition

2008-03-29 Thread hdante
^ > SyntaxError: invalid syntax > > WHAT IS WRONG WITH MY CODE? > > I appreciate your help. > > ##here is the function definition. > ##cross.py## > def cross(u,v) > """input two vectors u and v in 3-D space, >output a cross product of v

Re: Error message from function definition

2008-03-29 Thread Terry Reedy
Please do not post same question twice. -- http://mail.python.org/mailman/listinfo/python-list

Re: Help me on function definition

2008-03-29 Thread Terry Reedy
"aeneng" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | def cross(u,v) |"""input two vectors u and v in 3-D space, | output a cross product of vector w, in column or in row | accordingly.""" |ppp1,ppp2,ppp3=0.0,0.0,0.0 To add to other comments, remove above which is

Re: Help me on function definition

2008-03-29 Thread castironpi
): > >   File "", line 1, in ? > >   File "cross.py", line 8 > >     ppp2=u[2]*v[0]-u[0]*v[2] > >     ^ > > SyntaxError: invalid syntax > > > WHAT IS WRONG WITH MY CODE? > > > I appreciate your help. > > > ##here is the function definition. >

Re: Help me on function definition

2008-03-29 Thread Roel Schroeven
yntax > > WHAT IS WRONG WITH MY CODE? > > I appreciate your help. > > ##here is the function definition. > ##cross.py## > def cross(u,v) > """input two vectors u and v in 3-D space, >output a cross product of vector w, in column or i

Re: Help me on function definition

2008-03-28 Thread John Machin
[0]-u[0]*v[2] > ^ > SyntaxError: invalid syntax > > WHAT IS WRONG WITH MY CODE? > > I appreciate your help. > > ##here is the function definition. > ##cross.py## > def cross(u,v) > """input two vectors u and v in 3-D space, >output a c

Re: Help me on function definition

2008-03-28 Thread Steven D'Aprano
Oh, I forgot to mention... On Sat, 29 Mar 2008 01:47:21 +, aeneng wrote: > if __name__=="__main__": ... > print "file name is %s" %__name__ This doesn't do what you expect it to do. You've already established that __name__ is equal to "__main__", so you might as well change that line

Re: Help me on function definition

2008-03-28 Thread Ben Finney
"aeneng" <[EMAIL PROTECTED]> writes: > I am just starting to use python in numerical cacluation. Welcome, and congratulations on learning Python. > I need you to help me to see what's wrong with the following piece > of codes [...] Your code is rather difficult to read, since your expressions

Re: Help me on function definition

2008-03-28 Thread Steven D'Aprano
y the code that actually raises an error, not different code with different errors. The code you post reports this error: >>> import cross Traceback (most recent call last): File "", line 1, in File "cross.py", line 1 def cross(u,v) ^ Syn

Error message from function definition

2008-03-28 Thread aeneng pan
Dear community members, I just start to use python in numerical calculation. and I encountered some difficulties when I define my own function. Here is a piece of codes to compute the cross product of two 3x1 vector. can any one help me to find what is wrong with it? please see the codes below.

Re: Help me on function definition

2008-03-28 Thread Michael Wieher
gt; File "", line 1, in ? > File "cross.py", line 8 >ppp2=u[2]*v[0]-u[0]*v[2] >^ > SyntaxError: invalid syntax > > WHAT IS WRONG WITH MY CODE? > > I appreciate your help. > > ##here is the function definition. > ##cross.py## > def cross(u,v

Help me on function definition

2008-03-28 Thread aeneng
ssage show like this >>> import cross Traceback (most recent call last): File "", line 1, in ? File "cross.py", line 8 ppp2=u[2]*v[0]-u[0]*v[2] ^ SyntaxError: invalid syntax WHAT IS WRONG WITH MY CODE? I appreciate your help. ##here is the function defi

Re: Do eval() and exec not accept a function definition? (like 'def foo: pass) ?

2007-06-24 Thread vasudevram
On Jun 24, 6:28 am, Jean-Paul Calderone <[EMAIL PROTECTED]> wrote: > On Sun, 24 Jun 2007 11:17:40 +1000, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > >On Sat, 23 Jun 2007 19:58:32 +, vasudevram wrote: > > >> Hi group, > > >> Question: Do eval(

Re: Do eval() and exec not accept a function definition? (like 'def foo: pass) ?

2007-06-23 Thread Jean-Paul Calderone
On Sun, 24 Jun 2007 11:17:40 +1000, Steven D'Aprano <[EMAIL PROTECTED]> wrote: >On Sat, 23 Jun 2007 19:58:32 +, vasudevram wrote: > >> >> Hi group, >> >> Question: Do eval() and exec not accept a function definition? (like >> 'def foo: pa

Re: Do eval() and exec not accept a function definition? (like 'def foo: pass) ?

2007-06-23 Thread Steven D'Aprano
On Sat, 23 Jun 2007 19:58:32 +, vasudevram wrote: > > Hi group, > > Question: Do eval() and exec not accept a function definition? (like > 'def foo: pass) ? eval() is a function, and it only evaluates EXPRESSIONS, not code blocks. eval("2+3") # works eval

Re: Do eval() and exec not accept a function definition? (like 'def foo: pass) ?

2007-06-23 Thread Scott David Daniels
vasudevram wrote: > Hi group, > > Question: Do eval() and exec not accept a function definition? (like > 'def foo: pass) ? def is the first keyword in a _statement_, not an expression. exec executes statements, eval evaluates expressions. try this: exec "def fooli

Re: Do eval() and exec not accept a function definition? (like 'def foo: pass) ?

2007-06-23 Thread vasudevram
On Jun 24, 1:20 am, Eduardo Dobay <[EMAIL PROTECTED]> wrote: > Hey, > > I think you could use lambda functions for that matter (Ever heard of > them?). You could write something like: > > def generate_html_tag_function(tag_name, start_or_end): >start_or_end.lower() >assert(start_or_end in (

Re: Do eval() and exec not accept a function definition? (like 'def foo: pass) ?

2007-06-23 Thread Eduardo Dobay
Hey, I think you could use lambda functions for that matter (Ever heard of them?). You could write something like: def generate_html_tag_function(tag_name, start_or_end): start_or_end.lower() assert(start_or_end in ('start', 'end')) if start_or_end == 'start': function = lambda: '

Re: Do eval() and exec not accept a function definition? (like 'def foo: pass) ?

2007-06-23 Thread MC
Hi! Try with change all '\r\n' by '\n' -- @-salutations Michel Claveau -- http://mail.python.org/mailman/listinfo/python-list

Do eval() and exec not accept a function definition? (like 'def foo: pass) ?

2007-06-23 Thread vasudevram
Hi group, Question: Do eval() and exec not accept a function definition? (like 'def foo: pass) ? I wrote a function to generate other functions using something like eval("def foo: ") but it gave a syntax error ("Invalid syntax") with caret pointing to the 'd

Re: behavior difference for mutable and immutable variable in function definition

2007-05-05 Thread jianbing . chen
On May 4, 5:14 pm, Carsten Haese <[EMAIL PROTECTED]> wrote: > On Fri, 2007-05-04 at 14:30 -0700, [EMAIL PROTECTED] wrote: > > Hi, > > > Can anyone explain the following: > > > Python 2.5 (r25:51908, Apr 9 2007, 11:27:23) > > [GCC 4.1.1 20060525 (Red Hat 4.1.1-1)] on linux2 > > Type "help", "copyri

Re: behavior difference for mutable and immutable variable in function definition

2007-05-04 Thread Roger Miller
On May 4, 12:39 pm, 7stud <[EMAIL PROTECTED]> wrote: > On May 4, 3:30 pm, [EMAIL PROTECTED] wrote: > > > > > Hi, > > > Can anyone explain the following: > > > Python 2.5 (r25:51908, Apr 9 2007, 11:27:23) > > [GCC 4.1.1 20060525 (Red Hat 4.1.1-1)] on linux2 > > Type "help", "copyright", "credits" o

Re: behavior difference for mutable and immutable variable in function definition

2007-05-04 Thread 7stud
On May 4, 3:30 pm, [EMAIL PROTECTED] wrote: > Hi, > > Can anyone explain the following: > > Python 2.5 (r25:51908, Apr 9 2007, 11:27:23) > [GCC 4.1.1 20060525 (Red Hat 4.1.1-1)] on linux2 > Type "help", "copyright", "credits" or "license" for more information.>>> def > foo(): > > ... x = 2 >

Re: behavior difference for mutable and immutable variable in function definition

2007-05-04 Thread Carsten Haese
On Fri, 2007-05-04 at 14:30 -0700, [EMAIL PROTECTED] wrote: > Hi, > > Can anyone explain the following: > > Python 2.5 (r25:51908, Apr 9 2007, 11:27:23) > [GCC 4.1.1 20060525 (Red Hat 4.1.1-1)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> def foo(): >

Re: behavior difference for mutable and immutable variable in function definition

2007-05-04 Thread James Stroud
[EMAIL PROTECTED] wrote: > Hi, > > Can anyone explain the following: > > Python 2.5 (r25:51908, Apr 9 2007, 11:27:23) > [GCC 4.1.1 20060525 (Red Hat 4.1.1-1)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > def foo(): > > ... x = 2 > ... > foo(

behavior difference for mutable and immutable variable in function definition

2007-05-04 Thread jianbing . chen
Hi, Can anyone explain the following: Python 2.5 (r25:51908, Apr 9 2007, 11:27:23) [GCC 4.1.1 20060525 (Red Hat 4.1.1-1)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> def foo(): ... x = 2 ... >>> foo() >>> def bar(): ... x[2] = 2 ... >>> >>> bar()

Re: Small prog question from a newbie: abt variables in a function definition

2006-11-29 Thread Gabriel Genellina
At Wednesday 29/11/2006 06:48, B Shyam Sundar wrote: I am a newbie as far as python is concerned ... I am trying to write a code for playing bridge in obj oriented manner .. Well ... i have this small problem: class hand: def __init__(self,set_of_cards=[]): self.set_of_cards=set_o

Small prog question from a newbie: abt variables in a function definition

2006-11-29 Thread B Shyam Sundar
Hi all, I am a newbie as far as python is concerned ... I am trying to write a code for playing bridge in obj oriented manner .. Well ... i have this small problem: class hand: def __init__(self,set_of_cards=[]): self.set_of_cards=set_of_cards card_played_flag =0 def play(played_

Re: Function definition

2006-06-20 Thread bruno at modulix
faulkner wrote: (pelase don't top-post - fixed) > aarondesk wrote: > (snip) >>Now I've tried putting the function declaration after the call but the >>program wouldn't work. Is there anyway to put function declarations at >>the end of the program, rather than putting them at the beginning, >>which

Re: Function definition

2006-06-20 Thread Duncan Booth
aarondesk wrote: > I have a little .py file that has the format: > > > def fxn(a): > do stuff > > other stuff > ... > r = fxn(a) > > > > Now I've tried putting the function declaration after the call but the > program wouldn't work. Is there anyway to put function declarations at > t

Re: Function definition

2006-06-19 Thread forman . simon
aarondesk wrote: ... > > Now I've tried putting the function declaration after the call but the > program wouldn't work. Is there anyway to put function declarations at > the end of the program, rather than putting them at the beginning, > which is rather clunky? > > Thanks. > Aaron A function can

Re: Function definition

2006-06-19 Thread faulkner
no. python is not C. python is interpreted, not compiled, so if you want a function to exist when you call it, you need to define it before you call it. it isn't clunky, it's just how it's done. if you want to define a 'main' function at the top of your script/module, go for it. then you can use th

Function definition

2006-06-19 Thread aarondesk
I have a little .py file that has the format: def fxn(a): do stuff other stuff ... r = fxn(a) Now I've tried putting the function declaration after the call but the program wouldn't work. Is there anyway to put function declarations at the end of the program, rather than putting them

Re: Code evaluation at function definition execution time (was Re: Compile time evaluation (aka eliminating default argument hacks))

2005-03-10 Thread Carl Banks
Carl Banks wrote: > I could, however, see myself > using the slightly more complicated descriptor such as this (for a > wholly different reason, though): > > . def call_with_open_file(filename): > . def descriptor(func): > . flo = open(filename) > . try: f(flo) > . fi

Re: Code evaluation at function definition execution time (was Re: Compile time evaluation (aka eliminating default argument hacks))

2005-03-10 Thread Carl Banks
Nick Coghlan wrote: > Anyway, if others agree that the ability to execute a suite at def exeuction > time to preinitialise a function's locals without resorting to bytecode hacks is > worth having, finding a decent syntax is the next trick :) Workarounds: 1. Just use a freaking global, especially

Re: Code evaluation at function definition execution time (was Re: Compile time evaluation (aka eliminating default argument hacks))

2005-03-10 Thread Bengt Richter
On Fri, 25 Feb 2005 19:34:53 -0700, Steven Bethard <[EMAIL PROTECTED]> wrote: >Nick Coghlan wrote: >> Anyway, if others agree that the ability to execute a suite at def >> exeuction time to preinitialise a function's locals without resorting to >> bytecode hacks is worth having, finding a decent

Re: Code evaluation at function definition execution time (was Re: Compile time evaluation (aka eliminating default argument hacks))

2005-02-25 Thread Nick Coghlan
Steven Bethard wrote: Worth looking at is the thread: http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/58f53fe8bcc49664/ Huh - I thought I put something in the original post saying "without resorting to bytecode hacks", but I must have deleted it before sending the messag

Re: Code evaluation at function definition execution time (was Re: Compile time evaluation (aka eliminating default argument hacks))

2005-02-25 Thread Steven Bethard
Nick Coghlan wrote: Anyway, if others agree that the ability to execute a suite at def exeuction time to preinitialise a function's locals without resorting to bytecode hacks is worth having, finding a decent syntax is the next trick :) I'm not certain how many use cases really require a full su

Re: Code evaluation at function definition execution time (was Re: Compile time evaluation (aka eliminating default argument hacks))

2005-02-25 Thread Nick Coghlan
Nick Coghlan wrote: Basically, yeah. Although I later realised I got the name of the feature I want wrong - default arguments are evaluated when the def statement is executed, not when the code is compiled. So it's a matter of being able to execute some code in the functions local namespace at c

Code evaluation at function definition execution time (was Re: Compile time evaluation (aka eliminating default argument hacks))

2005-02-25 Thread Nick Coghlan
hich the Python compiler and parser should actually be able to handle would be to tack an optional clause on to the front of the function definition statement: using x, y from: # Again, the right syntax for early binding is not clear y = x + 2 def f(): print x, y (Similar to some of