a question about my script
Hi all,I am trying to get some files from an ftp site by ftplib module and I wrote the below script. However I have a problem. With my script, I login to ftp.genome.jp site. then, I am changing the directory to pub/kegg/genomes/afm and I am downloading "a.fumigatus.pep" file. However, what I want is to connect pub/kegg/genomes directory and in this directory there are 3 letters name files e.g. 'afm' and in each of these 3 letters files there is a file with the extension of '.pep' like a.fumigatus.pep. I want to get these '.pep' files from the 3 letter named files. If you help me I will be very glad. Thanks you in advance.Regards,Alperfrom ftplib import FTP def handleDownload( block): file.write(block) print ".",ftp = FTP('ftp.genome. jp') print ftp.login() directory = 'pub/kegg/genomes/ afm' print 'Changing to ' + directoryftp.cwd(directory) ftp.retrlines( 'LIST') filename = 'a.fumigatus. pep' print 'Opening local file ' + filenamefile = open(filename, 'wb') print 'Getting ' + filenameftp.retrbinary( 'RETR ' + filename, handleDownload) print 'Closing file ' + filenamefile.close() print 'Closing FTP connection'print ftp.close()-- http://mail.python.org/mailman/listinfo/python-list
Re: a question about my script
Hi,I changed the script as you wrote below: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=0for 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()However, it gave the same error message:230 Anonymous access granted, restrictions apply.Traceback (most recent call last): File "ftp1.0.py", line 18, in ? ftp.cwd(curdir) File "/usr/lib/python2.4/ftplib.py", line 494, in cwd return self.voidcmd(cmd) File "/usr/lib/python2.4/ftplib.py", line 246, in voidcmd return self.voidresp() File "/usr/lib/python2.4/ftplib.py", line 221, in voidresp resp = self.getresp() File "/usr/lib/python2.4/ftplib.py", line 216, in getresp raise error_perm, respftplib.error_perm: 550 pub/kegg/genomes/aae: No such file or directoryHowever, in ftp.genome.jp/pub/kegg/genomes/ site, there is 'aae' directory. What can be the reason?regards,alper- Original Message From: Gabriel Genellina <[EMAIL PROTECTED]>To: alper soyler <[EMAIL PROTECTED]>Cc: Python-list@python.orgSent: Tuesday, August 29, 2006 10:26:57 AMSubject: Re: a question about my scriptAt Tuesday 29/8/2006 03:55, alper soyler wrote:>I am trying to get some files from an ftp site by ftplib module and >I wrote the below script. However I have a problem. With my script, >I login to ftp.genome.jp site. then, I am changing the directory to >pub/kegg/genomes/afm and I am downloading "a.fumigatus.pep" file. >However, what I want is to connect pub/kegg/genomes directory and in >this directory there are 3 letters name files3 letters *files*? or 3 letters *directories*?>e.g. 'afm' and in each of these 3 letters files there is a file with >the extension of '.pep' like a.fumigatus.pep. I want to get these >'.pep' files from the 3 letter named files. If you help me I will be >very glad. Thanks you in advance.Do a cwd() starting one level above (that is, pub/kegg/genomes); using ftp.dir() you can get the subdirectories, then iterate over all of them, using another dir() to find the .pep files needed.>directory = 'pub/kegg/genomes/ afm'Is that whitespace intentional?(If you just want to download the files and don't need really a Python script, try wget...)Gabriel GenellinaSoftlab SRL __Preguntá. Respondé. Descubrí.Todo lo que querías saber, y lo que ni imaginabas,está en Yahoo! Respuestas (Beta).¡Probalo ya! http://www.yahoo.com.ar/respuestas-- http://mail.python.org/mailman/listinfo/python-list
Re: a question about my script
Hi,I changed the script as you wrote below: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=0for 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()However, it gave the same error message:230 Anonymous access granted, restrictions apply.Traceback (most recent call last): File "ftp1.0.py", line 18, in ? ftp.cwd(curdir) File "/usr/lib/python2.4/ftplib.py", line 494, in cwd return self.voidcmd(cmd) File "/usr/lib/python2.4/ftplib.py", line 246, in voidcmd return self.voidresp() File "/usr/lib/python2.4/ftplib.py", line 221, in voidresp resp = self.getresp() File "/usr/lib/python2.4/ftplib.py", line 216, in getresp raise error_perm, respftplib.error_perm: 550 pub/kegg/genomes/aae: No such file or directoryHowever, in ftp.genome.jp/pub/kegg/genomes/ site, there is 'aae' directory. What can be the reason?regards,alper- Original Message From: Gabriel Genellina <[EMAIL PROTECTED]>To: alper soyler <[EMAIL PROTECTED]>Cc: Python-list@python.orgSent: Tuesday, August 29, 2006 10:26:57 AMSubject: Re: a question about my scriptAt Tuesday 29/8/2006 03:55, alper soyler wrote:>I am trying to get some files from an ftp site by ftplib module and >I wrote the below script. However I have a problem. With my script, >I login to ftp.genome.jp site. then, I am changing the directory to >pub/kegg/genomes/afm and I am downloading "a.fumigatus.pep" file. >However, what I want is to connect pub/kegg/genomes directory and in >this directory there are 3 letters name files3 letters *files*? or 3 letters *directories*?>e.g. 'afm' and in each of these 3 letters files there is a file with >the extension of '.pep' like a.fumigatus.pep. I want to get these >'.pep' files from the 3 letter named files. If you help me I will be >very glad. Thanks you in advance.Do a cwd() starting one level above (that is, pub/kegg/genomes); using ftp.dir() you can get the subdirectories, then iterate over all of them, using another dir() to find the .pep files needed.>directory = 'pub/kegg/genomes/ afm'Is that whitespace intentional?(If you just want to download the files and don't need really a Python script, try wget...)Gabriel GenellinaSoftlab SRL __Preguntá. Respondé. Descubrí.Todo lo que querías saber, y lo que ni imaginabas,está en Yahoo! Respuestas (Beta).¡Probalo ya! http://www.yahoo.com.ar/respuestas-- http://mail.python.org/mailman/listinfo/python-list
Re: Python-list Digest, Vol 35, Issue 501
Trying to split the directories gave me the same error message with the previous one?Alper- Original Message From: [EMAIL PROTECTED]To: python-list@python.orgSent: Thursday, August 31, 2006 4:40:03 PMSubject: Python-list Digest, Vol 35, Issue 501Send Python-list mailing list submissions topython-list@python.orgTo subscribe or unsubscribe via the World Wide Web, visithttp://mail.python.org/mailman/listinfo/python-listor, 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 specificthan "Re: Contents of Python-list digest..."Today's Topics: 1. Tkinter listbox question ([EMAIL PROTECTED]) 2. Re: Using eval with substitutions (Peter Otten) 3. Re: a question about my script (alper soyler) 4. Re: a question about my script (Fredrik Lundh) 5. Re: Using eval with substitutions (Duncan Booth) 6. Re: a question about my script (alper soyler) 7. simultaneous copy to multiple media ([EMAIL PROTECTED])From: [EMAIL PROTECTED]Precedence: listMIME-Version: 1.0To: python-list@python.orgDate: 31 Aug 2006 05:41:43 -0700Message-ID: <[EMAIL PROTECTED]>Content-Type: text/plain; charset="iso-8859-1"Subject: Tkinter listbox questionMessage: 1Hi,I need help about Tkinter listbox widget.I want,when somebody click onany item(file) in Listbox,then in new Label widget text must beselected item from server.my program (wrong example):import ftputilimport Tkinterroot=Tkinter.Tk()ftp=ftputil.FTPHost('some imaginary server')def LabelWidget(event):a=Tkinter.Label(root,text=) # Text must be only name and fileformat,example: sun.gifa.grid()b=Tkinter.Listbox(root)b.insert(Tkinter.END,ftp._dir(''))b.place()c=Tkinter.Button(root,text='PRINT THIS FILE IN NEW LABEL WIDGET')c.bind('',LabelWidget)c.grid()root.mainloop()THANKS!!!Content-Transfer-Encoding: 7BitFrom: Peter Otten <[EMAIL PROTECTED]>Precedence: listMIME-Version: 1.0To: python-list@python.orgReferences: <[EMAIL PROTECTED]><[EMAIL PROTECTED]><[EMAIL PROTECTED]>Date: Thu, 31 Aug 2006 14:54:50 +0200Message-ID: <[EMAIL PROTECTED]>Content-Type: text/plain; charset=us-asciiSubject: Re: Using eval with substitutionsMessage: 2[EMAIL PROTECTED] wrote:> Fredrik Lundh wrote:>> (I'm afraid I don't really understand the point of your examples; what>> is it you're really trying to do here ?)> > A function is passed a bunch of string expressions like,> x = "a+b"> y= "x*a"> z= "x+y"> > where a and b are assumed to have been assigned values in the local> namespace. Now I have to evaluate another string such as,> "z+y+x"> > So as you say, I could do:> x=eval(x), y=eval(y), z=eval(z) and finally eval("z+y+x") but the> problem is that the initial strings are in no particular order, so I> don't know the sequence in which to perform the first 3 evaluations. I> was wondering if there was a simple way to 'pattern-match' so that the> required substitutions like z->x+y->x+x*a->(a+b)+(a+b)*a could be done> automatically.Here is something to start with:class EvalDict(object):def __init__(self, namespace):self.namespace = namespacedef __getitem__(self, key):value = self.namespace[key]if isinstance(value, str):self.namespace[key] = value = eval(value, {}, self)return valuedef smart_eval(expr, namespace):return eval(expr, {}, EvalDict(namespace))def f(): a = 2b = 3x = "a+b"y = "x*a"z = "x+y"return smart_eval("x + y + z", locals())if __name__ == "__main__": print f()Beware of infinite recursion:# RuntimeError: maximum recursion depth exceededsmart_eval("a + b", dict(a="b", b="a")) PeterFrom: alper soyler <[EMAIL PROTECTED]>Precedence: listMIME-Version: 1.0To: Python-list@python.orgIn-Reply-To: <[EMAIL PROTECTED]>Date: Thu, 31 Aug 2006 06:01:09 -0700 (PDT)Reply-To: alper soyler <[EMAIL PROTECTED]>Message-ID: <[EMAIL PROTECTED]>Content-Type: multipart/alternative; boundary="0-620705374-1157029269=:50849"Subject: Re: a question about my scriptMessage: 3Hi,I changed the script as you wrote below: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=0for direct in ftp.nlst(): curdir = '%s/%s' % (directory, direct) ftp.cwd(curdir) for filename in ftp.nlst(): if not filename.endswith('.pep'): continue file
Question about ftplib
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 "", line 1, in connectsocket.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=0for 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.orgSent: Friday, September 1, 2006 1:00:05 PMSubject: Python-list Digest, Vol 36, Issue 10Send Python-list mailing list submissions topython-list@python.orgTo subscribe or unsubscribe via the World Wide Web, visithttp://mail.python.org/mailman/listinfo/python-listor, 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 specificthan "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])From: "stdazi" <[EMAIL PROTECTED]>Precedence: listMIME-Version: 1.0To: python-list@python.orgReferences: <[EMAIL PROTECTED]><[EMAIL PROTECTED]><[EMAIL PROTECTED]>In-Reply-To: <[EMAIL PROTECTED]>Date: 1 Sep 2006 02:34:48 -0700Message-ID: <[EMAIL PROTECTED]>Content-Type: text/plain; charset="iso-8859-1"Subject: Re: python loopsMessage: 1`range' is especially useful for iterating over long sequences ;-)for i in range(0,100) :OverflowError: range() result has too many itemsSybren 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 ZappaContent-Transfer-Encoding: 7bitFrom: Georg Brandl <[EMAIL PROTECTED]>Precedence: listMIME-Version: 1.0To: python-list@python.orgReferences: <[EMAIL PROTECTED]>In-Reply-To: <[EMAIL PROTECTED]>Date: Fri, 01 Sep 2006 11:50:42 +0200Message-ID: <[EMAIL PROTECTED]>Content-Type: text/plain; charset=ISO-8859-15; format=flowedSubject: Re: Classes referencing each otherMessage: 2Manuel 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]>> > class B(object)>connected_to = [C]>> > class C(object)>connected_to = [A]>> > As you see, classes A and B reference classes that> are not yet defined when the class i