小编sha*_*noo的帖子

urllib.request模块无法在我的系统中安装

尝试使用以下命令安装urllib.request模块

sudo pip install urllib.request
Run Code Online (Sandbox Code Playgroud)

但它回来了

Downloading/unpacking urllib.request
  Could not find any downloads that satisfy the requirement urllib.request
Cleaning up...
No distributions at all found for urllib.request
Storing debug log for failure in /home/mounarajan/.pip/pip.log
Run Code Online (Sandbox Code Playgroud)

我该如何安装这个模块?

python ubuntu sudo pip urllib

10
推荐指数
3
解决办法
7万
查看次数

Ping 的 Python 控制台和文本输出,包括 \n\r

我不知道发生了什么,但是当我打印到控制台或文本文件时,换行符 (\n) 不起作用,而是显示在字符串中。知道如何在控制台和文本文件中避免这种情况吗?

我的代码:

import subprocess

hosts_file = open("hosts.txt","r")
lines = hosts_file.readlines()

for line in lines:
    line = line.strip()
    ping = subprocess.Popen(["ping", "-n", "3",line],stdout = subprocess.PIPE,stderr = subprocess.PIPE)
    out, error = ping.communicate()
    out = out.strip()
    error = error.strip()
    output = open("PingResults.txt",'a')
    output.write(str(out))
    output.write(str(error))
    print(out)
    print(error)
hosts_file.close()
Run Code Online (Sandbox Code Playgroud)

输出:

b'Pinging 192.168.0.1 with 32 bytes of data:\r\nRequest timed out.\r\nRequest ti
med out.\r\nRequest timed out.\r\n\r\nPing statistics for 192.168.0.1:\r\n    Pa
ckets: Sent = 3, Received = 0, Lost = 3 (100% loss),'
b''
b'Pinging 192.168.0.2 …
Run Code Online (Sandbox Code Playgroud)

python subprocess ping popen python-3.3

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

如何将单个hg存储库转换为多个存储库

我有一个包含5个子目录的存储库.

回购/

a/
    file-a
b/
    file-b
c/
    file-c
d/
    file-d
e/
    file-e
Run Code Online (Sandbox Code Playgroud)

如何将每个子目录转换为不同的存储库?(只应将给定子目录的相关变更集转换为新的存储库)

mercurial mercurial-convert

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