Re: A rather unpythonic way of doing things

2005-09-29 Thread Cyril Bazin
"Crypthonic" could be the exact word...On 29 Sep 2005 15:19:11 +0100, Peter Corbett <[EMAIL PROTECTED] > wrote:Richie Hindle <[EMAIL PROTECTED] > writes:>> [Peter]> > http://www.pick.ucam.org/~ptc24/yvfc.html>> [Jeff]> > Yuma Valley Agricultural Center? > > Yaak Valley Forest Council?>> I went thro

meschach + Python

2005-10-31 Thread Cyril Bazin
Hello, I need to compute eigenvalues and eigenvectors on sparse matrix. I found a C library "meschach" which seems to do the work. Unfortunatly, this libray doesn't seem to be interfaced in Python. Has anyone ever used this library and interfaced it in Python or has a solution to compute eigenva

Re: Can Anyone Help me on this

2005-11-03 Thread Cyril Bazin
Here is an example of copying then reversing a list: >>> l1 = [1,2,"C"] >>> l2 = l1[:] >>> l2.reverse() >>> l2 ['C', 2, 1] -- http://mail.python.org/mailman/listinfo/python-list

Re: initialising a list of lists

2005-11-16 Thread Cyril Bazin
Hello, >>> b = [[] for _ in xrange(6)] # <- note the xrange! >>> b[3].append('X') >>> b [[], [], [], ['X'], [], []] This syntax might be less hairy but could be better when you use large table. You can hide this syntax by making a function: def buildMatrix(nbRows):     return [[] for _ in xrange

Re: Loop until condition is true

2005-06-21 Thread Cyril BAZIN
Another question could be: why is there not a statement "whileTrue" or "loop"? For exemple: whileTrue:     statement 1     if condition:     break     statement 2 It could be an economy of one unuseful test by loop.On 6/21/05, Magnus Lycka <[EMAIL PROTECTED]> wrote: Remi Villate

Re: Boss wants me to program

2005-06-28 Thread Cyril BAZIN
Hello, If you have enough money to buy a licence, Visual Basic seem a very good option. (But you should learn how to use design patterns.) Without knowing this language I was able to perform a graphical user interface to interact with an automat, a mySQL database and many analogical sensors in le

Re: f*cking re module

2005-07-04 Thread Cyril BAZIN
If you are looking for HTML tags or something like that. Have a look at the HTMLParser (docs.python.org). On 4 Jul 2005 03:37:02 -0700, jwaixs <[EMAIL PROTECTED]> wrote: > Thank you for your replies, it's much obvious now. I know more what I > can and can't do with the re module. But is it possibl

Re: FORTRAN like formatting

2005-07-08 Thread Cyril BAZIN
Hello, I don't anderstand very well Fortran syntax, but want you say something like that: def toTable(n1, n2, n3): return "%20s%20s%20s"%tuple(["%.12f"%x for x in [n1, n2, n3]]) Example: >>> import math >>> toTable(math.pi, 10, 8.2323) ' 3.141592653590 10. 8.232300

Re: FORTRAN like formatting

2005-07-09 Thread Cyril Bazin
On Fri, 8 Jul 2005 20:31:06 +0200, Cyril BAZIN <[EMAIL PROTECTED]> > declaimed the following in comp.lang.python: > > > > > > def toTable(n1, n2, n3): > > return "%20s%20s%20s"%tuple(["%.12f"%x for x in [n1, n2, n3]]) > > >

Re: Tricky Dictionary Question from newbie

2005-07-11 Thread Cyril Bazin
Hello, Try that, it may not be the better solution, but it seems to work: #def invertDict(d): #    d2 = {} #    for k, v in d.iteritems(): #    d2.setdefault(v, []).append(k) #    return d2 Cyril On 7/11/05, Ric Da Force <[EMAIL PROTECTED]> wrote: Hi all,I have a dictionary containing about

Re: Tricky Dictionary Question from newbie

2005-07-11 Thread Cyril Bazin
Hum... I think an iteritems is better, this way, python don't need to create in memory a complete list of couple key, value.On 7/11/05, Markus Weihs <[EMAIL PROTECTED]> wrote: Hi! Dict = {'rt': 'repeated', 'sr':'repeated', 'gf':'not repeated'} NewDic = {} for k,v in Dict.items(): NewDic.setdef

Re: Replacing last comma in 'C1, C2, C3' with 'and' so that it reads 'C1, C2 and C3'

2005-07-12 Thread Cyril Bazin
If that can help you... def replaceLastComma(s):     i = s.rindex(",")     return ' and'.join([s[:i], s[i+1:]])     I don't know of ot's better to do a: ' and'.join([s[:i], s[i+1:]]) Or: ''.join([s[:i], ' and', s[i+1:]]) Or: s[:i] + ' and' + s[i+1] Maybe the better solution is not in the list...

Re: Trying to come to grips with static methods

2005-07-12 Thread Cyril Bazin
Im my opinion, class method are used to store some "functions" related to a class in the scope of the class. For example, I often use static methods like that: class Foo: On 7/12/05, Steven D'Aprano <[EMAIL PROTECTED]> wrote: I've been doing a lot of reading about static methods in Python, a

Re: Trying to come to grips with static methods

2005-07-12 Thread Cyril Bazin
(sorry, my fingers send the mail by there own ;-) Im my opinion, class method are used to store some functionalities (function) related to a class in the scope of the class. For example, I often use static methods like that: class Point:     def __init__(self, x, y):     self.x, self.y = x, y

Re: Trying to come to grips with static methods

2005-07-12 Thread Cyril Bazin
Cyril On 7/12/05, Robert Kern <[EMAIL PROTECTED]> wrote: Cyril Bazin wrote:> (sorry, my fingers send the mail by there own ;-)>> Im my opinion, class method are used to store some functionalities> (function) related to a class in the scope of the class. >> For example, I

Re: Efficiently Split A List of Tuples

2005-07-13 Thread Cyril Bazin
if t is your data, you can use: l1, l2 = zip(*t) Cyril On 7/14/05, Richard <[EMAIL PROTECTED]> wrote: I have a large list of two element tuples.  I want two separatelists: One list with the first element of every tuple, and thesecond list with the second element of every tuple.Each tuple contains

Re: What is your favorite Python web framework?

2005-07-18 Thread Cyril Bazin
Hello, I never used a web framework using Python modules, but I think cheetah, Karrigel and CherryPy are not good since they allow user to play with the HTML code. IMO, it's not pythonic but phpythonic. Isn't there a python framework inspirated by the Smalltalk framework Seaside? I think it's th

Re: Dictionary, keys and alias

2005-07-18 Thread Cyril Bazin
I think "hash" doesn't guarantee the unicity of the result. But, it should avoid the collisions... >>> foo = "foo" >>> hash(foo) -740391237 >>> hash(-740391237) -740391237 I think it's like some kind md5sum... I propose this solution: ---

Re: Dictionary, keys and alias

2005-07-19 Thread Cyril Bazin
Glauco, Be careful if you decide to use hash. There is possibility of bugs due to that approach, (if hash(x) == hash(y) and x != y). Even if the probability of bug is near 0, your computer will certainly recall you what is the murphy law. If I were you, I would prefer another approach. Cyril O

Re: python certification

2005-07-20 Thread Cyril Bazin
Fine, Go to "http://www.pythonchallenge.com" and try the challenge, if you are able to get to the level 17-18, you can say you start to have good skills in Python. You will  prove: you are not stupid, you know regex, basic sound/image treatment, the basics of zip/bz2, you understood how to use u

Re: How to store "3D" data? (data structure question)

2005-07-20 Thread Cyril Bazin
The question of the type of the data sutructure depends of your use of the data. You could avoid some confusion without naming your columns "lines"... Anyway, here is a piece of code that read the file and count the star on the fly: (The result is a dict of dict of int.)

Re: Hash functions

2005-07-21 Thread Cyril Bazin
Maybe in certain case you could use hash to compare objects (hashable of course) quicker by comparing there hash values, if the hash values are the same you test the equality between the objects. But the sets and dicts cover the greatest part of the use of hash. (Personally, I never used that exp

Re: Simple Problem

2005-07-24 Thread Cyril Bazin
By any chance are you speaking about the function "repr" ? Cyril On 24 Jul 2005 18:14:13 -0700, ncf <[EMAIL PROTECTED]> wrote: I know I've seen this somewhere before, but does anyone know what thefunction to escape a string is? (i.e., encoding newline to "\n" and achr(254) to "\xfe") (and visa-vers

Re: First app, thanks people

2005-07-25 Thread Cyril Bazin
In case you want some advises for your code: -backslashes are not necesseary when you declare list or dict on many lines. I didn't pay attention at the semantic of your code, but after giving a quick look, you can simplify things like: BRUSHSTYLENAMES = ['Transparent', 'Solid', 'BDiagonalHatch'

Re: Parallel arithmetic?

2005-08-04 Thread Cyril Bazin
Hello, I propose 3 solutions. If someone have time to waste, he can make a benchmark to know which is the fastest and give us the results on the list. Solution 1: import itertools c = [a_i-b_i for a_i, b_i in itertools.izip(a, b)] Solution 2: c = map(operator.sub, a, b) #"map" will be removed

Re: Splitting a string into groups of three characters

2005-08-08 Thread Cyril Bazin
Another solution derived from an old discussion about the same problem? def takeBy(s, n):     import itertools     list(''.join(x) for x in itertools.izip(*[iter(s)]*n)) (Hoping len(s) % n = 0) CyrilOn 8 Aug 2005 11:04:31 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED] > wrote:Yes i know i made a mi

Re: need help with python syntax

2005-08-11 Thread Cyril Bazin
I think bs = BeautifulSoup.BeautifulSoup( oFile) but I don't understand what you are doing... (I never used BeautifulSoup...) Maybe It is somthing like: import itertools for incident in itertools.chain(bs('tr',  {'bgcolor' : '#ee'}), bs('tr',  {'bgcolor' : 'white'})):     do_something() Look

Re: Help sorting a list by file extension

2005-08-12 Thread Cyril Bazin
Maybe simpler but not very much simpler: one line for each solution. And in your solution the lambda is evaluated at each comparaison of the sort algorithm isn't it? So your code seems less productive than the bengt's code which apply the same code as the lambda only one time by entry in the li

Re: A PIL Question

2005-08-14 Thread Cyril Bazin
Try Image.new in place of Image.Image if you want to build a new image. At which level are you? CyrilOn 14 Aug 2005 10:34:38 -0700, Ray <[EMAIL PROTECTED]> wrote: Hello,I'm using latest PIL version with Python 2.4.1. (for solving a level inPython Challenge actually...). Anyway, I'm trying to draw

Re: [newbie]search string in tuples

2005-08-20 Thread Cyril Bazin
Try the code below. #- list=["airplane","car","boat"] select = None while select not in list:   select=raw_input("Which vehicle?")#- Cyril On 8/20/05, Viper Jack <[EMAIL PROTECTED]> wrote: Hi all,i'm

Re: How to write this iterator?

2005-09-20 Thread Cyril Bazin
Ok! Now, you wrote your expected results I understand better what you want to do... Your solution seems fine except the "except IndexError:" part. I would have wrote: -- ...            except IndexError:                if self.iters:                    sel

listerator clonage

2005-02-12 Thread Cyril BAZIN
Hello, I want to build a function which return values which appear two or more times in a list: So, I decided to write a little example which doesn't work: #l = [1, 7, 3, 4, 3, 2, 1] #i = iter(l) #for x in i: #j = iter(i) #for y in j: #if x == y: #print x In thinked

Re: [perl-python] exercise: partition a list by equivalence

2005-02-18 Thread Cyril BAZIN
Hello John, Try your python code on this example: merge([[1,2], [3,4], [1,2], [5,3]]) The result given by your function is: [[3, 4, 5]] Sorry... To Xah: next time you propose an exercise, write some UNIT TESTS!!! Then people will be able to test if there answers are correct or not. Cyril

Re: executea string

2005-02-22 Thread Cyril BAZIN
> > c=2 > > e=3 > > s="12" > > code.append('funtion ("c, e,s")') > > print "\n".join(code) + '\n' > > Hello, You could try this: --- from string import Template code = "" c=2 e=3 s="12" code.append(Template('function ("$c, $e, $s")').substitute(vars())) print "\n".join

Re: How do I import everything in a subdir?

2005-03-07 Thread Cyril BAZIN
Hello, If you want to look for the files "*.py" in a directory, don't use shell command!!! You have many ways to access the content of a directory in Python. For exemple, you can use the glob module: >>> import glob >>> glob.glob('./[0-9].*') ['./1.gif', './2.txt'] >>> glob.glob('*.gif') ['1.gif

Re: flatten a level one list

2006-01-12 Thread Cyril Bazin
Another try: def flatten6(x, y): return list(chain(*izip(x, y))) (any case, this is shorter ;-) Cyril On 1/12/06, Michael Spencer <[EMAIL PROTECTED]> wrote: > Tim Hochberg wrote: > > Michael Spencer wrote: > >> > Robin Becker schrieb: > >> >> Is there some smart/fast way to flatten a leve

Re: flatten a level one list

2006-01-13 Thread Cyril Bazin
I added my own function to the benchmark of Robin Becker:from itertools import chaindef flatten9(x, y):   return list(chain(*izip(x, y)))Results: no psyco Name   10   20  100  200  500 1000 flatten1  104.499  199.699  854.301 167

Re: How to download a web page just like a web browser do ?

2006-08-23 Thread Cyril Bazin
look at the modules urllib and urllib2, they both are provided with python : http://docs.python.org/lib/module-urllib.html http://docs.python.org/lib/module-urllib2.htmlAnd look at the examples :http://docs.python.org/lib/node483.html http://docs.python.org/lib/urllib2-examples.htmlOn 23 Aug 2006 0

Re: Python-like C++ library

2006-08-23 Thread Cyril Bazin
Look at boost and boost.python . In your case, bosst.python seems more interesting, but you take a look at boost it may  help you at work... http://www.boost.org/ http://www.boost.org/libs/python/doc/CyrilOn 23 Aug 2006 07:19:42 -0700, Will McGugan <[EMAIL PROTECTED] > wrote:Hi folks,I'm forced to

www.mywebsite.py

2006-01-24 Thread Cyril Bazin
Does someone ever tried (and succeed) to make an address like "www.website.py".I found that the .py extension is given to the paraguay.I found this link ( http://www.nic.py/) but I don't speak spanish... If someone has more informations...Cyril -- http://mail.python.org/mailman/listinfo/python-lis

Re: PEP 354: Enumerations in Python

2006-02-28 Thread Cyril Bazin
What about that? SomeNumbers = enum('0', '1', '2', '3', '4', '5', '6', '7') or Rooms = enum('1bed', '2beds', 'moreThan2beds') or even Comments = enum('#', ';', '//') CyrilOn 28 Feb 2006 03:14:25 -0800, Carl Banks <[EMAIL PROTECTED]> wrote: Stefan Rank wrote:> on 28.02.2006 07:50 Carl Banks s

Re: Vectorization and Numeric (Newbie)

2006-02-28 Thread Cyril Bazin
Are you looking for the "map" function? >>> def f(x): return x+4 >>> map(f, [1,2,3,3,70]) [5, 6, 7, 7, 74] CyrilOn 2/28/06, Ronny Mandal <[EMAIL PROTECTED]> wrote: Assume you have a mathematical function, e.g. f(x) = x + 4To calculate all the values from 1 to n, a loop is one alternative.But to m

Re: spliting on ":"

2006-03-04 Thread Cyril Bazin
Your file looks like a list of IP adresses. You can use the urllib and urllib2 modules to parse IP adresses.import urllib2for line in open("fileName.txt"):    addr, port  = urllib2.splitport(line)     print (port != None) and '' or portCyril -- http://mail.python.org/mailman/listinfo/python-list

Re: spliting on ":"

2006-03-04 Thread Cyril Bazin
ort(line)     if port == None:    print ''     else:    print port On 3/4/06, Peter Hansen <[EMAIL PROTECTED]> wrote: Cyril Bazin wrote:> Your file looks like a list of IP adresses.> You can use the urllib and urllib2 modules to parse IP adresses.>> import

Re: spliting on ":"

2006-03-06 Thread Cyril Bazin
On 3/6/06, Bryan Olson <[EMAIL PROTECTED]> wrote: Peter Hansen wrote:> The archives could tell you more, but basically on is usually interested> in *identity* with a singleton object (None), not in whether the object> on is examining happens to compare equal.  A custom object could be > designed to

Re: searching substrings with interpositions

2005-05-24 Thread Cyril BAZIN
Just another solution, pretty and effective: def fct(a, b):   idx = -1   for c in a:     idx = b.find(c, idx+1)     if idx == -1:   return False   return True On 24 May 2005 06:06:03 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED] > wrote:thanx everyone, is what i need.As Claudio argues, it's a st

Re: Is there a better way of doing this?

2005-05-29 Thread Cyril BAZIN
Hi, I don't know very well what you want to do, but if you want to parse c++, take a look at "GCC-XML python" (http://www.gccxml.org) and the python binding (http://pygccxml.sourceforge.net/). These tools translate c++ code to XML. Then, you can parse xml with your favorite tools and find the name

Geometry library

2005-06-14 Thread Cyril BAZIN
Hello, I am looking for a geometry library for Python. I want to make some computations like:  -distance between vertex and polygon, vertex and polyline, vertex and segment, etc  -if a point is inside a polygon, if a polyline intersect a polygon, etc Thanks for your help, Cyril -- http://mail

Problem with MySQLdb and mod_python

2008-07-15 Thread Cyril Bazin
6, 13:58:00) [GCC 4.1.1 20061011 (Red Hat 4.1.1-30)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import MySQLdb >>> MySQLdb.__version__ '1.2.2' >>> import mod_python >>> mod_python.version '3.3.1' - If someone has any information that can help me... Thanks in advance, Cyril BAZIN -- http://mail.python.org/mailman/listinfo/python-list

Re: Problem with MySQLdb and mod_python

2008-07-17 Thread Cyril Bazin
think the problem comes from the MySQLdb module. If I can't find another solution, I think I will downgrade the MySQLdb version to 1.2.1 Cyril On Thu, Jul 17, 2008 at 7:27 AM, Lawrence D'Oliveiro <[EMAIL PROTECTED]> wrote: > In message <[EMAIL PROTECTED]>, Cyril Bazin >

Re: Try Python!

2006-03-30 Thread Cyril Bazin
Now, you can try "laszlo in 10 minutes" http://www.laszlosystems.com/lps/laszlo-in-ten-minutes/ . Reference: http://www.openlaszlo.org/ -- http://mail.python.org/mailman/listinfo/python-list

Re: GIS

2006-04-03 Thread Cyril Bazin
Postgis is only an extension of Postgres which add new classes and new operations specialised for GIS. All you should know, is how to build SQL requests for postgres... If you want to be familiarised with the GIS, you should try to make your own little project. So you will be able to ask more pre