我以为我听说py2exe能够做到这一点,但我从未弄明白.有没有人成功完成这个?我可以看到你的setup.py文件,以及你使用的命令行选项吗?
基本上我正在考虑给它一个可执行文件,它可以像解压缩/ temp和运行一样.
我有一个跨多个项目的大型源存储库.我想制作一份关于源代码健康状况的报告,找出需要解决的问题领域.
具体来说,我想调出具有高圈复杂度的例程,识别重复,并且可能运行一些类似lint的静态分析来发现可疑(因而可能是错误的)构造.
我该如何构建这样的报告?
我有一种情况,我希望能够在网络界面中将用户密码评级到我的系统,以便在他们点击提交之前知道他们是否有错密码.
关键要求:
我发现很多用jQuery编写的密码计,像http://www.passwordmeter.com/这样的东西太冗长了.
任何人都可以建议我可以使用javascript密码评估器,或举例说明如何写一个?
有许多方法可以进行调试,使用调试器就是其中之一,但对于谦虚,懒惰的程序员而言,简单的方法就是在代码中添加一堆打印语句.
即
def foo(x):
print 'Hey wow, we got to foo!', x
...
print 'foo is returning:', bar
return bar
Run Code Online (Sandbox Code Playgroud)
这种调试方式是否有正确的名称?
我有一节课:
class MyClass:
def __init__(self, foo):
if foo != 1:
raise Error("foo is not equal to 1!")
Run Code Online (Sandbox Code Playgroud)
和一个单元测试,应该确保正确传递给构造函数的错误arg引发错误:
def testInsufficientArgs(self):
foo = 0
self.assertRaises((Error), myClass = MyClass(Error, foo))
Run Code Online (Sandbox Code Playgroud)
但我明白了......
NameError: global name 'Error' is not defined
Run Code Online (Sandbox Code Playgroud)
为什么?我应该在哪里定义此Error对象?我认为它是内置的默认异常类型,不是吗?
在Python中使用双引号与单引号之间有什么区别吗?
"A string with double quotes"
'A string with single quotes'
Run Code Online (Sandbox Code Playgroud)
它们是一样的吗?python如何解释这些字符串有什么不同吗?
在PHP中,NAN比较假到0,"0",false,array(),array(1),NAN,null基本上所有其他类变量,我可以辨别.
但NAN == true回报true.为什么要NAN == true回来true?
我希望能够在我的Python 2.6程序中解析命令行参数.
理想情况下,我希望能够处理这些情况:
# Show some help
./myprogram --help
# These are equivalent
./myprogram --block=1
./myprogram -b 1
# This means verbose, and twice as verbose:
./myprogram -v
./myprogram -vv
Run Code Online (Sandbox Code Playgroud) 在维护网络时,运行透明代理通常是一件有用的事情.透明代理我指的是一个"劫持"传出连接并通过本地服务运行它们的代理.具体来说,我运行一个配置了squid的linux防火墙,以便端口80上的所有tcp/ip连接都由squid代理.
这是使用iptables'nat'表,使用IPv4获得的.
但IPv6的iptables没有'nat'表,所以我不能使用相同的实现.我可以使用什么技术透明地代理IPv6连接的流量?
使用hg qnew并hg qrefresh创建和更新我想要应用到我的存储库的补丁后,但是我写的提交消息hg qnew不是很好,它没有引用trac的票号,我想说点什么关于我的提交所解决的一些问题.
我有这个代码:
chars = #some list
try:
indx = chars.index(chars)
except ValueError:
#doSomething
else:
#doSomethingElse
Run Code Online (Sandbox Code Playgroud)
我希望能够这样做,因为我不喜欢知道造成例外:
chars = #some list
indx = chars.index(chars)
if indx == -1:
#doSomething
else:
#doSomethingElse
Run Code Online (Sandbox Code Playgroud)
有没有办法可以做到这一点?
我写了一些我希望移植到python的C代码,因为我觉得python是一种更好的"概念"语言.
在我的C代码中,我使用内存重新解释来实现我的目标,例如:
sizeof(int) is 4 byte
sizeof(char) is 1 byte
char c[4]={0x01,0x30,0x00,0x80};
int* i=(int*)c;
*i has the value 0x80003001
Run Code Online (Sandbox Code Playgroud)
同样,如果我有:
int* j = (int*)malloc(sizeof(int));
char* c = (char*)j;
*j = 0x78FF00AA;
c is now {0xAA, 0x00, 0xFF, 0x78}
Run Code Online (Sandbox Code Playgroud)
我想在python中做类似的事情,我意识到我可以使用位操作来完成这个:
chararray=[]
num=1234567890
size=8
while len(chararray) < size:
char = chr( (num & 255 ) )
num = num >> 8
chararray.append(char)
Run Code Online (Sandbox Code Playgroud)
但是我希望有更快的方法来实现这一目标.
python有没有类似于C的联合?
我有一个聚合物应用程序,它使用核心页面和核心菜单.这是一个最小的工作示例:
<!doctype html>
<html> <head>
<script src="/bower_components/platform/platform.js"></script>
<link rel="import" href="/bower_components/polymer/polymer.html">
<link rel="import" href="/bower_components/core-menu/core-menu.html">
<link rel="import" href="/bower_components/core-item/core-item.html">
<link rel="import" href="/bower_components/core-pages/core-pages.html">
</head>
<body unresolved>
<template is="auto-binding">
<core-menu selected="0" selectedIndex="{{selected}}">
<core-item label="Item 1"><a href="#foo" target="_self"></a></core-item>
<core-item label="Item 2"><a href="#bar" target="_self"></a></core-item>
</core-menu>
<core-pages selected="{{selected}}">
<div>one</div>
<div>two</div>
</core-pages>
</template>
Run Code Online (Sandbox Code Playgroud)
我如何制作它,以便如果我超链接到/example.html#bar,<div>two</div>将显示而不是<div>one</div>?