Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-08 Thread Chris Angelico via Python-list
On Sat, 9 Mar 2024 at 03:42, Grant Edwards via Python-list wrote: > > On 2024-03-08, Chris Angelico via Python-list wrote: > > On Sat, 9 Mar 2024 at 00:51, Grant Edwards via Python-list > > wrote: > > > >> One might argue that "global" isn't a good choice for what to call the > >> scope in questi

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-08 Thread Grant Edwards via Python-list
On 2024-03-08, Chris Angelico via Python-list wrote: > On Sat, 9 Mar 2024 at 00:51, Grant Edwards via Python-list > wrote: > >> One might argue that "global" isn't a good choice for what to call the >> scope in question, since it's not global. It's limited to that source >> file. It doesn't make s

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-08 Thread Chris Angelico via Python-list
On Sat, 9 Mar 2024 at 00:51, Grant Edwards via Python-list wrote: > One might argue that "global" isn't a good choice for what to call the > scope in question, since it's not global. It's limited to that source > file. It doesn't make sense to me to call a binding "global", when > there can be mul

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-08 Thread Grant Edwards via Python-list
On 2024-03-07, Cameron Simpson via Python-list wrote: > Yes. Note that the "global" namespace is the module in which the > function is defined. One might argue that "global" isn't a good choice for what to call the scope in question, since it's not global. It's limited to that source file. It d

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-07 Thread Cameron Simpson via Python-list
On 06Mar2024 15:12, Jacob Kruger wrote: So, this does not make sense to me in terms of the following snippet from the official python docs page: https://docs.python.org/3/faq/programming.html "In Python, variables that are only referenced inside a function are implicitly global. If a variable

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-07 Thread Jacob Kruger via Python-list
Thanks again, all. I think the python -i scoping2.py would have given me a good beginning as well - will archive that one for use. And, to maybe explain how I work - not an excuse at all - but, I am actually 100% blind, so a lot of the IDE's, or their common means/methods of interaction do

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Grant Edwards via Python-list
On 2024-03-07, dn via Python-list wrote: > The idea of importing a module into the REPL and then (repeatedly) > manually entering the code to set-up and execute is unusual (surely type > such into a script (once), and run that (repeatedly). As you say, most > of us would be working from an IDE

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread dn via Python-list
On 7/03/24 05:28, Jacob Kruger via Python-list wrote: ... So, yes, know this comes across like some form of a scam/joke, or list-garbage, since it doesn't make any sense to me at all, but still just wondering if missing something, or should I shift over to 3.12 to see if if works differently, o

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Roel Schroeven via Python-list
Grant Edwards via Python-list schreef op 6/03/2024 om 18:59: On 2024-03-06, Roel Schroeven via Python-list wrote: > Op 6/03/2024 om 17:40 schreef Jacob Kruger via Python-list: >> >>> from scoping2 import * > > [...] > > I would advice not to use 'import *', if at all possible, for multiple

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Grant Edwards via Python-list
On 2024-03-06, Roel Schroeven via Python-list wrote: > Op 6/03/2024 om 17:40 schreef Jacob Kruger via Python-list: >> >>> from scoping2 import * > > [...] > > I would advice not to use 'import *', if at all possible, for multiple > reasons, one of which is to prevent problems like this. Unfortun

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Roel Schroeven via Python-list
Op 6/03/2024 om 17:40 schreef Jacob Kruger via Python-list: >>> from scoping2 import * Ah yes, that explains what's happening. After that statement, the name dt_expiry in the current namespace is bound to the same object that the name dt_expiry in the namespace of module scoping2 is bound to. F

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Jacob Kruger via Python-list
Ok, Ethan, that makes sense - I generally work with modules in folders, etc., but, this was just test code, but, 'see' if I instead import scoping2 as sc2, and then refer to sc2.dt_expiry and sc2.do_it, then it does operate as it should - thanks, again. Jacob Kruger +2782 413 4791 "Resistance

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Ethan Furman via Python-list
On 3/6/24 08:28, Jacob Kruger via Python-list wrote: > C:\temp\py_try>python > Python 3.11.7 (tags/v3.11.7:fa7a6f2, Dec 4 2023, 19:24:49) [MSC v.1937 64 bit (AMD64)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> from scoping2 import * And it becomes c

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Jacob Kruger via Python-list
You'll see more details in other mail, but, here I am firing up standard python interpreter from within windows terminal, and then executing following line: from scoping2 import * And, this is under windows 11 windows terminal, which is where I generally interact with my python code, via com

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Jacob Kruger via Python-list
Matt, other mail is more relevant - seems to maybe have more to do with different behavour if import code, or not - no, does not make sense to me - but, here's the command line contents including printing out id() results, but, only working via importing code: #---start session--- C:\temp\py_

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Jacob Kruger via Python-list
Thanks for all your input people, and, yes, I know that besides the scope oddities the rest of the code is not my normal style either - was partly due to forms of experimentation to try figure out what could be causing issues. For example, instead of [:] syntax, was specifically using copy() to

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Roel Schroeven via Python-list
Op 6/03/2024 om 16:39 schreef Roel Schroeven via Python-list: Op 6/03/2024 om 13:55 schreef Jacob Kruger via Python-list: If you import the contents of that file into the python interpreter, [...] What exactly to you mean by "import the contents of that file into the python interpreter"? Othe

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Roel Schroeven via Python-list
Op 6/03/2024 om 13:55 schreef Jacob Kruger via Python-list: If you import the contents of that file into the python interpreter, [...] What exactly to you mean by "import the contents of that file into the python interpreter"? Other people have put your code in a script, executed it, and saw

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Thomas Passin via Python-list
On 3/6/2024 7:55 AM, Jacob Kruger via Python-list wrote: Ok, simpler version - all the code in a simpler test file, and working with two separate variables to explain exactly what am talking about: # start code from datetime import datetime, timezone, timedelta from copy import copy # initi

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Thomas Passin via Python-list
On 3/6/2024 5:59 AM, Alan Gauld via Python-list wrote: On 05/03/2024 22:46, Grant Edwards via Python-list wrote: Unfortunately (presumably thanks to SEO) the enshittification of Google has reached the point where searching for info on things like Python name scope, the first page of links are to

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Mats Wichmann via Python-list
On 3/6/24 05:55, Jacob Kruger via Python-list wrote: Ok, simpler version - all the code in a simpler test file, and working with two separate variables to explain exactly what am talking about: If you import the contents of that file into the python interpreter, dt_expiry will start off as "19

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Jacob Kruger via Python-list
So, this does not make sense to me in terms of the following snippet from the official python docs page: https://docs.python.org/3/faq/programming.html "In Python, variables that are only referenced inside a function are implicitly global. If a variable is assigned a value anywhere within the

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Jacob Kruger via Python-list
Ok, simpler version - all the code in a simpler test file, and working with two separate variables to explain exactly what am talking about: # start code from datetime import datetime, timezone, timedelta from copy import copy # initialise original values dt_expiry = datetime.strptime("1970

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Alan Gauld via Python-list
On 05/03/2024 22:46, Grant Edwards via Python-list wrote: > Unfortunately (presumably thanks to SEO) the enshittification of > Google has reached the point where searching for info on things like > Python name scope, the first page of links are to worthless sites like > geeksforgeeks. And not just

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-05 Thread Grant Edwards via Python-list
On 2024-03-05, Cameron Simpson via Python-list wrote: > Because there are no variable definitions in Python, when you write > a function Python does a static analysis of it to decide which > variables are local and which are not. If there's an assignment to a > variable, it is a local variable.

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-05 Thread Cameron Simpson via Python-list
On 05Mar2024 20:13, Jacob Kruger wrote: Now, what almost seems to be occurring, is that while just manipulating the contents of a referenced variable is fine in this context, the moment I try to reassign it, that's where the issue is occurring . Because there are no variable definitions in Py

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-05 Thread dn via Python-list
Jacob, Please reduce the problem to a small code-set which reproduces the problem. If we can reproduce same, then that tells us something. At the very least, we can experiment without having to expend amounts of time in a (likely faulty) bid to reproduce the same environment. Also, code is t

Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-05 Thread Jacob Kruger via Python-list
Hi there Working with python 3.11, and, issue that confused me for a little while, trying to figure out what was occurring - unless am completely confused, or missing something - was that, for example, when having pre-defined a variable, and then included it in the global statement inside a

Re: Abstractions [was Re: Pass variable by reference]

2014-05-09 Thread Mark H Harris
On 5/9/14 7:58 PM, Steven D'Aprano wrote: {snip} at which point we're now talking about a concrete, physical description of the process, not an abstraction. There really is a bottom-most turtle that holds up all the rest.) hi Steven, heh... yup, there really is a bottom-most turtle (and who c

Abstractions [was Re: Pass variable by reference]

2014-05-09 Thread Steven D'Aprano
On Fri, 09 May 2014 17:30:10 -0500, Mark H Harris wrote: > On 5/7/14 8:31 PM, Chris Angelico wrote: >> On Thu, May 8, 2014 at 4:11 AM, Mark H Harris >> wrote: >>> And we must never forget that CPython's underpinnings, uhm C, uses >>> variables, C ones... (never mind) >> >> Be careful of this one

Re: Pass variable by reference

2014-05-09 Thread Mark H Harris
On 5/7/14 8:31 PM, Chris Angelico wrote: On Thu, May 8, 2014 at 4:11 AM, Mark H Harris wrote: And we must never forget that CPython's underpinnings, uhm C, uses variables, C ones... (never mind) Be careful of this one. It's utterly irrelevant to your point, and may be distracting. I could im

Re: Values and objects [was Re: Pass variable by reference]

2014-05-09 Thread Mark H Harris
On 5/7/14 8:08 PM, Steven D'Aprano wrote: In Python, all values *are* objects. It isn't a matter of choosing one or the other. The value 1 is an object, not a native (low-level, unboxed) 32 or 64 bit int. Unlike C# or Java, there is no direct language facility to box native values into objects o

Value vs Identity (was Re: Pass variable by reference)

2014-05-07 Thread Chris Angelico
On Thu, May 8, 2014 at 7:22 AM, Marko Rauhamaa wrote: > Mark H Harris : > >> A == B >> True >> >> A is B >> False >> >> [...] >> >> This is just one of a dozen 'different' kinds of examples. And the >> answer is the same, Python does not have variables, Python has names >> bound to objects. > > Th

Re: Pass variable by reference

2014-05-07 Thread Chris Angelico
On Thu, May 8, 2014 at 4:11 AM, Mark H Harris wrote: > And we must never forget that CPython's underpinnings, uhm C, uses > variables, C ones... (never mind) Be careful of this one. It's utterly irrelevant to your point, and may be distracting. I could implement Ook in Python; does that mean tha

Values and objects [was Re: Pass variable by reference]

2014-05-07 Thread Steven D'Aprano
On Thu, 08 May 2014 00:22:55 +0300, Marko Rauhamaa wrote: > But hey, we can open another thread for whether Python has values or > objects! In Python, all values *are* objects. It isn't a matter of choosing one or the other. The value 1 is an object, not a native (low-level, unboxed) 32 or 64 b

Re: Pass variable by reference

2014-05-07 Thread Marko Rauhamaa
Mark H Harris : > A == B > True > > A is B > False > > [...] > > This is just one of a dozen 'different' kinds of examples. And the > answer is the same, Python does not have variables, Python has names > bound to objects. That is a different topic and isn't related to variables at all. Instead,

Re: Pass variable by reference

2014-05-07 Thread Mark H Harris
On 5/6/14 6:46 PM, Chris Angelico wrote: Is there really a fundamental difference between languages in which that is equally valid syntax and does exactly the same thing? No. And from that standpoint, python has variables. I know, because I thought about python's 'variables' as variables for

Re: Pass variable by reference

2014-05-06 Thread Steven D'Aprano
On Tue, 06 May 2014 19:54:28 -0700, Rustom Mody wrote: > The number of possible concepts is infinite > > The number of words is finite (even assuming unicode!!) Not true. If you allow longer and longer words, with no upper limit, the number of words is also infinite. If you allow compound word

Re: Pass variable by reference

2014-05-06 Thread Rustom Mody
On Wednesday, May 7, 2014 8:09:34 AM UTC+5:30, Chris Angelico wrote: > On Wed, May 7, 2014 at 12:18 PM, Rustom Mody wrote: > > Wrong conclusion! > > These 3 lines look the same and amount to much the same in python and C. > > But as the example widens to something beyond 3 lines, the difference > >

Re: Pass variable by reference

2014-05-06 Thread Chris Angelico
On Wed, May 7, 2014 at 12:18 PM, Rustom Mody wrote: > Wrong conclusion! > > These 3 lines look the same and amount to much the same in python and C. > > But as the example widens to something beyond 3 lines, the difference > will become more and more significant Python, C, REXX, BASIC, and pretty

Re: Pass variable by reference

2014-05-06 Thread Rustom Mody
nce > will work identically in all of them. Does BASIC have variables? > Presumably, since you can pass them by reference. Does REXX? You can't > pass by reference (all you can do is EXPOSE, which is more like > scoping rules, only it isn't); a C function can fiddle with any nam

Re: Pass variable by reference

2014-05-06 Thread Steven D'Aprano
On Tue, 06 May 2014 15:16:54 -0400, Terry Reedy wrote: > On 5/5/2014 8:39 PM, Satish Muthali wrote: >> Hello experts, >> >> I have a burning question on how to pass variable by reference in >> Python. > > Python passes objects to functions. CPython implements

Re: Pass variable by reference

2014-05-06 Thread Steven D'Aprano
On Tue, 06 May 2014 16:31:35 -0400, Ned Batchelder wrote: > On 5/6/14 12:42 AM, Gary Herron wrote: >> This gets confusing, but in fact the most accurate answer is that >> Python does not have "variables", so there is no such thing as passing >> "variabl

Re: The “does Python have variables?” debate (was: Pass variable by reference)

2014-05-06 Thread Chris Angelico
* have variables that work pretty much as expected by these > newcomers: the variables are declared and exist before a value is > assigned, they have the “box containing a value” conceptual model (as > contrasted with Python's “value with sticky-notes attached” model), the > “how do I

The “does Python have variables?” debate (was: Pass variable by reference)

2014-05-06 Thread Ben Finney
comment there. For Java, Javascript, PHP, they *do* have variables that work pretty much as expected by these newcomers: the variables are declared and exist before a value is assigned, they have the “box containing a value” conceptual model (as contrasted with Python's “value with sticky-notes atta

Re: Pass variable by reference

2014-05-06 Thread Chris Angelico
l strings, this sequence will work identically in all of them. Does BASIC have variables? Presumably, since you can pass them by reference. Does REXX? You can't pass by reference (all you can do is EXPOSE, which is more like scoping rules, only it isn't); a C function can fiddle with an

Re: Pass variable by reference

2014-05-06 Thread Ned Batchelder
On 5/6/14 5:00 PM, Mark H Harris wrote: On 5/6/14 3:31 PM, Ned Batchelder wrote: On 5/6/14 12:42 AM, Gary Herron wrote: This gets confusing, but in fact the most accurate answer is that Python does not have "variables", so there is no such thing as passing "variables" by re

Re: Pass variable by reference

2014-05-06 Thread Mark H Harris
On 5/6/14 3:31 PM, Ned Batchelder wrote: On 5/6/14 12:42 AM, Gary Herron wrote: This gets confusing, but in fact the most accurate answer is that Python does not have "variables", so there is no such thing as passing "variables" by reference or any other method. Python *do

Re: Pass variable by reference

2014-05-06 Thread Michael Torrie
On 05/05/2014 06:39 PM, Satish Muthali wrote: > I want to nuke /var/lib/postgresql/9.3.4/main/data , however > programatically I want it to be as: /var/lib/postgresql/ pgversion>/main/data > > Any help is appreciated. Not sure really. But if you want to pass a some data around that can be manip

Re: Pass variable by reference

2014-05-06 Thread Ned Batchelder
On 5/6/14 12:42 AM, Gary Herron wrote: This gets confusing, but in fact the most accurate answer is that Python does not have "variables", so there is no such thing as passing "variables" by reference or any other method. Python *does* have names bound to values, but tha

Re: Pass variable by reference

2014-05-06 Thread Terry Reedy
On 5/5/2014 8:39 PM, Satish Muthali wrote: Hello experts, I have a burning question on how to pass variable by reference in Python. Python passes objects to functions. CPython implements this by passing object pointers. In one sense, your request is impossible. In another, it already

Re: Pass variable by reference

2014-05-06 Thread Chris Angelico
On Tue, May 6, 2014 at 8:38 PM, Marko Rauhamaa wrote: > Chris Angelico : > >>> characters, words, lines = stats.read() >> >> That's not really pass-by-reference, though. What you're doing is >> output parameters, which are usually implemented in C wi

Re: Pass variable by reference

2014-05-06 Thread Marko Rauhamaa
Chris Angelico : >> characters, words, lines = stats.read() > > That's not really pass-by-reference, though. What you're doing is > output parameters, which are usually implemented in C with pointers, > but in Python with a return tuple. Correct, but it is wo

Re: Pass variable by reference

2014-05-06 Thread Chris Angelico
On Tue, May 6, 2014 at 7:11 PM, Marko Rauhamaa wrote: > Steven D'Aprano : > >> On Mon, 05 May 2014 17:39:44 -0700, Satish Muthali wrote: >>> I have a burning question on how to pass variable by reference in >>> Python. I understand that the data type has to be m

Re: Pass variable by reference

2014-05-06 Thread Marko Rauhamaa
Steven D'Aprano : > On Mon, 05 May 2014 17:39:44 -0700, Satish Muthali wrote: >> I have a burning question on how to pass variable by reference in >> Python. I understand that the data type has to be mutable. > > [...] > > To get an effect *similar* to pass

Re: Pass variable by reference

2014-05-06 Thread Steven D'Aprano
On Mon, 05 May 2014 17:39:44 -0700, Satish Muthali wrote: > Hello experts, > > I have a burning question on how to pass variable by reference in > Python. I understand that the data type has to be mutable. Python provides neither pass-by-reference nor pass-by-value argument pas

Re: Pass variable by reference

2014-05-05 Thread Gary Herron
On 05/05/2014 05:39 PM, Satish Muthali wrote: Hello experts, I have a burning question on how to pass variable by reference in Python. I understand that the data type has to be mutable. This gets confusing, but in fact the most accurate answer is that Python does not have "variables

Re: Pass variable by reference

2014-05-05 Thread Rustom Mody
On Tuesday, May 6, 2014 6:09:44 AM UTC+5:30, Satish Muthali wrote: > Hello experts, > I have a burning question on how to pass variable by reference in Python. Technically correct answer: You cant. But see below. > I understand that the data type has to be mutable. I dont know that m

Pass variable by reference

2014-05-05 Thread Satish Muthali
Hello experts, I have a burning question on how to pass variable by reference in Python. I understand that the data type has to be mutable. For example, here’s the issue I am running in to: I am trying to extract the PostgreSQL DB version for example: pgVer = [s.split() for s in os.popen

ctypes argument by reference

2011-12-28 Thread gaetan
l the callback if trans_init(pm_trans,flags, trans_cb_event(fpm_progress_event), trans_cb_conv(fpm_trans_conv), None) == -1 : foo... Into libpacman response is a C int pointer : ... QUESTION(trans, PM_TRANS_CONV_LOCAL_UPTODATE, local, NULL, NULL, &resp); ... but resp=0 howto pass re

Re: Pass by reference

2009-01-02 Thread alex goretoy
You are correct, terminology is a must. In order to stay on the same page. And yes, it;s not technically by ref. but it works for me at the moment. I was doing this in my code: l={"user":"asdf","pass":"goog"} d= { "login_url":"http://example.com/login";, "user":l["user"], "pass":l["pas

Re: Pass by reference

2009-01-02 Thread alex goretoy
You are correct, terminology is a must. In order to stay on the same page. And yes, it;s not technically by ref. but it works for me at the moment. I was doing this in my code: l={"user":"asdf","pass":"goog"} d= { "login_url":"http://example.com/login";, "user":l["user"], "pass":l["pas

Re: Pass by reference

2009-01-01 Thread Terry Reedy
alex goretoy wrote: I recently conquered this pass by ref thing. This is how I did it. What you did was to pass a mutable object and mutate it. Absolutely standard practice in Python. I am glad you learned it, but also learning and using the standard terminology will also help. Hope you e

Re: Pass by reference

2009-01-01 Thread alex goretoy
I recently conquered this pass by ref thing. This is how I did it. Python 2.4.3 (#1, Apr 3 2006, 14:02:53) [GCC 3.4.6] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> def f1(v): ... v="asdf" ... >>> def f2(v): ... v=["asdf"] ... >>> def f3(v): ...

Re: Pass by reference

2008-12-31 Thread Aaron Brady
On Dec 31, 5:30 am, iu2 wrote: > Hi, > > Is it possible somehow to change a varible by passing it to a > function? > > I tried this: > > def change_var(dict0, varname, val): >   dict0[varname] = val > > def test(): >   a = 100 >   change_var(locals(), 'a', 3) >   print a > > But test() didn't work

Re: Pass by reference

2008-12-31 Thread Chris Rebert
On Wed, Dec 31, 2008 at 5:04 AM, iu2 wrote: > For the 2 targets I have the variables comm1 and comm2. They are of > some class I wrote, representing many properties of the communication, > including the IP address. > There is one function that sends data, and it receives a commX var > (comm1 or c

Re: Pass by reference

2008-12-31 Thread iu2
On Dec 31, 1:48 pm, "Chris Rebert" wrote: ... > > Not really, or at the very least it'll be kludgey. Python uses > call-by-object (http://effbot.org/zone/call-by-object.htm), not > call-by-value or call-by-reference. > > Could you explain why you have to set so m

Re: Pass by reference

2008-12-31 Thread Bruno Desthuilliers
iu2 a écrit : Hi, Is it possible somehow to change a varible by passing it to a function? For which definition of "change a variable" ? I tried this: def change_var(dict0, varname, val): dict0[varname] = val Ok, this is mutating dict0, so it works. def test(): a = 100 change_var(

Re: Pass by reference

2008-12-31 Thread Chris Rebert
then > > var = creaet_obj(var) > > Is there another way? Not really, or at the very least it'll be kludgey. Python uses call-by-object (http://effbot.org/zone/call-by-object.htm), not call-by-value or call-by-reference. Could you explain why you have to set so many variable

Pass by reference

2008-12-31 Thread iu2
Hi, Is it possible somehow to change a varible by passing it to a function? I tried this: def change_var(dict0, varname, val): dict0[varname] = val def test(): a = 100 change_var(locals(), 'a', 3) print a But test() didn't work, the value a remains 100. I have several variables init

Re: Call by reference in SWIG?

2008-12-11 Thread Chris Mellon
On Thu, Dec 11, 2008 at 9:43 AM, Joe Strout wrote: > On Dec 10, 2008, at 10:19 PM, Nok wrote: > >> I can't get call-by-reference functions to work in SWIG... > > Python doesn't have any call-by-reference support at all [1], so I'm not > surprised that a

Re: Call by reference in SWIG?

2008-12-11 Thread Joe Strout
On Dec 10, 2008, at 10:19 PM, Nok wrote: I can't get call-by-reference functions to work in SWIG... Python doesn't have any call-by-reference support at all [1], so I'm not surprised that a straight translation of the call-by-reference C function doesn't work. Unfort

Call by reference in SWIG?

2008-12-10 Thread Nok
I can't get call-by-reference functions to work in SWIG... Even when wrapping a trivial example like this: /* File : trivial.i */ %module trivial %inline %{ class test { public: void foo(int *t) { *t=42; } }; %} I get a TypeError when trying to use it: import tr

Call by reference in SWIG?

2008-12-10 Thread Nok
I can't get call-by-reference functions to work in SWIG... Even when wrapping a trivial example like this: /* File : trivial.i */ %module trivial %inline %{ class test { public: void foo(int *t) { *t=42; } }; %} I get a TypeError when trying to use it: import tr

Re: call by reference howto????

2008-03-16 Thread Terry Reedy
"Steven D'Aprano" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | On Sat, 15 Mar 2008 11:50:17 -0700, Dennis Lee Bieber wrote: | | > Small integers are cached in Python, so they always have a fixed ID | > (address). | | Small integers are cached in CPython, making it an implementati

Re: call by reference howto????

2008-03-15 Thread Steven D'Aprano
On Sat, 15 Mar 2008 11:50:17 -0700, Dennis Lee Bieber wrote: > Small integers are cached in Python, so they always have a fixed ID > (address). Small integers are cached in CPython, making it an implementation- dependent feature. I don't believe that caching is promised by the language definitio

Re: call by reference howto????

2008-03-15 Thread sturlamolden
On 13 Mar, 09:22, Antoon Pardon <[EMAIL PROTECTED]> wrote: > Whatever python has for a calling convention, it is close enough that > naming it "call by reference" gives people a reasonable idea of what > is going on. Only to the extent that many mistake passing Java

Re: call by reference howto????

2008-03-15 Thread sturlamolden
On 28 Feb, 02:24, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > Python doesn't do call by reference. Nor does it do call by value. Please > pay no attention to anyone who says it does. Exactly. Python pass variables the same way as Lisp, which is neither

Re: call by reference howto????

2008-03-15 Thread sturlamolden
On 28 Feb, 02:24, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > Python doesn't do call by reference. Nor does it do call by value. Please > pay no attention to anyone who says it does. Exactly. Python pass variables the same way as Lisp, which is neither

Re: call by reference howto????

2008-03-15 Thread castironpi
On Mar 15, 12:39 am, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > On 14 Mar 2008 10:38:52 GMT, Antoon Pardon <[EMAIL PROTECTED]> > declaimed the following in comp.lang.python: > > > In that case I find it very strange that when this question comes > > up, I see so few attempts to explain how the

Re: call by reference howto????

2008-03-14 Thread Antoon Pardon
mer Higazi wrote: >| > >| >> Hi! >| >> Can somebody of you make me a sample how to define a function based on >| >> "call by reference" ??? >| > >| > Python doesn't do call by reference. Nor does it do call by value. > Please >| &g

Re: call by reference howto????

2008-03-14 Thread Antoon Pardon
On 2008-03-13, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > On Thu, 13 Mar 2008 08:54:43 +, Paul Rudin wrote: > >>> Whatever python has for a calling convention, it is close enough that >>> naming it "call by reference" gives people a reasonable id

Re: call by reference howto????

2008-03-13 Thread Steven D'Aprano
On Thu, 13 Mar 2008 08:54:43 +, Paul Rudin wrote: >> Whatever python has for a calling convention, it is close enough that >> naming it "call by reference" gives people a reasonable idea of what is >> going on. > > Quite. The thing is not to get hung up wi

Re: call by reference howto????

2008-03-13 Thread Terry Reedy
how to define a function based on | >> "call by reference" ??? | > | > Python doesn't do call by reference. Nor does it do call by value. Please | > pay no attention to anyone who says it does. | | Whatever python has for a calling convention, it is close enough that

Re: call by reference howto????

2008-03-13 Thread Paul Rudin
Antoon Pardon <[EMAIL PROTECTED]> writes: > On 2008-02-28, Steven D'Aprano <[EMAIL PROTECTED]> wrote: >> On Thu, 28 Feb 2008 02:02:19 +0200, Tamer Higazi wrote: >> >>> Hi! >>> Can somebody of you make me a sample how to define a function based o

Re: call by reference howto????

2008-03-13 Thread Antoon Pardon
On 2008-02-28, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > On Thu, 28 Feb 2008 02:02:19 +0200, Tamer Higazi wrote: > >> Hi! >> Can somebody of you make me a sample how to define a function based on >> "call by reference" ??? > > Python doesn&#

Re: call by reference howto????

2008-02-29 Thread Aahz
In article <[EMAIL PROTECTED]>, Steve Holden <[EMAIL PROTECTED]> wrote: > >As near as I can make out you appear to want to have thang delegate >certain of its method to thang.this. The easiest way to do that would be >to implement a __getattr__() in the Thang class to do so, but remember >that

Re: call by reference howto????

2008-02-29 Thread castironpi
> >>>> Hi! > >>>> Can somebody of you make me a sample how to define a function based on > >>>> "call by reference" ??? > >>>> I am a python newbie and I am not getting smart how to define functions, > >>>> that shoul

Re: call by reference howto????

2008-02-29 Thread Steve Holden
[EMAIL PROTECTED] wrote: > On Feb 29, 5:56 am, Steve Holden <[EMAIL PROTECTED]> wrote: >> [EMAIL PROTECTED] wrote: >>> On Feb 27, 6:02 pm, Tamer Higazi <[EMAIL PROTECTED]> wrote: >>>> Hi! >>>> Can somebody of you make me a sample how

Re: call by reference howto????

2008-02-29 Thread castironpi
On Feb 29, 5:56 am, Steve Holden <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > On Feb 27, 6:02 pm, Tamer Higazi <[EMAIL PROTECTED]> wrote: > >> Hi! > >> Can somebody of you make me a sample how to define a function based on > >> "cal

Re: call by reference howto????

2008-02-29 Thread Steve Holden
[EMAIL PROTECTED] wrote: > On Feb 27, 6:02 pm, Tamer Higazi <[EMAIL PROTECTED]> wrote: >> Hi! >> Can somebody of you make me a sample how to define a function based on >> "call by reference" ??? >> >> I am a python newbie and I am not getting sma

Re: call by reference howto????

2008-02-28 Thread castironpi
On Feb 27, 6:02 pm, Tamer Higazi <[EMAIL PROTECTED]> wrote: > Hi! > Can somebody of you make me a sample how to define a function based on > "call by reference" ??? > > I am a python newbie and I am not getting smart how to define functions, > that should modify

Re: call by reference howto????

2008-02-28 Thread Steve Holden
[EMAIL PROTECTED] wrote: > On Feb 27, 10:38 pm, Dan Bishop <[EMAIL PROTECTED]> wrote: > >> What exactly are you wanting to do? > > I'm having a hard time considering your question in the general case. > I'm thinking of too many cases, the details of which are relevant to > the answer, to even sub

Re: call by reference howto????

2008-02-27 Thread castironpi
On Feb 27, 10:38 pm, Dan Bishop <[EMAIL PROTECTED]> wrote: > What exactly are you wanting to do? I'm having a hard time considering your question in the general case. I'm thinking of too many cases, the details of which are relevant to the answer, to even subdivide them. My specialty is specific

Re: call by reference howto????

2008-02-27 Thread Dan Bishop
On Feb 27, 6:02 pm, Tamer Higazi <[EMAIL PROTECTED]> wrote: > Hi! > Can somebody of you make me a sample how to define a function based on > "call by reference" ??? > > I am a python newbie and I am not getting smart how to define functions, > that should modify

Re: call by reference howto????

2008-02-27 Thread 7stud
On Feb 27, 5:02 pm, Tamer Higazi <[EMAIL PROTECTED]> wrote: > Hi! > Can somebody of you make me a sample how to define a function based on > "call by reference" ??? > > I am a python newbie and I am not getting smart how to define functions, > that should modify

Re: call by reference howto????

2008-02-27 Thread Gabriel Genellina
En Wed, 27 Feb 2008 22:02:19 -0200, Tamer Higazi <[EMAIL PROTECTED]> escribió: > Can somebody of you make me a sample how to define a function based on > "call by reference" ??? > > I am a python newbie and I am not getting smart how to define functions, > that shou

Re: call by reference howto????

2008-02-27 Thread Steven D'Aprano
On Thu, 28 Feb 2008 02:02:19 +0200, Tamer Higazi wrote: > Hi! > Can somebody of you make me a sample how to define a function based on > "call by reference" ??? Python doesn't do call by reference. Nor does it do call by value. Please pay no attention to anyone who says

call by reference howto????

2008-02-27 Thread Tamer Higazi
Hi! Can somebody of you make me a sample how to define a function based on "call by reference" ??? I am a python newbie and I am not getting smart how to define functions, that should modify the variable I passed by reference. thanks in advance Tamer -- http://mail.python.o

Re: Passing by reference

2007-12-23 Thread Marc 'BlackJack' Rintsch
On Sun, 23 Dec 2007 03:10:48 -0800, MartinRinehart wrote: > Bruno, right now I've got this: > > def __init__ ( self, t ): > """ Constructor, called with array of strings. """ > > self.text = t > ... > > Some other program will say: > tok = Toker( text_array ) > tokens = tok.tokenize

  1   2   3   >