[Tutor] Are there any MAC OSX python users here?

2007-01-20 Thread Tony Cappellini

I'm trying to help some people run a python cmd line program on OSX.

Would you email me off list if you have OSX and run python apps form the cmd
line?

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


[Tutor] python certification

2007-01-20 Thread Ketan Maheshwari
Hi All:
I am looking forward to obtain some kind of certification for 
Python. Is there anything like that exist?
Could someone give me pointers for details.

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


Re: [Tutor] Are there any MAC OSX python users here?

2007-01-20 Thread Alan Gauld

"Tony Cappellini" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> I'm trying to help some people run a python cmd line program on OSX.
>
> Would you email me off list if you have OSX and run python apps form 
> the cmd
> line?

I do.

They need to start Applications-Utilities->Terminal

And that gets them a Unix terminal.
After that its standard Unix... What kind of problems are you having?

Alan G 


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


Re: [Tutor] Set changing order of items?

2007-01-20 Thread Adam Cripps
On 1/20/07, Kent Johnson <[EMAIL PROTECTED]> wrote:
> Adam Cripps wrote:
> > On 1/19/07, Simon Brunning <[EMAIL PROTECTED]> wrote:
> >> On 1/19/07, Adam Cripps <[EMAIL PROTECTED]> wrote:
> >>> I'm adding strings to a Set to prevent duplicates. However, the
> >>> strings are meant to be in the correct order. When I add the string to
> >>> the Set, the order seems to change (and I don't seem to be able to
> >>> predict what order they are in).
> >> Sets, like dictionaries, hold their items in an arbitrary order - see
> >> .
> >
> > OK - thanks for that - so it seems that using a Set will complicate
> > the matter more.
> >
> > Really, I want to have a set of sets which won't have any duplicates.
> > An example might look something ilke this:
> >
> > sums = [['1) 10 + 2 =', '12'], ['2) 13 + 4 =', '17']]
> > return sums
> >
> > How might I achieve this list, without the duplicates (the duplicate
> > bit is the bit I'm stuck on).
>
> What is your criterion for uniqueness? Are you looking at just the sum,
> as you mentioned earlier, or the whole problem? Why is the order
> important, since the problems are randomly generated?
>
> You should think about a more abstract way of representing a problem.
> For example, the two problems above could be represented as the tuples
> (10, 2, 12) and (13, 4, 17). If you want the whole problems to be
> unique, then creating a set of tuples like this should do what you want.
> (I used tuples instead of lists because you can't make a set of lists.)
>
> If you want only one problem with a given sum, then I would represent a
> problem as an entry in a dictionary where the sum is the key and the
> value is a tuple containing the two addends. Then you can keep putting
> problems in the dictionary until it is the size you want.
>
> Once you have the final set (or dict) of problems, then you can convert
> them to a string representation and print them.

Many thanks all - I've got there in the end, using a tuple inside a
set, ditching the question number and then rendering the sum for
output in my main gui module.

However, this does raise another issue now (which I had thought would
happen, but was putting it off until I'd solved the original problem).

Basically, the user can choose how many problems are set - i. They can
also choose the highest and lowest possible numbers - highest and
lowest. With these values, they can now create a scenario which will
lock the application - they can choose values with a narrow margin
(lowest = 5, highest = 6) and then choose to have 100 of these
problems (i=100). Of course, this will mean that my app will now go
through that loop trying to find a new combination that no longer is
possible.

Anyone have any guidance or tips here? How will I create a flag which
is raised once the loop becomes infinite?

TIA
Adam
-- 
http://www.monkeez.org
PGP key: 0x7111B833
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] 'elp!!!!!!!1Totally Clueless Newbie In Distress

2007-01-20 Thread Karl Wittgenstein

First of all let me thank you and Geoframer for your patience;it was very
kind that you bothered answering this,as I realize this is very basic
stuff.You people are Smart and Caring Dudes,which is a powerful combo for
educators!!

"Out of curiosity, what materials are you using to learn how to program?"

Well, mostly Google! I have just finished that RUR-PLE tutorial by Andre
Roberge, read some of the Python documentation-not as focused as I should,I
admit;many programming concepts are simply  totally alien to me,so I also
use Wikipedia a lot.They have a Python tutorial.Sometimes I do some math
research, as I only know very basic math,predicate logic and
statistics.Ialso tried a pygame tutorial,but can't import the damn
module without at
least one error and can't get the damn chimp.bmp file loaded!!!I used
os.path.join("folder","file") to no success...
Thank you again,and once more in advance - if you would be so kind as to
point me learning material...My spare time is very short,between graduation
and work,so I would appreciate very didatic material...Thank you guys again!


2007/1/19, Danny Yoo <[EMAIL PROTECTED]>:



> I've been dabbling into Python for about 6 weeks now.I'm a Social
> Sciences student who just got interested in programming and chose Python
> as first language.

Out of curiosity, what materials are you using to learn how to program?



> Isn't it legal to start a new block of code when starting a
> definition?And how come it returns 'variable' not defined,when they are
> defined by the = ??Should i make them global?

Wait, wait.  I think you may be misunderstanding the use of 'global'.
You should not be using global unless you really need it.



I see three variables here that you are interested in:

altura_aeronave
largura_aeronave
comprimento

Are these always collected together?  If they are related, you should have
a single structure that holds them together, rather than represent them as
three separate variables.


Concretely, you can represent these three values as a single tuple.  You
can think of it as a "vector" from your mathematics class.  For example:

#
def make_measure(start, stop):
"""make_measure: number number -> measure
Creates a new measure from start and stop."""
return (start, stop)

def measure_start(a_measure):
"""measure_start: measure -> number
Selects the start portion of a measure."""
return a_measure[0]

def measure_stop(a_measure):
"""measure_end: measure -> end
Selects the stop portion of a measure."""
return a_measure[1]
#


That is, these functions take inputs and produce outputs.  That should be
a concept that you are familiar with from your previous experience:

f(x) = 2x (math notation)

is a function that takes a number and produces the double of that number.
We write this in Python as:


def double(x):
"""double: number -> number
Returns the double of x."""
return x * 2



Getting back to the measure example: once we have these functions to build
measures and take them apart, we can then use these like this:


## Small test program
m1 = make_measure(3, 4)
m2 = make_measure(17, 42)
print "m1", measure_start(m1), measure_stop(m1)
print "m2", measure_start(m2), measure_stop(m2)


If we dislike the duplication of those last two statements here, we can
create a function that doesn't produce an output, but it still takes
input:



def print_measure(header_name, a_measure):
"""print_measure: measure string -> None
Prints out the measurement.
"""
print header_name, measure_start(a_measure), measure_stop(a_measure)



After we define this helper function "print_measure()", our little program
can now look like this:

#
## Small test program
m1 = make_measure(3, 4)
m2 = make_measure(17, 42)
print_measure("m1", m1)
print_measure("m2", m2)
#

Notice that, here, we do not need to say anything about "globals" to make
effective programs.  We are simply passing values back and forth as
parameters.


Does this make sense so far?  If you have any questions, please feel free
to ask.  Please continue to reply to Tutor by using your email client's
Reply to All feature.

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


Re: [Tutor] Set changing order of items?

2007-01-20 Thread Kent Johnson
Adam Cripps wrote:
> Many thanks all - I've got there in the end, using a tuple inside a
> set, ditching the question number and then rendering the sum for
> output in my main gui module.
> 
> However, this does raise another issue now (which I had thought would
> happen, but was putting it off until I'd solved the original problem).
> 
> Basically, the user can choose how many problems are set - i. They can
> also choose the highest and lowest possible numbers - highest and
> lowest. With these values, they can now create a scenario which will
> lock the application - they can choose values with a narrow margin
> (lowest = 5, highest = 6) and then choose to have 100 of these
> problems (i=100). Of course, this will mean that my app will now go
> through that loop trying to find a new combination that no longer is
> possible.

This is a pretty easy condition to test for - maybe check that the 
number of possible problems in the given range is at least double (or 
some multiple) of the number of problems desired. If not, print an error 
message and have them enter new values.
> 
> Anyone have any guidance or tips here? How will I create a flag which
> is raised once the loop becomes infinite?

You could also restrict the loop to, say, twice the number of problems 
desired and give up if after that many loops you don't have the desired 
number.

Kent

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


Re: [Tutor] 'elp!!!!!!!1Totally Clueless Newbie In Distress

2007-01-20 Thread Karl Wittgenstein

I would also like to ask what skills you think I should develop so I can
approach programming more
' natively', and would like to clarify the following issue:
input("Something") usually displays Something when prompting for input;why
is that the case when I run a single line of code and isn't when I use
many?When I run three lines straight in this format,only the first message
and prompt are displayed...That is surely out of the scope of my current
knowledgeWhich is not very encompassing,anyway.


2007/1/20, Karl Wittgenstein <[EMAIL PROTECTED]>:


First of all let me thank you and Geoframer for your patience;it was very
kind that you bothered answering this,as I realize this is very basic
stuff.You people are Smart and Caring Dudes,which is a powerful combo for
educators!!

"Out of curiosity, what materials are you using to learn how to program?"

Well, mostly Google! I have just finished that RUR-PLE tutorial by Andre
Roberge, read some of the Python documentation-not as focused as I should,I
admit;many programming concepts are simply  totally alien to me,so I also
use Wikipedia a lot.They have a Python tutorial.Sometimes I do some math
research, as I only know very basic math,predicate logic and statistics.Ialso 
tried a pygame tutorial,but can't import the damn module without at
least one error and can't get the damn chimp.bmp file loaded!!!I used
os.path.join("folder","file") to no success...
Thank you again,and once more in advance - if you would be so kind as to
point me learning material...My spare time is very short,between
graduation and work,so I would appreciate very didatic material...Thank
you guys again!


2007/1/19, Danny Yoo <[EMAIL PROTECTED]>:
>
>
> > I've been dabbling into Python for about 6 weeks now.I'm a Social
> > Sciences student who just got interested in programming and chose
> Python
> > as first language.
>
> Out of curiosity, what materials are you using to learn how to program?
>
>
>
> > Isn't it legal to start a new block of code when starting a
> > definition?And how come it returns 'variable' not defined,when they
> are
> > defined by the = ??Should i make them global?
>
> Wait, wait.  I think you may be misunderstanding the use of 'global'.
> You should not be using global unless you really need it.
>
>
>
> I see three variables here that you are interested in:
>
> altura_aeronave
> largura_aeronave
> comprimento
>
> Are these always collected together?  If they are related, you should
> have
> a single structure that holds them together, rather than represent them
> as
> three separate variables.
>
>
> Concretely, you can represent these three values as a single tuple.  You
> can think of it as a "vector" from your mathematics class.  For example:
>
> #
> def make_measure(start, stop):
> """make_measure: number number -> measure
> Creates a new measure from start and stop."""
> return (start, stop)
>
> def measure_start(a_measure):
> """measure_start: measure -> number
> Selects the start portion of a measure."""
> return a_measure[0]
>
> def measure_stop(a_measure):
> """measure_end: measure -> end
> Selects the stop portion of a measure."""
> return a_measure[1]
> #
>
>
> That is, these functions take inputs and produce outputs.  That should
> be
> a concept that you are familiar with from your previous experience:
>
> f(x) = 2x (math notation)
>
> is a function that takes a number and produces the double of that
> number.
> We write this in Python as:
>
> 
> def double(x):
> """double: number -> number
> Returns the double of x."""
> return x * 2
> 
>
>
> Getting back to the measure example: once we have these functions to
> build
> measures and take them apart, we can then use these like this:
>
> 
> ## Small test program
> m1 = make_measure(3, 4)
> m2 = make_measure(17, 42)
> print "m1", measure_start(m1), measure_stop(m1)
> print "m2", measure_start(m2), measure_stop(m2)
> 
>
> If we dislike the duplication of those last two statements here, we can
> create a function that doesn't produce an output, but it still takes
> input:
>
>
> 
> def print_measure(header_name, a_measure):
> """print_measure: measure string -> None
> Prints out the measurement.
> """
> print header_name, measure_start(a_measure), measure_stop(a_measure)
> 
>
>
> After we define this helper function "print_measure()", our little
> program
> can now look like this:
>
> #
> ## Small test program
> m1 = make_measure(3, 4)
> m2 = make_measure(17, 42)
> print_measure("m1", m1)
> print_measure("m2", m2)
> ##

Re: [Tutor] 'elp!!!!!!!1Totally Clueless Newbie In Distress

2007-01-20 Thread Kent Johnson
Karl Wittgenstein wrote:
> Thank you again,and once more in advance - if you would be so kind as to 
> point me learning material...My spare time is very short,between 
> graduation and work,so I would appreciate very didatic material...Thank 
> you guys again!

Try one of the tutorials listed here
http://wiki.python.org/moin/BeginnersGuide/NonProgrammers

or one of these books:
http://effbot.org/pyfaq/tutor-what-are-some-good-books-on-python.htm

Kent


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


Re: [Tutor] 'elp!!!!!!!1Totally Clueless Newbie In Distress

2007-01-20 Thread Kent Johnson
Karl Wittgenstein wrote:
> I would also like to ask what skills you think I should develop so I can 
> approach programming more
> ' natively', and would like to clarify the following issue:
> input("Something") usually displays Something when prompting for 
> input;why is that the case when I run a single line of code and isn't 
> when I use many?When I run three lines straight in this format,only the 
> first message and prompt are displayed...That is surely out of the scope 
> of my current knowledgeWhich is not very encompassing,anyway.

input('Something') displays the prompt 'Something' and then waits for 
input up to a new line. When you enter the input it will execute the 
next statement which may be another input().

Kent

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


[Tutor] How to import this program, and other questions

2007-01-20 Thread Dick Moores


Tutors,
I recently learned a bit about using the clnum package (see
<
http://calcrpnpy.sourceforge.net/clnumManual.html>),
and am trying to write a set of functions that I could import to do
very precise division, raising any number to any power, etc., where the
numbers can be strings in the form of "long floats", e.g.,
"1234.9872364091270983712639048710297".
I've succeed with a script, clnumDivision.py, (see it at
<
http://www.rcblue.com/Python/clnumDivision_for-web.py>) but it is
not one function, but a script with 3 functions plus a main(). So my
first question is how can I use this as a function that I could, for
example, import into the interactive shell by a "from xxx import
yyy", or an "import zzz"? Is the answer to put all 3
functions inside one big one? 
Also, I'd appreciate knowing if there are easier ways to do some of the
things I've done inside sciNotation() and numberRounding(), especially
the former. 
Thanks very much,
Dick Moores




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


Re: [Tutor] 'elp!!!!!!!1Totally Clueless Newbie In Distress

2007-01-20 Thread Karl Wittgenstein

"input('Something') displays the prompt 'Something' and then waits for
input up to a new line. When you enter the input it will execute the
next statement which may be another input()."
It should be so,man,I believe you.But believe me when I say that THIS DAMN
INTERPRETER DOES NOT ACT ACCORDINGLY!!!Sorry for the emotive caps,it's just
frustration biting my ancles...Maybe it's a SPE problem??
Thank you.



2007/1/20, Kent Johnson <[EMAIL PROTECTED]>:


Karl Wittgenstein wrote:
> I would also like to ask what skills you think I should develop so I can
> approach programming more
> ' natively', and would like to clarify the following issue:
> input("Something") usually displays Something when prompting for
> input;why is that the case when I run a single line of code and isn't
> when I use many?When I run three lines straight in this format,only the
> first message and prompt are displayed...That is surely out of the scope
> of my current knowledgeWhich is not very encompassing,anyway.

input('Something') displays the prompt 'Something' and then waits for
input up to a new line. When you enter the input it will execute the
next statement which may be another input().

Kent


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


Re: [Tutor] 'elp!!!!!!!1Totally Clueless Newbie In Distress

2007-01-20 Thread Kent Johnson
Karl Wittgenstein wrote:
> "input('Something') displays the prompt 'Something' and then waits for
> input up to a new line. When you enter the input it will execute the
> next statement which may be another input()."
> It should be so,man,I believe you.But believe me when I say that THIS 
> DAMN INTERPRETER DOES NOT ACT ACCORDINGLY!!!Sorry for the emotive 
> caps,it's just frustration biting my ancles...Maybe it's a SPE problem??
> Thank you.

Can you describe exactly what you are doing? And please stop with the 
swear words, they are not appropriate to this list.

Kent

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


Re: [Tutor] 'elp!!!!!!!1Totally Clueless Newbie In Distress

2007-01-20 Thread Karl Wittgenstein

Sorry for the swear words...

2007/1/20, Kent Johnson <[EMAIL PROTECTED]>:


Karl Wittgenstein wrote:
> "input('Something') displays the prompt 'Something' and then waits for
> input up to a new line. When you enter the input it will execute the
> next statement which may be another input()."
> It should be so,man,I believe you.But believe me when I say that THIS
> DAMN INTERPRETER DOES NOT ACT ACCORDINGLY!!!Sorry for the emotive
> caps,it's just frustration biting my ancles...Maybe it's a SPE problem??
> Thank you.

Can you describe exactly what you are doing? And please stop with the
swear words, they are not appropriate to this list.

Kent


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


Re: [Tutor] 'elp!!!!!!!1Totally Clueless Newbie In Distress

2007-01-20 Thread Karl Wittgenstein

Ok,got the script working almost fine now...The only problem is that the
program window closes before we can get a glimpse of the answer...I use SPE
under WinXP, and have seen this problem in every script i try...This is the
script,as redone by a Smart Caring Dude on this list:

global altura_aeronave, largura_aeronave, comprimento_aeronave,
comprimento,largura, altura

def compativel():
  global altura, altura_aeronave, comprimento, comprimento_aeronave, \
 largura, largura_aeronave
  if not largura <= largura_aeronave:
  print 'Volume largo demais!'
  elif not altura <= altura_aeronave:
  print 'Volume alto demais!'
  elif not comprimento<=comprimento_aeronave:
  print 'Volume comprido demais!'
def define():
  global largura, altura, comprimento
  largura=input("Por favor informe a largura do volume em cm")
  altura=input("Por favor informe a altura do volume em cm")
  comprimento=input("Por favor informe o comprimento do volume em cm")

def porao():
  global altura_aeronave, largura_aeronave, comprimento_aeronave
  porao = input("Por favor informe o porĂ£o a ser utilizado:1-4")
  if porao == 1 :
  altura_aeronave = 111
  largura_aeronave = 112
  comprimento_aeronave = 211 #You originally had comprimento here?
  return 1
  elif porao == 4:
  altura_aeronave = 112
  largura_aeronave = 113
  comprimento_aeronave = 212 #Same here
  return 1
  else:
  print "Porao inexistente!"

if porao():
  define()
  compativel()


2007/1/20, Kent Johnson <[EMAIL PROTECTED]>:


Karl Wittgenstein wrote:
> "input('Something') displays the prompt 'Something' and then waits for
> input up to a new line. When you enter the input it will execute the
> next statement which may be another input()."
> It should be so,man,I believe you.But believe me when I say that THIS
> DAMN INTERPRETER DOES NOT ACT ACCORDINGLY!!!Sorry for the emotive
> caps,it's just frustration biting my ancles...Maybe it's a SPE problem??
> Thank you.

Can you describe exactly what you are doing? And please stop with the
swear words, they are not appropriate to this list.

Kent


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


Re: [Tutor] Redirect from a CGI script

2007-01-20 Thread Paulino

Still doesn't work.

This should be a server issue, once I use a very basic server:

'from BaseHTTPServer import HTTPServer 
'from CGIHTTPServer import CGIHTTPRequestHandler

'HTTPServer(("localhost", 80),CGIHTTPRequestHandler).serve_forever()

I tryed also with the Karrigel embeded server and nothing happened...

I tryed all the sugestions from Andre with no succes.

The cgi script as only these two lines:
'print "Content-type:text/html\r\n"
'print "Location:http://python.org/\r\n\r";

I have a Win Xp pro machine with Python2.5.

Paulino

On Sat, 2007-01-20 at 02:10 +, Paulino wrote:
  

Thank you Andre,

well it doesn't work either!



This works, 


#!/usr/bin/python
print "Location:http://python.org/\r\n\r";

as does this

#!/usr/bin/python
print "Content-type:text/html\r"
print "Location:http://python.org/\r\n\r";


Tested using Apache on Linux.  A redirect should have a 3xx status.
Apache saw the location header and fixed the status to be 302.  My
browser (firefox) received the 302 status with the new location and
requested the new URL.

Each header line should be separated by \r\n.  A Python print on linux
will only output \n.  In actual practice, that appears to work OK.
either the browsers tolerate the missing \r or Apache fixes the data
stream.

Firefox plugins called tamperdata and liveheaders can be very helpful
for debugging these kinds of interactions.

Get the redirect to a real web site working.  Then fix it to redirect to
your script.  Use tamperdata to see what is going on if you have trouble
making it work.

  

Paulino


Andre Engels escreveu:
2007/1/18, Paulino <[EMAIL PROTECTED]>: 
How can i redirect to another URL from a python CGI script.

Is's suposed to be as simply as:

print "Location : http://newurl "

It's not working.

this simple code does't work - < redir.pyw>

'print "Content-Type:text/html\n\n"
'print "Location : /cgi-bin/ecodiv.pyw "
'print

I use CGIHTTPServer, the server script is as follows:

'from BaseHTTPServer import HTTPServer 
'from CGIHTTPServer import CGIHTTPRequestHandler

'HTTPServer(("localhost", 80),
CGIHTTPRequestHandler).serve_forever()

instead of redirecting, it only prints
'Location : /cgi-bin/ecodiv.pyw' inthe 
browser



I haven't tested it, but I think I had a similar error recently, and
that was solved by removing the \n\n at the end of the Content-Type
line. You could try that.






--
Andre Engels, [EMAIL PROTECTED]
ICQ: 6260644  --  Skype: a_engels
  

___
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] 'elp!!!!!!!1Totally Clueless Newbie In Distress

2007-01-20 Thread David Rock
* Karl Wittgenstein <[EMAIL PROTECTED]> [2007-01-20 13:10]:
> Ok,got the script working almost fine now...The only problem is that the
> program window closes before we can get a glimpse of the answer...I use SPE
> under WinXP, and have seen this problem in every script i try...This is the
> script,as redone by a Smart Caring Dude on this list:

It sounds like you need to run it from a command window.  Running it the
way you are isn't meant to leave a window up after the script is
finished. Do Start->Run->cmd  on XP to get a command window.  python
should already be in your path, so typing "python" at the propmt should
result in it running the interpreter.  If that works, exit the
interpreter and type "python scriptname" That should run your script,
and you will see the results in the command window because it won't
close after the script is done.

-- 
David Rock
[EMAIL PROTECTED]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Redirect from a CGI script

2007-01-20 Thread Python
On Sat, 2007-01-20 at 15:22 +, Paulino wrote:
> Still doesn't work. 

That's not terribly useful.  What status did tamperdata report?  What
did you see in the browser window?  Did you get a 302 status?

Try (specify the right URL for your script)

telnet localhost 80
GET /cgi-bin/redirect.py


What do you get?  (Describe what happens.)

Let us know if you don't understand the telnet command.

> 
> This should be a server issue, once I use a very basic server:
> 'from BaseHTTPServer import HTTPServer 
> 'from CGIHTTPServer import CGIHTTPRequestHandler
> 'HTTPServer(("localhost", 80),CGIHTTPRequestHandler).serve_forever()
> I tryed also with the Karrigel embeded server and nothing happened...
> 
> I tryed all the sugestions from Andre with no succes.
> 
> The cgi script as only these two lines:
> 'print "Content-type:text/html\r\n"
> 'print "Location:http://python.org/\r\n\r";
> 
> I have a Win Xp pro machine with Python2.5.
> 
> Paulino
> > On Sat, 2007-01-20 at 02:10 +, Paulino wrote:
> >   
> > > Thank you Andre,
> > > 
> > > well it doesn't work either!
> > > 
> > 
> > This works, 
> > 
> > #!/usr/bin/python
> > print "Location:http://python.org/\r\n\r";
> > 
> > as does this
> > 
> > #!/usr/bin/python
> > print "Content-type:text/html\r"
> > print "Location:http://python.org/\r\n\r";
> > 
> > 
> > Tested using Apache on Linux.  A redirect should have a 3xx status.
> > Apache saw the location header and fixed the status to be 302.  My
> > browser (firefox) received the 302 status with the new location and
> > requested the new URL.
> > 
> > Each header line should be separated by \r\n.  A Python print on linux
> > will only output \n.  In actual practice, that appears to work OK.
> > either the browsers tolerate the missing \r or Apache fixes the data
> > stream.
> > 
> > Firefox plugins called tamperdata and liveheaders can be very helpful
> > for debugging these kinds of interactions.
> > 
> > Get the redirect to a real web site working.  Then fix it to redirect to
> > your script.  Use tamperdata to see what is going on if you have trouble
> > making it work.
> > 
> >   
> > > Paulino
> > > 
> > > > Andre Engels escreveu:
> > > > 2007/1/18, Paulino <[EMAIL PROTECTED]>: 
> > > > How can i redirect to another URL from a python CGI script.
> > > > 
> > > > Is's suposed to be as simply as:
> > > > 
> > > > print "Location : http://newurl "
> > > > It's not working.
> > > > 
> > > > this simple code does't work - < redir.pyw>
> > > > 'print "Content-Type:text/html\n\n"
> > > > 'print "Location : /cgi-bin/ecodiv.pyw "
> > > > 'print
> > > > 
> > > > I use CGIHTTPServer, the server script is as follows:
> > > > 
> > > > 'from BaseHTTPServer import HTTPServer 
> > > > 'from CGIHTTPServer import CGIHTTPRequestHandler
> > > > 'HTTPServer(("localhost", 80),
> > > > CGIHTTPRequestHandler).serve_forever()
> > > > 
> > > > instead of redirecting, it only prints
> > > > 'Location : /cgi-bin/ecodiv.pyw' inthe 
> > > > browser
> > > > 
> > > > 
> > > > I haven't tested it, but I think I had a similar error recently, and
> > > > that was solved by removing the \n\n at the end of the Content-Type
> > > > line. You could try that.
> > > > 
> > > > 
> > > > 
> > > > 
> > > > 
> > > > 
> > > > -- 
> > > > Andre Engels, [EMAIL PROTECTED]
> > > > ICQ: 6260644  --  Skype: a_engels
> > > >   
> > > ___
> > > Tutor maillist  -  Tutor@python.org
> > > http://mail.python.org/mailman/listinfo/tutor
> > > 
> 
-- 
Lloyd Kvam
Venix Corp

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


Re: [Tutor] 'elp!!!!!!!1Totally Clueless Newbie In Distress

2007-01-20 Thread Roel Schroeven
Karl Wittgenstein schreef:
> Ok,got the script working almost fine now...The only problem is that the 
> program window closes before we can get a glimpse of the answer...I use 
> SPE under WinXP, and have seen this problem in every script i try...

Any program running in a console window does that. There are two ways 
around:
- open a console window and run your program from there, as David Rock 
describes
- you can work around it by adding raw_input("Press enter") as the very 
last line of the script

-- 
If I have been able to see further, it was only because I stood
on the shoulders of giants.  -- Isaac Newton

Roel Schroeven

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


Re: [Tutor] How to import this program, and other questions

2007-01-20 Thread Alan Gauld
"Dick Moores" <[EMAIL PROTECTED]> wrote 

> I've succeed with a script, clnumDivision.py, (see it 
> at < http://www.rcblue.com/Python/clnumDivision_for-web.py>) 
> but it is not one function, but a script with 3 functions plus a 
> main(). So my first question is how can I use this as a function 
> that I could, for example, import into the interactive shell 
> ...Is the answer to put all 3 functions inside one big one? 

Probably not, its more likely to be a small function that checks 
its input parameters and calls one of the 3 worker functions.
Thats a more user friendly method too since it givers users of 
the module the chance to use the internal functions in different 
ways if they don't want the top level convenience function...

I assume your main is called from within an if name== main clause?

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld

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


Re: [Tutor] Redirect from a CGI script

2007-01-20 Thread Danny Yoo


On Sat, 20 Jan 2007, Paulino wrote:

> Still doesn't work.

[some text cut]

> I tryed all the sugestions from Andre with no succes.
>
> The cgi script as only these two lines:
> 'print "Content-type:text/html\r\n"
> 'print "Location:http://python.org/\r\n\r";


Ok, good.

The last line of the program looks suspicious.  If it helps, let me 
rearrange the program that you've written to:

###
print "Content-type:text/html\r\n"
print "Location:http://python.org/\r\n";
print "\r"
###

The code is missing the critical '\n' that allows the web browser to 
recognize the header.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to import this program, and other questions

2007-01-20 Thread Dick Moores
At 10:01 AM 1/20/2007, Alan Gauld wrote:
>"Dick Moores" <[EMAIL PROTECTED]> wrote
>
> > I've succeed with a script, clnumDivision.py, (see it
> > at < http://www.rcblue.com/Python/clnumDivision_for-web.py>)
> > but it is not one function, but a script with 3 functions plus a
> > main(). So my first question is how can I use this as a function
> > that I could, for example, import into the interactive shell
> > ...Is the answer to put all 3 functions inside one big one?
>
>Probably not, its more likely to be a small function that checks
>its input parameters and calls one of the 3 worker functions.
>Thats a more user friendly method too since it givers users of
>the module the chance to use the internal functions in different
>ways if they don't want the top level convenience function...
>
>I assume your main is called from within an if name== main clause?

Yes. I just realized that I quoted the link wrong. Try 


The only user I have in mind is me. And I want to use all 3 functions 
together. Now that you've seen the program, could you explain what 
you meant by "a small function that checks its input parameters and 
calls one of the 3 worker functions."?

Thanks,

Dick Moores


>HTH,
>
>--
>Alan Gauld
>Author of the Learn to Program web site
>http://www.freenetpages.co.uk/hp/alan.gauld
>
>___
>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] Staring myself blind

2007-01-20 Thread Toon Pieton

Hey friendly users!

In a program I'm writing, I'm getting a Tab/space error, with the usual 1)
identation is incorrect or 2) mixes tabs and spaces. I just can't seem to
find. I tried selecting everything and untabbing it, no workie. I searched
an searched and searched, but couldnt find anything that is really wrong.

The error shows up on this line:
   highcard = [z[8],z[7],z[6],z[5],z[4]]

The lines surrounding this one are:
   while zab < winlen:
   yx = winner[int(winkeys[zab])]
   xz = yx[1]
   z = [yx[0],xz[0],xz[1],xz[2],xz[3],xz[4],xz[5)],xz[6]]
   # Card 1
   if z[7] > highcard[0]:
   highcard = [z[8],z[7],z[6],z[5],z[4]]
   defwinner = [winkeys[zab]]
   elif z[7] == highcard[0]:

I can't post the whole program, since it's ~1000 lines long.

Does anybody see what causes the problem? Or have any tips how to find the
error easily?

Thanks in advance!
Toon Pieton
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Redirect from a CGI script

2007-01-20 Thread Python
On Sat, 2007-01-20 at 10:13 -0800, Danny Yoo wrote:
> 
> On Sat, 20 Jan 2007, Paulino wrote:
> 
> > Still doesn't work.
> 
> [some text cut]
> 
> > I tryed all the sugestions from Andre with no succes.
> >
> > The cgi script as only these two lines:
> > 'print "Content-type:text/html\r\n"
> > 'print "Location:http://python.org/\r\n\r";
> 
> 
> Ok, good.
> 
> The last line of the program looks suspicious.  If it helps, let me 
> rearrange the program that you've written to:
> 
> ###
> print "Content-type:text/html\r\n"
> print "Location:http://python.org/\r\n";
> print "\r"
> ###
> 
> The code is missing the critical '\n' that allows the web browser to 
> recognize the header.

That gets supplied from the print - doesn't it?.

sys.stdout.write(...) would need the final \n and might actually be
clearer.

> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
-- 
Lloyd Kvam
Venix Corp

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


Re: [Tutor] Redirect from a CGI script

2007-01-20 Thread Danny Yoo


On Sat, 20 Jan 2007, Python wrote:

> On Sat, 2007-01-20 at 10:13 -0800, Danny Yoo wrote:

>> The last line of the program looks suspicious.  If it helps, let me
>> rearrange the program that you've written to:
>>
>> ###
>> print "Content-type:text/html\r\n"
>> print "Location:http://python.org/\r\n";
>> print "\r"
>> ###
>>
>> The code is missing the critical '\n' that allows the web browser to
>> recognize the header.
>
> That gets supplied from the print - doesn't it?.

Hi Lloyd and Paulino,


Ah, very true.  Ah ha!  That's exactly the problem here.  Thanks Lloyd!

What's happening is that Python's 'print' statement introduces its own 
newline between the content-type header and the location header.


So the bytes that are actually being written to the server look something 
like:

   "Content-type: text/html\r\n\nLocation: http://python.org/\r\n\n\r\n";

which is wrong: we really want it to be:

   "Content-type: text/html\r\nLocation: http://python.org/\r\n\r\n";


> sys.stdout.write(...) would need the final \n and might actually be
> clearer.

Yeah, I agree: that's exactly the right thing to use here.  (Actually, the 
right thing to do here is probably to use a separate client library that 
handles the ugliness, raw details of the CGI protocol.)


Paulino, in any case, use sys.stdout.write() rather than the print 
statement, at least when you're writing out the headers.  You need the 
extra control that sys.stdout.write() gives you: 'print' is introducing 
newlines that, under normal circumstances, are harmless, but when we're 
writing headers like this, make it easy to make the mistakes above.


Thanks again Lloyd!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Staring myself blind

2007-01-20 Thread Danny Yoo


On Sat, 20 Jan 2007, Toon Pieton wrote:

> In a program I'm writing, I'm getting a Tab/space error, with the usual 
> 1) identation is incorrect or 2) mixes tabs and spaces. I just can't 
> seem to find. I tried selecting everything and untabbing it, no workie. 
> I searched an searched and searched, but couldnt find anything that is 
> really wrong.

Hi Toon,

If you think you're running into tab/space issues, you can try running 
tabnanny on your program; it should help you detect the problem:

 http://docs.python.org/lib/module-tabnanny.html


But actually, there is a definite syntactic problem on one of the lines 
before the one you're looking at.  Take a very close look at:

>   z = [yx[0],xz[0],xz[1],xz[2],xz[3],xz[4],xz[5)],xz[6]]

There is an extra right parenthesis there that is almost certainly not 
supposed to be here.


By the way, the code you've shown us so far looks very syntactically 
fragile; I'd have to look at more of the code, but a "code smell" I'm 
sniffing is a lot of hardcoded array indexing.  Are you trying to treat an 
list as if it were a data structure?


Concretely, code that looks like the snippet above, or this code:

>   highcard = [z[8],z[7],z[6],z[5],z[4]]

is very susceptible to off-by-one errors (as well as syntactic typos). 
But even if it is technically correct, there's a more important reason why 
we should avoid code like this: there's no explicit, human reasoning in 
the numbers 8, 7, 6, 5, or 4 that would make it easy to know why the 
highcard depends on those values.  At least, we'd have to look at the rest 
of the program to figure this out.  So that knowledge is not as localized 
as it should be.

There are often different ways to write this that are less susceptible to 
syntactic typos.  If you could put up your code somewhere on the web, some 
of us here would be happy to do a code review with you.



> I can't post the whole program, since it's ~1000 lines long.

This is also a possible code smell.  Unless my code estimation is way off, 
I don't believe that code shouldn't be so long.  Get your code reviewed: 
we might be able to help you hack down the size of that code to something 
significantly tighter.


Good luck to you.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Staring myself blind

2007-01-20 Thread Danny Yoo
> This is also a possible code smell.  Unless my code estimation is way off, I 
> don't believe that code shouldn't be so long.

Oh good grief.  Forgive me for the double negative there.  I meant: "I 
don't believe the code should be that long."
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Staring myself blind

2007-01-20 Thread Bob Gailer
Toon Pieton wrote:
> Hey friendly users!
>
> In a program I'm writing, I'm getting a Tab/space error, with the 
> usual 1) identation is incorrect or 2) mixes tabs and spaces. I just 
> can't seem to find. I tried selecting everything and untabbing it, no 
> workie. I searched an searched and searched, but couldnt find anything 
> that is really wrong.
I copied this and pasted it in into my Python editor. I added while 1: 
at the top so I could preserve your indentation. What I get is a syntax 
error, highlighting the ) after the 5 in the line:

z = [yx[0],xz[0],xz[1],xz[2],xz[3],xz[4],xz[5)],xz[6]]

When I remove the ) it compiles OK.
>
> The error shows up on this line:
> highcard = [z[8],z[7],z[6],z[5],z[4]]
>
> The lines surrounding this one are:
> while zab < winlen:
> yx = winner[int(winkeys[zab])]
> xz = yx[1]
> z = 
> [yx[0],xz[0],xz[1],xz[2],xz[3],xz[4],xz[5)],xz[6]]
> # Card 1
> if z[7] > highcard[0]:
> highcard = [z[8],z[7],z[6],z[5],z[4]]
> defwinner = [winkeys[zab]]
> elif z[7] == highcard[0]:
>
> I can't post the whole program, since it's ~1000 lines long.
>
> Does anybody see what causes the problem? Or have any tips how to find 
> the error easily?
>
> Thanks in advance!
> Toon Pieton
> 
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>   


-- 
Bob Gailer
510-978-4454

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


Re: [Tutor] How to import this program, and other questions

2007-01-20 Thread Dick Moores


At 06:34 AM 1/20/2007, Dick Moores wrote:
Tutors,
I recently learned a bit about using the clnum package (see < 


http://calcrpnpy.sourceforge.net/clnumManual.html>),
and am trying to write a
set of functions that I could import to do very precise division, raising
any number to any power, etc., where the numbers can be strings in the
form of "long floats", e.g.,
"1234.9872364091270983712639048710297".
I've succeed with a script, clnumDivision.py, (see it at <
http://www.rcblue.com/Python/clnumDivision_for-web.py>) but it is not
one function, but a script with 3 functions plus a main(). So my first
question is how can I use this as a function that I could, for example,
import into the interactive shell by a "from xxx import yyy",
or an "import zzz"? Is the answer to put all 3 functions inside
one big one? 
Also, I'd appreciate knowing if there are easier ways to do some of the
things I've done inside sciNotation() and numberRounding(), especially
the former. 
I've been experimenting, and came up with this solution. At least it
works. I slightly rewrote
<
http://www.rcblue.com/Python/clnumDivision_for-web.py> as
clnumDiv.py 
(<
http://www.rcblue.com/Python/clnumDiv.py>) and put it in
E:\Python25\Lib\site-packages\mine and can now import by
from mine.clnumDiv import clnumDiv
or by   from mine.clnumDiv import clnumDiv as div
I can use this in other scripts, or at the interactive prompt:
from mine.clnumDiv import clnumDiv as div
>>> x = '1234.5678567856785678567856786586'
>>> y = '-.00098769876897687654654'
>>> prec = 50
>>> div(x, y, prec)
'-1.2499437030427053037075454076437920433253956536740E+006'
>>>
As I said, this works, but is clnumDiv.py organized correctly
pythonically?
Also, I'm still hoping for some suggestions about the details of the
code.
Thanks,
Dick Moores




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