<html>
<head>
<style>
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
FONT-SIZE: 10pt;
FONT-FAMILY:Tahoma
}
</style>
</head>
<body class='hmmessage'><div style="text-align: left;">thank you i did find solution i did have just change: <br><br></div>     unpackedData = struct.unpack(unpackFormat, data)  to<br><br>     unpackedData = struct.unpack(unpackFormat, data.decode('string_escape'))<br><br><br><br><br><blockquote><hr id="stopSpelling">From: python-list-request@python.org<br>Subject: Python-list Digest, Vol 55, Issue 179<br>To: python-list@python.org<br>Date: Fri, 11 Apr 2008 15:50:04 +0200<br><br><pre>Send Python-list mailing list submissions to<br>        python-list@python.org<br> <br>To subscribe or unsubscribe via the World Wide Web, visit<br>  <a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>or, via email, send a message with subject or body 'help' to<br>   python-list-request@python.org<br> <br>You can reach the person managing the list at<br>      python-list-owner@python.org<br> <br>When replying, please edit your Subject line so it is more specific<br>than "Re: Contents of Python-list digest..."<br></pre><blockquote>--Pièce jointe du message transmise--<br>From: ivan.illarionov@gmail.com<br>To: python-list@python.org<br>Date: Fri, 11 Apr 2008 05:58:46 -0700<br>Subject: Re: Rounding a number to nearest even<br><br><pre>On Apr 11, 2:14 pm, bdsatish <bdsat...@gmail.com> wrote:<br>> The built-in function round( ) will always "round up", that is 1.5 is<br>> rounded to 2.0 and 2.5 is rounded to 3.0.<br>><br>> If I want to round to the nearest even, that is<br>><br>> my_round(1.5) = 2        # As expected<br>> my_round(2.5) = 2        # Not 3, which is an odd num<br>><br>> I'm interested in rounding numbers of the form "x.5" depending upon<br>> whether x is odd or even. Any idea about how to implement it ?<br> <br>def even_round(x):<br>    if x % 1 == .5 and not (int(x) % 2):<br>        return float(int(x))<br>    else:<br>        return round(x)<br> <br>nums = [ 3.2, 3.6, 3.5, 2.5, -.5, -1.5, -1.3, -1.8, -2.5 ]<br>for num in nums:<br>    print num, '->', even_round(num)<br> <br>3.2 -> 3.0<br>3.6 -> 4.0<br>3.5 -> 4.0<br>2.5 -> 2.0<br>-0.5 -> 0.0<br>-1.5 -> -2.0<br>-1.3 -> -1.0<br>-1.8 -> -2.0<br>-2.5 -> -2.0<br> <br> <br></pre></blockquote><blockquote>--Pièce jointe du message transmise--<br>From: steve@holdenweb.com<br>To: python-list@python.org<br>Date: Fri, 11 Apr 2008 09:07:42 -0400<br>Subject: Re: (unknown)<br><br><pre>ha bo wrote:<br>> hi i use this programme in my application django:<br>> import struct<br>> MASK_CCITT  = 0x1021     # CRC-CCITT mask (ISO 3309, used in X25, HDLC)<br>> MASK_CRC16  = 0xA001     # CRC16 mask (used in ARC files)<br>> <br>> def updcrc(crc, data, mask=MASK_CRC16):<br>> <br>>      data_length = len(data)<br>>      unpackFormat = '%db' % data_length<br>>      unpackedData = struct.unpack(unpackFormat, data)<br>> <br>>      for char in data:<br>>             c = ord(char)<br>>             c = c << 8<br>>    <br>>             for j in xrange(8):<br>>                 if (crc ^ c) & 0x8000:<br>>                     crc = (crc << 1) ^ mask<br>>                 else:<br>>                     crc = crc << 1<br>>                 c = c << 1<br>> <br>>      return crc & 0xffff<br>> <br>> <br>> and i call this function in other function in my view:<br>> <br>> <br>> def encodekey(var, expires=None, user='', trusted=False):<br>>  <br>>         import random, base64<br>>         import updcrc<br>>         key = "%02X" % len(var) + var<br>>         key += "%02X" % len(user) + user<br>>         if expires is not None:<br>>             key += expires.strftime('%Y%m%d%H%M')<br>>         else:<br>>             year = random.choice(range(2000,2100))<br>>             month = 23<br>>             day = random.choice(range(1,32))<br>>             hour = random.choice(range(1,25))<br>>             minute = random.choice(range(1,60))<br>>             key += "%04d%02d%02d%02d%02d" % (year, month, day, hour, minute)<br>> <br>>         if trusted:<br>>             checksum = updcrc(42, key)<br>>         else:   <br>>             checksum = updcrc(0, key)<br>>         key += "%04X" % checksum<br>> <br>>         return base64.b64encode(key)<br>> but it give me this error:<br>> <br>> <br>>     unpack requires a string argument of length 31<br>> <br>> <br>> someone can help me<br>> <br>Next time you report an error, please include the whole traceback, not <br>just the exception message. That information is included for a reason.<br> <br>You might also want to print out the value of data in your updcrc <br>function, since that is where the problem is occurring.<br> <br>Finally I might point out there is little point to the struct.unpack <br>since you don't use its result, but I am guessing this is because your <br>algorithm is currently in transition.<br> <br>regards<br>  Steve<br>-- <br>Steve Holden        +1 571 484 6266   +1 800 494 3119<br>Holden Web LLC              <a href="http://www.holdenweb.com/" target="_blank">http://www.holdenweb.com/</a><br> <br> <br></pre></blockquote><blockquote>--Pièce jointe du message transmise--<br>From: victorsubervi@gmail.com<br>CC: python-list@python.org<br>To: gagsl-py2@yahoo.com.ar<br>Date: Fri, 11 Apr 2008 08:36:02 -0500<br>Subject: Re: String Literal to Blob<br><br><div>Nope. Do not see it. My ugly stupid way works. I guess I will just proceed with that and write my howto accordingly.</div><br><div>Victor<br><br></div><br><div class="gmail_quote">On Thu, Apr 10, 2008 at 9:01 PM, Gabriel Genellina <<a href="mailto:gagsl-py2@yahoo.com.ar">gagsl-py2@yahoo.com.ar</a>> wrote:<br><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0px 0px 0px 0.8ex; padding-left: 1ex;">En Thu, 10 Apr 2008 14:04:43 -0300, Victor Subervi<br><<a href="mailto:victorsubervi@gmail.com">victorsubervi@gmail.com</a>> escribió:<br><br><br><div><br><div></div><br><div class="Wj3C7c"><br>> Well, what I did was this:<br>><br>>             content = col_fields[0][14].tostring()<br>>             pic = "tmp" + str(i) + ".jpg"<br>>             img = open(pic, "w")<br><br>>             img.write(content)<br>>             print '<img src="%s"><br /><br />' % pic<br>>             img.close()<br>> where I am incrementing i. Ugly. Stupid. But if it is the only way to do<br><br>> it<br>> in python, and I do not want to invest the time doing it in php, which I<br>> think would be prettier in this instance, then I guess it will do. Your<br>> thoughts appreciated.<br><br></div></div>You REALLY should read some material on how HTTP works. I'll try to sketch<br><br>a few important points. First, suppose you have an HTML page (album.html)<br>with two images in it:<br><br><html><body><br><p>This is me: <img src="/images/myself.jpg"><br>and this is my cat <img src="/images/garfield.jpg"><br><br></body></html><br><br>Suppose the URL for that page is <a href="http://some.server.com/gabriel/album.html" target="_blank">http://some.server.com/gabriel/album.html</a><br>and you type that in your favorite browser. This is what happens:<br><br>1) The sees the initial "http:" and says "I'll use HTTP". Then sees<br>"<a href="http://some.server.com/" target="_blank">some.server.com</a>" and opens a connection to that server on port 80. Then<br><br>sees "/gabriel.album.html" and builds an HTTP GET request for it.<br>2) The server receives the GET request, looks for the "album.html"<br>document, determines the right Content-Type, and returns it specifying<br><br>"Content-Type: text/html"<br>3) The browser receives the HTML text and tries to display it. When it<br>encounters the first <img> tag it looks at the src attribute; it doesn't<br>know that image; so a *NEW* HTTP request is required. This time it says<br><br>"GET /images/myself.jpg"<br>4) The server receives the GET request, looks for a file with that name,<br>determines that it's a jpeg image, and returns its contents along with a<br>"Content-Type: image/jpeg".<br><br>5) The browser receives the image and is able to display it.<br>6) The same thing happens with the second <img> tag, there is a third HTTP<br>GET request for it.<br><br>Note that:<br>- The images themselves *aren't* in the HTML page, they are somewhere<br><br>else. HTML is text and contains ONLY the URI for the image.<br>- THREE DIFFERENT requests are done to show that page. Each one returns A<br>SINGLE OBJECT of A SINGLE TYPE.<br><br>The above was using static HTML with static images. If you use CGI to<br><br>generate dynamic content, it's the same thing. From the browser point of<br>view, there is no difference: it still will generate three different<br>requests for the three pieces (one html document with two images).<br><br>Your CGI script (or scripts) will receive three different requests then:<br>when requested for HTML, return HTML; when requested for an image, return<br>an image. They are DIFFERENT things, DIFFERENT requests, happening at<br><br>DIFFERENT times, so don't mix them.<br><br>I think that combining Steve's responses and mine you now have enough<br>information to be able to solve your problems. Perhaps if you re-read the<br>whole thread from start you'll have now a better understanding of what's<br><br>happening.<br><br>--<br><font color="#888888">Gabriel Genellina<br></font><br><div><br><div></div><br><div class="Wj3C7c"><br>--<br><a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br></div></div></blockquote></div><br><br></blockquote><blockquote>--Pièce jointe du message transmise--<br>From: huayang.xia@gmail.com<br>To: python-list@python.org<br>Date: Fri, 11 Apr 2008 06:37:23 -0700<br>Subject: Re: Convert PyIDispatch object to struct IDispatch*<br><br><pre>On Apr 11, 12:15 am, "Gabriel Genellina" <gagsl-...@yahoo.com.ar><br>wrote:<br>> En Thu, 10 Apr 2008 18:45:04 -0300, Huayang Xia <huayang....@gmail.com><br>> escribió:<br>><br>> > I am trying to use ctypes to call dll functions. One of the functions<br>> > requires argument "struct IDispatch* ". I do have a PyIDispatch object<br>> > in python. How can I convert this "PyIDispatch object" to "struct<br>> > IDispatch* "?<br>><br>> I think a PyIDispatch object is an IDispatch* itself.<br>> But you'll get better answers from the python-win32 list:<a href="http://mail.python.org/mailman/listinfo/python-win32" target="_blank">http://mail.python.org/mailman/listinfo/python-win32</a><br>><br>> --<br>> Gabriel Genellina<br> <br>Thanks for the info.<br> <br>To call a dll function, it needs a C style IDispatch*. PyIDispatch is<br>a python wrapped one. I found a reference from:<br> <br><a href="http://svn.python.org/projects/ctypes/trunk/comtypes/comtypes/test/test_win32com_interop.py" target="_blank">http://svn.python.org/projects/ctypes/trunk/comtypes/comtypes/test/test_win32com_interop.py</a><br> <br>which shows how to convert C style to python style. Unfortunately i<br>need the reversed version.<br> <br>I will post the question to python-win32.<br> <br></pre></blockquote><blockquote>--Pièce jointe du message transmise--<br>From: enleverlesX.XmcX@XmclaveauX.com<br>To: python-list@python.org<br>Date: Fri, 11 Apr 2008 15:38:32 +0200<br>Subject: Python plus<br><br><pre>After IronPython, Python + iron : <br> <a href="http://www.golfermania.com/SnakeEyes/PYTHON-PLUS-IRON.jpg" target="_blank">http://www.golfermania.com/SnakeEyes/PYTHON-PLUS-IRON.jpg</a><br> <br>;o)  <br> <br>Michel Claveau<br> <br> <br></pre></blockquote><blockquote>--Pièce jointe du message transmise--<br>From: mail@timgolden.me.uk<br>CC: python-list@python.org<br>Date: Fri, 11 Apr 2008 14:47:20 +0100<br>Subject: Re: Convert PyIDispatch object to struct IDispatch*<br><br><pre>Huayang Xia wrote:<br>> On Apr 11, 12:15 am, "Gabriel Genellina" <gagsl-...@yahoo.com.ar><br>> wrote:<br>>> En Thu, 10 Apr 2008 18:45:04 -0300, Huayang Xia <huayang....@gmail.com><br>>> escribió:<br>>><br>>>> I am trying to use ctypes to call dll functions. One of the functions<br>>>> requires argument "struct IDispatch* ". I do have a PyIDispatch object<br>>>> in python. How can I convert this "PyIDispatch object" to "struct<br>>>> IDispatch* "?<br>>> I think a PyIDispatch object is an IDispatch* itself.<br>>> But you'll get better answers from the python-win32 list:<a href="http://mail.python.org/mailman/listinfo/python-win32" target="_blank">http://mail.python.org/mailman/listinfo/python-win32</a><br>>><br>>> --<br>>> Gabriel Genellina<br>> <br>> Thanks for the info.<br>> <br>> To call a dll function, it needs a C style IDispatch*. PyIDispatch is<br>> a python wrapped one. I found a reference from:<br>> <br>> <a href="http://svn.python.org/projects/ctypes/trunk/comtypes/comtypes/test/test_win32com_interop.py" target="_blank">http://svn.python.org/projects/ctypes/trunk/comtypes/comtypes/test/test_win32com_interop.py</a><br>> <br>> which shows how to convert C style to python style. Unfortunately i<br>> need the reversed version.<br>> <br>> I will post the question to python-win32.<br> <br>I've had a quick look at the PyIDispatch source and I can't see any obvious<br>way in which the underlying IDispatch is exposed. May have missed something,<br>but it's possible that there's not way out.<br> <br>TJG<br> <br></pre></blockquote><blockquote>--Pièce jointe du message transmise--<br>From: hdante@gmail.com<br>To: python-list@python.org<br>Date: Fri, 11 Apr 2008 06:49:23 -0700<br>Subject: Re: Rounding a number to nearest even<br><br><pre>On Apr 11, 9:45 am, bdsatish <bdsat...@gmail.com> wrote:<br>> On Apr 11, 5:33 pm, bdsatish <bdsat...@gmail.com> wrote:<br>><br>><br>><br>> > HI Gerard,<br>><br>> > I think you've taken it to the best possible implementation. Thanks !<br>> > On Apr 11, 5:14 pm, Gerard Flanagan <grflana...@gmail.com> wrote:<br>><br>> > > In fact you can avoid the call to the builtin round:<br>><br>> > > ------------------------------------------------<br>><br>> > > assert myround(3.2) == 3<br>> > > assert myround(3.6) == 4<br>> > > assert myround(3.5) == 4<br>> > > assert myround(2.5) == 2<br>> > > assert myround(-0.5) == 0.0<br>> > > assert myround(-1.5) == -2.0<br>> > > assert myround(-1.3) == -1.0<br>> > > assert myround(-1.8) == -2<br>> > > assert myround(-2.5) ==  -2.0<br>> > > ------------------------------------------------<br>><br>> OK, I was  too early to praise Gerard. The following version:<br>><br>> def myround(x):<br>>      n = int(x)<br>>      if abs(x - n) >= 0.5 and n % 2:<br>>           return n + 1 - 2 * int(n<0)<br>>      else:<br>>           return n<br>><br>> of Gerard doesn't work for 0.6 (or 0.7, etc.) It gives the answer 0<br>> but I would expect 1.0 ( because 0.6 doesn't end in 0.5 at all... so<br>> usual rules of round( ) apply)<br> <br> Interestingly, you could solve this by using python 3. :-)<br> round(x[, n])<br>    Return the floating point value x rounded to n digits after the<br>decimal point. If n is omitted, it defaults to zero. Values are<br>rounded to the closest multiple of 10 to the power minus n; if two<br>multiples are equally close, rounding is done toward the even choice<br>(so, for example, both round(0.5) and round(-0.5) are 0, and<br>round(1.5) is 2). Delegates to x.__round__(n).<br> <br> My turn: ;-)<br> <br>def yaround(x):<br>    i = int(x)<br>    f = x - i<br>    if f != 0.5 and f != -0.5: return round(x)<br>    return 2.0*round(x/2.0)<br> <br>a = (-10.0, -9.0, -8.0, -4.6, -4.5, -4.4, -4.0, -3.6, -3.5,<br>     -3.4, -0.6, -0.5, -0.4, 0.0, 0.4, 0.5, 0.6, 0.9, 1.0,<br>     1.4, 1.5, 1.6, 2.0, 2.4, 2.5, 2.6, 10.0, 100.0)<br> <br>b = (-10.0, -9.0, -8.0, -5.0, -4.0, -4.0, -4.0, -4.0, -4.0,<br>     -3.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0,<br>     1.0, 2.0, 2.0, 2.0, 2.0, 2.0, 3.0, 10.0, 100.0)<br> <br>for i in range(len(a)):<br>    assert yaround(a[i]) == b[i]<br> <br> <br> <br> <br></pre></blockquote></blockquote><br /><hr />Discutez gratuitement avec vos amis en vidéo !  <a href='http://get.live.com/messenger/overview' target='_new'>Téléchargez Messenger, c'est gratuit !</a></body>
</html>