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()
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: [EMAIL PROTECTED]
To: python-list@python.org
Sent: Friday, September 1, 2006 1:00:05 PM
Subject: Python-list Digest, Vol 36, Issue 10
From: [EMAIL PROTECTED]
To: python-list@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@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
[EMAIL PROTECTED]
You can reach the person managing the list at
[EMAIL PROTECTED]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Python-list digest..."
python-list@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
[EMAIL PROTECTED]
You can reach the person managing the list at
[EMAIL PROTECTED]
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 ([EMAIL PROTECTED])
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 ([EMAIL PROTECTED])
From: "stdazi" <[EMAIL PROTECTED]>
Precedence: list
MIME-Version: 1.0
To: python-list@python.org
References: <[EMAIL PROTECTED]>
<[EMAIL PROTECTED]>
<[EMAIL PROTECTED]>
In-Reply-To: <[EMAIL PROTECTED]>
Date: 1 Sep 2006 02:34:48 -0700
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset="iso-8859-1"
Subject: Re: python loops
Message: 1
Precedence: list
MIME-Version: 1.0
To: python-list@python.org
References: <[EMAIL PROTECTED]>
<[EMAIL PROTECTED]>
<[EMAIL PROTECTED]>
In-Reply-To: <[EMAIL PROTECTED]>
Date: 1 Sep 2006 02:34:48 -0700
Message-ID: <[EMAIL PROTECTED]>
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:
> [EMAIL PROTECTED] 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
for i in range(0,100000000000000) :
OverflowError: range() result has too many items
Sybren Stuvel wrote:
> [EMAIL PROTECTED] 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 <[EMAIL PROTECTED]>
Precedence: list
MIME-Version: 1.0
To: python-list@python.org
References: <[EMAIL PROTECTED]>
In-Reply-To: <[EMAIL PROTECTED]>
Date: Fri, 01 Sep 2006 11:50:42 +0200
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Subject: Re: Classes referencing each other
Message: 2
From: Georg Brandl <[EMAIL PROTECTED]>
Precedence: list
MIME-Version: 1.0
To: python-list@python.org
References: <[EMAIL PROTECTED]>
In-Reply-To: <[EMAIL PROTECTED]>
Date: Fri, 01 Sep 2006 11:50:42 +0200
Message-ID: <[EMAIL PROTECTED]>
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
> 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 <[EMAIL PROTECTED]>
Precedence: list
MIME-Version: 1.0
To: python-list@python.org
References: <[EMAIL PROTECTED]>
<[EMAIL PROTECTED]>
<[EMAIL PROTECTED]>
<[EMAIL PROTECTED]>
In-Reply-To: <[EMAIL PROTECTED]>
Date: Fri, 01 Sep 2006 11:52:26 +0200
Message-ID: <[EMAIL PROTECTED]>
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
From: Joel Hedlund <[EMAIL PROTECTED]>
Precedence: list
MIME-Version: 1.0
To: python-list@python.org
References: <[EMAIL PROTECTED]>
<[EMAIL PROTECTED]>
<[EMAIL PROTECTED]>
<[EMAIL PROTECTED]>
In-Reply-To: <[EMAIL PROTECTED]>
Date: Fri, 01 Sep 2006 11:52:26 +0200
Message-ID: <[EMAIL PROTECTED]>
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
Yes, that was sloppy. Sorry.
/Joel
Content-Transfer-Encoding: Quoted-Printable
From: "Manuel Bleichner" <[EMAIL PROTECTED]>
Precedence: list
MIME-Version: 1.0
To: python-list@python.org
References: <[EMAIL PROTECTED]>
<[EMAIL PROTECTED]>
In-Reply-To: <[EMAIL PROTECTED]>
Date: Fri, 01 Sep 2006 11:56:07 +0200
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; format=flowed; delsp=yes; charset=iso-8859-15
Subject: Re: Classes referencing each other
Message: 4
From: "Manuel Bleichner" <[EMAIL PROTECTED]>
Precedence: list
MIME-Version: 1.0
To: python-list@python.org
References: <[EMAIL PROTECTED]>
<[EMAIL PROTECTED]>
In-Reply-To: <[EMAIL PROTECTED]>
Date: Fri, 01 Sep 2006 11:56:07 +0200
Message-ID: <[EMAIL PROTECTED]>
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
> 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: [EMAIL PROTECTED]
Precedence: list
MIME-Version: 1.0
To: python-list@python.org
References: <[EMAIL PROTECTED]>
<[EMAIL PROTECTED]>
<[EMAIL PROTECTED]>
<[EMAIL PROTECTED]>
In-Reply-To: <[EMAIL PROTECTED]>
Date: 1 Sep 2006 02:56:59 -0700
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset="iso-8859-1"
Subject: Re: python loops
Message: 5
Precedence: list
MIME-Version: 1.0
To: python-list@python.org
References: <[EMAIL PROTECTED]>
<[EMAIL PROTECTED]>
<[EMAIL PROTECTED]>
<[EMAIL PROTECTED]>
In-Reply-To: <[EMAIL PROTECTED]>
Date: 1 Sep 2006 02:56:59 -0700
Message-ID: <[EMAIL PROTECTED]>
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
> 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