[Tutor] Const on Python

2008-03-05 Thread Tiago Katcipis
Its a simple question but i have found some trouble to find a good 
answer to it, maybe i just dont searched enough but it wont cost 
anything to ask here, and it will not cost to much to answer :-). I have 
started do develop on python and i really liked it, but im still 
learning. Im used to develop on c++ and java and i wanted to know if 
there is any way to create a final or const member, a member that after 
assigned cant be reassigned. Thanks to anyone who tries to help me and 
sorry to bother with a so silly question. i hope someday i can be able 
to help :-)

best regards

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


Re: [Tutor] Const on Python

2008-03-05 Thread Tiago Katcipis
Thanks for the help John. I agree with you that the programmer is 
already a grow person and should know when he can modify a attribute 
:-). Instead when other people will be able to continue to develop on 
the code i writed the const would give confidence that someone would not 
mess with my constants... i dont think its really necessary the const, 
but if it exists i would use...if dont existsok. Looking forward to 
go on developing on python and have more questions, hope that they will 
be better than this one :-).

Again thanks for the help

best regards

katcipis

John Fouhy escreveu:
> On 06/03/2008, Tiago Katcipis <[EMAIL PROTECTED]> wrote:
>   
>>  learning. Im used to develop on c++ and java and i wanted to know if
>>  there is any way to create a final or const member, a member that after
>>  assigned cant be reassigned. Thanks to anyone who tries to help me and
>>  sorry to bother with a so silly question. i hope someday i can be able
>>  to help :-)
>> 
>
> The short answer is: "Not really".
>
> Actually, with recent versions of python, you could do something with
> properties.  e.g.:
>
>   
>>>> class MyClass(object):
>>>> 
> ... def fget_FOO(self):
> ... return 'foo'
> ... FOO = property(fget=fget_FOO)
> ...
>   
>>>> x = MyClass()
>>>> x.FOO
>>>> 
> 'foo'
>   
>>>> x.FOO = 'bar'
>>>> 
> Traceback (most recent call last):
>   File "", line 1, in 
> AttributeError: can't set attribute
>
>
> property() takes up to three arguments: get, set, and docstring.  In
> this case, I omitted the setter.  Thus python doesn't allow me to set
> that attribute.  You could also mess around with getattr() to achieve
> a similar effect.
>
> Generally, though, python takes the attitude that programmers are
> adults capable of thinking for themselves, and if you're silly enough
> to reassign a constant, you deserve whatever you get.  Best just to
> make your variable names ALL_CAPS and write documentation saying
> they're constant :-)
>
> See also this recipe:
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65207
> for another take on the issue.
>
>   

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


Re: [Tutor] Const on Python

2008-03-06 Thread Tiago Katcipis
thanks for the help Andreas, i dont really need that much a const so i wont
do anything like that to have a const like data. I am very used to java and
c++, thats why i always used acess modifier, but i think i can live without
it now i know that it dont exist in python :P.



On Thu, Mar 6, 2008 at 6:39 AM, Andreas Kostyrka <[EMAIL PROTECTED]>
wrote:

> The answer is slightly more complex.
>
> 1.) objects are either mutable or immutable. E.g. tuples and strings are
> per definition immutable and "constant". Lists and dictionaries are an
> example of the mutable kind.
>
> 2.) "variables", "instance members" are all only references to objects.
>
> Examples:
>
> # lists are mutable
> a = [1, 2]
> b = a
> b.append(3)
> assert a == [1, 2, 3]
>
> Now coming back to your question, that you want a non-changeable name,
> well, one can create such a beast, e.g.:
>
> def constant(value):
>def _get(*_dummy):
>return value
>return property(_get)
>
> class Test(object):
>const_a = constant(123)
>
> This creates a member that can only be fetched, but not set or deleted.
>
> But in practice, I personally never have seen a need for something like
> this. You can always overcome the above constant. Btw, you can do that
> in C++ privates too, worst case by casting around and ending up with a
> pointer that points to the private element ;)
>
> Andreas
>
>
> Am Mittwoch, den 05.03.2008, 21:07 -0300 schrieb Tiago Katcipis:
> > Its a simple question but i have found some trouble to find a good
> > answer to it, maybe i just dont searched enough but it wont cost
> > anything to ask here, and it will not cost to much to answer :-). I have
> > started do develop on python and i really liked it, but im still
> > learning. Im used to develop on c++ and java and i wanted to know if
> > there is any way to create a final or const member, a member that after
> > assigned cant be reassigned. Thanks to anyone who tries to help me and
> > sorry to bother with a so silly question. i hope someday i can be able
> > to help :-)
> >
> > best regards
> >
> > katcipis
> > ___
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Const on Python

2008-03-06 Thread Tiago Katcipis
so far im starting to feel all what you have said. Im using python to
implement some works on university and im felling that everything is high
level, easy to use, and far easier than c++ and even java. java is less
complicated than c++ but cant be compared with the simplicity of python
code. And the code gets pleasant to read...thanks to indentation and no
braces...i just lerned to hate the damn braces :P. Saddly the lab where i
work only develops on c++ for now... but everything that i can choose i will
develop with python, im still green on developing but so far it is the more
pleasant language to program...is actually fun to develop on python..all the
timein c++...sometimes is funthe most part of the time is debugging
suffering =/, and mistic compile errors that sometimes gets a lot of time to
understand what REALLY is the problem. Its amazing how the compiler can
trick you in c++, almost all the times it only points in the wrong
direction..the only thing that can help you is experience or someone with
experience at your side :P. Python runtime errors always helped me to debug
fast and easy, really a joy :D.

thanks everyone for helping me

On Thu, Mar 6, 2008 at 11:18 AM, Andreas Kostyrka <[EMAIL PROTECTED]>
wrote:

>
> Am Donnerstag, den 06.03.2008, 08:35 -0500 schrieb Kent Johnson:
> > C++ is extremely complex. The good side of this is it gives you
> > tremendous control - final, const, pass by reference or value, memory
> > allocation, etc, etc. The bad side is that it is a lot to think about -
> > should this parameter be const? who is going to deallocate this object?
> > and there is a lot of room for error, whole books have been written on
> > the topic (e.g. Effective C++ which even has a sequel).
>
> Concur. What is worse, it's to complicated for the average "commercial"
> developer. And the claim that you can program C++ effectively without
> knowing the whole language does not work in practice. (Hint: Yes, you
> can program without understanding the whole language. And no, you have
> no chance of debugging your program if you don't understand what that
> complicated library is doing. So in practice you end with senior
> developers doing the debugging, while the newbies try to understand what
> you are doing.)
>
> As a saving grace to C++ I must note that there are a number of
> "features" in Python that can produce something comparativly
> newbie-unfriendly as C++. But you will notice that most Python
> developers shrink away from using these features, so in effect this is
> not a burning issue. Somehow these "advanced" topics don't deter newbies
> from writing and debugging Python programs. (E.g. you can program for
> years Python without learning the fact that it's not the class that does
> the self bounding, instead it's function.__get__ that does it ;) )
>
> >
> > Java is less complex and flexible than C++. At first I missed the
> > control of C++, then I realized that it wasn't really buying me much and
> > that the cost was too high - coding Java is much less work than coding
> C++.
>
> Java has automatic memory management, is safe (meaning that typically
> the worst thing that happens is traceback), and has an object model that
> nearer to a dynamic language like Python or Smalltalk than to C++.
> Basically, while it looks much like C++ on a first glance, the
> underpinnings come from more dynamic/runtime oriented languages.
>
> And because it does all these irrelevant details for the developer
> automatically, the IT industry can get enough souls to program it. ;)
>
> >
> > Then Python. Python takes away even more low-level control. And I don't
> > miss it at all. My Python programs work just fine without static typing,
> > constants, etc.
>
> Worse, something that one likes to forget. Practically in any software
> system the amount of code that is heavily exercised, the "inner loop" is
> tiny. Meaning that after having written your Python code (usually in a
> fraction of the time planned for the C++ implementation), you can
> improve the algorithms and speed up these critical sections. (By redoing
> them in Python, Pyrex, C/C++.)
>
> That's the underlying truth to "Python faster than C++" message. Not
> because Python is faster than C++ (in execution speed). Of the primitive
> operations around 98-98% are slower in Python than in C/C++. But it
> allows you to implement your application faster than in C++. The initial
> implementation will be slower than a C++ implementation. But it might be
> already "fast enough". But the point is, that in most cases, your
> friendly C++ coder in the next room is still implementing his initial
> implementation while the Python coder is already benchmarking/tuning his
> app. Or spends time thinking about the algorithms.
>
> So the following stands, usually, and you can usually even replace the
> languages with Perl, Ruby, PHP, Smalltalk, Lisp, Java, ...:
>
> C++ is faster than Python (if the resources in money and time are
> unlimited: that'

Re: [Tutor] Begining Python

2008-03-11 Thread Tiago Katcipis
tutorial i liked this one when i was starting
http://docs.python.org/tut/

free IDE that i use is Eclipse with PyDev plugin.
http://pydev.sourceforge.net/
www.eclipse.org


On Tue, Mar 11, 2008 at 4:41 PM, Meftah Tayeb <[EMAIL PROTECTED]>
wrote:

>  hi my friends,
> please i want to begin developing with python.
> 1. do you know a tutorial for this ?
> 2. do you know a Free IDE for Python (for windows) ?
>
> Thanks
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Question about global variables on modules

2008-04-04 Thread Tiago Katcipis
I know its not such a pretty thing to have global variables but its only
for an exercise my teacher told to do. Its a function to calculate the
results of a matrix using jacob. I want to inside the module (inside a
function on the module )assign a value to a global variable, but the
only way i found to do this inside the own module function is importing
the module inside himself. Is there another way of doing this? its kind
odd to import the module to himself, i think  :-) 

here goes the code

<>

import lineares_jacob

*ERRO_FINAL = 0.0*

def obter_respostas(matriz, incognitas, erro_max):
  erro = erro_max * 10
  n = len(matriz)
 
  while(erro >= erro_max):
novas_incognitas = []
y_um = (2.0 + (1.0 * incognitas[1]) - (1.0 * incognitas[4999])) / 3.0
novas_incognitas.append(y_um)
   
for i in range(1 , (n - 1)):
  yi = ( (2.0 * i) + incognitas[i - 1] + incognitas[i + 1] ) / (2.0 + i)
  novas_incognitas.append(yi)
 
y_cinc_mil = (1.0 - incognitas[0] + incognitas[4998]) / 5002.0
novas_incognitas.append(y_cinc_mil)
   
maior = novas_incognitas[0] - incognitas[0]
   
for i in range(1, 5000):
  dif = novas_incognitas[i] - incognitas[i]
  if(dif > maior):
maior = dif
   
erro = maior
incognitas = novas_incognitas
 
  *lineares_jacob.ERRO_FINAL = erro*
  return incognitas

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


[Tutor] Question about global variables on modules

2008-04-06 Thread Tiago Katcipis
I know its not such a pretty thing to have global variables but its only
for an exercise my teacher told to do. Its a function to calculate the
results of a matrix using jacob. I want to inside the module (inside a
function on the module )assign a value to a global variable, but the
only way i found to do this inside the own module function is importing
the module inside himself. Is there another way of doing this? its kind
odd to import the module to himself, i think :-)

here goes the code

<>

import lineares_jacob

*ERRO_FINAL = 0.0*

def obter_respostas(matriz, incognitas, erro_max):
  erro = erro_max * 10
  n = len(matriz)
 
  while(erro >= erro_max):
novas_incognitas = []
y_um = (2.0 + (1.0 * incognitas[1]) - (1.0 * incognitas[4999])) / 3.0
novas_incognitas.append(y_um)
   
for i in range(1 , (n - 1)):
  yi = ( (2.0 * i) + incognitas[i - 1] + incognitas[i + 1] ) / (2.0 + i)
  novas_incognitas.append(yi)
 
y_cinc_mil = (1.0 - incognitas[0] + incognitas[4998]) / 5002.0
novas_incognitas.append(y_cinc_mil)
   
maior = novas_incognitas[0] - incognitas[0]
   
for i in range(1, 5000):
  dif = novas_incognitas[i] - incognitas[i]
  if(dif > maior):
maior = dif
   
erro = maior
incognitas = novas_incognitas
 
  *lineares_jacob.ERRO_FINAL = erro*
  return incognitas
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Little problem with math module

2008-04-20 Thread Tiago Katcipis
im not understanding why is this a problem...i have this simple function

def newton_divergente(x): 
  return math.pow(x, 1.0/3.0)

but when x = -20 it returns this error

return math.pow(x, 1.0/3.0)
ValueError: math domain error

but why is that? is it impossible to calculate -20 ^ (1/3) ?

here on my calculator i get the result -6,7, but python seens to
dont now the answer, why? am i doing something wrong? =/

thanks to everyone who tries do help

best regards

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


Re: [Tutor] Little problem with math module

2008-04-20 Thread Tiago Katcipis
ops, now i realize the mistake i was making. Thanks for the help people

Tiago Katcipis escreveu:
> im not understanding why is this a problem...i have this simple function
>
> def newton_divergente(x): 
>   return math.pow(x, 1.0/3.0)
>
> but when x = -20 it returns this error
>
> return math.pow(x, 1.0/3.0)
> ValueError: math domain error
>
> but why is that? is it impossible to calculate -20 ^ (1/3) ?
>
> here on my calculator i get the result -6,7, but python seens to
> dont now the answer, why? am i doing something wrong? =/
>
> thanks to everyone who tries do help
>
> best regards
>
> katcipis
>
>   

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


Re: [Tutor] Little problem with math module

2008-04-20 Thread Tiago Katcipis
well i made a mistake again :P. i have the function x ^ 1/3, i first
remembered that negative numbers do not have a square, but in this case
negative numbers are ok...because it aint 1/2 ...its 1/3. Can anyone
give a hint of how i can calculate it without using pow ou **? none of
them work properly


Tiago Katcipis escreveu:
> im not understanding why is this a problem...i have this simple function
>
> def newton_divergente(x): 
>   return math.pow(x, 1.0/3.0)
>
> but when x = -20 it returns this error
>
> return math.pow(x, 1.0/3.0)
> ValueError: math domain error
>
> but why is that? is it impossible to calculate -20 ^ (1/3) ?
>
> here on my calculator i get the result -6,7, but python seens to
> dont now the answer, why? am i doing something wrong? =/
>
> thanks to everyone who tries do help
>
> best regards
>
> katcipis
>
>   

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


Re: [Tutor] Little problem with math module

2008-04-21 Thread Tiago Katcipis
i will change the subject but this one is interessenting.

i have this test code

import funcoes
import bissecao
import falsa_posicao
import falsa_posicaom
import newton_simples
import math

INTERVALO = [0,1]
ERRO_DET = math.pow(10, -16)
ITER = funcoes.calcular_num_iteracoes(INTERVALO[0], INTERVALO[1], ERRO_DET)

print 'Por bissecao: '
print 'Numero de iteracoes necessarios = ', ITER
resultado, erro = bissecao.obter_alpha(INTERVALO,
funcoes.convergente_simples, ERRO_DET, ITER)
print 'Alpha = ', resultado
print 'Erro = ', erro
print ''


and i have this function on bissecao

import math
import funcoes

def obter_alpha(intervalo, funcao, erro_passado = 0.0, limite = 20):

  a = intervalo[0]
  b = intervalo[1]
  fa = funcao(a)
  fb = funcao(b)
  erro = erro_passado * 10.0
  contador = 0
  xm = 0.0
 
  if( (fa * fb) < 0 ):
   
while(contador < limite):
  contador += 1
  xm = (a + b) / 2.0
  fm = funcao(xm)
 
  if(fm == 0):
return xm, 0.0
 
  if( (fm * fa) < 0.0):
b = xm
  else:
a = xm
   
  erro = funcoes.calcular_erro(a, b)
 
  if(erro < erro_passado):
return xm, erro
 
  print 'Iteracao ', contador, ' alpha = ', xm
  print 'Erro ', contador, ' = ', erro
 
   
return xm, erro
 
  else:
print 'Funcao nao eh continua'
 
 

my problem is, INSIDE the funcion...the variable erro is correct, but
when i return it to the test...and the test prints itcomes out 0.0.
Its disturbing...i didnt found a way of solving this.

the out of the test is like this

Erro  50  =  1.50914019446e-15
Iteracao  51  alpha =  0.588532743982
Erro  51  =  7.54570097231e-16
Alpha =  0.588532743982
Erro =  0.0

it would print more things but it is desnecessary, inside the function
erro has a value like 7.54570097231e-16, but when it is returned it goes
out like 0.0. What can i do to prevent this from happening?

the whole thing is at
https://svn.inf.ufsc.br/katcipis/python/trunk/Funcoes/src/

just log as user "guest" without a password

ALAN GAULD escreveu:
> On Mon, Apr 21, 2008 at 12:07 AM, Alan Gauld
> <[EMAIL PROTECTED] > wrote:
>
>
> >>> pow(-20, 0.333)
> Traceback (most recent call last):
>  File "", line 1, in 
> ValueError: negative number cannot be raised to a fractional power
> >>> -20**0.333
> -2.7144173455393048
> >>>
>
> I think you're confusing the order of operations.
>
> math.pow(-20, (1.0/3.0)) and -20**(1.0/3.0) are not equivalent
>
> Whereas, as john mentioned, -20**(1.0/3.0) is actually
> -(20**(1.0/3.0)), math.pow(-20, (1.0/3.0)) is (-20)**(1.0/3.0)
>
> Yes, quite correct, I posted my reply before the others had
> posted theirs although it showed up afterwards(at least on gmane)
>  
> > exponentiation has higher precedence over positive, negative.
>  
> Yep, I hadn't realized that, although it does make sense when you
> think about it :-)
>
> /> Note that math.pow is unrelated to the builtin power operator /
> /> and the result of math.pow(0.0, -2.0) will vary by platform. /
>  
> /This is interesting, I had assumed that pow simply called **./
> Does anyone know why they made it different?
>  
> Alan G.
> 
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>   

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


[Tutor] Best way to define comparison

2008-05-17 Thread Tiago Katcipis
Im writing a class on python and i want to implement the == and != operators
on it. I have read about __cmp__ and about __eq__ for == and __ne__ for ! =.
My question is... who is the better to use? and if there is no better what
are the advantages and disvantages of them. Some articles talk about using
cmp, and others about the eq...its a little confusing :-(
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Best way to define comparison

2008-05-17 Thread Tiago Katcipis
ops im sorry..i didnt noticed that reply just replyed to you..i thought it
would go to the list.

Thanks for the help

best regards

On Sat, May 17, 2008 at 8:36 PM, Kent Johnson <[EMAIL PROTECTED]> wrote:

> On Sat, May 17, 2008 at 7:04 PM, Tiago Katcipis <[EMAIL PROTECTED]>
> wrote:
> > ive been reading and really seens to be better to use cmp... i will not
> have
> > to write a method to every single operator. But when python compare
> > objects...like in Sets or Lists...to check for membership etc, it uses
> cmp
> > ou eq?
>
> It uses __eq__() if it is defined, otherwise __cmp__()
> http://docs.python.org/ref/customization.html
>
> Kent
>
> PS Please use Reply All to reply to the list
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Equivalent of grep in python

2008-12-21 Thread Tiago Katcipis
i believe that the following should work

file1 = open(fileO, 'r')
re.findall ('some_text', file1.read())

readlines returns a list with lists inside, where every list is a line of
the text. The read function returns the entire file as one string, so it
should work to what you are wanting to do.

best regards

Katcipis

On Sun, Dec 21, 2008 at 12:02 AM, ppaarrkk  wrote:

>
> The following works :
>
> file1 = open (file0, "r")
>
> re.findall ( 'some_text', file1.readline() )
>
>
> But this doesn't :
>
> re.findall ( 'some_text', file1.readlines() )
>
>
>
> How do I use grep for a whole text file, not just a single string ?
> --
> View this message in context:
> http://www.nabble.com/Equivalent-of-grep-in-python-tp2356p2356.html
> Sent from the Python - tutor mailing list archive at Nabble.com.
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
"it might be a profitable thing to learn Java, but it has no intellectual
value whatsoever" Alexander Stepanov
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Equivalent of grep in python

2008-12-21 Thread Tiago Katcipis
i forgot, this might help you

http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-files

On Sun, Dec 21, 2008 at 11:57 AM, Tiago Katcipis wrote:

> i believe that the following should work
>
> file1 = open(fileO, 'r')
> re.findall ('some_text', file1.read())
>
> readlines returns a list with lists inside, where every list is a line of
> the text. The read function returns the entire file as one string, so it
> should work to what you are wanting to do.
>
> best regards
>
> Katcipis
>
>
> On Sun, Dec 21, 2008 at 12:02 AM, ppaarrkk  wrote:
>
>>
>> The following works :
>>
>> file1 = open (file0, "r")
>>
>> re.findall ( 'some_text', file1.readline() )
>>
>>
>> But this doesn't :
>>
>> re.findall ( 'some_text', file1.readlines() )
>>
>>
>>
>> How do I use grep for a whole text file, not just a single string ?
>> --
>> View this message in context:
>> http://www.nabble.com/Equivalent-of-grep-in-python-tp2356p2356.html
>> Sent from the Python - tutor mailing list archive at Nabble.com.
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>
>
>
> --
> "it might be a profitable thing to learn Java, but it has no intellectual
> value whatsoever" Alexander Stepanov
>



-- 
"it might be a profitable thing to learn Java, but it has no intellectual
value whatsoever" Alexander Stepanov
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Equivalent of grep in python

2008-12-21 Thread Tiago Katcipis
Sorry its true, i made a mistake. Readlines is a list with all the lines
inside. I never used readlines (i usually use read), i just read about it on
the tutorial long time ago.

>>> f.readlines()
['This is the first line of the file.\n', 'Second line of the file\n'


Thanks for the help.


On Sun, Dec 21, 2008 at 4:44 PM, Luke Paireepinart
wrote:

> I believe readlines returns a list of strings, not a list of lists.
> You can iterate over the characters in a string if you want, though.
>
> On 12/21/08, Tiago Katcipis  wrote:
> > i forgot, this might help you
> >
> >
> http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-files
> >
> >
> >  On Sun, Dec 21, 2008 at 11:57 AM, Tiago Katcipis 
> > wrote:
> > > i believe that the following should work
> > >
> > > file1 = open(fileO, 'r')
> > > re.findall ('some_text', file1.read())
> > >
> > > readlines returns a list with lists inside, where every list is a line
> of
> > the text. The read function returns the entire file as one string, so it
> > should work to what you are wanting to do.
> > >
> > > best regards
> > >
> > > Katcipis
> > >
> > >
> > >
> > >
> > >
> > > On Sun, Dec 21, 2008 at 12:02 AM, ppaarrkk 
> wrote:
> > >
> > > >
> > > > The following works :
> > > >
> > > > file1 = open (file0, "r")
> > > >
> > > > re.findall ( 'some_text', file1.readline() )
> > > >
> > > >
> > > > But this doesn't :
> > > >
> > > > re.findall ( 'some_text', file1.readlines() )
> > > >
> > > >
> > > >
> > > > How do I use grep for a whole text file, not just a single string ?
> > > > --
> > > > View this message in context:
> >
> http://www.nabble.com/Equivalent-of-grep-in-python-tp2356p2356.html
> > > > Sent from the Python - tutor mailing list archive at Nabble.com.
> > > >
> > > > ___
> > > > Tutor maillist  -  Tutor@python.org
> > > > http://mail.python.org/mailman/listinfo/tutor
> > > >
> > >
> > >
> > >
> > > --
> > > "it might be a profitable thing to learn Java, but it has no
> intellectual
> > value whatsoever" Alexander Stepanov
> > >
> >
> >
> >
> > --
> > "it might be a profitable thing to learn Java, but it has no intellectual
> > value whatsoever" Alexander Stepanov
> >
> > ___
> >  Tutor maillist  -  Tutor@python.org
> >  http://mail.python.org/mailman/listinfo/tutor
> >
> >
>



-- 
"it might be a profitable thing to learn Java, but it has no intellectual
value whatsoever" Alexander Stepanov
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Handling post request

2009-01-28 Thread Tiago Katcipis
thanks for the help, im really not used on doing web stuff, ill try reading
the how to.

On Wed, Jan 28, 2009 at 9:03 AM, Alan Gauld wrote:

> "Tiago Katcipis"  wrote
>
>  I am trying to make a small HTTP server on python just to handle some POST
>> and GET requests. I never worked with http before and dont know if i am
>> doing something completely stupid (probably yes).
>>
>
> Not stupid so much as overly complicated.
>
> The cgi module will do all the hard work for you including transparently
> handling POST and GET requests
>
> Read the web HOWTO document:
>
> http://docs.python.org/howto/webservers.html
>
> Then read the CGI module documentation which includes a very quick
> introduction to CGI programming. If you are intending expanding the web
> site to anything beyond trivial consider using a Framework such as
> Django, Turbo Gears or Pylons.
>
> Unless you are trying to do something very clever - which given your
> level of knowledge I'd guess is not the case - then the standard
> cgi module should do all you need!
>
> HTH,
>
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
"it might be a profitable thing to learn Java, but it has no intellectual
value whatsoever" Alexander Stepanov
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Handling post request

2009-01-28 Thread Tiago Katcipis
actualy i have found what i wanted on the rfile attribute, i already tried
before to read it but the application just freezes when i try to read() or
readline() on it. But after i make the request, and both client and server
sides freezes, if i kill the client side the server becomes able of reading
the rfile.

Does anyone know why i just cant read the rfile without killing the client
side? it feels like the client side is waiting for something while the
server is unable to read the rfile while the client side is waiting.

On Wed, Jan 28, 2009 at 9:09 AM, Tiago Katcipis wrote:

> thanks for the help, im really not used on doing web stuff, ill try reading
> the how to.
>
>
> On Wed, Jan 28, 2009 at 9:03 AM, Alan Gauld wrote:
>
>> "Tiago Katcipis"  wrote
>>
>>  I am trying to make a small HTTP server on python just to handle some
>>> POST
>>> and GET requests. I never worked with http before and dont know if i am
>>> doing something completely stupid (probably yes).
>>>
>>
>> Not stupid so much as overly complicated.
>>
>> The cgi module will do all the hard work for you including transparently
>> handling POST and GET requests
>>
>> Read the web HOWTO document:
>>
>> http://docs.python.org/howto/webservers.html
>>
>> Then read the CGI module documentation which includes a very quick
>> introduction to CGI programming. If you are intending expanding the web
>> site to anything beyond trivial consider using a Framework such as
>> Django, Turbo Gears or Pylons.
>>
>> Unless you are trying to do something very clever - which given your
>> level of knowledge I'd guess is not the case - then the standard
>> cgi module should do all you need!
>>
>> HTH,
>>
>>
>> --
>> Alan Gauld
>> Author of the Learn to Program web site
>> http://www.alan-g.me.uk/
>>
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>
>
>
> --
> "it might be a profitable thing to learn Java, but it has no intellectual
> value whatsoever" Alexander Stepanov
>



-- 
"it might be a profitable thing to learn Java, but it has no intellectual
value whatsoever" Alexander Stepanov
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Handling post request

2009-01-28 Thread Tiago Katcipis
I am trying to make a small HTTP server on python just to handle some POST
and GET requests. I never worked with http before and dont know if i am
doing something completely stupid (probably yes). I read anything possible
already and i just cant find how i access the information sent on the POST
request, i need these because some parameters needed by the server must be
sent on the POST request, my client test does this:


f = urllib2.urlopen(url,  urllib.urlencode('http://my_server_adress:port',
{'Teste' : 'teste', 'Teste2' : 't2', 'Teste3' : 't3'}))
f.close()

The server runs ok and receives the POST request just fine, but im not
finding where the data that i have sent on the post request is being held.
Sorry if the question is extremely stupid, i really tried a lot of things
already and read a lot, maybe i just have let something pass when i was
reading or i am understanding something terribly wrong :-(.

O already have take a look at:
http://docs.python.org/library/simplehttpserver.html#module-SimpleHTTPServer
http://docs.python.org/library/basehttpserver.html#BaseHTTPServer.BaseHTTPRequestHandler.handle_one_request
http://effbot.org/librarybook/simplehttpserver.htm
http://personalpages.tds.net/~kent37/kk/00010.html


my server code is:
def adcionar_tratador_server(endereco_servidor, tratador):
   BaseHTTPServer.HTTPServer(endereco_servidor, tratador).serve_forever()


class
TratadorRequisicaoHTTPIDLocutor(BaseHTTPServer.BaseHTTPRequestHandler):

  def do_HEAD(self):
print self.command
print self.path
print self.headers
print self.headers.getplist()
print self.raw_requestline
print urlparse.urlparse(self.path)
return 'ok'


  def do_GET(self):
print self.command
print self.path
print self.headers
print self.headers.getplist()
print self.raw_requestline
print urlparse.urlparse(self.path)
return 'ok'


  def do_POST(self):
print self.command
print self.path
print self.headers
print self.headers.getplist()
print self.raw_requestline
print urlparse.urlparse(self.path)
return 'ok'

adcionar_tratador_server(('', 8000) , TratadorRequisicaoHTTPIDLocutor)





-- 
"it might be a profitable thing to learn Java, but it has no intellectual
value whatsoever" Alexander Stepanov
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Handling post request

2009-01-28 Thread Tiago Katcipis
thank you all for the help but i have finnaly been able to do what i wanted.
I will not use CGI scripts, its very simple what im doing and i just wanted
the parameters sent on the POST like:
*
"name1=value1&name2=value2&name3=value3"*

but reading about CGI i discovered that the size of these parameters are in
content-lenght, when reading the rfile with the content-length as the number
of bytes to read it has worked fine.

best regards

On Wed, Jan 28, 2009 at 9:20 AM, Justin Ezequiel <
justin.mailingli...@gmail.com> wrote:

> > From: Tiago Katcipis 
> >
> > I am trying to make a small HTTP server on python just to handle some
> POST
> > and GET requests. I never worked with http before and dont know if i am
> > doing something completely stupid (probably yes). I read anything
> possible
> > already and i just cant find how i access the information sent on the
> POST
> > request, i need these because some parameters needed by the server must
> be
> > sent on the POST request, my client test does this:
> >
> >
> > f = urllib2.urlopen(url,  urllib.urlencode('http://my_server_adress:port
> ',
> > {'Teste' : 'teste', 'Teste2' : 't2', 'Teste3' : 't3'}))
> > f.close()
> >
> > The server runs ok and receives the POST request just fine, but im not
> > finding where the data that i have sent on the post request is being
> held.
> > Sorry if the question is extremely stupid, i really tried a lot of things
> > already and read a lot, maybe i just have let something pass when i was
> > reading or i am understanding something terribly wrong :-(.
>
> Hello, I needed to do the same recently to test my scripts that do GET
> and POST to a web site.
> Found how to get at the posted data within CGIHTTPServer.py
> particularly the run_cgi method of the CGIHTTPRequestHandler class.
>
> At first I just ran an instance of the CGIHTTPServer and had a few CGI
> scripts until I read the code for the run_cgi method above.
> Now my test script runs an HTTP server in a daemon thread using my
> subclass of the CGIHTTPRequestHandler then the main thread then runs
> my GET and POST code.
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
"it might be a profitable thing to learn Java, but it has no intellectual
value whatsoever" Alexander Stepanov
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor