Re: [Tutor] Diff for Python

2008-04-04 Thread Terry Carroll
On Fri, 4 Apr 2008, Wayne Watson wrote:

> Is there a Linux diff-like command for Python code? I'd like to see the 
> difference between two py files.

You could just use diff.

Python itself also has difflib:

http://python.org/doc/2.5/lib/module-difflib.html

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


[Tutor] Code optmisation

2008-04-04 Thread yogi
Hi ,
   Here is my first usable Python code.
The code works. 
Here is what I'm trying to do.
I have two huge text files. After some processing, One is 12M  (file A) and the 
other 1M (file B) .
The files have columns which are of interest to me.

I 'm trying to match entries of column [0] on file A and B
If it is true proceed to find entries (Rows in file A)  in range provided  by 
columns  [1]  [2] and  [3]  [4] in file B.
Column [1] and [3] define the lower bounds of the range
Column [3] and [4] define the  upper bounds of the range
I also have put a variation of value  so  that  I can  lookup  +/-  var. 



 #/bin/python
import sys, os, csv, re
x =  0  #Define Zero for now
var = 100   #Taking the variation 
# This programme finds the SNPs from the range passed 
# csv splits columns and this file is tab spaced
fis = csv.reader(open("divs.map", "rb"), delimiter='\t', quoting=csv.QUOTE_NONE)
for row in fis:
# csv splits columns and this file is ","  spaced
gvalues = csv.reader(open("genvalues", "rb"), delimiter=',', 
quoting=csv.QUOTE_NONE) 
for gvalue in gvalues:
# To see  Columns (chr) Match 
if row[0] == gvalue[0]:
# If  Column 3  (range) is Zero  print row
if int(gvalue[3]) ==  x:
a = int(gvalue[1]) - var
b = int(gvalue[2]) + var + 1
if int(a <= int(row[3]) <= b):
print   row
# If  Column 3  (range) is not zero find matches and print row
else:
a = int(gvalue[1]) - var
b = int(gvalue[2]) + var + 1
if int(a <= int(row[3]) <= b):
print row
c = int(gvalue[3]) - var
d = int(gvalue[4]) + var + 1
if int(c <= int(row[3]) <= d):
print   row

-

Question1 : Is there a better way ?
Question2 : For now I'm using shells time  call  for calculating time required. 
Does Python provide a more fine grained check.
Question 2: If I have convert this code into a function.
Should I ?

def parse():
...
...
...
...


parse ()


  

You rock. That's why Blockbuster's offering you one month of Blockbuster Total 
Access, No Cost.  
http://tc.deals.yahoo.com/tc/blockbuster/text5.com

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


Re: [Tutor] Question about global variables on modules

2008-04-04 Thread Anthony Baldwin
Tiago Katcipis wrote:
> I know its not such a pretty thing to have global variables but its only
> for an exercise my teacher told to do. Its a function to calculate the
> results of a matrix using jacob. I want to inside the module (inside a
> function on the module )assign a value to a global variable, but the
> only way i found to do this inside the own module function is importing
> the module inside himself. Is there another way of doing this? its kind
> odd to import the module to himself, i think  :-) 
>
> here goes the code
>   
Oi, Tiago

Não sei muito bem como funciona em Python,
sendo que já estou começando a aprender-lo, mais,
deve ter algo como o "uplevel" em Tcl, não?
Tcl's uplevel sets a variável pelo namespace global.
Ou talvez algo como
set ::var value (esse funciona em tcl
pra set a variável globalmente mas dentro de um proc)?

/tony

-- 
Anthony Baldwin

http://www.BaldwinLinguas.com 
Translation & Interpreting

http://www.TransProCalc.org 
Free translation project mgmt software 

http://www.LinguasOS.org 
Linux for Translators


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


[Tutor] Diff for Python

2008-04-04 Thread Wayne Watson
Is there a Linux diff-like command for Python code? I'd like to see the 
difference between two py files.

-- 
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

   "Philosophy is questions that may never be 
answered. Religion is answers that may never 
be questioned" -- Anon
 
Web Page: 

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


Re: [Tutor] Python Newbie: Lost in Loop

2008-04-04 Thread yogi
Hi all ,
   Thanks for the input. 
I must add Kent's solution was the fastest. The actual file
to parse is 12MB.

Though Eric's solution was more readable ( atleast for me).


Now that I have the logic and code right I have to work on
the real problem.

Thanks in advance,
yogesh





  

You rock. That's why Blockbuster's offering you one month of Blockbuster Total 
Access, No Cost.  
http://tc.deals.yahoo.com/tc/blockbuster/text5.com

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


[Tutor] Question about global variables on modules

2008-04-04 Thread Tiago Katcipis
I know its not such a pretty thing to have global variables but its only
for an exercise my teacher told to do. Its a function to calculate the
results of a matrix using jacob. I want to inside the module (inside a
function on the module )assign a value to a global variable, but the
only way i found to do this inside the own module function is importing
the module inside himself. Is there another way of doing this? its kind
odd to import the module to himself, i think  :-) 

here goes the code

<>

import lineares_jacob

*ERRO_FINAL = 0.0*

def obter_respostas(matriz, incognitas, erro_max):
  erro = erro_max * 10
  n = len(matriz)
 
  while(erro >= erro_max):
novas_incognitas = []
y_um = (2.0 + (1.0 * incognitas[1]) - (1.0 * incognitas[4999])) / 3.0
novas_incognitas.append(y_um)
   
for i in range(1 , (n - 1)):
  yi = ( (2.0 * i) + incognitas[i - 1] + incognitas[i + 1] ) / (2.0 + i)
  novas_incognitas.append(yi)
 
y_cinc_mil = (1.0 - incognitas[0] + incognitas[4998]) / 5002.0
novas_incognitas.append(y_cinc_mil)
   
maior = novas_incognitas[0] - incognitas[0]
   
for i in range(1, 5000):
  dif = novas_incognitas[i] - incognitas[i]
  if(dif > maior):
maior = dif
   
erro = maior
incognitas = novas_incognitas
 
  *lineares_jacob.ERRO_FINAL = erro*
  return incognitas

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


Re: [Tutor] Don't miss "Python-by-example - new online guide to

2008-04-04 Thread Dick Moores


At 11:26 AM 4/4/2008, Tony Cappellini wrote:
Date: Fri, 04 Apr 2008 07:12:11
-0700
From: Dick Moores
<[EMAIL PROTECTED]>
Subject: [Tutor] Don't miss "Python-by-example - new online guide
to
   Python Standard Library"
To: Python Tutor List

Message-ID:
<
[EMAIL PROTECTED]>
Dick- there was no url with your message.
Here's what I sent to the list:
=
A new one-man project, just getting started. 
<

http://www.lightbird.net/py-by-example/>
This guide aims to show examples of use of all Python Library Reference
functions, methods and classes. At this point, only the more widely used
modules were added and only functions use examples are given. Python
version 2.5 was used for examples unless noted otherwise. Example of
output of a function is shown in the form of function_call(args) #
[result]: 
    math.sqrt(9)   # 3.0


See the thread in the python-list archive:<

http://mail.python.org/pipermail/python-list/2008-April/thread.html#484484
 >


Also See Python Module Of The
Week, by Doug Hellman

http://www.doughellmann.com/projects/PyMOTW/
Thanks for this link!
Dick Moores



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


Re: [Tutor] Which Python Script Editor of Choice?

2008-04-04 Thread Jeff Younker
Jeffrey Dates wrote:
> So as I'm starting to get into writing some scripts, I'm looking for  
> recommendations for a nifty script editor.  Ideally a freeware/ 
> shareware solution until I can justify a purchase of something more  
> beefy.
>
> Currently I'm using PSPad, however it's pretty dumb and doesn't  
> recognize Python context.  Which, I suppose is fine, but would be  
> nice if there was one.  Especially since I'm learning.

I use Eclipse+PyDev plugin+commercial ($30) PyDev extensions (which
runs for free, but nags every hour or so.)   I has a feature set that  
no other
python IDE has at this point.  (Let me qualify that:  I haven't looked  
at the Iron
Python tools on windows, and they might be better, but I don't do much  
in
the windows world so I haven't looked at it yet.)

- Jeff Younker - [EMAIL PROTECTED] -

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


Re: [Tutor] Python Newbie: Lost in Loop

2008-04-04 Thread Eric Walstad
Hi Yogi, welcome to Python!

yogi wrote:
...
 > if (str(gen) == str(row[0])):
 > print 'Match for 16 found
Is the conversion to string really necessary?  Even if it is, do it once 
for gen, when you define it:
gen = '16'
so you don't have to convert on every iteration of the loop.  I think 
you want gen to be a integer, though, because you later compare it to 
other integers in your range().


...
> for row[2] in range (rval0l,rval0u):
> print row

I don't think this bit is doing what you think it is.  For each 
iteration you are assigning a value to the third element in the row list:
   row[2] = 6009890
   row[2] = 6009891
   ...
   row[2] = 6009938
etc.
I don't think you want to loop over the range but instead want to check 
to see if row[2] is between rval0l and rval0u.  You can do that by using

if x in some_list

which will return true if x is a member of the list.  range() will give 
you the list of values to check against (but only create that list once 
unless it changes on each row you are processing and in your code 
example, it's not changing).  Remember, it's easy and enlightening to 
test code on the Python command line:
 >>> rval0l = 6009890
 >>> rval0u = 6009939
 >>> range(rval0l,rval0u)
[6009890, 6009891, 6009892, 6009893, 6009894, 6009895, 6009896, 6009897, 
6009898, 6009899, 6009900, 6009901, 6009902, 6009903, 6009904, 6009905, 
6009906, 6009907, 6009908, 6009909, 6009910, 6009911, 6009912, 6009913, 
6009914, 6009915, 6009916, 6009917, 6009918, 6009919, 6009920, 6009921, 
6009922, 6009923, 6009924, 6009925, 6009926, 6009927, 6009928, 6009929, 
6009930, 6009931, 6009932, 6009933, 6009934, 6009935, 6009936, 6009937, 
6009938]
 >>> my_range = range(rval0l,rval0u)
 >>> 6009893 in my_range
True
 >>> 5 in my_range
False


gen = 16
idx_snp = 2
my_range = range(rval0l,rval0u)
for row in file:
 snp = int(row[idx_snp])
 if snp == gen:
   print 'Found %s' % gen
   if snp in my_range:
   print "Found match:", row


Eric.
PS, if your input file is as simple as your example, the csv module 
isn't getting you much benefit/complexity:

for row in open("divs.map"):
 fields = row.split('\t')
 print fields


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


Re: [Tutor] Python Newbie: Lost in Loop

2008-04-04 Thread Alan Gauld
"Kent Johnson" <[EMAIL PROTECTED]> wrote

> Aside to the list:
> Did anyone else know that you can assign to a list element 
> as the target of a for statement?

Nope, and in fact I was just trying it out at the >>> prompt 
when your message came in!

On a general point for the OP, I doubt if you need the 
csv module for this. You could generate the required data 
list using a simple string split() and a single list 
comprehension:

fis = [line.split() for line in infile]

Which might simplify things slightly.

Also it might help processing to sort the list based 
on the range value. But it depends on what other 
extractions/processing need to be done.

-- 
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


Re: [Tutor] Don't miss "Python-by-example - new online guide to

2008-04-04 Thread Tony Cappellini
 Date: Fri, 04 Apr 2008 07:12:11 -0700
From: Dick Moores <[EMAIL PROTECTED]>
Subject: [Tutor] Don't miss "Python-by-example - new online guide to
   Python Standard Library"
To: Python Tutor List 
Message-ID: <[EMAIL PROTECTED]>

Dick- there was no url with your message.

Also See Python Module Of The Week, by Doug Hellman
http://www.doughellmann.com/projects/PyMOTW/

Doug also has regular columns in Python Magazine-
http://pymag.phparch.com/
a great publication targeted mostly for beginner-intermediate level
Pythonistas
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Newbie: Lost in Loop

2008-04-04 Thread Kent Johnson
yogi wrote:
> Hi all, 
> I ´m a Python Newbie. Just 48 hrs into Python.
> I am  trying to parse a file which is tab spaced.

You're close...

> My Python code
>  #/bin/python
> import sys, csv, re
> 
> # This programme finds the SNPs from the range passed from
> the select option
> ## But first for fixed values.
> gen = 16
> rval0l = 6009890
> rval0u = 6009939
> rval1l = 0
> rval1u = 0
> types = (int, str, int, int)
> fis = csv.reader(open("divs.map", "rb"), delimiter='\t',
> quoting=csv.QUOTE_NONE) # csv splits columns and this file
> is tab spaced
> # Reading file line by line and using Regex to match the
> gene.
> for row in fis:
> #if re.search("^[1-9]\-^[1-9]\:^[1-9]\-^[1-9]", row
> [3]):
> if (str(gen) == str(row[0])):

row[0] is already a string so this could be
   if str(gen) == row[0]
or
   if gen == int(row[0])

> print 'Match for 16 found looking for SNPs
> in range between '+ str(rval0l),str(rval0u)+' '
> for row[2] in range (rval0l,rval0u):
> print row

This is confused. I think you want all the rows where row[3] (not 2) is 
between rval0l and rval0u? So just make this another condition:
   if rval0l <= int(row[3]) <= rval0u:
 print row

Aside to the list:
Did anyone else know that you can assign to a list element as the target 
of a for statement?

In [6]: row=range(3)
In [8]: for row[2] in range(5):
 print row
...:
...:
[0, 1, 0]
[0, 1, 1]
[0, 1, 2]
[0, 1, 3]
[0, 1, 4]

Color me surprised.

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


[Tutor] Python Newbie: Lost in Loop

2008-04-04 Thread yogi
Hi all, 
I ´m a Python Newbie. Just 48 hrs into Python.
I am  trying to parse a file which is tab spaced.

head -5 of the file in question.

1   rs3094315   0   792429
1   rs6672353   0   817376
1   rs4040617   0   819185
1   rs2980300   0   825852
1   rs2905036   0   832343
1   rs4245756   0   839326
1   rs4075116   0   1043552
1   rs9442385   0   1137258
1   rs10907175  0   1170650
1   rs2887286   0   1196054

column[0] increments [1-22].
column [1] has values I´m interested in 
columns [2] Its a Zero
column [3] has values which I pass for range boundary.

My Python code
 #/bin/python
import sys, csv, re

# This programme finds the SNPs from the range passed from
the select option
## But first for fixed values.
gen = 16
rval0l = 6009890
rval0u = 6009939
rval1l = 0
rval1u = 0
types = (int, str, int, int)
fis = csv.reader(open("divs.map", "rb"), delimiter='\t',
quoting=csv.QUOTE_NONE) # csv splits columns and this file
is tab spaced
# Reading file line by line and using Regex to match the
gene.
for row in fis:
#if re.search("^[1-9]\-^[1-9]\:^[1-9]\-^[1-9]", row
[3]):
if (str(gen) == str(row[0])):
print 'Match for 16 found looking for SNPs
in range between '+ str(rval0l),str(rval0u)+' '
for row[2] in range (rval0l,rval0u):
print row

My Python code is not behaving as I want it to be.
When I pass the range values . 
The Code should parse the file.
Match the value of Col3. 
look for values in col(3) within the range limit (Which it
does)

print rows Matching the criteria.(which it does not).
It prints rows which are not even the file.

Can somebody point me in the right direction.

Thanks in advance
yogesh




  

You rock. That's why Blockbuster's offering you one month of Blockbuster Total 
Access, No Cost.  
http://tc.deals.yahoo.com/tc/blockbuster/text5.com

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


Re: [Tutor] Don't miss "Python-by-example - new online guide to

2008-04-04 Thread Julia
>
> Message: 4
> Date: Fri, 04 Apr 2008 07:12:11 -0700
> From: Dick Moores <[EMAIL PROTECTED]>
> Subject: [Tutor] Don't miss "Python-by-example - new online guide to
>Python Standard Library"
> To: Python Tutor List 
> Message-ID: <[EMAIL PROTECTED]>
> Content-Type: text/plain; charset="us-ascii"
>
> An HTML attachment was scrubbed...
> URL:
> http://mail.python.org/pipermail/tutor/attachments/20080404/8e49a5e0/attachment-0001.htm


I really appreciate guides that cut to the core directly. Great work Moores
:)
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Interactive physics simulation over web

2008-04-04 Thread Kent Johnson
Adam Bark wrote:

> I think you can use Jython in a Java applet, that might be what you're 
> looking for.

Yes, but it does increase the size of the download considerably since 
jython.jar is needed by the browser.

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


Re: [Tutor] Interactive physics simulation over web

2008-04-04 Thread Kent Johnson
Brain Stormer wrote:
> I am working on a physics simulation and would like to publish it on the 
> web.  The simulation requires input fields, mouse action (picking points 
> in a display pane) and movie like feature with play, pause, skip forward 
> and skip backward.  I was wondering if this can be done using Python and 
> a Python web tool kit like Django.  I can see that this can be done 
> using Java/Java Script but don't feel like re-familiarizing myself to 
> Java.  I looked into the Python web programming page 
>  but it didn't answer my 
> questions.  My goal is keep this simulation completely written in Python.

You can use Python and Django for the server-side of this but for the 
client side you probably want to look at JavaScript and / or Flash.

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


Re: [Tutor] Don't miss "Python-by-example - new online guide to Python Standard Library"

2008-04-04 Thread Tim Golden
linuxian iandsd wrote:
> well, good to see something like this comming ... i used to browse for hours
> to find nothing but long long documentation & not a single real life
> example... but i guess its because i m used to the old  'howto'  way of
> ducumentation ...

It's one of those things; people learn in different ways. Some people
prefer dry reference guides; others like the cookbook approach (I do
myself). Still others want a complete worked example. And so on.

For me, documentation in its many forms is a *vital* part of any
software project, especially Open Source stuff. The more people
who put together coherent examples, articles, hints, tips etc.,
the better for the rest of the community.

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


Re: [Tutor] Interactive physics simulation over web

2008-04-04 Thread Adam Bark
On 04/04/2008, Brain Stormer <[EMAIL PROTECTED]> wrote:
>
> I am working on a physics simulation and would like to publish it on the
> web.  The simulation requires input fields, mouse action (picking points in
> a display pane) and movie like feature with play, pause, skip forward and
> skip backward.  I was wondering if this can be done using Python and a
> Python web tool kit like Django.  I can see that this can be done using
> Java/Java Script but don't feel like re-familiarizing myself to Java.  I
> looked into the Python web programming 
> pagebut it didn't answer my 
> questions.  My goal is keep this simulation
> completely written in Python.


I think you can use Jython in a Java applet, that might be what you're
looking for.
HTH,
Adam.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Don't miss "Python-by-example - new online guide to Python Standard Library"

2008-04-04 Thread linuxian iandsd
well, good to see something like this comming ... i used to browse for hours
to find nothing but long long documentation & not a single real life
example... but i guess its because i m used to the old  'howto'  way of
ducumentation ...


On Fri, Apr 4, 2008 at 2:12 PM, Dick Moores <[EMAIL PROTECTED]> wrote:

>  A new one-man project, just getting started.
> < http://www.lightbird.net/py-by-example/>
>
> This guide aims to show examples of use of all Python Library Reference
> functions, methods and classes. At this point, only the more widely used
> modules were added and only functions use examples are given. Python version
> 2.5 was used for examples unless noted otherwise. Example of output of a
> function is shown in the form of function_call(args) # [result]:
>
> math.sqrt(9)   # 3.0
>
>
> See the thread in the python-list 
> archive:
>
> Dick Moores
>
> ___
> 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] Interactive physics simulation over web

2008-04-04 Thread Brain Stormer
I am working on a physics simulation and would like to publish it on the
web.  The simulation requires input fields, mouse action (picking points in
a display pane) and movie like feature with play, pause, skip forward and
skip backward.  I was wondering if this can be done using Python and a
Python web tool kit like Django.  I can see that this can be done using
Java/Java Script but don't feel like re-familiarizing myself to Java.  I
looked into the Python web programming
pagebut it didn't answer
my questions.  My goal is keep this simulation
completely written in Python.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Don't miss "Python-by-example - new online guide to Python Standard Library"

2008-04-04 Thread Dick Moores


A new one-man project, just getting started. 
<
http://www.lightbird.net/py-by-example/>
This guide aims to show examples of use of all Python Library Reference
functions, methods and classes. At this point, only the more widely used
modules were added and only functions use examples are given. Python
version 2.5 was used for examples unless noted otherwise. Example of
output of a function is shown in the form of function_call(args) #
[result]: 
    math.sqrt(9)   # 3.0

See the thread in the python-list
archive:<
http://mail.python.org/pipermail/python-list/2008-April/thread.html#484484
>
Dick Moores


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


[Tutor] Fwd: Unittest traceback

2008-04-04 Thread Oleg Oltar
-- Forwarded message --
From: Oleg Oltar <[EMAIL PROTECTED]>
Date: Fri, Apr 4, 2008 at 2:49 PM
Subject: Re: [Tutor] Unittest traceback
To: Kent Johnson <[EMAIL PROTECTED]>


Yes! Tried in command line. works fine there. Not sure howto customize my
IDE correctly. I use Emacs.

Thanks,
Oleg


On Fri, Apr 4, 2008 at 2:36 PM, Kent Johnson <[EMAIL PROTECTED]> wrote:

> Oleg Oltar wrote:
>
> > Hi!
> > I am trying to use unittest in python first time. But have a strange
> > traceback each time I run my sample tests.
> >
>
> How are you running the test? My guess is that you are running it in an
> IDE or something that shows the normal system exit exception.
>
> Calling sys.exit() raises the SystemExit exception with a result code.
> Normally this is not shown by the runner.
>
> In Python False == 0 so your program is exiting normally with a code of 0
> (no error). It is probably the program runner that is showing the traceback.
>
> Try running the program from the command line.
>
> Kent
>
>
>  Can you please explain why I have it. No info about it in the doc. e.g.
> > the code is
> >
> > import unittest
> > import squaren
> >
> > class TestCases(unittest.TestCase):
> >def setUp(self):
> >pass
> >
> >def testsmall(self):
> >self.assertEqual(True, True)
> >
> >
> >
> > if __name__ == '__main__':
> >unittest.main()
> >
> > And the traceback is
> > --
> > Ran 1 test in 0.000s
> >
> > OK
> > Traceback (most recent call last):
> >  File "/tmp/py359hJx", line 14, in 
> >unittest.main()
> >  File "/opt/local/lib/python2.5/unittest.py", line 768, in __init__
> >self.runTests()
> >  File "/opt/local/lib/python2.5/unittest.py", line 806, in runTests
> >sys.exit(not result.wasSuccessful())
> > SystemExit: False
> >
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Unittest traceback

2008-04-04 Thread Kent Johnson
Oleg Oltar wrote:
> Hi! 
> 
> I am trying to use unittest in python first time. But have a strange 
> traceback each time I run my sample tests.

How are you running the test? My guess is that you are running it in an 
IDE or something that shows the normal system exit exception.

Calling sys.exit() raises the SystemExit exception with a result code. 
Normally this is not shown by the runner.

In Python False == 0 so your program is exiting normally with a code of 
0 (no error). It is probably the program runner that is showing the 
traceback.

Try running the program from the command line.

Kent

> Can you please explain why I have it. No info about it in the doc. 
> e.g. the code is
> 
> import unittest
> import squaren
> 
> class TestCases(unittest.TestCase):
> def setUp(self):
> pass
> 
> def testsmall(self):
> self.assertEqual(True, True)
> 
> 
> 
> if __name__ == '__main__':
> unittest.main()
> 
> And the traceback is 
> 
> --
> Ran 1 test in 0.000s
> 
> OK
> Traceback (most recent call last):
>   File "/tmp/py359hJx", line 14, in 
> unittest.main()
>   File "/opt/local/lib/python2.5/unittest.py", line 768, in __init__
> self.runTests()
>   File "/opt/local/lib/python2.5/unittest.py", line 806, in runTests
> sys.exit(not result.wasSuccessful())
> SystemExit: False
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Unittest traceback

2008-04-04 Thread Oleg Oltar
Hi!
I am trying to use unittest in python first time. But have a strange
traceback each time I run my sample tests.
Can you please explain why I have it. No info about it in the doc.
e.g. the code is

import unittest
import squaren

class TestCases(unittest.TestCase):
def setUp(self):
pass

def testsmall(self):
self.assertEqual(True, True)



if __name__ == '__main__':
unittest.main()

And the traceback is

--
Ran 1 test in 0.000s

OK
Traceback (most recent call last):
  File "/tmp/py359hJx", line 14, in 
unittest.main()
  File "/opt/local/lib/python2.5/unittest.py", line 768, in __init__
self.runTests()
  File "/opt/local/lib/python2.5/unittest.py", line 806, in runTests
sys.exit(not result.wasSuccessful())
SystemExit: False
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor