[Tutor] static variables - lock/semaphore

2006-07-01 Thread anil maran
hi
i have a program that is run on a website, and as it
is run from a website, it can be called more than once
and hence could end up corrupting db/data
is there a way to use some sort of semaphore or lock
so that it is not accessed simultaneously
the problem is it can be done with static variables in
C but how is it done in python
thanks a lot

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] static variables - lock/semaphore

2006-07-01 Thread Alan Gauld
 i have a program that is run on a website, and as it
 is run from a website, it can be called more than once
 and hence could end up corrupting db/data
 is there a way to use some sort of semaphore or lock
 so that it is not accessed simultaneously

There are ways of doing this in Python but if you are using 
a relational database for the data its usually easier to 
apply row level locking at the database level.

 the problem is it can be done with static variables in
 C but how is it done in python

It could be done with a global variable in Python in the 
same way but there are other solutions based around
threads which have explicit locks etc. For a web 
application using Python threads would probably be 
a good bet.

But you may find the whole problem simplified by adopting a 
web framework such as TurboGears which will take care of 
a lot of these kinds of issues for you - but with a bit of a 
learning curve. But if you have several web apps to build 
I'd seriously consider this route.

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] python debugger

2006-07-01 Thread Liviu Antoniu
Hi, guys,I have a small problem with python's debugger. I don't know how can I debugg a script through this debugger.Can you tell me?Thank you very much___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] static variables - lock/semaphore

2006-07-01 Thread Kent Johnson
anil maran wrote:
 hi
 i have a program that is run on a website, and as it
 is run from a website, it can be called more than once
 and hence could end up corrupting db/data
 is there a way to use some sort of semaphore or lock
 so that it is not accessed simultaneously
 the problem is it can be done with static variables in
 C but how is it done in python

If you are using a database for storage you should learn how to use the 
transactional features of the database. They are designed to let you 
control what happens when multiple users access the database at the same 
time.

To protect access to other kinds of data look at threading.Lock and RLock.

Kent

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


Re: [Tutor] saving output in a text file (fwd)

2006-07-01 Thread Danny Yoo
[forwarding to Tutor]

-- Forwarded message --
Date: Sat, 01 Jul 2006 13:58:47 +0400
From: Hafsa raza [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Subject: Re: [Tutor] saving output in a text file


Thank you for the quick reply. Let me put my question in a more
clearer way for you.

If we want to create a text file and write some text into it we use the
following command in Python:

myfile = open(test.txt,w)?xml:namespace prefix = o ns =
urn:schemas-microsoft-com:office:office /

myfile.write(hello world)

But what if instead of writing the text 'hello world', i want to write
the output returned by a regular expression pattern, into the text file,
how would we specify that in the write command.

Regards,

Hafsa






From:  Danny Yoo [EMAIL PROTECTED]
To:  Hafsa raza [EMAIL PROTECTED]
CC:  tutor@python.org
Subject:  Re: [Tutor] saving output in a text file
Date:  Fri, 30 Jun 2006 15:04:41 -0700 (PDT)
def double(s):
double: string - string
doubles up the input string s.
return s + s


Gaah.  Typos.  My apologies.  Here's a correction to double()

 def double(s):
 double: string - string
 Doubles up the input string s.  For example, double(abc)
 should return abcabc.
 
 return s + s


Would you be able to write a program that takes hello world,
runs
it through double(), and writes out hello worldhelloworld to
disk?

I meant to say that the expected content of the file should be:

  hello worldhello world

My apologies; I rushed that message too quickly.



FREE pop-up blocking with the new MSN Toolbar MSN Toolbar Get it now!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] saving output in a text file (fwd)

2006-07-01 Thread Danny Yoo
 If we want to create a text file and write some text into it we use the 
 following command in Python:

 myfile = open(test.txt,w)?xml:namespace prefix = o ns =
 urn:schemas-microsoft-com:office:office /

 myfile.write(hello world)

 But what if instead of writing the text 'hello world', i want to write 
 the output returned by a regular expression pattern, into the text file, 
 how would we specify that in the write command.


Just as a disclaimer: I am doing my utmost not to give out The Answer 
here.  So if it sounds like I'm not being very direct, that's precisely 
because you have a good intuition.  *grin* I'm trying to poke at the 
source of the problem, and not the immediate side effects.



You still haven't tackled my initial question about:

 def double(s):
 double: string - string
 Doubles up the input string s.  For example, double(abc)
 should return abcabc.
 
 return s + s


 Would you be able to write a program that takes hello world, runs it 
 through double(), and writes out hello worldhello world to disk?

Can you try this mini-problem first?  What you've done doesn't touch on 
the question: would you know how to use double() as a part of the write()?

Note that this is just a variation of your original question, replacing 
the regex part with the use of a helper function.  It seems like this 
should be even easier than the problem you're having now.

Here's why I'm asking this: if you're getting stuck at this point too, 
then I'll assume that the problem is that you are unfamiliar with using 
helper functions and function composition.  Then the group as a whole can 
help you with that, since that's a fundamental programming skill that 
you'll want to develop.

But if you can do the mini-exercise, then the focus shifts to the use of 
regular expressions, and things become much easier, since it'll mean that 
you're not familiar with the regex API.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor