Re: Seeding the rand() Generator

2009-08-04 Thread Fred Atkinson
On Tue, 04 Aug 2009 07:12:30 GMT, Jarkko Torppa
 wrote:

>On 2009-08-04, Fred Atkinson  wrote:
>> On Mon, 3 Aug 2009 20:00:08 -0700 (PDT), Carl Banks
>> wrote:
>>>
>>>If you don't "get" why this is a MySQL question and not a Python
>>>question, then you need to learn more about what you are doing.
>>
>>  I wouldn't agree.  
>>
>>  I tried using the same command I used when I did this in PHP.
>> That command was: mt_srand(date("w"))
>>
>>  It was a PHP command that seeds the MySQL random function,
>> according to the folks on the PHP newsgroup.  
>
>It seems that they lied to you. Did you actually try that ?
>
>>  I'm trying to figure out what the Python equivalent of that
>> is.  
>
>Python equivalent of that is random.seed(x), if PHP docs are to be believed.
>
>>  Now do you see?  
>
>What you acutally want is "select *,rand(3) as rand from table
>order by rand" or something like that. That 3 is the seed in there.

Yes, I actually tried that and it worked.  

Things got much more random after I started using it. 

Regards, 



Fred 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Seeding the rand() Generator

2009-08-03 Thread Fred Atkinson
On Mon, 3 Aug 2009 20:00:08 -0700 (PDT), Carl Banks
 wrote:

>Your question is a MySQL question, not a Python question.  I don't
>know off hand how to seed the RNG in MySQL, and, since this is a
>Python group and not a MySQL group, I don't care to look it up.  But
>if you were able to produce the MySQL statement in PHP that does it
>you shouldn't need to ask.
>
>If you don't "get" why this is a MySQL question and not a Python
>question, then you need to learn more about what you are doing.

I wouldn't agree.  

I tried using the same command I used when I did this in PHP.
That command was: mt_srand(date("w"))

It was a PHP command that seeds the MySQL random function,
according to the folks on the PHP newsgroup.  

I'm trying to figure out what the Python equivalent of that
is.  

Now do you see?  



Fred 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Seeding the rand() Generator

2009-08-03 Thread Fred Atkinson
On Sun, 2 Aug 2009 17:00:40 -0700 (PDT), Carl Banks
 wrote:

I appreciate the response.  

I am executing a statement to retrieve one record at random.  

An example would be: SELECT first, second, third, fourth,
fifth, sixth from sometable order by rand() limit 1

It would be contained as: stmt = "SELECT first, second, third,
fourth, fifth, sixth from sometable order by rand() limit 1"

Then I would execute it with the command: cursor.execute(stmt)

How would I correctly seed the random generator in the MySQL
statement from within Python?  

Regards, 



Fred 
-- 
http://mail.python.org/mailman/listinfo/python-list


Get Cliet IP Address

2009-08-02 Thread Fred Atkinson
What is the function to obtain the client browser's IP
address?   




Fred 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Predefined Variables

2009-08-02 Thread Fred Atkinson
On Sun, 02 Aug 2009 08:11:22 -0700, Scott David Daniels
 wrote:

>Piet van Oostrum wrote:
>>>>>>> Scott David Daniels  (SDD) wrote:
>>> SDD> Stephen Cuppett (should have written in this order):
>>>>> "Fred Atkinson"  wrote ...
>>>>>> Is there a pre-defined variable that returns the GET line...
>>>>> os.environment('QUERY_STRING')
>>> SDD> Maybe you mean:
>>> SDD> os.environ['USER']
>> Let's take the best of both:
>> os.environ['QUERY_STRING']
>
>Sorry about that.  I was testing expression before posting, and I don't
>do that much cgi stuff.  I forgot to restore the variable name.
>
>--Scott David Daniels
>scott.dani...@acm.org

I finally got it to work with x =getenv('QUERY_STRING')

Regards, 



Fred 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Seeding the rand() Generator

2009-08-02 Thread Fred Atkinson
On Sun, 02 Aug 2009 08:53:50 -0700, Scott David Daniels
 wrote:

>Fred Atkinson wrote:
>>  How does one seed the rand() generator when retrieving random
>> recordings in MySQL?  
>
>It is not entirely clear what you are asking.  If you are talking about
>MySQL's random number generator, you are talking in the wrong newsgroup.
>If you are talking about Python's, does this work?
> import random
> random.seed(123542552)
>I'm not quite sure how you came to believe that Python controls MySQL,
>as opposed to using its services.
>
>--Scott David Daniels
>scott.dani...@acm.org

I am coding in Python.  

I am accessing a MySQL database.  

I have a string to instruct the MySQL database to use the
'rand()' function to randomly choose one of the records in the
database.  

I know how to seed it in PHP.  Does anyone know how to see it
from with Python?  

Regards, 




Fred 
-- 
http://mail.python.org/mailman/listinfo/python-list


Seeding the rand() Generator

2009-08-02 Thread Fred Atkinson
How does one seed the rand() generator when retrieving random
recordings in MySQL?  

Regards, 



Fred 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Predefined Variables

2009-08-01 Thread Fred Atkinson
On Sat, 01 Aug 2009 18:56:33 -0700, Fred Atkinson
 wrote:

>On Thu, 23 Jul 2009 15:28:50 +0200, "Diez B. Roggisch"
> wrote:
>
>>Fred Atkinson wrote:
>>
>>> Is there a pre-defined variable that returns the GET line
>>> (http://www.php.net/index.php?everythingafterthequestionmark) as a
>>> single variable (rather than individual variables)?
>>
>>Variables don't return things. Functions do. And additionally the answer
>>depends on what and with what you actually do.
>>
>>Diez
>
>   I want to display the client browser's IP address on the Web
>page.  
>
>   I'd like to create a variable like this: ip = somefunction(). 
>   Then I can print the IP address on the Web page and/or log it
>in an error file.  
>
>
>
>   Fred 

I replied to the wrong post.  

Sorry.  

 I want to do something like this: 

string = os.environment('QUERY_STRING')

If this is the string in the URL:
http://www.someurl.com/cgi-bin/somescript.cgi?anythingafterthequestionmark
   'string' should now contain the value
'everythingafterthequestionmark'

   When I use the os.environment('QUERY_STRING'), it doesn't work.  

   Is there something I should import to make this function work?  Or
what else is wrong?  



Fred 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Predefined Variables

2009-08-01 Thread Fred Atkinson
On Thu, 23 Jul 2009 15:28:50 +0200, "Diez B. Roggisch"
 wrote:

>Fred Atkinson wrote:
>
>> Is there a pre-defined variable that returns the GET line
>> (http://www.php.net/index.php?everythingafterthequestionmark) as a
>> single variable (rather than individual variables)?
>
>Variables don't return things. Functions do. And additionally the answer
>depends on what and with what you actually do.
>
>Diez

I want to display the client browser's IP address on the Web
page.  

I'd like to create a variable like this: ip = somefunction(). 
Then I can print the IP address on the Web page and/or log it
in an error file.  



Fred 
-- 
http://mail.python.org/mailman/listinfo/python-list


Predefined Variables

2009-07-24 Thread Fred Atkinson
Is there a pre-defined variable that returns the GET line
(http://www.php.net/index.php?everythingafterthequestionmark) as a
single variable (rather than individual variables)?  

Regards, 



Fred 
-- 
http://mail.python.org/mailman/listinfo/python-list


Final Project

2009-07-19 Thread Fred Atkinson
I'm looking for some ideas here.  

I think I've mentioned I am taking a course in Python and PHP.
The professor wants each of us to pick a project to write in both
languages.  It has to be something fairly complex and I'd like for it
to be something that would be useful on my Web site(s).  

I would be grateful for any and all suggestions.  

Regards, 





Fred 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: explode()

2009-07-14 Thread Fred Atkinson
On Mon, 13 Jul 2009 23:54:11 -0700 (PDT), alex23 
wrote:

>Fred Atkinson  wrote:
>>         I wish the Python site was as well written as the PHP site. On
>> the PHP site, I can look up a command and they show not only the docs
>> on that command but a list of all other commands associated with it.  
>
>Hey Fred,
>
>My problem is the complete opposite, I wish I could as easily
>interrogate objects in PHP about their behaviour as I can Python :)
>
>In case you're not familiar with this, you can see what methods are
>attached to an object using the intepreter via dir() and see the
>associated docstring for them via help(). Try looking at 'dir(str)'
>for a list of methods that strings recognise, then 'help(str.join)' to
>see the help on join.
>
>This is such a handy ability to have that I miss this casual
>introspection in everything else in which I'm required to develop.
>
>Hope this helps.

I appreciate the information.  I'm halfway through a course in
PHP and Python.  We are given assignments and we have to write the
assignment in both languages.  

I'll take a look at that as I work on this week's assignment
(I've only got a month to finish the course but I can probably take
some time to look at this.  

Regards, 




Fred 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: explode()

2009-07-14 Thread Fred Atkinson
On Tue, 14 Jul 2009 05:41:40 GMT, Tim Harig 
wrote:

>On 2009-07-14, Fred Atkinson  wrote:
>>  The one thing I really dislike about Python over PHP is that
>> Python can usually only appear in the cgi directory (unless other
>> arragements are made with your hosting provider or if you reconfigure
>> Apache on your own server if you have your own).  With PHP, I can put
>> them in any folder on my Web site without any problem.  
>
>That is a server configuration and has nothing to do with Python directly.

Agreed, it doesn't.  But if my hosting provider won't change it, I'm
stuck with it.  

Regards, 



 Fred 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: explode()

2009-07-13 Thread Fred Atkinson
On Mon, 13 Jul 2009 22:32:55 -0700, Chris Rebert 
wrote:

>On Mon, Jul 13, 2009 at 11:28 PM, Fred Atkinson wrote:
>> On Sat, 11 Jul 2009 18:50:28 -0700, Chris Rebert 
>> wrote:
>>
>>>On Sat, Jul 11, 2009 at 7:41 PM, Fred Atkinson wrote:
>>>>        What is the Python equivalent of the PHP explode() function?
>>>
>>>some_string.split("separator")
>>>
>>>Cheers,
>>>Chris
>>
>>     What would the equivalent of the PHP function implode be?
>
>"separator".join(a_list_of_strings)
>
>I would recommend you read the Python manual's section on string methods:
>http://docs.python.org/library/stdtypes.html#string-methods
>
>Cheers,
>Chris

Chris, 

You always seem to be waiting when I post a question.  Do you
ever sleep?  

I wish the Python site was as well written as the PHP site. On
the PHP site, I can look up a command and they show not only the docs
on that command but a list of all other commands associated with it.  

Thanks.  Python is a whole new animal to me.  I'm taking a
course in PHP and Python online right now.  I've done PHP scripting
before though I don't claim to be a whiz on it.  But I'd barely heard
of Python before I took this course.  

The one thing I really dislike about Python over PHP is that
Python can usually only appear in the cgi directory (unless other
arragements are made with your hosting provider or if you reconfigure
Apache on your own server if you have your own).  With PHP, I can put
them in any folder on my Web site without any problem.  

Regards, 




Fred 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: explode()

2009-07-13 Thread Fred Atkinson
On Sat, 11 Jul 2009 18:50:28 -0700, Chris Rebert 
wrote:

>On Sat, Jul 11, 2009 at 7:41 PM, Fred Atkinson wrote:
>>        What is the Python equivalent of the PHP explode() function?
>
>some_string.split("separator")
>
>Cheers,
>Chris

 What would the equivalent of the PHP function implode be?  

Thanks, 




Fred 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: explode()

2009-07-11 Thread Fred Atkinson
On Sat, 11 Jul 2009 18:50:28 -0700, Chris Rebert 
wrote:

>On Sat, Jul 11, 2009 at 7:41 PM, Fred Atkinson wrote:
>>        What is the Python equivalent of the PHP explode() function?
>
>some_string.split("separator")
>
>Cheers,
>Chris

Thanks, 



Fred 
-- 
http://mail.python.org/mailman/listinfo/python-list


explode()

2009-07-11 Thread Fred Atkinson
What is the Python equivalent of the PHP explode() function?  





Fred 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IP Address Function

2009-07-08 Thread Fred Atkinson
On Wed, 08 Jul 2009 12:29:54 +0200, Piet van Oostrum 
wrote:

>Something like:
>
>#! /usr/bin/env python
>
>import cgi
>from os import getenv
>
>print "Content-type: text/html"
>print
>
>ipaddr = (getenv("HTTP_CLIENT_IP") or
>  getenv("HTTP_X_FORWARDED_FOR") or
>  getenv("HTTP_X_FORWARDED_FOR") or
>  getenv("REMOTE_ADDR") or
>  "UNKNOWN")
>
>print ipaddr

That did it.  

I wonder why they don't just have a function to return it instead of
putting you through all of that?  

At any rate, it works.  

Regards, 




  Fred 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IP Address Function

2009-07-08 Thread Fred Atkinson
On Tue, 07 Jul 2009 22:54:03 -0300, "Gabriel Genellina"
 wrote:

>En Tue, 07 Jul 2009 22:45:24 -0300, Fred Atkinson   
>escribió:
>
>>  Is there a Python function I can use to get the user's IP
>> address so I can display it on his browser?
>
>There is a long distance between "Python" and "browser" - you'll have to  
>tell us what is in between the two.

I want to have a Web page come up (written in Python, cgi)
that returns the IP address of the browser (user's PC's IP address).  

>By example, do you have a server and the user connects to it? is it  
>running Python? how do you run the Python application?
>And why do you want to do that on the server side? Isn't easier to do that  
>on the client side? What about proxies? NAT?

Yes.  By CGI.  

>If using CGI, look at the REMOTE_ADDR environment variable.

I did look at REMOTE_ADDR but I've been unable to figure out
the correct way to code it.  I've tried a number of ways but I've been
unsuccessful.  

Ideally, I'd like to store the brower's IP address in a string
and then print the string on the Web page from a Python CGI script.  

Regards, 



Fred 
-- 
http://mail.python.org/mailman/listinfo/python-list


IP Address Function

2009-07-07 Thread Fred Atkinson
Is there a Python function I can use to get the user's IP
address so I can display it on his browser?  

Regards, 




Fred 
-- 
http://mail.python.org/mailman/listinfo/python-list