Re: Few Coding suggestions - resending
On Mon, Jan 12, 2015 at 8:42 AM, Ganesh Pal ganesh1...@gmail.com wrote: On Sun, Jan 11, 2015 at 7:57 PM, Dave Angel da...@davea.name wrote: No idea how that represents a difference of 5 minutes. So I'll take a totally wild guess that you meant: Sunday 23:50 23:55 Monday 00:00 00:05 Monday 00:10 00:15 Monday 00:20 00:25 Monday 00:30 00:35 which would have the 2nd column 5 minutes after the first. You need another datetime object, let's call it 'end' end = start + timedelta(minutes=5) and now you want to yield three things, in a tuple: yield (start.strftime(%A), start.strftime(%H:%M), end.strftime(%H:%M)) Of course that's a pain to do twice, as you have two yields in that function. I'll leave you to reorder the loop to make that unnecessary. Hint, do the yield first, THEN increment the start variable. Thanks for the inputs , I tried doing the increments and decrements first and then Yield Program: Login-1@SNAP-BOX-1 new]$ cat time_range_01.py #!/usr/bin/python import time from datetime import date, time, datetime, timedelta #h = datetime.strftime(%H) #m = datetime.strftime(%M) h=23 m=50 d = date.today() print d def yield_times(): global h,m,d start = datetime.combine(d, time(int(h),int(m))) end = datetime.combine(d, time(int(h),int(m))) while True: start += timedelta(minutes=10) end = start + timedelta(minutes=5) yield(start.strftime(%A),start.strftime(%H:%M),end.strftime(%H:%M)) gen = yield_times() for i in range(10): print gen.next() output : [Login-1@SNAP-BOX-1 new]$ python time_range_01.py 2015-01-12 ('Tuesday', '00:00', '00:05') ('Tuesday', '00:10', '00:15') ('Tuesday', '00:20', '00:25') ('Tuesday', '00:30', '00:35') ('Tuesday', '00:40', '00:45') ('Tuesday', '00:50', '00:55') ('Tuesday', '01:00', '01:05') ('Tuesday', '01:10', '01:15') ('Tuesday', '01:20', '01:25') ('Tuesday', '01:30', '01:35') PS : Except formatting the results looks pretty much what i was expecting .I was pretty much happy to see this last night :) . and in the other loop, you want res = {} {} {}\n.format(gen.next) print res, Thanks , I will have to modify for the new output (b) how to copy the above output (i.e with the new column to a file.) Instead of printing, just do f.write(res). Or do both. Notice that to make this easy, i avoided doing any formatting in the print statement. I used a trailing comma on it to avoid print adding a newline, and instead put it explicitly in the format method call. Sure (c) The final output should be a file , having the entries day , start , end time of the remote file. how do i pass the this to yeild-times() import time /* Assuming I retrive the below values h,m,d from the remote machine*/ h = time.strftime(%H) m = time.strftime(%M) d = date.today() Those first two are strings, but the third is a datetime object. That last can be painful to pass between machines. Correct , also looks like I have another issue , if I happen to pass the first two strings # instead hard coded value i.e h = 23 and y =50 , i try using the string directly I end up getting the below error : h = datetime.strftime(%H) m = datetime.strftime(%M) [Login-1@SNAP-BOX-1 new]$ python time_range_01.py Traceback (most recent call last): File time_range_01.py, line 4, in module h = datetime.strftime(%H) TypeError: descriptor 'strftime' requires a 'datetime.date' object but received a 'str' The date time object is retrieved once once from the remote machine and just for building the file in the required format. Do you foresee any problems using this ? def yield_times(): global h,m,d No idea what that's all about. If you want to pass arguments to yield_times(), put them inside the parens. sure . Regards, Gpal -- https://mail.python.org/mailman/listinfo/python-list
[issue23160] Respect the environment variable SVNROOT in external-common.bat
Anselm Kruis added the comment: Your guess is correct, it will be a null merge into default. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23160 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20284] patch to implement PEP 461 (%-interpolation for bytes)
Ethan Furman added the comment: I've been digging into this over the last week and come to the realization that I won't be able to finish this patch. My apologies. Victor, can you take over? I would appreciate it. The tests I have written are only for the Python side. The patch I was working on (inherited from Niel and the Python 2 code base) also added a couple C ABI functions -- do we want/need these? How do we write tests for them? -- stage: patch review - needs patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20284 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22977] Unformatted “Windows Error 0x%X” exception message on Wine
STINNER Victor added the comment: The attached patch lacks an unit test. When I will be able to build CPython again, I will try the patch. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22977 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue23221] a(n) the, the a(n) typos
Karan Goel added the comment: Hey I'll be working on this and submitting a patch. -- nosy: +karan ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23221 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Track down SIGABRT
I have a long-running python/CherryPy Web App server process that I am running on Mac OS X 10.8.5. Python 2.7.2 running in 32-bit mode (for now, I have the code in place to change over to 64 bit, but need to schedule the downtime to do it). On the 6th of this month, during normal operation from what I can tell, and after around 33 days of trouble-free uptime, the python process crashed with a SIGABRT. I restarted the process, and everything looked good again until yesterday, when it again crashed with a SIGABRT. The crash dump the system gave me doesn't tell me much, other than that it looks like python is calling some C function when it crashes. I've attached the crash report, in case it can mean something more to someone else.Can anyone give me some hints as to how to track down the cause of this crash? It's especially problematic since I can't mess with the live server for testing, and it is quite a while between crashes, making it difficult, if not impossible, to reproduce in testing. Thanks. ---Israel BrewsterSystems Analyst IIRavn Alaska5245 Airport Industrial RdFairbanks, AK 99709(907) 450-7293---BEGIN:VCARD VERSION:3.0 N:Brewster;Israel;;; FN:Israel Brewster ORG:Frontier Flying Service;MIS TITLE:PC Support Tech II EMAIL;type=INTERNET;type=WORK;type=pref:isr...@frontierflying.com TEL;type=WORK;type=pref:907-450-7293 item1.ADR;type=WORK;type=pref:;;5245 Airport Industrial Wy;Fairbanks;AK;99701; item1.X-ABADR:us CATEGORIES:General X-ABUID:36305438-95EA-4410-91AB-45D16CABCDDC\:ABPerson END:VCARD Python_2015-01-08-152219_minilogger.crash Description: Binary data -- https://mail.python.org/mailman/listinfo/python-list
[issue23193] Please support numeric_owner in tarfile
Eric V. Smith added the comment: I think Michael is asking if the proposed change would ever be accepted. If the answer is no, not even if you write the tests and update the documentation, then there's no sense putting the work into this. That seems like a reasonable question to me. I think the proposed change is reasonable, but I'm no tarfile expert. But since this functionality is available in the tar command as --numeric-owner, I think the feature request itself is a good idea. -- nosy: +eric.smith ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23193 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: annoying doctest problem
On 12/01/2015 13:00, Steven D'Aprano wrote: Skip Montanaro wrote: ISTR that when Tim Peters first implemented first, the typical way you were expected to get tests into a doc string was to copy from an interactive session, which would not have this problem. I believe that is still documented as the way to generate doctests. Also, to Steven's comment about fussiness, it isn't so much that it's fussy. It's more that it's dumb. I just does a simple string comparison of the expected and actual outputs. It would be impossible for doctest to know whether the expected output was something like repr or str output, and thus safe to exchange single for double (don't forget to escape other embedded quotes!), or was some sort of user-generated string, perhaps intended to be text in another programming language which has different quoting rules than Python. Therefore, fussy (or dumb) is exactly what you want. I didn't mean to give the impression that doctest was wrong to be fussy, or dumb if you prefer. I think it's exactly the right behaviour. If doctest is dumb then that's clearly down to the author. Perhaps we should refer him or her to the Zen of Python so they don't repeat the mistake with future design decisions? -- 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: annoying doctest problem
Skip Montanaro wrote: ISTR that when Tim Peters first implemented first, the typical way you were expected to get tests into a doc string was to copy from an interactive session, which would not have this problem. I believe that is still documented as the way to generate doctests. Also, to Steven's comment about fussiness, it isn't so much that it's fussy. It's more that it's dumb. I just does a simple string comparison of the expected and actual outputs. It would be impossible for doctest to know whether the expected output was something like repr or str output, and thus safe to exchange single for double (don't forget to escape other embedded quotes!), or was some sort of user-generated string, perhaps intended to be text in another programming language which has different quoting rules than Python. Therefore, fussy (or dumb) is exactly what you want. I didn't mean to give the impression that doctest was wrong to be fussy, or dumb if you prefer. I think it's exactly the right behaviour. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: class-based class decorator
- Original Message - From: Ian Kelly ian.g.ke...@gmail.com To: Python python-list@python.org Cc: Sent: Saturday, January 10, 2015 7:30 AM Subject: Re: class-based class decorator On Fri, Jan 9, 2015 at 2:26 PM, Albert-Jan Roskam fo...@yahoo.com.dmarc.invalid wrote: Hi, I am trying to write a class decorator that checks whether deprecated parameters with non-default arguments are used. More complete code is here: http://pastebin.com/ZqnMis6M. Oops, the period was included in the url. It was http://pastebin.com/ZqnMis6M In the code below, how should I modify __call__ such that f.bar(old=oh no) prints hello world? I thought it would be a fun way to play with the inspect module, but my head is numb now and I am thirsty for a beer! You can use inspect.getargspec to look up the default argument values for the target function. You can use inspect.getcallargs to map your *args and **kwargs to a dictionary of argument names and values. Since the target function will be the unbound __init__ method, you'll also want to pass in a dummy value like None for the self argument. Then you just look up each of the deprecated names in the result and flag any where the value doesn't match the default. If you were using Python 3.3+, then I would recommend using inspect.signature instead, which is a lot more powerful. But your code appears to be Python 2, so we work with what we've got. Hi Ian, Chris, Thanks for your replies. I changed it into a regular decorator (not a class decorator). It would have been even nicer if I only needed to specify it once per class, but, well, in my case this hardly matters. The code below works as intended. One problem (not specific to the code): the decorator destroys the signature: it always becomes *args, **kwargs). This is annoying with help(), but what worries me most is that my Sphinx documentation is also affected. The information about the defaults gets lost (the parameters are decribed in the docstring, but not the defaults). That kind of sucks. Is there a builtin way around this (in other words: I am aware of this package: https://pypi.python.org/pypi/decorator). I am hoping to get the code working on Python 2.7 and 3.3 and up. import functools import inspect import warnings warnings.simplefilter(always) class check_deprecated_args(object): def __init__(self, deprecated_params, msg=None): self.deprecated_params = deprecated_params self.msg = msg def __call__(self, func): @functools.wraps(func) def inner(*args, **kwargs): argspec = inspect.getargspec(func) default_signature = dict(zip(argspec.args[1:], argspec.defaults)) callargs = inspect.getcallargs(func, *args, **kwargs) deprecated_calls = [(p, a) for p, a in callargs.items() if p in self.deprecated_params and a != default_signature[p]] for (param, arg) in deprecated_calls: msg = you're using obsolete parameters in %s: [%s:%s] msg = msg % (func.__name__, param, arg) msg = msg + + self.msg if self.msg else msg warnings.warn(msg, DeprecationWarning, stacklevel=2) return func(*args, **kwargs) functools.update_wrapper(inner, func) return inner if __name__ == __main__: class Foo(object): @check_deprecated_args([old, older], use 'brand_new' param instead) def __init__(self, old=old, older=ancient): print hello @check_deprecated_args(deprecated_params=[old, older]) def bar(self, old=default): print world f = Foo(old=old, older=dino era) f.bar(gnarly) help(f) # now the signature is *args, **kwargs, which makes my Sphinx documentation less readable! Best wishes, Albert-Jan -- https://mail.python.org/mailman/listinfo/python-list
[issue23193] Please support numeric_owner in tarfile
R. David Murray added the comment: I concur that this is a reasonable feature request, and it is not one that can be satisfied without modifying the tarfile module (that is, you can't write a simple wrapper to tarfile to get the functionality desired without cutting and pasting the entire chown method). -- nosy: +r.david.murray ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23193 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue23189] Set docstrings to empty string when optimizing with -OO.
Jarle Selvåg added the comment: I agree that -OO does what (people have agreed) it's supposed to do. Many packages manipulates the docstring without checking for 'None' (see list below). For many package developers, it seems hard to remember that the docstrings may disappear after optimization. This behavior is not intuitive. At least in cases where the docstring is set to a string value, the expected behavior in my opinion would be to set its value to an empty string during optimization with -OO. Here are some of the packages that run into trouble when the docstrings are set to 'None' by the -OO optimization: algopy astropy lmfit pyamg pyvisa mpl_toolkits sympy statsmodels patsy sklearn -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23189 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: Few Coding suggestions - resending
Thanks to all and dear Dave Angel, I got this working :) , using your valuable inputs . Here is the final program: Throttling-1# cat sleep_schedule_file.py #!/usr/bin/python import time import pdb from datetime import date, time, datetime, timedelta #'''run these on the remote commmand ''' n = datetime.now() h = n.strftime(%H) m = n.strftime(%M) d = date.today() #''' get the sleep_schedule_structure ''' def yield_times(): start = datetime.combine(d, time(int(h),int(m))) end = datetime.combine(d, time(int(h),int(m))) while True: start += timedelta(minutes=4) end = start + timedelta(minutes=2) yield(start.strftime(%A),start.strftime(%H:%M),end.strftime(%H:%M)) gen = yield_times() f = open('/tmp/sleep_sched.conf','wb') for ii in range(10): a,b,c = gen.next() res = {0} {1} {2} \n.format(a,b,c) print res, f.write(res) f.close() Gpal On Mon, Jan 12, 2015 at 3:23 PM, Ganesh Pal ganesh1...@gmail.com wrote: On Mon, Jan 12, 2015 at 8:42 AM, Ganesh Pal ganesh1...@gmail.com wrote: On Sun, Jan 11, 2015 at 7:57 PM, Dave Angel da...@davea.name wrote: No idea how that represents a difference of 5 minutes. So I'll take a totally wild guess that you meant: Sunday 23:50 23:55 Monday 00:00 00:05 Monday 00:10 00:15 Monday 00:20 00:25 Monday 00:30 00:35 which would have the 2nd column 5 minutes after the first. You need another datetime object, let's call it 'end' end = start + timedelta(minutes=5) and now you want to yield three things, in a tuple: yield (start.strftime(%A), start.strftime(%H:%M), end.strftime(%H:%M)) Of course that's a pain to do twice, as you have two yields in that function. I'll leave you to reorder the loop to make that unnecessary. Hint, do the yield first, THEN increment the start variable. Thanks for the inputs , I tried doing the increments and decrements first and then Yield Program: Login-1@SNAP-BOX-1 new]$ cat time_range_01.py #!/usr/bin/python import time from datetime import date, time, datetime, timedelta #h = datetime.strftime(%H) #m = datetime.strftime(%M) h=23 m=50 d = date.today() print d def yield_times(): global h,m,d start = datetime.combine(d, time(int(h),int(m))) end = datetime.combine(d, time(int(h),int(m))) while True: start += timedelta(minutes=10) end = start + timedelta(minutes=5) yield(start.strftime(%A),start.strftime(%H:%M),end.strftime(%H:%M)) gen = yield_times() for i in range(10): print gen.next() output : [Login-1@SNAP-BOX-1 new]$ python time_range_01.py 2015-01-12 ('Tuesday', '00:00', '00:05') ('Tuesday', '00:10', '00:15') ('Tuesday', '00:20', '00:25') ('Tuesday', '00:30', '00:35') ('Tuesday', '00:40', '00:45') ('Tuesday', '00:50', '00:55') ('Tuesday', '01:00', '01:05') ('Tuesday', '01:10', '01:15') ('Tuesday', '01:20', '01:25') ('Tuesday', '01:30', '01:35') PS : Except formatting the results looks pretty much what i was expecting .I was pretty much happy to see this last night :) . and in the other loop, you want res = {} {} {}\n.format(gen.next) print res, Thanks , I will have to modify for the new output (b) how to copy the above output (i.e with the new column to a file.) Instead of printing, just do f.write(res). Or do both. Notice that to make this easy, i avoided doing any formatting in the print statement. I used a trailing comma on it to avoid print adding a newline, and instead put it explicitly in the format method call. Sure (c) The final output should be a file , having the entries day , start , end time of the remote file. how do i pass the this to yeild-times() import time /* Assuming I retrive the below values h,m,d from the remote machine*/ h = time.strftime(%H) m = time.strftime(%M) d = date.today() Those first two are strings, but the third is a datetime object. That last can be painful to pass between machines. Correct , also looks like I have another issue , if I happen to pass the first two strings # instead hard coded value i.e h = 23 and y =50 , i try using the string directly I end up getting the below error : h = datetime.strftime(%H) m = datetime.strftime(%M) [Login-1@SNAP-BOX-1 new]$ python time_range_01.py Traceback (most recent call last): File time_range_01.py, line 4, in module h = datetime.strftime(%H) TypeError: descriptor 'strftime' requires a 'datetime.date' object but received a 'str' The date time object is retrieved once once from the remote machine and just for building the file in the required format. Do you foresee any problems using this ? def yield_times(): global h,m,d No idea what that's all about. If you want to pass arguments to yield_times(), put them inside the parens. sure . Regards, Gpal -- https://mail.python.org/mailman/listinfo/python-list
Reg: scrappring error
Traceback (most recent call last): File sample.py, line 28, in module scrape_data(row['All Samples'],row['URL']) File sample.py, line 13, in scrape_data html = etree.HTML(urllib2.urlopen(url).read()) File C:\Users\sushanth.thangamani\AppData\Local\Continuum\Anaconda\lib\urllib 2.py, line 127, in urlopen return _opener.open(url, data, timeout) File C:\Users\sushanth.thangamani\AppData\Local\Continuum\Anaconda\lib\urllib 2.py, line 410, in open response = meth(req, response) File C:\Users\sushanth.thangamani\AppData\Local\Continuum\Anaconda\lib\urllib 2.py, line 523, in http_response 'http', request, response, code, msg, hdrs) File C:\Users\sushanth.thangamani\AppData\Local\Continuum\Anaconda\lib\urllib 2.py, line 442, in error result = self._call_chain(*args) File C:\Users\sushanth.thangamani\AppData\Local\Continuum\Anaconda\lib\urllib 2.py, line 382, in _call_chain result = func(*args) File C:\Users\sushanth.thangamani\AppData\Local\Continuum\Anaconda\lib\urllib 2.py, line 629, in http_error_302 return self.parent.open(new, timeout=req.timeout) File C:\Users\sushanth.thangamani\AppData\Local\Continuum\Anaconda\lib\urllib 2.py, line 410, in open response = meth(req, response) File C:\Users\sushanth.thangamani\AppData\Local\Continuum\Anaconda\lib\urllib 2.py, line 523, in http_response 'http', request, response, code, msg, hdrs) File C:\Users\sushanth.thangamani\AppData\Local\Continuum\Anaconda\lib\urllib 2.py, line 442, in error result = self._call_chain(*args) File C:\Users\sushanth.thangamani\AppData\Local\Continuum\Anaconda\lib\urllib 2.py, line 382, in _call_chain result = func(*args) File C:\Users\sushanth.thangamani\AppData\Local\Continuum\Anaconda\lib\urllib 2.py, line 629, in http_error_302 return self.parent.open(new, timeout=req.timeout) File C:\Users\sushanth.thangamani\AppData\Local\Continuum\Anaconda\lib\urllib 2.py, line 410, in open response = meth(req, response) File C:\Users\sushanth.thangamani\AppData\Local\Continuum\Anaconda\lib\urllib 2.py, line 523, in http_response 'http', request, response, code, msg, hdrs) File C:\Users\sushanth.thangamani\AppData\Local\Continuum\Anaconda\lib\urllib 2.py, line 442, in error result = self._call_chain(*args) File C:\Users\sushanth.thangamani\AppData\Local\Continuum\Anaconda\lib\urllib 2.py, line 382, in _call_chain result = func(*args) File C:\Users\sushanth.thangamani\AppData\Local\Continuum\Anaconda\lib\urllib 2.py, line 629, in http_error_302 return self.parent.open(new, timeout=req.timeout) File C:\Users\sushanth.thangamani\AppData\Local\Continuum\Anaconda\lib\urllib 2.py, line 410, in open response = meth(req, response) File C:\Users\sushanth.thangamani\AppData\Local\Continuum\Anaconda\lib\urllib 2.py, line 523, in http_response 'http', request, response, code, msg, hdrs) File C:\Users\sushanth.thangamani\AppData\Local\Continuum\Anaconda\lib\urllib 2.py, line 442, in error result = self._call_chain(*args) File C:\Users\sushanth.thangamani\AppData\Local\Continuum\Anaconda\lib\urllib 2.py, line 382, in _call_chain result = func(*args) File C:\Users\sushanth.thangamani\AppData\Local\Continuum\Anaconda\lib\urllib 2.py, line 629, in http_error_302 return self.parent.open(new, timeout=req.timeout) File C:\Users\sushanth.thangamani\AppData\Local\Continuum\Anaconda\lib\urllib 2.py, line 410, in open response = meth(req, response) File C:\Users\sushanth.thangamani\AppData\Local\Continuum\Anaconda\lib\urllib 2.py, line 523, in http_response 'http', request, response, code, msg, hdrs) File C:\Users\sushanth.thangamani\AppData\Local\Continuum\Anaconda\lib\urllib 2.py, line 442, in error result = self._call_chain(*args) File C:\Users\sushanth.thangamani\AppData\Local\Continuum\Anaconda\lib\urllib 2.py, line 382, in _call_chain result = func(*args) File C:\Users\sushanth.thangamani\AppData\Local\Continuum\Anaconda\lib\urllib 2.py, line 629, in http_error_302 return self.parent.open(new, timeout=req.timeout) File C:\Users\sushanth.thangamani\AppData\Local\Continuum\Anaconda\lib\urllib 2.py, line 410, in open response = meth(req, response) File C:\Users\sushanth.thangamani\AppData\Local\Continuum\Anaconda\lib\urllib 2.py, line 523, in http_response 'http', request, response, code, msg, hdrs) File C:\Users\sushanth.thangamani\AppData\Local\Continuum\Anaconda\lib\urllib 2.py, line 442, in error result = self._call_chain(*args) File C:\Users\sushanth.thangamani\AppData\Local\Continuum\Anaconda\lib\urllib 2.py, line 382, in _call_chain result = func(*args) File C:\Users\sushanth.thangamani\AppData\Local\Continuum\Anaconda\lib\urllib 2.py, line 629, in http_error_302 return self.parent.open(new, timeout=req.timeout) File C:\Users\sushanth.thangamani\AppData\Local\Continuum\Anaconda\lib\urllib 2.py, line 410, in open response = meth(req, response) File
unidecode
Along lines of recent queries/questions, which had mostly sorted out, but, which was still trying to fine tune with regards to text file formats, in terms of writing as strings, or as binary files, and where was still trying to decide if wanted to worry about maybe specifically just handling forms of manual/hard-coded translations of certain accented characters which might relate to some of them that might get used quite often in names, etc., I just came across the following unidecode module: https://pypi.python.org/pypi/Unidecode/ Seems to just take any unicode value, and 'translate' it into a string value, and will apparently try handle some forms of character substitution - but will play around with it a bit more, and let's see... Stay well Jacob Kruger Blind Biker Skype: BlindZA Roger Wilco wants to welcome you...to the space janitor's closet... - Original Message - From: Jacob Kruger To: Jacob Kruger Sent: Monday, January 12, 2015 2:15 PM Subject: unidecode https://pypi.python.org/pypi/Unidecode/ Jacob Kruger Blind Biker Skype: BlindZA Roger Wilco wants to welcome you...to the space janitor's closet... -- https://mail.python.org/mailman/listinfo/python-list
PythonFOSDEM 2015 - Schedule Updated… We will start at 10:30 AM
Dear Python Community, Because the FOSDEM will start at 10:30 AM on Saturday 31st January, the first talk will be at 10:30 AM. Thus all the talks will be ajusted. The Schedule on the site of FOSDEM and on the PythonFOSDEM site have been updated. https://fosdem.org/2015/schedule/track/python/ Regards, Stephane -- Stéphane Wirtel - http://wirtel.be - @matrixise -- https://mail.python.org/mailman/listinfo/python-list
[issue22932] email.utils.formatdate uses unreliable time.timezone constant
Changes by Dmitry Shachnev mity...@gmail.com: Added file: http://bugs.python.org/file37683/issue22932_combined.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22932 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: annoying doctest problem
On Mon, Jan 12, 2015 at 6:15 AM, Skip Montanaro skip.montan...@gmail.com wrote: ... first implemented first ... s/first/doctest/ Darn auto-correct... Skip -- https://mail.python.org/mailman/listinfo/python-list
[issue23221] a(n) the, the a(n) typos
Karan Goel added the comment: There we go. I fixed all the reported typos using the best of my knowledge. -- keywords: +patch Added file: http://bugs.python.org/file37680/issue23221.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23221 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue23209] asyncio: break some cycles
Martin Richard added the comment: I updated the selector patch so BaseSelector.get_key() raises KeyError if the mapping is None. All the (non skipped) tests in test_selectors.py passed. Anyway, if there is an other problem with freeing the mapping object (I don't know, maybe reopening a loop may be considered?) this patch can probably be dropped. Since this cycle is broken when the loop is closed, the objects will likely be collected once the program terminates. -- Added file: http://bugs.python.org/file37681/break-selector-map-cycle.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23209 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue23209] asyncio: break some cycles
STINNER Victor added the comment: I opened the issue #23225 selectors: raise an exception if the selector is closed which is a different approach (but it should also fix the reference cycle, I kept the self._map = None change). -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23209 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue23225] selectors: raise an exception if the selector is closed
New submission from STINNER Victor: I propose to raise a RuntimeError exception on operations of a selector when the selector is closed. I'm not sure that RuntimeError is the most common exception: - io and gzip raise ValueError - asyncio raises RuntimeError (and selectors is linked to asyncio) - multiprocessing raises OSError - dbm.dumb raises dbm.dumb.error This issue is related to the issue #23209 which propopses to set the _map attribute to None when in the close() method. -- components: asyncio files: close_selector.patch keywords: patch messages: 233881 nosy: gvanrossum, haypo, martius, neologix, yselivanov priority: normal severity: normal status: open title: selectors: raise an exception if the selector is closed versions: Python 3.4, Python 3.5 Added file: http://bugs.python.org/file37682/close_selector.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23225 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: annoying doctest problem
ISTR that when Tim Peters first implemented first, the typical way you were expected to get tests into a doc string was to copy from an interactive session, which would not have this problem. Also, to Steven's comment about fussiness, it isn't so much that it's fussy. It's more that it's dumb. I just does a simple string comparison of the expected and actual outputs. It would be impossible for doctest to know whether the expected output was something like repr or str output, and thus safe to exchange single for double (don't forget to escape other embedded quotes!), or was some sort of user-generated string, perhaps intended to be text in another programming language which has different quoting rules than Python. Therefore, fussy (or dumb) is exactly what you want. I-said-what-I-meant-ly y'rs, Skip -- https://mail.python.org/mailman/listinfo/python-list
Happy new year with Dipy 0.8!
Dear all, We are very happy to announce a new release of Diffusion Imaging in Python (Dipy). Here is a summary of the most important new features and developments. DIPY 0.8.0 (Released on Tuesday, 6 Jan 2015) Nonlinear Image-based Registration (SyN) An implementation of the Symmetric Normalization method for nonlinear diffeomorphic registration. This implementation is lightweight, and does not depend on ITK or ANTS. It is written entirely in Python and Cython. Streamline-based Linear Registration (SLR) A new method that allows direct registration of bundles of streamlines. Especially useful for creating atlases of specific types of bundles. Linear Fascicle Evaluation (LiFE) This is a Python implementation of a new method for evaluation of tractrography solutions. Sparse Fascicle Model (SFM) A new signal reconstruction method , added to the large stack of reconstruction models already available in Dipy, including implementations of CSD and SHORE. Non-local means denoising (NLMEANS) Denoising is a technique that can boost most of your analysis techniques as it can increase the signal to noise ratio of your data. We started this new module by implementing a very generic denoising technique that can be used also for fMRI and T1 images. New modular tracking machinery This is a collection of new objects which allows rapid development of new fiber tracking algorithms. In summary, since January 2014 (version 0.7.1), we closed 388 issues and merged 155 pull requests. The project now has a total of more than 4000 commits and 29 contributors. We would appreciate if you could forward this information to any interested individuals or labs. Yours sincerely, On behalf of the Dipy developers, Eleftherios Garyfallidis http://dipy.org -- https://mail.python.org/mailman/listinfo/python-list
Re: Array of hash table
Can any one tell me how to create graph={ nodes: [ { id: n0, label: A node, x: 0, [ ... elided ... ] } ] } Taking a guess and guessing that graphviz might be useful for you: https://code.google.com/p/pydot/. -- https://mail.python.org/mailman/listinfo/python-list
IMAPClient 0.12
IMAPClient is an easy-to-use, Pythonic and complete IMAP client library. Version 0.12 has just been released with the following highlights: * Unicode handling has been fixed. Some bad decisions were made during the Python 3 port (v0.10) and this release fixes that. Bytes are now returned in most places (instead of unicode strings). * MODSEQ parts in SEARCH responses are now handled correctly. A crash has been fixed when MODSEQ queries (part of the CONDSTORE extension) are made with the search method. The returned MODSEQ value is now available via the modseq attribute on the returned list of ids. * Extra __init__ keyword args are passed through. This allows access to SSL options that the underlying imaplib library might support (Python version dependent). * Python 3.4 is now officially supported. * More control over OAUTH2 parameters. * The deprecated get_folder_delimiter() method has been removed. Many thanks go to Inbox for sponsoring the significant unicode changes in this release. More about them at http://inboxapp.com/. More details about this release can be found at: * https://bitbucket.org/mjs0/imapclient/src/tip/NEWS.rst * http://imapclient.readthedocs.org/en/0.12/ * http://imapclient.freshfoo.com/ * https://pypi.python.org/pypi/IMAPClient/0.12 -- https://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
Re: application console with window
and u have another below choice http://docs.python.org/howto/curses.html http://urwid.org/ On Thu, Jan 8, 2015 at 12:54 AM, Amir Arsalan am1r.ar3a...@gmail.com wrote: Hi adam, U can use from npyscreen. Npyscreen.readthedocs.org On Jan 8, 2015 12:50 AM, adam a...@poczta.emiter-uslugi.pl wrote: Is in here maybe someone who speak Polish? I would like to write application witch looks like this http://linuxiarze.pl/obrazy/internet1/ceni1.png I'm looking for some libs, tutorials, or other informations. I'm searching this informations for python3. adam -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: application console with window
Hi adam, U can use from npyscreen. Npyscreen.readthedocs.org On Jan 8, 2015 12:50 AM, adam a...@poczta.emiter-uslugi.pl wrote: Is in here maybe someone who speak Polish? I would like to write application witch looks like this http://linuxiarze.pl/obrazy/internet1/ceni1.png I'm looking for some libs, tutorials, or other informations. I'm searching this informations for python3. adam -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: annoying doctest problem
Mark Lawrence wrote: If doctest is dumb then that's clearly down to the author. Perhaps we should refer him or her to the Zen of Python so they don't repeat the mistake with future design decisions? o_O I don't even ... wait ... [starts typing] [stops typing] ... okay. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
[issue22977] Unformatted “Windows Error 0x%X” exception message on Wine
Changes by Berker Peksag berker.pek...@gmail.com: -- stage: - patch review versions: +Python 3.4, Python 3.5 -Python 3.3 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22977 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: Python 3 regex?
On 12/01/2015 18:03, Jason Bailey wrote: Hi all, I'm working on a Python _3_ project that will be used to parse ISC DHCPD configuration files for statistics and alarming purposes (IP address pools, etc). Anyway, I'm hung up on this one section and was hoping someone could provide me with some insight. My script first reads the DHCPD configuration file into memory - variable filebody. It then utilizes the re module to find the configuration details for the wanted shared network. Hi Jason, If you actually look at the syntax of what you are parsing, it is very simple. My recommendation would be to write a recursive decent parser for your files. That way will be easier to write, much easier to modify and almost certainly faster that a RE solution - and it can easily give you all the information in the file thus future proofing it. 'Some people, when confronted with a problem, think I know, I'll use regular expressions. Now they have two problems.' - Jamie Zawinski. Regards Ian -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 3 regex?
On Tue, Jan 13, 2015 at 5:03 AM, Jason Bailey jbai...@emerytelcom.com wrote: Unfortunately, I get no matches. From output on the command line, I can see that Python is adding extra backslashes to my re.compile string. I have added the raw 'r' in front of the strings to prevent it, but to no avail. Regexes are notoriously hard to debug. Is there any particular reason you _have_ to use one here? ISTM you could simplify it enormously by just looking for the opening string: shared_network = My-Network-FECO network = filebody.split(\nshared-network +shared_network+ {,1)[1].split(\n}\n)[0] Assuming your file is always correctly indented, and assuming you don't have any other instances of that header string, you should be fine. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 3 regex woes (parsing ISC DHCPD config)
On 01/12/2015 01:20 PM, Jason Bailey wrote: Hi all, What changed between 1:03 and 1:20 that made you post a nearly identical second message, as a new thread? Unfortunately, I get no matches. From output on the command line, I can see that Python is adding extra backslashes to my re.compile string. I have added the raw 'r' in front of the strings to prevent it, but to no avail. What makes you think that? Please isolate this part of your problem with a simple short program, so we can diagnose it. You're probably getting confused between str() and repr(). The latter adds backslash escape sequences for good reason, and if you don't understand it, you might think the strings are getting corrupted. -- DaveA -- https://mail.python.org/mailman/listinfo/python-list
Namespace puzzle, list comprehension fails within class definition
I've never come across this before. Here's a minimal example (in Python 3.4): Code: - d = {0:a, 1:b, 2:c, 3:d} e = [d[x] for x in (0,2)] class Foo: f = {0:a, 1:b, 2:c, 3:d} print(f) g = [f[x] for x in (0,2)] foo = Foo() Output: - {0: 'a', 1: 'b', 2: 'c', 3: 'd'} Traceback (most recent call last): File minimal example.py, line 6, in module class Foo: File minimal example.py, line 9, in Foo g = [f[x] for x in (0,2)] File minimal example.py, line 9, in listcomp g = [f[x] for x in (0,2)] NameError: name 'f' is not defined - When I am working in the top-level namespace, I get no errors when referencing the dictionary, d, inside the list comprehension which generates e. When I am working inside the class namespace, the print function call on line 8 recognizes the name f and prints the dictionary bound to that name. However, the LIST COMPREHENSION defined inside the class namespace generates a NameError. In all my years of Python programming, I guess that I have never tried to define a class attribute using a list comprehension. Why doesn't it work? Any advice, and suggestions for Pythonic workarounds, are appreciated. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 3 regex?
On Tue, Jan 13, 2015 at 6:48 AM, Ian hobso...@gmail.com wrote: My recommendation would be to write a recursive decent parser for your files. That way will be easier to write, much easier to modify and almost certainly faster that a RE solution - and it can easily give you all the information in the file thus future proofing it. Generally, even a recursive descent parser will be overkill. It's pretty easy to do simple string manipulation to get the info you want; maybe that means restricting the syntax some, but for a personal-use script, that's usually no big cost. The example I gave requires that the indentation be correct, and on this mailing list, I think people agree that that's not a deal-breaker :) ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Namespace puzzle, list comprehension fails within class definition
Following up to myself: I finally did the right keyword search, and found a relevant article: http://stackoverflow.com/questions/13905741/accessing-class-variables-from-a-list-comprehension-in-the-class-definition Maybe I HAVE tried to define a list comprehension inside a class definition before. What I tried to do would have apparently worked in Python 2. But in Python 3, the namespace behavior has changed (and I'm still reading the article to understand how and why). I guess that I could define my objects as globals... now, why would Python force me into doing that? :^( -- https://mail.python.org/mailman/listinfo/python-list
Re: Namespace puzzle, list comprehension fails within class definition
On Tue, Jan 13, 2015 at 7:25 AM, John Ladasky john_lada...@sbcglobal.net wrote: When I am working inside the class namespace, the print function call on line 8 recognizes the name f and prints the dictionary bound to that name. However, the LIST COMPREHENSION defined inside the class namespace generates a NameError. A list comp is defined with a function call: def f(): ... return [x*x for x in range(4)] ... dis.dis(f) 2 0 LOAD_CONST 1 (code object listcomp at 0x7fdf25981420, file stdin, line 2) 3 LOAD_CONST 2 ('f.locals.listcomp') 6 MAKE_FUNCTION0 9 LOAD_GLOBAL 0 (range) 12 LOAD_CONST 3 (4) 15 CALL_FUNCTION1 (1 positional, 0 keyword pair) 18 GET_ITER 19 CALL_FUNCTION1 (1 positional, 0 keyword pair) 22 RETURN_VALUE This prevents leakage of the iterator into the enclosing scope. Personally, I think it's a hack to get around the fact that Python doesn't have any concept of sub-function-scope (similar to the weird hack in try/except); if it weren't for that, true nesting would be easier. As it is, function definitions in class scope have a special meaning, and that interferes a bit with list comps. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: I must be missing something obvious in installing Python 3.4.2...
On 12/01/2015 18:02, Andrew Koenig wrote: Downloaded and installed 64-bit Python 3.4 and pywin32-219. Both installed smoothly on my 64-bit Win7 machine. I added C:\Python34 to the search path. If I launch a Windows command window and run python -m ensurepip I get the following: Ignoring indexes: https://pypi.python.org/simple/ Downloading/unpacking setuptools Cleaning up... Exception: Traceback (most recent call last): File C:\Users\ark\AppData\Local\Temp\tmpe3ckts9f\pip-1.5.6-py2.py3-none-any.w hl\pip\basecommand.py, line 122, in main status = self.run(options, args) File C:\Users\ark\AppData\Local\Temp\tmpe3ckts9f\pip-1.5.6-py2.py3-none-any.w hl\pip\commands\install.py, line 278, in run requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundl e=self.bundle) File C:\Users\ark\AppData\Local\Temp\tmpe3ckts9f\pip-1.5.6-py2.py3-none-any.w hl\pip\req.py, line 1177, in prepare_files url = finder.find_requirement(req_to_install, upgrade=self.upgrade) File C:\Users\ark\AppData\Local\Temp\tmpe3ckts9f\pip-1.5.6-py2.py3-none-any.w hl\pip\index.py, line 209, in find_requirement file_locations, url_locations = self._sort_locations(locations) File C:\Users\ark\AppData\Local\Temp\tmpe3ckts9f\pip-1.5.6-py2.py3-none-any.w hl\pip\index.py, line 128, in _sort_locations sort_path(os.path.join(path, item)) File C:\Users\ark\AppData\Local\Temp\tmpe3ckts9f\pip-1.5.6-py2.py3-none-any.w hl\pip\index.py, line 109, in sort_path if mimetypes.guess_type(url, strict=False)[0] == 'text/html': File C:\Python34\lib\mimetypes.py, line 287, in guess_type init() File C:\Python34\lib\mimetypes.py, line 348, in init db.read_windows_registry() File C:\Python34\lib\mimetypes.py, line 255, in read_windows_registry with _winreg.OpenKey(hkcr, subkeyname) as subkey: TypeError: OpenKey() argument 2 must be str without null characters or None, not str Ouch! That looks like another variation on a bug of which we've fixed at least two variations to do with reading mimetypes from the Windows registry. Can you see what the following code produces, please: code import winreg as _winreg hkcr = _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, ) with open(classes.txt, w) as f: i = 0 while True: try: ctype = _winreg.EnumKey(hkcr, i) except EnvironmentError: break else: f.write(%s - %r\n % (type(ctype), ctype)) i += 1 /code TJG -- https://mail.python.org/mailman/listinfo/python-list
[issue19777] Provide a home() classmethod on Path objects
STINNER Victor added the comment: +def _test_home(self, p): +q = self.cls(os.path.expanduser('~')) +self.assertEqual(p, q) +self.assertEqual(str(p), str(q)) +self.assertIs(type(p), type(q)) +self.assertTrue(p.is_absolute()) + +def test_home(self): +p = self.cls.home() +self._test_home(p) Why are you using a submethod _test_home()? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19777 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: I must be missing something obvious in installing Python 3.4.2...
python --version reports 3.4.2, which is what I expected. I see no PYTHONPATH variable, or any environment variable with a name beginning PY (either upper or lower case). -- https://mail.python.org/mailman/listinfo/python-list
Broken IF statement
https://bpaste.net/show/93be9e15634b --- Line 19 through 22 At all times, my program is assigning the object priority of 0, even if one already exists in the database with a priority of 0 (it's supposed to be assigning it a priority of 1 in those cases). I'm a non developer trying to fix a freelancer's code. Would anybody be able to suggest changes to the IF logic that might be able to fix it, assuming the statements in the code provided look flawed? Thanks... -- https://mail.python.org/mailman/listinfo/python-list
Re: Namespace puzzle, list comprehension fails within class definition
On 01/12/2015 12:25 PM, John Ladasky wrote: d = {0:a, 1:b, 2:c, 3:d} e = [d[x] for x in (0,2)] class Foo: f = {0:a, 1:b, 2:c, 3:d} print(f) g = [f[x] for x in (0,2)] In Foo 'f' is part of an unnamed namespace; the list comp 'g' has its own namespace, effectively making be a nonlocal; class name lookup skips nonlocal namespaces. Workaround: use an actual for loop. -- ~Ethan~ signature.asc Description: OpenPGP digital signature -- https://mail.python.org/mailman/listinfo/python-list
Re: Namespace puzzle, list comprehension fails within class definition
On Monday, January 12, 2015 at 12:41:30 PM UTC-8, Ethan Furman wrote: In Foo 'f' is part of an unnamed namespace; the list comp 'g' has its own namespace, effectively making be a nonlocal; class name lookup skips nonlocal namespaces. Workaround: use an actual for loop. Thanks, Ethan. That works. As you can see from my other post, I've just discovered that the scoping rules for list comprehensions were changed between Py2 and Py3. -- https://mail.python.org/mailman/listinfo/python-list
[issue19777] Provide a home() classmethod on Path objects
Roundup Robot added the comment: New changeset 4a55b98314cd by Antoine Pitrou in branch 'default': Issue #19777: Provide a home() classmethod on Path objects. https://hg.python.org/cpython/rev/4a55b98314cd -- nosy: +python-dev ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19777 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: I must be missing something obvious in installing Python 3.4.2...
It runs and creates a classes.txt file with 803 lines. The first few: class 'str' - '$cpfile12' class 'str' - '$crfile12' class 'str' - '$cxfile12' class 'str' - '*' class 'str' - '.$cp' class 'str' - '.$cr' class 'str' - '.$cx' class 'str' - '.386' class 'str' - '.3ds' A few lines in the middle that might be relevant: class 'str' - '.py' class 'str' - '.pyc' class 'str' - '.pyo' class 'str' - '.pys' class 'str' - '.pyw' And the last few: class 'str' - '{C7A40493-BF23-4B53-AB2A-4A923B3EE34B}\x00' class 'str' - '{E14E55A7-29C8-4389-8E5A-3EF964510FCA}\x00' class 'str' - '{F5E30566-7C8F-4037-A8FF-A7382E251C56}\x00' Anything in particular I should be looking for? -- https://mail.python.org/mailman/listinfo/python-list
[issue23199] libpython27.a in amd64 release is 32-bit
Steve Dower added the comment: Is the libpython27.a file actually a 32-bit version or is it just corrupted? It seems to be considerably smaller than the version in the 32-bit installer, but it is certainly not being generated from the 32-bit version. I didn't write this code originally, and I don't use MinGW, so I'm not entirely familiar with how it should work. Do I need separate 64-bit tools to build the library for the 64-bit DLL or will the 32-bit tools suffice? Are the interfaces stable enough within 64-bit versions of MinGW that shipping the library makes sense, or are people likely to always need to regenerate it anyway? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23199 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: I must be missing something obvious in installing Python 3.4.2...
On 12/01/2015 21:45, Andrew Koenig wrote: It runs and creates a classes.txt file with 803 lines. The first few: class 'str' - '$cpfile12' class 'str' - '$crfile12' class 'str' - '$cxfile12' class 'str' - '*' class 'str' - '.$cp' class 'str' - '.$cr' class 'str' - '.$cx' class 'str' - '.386' class 'str' - '.3ds' A few lines in the middle that might be relevant: class 'str' - '.py' class 'str' - '.pyc' class 'str' - '.pyo' class 'str' - '.pys' class 'str' - '.pyw' And the last few: class 'str' - '{C7A40493-BF23-4B53-AB2A-4A923B3EE34B}\x00' class 'str' - '{E14E55A7-29C8-4389-8E5A-3EF964510FCA}\x00' class 'str' - '{F5E30566-7C8F-4037-A8FF-A7382E251C56}\x00' Anything in particular I should be looking for? I was actually expecting to see something like a byestring, but in fact those last few items look suspicious with their trailing NULs. The mimetypes code tries to open each key to find its associated mimetype(s) and would probably fail on those. The PyArg_ParseTupleAndKeywords in OpenKey is using the Z pattern for its first parameter which disallows embedded NULs. Obviously we can trap-and-skip within the mimetypes code but that won't help you immediately (short of your patching your own lib/mimetypes). Is it possible to temporarily rename those keys out of the way, or to strip their trailing NULs to see if the problem goes away? TJG -- https://mail.python.org/mailman/listinfo/python-list
Re: Broken IF statement
On Tue, Jan 13, 2015 at 8:19 AM, jobopps...@gmail.com wrote: https://bpaste.net/show/93be9e15634b --- Line 19 through 22 At all times, my program is assigning the object priority of 0, even if one already exists in the database with a priority of 0 (it's supposed to be assigning it a priority of 1 in those cases). I'm a non developer trying to fix a freelancer's code. Would anybody be able to suggest changes to the IF logic that might be able to fix it, assuming the statements in the code provided look flawed? Normally, I would suggest talking to the freelancer who wrote the code, unless you're no longer working with him/her. Changing someone's code out from under them is a great way to annoy and confuse. Including the text in-line as it's short enough for that: def create_socialaccount(profile, urls, twitters, facebooks, statuses=None): Add or update all the social accounts linked to the 'profile' results = [] l = [(urls, SocialAccount.HOMEPAGE, HOMEPAGE_COL_START), (twitters, SocialAccount.TWITTER, TWITTER_COL_START), (facebooks, SocialAccount.FACEBOOK, FACEBOOK_COL_START)] for objs, service, offset in l: for i, value in enumerate(objs): if value: obj, created = SocialAccount.objects.get_or_create( social_profile=profile, service=service, value=value, ) # The first object added/updated gets a priority of 0, all # others get a 1 if i == 0: obj.priority = 0 else: obj.priority = 1 What kind of object is this 'obj'? After you make a change to it, do you need to tell it to write to a database or something? What you could try is changing the priority assignments to, say, 2 and 3. That would tell you that it's making the change. But if the intention is to have the first successful one at priority 0 and all others at priority 1 (which is what the comment implies), then I'd write it like this: def create_socialaccount(profile, urls, twitters, facebooks, statuses=None): Add or update all the social accounts linked to the 'profile' l = [(urls, SocialAccount.HOMEPAGE, HOMEPAGE_COL_START), (twitters, SocialAccount.TWITTER, TWITTER_COL_START), (facebooks, SocialAccount.FACEBOOK, FACEBOOK_COL_START)] for objs, service, offset in l: prio = 0 for value in objs: if value: obj, created = SocialAccount.objects.get_or_create( social_profile=profile, service=service, value=value, ) # The first object added/updated gets a priority of 0, all # others get a 1 obj.priority = prio prio = 1 It's not clear whether first means first of each type or first overall. For instance, if someone has three twitters and two facebooks, should one twitter and one facebook be given priority 0, or should one twitter get prio 0 and everything else prio 1? I've coded it for the former, but you could easily make it the latter by simply shifting the prio = 0 statement one line further up (and unindenting it), thus putting it before the entire loop. Does that help, at all? ChrisA -- https://mail.python.org/mailman/listinfo/python-list
[issue23225] selectors: raise an exception if the selector is closed
Charles-François Natali added the comment: RuntimeError sounds better to me (raising ValueError when no value is provided, e.g. in select() sounds definitely strange). -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23225 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1250] Building external modules using Sun Studio 12
Erik O'Shaughnessy added the comment: Still seeing this issue on Solaris 11 with Solaris Studio compilers when building pandas 0.15.2 and matplotlib 1.4.2. -- nosy: +Erik.O'Shaughnessy ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1250 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: Broken IF statement
Thanks Chris. This definitely helps. I will test it and see what happens. In terms of the previous code, what it was intended to do wasn't actually happening. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 3 regex woes (parsing ISC DHCPD config)
- Original Message - From: Jason Bailey jbai...@emerytelcom.com To: python-list@python.org Cc: Sent: Monday, January 12, 2015 7:20 PM Subject: Python 3 regex woes (parsing ISC DHCPD config) Hi all, I'm working on a Python _3_ project that will be used to parse ISC DHCPD configuration files for statistics and alarming purposes (IP address pools, etc). Anyway, I'm hung up on this one section and was hoping someone could provide me with some insight. My script first reads the DHCPD configuration file into memory - variable filebody. It then utilizes the re module to find the configuration details for the wanted shared network. The config file might look something like this: ## shared-network My-Network-MOHE { subnet 192.168.0.0 netmask 255.255.248.0 { option routers 192.168.0.1; option tftp-server-name 192.168.90.12; pool { deny dynamic bootp clients; range 192.168.0.20 192.168.7.254; } } } shared-network My-Network-CDCO { subnet 192.168.8.0 netmask 255.255.248.0 { option routers 10.101.8.1; option tftp-server-name 192.168.90.12; pool { deny dynamic bootp clients; range 192.168.8.20 192.168.15.254; } } } shared-network My-Network-FECO { subnet 192.168.16.0 netmask 255.255.248.0 { option routers 192.168.16.1; option tftp-server-name 192.168.90.12; pool { deny dynamic bootp clients; range 192.168.16.20 192.168.23.254; } } } ## Suppose I'm trying to grab the shared network called My-Network-FECO from the above config file stored in the variable 'filebody'. First I have my variable 'shared_network' which contains the string My-Network-FECO. I compile my regex: m = re.compile(r^(shared\-network ( + re.escape(shared_network) + r) \{((\n|.|\r\n)*?)(^\})), re.MULTILINE|re.UNICODE) I search for regex matches in my config file: m.search(filebody) Unfortunately, I get no matches. From output on the command line, I can see that Python is adding extra backslashes to my re.compile string. I have added the raw 'r' in front of the strings to prevent it, but to no avail. Thoughts on this? Will the following work for you? My brain shuts down when I try to read your regex, but I believe you also used a non-greedy match. Python 3.4.2 (default, Nov 20 2014, 13:01:11) [GCC 4.7.2] on linux Type help, copyright, credits or license for more information. cfg = shared-network My-Network-MOHE { ... subnet 192.168.0.0 netmask 255.255.248.0 { ... option routers 192.168.0.1; ... option tftp-server-name 192.168.90.12; ... pool { ... deny dynamic bootp clients; ... range 192.168.0.20 192.168.7.254; ... } ... } ... } ... ... shared-network My-Network-CDCO { ... subnet 192.168.8.0 netmask 255.255.248.0 { ... option routers 10.101.8.1; ... option tftp-server-name 192.168.90.12; ... pool { ... deny dynamic bootp clients; ... range 192.168.8.20 192.168.15.254; ... } ... } ... } ... ... shared-network My-Network-FECO { ... subnet 192.168.16.0 netmask 255.255.248.0 { ... option routers 192.168.16.1; ... option tftp-server-name 192.168.90.12; ... pool { ... deny dynamic bootp clients; ... range 192.168.16.20 192.168.23.254; ... } ... } ... } import re re.findall(rshared\-network (.+) \{?, cfg) ['My-Network-MOHE', 'My-Network-CDCO', 'My-Network-FECO'] -- https://mail.python.org/mailman/listinfo/python-list
[issue23199] libpython27.a in amd64 release is 32-bit
Zach Welch added the comment: The libpython27.a is an actual 32-bit version, as confirmed by running objdump -t on it. It reports the sections' file format as pe-i386 instead of pe-x86-64. I am only using it for building for the 64-bit target, so I cannot confirm its viability for 32-bit builds. To build 64-bit Windows binaries, you need a MinGW-w64 toolchain (which is a completely separate project from the original MinGW project). The target triplet is x86_64-w64-mingw32. I cannot speak to the stability of the MinGW-w64 library interface, but I would expect it to be stable. To wit, I would be shocked if future changes required regeneration of third-party .a files. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23199 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: Comparisons and sorting of a numeric class....
On 01/07/2015 04:04 PM, Ethan Furman wrote: On 01/06/2015 07:37 PM, Andrew Robinson wrote: Explain; How does mere subclassing of bool break the contract that bool has? eg: What method or data would the superclass have that my subclass would not? bool's contract is that there are only two values (True and False) and only one instance each of those two values (True and False). If bool were subclassable, new values could be added with either completely different values (PartTrue) or with more of the same value (True, ReallyTrue, AbsolutelyTrue) -- hence, broken contract. -- ~Ethan~ Huh? I'm not adding any values when I merely subclass bool ; and even if the subclass could be instantiated -- that's doesn't mean a new value or instance of the base class (bool) must exist. For I could happily work with a new subclass that contains no new data, but only an already _existing instance_ of 'True' or 'False_'_ as its value source. That means there is no new value... but at most (and even that could be worked around) a new instance of a subclass containing an existing instance of it's base class. Note: Guido only mentioned that he didn't want multiple instances of the base class bool -- But that's not technically the same as objecting to a subclass having an instance which CONTAINS an original bool instance and not a new one. There are other ways Guido could have modified the Python language to prevent creation of new values without preventing the creation of a subclass -- if that's what he was really afterSo -- no -- I disagree with you. Subclassing is allowed in many other OOP languages (not just C++) when working with singletons, and dualtons, n-tons... and the very PURPOSE of those objects is to prevent multiple instances, or spreading of control. BUT -- Most object oriented languages I know of -- allow as standard practice, subclassing of n-tons -- while (often) simultaneously controlling or even eliminating the number of instances a subclass may have / and or the values it may take. eg: depending on how flexible the type/class definition of a language is -- languages handle sub-classing of singletons differently. Besides, a contract for a class can only be assumed to be valid for code designed for that specific class -- not code made for a subclass; The contract for bool simply says nothing about programs designed for any other classes that bool is found inside of -- either as a subclass or a subelement; eg: I can still put bool inside another object with different methods: eg: I just write: (False,) as proof -- so Guido couldn't possibly have been trying to limit the methods which can operate on bool or the number of links to bool. So I don't understand why Guido cared to restrict subclassing of bool -- and what the contract you mention has to do with it -- eg: what was his actual goal ? Was it memory conservation, or compatability of built-in return types -- or what ? There is no written 'contract' saying exactly what Guido's design objectives were in detail and more importantly 'WHY'; but Guido only said that subclassing instances allowed a 'back door' (not that subclassiing itself was bad, just that it allowed some side effect...) to whatever Guido really didn't want to happen. Python generally allows subclassing of singleton instances; so that makes 'bool' is an arbitrary exception to the general rule which Guido decided to make... and he did so without any very clear explanation as to why. eg: he cited what C/C++ *must *do as part of his reasoning -- but C/C++ can apparently do something that Guido thought it couldn't (Guido was flat wrong) and for that reason, I really wonder if Guido's decision was some kind of spur of the moment erroneous epiphany -- bolstered by the fact that he said I realized last night... like something he had never thought of before, or thought through carefully https://mail.python.org/pipermail/python-dev/2002-March/020822.html And worse, Guido's problem even apparently extends to making 'duck types' which other writers in this thread have been proposing I do. eg: They, too, are going against canonical Guido's epiphany night... Of course, you can define your own subclass of int similar to the bool class I show in the PEP, and you can give it any semantics you want -- but that_would also defeat the purpose of having a standard bool_. Not to mention, that Charles Bool's two initial values True and False are NOT the only ones used in computer engineering and science; for boolean logic only became useful at a time when engineers and mathematicians realized that at least a third type, AKA: 'Don't care' -- was necessary for doing correctness testing of logic in a tractable way. So -- Guido arbitrarily chose to make bool based on a historical curiosity that never has been mainstream in logic analysis. eg: He based it on a beta quality revision of boolean theory
Re: Comparisons and sorting of a numeric class....
On Tue, Jan 13, 2015 at 9:27 AM, Andrew Robinson andr...@r3dsolutions.com wrote: Huh? I'm not adding any values when I merely subclass bool ; and even if the subclass could be instantiated -- that's doesn't mean a new value or instance of the base class (bool) must exist. For I could happily work with a new subclass that contains no new data, but only an already existing instance of 'True' or 'False' as its value source. That means there is no new value... but at most (and even that could be worked around) a new instance of a subclass containing an existing instance of it's base class. If you subclass bool and instantiate your subclass, you have made a new instance of bool, because every instance of a subclass is an instance of its superclass. The Python bool type has the following invariant, for any object x: assert not isinstance(x, bool) or x is True or x is False (You can fiddle with this in Py2 by rebinding the names True and False, but you could replace those names with (1==1) and (1==0) if you want to be completely safe. Likewise, the name bool could be replaced with (1==1).__class__ to avoid any stupidities there. But conceptually, that's the invariant.) Subclassing bool breaks this invariant, unless you never instantiate the subclass, in which case it's completely useless. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
What does pip install do?
Folks, I've learned a lot today about python packaging and stuff, thanks to a couple of good websites. I've learned how to install a package from PyPi with pip, choose which version, upgrade it, uninstall it, use virtualenv, BUT I'm still asking myself: what does pip install *concretely* do on my virtual environment? It seems to add a directory in the /site-packages directory, but what does it do when for example command-line scripts are shipped with it? Is something else happening in the background? Neither does the Python Packaging Authority website (https://pip.pypa.io/en/latest/user_guide.html) nor the python-packaging-user-guide (http://python-packaging-user-guide.readthedocs.org/en/latest/installing.html) nor the Installing python packages from the python docs (https://docs.python.org/3/installing/) seem to provide an answer to this question. Or did I simply miss it? Thanks! Fabien -- https://mail.python.org/mailman/listinfo/python-list
Re: I must be missing something obvious in installing Python 3.4.2...
Not sure that would be a good idea: There are 22 such keys, as opposed to only two keys with Windows ID strings that don't end in nulls. I found this article: http://www.swarley.me.uk/blog/2014/04/23/python-pip-and-windows-registry-corruption/ with the comment If you are happy to completely remove any problematic keys, and accept any associated breakages that may occur, then this is the easiest solution. I am concerned that if I change these keys, something else might break and I have no easy way of figuring out what. -- https://mail.python.org/mailman/listinfo/python-list
[issue23185] add inf and nan to math module
Guido van Rossum added the comment: Should inf and nan be added to cmath too? It has e and pi and isnan() and isinf()... Also complex(0, math.nan) a value that is printed as nanj and complex(nanj) parses and returns such a value, so the point could be made that there should be a constant named complex.nanj. -- nosy: +gvanrossum ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23185 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue23226] Add float linspace recipe to docs
New submission from Andrew Barnert: In a recent thread on python-ideas (https://mail.python.org/pipermail/python-ideas/2015-January/030817.html), it was concluded that Python should not have a range-like type for floats in the stdlib, but there should be some simple discussion of the alternatives in the docs. The attached diff describes the issues, demonstrates the simplest reasonable algorithm, and links to a recipe on ActiveState (which builds the same algorithm into a lazy sequence, and links to other recipes with different alternatives). -- assignee: docs@python components: Documentation files: stdtypes.rst.diff keywords: patch messages: 233893 nosy: abarnert, docs@python priority: normal severity: normal status: open title: Add float linspace recipe to docs type: enhancement versions: Python 3.5 Added file: http://bugs.python.org/file37684/stdtypes.rst.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23226 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: What does pip install do?
On Tue, Jan 13, 2015 at 9:35 AM, Fabien fabien.mauss...@gmail.com wrote: I've learned a lot today about python packaging and stuff, thanks to a couple of good websites. I've learned how to install a package from PyPi with pip, choose which version, upgrade it, uninstall it, use virtualenv, BUT I'm still asking myself: what does pip install *concretely* do on my virtual environment? As far as I know, it's equivalent to three steps: 1) Download the appropriate version of a package (the latest, if you didn't say otherwise) 2) Extract that package 3) Run 'python setup.py'. What setup.py does is up to the package, but for a pure-Python package it should simply create something in site-packages. It might do a lot more, though - compiling C or Fortran code, for instance. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
[issue17911] traceback: add a new thin class storing a traceback without storing local variables
Robert Collins added the comment: w.r.t. a new linecache interface, it looks like we need two attributes from f_globals: __name__ and __loader__, so that we can eventually call __loader__.get_source(__name__). One small change (to let me focus on traceback) would be to add another kw argument to the existing calls that take module_globals, called e.g. get_source, which would be a simple callable (source = get_source()). For the deferred linecache situation, we'd then create partial(f_globals.__loader__.get_source, f_globals.__name__) and keep that around until we need the source. We could even abstract that out into a function in linecache to keep the knowledge in one place. Another way to tackle this would be to add a new function to linecache that lazily seeds the cache: it would stash the get_source method and the name against the filename, and when getline[s] is called actually invoke it. I think the second way is a bit nicer myself. What do folk think? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17911 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22729] `wait` and `as_completed` depend on private api
Andrew Svetlov added the comment: -1. Sorry, I don't see the reason for making custom `Future` class. Can you elaborate? -- nosy: +asvetlov ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22729 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22286] Allow backslashreplace error handler to be used on input
Changes by Martin Panter vadmium...@gmail.com: -- nosy: +vadmium ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22286 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: I must be missing something obvious in installing Python 3.4.2...
Fixed it! The aforementioned article is correct. I downloaded the RegDelNull program mentioned in the article (http://technet.microsoft.com/en-us/sysinternals/bb897448.aspx) and ran it on hkcr, hkcu, hklm, hku, and hkcc (short for HKEY_CLASSES_ROOT, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, HKEY_USERS, and HKEY_CURRENT_CONFIG), respectively. It deleted a bunch of keys. Rerunning the program you posted earlier revealed no keys with embedded nulls in their names, and ensurepip now works. I have no idea how these keys got there. For all I know they are the result of malware. I think it would be worthwhile changing the Python code to detect nulls and perhaps issue a warning that directs people to this article or something like it. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 3 regex?
'Some people, when confronted with a problem, think I know, I'll use regular expressions. Now they have two problems.' - Jamie Zawinski. This statement is one of my favorite examples of powerful propaganda, which has scared more folks away from regexps than even the Upright Citizens Brigade could manage with their Journey through the center of gas giant #7 and it's resulting aggravated assault on American coinage! I wonder if Jamie's conclusions are a result of careful study, or merely, an attempt to resolve his own cognitive dissonance? Of course, if the latter is true, then i give him bonus points for his use of the third person to veil his own inadequacies -- nice Jamie, *very* nice! Rick it sounds like you're accusing Jamie of cowardice resulting in sour grapes? Indeed! The problem with statements like his is that, the ironic humor near the end *fortifies* the argument so much that the reader forgets the limits of the harm (quantified as: some people) and immediately accepts the consequences as effecting all people who choose to use regexps, or more generally, accepts the argument as a universal unbounded truth. Besides, who would want to be a member of a group for which the individuals are too stupid to know good choices from bad choices? HA, PEER PRESSURE, IT'S A POWERFUL THING! But there is more going on here than just mere slight of forked tongue my friends, because, even the most accomplished propagandist cannot fool *most* of the people. No, this type of powerful propaganda only succeeds when the subject matter is both cryptic *AND* esoteric. For instance, in the following example, i contrive a similarly ironic statement to showcase the effects of such propaganda, but one that covers a subject matter in which laymen either: already understand, or, can easily attain enough knowledge to appreciate the humor. # Ironic Twist # # Some diabetics, when confronted with hunger, think I# # know, I'll eat a box of sugar cookies. -- now they have # # two problems!' # Wait a minute Rick! After eating the cookies the diabetic would not longer be hungry, so how could he have two problems? Your logic is flawed! Au Contraire! Read the statement carefully, I said: When *CONFRONTED* with hunger -- the two problems (and the eventual side effect) exist at the *MOMENT* the diabetic considers eating the cookies. PROBLEM1: Need to eat! PROBLEM2: Cookies raise glucose too quickly In this example, even a layman would understand that the statement is meant to showcase the irony of resolving a problem (hunger) with a solution (eating a box of cookies) that results in the undesirable outcome of (hyperglycemia). And while this statement, and the one about regexps, both contain a factual underlying truth (basically that negative side effects should be avoided) the layman will lack the esoteric knowledge of regexps to confirm the factual basis for himself, and will instead blindly adopt the propagandist assertion as truth, based solely on the humorous prowess of the propagandist. The most effective propaganda utilizes the sub-conscience. You see, the role of propaganda is to modify behavior, and it is a more prevalent and powerful tool than most people realize! The propagandist will seek to control you; he'll use your ignorance against you; but you didn't notice because he made you laugh! WHO'S LAUGHING NOW? -- YOU MINDLESS ROBOTS! But what's so evil about that Rick? He scared away a few feeble minded folks. SO WHAT! I argue that we are all feeble minded in any subject we have not yet mastered. His propaganda (be it intentional or not) is so powerful that it defeats the neophyte before they can even begin. Because it gives them the false impression that regexps are only used by foolish people. Yes, i'll admit, regexps are very cryptic, but once you grasp their intricacies, you appreciate the succinctness of there syntax, because, what makes them so powerful is not only the extents of their pattern matching abilities, but their conciseness. -- https://mail.python.org/mailman/listinfo/python-list
[issue15836] unittest assertRaises should verify excClass is actually a BaseException class
Changes by Martin Panter vadmium...@gmail.com: -- nosy: +vadmium ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15836 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue15836] unittest assertRaises should verify excClass is actually a BaseException class
Changes by Berker Peksag berker.pek...@gmail.com: -- nosy: +berker.peksag stage: patch review - commit review versions: +Python 3.4 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15836 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: Comparisons and sorting of a numeric class....
On Tue, Jan 13, 2015 at 12:59 PM, Andrew Robinson andr...@r3dsolutions.com wrote: There is no need to copy data from an initialized superclass instance into a subclass instance that has no new data, but only rebind -- or add a binding/proxy object -- to bind the superclass instance to the subclass methods. eg: what is now standard practice to create a new copy of the superclass: class myFalse( bool ): __new__( self, data ): return super( myFalse, self ).__new__(self,data) Could be replaced by a general purpose proxy meant to handle singleton subclassing: class myFalse( bool ): __new__( self ): return bind_superinstance_to_subclass( False, myFalse ) I don't understand. What do you expect this to be doing? Are you trying to replace the original False with your new subclass? he Python bool type has the following invariant, for any object x: assert not isinstance(x, bool) or x is True or x is False I mean, even right now -- with the language as-is -- let's define something that blatantly creates a new instance of something neither an actual instance of True nor False, and make that x -- and see if your assertion catches it: Python 2.7.5 (default, May 29 2013, 02:28:51) [GCC 4.8.0] on linux2 Type help, copyright, credits or license for more information. x=(False,) assert not isinstance(x, bool) or x is True or x is False LOL ... no exception was raised... and we know if the assertion Failed, an exception ought to be raised: The assertion did not fail. There are three parts, and as long as one of them is true, the assertion will pass: 1) x isn't an instance of bool 2) x is the object known as True 3) x is the object known as False You just gave an example of the first part of the invariant. That's an instance of tuple, which is not a subclass of bool, ergo isinstance(x, bool) returns False, negating that makes True, and the assertion passes. [1] So -- your assertion, at least as shown, is pretty useless in helping determine why subclassing is not allowed, or instances of subclasses that are not distinct from their superclasses existing instance. It exactly defines the nature of Python's bool type: there are precisely two instances of it. ChrisA [1] Which puts me in mind of https://www.youtube.com/watch?v=D0yYwBzKAyY -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 3 regex?
On Tue, Jan 13, 2015 at 10:47 AM, Rick Johnson rantingrickjohn...@gmail.com wrote: WHO'S LAUGHING NOW? -- YOU MINDLESS ROBOTS! It's very satisfying when mindless robots laugh. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
[issue9587] unittest.assertRaises() return the raised exception
Changes by Martin Panter vadmium...@gmail.com: -- nosy: +vadmium ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9587 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19777] Provide a home() classmethod on Path objects
Antoine Pitrou added the comment: I've committed the patch, thank you! -- resolution: - fixed stage: needs patch - resolved status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19777 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22977] Unformatted “Windows Error 0x%X” exception message on Wine
Martin Panter added the comment: This patch includes a test case, based on Eryksun’s exception code -- Added file: http://bugs.python.org/file37686/win-error-format-v2.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22977 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: Python 3 regex?
On Monday, January 12, 2015 at 7:55:32 PM UTC-6, Mark Lawrence wrote: On 12/01/2015 23:47, Rick Johnson wrote: 'Some people, when confronted with a problem, think I know, I'll use regular expressions. Now they have two problems.' - Jamie Zawinski. [snip] If you wish to use a hydrogen bomb instead of a tooth pick feel free, I won't lose any sleep over it. Meanwhile I'll get on with writing code, and for the simple jobs that can be completed with string methods I'll carry on using them. When that gets too complicated I'll reach for the regex manual, knowing full well that there's enough data in books and online to help even a novice such as myself get over all the hurdles. If that isn't good enough then maybe a full blown parser, such as the pile listed here [snip] Mark, if you're going to quote me, then at least quote me in a manner that does not confuse the content of my post. The snippet you posted was not a statement of mine, rather, it was a quote that i was responding to, and without any context of my response, what is the point of quoting anything at all? It would be better to quote nothing and just say @Rick, then to quote something which does not have any context. Every python programmer worth his *SALT* should master the following three text processing capabilities of Python, and he should know how and when to apply them (for they all have strengths and weaknesses): (1) String methods: Simplistic API, but with limited capabilities -- but never underestimate the possibilities! (2) Regexps: Great for pattern matching with a powerful and concise syntax, but highly cryptic and unintuitive for the neophyte (and sometimes even the guru! *wink*). (3) Parsers: Great for extracting deeper meaning from text, but if pattern matching is all you need, then why not use (1) or (2) -- are you scared or uninformed? We can easily forgive a child who is afraid of the dark; the real tragedy of life is when men are afraid of the light. -- Plato IMHO, if you seek to only match patterns, then string methods should be your first choice, however, if the pattern is too difficult for string methods, then graduate to regexps. If you need to extract deeper meaning from text, by all means utilize a parser. But above all, don't fall for these religious teachings about how regexps are too difficult for mortals -- that's just hysteria. If you follow the outline i provided above, you should find Python's text processing Nirvana. -- https://mail.python.org/mailman/listinfo/python-list
Re: Reg: scrappring error
On 1/11/2015 9:27 PM, Sushanth wrote: SNIP urllib2.HTTPError: HTTP Error 302: The HTTP server returned a redirect error that would lead to an infinite loop. Looks like the server has a link on this page pointing back to itself or somesuch. Does this help? Emile -- https://mail.python.org/mailman/listinfo/python-list
[issue23226] Add float linspace recipe to docs
Andrew Barnert added the comment: As suggested by the review: removing unnecessary parenthetical, changing ulp to digit, and fixing the recipe link. -- Added file: http://bugs.python.org/file37685/stdtypes.rst.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23226 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: Comparisons and sorting of a numeric class....
On 01/12/2015 02:35 PM, Chris Angelico wrote: On Tue, Jan 13, 2015 at 9:27 AM, Andrew Robinson andr...@r3dsolutions.com wrote: Huh? I'm not adding any values when I merely subclass bool ; and even if the subclass could be instantiated -- that's doesn't mean a new value or instance of the base class (bool) must exist. For I could happily work with a new subclass that contains no new data, but only an already existing instance of 'True' or 'False' as its value source. That means there is no new value... but at most (and even that could be worked around) a new instance of a subclass containing an existing instance of it's base class. Hmmm That may be true in python, as it is now, but that doesn't mean that Guido had to leave it that way when he decided to change the language to single out bool, and make it's subclassing rules abnormal in the first place. He was changing the language when he made the decision after all !! What I am wanting to know is WHY did Guido think it so important to do that ? Why was he so focused on a strict inability to have any instances of a bool subclass at all -- that he made a very arbitrary exception to the general rule that base types in Python can be subclassed ? There's no reason in object oriented programming principles in general that requires a new subclass instance to be a COMPLETELY DISTINCT instance from an already existing superclass instance nor, have I ever seen Guido say that Python is designed intentionally to force this to always be the case... so I'm not sure that's its anything more than a non guaranteed implementation detail that Python acts the way you say it does I don't see, within Python, an intrinsic reason (other than lack of support/foresight in the historical evolution of Python to date), as to why a subclass couldn't be instanted with the data coming from an *already* existing instance of it's superclass. There is no need to copy data from an initialized superclass instance into a subclass instance that has no new data, but only rebind -- or add a binding/proxy object -- to bind the superclass instance to the subclass methods. eg: what is now standard practice to create a new copy of the superclass: class myFalse( bool ): __new__( self, data ): return super( myFalse, self ).__new__(self,data) Could be replaced by a general purpose proxy meant to handle singleton subclassing: class myFalse( bool ): __new__( self ): return bind_superinstance_to_subclass( False, myFalse ) he Python bool type has the following invariant, for any object x: assert not isinstance(x, bool) or x is True or x is False Really !??? Where, in the language definition, did Guido explicitly guarantee this invariant ? (You can fiddle with this in Py2 by rebinding the names True and False, but you could replace those names with (1==1) and (1==0) if you want to be completely safe. Likewise, the name bool could be replaced with (1==1).__class__ to avoid any stupidities there. But conceptually, that's the invariant.) Interesting ... but rebinding True and False, won't extend the new capabilities to modules which are imported. They will still, I think, be bound to the old True and False values. I know, for example -- I can redefine the class bool altogether; although the type string becomes 'main.bool' -- none the less, it does not exist in default scope when I switch namespaces; eg: in a module being imported 'bool' still means the old version of class bool. I have to do something more drastic, like __builtins__.bool = class bool(int): ... And then, even modules will recognize the changed class definition. Hmmm. __builtins__.True='yes' True 'yes' However, such actions -- I think -- are rather drastic; because they produce situations where another third party library in competition with mine might also have need of subclassing 'bool' and then we are in a fight for a static binding name with winner takes all ... rather than sharing dynamically compatible definitions based on subclasses. Subclassing bool breaks this invariant, unless you never instantiate the subclass, in which case it's completely useless. Well we can't subclass bool now -- and the language would have to change in order for us to be able to subclass it; So -- I don't think your assert statement guarantees anything if case the language changes... On the other hand, I also don't see that your assert statement would ever return False even as it is written --- even if the object (x) was sub-classed or a totally different object than True or False and so I *definitely* don't see why your assert statement would Fail if the language changed in one of several subtle ways I think it could. I mean, even right now -- with the language as-is -- let's define something that blatantly creates a new instance of something neither an actual instance of True nor False, and make that x -- and see if your assertion catches it:
Re: Track down SIGABRT
I have a long-running python/CherryPy Web App server process that I am running on Mac OS X 10.8.5. Python 2.7.2 running in 32-bit mode (for now, I have the code in place to change over to 64 bit, but need to schedule the downtime to do it). On the 6th of this month, during normal operation from what I can tell, and after around 33 days of trouble-free uptime, the python process crashed with a SIGABRT. I restarted the process, and everything looked good again until yesterday, when it again crashed with a SIGABRT. Can you monitor disk and memory on the host? Perhaps it is climbing towards an unacceptable value right before crashing. Do you have the option of stopping and starting your process every night or every week? -- https://mail.python.org/mailman/listinfo/python-list
Re: Comparisons and sorting of a numeric class....
Hmm LOL ... no exception was raised... and we know if the assertion Failed, an exception ought to be raised: The assertion did not fail. There are three parts, and as long as one of them is true, the assertion will pass: 1) x isn't an instance of bool 2) x is the object known as True 3) x is the object known as False You just gave an example of the first part of the invariant. That's an instance of tuple, which is not a subclass of bool, ergo isinstance(x, bool) returns False, negating that makes True, and the assertion passes. [1] Uh ... yeah... and so an assertion meant to test if something is or is not a bool let a non-bool pass the assertion. That seems rather ... silly, and useless, ... and so I really doubt the assertion -- based on it's behavior --can distinguish an actual bool from a subclassed one or a totally unrelated object ... I mean, let's start by testing if x as an actual boolean will cause the assertion to act differently from a fake-non bool object which we already tried. x=True x=True assert not isinstance(x, bool) or x is True or x is False Wow. No difference in behavior. So (as a test) it can't distinguish between an actual boolean and a faked one. They both pass the assertion. So -- What good is this assertion? It tells us nothing useful when executed. Also what if we put in a subclass Instead of pretending what if -- let's actually REPLACE python's built in bool class with an emulation that ALLOWS subclassing and THEN let's TEST my hypothesis that the assert statement you gave me can't tell the difference between bools any anthing else by it's actions... ( h ... another back-door that Guido forgot about... or perhaps purposely left open...) class bool( int ): def __new__(self,data): return super( bool, self).__new__(self, [0,1][data!=0] ) def __repr__(self): return [ 'True', 'False' ][self0] __builtins__.bool=bool __builtins__.True=bool( 1==1 ) __builtins__.False=bool( 1==0 ) And, running it in the python interpreter... class bool( int ): ... def __new__(self,data): return super( bool, self).__new__(self, [0,1][data!=0] ) ... def __repr__(self): return [ 'True', 'False' ][self0] ... __builtins__.bool=bool __builtins__.True=bool( 1==1 ) __builtins__.False=bool( 1==0 ) type(True) class '__main__.bool' I now have proof that the replacement succeeded. So let's subclass bool !!! class subBool(bool): pass ... and now, let's see if your assertion believes a subclass of bool is a bool... x=subBool(0) assert not isinstance(x, bool) or x is True or x is False Wow. No change. So -- it doesn't fail when the object ISN'T a bool, it doesn't fail when the object IS a bool, and it doesn't fail when the object is a subclass of bool; and #1 matches that of a True bool! or if #1 doesn't match that of a true bool. isinstance( x, bool ) , True isinstance( True, bool ) True Therefore, your explantion ( so far ) of how to interpret the invariant, is consistent with it explicitly and *precisely* 'passing' all possible instances of subclasses of bool, all instances of non-bools, and all instances of bools. Yes, the assertion you chose passes precisely ANYTHING! (facetous use of precise.). It's a worthless assertion in the sense that it has no explicit logic to DISTINGUISH what Guido/Python does want a bool to be from what you have said and implied Guido doesn't want (even though I've never seen Guido agree with you on this assertion thing...) . So -- your assertion, at least as shown, is pretty useless in helping determine why subclassing is not allowed, or instances of subclasses that are not distinct from their superclasses existing instance. It exactly defines the nature of Python's bool type: there are precisely two instances of it. ChrisA [1] Which puts me in mind of https://www.youtube.com/watch?v=D0yYwBzKAyY Uh, no, -- your assertion excludes nothing you've been telling me is not a bool by contract -- so it doesn't 'define' anything precisely because it's by definition inaccurate. it's simply an invariant form of spam with three terms you can interpret any way you like. Where did you get that assertion from anyway and how is it related to Guido and formal definitions of the python language ??? Are you really trying to imply that Guido wrote that assertion ? On Tue, Jan 13, 2015 at 12:59 PM, Andrew Robinson andr...@r3dsolutions.com wrote: There is no need to copy data from an initialized superclass instance into a subclass instance that has no new data, but only rebind -- or add a binding/proxy object -- to bind the superclass instance to the subclass methods. eg: what is now standard practice to create a new copy of the superclass: class myFalse( bool ): __new__( self, data ): return super( myFalse, self ).__new__(self,data) Could be replaced by a general purpose proxy meant to handle singleton subclassing: class myFalse( bool ): __new__( self ): return
Re: Python 3 regex?
On 12/01/2015 23:47, Rick Johnson wrote: 'Some people, when confronted with a problem, think I know, I'll use regular expressions. Now they have two problems.' - Jamie Zawinski. [normal cobblers snipped] If you wish to use a hydrogen bomb instead of a tooth pick feel free, I won't lose any sleep over it. Meanwhile I'll get on with writing code, and for the simple jobs that can be completed with string methods I'll carry on using them. When that gets too complicated I'll reach for the regex manual, knowing full well that there's enough data in books and online to help even a novice such as myself get over all the hurdles. If that isn't good enough then maybe a full blown parser, such as the pile listed here http://nedbatchelder.com/text/python-parsers.html ? -- 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
[issue23224] LZMADecompressor object is only initialized in __init__
Martin Panter added the comment: A patch for this might conflict with the LZMA patch for Issue 15955, so it would be simplest to wait for that issue to be resolved first -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23224 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22932] email.utils.formatdate uses unreliable time.timezone constant
R. David Murray added the comment: The tests fail for me the same way both before and after the code patch: == FAIL: test_formatdate (test.test_email.test_utils.FormatDateTests) -- Traceback (most recent call last): File /home/rdmurray/python/p34/Lib/test/support/__init__.py, line 1525, in inner return func(*args, **kwds) File /home/rdmurray/python/p34/Lib/test/test_email/test_utils.py, line 145, in test_formatdate self.assertEqual(string, 'Mon, 01 Dec 2014 15:00:00 -') AssertionError: 'Mon, 01 Dec 2014 14:00:00 -' != 'Mon, 01 Dec 2014 15:00:00 -' - Mon, 01 Dec 2014 14:00:00 - ? ^ + Mon, 01 Dec 2014 15:00:00 - ? ^ == FAIL: test_formatdate_with_localtime (test.test_email.test_utils.FormatDateTests) -- Traceback (most recent call last): File /home/rdmurray/python/p34/Lib/test/support/__init__.py, line 1525, in inner return func(*args, **kwds) File /home/rdmurray/python/p34/Lib/test/test_email/test_utils.py, line 157, in test_formatdate_with_localtime self.assertEqual(string, 'Mon, 01 Dec 2014 18:00:00 +0300') AssertionError: 'Mon, 01 Dec 2014 18:00:00 +0400' != 'Mon, 01 Dec 2014 18:00:00 +0300' - Mon, 01 Dec 2014 18:00:00 +0400 ? ^ + Mon, 01 Dec 2014 18:00:00 +0300 ? ^ -- components: +email ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22932 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: Namespace puzzle, list comprehension fails within class definition
On Mon, 12 Jan 2015 12:40:13 -0800, Ethan Furman wrote: On 01/12/2015 12:25 PM, John Ladasky wrote: d = {0:a, 1:b, 2:c, 3:d} e = [d[x] for x in (0,2)] class Foo: f = {0:a, 1:b, 2:c, 3:d} print(f) g = [f[x] for x in (0,2)] In Foo 'f' is part of an unnamed namespace; the list comp 'g' has its own namespace, effectively making be a nonlocal; class name lookup skips nonlocal namespaces. Actually, no it doesn't. py def factory(): ... x = 23 ... class Inner(object): ... print('x is', x) ... return Inner ... py o = factory() x is 23 The problem is that *functions* lookup don't include the class body in their scope. This is by design, and goes back to Python 1.5 or older: [steve@ando ~]$ python1.5 Python 1.5.2 (#1, Aug 27 2012, 09:09:18) [GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam class Outer: ... x = 23 ... f = lambda: x+1 ... y = f() ... Traceback (innermost last): File stdin, line 1, in ? File stdin, line 4, in Outer File stdin, line 3, in lambda NameError: x Workaround: use an actual for loop. Sad but true. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
[issue10552] Tools/unicode/gencodec.py error
Martin Panter added the comment: Here is a new version of Kuchling’s patch. I restored some mapping files which do not give any errors (including the mac_turkish codec, which is actually documented), and removed both readme files. -- components: +Unicode nosy: +haypo, vadmium versions: +Python 3.4 Added file: http://bugs.python.org/file37687/10552-remove-apple-files-v2.txt ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10552 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: Comparisons and sorting of a numeric class....
On Mon, Jan 12, 2015 at 9:16 PM, Andrew Robinson andr...@r3dsolutions.com wrote: Instead of pretending what if -- let's actually REPLACE python's built in bool class with an emulation that ALLOWS subclassing and THEN let's TEST my hypothesis that the assert statement you gave me can't tell the difference between bools any anthing else by it's actions... ( h ... another back-door that Guido forgot about... or perhaps purposely left open...) class bool( int ): def __new__(self,data): return super( bool, self).__new__(self, [0,1][data!=0] ) def __repr__(self): return [ 'True', 'False' ][self0] __builtins__.bool=bool __builtins__.True=bool( 1==1 ) __builtins__.False=bool( 1==0 ) Your posts are so wordy that I'm not even going to try to respond to all of them, but this is an interesting point that bears explanation. The reason you can reassign True and False in Python 2.x is for backward compatibility with scripts that predated the built-in bool type and would do things like: True = 1 False = 0 However, this longstanding wart was fixed in Python 3 by making True and False keywords: True = 42 File stdin, line 1 SyntaxError: can't assign to keyword __builtins__.True = 42 File stdin, line 1 __builtins__.True = 42 ^ SyntaxError: invalid syntax -- https://mail.python.org/mailman/listinfo/python-list
Re: Comparisons and sorting of a numeric class....
On Tue, Jan 13, 2015 at 3:57 PM, Steven D'Aprano st...@pearwood.info wrote: On Tue, 13 Jan 2015 09:35:43 +1100, Chris Angelico wrote: Subclassing bool breaks this invariant, unless you never instantiate the subclass, in which case it's completely useless. Not necessarily. A class that you never instantiate, but use as an object itself, is another way of implementing the singleton design pattern. Obviously all the methods have to be class methods, but it is doable. But wacky exceptions like subclasses that aren't instantiated aside, normally if you subclass something you intend to instantiate it. True, I should have said probably useless instead of completely useless. :) There's always *something* you could do with it. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: class-based class decorator
On Jan 12, 2015 6:47 AM, Albert-Jan Roskam fo...@yahoo.com wrote: Thanks for your replies. I changed it into a regular decorator (not a class decorator). It would have been even nicer if I only needed to specify it once per class, but, well, in my case this hardly matters. The code below works as intended. One problem (not specific to the code): the decorator destroys the signature: it always becomes *args, **kwargs). This is annoying with help(), but what worries me most is that my Sphinx documentation is also affected. The information about the defaults gets lost (the parameters are decribed in the docstring, but not the defaults). That kind of sucks. Is there a builtin way around this (in other words: I am aware of this package: https://pypi.python.org/pypi/decorator). I am hoping to get the code working on Python 2.7 and 3.3 and up. As of (I think) 3.4 pydoc and the help() function will show you the signature of the wrapped function as long as you use functools.wraps. I don't know what the status is for Sphinx; all I can offer is this stackoverflow link. http://stackoverflow.com/questions/3687046/python-sphinx-autodoc-and-decorated-members -- https://mail.python.org/mailman/listinfo/python-list
Re: What does pip install do?
On 12.01.2015 23:46, Chris Angelico wrote: On Tue, Jan 13, 2015 at 9:35 AM, Fabienfabien.mauss...@gmail.com wrote: BUT I'm still asking myself: what does pip install*concretely* do on my virtual environment? As far as I know, it's equivalent to three steps: 1) Download the appropriate version of a package (the latest, if you didn't say otherwise) 2) Extract that package 3) Run 'python setup.py'. What setup.py does is up to the package, but for a pure-Python package it should simply create something in site-packages. It might do a lot more, though - compiling C or Fortran code, for instance. Thanks Chris. I should then rephrase my question to what does python setup.pt do? ;-). My point was also that I think that this information (mostly: what will change on my system or my virtual env when I install a python package?) could/should be provided in the mentioned resources: Python Packaging Authority website (https://pip.pypa.io/en/latest/user_guide.html), python-packaging-user-guide (http://python-packaging-user-guide.readthedocs.org/en/latest/installing.html) Installing python packages from the python docs (https://docs.python.org/3/installing/) I've found a bit more about this (How installation works) in the Python 3 doc which is now considered legacy and might therefore not be read: https://docs.python.org/3.4/install/index.html#installing-python-modules-legacy-version Fabien -- https://mail.python.org/mailman/listinfo/python-list
Re: Comparisons and sorting of a numeric class....
On Tue, Jan 13, 2015 at 4:32 PM, Steven D'Aprano st...@pearwood.info wrote: Crashing the interpreter from pure Python code is *absolutely not allowed*, so anything which would allow that is forbidden. Except when you willingly shoot yourself in the foot. rosuav@sikorsky:~$ python Python 2.7.3 (default, Mar 13 2014, 11:03:55) [GCC 4.7.2] on linux2 Type help, copyright, credits or license for more information. import sys def f(): sys.setrecursionlimit(sys.getrecursionlimit()+1) or f() ... f() Segmentation fault rosuav@sikorsky:~$ python3 Python 3.5.0a0 (default:1c51f1650c42+, Dec 29 2014, 02:29:06) [GCC 4.7.2] on linux Type help, copyright, credits or license for more information. import sys def f(): sys.setrecursionlimit(sys.getrecursionlimit()+1) or f() ... f() Segmentation fault But otherwise, yes. You shouldn't be able to segfault Python with Python code. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Using a ChangeLog as a canonical source of package metadata
On Mon, 12 Jan 2015 05:24:00 -0800, wxjmfauth wrote: To tell you the truth, I'm unable to put your product to work. If you follow the instructions in the README, and it still doesn't work, that's a bug and I will be happy to fix it. If you insist on doing things your own way, and breaking the package, then I cannot help you. -- Steve -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 3 regex?
On Mon, 12 Jan 2015 19:48:18 +, Ian wrote: My recommendation would be to write a recursive decent parser for your files. That way will be easier to write, I know that writing parsers is a solved problem in computer science, and that doing so is allegedly one of the more trivial things computer scientists are supposed to be able to do, but the learning curve to write parsers is if anything even higher than the learning curve to write a regex. I wish that Python made it as easy to use EBNF to write a parser as it makes to use a regex :-( http://en.wikipedia.org/wiki/Extended_Backus–Naur_Form -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: Comparisons and sorting of a numeric class....
On Mon, 12 Jan 2015 17:59:42 -0800, Andrew Robinson wrote: [...] What I am wanting to know is WHY did Guido think it so important to do that ? Why was he so focused on a strict inability to have any instances of a bool subclass at all -- that he made a very arbitrary exception to the general rule that base types in Python can be subclassed ? It's not arbitrary. All the singleton (doubleton in the case of bool) classes cannot be subclassed. E.g. NoneType: py class X(type(None)): ... pass ... Traceback (most recent call last): File stdin, line 1, in module TypeError: Error when calling the metaclass bases type 'NoneType' is not an acceptable base type Likewise for the NotImplemented and Ellipsis types. The reason is the same: if a type promises that there is one and only one instance (two in the case of bool), then allowing subtypes will break that promise in the 99.99% of cases where the subtype is instantiated. I suppose in principle Python could allow you to subclass singleton classes to your hearts content, and only raise an error if you try to instantiate them, but that would probably be harder and more error-prone to implement, and would *definitely* be harder to explain. There may be others too: py from types import FunctionType py class F(FunctionType): ... pass ... Traceback (most recent call last): File stdin, line 1, in module TypeError: Error when calling the metaclass bases type 'function' is not an acceptable base type My guess here is that functions are so tightly coupled to the Python interpreter that allowing you to subclass them, and hence break required invariants, could crash the interpreter. Crashing the interpreter from pure Python code is *absolutely not allowed*, so anything which would allow that is forbidden. There's no reason in object oriented programming principles in general that requires a new subclass instance to be a COMPLETELY DISTINCT instance from an already existing superclass instance True. But what is the point of such a subclass? I don't think you have really thought this through in detail. Suppose we allowed bool subclasses, and we implement one which *only* returns True and False, without adding a third instance: class MyBool(bool): def __new__(cls, arg): if cls.condition(arg): return True else: return False @classmethod def condition(cls, obj): # decide whether obj is true-ish or false-ish. pass def spam(self): return self.eggs() def eggs(self): return 23 And then you do this: flag = MyBool(something) flag.spam() What do you expect to happen? Since flag can *only* be a regular bool, True or False, it won't have spam or eggs methods. You might think of writing the code using unbound methods: MyBool.spam(flag) (assuming that methods don't enforce the type restriction that self must be an instance of their class), but that fails when the spam method calls self.eggs. So you have to write your methods like this: def spam(self): return MyBool.eggs(self) hard-coding the class name! You can't use type(self), because that's regular bool, not MyBool. This is a horrible, error-prone, confusing mess of a system. If you're going to write code like this, you are better off making MyBool a module with functions instead of a class with methods. nor, have I ever seen Guido say that Python is designed intentionally to force this to always be the case... so I'm not sure that's its anything more than a non guaranteed implementation detail that Python acts the way you say it does It is a documented restriction on bool. Whether you agree with the decision or not, it is not an implementation detail, it is a language promise. https://docs.python.org/2/library/functions.html#bool -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: Namespace puzzle, list comprehension fails within class definition
On 01/12/2015 08:49 PM, Steven D'Aprano wrote: On Mon, 12 Jan 2015 12:40:13 -0800, Ethan Furman wrote: [...] class name lookup skips nonlocal namespaces. Actually, no it doesn't. [...] The problem is that *functions* lookup don't include the class body in their scope. Ah, thanks for the correction! -- ~Ethan~ signature.asc Description: OpenPGP digital signature -- https://mail.python.org/mailman/listinfo/python-list
Re: I must be missing something obvious in installing Python 3.4.2...
On 12/01/2015 23:12, Andrew Koenig wrote: Fixed it! The aforementioned article is correct. I downloaded the RegDelNull program mentioned in the article (http://technet.microsoft.com/en-us/sysinternals/bb897448.aspx) and ran it on hkcr, hkcu, hklm, hku, and hkcc (short for HKEY_CLASSES_ROOT, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, HKEY_USERS, and HKEY_CURRENT_CONFIG), respectively. It deleted a bunch of keys. Rerunning the program you posted earlier revealed no keys with embedded nulls in their names, and ensurepip now works. I have no idea how these keys got there. For all I know they are the result of malware. I think it would be worthwhile changing the Python code to detect nulls and perhaps issue a warning that directs people to this article or something like it. Thanks, yes. Unfortunate that no-one's actually reported this before as a bug -- as far as I'm aware. Would you be in a position to report this at bugs.python.org? If not, I'll do it when I get a chance. TJG -- https://mail.python.org/mailman/listinfo/python-list
[RELEASE] ‘python-daemon’ version 2.0.2 released
Howdy all, I am pleased to announce the release of version 2.0.2 of the ‘python-daemon’ library. The current release is always available at URL:https://pypi.python.org/pypi/python-daemon/. The project's forums and VCS are hosted at Alioth URL:https://alioth.debian.org/projects/python-daemon/. Significant changes since the previous version == This is a bug fix release, addressing packaging bugs: * Declare test-time dependency on recent ‘unittest2’. * Declare packaging-time dependency on ‘docutils’ library. Many thanks to users who promptly reported these omissions. What is the ‘python-daemon’ library? ‘python-daemon’ is a Python library to implement a well-behaved Unix daemon process. -- \ “… one of the main causes of the fall of the Roman Empire was | `\that, lacking zero, they had no way to indicate successful | _o__) termination of their C programs.” —Robert Firth | Ben Finney b...@benfinney.id.au signature.asc Description: Digital signature -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 3 regex?
On 13/01/2015 02:53, Rick Johnson wrote: On Monday, January 12, 2015 at 7:55:32 PM UTC-6, Mark Lawrence wrote: On 12/01/2015 23:47, Rick Johnson wrote: 'Some people, when confronted with a problem, think I know, I'll use regular expressions. Now they have two problems.' - Jamie Zawinski. [snip] If you wish to use a hydrogen bomb instead of a tooth pick feel free, I won't lose any sleep over it. Meanwhile I'll get on with writing code, and for the simple jobs that can be completed with string methods I'll carry on using them. When that gets too complicated I'll reach for the regex manual, knowing full well that there's enough data in books and online to help even a novice such as myself get over all the hurdles. If that isn't good enough then maybe a full blown parser, such as the pile listed here [snip] Mark, if you're going to quote me, then at least quote me in a manner that does not confuse the content of my post. The snippet you posted was not a statement of mine, rather, it was a quote that i was responding to, and without any context of my response, what is the point of quoting anything at all? It would be better to quote nothing and just say @Rick, then to quote something which does not have any context. You snipped the bit that says [normal cobblers snipped]. Every python programmer worth his *SALT* should master the following three text processing capabilities of Python, and he should know how and when to apply them (for they all have strengths and weaknesses): (1) String methods: Simplistic API, but with limited capabilities -- but never underestimate the possibilities! (2) Regexps: Great for pattern matching with a powerful and concise syntax, but highly cryptic and unintuitive for the neophyte (and sometimes even the guru! *wink*). (3) Parsers: Great for extracting deeper meaning from text, but if pattern matching is all you need, then why not use (1) or (2) -- are you scared or uninformed? String methods, regexes, parsers, isn't that what I've already said above? Why repeat it? We can easily forgive a child who is afraid of the dark; the real tragedy of life is when men are afraid of the light. -- Plato IMHO, if you seek to only match patterns, then string methods should be your first choice, however, if the pattern is too difficult for string methods, then graduate to regexps. If you need to extract deeper meaning from text, by all means utilize a parser. I feel humbled that a great such as yourself is again repeating what I've already said. But above all, don't fall for these religious teachings about how regexps are too difficult for mortals -- that's just hysteria. If you follow the outline i provided above, you should find Python's text processing Nirvana. My favourite things in programming all go along the lines of DRY and KISS, with Although practicality beats purity being the most important of the lot. So called religious teachings never enter into my way of doing things. For example I can't stand code which jumps through hoops to avoid using GOTO, whereas nothing is cleaner than (say) GOTO ERROR. You'll (plural) find loads of them in cPython. -- 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: Python 3 regex?
On Mon, 12 Jan 2015 15:47:08 -0800, Rick Johnson wrote: 'Some people, when confronted with a problem, think I know, I'll use regular expressions. Now they have two problems.' - Jamie Zawinski. I wonder if Jamie's conclusions are a result of careful study, or merely, an attempt to resolve his own cognitive dissonance? Zawinski is one of the pantheon of geek demi-gods, with Linus, Larry, Guido, RMS, and a few others. (Just don't ask me to rank them. I'm not qualified.) His comment isn't based on a failure to grok regular expressions, but on an understanding that many people use regular expressions inappropriately. Here is more on the context of the famous quote: http://regex.info/blog/2006-09-15/247 (By the way, the quote actually wasn't original to JZ, he stole it from an all but identical quote about awk.) [...] For instance, in the following example, i contrive a similarly ironic statement to showcase the effects of such propaganda, but one that covers a subject matter in which laymen either: already understand, or, can easily attain enough knowledge to appreciate the humor. # Ironic Twist # # Some diabetics, when confronted with hunger, think I# # know, I'll eat a box of sugar cookies. -- now they have # # two problems!' Not the best of analogies, since there are two forms of diabetes. Those with Type 2 diabetes can best manage their illness by avoiding sugar cookies. Those with Type 1 should keep a box of sugar cookies (well, perhaps glucose lollies are more appropriate) on hand for emergencies. http://www.betterhealth.vic.gov.au/bhcv2/bhcarticles.nsf/pages/Diabetes_explained?open In any case, most people with diabetes (or at least those who are still alive) are reasonably good at managing their illness and wouldn't make the choice you suggest. You have missed the point that people who misuse regexes are common in programming circles, while diabetics who eat a box of sugar cookies instead of a meal are rare. To take your analogy to an extreme: Some people, when faced with a problem, say I know, I'll cut my arm off with a pocketknife! Now they have two problems. This is not insightful or useful. Except in the most specialised and extreme circumstances, such as being trapped in the wilderness with a boulder on your arm, nobody would consider this to be good advice. But using regexes to validate email addresses or parse HTML? The internet is full of people who thought that was a good idea. [...] Yes, i'll admit, regexps are very cryptic, but once you grasp their intricacies, you appreciate the succinctness of there syntax, because, what makes them so powerful is not only the extents of their pattern matching abilities, but their conciseness. Even Larry Wall says that regexes are too concise and cryptic: http://perl6.org/archive/doc/design/apo/A05.html -- Steve -- https://mail.python.org/mailman/listinfo/python-list
[issue23227] Generator's finally block not run if close() called before first iteration
New submission from Stephen Drake: If a generator has its close() method called before any items are requested from it, a finally block in the generator function will not be executed. I encountered this when wrapping an open file to alter the result of iterating over it. Using a generator function with a try/finally block seemed like a simple way of acheiving this. Here's an example that logs each line as it's read: def logged_lines(f): try: for line in f: logging.warning(line.strip()) yield line finally: logging.warning('closing') f.close() If the generator is created and closed immediately, the underlying file-like object is left open: f = urlopen('https://docs.python.org/') lines = logged_lines(f) lines.close() f.closed False But once the first item is requested from the generator, close() will trigger cleanup: lines = logged_lines(f) next(lines) WARNING:root:!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN '!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN\n' lines.close() WARNING:root:closing f.closed True Having read the documentation for yield expressions, I don't believe this behaviour to be non-conformant - but it still seems like a bit of a gotcha to me. Should this usage be warned against? -- assignee: docs@python components: Documentation, Interpreter Core messages: 233903 nosy: docs@python, sjdrake priority: normal severity: normal status: open title: Generator's finally block not run if close() called before first iteration type: behavior versions: Python 2.7, Python 3.4 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23227 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: Comparisons and sorting of a numeric class....
On Tue, 13 Jan 2015 09:35:43 +1100, Chris Angelico wrote: Subclassing bool breaks this invariant, unless you never instantiate the subclass, in which case it's completely useless. Not necessarily. A class that you never instantiate, but use as an object itself, is another way of implementing the singleton design pattern. Obviously all the methods have to be class methods, but it is doable. But wacky exceptions like subclasses that aren't instantiated aside, normally if you subclass something you intend to instantiate it. In Java terms bool is a final class which means it cannot be subclassed. Although Python is not anywhere near as restrictive as Java, and makes a virtue out of allowing the programmer to shot themselves in the foot, there are some restrictions and this is one of them. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: I must be missing something obvious in installing Python 3.4.2...
On Monday, January 12, 2015 at 10:09:03 PM UTC-8, Tim Golden wrote: On 12/01/2015 23:12, Andrew Koenig wrote: Fixed it! The aforementioned article is correct. I downloaded the RegDelNull program mentioned in the article (http://technet.microsoft.com/en-us/sysinternals/bb897448.aspx) and ran it on hkcr, hkcu, hklm, hku, and hkcc (short for HKEY_CLASSES_ROOT, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, HKEY_USERS, and HKEY_CURRENT_CONFIG), respectively. It deleted a bunch of keys. Rerunning the program you posted earlier revealed no keys with embedded nulls in their names, and ensurepip now works. I have no idea how these keys got there. For all I know they are the result of malware. I think it would be worthwhile changing the Python code to detect nulls and perhaps issue a warning that directs people to this article or something like it. Thanks, yes. Unfortunate that no-one's actually reported this before as a bug -- as far as I'm aware. Would you be in a position to report this at bugs.python.org? If not, I'll do it when I get a chance. TJG http://bugs.python.org/issue22028 -- https://mail.python.org/mailman/listinfo/python-list
Re: class-based class decorator
- Original Message - From: Albert-Jan Roskam fo...@yahoo.com.dmarc.invalid import functools import inspect import warnings warnings.simplefilter(always) class check_deprecated_args(object): def __init__(self, deprecated_params, msg=None): self.deprecated_params = deprecated_params self.msg = msg def __call__(self, func): @functools.wraps(func) def inner(*args, **kwargs): argspec = inspect.getargspec(func) default_signature = dict(zip(argspec.args[1:], argspec.defaults)) callargs = inspect.getcallargs(func, *args, **kwargs) deprecated_calls = [(p, a) for p, a in callargs.items() if p in self.deprecated_params and a != default_signature[p]] for (param, arg) in deprecated_calls: msg = you're using obsolete parameters in %s: [%s:%s] msg = msg % (func.__name__, param, arg) msg = msg + + self.msg if self.msg else msg warnings.warn(msg, DeprecationWarning, stacklevel=2) return func(*args, **kwargs) functools.update_wrapper(inner, func) return inner if __name__ == __main__: class Foo(object): @check_deprecated_args([old, older], use 'brand_new' param instead) def __init__(self, old=old, older=ancient): print hello @check_deprecated_args(deprecated_params=[old, older]) def bar(self, old=default): print world f = Foo(old=old, older=dino era) f.bar(gnarly) help(f) # now the signature is *args, **kwargs, which makes my Sphinx documentation less readable! Best wishes, Albert-Jan I don't really understand how you successfuly manage positional parameters, since the caller may not name them. I'm asking because if your intend to check only the keyword parameters, there's a much simplier solution. 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