字符串即时更改 [英] String changing on the fly

查看:90
本文介绍了字符串即时更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我是Python新手。你可以告诉我,如果以下是

可能。


我的用户正在使用其他脚本语言来编写脚本。他们

用来写东西(保持简单)

T = 100

do_action(''花费$ T美元''' )


其中上述语法(''花费$ T美元'')被称为(''它

花费100美元'')。

我通过使用''it cost''+ str(T)+'''''来看到这样做。

但是试图让它向后兼容,有没有办法让

函数do_action,它位于一个单独的文件中,以

取原始字符串(带''$ T'' )并将其替换为价值

的T?


欢呼

解决方案

< blockquote> T dollar'')


其中上述语法(''It cost


T dollar'')被编入为'''它

花费100美元'')。

我通过使用''it cost''+ str(T)+''dollar'来看待它'。

但是试图让它向后兼容,是否有一种方法可以将

函数do_action置于一个单独的文件中,以

取原始字符串(带''


T'')并将其替换为值

的T?


欢呼


Hi,

I''m new to Python. Can you please tell me if the following is
possible.

My users are using other scripting launguage to write scripts. They
are used to write somthing like (keeping it simple)
T = 100
do_action (''It cost $T dollars'')

where the above syntax (''It cost $T dollars'') is interperted as (''It
cost 100 dollars'').
I saw on way of doing it by using ''it cost ''+ str(T) + '' dollars''.
But trying to keep it backward compatible, is there a way for the
function do_action, which resides in a class in a seperate file, to
take the original string (with the ''$T'') and replace it with the value
of T?

cheers

解决方案

T dollars'')

where the above syntax (''It cost


T dollars'') is interperted as (''It
cost 100 dollars'').
I saw on way of doing it by using ''it cost ''+ str(T) + '' dollars''.
But trying to keep it backward compatible, is there a way for the
function do_action, which resides in a class in a seperate file, to
take the original string (with the ''


T'') and replace it with the value
of T?

cheers


这篇关于字符串即时更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆