Defining constant strings

danielx danielwong at berkeley.edu
Sun Aug 27 12:53:02 EDT 2006


I would really like to highlight something Tal has already said: Python
strings are immutable. That means if you construct a string object, you
don't have to worry about someone else going in and changing that
object. What might happen, however, is that someone might reassign a
variable you have which points to that object. You can tell people not
to do this (although you can't force them) using a mechanism Tal has
also described. You give your variable a name which is all caps.

Hans wrote:
> Hi,
>
> I want to define a couple of constant strings, like in C:
> #define mystring "This is my string"
> or using a const char construction.
>
> Is this really not possible in Python?
>
> Hans
> ------=_NextPart_000_004E_01C6C9FF.C5137CF0
> Content-Type: text/html; charset=iso-8859-1
> Content-Transfer-Encoding: quoted-printable
> X-Google-AttachSize: 902
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
> <HTML><HEAD>
> <META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
> <META content="MSHTML 6.00.2900.2604" name=GENERATOR>
> <STYLE></STYLE>
> </HEAD>
> <BODY bgColor=#e6e3df>
> <DIV><FONT face=Arial size=2>Hi,</FONT></DIV>
> <DIV><FONT face=Arial size=2></FONT> </DIV>
> <DIV><FONT face=Arial size=2>I want to define a couple of constant strings, like
> in C:</FONT></DIV>
> <DIV><FONT face=Arial size=2>#define mystring "This is my string"</FONT></DIV>
> <DIV><FONT face=Arial size=2>or using a const char construction.</FONT></DIV>
> <DIV><FONT face=Arial size=2></FONT> </DIV>
> <DIV><FONT face=Arial size=2>Is this really not possible in Python?</FONT></DIV>
> <DIV><FONT face=Arial size=2></FONT> </DIV>
> <DIV><FONT face=Arial size=2>Hans</FONT></DIV></BODY></HTML>
> 
> ------=_NextPart_000_004E_01C6C9FF.C5137CF0--




More information about the Python-list mailing list