有没有一种简单的方法来解析这个字符串? [英] Is there a simple way to parse this string ?

查看:48
本文介绍了有没有一种简单的方法来解析这个字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我需要翻译以下字符串

a =''(0,0,0,255),(192,192, 192,255),正确,8''


进入以下列表或元组

b = [(0,0,0,255),(192 ,192,192,255),真实,8]


有一种简单的方法可以解决这个问题。

(现在不需要,但可能需要它在未来:甚至更深的嵌套

列表,用字符串表示。)


谢谢,

Stef Mientki

推荐答案

Stef,


您可以通过以下方式快速获得元组:


t = eval(''(0,0,0,255),(192,192,192,255),True,8'')


Joseph Armbruster

12月19日下午4:17,Stef Mientki< stef.mien ... @ gmail.comwrote:
Stef,

You can quickly get a tuple via:

t = eval(''(0, 0, 0, 255), (192, 192, 192, 255), True, 8'')

Joseph Armbruster

On Dec 19, 4:17 pm, Stef Mientki <stef.mien...@gmail.comwrote:

hello ,


我需要翻译以下字符串

a =''(0,0,0,255),(192,192,192,255) ,是的,8''


进入以下列表或元组

b = [(0,0,0,255),(192,192,192,255),True,8]


有一个简单的方法来实现这个目标。

(现在不需要,但将来可能需要它:更深层次嵌套

列表,用字符串表示。)


谢谢,

Stef Mientki
hello,

I need to translate the following string
a = ''(0, 0, 0, 255), (192, 192, 192, 255), True, 8''

into the following list or tuple
b = [(0, 0, 0, 255), (192, 192, 192, 255), True, 8 ]

Is there a simple way to to this.
(Not needed now, but might need it in the future: even deeper nested
lists, represented by a string.)

thanks,
Stef Mientki


Stef Mientki写道:
Stef Mientki wrote:

你好,


我需要翻译以下字符串

a ='''(0,0,0,255),(192,192,192,255),真,8''


进入以下列表或元组

b = [(0,0,0,255),(192,192,192,255),真,8]


有一个简单的方法来。

(现在不需要,但将来可能需要它:更深层次嵌套

列表,用字符串表示。)


谢谢,

Stef Mientki
hello,

I need to translate the following string
a = ''(0, 0, 0, 255), (192, 192, 192, 255), True, 8''

into the following list or tuple
b = [(0, 0, 0, 255), (192, 192, 192, 255), True, 8 ]

Is there a simple way to to this.
(Not needed now, but might need it in the future: even deeper nested
lists, represented by a string.)

thanks,
Stef Mientki



此列表中有一些主题你需要注意的事项。

确保你知道字符串的来源并控制

的内容。如果您从用户那里读取他们可以输入的内容:


os.system(''rm -rf *'')或os.system(''del *。*'' )


eval它会删除磁盘上的所有文件


-Larry

There are threads on this list about eval and how you need to be careful.
Make sure you know where the string is coming from and can control the
contents. If you read if from a user they could type in:

os.system(''rm -rf *'') or os.system(''del *.*'')

eval that and it deletes all the files on your disk

-Larry


12月20日上午9:10,Larry Bates< larry.ba ... @ websafe.comwrote:
On Dec 20, 9:10 am, Larry Bates <larry.ba...@websafe.comwrote:

Stef Mientki写道:
Stef Mientki wrote:

hello,
hello,


我需要翻译以下字符串

a =''(0,0,0,255),(192,192,192,255),True,8''
I need to translate the following string
a = ''(0, 0, 0, 255), (192, 192, 192, 255), True, 8''


进入以下列表或元组

b = [(0,0,0,255),(192,192,192,255),True,8]
into the following list or tuple
b = [(0, 0, 0, 255), (192, 192, 192, 255), True, 8 ]


有一种简单的方法可以解决这个问题。

(现在不需要,但未来可能需要它:更深层次嵌套

列表代表由字符串表示。)
Is there a simple way to to this.
(Not needed now, but might need it in the future: even deeper nested
lists, represented by a string.)


谢谢,

Stef Mientki
thanks,
Stef Mientki



此列表中有关于eval的线程以及您需要注意的方式。


There are threads on this list about eval and how you need to be careful.



特别是Paul Maguire最近指出一个安全的评估员,即b $ b被限制(IIRC)到像int / dicts / etc这样的东西/ floats /

string / etc常量 - 看起来就像你需要的那样。

In particular Paul Maguire recently pointed to a safe evaluator that
was restricted (IIRC) to something like lists/dicts/etc of ints/floats/
string/etc constants -- looks like just what you need.


确保你知道字符串的来源并且可以控制

的内容。如果您从用户那里读取他们可以输入的内容:


os.system(''rm -rf *'')或os.system(''del *。*'' )


eval它会删除磁盘上的所有文件
Make sure you know where the string is coming from and can control the
contents. If you read if from a user they could type in:

os.system(''rm -rf *'') or os.system(''del *.*'')

eval that and it deletes all the files on your disk



有没有人知道可以自动killfile的新闻阅读器

建议eval没有任何警告的人?或者我们应该让达尔文的选择产生影响吗?

Does anyone know of a newsreader that can automatically killfile
people who suggest eval without any warnings at all? Or should we let
Darwinian selection take its effect?


这篇关于有没有一种简单的方法来解析这个字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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