[Tutor] need help planning website updates

2005-01-20 Thread Jay Loden
I have a sort of simple CMS system on my website made from a conglomeration of 
scripts.  On the left column, I want to add a feature that shows the last 
five items updated (only html & exe files in the /var/www/html/ for example) 
directory that I have updated, with each item as a link to the page. You can 
see what this is supposed to look like at http://jayloden.com (right now it's 
being done by hand)

I've been thinking of having a crontab run a Python script, which logs checks 
a file with something along the lines of: 

file.foo = 12:20-1/20/05

for each file, containing the date and time the file was last modified.  Then 
I would have the crontab script check the date in the file versus the dates 
on the current files, and if the current files have been updated, to add them 
to the html on the side of the page.  I have no trouble setting up the 
crontab, or editing the html template for my page (it's all created from php 
on the fly) but I wanted to know if I am going about this a semi-intelligent 
and/or efficient way, or if there is some incredibly better way that I could 
do this with Python.  For example, is there some other way to notify my 
script that a file has been modified, rather than run a crontab a couple 
times an hour.  Is there maybe a better way to store and check dates, etc. 

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


Re: [Tutor] need help planning website updates

2005-01-20 Thread Jay Loden
Adding it into the PHP that creates the html would create too much overhead 
since it loads each page individually upon request, and that would mean 
running the modified time check on every page load.  

But I was thinking about this after I sent the mail, and I think you have a 
point with just outputting the five last modified out of all files.  This was 
one of those times when your brain fails you and you think up an overly 
complicated solution to a simple problem. This way the script just has to run 
every 15 minutes or so and give me the five most recent files for use in the 
PHP. 

Thanks!

-Jay

On Thursday 20 January 2005 12:45, Kent Johnson wrote:
> It seems to me that if you want the five most recent changes, you don't
> have to keep a list of modified dates. Just get the modified date for all
> the files of interest and sort by date, then pick the top five.
>
> You could do this as part of your process to build the web site maybe?
>
> Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] glob or filter help

2005-01-21 Thread Jay Loden
I have the following code in my updates script (gets the five most recent 
updated files on my site)

def get_fles(exts, upd_dir):
 '''return list of all the files matching any extensions in list exts'''
 fle_list = [] 
 for each in exts:
  cmd = upd_dir + "*." + each
  ext_ls = glob.glob(cmd)
  fle_list = fle_list + ext_ls
 return filter(notlink, fle_list)

I wanted to just get one list, of all the .htm and .exe files in my upd_dir.  
I was trying to make a far more elegant solution that what's above, that 
could generate a list through a filter.  Is there a way to trim the code down 
to something that does ONE sort through the directory and picks up the .htm 
and .exe files? (note, it is not necessary for this to recurse through 
subdirectories in the upd_dir).  I have cmd defined above because calling
"glob.glob(upd_dir + "*." + each) returned the error "cannot concatenate 
string and list objects" - is this the only way around that, or is there a 
better way?

Also in the above code, "notlink" is just a function that returns True if 
"islink()" returns truethere has to be a better way to use this with 
filter(), how can i make filter use "if islink()!=true" as its condition?

The script is working now, (I know, I know, if it ain't broke, don't fix 
it...) but I want to be a better programmer so more elegant solutions are 
accepted gratefully. 
-Jay
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] read line x from a file

2005-01-21 Thread Jay Loden
One simple solution is to do: 

fle = open(file)
contents = file.readlines()
file.close()
print contents[x]  #or store this in a variable, whatever

-Jay

On Friday 21 January 2005 11:22, J. M. Strother wrote:
> I have  a text file containing 336 records.
> I can read and print out the whole file without any problem.
> What I want to do is read and print out one record only (chosen at
> random). So I need to get to record x, select it, and then print it (or
> store it in a variable).
> Can anyone tell me now to do this?
>
> I'm new to Python and programming, so sorry if this is very basic. Thanks.
>
> jon
> ___
> 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] New to Python

2005-01-26 Thread Jay Loden
I also recommend the book "Dive Into Python" - it gets awesome reviews, and 
the book is under Creative Commons license, so it's free to download and 
distribute. 

http://diveintopython.org 

I also have the book "Core Python Programming" which is pretty good, and has a 
nice way of leaping right into code so that if you have any prior knowledge, 
you can use it to learn faster. 

-Jay

On Wednesday 26 January 2005 09:09 pm, Jason White wrote:
> 
> Greetings all, I'm new to python and thought I'd pop in here for
> advice. I've done object oriented design and programmed in perl,
> java, c++, basic, etc. I haven't done a lot of development, mostly
> just glorified oject-oriented scripts. I'm curious about good
> tutorial websites and books to buy.
>  
> I also have a development question for anybody who might know.  The
> project I'm working on now to develop my python skills is a prgram to
> script control another windows program.  The program doesn't have a
> published API so I'll probably need to locate memory addresses data fields
> and button routines.  Am I in way over my head for a Python beginner
> or does anybody have any advice for where to start poking around in memory
> and which python classes I should use to do so? 
>  
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] files in a directory

2005-01-30 Thread Jay Loden
There's a few ways to accomplish this...the way that comes to mind is: 

##
import glob

files = glob.glob("/path/to/director/*.dml")  # assuming you want only .dml 

def spot(file):
  '''search for intensity spots and report them to an output file'''
  f1 = open('my_intensity_file.dml','r')
  int = f1.read().split('\n')

  my_vals  = intParser(int) 

  intParser return a list
  f2  = open('myvalues.txt','w') # you will want to change this to output mult 
  for line in my_vals:   # files, or to at least append instead of overwriting
  f2.write(line)
f2.write('\n')
  f2.close()

def main():
  for each in files:
spot(each)

main()

##

Basically, turn the parsing into a function, then create a list of files, and 
perform the parsing on each file.  glob() lets you grab a whole list of files 
matching the wildcard just like if you typed "ls *.dml" or whatever into a 
command prompt.  There wasn't too much info about specifically how you needed 
this to work, so this is a rough sketch of what you want. Hopefully it helps.

-Jay

On Sunday 30 January 2005 03:03 am, kumar s wrote:
> Hello.
>
> I wrote a parser to parse spot intensities. The input
> to this parser i am giving one single file
>
> f1 = open('my_intensity_file.dml','r')
> int = f1.read().split('\n')
>
> my_vals  = intParser(int)
>
> intParser return a list
> f2  = open('myvalues.txt','w')
> for line in my_vals:
>  f2.write(line)
>  f2.write('\n')
>
> f2.close()
>
>
> The problem with this approach is that, i have to give
> on file per a run. I have 50 files to pare and i want
> to do that in one GO.  I kepy those 50 files in one
> directory. Can any one suggest an approach to automate
> this process.
>
> I tried to use f1 = stdin(...) it did not work. i dont
> know , possible is that i am using incorrect syntax.
>
> Any suggestions.
>
> Thank you.
> K
>
>
>
>
>
>
>
> __
> Do you Yahoo!?
> All your favorites on one personal page – Try My Yahoo!
> http://my.yahoo.com
> ___
> 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] sys.argv[1: ] help

2005-02-25 Thread Jay Loden
Should be: 

import sys

def main():
  '''prints out the first command line argument'''
  print sys.argv[1]

main()

On Friday 25 February 2005 04:35 pm, Richard gelling wrote:
> Hi,
>
> I am reading ' Learning Python second edition' by Mark Lutz and David
> Ascher, and  I trying the code examples as  I go along. However I am
> having a problem with the following, which I don't seem to be able to
> resolve :-
>
> # test.py
> import sys
>
> print sys[ 1: ]
>
> This I believe is supposed to print the 1st argument passed to the
> program. However if I try
>
> test.py fred
>
> All  I get at the command line is
>
> []
>
> If I try :-
>
> python test.py fred
>
> I get
>
> ['fred']
>
> as I believe you are supposed to. I can run other examples,I have typed
> in by just using the file name, but not this particular example. Could
> anyone shine any light on what I am missing or have not configured
> correctly. I am runnung Python 2.4 on a windows XP box.
>
> Thanks a lot
>
> Richard 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


Re: [Tutor] Newbie simple question

2005-02-25 Thread Jay Loden
You want readlines() not readline() and it should work something like this:

remailfile = open("remail2.txt", r)
remails = remailfile.readlines()

for line in remails:
  #do something

-Jay

On Friday 25 February 2005 05:14 pm, Valone, Toren W. wrote:
> I need to know how to read the next line while in the "for line in" loop.
> Readline does not read the next line (I watched it in debug) I think it has
> something to do with the for line loop but I have not found any
> documentation in the doc's or tutor for any functions for line..
>
> Thanks, please forgive the sloppy code.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Prepend to a list?

2005-03-19 Thread Jay Loden
How can I prepend something to a list? I thought that I could do
list.prepend()  since you can do list.append() but apparently not.  Any way to 
add something to a list at the beginning, or do I just have to make a new 
list? 

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


[Tutor] random import errors?

2005-04-01 Thread Jay Loden
I have a python script that runs on my webserver every fifteen minutes.  It 
has run for several months with absolutely no problems.  Suddenly, yesterday 
morning I got an email from cron with an import error for sre_constants (see 
below)

I logged in with ssh, manually ran the script and got the same error.  started 
a Python interpreter shell, did "import sre_constants" and got no error.  
Exited, then ran the script again...and got an error importing 'string'.  I 
manually started up Python interpreter again and imported string, again with 
no error.  Then I exited and ran the script, and it ran fine with no errors. 

I got another such email from cron at 2:30am today ... anyone have any idea 
what would cause such a seemingly random problem after months of working 
fine? 

(sample traceback is below)
-Jay

'import site' failed; use -v for traceback
Traceback (most recent call last):
  File "/usr/local/bin/last_update", line 7, in ?
    import os, glob, time
  File "/usr/lib/python2.2/glob.py", line 4, in ?
    import fnmatch
  File "/usr/lib/python2.2/fnmatch.py", line 13, in ?
    import re
  File "/usr/lib/python2.2/re.py", line 27, in ?
    from sre import *
  File "/usr/lib/python2.2/sre.py", line 97, in ?
    import sre_compile
  File "/usr/lib/python2.2/sre_compile.py", line 15, in ?
    from sre_constants import *
ImportError: No module named sre_constants
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Re: random import errors

2005-04-05 Thread Jay Loden
Only one version installed, and I could copy it over from elsewhere, but I 
wouldn't be inclined to do so since it works right now. 

-Jay

On Tuesday 05 April 2005 10:22 pm, Lee Harr wrote:
> >I have a python script that runs on my webserver every fifteen minutes. 
> > It has run for several months with absolutely no problems.  Suddenly,
> > yesterday
> >morning I got an email from cron with an import error for sre_constants
> >(see
> >below)
> >
> >
> >   File "/usr/lib/python2.2/sre_compile.py", line 15, in ?
> > from sre_constants import *
> >ImportError: No module named sre_constants
>
> Do you have more than one version of python installed?
> Can you copy sre_constants.py from another system?
>
> _
> Express yourself instantly with MSN Messenger! Download today it's FREE!
> http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
>
> ___
> 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] Cell Bio Newbie Here

2005-04-11 Thread Jay Loden
Ok, it's a logic error in the while loop.  Starting at the beginning: you 
can't compare the value of "password" until the user inputs the value, which 
is why it's requiring you to put password = "foobar" at the top.  Otherwise, 
password has no value, and as far as the interpreter is concerned, it doesn't 
exist yet. 

The rest of it is a logic error because your while loop is executing as long 
as "unicorn" != "foobar" and therefore it's continuously looping.  Each time 
it loops, it asks for the password again, and sets a LOCAL variable called 
password to the new raw_input.  Then, when you get to the third time, it does 
the "if current_count in." Great.  But after my third mistake, it just loops in "That must have
> been complicated."
>
> I'd like for someone to tell me "why" i screwed up.  Not to just fix it.

> #first of all, why does this have to be here?
> password="foobar"
>
> count=3
> current_count=0
>
> while password !="unicorn":
>  if current_count  password=raw_input("Password:")
>  current_count=current_count+1
>  else:
>  print "That must have been complicated"
>
>
> print "Welcome in"
> Best,
>
> Gary
>
>
>
> Gary Laevsky, Ph.D.
> Keck Facility Manager, CenSSIS
> Northeastern University
> 302 Stearns
> 360 Huntington Ave.
> Boston, MA 02115
> voice(617) 373 - 2589
> fax(617) 373 - 7783
>
> http://www.censsis.neu.edu
>
> http://www.ece.neu.edu/groups/osl
>
> http://www.keck3dfm.neu.edu
>
> ___
> 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] how to display an image using python

2005-04-14 Thread Jay Loden
If you don't mind using an external program, you could use the 'display' 
command from ImageMagick. 

-Jay

On Thursday 14 April 2005 07:59 pm, Ertl, John wrote:
> All,
>
> I have asked this question before, but one more time most have commented
> about manipulation but displaying the image has become the big issue.  I
> want to display png and gif images on a Linux machine using python.  I am
> using PyNGL to make the images and PIL to manipulate them but I cannot load
> xv on the machines and PIL uses xv to display.  I have looked at
> PythonMagick but I could not even get past installing it.  It does not have
> a setup.py and uses boost.  I am hoping for a more straightforward Python
> way.
>
> Thanks,
>
> John Ertl
> ___
> 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] Installation Routines (Joseph Quigley)

2005-04-21 Thread Jay Loden
Rpm does in fact have dependency resolution, and rpm-based distributions use a 
package manager that can download the dependencies and install them for you - 
urpmi on mandrake, yum or apt4rpm on Fedora and Redhat, Yast on Suse

I've used all of these, they are all rpm based, and they all install 
dependencies. If you use the raw "rpm" command, even that will tell you 
"missing dependecy foo".

That being said, apt-get on debian is still my favorite (for sheer number of 
available packages), but urpmi on mandrake or Yast on Suse are quite 
excellent.

-Jay

On Wednesday 20 April 2005 04:17 pm, Max Noel wrote:
emerge and apt-get come to mind. rpm is inferior (no dependency
> resolution) but still does a good job, and I hear autopackage isn't
> bad.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python and Web Pages?

2005-04-23 Thread Jay Loden
I use both Python and PHP on my website to do a variety of tasks.  Some things 
PHP can do much easier than Python, but if you're doing simple things like 
form handling, Python will do nicely.  

If you're comfortable with Python, use it.  I find Python much easier to work 
with than PHP for a lot of things, but PHP works better with dynamic content 
within html, so I use each one where it's easiest. However, if you're not 
familiar with PHP, then I definitely wouldn't go out and learn PHP for this; 
just stick with Python because you'll get it done faster when you're 
comfortable.

-Jay

On Saturday 23 April 2005 05:09 pm, Paul Tader wrote:
> I have a couple programs/scripts that I want to write that need to be
> web-based.  Can Python (and a little HTML) accomplish this?  Or are
> other languages like PHP, or Perl better suited?
>
>
> A little more detail:
>
> One project is to make a web page that users login to with a name and
> password, choose from a list of "canned" directory structure (ie. how
> many subdirectories, top-level name, maybe permissions, etc), hit a "GO"
> button and then the directories are made.
>
> Another example is a web-based form that users interface with a mySQL
> database.  Simple additions/changes/deletions.  Basic stuff.
>
>
> Thanks,
> Paul
>
>
>
> ___
> 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] getopt matching incorrect options

2005-07-11 Thread Jay Loden
I have an app that takes a command line argument of -l or --list.  It uses the 
getopt module to parse the arguments, and I just noticed that for some reason, 
getopt is matching "--lis" or "--li" etc to "--list". (Code pasted in below)

Is this normal behavior, and if so, is there any way to avoid this? I just want 
it to match "--list" to "--list", not "--l" and "--li" and "--lis" etc. 

-Jay


## Code chunk below ##

 try:
options,args = getopt.getopt(sys.argv[1:], "Rf:shvl", ["list", 
"full-restart=", "full-restart-all", "status-all", "help", "version"])

 except getopt.GetoptError:
# print help information and exit:
usage()
sys.exit(2)

if opt in ("-l", "--list"):
listServices(svcs)
sys.exit()
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] getopt matching incorrect options

2005-07-11 Thread Jay Loden
I have an app that takes a command line argument of -l or --list.  It uses the 
getopt module to parse the arguments, and I just noticed that for some 
reason, getopt is matching "--lis" or "--li" etc to "--list". (Code pasted in 
below)

Is this normal behavior, and if so, is there any way to avoid this? I just 
want it to match "--list" to "--list", not "--l" and "--li" and "--lis" etc. 

-Jay


## Code chunk below ##

 try:
options,args = getopt.getopt(sys.argv[1:], "Rf:shvl", ["list", 
"full-restart=", "full-restart-all", "status-all", "help", "version"])

 except getopt.GetoptError:
# print help information and exit:
usage()
sys.exit(2)

if opt in ("-l", "--list"):
listServices(svcs)
sys.exit()
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Deleting an entry from a dictionary

2005-08-03 Thread Jay Loden
I don't believe it does...some time ago I asked about this when I was creating 
a list and I wanted the opposite of list.append() - if you search "prepend to 
a list" you should find the responses I was sent. 

The only solutions Python offers that I'm aware of are to either use 
list.insert() at the zero index, or use list.reverse() with list.append() to 
flip the list around, add an item, then reverse it back to the original order 
with one new item at the beginning. 

-Jay

On Wednesday 03 August 2005 2:21 pm, Smith, Jeff wrote:
> Ummm...that doesn't do what I asked.
>
> pop is a linguistic idiom for
>
> (val, mylist) = (mylist[-1], mylist[0:-1])
>
> shift is the standard idiom for
>
> (val, mylist) = (mylist[0], mylist[1:])
>
> but Python doesn't appear to offer this.
>
> Jeff
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How do I add an argument too...

2005-08-03 Thread Jay Loden
I think it was just a typo for "the python distro" that came out as "the 
epython distro"...

On Thursday 21 July 2005 9:15 pm, Danny Yoo wrote:
> On Thu, 21 Jul 2005, Joseph Quigley wrote:
> > optparse.. Can I download that as a module or do I have to download
> > epython?
>
> Hi Joseph,
>
> optparse derives from a hird-party library called Optik, so in a pinch,
> you can probably just use Optik:
>
> http://optik.sourceforge.net/
>
> It's also possible to port optparse back to older versions of Python,
> although that may take more work.
>
> Good luck!
>
> ___
> 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] Zope/Python web devel

2005-08-03 Thread Jay Loden
I've been considering some web projects recently, but I have some concerns 
about selecting the tools I plan to use. I like Python, and I was immediately 
thinking of using Zope to build on.

However, I am concerned about performance, resource usage, and scalability. 
Does anyone here have any experience with Zope or any other application 
frameworks like CherryPy used in a large/enterprise environment? Is Zope 
overly memory hungry or slow? If performance is a key point, am I better off 
growing my own solution from the ground up?

Second, and more specific to Python itself - does anyone here have first hand 
knowledge of how Python compares with other solutions for server side web 
development? I'm specifically interested in comparisons to PHP, but Ruby, 
Perl, Java, C/C++ and Lisp, etc. observations would be welcome. Basically, 
I'm trying to get a feel for what kind of performance and resource usage I'd 
see out of Python versus other options. I realize this is heavily dependent 
on what exactly I end up doing, but just as a general observation, I'd like 
to know what others have experienced. I know that some large web applications 
are built on Python (Yahoo Mail, Google), but there's certainly less being 
done in Python on the web than in Perl or PHP. I just want to make sure this 
isn't because of Python disadvantages as opposed to simple market share.

All responses are welcome. If anyone has links to some benchmarking studies 
comparing the two for web development I'd be grateful for those as well.

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


Re: [Tutor] while loops

2005-08-08 Thread Jay Loden
> coin = random.randrange(2)

That's the problem there...you've got coin assigned outside the while loop, so 
it is assigned 0 or 1 once, before the loop, and then you're running 100 
checks on the same value. 

If you move 
> coin = random.randrange(2)

to inside the while loop before the if statement, you'll get the result you 
want. 

-Jay


On Monday 08 August 2005 5:41 pm, Will Harris wrote:
> I am working my way through "python programming for the absolute beginner"
> and one of the challenges is to create a program that will flip a coin 100
> times and tell you how many of each it did. Now I have it flipping the
> coin, but when I try to do this 100 times I end up with it running through
> 100 times, but always the same result comes back. It will either be 100
> heads, or 100 tails. I have tried if statements and while loops and both
> seem to give me all or nothing. I am just looking for a hint at the
> direction to look of adjust to get the code below working not really the
> solution. Thanks in advanced for any tips.
>
> #!/usr/bin/python
> import random
>
> coin = random.randrange(2)
>
> count = 0
> head_count = 0
> tail_count = 0
>
> while (count != 100):
> if coin == 0:
> print "You got Heads!"
> head_count = head_count + 1
> count = count + 1
> else:
> print "You got Tails!"
> tail_count = tail_count + 1
> count = count + 1
>
> print "Out of", count, "you flipped", head_count, "heads and ", tail_count,
> "tails"
>
> ___
> 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] Invoking bash from within a python program

2005-09-02 Thread Jay Loden
Watch yourself on this one, slocate can often return some unexpected results 
for file searches, and the last thing you want to do is delete something 
important while trying to remove the latest game you installed. 

Also, if you're installing from source you can often run "make uninstall" to 
remove the installed files. 

And finally, the Vinay's suggestion of a simple one liner shell script is much 
simpler and probably as fast or faster than anything you come up with in 
Python.

Just figured I'd lend some words of warning to you as someone who's made 
similar mistakes in the past ;)

-Jay

On Sunday 14 August 2005 6:33 am, joe_schmoe wrote:
> The basic idea I was toying around with is to create a delete/uninstall
> program that would take the output of slocate and iterate through that
> deleting all of the files associated with the program
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python equiv to PHP "include" ?

2005-09-29 Thread Jay Loden
I've not been able to find an answer to this conundrum anywhere: 

My current website is done in PHP with a setup something like this: 

::PHP TEMPLATE CODE::

include('file.htm')

::PHP TEMPLATE CODE::

This way, I can have PHP embedded in my htm files and it will be processed as 
part of the script. For example, I can have a form that's written in HTML and 
processed in PHP, then simply 'include("form.htm")' and I have a form with 
processing that's ALSO wrapped in my site template. 

I can't figure out how one would approach this in Python (i'm using 
mod_python). There's no equivalent to the "include" function from PHP. I 
can't use import because then Python would try to parse the HTML from the 
imported file. I've looked at stuff like cheetah and PSP, but neither of 
those actually answers the question, which is how can I include dynamic 
content including PHP code directly into an existing script. Even if I 
started using PSP, I still can't "include" a PSP page into the middle of 
another PSP page.

I'm definitely willing to consider any other solution for how I can make a 
form that processes its input but maintains my template code wrapped around 
it, so feel free to point out a "Pythonic" method. I just don't want to 
duplicate the template code, and I can't find a nice neat solution like what 
I've got in PHP.

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


Re: [Tutor] Python equiv to PHP "include" ?

2005-09-29 Thread Jay Loden
Alan, thanks for your responses, they're quite helpful. I suspect the real 
problem I'm having is simply trying to switch modes of thinking to CGI style 
or mod_python style instead of the PHP style embedded code. 

The whole point of this exercise for me was to decide which language I prefer 
for web development and evaluate Python for web work. So far, I've found PHP 
much easier to work with and less "clunky" in terms of what I'm trying to do 
- but I believe that's very much a function of my thinking being rooted in 
the PHP style. 

If Im understanding this right...the Pythonic/CGI method for something like 
this is to import a template module of some kind, then call methods from that 
template to display the template, with other Python code in the middle that 
takes care of form processing? 

The solution I have now feels smoother, since all I do is put content 
into .htm files, then pull them into a template that's basically an html 
sandwich. This gives me capability to stick a  section into the .htm 
file itself - for example a form with some dynamic content/variables - and 
then from a user perspective, all they see is a normal html page.  

>From a server side, it's seeing one big PHP script that includes both template 
code and form code, but without me needing to write any templating code into 
the form itself - instead I just call the form into the template.  With 
Python, it seems like this kind of approach is impossible, and it also means 
that my form would probably have to have some kind of special extension, like 
"form.py" (so the handler knows what to do with it) instead of just being 
located at "form.htm" - am I following this all correctly? 

Does anyone know of any soup-to-nuts CGI programming examples online for 
Python that might make this clearer so I can bug the list less and just read 
some example code?

-Jay

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


[Tutor] Mod_python greedy url matching

2005-10-04 Thread Jay Loden
I'm having trouble with Apache and Mod_python - mod_python is set to 
use /var/www/html and pass all *.htm files on to the handler I wrote. 
Unfortunately, mod_python does a greedy match, 
so /var/www/html/subdirectory/file.htm still gets passed to the handler!  Is 
there some way to limit the handler to the directory and NOT include 
subdirectories?

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


Re: [Tutor] hand-holding for web development

2005-10-17 Thread Jay Loden
You need an Apache config section to tell it what to use mod_python on and 
how. For example, in httpd.conf or a separate file in your conf.d directory 
for apache: 


   AddHandler  mod_python .py
   PythonHandler test
   PythonDebug On


tells Apache to use mod_python on all .py files in my /var/www/html directory 
(which is also the document root on my server). 

Once that's loaded you should be able to run whatever your python code through 
a handler. For example, saving this as test.py: 

#
#mod_python super basic test script
#
from mod_python import apache

def handler(req):
   req.content_type = "text/html"
   req_file = basename(req.uri)
   if req.header_only:
  return apache.OK

   else:
  req.write("mod_python is working")
  return apache.OK

# end of script

This should print "mod_python is working" to the browser if you visit 
http://yoursite.com/test.py 

Remember that you need to restart/reload apache after any config change. The 
basic gist is that any .py file you load in the /var/www/html runs the script 
"test.py" (PythonHandler test) and executes the "handler()" function within 
the script. NOTE: this can be very non-intuitive, becuase running 
http://yoursite.com/test.py has exactly the same result as 
http;//yoursite.com/foo.py - because they're both simply running the handler 
script, test.py, for ALL .py files in the directory. That means that your 
PythonHandler script needs to dispatch other scripts or load special pages in 
order to get different code to run. Also note that there are some pre-written 
Handler scripts that come with mod_python that can often do most of your work 
for you.

You'll probably want a good tutorial on using mod_python to make sense of all 
this, because it's not really intuitive and it works differently than 
traditional cgi programming. Take a look at: 
http://modpython.org/live/current/doc-html/ 
to get you started, it's a lot more detailed and will probably answer your 
questions better. 

-Jay

On Thursday 13 October 2005 3:49 pm, nitin chandra wrote:
> Hi!...
> i am new to Python and i want to develop a website with forms; data
> submitted through forms will be stored in PostgreSQL.
> I am working on derivant of FC3, OpenLX.
> I have Apache 2.0.54 version installed, which is pre-configured with
> mod_python.
> how do i load and view my .py/.html web page (file) on the browser.
> i need the initial hand holding/guidance of how to start, configure , and
> develop modules.
>  thank in advance.
>  Nitin Chandra
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] hand-holding for web development

2005-10-24 Thread Jay Loden
Sorry, didn't see your reply until now...

the directory section can go either in your main apache config file (in my 
case, /etc/httpd/conf/httpd.conf ) OR in a separate file in the conf.d 
directory. In my case, I have a python.conf file in /etc/httpd/conf.d/ that 
contains the following: 

LoadModule python_module modules/mod_python.so


AddHandler  mod_python .htm
PythonHandler parse
#  PythonDebug On


As for Django, I don't even know what that is, let alone how to interface to 
it, so you'd have to look elsewhere for help on that. I imagine there's 
someplace online you can get Django help such a specific mailing list.

-Jay

On Tuesday 18 October 2005 04:23 pm, nitin chandra wrote:
> Thanks Jay
>
> i guess the  can be added only in one of the conf
> file. Which one should i add in?
>
> Thaks you. could you please guide how to interface Django with
> mod_python, for effectively using in web site development?
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor