小编Stu*_*ans的帖子

无法连接到python -m SimpleHTTPServer服务器

这可能是一个非常简单的问题,但我无法在任何地方找到答案.在有关它的在线文章中,他们没有显示使用SimpleHTTPServer共享目录的确切过程.我已成功运行该命令并让服务器运行,但我只能在启动它的机器上访问它.

192.168.1.2:8000
Run Code Online (Sandbox Code Playgroud)

我在Windows机器和iPad上试过它(虽然这并没有真正有所作为)在本地网络上.要访问它,我一直在使用我通过运行找到的本地IP地址,ifconfig | grep inet返回(以及其他匹配项):

inet 192.168.1.2 netmask 255.255.255.0 broadcast 192.168.1.255

在网上搜索后,我发现:https://github.com/shbhrsaha/instant-sharing/blob/master/share.py.

有一个功能,据说给你一个方便的网址与你的朋友分享,但我尝试在本地运行,我得到的只是"localhost.localdomain",显然返回127.0.0.1

我怎样才能做到这一点?

python command-line server

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

从Python中的类调用函数时,参数数量错误

我正在尝试在python中编写遗传算法的实现。它说在那里,当只允许一个时,我用两个参数来调用它,但是我确定我不允许。

以下是相关代码:

class GA:
    def __init__(self, best, pops=100, mchance=.07, ps=-1):
        import random as r

        self.pop = [[] for _ in range(pops)]

        if ps == -1:
            ps = len(best)

        for x in range(len(self.pop)): #Creates array of random characters
            for a in range(ps):
                self.pop[x].append(str(unichr(r.randint(65,122))))

    def mutate(array):
        if r.random() <=  mchance:
            if r.randint(0,1) == 0:
                self.pop[r.randint(0, pops)][r.randint(0, ps)] +=1
            else:
                self.pop[r.randint(0, pops)][r.randint(0, ps)] -=1
Run Code Online (Sandbox Code Playgroud)

这是我初始化并从类中调用时的代码:

a = GA("Hello",10,5)
a.mutate(a.pop)
Run Code Online (Sandbox Code Playgroud)

从IDLE返回以下错误:

TypeError: mutate() takes exactly 1 argument (2 given)
Run Code Online (Sandbox Code Playgroud)

我怎样才能解决这个问题?

python syntax-error

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

标签 统计

python ×2

command-line ×1

server ×1

syntax-error ×1