由买买提看人间百态

topics

全部话题 - 话题: indented
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
k***r
发帖数: 4260
1
来自主题: Programming版 - 有人用Haskell吗
When there are compilation errors, it's a matter of best effort,
no matter what language it is. I think the same is true for Python.
You can still figure out the boundaries (or the lack of it) of code
blocks. The only difference is what to look for, {} or spaces/tabs.
I think the algorithms work very similarly, if not exactly the same
way.
For all the Python IDEs I've tried, including eclipse with PyDev plugin,
all IDEs do indentation for you when you hit enter. PyDev's Python
support may not be
k***r
发帖数: 4260
2
来自主题: Programming版 - 有人用Haskell吗
The code structure info will not be lost. It's probably a bit
more work to implement but it's doable. Let me give you an example.
Let's say you have:
def f1():
____print 'f1'
def f2():
____print 'f2'
And we want to inline f2() into f1(). You cut f2's code,
and go to f1, right after the ":", hit enter. The carret will be
indented automatically because it's inside a function. Before you
do Paste, the code looks like this:
def f1():
____<- this is where the carret is
____print f2
Then you hit "Past
k***r
发帖数: 4260
3
来自主题: Programming版 - 有人用Haskell吗
I just did a side by side comparison of java and python code.
I know it's subjective, but I find Python code is easier to read
and follow, in terms of coding style. Since you write more (maybe
10-20%, because of the savings on { and }) code lines in a page,
it's also easier to get a bigger picture of what the code is
trying to do.
The problem I have with Python is not indentations. It's dynamic
nature of types. Java compiler does catch a lot of potential
errors that Python compiler wouldn't.
g*****g
发帖数: 34805
4
来自主题: Programming版 - 有人用Haskell吗
Let's say you have code
print 'f1'
print 'f2'
Now you go somewhere, copy/paste a piece of code in between, it becomes

print 'f1'
if 1+1 == 2 :
print 'f3'
print 'f2'
No matter how smart your IDE is, it must be confused when trying formatting
I really doubt you can just copy/paste without some manual indentation.
And it's certainly error-prone.
k***r
发帖数: 4260
5
来自主题: Programming版 - 有人用Haskell吗
- code copied from web pages where indentation is lost
code is screwed up. No question about that
- mixed spaces and tabs
This can be converted by IDE. You just need to tell your IDE
what's the equivalent of a tab. Python coding convertion
recommends 4 spaces and that's what people use most of the time.
The good thing is, if a different style is contained in one
module or function, you will be fine even if they are mixed.
So this is less likely to be a problem.
No doubt that Python is more sensi
w****i
发帖数: 964
6
来自主题: Programming版 - 请问运行python的一些技巧。
Maybe the indent was not removed
I*******e
发帖数: 1879
7
来自主题: Programming版 - [合集] 大家的set sw都设多少啊?
☆─────────────────────────────────────☆
gandjmitbbs (Nothing) 于 (Fri May 15 22:09:24 2009) 提到:
习惯4,被要求和其他人保持一致,要改成2。觉得很别扭。
这个宽度和字体有关吧。
另外set ts和set sw有啥区别啊?
☆─────────────────────────────────────☆
icewolf (好好活) 于 (Fri May 15 22:50:26 2009) 提到:
shiftwidth is how many char to shift when you use ">>" or "<<" or used by
indent
tabstop is how many char to count when you press "tab".
我也不习惯2,但好像很多gnu的c程序都是2啊,而且风格非常诡异……
4是介于2和8之间一个不错的compromise,呵呵!另外PEP8 (python)也是用4滴

☆───────────────────────
S*********g
发帖数: 5298
8
来自主题: Programming版 - 请问大家怎样让程序难以读懂
这个太没戏了,随便一个软smart indent一下就解决了
b******n
发帖数: 592
9
来自主题: Programming版 - 小孩子学哪种编程语言比较好?
python is definitely not good. indentation? no way kids can stand it. import
modules ... you need a language supports graphics without efforts..no
library
dependency.. maybe processing...
X****r
发帖数: 3557
10
来自主题: Programming版 - implement a simple regular expression match?
For this simple regex you don't need to explicitly convert to DFA.
e.g. you can maintaining a list of possible 'leads' so far.
Of course, this won't be as efficient as pre-compute the
state table for the given regex, but if you want a simple one:
#define MAX_STARS 256
int match(const char *input, const char *regex) {
int p[2][MAX_STARS] = {0};
int c[2] = {1};
int w = 0, nw = 1, i, j;
char ch, nch;
for (; *input; input++) {
c[nw] = 0;
for (i = 0; i < c[w]; i++) {
j = p[w][... 阅读全帖
X****r
发帖数: 3557
11
来自主题: Programming版 - 这个程序怎么解决
You 'if' is not inside the outer 'for' as you think.
Use {} for the 'for'. Indentions are just for visual, compiler ignores them.
t****t
发帖数: 6806
12
来自主题: Programming版 - vi 和我
我给vi做过一个我们自己用的语言的indent. 其实也没什么难的, 拿matlab的抄一抄就
好了.
c******2
发帖数: 957
13

您用的版本是不是和我不一样的?我的是python3.2
因为我输进去之后,有好些地方说SyntaxError: inconsistent use of tabs and
spaces in indentation不知道是怎么回事呀。。。
如果有时间,能不能麻烦您也帮忙看看我和同学讨论出来的还是有错误的一段代码:
def main():
print("Please input the filename to read: ")
f2read=input()
print("Please input the filename to write: ")
f2write=input()
f1=file(f2read, "r")
f2=file(f2write, "w")
def acronym(string):
p=string.split("")
for word in p:
s+=(word[0].upper())
return s
lines=f1.rea... 阅读全帖
b*****d
发帖数: 7166
14
来自主题: Programming版 - python 问题
我又试了几次,发现如果手动输入,就没错。如果copy-paste,或者用load从文件里加
入就报错。应该是indent出了问题。
大家用什么编辑器呀,我用的是vi。
y**b
发帖数: 10166
15
来自主题: Programming版 - 缩进用空格好,还是tab好?
没有。一直用emacs,刚发现emacs也能。
in your .emacs file:
(setq-default indent-tabs-mode nil)
T****U
发帖数: 3344
16
来自主题: Programming版 - correct indentation in python ?
是很土,很容易看岔
r*******n
发帖数: 3020
17
来自主题: Programming版 - correct indentation in python ?
关于curly braces语法,我认为是因为先入为主的因素
看惯了c、c++,java,c#,
v*****r
发帖数: 2325
18
来自主题: Programming版 - correct indentation in python ?
google:
vimrc settings:
autocmd BufRead *.py set smartindent cinwords=if,elif,else,for,while,try,
except,finally,def,class
unfortunately i only get it working once, then no longer working
could you please share the tips
v*****r
发帖数: 2325
19
来自主题: Programming版 - correct indentation in python ?
i see the smartindent autoident working with some lines, but not others
check following, line 1-3 are able to autoident, line 4-5 only line 5
autoident, line 4 refuse to do so
1 line = "Cats are smarter than dogs";
2 matchObj = re.match( r'(.*) are(\.*)', line, re.M|re.I)
3 if matchObj:
4count_ban = len(has_ban.keys())
5 print "count_ban = ", count_ban
l*********s
发帖数: 5409
20
来自主题: Programming版 - correct indentation in python ?
99% is your vimrc misconfigured.do a cat to confirm if it is actually wrong
.
f********o
发帖数: 1163
21
#!/usr/bin/python
import os;
import sys;
class Person:
''' Defines a Person class '''
population = 0
def __init__(self,name):
''' I really hate the indents. '''
self.name = name;
print 'The person'"'s"'name is %s' % self.name;
Person.population += 1;
def __del__(self):
print '%s says bye;' % self.name
Person.population -= 1
if Person.population == 0:... 阅读全帖
m********5
发帖数: 17667
22
welcome to python world! I provided a fix which can run flawless to your
class design. Seems like u r from java ;) We should always Keep
in mind that, unlike java, python is a dynamic language.
The counterpart of static class variable of java is class variable.
Using the class name as a reference to a class is very common outside the
class def. However, it is not a very good idea to do so within the class def
, because any class itself is an instance of `type`. The name space looking-
up can m... 阅读全帖
f**f
发帖数: 30
23
来自主题: Programming版 - 求教一个程序问题
你写的貌似有indentation错误
for 循环算出balence就完成任务了,接下来那个改变lower和upper应该在for循环的外
边,while循环的里边?
r*******n
发帖数: 3020
24
来自主题: Programming版 - Python for Data Analysis
比如骂 indentation
d***q
发帖数: 1119
25
来自主题: Programming版 - Python for Data Analysis

haskell also need indention.
d********g
发帖数: 10550
26
来自主题: Programming版 - json是一种革命性的创造
另外Python的缩进一般不超过3、4层,按PEP 8的79宽度和4 indent,太多层数就写不
了什么代码。这也是强制要求你需要精简代码,而且用list comprehension如同进入了
极乐世界
l*********s
发帖数: 5409
27
来自主题: Programming版 - Python 缩进的syntax
but all IDEs and non-ide editors I have used support auto-indenting for
python. except notepad.
z****e
发帖数: 54598
28
来自主题: Programming版 - Python 缩进的syntax
那我再精确一点吧
你未必会用vim写
或者我再精确一点
你不能assume他用的是auto-indenting工具
l*********s
发帖数: 5409
29
来自主题: Programming版 - Python 缩进的syntax
Come on, notepad 是不支持auto-indenting,word也不支持,问题是那个正常人会用这
两写程序?如果这是你的本意,我只能说你的想法太独特了,太新奇了。
l*y
发帖数: 21010
30
来自主题: Programming版 - Python 缩进的syntax
就算用vim 写c/c++,也可以gvGG=来给整个code indent。根本不是ide啊
d***q
发帖数: 1119
31
来自主题: Programming版 - Python 缩进的syntax
haskell do require indention but it looks like nobody care about that.
r****y
发帖数: 26819
32
来自主题: Programming版 - Python 缩进的syntax
插一句实在话,我觉得python的code indent给人带来的不方便可能还不如换用不同键盘
给人带来的不方便。当然有些人就是只能接受某种机械键盘,别的键盘就没法用。
l*y
发帖数: 21010
33
来自主题: Programming版 - Python 缩进的syntax
你这个说法至少完全不适用与我。我确实尝试用过python,除了受不了indentation,
还受不了很多。相比之下,perl真是顺手多了。

键盘
E*****m
发帖数: 25615
34
来自主题: Programming版 - Python 缩进的syntax

indentation 對一些網站是有點問題,但也不是啥天大地大不能解決的。
l*y
发帖数: 21010
35
python是不可能自动给本身没有缩进的代码 re-indent的
只能在敲代码的时候给你下一行自动缩进
设计的就是这样。。
r*********r
发帖数: 3195
36
i learned python during one coding test, which has to been done in python.
took about half hour to understand the syntax, and it's fun to code!
the indentation is not a problem as long as you have an editor that supports
it, such as emacs.
p*****2
发帖数: 21240
37
来自主题: Programming版 - python indentation
以前还觉得挺好的,看到大家complain还不太理解。
这两天用coffeescript才明白为什么大家这么痛恨。现在终于体会到了痛苦了。
f**********2
发帖数: 2401
38
来自主题: Programming版 - python indentation
痛苦在于?
d*******r
发帖数: 3299
39
来自主题: Programming版 - python indentation
为啥呢
s***o
发帖数: 175
40
来自主题: Programming版 - python indentation
已经是讨论了几十年的问题,不要太纠结这个了。
p*****2
发帖数: 21240
41
来自主题: Programming版 - python indentation
貌似这个跟CS有一定的关系。网上看到有人complain说问了一些朋友,大家都觉得
python没感觉有什么不爽的,但是到了CS就感觉到了。看来CS学python有点邯郸了。
w****k
发帖数: 6244
42
来自主题: Programming版 - lisper
很多editor都有检查这个indent的功能,再设上tab自动转成space,基本不会有问题。
E*****m
发帖数: 25615
43
来自主题: Programming版 - lisper
Lisp 的 () 和 Python 的 indentation 可以看作是各自
設下的門禁, 把那些只重視表面的人打回去。 呵呵!
i***r
发帖数: 1035
44
来自主题: Programming版 - 请问python的多重循环怎么实现?
你的loop是对的吧?
仔细检查indentation,全部换成一样的。
可以用python来读自己的script,然后每行看是不是tab 和 space混了
b*****e
发帖数: 474
45
来自主题: Programming版 - 请教 C++ 题
毛病太多了, 我来挑几个:
template
class SortedList
{
public:
// 1. no c'tor nor d'tor? make sure m_head is NULL
void Push(T value) // 2. pass by value? also try const
{
Node ** where = &m_head; // 3. maybe a little confusing, but using
Node** does help a little when *where is NULL or m_head
while (*where && (*where)->value < value) { // 4. consider a
comparator rather than the <
where = &((*where)->next);
}
*where = new Node(value,*where... 阅读全帖
b*****e
发帖数: 474
46
来自主题: Programming版 - 请教 C++ 题
毛病太多了, 我来挑几个:
template
class SortedList
{
public:
// 1. no c'tor nor d'tor? make sure m_head is NULL
void Push(T value) // 2. pass by value? also try const
{
Node ** where = &m_head; // 3. maybe a little confusing, but using
Node** does help a little when *where is NULL or m_head
while (*where && (*where)->value < value) { // 4. consider a
comparator rather than the <
where = &((*where)->next);
}
*where = new Node(value,*where... 阅读全帖
d********g
发帖数: 10550
47
来自主题: Programming版 - node来势凶猛,已经完胜Ruby了
做frontend脚本代码风格比较重要,还是带括号的有优势因为可以随意压缩。Python估
计没办法因为4 indent
m******t
发帖数: 635
48
来自主题: Programming版 - 这次node把python也给干了
CoffeeScript基本上是Ruby的语法加Python的indentation
w**z
发帖数: 8232
49
来自主题: Programming版 - Google Java coding standard (转载)
【 以下文字转载自 Java 讨论区 】
发信人: wwzz (一辈子当码工), 信区: Java
标 题: Google Java coding standard
发信站: BBS 未名空间站 (Thu Feb 27 18:24:40 2014, 美东)
Yep, Google's got standards when it comes to Java coding, and they've been
carefully documented for your enlightenment. While these enforceable coding
conventions are clearly most relevant to Java developers interested in
joining the Googleplex, they're also a good indicator of what you might
expect to see in other shops. InfoQ's Bienvenido David lists some of the
rul... 阅读全帖
d******e
发帖数: 2265
50
来自主题: Programming版 - python有快速loop over dict的方法吗?
import json
print json.dumps(mydick, sort_keys=True,
indent=4, separators=(',', ': '))
不用谢。
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)