[Tutor] python coding using regular expression

2006-12-21 Thread sg

hi
 i am new to python. i want help in regular expression.. anyone explain
or guide me for following problem..

the content of txt file is splitted using the pipe | symbol and sorted .
then the field in the first row is compared with field in the second row and
the second row field is compared with third and so on till end of file.. if
there is mismatch between the row, the error will be throw as follows..
For example,

david thomson
davis thomson

 in above string 'd' and 's' are mismatched.. so the error will be thrown.

-- 
View this message in context: 
http://www.nabble.com/python-coding-using-regular-expression-tf2863876.html#a8003182
Sent from the Python - tutor mailing list archive at Nabble.com.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python coding using regular expression

2006-12-21 Thread Luke Paireepinart
sg wrote:
> hi
>  i am new to python. i want help in regular expression.. anyone explain
> or guide me for following problem..
>
> the content of txt file is splitted using the pipe | symbol and sorted .
> then the field in the first row is compared with field in the second row and
> the second row field is compared with third and so on till end of file.. if
> there is mismatch between the row, the error will be throw as follows..
> For example,
>
> david thomson
> davis thomson
>
>  in above string 'd' and 's' are mismatched.. so the error will be thrown.
>
>   
This sounds to me like a homework problem.
In any case, there's no reason to use regexps here. 
If you're checking for _any_ difference between two strings, you can 
just use the regular comparison operator:
 >>> 'david thomson' == 'davis thomson'
False

Unless you have some other requirements you haven't mentioned.
HTH,
-Luke
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python coding using regular expression

2006-12-21 Thread Kent Johnson
sg wrote:
> hi
>  i am new to python. i want help in regular expression.. anyone explain
> or guide me for following problem..
> 
> the content of txt file is splitted using the pipe | symbol and sorted .
> then the field in the first row is compared with field in the second row and
> the second row field is compared with third and so on till end of file.. if
> there is mismatch between the row, the error will be throw as follows..
> For example,
> 
> david thomson
> davis thomson
> 
>  in above string 'd' and 's' are mismatched.. so the error will be thrown.

I don't think you need regular expressions for this. What do you mean by 
mismatched? any difference between them, or something more subtle?

If you compare the first row to the second, the second to the third, 
etc, then you will get the error unless every line is the same. Is that 
what you want?

If I understand you, what you want to do can be done with a simple loop 
over the lines with a variable that remembers the value of the previous 
line.

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Project Review

2006-12-21 Thread Carlos
Hello,

I have been working in a script for my master thesis project (M Arch) 
and since this is the first project that I do in this way, I would like 
to know if someone here would be interested in taking a look at what I 
have done so far. My impression is that since I have been learning on my 
own, I am doing stuff probably not in the best way. The idea is that 
someone who really knows about programming can take a look and give me 
some advice to correct the points that are not so good in my code.

I don't know if this is a good thing to ask in this mailing list, or if 
it is possible for someone to take a look and spot my errors, but I 
really can't think of a better way.

Best regards,
Carlos
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Project Review

2006-12-21 Thread Kent Johnson
Carlos wrote:
> Hello,
> 
> I have been working in a script for my master thesis project (M Arch) 
> and since this is the first project that I do in this way, I would like 
> to know if someone here would be interested in taking a look at what I 
> have done so far. My impression is that since I have been learning on my 
> own, I am doing stuff probably not in the best way. The idea is that 
> someone who really knows about programming can take a look and give me 
> some advice to correct the points that are not so good in my code.
> 
> I don't know if this is a good thing to ask in this mailing list, or if 
> it is possible for someone to take a look and spot my errors, but I 
> really can't think of a better way.

If it is a short script you can just include it in an email to the list. 
Longer than 50-100 lines is probably too long for mail. In this case the 
best thing is to put the script on a web site and post the URL to the list.

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python and rpy

2006-12-21 Thread Geoframer

Okay this might not be the best place to post my question, but on the
rpy-list i'm getting no response and i'm really stuck with this problem.
Perhaps anyone on here has run into the same problem... I'm thinking my
newbieness to python probably is one of the reasons why i fail to see
what i'm doing wrong...

R is a statistical language and Rpy is the python interface for it. However
somehow I'm failing to see a step in the python code with which I
address the R language.

in R I can do :

a=diag(10)  #produces an identity matrix of size
10
b=kmeans(a,2,5,10,"Forgy")#calculate a kmeans clustering algorithm on
the 10 vectors contained by the matrix just declared.


in Ipython this does :

-
In [1]: from rpy import *
RHOME= C:\Program Files\R\R-2.4.0
RVERSION= 2.4.0
RVER= 2040
RUSER= C:\Documents and Settings\Ronald
Loading the R DLL C:\Program Files\R\R-2.4.0\bin\R.dll .. Done.
Loading Rpy version 2040 .. Done.
Creating the R object 'r' ..  Done

In [2]: a = r.diag(10)

In [3]: b = r.kmeans(a,2,10,5,"Forgy")
---
rpy.RExceptionTraceback (most recent call
last)

C:\Python24\

RException: Error in as.double.default(x) : (list) object cannot be coerced
to '
double'
-

I've tried numerous things to get it to work, but i basically can not find
out how i do something as simple as the two statements in R in RPython.
Apparently something is going wrong somewhere in the conversion of python
objects to R objects but i can't seem to fix it. There is a code snippet in
the RPy-reference manual but it's only valid for python 2.2 and 2.1 and i
couldn't get it to work on 2.4.

If anyone has a clue on how to do this or can point me in the right
direction, i'd be much oblidged.

Kind Regards - Geofram
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Project Review

2006-12-21 Thread Carlos
Kent,

Yes it is a little longer than that, let me see how can I make it more 
compact and will get back to the list with a URL.

Thanks!!!
Carlos

Kent Johnson wrote:
> Carlos wrote:
>> Hello,
>>
>> I have been working in a script for my master thesis project (M Arch) 
>> and since this is the first project that I do in this way, I would 
>> like to know if someone here would be interested in taking a look at 
>> what I have done so far. My impression is that since I have been 
>> learning on my own, I am doing stuff probably not in the best way. 
>> The idea is that someone who really knows about programming can take 
>> a look and give me some advice to correct the points that are not so 
>> good in my code.
>>
>> I don't know if this is a good thing to ask in this mailing list, or 
>> if it is possible for someone to take a look and spot my errors, but 
>> I really can't think of a better way.
>
> If it is a short script you can just include it in an email to the 
> list. Longer than 50-100 lines is probably too long for mail. In this 
> case the best thing is to put the script on a web site and post the 
> URL to the list.
>
> Kent
>
>

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Project Review

2006-12-21 Thread Christopher Arndt
Carlos schrieb:
> I don't know if this is a good thing to ask in this mailing list, or if 
> it is possible for someone to take a look and spot my errors, but I 
> really can't think of a better way.

It might be a better idea to ask for solutions or hints for a specific problem
or comments on a specific piece of code. Most of us here probably don't have
the time to read through big amounts of code without knowing if we encounter
anything interesting in the process.

So my suggestion is: try to wake our interest by showing us some code where you
think is a problem or by giving us some more background information on your
project. So far I could only gather that you are writing a thesis and there is
something with a cryptic acronym (M Arch) involved. I have not idea, what this
is about, so tell us!

Chris

P.S. This is basically just rephrasing what has been already said by others and
better: http://www.catb.org/~esr/faqs/smart-questions.html
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Project Review

2006-12-21 Thread Jonathon Sisson
Christopher Arndt wrote:
> P.S. This is basically just rephrasing what has been already said by others 
> and
> better: http://www.catb.org/~esr/faqs/smart-questions.html


Seriously, that is an excellent guide.  Eric S. Raymond writes some high 
quality stuff.  Anyone new to posting on this list (or any other, for 
that matter) should read that.  I highly recommend it and thanks Chris 
for posting that link.

And check out some of Eric's other guides and essays as well.  A 
particular favorite of mine (especially if you are interested in open 
source software and the development model utilized by most of the open 
source community) is http://www.catb.org/~esr/writings/cathedral-bazaar/

Great post, Chris.  Thanks!

Jonathon
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Project Review

2006-12-21 Thread Christopher Arndt
Jonathon Sisson schrieb:
> Christopher Arndt wrote:
>> P.S. This is basically just rephrasing what has been already said by others 
>> and
>> better: http://www.catb.org/~esr/faqs/smart-questions.html
> 
> Seriously, that is an excellent guide.  Eric S. Raymond writes some high 
> quality stuff.  Anyone new to posting on this list (or any other, for 
> that matter) should read that.

Well, not all admonitions from this article apply with full force to posters on
this list, because this list is specifically for those who are not no well
versed in Python and often in netiquette as well. But the main point to
remember stays the same:

When you write a question, always ask yourself: how do get somebody to bother
answering _my_ question, by making it interesting for _him/her_, because, as
you always have to keep in mind, he/she will get no other reward for it.

Chris
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tutor Digest, Vol 34, Issue 42

2006-12-21 Thread Carlos

Chis,

In the past  I have received very valuable info from other list users, 
that has helped me to solve problems that I had. Just yesterday Kent 
helped me with something very specific.


I'm asking for a project review because my code is working now, it is 
not complete but it is working. What I need is not a specific solution, 
but more something like a general review of the code. Because while 
probably everything is working, there might be very evident problems 
that are general in nature and that are impossible for me to spot for a 
number of reasons.


What is this project about? Well I'm allways a little bit afraid to 
speak about that, because after 30 seconds most of the people just wants 
to get away as fast as possible. But hey, you asked for it :-)


My project is a building prototyping system, my idea is that it is 
possible to investigate different spatial configurations for an 
anchitectural project, for you to have a better idea, let me show a 
simplified step list:


1. - Locate the plot that contains the architectural project. Details 
like orientation, latitude and longitude are relevant.




2. - Generate the collection of spaces that compose the project. Details 
like size and position respect to other spaces are relevant.




3. - Analyze the collection of spaces. This is an intermediate step, and 
its function is that the system knows the details of the given data.




4. - Run the system. Based on a Genetic Algorithm, the system generates 
a population of possible solutions and evaluates how well they perform 
to give at the end a number of solutions that represent possible 
projects. For the first version of the system the evaluated 
considerations are going to be kept at a minimum, with the intention of 
simplifying the development process. Those considerations are going to 
be on the one hand, proximity that is expressed in the schematic design. 
And on the other hand an external evolutionary pressure, in this case 
sun incidence. Further versions of the system are intended to cover more 
aspects of an architectural project.


If you, besides python, know something about Maya (the 3D App) that 
would just be great for me. I have spent the last semester learning 
python and mel the scripting language of maya. Thankfuly I found 
something called cgkit, that has let me use python inside of maya.


And if by chance you are familiar with genetic algorithms, well that 
would be perfect, because you can take a look at how I took a genetic 
algorithm python module and applied to my project.


But in the case that you are not familiar with maya or genetic 
algorithms, well the code is still python and I bet that a veteran like 
you can spot a bunch of things that could be done better, at the big 
scale of the code workings or a the small one of specific stuff.


MArch as far as I know is not something cryptic, it stands for Master of 
Architecture and it follows the normal master courses notation. You can 
check it here 
.


Just to clarify :-)

Cheers
Carlos

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Project Review (Was: Tutor Digest, Vol 34, Issue 42)

2006-12-21 Thread Christopher Arndt
Carlos schrieb:
> And if by chance you are familiar with genetic algorithms, well that
> would be perfect, because you can take a look at how I took a genetic
> algorithm python module and applied to my project.

I'm afraid that I don't have the domain specific knowledge to be of much help
here and I must admit, that I'm not very interested in it either, but at least,
now I know enough to make that decision ;-)

> But in the case that you are not familiar with maya or genetic
> algorithms, well the code is still python and I bet that a veteran like
> you can spot a bunch of things that could be done better, at the big
> scale of the code workings or a the small one of specific stuff.

I would suggest, you upload you code somewhere (make it password protected, if
you must) so that several people have an opportunity to look at it. I could
probably comment on the 'Pythonicity' of the code, others might be better
suited to 'understand' the code.

> MArch as far as I know is not something cryptic, it stands for Master of
> Architecture and it follows the normal master courses notation. You can
> check it here
> .

Not everybody speaks English as their mothertongue or knows about the
Anglo-saxon education system, you know ;-)


Chris
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python and rpy

2006-12-21 Thread Kent Johnson
Geoframer wrote:
> R is a statistical language and Rpy is the python interface for it. 
> However somehow I'm failing to see a step in the python code with which I
> address the R language.
> 
> in R I can do :
> 
> a=diag(10)  #produces an identity matrix of 
> size 10
> b=kmeans(a,2,5,10,"Forgy")#calculate a kmeans clustering algorithm 
> on the 10 vectors contained by the matrix just declared.
> 
> 
> in Ipython this does :
> 
> -
> In [1]: from rpy import *
> RHOME= C:\Program Files\R\R-2.4.0
> RVERSION= 2.4.0
> RVER= 2040
> RUSER= C:\Documents and Settings\Ronald
> Loading the R DLL C:\Program Files\R\R-2.4.0\bin\R.dll .. Done.
> Loading Rpy version 2040 .. Done.
> Creating the R object 'r' ..  Done
> 
> In [2]: a = r.diag(10)
> 
> In [3]: b = r.kmeans(a,2,10,5,"Forgy")
> ---
> rpy.RExceptionTraceback (most recent 
> call last)
> 
> C:\Python24\
> 
> RException: Error in as.double.default(x) : (list) object cannot be 
> coerced to '
> double'
> -

This seems to work, it keeps a in the internal R representation instead 
of converting it to a list of lists:

In [1]: from rpy import *
RHOME= C:\Program Files\R\R-2.3.1
RVERSION= 2.3.1
RVER= 2031
RUSER= G:\
Loading the R DLL C:\Program Files\R\R-2.3.1\bin\R.dll .. Done.
Loading Rpy version 2031 .. Done.
Creating the R object 'r' ..  Done

In [22]: aa=with_mode(NO_CONVERSION, r.diag)(10)

In [25]: b=r.kmeans(aa,2,10,5,"Forgy")

In [26]: b
Out[26]:
{'centers': [[0.,
   0.,
   0.,
   0.,
   0.0,
   0.,
   0.,
   0.,
   0.,
   0.],
  [0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0]],
  'cluster': [1, 1, 1, 1, 2, 1, 1, 1, 1, 1],
  'size': [9, 1],
  'withinss': [8.0018, 0.0]}

 > I've tried numerous things to get it to work, but i basically can not
 > find out how i do something as simple as the two statements in R in
 > RPython. Apparently something is going wrong somewhere in the conversion
 > of python objects to R objects but i can't seem to fix it. There is a
 > code snippet in the RPy-reference manual but it's only valid for python
 > 2.2 and 2.1 and i couldn't get it to work on 2.4.

Where is the snippet?

Cheers,
Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor