yield keyword usage
hi coulde any one show me the usage of "yield" keyword specially in this example: """Fibonacci sequences using generators This program is part of "Dive Into Python", a free Python book for experienced programmers. Visit http://diveintopython.org/ for the latest version. """ __author__ = "Mark Pilgrim ([EMAIL PROTECTED])" __version__ = "$Revision: 1.2 $" __date__ = "$Date: 2004/05/05 21:57:19 $" __copyright__ = "Copyright (c) 2004 Mark Pilgrim" __license__ = "Python" def fibonacci(max): a, b = 0, 1 while a < max: yield a a, b = b, a+b for n in fibonacci(1000): print n, -- http://mail.python.org/mailman/listinfo/python-list
downloading files
I foundd this code in ASPN Python Cookbook for downloading files in
python but when it finished downloading files the files became
corrupted and didn't open, the files in internet havn't any problem:
def download(url,fileName):
"""Copy the contents of a file from a given URL
to a local file.
"""
import urllib
webFile = urllib.urlopen(url)
localFile = open(fileName, 'w')
localFile.write(webFile.read())
webFile.close()
localFile.close()
download('http://www.2shared.com/download/1839752/cd520048/
xpersia14.3gp?tsid=20070803-143313-49566ea2', 'xpersia4.3gp' )
--
http://mail.python.org/mailman/listinfo/python-list
Re: downloading files
On Aug 3, 10:10 pm, Steve Holden <[EMAIL PROTECTED]> wrote:
> Ehsan wrote:
> > I foundd this code in ASPN Python Cookbook for downloading files in
> > python but when it finished downloading files the files became
> > corrupted and didn't open, the files in internet havn't any problem:
>
> > def download(url,fileName):
> >"""Copy the contents of a file from a given URL
> >to a local file.
> >"""
> >import urllib
> >webFile = urllib.urlopen(url)
> >localFile = open(fileName, 'w')
> >localFile.write(webFile.read())
> >webFile.close()
> >localFile.close()
> > download('http://www.2shared.com/download/1839752/cd520048/
> > xpersia14.3gp?tsid=20070803-143313-49566ea2', 'xpersia4.3gp' )
>
> I'm guessing there are binary files and you are running on Windows,
> which is inserting a carriage return before ebery newline. Try
>
> localFile = open(fileName, 'wb')
>
> to avoid thus behavior.
>
> regards
> Steve
> --
> Steve Holden+1 571 484 6266 +1 800 494 3119
> Holden Web LLC/Ltd http://www.holdenweb.com
> Skype: holdenweb http://del.icio.us/steve.holden
> --- Asciimercial --
> Get on the web: Blog, lens and tag the Internet
> Many services currently offer free registration
> --- Thank You for Reading -- Hide quoted text -
>
> - Show quoted text -
thanx Steve
It works but could you explain more what's wrong with just 'w'?
--
http://mail.python.org/mailman/listinfo/python-list
regexp problem in Python
I want to find "http://www.2shared.com/download/1716611/e2000f22/
Jadeed_Mlak14.wmv?tsid=20070803-164051-9d637d11" or 3gp instead of
wmv in the text file like this :
""some code""
function reportAbuse() {
var windowname="abuse";
var url="/abuse.jsp?link=" + "http://www.2shared.com/file/1716611/
e2000f22/Jadeed_Mlak14.html";
OpenWindow =
window.open(url,windowname,'toolbar=no,scrollbars=no,resizable=no,width=500,height=500,left=50,top=50');
OpenWindow.focus();
}
function startDownload(){
window.location = "http://www.2shared.com/download/1716611/
e2000f22/Jadeed_Mlak14.wmv?tsid=20070803-164051-9d637d11";
//document.downloadForm.submit();
}
http://www.2shared.com/download/1716611/e2000f22/
Jadeed_Mlak14.3gp?tsid=20070803-164051-9d637d11"sfgsfgsfgv
I use this pattern :
"http.*?\.(wmv|3gp).*""
but it returns only 'wmv' and '3gp' instead of "http://www.2shared.com/
download/1716611/e2000f22/Jadeed_Mlak14.wmv?
tsid=20070803-164051-9d637d11"
what can I do? what's wrong whit this pattern? thanx for your comments
--
http://mail.python.org/mailman/listinfo/python-list
Re: regexp problem in Python
On Aug 4, 1:36 am, Dave Hansen <[EMAIL PROTECTED]> wrote: > On Aug 3, 4:41 pm, Ehsan <[EMAIL PROTECTED]> wrote: > > > I want to find "http://www.2shared.com/download/1716611/e2000f22/ > [...] > > I use this pattern : > > "http.*?\.(wmv|3gp).*"" > > > but it returns only 'wmv' and '3gp' instead of "http://www.2shared.com/ > > download/1716611/e2000f22/Jadeed_Mlak14.wmv? > > tsid=20070803-164051-9d637d11" > > > what can I do? what's wrong whit this pattern? thanx for your comments > > Just a guess, based on too little information: Try "(http.*?\.(wmv| > 3gp).*)" > > Regards, > >-=Dave no, it doesn't work -- http://mail.python.org/mailman/listinfo/python-list
Re: regexp problem in Python
On Aug 4, 1:22 pm, Sönmez Kartal <[EMAIL PROTECTED]> wrote:
> On 4 A ustos, 00:41, Ehsan <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > I want to find "http://www.2shared.com/download/1716611/e2000f22/
> > Jadeed_Mlak14.wmv?tsid=20070803-164051-9d637d11" or 3gp instead of
> > wmv in the text file like this :
> >
> > ""some code""
> > function reportAbuse() {
> > var windowname="abuse";
> > var url="/abuse.jsp?link=" + "http://www.2shared.com/file/1716611/
> > e2000f22/Jadeed_Mlak14.html";
> > OpenWindow =
> > window.open(url,windowname,'toolbar=no,scrollbars=no,resizable=no,width=500,height=500,left=50,top=50');
> > OpenWindow.focus();
> > }
> > function startDownload(){
> > window.location = "http://www.2shared.com/download/1716611/
> > e2000f22/Jadeed_Mlak14.wmv?tsid=20070803-164051-9d637d11";
> > //document.downloadForm.submit();
> > }
> >
> >
> > http://www.2shared.com/download/1716611/e2000f22/
> > Jadeed_Mlak14.3gp?tsid=20070803-164051-9d637d11"sfgsfgsfgv
>
> > I use this pattern :
> > "http.*?\.(wmv|3gp).*""
>
> > but it returns only 'wmv' and '3gp' instead of "http://www.2shared.com/
> > download/1716611/e2000f22/Jadeed_Mlak14.wmv?
> > tsid=20070803-164051-9d637d11"
>
> > what can I do? what's wrong whit this pattern? thanx for your comments
>
> You could use r'window.location = "(.*?\.(wmv|3gp)";' as your regex
> string, I guess..- Hide quoted text -
>
> - Show quoted text -
I didn't get what do you mean? i think i must just change the pattern
but I don't know how to find bestfit pattern
--
http://mail.python.org/mailman/listinfo/python-list
How to use pip to install dtrx?
Hi, I want to use pip to install dtrx. However, I got the following error. ~~~ $ pip install --allow-external dtrx dtrx DEPRECATION: --allow-external has been deprecated and will be removed in the future. Due to changes in the repository protocol, it no longer has any effect. Collecting dtrx Could not find a version that satisfies the requirement dtrx (from versions: ) No matching distribution found for dtrx ~~~ Is there any way to solve this problem? Thanks in advance. Best regards, Ehsan -- https://mail.python.org/mailman/listinfo/python-list
