Question about ftplib
alper soyler
alpersoyler at yahoo.com
Fri Sep 1 06:33:55 EDT 2006
I am trying to get '.pep' files from the ftp.genome.jp/pub/kegg/genomes/??? directories (???=directory names) with the below script. However, after downloading 121 files (I have to download 300 more), it gave me the time out error message:
Traceback (most recent call last):
File "ftp1.0.py", line 18, in ?
for filename in ftp.nlst():
File "/usr/lib/python2.4/ftplib.py", line 448, in nlst
self.retrlines(cmd, files.append)
File "/usr/lib/python2.4/ftplib.py", line 396, in retrlines
conn = self.transfercmd(cmd)
File "/usr/lib/python2.4/ftplib.py", line 345, in transfercmd
return self.ntransfercmd(cmd, rest)[0]
File "/usr/lib/python2.4/ftplib.py", line 324, in ntransfercmd
conn.connect(sa)
File "<string>", line 1, in connect
socket.error: (110, 'Connection timed out')
How can I continue from the last download or is there any way to arrange the time?
Script:
from ftplib import FTP
def handleDownload(block):
file.write(block)
print ".",
ftp = FTP('ftp.genome.jp')
print ftp.login()
directory = '/pub/kegg/genomes'
ftp.cwd(directory)
k=0
for direct in ftp.nlst():
curdir = '%s/%s' % (directory, direct)
ftp.cwd(curdir)
for filename in ftp.nlst():
if not filename.endswith('.pep'): continue
file = open(filename, 'wb')
ftp.retrbinary('RETR %s/%s' % (curdir, filename), handleDownload)
file.close()
k=k+1
print ftp.close()
----- Original Message ----
From: python-list-request at python.org
To: python-list at python.org
Sent: Friday, September 1, 2006 1:00:05 PM
Subject: Python-list Digest, Vol 36, Issue 10
Send Python-list mailing list submissions to
python-list at python.org
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.python.org/mailman/listinfo/python-list
or, via email, send a message with subject or body 'help' to
python-list-request at python.org
You can reach the person managing the list at
python-list-owner at python.org
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Python-list digest..."
Today's Topics:
1. Re: python loops (stdazi)
2. Re: Classes referencing each other (Georg Brandl)
3. Re: Python style: to check or not to check args and data
members (Joel Hedlund)
4. Re: Classes referencing each other (Manuel Bleichner)
5. Re: python loops (bearophileHUGS at lycos.com)
From: "stdazi" <stdazi at gmail.com>
Precedence: list
MIME-Version: 1.0
To: python-list at python.org
References: <NYOBGCEXSMTP21ETwCv0005d3ba at nyobgcexsmtp21.uswin.ad.vzwcorp.com>
<mailman.10211.1157052834.27775.python-list at python.org>
<slrnefeft1.9bt.sybrenUSE at schuimige.stuvel.eu>
In-Reply-To: <slrnefeft1.9bt.sybrenUSE at schuimige.stuvel.eu>
Date: 1 Sep 2006 02:34:48 -0700
Message-ID: <1157103288.783306.106850 at p79g2000cwp.googlegroups.com>
Content-Type: text/plain; charset="iso-8859-1"
Subject: Re: python loops
Message: 1
`range' is especially useful for iterating over long sequences ;-)
for i in range(0,100000000000000) :
OverflowError: range() result has too many items
Sybren Stuvel wrote:
> Michael.Coll-Barth at VerizonWireless.com enlightened us with:
> > I thought the xrange was preferred? for x in xrange(length):
>
> True. It doesn't create the entire list, like range does. range(1000)
> creates a 1000-element list. xrange(1000) just iterates through the
> appropirate values.
>
> > The information contained in this message and any attachment may be
> > proprietary, confidential, and privileged or subject to the work
> > product doctrine and thus protected from disclosure. If the reader
> > of this message is not the intended recipient, or an employee or
> > agent responsible for delivering this message to the intended
> > recipient, you are hereby notified that any dissemination,
> > distribution or copying of this communication is strictly
> > prohibited. If you have received this communication in error,
> > please notify me immediately by replying to this message and
> > deleting it and all copies and backups thereof. Thank you.
>
> And how are we supposed to interpret this? Copying this communication
> may be prohibited, but both email and usenet messages are copied all
> the time. Without that, both systems fail miserably.
>
> Sybren
> --
> The problem with the world is stupidity. Not saying there should be a
> capital punishment for stupidity, but why don't we just take the
> safety labels off of everything and let the problem solve itself?
> Frank Zappa
Content-Transfer-Encoding: 7bit
From: Georg Brandl <g.brandl-nospam at gmx.net>
Precedence: list
MIME-Version: 1.0
To: python-list at python.org
References: <mailman.10236.1157100375.27775.python-list at python.org>
In-Reply-To: <mailman.10236.1157100375.27775.python-list at python.org>
Date: Fri, 01 Sep 2006 11:50:42 +0200
Message-ID: <ed8vpi$tej$1 at news.albasani.net>
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Subject: Re: Classes referencing each other
Message: 2
Manuel Bleichner wrote:
> Hello list,
>
> I have searched for some time now, but no result...
> I'm having the following problem:
>
> In a module I have a huge number of classes of the form:
>
> class A(object):
> connected_to = [B, C]
> <other attributes...>
>
> class B(object)
> connected_to = [C]
> <other attributes...>
>
> class C(object)
> connected_to = [A]
> <other attributes...>
>
> As you see, classes A and B reference classes that
> are not yet defined when the class is being defined.
> It will raise a NameError: 'B'.
>
> I know i could solve this by leaving out the definition
> of 'connected_to' in A and attach it to the class later on by
> A.connected_to = [B, C]
> but I would like to avoid this, because in the module
> there are about 50 classes that have to be altered from time
> to time and it's just incredibly ugly if I have to look for
> the attribute definitions in more than one place.
You could move all connections to a central location after the
class definitions, such as
class A: pass
class B: pass
class C: pass
connections = {A: (B, C), B: (C,), C: (A,)}
Georg
Content-Transfer-Encoding: 7bit
From: Joel Hedlund <yohell at ifm.liu.se>
Precedence: list
MIME-Version: 1.0
To: python-list at python.org
References: <ed7q6j$9mh$1 at news.lysator.liu.se>
<44f78549$0$11377$636a55ce at news.free.fr>
<ed8qj8$foe$1 at news.lysator.liu.se>
<44f7fc6b$0$26046$626a54ce at news.free.fr>
In-Reply-To: <44f7fc6b$0$26046$626a54ce at news.free.fr>
Date: Fri, 01 Sep 2006 11:52:26 +0200
Message-ID: <ed8vl3$h08$1 at news.lysator.liu.se>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Subject: Re: Python style: to check or not to check args and data members
Message: 3
> And while we're at it : please avoid top-posting.
Yes, that was sloppy. Sorry.
/Joel
Content-Transfer-Encoding: Quoted-Printable
From: "Manuel Bleichner" <manuel at prolink.de>
Precedence: list
MIME-Version: 1.0
To: python-list at python.org
References: <mailman.10236.1157100375.27775.python-list at python.org>
<Xns983167DE33BB3duncanbooth at 127.0.0.1>
In-Reply-To: <Xns983167DE33BB3duncanbooth at 127.0.0.1>
Date: Fri, 01 Sep 2006 11:56:07 +0200
Message-ID: <op.te61vtd858416w at merkur.intern.prolink.de>
Content-Type: text/plain; format=flowed; delsp=yes; charset=iso-8859-15
Subject: Re: Classes referencing each other
Message: 4
Thanks for your answer :)
> You could use a function:
>
> class A(object):
> @staticmethod
> def connected_to(): return [B, C]
> <other attributes...>
I already thought about such a solution, but since
my code has to be compatible with python 2.3, i would
have to use the connected_to = staticmethod(connected_to)
syntax, which bloats the code and makes it quite unreadable.
> or just store the names of the classes and do a similar fixup once they
> are
> all defined:
>
> class A(object):
> connected_to = ['B', 'C']
> <other attributes...>
>
> for cls in globals().values():
> if (type(cls) is type and
> hasattr(cls, 'connected_to')):
> cls.connected_to = [globals()[c] for c in cls.connected_to ]
This solution seems good to me. It won't work for me as it is,
because the structure of the classes is actually a bit more
complex, but it pushed me in the right direction.
Thanks again,
Manuel
From: bearophileHUGS at lycos.com
Precedence: list
MIME-Version: 1.0
To: python-list at python.org
References: <1157050085.120921.31840 at h48g2000cwc.googlegroups.com>
<JcGJg.21533$ED.7604 at read2.cgocable.net>
<1157051115.635459.215920 at p79g2000cwp.googlegroups.com>
<1157051784.609953.196100 at h48g2000cwc.googlegroups.com>
In-Reply-To: <1157051784.609953.196100 at h48g2000cwc.googlegroups.com>
Date: 1 Sep 2006 02:56:59 -0700
Message-ID: <1157104618.899811.216640 at p79g2000cwp.googlegroups.com>
Content-Type: text/plain; charset="iso-8859-1"
Subject: Re: python loops
Message: 5
Kay Schluehr:
> I hate ii ;)
It's not nice looking, I agree. A more explicit name is often better.
But I think ii is better than i because you can find it in the code
(with the Find command of the editor or grep) more easily than i.
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20060901/0b018fb9/attachment.html>
More information about the Python-list
mailing list