可能重复:
强制执行python代码样式/标准的工具
是否有任何工具可以在Python中强制执行代码标准并打印出违规列表?我正在寻找一种类似于Java中的checkstyle的工具.
我正在尝试为preg_replace找到一个表达式,它删除图像的所有内联css样式.例如,我有这样的文字:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. <img style="float:left; margin:0 0 10px 10px;" src="image.jpg" /> Proin vestibulum libero id nisl dignissim eu sodales.
Run Code Online (Sandbox Code Playgroud)
我需要让它看起来像:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. <img src="image.jpg" /> Proin vestibulum libero id nisl dignissim eu sodales.
Run Code Online (Sandbox Code Playgroud)
我已经尝试过几十种表达方式
preg_replace("%<img(.*?)style(.*?)=(.*?)(\'|\")(.+?)(\'|\")(.*?)>%i", "<img\$1\$7>", $article->text)
Run Code Online (Sandbox Code Playgroud)
但没有任何效果.有什么建议?
我今天看到这个代码:
if(++counter == 10)
{
//Do Something
foo();
}
Run Code Online (Sandbox Code Playgroud)
我认为这是一种糟糕的风格,但是,执行编译器依赖于它吗?比如在我们到达这一行之前计数器设置为8,它会增加它,然后比较10到8,之前的值,或比较10到9,计数器增加后的值?
你觉得怎么样?这是常见做法吗?坏风格?
ChartLabels -> Placed[{{Style["0", Bold, 18, FontFamily -> "Helvetica"]},
{Style["1", Bold, 18, FontFamily -> "Helvetica"]},
{Style["2", Bold, 18, FontFamily -> "Helvetica"]},
{Style["3", Bold, 18, FontFamily -> "Helvetica"]},
{Style["4", Bold, 18,
FontFamily -> "Helvetica"]}},
{{.1, .15}, {.3, .15}, {.5, .15}, {.7, .15},{.9, .15}}]
Run Code Online (Sandbox Code Playgroud)
首先,我很抱歉这对我自己来说甚至是一种尴尬,但我无法弄清楚如何在那里使用一个功能.
我怎么能让这更紧?
我尝试嵌套Switch失败了.
这种编写IF条件的方式是否在Java和C#语言中被认为是良好的编码风格?
if (checkIfIdInFirstRange()){
//call Range1 handling method
}else if(checkIfIdInSecondRange()){
//call Range2 handling method
}else{
//call error handling method
}
Run Code Online (Sandbox Code Playgroud)
我想知道IF条件本身内部的方法,还是更好的做法:
int idInRange = getIdInRange();
//handle isInRange
Run Code Online (Sandbox Code Playgroud) 我会尝试尽可能地将其作为封闭式问题:
我经常发现我有一组进口,如一堆进口; 但是稍后我可能删除或移动使用这些导入项目的代码部分到另一个文件.问题是我经常忘记为什么我使用特定的导入(例如,我经常使用Counter类,或者来自itertools的随机内容.)因此我可能希望有注释来指定我的导入的内容; 这样,如果我不再需要它们,我可以删除整个块.
使用我的import语句进行注释是否被认为是不好的风格?
我们有很多带有丑陋导入语句的文件,如下所示:
from project.foo import a, b
from project.foo import c
from project.bar import d, e, f, g
Run Code Online (Sandbox Code Playgroud)
是否存在将每行更改为一次导入的内容?
from project.foo import a
from project.foo import b
from project.foo import c
from project.bar import d
from project.bar import e
from project.bar import f
from project.bar import g
Run Code Online (Sandbox Code Playgroud)
澄清:原因是保持一致的风格,如Google的Python风格指南.
我一直在浏览Android开发教程,我看到很多这样的调用:
String date = new StringBuilder().append(mMonth + 1).append("-").append(mDay).append("-").append(mYear).append(" "));
Run Code Online (Sandbox Code Playgroud)
这似乎是一种很好的速记方式,但这真的是一种很好的做法吗?这会产生任何负面影响吗?
我有这个代码.
c = getch()
if c == "r":
return randrange(101, len(mylist) - 1)
if c == "u":
return 100
if c == "b":
return -2
if c == "w":
return -3
if c == "m":
return -4
if c == "d":
return -5
if c == "e":
return -6
if c == "k":
return -7
if c == "g":
return -8
if c == "p":
return -9
if c == "o":
right = center - 1
else:
left = center …Run Code Online (Sandbox Code Playgroud) 升级到iOS 5和Xcode 4.2后出现一些设计问题
这就是我在iOS 4中查看的视图:
这就是它在iOS 5中的样子:
在我的导航委托中,我有以下方法在顶部绘制"图像":
- (void)drawRect:(CGRect)rect {
UIImage *image;
if(self.barStyle == UIBarStyleDefault){
image = [UIImage imageNamed: @"topbar_base.png"];
}
else{
image = [UIImage imageNamed: @"nyhedsbar_base.png"];
}
[image drawInRect:CGRectMake(-1, -1, self.frame.size.width+3, self.frame.size.height+3)];
}
Run Code Online (Sandbox Code Playgroud)
在我的控制器内部,我设置了以下内容:
self.navigationBarStyle = UIBarStyleBlack;
Run Code Online (Sandbox Code Playgroud)
怎么会在iOS 5中不起作用?
谢谢
coding-style ×10
python ×4
java ×2
c ×1
c# ×1
comments ×1
if-statement ×1
image ×1
import ×1
ios ×1
iphone ×1
map ×1
php ×1
preg-replace ×1
regex ×1