Re: How to use time.clock() function in python

2007-01-22 Thread samuel . y . l . cheung
Thanks.

I have a fuction called 'func1'.

def func1:
 # logic of the function

When my script just call 'func1()' it works.
func1()

But when put it under timerit.Timer, like this:
t = timeit.Timer("func1()","")
t.repeat(1, 10)

# want to time how long it takes to run 'func1' 10 times, I get an
error like this:
  File "/usr/lib/python2.4/timeit.py", line 188, in repeat
t = self.timeit(number)
  File "/usr/lib/python2.4/timeit.py", line 161, in timeit
timing = self.inner(it, self.timer)
  File "", line 6, in inner
NameError: global name 'func1' is not defined

I don't understand why i can't find 'func1', when I call the function
'func1' directly, it works.
but why when I call it within 'timeit', it can't find it?

Thank you.





Gabriel Genellina wrote:
> At Monday 22/1/2007 19:05, [EMAIL PROTECTED] wrote:
>
> >I am following this python example trying to time how long does an
> >operation takes, like this:
> >
> >My question is why the content of the file (dataFile) is just '0.0'?
> >I have tried "print >>dataFile, timeTaken" or "print >>dataFile,str(
> >timeTaken)", but gives me 0.0.
> >Please tell me what am I missing?
> >
> >
> > t1 = time.clock()
> > os.system(cmd)
> >
> > outputFile = str(i) + ".png"
> >
> > t2 = time.clock()
> >
> > timeTaken = t2 - t1
> > allTimeTaken += timeTaken
> > print >>dataFile, timeTaken
>
> time.clock() may not give you enough precision; see this recent post
> http://mail.python.org/pipermail/python-list/2007-January/422676.html
> Use the timeit module instead.
>
>
> --
> Gabriel Genellina
> Softlab SRL
>
>
>
>
>
>
> __
> Preguntá. Respondé. Descubrí.
> Todo lo que querías saber, y lo que ni imaginabas,
> está en Yahoo! Respuestas (Beta).
> ¡Probalo ya! 
> http://www.yahoo.com.ar/respuestas

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


Re: How to use cmp() function to compare 2 files?

2007-02-27 Thread samuel . y . l . cheung
On Feb 27, 12:07 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
> In <[EMAIL PROTECTED]>, [EMAIL PROTECTED]
> wrote:
>
> >   File "./scripts/regressionTest.py", line 30, in getSnapShot
> > if (difflib.context_diff(f1.readlines(), f2.readlines()).len() ==
> > 0):
> >  # no difference
> > else:
> >  # files are different
> > AttributeError: 'generator' object has no attribute 'len'
>
> > Can you please help?
>
> The function returns a generator/iterator over the differences which has
> no `len()` method.  If you just want to know if two files are equal or not
> use `filecmp.cmp()`.  Read the docs about the `shallow` argument of that
> function.
>
> Ciao,
> Marc 'BlackJack' Rintsch

Thanks. I use that before, it does not work for me, since it always
return 1, regardless if the file content of 2 files are different or
not.


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