为什么“经常使用“.some_string”? [英] Why " ".some_string is often used ?

查看:157
本文介绍了为什么“经常使用“.some_string”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



大家好,


这不是我第一次在Python中看到这种编码方式和

我想知道为什么这样编码:


如何使用PyXML

http://pyxml.sourceforge.net/topics/howto/node14.html

在此显示函数,但我在许多其他代码中看到了这一点:


def normalize_whitespace(text):

"从字符串中删除多余的空格

返回''''。join(text.split())


是否有理由而不是只返回join(text.split()) ?

为什么连接 "字符串而不仅仅是返回字符串?


提前感谢您的解释。


问候,


-

Stephane Ninin

解决方案

"StéphaneNinin"写道:

有没有理由做而不只是返回join(text.split())?
为什么连接 "而不仅仅是返回字符串




因为除非你已经完成了它们,否则它们不是一回事>

来自字符串导入加入


优先。加入不是内置函数。


-

__ Erik Max Francis&& ma*@alcyone.com && http://www.alcyone.com/max/

/ \美国加利福尼亚州圣何塞市&& 37 20 N 121 53 W&& & tSftDotIotE

\ __ /我把我的脚踢在废线上,阳光

- 美国人,_Chess_


同样出现了Erik Max Francis:

是否有理由而不仅仅返回join(text.split())?
为什么连接 "而不是只返回字符串



因为除非你已经做过,否则它们不是一回事
首先从字符串导入加入

。 join不是内置函数。




好​​的。谢谢。

我刚刚意识到。这里也没有与连接无关。


2004-01-07,Erik Max Francis< ma*@alcyone.com>写道:

因为他们不是一回事,除非你已经完成了从字符串导入加入

首先。 join不是内置函数。




你知道,鉴于文本量庞大,Pythonistas写的关于Python的内容并不是因为
属于Perlish的陷阱魔术线虫这肯定有点儿,

不要想?不知道这个成语是如何进入的。想想所有这些我一直在做的事情:


导入字符串

string.join ()


-

Steve C. Lamb |我是你的牧师,我是你的缩水,我是你的

PGP钥匙:8B6E99C5 |与灵魂交换机的主要连接。

------------------------------- + - -------------------------------------------



Hi all,

This is not the first time I see this way of coding in Python and
I wonder why this is coded this way:

Howto on PyXML
(http://pyxml.sourceforge.net/topics/howto/node14.html)
shows it on this function, but I saw that in many other pieces of code:

def normalize_whitespace(text):
"Remove redundant whitespace from a string"
return '' ''.join(text.split())

Is there a reason to do instead of just returning join(text.split()) ?
why concatenate " " to the string and not just returning the string instead ?

Thanks in advance for your explanations.

Regards,

--
Stephane Ninin

解决方案

"Stéphane Ninin" wrote:

Is there a reason to do instead of just returning join(text.split()) ?
why concatenate " " to the string and not just returning the string
instead ?



Because they''re not the same thing unless you''ve already done

from string import join

first. join is not a builtin function.

--
__ Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
/ \ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
\__/ I get my kicks above the wasteline, sunshine
-- The American, _Chess_


Also sprach Erik Max Francis :

Is there a reason to do instead of just returning join(text.split()) ?
why concatenate " " to the string and not just returning the string
instead ?



Because they''re not the same thing unless you''ve already done

from string import join

first. join is not a builtin function.



Ok. Thanks.
I just realized that "." had also nothing to do with concatenation here.


On 2004-01-07, Erik Max Francis <ma*@alcyone.com> wrote:

Because they''re not the same thing unless you''ve already done

from string import join

first. join is not a builtin function.



You know, given the volumes of text Pythonistas write about Python not
falling to the Perlish trap of magic linenoise this certainly smacks of it,
don''tcha think? Wonder how this idiom slipped in. To think all this time I
have been doing:

import string
string.join()

--
Steve C. Lamb | I''m your priest, I''m your shrink, I''m your
PGP Key: 8B6E99C5 | main connection to the switchboard of souls.
-------------------------------+---------------------------------------------


这篇关于为什么“经常使用“.some_string”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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