Defining constant strings
Peter Otten
__peter__ at web.de
Sun Aug 27 12:31:09 EDT 2006
Hans wrote:
> 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?
No, this is not really not possible in Python:
$ ls
preprocess.pyp
$ cat preprocess.pyp
#define MYSTRING "Hello, world"
def f():
print "Goodbye, " MYOTHERSTRING
print MYSTRING
f()
$ gcc -DMYOTHERSTRING="'sanity'" -xc -E preprocess.pyp -o preprocess.py
$ python preprocess.py
Hello, world
Goodbye, sanity
$
:-)
Peter
More information about the Python-list
mailing list