Steven D'Aprano <[EMAIL PROTECTED]> wrote:
> If you think about Python
> as if it were C or Java, you will forever be confused about its behaviour.
Thinking of it as Java actually works great here.
> Understand Python's call by object behaviour, and it will all make sense.
Java's behavior is id
Steven D'Aprano wrote:
> On Thu, 15 Dec 2005 08:22:37 +, Steve Holden wrote:
>
>
>>Hear, hear. However you describe it Python is what it is, and this
>>interminable discussion about its similarities with and differences from
>>various concepts (most lately call by name/call by value) doesn'
Quoth Chris Mellon <[EMAIL PROTECTED]>:
|
|> Terminology is important, because we understand the world through
|> language. If your language is confused or misleading, your understanding
|> will also be confused or incomplete.
|
| I think the issue is pretty simple, myself:
|
| With mutable object
Chris Mellon <[EMAIL PROTECTED]> writes:
> I think the issue is pretty simple, myself:
> With mutable objects, Python has the semantics normally associated
> with pass-by-reference.
Except when it doesn't. For instance, if that were true, then in this:
>>> def inc(x):
... x = x + [1]
...
>>> y
Chris Mellon wrote:
>
>> Terminology is important, because we understand the world through
>> language. If your language is confused or misleading, your
>> understanding will also be confused or incomplete.
>
> I think the issue is pretty simple, myself:
>
> So you could say that Python has bot
On 12/15/05, Chris Mellon <[EMAIL PROTECTED]> wrote:
>
> > Terminology is important, because we understand the world through
> > language. If your language is confused or misleading, your understanding
> > will also be confused or incomplete.
>
> I think the issue is pretty simple, myself:
>
> Wit
> Terminology is important, because we understand the world through
> language. If your language is confused or misleading, your understanding
> will also be confused or incomplete.
I think the issue is pretty simple, myself:
With mutable objects, Python has the semantics normally associated
wit
On Wed, 14 Dec 2005 18:17:57 -0800, Tuvas wrote:
> I don't know if I can help with this much, I'm still somewhat new to
> python, but it is my understanding that "simple" variable, ei, strings,
> ints, etc, although they don't have such names, behave like variables,
> ei, if you pass them to a fun
On Thu, 15 Dec 2005 08:22:37 +, Steve Holden wrote:
> Hear, hear. However you describe it Python is what it is, and this
> interminable discussion about its similarities with and differences from
> various concepts (most lately call by name/call by value) doesn't much
> aid understanding fo
Donn Cave wrote:
> Quoth Mike Meyer <[EMAIL PROTECTED]>:
> | Donn Cave <[EMAIL PROTECTED]> writes:
> ...
>
> The question is whether basically everyone needs to get there, or we
> can expect the masses to use the language _without understanding it_
> in this sense, without understanding the langua
Quoth Mike Meyer <[EMAIL PROTECTED]>:
| Donn Cave <[EMAIL PROTECTED]> writes:
...
|> Historically, the way I remember it, there was a time not too
|> long ago when GvR and his minions sort of dismissed the idea
|> that you needed to understand the reference/object model from
|> the outset. I mean,
"Tuvas" <[EMAIL PROTECTED]> writes:
> I don't know if I can help with this much, I'm still somewhat new to
> python, but it is my understanding that "simple" variable, ei, strings,
> ints, etc, although they don't have such names, behave like variables,
> ei, if you pass them to a function, the fun
Tuvas wrote:
> I don't know if I can help with this much, I'm still somewhat new to
> python, but it is my understanding that "simple" variable, ei, strings,
> ints, etc, although they don't have such names, behave like variables,
> ei, if you pass them to a function, the function will copy them i
Donn Cave <[EMAIL PROTECTED]> writes:
> I would like to argue that "value" basically means the
> computational effect. In "s = a + b", the value of "b"
> is whatever ends up applied to that "+" operator. In
> isolation, the value of some object is its computational
> potential - the object isn't
Tom Anderson <[EMAIL PROTECTED]> writes:
>> Python does call by reference, which means that it passes pointers
>> to objects by value.
> That's not what call by reference is - call by reference is passing
> pointers to *variables* by value.
In which case, Python can't do call-by-reference at all,
I don't know if I can help with this much, I'm still somewhat new to
python, but it is my understanding that "simple" variable, ei, strings,
ints, etc, although they don't have such names, behave like variables,
ei, if you pass them to a function, the function will copy them into a
new spot. Howeve
Donn Cave wrote:
> While I agree (with another post) that there seems to be
> a difference in perspective that depends on what language
> you were using when you first heard these terms, in the
> end it really seems sort of almost disingenuous to argue
> that the "value" in question is actually a
In article <[EMAIL PROTECTED]>,
"Ben Sizer" <[EMAIL PROTECTED]> wrote:
> Steven D'Aprano wrote:
> > def modify_in_place(obj):
> > """Modify an arbitrary object in place."""
> > obj = None
> >
> > x = [1, 2, 3] # mutable object
> > modify_in_place(x)
> > assert x is None
> >
> >
> > Doesn't
On Wed, 14 Dec 2005 12:51:43 -0500, Mike Meyer wrote:
> To restate the first paragraph: Python's calling semantics are a
> proper subset of call-by-reference. If the object passed has the same
> behavior as it does in a call-by-reference lanuage, then the behavior
> of the argument is the same as
On Tue, 13 Dec 2005, Steve Holden wrote:
> Tom Anderson wrote:
>> On Tue, 13 Dec 2005, Steven D'Aprano wrote:
>>
>>> On Mon, 12 Dec 2005 18:51:36 -0600, Larry Bates wrote:
>>>
>>> [snippidy-doo-dah]
>>>
I had the same thought, but reread the post. He asks "if a given
variable is a c
On Wed, 14 Dec 2005, Steven D'Aprano wrote:
> On Tue, 13 Dec 2005 15:28:32 +, Tom Anderson wrote:
>
>> On Tue, 13 Dec 2005, Steven D'Aprano wrote:
>>
>>> On Mon, 12 Dec 2005 18:51:36 -0600, Larry Bates wrote:
>>>
>>> [snippidy-doo-dah]
>>>
I had the same thought, but reread the post. He
On Tue, 13 Dec 2005, Mike Meyer wrote:
> You can show the same difference in behavior between Python and C (for
> example) without using a function call.
Really? You certainly don't do that with the code below.
> Here's C:
>
> #include
>
> main() {
> int i, *ref ;
> i = 1 ;
> ref = &i ; /
On Tue, 13 Dec 2005, Xavier Morel wrote:
> Tom Anderson wrote:
>
>> In what sense are the names-bound-to-references-to-objects not
>> variables?
>
> In the sense that a variable has various meta-informations (at least a
> type)
No. In a statically typed language (or possibly only a manifestly t
On Tue, 13 Dec 2005, Fredrik Lundh wrote:
> Steve Holden wrote:
>
>> In Python a name (*not* a "variable", though people do talk loosely
>> about "instance variables" and "class variables" just to be able to use
>> terms familiar to users of other to languages) is simply *bound* to a
>> value.
Steven D'Aprano <[EMAIL PROTECTED]> writes:
> Mike Meyer wrote:
>>>So Python behaves demonstrably different from BOTH call by value and call
>>>by reference. Consequently, it is neither of them.
>> Right. *Python* behaves differently. That's not the same thing as
>> Python's calling behaving differ
Steven D'Aprano wrote:
> def modify_in_place(obj):
> """Modify an arbitrary object in place."""
> obj = None
>
> x = [1, 2, 3] # mutable object
> modify_in_place(x)
> assert x is None
>
>
> Doesn't work either.
To be fair, this isn't because the function is not pass by reference,
but becau
Mike Meyer wrote:
>>So Python behaves demonstrably different from BOTH call by value and call
>>by reference. Consequently, it is neither of them.
>
>
> Right. *Python* behaves differently. That's not the same thing as
> Python's calling behaving differently. If you choose objects that are
> beh
Steven D'Aprano <[EMAIL PROTECTED]> writes:
> But neither is it call by reference. If it were call by reference, I could
> write something like this:
>
> def increment(n):
> """Add one to the argument changing it in place."""
> # In Pascal, I would need the var keyword to get this behaviour
On Tue, 13 Dec 2005 23:21:02 +0100, Xavier Morel wrote:
> Steven D'Aprano wrote:
>> name = "spam spam spam spam"
>>
>> the value of the variable "name" is a pointer, and not a string. Riiight.
>>
> Yes, it's a reference to an object of type string holding the value
>
The underlying C implemen
Xavier Morel wrote:
> Now use a mutable type instead of an immutable int and you'll notice a
> pass-by-reference behavior.
python passes a reference to the value, not a reference to the variable.
call-by-reference usually refers to the latter. see e.g.
http://foldoc.org/?call-by-reference
Steven D'Aprano wrote:
> name = "spam spam spam spam"
>
> the value of the variable "name" is a pointer, and not a string. Riiight.
>
Yes, it's a reference to an object of type string holding the value
> def increment(n):
> """Add one to the argument changing it in place."""
> # In Pas
On Tue, 13 Dec 2005 15:28:32 +, Tom Anderson wrote:
> On Tue, 13 Dec 2005, Steven D'Aprano wrote:
>
>> On Mon, 12 Dec 2005 18:51:36 -0600, Larry Bates wrote:
>>
>> [snippidy-doo-dah]
>>
>>> I had the same thought, but reread the post. He asks "if a given
>>> variable is a character or a num
Tom Anderson wrote:
> In what sense are the names-bound-to-references-to-objects not variables?
>
In the sense that a variable has various meta-informations (at least a
type) while a Python name has no information. A Python name would be
equivalent to a C void pointer, it can mean *any*thing an
Steve Holden wrote:
> In Python a name (*not* a "variable", though people do talk loosely
> about "instance variables" and "class variables" just to be able to use
> terms familiar to users of other to languages) is simply *bound* to a
> value. The only storage that is required, therefore, is eno
Tom Anderson wrote:
> On Tue, 13 Dec 2005, Steven D'Aprano wrote:
>
>
>>On Mon, 12 Dec 2005 18:51:36 -0600, Larry Bates wrote:
>>
>>[snippidy-doo-dah]
>>
>>
>>>I had the same thought, but reread the post. He asks "if a given
>>>variable is a character or a number". I figured that even if he is
On Tue, 13 Dec 2005, Steven D'Aprano wrote:
> On Mon, 12 Dec 2005 18:51:36 -0600, Larry Bates wrote:
>
> [snippidy-doo-dah]
>
>> I had the same thought, but reread the post. He asks "if a given
>> variable is a character or a number". I figured that even if he is
>> coming from another languag
LOL. As to me being a newbie to programming, well, I've been
programming to some extent for the last 10 years, although never
professionally. The first few questions were enough to help me solve
the problem that I had. And I've been programming Python for 4 months
or so, but it's been pretty intens
Gary Herron wrote:
> In Python, all values have an associated type which you can query with
> type(v) thus:
>
> from types import *
>
> if type(v) == IntType:
> ... whatever ...
>
> Several types would qualify as "numbers": IntType, FloatType, LongType,
> and ComplexType,
> and sev
Tuvas wrote:
>I need a function that will tell if a given variable is a character or
>a number. Is there a way to do this? Thanks!
>
>
>
In Python, all values have an associated type which you can query with
type(v) thus:
from types import *
if type(v) == IntType:
... whatever ...
On Mon, 12 Dec 2005 18:51:36 -0600, Larry Bates wrote:
[snippidy-doo-dah]
> I had the same thought, but reread the post. He asks "if a given
> variable is a character or a number". I figured that even if he
> is coming from another language he knows the difference between
> "a given variable" a
Steven D'Aprano wrote:
> On Mon, 12 Dec 2005 14:24:48 -0700, Steven Bethard wrote:
>
>
>>Tuvas wrote:
>>
>>>I need a function that will tell if a given variable is a character or
>>>a number. Is there a way to do this? Thanks!
>>
>>What's your use case? This need is incommon in Python...
>
>
>
Steven D'Aprano wrote:
> Judging by the tone of the original poster's question, I'd say for sure he
> is an utter Python newbie, probably a newbie in programming in general,
> so I bet that what (s)he really wants is something like this:
>
> somefunction("6")
> -> It is a number.
>
> somefunction
On Mon, 12 Dec 2005 14:24:48 -0700, Steven Bethard wrote:
> Tuvas wrote:
>> I need a function that will tell if a given variable is a character or
>> a number. Is there a way to do this? Thanks!
>
> What's your use case? This need is incommon in Python...
No offense to the four or five helpful
Tuvas wrote:
> I need a function that will tell if a given variable is a character or
> a number. Is there a way to do this? Thanks!
What's your use case? This need is incommon in Python...
STeVe
--
http://mail.python.org/mailman/listinfo/python-list
Tuvas wrote:
> I need a function that will tell if a given variable is a character or
> a number. Is there a way to do this? Thanks!
>
You can test the type of the object as follows:
>>> a='abc'
>>> isinstance(a, str)
True
>>> isinstance(a, (list, tuple))
False
>>>
The old way was to use type(a),
On 12 Dec 2005 08:26:06 -0800, Tuvas <[EMAIL PROTECTED]> wrote:
> I need a function that will tell if a given variable is a character or
> a number. Is there a way to do this? Thanks!
Use isinstance().
e.g.:
x = 7
isinstance(x, int)
-> True
isinstance(x, basestring)
-> False
x = "Hello"
isinstan
"Tuvas" <[EMAIL PROTECTED]> wrote in
news:[EMAIL PROTECTED]:
> I need a function that will tell if a given variable is a
> character or a number. Is there a way to do this? Thanks!
>
If you really need to, you can test for type:
>>> for x in ['3',3,3.1,3j]:
... print type(x)
>>> for x
I need a function that will tell if a given variable is a character or
a number. Is there a way to do this? Thanks!
--
http://mail.python.org/mailman/listinfo/python-list
48 matches
Mail list logo