Re: mutable ints: I think I have painted myself into a corner
On 19May2013 09:01, Peter Otten __pete...@web.de wrote: | Cameron Simpson wrote: | | TL;DR: I think I want to modify an int value in place. | | Yesterday I was thinking about various flag set objects I have | floating around which are essentially bare objects whose attributes | I access, for example: | |flags = object() |flags.this = True |flags.that = False | | and then elsewhere: | |if flags.that: | do that ... | | Nice and readable, but I thought to myself: so bulky! | | Plus, it doesn't work: Yeah, sorry. My old code was a trite subclass of object. The new broken code is a subclass of int. | But setting up a flags object? What I _want_ to write is code like this: | |Flags = BitMask('this', 'that') | |# set default state |flags = Flags() |flags.this = False |flags.that = True |... iterate over some options ...: flags.this = True | | and there's my problem. This would modify the int in place. There's | no way to do that. For the base type (int) this makes perfect sense, | as they're immutable. | | Before I toss this approach and retreat to my former object | technique, does anyone see a way forward to modify an int subclass | instance in place? (That doesn't break math, preferably; I don't | do arithmetic with these things but they are, after all, ints...) | | No, but you could make | | flags = Flags(this=False, that=True) Yes, that is true. Flags would need to be a factory function computing the corresponding bitmask value and then returning my new int, but it would work. It still wouldn't let me go the whole way of modifying the flags after instantiation. Cheers, -- Cameron Simpson c...@zip.com.au Carpe Daemon - Seize the Background Process - Paul Tomblin ab...@freenet2.carleton.ca -- http://mail.python.org/mailman/listinfo/python-list
Re: mutable ints: I think I have painted myself into a corner
On 20May2013 13:23, Greg Ewing greg.ew...@canterbury.ac.nz wrote: | Cameron Simpson wrote: | It's an int _subclass_ so that it is no bigger than an int. | | If you use __slots__ to eliminate the overhead of an | instance dict, you'll get an object consisting of a | header plus one reference, which is probably about the | size of an int. But you'll also need an int to put in | that slot, so the total size will be about twice that | of an int. Yeah, I was thinking I'd need to go that way. Thanks for the suggestion. | Another approach would be to subclass array.array and | give instances of it type integer and size 1. Together | with empty __slots__, it will probably be a bit bigger | than an int, but it might still be smaller than a | custom object plus an int. Really? Interesting. I thinik it crosses my too baroque threshold, but maybe not:-) | If all of these are still too big, you might need to | find some way of packing multiple instances into a | single array.array. Space isn't that real an issue at present; I'll keep that kind of approach in mind if it comes up. This really came up because I was feeling that the obvious object-with-boolean-attributes was terrbily wasteful for something that can be inplemented with a single int, in principle. Cheers, -- Cameron Simpson c...@zip.com.au How do you blip the throttle and wave? Do you blip it real high, then wave before the revs drop back? Blip = right hand; Wave = left hand. Do both simultaneously. QED. Doesnt this make the bike lurch forward thru the intersection? Not if the disk lock is in place... - Dean Woodward de...@agora.rdrop.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Please help with Threading
On 18 May 2013 20:33, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: Python threads work fine if the threads either rely on intelligent DLLs for number crunching (instead of doing nested Python loops to process a numeric array you pass it to something like NumPy which releases the GIL while crunching a copy of the array) or they do lots of I/O and have to wait for I/O devices (while one thread is waiting for the write/read operation to complete, another thread can do some number crunching). Has nobody thought of a context manager to allow a part of your code to free up the GIL? I think the GIL is not inherently bad, but if it poses a problem at times, there should be a way to get it out of your... Way. -- http://mail.python.org/mailman/listinfo/python-list
Re: Future standard GUI library
On 5/20/2013 1:04 AM, Vito De Tullio wrote: Terry Jan Reedy wrote: Do you think tkinter is going to be the standard python built-in gui solution as long as python exists? AT the moment, there is nothing really comparable that is a realistic candidate to replace tkinter. FLTK? (http://www.fltk.org/index.php) tkinter is the Python wrapper of the tk library, just as wxpython is the python wrapper of the wx library. I do not see a py-fltk wrapper. -- http://mail.python.org/mailman/listinfo/python-list
Question about ast.literal_eval
Hi all I am trying to emulate a SQL check constraint in Python. Quoting from the PostgreSQL docs, A check constraint is the most generic constraint type. It allows you to specify that the value in a certain column must satisfy a Boolean (truth-value) expression. The problem is that I want to store the constraint as a string, and I was hoping to use ast.literal_eval to evaluate it, but it does not work. x = 'abc' x in ('abc', xyz') True b = x in ('abc', 'xyz') eval(b) True from ast import literal_eval literal_eval(b) ValueError: malformed node or string: _ast.Compare object at ... Is there a safe way to do what I want? I am using python 3.3. Thanks Frank Millman -- http://mail.python.org/mailman/listinfo/python-list
CFP: MuCoCoS Workshop at PACT-2013 (Edinburgh, Scotland, UK)
CALL FOR PAPERS: 6th International Workshop on Multi/many-Core Computing Systems (MuCoCoS-2013) September 7, 2013, Edinburgh, Scotland, UK in conjunction with the 22nd Int. Conference on Parallel Architectures and Compilation Techniques (PACT-2013) http://www.ida.liu.se/conferences/mucocos2013 AIMS AND SCOPE The pervasiveness of homogeneous and heterogeneous multi-core and many-core processors, in a large spectrum of systems from embedded and general-purpose to high-end computing systems, poses major challenges to software industry. In general, there is no guarantee that software developed for a particular architecture will be executable (that is functional) on another architecture. Furthermore, ensuring that the software preserves some aspects of performance behavior (such as temporal or energy efficiency) across different such architectures is an open research issue. Therefore, this workshop focuses on language level, system software and architectural solutions for performance portability across different architectures and for automated performance tuning. The topics of the MuCoCoS workshop include but are not limited to: * Performance measurement, modeling, analysis and tuning * Portable programming models, languages and compilation techniques * Run-time systems and hardware support mechanisms for auto-tuning * Tunable algorithms and data structures * Case studies highlighting performance portability and tuning. As the sixth workshop in the series MuCoCoS 2008 (Barcelona, Spain), MuCoCoS 2009 (Fukuoka, Japan), MuCoCoS 2010 (Krakow, Poland), MuCoCoS 2011 (Seoul, Korea), and MuCoCoS 2012 (Salt Lake City, USA), MuCoCoS 2013 will be held in Edinburgh, UK, in conjunction with the 22nd International Conference on Parallel Architectures and Compilation Techniques (PACT 2013). SUBMISSION GUIDELINES The papers should be prepared using the IEEE format (two-column, 10pt, LaTeX users please use style IEEEtran.cls), and no longer than 10 pages. Submitted papers will be carefully evaluated based on originality, significance to workshop topics, technical soundness, and presentation quality. Please submit your paper (as PDF, viewable by Adobe Reader v5.0 or higher, with all fonts embedded please) electronically using the online submission system https://www.easychair.org/conferences/?conf=mucocos2013 Submission of the paper implies that, should the paper be accepted, at least one of the authors will register and present the paper at the workshop. Accepted papers will be published in electronic form in IEEE Xplore (confirmation pending). They will also be included in the PACT USB proceedings. We also plan to invite authors of the best MuCoCoS papers after the workshop to submit their extended workshop papers to a special issue of Computing Journal (Springer) (confirmation pending). IMPORTANT DATES Submission: May 27, 2013 (Firm Deadline) Notification: June 23, 2013 Camera-ready: July 7, 2013 Workshop: September 7, 2013 WORKSHOP ORGANIZATION Christoph Kessler, Linköping University, Sweden, program chair Sabri Pllana, Linnaeus University, Sweden, co-chair PROGRAM COMMITTEE Marco Aldinucci, Univ. of Torino, Italy Beverly Bachmayer, Intel, Germany David Bader, Georgia Tech, USA Jacob Barhen, Oak Ridge National Lab, USA Siegfried Benkner, Univ. of Vienna, Austria Franz Franchetti, Carnegie Mellon University, USA Grigori Fursin, INRIA, France Jörg Keller, FernUniv. Hagen, Germany Lasse Natvig, NTNU Trondheim, Norway Mitsuhisa Sato, Univ. of Tsukuba, Japan Samuel Thibault, INRIA / Univ. of Bordeaux, France Philippas Tsigas, Chalmers University, Sweden Jakub Yaghob, Charles University Prague, Czech Republic -- http://mail.python.org/mailman/listinfo/python-list
RE: Question about ast.literal_eval
It seems to me you can't use ast.literal_eval()[1] to evaluate that kind of expression because it's just for literals[2]. Why don't you use eval()? [1] http://docs.python.org/2/library/ast.html#ast-helpers [2] http://docs.python.org/2/reference/lexical_analysis.html#literals To: python-list@python.org From: fr...@chagford.com Subject: Question about ast.literal_eval Date: Mon, 20 May 2013 09:05:48 +0200 Hi all I am trying to emulate a SQL check constraint in Python. Quoting from the PostgreSQL docs, A check constraint is the most generic constraint type. It allows you to specify that the value in a certain column must satisfy a Boolean (truth-value) expression. The problem is that I want to store the constraint as a string, and I was hoping to use ast.literal_eval to evaluate it, but it does not work. x = 'abc' x in ('abc', xyz') True b = x in ('abc', 'xyz') eval(b) True from ast import literal_eval literal_eval(b) ValueError: malformed node or string: _ast.Compare object at ... Is there a safe way to do what I want? I am using python 3.3. Thanks Frank Millman -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about ast.literal_eval
On Mon, May 20, 2013 at 5:05 PM, Frank Millman fr...@chagford.com wrote: Hi all I am trying to emulate a SQL check constraint in Python. Quoting from the PostgreSQL docs, A check constraint is the most generic constraint type. It allows you to specify that the value in a certain column must satisfy a Boolean (truth-value) expression. The problem is that I want to store the constraint as a string, and I was hoping to use ast.literal_eval to evaluate it, but it does not work. x = 'abc' x in ('abc', xyz') True b = x in ('abc', 'xyz') eval(b) True from ast import literal_eval literal_eval(b) ValueError: malformed node or string: _ast.Compare object at ... Is there a safe way to do what I want? I am using python 3.3. An SQL constraint has a whole lot that Python can't do conveniently, and vice versa, so I think you do yourself a disservice by trying to tie yourself to that. The problem here is that 'in' is an operator, so this is not a literal. One possible solution would be to separate out your operator (and have just a handful permitted), and then use ast.literal_eval for just the second operand - something like this: import ast import operator ops = { 'in':lambda x,y: x in y, # operator.contains has the args backwards '==':operator.eq, # or use '=' for more SQL-like syntax '':operator.lt, '':operator.gt, } op, value = 'in', ('abc', 'xyz') x = 'abc' if ops[op](x,ast.literal_eval(value)): print(Constraint passed) else: print(Ignore this one) ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: How to run a python script twice randomly in a day?
On 20May2013 09:47, Avnesh Shakya avnesh.n...@gmail.com wrote: | On Mon, May 20, 2013 at 9:42 AM, Cameron Simpson c...@zip.com.au wrote: | On 19May2013 20:54, Avnesh Shakya avnesh.n...@gmail.com wrote: | |How to run a python script twice randomly in a day? Actually | | I want to run my script randomly in a day and twice only. Please | | help me.. how is it possible. | | Do you mean run twice a day, each at random times? | | If so, do the obvious: at midnight, pick two random times. Sleep | until the first time, run the script, sleep until the second time, | run the script. | | There are various ways to do the sleeping and midnight bits; they're | up to you. | | Thanks, Can you mail documentation or link for it? I am totally new for it. 1: Please reply on-list; you asked the list, the discussion should remain there. I have added the list to the CC line. 2: Please don't top-post. Quote only the relevant bits of the previous message and reply below. If the message is long, do that in pieces. [quote] reply [quote] reply. Like a conversation. Now, to your questions. A UNIX user would use cron to schedule the midnight job and from the midnight job then probably use at to schedule the other jobs to run at specific times. See man 1 crontab, man 5 crontab to submit the cron jobs and man at to submit the once off jobs. UNIX means Linux, Solaris, AIX, any of the BSDs (includes MacOSX), etc. You could a small python script for the midnight job, and it would submit the at jobs. See the random module to compute a pseudorandom number (and thus a random time), the datetime module to compute the dates and times from that number, and the subprocess module to submit the at job for the chosen run times. The modules are here: http://docs.python.org/3/py-modindex.html That presumes python 3; if you're using python 2 the docs for that are available at the same web site. You don't need to use at. Your midnight job could just compute the time in seconds to each job time, then use the time.sleep function to delay until then. See the time module at the above link. Nobody on this list will write your program for you. Attempt to write the program, then come to the list with your attempt and any problems. People will help if you've made an initial effort, and continue to try. This question has the feel of a homework question; the point of homework is for you to learn by solving a problem yourself. It is fine to seek help, but you must make the effort yourself. Come back with specific questions. Cheers, -- Cameron Simpson c...@zip.com.au I'm not weird; I'm gifted. -- http://mail.python.org/mailman/listinfo/python-list
Re: Please help with Threading
On 20May2013 07:25, Fábio Santos fabiosantos...@gmail.com wrote: | On 18 May 2013 20:33, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: | Python threads work fine if the threads either rely on intelligent | DLLs for number crunching (instead of doing nested Python loops to | process a numeric array you pass it to something like NumPy which | releases the GIL while crunching a copy of the array) or they do lots of | I/O and have to wait for I/O devices (while one thread is waiting for | the write/read operation to complete, another thread can do some number | crunching). | | Has nobody thought of a context manager to allow a part of your code to | free up the GIL? I think the GIL is not inherently bad, but if it poses a | problem at times, there should be a way to get it out of your... Way. The GIL makes individual python operations thread safe by never running two at once. This makes the implementation of the operations simpler, faster and safer. It is probably totally infeasible to write meaningful python code inside your suggested context manager that didn't rely on the GIL; if the GIL were not held the code would be unsafe. It is easy for a C extension to release the GIL, and then to do meaningful work until it needs to return to python land. Most C extensions will do that around non-trivial sections, and anything that may stall in the OS. So your use case for the context manager doesn't fit well. -- Cameron Simpson c...@zip.com.au Gentle suggestions being those which are written on rocks of less than 5lbs. - Tracy Nelson in comp.lang.c -- http://mail.python.org/mailman/listinfo/python-list
RE: Please help with Threading
Date: Sun, 19 May 2013 13:10:36 +1000 From: c...@zip.com.au To: carlosnepomuc...@outlook.com CC: python-list@python.org Subject: Re: Please help with Threading On 19May2013 03:02, Carlos Nepomuceno carlosnepomuc...@outlook.com wrote: | Just been told that GIL doesn't make things slower, but as I | didn't know that such a thing even existed I went out looking for | more info and found that document: | http://www.dabeaz.com/python/UnderstandingGIL.pdf | | Is it current? I didn't know Python threads aren't preemptive. | Seems to be something really old considering the state of the art | on parallel execution on multi-cores. | What's the catch on making Python threads preemptive? Are there any ongoing projects to make that? Depends what you mean by preemptive. If you have multiple CPU bound pure Python threads they will all get CPU time without any of them explicitly yeilding control. But thread switching happens between python instructions, mediated by the interpreter. I meant operating system preemptive. I've just checked and Python does not start Windows threads. The standard answers for using multiple cores is to either run multiple processes (either explicitly spawning other executables, or spawning child python processes using the multiprocessing module), or to use (as suggested) libraries that can do the compute intensive bits themselves, releasing the while doing so so that the Python interpreter can run other bits of your python code. I've just discovered the multiprocessing module[1] and will make some tests with it later. Are there any other modules for that purpose? I've found the following articles about Python threads. Any suggestions? http://www.ibm.com/developerworks/aix/library/au-threadingpython/ http://pymotw.com/2/threading/index.html http://www.laurentluce.com/posts/python-threads-synchronization-locks-rlocks-semaphores-conditions-events-and-queues/ [1] http://docs.python.org/2/library/multiprocessing.html Plenty of OS system calls (and calls to other libraries from the interpreter) release the GIL during the call. Other python threads can run during that window. And there are other Python implementations other than CPython. Cheers, -- Cameron Simpson c...@zip.com.au Processes are like potatoes. - NCR device driver manual -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about ast.literal_eval
[Corrected top-posting] To: python-list@python.org From: fr...@chagford.com Subject: Question about ast.literal_eval Date: Mon, 20 May 2013 09:05:48 +0200 Hi all I am trying to emulate a SQL check constraint in Python. Quoting from the PostgreSQL docs, A check constraint is the most generic constraint type. It allows you to specify that the value in a certain column must satisfy a Boolean (truth-value) expression. The problem is that I want to store the constraint as a string, and I was hoping to use ast.literal_eval to evaluate it, but it does not work. On 20/05/2013 09:34, Carlos Nepomuceno wrote: It seems to me you can't use ast.literal_eval()[1] to evaluate that kind of expression because it's just for literals[2]. Why don't you use eval()? Because users can create their own columns, with their own constraints. Therefore the string is user-modifiable, so it cannot be trusted. Frank -- http://mail.python.org/mailman/listinfo/python-list
RE: Please help with Threading
Date: Mon, 20 May 2013 17:45:14 +1000 From: c...@zip.com.au To: fabiosantos...@gmail.com Subject: Re: Please help with Threading CC: python-list@python.org; wlfr...@ix.netcom.com On 20May2013 07:25, Fábio Santos fabiosantos...@gmail.com wrote: | On 18 May 2013 20:33, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: | Python threads work fine if the threads either rely on intelligent | DLLs for number crunching (instead of doing nested Python loops to | process a numeric array you pass it to something like NumPy which | releases the GIL while crunching a copy of the array) or they do lots of | I/O and have to wait for I/O devices (while one thread is waiting for | the write/read operation to complete, another thread can do some number | crunching). | | Has nobody thought of a context manager to allow a part of your code to | free up the GIL? I think the GIL is not inherently bad, but if it poses a | problem at times, there should be a way to get it out of your... Way. The GIL makes individual python operations thread safe by never running two at once. This makes the implementation of the operations simpler, faster and safer. It is probably totally infeasible to write meaningful python code inside your suggested context manager that didn't rely on the GIL; if the GIL were not held the code would be unsafe. I just got my hands dirty trying to synchronize Python prints from many threads. Sometimes they mess up when printing the newlines. I tried several approaches using threading.Lock and Condition. None of them worked perfectly and all of them made the code sluggish. Is there a 100% sure method to make print thread safe? Can it be fast??? It is easy for a C extension to release the GIL, and then to do meaningful work until it needs to return to python land. Most C extensions will do that around non-trivial sections, and anything that may stall in the OS. So your use case for the context manager doesn't fit well. -- Cameron Simpson c...@zip.com.au Gentle suggestions being those which are written on rocks of less than 5lbs. - Tracy Nelson in comp.lang.c -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about ast.literal_eval
On Mon, May 20, 2013 at 5:50 PM, Frank Millman fr...@chagford.com wrote: On 20/05/2013 09:34, Carlos Nepomuceno wrote: Why don't you use eval()? Because users can create their own columns, with their own constraints. Therefore the string is user-modifiable, so it cannot be trusted. Plenty of reason right there :) Is it a requirement that they be able to key in a constraint as a single string? We have a similar situation in one of the systems at work, so we divided the input into three(ish) parts: pick a field, pick an operator (legal operators vary according to field type - integers can't be compared against regular expressions, timestamps can use = and only), then enter the other operand. Sure, that cuts out a few possibilities, but you get 99.9%+ of all usage and it's easy to sanitize. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Please help with Threading
My use case was a tight loop processing an image pixel by pixel, or crunching a CSV file. If it only uses local variables (and probably hold a lock before releasing the GIL) it should be safe, no? My idea is that it's a little bad to have to write C or use multiprocessing just to do simultaneous calculations. I think an application using a reactor loop such as twisted would actually benefit from this. Sure, it will be slower than a C implementation of the same loop, but isn't fast prototyping a very important feature of the Python language? On 20 May 2013 08:45, Cameron Simpson c...@zip.com.au wrote: On 20May2013 07:25, Fábio Santos fabiosantos...@gmail.com wrote: | On 18 May 2013 20:33, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: | Python threads work fine if the threads either rely on intelligent | DLLs for number crunching (instead of doing nested Python loops to | process a numeric array you pass it to something like NumPy which | releases the GIL while crunching a copy of the array) or they do lots of | I/O and have to wait for I/O devices (while one thread is waiting for | the write/read operation to complete, another thread can do some number | crunching). | | Has nobody thought of a context manager to allow a part of your code to | free up the GIL? I think the GIL is not inherently bad, but if it poses a | problem at times, there should be a way to get it out of your... Way. The GIL makes individual python operations thread safe by never running two at once. This makes the implementation of the operations simpler, faster and safer. It is probably totally infeasible to write meaningful python code inside your suggested context manager that didn't rely on the GIL; if the GIL were not held the code would be unsafe. It is easy for a C extension to release the GIL, and then to do meaningful work until it needs to return to python land. Most C extensions will do that around non-trivial sections, and anything that may stall in the OS. So your use case for the context manager doesn't fit well. -- Cameron Simpson c...@zip.com.au Gentle suggestions being those which are written on rocks of less than 5lbs. - Tracy Nelson in comp.lang.c -- http://mail.python.org/mailman/listinfo/python-list
RE: Question about ast.literal_eval
To: python-list@python.org From: fr...@chagford.com Subject: Re: Question about ast.literal_eval Date: Mon, 20 May 2013 09:50:02 +0200 [Corrected top-posting] To: python-list@python.org From: fr...@chagford.com Subject: Question about ast.literal_eval Date: Mon, 20 May 2013 09:05:48 +0200 Hi all I am trying to emulate a SQL check constraint in Python. Quoting from the PostgreSQL docs, A check constraint is the most generic constraint type. It allows you to specify that the value in a certain column must satisfy a Boolean (truth-value) expression. The problem is that I want to store the constraint as a string, and I was hoping to use ast.literal_eval to evaluate it, but it does not work. On 20/05/2013 09:34, Carlos Nepomuceno wrote: It seems to me you can't use ast.literal_eval()[1] to evaluate that kind of expression because it's just for literals[2]. Why don't you use eval()? Because users can create their own columns, with their own constraints. Therefore the string is user-modifiable, so it cannot be trusted. I understand your motivation but I don't know what protection ast.literal_eval() is offering that eval() doesn't. Frank -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about ast.literal_eval
On 20/05/2013 09:55, Chris Angelico wrote: On Mon, May 20, 2013 at 5:50 PM, Frank Millman fr...@chagford.com wrote: On 20/05/2013 09:34, Carlos Nepomuceno wrote: Why don't you use eval()? Because users can create their own columns, with their own constraints. Therefore the string is user-modifiable, so it cannot be trusted. Plenty of reason right there :) Is it a requirement that they be able to key in a constraint as a single string? We have a similar situation in one of the systems at work, so we divided the input into three(ish) parts: pick a field, pick an operator (legal operators vary according to field type - integers can't be compared against regular expressions, timestamps can use = and only), then enter the other operand. Sure, that cuts out a few possibilities, but you get 99.9%+ of all usage and it's easy to sanitize. ChrisA It is not a requirement, no. I just thought it would be a convenient short-cut. I had in mind something similar to your scheme above, so I guess I will have to bite the bullet and implement it. Thanks Frank -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about ast.literal_eval
On Mon, May 20, 2013 at 5:55 PM, Carlos Nepomuceno carlosnepomuc...@outlook.com wrote: I understand your motivation but I don't know what protection ast.literal_eval() is offering that eval() doesn't. eval will *execute code*, while literal_eval will not. That's the protection. With ast.literal_eval, all that can happen is that it produces a single result value. In this case, unfortunately, that's insufficient; a comparison needs to be done, ergo it's not an entire literal. But something else in the ast module may be able to serve, or maybe literal_eval can do the bulk of the work. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about ast.literal_eval
On 20/05/2013 09:55, Carlos Nepomuceno wrote: Why don't you use eval()? Because users can create their own columns, with their own constraints. Therefore the string is user-modifiable, so it cannot be trusted. I understand your motivation but I don't know what protection ast.literal_eval() is offering that eval() doesn't. Quoting from the manual - Safely evaluate an expression node or a string containing a Python expression. The string or node provided may only consist of the following Python literal structures: strings, bytes, numbers, tuples, lists, dicts, sets, booleans, and None. The operative word is 'safely'. I don't know the details, but it prevents the kinds of exploits that can be carried out by malicious code using eval(). I believe it is the same problem as SQL injection, which is solved by using parameterised queries. Frank -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about ast.literal_eval
On Mon, 20 May 2013 10:55:35 +0300, Carlos Nepomuceno wrote: I understand your motivation but I don't know what protection ast.literal_eval() is offering that eval() doesn't. eval will evaluate any legal Python expression: py eval(__import__('os').system('echo Mwahaha! Now you are pwned!') or 42) Mwahaha! And now you are pwned! 42 ast.literal_eval() does exactly what the name says: it will evaluate any legal Python LITERAL, including ints, floats, lists, dicts and strings, but not arbitrary expressions. py ast.literal_eval('123') 123 py ast.literal_eval('[123, None, spam]') [123, None, 'spam'] -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Please help with Threading
On 20May2013 10:53, Carlos Nepomuceno carlosnepomuc...@outlook.com wrote: | I just got my hands dirty trying to synchronize Python prints from many threads. | Sometimes they mess up when printing the newlines. | I tried several approaches using threading.Lock and Condition. | None of them worked perfectly and all of them made the code sluggish. Show us some code, with specific complaints. Did you try this? _lock = Lock() def lprint(*a, **kw): global _lock with _lock: print(*a, **kw) and use lprint() everywhere? For generality the lock should be per file: the above hack uses one lock for any file, so that's going to stall overlapping prints to different files; inefficient. There are other things than the above, but at least individual prints will never overlap. If you have interleaved prints, show us. | Is there a 100% sure method to make print thread safe? Can it be fast??? Depends on what you mean by fast. It will be slower than code with no lock; how much would require measurement. Cheers, -- Cameron Simpson c...@zip.com.au My own suspicion is that the universe is not only queerer than we suppose, but queerer than we *can* suppose. - J.B.S. Haldane On Being the Right Size in the (1928) book Possible Worlds -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about ast.literal_eval
On 20 May 2013 09:19, Frank Millman fr...@chagford.com wrote: Quoting from the manual - Safely evaluate an expression node or a string containing a Python expression. The string or node provided may only consist of the following Python literal structures: strings, bytes, numbers, tuples, lists, dicts, sets, booleans, and None. The operative word is 'safely'. I don't know the details, but it prevents the kinds of exploits that can be carried out by malicious code using eval(). Literals are only a subset of expressions. The documentation is a bit misleading, by stating it accepts a python expression. This individual is rightfully confused. -- http://mail.python.org/mailman/listinfo/python-list
Re: Please help with Threading
On Mon, May 20, 2013 at 6:35 PM, Cameron Simpson c...@zip.com.au wrote: _lock = Lock() def lprint(*a, **kw): global _lock with _lock: print(*a, **kw) and use lprint() everywhere? Fun little hack: def print(*args,print=print,lock=Lock(),**kwargs): with lock: print(*args,**kwargs) Question: Is this a cool use or a horrible abuse of the scoping rules? ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Diacretical incensitive search
On Fri, 2013-05-17, Olive wrote: One feature that seems to be missing in the re module (or any tools that I know for searching text) is diacretical incensitive search. I would like to have a match for something like this: re.match(franc, français) ... The algorithm to write such a function is trivial but there are a lot of mark we can put on a letter. It would be necessary to have the list of a's with something on it. i.e. à,á,ã, etc. and this for every letter. Trying to make such a list by hand would inevitably lead to some symbols forgotten (and would be tedious). Ok, but please remember that the diacriticals are of varying importance. The english naïve is easily recognizable when written as naive. The swedish word får cannot be spelled far and still be understood. This is IMHO out of the scope of re, and perhaps case-insensitivity should have been too. Perhaps it /would/ have been, if regular expressions hadn't come from the ASCII world where these things are easy. /Jorgen -- // Jorgen Grahn grahn@ Oo o. . . \X/ snipabacken.se O o . -- http://mail.python.org/mailman/listinfo/python-list
Re: Future standard GUI library
On 2013-05-20 08:00, Terry Jan Reedy wrote: On 5/20/2013 1:04 AM, Vito De Tullio wrote: Terry Jan Reedy wrote: Do you think tkinter is going to be the standard python built-in gui solution as long as python exists? AT the moment, there is nothing really comparable that is a realistic candidate to replace tkinter. FLTK? (http://www.fltk.org/index.php) tkinter is the Python wrapper of the tk library, just as wxpython is the python wrapper of the wx library. I do not see a py-fltk wrapper. It exists, but it's really old. http://pyfltk.sourceforge.net/ -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: Please help with Threading
It is pretty cool although it looks like a recursive function at first ;) On 20 May 2013 10:13, Chris Angelico ros...@gmail.com wrote: On Mon, May 20, 2013 at 6:35 PM, Cameron Simpson c...@zip.com.au wrote: _lock = Lock() def lprint(*a, **kw): global _lock with _lock: print(*a, **kw) and use lprint() everywhere? Fun little hack: def print(*args,print=print,lock=Lock(),**kwargs): with lock: print(*args,**kwargs) Question: Is this a cool use or a horrible abuse of the scoping rules? ChrisA -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Please help with Threading
On 20May2013 19:09, Chris Angelico ros...@gmail.com wrote: | On Mon, May 20, 2013 at 6:35 PM, Cameron Simpson c...@zip.com.au wrote: |_lock = Lock() | |def lprint(*a, **kw): | global _lock | with _lock: |print(*a, **kw) | | and use lprint() everywhere? | | Fun little hack: | | def print(*args,print=print,lock=Lock(),**kwargs): | with lock: | print(*args,**kwargs) | | Question: Is this a cool use or a horrible abuse of the scoping rules? I carefully avoided monkey patching print itself:-) That's... mad! I can see what the end result is meant to be, but it looks like a debugging nightmare. Certainly my scoping-fu is too weak to see at a glance how it works. -- Cameron Simpson c...@zip.com.au I will not do it as a hack I will not do it for my friends I will not do it on a MacI will not write for Uncle Sam I will not do it on weekends I won't do ADA, Sam-I-Am - Gregory Bond g...@bby.com.au -- http://mail.python.org/mailman/listinfo/python-list
RE: Please help with Threading
Date: Mon, 20 May 2013 18:35:20 +1000 From: c...@zip.com.au To: carlosnepomuc...@outlook.com CC: python-list@python.org Subject: Re: Please help with Threading On 20May2013 10:53, Carlos Nepomuceno carlosnepomuc...@outlook.com wrote: | I just got my hands dirty trying to synchronize Python prints from many threads. | Sometimes they mess up when printing the newlines. | I tried several approaches using threading.Lock and Condition. | None of them worked perfectly and all of them made the code sluggish. Show us some code, with specific complaints. Did you try this? _lock = Lock() def lprint(*a, **kw): global _lock with _lock: print(*a, **kw) and use lprint() everywhere? It works! Think I was running the wrong script... Anyway, the suggestion you've made is the third and latest attempt that I've tried to synchronize the print outputs from the threads. I've also used: ### 1st approach ### lock = threading.Lock() [...] try: lock.acquire() [thread protected code] finally: lock.release() ### 2nd approach ### cond = threading.Condition() [...] try: [thread protected code] with cond: print '[...]' ### 3rd approach ### from __future__ import print_function def safe_print(*args, **kwargs): global print_lock with print_lock: print(*args, **kwargs) [...] try: [thread protected code] safe_print('[...]') Except for the first one all kind of have the same performance. The problem was I placed the acquire/release around the whole code block, instead of only the print statements. Thanks a lot! ;) For generality the lock should be per file: the above hack uses one lock for any file, so that's going to stall overlapping prints to different files; inefficient. There are other things than the above, but at least individual prints will never overlap. If you have interleaved prints, show us. | Is there a 100% sure method to make print thread safe? Can it be fast??? Depends on what you mean by fast. It will be slower than code with no lock; how much would require measurement. Cheers, -- Cameron Simpson c...@zip.com.au My own suspicion is that the universe is not only queerer than we suppose, but queerer than we *can* suppose. - J.B.S. Haldane On Being the Right Size in the (1928) book Possible Worlds -- http://mail.python.org/mailman/listinfo/python-list
Re: Please help with Threading
On Mon, May 20, 2013 at 7:54 PM, Cameron Simpson c...@zip.com.au wrote: On 20May2013 19:09, Chris Angelico ros...@gmail.com wrote: | On Mon, May 20, 2013 at 6:35 PM, Cameron Simpson c...@zip.com.au wrote: |_lock = Lock() | |def lprint(*a, **kw): | global _lock | with _lock: |print(*a, **kw) | | and use lprint() everywhere? | | Fun little hack: | | def print(*args,print=print,lock=Lock(),**kwargs): | with lock: | print(*args,**kwargs) | | Question: Is this a cool use or a horrible abuse of the scoping rules? I carefully avoided monkey patching print itself:-) That's... mad! I can see what the end result is meant to be, but it looks like a debugging nightmare. Certainly my scoping-fu is too weak to see at a glance how it works. Hehe. Like I said, could easily be called abuse. Referencing a function's own name in a default has to have one of these interpretations: 1) It's a self-reference, which can be used to guarantee recursion even if the name is rebound 2) It references whatever previously held that name before this def statement. Either would be useful. Python happens to follow #2; though I can't point to any piece of specification that mandates that, so all I can really say is that CPython 3.3 appears to follow #2. But both interpretations make sense, and both would be of use, and use of either could be called abusive of the rules. Figure that out. :) The second defaulted argument (lock=Lock()), of course, is a common idiom. No abuse there, that's pretty Pythonic. This same sort of code could be done as a decorator: def serialize(fn): lock=Lock() def locked(*args,**kw): with lock: fn(*args,**kw) return locked print=serialize(print) Spelled like this, it's obvious that the argument to serialize has to be the previous 'print'. The other notation achieves the same thing, just in a quirkier way :) ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Future standard GUI library
On 5/20/13 1:04 AM, Vito De Tullio wrote: FLTK? (http://www.fltk.org/index.php) FLTK is even uglier than non-themed Tkinter: non-native on every platform. Tkinter wraps native widgets on MacOS and WIndows, but FLTK draws its own widgets everywhere. -- Kevin Walzer Code by Kevin/Mobile Code by Kevin http://www.codebykevin.com http://www.wtmobilesoftware.com -- http://mail.python.org/mailman/listinfo/python-list
RE: How to write fast into a file in python?
Oh well! Just got a flashback from the old times at the 8-bit assembly line. Dirty deeds done dirt cheap! lol Date: Sun, 19 May 2013 16:44:55 +0100 From: pyt...@mrabarnett.plus.com To: python-list@python.org Subject: Re: How to write fast into a file in python? On 19/05/2013 04:53, Carlos Nepomuceno wrote: Date: Sat, 18 May 2013 22:41:32 -0400 From: da...@davea.name To: python-list@python.org Subject: Re: How to write fast into a file in python? On 05/18/2013 01:00 PM, Carlos Nepomuceno wrote: Python really writes '\n\r' on Windows. Just check the files. That's backwards. '\r\n' on Windows, IF you omit the b in the mode when creating the file. Indeed! My mistake just made me find out that Acorn used that inversion on Acorn MOS. According to this[1] (at page 449) the OSNEWL routine outputs '\n\r'. What the hell those guys were thinking??? :p Doing it that way saved a few bytes. Code was something like this: FFE3 .OSASCI CMP #0D FFE5 BNE OSWRCH FFE7 .OSNEWL LDA #0A FFE9 JSR OSWRCH FFEC LDA #0D FFEE .OSWRCH ... This means that the contents of the accumulator would always be preserved by a call to OSASCI. OSNEWL This call issues an LF CR (line feed, carriage return) to the currently selected output stream. The routine is entered at FFE7. [1] http://regregex.bbcmicro.net/BPlusUserGuide-1.07.pdf -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Please help with Threading
On 5/20/2013 6:09 AM, Chris Angelico wrote: Referencing a function's own name in a default has to have one of these interpretations: 1) It's a self-reference, which can be used to guarantee recursion even if the name is rebound 2) It references whatever previously held that name before this def statement. The meaning must be #2. A def statement is nothing more than a fancy assignment statement. This: def foo(a): return a + 1 is really just the same as: foo = lambda a: a+1 (in fact, they compile to identical bytecode). More complex def's don't have equivalent lambdas, but are still assignments to the name of the function. So your apparently recursive print function is no more ambiguous x = x + 1. The x on the right hand side is the old value of x, the x on the left hand side will be the new value of x. # Each of these updates a name x = x + 1 def print(*args,print=print,lock=Lock(),**kwargs): with lock: print(*args,**kwargs) Of course, if you're going to use that code, a comment might be in order to help the next reader through the trickiness... --Ned. -- http://mail.python.org/mailman/listinfo/python-list
Re: Please help with Threading
On 05/20/2013 03:55 AM, Fábio Santos wrote: My use case was a tight loop processing an image pixel by pixel, or crunching a CSV file. If it only uses local variables (and probably hold a lock before releasing the GIL) it should be safe, no? Are you making function calls, using system libraries, or creating or deleting any objects? All of these use the GIL because they use common data structures shared among all threads. At the lowest level, creating an object requires locked access to the memory manager. Don't forget, the GIL gets used much more for Python internals than it does for the visible stuff. -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about ast.literal_eval
On 20/05/2013 10:07, Frank Millman wrote: On 20/05/2013 09:55, Chris Angelico wrote: Is it a requirement that they be able to key in a constraint as a single string? We have a similar situation in one of the systems at work, so we divided the input into three(ish) parts: pick a field, pick an operator (legal operators vary according to field type - integers can't be compared against regular expressions, timestamps can use = and only), then enter the other operand. Sure, that cuts out a few possibilities, but you get 99.9%+ of all usage and it's easy to sanitize. ChrisA It is not a requirement, no. I just thought it would be a convenient short-cut. I had in mind something similar to your scheme above, so I guess I will have to bite the bullet and implement it. Can anyone see anything wrong with the following approach. I have not definitely decided to do it this way, but I have been experimenting and it seems to work. I store the boolean test as a json'd list of 6-part tuples. Each element of the tuple is a string, defined as follows - 0 - for the first entry in the list, the word 'check' (a placeholder - it is discarded at evaluation time), for any subsequent entries the word 'and' or 'or'. 1 - left bracket - either '(' or ''. 2 - column name to check - it will be validated on entry. 3 - operator - must be one of '=', '!=', '', '', '=', '=', 'in', 'is', 'is not'. At evaluation time, '=' is changed to '=='. 4 - value to compare - at evaluation time I call str(literal_eval(value)) to ensure that it is safe. 5 - right bracket - either ')' or ''. At evaluation time I loop through the list, construct the boolean test as a string, and call eval() on it. Here are some examples - check = [] check.append(('check', '', 'name', 'in', ('abc', 'xyz'), '')) check = [] check.append(('check', '', 'value', '=', '0', '')) check = [] check.append(('check', '(', 'descr', 'is not', 'None', '')) check.append(('and', '', 'alt', 'is', 'None', ')')) check.append(('or', '(', 'descr', 'is', 'None', '')) check.append(('and', '', 'alt', 'is not', 'None', ')')) I don't plan to check the logic - I will just display the exception if it does not evaluate. It seems safe to me. Can anyone see a problem with it? Frank -- http://mail.python.org/mailman/listinfo/python-list
Re: Please help with Threading
=On Mon, May 20, 2013 at 8:46 PM, Ned Batchelder n...@nedbatchelder.com wrote: On 5/20/2013 6:09 AM, Chris Angelico wrote: Referencing a function's own name in a default has to have one of these interpretations: 1) It's a self-reference, which can be used to guarantee recursion even if the name is rebound 2) It references whatever previously held that name before this def statement. The meaning must be #2. A def statement is nothing more than a fancy assignment statement. Sure, but the language could have been specced up somewhat differently, with the same syntax. I was fairly confident that this would be universally true (well, can't do it with 'print' per se in older Pythons, but for others); my statement about CPython 3.3 was just because I hadn't actually hunted down specification proof. So your apparently recursive print function is no more ambiguous x = x + 1. The x on the right hand side is the old value of x, the x on the left hand side will be the new value of x. # Each of these updates a name x = x + 1 def print(*args,print=print,lock=Lock(),**kwargs): with lock: print(*args,**kwargs) Yeah. The decorator example makes that fairly clear. Of course, if you're going to use that code, a comment might be in order to help the next reader through the trickiness... Absolutely!! ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about ast.literal_eval
On Mon, 20 May 2013 15:26:02 +0200, Frank Millman wrote: Can anyone see anything wrong with the following approach. I have not definitely decided to do it this way, but I have been experimenting and it seems to work. I store the boolean test as a json'd list of 6-part tuples. Each element of the tuple is a string, defined as follows - 0 - for the first entry in the list, the word 'check' (a placeholder - it is discarded at evaluation time), for any subsequent entries the word 'and' or 'or'. 1 - left bracket - either '(' or ''. 2 - column name to check - it will be validated on entry. 3 - operator - must be one of '=', '!=', '', '', '=', '=', 'in', 'is', 'is not'. At evaluation time, '=' is changed to '=='. 4 - value to compare - at evaluation time I call str(literal_eval(value)) to ensure that it is safe. 5 - right bracket - either ')' or ''. At evaluation time I loop through the list, construct the boolean test as a string, and call eval() on it. [...] It seems safe to me. Can anyone see a problem with it? It seems safe to me too, but then any fool can come up with a system which they themselves cannot break :-) I think the real worry is validating the column name. That will be critical. Personally, I would strongly suggest writing your own mini- evaluator that walks the list and evaluates it by hand. It isn't as convenient as just calling eval, but *definitely* safer. If you do call eval, make sure you supply the globals and locals arguments. The usual way is: eval(expression, {'__builtins__': None}, {}) which gives you an empty locals() and a minimal, (mostly) safe globals. Finally, as a belt-and-braces approach, I wouldn't even call eval directly, but call a thin wrapper that raises an exception if the expression contains an underscore. Underscores are usually the key to breaking eval, so refusing to evaluate anything with an underscore raises the barrier very high. And even with all those defences, I wouldn't allow untrusted data from the Internet anywhere near this. Just because I can't break it, doesn't mean it's safe. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about ast.literal_eval
On Mon, May 20, 2013 at 11:26 PM, Frank Millman fr...@chagford.com wrote: 0 - for the first entry in the list, the word 'check' (a placeholder - it is discarded at evaluation time), for any subsequent entries the word 'and' or 'or'. 1 - left bracket - either '(' or ''. 5 - right bracket - either ')' or ''. I think what you have is safe, but extremely complicated to work with. Six separate pieces, and things have to be in the right slots... I think you've spent too many complexity points on the above three components, and you're getting too little return for them. What happens if the nesting is mucked up? Could get verrry messy to check. Combining multiple conditions with a mixture of ands and ors is a nightmare to try to explain (unless you just point to the Python docs, which IMO costs you even more complexity points); the only safe option is to parenthesize everything. The system I pushed for at work (which was finally approved and implemented a few months ago) is more or less this: conditions are grouped together into blocks; for each group, you can choose whether it's all or any (aka and/or), and you choose whether the overall result is all-groups or any-group. That still costs a few complexity points (and, btw, our *actual* implementation is a bit more complicated than that, but I think we could cut it down to what I just described here without loss of functionality), but it gives the bulk of what people will actually want without the complexities of point-and-click code. The downside of that sort of system is that it requires a two-level tree. On the flip side, that's often how people will be thinking about their conditions anyway (eg using a pair of conditions and to implement a range check - conceptually it's a single check), so that won't cost too much. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about ast.literal_eval
On Tue, May 21, 2013 at 2:12 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: Personally, I would strongly suggest writing your own mini- evaluator that walks the list and evaluates it by hand. It isn't as convenient as just calling eval, but *definitely* safer. Probably faster, too, for what it's worth - eval is pretty expensive. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Harmonic distortion of a input signal
Non sense. The discrete fft algorithm is valid only if the number of data points you transform does correspond to a power of 2 (2**n). Keywords to the problem: apodization, zero filling, convolution product, ... eg. http://en.wikipedia.org/wiki/Convolution jmf -- http://mail.python.org/mailman/listinfo/python-list
Re: Harmonic distortion of a input signal
Am 20.05.13 19:23, schrieb jmfauth: Non sense. Dito. The discrete fft algorithm is valid only if the number of data points you transform does correspond to a power of 2 (2**n). Where did you get this? The DFT is defined for any integer point number the same way. Just if you want to get it fast, you need to worry about the length. For powers of two, there is the classic Cooley-Tukey. But there do exist FFT algorithms for any other length. For example, there is the Winograd transform for a set of small numbers, there is mixed-radix to reduce any length which can be factored, and there is finally Bluestein which works for any size, even for a prime. All of the aforementioned algorithms are O(log n) and are implemented in typical FFT packages. All of them should result (up to rounding differences) in the same thing as the naive DFT sum. Therefore, today Keywords to the problem: apodization, zero filling, convolution product, ... Not for a periodic signal of integer length. eg. http://en.wikipedia.org/wiki/Convolution How long do you read this group? Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: Harmonic distortion of a input signal
Oops, I thought we were posting to comp.dsp. Nevertheless, I think numpy.fft does mixed-radix (can't check it now) Am 20.05.13 19:50, schrieb Christian Gollwitzer: Am 20.05.13 19:23, schrieb jmfauth: Non sense. Dito. The discrete fft algorithm is valid only if the number of data points you transform does correspond to a power of 2 (2**n). Where did you get this? The DFT is defined for any integer point number the same way. Just if you want to get it fast, you need to worry about the length. For powers of two, there is the classic Cooley-Tukey. But there do exist FFT algorithms for any other length. For example, there is the Winograd transform for a set of small numbers, there is mixed-radix to reduce any length which can be factored, and there is finally Bluestein which works for any size, even for a prime. All of the aforementioned algorithms are O(log n) and are implemented in typical FFT packages. All of them should result (up to rounding differences) in the same thing as the naive DFT sum. Therefore, today Keywords to the problem: apodization, zero filling, convolution product, ... Not for a periodic signal of integer length. eg. http://en.wikipedia.org/wiki/Convolution How long do you read this group? Christian -- http://mail.python.org/mailman/listinfo/python-list
pip and different branches?
We use github and we work on many different branches at the same time. The problem is that we have 5 repos now, and for each repo we might have the same branches on all of them. Now we use pip and install requirements such as: git+ssh://g...@github.com/repo.git@dev Now the problem is that the requirements file are also under revision control, and constantly we end up in the situation that when we merge branches the branch settings get messed up, because we forget to change them. I was looking for a solution for this that would allow me to: - use the branch of the main repo for all the dependencies - fallback on master if that branch doesn't exist I thought about a few options: 1. create a wrapper for PIP that manipulates the requirement file, that now would become templates. In this way I would have to know however if a branch exist or not, and I didn't find a way to do that without cloning the repo. 2. modify PIP to not fail when checking out a non existing branch, so that if it's not found it falls back on master automatically. 3. use some git magic hooks but I'm not sure what exactly 4. stop using virtualenv + pip and use something smarter that handles this. Any suggestions? Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Please help with Threading
I didn't know that. On 20 May 2013 12:10, Dave Angel da...@davea.name wrote: Are you making function calls, using system libraries, or creating or deleting any objects? All of these use the GIL because they use common data structures shared among all threads. At the lowest level, creating an object requires locked access to the memory manager. Don't forget, the GIL gets used much more for Python internals than it does for the visible stuff. I did not know that. It's both interesting and somehow obvious, although I didn't know it yet. -- http://mail.python.org/mailman/listinfo/python-list
Re: What was the project that made you feel skilled in Python?
TBH, I think that the first thing that I did that made me feel that I could hold my own was when I had my first (and only thus far) patch accepted into the stdlib. To me, there's a /big/ difference between throwing together a package that a few people may find useful and putting a patch together that's accepted by a particular module expert and committed to the stdlib. To intermediate learners, I would strongly advocate getting their hands dirty with some part of the stdlib. Really (imho), there's really no better place to learn. Yes, in whole, it's a large project, but there are quite a few small(er) modules that, once their environment is set up, are self-contained and easy to follow along. Even if they don't get anything committed, learning from Python experts is far more useful than any other path that I've personally taken. Having said that, another great learning experience for me was when I wrote my OAuth 2.0 client (https://github.com/demianbrecht/sanction) and brought the initial implementation (460'ish LoC) to 66 LoC (pre-2/3 support). In part, this was due to taking a different design approach, but it was also in part due to taking advantage of Python idioms rather than simply using approaches that I had used in other languages. On Sun, May 19, 2013 at 4:30 AM, Ned Batchelder n...@nedbatchelder.com wrote: Hi all, I'm trying to come up with more project ideas for intermediate learners, somewhat along the lines of http://bit.ly/intermediate-python-projects . So here's a question for people who remember coming up from beginner: as you moved from exercises like those in Learn Python the Hard Way, up to your own self-guided work on small projects, what project were you working on that made you feel independent and skilled? What program first felt like your own work rather than an exercise the teacher had assigned? I don't want anything too large, but big enough that there's room for design, and multiple approaches, etc. Thanks in advance! --Ned. -- http://mail.python.org/mailman/listinfo/python-list -- Demian Brecht http://demianbrecht.github.com -- http://mail.python.org/mailman/listinfo/python-list
Re: What was the project that made you feel skilled in Python?
Hi Demian, Can I ask what you mean by working through the stdlib? As in writing code pieces utilizing each module from the stdlib? Also, you're talking about patches in the stdlib? Is there a separate library of patches? Forgive me if I'm google-failing hard over here. -- http://mail.python.org/mailman/listinfo/python-list
Re: What was the project that made you feel skilled in Python?
On 5/20/2013 3:36 PM, Thomas Murphy wrote: talking about patches in the stdlib? Is there a separate library of patches? http://bugs.python.org http://docs.python.org/devguide/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Future standard GUI library
On 2013-05-20, Terry Jan Reedy tjre...@udel.edu wrote: On 5/20/2013 1:04 AM, Vito De Tullio wrote: Terry Jan Reedy wrote: Do you think tkinter is going to be the standard python built-in gui solution as long as python exists? AT the moment, there is nothing really comparable that is a realistic candidate to replace tkinter. FLTK? (http://www.fltk.org/index.php) tkinter is the Python wrapper of the tk library, just as wxpython is the python wrapper of the wx library. I do not see a py-fltk wrapper. http://pyfltk.sourceforge.net/ -- Grant Edwards grant.b.edwardsYow! Is it 1974? What's at for SUPPER? Can I spend gmail.commy COLLEGE FUND in one wild afternoon?? -- http://mail.python.org/mailman/listinfo/python-list
Re: Please help with Threading
Chris Angelico於 2013年5月20日星期一UTC+8下午5時09分13秒寫道: On Mon, May 20, 2013 at 6:35 PM, Cameron Simpson c...@zip.com.au wrote: _lock = Lock() def lprint(*a, **kw): global _lock with _lock: print(*a, **kw) and use lprint() everywhere? Fun little hack: def print(*args,print=print,lock=Lock(),**kwargs): with lock: print(*args,**kwargs) Question: Is this a cool use or a horrible abuse of the scoping rules? ChrisA OK, if the python interpreter has a global hiden print out buffer of ,say, 2to 16 K bytes, and all string print functions just construct the output string from the format to this string in an efficient low level way, then the next question would be that whether the uses can use functions in this low level buffer for other string formatting jobs. -- http://mail.python.org/mailman/listinfo/python-list
Re: Please help with Threading
On Tue, May 21, 2013 at 11:44 AM, 8 Dihedral dihedral88...@googlemail.com wrote: OK, if the python interpreter has a global hiden print out buffer of ,say, 2to 16 K bytes, and all string print functions just construct the output string from the format to this string in an efficient low level way, then the next question would be that whether the uses can use functions in this low level buffer for other string formatting jobs. You remind me of George. http://www.chroniclesofgeorge.com/ Both make great reading when I'm at work and poking around with random stuff in our .SQL file of carefully constructed mayhem. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about ast.literal_eval
On Monday, May 20, 2013 2:05:48 AM UTC-5, Frank Millman wrote: Hi all I am trying to emulate a SQL check constraint in Python. Quoting from the PostgreSQL docs, A check constraint is the most generic constraint type. It allows you to specify that the value in a certain column must satisfy a Boolean (truth-value) expression. The problem is that I want to store the constraint as a string, and I was hoping to use ast.literal_eval to evaluate it, but it does not work. x = 'abc' x in ('abc', xyz') True b = x in ('abc', 'xyz') eval(b) True from ast import literal_eval literal_eval(b) ValueError: malformed node or string: _ast.Compare object at ... Is there a safe way to do what I want? I am using python 3.3. Thanks Frank Millman You might find the asteval module (https://pypi.python.org/pypi/asteval) useful. It provides a relatively safe eval, for example: import asteval a = asteval.Interpreter() a.eval('x = abc') a.eval('x in (abc, xyz)') True a.eval('import os') NotImplementedError import os 'Import' not supported a.eval('__import__(os)') NameError __import__(os) name '__import__' is not defined This works by maintaining an internal namespace (a flat dictionary), and walking the AST generated for the expression. It supports most Python syntax, including if, for, while, and try/except blocks, and function definitions, and with the notable exceptions of eval, exec, class, lambda, yield, and import. This requires Python2.6 and higher, and does work with Python3.3. Of course, it is not guaranteed to be completely safe, but it does disallow imports, which seems like the biggest vulnerability concern listed here. Currently, there is no explicit protection against long-running calculations for denial of service attacks. If you're exposing an SQL database to user-generated code, that may be worth considering. Cheers, --Matt Newville -- http://mail.python.org/mailman/listinfo/python-list
RE: Please help with Threading
sys.stdout.write() does not suffer from the newlines mess up when printing from many threads, like print statement does. The only usage difference, AFAIK, is to add '\n' at the end of the string. It's faster and thread safe (really?) by default. BTW, why I didn't find the source code to the sys module in the 'Lib' directory? Date: Tue, 21 May 2013 11:50:17 +1000 Subject: Re: Please help with Threading From: ros...@gmail.com To: python-list@python.org On Tue, May 21, 2013 at 11:44 AM, 8 Dihedral dihedral88...@googlemail.com wrote: OK, if the python interpreter has a global hiden print out buffer of ,say, 2to 16 K bytes, and all string print functions just construct the output string from the format to this string in an efficient low level way, then the next question would be that whether the uses can use functions in this low level buffer for other string formatting jobs. You remind me of George. http://www.chroniclesofgeorge.com/ Both make great reading when I'm at work and poking around with random stuff in our .SQL file of carefully constructed mayhem. ChrisA -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: How to run a python script twice randomly in a day?
On 20May2013 15:05, Avnesh Shakya avnesh.n...@gmail.com wrote: | Thanks a lot. No worries, but ... AGAIN: - please DO NOT top post. Post below, trimming the quoted material. - please POST TO THE LIST, not just to me. This is a public discussion. Now... | I did something. | I have created test.sh file in which i put- | | #!/bin/bash | cd /home/avin/cronJob | python try.py Ok, good. Some minor remarks: Personally, I always use: #!/bin/sh instead of requiring bash. All UNIX systems have sh, bash is only common. And even when present, it may not be in /bin. /bin/sh is always there, and unless you're doing something quite unusual, it works just fine. | then i went on terminal - | and run crontab -e | and wrote- | */2 * * * * bash /home/avin/cronJob/test.sh | and saved it. IIRC, this runs every two minutes. Good for testing, but not your original spec. Also, if you make the shell script (test.sh) executable you do not need to specify the interpreter. Treat your script like any other command! So: chmod +rx /home/avin/cronJob/test.sh and then your cron line can look like this: */2 * * * * /home/avin/cronJob/test.sh Also, treat your script the same way as your shell script, start it with a #! like this: #!/usr/bin/python Make it executable: chmod +rx /home/avin/cronJob/try.py and then you don't need to say python in your shell script: ./try.py (You need the ./ because the current directory is not in your command search path ($PATH).) | It's working fine. | but when I m using like | | import random | a = random.randrange(0, 59) | */a * * * * bash /home/avin/cronJob/test.sh | then it's showing error becose of varable 'a', so now how can i take | variable? I take it that this is your python program intended to schedule the two randomly timed runs? As a start, it must all be python. The first two lines are. The third line is a crontab line. So as a start, you need to look more like this: #!/usr/bin/python import random a = random.randrange(0, 59) cronline = '*/%d * * * * /home/avin/cronJob/test.sh' % (a,) print(cronline) At least then you can see the cron line you're making. It still does not add it to a cron job. Some remarks: - randrange() is like other python ranges: it does not include the end value. So your call picks a number from 0..58, not 0..59. Say randrange(0,60). Think start, length. - My recollection is that you wanted to run a script twice a day at random times. Your cron line doesn't do that. - If you're picking random run times you want to schedule a once-off job for each to run at a particular times. Cron schedules repeating jobs. To run at a particular time you want an at job. - You need to do one of two things in the pick-a-time script: - pick a time, then sleep until that time and then directly invoke the try.py script or - pick a time, then use the at command to schedule the try.py (or test.sh) script. The first approach would look a bit like this (totally untested): #!/usr/bin/python import random import subporcess import time # choose range time in the next 24 hours when = random.randrange(0, 24 * 3600) # sleep that many seconds time.sleep(when) subprocess.call(['/home/avin/cronJob/test.sh']) For two runs, pick two times. Swap them into order. Sleep twice, once until the first time and then once until the second time. Etc. The second approach (using at) would not sleep. instead, compute (using the datetime module) the date and time each job should run, and invoke at using the subprocess module, piping the text /home/avin/cronJob/test.sh\n to it. Cheers, -- Cameron Simpson c...@zip.com.au On a related topic, has anyone looked at doing a clean-room copy of CSS a la RC2 and RC4 a few years back? I know one or two people have looked at this in an informal manner, but we couldn't find anyone who hadn't already seen the DeCSS code to act as the clean person (it says a lot for the status of their trade secret that we couldn't actually find anyone who didn't already know it). - Peter Gutmann pgut...@cs.auckland.ac.nz -- http://mail.python.org/mailman/listinfo/python-list
RE: Please help with Threading
On Tue, May 21, 2013 at 11:44 AM, 8 Dihedral dihedral88...@googlemail.com wrote: OK, if the python interpreter has a global hiden print out buffer of ,say, 2to 16 K bytes, and all string print functions just construct the output string from the format to this string in an efficient low level way, then the next question would be that whether the uses can use functions in this low level buffer for other string formatting jobs. You remind me of George. http://www.chroniclesofgeorge.com/ Both make great reading when I'm at work and poking around with random stuff in our .SQL file of carefully constructed mayhem. ChrisA lol I need more cowbell!!! Please!!! lol -- http://mail.python.org/mailman/listinfo/python-list
Re: How to run a python script twice randomly in a day?
Thanks a lot. I got it. On Tue, May 21, 2013 at 6:42 AM, Cameron Simpson c...@zip.com.au wrote: On 20May2013 15:05, Avnesh Shakya avnesh.n...@gmail.com wrote: | Thanks a lot. No worries, but ... AGAIN: - please DO NOT top post. Post below, trimming the quoted material. - please POST TO THE LIST, not just to me. This is a public discussion. Now... | I did something. | I have created test.sh file in which i put- | | #!/bin/bash | cd /home/avin/cronJob | python try.py Ok, good. Some minor remarks: Personally, I always use: #!/bin/sh instead of requiring bash. All UNIX systems have sh, bash is only common. And even when present, it may not be in /bin. /bin/sh is always there, and unless you're doing something quite unusual, it works just fine. | then i went on terminal - | and run crontab -e | and wrote- | */2 * * * * bash /home/avin/cronJob/test.sh | and saved it. IIRC, this runs every two minutes. Good for testing, but not your original spec. Also, if you make the shell script (test.sh) executable you do not need to specify the interpreter. Treat your script like any other command! So: chmod +rx /home/avin/cronJob/test.sh and then your cron line can look like this: */2 * * * * /home/avin/cronJob/test.sh Also, treat your script the same way as your shell script, start it with a #! like this: #!/usr/bin/python Make it executable: chmod +rx /home/avin/cronJob/try.py and then you don't need to say python in your shell script: ./try.py (You need the ./ because the current directory is not in your command search path ($PATH).) | It's working fine. | but when I m using like | | import random | a = random.randrange(0, 59) | */a * * * * bash /home/avin/cronJob/test.sh | then it's showing error becose of varable 'a', so now how can i take | variable? I take it that this is your python program intended to schedule the two randomly timed runs? As a start, it must all be python. The first two lines are. The third line is a crontab line. So as a start, you need to look more like this: #!/usr/bin/python import random a = random.randrange(0, 59) cronline = '*/%d * * * * /home/avin/cronJob/test.sh' % (a,) print(cronline) At least then you can see the cron line you're making. It still does not add it to a cron job. Some remarks: - randrange() is like other python ranges: it does not include the end value. So your call picks a number from 0..58, not 0..59. Say randrange(0,60). Think start, length. - My recollection is that you wanted to run a script twice a day at random times. Your cron line doesn't do that. - If you're picking random run times you want to schedule a once-off job for each to run at a particular times. Cron schedules repeating jobs. To run at a particular time you want an at job. - You need to do one of two things in the pick-a-time script: - pick a time, then sleep until that time and then directly invoke the try.py script or - pick a time, then use the at command to schedule the try.py (or test.sh) script. The first approach would look a bit like this (totally untested): #!/usr/bin/python import random import subporcess import time # choose range time in the next 24 hours when = random.randrange(0, 24 * 3600) # sleep that many seconds time.sleep(when) subprocess.call(['/home/avin/cronJob/test.sh']) For two runs, pick two times. Swap them into order. Sleep twice, once until the first time and then once until the second time. Etc. The second approach (using at) would not sleep. instead, compute (using the datetime module) the date and time each job should run, and invoke at using the subprocess module, piping the text /home/avin/cronJob/test.sh\n to it. Cheers, -- Cameron Simpson c...@zip.com.au On a related topic, has anyone looked at doing a clean-room copy of CSS a la RC2 and RC4 a few years back? I know one or two people have looked at this in an informal manner, but we couldn't find anyone who hadn't already seen the DeCSS code to act as the clean person (it says a lot for the status of their trade secret that we couldn't actually find anyone who didn't already know it). - Peter Gutmann pgut...@cs.auckland.ac.nz -- http://mail.python.org/mailman/listinfo/python-list
Re: Please help with Threading
On Tue, 21 May 2013 05:53:46 +0300, Carlos Nepomuceno wrote: BTW, why I didn't find the source code to the sys module in the 'Lib' directory? Because sys is a built-in module. It is embedded in the Python interpreter. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
PEP 378: Format Specifier for Thousands Separator
Is there a way to format integers with thousands separator (digit grouping) like the format specifier of str.format()? I'm currently using the following: sys.stdout.write('Number = %s\n' % '{:,.0f}'.format(x)) Number = 12,345 'x' is unsigned integer so it's like using a sledgehammer to crack a nut! I'd like to have something like: sys.stdout.write('Number = %,u\n' % x) Is that possible? How can I do it if not already available? -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP 378: Format Specifier for Thousands Separator
In article blu176-w10190cb892a0414c988a05d7...@phx.gbl, Carlos Nepomuceno carlosnepomuc...@outlook.com wrote: Is there a way to format integers with thousands separator (digit grouping) like the format specifier of str.format()? I'm currently using the following: sys.stdout.write('Number = %s\n' % '{:,.0f}'.format(x)) Number = 12,345 'x' is unsigned integer so it's like using a sledgehammer to crack a nut! I'd like to have something like: sys.stdout.write('Number = %,u\n' % x) Is that possible? How can I do it if not already available? For Python 3.2+ or 2.7, why not just: print('Number = {:,}'.format(x)) Number = 12,345 -- Ned Deily, n...@acm.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about ast.literal_eval
On 21/05/2013 04:39, matt.newvi...@gmail.com wrote: You might find the asteval module (https://pypi.python.org/pypi/asteval) useful. It provides a relatively safe eval, for example: import asteval a = asteval.Interpreter() a.eval('x = abc') a.eval('x in (abc, xyz)') True a.eval('import os') NotImplementedError import os 'Import' not supported a.eval('__import__(os)') NameError __import__(os) name '__import__' is not defined This works by maintaining an internal namespace (a flat dictionary), and walking the AST generated for the expression. It supports most Python syntax, including if, for, while, and try/except blocks, and function definitions, and with the notable exceptions of eval, exec, class, lambda, yield, and import. This requires Python2.6 and higher, and does work with Python3.3. Of course, it is not guaranteed to be completely safe, but it does disallow imports, which seems like the biggest vulnerability concern listed here. Currently, there is no explicit protection against long-running calculations for denial of service attacks. If you're exposing an SQL database to user-generated code, that may be worth considering. Thanks for this, Matt. I will definitely look into it. Frank -- http://mail.python.org/mailman/listinfo/python-list
[issue16024] Doc cleanup regarding path=fd, dir_fd, follow_symlinks, etc
Larry Hastings added the comment: I would, but I can't get it to apply cleanly, either to tip or to historical revisions back in Sepember. Kaleb, what revision is the branch that you generated the diff from? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16024 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17973] FAQ entry for: '+=' on a list inside tuple both succeeds and raises an exception
Mark Dickinson added the comment: David: not sure. I don't think I'd go for it---I think the cure is worse than the disease. I think the FAQ is why it fails when the extend succeeds Agreed. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17973 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18020] html.escape 10x slower than cgi.escape
New submission from Florent Xicluna: I noticed the convenient ``html.escape`` in Python 3.2 and ``cgi.escape`` is marked as deprecated. However, the former is an order of magnitude slower than the latter. $ python3 --version Python 3.3.2 With html.escape: $ python3 -m timeit -s from html import escape as html; from cgi import escape; s = repr(copyright) h = html(s) 1 loops, best of 3: 48.7 usec per loop $ python3 -m timeit -s from html import escape as html; from cgi import escape; s = repr(copyright) * 19 h = html(s) 1000 loops, best of 3: 898 usec per loop With cgi.escape: $ python3 -m timeit -s from html import escape as html; from cgi import escape; s = repr(copyright) h = escape(s) 10 loops, best of 3: 7.42 usec per loop $ python3 -m timeit -s from html import escape as html; from cgi import escape; s = repr(copyright) * 19 h = escape(s) 1 loops, best of 3: 21.5 usec per loop Since this kind of function is called frequently in template engines, it makes a difference. Of course C replacements are available on PyPI: MarkupSafe or Webext But it would be nice to restore the performance of cgi.escape with a pragmatic `.replace(` approach. -- components: Library (Lib) messages: 189641 nosy: ezio.melotti, flox, orsenthil priority: normal severity: normal status: open title: html.escape 10x slower than cgi.escape type: performance versions: Python 3.2, Python 3.3 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18020 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue16611] multiple problems with Cookie.py
Florent Xicluna added the comment: Eric, this last one is not a bug in Cookie. This is a limitation with Python 2. See #18012. -- nosy: +flox ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16611 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18020] html.escape 10x slower than cgi.escape
Graham Dumpleton added the comment: Importing the cgi module the first time even in Python 2.X was always very expensive. I would suggest you redo the test using timing done inside of the script after modules have been imported so as to properly separate module import time in both cases from execution time of the specific function. -- nosy: +grahamd ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18020 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18020] html.escape 10x slower than cgi.escape
Florent Xicluna added the comment: I would suggest you redo the test using timing done inside of the script after modules have been imported. The -s switch takes care of this. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18020 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17976] file.write doesn't raise IOError when it should
Jaakko Moisio added the comment: The test pass with Python 3 which does not use the FILE* API anymore. So you should maybe migrate to Python 3 :-) Yes. I will eventually. But not all the libraries I'm using are migrated yet. -- Added file: http://bugs.python.org/file30317/fileobject-fix5.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17976 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue16024] Doc cleanup regarding path=fd, dir_fd, follow_symlinks, etc
Larry Hastings added the comment: p.s. Thanks for reviving the patch. I forgot about this one! -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16024 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18020] html.escape 10x slower than cgi.escape
Graham Dumpleton added the comment: Whoops. Missed the quoting. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18020 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17973] FAQ entry for: '+=' on a list inside tuple both succeeds and raises an exception
Ronald Oussoren added the comment: David: your update to the FAQ looks ok to me. I don't like updating the __setitem__ of tuple to allow setting an identical value (that is 'a[0] = a[0]'), it is a bit too magic to my taste and hides the real problem. I'd slightly prefer my idea: update the code generated for += to try performing the assignment before calling __iadd__. I hadn't looked at the AST compiler before, but at first glance implementing my idea seems easier than I had expected and I'm working on an experimental patch. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17973 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17973] FAQ entry for: '+=' on a list inside tuple both succeeds and raises an exception
Mark Dickinson added the comment: it is a bit too magic to my taste and hides the real problem. Agreed. I do wonder whether there's a solution that allows the operation to succeed, though. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17973 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17973] FAQ entry for: '+=' on a list inside tuple both succeeds and raises an exception
Ronald Oussoren added the comment: issue-17973-experimental.txt is a very crude first attempt at catching augment assignment to an immutable LHS. On first glance the code works, but it causes problems in the test suite and hence isn't correct yet. The generated code also isn't optimal, the LHS is evaluated too many times. With the patch ``([],)[0] += ['a']`` raises an exception, and doesn't update the list. I also haven't done benchmarking of the code, I'd expect a slowdown in micro benchmarks for augmented assignment when the LHS isn't a simple name because there is more byte code (``a[0] += b`` disassembly expands from 8 to 14 lines). -- Added file: http://bugs.python.org/file30318/issue-17973-experimental.txt ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17973 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17973] FAQ entry for: '+=' on a list inside tuple both succeeds and raises an exception
Ronald Oussoren added the comment: Allowing the operation to succeed wouldn't be right, you are assigning to an immutable location after all. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17973 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17973] FAQ entry for: '+=' on a list inside tuple both succeeds and raises an exception
Mark Dickinson added the comment: Unfortunately, I don't think the checking first approach can work either: in the case where the object *does* accept assignments, it will now be assigned to twice. If there are side-effects from those assignments, then that will change behaviour. An example is the Enthought traits library, where assignment to a list item causes a notification to be fired; with this change, listeners would now receive two events instead of one. I suspect there just isn't a good solution here. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17973 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18011] Inconsistency between b32decode() documentation, docstring and code
Changes by Ethan Furman et...@stoneleaf.us: -- nosy: +ethan.furman ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18011 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17973] FAQ entry for: '+=' on a list inside tuple both succeeds and raises an exception
Changes by Ezio Melotti ezio.melo...@gmail.com: -- nosy: +ezio.melotti ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17973 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17973] FAQ entry for: '+=' on a list inside tuple both succeeds and raises an exception
Amaury Forgeot d'Arc added the comment: what if we try the assignment, and catch TypeError only if __iadd__ returned self? -- nosy: +amaury.forgeotdarc ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17973 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17914] add os.cpu_count()
Roundup Robot added the comment: New changeset 5e0c56557390 by Charles-Francois Natali in branch 'default': Issue #17914: Add os.cpu_count(). Patch by Yogesh Chaudhari, based on an http://hg.python.org/cpython/rev/5e0c56557390 -- nosy: +python-dev ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17914 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17024] cElementTree calls end() on parser taget even if start() fails
Eli Bendersky added the comment: Yes, it doesn't seem that expat cares too much about propagating errors from every single handler. Digging in its code comments, it says that even when XML_StopParser is called, some event handlers (like the one for end element) may still be called since otherwise they will be lost. I don't know if this is important enough to muck with the way expat does things internally - I would expect this problem to exist in all Python XML modules that use expat. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17024 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17914] add os.cpu_count()
Charles-François Natali added the comment: Alright, committed. Yogesh, thanks for the patch! I'm attaching a patch to replace several occurrences of multiprocessing.cpu_count() by os.cpu_count() in the stdlib/test suite. -- Added file: http://bugs.python.org/file30319/use_cpu_count.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17914 ___diff -r 5e0c56557390 Doc/library/multiprocessing.rst --- a/Doc/library/multiprocessing.rst Mon May 20 14:40:46 2013 +0200 +++ b/Doc/library/multiprocessing.rst Mon May 20 14:52:18 2013 +0200 @@ -1646,9 +1646,9 @@ callbacks and has a parallel map implementation. *processes* is the number of worker processes to use. If *processes* is - ``None`` then the number returned by :func:`cpu_count` is used. If - *initializer* is not ``None`` then each worker process will call - ``initializer(*initargs)`` when it starts. + ``None`` then the number returned by :func:`os.cpu_count` is used, with a + fallback value of 1. If *initializer* is not ``None`` then each worker + process will call ``initializer(*initargs)`` when it starts. .. versionadded:: 3.2 *maxtasksperchild* is the number of tasks a worker process can complete diff -r 5e0c56557390 Lib/concurrent/futures/process.py --- a/Lib/concurrent/futures/process.py Mon May 20 14:40:46 2013 +0200 +++ b/Lib/concurrent/futures/process.py Mon May 20 14:52:18 2013 +0200 @@ -331,7 +331,7 @@ _check_system_limits() if max_workers is None: -self._max_workers = multiprocessing.cpu_count() +self._max_workers = os.cpu_count() or 1 else: self._max_workers = max_workers diff -r 5e0c56557390 Lib/multiprocessing/pool.py --- a/Lib/multiprocessing/pool.py Mon May 20 14:40:46 2013 +0200 +++ b/Lib/multiprocessing/pool.py Mon May 20 14:52:18 2013 +0200 @@ -17,10 +17,11 @@ import queue import itertools import collections +import os import time import traceback -from multiprocessing import Process, cpu_count, TimeoutError +from multiprocessing import Process, TimeoutError from multiprocessing.util import Finalize, debug # @@ -147,10 +148,7 @@ self._initargs = initargs if processes is None: -try: -processes = cpu_count() -except NotImplementedError: -processes = 1 +processes = os.cpu_count() or 1 if processes 1: raise ValueError(Number of processes must be at least 1) diff -r 5e0c56557390 Lib/test/regrtest.py --- a/Lib/test/regrtest.py Mon May 20 14:40:46 2013 +0200 +++ b/Lib/test/regrtest.py Mon May 20 14:52:18 2013 +0200 @@ -508,12 +508,9 @@ elif o in ('-j', '--multiprocess'): use_mp = int(a) if use_mp = 0: -try: -import multiprocessing -# Use all cores + extras for tests that like to sleep -use_mp = 2 + multiprocessing.cpu_count() -except (ImportError, NotImplementedError): -use_mp = 3 +# Use all cores + extras for tests that like to sleep +ncpu = os.cpu_count() or 1 +use_mp = 2 + ncpu if use_mp == 1: use_mp = None elif o == '--header': ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7214] TreeBuilder.end(tag) differs between cElementTree and ElementTree
Eli Bendersky added the comment: TreeBuilder is an interface users can implement. As such, 'tag' is a convenience the user-defined tree builder can use, as in: class Target(object): def start(self, tag, attrib): print('i see start', tag) def end(self, tag): print('i see end', tag) def close(self): return DONE parser = ET.XMLParser(target=Target()) parser.feed(TAGsd/TAG) The default TreeBuilder simply needs to build the tree, and it doesn't actually use the tag argument (except for some sanity checking in the Python version). But user code is free to use it. -- resolution: - wont fix stage: test needed - committed/rejected status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7214 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17914] add os.cpu_count()
STINNER Victor added the comment: In my patch cpu_count.patch, I changed posix_cpu_count(): * rewrite Mac OS X implementation: code in 5e0c56557390 looks wrong. It gets a MIB but then don't use it when calling _bsd_cpu_count(). But I didn't check my patch nor the commit version on Mac OS X. * use int ncpu; instead of long ncpu; when calling mpctl() and sysctl(). For mpctl(), ncpu is used to store the result, so a wide type is ok. But for sysctl(), we pass a pointer. What happens if sysctl() expects int whereas we pass a pointer to a long? We announce sizeof(int)!? * inline _bsd_cpu_count() Sorry for this late review. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17914 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18021] Update broken link to Apple Publication Style Guide
New submission from Madison May: The links at http://docs.python.org/devguide/documenting.html#building-doc and http://docs.python.org/devguide/docquality.html to http://developer.apple.com/mac/library/documentation/UserExperience/Conceptual/APStyleGuide/APSG_2009.pdf lead to a Page Not Found message and a redirect to http://developer.apple.com/library/mac/navigation/. This url should be updated to point to another copy of the 2009 style guide or https://help.apple.com/asg/mac/2013/ASG_2013.pdf, the 2013 version of Apple's Style Guide. -- components: Devguide messages: 189659 nosy: Madison.May, ezio.melotti priority: normal severity: normal status: open title: Update broken link to Apple Publication Style Guide type: enhancement ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18021 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13612] xml.etree.ElementTree says unknown encoding of a regular encoding
Eli Bendersky added the comment: In 3.3+ there's no distinction between wide and narrow builds. Does anyone know how this should be affected? [I don't know much about unicode and encodings, unfortunately] -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13612 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14009] Clearer documentation for cElementTree
Eli Bendersky added the comment: The ET docs have been significantly revamped in 3.3 I don't think cET needs to be documented. It's just confusing. -- resolution: - wont fix stage: commit review - committed/rejected status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14009 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18021] Update broken link to Apple Publication Style Guide
Changes by Madison May madison@students.olin.edu: -- type: enhancement - behavior ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18021 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17900] Recursive OrderedDict pickling
Serhiy Storchaka added the comment: Ping. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17900 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18022] Inconsistency between quopri.decodestring() and email.quoprimime.decode()
New submission from Serhiy Storchaka: import quopri, email.quoprimime quopri.decodestring(b'==41') b'=41' email.quoprimime.decode('==41') '=A' I don't see a rule about double '=' in RFC 1521-1522 or RFCs 2045-2047 and I think quopri is wrong. Other half of this bug (encoding '=' as '==') was fixed in 9bc52706d283. -- components: Library (Lib), email messages: 189663 nosy: Jeremy.Hylton, barry, gvanrossum, r.david.murray, serhiy.storchaka priority: normal severity: normal status: open title: Inconsistency between quopri.decodestring() and email.quoprimime.decode() type: behavior versions: Python 2.7, Python 3.3, Python 3.4 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18022 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17955] Minor updates to Functional HOWTO
Roundup Robot added the comment: New changeset 20409786cf8e by Andrew Kuchling in branch 'default': #17955: minor updates to Functional howto http://hg.python.org/cpython/rev/20409786cf8e -- nosy: +python-dev ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17955 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17955] Minor updates to Functional HOWTO
Changes by A.M. Kuchling li...@amk.ca: -- resolution: - fixed status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17955 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17955] Minor updates to Functional HOWTO
Changes by A.M. Kuchling li...@amk.ca: -- stage: commit review - committed/rejected ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17955 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18003] New lzma crazy slow with line-oriented reading.
Michael Fox added the comment: I was thinking about this line: end = self._buffer.find(b\n, self._buffer_offset) + 1 Might be a bug? For example, is there a unicode where one of several bytes is '\n'? In this case it splits the line in the middle of a character, right? On Sun, May 19, 2013 at 3:28 PM, Arfrever Frehtes Taifersar Arahesis rep...@bugs.python.org wrote: Changes by Arfrever Frehtes Taifersar Arahesis arfrever@gmail.com: -- nosy: +Arfrever ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18003 ___ -- - Michael -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18003 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8743] set() operators don't work with collections.Set instances
Changes by Nick Coghlan ncogh...@gmail.com: -- nosy: +ncoghlan ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8743 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2226] Small _abcoll Bugs / Oddities
Changes by Nick Coghlan ncogh...@gmail.com: -- nosy: +ncoghlan ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue2226 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17973] FAQ entry for: '+=' on a list inside tuple both succeeds and raises an exception
Roundup Robot added the comment: New changeset b363473cfe9c by R David Murray in branch '3.3': #17973: Add FAQ entry for ([],)[0] += [1] both extending and raising. http://hg.python.org/cpython/rev/b363473cfe9c New changeset 6d2f0edb0758 by R David Murray in branch 'default': Merge #17973: Add FAQ entry for ([],)[0] += [1] both extending and raising. http://hg.python.org/cpython/rev/6d2f0edb0758 New changeset 8edfe539d4c6 by R David Murray in branch '2.7': #17973: Add FAQ entry for ([],)[0] += [1] both extending and raising. http://hg.python.org/cpython/rev/8edfe539d4c6 -- nosy: +python-dev ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17973 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17973] FAQ entry for: '+=' on a list inside tuple both succeeds and raises an exception
R. David Murray added the comment: You still have the side effect problem, as far as I can see. I'm going to close this doc issue, if you guys do come up with some clever fix, you can reopen it again :) -- resolution: - fixed stage: patch review - committed/rejected status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17973 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18003] New lzma crazy slow with line-oriented reading.
Nadeem Vawda added the comment: No, that is the intended behavior for binary streams - they operate at the level of individual byes. If you want to treat your input file as Unicode-encoded text, you should open it in text mode. This will return a TextIOWrapper which handles the decoding and line splitting properly. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18003 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9189] Improve CFLAGS handling
Jed Brown added the comment: Undefined variables are still a problem: $ echo 'FROTZ = ${CFLAGS}' make.py3 $ python3 Python 3.3.1 (default, Apr 6 2013, 19:03:55) [GCC 4.8.0] on linux Type help, copyright, credits or license for more information. import distutils.sysconfig distutils.sysconfig.parse_makefile('make.py3') Traceback (most recent call last): File stdin, line 1, in module File /usr/lib/python3.3/distutils/sysconfig.py, line 367, in parse_makefile item = str(done['PY_' + n]) KeyError: 'PY_CFLAGS' Proposed fix: --- i/Lib/distutils/sysconfig.py +++ w/Lib/distutils/sysconfig.py @@ -357,7 +357,7 @@ def parse_makefile(fn, g=None): found = False else: -item = str(done['PY_' + n]) +item = str(done.get('PY_' + n, '')) else: done[n] = item = if found: -- nosy: +jedbrown ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9189 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2226] Small _abcoll Bugs / Oddities
Changes by Florent Xicluna florent.xicl...@gmail.com: -- nosy: +flox ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue2226 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17914] add os.cpu_count()
Roundup Robot added the comment: New changeset a85ac58e9eaf by Charles-Francois Natali in branch 'default': Issue #17914: Remove OS-X special-case, and use the correct int type. http://hg.python.org/cpython/rev/a85ac58e9eaf -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17914 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13612] xml.etree.ElementTree says unknown encoding of a regular encoding
Amaury Forgeot d'Arc added the comment: encoding=GBK causes a buffer overflow in PyUnknownEncodingHandler, because the result of PyUnicode_Decode() is only 192 characters long. Exact behavior is not defined... -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13612 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17914] add os.cpu_count()
Roundup Robot added the comment: New changeset f9d815522cdb by Charles-Francois Natali in branch 'default': Issue #17914: We can now inline _bsd_cpu_count(). http://hg.python.org/cpython/rev/f9d815522cdb -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17914 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com