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 i
> 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 t
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 b
> [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
se
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 ?
>>
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
>
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.
[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 furthe
[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 mis
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 equ
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 l
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
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 object
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 lang
[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 th
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 makin
[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
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
> 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
[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 decla
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 consta
[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 modifie
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 langua
[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 ab
[EMAIL PROTECTED] wrote:
> 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
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, this
26 matches
Mail list logo