Re: string interpolation for python

2012-04-02 Thread Laurent Claessens
Seems you miss understood my notion of dynamic string. Dynamic strings are expressions in disguise: the things in between $...$ are plain old expressions (with optional formatting specifications). They are evaluated as if they were outside the dynamic string. We put them in there to to kill two

Re: Distribution

2012-03-20 Thread Laurent Claessens
Il 20/03/2012 12:21, Ben Finney ha scritto: prince.pangeniprince.ra...@gmail.com writes: I am doing a simulation project using Python. In my project, I want to use some short of distribution to generate requests to a server. I guess scipy is also available in plain python (didn't

Re: what is best method to set sys.stdout to utf-8?

2012-03-07 Thread Laurent Claessens
() ... well ... a part of the fact that it is much longer ? Laurent Claessens -- http://mail.python.org/mailman/listinfo/python-list

Re: Naming convention for in-house modules (Newbie question)

2012-02-09 Thread Laurent Claessens
Here is my question: I would like to start an in-house library of small modules to import, for things like error handling/logging. That's easy enough, but is there a recommended way of naming such modules? I am concerned about avoiding name clashes with standard modules and site packages.

Re: Naming convention for in-house modules (Newbie question)

2012-02-09 Thread Laurent Claessens
This is not 100% an answer to the question, but you should read that : http://www.python.org/dev/peps/pep-0008/ The OP mentions PEP 8 in the bit of his message that you *don't* quote. Well... I've to sleep. Sorry :( Laurent -- http://mail.python.org/mailman/listinfo/python-list

Re: Killing threads, and os.system()

2012-01-31 Thread Laurent Claessens
Le 31/01/2012 17:04, Dennis Lee Bieber a écrit : Of course, if that thread is stuck waiting for a call to os.system() to complete, then it can not do anything... os.system() is a rather limited, restrictive, call -- best used for quick one-of operations. If running Python

Killing threads, and os.system()

2012-01-30 Thread Laurent Claessens
Hello all I've a program that launches a lot of threads and each of them launches a os.system(my_command). My program also keeps a list of the launched threads, so I can make for loops on the threads. My aim is to kill everything with ctrl-C (KeyboardInterrupt). Of course I tried

Re: ERROR:root:code for hash md5 was not found

2012-01-11 Thread Laurent Claessens
Le 11/01/2012 12:19, mike a écrit : Hi, We are running are running Python program on Redhat 5.5. When executing our program we get the following error ( see below). Any ideas what this is due to? On my computer hashlib has md5 : Python 2.6.6 (r266:84292, Sep 15 2010, 16:22:56) [GCC

Re: Complete beginner, any help appreciated :) - For Loops

2011-12-01 Thread Laurent Claessens
for x in y However, what does for and in mean in this context? It means basically the same as in Englsish Does the following links answer the question ? http://www.ibiblio.org/g2swap/byteofpython/read/for-loop.html http://dsnra.jpl.nasa.gov/software/Python/diveintopython.pdf (page 58) Have

Re: suitability of python

2011-11-24 Thread Laurent Claessens
Le 24/11/2011 13:31, Rudra Banerjee a écrit : Dear friends, I am a newbie in python and basically i use python for postprocessing like plotting, data manipulation etc. Based on ease of programming on python I am wondering if I can consider it for the main development as well. My jobs (written on

Re: Extracting elements over multiple lists?

2011-11-07 Thread Laurent Claessens
Le 07/11/2011 18:12, JoeM a écrit : Howdy, If I have a few lists like a=[1,2,3,4,5] b=[one, two, three, four, five] c=[cat, dog, parrot, clam, ferret] what is the most pythonic method of removing the first element from all of the lists? Do you want to remove the first item of each list, or

Re: Extracting elements over multiple lists?

2011-11-07 Thread Laurent Claessens
Le 07/11/2011 19:01, JoeM a écrit : Thanks guys, I was just looking for a one line solution instead of a for loop if possible. Why do you consider [x.remove(x[0]) for x in [a,b,c]] cheating? It seems compact and elegant enough for me. I have the feeling that it does not do what I expect it

Re: Entre local et global

2011-10-28 Thread Laurent Claessens
Woops. This was aimed to the french speaking python's usenet. Sorry. Laurent Le 28/10/2011 11:29, Laurent a écrit : Le 28/10/2011 10:43, ll.snark a écrit : On 27 oct, 17:06, Laurent Claessensmoky.m...@gmail.com wrote: J'aimerais donc pouvoir indiquer dans fonca, que la variable lst

Re: 1/2 evaluates to 0

2011-10-13 Thread Laurent Claessens
Wohaw. This means that this behavior is going to be default in a foreseeable future ? It's the default in 3.x. I can't imagine it ever being the default in 2.x. 2.7 is now in bug-fix only mode, so no new features, and there won't be a 2.8, so true division will never be the default in

Re: 1/2 evaluates to 0

2011-10-13 Thread Laurent Claessens
You should get in touch with the Sage developers. In the Sage FAQ they say that until SciPy is ported to run with Python 3.x and Cython supports Python 3.x, Sage will continue to use Python 2.x. ``scipy.weave``. So according to the Sage FAQ there is no reason why Sage shouldn't support

1/2 evaluates to 0

2011-10-12 Thread Laurent Claessens
Hi all This is well known : 1/2 0 This is because the division is an integer division. My question is : how can I evaluate 1/2 to 0.5 ? Is there some non integer division operator ? Up to now I workarounded writing float(1)/2. Is there an other way ? My Zen of python says : There should

Re: Counting the number of call of a function

2011-09-30 Thread Laurent Claessens
The keys of globals() are the _names_. You're giving it the function itself. Ow, ok. I didn't caught it. I understand now. A decorator would be better. Yes. I keep the solution with foo=Wraper(foo) Thanks a lot all ! Laurent -- http://mail.python.org/mailman/listinfo/python-list

Re: Question on Manipulating List and on Python

2011-09-29 Thread Laurent Claessens
Le 29/09/2011 18:27, John Gordon a écrit : Ina6679459-fc57-4389-8d43-1e5ed960d...@y18g2000yqy.googlegroups.com Subhabrata Banerjeesubhagurgaon2...@gmail.com writes: (i) I have a file of lists. Now, the first digit starts with a number or index, like, [001, Obama, USA, President] [002

Counting the number of call of a function

2011-09-29 Thread Laurent Claessens
Hello Is it possible to count the number of time a function is called ? Of course, if I've access to the source code, it's easy. I tried the following : def foo(): print foo ! class wraper(object): def __init__(self,fun): globals()[fun]=self.replacement def

Re: how to call a function for evry 10 secs

2011-06-30 Thread Laurent Claessens
But if the function itself runs for longer than 10 seconds, there will be a major problem, as the sleep apparently takes the argument as unsigned, and a negative number is a very big sleep! Launch each call in a separate thread. If the calls are independent, this could be a solution.

Re: reg: playing with the list

2011-06-24 Thread Laurent Claessens
You might try writing the boolean function is_prime(n) for almost any n. There was a recent discussion on this topic. Since the guy is new in programming, I complete the answer, just in case. Using the function is_prime(n), FIRST POSSIBILITY : new_list=[] for n in old_list: if

Re: help me in knowing the syntax for loop and switch statements in python 3.2

2011-06-23 Thread Laurent Claessens
Le 23/06/2011 11:48, mahantesh varavattekar a écrit : Hi, i am new to python please help to let me know the syntax for python 3.2. with examples. and how can i use these things for ranges http://lmgtfy.com/?q=python+syntax+range+example Laurent --

Re: What is this syntax ?

2011-06-19 Thread Laurent Claessens
Le 19/06/2011 15:41, candide a écrit : With Python 2.7 : x=foo print ''+x+'' foo What is this curious syntax on line 2 ? Where is it documented ? When you want to have an explicit double quote in a string, you put in between single quote '. (and vice versa) So here you have

Re: threading : make stop the caller

2011-06-19 Thread Laurent Claessens
Le 19/06/2011 17:19, Chris Angelico a écrit : On Mon, Jun 20, 2011 at 12:42 AM, Laurent Claessensmoky.m...@gmail.com wrote: Hello I've a list of tasks to perform. Each of them is a threading.Thread. Basically I have : while task_list : task = task_list[0] task.run()

Re: threading : make stop the caller

2011-06-19 Thread Laurent Claessens
Le 19/06/2011 18:03, Chris Angelico a écrit : On Mon, Jun 20, 2011 at 1:39 AM, Laurent Claessensmoky.m...@gmail.com wrote: My problem is that when FileToCopyTask raises an error, the program does not stop. In fact when the error is Disk Full, I want to stop the whole program because I know

Re: threading : make stop the caller

2011-06-19 Thread Laurent Claessens
Popping task off the end of the list is more efficient: while task_list: task_list.pop().start() That's cool. In my case it's better to do task_list.pop(0).start in order to pop the first element. or if the list is static No, my list is dynamic and is feeded by an other thread

threading : make stop the caller

2011-06-19 Thread Laurent Claessens
Hello I've a list of tasks to perform. Each of them is a threading.Thread. Basically I have : while task_list : task = task_list[0] task.run() task_list.remove(task) Now I want, in some circumstance to raise errors that make the loop stop. In order IOError to make stop the

Re: threading : make stop the caller

2011-06-19 Thread Laurent Claessens
I read the library documentation. I think that if I get a trick to kill a thread, then I'm done. Is there a way ? Laurent Le 19/06/2011 17:39, Laurent Claessens a écrit : Le 19/06/2011 17:19, Chris Angelico a écrit : On Mon, Jun 20, 2011 at 12:42 AM, Laurent Claessensmoky.m...@gmail.com

Re: os.path and Path

2011-06-16 Thread Laurent Claessens
So, I suppose I shall have to let go of my dreams of -- Path('/some/path/and/file') == '\\some\\path\\and\\file' and settle for -- Path('...') == Path('...') but I don't have to like it. :( Why not define the hash method to first convert to '/some/path/and/file' and then hash ? By

Re: the stupid encoding problem to stdout

2011-06-10 Thread Laurent Claessens
Le 09/06/2011 04:18, Sérgio Monteiro Basto a écrit : hi, cat test.py #!/usr/bin/env python #-*- coding: utf-8 -*- u = u'moçambique' print u.encode(utf-8) print u chmod +x test.py ../test.py moçambique moçambique The following tries to encode before to print. If you pass an already

Re: the stupid encoding problem to stdout

2011-06-09 Thread Laurent Claessens
Le 09/06/2011 04:18, Sérgio Monteiro Basto a écrit : hi, cat test.py #!/usr/bin/env python #-*- coding: utf-8 -*- u = u'moçambique' print u.encode(utf-8) print u chmod +x test.py ../test.py moçambique moçambique The following tries to encode before to print. If you pass an already

Re: the stupid encoding problem to stdout

2011-06-09 Thread Laurent Claessens
Le 09/06/2011 04:18, Sérgio Monteiro Basto a écrit : hi, cat test.py #!/usr/bin/env python #-*- coding: utf-8 -*- u = u'moçambique' print u.encode(utf-8) print u chmod +x test.py ../test.py moçambique moçambique The following tries to encode before to print. If you pass an already

Re: scope of function parameters

2011-05-30 Thread Laurent Claessens
Le 29/05/2011 23:42, Ben Finney a écrit : Peter Pearsonppearson@nowhere.invalid writes: Python works in terms of objects having names, and one object can have many names. Or no names. So it's less accurate (though better than talking of “variables”) to speak of Python objects “having

Re: scope of function parameters

2011-05-30 Thread Laurent Claessens
Le 30/05/2011 11:02, Terry Reedy a écrit : On 5/30/2011 3:38 AM, Laurent wrote: Cool. I was thinking that 5 was the name, but 5.__add__(6) File stdin, line 1 5.__add__(6) Try 5 .__add__(6) What is the rationale behind the fact to add a space between 5 and .__add__ ? Why does it

Re: scope of function parameters

2011-05-30 Thread Laurent Claessens
What is the rationale behind the fact to add a space between 5 and .__add__ ? Why does it work ? It's a hint for the tokenizer. I didn't know the tokenizer. Now I understand. Thanks Laurent -- http://mail.python.org/mailman/listinfo/python-list

Re: scope of function parameters

2011-05-30 Thread Laurent Claessens
What is the rationale behind the fact to add a space between 5 and .__add__ ? Why does it work ? It's a hint for the tokenizer. I didn't know the tokenizer. Now I understand. Thanks Laurent -- http://mail.python.org/mailman/listinfo/python-list

Re: Parsing a graph image

2011-05-13 Thread Laurent Claessens
Yes, I want to extract the data that is contained in an image file. Greets Maybe ask to imagemagick's or matplotlib. They should know if it is possible at all. Good luck. Laurent -- http://mail.python.org/mailman/listinfo/python-list

Re: Parsing a graph image

2011-05-13 Thread Laurent Claessens
Yes, I want to extract the data that is contained in an image file. Greets Maybe ask to imagemagick's or matplotlib. They should know if it is possible at all. Good luck. Laurent -- http://mail.python.org/mailman/listinfo/python-list

Re: Parsing a graph image

2011-05-13 Thread Laurent Claessens
Yes, I want to extract the data that is contained in an image file. Greets Maybe ask to imagemagick's or matplotlib. They should know if it is possible at all. Good luck. Laurent -- http://mail.python.org/mailman/listinfo/python-list

Re: Parsing a graph image

2011-05-13 Thread Laurent Claessens
Yes, I want to extract the data that is contained in an image file. Greets Maybe ask to imagemagick's or matplotlib. They should know if it is possible at all. Good luck. Laurent -- http://mail.python.org/mailman/listinfo/python-list

Re: Parsing a graph image

2011-05-13 Thread Laurent Claessens
Yes, I want to extract the data that is contained in an image file. Greets Basti Yes, I want to extract the data that is contained in an image file. Greets Maybe ask to imagemagick's or matplotlib. They should know if it is possible at all. Good luck. Laurent --

Re: Parsing a graph image

2011-05-13 Thread Laurent Claessens
I guess it requires some kind of image processing , where you can move around image pixel by pixel and somehow figure out what color is present in that pixel . If there isn’t much noise in the image you should sharp contrast and would be able to differentiate between two colors ? if yes ( I

Re: Python backup programs?

2011-05-11 Thread Laurent Claessens
Le 11/05/2011 01:57, James Mills a écrit : On Wed, May 11, 2011 at 9:00 AM, Dan Strombergdrsali...@gmail.com wrote: What are your favorite backup programs written, in whole or in part, in Python? My favorite one is the one I wrote myself for myself ;) The point I like : 1. the backup

Re: checking if a list is empty

2011-05-11 Thread Laurent Claessens
In this case, the interpretation of an arbitrary object as a boolean is peculiar for python. An empty list is a real, existing object, and the supposition that [] be false is counter-intuitive. It can be learnt, and the shorthand may be powerful when it is, but it will confuse many readers.

Re: checking if a list is empty

2011-05-11 Thread Laurent Claessens
I believe you are grossly oversimplifying whatever code you had. Using the definition of f from above: theta = math.pi/4 f(math.cos(2*theta)) 6.12303176911e-17 Yes: its oversimplifued. The angle come from a normal vector of a curve and so on In particular, I was using Sage; the

Re: checking if a list is empty

2011-05-11 Thread Laurent Claessens
I believe you are grossly oversimplifying whatever code you had. Using the definition of f from above: theta = math.pi/4 f(math.cos(2*theta)) 6.12303176911e-17 Yes: its oversimplifued. The angle come from a normal vector of a curve and so on In particular, I was using Sage; the

Re: [2.5.1] Script to download and rename bunch of files?

2011-04-08 Thread Laurent Claessens
Le 08/04/2011 14:47, Gilles Ganault a écrit : Hello, Before I go ahead and learn how to write this, I was wondering if someone knew of some source code I could use to download and rename a bunch of files, ie. the equivalent of wget's -O switch? I would provide a two-column list where

Re: Non-deterministic output

2011-03-28 Thread Laurent Claessens
One of us thought it could be set and dictionaries not always yielding the same results. I, however, would think that given the exact same operations, a set/dictionary would always yield the same results. Am I correct? Or could different runs of the same program yield different results due to,

Re: Decorator Syntax

2011-03-22 Thread Laurent Claessens
And I'm willing to bet that there are plenty of scripts out there that use dec as a name for Decimal objects. You won. I owe you a beer ;) Laurent -- http://mail.python.org/mailman/listinfo/python-list

Re: os.path.walk() to get full path of all files

2011-03-17 Thread Laurent Claessens
file_list = [] for root, _, filenames in os.walk(root_path): for filename in filenames: file_list.append(os.path.join(root, filename)) What does the notation _ stands for ? Is it a sort of /dev/null ? I know that in the terminal it represents the last printed text. Laurent

Re: alphanumeric list

2011-03-16 Thread Laurent Claessens
string = EE472B t = [] for x in string[:]: print t.append(A) #i don't want to append A, the final result is EAEA4A7A2ABA As it, it prints None 6 times. Then t is ['A','A','A','A','A'] What you have to do is to read about basic python. Search for python tutorial on the net. Then

Re: alphanumeric list

2011-03-16 Thread Laurent Claessens
string = EE472B t = [] for x in string[:]: print t.append(A) #i don't want to append A, the final result is EAEA4A7A2ABA As it, it prints None 6 times. Then t is ['A','A','A','A','A'] What you have to do is to read about basic python. Search for python tutorial on the net. Then

Re: alphanumeric list

2011-03-15 Thread Laurent Claessens
Le 15/03/2011 09:10, yqyq22 a écrit : Hi all, I would like to put an alphanumeric string like this one EE472A86441AF2E629DE360 in a list, then iterate inside the entire string lenght and change each digit with a random digit. Do u have some suggestion? thanks a lot This can be a way to begin :

LaTeX parser and pstricks generator in python

2010-02-14 Thread Laurent Claessens
Hi all. I just put online a first version of two tools that combine LaTeX and python. The first one, phystricks[1], is a python module intended to generate pstricks code. The main features are * you don't have to know pstricks (but you need to have some basics in python) * you have python