how to display the result in table with jinkoa2 temple?
import sqlite3 db=r'F:\workspace\china\data\china.sqlite' con=sqlite3.connect(db) cur=con.cursor() res=cur.execute('select 代码,所属行业,注册资本,雇员人数,管理人员人数 from profile limit 20').fetchall() the result is a list. for row in res: ... print(row) ... ('60', '银行', '187亿', 39340.0, 30.0) ('64', '民航机场', '11.5亿', 4499.0, 23.0) ('65', '钢铁行业', '101亿', 38857.0, 24.0) ('66', '汽车行业', '20.0亿', 10290.0, 20.0) ('67', '房地产', '10.1亿', 2332.0, 19.0) ('68', '公用事业', '22.0亿', 6515.0, 20.0) ('69', '民航机场', '19.3亿', 5472.0, 18.0) ('600010', '钢铁行业', '80.0亿', 31389.0, 19.0) ('600011', '电力行业', '141亿', 37729.0, 29.0) ('600012', '高速公路', '16.6亿', 2106.0, 14.0) ('600015', '银行', '89.0亿', 25200.0, 34.0) ('600016', '银行', '340亿', 54927.0, 32.0) ('600017', '港口水运', '30.8亿', 5340.0, 21.0) ('600018', '港口水运', '228亿', 19842.0, 20.0) ('600019', '钢铁行业', '165亿', 37487.0, 23.0) ('600020', '高速公路', '22.5亿', 2959.0, 32.0) ('600021', '电力行业', '21.4亿', 6673.0, 22.0) ('600022', '钢铁行业', '64.4亿', 31738.0, 20.0) ('600023', '电力行业', '118亿', 10142.0, 14.0) ('600026', '港口水运', '34.0亿', 7536.0, 21.0) i want to display it in html table . html_str='table border=1' for row in res: html_str=html_str+'tr' for col in row: html_str=html_str+'td'+str(col).replace('\s','') html_str=html_str+'/td' html_str=html_str+'/tr' html_str=html_str+'/table' myhtml=open('f:\\test.html','w') myhtml.write(html_str) myhtml.close() when i open 'f:\\test.html' in chrome , how can i change my code more elegantly with temple jinjia2 to do the same display ? -- https://mail.python.org/mailman/listinfo/python-list
Re: Dynamically swapping between two algorithms
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes: ... *If* Python was a different language, I would spawn two threads, one using SHORT and the other using LARGE, then which ever completes first, I'd just kill the other. Alas, this won't work because (1) the GIL The GIL does not prevent this scenario. The two threads will not really run in parallel but interleaved - but this should not be a big problem. and (2) you cannot forcibly kill threads, only ask them to die and hope they listen. You can kill threads (though you will need a C level function for this) as long as they execute Python code. And it is your code: you can make your threads be listening, from time to time in the computation. -- https://mail.python.org/mailman/listinfo/python-list
Re: how to write a html to automatically display the dictionary?
- Original Message - From: luofeiyu elearn2...@gmail.com To: Joel Goldstick joel.goldst...@gmail.com, python-list@python.org Sent: Wednesday, 24 September, 2014 1:06:25 AM Subject: Re: how to write a html to automatically display the dictionary? how can i create the proper html file with Jinjia 2 or other temple? template :) I'm surprised you didn't figure it out by looking at jinja2 examples in their documentation. python 2.7 : from jinja2 import Template template = Template(''' table border=1 tr{% for k in x.keys()%}th{{k}}/th{%endfor%}/tr tr{% for k in x.values()%}td{{k}}/td{%endfor%}/tr /table''') with open('foo.html', 'w') as myFile: myFile.write(template.render(x={'f1':1,'f2':2,'f3':3})) Regards, JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. -- https://mail.python.org/mailman/listinfo/python-list
why can't open the file with browser?
| import webbrowser webbrowser.open('f:\\test.html') why the file f:\\test.html is opened by notepad ,not by my firefox or chrome? | -- https://mail.python.org/mailman/listinfo/python-list
import reloading
I'm tryng to bring some outdated ihooks code into the modern world. I notice that module loaders are supposed to re-use an existing module if it is already in sys.modules. Is a loader supposed to reset all the reused module's attributes and reset the __dict__ or does it just run the code from the module in hte __dict__? -- Robin Becker -- https://mail.python.org/mailman/listinfo/python-list
Re: GCD in Fractions
On 23/09/2014 23:52, Mark Lawrence wrote: On 23/09/2014 22:48, blindanagram wrote: On 23/09/2014 20:30, Mark Lawrence wrote: On 23/09/2014 18:43, blindanagram wrote: All you need do is raise an issue on the bug tracker, provide a patch to code, test and docs and the job is done. Thank you for your helpful comment. I will happily do this if after discussion here there is a reasonable level of support and encouragement for such an action. However, there is at least one person here who takes the view that backward compatibility outranks mathematical correctness and I don't want to find that 'I am banging my head against a brick wall' if this is likely to be the stance that Python developers take. From https://docs.python.org/devguide/experts.html Mark Dickinson and Raymond Hettinger are listed as the maintainers of the fractions module. If they're not lurking here I'd guess the simplest way to contact them is via the bug tracker. That also gives the official mechanism as to whether or not an enhancement request such as this is accepted or rejected and the rationale behind the decision. For example it is feasible that the current behaviour would be deprecated in Python 3.5 and changed in 3.6 to match your needs. I don't have enough knowledge of the maths to say one way or another, but I'm certain that others will chip in with their comments. Best of luck anyway :) Somebody got there first http://bugs.python.org/issue22477 -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: GCD in Fractions
Mark Lawrence breamoreboy at yahoo.co.uk writes: Somebody got there first http://bugs.python.org/issue22477 I think there's good reason to suspect that Brian Gladman and blindanagram are one and the same. :-) sorted(BrianGladman.lower()) == sorted(blindanagram) True -- https://mail.python.org/mailman/listinfo/python-list
Re: why can't open the file with browser?
Maybe it's supposed to be file://localhost/test.html ? Just a guess, as I don't use Windows. Skip On Wed, Sep 24, 2014 at 4:32 AM, luofeiyu elearn2...@gmail.com wrote: import webbrowser webbrowser.open('f:\\test.html') why the file f:\\test.html is opened by notepad ,not by my firefox or chrome? -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: GCD in Fractions
blindanagram wrote: Seccondly (as others here have pointed out), the mathematical properties of the greatest common divisor are well defined for both positive and negative integers. You keep saying that, but it simply is not true. Different people use different definitions. Some refuse to allow negative arguments at all. Some insist that the GCD must be positive. Others allow it to be negative. GCD is well-defined for **positive integers only**. Mathworld emphasises positive integers in their definition, repeating the phrase THREE times in the first paragraph: The greatest common divisor, sometimes also called the highest common divisor (Hardy and Wright 1979, p. 20), of two positive integers a and b is the largest divisor common to a and b. For example, GCD(3,5)=1, GCD(12,60)=12, and GCD(12,90)=6. The greatest common divisor GCD(a,b,c,...) can also be defined for three or more positive integers as the largest divisor shared by all of them. Two or more positive integers that have greatest common divisor 1 are said to be relatively prime to one another, often simply just referred to as being relatively prime. http://mathworld.wolfram.com/GreatestCommonDivisor.html The rest of the page avoids mentioning anything about negative values. There are five graphs on the page, all five are limited to only positive values. Mathworld does show one thing that suggests an interpretation for the GCD of negative values: The GCD is distributive GCD(ma,mb)=mGCD(a,b) which tells us that: GCD(-x, -y) = -GCD(x, y) And yet, Mathematica has: GCD(-x, -y) = GCD(x, y) the very opposite of what Mathworld says, despite coming from the same people. http://functions.wolfram.com/IntegerFunctions/GCD/04/02/01/ The Collins Dictionary of Mathematics (second edition, 2002) says: highest common factor, greatest common factor, or greatest common divisor (abbrev hcf, gcf, gcd) n, an integer d that exactly divides (sense 2) two given integers a and b, and is such that if c divides a and b, then c divides d; this definition extends to finite sets of integers and to integral domains. For example, the highest common factor of 12, 60 and 84 is 12. Yet again, we have no clear definition for negative values. Here's an example using Euclid's algorithm to calculate the GCD of negative numbers, and sure enough, you get a negative result: https://answers.yahoo.com/question/index?qid=20111021023909AA8bCjB Wikipedia, on the other hand, defines GCD: In mathematics, the greatest common divisor (gcd), also known as the greatest common factor (gcf), highest common factor (hcf), or greatest common measure (gcm), of two or more integers (when at least one of them is not zero), is the largest positive integer that divides the numbers without a remainder. https://en.wikipedia.org/wiki/Greatest_common_divisor So: - Mathworld says that GCD of two negative numbers is a negative number; - but Mathematica says that GCD of two negative numbers is a positive; - Wikipedia agrees with Mathematica and disagrees with Mathworld; - Euclid's algorithm returns negative values for the GCD of two negatives; - Collins Dictionary gives a definition which is met by either positive or negative results. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re:import reloading
Robin Becker ro...@reportlab.com Wrote in message: I'm tryng to bring some outdated ihooks code into the modern world. I notice that module loaders are supposed to re-use an existing module if it is already in sys.modules. No, the loader is required to reuse the existing module. Is a loader supposed to reset all the reused module's attributes and reset the __dict__ or does it just run the code from the module in hte __dict__? Nothing gets reset or run. It simply reuses the existing module object. There are ways to fool the loader, for example by having a module visible in more than one file system path. The most common of these bugs is a module that tries to import the script that's started it all. Because that initial script is named __main__ internally, if you try to import it by filename you end up with two instances. -- DaveA -- https://mail.python.org/mailman/listinfo/python-list
RE: why can't open the file with browser?
import webbrowser webbrowser.open('f:\\test.html') why the file f:\\test.html is opened by notepad ,not by my firefox or chrome? The default protocol in a browser is http. If you're not running a server on your local machine, you need to specify a different protocol. Try file:///f:/test.html I also don't run Windows any more so I might have the drive letter part wrong. -- DaveA Original message From: luofeiyu elearn2...@gmail.com Date:09/24/2014 5:32 AM (GMT-05:00) To: python-list@python.org Subject: why can't open the file with browser? import webbrowser webbrowser.open('f:\\test.html') why the file f:\\test.html is opened by notepad ,not by my firefox or chrome? -- https://mail.python.org/mailman/listinfo/python-list
Re: why can't open the file with browser?
On Wed, Sep 24, 2014 at 7:32 PM, luofeiyu elearn2...@gmail.com wrote: import webbrowser webbrowser.open('f:\\test.html') why the file f:\\test.html is opened by notepad ,not by my firefox or chrome? It looks to me as if your default association is set to Notepad rather than a web browser. Try opening one of the browsers' settings pages and making it your default browser. In Chrome, that's chrome://settings/ and it's near the bottom; in Firefox, go to Tools|Options, Advanced, and it's on the General tab. (They might check on startup and offer to make themselves default, which would save you some trouble.) ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Receiving large files with @tornado.web.stream_request_body
I was using tornado 3 before. I see that file streaming was included in version 4. This is something I need for posting large files. I have a problem receiving multiple files with a single POST request. Client side could be something like this: form action=/postfiles First file: input type=file name=fname1br Second file: input type=file name=fname2br Third file: input type=file name=fname3br input type=submit value=Submit /form Suppose the user has seleted 3 large ISO files, I would like to stream them into files on the server side. This is what I was trying: @tornado.web.stream_request_body class PostFilesHandler(tornado.web.RequestHandler): def post(self): for postfile in self.request.files: print(File info:,postfile) # There is no postfile[body] here!!! def prepare(self): self.temp_file = tempfile.NamedTemporaryFile(delete=False) def data_received(self, chunk): self.temp_file.write(chunk) # This is great but which file is this??? The problem is obvious: the data_received method receives raw data, but how do I tell when data body for a file ends and another begins? How can I save the body of all posted files into different named temp files, and then access them from from the post() method? The main reason for using this is to limit memory usage. Some files might be GB sized and I don't want to store them in memory. Can please someone point me to a working example? Thanks Laszlo -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. -- https://mail.python.org/mailman/listinfo/python-list
Re: Best way to deal with different data types in a list comprehension
Larry Martell wrote: I have some code that I inherited: ' '.join([self.get_abbrev()] + [str(f['value') for f in self.filters if f.has_key('value')]).strip() This broke today when it encountered some non-ascii data. It's already broken. It gives a Syntax Error part way through: py ' '.join([self.get_abbrev()] + ...[str(f['value') File stdin, line 2 [str(f['value') ^ SyntaxError: invalid syntax Please copy and paste the actual code, don't retype it. This is my guess of what you actually have, reformatted to make it more clear (at least to me): ' '.join( [self.get_abbrev()] + [str(f['value']) for f in self.filters if f.has_key('value')] ).strip() I *think* that the call to strip() is redundant. Hmmm... perhaps not, if the self.get_abbrev() begins with whitespace, or the last f['value'] ends with whitespace. You should consider removing that call to .strip(), but for now I'll assume it actually is useful and leave it in. First change: assuming the filters are dicts, do the test this way: ' '.join( [self.get_abbrev()] + [str(f['value']) for f in self.filters if 'value' in f] ).strip() Now, the *right* way to fix your problem is to convert the whole application to use unicode strings everywhere instead of byte strings. I'm guessing you are using Python 2.6 or 2.7. You say it broke when given some non-ascii data, but that's extremely ambiguous. {23: 42} is non-ascii data. What exactly do you have, and where did it come from? My *guess* is that you had a Unicode string, containing characters which cannot be converted to ASCII. py str(u'Ωπ') Traceback (most recent call last): File stdin, line 1, in module UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128) I changed the str(f['value']) line to f['value'].encode('utf-8'), Hmmm, I'm not sure that's a good plan: py u'Ωπ'.encode('utf-8') '\xce\xa9\xcf\x80' Do you really want to find arbitrary bytes floating through your strings? A better strategy is to convert the program to use unicode strings internally, and only convert to byte strings when you read and write to files. But assuming you don't have the time or budget for that sort of re-write, here's a minimal chance which might do the job: u' '.join( [self.get_abbrev()] + [unicode(f['value']) for f in self.filters if 'value' in f] ).strip() That works correctly for random objects and ASCII byte strings: py unicode([1, 2, 3]) u'[1, 2, 3]' py unicode('bytes') u'bytes' Alas, it will fail for non-ASCII byte strings: py unicode('bytes \xFF') Traceback (most recent call last): File stdin, line 1, in module UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 6: ordinal not in range(128) Here's a version which prefers byte-strings, but should be able to handle everything you throw at it: ' '.join( [self.get_abbrev()] + [ (x.encode('utf-8') if isinstance(x, unicode) else x) for x in (f['value'] for f in self.filters if 'value' in f) ] ).strip() Note the use of a generator expression inside the list comp. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: GCD in Fractions
On 24/09/2014 12:44, Steven D'Aprano wrote: blindanagram wrote: [snip] - Mathworld says that GCD of two negative numbers is a negative number; - but Mathematica says that GCD of two negative numbers is a positive; - Wikipedia agrees with Mathematica and disagrees with Mathworld; After looking at these (and several other) on-line mathematical sites, I realised that I would have to go back to long standing mathemmatical references to find how the gcd is defined by those that explicitly cover the greatest common divisor for negative integers (I did this before raising the issue here). All four that I have so far looked at have definitions that lead to gcd(a, b) for integers being equal to gcd(|a|, |b|). I hope to visit a University library shortly to review more. Does anyone know of such a reference that uses a definition that conflicts with gcd(a, b) for integers being equal to gcd(|a|, |b|)? -- https://mail.python.org/mailman/listinfo/python-list
Re: import reloading
On 24/09/2014 12:54, Dave Angel wrote: Robin Becker ro...@reportlab.com Wrote in message: ... Is a loader supposed to reset all the reused module's attributes and reset the __dict__ or does it just run the code from the module in hte __dict__? Nothing gets reset or run. It simply reuses the existing module object. I find that a bit weird. In fact as a test I created a testmod.py ### A=3 print('A=%r' % A) ### then in python3.4 Python 3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:24:06) [MSC v.1600 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. import testmod A=3 testmod.A 3 #I externally changed testmod.py to read #a=4 #print('a=%r' % a) import imp imp.reload(testmod) a=4 module 'testmod' from 'C:\\code\\tests\\testmod.py' testmod.A 3 testmod.a 4 so you are right the old module variables are still there. Presumably any functions/classes etc etc that don't get overwritten will also continue to exist. There are ways to fool the loader, for example by having a module visible in more than one file system path. The most common of these bugs is a module that tries to import the script that's started it all. Because that initial script is named __main__ internally, if you try to import it by filename you end up with two instances. -- Robin Becker -- https://mail.python.org/mailman/listinfo/python-list
brackets at the end of a method name
Hi Once a file is opened with: f=open(foo.txt, r) we have some methods associated with file f f.read() f.readline() .. f.close() f.name f.mode I dont understand why sometimes there are brackets () at the end of the method name (ie close())and sometimes no (ie name) I thought that maybe methods with () could have a parameter passed to, for example f.close(parameter) but it is not the case. This is documentation about close(), there is no parameter. close() Close the current file and forget everything we know about it (including the filename and the current line number). thx -- https://mail.python.org/mailman/listinfo/python-list
Re: brackets at the end of a method name
On 2014-09-24 13:30:55 +, ast said: we have some methods associated with file f […] f.close() f.name print(type(f.close)) print(type(f.name)) Spot the difference. -- Andrea -- https://mail.python.org/mailman/listinfo/python-list
Re: brackets at the end of a method name
Andrea D'Amore anddamnopsam+gru...@brapi.net a écrit dans le message de news:lvuhdu$c6q$1...@virtdiesel.mng.cu.mi.it... On 2014-09-24 13:30:55 +, ast said: we have some methods associated with file f […] f.close() f.name print(type(f.close)) print(type(f.name)) Spot the difference. -- Andrea f.name is an attribute and f.close a method ! How stupid am i thx -- https://mail.python.org/mailman/listinfo/python-list
Re: import reloading
Robin Becker ro...@reportlab.com Wrote in message: On 24/09/2014 12:54, Dave Angel wrote: Robin Becker ro...@reportlab.com Wrote in message: ... Is a loader supposed to reset all the reused module's attributes and reset the __dict__ or does it just run the code from the module in hte __dict__? Nothing gets reset or run. It simply reuses the existing module object. I find that a bit weird. In fact as a test I created a testmod.py ### A=3 print('A=%r' % A) ### then in python3.4 Python 3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:24:06) [MSC v.1600 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. import testmod A=3 testmod.A 3 #I externally changed testmod.py to read #a=4 #print('a=%r' % a) import imp imp.reload(testmod) a=4 module 'testmod' from 'C:\\code\\tests\\testmod.py' testmod.A 3 testmod.a 4 so you are right the old module variables are still there. Presumably any functions/classes etc etc that don't get overwritten will also continue to exist. Please don't misquote me. I have no idea why testmod.A gave you a number at all. Must be a bug in reload. Anyway I talked only about import. imp.reload is an abomination useful only to occasionally save time in an interactive session. import, on the other hand, had better continue to be consistent. Many modules are imported dozens of times in a typical application, and you wouldn't want multiple instances of them. -- DaveA -- https://mail.python.org/mailman/listinfo/python-list
how to make return(self.res) not to output the content of list ?
There is a file named analyse.py in the D:\Python34\Lib\site-packages. import sqlite3,os,jinja2 db = r'F:\workspace\china\data\china.sqlite' con = sqlite3.connect(db) cur = con.cursor() class status(): def grow(self): self.res=cur.execute('select 代码,所属行业,注册资本,雇员人数,管 理人员人数 from profile limit 10').fetchall() def display(self): template = jinja2.Template(''' table border=1 {% for row in res %} tr {% for col in row -%} td{{ col}}/td {% endfor %} /tr {% endfor %} /table ''') with open('f:\\test.html', 'w') as f: f.write(template.render(res=self.res)) import webbrowser webbrowser.open('f:\\test.html') when i open python3.4 console to input the code: import analyse x=analyse.status() x.grow() x.display() i get when i add return(self.res) in grow method to make analyse.py into the following: import sqlite3,os,jinja2 db = r'F:\workspace\china\data\china.sqlite' con = sqlite3.connect(db) cur = con.cursor() class status(): def grow(self): self.res=cur.execute('select 代码,所属行业,注册资本,雇员人数,管 理人员人数 from profile limit 10').fetchall() return(self.res) def display(self): template = jinja2.Template(''' table border=1 {% for row in res %} tr {% for col in row -%} td{{ col}}/td {% endfor %} /tr {% endfor %} /table ''') with open('f:\\test.html', 'w') as f: f.write(template.render(res=self.res)) import webbrowser webbrowser.open('f:\\test.html') now again input the code: import analyse x=analyse.status() x.grow() the x.grow() will output [('60', '银行', '187亿', 39340.0, 30.0), ('64', '民航机场', '11.5亿', 4499.0, 23.0), ('65', '钢铁行业', '101亿', 38857.0, 24.0), ('66', '汽车行业', '20.0亿', 10290.0, 20.0), ('67', '房地产', '10.1亿', 2332.0, 19.0), ('68', '公用事业', '22.0亿', 6515.0, 20.0), ('69', '民航机场', '19.3亿', 5472.0, 18.0), ('600010', '钢铁行业', '80.0亿', 31389.0, 19.0), ('600011', '电力行业', '141亿', 37729.0, 29.0), ('600012', '高速公路', '16.6亿', 2106.0, 14.0)] now what i want to do is : 1.keep return(self.res) in grow method. 2.it is my target that when run the code: import analyse x=analyse.status() x.grow() there is nothing output in my console , to make return(self.res) not to output the content of list , how can i do ? -- https://mail.python.org/mailman/listinfo/python-list
Re: Flask and Python 3
On Wed, Sep 24, 2014 at 3:23 AM, Juan Christian juan0christ...@gmail.com wrote: I didn't learn debug with Flask yet. Only in the next videos. Learning from videos is the worst thing you can do. Use the official flask documentation at http://flask.pocoo.org/docs/0.10/quickstart/ — it’s much friendlier than a video. Also, there is nothing to “learn” — just change the line, and you will have more helpful errors. -- Chris “Kwpolska” Warrick http://chriswarrick.com/ PGP: 5EAAEA16 stop html mail | always bottom-post | only UTF-8 makes sense -- https://mail.python.org/mailman/listinfo/python-list
Re: GCD in Fractions
On Wed, Sep 24, 2014 at 5:44 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: The Collins Dictionary of Mathematics (second edition, 2002) says: highest common factor, greatest common factor, or greatest common divisor (abbrev hcf, gcf, gcd) n, an integer d that exactly divides (sense 2) two given integers a and b, and is such that if c divides a and b, then c divides d; this definition extends to finite sets of integers and to integral domains. For example, the highest common factor of 12, 60 and 84 is 12. Yet again, we have no clear definition for negative values. Well, this definition would imply that gcd(a, b) should always return *two* results, one positive and one negative. I don't think anybody wants that. It would make more sense to standardize on one of them, and if we take sqrt as an example, then the result should be positive. Here's an example using Euclid's algorithm to calculate the GCD of negative numbers, and sure enough, you get a negative result: https://answers.yahoo.com/question/index?qid=20111021023909AA8bCjB This depends entirely on your implementation of the modulo operation, which is an issue of computing since the operator is not used in mathematics. The algorithm itself only specifies at each step to solve the equation R_{n-2} = Q * R_{n-1} + R_{n}, such that |R_{n}| |R_{n-1}|. For any given input there can be many possible solutions, both positive and negative, regardless of the signs of the inputs, and it doesn't matter which solution you choose. So one could implement Euclid's algorithm to return either a positive or negative result for any arbitrary pair of integers. -- https://mail.python.org/mailman/listinfo/python-list
Re: Receiving large files with @tornado.web.stream_request_body
@tornado.web.stream_request_body class PostFilesHandler(tornado.web.RequestHandler): def post(self): for postfile in self.request.files: print(File info:,postfile) # There is no postfile[body] here!!! def prepare(self): self.temp_file = tempfile.NamedTemporaryFile(delete=False) def data_received(self, chunk): self.temp_file.write(chunk) # This is great but which file is this??? I have found out that the raw post data is stored there. Extracting file contents from that raw file is possible. However, the provisional email.contentmanager class does not provide methods for extracting streams from a mime message. Which is bad, because nobody wants to load a huge mime message into memory (for example, a DVD iso file...) -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. -- https://mail.python.org/mailman/listinfo/python-list
ThreadPoolExecutor - callback guaranteed to run in same thread as the submitted function?
Hello, In the ThreadPoolExecutor (TPE), is the callback always guaranteed to run in the same thread as the submitted function? For example, I tested this with the following code. I ran it many times and it seemed like `func` and `callback` always ran in the same thread. import concurrent.futures import random import threading import time executor = concurrent.futures.ThreadPoolExecutor(max_workers=3) def func(x): time.sleep(random.random()) return threading.current_thread().name def callback(future): time.sleep(random.random()) x = future.result() cur_thread = threading.current_thread().name if (cur_thread != x): print(cur_thread, x) print('main thread: %s' % threading.current_thread()) for i in range(1): future = executor.submit(func, i) future.add_done_callback(callback) However, it seemed to fail when I removed the `time.sleep(random.random())` statements, i.e. at least a few `func` functions and `callbacks` **did not** run in the same thread. For a project that I am working on, the callback must always run on the same thread as the submitted function, so I wanted to be sure that this is guaranteed by TPE. (And also the results of the test without the random sleep seemed puzzling). I looked at the source code for executors (see https://hg.python.org/cpython/file/6d44906344f4/Lib/concurrent/futures/_base.py#l297) and it does not seem like we switch the thread to the main thread before we run the callback. But just wanted to be sure. Any insight would be appreciated! Thanks, Praveen -- https://mail.python.org/mailman/listinfo/python-list
RE: Python as Windows Service
De : Gmail [mailto:mrje...@gmail.com] Envoyé : Wednesday, September 24, 2014 2:41 PM À : Arulnambi Nandagoban Objet : Re: Python as Windows Service Also, this may work for you http://nssm.cc/description http://nssm.cc/usage NSSM installs an existing app as a service. /Jean On Sep 24, 2014, at 3:16 AM, Arulnambi Nandagoban a.nandago...@traxens.com wrote: De : MrJean1 [mailto:mrje...@gmail.com] Envoyé : Tuesday, September 23, 2014 5:55 PM À : a.nandago...@traxens.com Objet : Python as Windows Service Here's one, simple example http://stackoverflow.com/questions/32404/is-it-possible-to-run-a-python-script-as-a-service-in-windows-if-possible-how There are more, just search for Python Windows Service for example. /Jean Thank you !!! -- Nambi Thank you again !!! I managed to run the server as as service with help of sample code provided in http://stackoverflow.com/questions/32404/is-it-possible-to-run-a-python-script-as-a-service-in-windows-if-possible-how . I found some problem in stopping the service. I feel it because of socket.accept() which blocks. This the class where I implemented the server in the main method. class TraxServerSvc (win32serviceutil.ServiceFramework): _svc_name_ = Testserver _svc_display_name_ = Pytestserver def __init__(self,args): win32serviceutil.ServiceFramework.__init__(self,args) self.hWaitStop = win32event.CreateEvent(None,0,0,None) self.sloop = True self.serversock = 0 def SvcStop(self): self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) win32event.SetEvent(self.hWaitStop) self.sloop = False def SvcDoRun(self): servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE, servicemanager.PYS_SERVICE_STARTED, (self._svc_name_,'')) self.main() def main(self): self.serversock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.serversock.bind(server_config()) self.serversock.listen(5) while (win32event.WaitForSingleObject(self.hWaitStop, 0) == 258): try: clientsock, addr = self.serversock.accept() Pysconfig.logger.info('...connected from: %s', addr) # logging thread.start_new_thread(handler, (clientsock, addr)) Pysconfig.logger.info('Thread ID: %s', thread.get_ident()) # logging except socket.error, msg: Pysconfig.logger.info('Failed to create socket. Error code: ' + str(msg[0]) + ' , Error message : ' + msg[1]) pass self.serversock.shutdown(socket.SHUT_RDWR) self.serversock.close() servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE, servicemanager.PYS_SERVICE_STOPPED, (self._svc_name_,'')) if __name__ == '__main__': win32serviceutil.HandleCommandLine(TraxServerSvc) When win32event.WaitForSingleObject(self.hWaitStop, 0) method returns zero , I need to quit the while loop to stop the service. But in the above case, since it blocks in accept , I need to make connection from client to completely stop service. -- nambi -- https://mail.python.org/mailman/listinfo/python-list
Re: Fuzzy Counter?
On Tue, Sep 23, 2014 at 11:01 PM, Miki Tebeka miki.teb...@gmail.com wrote: On Tuesday, September 23, 2014 7:33:06 PM UTC+3, Rob Gaddi wrote: While you're at it, think long and hard about that definition of fuzziness. If you can make it closer to the concept of histogram bins you'll get much better performance. The problem for me here is that I can't determine the number of bins in advance. I'd like to get frequencies. I guess every new (don't have any previous equal item) can be a bin. Then your result depends on the order of your input, which is usually not a good thing. Why would you need to determine the *number* of bins in advance? You just need to determine where they start and stop. If for example your epsilon is 0.5, you could determine the bins to be at [-0.5, 0.5); [0.5, 1.5); [1.5, 2.5); ad infinitum. Then for each actual value you encounter, you could calculate the appropriate bin, creating it first if it doesn't already exist. -- https://mail.python.org/mailman/listinfo/python-list
Re: how to make return(self.res) not to output the content of list ?
On Wed, Sep 24, 2014 at 7:55 AM, luofeiyu elearn2...@gmail.com wrote: now what i want to do is : 1.keep return(self.res) in grow method. 2.it is my target that when run the code: import analyse x=analyse.status() x.grow() there is nothing output in my console , to make return(self.res) not to output the content of list , how can i do ? You could write a separate method that just calls self.grow() and does not return the result, and call that method instead from the interactive interpreter. -- https://mail.python.org/mailman/listinfo/python-list
Re: GCD in Fractions
blindanagram schrieb am 24.09.2014 um 15:25: On 24/09/2014 12:44, Steven D'Aprano wrote: blindanagram wrote: [snip] - Mathworld says that GCD of two negative numbers is a negative number; - but Mathematica says that GCD of two negative numbers is a positive; - Wikipedia agrees with Mathematica and disagrees with Mathworld; After looking at these (and several other) on-line mathematical sites, I realised that I would have to go back to long standing mathemmatical references to find how the gcd is defined by those that explicitly cover the greatest common divisor for negative integers (I did this before raising the issue here). All four that I have so far looked at have definitions that lead to gcd(a, b) for integers being equal to gcd(|a|, |b|). I hope to visit a University library shortly to review more. Does anyone know of such a reference that uses a definition that conflicts with gcd(a, b) for integers being equal to gcd(|a|, |b|)? Steven has already given sources that suggest that the result of gcd() should be positive. Just like he gave sources that suggest the opposite. So, the question is not how or where to find even more sources, or to decide which of those sources is more right than the others, the question is whether such a shaky ground is a reasonable foundation for breaking other people's code. We have an open tracker ticket now on changing *something* about the current situation. Let's just add some new functionality somewhere if people really want it (as in need it for their code, not just want it for purity reasons or sleep better when they know it's out there), but please, everyone, stop complaining about fractions.gcd not catering for your needs. It does what it's there for, even if the name is more public or more generic than you might want. There are other ways to fix the actual problem and move on. Stefan -- https://mail.python.org/mailman/listinfo/python-list
Re: how to make return(self.res) not to output the content of list ?
luofeiyu wrote: There is a file named analyse.py in the D:\Python34\Lib\site-packages. import sqlite3,os,jinja2 db = r'F:\workspace\china\data\china.sqlite' con = sqlite3.connect(db) cur = con.cursor() class status(): def grow(self): self.res=cur.execute('select 代码,所属行业,注册资本,雇员人数,管 理人员人数 from profile limit 10').fetchall() def display(self): template = jinja2.Template(''' table border=1 {% for row in res %} tr {% for col in row -%} td{{ col}}/td {% endfor %} /tr {% endfor %} /table ''') with open('f:\\test.html', 'w') as f: f.write(template.render(res=self.res)) import webbrowser webbrowser.open('f:\\test.html') when i open python3.4 console to input the code: import analyse x=analyse.status() x.grow() x.display() i get when i add return(self.res) in grow method to make analyse.py into the following: import sqlite3,os,jinja2 db = r'F:\workspace\china\data\china.sqlite' con = sqlite3.connect(db) cur = con.cursor() class status(): def grow(self): self.res=cur.execute('select 代码,所属行业,注册资本,雇员人数,管 理人员人数 from profile limit 10').fetchall() return(self.res) def display(self): template = jinja2.Template(''' table border=1 {% for row in res %} tr {% for col in row -%} td{{ col}}/td {% endfor %} /tr {% endfor %} /table ''') with open('f:\\test.html', 'w') as f: f.write(template.render(res=self.res)) import webbrowser webbrowser.open('f:\\test.html') now again input the code: import analyse x=analyse.status() x.grow() the x.grow() will output [('60', '银行', '187亿', 39340.0, 30.0), ('64', '民航机场', '11.5亿', 4499.0, 23.0), ('65', '钢铁行业', '101亿', 38857.0, 24.0), ('66', '汽车行业', '20.0亿', 10290.0, 20.0), ('67', '房地产', '10.1亿', 2332.0, 19.0), ('68', '公用事业', '22.0亿', 6515.0, 20.0), ('69', '民航机场', '19.3亿', 5472.0, 18.0), ('600010', '钢铁行业', '80.0亿', 31389.0, 19.0), ('600011', '电力行业', '141亿', 37729.0, 29.0), ('600012', '高速公路', '16.6亿', 2106.0, 14.0)] now what i want to do is : 1.keep return(self.res) in grow method. 2.it is my target that when run the code: import analyse x=analyse.status() x.grow() there is nothing output in my console , to make return(self.res) not to output the content of list , how can i do ? You can set the display hook: [1, 2, 3] [1, 2, 3] import sys sys.displayhook = lambda obj: None [1, 2, 3] -- https://mail.python.org/mailman/listinfo/python-list
Re: GCD in Fractions
On 24/09/2014 12:14, Mark Dickinson wrote: Mark Lawrence breamoreboy at yahoo.co.uk writes: Somebody got there first http://bugs.python.org/issue22477 I think there's good reason to suspect that Brian Gladman and blindanagram are one and the same. :-) sorted(BrianGladman.lower()) == sorted(blindanagram) True Is that considered proof that I still reign supreme as the most unobservant person on the planet? :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: why can't open the file with browser?
On 24/09/2014 13:22, Chris Angelico wrote: On Wed, Sep 24, 2014 at 7:32 PM, luofeiyu elearn2...@gmail.com wrote: import webbrowser webbrowser.open('f:\\test.html') why the file f:\\test.html is opened by notepad ,not by my firefox or chrome? It looks to me as if your default association is set to Notepad rather than a web browser. Try opening one of the browsers' settings pages and making it your default browser. In Chrome, that's chrome://settings/ and it's near the bottom; in Firefox, go to Tools|Options, Advanced, and it's on the General tab. (They might check on startup and offer to make themselves default, which would save you some trouble.) ChrisA From https://docs.python.org/3/library/webbrowser.html#module-webbrowser Note that on some platforms, trying to open a filename using this function, may work and start the operating system’s associated program. However, this is neither supported nor portable. So it looks like a case of changing the file association through control panel or similar. I'll leave the OP to find out how to do that as an exercise. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: GCD in Fractions
On Wed, Sep 24, 2014, at 10:26, Ian Kelly wrote: This depends entirely on your implementation of the modulo operation, which is an issue of computing since the operator is not used in mathematics. Wikipedia suggests that remainders from Euclidean division should be used. In Euclidean division, the remainder is always positive. (whereas either C or Python allows the modulo to be negative, in different situations: in python [round quotient down] the modulo has the same sign as b, whereas in C [round quotient to zero] the modulo has the same sign as a). def mod(a, b): r = a % b return r + abs(b) if r 0 else r def gcd(a, b): if b == 0: return a else: return gcd(b, mod(a, b)) This appears to give a negative result when: a 0 and b == 0, obviously. A is returned as the gcd. a == 0 and b 0. B is returned as the gcd |a| is exactly divisible by |b| and b 0. B is returned as the gcd. However, it still lacks the symmetry of gcd(a, b) == gcd(b, a) in some cases. For example, gcd(-2, 6) is 2, whereas gcd(6, -2) is -2. -- https://mail.python.org/mailman/listinfo/python-list
String representations of numbers and approximate equality
Yes, it's another how can I see if two numbers are approximately equal thread, but this time I have a concrete definition of approximately equal... and they're Decimals, not floats. I have a number of files (this is an ongoing thing) in which there are two columns of numbers. One of them should be equal to the other times some factor which the program knows from elsewhere. All the numbers are represented as strings of ASCII decimal digits, possibly including a U+002E decimal point. Something like this: # (these are calculated on factor 30) [0.75, 22.5] [0.80, 24] [4.73, 142] The definition of valid is that, within the rounding they've been given, the values are correct. The first two are strictly correct; the third would be 141.9 with full accuracy but 142 is deemed good enough. But this should fail: [0.1, 10] 0.1 * 30 should be 3, not 10; and 10 / 30 should be 0.333, not 0.1; therefore this is wrong. This is a san-check for human-entered data, so sloppiness is necessary. I just want to have a chance to catch obvious typos and such. In theory, I think, a decimal.Decimal context should be able to do what I want here - but I'm not particularly familiar with it. Performance isn't critical, so stupid techniques that work on the actual string representation would be fine too. In general, the numbers will be fairly small. Maybe 3-4 digits before the decimal point, and probably not more than 2-3 after. Not sure if that makes things any easier or not. All advice appreciated! ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: GCD in Fractions
On 24/09/2014 17:13, Stefan Behnel wrote: blindanagram schrieb am 24.09.2014 um 15:25: On 24/09/2014 12:44, Steven D'Aprano wrote: [snip] We have an open tracker ticket now on changing *something* about the current situation. Let's just add some new functionality somewhere if people really want it (as in need it for their code, not just want it for purity reasons or sleep better when they know it's out there), but please, everyone, stop complaining about fractions.gcd not catering for your needs. It does what it's there for, even if the name is more public or more generic than you might want. There are other ways to fix the actual problem and move on. This has never been about my need to use fractions.gcd since I don't even use it (I have my own implementation). -- https://mail.python.org/mailman/listinfo/python-list
Re: GCD in Fractions
On 24/09/2014 17:34, Mark Lawrence wrote: On 24/09/2014 12:14, Mark Dickinson wrote: Mark Lawrence breamoreboy at yahoo.co.uk writes: Somebody got there first http://bugs.python.org/issue22477 I think there's good reason to suspect that Brian Gladman and blindanagram are one and the same. :-) sorted(BrianGladman.lower()) == sorted(blindanagram) True Is that considered proof that I still reign supreme as the most unobservant person on the planet? :) I am afraid not - you are far from alone :-) I have used this alias for quite a few years now on sci.crypt without people realising who 'owns' it (there are reasons why people on sci.crypt might discover this). -- https://mail.python.org/mailman/listinfo/python-list
Re: GCD in Fractions
On 9/24/2014 7:44 AM, Steven D'Aprano wrote: blindanagram wrote: Seccondly (as others here have pointed out), the mathematical properties of the greatest common divisor are well defined for both positive and negative integers. You keep saying that, but it simply is not true. Different people use different definitions. Some refuse to allow negative arguments at all. Some insist that the GCD must be positive. Others allow it to be negative. [convincing evidence of the above snipped] The negative of the greatest common divisor is the least common divisor (when the range includes negative integers). If a 'gcd' is allowed to be negative, one must re-interpret 'gcd' as abbreviating 'greatest-magnitude common divisor'. It then might be better called 'gmcd'. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: GCD in Fractions
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes: blindanagram wrote: Seccondly (as others here have pointed out), the mathematical properties of the greatest common divisor are well defined for both positive and negative integers. You keep saying that, but it simply is not true. Different people use different definitions. Some refuse to allow negative arguments at all. Some insist that the GCD must be positive. Others allow it to be negative. I can't find a good source for allowing it to be negative, though. Clearly, the primary use of the function is on the positive integers, with the negatives being an extension. Mathworld does show one thing that suggests an interpretation for the GCD of negative values: The GCD is distributive GCD(ma,mb)=mGCD(a,b) which tells us that: GCD(-x, -y) = -GCD(x, y) And yet, Mathematica has: GCD(-x, -y) = GCD(x, y) the very opposite of what Mathworld says, despite coming from the same people. This is most likely simply them dropping the constraint that m must be non-negative. Wikipedia, for example, specifies it under Properties. The Collins Dictionary of Mathematics (second edition, 2002) says: highest common factor, greatest common factor, or greatest common divisor (abbrev hcf, gcf, gcd) n, an integer d that exactly divides (sense 2) two given integers a and b, and is such that if c divides a and b, then c divides d; this definition extends to finite sets of integers and to integral domains. For example, the highest common factor of 12, 60 and 84 is 12. Yet again, we have no clear definition for negative values. As pointed out, this definition always yields two values (positive and negative), even for positive a and b, so there's nothing special for negative a or b. Typically, I've seen this augmented with choose the positive one to get a single value. Here's an example using Euclid's algorithm to calculate the GCD of negative numbers, and sure enough, you get a negative result: The algorithm is pretty irrelevant here. gcd's not defined by a particular algorithm to calculate it. From everything that I've seen, mathematicians consider the gcd to be always positive. Now, that's not saying that fraction should implement the mathematical gcd, if it doesn't need it. That should be its own argument, though; it doesn't help to add false doubt about what the gcd of negative numbers should be. Cheers, Johann -- https://mail.python.org/mailman/listinfo/python-list
Syntax error in python unittest script
Hi, I am learning to use unittest with python and walkthrough with this example http://agiletesting.blogspot.com/2005/01/python-unit-testing-part-1-unittest.html so my test script is like this: import json import urllib #import time #from util import * import httplib #import sys #from scapy.all import * import unittest import os, sys, socket, struct, select, time from threading import Thread import logging import traceback class testFirewall( unittest.TestCase ): def setUp(self): set up data used in the tests. setUp is called before each test function execution. self.controllerIp=127.0.0.1 self.switches = [00:00:00:00:00:00:00:01] self.startTime_ = time.time() self.failed = False self.reportStatus_ = True self.name_ = Firewall self.log = logging.getLogger(unittest) def tearDown(self): if self.failed: return duration = time.time() - self.startTime_ self.cleanup(True) if self.reportStatus_: self.log.info(=== Test %s completed normally (%d sec), self.name_, duration def cleanup(self, success): sys.excepthook = sys.__excepthook__ try: return except NameError: self.log.error(Exception hit during cleanup, bypassing:\n%s\n\n % traceback.format_exc()) pass else: fail(Expected a NameError) def testStatusFirewall(self): command = http://%s:8080/wm/firewall/module/status/json; % self.controllerIp x = urllib.urlopen(command).read() parsedResult = json.loads(x) return parsedResult['result'] def suite(): suite = unittest.TestSuite() suite.addTest(unittest.makeSuite(testFirewall)) return suite if __name__ == '__main__': logging.basicConfig(filename='/tmp/testfirewall.log', level=logging.DEBUG, format='%(asctime)s %(levelname)s %(name)s %(message)s') logger=logging.getLogger(__name__) suiteFew = unittest.TestSuite() suiteFew.addTest(testFirewall(testStatusFirewall)) unittest.TextTestRunner(verbosity=2).run(suiteFew) #unittest.main() #unittest.TextTestRunner(verbosity=2).run(suite()) while running it in console using python FileName.py It gives me errror File TestTest.py, line 44 def cleanup(self, success): ^ SyntaxError: invalid syntax I guess it is due to time module but as you can see I already had import time. what can be the reason if I comment those line containing the time it works. But i need to keep track of duration Please help and suggest. Thanks, Milson -- https://mail.python.org/mailman/listinfo/python-list
Re: Flask and Python 3
On Wednesday, September 24, 2014, Chris “Kwpolska” Warrick kwpol...@gmail.com wrote: Learning from videos is the worst thing you can do. Use the official flask documentation at http://flask.pocoo.org/docs/0.10/quickstart/ — it’s much friendlier than a video. Also, there is nothing to “learn” — just change the line, and you will have more helpful errors. That's the way I always learned everything. I watch some video courses, read a book and read the official documentation altogether. My way can't work for you, but for me it's excellent. And you don't even know which video/course I'm talking about, so it's gross to tell that videos are the worst thing... Anyway, the problem was solved, I already learned lots of new things and I'm practicing them. -- https://mail.python.org/mailman/listinfo/python-list
Re: Syntax error in python unittest script
On 9/24/2014 12:33 PM, Milson Munakami wrote: def tearDown(self): if self.failed: return duration = time.time() - self.startTime_ self.cleanup(True) if self.reportStatus_: self.log.info(=== Test %s completed normally (%d sec), self.name_, duration The method above doesn't end cleanly (you need to add a close paren to the last line at least) Emile def cleanup(self, success): -- https://mail.python.org/mailman/listinfo/python-list
Re: Syntax error in python unittest script
Milson Munakami wrote: if self.reportStatus_: self.log.info(=== Test %s completed normally (%d sec), self.name_, duration The info() call is missing the closing parenthesis def cleanup(self, success): sys.excepthook = sys.__excepthook__ It gives me errror File TestTest.py, line 44 def cleanup(self, success): ^ SyntaxError: invalid syntax To find a syntax error it is often a good idea to look into the code that precedes the line that the compiler complains about. -- https://mail.python.org/mailman/listinfo/python-list
Re:String representations of numbers and approximate equality
Chris Angelico ros...@gmail.com Wrote in message: Yes, it's another how can I see if two numbers are approximately equal thread, but this time I have a concrete definition of approximately equal... and they're Decimals, not floats. I have a number of files (this is an ongoing thing) in which there are two columns of numbers. One of them should be equal to the other times some factor which the program knows from elsewhere. All the numbers are represented as strings of ASCII decimal digits, possibly including a U+002E decimal point. Something like this: # (these are calculated on factor 30) [0.75, 22.5] [0.80, 24] [4.73, 142] The definition of valid is that, within the rounding they've been given, the values are correct. The first two are strictly correct; the third would be 141.9 with full accuracy but 142 is deemed good enough. But this should fail: Your definition is not nearly as concrete as you think. Is the first number considered to be exact, and we'll only check the second? Will the factor always be an int, and thus exact? When the desired second number is exactly halfway between two values, is rounding down as acceptable as up? (Eg, exact answer 142.75, acceptable 142.7 and 142.8) Once you're sure of the goal, it's a question of whether the decimal package can handle it. I would be inclined to do it in two stages. Drop all the periods and convert each to int (long). Multiply and Add 5**n, where n is related to the length of the target. Convert to string, padded with lots of zeroes. See if the exact string begins with the target. If not, they're not close enough. If the first part passes, you just have to check the position of the decimal point. Or you could check the implementation of round. If you pick the right value for round, you could do an exact comparison. Alternatively, if you're just looking to catch typos, it could be simpler. Or if you put constraints on the numbers involved. -- DaveA -- https://mail.python.org/mailman/listinfo/python-list
Re: Syntax error in python unittest script
On Wednesday, September 24, 2014 1:33:35 PM UTC-6, Milson Munakami wrote: Hi, I am learning to use unittest with python and walkthrough with this example http://agiletesting.blogspot.com/2005/01/python-unit-testing-part-1-unittest.html Thanks so my test script is like this: import json import urllib #import time #from util import * import httplib #import sys #from scapy.all import * import unittest import os, sys, socket, struct, select, time from threading import Thread import logging import traceback class testFirewall( unittest.TestCase ): def setUp(self): set up data used in the tests. setUp is called before each test function execution. self.controllerIp=127.0.0.1 self.switches = [00:00:00:00:00:00:00:01] self.startTime_ = time.time() self.failed = False self.reportStatus_ = True self.name_ = Firewall self.log = logging.getLogger(unittest) def tearDown(self): if self.failed: return duration = time.time() - self.startTime_ self.cleanup(True) if self.reportStatus_: self.log.info(=== Test %s completed normally (%d sec), self.name_, duration def cleanup(self, success): sys.excepthook = sys.__excepthook__ try: return except NameError: self.log.error(Exception hit during cleanup, bypassing:\n%s\n\n % traceback.format_exc()) pass else: fail(Expected a NameError) def testStatusFirewall(self): command = http://%s:8080/wm/firewall/module/status/json; % self.controllerIp x = urllib.urlopen(command).read() parsedResult = json.loads(x) return parsedResult['result'] def suite(): suite = unittest.TestSuite() suite.addTest(unittest.makeSuite(testFirewall)) return suite if __name__ == '__main__': logging.basicConfig(filename='/tmp/testfirewall.log', level=logging.DEBUG, format='%(asctime)s %(levelname)s %(name)s %(message)s') logger=logging.getLogger(__name__) suiteFew = unittest.TestSuite() suiteFew.addTest(testFirewall(testStatusFirewall)) unittest.TextTestRunner(verbosity=2).run(suiteFew) #unittest.main() #unittest.TextTestRunner(verbosity=2).run(suite()) while running it in console using python FileName.py It gives me errror File TestTest.py, line 44 def cleanup(self, success): ^ SyntaxError: invalid syntax I guess it is due to time module but as you can see I already had import time. what can be the reason if I comment those line containing the time it works. But i need to keep track of duration Please help and suggest. Thanks, Milson -- https://mail.python.org/mailman/listinfo/python-list
Re: Syntax error in python unittest script
On 24/09/2014 21:06, Milson Munakami wrote: [snipped all the usual garbage] Would you please access this list via https://mail.python.org/mailman/listinfo/python-list or read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing double line spacing and single line paragraphs, thanks. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Receiving large files with @tornado.web.stream_request_body
2014.09.24. 16:31 keltezéssel, Nagy László Zsolt írta: @tornado.web.stream_request_body class PostFilesHandler(tornado.web.RequestHandler): def post(self): for postfile in self.request.files: print(File info:,postfile) # There is no postfile[body] here!!! def prepare(self): self.temp_file = tempfile.NamedTemporaryFile(delete=False) def data_received(self, chunk): self.temp_file.write(chunk) # This is great but which file is this??? I have found out that the raw post data is stored there. Extracting file contents from that raw file is possible. However, the provisional email.contentmanager class does not provide methods for extracting streams from a mime message. Which is bad, because nobody wants to load a huge mime message into memory (for example, a DVD iso file...) I wrote my own solution in the meantime, that can parse any large POST request into temporary files without using too much memory. If anyone is interested I can post it here. -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. -- https://mail.python.org/mailman/listinfo/python-list
Re: Syntax error in python unittest script
On 9/24/2014 3:33 PM, Milson Munakami wrote: I am learning to use unittest with python [way too long example] File TestTest.py, line 44 def cleanup(self, success): ^ SyntaxError: invalid syntax A common recommendation is to find the *minimal* example that exhibits the problem. (Start with commenting out everything after the code in the traceback, then at least half the code before it. Etc.) That means that removing or commenting out a single statememt and the problem disappears. In compound statements, you may need to insert 'pass' to not create a new problem. If you had done that, you would have reduced your code to something like class testFirewall( unittest.TestCase ): def tearDown(self): if self.reportStatus_: self.log.info(=== Test %s completed normally (%d sec), self.name_, duration def cleanup(self, success): sys.excepthook = sys.__excepthook__ At that point, replacing self.log.info(... with pass would have made it clear that the problem was with the replaced statement. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: GCD in Fractions
On 09/24/14 09:25, blindanagram wrote: On 24/09/2014 12:44, Steven D'Aprano wrote: blindanagram wrote: [snip] - Mathworld says that GCD of two negative numbers is a negative number; - but Mathematica says that GCD of two negative numbers is a positive; - Wikipedia agrees with Mathematica and disagrees with Mathworld; After looking at these (and several other) on-line mathematical sites, I realised that I would have to go back to long standing mathemmatical references to find how the gcd is defined by those that explicitly cover the greatest common divisor for negative integers (I did this before raising the issue here). All four that I have so far looked at have definitions that lead to gcd(a, b) for integers being equal to gcd(|a|, |b|). I hope to visit a University library shortly to review more. Does anyone know of such a reference that uses a definition that conflicts with gcd(a, b) for integers being equal to gcd(|a|, |b|)? I doubt you'll find an advanced mathematical text that has such a definition. I think most abstract algebra texts would give a definition equivalent to saying that for any integers n and m the ideal generated by n and m is equal to the principal ideal generated by gcd(n,m); that is the heart of the matter mathematically, and this definition generalizes to other so-called principal ideal domains than the integers. (Don't want to Google for ideal and principal ideal? OK: an ideal is a subset of the integers closed under addition of any two of its elements, and under multiplication of any of its elements by any integer; a set of integers generates an ideal if that ideal is the intersection of all ideals containing that set, and a principal ideal is an ideal generated by a singleton set. For more elaboration, though, I'm going to point you at the internet, or better, some of those advanced texts in the library.) After working through what the definitions of ideals and principal ideals imply for the the definition above of gcd, you get the statement that k is the (or, better, a) gcd of n and m if and only if k divides n and m, and any other integer that divides both n and m divides k. The upshot is that, mathematically, gcd is only defined up to a change of sign, which helps explain why references may disagree with each other. Some authors may impose the restriction than gcd(n,m) = 0 for all n and m (which does have the advantage that then greatest really means greatest and not just greatest absolute value), but that isn't really a necessary part of the definition as far as the mathematically important properties of gcd are concerned. All that the abstract algebra requires is that |gcd(n,m)| = |gcd(|n|,|m|)|. So implementations of gcd that sometimes return a negative value are not, it seems to me, mathematically broken, though they might violate the principle of least surprise. for-whatever-it's-worth'ly-yrs, R. Beaudoin -- https://mail.python.org/mailman/listinfo/python-list
Re: String representations of numbers and approximate equality
On Wed, Sep 24, 2014 at 9:54 AM, Chris Angelico ros...@gmail.com wrote: Yes, it's another how can I see if two numbers are approximately equal thread, but this time I have a concrete definition of approximately equal... and they're Decimals, not floats. I have a number of files (this is an ongoing thing) in which there are two columns of numbers. One of them should be equal to the other times some factor which the program knows from elsewhere. All the numbers are represented as strings of ASCII decimal digits, possibly including a U+002E decimal point. Something like this: # (these are calculated on factor 30) [0.75, 22.5] [0.80, 24] [4.73, 142] The definition of valid is that, within the rounding they've been given, the values are correct. The first two are strictly correct; the third would be 141.9 with full accuracy but 142 is deemed good enough. But this should fail: [0.1, 10] 0.1 * 30 should be 3, not 10; and 10 / 30 should be 0.333, not 0.1; therefore this is wrong. tolerance = decimal.Decimal('0.1') # I hesitate to call it epsilon if abs(decimal1 - decimal2) = tolerance: print('They are close') else: print('They are different') -- https://mail.python.org/mailman/listinfo/python-list
cannot run a ruby script from a python script.
hello all. i have a linux computer that i use to run a GUI (wxGTK) program. In this program, there is a call to run an external ruby script. command = ruby run_my_command.rb os.system(command) however, when it runs, i get this in the terminal sh: 1: ruby: not found i had considered that the path to the executable was messed up or somesuch, but when i just run python in the interpreter, it works fine. also, i have another computer with identical hardware, same OS, same package versions that it does work on also. This machine is to be a backup. Another note: When i run which ruby i get the path to the ruby executable. If i use that in my code, it will run, however, it will not be able to find any of the modules that i need for the ruby script to import. example command = /path/to/ruby run_my_command.rb os.system(command) will run the ruby script, but the ruby script will not be able to import any of it's modules. thanks for any tips on this. -- https://mail.python.org/mailman/listinfo/python-list
Re: how to make return(self.res) not to output the content of list ?
`sys.displayhook = lambda obj: None ` will block everything to be displayed on the interactive python console . i rewrite my code as the following : import sqlite3,os,jinja2 db = r'data.sqlite' con = sqlite3.connect(db) cur = con.cursor() class status(): def __init__(): import sys sys.displayhook=mydisplay def mydisplay(x): if (x is not the result of an method grow of class status ) : x #how to do in python code? else : pass def grow(self): self.res= a data ananlyse process return(self.res) def display(self): #to display it in the html table how to fulfill the mydisplay function in python code to make x.grow() in the following not to output the list of self.res?? import analyse x=analyse.status() x.grow() -- https://mail.python.org/mailman/listinfo/python-list
Re: how to make return(self.res) not to output the content of list ?
You could write a separate method that just calls self.grow() and does not return the result, and call that method instead from the interactive interpreter. how can i change your meaning into python code? There is my code structure. class status(): def grow(self): self.res= a data ananlyse process return(self.res) def display(self): #to display it in the html table -- https://mail.python.org/mailman/listinfo/python-list
Re: cannot run a ruby script from a python script.
On 24Sep2014 16:57, Shawn Bright sh...@skrite.net wrote: i have a linux computer that i use to run a GUI (wxGTK) program. In this program, there is a call to run an external ruby script. command = ruby run_my_command.rb os.system(command) however, when it runs, i get this in the terminal sh: 1: ruby: not found i had considered that the path to the executable was messed up or somesuch, but when i just run python in the interpreter, it works fine. also, i have another computer with identical hardware, same OS, same package versions that it does work on also. This machine is to be a backup. Another note: When i run which ruby i get the path to the ruby executable. If i use that in my code, it will run, however, it will not be able to find any of the modules that i need for the ruby script to import. For your edification: modify your command to be this: command = which ruby; echo $PATH; ruby run_my_command.rb and see if the output says what you expect. From the behaviour you describe I would expect that the GUI program, when it fails, is not being invoked from your command line but from some menu or suchlike. Further, I would guess that the invoking program (window manager, whatever) does not have ruby in its $PATH. This same effect obtains when you use the full path to ruby (usually a bad idea because your script may not work on another system where ruby is somewhere different) because like $PATH, the ruby search path also lacks the directories where the modules reside. When you run it from your command prompt or from the python interpreter your environment is already set up with this extra information. Cheers, Cameron Simpson c...@zip.com.au C makes it easy for you to shoot yourself in the foot. C++ makes that harder, but when you do, it blows away your whole leg. - Bjarne Stroustrup -- https://mail.python.org/mailman/listinfo/python-list
Re: how to make return(self.res) not to output the content of list ?
On 25Sep2014 08:15, luofeiyu elearn2...@gmail.com wrote: You could write a separate method that just calls self.grow() and does not return the result, and call that method instead from the interactive interpreter. luofeiyu: please take care to include the attribution line. The text above is from Ian Kelly, but you do not show that. Attribution is important: it both gives credit and also lets people know who said what. On 25Sep2014 08:15, luofeiyu elearn2...@gmail.com wrote: how can i change your meaning into python code? Well, I'd not do it that way. I would just make .grow() not return self.res. Basicly, if a function returns None (which it does when it does not have an explicit return command), the python interpreter prints no output. So I would just write .grow() like this: def grow(self): self.res= a data ananlyse process Let the caller access self.res directly afterwards if they want to. For Ian's suggestion, write a trivial method like this: def grow_but_be_silent(self): self.grow() Cumbersome, but it would do what you seem to ask for. Cheers, Cameron Simpson c...@zip.com.au Drive Agressively Rash Magnificently - Nankai Leathers -- https://mail.python.org/mailman/listinfo/python-list
Re: String representations of numbers and approximate equality
On Thu, Sep 25, 2014 at 5:56 AM, Dave Angel da...@davea.name wrote: Your definition is not nearly as concrete as you think. Is the first number considered to be exact, and we'll only check the second? Will the factor always be an int, and thus exact? Apologies: the definition is concrete, just under-specified in the post. No, both numbers are inexact; most notably, one third of the factor might be involved - both of these should be correct: [1.333, 40] [1.33, 40] But if it's easier to assume that one or t'other must be exact, that's fine too - I can just run the check twice, once each way. When the desired second number is exactly halfway between two values, is rounding down as acceptable as up? (Eg, exact answer 142.75, acceptable 142.7 and 142.8) Yes, either would be accepted. Once you're sure of the goal, it's a question of whether the decimal package can handle it. I would be inclined to do it in two stages. Drop all the periods and convert each to int (long). Multiply and Add 5**n, where n is related to the length of the target. Convert to string, padded with lots of zeroes. See if the exact string begins with the target. If not, they're not close enough. If the first part passes, you just have to check the position of the decimal point. Or you could check the implementation of round. If you pick the right value for round, you could do an exact comparison. Alternatively, if you're just looking to catch typos, it could be simpler. Or if you put constraints on the numbers involved. It is just to catch typos. I don't mind if it misses some cases, not a big deal. Thanks for the suggestion. I'll see how that looks in code. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Flask and Python 3
On Thu, Sep 25, 2014 at 5:39 AM, Juan Christian juan0christ...@gmail.com wrote: That's the way I always learned everything. I watch some video courses, read a book and read the official documentation altogether. My way can't work for you, but for me it's excellent. And you don't even know which video/course I'm talking about, so it's gross to tell that videos are the worst thing... It doesn't matter which video/course you were talking about. Chris was talking about the *format* of videos. And I agree with him. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Which module I'm missing?
Hi, ALL, I got a suggestion to install eric for my developmental needs. Unfortunately, it looks like my Linux distribution have a bug as running eric throws an exception. [code] igor@IgorDellGentoo ~/plaso-build/liblnk-20140905 $ eric5 An unhandled exception occurred. Please report the problem using the error reporting dialog or via email to eric5-b...@eric-ide.python-projects.org. A log has been written to /home/igor/.eric5/eric5_error.log. Error information: 2014-09-21, 07:56:26 class 'ImportError': No module named 'DebugClients.Python3.coverage' File /usr/lib64/python3.3/site-packages/eric5/eric5.py, line 268, in module main() File /usr/lib64/python3.3/site-packages/eric5/eric5.py, line 245, in main from UI.UserInterface import UserInterface File /usr/lib64/python3.3/site-packages/eric5/UI/UserInterface.py, line 34, in module from QScintilla.MiniEditor import MiniEditor File /usr/lib64/python3.3/site-packages/eric5/QScintilla/MiniEditor.py, line 26, in module from .SearchReplaceWidget import SearchReplaceWidget File /usr/lib64/python3.3/site-packages/eric5/QScintilla/SearchReplaceWidget.py, line 16, in module from .Editor import Editor File /usr/lib64/python3.3/site-packages/eric5/QScintilla/Editor.py, line 35, in module from DataViews.PyCoverageDialog import PyCoverageDialog File /usr/lib64/python3.3/site-packages/eric5/DataViews/PyCoverageDialog.py, line 22, in module from DebugClients.Python3.coverage.misc import CoverageException Version Numbers: Python 3.3.3 Qt 4.8.5 PyQt4 4.10.3 sip 4.15.3 QScintilla 2.7.2 WebKit 534.34 eric5 5.3.6 (rev 1d360120e928) Platform: linux 3.3.3 (default, May 29 2014, 03:55:37) [GCC 4.7.3] Distribution Info: /etc/os-release NAME=Gentoo ID=gentoo PRETTY_NAME=Gentoo/Linux ANSI_COLOR=1;32 HOME_URL=http://www.gentoo.org/; SUPPORT_URL=http://www.gentoo.org/main/en/support.xml; BUG_REPORT_URL=https://bugs.gentoo.org/; /etc/gentoo-release Gentoo Base System release 2.2 igor@IgorDellGentoo ~/plaso-build/liblnk-20140905 $ emerge -pv eric These are the packages that would be merged, in order: Calculating dependencies... done! [ebuild R] dev-util/eric-5.3.6:5 USE=spell LINGUAS=ru -cs -de -en -es -fr -it -tr -zh_CN 0 kB Total: 1 package (1 reinstall), Size of downloads: 0 kB igor@IgorDellGentoo ~/plaso-build/liblnk-20140905 $ eselect python list Available Python interpreters: [1] python2.7 * [2] python3.3 [/code] So my question is: which module I need to install? Thank you. -- https://mail.python.org/mailman/listinfo/python-list
Automatic Crash Reporting
Can anyone recommend a good automatic crash reporting module that would work nicely with a python3/pyqt4 application? Thanks. Tim -- https://mail.python.org/mailman/listinfo/python-list
[issue22464] Speed up fractions implementation
Stefan Behnel added the comment: BTW, the last two patches (int4 and redundant_property) are ready to be applied. Anyone? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22464 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22464] Speed up fractions implementation
Roundup Robot added the comment: New changeset 646bc7d3544b by Georg Brandl in branch 'default': #22464: Speed up common Fraction operations by special-casing several https://hg.python.org/cpython/rev/646bc7d3544b -- nosy: +python-dev ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22464 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22464] Speed up fractions implementation
Georg Brandl added the comment: Left this open in case you have additional patches coming. -- nosy: +georg.brandl ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22464 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12006] strptime should implement %V or %u directive from libc
Erik Cederstrand added the comment: I don't have the repo handy to make a patch against 3.5, but would an addition like this do? in Lib/_strptime.py: +elif iso_week != -1 and iso_year == -1: +raise ValueError('%Y' directive is ambiguous in combination with '%V'. Use '%G' instead.) +elif julian == -1 and iso_week != -1 and iso_weekday != -1: +year, julian = _calc_julian_from_V(iso_year, iso_week, iso_weekday) In Lib/test/test_strptime.py: def test_ValueError(self): +# Make sure ValueError is raised when match fails or format is bad +self.assertRaises(ValueError, _strptime._strptime, data_string=1905 52, + format=%Y %V) -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12006 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22477] GCD in Fractions
New submission from Brian Gladman: There is a discussion of this issue on comp.lang.python The function known as 'the greatest common divisor' has a number of well defined mathematical properties for both positive and negative integers (see, for example, Elementary Number Theory by Kenneth Rosen). In particular gcd(a, b) = gcd(|a|, |b|). But the Python version of this function in the fractions module doesn't conform to these properties since it returns a negative value when its second parameter is negative. This behaviour is documented but I think it is undesirable to provide a function that has the well known and widely understood name 'gcd', but one that doesn't match the behaviour normally associated with this function. I hence believe that consideration should be given to changing the behaviour of the Python greatest common divisor function to match the mathematical properties expected of this function. If necessary a local function in the fractions module could maintain the current behaviour. -- components: Library (Lib) messages: 227410 nosy: b...@gladman.plus.com priority: normal severity: normal status: open title: GCD in Fractions type: behavior versions: Python 3.4 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22477 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue5550] [urllib.request]: Comparison of HTTP headers should be insensitive to the case
karl added the comment: Ok my tests are ok. → ./python.exe -m unittest -v Lib/test/test_urllib2net.py test_close (Lib.test.test_urllib2net.CloseSocketTest) ... ok test_custom_headers (Lib.test.test_urllib2net.OtherNetworkTests) ... FAIL test_file (Lib.test.test_urllib2net.OtherNetworkTests) ... test_ftp (Lib.test.test_urllib2net.OtherNetworkTests) ... skipped Resource 'ftp://gatekeeper.research.compaq.com/pub/DEC/SRC/research-reports/00README-Legal-Rules-Regs' is not available test_headers_case_sensitivity (Lib.test.test_urllib2net.OtherNetworkTests) ... ok test_redirect_url_withfrag (Lib.test.test_urllib2net.OtherNetworkTests) ... ok test_sites_no_connection_close (Lib.test.test_urllib2net.OtherNetworkTests) ... ok test_urlwithfrag (Lib.test.test_urllib2net.OtherNetworkTests) ... ok test_ftp_basic (Lib.test.test_urllib2net.TimeoutTest) ... ok test_ftp_default_timeout (Lib.test.test_urllib2net.TimeoutTest) ... ok test_ftp_no_timeout (Lib.test.test_urllib2net.TimeoutTest) ... ok test_ftp_timeout (Lib.test.test_urllib2net.TimeoutTest) ... ok test_http_basic (Lib.test.test_urllib2net.TimeoutTest) ... ok test_http_default_timeout (Lib.test.test_urllib2net.TimeoutTest) ... ok test_http_no_timeout (Lib.test.test_urllib2net.TimeoutTest) ... ok test_http_timeout (Lib.test.test_urllib2net.TimeoutTest) ... ok I wonder if test_custom_headers fails because of my modifications. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5550 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22477] GCD in Fractions
STINNER Victor added the comment: See also issue #22464. -- nosy: +haypo ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22477 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22477] GCD in Fractions
Mark Dickinson added the comment: +1 from me. -- nosy: +mark.dickinson ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22477 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22408] Tkinter doesn't handle Unicode dead key combinations on Windows
Drekin added the comment: I installed wish and tried the demos shipped with Python. The behavior occurs during the demo basic editable text. So it's an issue of Tk itself. Actually the same behavior occurs even in the wish shell. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22408 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17835] test_io broken on PPC64 Linux
James Spurin added the comment: I encountered similar issues to those discussed in this issue whilst compiling 3.4.1 on 'Red Hat Enterprise Linux Server release 6.5 (Santiago)' In particular, the following tests were failing - [root@lonlx90800 ~]# /local/0/python-3.4.1/bin/python3 /local/0/python-3.4.1/lib/python3.4/test/test_asyncio/test_subprocess.py F...F... == FAIL: test_broken_pipe (__main__.SubprocessFastWatcherTests) -- Traceback (most recent call last): File /local/0/python-3.4.1/lib/python3.4/test/test_asyncio/test_subprocess.py, line 129, in test_broken_pipe self.loop.run_until_complete(proc.communicate(large_data)) AssertionError: BrokenPipeError not raised == FAIL: test_broken_pipe (__main__.SubprocessSafeWatcherTests) -- Traceback (most recent call last): File /local/0/python-3.4.1/lib/python3.4/test/test_asyncio/test_subprocess.py, line 129, in test_broken_pipe self.loop.run_until_complete(proc.communicate(large_data)) AssertionError: BrokenPipeError not raised In this case, the issues are being caused by the following kernel parameters that we have for our default build - # ## TIBCO network tuning # # net.core.rmem_default = 33554432 net.core.wmem_default = 33554432 net.core.rmem_max = 33554432 net.core.wmem_max = 33554432 Toggling the support.PIPE_MAX_SIZE to +32MB or temporarily removing these parameters mitigates the issue. Is there a better way of calculating support.PIPE_MAX_SIZE so it is reflective of the actual OS value? -- nosy: +spurin ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17835 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22478] tests for urllib2net are in bad shapes
New submission from karl: → ./python.exe -V Python 3.4.2rc1+ → hg tip changeset: 92532:6dcc96fa3970 tag: tip parent: 92530:ad45c2707006 parent: 92531:8eb4eec8626c user:Benjamin Peterson benja...@python.org date:Mon Sep 22 22:44:21 2014 -0400 summary: merge 3.4 (#22459) When working on issue #5550, I realized that some tests are currently failing. Here the log of running: → ./python.exe -m unittest -v Lib/test/test_urllib2net.py test_close (Lib.test.test_urllib2net.CloseSocketTest) ... ok test_custom_headers (Lib.test.test_urllib2net.OtherNetworkTests) ... FAIL test_file (Lib.test.test_urllib2net.OtherNetworkTests) ... test_ftp (Lib.test.test_urllib2net.OtherNetworkTests) ... skipped Resource 'ftp://gatekeeper.research.compaq.com/pub/DEC/SRC/research-reports/00README-Legal-Rules-Regs' is not available test_redirect_url_withfrag (Lib.test.test_urllib2net.OtherNetworkTests) ... ok test_sites_no_connection_close (Lib.test.test_urllib2net.OtherNetworkTests) ... ok test_urlwithfrag (Lib.test.test_urllib2net.OtherNetworkTests) ... ok test_ftp_basic (Lib.test.test_urllib2net.TimeoutTest) ... ok test_ftp_default_timeout (Lib.test.test_urllib2net.TimeoutTest) ... ok test_ftp_no_timeout (Lib.test.test_urllib2net.TimeoutTest) ... ok test_ftp_timeout (Lib.test.test_urllib2net.TimeoutTest) ... ok test_http_basic (Lib.test.test_urllib2net.TimeoutTest) ... ok test_http_default_timeout (Lib.test.test_urllib2net.TimeoutTest) ... ok test_http_no_timeout (Lib.test.test_urllib2net.TimeoutTest) ... ok test_http_timeout (Lib.test.test_urllib2net.TimeoutTest) ... ok == ERROR: test_file (Lib.test.test_urllib2net.OtherNetworkTests) (url='file:/Users/karl/code/cpython/%40test_61795_tmp') -- Traceback (most recent call last): File /Users/karl/code/cpython/Lib/test/test_urllib2net.py, line 243, in _test_urls f = urlopen(url, req, TIMEOUT) File /Users/karl/code/cpython/Lib/test/test_urllib2net.py, line 33, in wrapped return _retry_thrice(func, exc, *args, **kwargs) File /Users/karl/code/cpython/Lib/test/test_urllib2net.py, line 23, in _retry_thrice return func(*args, **kwargs) File /Users/karl/code/cpython/Lib/urllib/request.py, line 447, in open req = Request(fullurl, data) File /Users/karl/code/cpython/Lib/urllib/request.py, line 267, in __init__ origin_req_host = request_host(self) File /Users/karl/code/cpython/Lib/urllib/request.py, line 250, in request_host host = _cut_port_re.sub(, host, 1) TypeError: expected string or buffer == ERROR: test_file (Lib.test.test_urllib2net.OtherNetworkTests) (url=('file:///nonsensename/etc/passwd', None, class 'urllib.error.URLError')) -- Traceback (most recent call last): File /Users/karl/code/cpython/Lib/test/test_urllib2net.py, line 243, in _test_urls f = urlopen(url, req, TIMEOUT) File /Users/karl/code/cpython/Lib/test/test_urllib2net.py, line 33, in wrapped return _retry_thrice(func, exc, *args, **kwargs) File /Users/karl/code/cpython/Lib/test/test_urllib2net.py, line 23, in _retry_thrice return func(*args, **kwargs) File /Users/karl/code/cpython/Lib/urllib/request.py, line 447, in open req = Request(fullurl, data) File /Users/karl/code/cpython/Lib/urllib/request.py, line 267, in __init__ origin_req_host = request_host(self) File /Users/karl/code/cpython/Lib/urllib/request.py, line 250, in request_host host = _cut_port_re.sub(, host, 1) TypeError: expected string or buffer == FAIL: test_custom_headers (Lib.test.test_urllib2net.OtherNetworkTests) -- Traceback (most recent call last): File /Users/karl/code/cpython/Lib/test/test_urllib2net.py, line 186, in test_custom_headers self.assertEqual(request.get_header('User-agent'), 'Test-Agent') AssertionError: 'Python-urllib/3.4' != 'Test-Agent' - Python-urllib/3.4 + Test-Agent -- Ran 16 tests in 124.879s FAILED (failures=1, errors=2, skipped=1) -- components: Tests messages: 227417 nosy: karlcow priority: normal severity: normal status: open title: tests for urllib2net are in bad shapes versions: Python 3.5 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22478 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue5550] [urllib.request]: Comparison of HTTP headers should be insensitive to the case
karl added the comment: Opened issue #22478 for the tests failing. Not related to my modification. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5550 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22477] GCD in Fractions
Mark Dickinson added the comment: The current `gcd` definition is almost accidental, in that it just happens to be what's convenient for use in normalisation in the Fraction type. If people are using it as a standalone implementation of gcd, independent of the fractions module, then defining the result to be always nonnegative is probably a little less surprising than the current behaviour. BTW, I don't think there's a universally agreed definition for the extension of the gcd to negative numbers (and I certainly wouldn't take Rosen's book as authoritative: did you notice the bit where he talks about 35-bit machines being common?), so I don't regard the fraction module definition as wrong, per se. But I do agree that the behaviour you propose would be less surprising. One other thought: if we're really intending for gcd to be used independently of the fractions module, perhaps it should be exposed as math.gcd. (That would also give the opportunity for an optimised C version.) -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22477 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22478] tests for urllib2net are in bad shapes
karl added the comment: ok let's see → ./python.exe -m unittest -v Lib.test.test_urllib2net.OtherNetworkTests.test_custom_headers test_custom_headers (Lib.test.test_urllib2net.OtherNetworkTests) ... FAIL == FAIL: test_custom_headers (Lib.test.test_urllib2net.OtherNetworkTests) -- Traceback (most recent call last): File /Users/karl/code/cpython/Lib/test/test_urllib2net.py, line 186, in test_custom_headers self.assertEqual(request.get_header('User-agent'), 'Test-Agent') AssertionError: 'Python-urllib/3.4' != 'Test-Agent' - Python-urllib/3.4 + Test-Agent -- Ran 1 test in 0.551s FAILED (failures=1) → ./python.exe Python 3.4.2rc1+ (3.4:8eb4eec8626c+, Sep 23 2014, 21:53:11) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.51)] on darwin Type help, copyright, credits or license for more information. import urllib.request url = 'http://127.0.0.1/' opener = urllib.request.build_opener() request = urllib.request.Request(url) request.header_items() [] request.headers {} request.add_header('User-Agent', 'Test-Agent') request.headers {'User-agent': 'Test-Agent'} request.header_items() [('User-agent', 'Test-Agent')] opener.open(request) http.client.HTTPResponse object at 0x10c0aedc0 request.get_header('User-agent'), 'Test-Agent' ('Test-Agent', 'Test-Agent') request.header_items() [('User-agent', 'Test-Agent'), ('Host', '127.0.0.1')] request.headers {'User-agent': 'Test-Agent'} OK so far so good. And my server recorded 127.0.0.1 - - [24/Sep/2014:17:07:41 +0900] GET / HTTP/1.1 200 9897 - Test-Agent Let's do it the way, the test has been designed. → ./python.exe Python 3.4.2rc1+ (3.4:8eb4eec8626c+, Sep 23 2014, 21:53:11) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.51)] on darwin Type help, copyright, credits or license for more information. import urllib.request url = 'http://127.0.0.1/' opener = urllib.request.build_opener() request = urllib.request.Request(url) request.header_items() [] opener.open(request) http.client.HTTPResponse object at 0x10e05aa80 request.header_items() [('User-agent', 'Python-urllib/3.4'), ('Host', '127.0.0.1')] request.has_header('User-agent') True request.add_header('User-Agent', 'Test-Agent') opener.open(request) http.client.HTTPResponse object at 0x10e05ab50 request.get_header('User-agent'), 'Test-Agent' ('Python-urllib/3.4', 'Test-Agent') request.add_header('Foo', 'bar') request.header_items() [('User-agent', 'Test-Agent'), ('Host', '127.0.0.1'), ('Foo', 'bar')] opener.open(request) http.client.HTTPResponse object at 0x10e05ad58 request.header_items() [('User-agent', 'Test-Agent'), ('Host', '127.0.0.1'), ('Foo', 'bar')] request.get_header('User-agent'), 'Test-Agent' ('Python-urllib/3.4', 'Test-Agent') request.headers {'User-agent': 'Test-Agent', 'Foo': 'bar'} And the server recorded. 127.0.0.1 - - [24/Sep/2014:17:12:52 +0900] GET / HTTP/1.1 200 9897 - Python-urllib/3.4 127.0.0.1 - - [24/Sep/2014:17:12:52 +0900] GET / HTTP/1.1 200 9897 - Python-urllib/3.4 127.0.0.1 - - [24/Sep/2014:17:14:15 +0900] GET / HTTP/1.1 200 9897 - Python-urllib/3.4 So it seems that User-Agent is immutable once it has been set the first time. Not in the same dictionary. request.unredirected_hdrs {'User-agent': 'Python-urllib/3.4', 'Host': '127.0.0.1'} -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22478 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22408] Tkinter doesn't handle Unicode dead key combinations on Windows
Ned Deily added the comment: OK, then if you want to pursue the issue, I'd suggest asking on one of the Tcl/Tk forums (perhaps comp.lang.tcl) or Stackoverflow and/or checking the Tk issue tracker (https://core.tcl.tk/tk/reportlist). Good luck! -- resolution: - third party stage: - resolved status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22408 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22478] tests for urllib2net are in bad shapes
karl added the comment: Ah! the User-Agent (or anything which is in unredirected_hdrs) will not be updated if it has already been set once. https://hg.python.org/cpython/file/064f6baeb6bd/Lib/urllib/request.py#l1154 headers = dict(request.unredirected_hdrs) headers {'User-agent': 'Python-urllib/3.4', 'Host': '127.0.0.1'} request.headers {'User-agent': 'Test-Agent', 'Foo': 'cool'} headers.update(dict((k, v) for k, v in request.headers.items() if k not in headers)) headers {'User-agent': 'Python-urllib/3.4', 'Host': '127.0.0.1', 'Foo': 'cool'} -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22478 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22478] tests for urllib2net are in bad shapes
Changes by Ned Deily n...@acm.org: -- nosy: +orsenthil ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22478 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22477] GCD in Fractions
gladman added the comment: On 24/09/2014 08:58, Mark Dickinson wrote: Mark Dickinson added the comment: The current `gcd` definition is almost accidental, in that it just happens to be what's convenient for use in normalisation in the Fraction type. If people are using it as a standalone implementation of gcd, independent of the fractions module, then defining the result to be always nonnegative is probably a little less surprising than the current behaviour. BTW, I don't think there's a universally agreed definition for the extension of the gcd to negative numbers (and I certainly wouldn't take Rosen's book as authoritative: did you notice the bit where he talks about 35-bit machines being common?), so I don't regard the fraction module definition as wrong, per se. But I do agree that the behaviour you propose would be less surprising. I only quoted Rosen because I had it immediately to hand. I will willingly supply more references if you need them. Sadly even some maths books don't cover this at all but then go on to rely on the co-prime test gcd(a, b) == 1 even when a and/or b can be negative. So I would agree that it is easy to conclude that the gcd is not defined for negative numbers. But, of those maths texts that explicitly cover the behaviour of the gcd for negative numbers, I do not know of any that do not define gcd(a, b) to be gcd(|a|, |b|). One other thought: if we're really intending for gcd to be used independently of the fractions module, perhaps it should be exposed as math.gcd. (That would also give the opportunity for an optimised C version.) To me it makes more sense to put this in math as this is where I would expect to find it. But a comment on comp.lang.python was not in favour of this. -- nosy: +gladman ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22477 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22475] asyncio task get_stack documentation seems to contradict itself
Changes by Antoine Pitrou pit...@free.fr: -- nosy: +giampaolo.rodola, gvanrossum, haypo, pitrou, yselivanov ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22475 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22476] asyncio task chapter confusion about 'task', 'future', and 'schedule'
Changes by Antoine Pitrou pit...@free.fr: -- nosy: +giampaolo.rodola, gvanrossum, haypo, pitrou, yselivanov ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22476 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22474] No explanation of how a task gets destroyed in asyncio 'task' documentation
Changes by Antoine Pitrou pit...@free.fr: -- nosy: +giampaolo.rodola, gvanrossum, haypo, pitrou, yselivanov ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22474 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22473] The gloss on asyncio future with run_forever example is confusing
Changes by Antoine Pitrou pit...@free.fr: -- nosy: +giampaolo.rodola, gvanrossum, haypo, pitrou, yselivanov ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22473 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18629] future division breaks timedelta division by integer
Antoine Pitrou added the comment: It's not a duplicate. -- status: pending - open ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18629 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18993] There is an overshadowed and invalid test in testmock.py
Berker Peksag added the comment: This has been fixed in https://hg.python.org/cpython/rev/c8c11082bd0c. -- nosy: +berker.peksag resolution: - out of date stage: - resolved status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18993 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21049] Warning at interpreter exit triggers flood of “ImportWarning: sys.meta_path is empty”
Quentin Pradet added the comment: I've also been affected by this when testing integration with a third-party library (NLTK). NLTK does need to be fixed, but the ResourceWarning already say so. The new one-liner doesn't seem contrived to me. -- nosy: +Quentin.Pradet ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21049 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22477] GCD in Fractions
Mark Dickinson added the comment: I will willingly supply more references if you need them. I don't. :-) I've taught more elementary number classes and reviewed more elementary number theory texts (including Rosen's) than I care to remember, and I have plenty of my own references. I stand by my assertion that the fractions module gcd is not wrong: it returns 'a' greatest common divisor for arbitrary integer inputs. A bit more: the concept of greatest common divisor is slightly ambiguous: you can define the notion of a greatest common divisor for an arbitrary commutative ring-with-a-1 R: c is a greatest common divisor of a and b if c is a common divisor (i.e. c divides a and c divides b, where x divides y is synonymous with y is a multiple of x), and any other common divisor divides c. No ordering is necessary: greatest here is with respect to the divisibility lattice rather than with respect to any kind of total ordering. One advantage of this definition is that it makes it clear that 0 is a greatest common divisor of 0 and 0. If further R is an integral domain, then it follows immediately from the definition that any two greatest common divisors of a and b (if they exist) are associates: a is a unit times b. In the particular case where R is the usual ring of rational integers, that means that the greatest common divisor of two numbers a and b is only really defined up to +/-; that is, the sign of the result is unimportant. (An alternative viewpoint is to think of the gcd, when it exists, as a principal ideal rather than an element of the ring.) See https://proofwiki.org/wiki/Definition:Greatest_Common_Divisor/Integral_Domain for more along these lines. So you're using one definition, I'm using another. Like I said, there's no universal agreement. ;-). -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22477 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22479] strange behavior of importing random module
New submission from Bekket McClane: When I import the random module using import random in the command line, it worked fine. But if I import it in the file, the program will throw a strange error, but sometimes it just exit right away after the import statement with no error. Moreover, if I execute the python command line again and import random after that, the command line python exit right away too(with exit code 0). Only if I restarted the whole terminal program did the strange behavior gone -- components: Library (Lib) files: Screenshot from 2014-09-24 17:04:58.png messages: 227428 nosy: Bekket.McClane priority: normal severity: normal status: open title: strange behavior of importing random module type: crash versions: Python 2.7 Added file: http://bugs.python.org/file36705/Screenshot from 2014-09-24 17:04:58.png ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22479 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22478] tests for urllib2net are in bad shapes
Senthil Kumaran added the comment: I suspect that you have your interpreters confused. (For e.g, I see 3.4 run against the trunk and the error messages are leading me to believe that 2.7 version in run on 3 code). Or your local copy is not in right shape. I tested it on 3.4 and cpython default and everything was OK. [localhost 3.4]$ ./python.exe -m unittest -v Lib/test/test_urllib2net.py ... Ran 15 tests in 36.672s OK [localhost 3.4]$ hg log -r 3.4 changeset: 92551:bce1594023f9 branch: 3.4 parent: 92548:381d6362c7bc parent: 92546:ff2cb4dc36e7 user:Serhiy Storchaka storch...@gmail.com date:Tue Sep 23 23:23:41 2014 +0300 description: Merge heads [localhost cpython]$ ./python.exe -m unittest -v Lib/test/test_urllib2net.py ... Ran 15 tests in 32.779s OK [localhost cpython]$ hg log -r tip changeset: 92555:064f6baeb6bd tag: tip user:Georg Brandl ge...@python.org date:Wed Sep 24 09:08:12 2014 +0200 files: Python/importlib.h description: Update importlib.h frozen bytecode (changed due to commit c0ca9d32aed4). -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22478 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22478] tests for urllib2net are in bad shapes
Senthil Kumaran added the comment: The buildbots are not showing this error too. I suggest you reset your local copy with the pristine one from remote, do a make distclean; ./configure; make and then run the tests. -- assignee: - orsenthil resolution: - works for me stage: - resolved status: open - closed type: - behavior ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22478 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22479] strange behavior of importing random module
STINNER Victor added the comment: It's not a bug in Python. The problem is that your project contains a file called random.py which is used instead of the random from the standard library. Rename the file (and remove random.pyc). -- nosy: +haypo resolution: - not a bug status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22479 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21860] Correct FileIO docstrings
Roundup Robot added the comment: New changeset 2058d94f32dd by Berker Peksag in branch '3.4': Issue #21860: Correct docstrings of FileIO.seek() and FileIO.truncate() methods. https://hg.python.org/cpython/rev/2058d94f32dd New changeset de645efe6a9b by Berker Peksag in branch 'default': Issue #21860: Correct docstrings of FileIO.seek() and FileIO.truncate() methods. https://hg.python.org/cpython/rev/de645efe6a9b -- nosy: +python-dev ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21860 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21860] Correct FileIO docstrings
Berker Peksag added the comment: Thanks for the patch, Terry. -- assignee: haypo - berker.peksag nosy: +berker.peksag resolution: - fixed stage: commit review - resolved status: open - closed versions: +Python 3.5 -Python 3.3 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21860 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21860] Correct FileIO docstrings
Roundup Robot added the comment: New changeset be2746c565c2 by Berker Peksag in branch '2.7': Issue #21860: Correct docstrings of FileIO.seek() and FileIO.truncate() methods. https://hg.python.org/cpython/rev/be2746c565c2 -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21860 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22427] TemporaryDirectory attempts to clean up twice
Roundup Robot added the comment: New changeset 7ea2153eae87 by Serhiy Storchaka in branch '3.4': Issue #22427: TemporaryDirectory no longer attempts to clean up twice when https://hg.python.org/cpython/rev/7ea2153eae87 New changeset e9d4288c32de by Serhiy Storchaka in branch 'default': Issue #22427: TemporaryDirectory no longer attempts to clean up twice when https://hg.python.org/cpython/rev/e9d4288c32de -- nosy: +python-dev ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22427 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22477] GCD in Fractions
gladman added the comment: On 24/09/2014 10:13, Mark Dickinson wrote: Mark Dickinson added the comment: I will willingly supply more references if you need them. I don't. :-) I've taught more elementary number classes and reviewed more elementary number theory texts (including Rosen's) than I care to remember, and I have plenty of my own references. I stand by my assertion that the fractions module gcd is not wrong: it returns 'a' greatest common divisor for arbitrary integer inputs. Well we will just have to agree to disagree on this :-) -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22477 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22219] python -mzipfile fails to add empty folders to created zip
Serhiy Storchaka added the comment: Hmm, looks as I forgot to attach a patch. -- keywords: +patch Added file: http://bugs.python.org/file36706/zipfile_add_dirs.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22219 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22427] TemporaryDirectory attempts to clean up twice
Serhiy Storchaka added the comment: Committed without this test. Thank you Victor and Yury for your comments. -- resolution: - fixed stage: patch review - resolved status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22427 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22477] GCD in Fractions
Mark Dickinson added the comment: Well we will just have to agree to disagree on this :-) Sure. In the mean time, would you be interested in writing a patch targeting Python 3.5? (Irrespective of the arguments about the definition, I don't think this is a change that could be applied in a 3.4 bugfix release.) -- type: behavior - enhancement versions: +Python 3.5 -Python 3.4 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22477 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22480] SystemExit out of run_until_complete causes AttributeError when using python3 -m
New submission from chrysn: the attached test.py snipplet, which runs an asyncio main loop to the completion of a coroutine raising SystemExit, runs cleanly when invoked using `python3 test.py`, but shows a logging error from the Task.__del__ method when invoked using `python3 -m test`. the error message (attached as test.err) indicates that the builtins module has already been emptied by the time the Task's destructor is run. i could reproduce the problem with an easier test case without asyncio (destructoretest.py), but then again, there the issue is slightly more obvious (one could argue a don't do that, then), and it occurs no matter how the program is run. i'm leaving this initially assigned to asyncio, because (to the best of my knowledge) test.py does not do bad things by itself, and the behavior is inconsistent only there. -- components: asyncio messages: 227440 nosy: chrysn, gvanrossum, haypo, yselivanov priority: normal severity: normal status: open title: SystemExit out of run_until_complete causes AttributeError when using python3 -m versions: Python 3.4 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22480 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22480] SystemExit out of run_until_complete causes AttributeError when using python3 -m
Changes by chrysn chr...@fsfe.org: Added file: http://bugs.python.org/file36707/test.py ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22480 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22480] SystemExit out of run_until_complete causes AttributeError when using python3 -m
Changes by chrysn chr...@fsfe.org: Added file: http://bugs.python.org/file36708/test.err ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22480 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22480] SystemExit out of run_until_complete causes AttributeError when using python3 -m
Changes by chrysn chr...@fsfe.org: Added file: http://bugs.python.org/file36709/destructortest.py ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22480 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com