代码缩进 [英] code indentation

查看:94
本文介绍了代码缩进的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


在我以前的帖子中,我一直在谈论用exec运行代码......

所以现在我有问题使用代码缩进,正如Gabriel Genellina所说:


>如果您正在使用前一段时间建议的tokenize模块,请尝试分析令牌序列你可以使用{}(或者用你自己的语言开始/结束对,更容易区分字典
显示)和你从真实中得到的序列。 python代码。然后写一个脚本将一个转换成另一个:


>来自tokenize import generate_tokens

来自令牌从cStringIO导入tok_name
导入StringIO


> def analyze(source):

g = generate_tokens(StringIO (来源).readline)

for toknum,tokval,_,_,_ in g:

print tok_name [toknum],repr(tokval)


>我认为你基本上必须忽略INDENT,DEDENT和替换
NAME +" begin"使用INDENT,NAME +end与DEDENT。



所以......我怎么能这样做?????????????

我我将不胜感激任何帮助!!!!!


问候,

Vedran

__________________________________________________ ________________ Vedran

veki ICQ#:264412055当前ICQ状态:+更多联系方式获取ICQ!

__________________________________________________ ________________

解决方案

Steve Holden< st *** @ holdenweb.com撰写:

ve *********** @ v-programs.com 写道:


On 24 srp,05:20, Gabriel Genellina < gagsl -... @ yahoo.com.arwrote:


En Mon,2007年7月23日16:53:01 -0300,... ::: JA ::: ...

< vedrandeko ... @ v-programs.comescribi?3:
那么......我怎么能这样做? ?????????
我将不胜感激任何帮助!!!!!

尝试一个简单的例子。让我们说你要转换这个:

[...]



[...]你能给我一些吗?这个例子的脚本?请!!!


PS:感谢你的时间!!!!!!!!!!



不幸的是,您同时遇到两种语言的困难

:您的英语水平虽然令人印象深刻但却显得很明显/>
不足以解释问题[...]



而我们正在谈论的是沟通问题:原文海报

会很好地了解到增加连续

标点符号(!!!,???)的数量是一个肯定的方法可以让很多人失望/>
否则会有所帮助。句子最多需要一个''''或''''',

增加更多不会提高被认真对待的机会。


- -

\我们必须走出去,粉碎每一个世界观,不要相信宽容和言论自由。 - David Brin |
_o__)|

Ben Finney


On 25 srp,01:07,Ben Finney< bignose + hates-s ... @ benfinney.id.au>

写道:


Steve Holden< st。 .. @ holdenweb.comwrites:


vedrandeko ... @ v-programs.com写道:


在24srp,05:20,Gabriel Genellina, < gagsl -... @ yahoo.com.arwrote:

> En Mon,2007年7月23日16:53:01 -0300,... ::: JA ::: .. 。

>< vedrandeko ... @ v-programs.comescribió:

>>那么......我怎么能这样做? ??????????

>>我将不胜感激任何帮助!!!!!

>尝试一个简单的例子。让我们说你要转换它:

> [...]

[...]你能给我一些这样的例子吗?请!!!


PS:感谢你的时间!!!!!!!!!!


不幸的是,您同时遇到两种语言的困难

:你的命令英语,虽然令人印象深刻,但似乎不足以让你解释问题[...]



而我们是关于沟通的话题:原来的海报

会很好地了解到增加连续

标点符号(!!!,???)的数量是肯定的拒绝许多人的方式

否则会有所帮助。句子最多需要一个''''或''''',

增加更多不会提高被认真对待的机会。


- -

\我们必须走出去,粉碎每一个世界观,不要相信宽容和言论自由。 - David Brin |
_o__)|

Ben Finney






我只是寻求帮助因为我不明白这个令牌模块

那么好。

如果你可以帮助我而不是请帮助我,但如果你不能那么

请不要给我留下一些愚蠢的

消息



问候,


Vedran


ve *********** @ v-programs.com 写道:

< blockquote class =post_quotes>
>而我们正在谈论沟通的主题:原始海报
会很好地学习增加连续的标点符号数量( !!!,???)是一个肯定的方式来拒绝许多人,否则谁会有所帮助。句子最多需要一个''''或''''',
增加更多不会提高被认真对待的机会。



And如果你可以帮助我,请帮助我,但如果你不能那么

请不要给我留下一些愚蠢的消息



这是多么愚蠢?这是明智的建议。


哪个看起来更严重:


这个:

我可以做到了!你能帮我吗???? !!!?


或者这个:

我不知道答案。你能帮帮我吗?


即使它对你没有任何影响,对很多人来说也是如此。所以Ben是

吧:如果你限制使用标点​​符号(如果只是因为它更容易阅读),那么人们*会更加认真地对待你的帖子。

不要觉得被冒犯,没有人试图让你失望。


/ W


Hello,

In my previously post I have been talk about running code with exec in......
So now I have problem with code indentation, as Gabriel Genellina says:

>If you are using the tokenize module as suggested some time ago, try to
analyze the token sequence you get using { } (or perhaps begin/end pairs
in your own language, that are easier to distinguish from a dictionary
display) and the sequence you get from the "real" python code. Then write
a script to transform one into another:

>from tokenize import generate_tokens
from token import tok_name
from cStringIO import StringIO

>def analyze(source):
g = generate_tokens(StringIO(source).readline)
for toknum, tokval, _, _, _ in g:
print tok_name[toknum], repr(tokval)

>I think you basically will have to ignore INDENT, DEDENT, and replace
NAME+"begin" with INDENT, NAME+"end" with DEDENT.

So......how can I do this?????????????
I will appreciate any help!!!!!

Regards,
Vedran
__________________________________________________ ________________ Vedran
veki ICQ#: 264412055 Current ICQ status: + More ways to contact me Get ICQ!
__________________________________________________ ________________

解决方案

Steve Holden <st***@holdenweb.comwrites:

ve***********@v-programs.com wrote:

On 24 srp, 05:20, "Gabriel Genellina" <gagsl-...@yahoo.com.arwrote:

En Mon, 23 Jul 2007 16:53:01 -0300, ...:::JA:::...
<vedrandeko...@v-programs.comescribi?3:
So......how can I do this?????????????
I will appreciate any help!!!!!
Try with a simple example. Let''s say you want to convert this:
[...]

[...] Can you give me some example script of this? Please!!!

PS: THANKS FOR YOUR TIME!!!!!!!!!!


It''s unfortunate that you are having difficulty with two languages
simultaneously: your command of English, though impressive, appears
to be insufficient for you to explain the problem [...]

And while we''re on the topic of communication: The original poster
would do well to learn that increasing the number of consecutive
punctuation marks (!!!, ???) is a sure way to turn away many people
who would otherwise be helpful. Sentences need at most one ''!'' or ''?'',
adding more does not improve the chances of being taken seriously.

--
\ "We have to go forth and crush every world view that doesn''t |
`\ believe in tolerance and free speech." -- David Brin |
_o__) |
Ben Finney


On 25 srp, 01:07, Ben Finney <bignose+hates-s...@benfinney.id.au>
wrote:

Steve Holden <st...@holdenweb.comwrites:

vedrandeko...@v-programs.com wrote:

On 24 srp, 05:20, "Gabriel Genellina" <gagsl-...@yahoo.com.arwrote:
>En Mon, 23 Jul 2007 16:53:01 -0300, ...:::JA:::...
><vedrandeko...@v-programs.comescribió:
>>So......how can I do this?????????????
>>I will appreciate any help!!!!!
>Try with a simple example. Let''s say you want to convert this:
>[...]
[...] Can you give me some example script of this? Please!!!

PS: THANKS FOR YOUR TIME!!!!!!!!!!

It''s unfortunate that you are having difficulty with two languages
simultaneously: your command of English, though impressive, appears
to be insufficient for you to explain the problem [...]


And while we''re on the topic of communication: The original poster
would do well to learn that increasing the number of consecutive
punctuation marks (!!!, ???) is a sure way to turn away many people
who would otherwise be helpful. Sentences need at most one ''!'' or ''?'',
adding more does not improve the chances of being taken seriously.

--
\ "We have to go forth and crush every world view that doesn''t |
`\ believe in tolerance and free speech." -- David Brin |
_o__) |
Ben Finney

Hi,

I was only ask for help becose I don''t understand this tokenize module
so well.
And if you can help me than please help me , but if you can''t then
please don''t leave me some stupid
messages


Regards,

Vedran


ve***********@v-programs.com wrote:

>And while we''re on the topic of communication: The original poster
would do well to learn that increasing the number of consecutive
punctuation marks (!!!, ???) is a sure way to turn away many people
who would otherwise be helpful. Sentences need at most one ''!'' or ''?'',
adding more does not improve the chances of being taken seriously.


And if you can help me than please help me , but if you can''t then
please don''t leave me some stupid messages

Whats stupid about this? It''s sane advice.

Which looks more serious to you:

this:
I can''t do it!!!! Can you PLEASE help me????!!!?!

or this:
I don''t know the answer. Can you please help me?

Even if it makes no difference to you, to many people it does. So Ben is
right: People *will* take your posts more seriously if you restrict your
use of punctuation (if only because its easier to read).
Don''t feel offended, nobody was trying to put you down.

/W


这篇关于代码缩进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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