Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define a python string (quasi-)constant that has dynamic inputs?

For example:

MY_MESSAGE = 'Dear %s, hello.'
# ...
name = "jj"
print MY_MESSAGE % name

Does python have a feature for accomplishing something like my above code?

like image 276
Dolan Antenucci Avatar asked Dec 21 '22 09:12

Dolan Antenucci


2 Answers

Yes, the exact way you wrote it. Your code is fine.

like image 69
mal-wan Avatar answered Dec 24 '22 03:12

mal-wan


Python does not really have the same concept of "constant" that you will find in C. So what you have there is a fairly good approach.

I would actually argue that this is one example of "we're all consenting adults" does not hold up terribly well. Think the language is awesome, but a constant every now and again would be... nice.

like image 35
cwallenpoole Avatar answered Dec 24 '22 03:12

cwallenpoole