Re: IsString

2005-12-17 Thread Alex Martelli
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

Re: IsString

2005-12-16 Thread Steve Holden
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'

Re: IsString

2005-12-15 Thread Donn Cave
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

Re: IsString

2005-12-15 Thread Mike Meyer
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

RE: IsString

2005-12-15 Thread Delaney, Timothy (Tim)
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

Re: IsString

2005-12-15 Thread Chris Mellon
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

Re: IsString

2005-12-15 Thread Chris Mellon
> 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

Re: IsString

2005-12-15 Thread Steven D'Aprano
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

Re: IsString

2005-12-15 Thread Steven D'Aprano
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

Re: IsString

2005-12-15 Thread Steve Holden
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

Re: IsString

2005-12-14 Thread Donn Cave
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,

Re: IsString

2005-12-14 Thread Mike Meyer
"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

Re: IsString

2005-12-14 Thread bonono
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

Re: IsString

2005-12-14 Thread Mike Meyer
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

Re: IsString

2005-12-14 Thread Mike Meyer
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,

Re: IsString

2005-12-14 Thread Tuvas
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

Re: IsString

2005-12-14 Thread Fredrik Lundh
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

Re: IsString

2005-12-14 Thread Donn Cave
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

Re: IsString

2005-12-14 Thread Steven D'Aprano
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

Re: IsString

2005-12-14 Thread Tom Anderson
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

Re: IsString

2005-12-14 Thread Tom Anderson
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

Re: IsString

2005-12-14 Thread Tom Anderson
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 ; /

Re: IsString

2005-12-14 Thread Tom Anderson
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

Re: IsString

2005-12-14 Thread Tom Anderson
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.

Re: IsString

2005-12-14 Thread Mike Meyer
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

Re: IsString

2005-12-14 Thread Ben Sizer
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

Re: IsString

2005-12-14 Thread Steven D'Aprano
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

Re: IsString

2005-12-13 Thread Mike Meyer
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

Re: IsString

2005-12-13 Thread Steven D'Aprano
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

Re: IsString

2005-12-13 Thread Fredrik Lundh
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

Re: IsString

2005-12-13 Thread Xavier Morel
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

Re: IsString

2005-12-13 Thread Steven D'Aprano
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

Re: IsString

2005-12-13 Thread Xavier Morel
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

Re: IsString

2005-12-13 Thread Fredrik Lundh
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

Re: IsString

2005-12-13 Thread Steve Holden
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

Re: IsString

2005-12-13 Thread Tom Anderson
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

Re: IsString

2005-12-13 Thread Tuvas
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

Re: IsString

2005-12-13 Thread Duncan Booth
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

Re: IsString

2005-12-13 Thread Gary Herron
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 ...

Re: IsString

2005-12-13 Thread Steven D'Aprano
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

Re: IsString

2005-12-12 Thread Larry Bates
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... > > >

Re: IsString

2005-12-12 Thread Steven Bethard
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

Re: IsString

2005-12-12 Thread Steven D'Aprano
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

Re: IsString

2005-12-12 Thread Steven Bethard
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

Re: IsString

2005-12-12 Thread Larry Bates
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),

Re: IsString

2005-12-12 Thread Peter Decker
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

Re: IsString

2005-12-12 Thread Rick Wotnaz
"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

IsString

2005-12-12 Thread Tuvas
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