mod_python performs several magnitudes slower than PHP?

2007-05-19 Thread chris . monsanto
Recently I've had to move my site to a new dedicated server running
FreeBSD 6.1. After installing apache 2.0.59, python 2.4.4 and
mod_python 3.3.1, I decided to bench a script in PHP vs one in Python.
I found out that for some reason, my mod_python was performing
extremely slow - magnitudes slower than it should. I scowered the
internet for hours and asked a few friends and still haven't been able
to find a solution to the problem.

from mod_python import apache

def handler(req):
  for i in xrange(1000):
print >> req, "Yeah"
  return apache.OK

and...



when I ran ab on both using 1000 requests and a concurrency of 10, i
got these results:

python- Requests per second:21.37 [#/sec] (mean)
php- Requests per second:1008.37 [#/sec] (mean)

Any ideas would really be appreciated... I'm on my last leg.

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


Re: Tapping into the access of an int instance

2007-09-20 Thread chris . monsanto
On Sep 20, 1:21 pm, "Tor Erik Sønvisen" <[EMAIL PROTECTED]> wrote:
> Hi,
>
> Does anyone know how to interrupt the lookup of an integer value? I
> know I need to subclass int, since builtin types can't be altered
> directly...
>
> Below is how far I've come... What I want is to tap into the access of
> instance i's value 1...
>
> >>> class Int(int):
>
> def __init__(self, *a, **k):
> super(Int, self).__init__(self, *a, **k)
>
> >>> i = Int(1)
> >>> i
>
> 1
>
> Regards,
> Tor Erik

While I'm not *totally* sure what you are asking, you can access the
first parameter you passed in __init__ via args[0].

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

Re: RE Help

2007-09-21 Thread chris . monsanto
On Sep 21, 2:44 pm, David <[EMAIL PROTECTED]> wrote:
> > data = "asdfasgSTARTpruyerfghdfjENDhfawrgbqfgsfgsdfg"
> > x = re.compile('START.END', re.DOTALL)
>
> This should work:
>
> x = re.compile('START(.*)END', re.DOTALL)

You'll want to use a non-greedy match:

x = re.compile(r"START(.*?)END", re.DOTALL)

Otherwise the . will match END as well.

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


Re: RE Help

2007-09-21 Thread chris . monsanto
On Sep 21, 3:32 pm, [EMAIL PROTECTED] wrote:
> > You'll want to use a non-greedy match:
> > x = re.compile(r"START(.*?)END", re.DOTALL)
> > Otherwise the . will match END as well.
>
> On Sep 21, 3:23 pm, Steve Holden <[EMAIL PROTECTED]> wrote:
>
> > Only if there's a later END in the string, in which case the user's
> > requirements will determine whether greedy matching is appropriate.
>
> > regards
> >   Steve
>
> There will be lots of START END combinations in the data. This is more
> accurate:
>
> sfgdfg*START*dfhdgh*END*dfdgh*START*dfhfdgh*END*dfgsdh*START*sdfhfdhj*END*fdghfdj
>
> The RE should extract the data between each couples of START and END.
>
> Thanks!

You'll want to use my version then. Glad to help!

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


Re: RE Help

2007-09-21 Thread chris . monsanto
On Sep 21, 4:09 pm, Thomas Jollans <[EMAIL PROTECTED]> wrote:
> On Friday 21 September 2007, [EMAIL PROTECTED] wrote:
>
> > Not specific to Python, but it will be implemented in it... how do I
> > compile a RE to catch everything between two know values? Here's what
> > I've tried (but failed) to accomplish... the knowns here are START and
> > END:
>
> > data = "asdfasgSTARTpruyerfghdfjENDhfawrgbqfgsfgsdfg"
> > x = re.compile('START.END', re.DOTALL)
>
> > x.findall(data)
>
> I'm not sure finding a variable number of occurences can be done with re. How
> about
>
> # data = the string
> strings = []
> for s in data.split('START')[1:]:
> strings.append(s.split('END')[0])

use re.findall :-)

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


Re: newb: Simple regex problem headache

2007-09-21 Thread chris . monsanto
On Sep 21, 5:04 pm, crybaby <[EMAIL PROTECTED]> wrote:
> import re
>
> s1 =' 25000 '
> s2 = ' 5.5910 '
>
> mypat = re.compile('[0-9]*(\.[0-9]*|$)')
> rate= mypat.search(s1)
> print rate.group()
>
> rate=mypat.search(s2)
> print rate.group()
> rate = mypat.search(s1)
> price = float(rate.group())
> print price
>
> I get an error when it hits the whole number, that is in this format:
> s1 =' 25000 '
> For whole number s2, mypat catching empty string.  I want it to give
> me 25000.
> I am getting this error:
>
> price = float(rate.group())
> ValueError: empty string for float()
>
> Anyone knows, how I can get 25000 out of s2 = ' 5.5910 '
> using regex pattern, mypat = re.compile('[0-9]*(\.[0-9]*|$)').  mypat
> works fine for real numbers, but doesn't work for whole numbers.
>
> thanks

Your pattern matches the empty string a bit too well, if you know what
I mean!

Changing the regex slightly to '[0-9]+(\.[0-9]+)?' yields the results
you want:

25000
5.5910
25000.0


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


Re: Would Anonymous Functions Help in Learning Programming/Python?

2007-09-21 Thread chris . monsanto
On Sep 21, 5:37 pm, Cristian <[EMAIL PROTECTED]> wrote:
> A friend of mine is an engineer and he's been needing to do more and
> more programming as he goes on with is career. I convinced him to
> learn Python instead of Perl and he's really started to like it. He
> usually comes to me when he can't accomplish a task with his current
> knowledge and I introduce him to a new feature in Python. FYIW, he
> thought List Comprehensions were freakin' awesome. He's started
> writing his own personal scripts for tasks like web scraping. So, from
> personal experience, Python truly is a great first language to learn.
>
> Although his learning experience has gone mostly smoothly, he's hit a
> lot of speed bumps with functions. Specifically, he's having trouble
> thinking of functions as first order data (don't worry, I haven't
> confused him with such terminology yet). He had a little trouble
> understanding that you can pass functions as arguments to other
> functions (e.g., passing a key to the list.sort method). He also had a
> little trouble grasping functions within other functions. Last but not
> least, he had trouble grasping methods in class declarations,
> especially the required self as the first argument (I'm sure he wasn't
> the first).
>
> Now, my friend's a smart guy so I know it isn't any lack of brain
> cells on his part. I still remember many students in my CS classes
> having trouble grasping the very same concept. And, after we finally
> get a hold of first order functions, we appreciate its incorporation
> into languages. It would be a shame if my friend just learns the
> motions and never incorporates first order functions into his
> programs. I began to wonder if there was anything Python could do to
> help newcomers grasp the power of first order functions or, as
> Pythonistas put it, everything is an object.
>
> To me, the biggest setback for new programmers is the different syntax
> Python has for creating functions. Instead of the common (and easy to
> grasp) syntax of foo = bar Python has the def foo(): syntax. So, when
> a new programmer is first introduced to functions they are immediately
> confronted with the notion that functions are "different". After all,
> they have their own special syntax. This seems to only further the
> separation newbies make between "data" and "functions" or "stuff" and
> "actions". Now, the vast majority of us learned this dichotomy when we
> first began to program, so we are ingrained to assume and even expect
> a different syntax for function declaration, but in a program like
> Python there doesn't seem to be any other reason to have it.
> Furthermore, I think it actually inhibits the learning of the
> uninitiated. We can, of course, keep the current syntax as sugar.
>
> To someone who's learning to program wouldn't a syntax like the
> further give them all they need and also reinforces the idea that
> functions are data just like everything else?
>
> my_function = function(foo, bar): pass
> an_instance_method = function(self, foo): pass
> a_method_declaration = method(self, foo): pass
>
> The last one is mostly my pet peeve of having Python "magically"
> create methods out of (what is essentially) a function declaration.
> When I first learned it, it felt wrong but you had to press through it
> because there was really no other way of declaring methods.
>
> What do you think? Have you hit this roadblock when helping others
> learn Python? Does the current syntax make you feel that functions are
> still treated as second class (get it?) citizens?

There are already anonymous functions in Python.

lambda x, y, z: x + y + z

is the same as:

def _(x, y, z): return x + y + z

As for the method stuff, check out staticmethod(). If you assign
staticmethod() to an object, it will be treated as a
normal function and not as a "method."

I have my own personal opinions about how methods should be in Python,
but, whatever. It's weird to deal with stuff like this:

x.y = re.match # Assign a function to an attribute of a class, but it
doesn't work because you can't assign anything but methods!
x.y = staticmethod(re.match) # Ugly

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


Re: Would Anonymous Functions Help in Learning Programming/Python?

2007-09-21 Thread chris . monsanto
On Sep 21, 6:07 pm, Cristian <[EMAIL PROTECTED]> wrote:
> On Sep 21, 2:48 pm, [EMAIL PROTECTED] wrote:
>
>
>
> > There are already anonymous functions in Python.
>
> > lambda x, y, z: x + y + z
>
> > is the same as:
>
> > def _(x, y, z): return x + y + z
>
> > As for the method stuff, check out staticmethod(). If you assign
> > staticmethod() to an object, it will be treated as a
> > normal function and not as a "method."
>
> > I have my own personal opinions about how methods should be in Python,
> > but, whatever. It's weird to deal with stuff like this:
>
> > x.y = re.match # Assign a function to an attribute of a class, but it
> > doesn't work because you can't assign anything but methods!
> > x.y = staticmethod(re.match) # Ugly
>
> True, there is lambda, but that is very limited. It might be useful
> for key arguments, but not much else. It doesn't solve the teaching
> problem of "See, functions are just like any other data type. You can
> assign it to a variable." It would be a footnote if it's mentioned at
> all. My hope is to subtly reinforce the notion that functions are data
> and can be passed around. The current function declaration doesn't
> help with this. Creating a function and assigning it to a name is
> exactly what Python does, why not have it come out in the syntax? It's
> not necessary, yes, but I think it would be helpful for teaching
> purposes.
>
> Again, it's not necessary as much as it's more intuitive and obvious
> what's going on. This helps a beginner sort out the process from the
> syntax without taking it on faith. They can see the class declaration
> and see "I'm defining just another attribute to this class only this
> time it happens to be method".
>
> There is nothing functionally lacking in Python. I'm just curious if
> there's anything Python can do syntax-wise to help a person better
> grasp programming ideas and Python's inner workings.

Guido apparently doesn't like lambda; I'm not really sure why, it's
extremely useful. There were rumors of it leaving in Python 3000, but
thankfully there was the decision to keep them. (I have a feeling if
they weren't kept in, a project fork would have happened or such.)
Anyway, one of the biggest problems implementation wise is indentation
in an expression - there is no expression currently that uses
significant whitespace. Python draws a pretty clear line between
expression and statement. I do agree with you however, it seems as if
there is an arbitrary line between function definitions and normal
variable assignment that shouldn't be there for the sake of
consistency.

A question: if you WERE to implement function definitions as normal
expressions, how would you go about embedding it within an expression?

x = map(def a:



, [1, 2, 3])

It looks hideous in my opinion and lining up the , with the def is
ugly. Not to mention currently, inside groupings, whitespace is
ignored. How would you handle a whitespace signif. expression inside a
grouping which by definition ignores whitespace?

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


Re: Counting method calls

2007-09-21 Thread chris . monsanto
On Sep 21, 7:15 pm, Ricardo Aráoz <[EMAIL PROTECTED]> wrote:
> Hi, I know I'm being dumb but, why does it not work?
>
> >>> class MyList(list):
>
> ... def __init__(self):
> ... self.calls = 0
> ... def __getattr__(self, name):
> ... self.calls += 1
> ... return list.__getattribute__(self, name)
>
> >>> a = MyList()
> >>> a
> []
> >>> a.append(1)
> >>> a
> [1]
> >>> a.calls
> 88
> >>> a.append(3)
> >>> a.calls
> 88
> >>> a.sort()
> >>> a
> [1, 3]
> >>> a.calls
>
> 176
>
> TIA

__getattr__ only works for attributes that don't exist. The name is
sorta confusing...

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

Re: sorteddict PEP proposal [started off as orderedict]

2007-09-25 Thread chris . monsanto
On Sep 25, 1:35 pm, thebjorn <[EMAIL PROTECTED]>
wrote:
> On Sep 25, 10:53 am, Mark Summerfield <[EMAIL PROTECTED]>
> wrote:
>
> > Hi,
>
> > Below is a PEP proposal for a sorteddict. It arises out of a
> > discussion on this list that began a few weeks ago with the subject of
> > "An ordered dictionary for the Python library?", and a similar one on
> > the P3K mailing list with the subject "ordered dict for p3k
> > collections?".
>
> > If there is positive feedback I will submit the PEP to the reviewers,
> > so if you think it is a good idea please say so. (I'm sure that if you
> > _don't_ like it you'll tell me anyway:-)
>
> I can't see much advantage over:
>
>   for key in sorted(mydict):
>   ...
>
> A much simpler data-structure, that is also very useful, is a
> dictionary that keeps insertion order -- it's also something that's a
> tad bit more difficult to implement yourself than the above. My
> personal implementation is documented 
> athttp://blog.tkbe.org/archive/python-property-set/
> It's very tempting to add value access by numerical index (I did as
> well), however I now think it's a mistake.
>
> -1 from me.
>
> -- bjorn

I agree on both counts. When I saw this topic, I was hoping it would
be about a structure that remembers insertion order. Now if you
drafted a pep on THAT, I would stand behind it.

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


Re: A question on python performance.

2007-09-26 Thread chris . monsanto
On Sep 26, 2:26 pm, "Joe Goldthwaite" <[EMAIL PROTECTED]> wrote:
> Hi everyone,
>
> I'm a developer who's been using python for a couple of years.  I wrote a
> fairly large application using it but I was learning the language at the
> same time so it most of the code kind of sucks.
>
> I've learned a lot since then and I've been going through my code trying to
> organize it better and make better use of Python's features.  I'm still  not
> an expert by any definition but I'm slowly getting better.
>
> I've been working on a trend class that takes twelve monthly numbers and
> returns a period to date, quarter to date, year to date and quarterly year
> to date numbers for a specific period. This worked but I ended up with a lot
> of code like this;
>
> def getValue(trend, param, per):
>if param == 'Ptd':
>  return trend.Ptd(per)
>elif param == 'Qtd':
>   return trend.Qtd(per)
>elif param == 'Ytd':
>   return trend.Ytd(per)
>elif param == 'YtdQ':
>   return trend.YtdQ(per)
>
> The code gets kind of wordy so I started trying to figure out how to call
> them dynamically since the param type is the same as the method the
> retrieves it.  I came up with this;
>
> def getValue(trend, param, per):
>return trend.__class__.__dict__[param](trend, per)
>
> That worked but it seems like the above line would have to do lots more
> object look ups at runtime so I didn't think it would be very efficient.  I
> thought maybe I could add a caller method to the trend class and I came up
> with this;
>
> class trend:
>...
>...
>...
>def caller(self, param, *args):
>   return self.__class__.__dict__[param](self, *args)
>
> This simplified the getValue function to this;
>
> def getValue(trend, param, per):
> return trend.caller(param, per)
>
> Out of curiosity, I thought I'd do some benchmarking and see which one
> performs the best. I executed three multiple times;
>
> loop one.  Time=11.71 seconds;
> trend.Ptd(per)
> trend.Qtd(per)
> trend.Ytd(per)
> trend.YtdQ(per)
>
> loop two. 12.107 seconds;
> trend.__class__.__dict__['Ptd'](trend, per)
> trend.__class__.__dict__['Qtd'](trend, per)
> trend.__class__.__dict__['Ytd'](trend, per)
> trend.__class__.__dict__['YtdQ'](trend, per)
>
> loop three. 17.085 seconds;
> trend.caller('Ptd', per)
> trend.caller('Qtd', per)
> trend.caller('Ytd', per)
> trend.caller('YtdQ', per)
>
> The first surprise was how close the first and second loops were.  I would
> have thought the first loop would be much faster.  The second surprise was
> how much slower the third loop was.  I know it has an extra call in there
> but other than that, it's doing basically the same thing as loop two.  Is
> there that much overhead in making a class method call?
>
> Can anyone explain the differences?

Makes perfect sense to me! Think about it:

method 1: looks up the method directly from the object (fastest)
method 2: looks up __class__, then looks up __dict__, then gets the
element from __dict__
method 3: looks up caller, looks up __class__, looks up __dict__, gets
element from __dict__

To get the element directly from the object (method 1), Python has to
internally check __class__.__dict__[element], which shows why method 1
and method 2 are nearly the same speed. The last version has to look
up caller in addition to the process described by method 2.

The best way to do what you are doing:

getattr(self, param)(self, *args)

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


Re: remove list elements..

2007-10-05 Thread chris . monsanto
On Oct 5, 10:27 am, Abandoned <[EMAIL PROTECTED]> wrote:
> Hi..
> I have a problem..
> list1=[11, 223, 334, 4223...] 1 million element
> list2=[22,223,4223,2355...] 500.000 element
>
> I want to difference list1 to list2 but order very importent..
>
> My result must be:
> list3=[11,334,...]
>
> I do this use FOR easly but the speed very imported for me. I want to
> the fastest method please help me.
>
> I'm sorry my bad english.
>
> King regards..

Research the "set" data type. :)

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


Re: novice list

2007-10-05 Thread chris . monsanto
On Oct 5, 10:22 am, Paul Rudin <[EMAIL PROTECTED]> wrote:
> István <[EMAIL PROTECTED]> writes:
> > Could somebody suggest me a novice Python list, please?
>
> Here you go:
>
> ['novice']
>
> (Sorry, couldn't resist.)

No no... I think he meant a "simple" list. Like, you know, a list
novices can handle.

I suggest the empty list []!

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

Re: Top Programming Languages of 2013

2007-10-07 Thread chris . monsanto
On Oct 7, 11:54 am, Wildemar Wildenburger
<[EMAIL PROTECTED]> wrote:
> Kay Schluehr wrote:
> > On Oct 7, 8:05 am, Dick Moores <[EMAIL PROTECTED]> wrote:
> >> 
>
> >> Dick Moores
>
> > Despite my doubts that Ajax and .NET will be programming languages in
> > 2013 a more interesting question is: what could push Python forward
> > s.t. it eats such a large piece of the PL cake?
>
> import friends
> import sex
>
> try:
>  sex.have()
> except ErrectionError, PrematureError:
>  pass
> finally:
>  sex.brag(friends)

Traceback (most recent call last):
  File "", line 1, in 
KeyError: 'woman'


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


Re: if then elif

2007-10-10 Thread chris . monsanto
On Oct 10, 5:03 pm, Larry Bates <[EMAIL PROTECTED]> wrote:
> Shawn Minisall wrote:
> > I just learned about if, then elif statements and wrote this program.
> > The problem is, it's displaying all of the possibilities even after you
> > enter a 0, or if the fat grams are more then the total number of
> > calories , that is supposed to stop the program instead of continuing on
> > with the print statements that don't apply.  Any idea's?  thanks
>
> >#Prompt for calories
> >cal = input("Please enter the number of calories in your food: ")
>
> >#Prompt for fat
> >fat = input("Please enter the number of fat grams in your food: ")
>
> >#Input validation
> >if cal or fat <= 0:
> >   #Display message
> >print "Error.  The number of calories and/or fat grams must be
> > positive"
> >print
>
> >else:
> >#Calculate calories from fat
> >calfat = float(fat) * 9
> >  #Calculate number of calories from fat
> >caldel = calfat / cal
>
> >#change calcent decimal to percentage
> >calcent = caldel * 100
>
> >if calfat > cal:
> >print "The calories or fat grams were incorrectly entered."
>
> >else:
> >#evaluate input
> >if caldel <= .3:
> >print "Your food is low in fat."
> >elif caldel >= .3:
> >print "Your food is high in fat."
>
> >#Display percentage of calories from fat
> >print "The percentage of calories from fat in your food is %",
> > calcent
>
> > Here's an example of the output...
>
> > Please enter the number of calories in your food: 50
> > Please enter the number of fat grams in your food: 30
> > Error.  The number of calories and/or fat grams must be positive
>
> > Your food is low in fat.
> > The percentage of calories from fat in your food is % 0.0
>
> > It was supposed to print The calories or fat grams were incorrectly
> > entered since the calories from fat was greater then the total number of
> > calories.
>
> Boolean problem:
>
> if cal or fat <= 0
>
> That may be the way you say it or "think" it but it won't work.
>
> 'cal or fat' is evaluated first.  Since they both have values this ALWAYS
> evaluates to 1 which is NEVER less than or equal to 0.
>
> You are looking for
>
> if (cal <= 0) or (fat <=0):
>
> (Note: Parenthesis not required, but it may help you understand precedence of
> evaluation.  Also read here:
>
> http://www.ibiblio.org/g2swap/byteofpython/read/operator-precedence.html
>
> -Larry

that's the most incorrect thing i've heard all day!

if cal or fat <= 0 is parsed as if (cal) or (fat <= 0)

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


Re: unicodedata implementation - categories

2007-10-13 Thread chris . monsanto
On Oct 13, 4:32 pm, James Abley <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I'm trying to understand how CPython implements unicodedata, with a view to
> providing an implementation for Jython. This is a background, low priority
> thing for me, since I last posted to this list about it in February!
>
> Python 2.5.1 (r251:54863, May  2 2007, 16:56:35)
> [GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.>>> 
> import unicodedata
> >>> c = unichr(0x10)
> >>> unicodedata.name(c)
>
> Traceback (most recent call last):
>   File "", line 1, in 
> ValueError: no such name>>> unicodedata.category(unichr(0x10))
>
> 'Cn'
>
> 0x10 is not a valid codepoint in Unicode 4.1, which is the version of
> the Unicode standard that Python 2.5 supports.
>
> So I have a couple of questions:
>
> 1) Why doesn't the category method raise an Exception, like the name method
> does?
> 2) Given that the category method doesn't currently raise an Exception,
> please could someone explain how the category is calculated? I have tried to
> figure it out based on the CPython code, but I have thus far failed, and I
> would also prefer to have it explicitly defined, rather than mandating that
> a Jython (.NET, etc) implementation uses the same (possibly non-optimal for
> Java) data structures and algorithms.
>
> My background is Mathematics rather than pure Computer Science, so doubtless
> I still have some gaps in my education to be filled when it comes to data
> structures and algorithms and I would welcome the opportunity to fill some
> of those in. References to Knuth or some on-line reading would be much
> appreciated, to help me understand the CPython part.
>
> Cheers,
>
> James
> --
> View this message in 
> context:http://www.nabble.com/unicodedata-implementation---categories-tf46194...
> Sent from the Python - python-list mailing list archive at Nabble.com.

Cn is the "Other, Not Assigned" category in Unicode. No characters in
Unicode have this property. I'm not sure why it doesn't raise an
Exception, but if category() returns Cn, then you know it's not a
valid character.

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


Re: Problem with regexp and text injection

2007-10-21 Thread chris . monsanto
On Oct 21, 6:22 pm, Panagiotis Atmatzidis <[EMAIL PROTECTED]>
wrote:
> Hello,
>
> I want to create a script in python that search for .html files in the
> predefined directory and subdirectories. Then it checks if a specific
> snippet of code exists in the .html file, if not it injects/adds the
> code right below the string  otherwise bypasses the file.
>
> I wrote the first part, I managed to write search function and I'm
> trying to find my way out of regular expressions reading the manuals.
> However I don't know what kind of function and module to use in order
> to write this function, re.search(), re.string() or re.match() or
> maybe re.compile() ?
>
> I have not much programming experience. Programming is not my cup of
> tea.
>
> Can someone help by pointing me to a sample code with comments if
> possible.
>
> Regards,
>
> atma

import glob
glob.glob("*.html") # returns a list of all filenames you are looking
for

-

import re
m = re.search(regular_expression_testing_for_string_of_code,
string_with_contents_of_page) # checks if your snippet is there
if m is None:
new_contents = re.sub(r"(?xis) ", lambda m: m.group() +
your_snippet_of_code, string_with_contents_of_page) # Add the snippet
to the body. I use a function as the replacement in case your snippet
has backreferences in it for some reason. If it doesn't, feel free to
use r"\0" + snippet_of_code.


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


Re: basic threading question

2007-10-30 Thread chris . monsanto
On Oct 30, 7:58 pm, "bambam" <[EMAIL PROTECTED]> wrote:
> Are function variables thread safe?
>
> def f(a):
> # whatever
> return float(a)
>
> Is that OK?
>
> def f(a):
> #whatever
> b=a:
> #whatever:
> return float(b)
>
> Is that OK?
>
> Steve.

Huh?

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