Python-list Digest, Vol 28, Issue 191

Manish Kumar (WT01 - Software Products & OSS) kumar.manish at wipro.com
Thu Jan 12 05:00:02 EST 2006


Hi,

It does not work. I had already tried this earlier.

Please suggest some other solutions.

Also, I would like to see the stack from where the exception started.

Thanks n regards,
Manish Kumar

On Thu, 2006-01-12 at 10:40 +0100, python-list-request at python.org wrote:
> Send Python-list mailing list submissions to
> 	python-list at python.org
> 
> To subscribe or unsubscribe via the World Wide Web, visit
> 	http://mail.python.org/mailman/listinfo/python-list
> or, via email, send a message with subject or body 'help' to
> 	python-list-request at python.org
> 
> You can reach the person managing the list at
> 	python-list-owner at python.org
> 
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Python-list digest..."
> Today's Topics:
> 
>    1. Re: Exception Handling (Sheldon)
>    2. Re: void * C array to a Numpy array using Swig (Jon)
>    3. Re: flatten a level one list (Peter Otten)
>    4. Re: Why keep identity-based equality comparison? (Paul Rubin)
>    5. Re: flatten a level one list (Paul Rubin)
>    6. How can I create a dict that sets a flag if it's been
>       modified (sandravandale at yahoo.com)
>    7. Re: Python Scripts to logon to websites (Paul Rubin)
>    8. Re: flatten a level one list (bonono at gmail.com)
>    9. Re: How can I create a dict that sets a flag if it's been
>       modified (Amit Khemka)
>   10. Re: How can I create a dict that sets a flag if it's been
>       modified (Paul Rubin)
>   11. Re: Unicode style in win32/PythonWin (Thomas Heller)
>   12. Re: Real-world use cases for map's None fill-in feature?
>       (Raymond Hettinger)
> email message attachment
> On Thu, 2006-01-12 at 10:40 +0100, python-list-request at python.org
> wrote:
> > Hi,
> > This is a non-trivial thing that you are trying to do. You can use some
> > of python's built-in exceptions, like RuntimeError or IOError and if so
> > then:
> > try:
> >    call C
> > except IOError, e:
> >     print e
> > 
> > But this will return and print only IOErrors if they occur.
> > 
> > You can define your own error handling using the function RAISE:
> > try:
> >   Call C
> > except:
> >   raise my_error.
> > 
> > A catch-all error is RuntimeError; try this first.
> > try:
> >  call C
> > except RuntimeError, r:
> >   print r
> > 
> > You can read up on it here:
> > http://docs.python.org/api/standardExceptions.html
> > 
> > 
> > Cheers,
> > Sheldon
> > 
> > 
> email message attachment
> On Thu, 2006-01-12 at 10:40 +0100, python-list-request at python.org
> wrote:
> > Krish,
> > 
> > In case you find a good solution, I am also looking for one!
> > 
> > For now I essentially use helper functions on the c side which wrap in
> > SWIG to return the data as a string in python. That string can then be
> > converted to a numpy array using the fromstring function. This is
> > inefficient as it does an unnecessary copy but avoids dependence on
> > numeric versus numarray etc. It uses the cstring thing in SWIG (see the
> > manual). The library I am wrapping does not have an image struct, but
> > returns the data into memory that the user has to malloc.
> > 
> > In the swig file I have something like this, which I've simplified to
> > try to get to the point. It assumes you have two c functions which take
> > a pointer to your struct as argument, the first returns the size of the
> > data (what to malloc), the second copies the data into your memory
> > where a pointer to the memory location was second arg.
> > 
> > Doubtless I've introduced typos below, but hopefully you get the idea?
> > 
> > Good luck,
> > 
> > Jon
> > ---
> > typedef struct
> > {
> > stuff    /* I don't know or care what is in here */
> > } imagefilestruct;
> > 
> > %extend imagefilestruct {
> > 
> >  [... snip constructor destructor other functions etc]
> > 
> > %cstring_output_allocate_size( char ** s, int *slen, free(*$1))
> > get_data ;
> > 
> > void get_data(char **s, int *slen){
> >    void * array;
> >    size_t size;
> >    size = libraryfunction_get_size(self);
> >    array=malloc(size));
> >    libraryfunc_get_data(self, array);
> >    *slen = size;
> >    *s = (char *) array;
> >    }
> > }
> > 
> > 
> email message attachment
> On Thu, 2006-01-12 at 10:40 +0100, python-list-request at python.org
> wrote:
> > Tim Hochberg wrote:
> > 
> > > Here's one more that's quite fast using Psyco, but only average without
> > > it.
> >  
> > > def flatten6():
> > >      n = min(len(xdata), len(ydata))
> > >      result = [None] * (2*n)
> > >      for i in xrange(n):
> > >              result[2*i] = xdata[i]
> > >              result[2*i+1] = ydata[i]
> > 
> > I you require len(xdata) == len(ydata) there's an easy way to move the loop
> > into C:
> > 
> > def flatten7():
> >     n = len(xdata)
> >     assert len(ydata) == n
> >     result = [None] * (2*n)
> >     result[::2] = xdata
> >     result[1::2] = ydata
> >     return result
> > 
> > $ python -m timeit 'from flatten import flatten6 as f' 'f()'
> > 1000 loops, best of 3: 847 usec per loop
> > $ python -m timeit 'from flatten import flatten7 as f' 'f()'
> > 10000 loops, best of 3: 43.9 usec per loop
> > 
> > Peter
> > 
> email message attachment
> On Thu, 2006-01-12 at 10:40 +0100, python-list-request at python.org
> wrote:
> > Antoon Pardon <apardon at forel.vub.ac.be> writes:
> > > There is a use case for things like 1 < (1,3) making sense and denoting
> > > a total order. When you have a hetergenous list, having a total order
> > > makes it possible to sort the list which will make it easier to
> > > weed out duplicates. So why don't you demand a use case for the
> > > new behaviour to counter this use case?
> > 
> > This could easily be handled with an alternate comparison function
> > that you pass to the sort function.
> > 
> email message attachment
> On Thu, 2006-01-12 at 10:40 +0100, python-list-request at python.org
> wrote:
> > Robin Becker <robin at SPAMREMOVEjessikat.fsnet.co.uk> writes:
> > > >>>>>reduce(operator.add,a)
> > > ...
> > > A fast implementation would probably allocate the output list just
> > > once and then stream the values into place with a simple index.
> > 
> > That's what I hoped "sum" would do, but instead it barfs with a type
> > error.  So much for duck typing.
> > 
> email message attachment
> On Thu, 2006-01-12 at 10:40 +0100, python-list-request at python.org
> wrote:
> > I can think of several messy ways of making a dict that sets a flag if
> > it's been altered, but I have a hunch that experienced python
> > programmers would probably have an easier (well maybe more Pythonic)
> > way of doing this.
> > 
> > It's important that I can read the contents of the dict without
> > flagging it as modified, but I want it to set the flag the moment I add
> > a new element or alter an existing one (the values in the dict are
> > mutable), this is what makes it difficult. Because the values are
> > mutable I don't think you can tell the difference between a read and a
> > write without making some sort of wrapper around them.
> > 
> > Still, I'd love to hear how you guys would do it.
> > 
> > Thanks,
> > -Sandra
> > 
> > 
> email message attachment
> On Thu, 2006-01-12 at 10:40 +0100, python-list-request at python.org
> wrote:
> > Steve Holden <steve at holdenweb.com> writes:
> > > Underlining your point, the difference between the two is that digest
> > > offers *strong* authentication (i.e. is not subject to replay attacks)
> > 
> > As I mentioned in another post, that's really not enough, since digest
> > still exposes the password hash to offline dictionary attacks, which
> > are sure to nab some passwords if you have a lot of users being
> > sniffed and you don't impose severe amounts of password discipline on
> > them.  There's also usually no way to log out from an http
> > authenticated session except by completely closing the browser.  All
> > in all, if you have nontrivial security requirements there's not much
> > point in using Digest.  Use form-based authentication over SSL/TLS
> > instead.  Make sure that the application locks out the user account
> > (at least temporarily) after too many failed login attempts, something
> > http authentication implementations that I know of don't bother to do.
> > 
> > For higher security applications (e.g. extranets, admin interfaces,
> > etc), use client certificates on hardware tokens.
> > 
> email message attachment
> On Thu, 2006-01-12 at 10:40 +0100, python-list-request at python.org
> wrote:
> > Robin Becker wrote:
> > > Paul Rubin wrote:
> > > > Paul Rubin <http://phr.cx@NOSPAM.invalid> writes:
> > > >
> > > >>>>>import operator
> > > >>>>>a=[(1,2),(3,4),(5,6)]
> > > >>>>>reduce(operator.add,a)
> > > >>
> > > >>(1, 2, 3, 4, 5, 6)
> > > >
> > > >
> > > > (Note that the above is probably terrible if the lists are large and
> > > > you're after speed.)
> > > yes, and it is all in C and so could be a contender for the speed champ.
> > > I guess what you're saying is that it's doing
> > >
> > That is what I thought too but seems that [x for pair in li for x in
> > pair] is the fastest on my machine and what is even stranger is that if
> > I use psyco.full(), I got a 10x speed up for this solution(list
> > comprehension) which is head and shoulder above all the other suggested
> > so far.
> > 
> > 
> email message attachment
> On Thu, 2006-01-12 at 10:40 +0100, python-list-request at python.org
> wrote:
> > Ideally, I would have made a wrapper to add/delete/modify/read from
> > the dictionay.
> > 
> > But other than this, one way i can think straight off is to "pickle"
> > the dict, and to see if the picked object is same as current object.
> > 
> > cheers,
> > amit.
> > 
> > On 12 Jan 2006 01:15:38 -0800, sandravandale at yahoo.com
> > <sandravandale at yahoo.com> wrote:
> > > I can think of several messy ways of making a dict that sets a flag if
> > > it's been altered, but I have a hunch that experienced python
> > > programmers would probably have an easier (well maybe more Pythonic)
> > > way of doing this.
> > >
> > > It's important that I can read the contents of the dict without
> > > flagging it as modified, but I want it to set the flag the moment I add
> > > a new element or alter an existing one (the values in the dict are
> > > mutable), this is what makes it difficult. Because the values are
> > > mutable I don't think you can tell the difference between a read and a
> > > write without making some sort of wrapper around them.
> > >
> > > Still, I'd love to hear how you guys would do it.
> > >
> > > Thanks,
> > > -Sandra
> > >
> > > --
> > > http://mail.python.org/mailman/listinfo/python-list
> > >
> > 
> > 
> > --
> > ----
> > Endless the world's turn, endless the sun's spinning
> > Endless the quest;
> > I turn again, back to my own beginning,
> > And here, find rest.
> > 
> email message attachment
> On Thu, 2006-01-12 at 10:40 +0100, python-list-request at python.org
> wrote:
> > sandravandale at yahoo.com writes:
> > > Still, I'd love to hear how you guys would do it.
> > 
> > Make a subclass of dict, or an object containing a dictionary, that
> > has a special __setattr__ method that traps updates and sets that
> > modification flag.  There are contorted ways the caller can avoid
> > triggering the flag, but Python is not Java and it in general makes no
> > attempt to protect its objects against hostile code inside the
> > application.
> > 
> > Your suggestion of using pickle is shaky in my opinion, since pickle's
> > docs don't guarantee that pickling the same dictionary twice will
> > return the same pickle both times.  If it happens to work that way,
> > it's just an implementation accident.
> > 
> email message attachment
> On Thu, 2006-01-12 at 10:40 +0100, python-list-request at python.org
> wrote:
> > "Robert" <kxroberto at googlemail.com> writes:
> > 
> > > Neil Hodgson wrote:
> > >> Robert:
> > >>
> > >> > After "is_platform_unicode = <auto>", scintilla displays some unicode
> > >> > as you showed. but the win32-functions (e.g. MessageBox) still do not
> > >> > pass through wide unicode.
> > >>
> > >>     Win32 issues are better discussed on the python-win32 mailing list
> > >> which is read by more of the people interested in working on this library.
> > >> http://mail.python.org/mailman/listinfo/python-win32
> > >>     Patches that improve MessageBox in particular or larger sets of
> > >> functions in a general way are likely to be welcomed.
> > >
> > > ok. I have no patches so far as of now - maybe later. Played with
> > > Heller's ctypes for my urgent needs. That works correct with unicode
> > > like this:
> > >
> > >>>> import ctypes
> > >>>> ctypes.windll.user32.MessageBoxW(0,u'\u041f\u043e\u0448\u0443\u043a.txt',0,0)
> > > 1
> > 
> > FYI, if you assign the argtypes attribute for ctypes functions, the
> > ascii/unicode conversion is automatic (if needed).
> > 
> > So after these assignments:
> > 
> >   ctypes.windll.user32.MessageBoxW.argtypes = (c_int, c_wchar_p,
> >                                                c_wchar_p, c_int)
> >   ctypes.windll.user32.MessageBoxA.argtypes = (c_int, c_char_p,
> >                                                c_char_p, c_int)
> > 
> > both MessageBoxA and MessageBoxW can both be called with either ansi and
> > unicode strings, and should work correctly.  By default the conversion
> > is done with ('msbc', 'ignore'), but this can also be changed,
> > ctypes-wide, with a call to ctypes.set_conversion_mode(encoding,errors).
> > 
> > You have to pass None for the third parameter (if not a string).
> > 
> > Thomas
> > 
> email message attachment
> On Thu, 2006-01-12 at 10:40 +0100, python-list-request at python.org
> wrote:
> > [rurpy at yahoo.com]
> > > > > How well correlated in the use of map()-with-fill with the
> > > > > (need for) the use of zip/izip-with-fill?
> > 
> > [raymond]
> > > > Close to 100%.  A non-iterator version of izip_longest() is exactly
> > > > equivalent to map(None, it1, it2, ...).
> > 
> > [rurpy at yahoo.com]
> > > If I use map()
> > > I can trivially determine the arguments lengths and deal with
> > > unequal length before map().  With iterators that is more
> > > difficult.  So I can imagine many cases where izip might
> > > be applicable but map not, and a lack of map use cases
> > > not representative of izip use cases.
> > 
> > You don't seem to understand what map() does.  There is no need  to
> > deal with unequal argument lengths before map(); it does the work for
> > you.  It handles iterator inputs the same way.  Meditate on this:
> > 
> >     def izip_longest(*args):
> >         return iter(map(None, *args))
> > 
> > Modulo arbitrary fill values and lazily evaluated inputs, the semantics
> > are exactly what is being requested.  Ergo, lack of use cases for
> > map(None,it1,it2) means that izip_longest(it1,it2) isn't needed.
> > 
> > Raymond
> > 
> > 
> -- 
> http://mail.python.org/mailman/listinfo/python-list



The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments. 

WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
 
www.wipro.com



More information about the Python-list mailing list