Piet van Oostrum wrote:
Edward Elliott [EMAIL PROTECTED] (EE) wrote:
EE Piet van Oostrum wrote:
[EMAIL PROTECTED] (T) wrote:
T As you can see, the constant A can be modified this easily. But if
T there were an intuitive mechanism to declare a symbol to be immutable,
T then there won't be
Edward Elliott [EMAIL PROTECTED] (EE) wrote:
EE Piet van Oostrum wrote:
[EMAIL PROTECTED] (T) wrote:
T As you can see, the constant A can be modified this easily. But if
T there were an intuitive mechanism to declare a symbol to be immutable,
T then there won't be this problem.
Mutability
[EMAIL PROTECTED] (T) wrote:
T As you can see, the constant A can be modified this easily. But if
T there were an intuitive mechanism to declare a symbol to be immutable,
T then there won't be this problem.
Mutability is not a property of symbols but of values. So it doesn't make
sense to
Piet van Oostrum wrote:
[EMAIL PROTECTED] (T) wrote:
T As you can see, the constant A can be modified this easily. But if
T there were an intuitive mechanism to declare a symbol to be immutable,
T then there won't be this problem.
Mutability is not a property of symbols but of values. So it
Fredrik Lundh a écrit :
Christophe wrote:
I think you've made a mistake in your example.
constant A = []
def foo(var):
... var.append('1')
... print var
...
b = A
foo(b)
foo(b)
and this ?
constant A = []
print A
Edward Elliott wrote:
Michele Simionato wrote:
A = [] # let's declare a constant here
b = A # and let's assign the constant here
b.append('1') # OOPS!
But it makes no sense to use a mutable object for a constant!
The user should use a tuple,
Sure. Now show me the builtin
Christophe wrote:
I think you've made a mistake in your example.
constant A = []
def foo(var):
... var.append('1')
... print var
...
b = A
foo(b)
foo(b)
and this ?
constant A = []
print A is A
Obviously, False.
why
Christophe wrote:
That's easy, since A is a symbolic constant know at compile time, and
since it's a known mutable objet, the code once compiled will be
equivalent to:
b = [[]]
# much later
b|0].append('1')
the OP talked about constants as names for immutable objects, not pre-
Fredrik Lundh a écrit :
Christophe wrote:
That's easy, since A is a symbolic constant know at compile time, and
since it's a known mutable objet, the code once compiled will be
equivalent to:
b = [[]]
# much later
b|0].append('1')
the OP talked about constants as names for
Edward Elliott wrote:
Michele Simionato wrote:
Python solution is to rely on the intelligence of programmers. If they
see an all caps name and then they try to change it without knowing what
they are doing, then they are stupid. If you have stupid programmers there
is no way the language
Michele Simionato wrote:
A = [] # let's declare a constant here
b = A # and let's assign the constant here
b.append('1') # OOPS!
But it makes no sense to use a mutable object for a constant!
The user should use a tuple,
Sure. Now show me the builtin immutable equivalent of a dict.
[EMAIL PROTECTED] a écrit :
Bruno Desthuilliers wrote:
[EMAIL PROTECTED] a écrit :
Hi Pythonians,
To begin with I'd like to apologize that I am not very experienced
Python programmer so please forgive me if the following text does not
make any sense.
I have been missing constants in Python
[EMAIL PROTECTED] a écrit :
Yes, I know that constant A will also be modified as the b[0] points
to A. Obviously the [] should be marked as immutable, as A is declared
to be constant thus immutable. If somebody tries to modify this
immutable object an error would occur.
When I further
[EMAIL PROTECTED] wrote:
For example:
A = [] # let's declare a constant here
b = A # and let's assign the constant here
b.append('1') # OOPS!
c = A
print A
['1']
print b
['1']
print c
['1']
As you can see, the constant A can be modified this easily. But if
there were an
Yes, I know that constant A will also be modified as the b[0] points
to A. Obviously the [] should be marked as immutable, as A is declared
to be constant thus immutable. If somebody tries to modify this
immutable object an error would occur.
When I further thought about this problem with
[EMAIL PROTECTED] wrote:
Yes, I know that constant A will also be modified as the b[0] points
to A. Obviously the [] should be marked as immutable, as A is declared
to be constant thus immutable. If somebody tries to modify this
immutable object an error would occur.
so a constant
are you sure you know how Python's object model work ? if you do, please
explain your proposal in terms of what needs to be changed, rather than in
terms of wishful thinking.
No, I do not know. As stated in my first post, I am quite newbie in
Python and miss a simple and intuitive mechanism
Fredrik Lundh a écrit :
[EMAIL PROTECTED] wrote:
For example:
A = [] # let's declare a constant here
b = A # and let's assign the constant here
b.append('1') # OOPS!
c = A
print A
['1']
print b
['1']
print c
['1']
As you can see, the constant A can be modified this easily. But if
[EMAIL PROTECTED] wrote:
As stated in my first post, I am quite newbie in
Python and miss a simple and intuitive mechanism that would allow to
declare something as constant and that would protect these constant
objects from accidental modifications.
T.S.
Python solution is to rely on the
Michele Simionato wrote:
Python solution is to rely on the intelligence of programmers. If they
see an all caps name and then they try to change it without knowing what
they are doing, then they are stupid. If you have stupid programmers there
is no way the language can stop them for making
[EMAIL PROTECTED] wrote:
What I'd like to see here is that b gets a copy of A so that the
original A won't be modified as we play with b. However, as we assign a
constant value A to b, I wouldn't want to restrict myself from playing
with b.
If A is a list you can take a copy-slice liek this:
Edward Elliott wrote:
Michele Simionato wrote:
Python solution is to rely on the intelligence of programmers. If they
see an all caps name and then they try to change it without knowing what
they are doing, then they are stupid. If you have stupid programmers
there is no way the language can
[EMAIL PROTECTED] a écrit :
Hi Pythonians,
To begin with I'd like to apologize that I am not very experienced
Python programmer so please forgive me if the following text does not
make any sense.
I have been missing constants in Python language.
Why so ?
I guess you're talking about
Bruno Desthuilliers wrote:
[EMAIL PROTECTED] a écrit :
Hi Pythonians,
To begin with I'd like to apologize that I am not very experienced
Python programmer so please forgive me if the following text does not
make any sense.
I have been missing constants in Python language.
Why so ?
Hi Pythonians,
To begin with I'd like to apologize that I am not very experienced
Python programmer so please forgive me if the following text does not
make any sense.
I have been missing constants in Python language. There are some
workarounds available, for example the const-module. To me,
25 matches
Mail list logo