Re: program organization question for web development with python

2010-09-27 Thread Hans
On Sep 17, 2:36 am, Bruno Desthuilliers bruno.
42.desthuilli...@websiteburo.invalid wrote:
 Hans a écrit :
 (snip)

  Maybe I did not make my question clear. I never tried python web
  programing before, so I want to start from CGI.

 You can indeed learn quite a few things doing raw CGI - the most
 important one being why frameworks are a good idea !-)

  I read something about web framework like django, but seems it's a
  little bit complicated.

 Not that much IMHO, but being an early django user I'm probably a bit
 biased. Now Python is known as the language with more web frameworks
 than keywords, so you could probably check some lighter framework like
   web.py (http://webpy.org/) or flask (http://flask.pocoo.org/).

  my task is actually very simple: get search
  string from input, and then search database, print search result. I
  thought CGI should be good enough to do this.

 CGI is good enough to do any web stuff - just like assembler is good
 enough to write any application !-)



  I don't have any idea about how to organize those cgi codes, so what
  I'm asking is:

  1. do I have to have each single file for each hyper-link? Can I put
  them together? how?

  2. how can I pass a db_cursor to another file?   can I use db_cursor as
  a parameter?

 Obviously not. FWIW, both questions show a lack of understanding of the
 HTTP protocol, and you can't hope to do anything good in web programming
 if you don't understand at least the basics of the HTTP protocol,
 specially the request/response cycle.

 Now for a couple more practical answers:

 There are basically two ways to organize your url = code mapping:
 1/ have only one cgi script and use querystring params to tell which
 action should be executed.
 2/ have one cgi script per action.

 The choice is up to you. For a simple app like yours, the first solution
 is probably the most obvious : always display the seach form, if the
 user submitted the form also display the result list. That's how google
 works (wrt/ user interface I mean).

 Now if you still need / want to have distinct scripts and want to factor
 out some common code, you just put the common code in a module that you
 import from each script.

Thank you very much! I got your meaning. The choice 1 is definitely
what I want, I just cannot think about this idea by myself. Thank you
again!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: program organization question for web development with python

2010-09-19 Thread Lawrence D'Oliveiro
In message
6102316a-d6e6-4cf2-8a1b-ecc5d3247...@w15g2000pro.googlegroups.com, Hans 
wrote:

 print a href=display_tb.py?id=%stable=%scursor=%s%s/a %
 (record[0],table_name,cursor_name,record1)

I would recommend avoiding filename extensions in your URLs wherever 
possible. For executables, in particular, leaving out the “.py” or “.pl” or 
whatever makes it easier to switch languages, should you need to in future.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: program organization question for web development with python

2010-09-17 Thread Bruno Desthuilliers

Hans a écrit :
(snip)


Maybe I did not make my question clear. I never tried python web
programing before, so I want to start from CGI.


You can indeed learn quite a few things doing raw CGI - the most 
important one being why frameworks are a good idea !-)



I read something about web framework like django, but seems it's a
little bit complicated.


Not that much IMHO, but being an early django user I'm probably a bit 
biased. Now Python is known as the language with more web frameworks 
than keywords, so you could probably check some lighter framework like 
 web.py (http://webpy.org/) or flask (http://flask.pocoo.org/).



my task is actually very simple: get search
string from input, and then search database, print search result. I
thought CGI should be good enough to do this.


CGI is good enough to do any web stuff - just like assembler is good 
enough to write any application !-)



I don't have any idea about how to organize those cgi codes, so what
I'm asking is:

1. do I have to have each single file for each hyper-link? Can I put
them together? how?



2. how can I pass a db_cursor to another file?   can I use db_cursor as
a parameter?


Obviously not. FWIW, both questions show a lack of understanding of the 
HTTP protocol, and you can't hope to do anything good in web programming 
if you don't understand at least the basics of the HTTP protocol, 
specially the request/response cycle.


Now for a couple more practical answers:

There are basically two ways to organize your url = code mapping:
1/ have only one cgi script and use querystring params to tell which 
action should be executed.

2/ have one cgi script per action.

The choice is up to you. For a simple app like yours, the first solution 
is probably the most obvious : always display the seach form, if the 
user submitted the form also display the result list. That's how google 
works (wrt/ user interface I mean).


Now if you still need / want to have distinct scripts and want to factor 
out some common code, you just put the common code in a module that you 
import from each script.

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


Re: program organization question for web development with python

2010-09-16 Thread Hans
On Sep 15, 5:33 pm, James Mills prolo...@shortcircuit.net.au wrote:
 On Thu, Sep 16, 2010 at 10:14 AM, Hans hans...@gmail.com wrote:
  I'm new to this area. Please allow me to ask some (maybe stupid)
  questions.

 Without reading the rest of your post too much. Designs are up to you,
 I can't comment.

 I can only share in a fairly common view, and that is, we'd encourage
 you to use a web framework
 as opposed to plain old CGI.

 cheers
 james

 --
 -- James Mills
 --
 -- Problems are solved by method

Hi James,

Thanks for response.
Maybe I did not make my question clear. I never tried python web
programing before, so I want to start from CGI.

I read something about web framework like django, but seems it's a
little bit complicated. my task is actually very simple: get search
string from input, and then search database, print search result. I
thought CGI should be good enough to do this.

I don't have any idea about how to organize those cgi codes, so what
I'm asking is:

1. do I have to have each single file for each hyper-link? Can I put
them together? how?
2. how can I pass a db_cursor to another file? can I use db_cursor as
a parameter?

Thanks again!

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


Re: program organization question for web development with python

2010-09-16 Thread MRAB

On 16/09/2010 18:19, Hans wrote:

On Sep 15, 5:33 pm, James Millsprolo...@shortcircuit.net.au  wrote:

On Thu, Sep 16, 2010 at 10:14 AM, Hanshans...@gmail.com  wrote:

I'm new to this area. Please allow me to ask some (maybe stupid)
questions.


Without reading the rest of your post too much. Designs are up to you,
I can't comment.

I can only share in a fairly common view, and that is, we'd encourage
you to use a web framework
as opposed to plain old CGI.

cheers
james

--
-- James Mills
--
-- Problems are solved by method


Hi James,

Thanks for response.
Maybe I did not make my question clear. I never tried python web
programing before, so I want to start from CGI.

I read something about web framework like django, but seems it's a
little bit complicated. my task is actually very simple: get search
string from input, and then search database, print search result. I
thought CGI should be good enough to do this.

I don't have any idea about how to organize those cgi codes, so what
I'm asking is:

1. do I have to have each single file for each hyper-link? Can I put
them together? how?
2. how can I pass a db_cursor to another file? can I use db_cursor as
a parameter?


I recently wrote a web-based program using CherryPy, which was very
straightforward. That might suit your needs.
--
http://mail.python.org/mailman/listinfo/python-list


Re: program organization question for web development with python

2010-09-16 Thread Iuri
Another pretty web framework is Bottle (http://bottle.paws.de). It is very
easy to setup and use. I use it to tasks like this one you want.

[]s
iuri


On Thu, Sep 16, 2010 at 3:01 PM, MRAB pyt...@mrabarnett.plus.com wrote:

 On 16/09/2010 18:19, Hans wrote:

 On Sep 15, 5:33 pm, James Millsprolo...@shortcircuit.net.au  wrote:

 On Thu, Sep 16, 2010 at 10:14 AM, Hanshans...@gmail.com  wrote:

 I'm new to this area. Please allow me to ask some (maybe stupid)
 questions.


 Without reading the rest of your post too much. Designs are up to you,
 I can't comment.

 I can only share in a fairly common view, and that is, we'd encourage
 you to use a web framework
 as opposed to plain old CGI.

 cheers
 james

 --
 -- James Mills
 --
 -- Problems are solved by method


 Hi James,

 Thanks for response.
 Maybe I did not make my question clear. I never tried python web
 programing before, so I want to start from CGI.

 I read something about web framework like django, but seems it's a
 little bit complicated. my task is actually very simple: get search
 string from input, and then search database, print search result. I
 thought CGI should be good enough to do this.

 I don't have any idea about how to organize those cgi codes, so what
 I'm asking is:

 1. do I have to have each single file for each hyper-link? Can I put
 them together? how?
 2. how can I pass a db_cursor to another file? can I use db_cursor as
 a parameter?

  I recently wrote a web-based program using CherryPy, which was very
 straightforward. That might suit your needs.

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

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


program organization question for web development with python

2010-09-15 Thread Hans
Hi,

I'm new to this area. Please allow me to ask some (maybe stupid)
questions.

I'm planning to write a web application which used for searching my
mysql database.

1. files organization

I have this in my main.py:
print a href=display_tb.py?id=%stable=%scursor=%s%s/a %
(record[0],table_name,cursor_name,record1)

it kind of works but not comfortable to me.

Do I have to use two files(main.py and display_tb.py)? does that means
each hyper-link needs a single file? Can I put those files together
and then they can share variables,classes, modules, etc?

2. database cursor as parameter?
I created database cursor in my main.py and then I have to use it in
another file(display_tb.py), Can I?  I put cursor as a parameter and
try to send it through hyper-link. but it somehow does not work.
error log listed below:

 /usr/lib/cgi-bin/display_tb.py in ()
   20 sql_str = SELECT * FROM %s  % search_str_list
   21 print p%s/p % sql_str
   22 cursor_ptr.execute(sql_str)
   23 result = cursor_ptr.fetchall()
   24
cursor_ptr = 'MySQLdb.cursors.Cursor object at 0xb786b36c',
cursor_ptr.execute undefined, sql_str = 'SELECT * FROM env_test where
id=20 '

type 'exceptions.AttributeError': 'str' object has no attribute
'execute'
  args = ('str' object has no attribute 'execute',)
  message = 'str' object has no attribute 'execute'

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


Re: program organization question for web development with python

2010-09-15 Thread James Mills
On Thu, Sep 16, 2010 at 10:14 AM, Hans hans...@gmail.com wrote:
 I'm new to this area. Please allow me to ask some (maybe stupid)
 questions.

Without reading the rest of your post too much. Designs are up to you,
I can't comment.

I can only share in a fairly common view, and that is, we'd encourage
you to use a web framework
as opposed to plain old CGI.

cheers
james

-- 
-- James Mills
--
-- Problems are solved by method
-- 
http://mail.python.org/mailman/listinfo/python-list


program organization question

2009-01-28 Thread Vincent Davis
Basically my program simulates the Medical Residency Match, generating
simulated data, running the match and then summarizing results. Currently it
does this all in one document (starting conditions--Gen data--run
match--summarize results). I will be running multiple simulations on
different starting condition and data generation. My question is how should
I organize this. My plane was to have a separate document for staring
conditions, data generation because these will change for each simulation.
Then on for the match a summarizing data as this will always be the same
except for saving the results as different names.
I don't even know how to pass data from on program to another although I
think I can figure this out.

Any guidance?

Thanks
Vincent Davis
--
http://mail.python.org/mailman/listinfo/python-list