String flags - redundant?

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Tue Jul 15 11:39:39 EDT 2008


On Tue, 15 Jul 2008 18:14:15 +0300, Alexandru Palade wrote:

> I'm rather a Python newbie, so I've put myself a question. Are these two 
> statements (performance-wise) equal?
> 
> r""" Text """
> and
> """ Text """
> 
> I mean using the raw flag speeds up things because the interpreter 
> doesn't need to look after escape sequences? Or it's rather optimized? 
> I'm asking you this because I want to know how my """-style comments 
> should be written in order not to affect the performance.

*Please* stop worrying about the speed of the compilation here.  If you
have doubts about speed then measure and find the bottlenecks in your code
and iff you find hotspots *then* try to optimize.  But only iff the
program is *to slow*, not when it's fast enough anyway.  In that case you
should always favor more readable code above speed.

> And another short question... Are there any flags to specify variables 
> intercalation in a string? I mean "I have x apples", how can i specify 
> for the interpreter to substitute x with it's value? (in case *x* is a 
> variable). And if this flag exists is it better to use "I have " + x + " 
> apples" or the above mentioned way?

Maybe you should work through the tutorial in the Python documentation.

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list