下面的程序给出了以下输出:
Listing directory ftp://ftp.ncbi.nih.gov/pub/geo/DATA/SeriesMatrix
1.1 Mbyte
229.0 s
38 Kbit/s
Downloading file ftp://ftp.ncbi.nih.gov/pub/geo/DATA/SeriesMatrix/GSE30/GSE30_series_matrix.txt.gz
2.3 Mbyte
3.1 s
6221 Kbit/s
Run Code Online (Sandbox Code Playgroud)
为什么目录列表与文件下载相比如此之慢?有没有办法加快目录列表?
这是代码
from __future__ import division
import ftplib
import time
server = 'ftp.ncbi.nih.gov'
dirPath = '/pub/geo/DATA/SeriesMatrix'
filePath = '/pub/geo/DATA/SeriesMatrix/GSE30/GSE30_series_matrix.txt.gz'
ftp = ftplib.FTP(server)
ftp.login('anonymous', 'john.smith@gmail.com')
print 'Listing directory ftp://' + server + dirPath
fileNames = []
t = time.clock()
ftp.retrlines('NLST ' + dirPath, fileNames.append)
t = time.clock() - t
size = sum([len(fileName) + 1 for fileName in fileNames])
print '{0:.1f} Mbyte\n{1:.1f} s\n{2:.0f} …
Run Code Online (Sandbox Code Playgroud) 我是python的新手,刚开始学习它.
我已经为Visual Studio 2010安装了Python Tools并使用VS作为我的编辑器.
我的测试python程序运行正常,但在输出窗口的最后一行我看到以下内容
The thread 'Python Thread' (0x6f4) has exited with code 0 (0x0).
Run Code Online (Sandbox Code Playgroud)
请告诉我这个错误意味着什么,我该如何解决它.提前谢谢!
编辑:此外,每当我尝试通过按F5(开始调试)运行我的程序时,它会打开一个名为c:\ Program Files\Python32\python.exe的命令窗口,它似乎从其位置调用主python文件.它应该打开那个命令窗口一秒钟吗?我怀疑该命令窗口是否是"Python线程".
Edit_2:
对于所有未来的新探险家或蟒蛇:
如果您正在使用Visual Tools的Python工具,您可能希望使用Shift + Alt + F5而不是F5来构建程序.这将在VS内部的Python交互式窗口中输出,它不会显示烦人的命令窗口弹出窗口.
为什么
any(['','foo'])
Run Code Online (Sandbox Code Playgroud)
举起例外
TypeError: cannot perform reduce with flexible type
Run Code Online (Sandbox Code Playgroud)
我认为它应该评估True
,因为
bool('')
评估为 False
bool('foo')
评估为 True
any()
可以使用任何可转换的对象序列bool
我正在使用Python 2.7.
以下代码不起作用,也过于冗长和冗余.修复它的最佳方法是什么?
if os.path.exists('*.obj'):
os.remove('*.obj')
if os.path.exists('*.dll'):
os.remove('*.dll')
if os.path.exists('*.exe'):
os.remove('*.exe')
if os.path.exists('*.manifest'):
os.remove('*.manifest')
if os.path.exists('*.pch'):
os.remove('*.pch')
if os.path.exists('*.lib'):
os.remove('*.lib')
if os.path.exists('*.rsp'):
os.remove('*.rsp')
if os.path.exists('Makefile'):
os.remove('Makefile')
Run Code Online (Sandbox Code Playgroud) 当我尝试
import locale
locale.setlocale(locale.LC_COLLATE, 'ja-JP')
Run Code Online (Sandbox Code Playgroud)
我收到错误消息
locale.Error: unsupported locale setting
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?我在Windows 7上使用Python 2.7.3.
如何在不使用内置*和/操作数的情况下乘以和除以两个int值.是否可以使用+和 - 操作数来实现这一目标?
int n1;
int n2;
int product;
cout << "Input 2 numbers you wish to multiply" << endl;
cin >> n1;
cin >> n2;
//perform multiplication operation here
return 0;
Run Code Online (Sandbox Code Playgroud)
谢谢,
def is_odd(num):
# Return True or False, depending on if the input number is odd.
# Odd numbers are 1, 3, 5, 7, and so on.
# Even numbers are 0, 2, 4, 6, and so on.
Run Code Online (Sandbox Code Playgroud)
我想知道你会从这里做些什么来得到那些答案.