小编Jad*_*una的帖子

PyInstaller文件很大

我使用wxPython制作了简单的代码编辑器.文件大小(python文件)是1.3 KB.但是当我使用PyInstaller创建可执行文件时,我得到30 MB的文件!有没有办法减少文件大小?顺便说一句,我不是导入整个wx库,只导入我需要的组件(ex from wx import Frame).

使用Linux,Fedora 18 64bit.

python size wxpython file pyinstaller

7
推荐指数
1
解决办法
8497
查看次数

在Python中,'<function at ...>'是什么意思?

什么<function at 'somewhere'>意思?例:

>>> def main():
...     pass
...
>>> main
<function main at 0x7f95cf42f320>
Run Code Online (Sandbox Code Playgroud)

也许有办法以某种方式使用它0x7f95cf42f320

python function repr memory-address

5
推荐指数
1
解决办法
8549
查看次数

Python urllib2 登录到 minecraft.net

我有问题。我正在编写一个简单的脚本来登录 minecraft.net,然后列出所有经典服务器。但是当我运行我的脚本时,它只是将我重定向回 minecraft.net/login。这是我到目前为止所拥有的:

import urllib2
import urllib
import re

url = "https://www.minecraft.net/login"
page = urllib2.urlopen(url)
data = page.read()
page.close()

authToken = re.search('name="authenticityToken"[\s]+value="(.+)"', data).group(1)

data_dict = {
    "username": "USERNAME",
    "password": "PASSWORD",
    "remember": "true",
    #"redirect": "https://www.minecraft.net",
    "authenticityToken": authToken
}
print urllib.urlencode(data_dict)
req = urllib2.Request(url, data=urllib.urlencode(data_dict))
page = urllib2.urlopen(req)
data = page.read()
page.close()
Run Code Online (Sandbox Code Playgroud)

我做错了什么?

python login urllib2 minecraft

4
推荐指数
1
解决办法
959
查看次数

在Python行中查找多位整数

快速问题(使用Python 3.x) - 我正在编写一个Python程序,它接受多行输入,然后搜索该输入,查找所有整数,对它们求和,并输出结果.我有点难以找到最有效的搜索方式并找到多位整数 - 如果一行包含12,我想找到12而不是[1,2].这是我的代码,未完成:

def tally():
    #the first lines here are just to take multiple input
    text = []
    stripped_int = []
    stopkey = "END"
    while True:
        nextline = input("Input line, END to quit>")
        if nextline.strip() == stopkey:
            break
        text.append(nextline)
    #now we get into the processing
    #first, strip all non-digit characters
    for i in text:
        for x in i:
            if x.lower() in ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','!',',','?']:
                pass
            else:
                stripped_int.append(x)
    print(stripped_int)

tally()
Run Code Online (Sandbox Code Playgroud)

这打印出一个包含所有整数的列表,但是我对如何将整数保持在一起感到困惑.有任何想法吗?

python python-3.x

1
推荐指数
1
解决办法
296
查看次数

Python - @property vs func()

用它来someclass.func代替我一直是我的梦想someclass.func().我读到了关于@decorators.现在我问:

哪种方式更好?

方式1

class Main(object):

    def __init__(self):

        self.func()

    def func(self):

        print 'hi'
Run Code Online (Sandbox Code Playgroud)

要么...

方式2

class Main(object):

    def __init__(self):

        self.func

    @property
    def func(self):

        print 'hi'
Run Code Online (Sandbox Code Playgroud)

编辑

以下是代码:http: //randomgalaxy.com/stackoverflow/python-property-vs-func/term.py

python properties function

1
推荐指数
1
解决办法
609
查看次数

C++正则表达式错误

我一直在使用C++中的正则表达式,但遇到了一些错误:

这是我的剧本

#include <iostream>
#include <regex>
using namespace std;

string input(string prompt)
{
    cout << prompt;
    string str;
    cin >> str;
    return str;
}

int main() {
    string str;
    while (true) {

        str = input("Enter some text: ");
        regex e("([:w:])+", regex_constants::icase);

        bool match = regex_match(str, e);

        cout << (match? "Matched" : "Not matched") << endl;
    }
}
Run Code Online (Sandbox Code Playgroud)

当我编译它并运行(g++ -std=c++11 test.cpp && ./a.out)时,我收到以下错误:

Enter some text: abcde
terminate called after throwing an instance of 'std::regex_error'
  what():  regex_error
Aborted (core …
Run Code Online (Sandbox Code Playgroud)

c++ regex g++ c++11

1
推荐指数
1
解决办法
1309
查看次数

Python - 0**0 == 1?

我正在玩**操作员,并注意到:

0**0 == 1
Run Code Online (Sandbox Code Playgroud)

pow(0, 0) == 1
Run Code Online (Sandbox Code Playgroud)

甚至math:

math.pow(0, 0) == 1
Run Code Online (Sandbox Code Playgroud)

谷歌!(搜索0**0)

为什么会这样?据我所知0**0未定义

python math pow

-4
推荐指数
1
解决办法
204
查看次数