Re: How to test if a file is a symbolic link?

2009-10-28 Thread tec
On 2009-10-29 11:19, Peng Yu wrote: 'symbolic_link' is a symbolic link in the current directory. I run 'python main.py', but it does not return me anything. I want to check if a file is a symbolic link. I'm wondering what is the correct way to do so? $cat main.py import stat import os st =

Re: How to test if a file is a symbolic link?

2009-10-28 Thread Steven D'Aprano
On Wed, 28 Oct 2009 22:19:55 -0500, Peng Yu wrote: 'symbolic_link' is a symbolic link in the current directory. I run 'python main.py', but it does not return me anything. I want to check if a file is a symbolic link. I'm wondering what is the correct way to do so? $cat main.py import

Re: How to test if a file is a symbolic link?

2009-10-28 Thread ma
import os if os.path.islink('symbolic_link'): print hello. Cheers, Mahmoud Abdelkader On Oct 28, 2009, at 11:19 PM, Peng Yu pengyu...@gmail.com wrote: 'symbolic_link' is a symbolic link in the current directory. I run 'python main.py', but it does not return me anything. I want to check

Re: How to test if a file is a symbolic link?

2009-10-28 Thread Ben Finney
Peng Yu pengyu...@gmail.com writes: 'symbolic_link' is a symbolic link in the current directory. I run 'python main.py', but it does not return me anything. I want to check if a file is a symbolic link. You have the same access to the Python help as we do: import os.path

Re: How to test python snippets in my documents?

2009-05-26 Thread Lie Ryan
Matthew Wilson wrote: I'm using a homemade script to verify some code samples in my documentation. Here it is: #! /usr/bin/env python2.6 # vim: set expandtab ts=4 sw=4 filetype=python: import doctest, os, sys def main(s): Run doctest.testfile(s, None) return

Re: How to test python snippets in my documents?

2009-05-26 Thread Ned Deily
In article zjtsl.34029$zp4.2...@nlpi067.nbdc.sbc.com, Matthew Wilson m...@tplus1.com wrote: I'm using a homemade script to verify some code samples in my documentation. [...] The script checks all the files listed as arguments. This is OK, but is there anything better? Perhaps a

Re: How to test if a key in a dictionary exists?

2007-03-12 Thread Larry Bates
Frank wrote: Hi, does anyone know how one can test if, e.g., a dictionary 'name' has a key called 'name_key'? This would be possible: keys_of_names = names.keys() L = len(keys_of_names) for i in range(L): if keys_of_names[i] == name_key: print 'found' But certainly not

Re: How to test if a key in a dictionary exists?

2007-03-12 Thread [EMAIL PROTECTED]
On Mar 11, 11:49 pm, John Machin [EMAIL PROTECTED] wrote: On Mar 12, 3:19 pm, [EMAIL PROTECTED] (Alex Martelli) wrote: Paul McGuire [EMAIL PROTECTED] wrote: will be. For instance, when working with data from 0 to 100 and looking for frequencies by decade, you can initialize the

Re: How to test if a key in a dictionary exists?

2007-03-11 Thread Paul McGuire
On Mar 10, 9:12 pm, Paul Rubin http://[EMAIL PROTECTED] wrote: if hist.has_key(outcome): hist[outcome] += 1 # if key already exists, increment else: hist[outcome] = 1 # else create a new key You could write that: hist[outcome] = 1 + hist.get(outcome, 0) Or with Python

Re: How to test if a key in a dictionary exists?

2007-03-11 Thread Alex Martelli
Paul McGuire [EMAIL PROTECTED] wrote: will be. For instance, when working with data from 0 to 100 and looking for frequencies by decade, you can initialize the histogram- dict with: for i in range(10): histodict[i] = 0 A better way, of course (also saving the histodict = {} which you

Re: How to test if a key in a dictionary exists?

2007-03-11 Thread John Machin
On Mar 12, 3:19 pm, [EMAIL PROTECTED] (Alex Martelli) wrote: Paul McGuire [EMAIL PROTECTED] wrote: will be. For instance, when working with data from 0 to 100 and looking for frequencies by decade, you can initialize the histogram- dict with: for i in range(10): histodict[i] = 0

Re: How to test if a key in a dictionary exists?

2007-03-10 Thread Irmen de Jong
Frank wrote: Hi, does anyone know how one can test if, e.g., a dictionary 'name' has a key called 'name_key'? name_key in name e.g. name={john: 42} john in name True julie in name False --Irmen -- http://mail.python.org/mailman/listinfo/python-list

Re: How to test if a key in a dictionary exists?

2007-03-10 Thread Rune Strand
Yes, you have name.has_key(name_key) and perhaps better, the in operator: if name_key in name: do something -- http://mail.python.org/mailman/listinfo/python-list

Re: How to test if a key in a dictionary exists?

2007-03-10 Thread Jeff McNeil
Sure, you can use if key in dict to test for membership: Python 2.3.5 (#1, Jan 13 2006, 20:13:11) [GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin Type help, copyright, credits or license for more information. exampledict = {a : 1, b : 2} a in exampledict True q in exampledict False

Re: How to test if a key in a dictionary exists?

2007-03-10 Thread Bjoern Schliessmann
Frank wrote: does anyone know how one can test if, e.g., a dictionary 'name' has a key called 'name_key'? Yes. It's already posted; next time have a look at the concise library reference: http://docs.python.org/lib/typesmapping.html This would be possible: keys_of_names = names.keys()

Re: How to test if a key in a dictionary exists?

2007-03-10 Thread [EMAIL PROTECTED]
On Mar 10, 3:17?pm, Frank [EMAIL PROTECTED] wrote: Hi, does anyone know how one can test if, e.g., a dictionary 'name' has a key called 'name_key'? This would be possible: keys_of_names = names.keys() L = len(keys_of_names) for i in range(L): if keys_of_names[i] == name_key: print

Re: How to test if a key in a dictionary exists?

2007-03-10 Thread Paul Rubin
if hist.has_key(outcome): hist[outcome] += 1 # if key already exists, increment else: hist[outcome] = 1 # else create a new key You could write that: hist[outcome] = 1 + hist.get(outcome, 0) Or with Python 2.5 you could use hist = defaultdict(int) ... hist[outcome]

Re: How to test whether a host is reachable?

2007-02-22 Thread Chris Mellon
On 2/22/07, Fabian Steiner [EMAIL PROTECTED] wrote: Hello! As the subject says I need to test whether a host computer in our network is reachable or not. At the moment I simply attempt to connect to a given port that is open when the machine is online: [...] sock =

Re: How to test whether a host is reachable?

2007-02-22 Thread Larry Bates
Fabian Steiner wrote: Hello! As the subject says I need to test whether a host computer in our network is reachable or not. At the moment I simply attempt to connect to a given port that is open when the machine is online: [...] sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

Re: How to test whether a host is reachable?

2007-02-22 Thread Diez B. Roggisch
Just because you could ping with ICMP packets doesn't mean you could do anything with the machine. I assume that you are connecting to do something on the machine. Just wrap what you are trying to do in try: block. It will either succeed or fail. Handle the exeption. And the other way

Re: How to test whether a host is reachable?

2007-02-22 Thread Fabian Steiner
Hello! Chris Mellon wrote: On 2/22/07, Fabian Steiner [EMAIL PROTECTED] wrote: [...] Now I am wondering if there isn't any better method which would be more general. In fact, I think of something like a python version of ping which only tries to send ICMP packets. However, I don't know what

Re: How to test whether a host is reachable?

2007-02-22 Thread Bart Ogryczak
On Feb 22, 3:22 pm, Fabian Steiner [EMAIL PROTECTED] wrote: Now I am wondering if there isn't any better method which would be more general. In fact, I think of something like a python version of ping which only tries to send ICMP packets. Server or a firewall in between most probably will

Re: How to test if one dict is subset of another?

2007-02-20 Thread Paul Rubin
Jay Tee [EMAIL PROTECTED] writes: for j in jobs: if (j.get('user') == 'jeff' and j.get('state')=='running') : do_something() Sounds like you need some backing data structures, like indexes in a database, e.g. (untested, uses the cool new defaultdicts of 2.5): index =

Re: How to test if one dict is subset of another?

2007-02-20 Thread Jay Tee
On Feb 20, 9:12 am, Paul Rubin http://[EMAIL PROTECTED] wrote: do_something() you'd just write: for j in (index['user']['jeff'] index['state']['running']): do_something() Hi, it looks very cool, except that one of the constraints mentioned is that the solution has to

Re: How to test if one dict is subset of another?

2007-02-20 Thread Paul Rubin
Jay Tee [EMAIL PROTECTED] writes: it looks very cool, except that one of the constraints mentioned is that the solution has to work properly on pythons 2.2 and 2.3. That thing doesn't really deeply depend on defaultdict, it's just convenient. You can add a few more lines of code in the

Re: How to test if one dict is subset of another?

2007-02-20 Thread Jay Tee
Hi your post had the following construct: for j in (index['user']['jeff'] index['state']['running']): do_something() but Python 2.3.4 (#1, Oct 11 2006, 06:18:43) [GCC 3.4.6 20060404 (Red Hat 3.4.6-3)] on linux2 Type help, copyright, credits or license for more information. l1=

Re: How to test if one dict is subset of another?

2007-02-20 Thread Paul Rubin
Jay Tee [EMAIL PROTECTED] writes: l1= [3, 4, 7, 2] l2 = [2, 3] l2 = [2, 3, 99] l1 l2 Traceback (most recent call last): File stdin, line 1, in ? TypeError: unsupported operand type(s) for : 'list' and 'list' what am I missing? They are sets, not lists. from sets import Set as

Re: How to test if one dict is subset of another?

2007-02-20 Thread Jay Tee
On Feb 20, 6:44 pm, Paul Rubin http://[EMAIL PROTECTED] wrote: They are sets, not lists. from sets import Set as set # use in 2.3 and earlier l1= set([3, 4, 7, 2]) l2 = set([2, 3]) l2 = set([2, 3, 99]) print l1 l2 Thanks Paul, but: bosui:~ python Python 2.2.3 (#1, Oct 26

Re: How to test if one dict is subset of another?

2007-02-20 Thread Paul Rubin
Jay Tee [EMAIL PROTECTED] writes: Python 2.2.3 (#1, Oct 26 2003, 11:49:53) ImportError: No module named sets Hmm, well I think the sets module in 2.3 is written in Python, so you could drop it into your application for use in 2.2. Better would be to use the C version from 2.4 if you can. Or

Re: How to test if one dict is subset of another?

2007-02-20 Thread Jay Tee
Hi, thanks! the code lift from 2.3 to 2.2 worked (thank Guido et al for BACKWARDS COMPATIBILITY ;-)) ... unfortunately I was in a hurry to get the release out since a colleague's cluster was croaking under the load of the old, non-indexed version. Your solution is nicer looking than mine, and

Re: How to test if one dict is subset of another?

2007-02-19 Thread Diez B. Roggisch
Jay Tee schrieb: Hi, I have some code that does, essentially, the following: - gather information on tens of thousands of items (in this case, jobs running on a compute cluster) - store the information as a list (one per job) of Job items (essentially wrapped dictionaries

Re: How to test if one dict is subset of another?

2007-02-19 Thread Peter Otten
Jay Tee wrote: Hi, I have some code that does, essentially, the following: - gather information on tens of thousands of items (in this case, jobs running on a compute cluster) - store the information as a list (one per job) of Job items (essentially wrapped dictionaries

Re: How to test if one dict is subset of another?

2007-02-19 Thread Jay Tee
On Feb 19, 11:07 am, Peter Otten [EMAIL PROTECTED] wrote: Use a RDBMS (a database), they tend to be good at this kind of operations. yeah, one of the options is metakit ... sqlite and buzhug both looked promising but the constraint of pythons 2.2 and 2.3 ruled that out. disadvantage of metakit

Re: How to test if one dict is subset of another?

2007-02-19 Thread Peter Otten
Jay Tee wrote: On Feb 19, 11:07 am, Peter Otten [EMAIL PROTECTED] wrote: Use a RDBMS (a database), they tend to be good at this kind of operations. yeah, one of the options is metakit ... sqlite and buzhug both looked promising but the constraint of pythons 2.2 and 2.3 ruled that out.

Re: How to test if one dict is subset of another?

2007-02-19 Thread Hendrik van Rooyen
Jay Tee [EMAIL PROTECTED] wrote: Hi, I have some code that does, essentially, the following: - gather information on tens of thousands of items (in this case, jobs running on a compute cluster) - store the information as a list (one per job) of Job items (essentially wrapped

Re: How to test if two strings point to the same file or directory?

2006-12-17 Thread Tim Golden
Sandra-24 wrote: Comparing file system paths as strings is very brittle. Is there a better way to test if two paths point to the same file or directory (and that will work across platforms?) I suspect that the and that will work across platforms parenthesis is in effect a killer. However, if

Re: How to test if two strings point to the same file or directory?

2006-12-17 Thread Tim Chase
The current setup will not silently fail when run on win32. How could it? It doesn't exist; it can't be run. Ah...didn't know which it did (or didn't do) as I don't have a win32 box at hand on which to test it. In chasing the matter further, the OP mentioned that their particular problem was

Re: How to test if two strings point to the same file or directory?

2006-12-17 Thread Sandra-24
It looks like you can get a fairly good apporximation for samefile on win32. Currently I'm using the algorithm suggested by Tim Chase as it is good enough for my needs. But if one wanted to add samefile to the ntpath module, here's the algorithm I would suggest: If the passed files do not exist,

Re: How to test if two strings point to the same file or directory?

2006-12-16 Thread Tim Chase
Comparing file system paths as strings is very brittle. Is there a better way to test if two paths point to the same file or directory (and that will work across platforms?) os.path.samefile(filename1, filename2) os.path.sameopenfile(fileobject1, fileobject2) -tkc --

Re: How to test if two strings point to the same file or directory?

2006-12-16 Thread Steven D'Aprano
On Sat, 16 Dec 2006 17:02:04 -0800, Sandra-24 wrote: Comparing file system paths as strings is very brittle. Why do you say that? Are you thinking of something like this? /home//user/somedirectory/../file /home/user/file Both point to the same file. Is there a better way to test if two

Re: How to test if two strings point to the same file or directory?

2006-12-16 Thread John Machin
Tim Chase wrote: Comparing file system paths as strings is very brittle. Is there a better way to test if two paths point to the same file or directory (and that will work across platforms?) os.path.samefile(filename1, filename2) os.path.sameopenfile(fileobject1, fileobject2)

Re: How to test if two strings point to the same file or directory?

2006-12-16 Thread Tim Chase
Comparing file system paths as strings is very brittle. Why do you say that? Are you thinking of something like this? /home//user/somedirectory/../file /home/user/file Or even ~/file How complicated do you want to get? If you are thinking about aliases, hard links, shortcuts,

Re: How to test if two strings point to the same file or directory?

2006-12-16 Thread Steven D'Aprano
On Sun, 17 Dec 2006 12:30:15 +1100, Steven D'Aprano wrote: Is there a better way to test if two paths point to the same file or directory (and that will work across platforms?) How complicated do you want to get? If you are thinking about aliases, hard links, shortcuts, SMB shares and

Re: How to test if two strings point to the same file or directory?

2006-12-16 Thread Tim Chase
Comparing file system paths as strings is very brittle. Is there a better way to test if two paths point to the same file or directory (and that will work across platforms?) os.path.samefile(filename1, filename2) os.path.sameopenfile(fileobject1, fileobject2) Nice try, but they

Re: How to test if two strings point to the same file or directory?

2006-12-16 Thread John Machin
Tim Chase wrote: [snip] I'd suggest os.path.samefile which should handle case-sensitive (non-win32) vs case-insensitive (win32) filenames, soft-links, and hard-links. Not sure it's prescient enough to know if you have two remote shares, it will unwind them to their full server-path name.

Re: How to test if two strings point to the same file or directory?

2006-12-16 Thread Sandra-24
On Dec 16, 8:30 pm, Steven D'Aprano [EMAIL PROTECTED] wrote: On Sat, 16 Dec 2006 17:02:04 -0800, Sandra-24 wrote: Comparing file system paths as strings is very brittle.Why do you say that? Are you thinking of something like this? /home//user/somedirectory/../file /home/user/file Both

Re: How to test if two strings point to the same file or directory?

2006-12-16 Thread John Machin
Tim Chase wrote: Comparing file system paths as strings is very brittle. Is there a better way to test if two paths point to the same file or directory (and that will work across platforms?) os.path.samefile(filename1, filename2) os.path.sameopenfile(fileobject1, fileobject2)

Re: How to test if two strings point to the same file or directory?

2006-12-16 Thread Leif K-Brooks
Tim Chase wrote: Comparing file system paths as strings is very brittle. Why do you say that? Are you thinking of something like this? /home//user/somedirectory/../file /home/user/file Or even ~/file ~ is interpreted as my home directory by the shell, but when it's used in a

Re: How to test if two strings point to the same file or directory?

2006-12-16 Thread Erik Max Francis
Leif K-Brooks wrote: ~ is interpreted as my home directory by the shell, but when it's used in a path, it has no special meaning. open('~/foo.txt') tries to open a file called foo.txt in a subdirectory of the current directory called '~'. That's what os.path.expanduser is for. -- Erik Max

Re: How to test if two strings point to the same file or directory?

2006-12-16 Thread John Nagle
Sandra-24 wrote: Comparing file system paths as strings is very brittle. Is there a better way to test if two paths point to the same file or directory (and that will work across platforms?) No. There are ways to do it for many operating systems, but there is no system-independent

Re: How to test python extension modules during 'make check' / 'make distcheck'?

2006-11-02 Thread Leo Kislov
Mark Asbach wrote: Hi pythonians, I'm one of the maintainers of an open source image processing toolkit (OpenCV) and responsible for parts of the autotools setup. The package mainly consists of four shared libraries but is accompanied by a python package containing some pure python code and

Re: How to test if object is sequence, or iterable?

2006-07-22 Thread Bruno Desthuilliers
Tim N. van der Leeuw a écrit : Hi, I'd like to know if there's a way to check if an object is a sequence, or an iterable. Something like issequence() or isiterable(). Does something like that exist? (Something which, in case of iterable, doesn't consume the first element of the iterable)

Re: How to test if object is sequence, or iterable?

2006-07-22 Thread Tim N. van der Leeuw
Bruno Desthuilliers wrote: Tim N. van der Leeuw a écrit : Hi, I'd like to know if there's a way to check if an object is a sequence, or an iterable. Something like issequence() or isiterable(). Does something like that exist? (Something which, in case of iterable, doesn't consume

Re: How to test if object is sequence, or iterable?

2006-07-22 Thread Terry Reedy
Tim N. van der Leeuw [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi, I'd like to know if there's a way to check if an object is a sequence, or an iterable. Something like issequence() or isiterable(). How about try: it = iter(possible_iterable) except TypeError: bail() Terry

Re: How to test if object is sequence, or iterable?

2006-07-22 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], Bruno Desthuilliers wrote: Tim N. van der Leeuw a écrit : Hi, I'd like to know if there's a way to check if an object is a sequence, or an iterable. Something like issequence() or isiterable(). Does something like that exist? (Something which, in case of iterable,

Re: How to test if object is sequence, or iterable?

2006-07-22 Thread Bruno Desthuilliers
Marc 'BlackJack' Rintsch a écrit : In [EMAIL PROTECTED], Bruno Desthuilliers wrote: Tim N. van der Leeuw a écrit : Hi, I'd like to know if there's a way to check if an object is a sequence, or an iterable. Something like issequence() or isiterable(). Does something like that exist?

Re: How to test if object is sequence, or iterable?

2006-07-22 Thread Nick Vatamaniuc
Tim, An object is iterable if it implements the iterator protocol. A good enough check to see if it does is to check for the presense of the __iter__() method. The way to do it is: hasattr(object,'__iter__') You are correct in the fact that you check if an object is iterable rather than using

Re: How to test if object is sequence, or iterable?

2006-07-22 Thread Terry Reedy
Nick Vatamaniuc [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Tim, An object is iterable if it implements the iterator protocol There are presently two iterator protocols. The old one will be likely be dropped in 3.0 (currently being discussed). . A good enough check to see

Re: How to test wxPython by unittest

2006-03-24 Thread Frank Niessink
sillyemperor: I was a new guy of Python,when i want to test my wxPython app by unittest,it couldn`t work.I fund a stubmaker.py but it only for wxDialog but all widgets.Can someone can tell me how test wxPython by unittest?Thanks Here's a small example to get you started: import unittest,

Re: how to test for a dependency

2006-01-09 Thread Dennis Benzinger
Darren Dale schrieb: Hello, I would like to test that latex is installed on a windows, mac or linux machine. What is the best way to do this? This should work: if os.system('latex -v'): print 'please install latex' but I dont actually want the latex version information to print to

Re: how to test for a dependency

2006-01-09 Thread Sybren Stuvel
Darren Dale enlightened us with: I would like to test that latex is installed on a windows, mac or linux machine. What is the best way to do this? This should work: if os.system('latex -v'): print 'please install latex' The downside is that you can only use this to test by executing.

Re: how to test for a dependency

2006-01-09 Thread Darren Dale
Dennis Benzinger wrote: Darren Dale schrieb: Hello, I would like to test that latex is installed on a windows, mac or linux machine. What is the best way to do this? This should work: if os.system('latex -v'): print 'please install latex' but I dont actually want the latex

Re: how to test for a dependency

2006-01-09 Thread Darren Dale
Sybren Stuvel wrote: Darren Dale enlightened us with: I would like to test that latex is installed on a windows, mac or linux machine. What is the best way to do this? This should work: if os.system('latex -v'): print 'please install latex' The downside is that you can only use this

Re: how to test for a dependency

2006-01-09 Thread Steven Bethard
Darren Dale wrote: I would like to test that latex is installed on a windows, mac or linux machine. What is the best way to do this? This should work: if os.system('latex -v'): print 'please install latex' but I dont actually want the latex version information to print to screen. I

Re: How to test if an object IS another object?

2005-06-13 Thread bruno modulix
[EMAIL PROTECTED] wrote: Tuples (which are immutable) also appear to be reused foo = () bar = () foo is bar True Not always: foo = (1,) bar = (1,) foo is bar = False -- bruno desthuilliers python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL

Re: How to test if an object IS another object?

2005-06-12 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : If two objects are of equal value you can compare them with ==. What I want to do is find out if two objects are actually just references to the same object, how can I do this in Python? The most obvious way (as usual ?): if obj1 is obj2: // your code here --

Re: How to test if an object IS another object?

2005-06-12 Thread eloff777
Sorry about removing my message, I posted with the wrong google account, I don't really want my email where those irritating spam bots can find it. The most obvious way (as usual ?): if obj1 is obj2: // your code here I immediately thought of is, and tested it in the console, but it didn't

Re: How to test if an object IS another object?

2005-06-12 Thread Paul Rubin
[EMAIL PROTECTED] writes: foo = 3 bar = 3 clearly foo and bar have the same value but they are different objects aren't they? No, they're the same object. Now try it with 300 instead of 3 ;-). -- http://mail.python.org/mailman/listinfo/python-list

Re: How to test if an object IS another object?

2005-06-12 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : Sorry about removing my message, I posted with the wrong google account, I don't really want my email where those irritating spam bots can find it. The most obvious way (as usual ?): if obj1 is obj2: // your code here I immediately thought of is, and

Re: How to test if an object IS another object?

2005-06-12 Thread eloff777
Fascinating. With small strings, it uses the same object, and with small numbers like 3. With 300 they were different objects (why, shouldn't they both be ints still?) Mutable objects functioned differently as you suggested: foo = [] bar = [] foo == bar True foo is bar False Tuples (which are

Re: How to test if an object IS another object?

2005-06-12 Thread Grant Edwards
On 2005-06-12, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: The most obvious way (as usual ?): if obj1 is obj2: // your code here I immediately thought of is, and tested it in the console, but it didn't work quite like I expected: foo = 3 bar = 3 zoo = foo foo is zoo True foo is bar True

Re: How to test if an object IS another object?

2005-06-12 Thread Grant Edwards
On 2005-06-12, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Fascinating. With small strings, it uses the same object, and with small numbers like 3. With 300 they were different objects (why, It's purely an implimentation detail. The small integers get used a lot, so Python keeps a pre-created

Re: How to test if an object IS another object?

2005-06-12 Thread Roose
This isn't a good example to test with, since 3 is an immutable object, as is 300 and all ints. It's more meaningful if the objects are mutable. Why do you want to test identity in the first place? Roose [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Sorry about removing my

Re: How to test that an exception is raised ?

2005-01-31 Thread Antoon Pardon
Op 2005-01-28, StepH schreef [EMAIL PROTECTED]: Antoon Pardon a écrit : Op 2005-01-28, StepH schreef [EMAIL PROTECTED]: Thanks for you answer. I'm new to Python (coming from C/C++). Do you say that it's not possible to test (using unittest) if an exception is well raised if the tested code

Re: How to test that an exception is raised ?

2005-01-28 Thread Ishwor
[snipped alot of codes that doesn't mean much ] if you want to check for exception then it goes like this try: put your code here which fails on certain exception like maybe IOError catch IOError: put a code to do something when IOError is raised sorry i won't bother to read your code because

Re: How to test that an exception is raised ?

2005-01-28 Thread Dan Perl
StepH [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] But i've prob with the 1st test : test_badFile. When I run the test, unittest say that no error is Raised. But when I run the mps2xml module with a bad file as arg., the exception is well Raised. I assume you don't actually

Re: How to test that an exception is raised ?

2005-01-28 Thread StepH
Thanks for you answer. I'm new to Python (coming from C/C++). But i've prob with the 1st test : test_badFile. When I run the test, unittest say that no error is Raised. But when I run the mps2xml module with a bad file as arg., the exception is well Raised. I assume you don't actually

Re: How to test that an exception is raised ?

2005-01-28 Thread Dan Perl
StepH [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Do you say that it's not possible to test (using unittest) if an exception is well raised if the tested code catch it ? How to solve this paradoxe ? How to automaticaly test such code ? Then you need a side-effect in catching

Re: How to test that an exception is raised ?

2005-01-28 Thread StepH
Antoon Pardon a écrit : Op 2005-01-28, StepH schreef [EMAIL PROTECTED]: Thanks for you answer. I'm new to Python (coming from C/C++). Do you say that it's not possible to test (using unittest) if an exception is well raised if the tested code catch it ? How to solve this paradoxe ? How to

Re: How to test that an exception is raised ?

2005-01-28 Thread Dan Perl
StepH [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] So why the assertRaises function in unittest ? My goal is to test if an exception is well raised when a bad filename is passed to the mps2xml function. It is for functions in which the exception is raised and not caught. You

<    1   2   3