Re: Question about ast.literal_eval

2013-05-20 Thread Frank Millman
On 20/05/2013 18:13, Chris Angelico wrote: On Mon, May 20, 2013 at 11:26 PM, Frank Millman 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 ''.

Re: Question about ast.literal_eval

2013-05-20 Thread Frank Millman
On 20/05/2013 18:12, Steven D'Aprano wrote: 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. [...] It seems safe to me too,

Re: Question about ast.literal_eval

2013-05-20 Thread Frank Millman
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 i

Re: PEP 378: Format Specifier for Thousands Separator

2013-05-20 Thread Ned Deily
In article , Carlos Nepomuceno 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 uns

PEP 378: Format Specifier for Thousands Separator

2013-05-20 Thread Carlos Nepomuceno
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 crac

Re: Please help with Threading

2013-05-20 Thread Steven D'Aprano
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

Re: How to run a python script twice randomly in a day?

2013-05-20 Thread Avnesh Shakya
Thanks a lot. I got it. On Tue, May 21, 2013 at 6:42 AM, Cameron Simpson wrote: > On 20May2013 15:05, Avnesh Shakya 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.

RE: Please help with Threading

2013-05-20 Thread Carlos Nepomuceno
> On Tue, May 21, 2013 at 11:44 AM, 8 Dihedral > 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

Re: How to run a python script twice randomly in a day?

2013-05-20 Thread Cameron Simpson
On 20May2013 15:05, Avnesh Shakya 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

RE: Please help with Threading

2013-05-20 Thread Carlos Nepomuceno
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

Re: Question about ast.literal_eval

2013-05-20 Thread matt . newville
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 mus

Re: Please help with Threading

2013-05-20 Thread Chris Angelico
On Tue, May 21, 2013 at 11:44 AM, 8 Dihedral 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 qu

Re: Please help with Threading

2013-05-20 Thread 88888 Dihedral
Chris Angelico於 2013年5月20日星期一UTC+8下午5時09分13秒寫道: > On Mon, May 20, 2013 at 6:35 PM, Cameron Simpson wrote: > > > _lock = Lock() > > > > > > def lprint(*a, **kw): > > > global _lock > > > with _lock: > > > print(*a, **kw) > > > > > > and use lprint() everywhere? > > > >

Re: Future standard GUI library

2013-05-20 Thread Grant Edwards
On 2013-05-20, 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 rea

Re: What was the project that made you feel skilled in Python?

2013-05-20 Thread Terry Jan Reedy
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: What was the project that made you feel skilled in Python?

2013-05-20 Thread Thomas Murphy
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

Re: What was the project that made you feel skilled in Python?

2013-05-20 Thread Demian Brecht
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 th

Re: Please help with Threading

2013-05-20 Thread Fábio Santos
I didn't know that. On 20 May 2013 12:10, "Dave Angel" 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

pip and different branches?

2013-05-20 Thread andrea crotti
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 r

Re: Harmonic distortion of a input signal

2013-05-20 Thread Christian Gollwitzer
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

Re: Harmonic distortion of a input signal

2013-05-20 Thread 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 i

Re: Harmonic distortion of a input signal

2013-05-20 Thread jmfauth
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/mailma

Re: Question about ast.literal_eval

2013-05-20 Thread Chris Angelico
On Tue, May 21, 2013 at 2:12 AM, Steven D'Aprano 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 i

Re: Question about ast.literal_eval

2013-05-20 Thread Chris Angelico
On Mon, May 20, 2013 at 11:26 PM, Frank Millman 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

Re: Question about ast.literal_eval

2013-05-20 Thread Steven D'Aprano
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 eleme

Re: Please help with Threading

2013-05-20 Thread Chris Angelico
=On Mon, May 20, 2013 at 8:46 PM, Ned Batchelder 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 re

Re: Question about ast.literal_eval

2013-05-20 Thread Frank Millman
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 op

Re: Please help with Threading

2013-05-20 Thread Dave Angel
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

Re: Please help with Threading

2013-05-20 Thread Ned Batchelder
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

RE: How to write fast into a file in python?

2013-05-20 Thread Carlos Nepomuceno
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 fi

Re: Future standard GUI library

2013-05-20 Thread Kevin Walzer
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

Re: Please help with Threading

2013-05-20 Thread Chris Angelico
On Mon, May 20, 2013 at 7:54 PM, Cameron Simpson wrote: > On 20May2013 19:09, Chris Angelico wrote: > | On Mon, May 20, 2013 at 6:35 PM, Cameron Simpson wrote: > | > _lock = Lock() > | > > | > def lprint(*a, **kw): > | > global _lock > | > with _lock: > | > print(*a, **kw) > |

RE: Please help with Threading

2013-05-20 Thread Carlos Nepomuceno
> 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 wrote: > | I just got my hands dirty trying t

Re: Please help with Threading

2013-05-20 Thread Cameron Simpson
On 20May2013 19:09, Chris Angelico wrote: | On Mon, May 20, 2013 at 6:35 PM, Cameron Simpson wrote: | > _lock = Lock() | > | > def lprint(*a, **kw): | > global _lock | > with _lock: | > print(*a, **kw) | > | > and use lprint() everywhere? | | Fun little hack: | | def print(*ar

Re: Please help with Threading

2013-05-20 Thread Fábio Santos
It is pretty cool although it looks like a recursive function at first ;) On 20 May 2013 10:13, "Chris Angelico" wrote: > On Mon, May 20, 2013 at 6:35 PM, Cameron Simpson wrote: > > _lock = Lock() > > > > def lprint(*a, **kw): > > global _lock > > with _lock: > > print(*a, **kw

Re: Future standard GUI library

2013-05-20 Thread Robert Kern
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 candida

Re: Diacretical incensitive search

2013-05-20 Thread Jorgen Grahn
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

Re: Please help with Threading

2013-05-20 Thread Chris Angelico
On Mon, May 20, 2013 at 6:35 PM, Cameron Simpson 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,**

Re: Question about ast.literal_eval

2013-05-20 Thread Fábio Santos
On 20 May 2013 09:19, "Frank Millman" 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,

Re: Please help with Threading

2013-05-20 Thread Cameron Simpson
On 20May2013 10:53, Carlos Nepomuceno 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 ma

Re: Question about ast.literal_eval

2013-05-20 Thread Steven D'Aprano
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!'

Re: Question about ast.literal_eval

2013-05-20 Thread Frank Millman
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'

Re: Question about ast.literal_eval

2013-05-20 Thread Chris Angelico
On Mon, May 20, 2013 at 5:55 PM, 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 *execute code*, while literal_eval will not. That's the protection. With ast.literal_eval, all that can happen

Re: Question about ast.literal_eval

2013-05-20 Thread Frank Millman
On 20/05/2013 09:55, Chris Angelico wrote: On Mon, May 20, 2013 at 5:50 PM, Frank Millman 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 can

RE: Question about ast.literal_eval

2013-05-20 Thread Carlos Nepomuceno
> 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 abo

Re: Please help with Threading

2013-05-20 Thread Fábio Santos
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 c

Re: Question about ast.literal_eval

2013-05-20 Thread Chris Angelico
On Mon, May 20, 2013 at 5:50 PM, Frank Millman 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 ri

RE: Please help with Threading

2013-05-20 Thread Carlos Nepomuceno
> 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 wrote: > | On 18 May 2013 20:33

Re: Question about ast.literal_eval

2013-05-20 Thread Frank Millman
[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 generi

RE: Please help with Threading

2013-05-20 Thread Carlos Nepomuceno
> 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 wrote: > | Just been told that GIL doesn't ma

Re: Please help with Threading

2013-05-20 Thread Cameron Simpson
On 20May2013 07:25, Fábio Santos wrote: | On 18 May 2013 20:33, "Dennis Lee Bieber" 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 lik

Re: How to run a python script twice randomly in a day?

2013-05-20 Thread Cameron Simpson
On 20May2013 09:47, Avnesh Shakya wrote: | On Mon, May 20, 2013 at 9:42 AM, Cameron Simpson wrote: | > On 19May2013 20:54, Avnesh Shakya 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

Re: Question about ast.literal_eval

2013-05-20 Thread Chris Angelico
On Mon, May 20, 2013 at 5:05 PM, 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 > Bo

RE: Question about ast.literal_eval

2013-05-20 Thread Carlos Nepomuceno
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 -

CFP: MuCoCoS Workshop at PACT-2013 (Edinburgh, Scotland, UK)

2013-05-20 Thread SP
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 Techni

Question about ast.literal_eval

2013-05-20 Thread Frank Millman
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

Re: Future standard GUI library

2013-05-20 Thread Terry Jan Reedy
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.fl