Have you tried opening the zip file in binary mode?
Regards,
Marek
--
http://mail.python.org/mailman/listinfo/python-list
Dustan napisał(a):
> Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit
> (Intel)] on
> win32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> 'HELP!%(xyz)/' % {'xyz':' PLEASE! '}
> Traceback (most recent call last):
> File "", line 1, in
> ValueError
Ciprian Dorin, Craciun napisał(a):
> Python way:
> def compare (a, b, comp = eq) :
> if len (a) != len (b) :
> return False
> for i in xrange (len (a)) :
> if not comp (a[i], b[i]) :
>return False
> return True
This is shorter, but I'm not sure if more pythonic:
def compare(a, b, compfun
bullockbefriending bard napisał(a):
> I'm not sure if my terminology is precise enough, but what I want to
> do is:
>
> Given an ordered sequence of n items, enumerate all its possible k-
> segmentations.
>
> This is *not* the same as enumerating the k set partitions of the n
> items because I am o
Erhard napisał(a):
> I've been looking at the date/time classes and I'm at a loss as to how
> to do this (probably too used to other platforms).
>
> I have two date/time values. One represents 'now' and the other the last
> modified time of a file on disk (from stat). I need to calculate the
> diff
Simon Mullis napisał(a):
> Something like:
>
> dict_of_counts = dict([(v[0:3], "count") for v in l])
>
> I can't seem to figure out how to get "count", as I cannot do x += 1
> or x++ as x may or may not yet exist, and I haven't found a way to
> create default values.
It seems to me that the "count
castironpi napisał(a):
> Is there a way to initialize a ctypes Structure to point to an offset
> into a buffer? I don't know if the way I'm doing it is supported.
There is a high probability you're abusing ctypes too much, but it's
possible. The following seems to work:
from ctypes import *
clas
Dave napisał(a):
> Hey there, having a bit of problem iterating through lists before i go
> on any further, here is
> a snip of the script.
> --
> d = "a1 b1 c1 d1 e1 a2 b2 c2 d2 e2 a3 b3 c3 d3 e3 a4 b4 c4 d4 e4 a5 b5
> c5 d5 e5"
> inLst = d.split()
> hitLst = []
>
> hitNum = 0
> stopCnt = 6 + hitN
[EMAIL PROTECTED] napisał(a):
> Hi, I have just encountered a Python behaviour I wouldn't expect. Take
> the following code:
>
>
> class Parent:
> a = 1
>
> def m (self, param = a):
> print "param = %d" % param
Excellent explanation by Mark Wooding. I would only like to add that
the standard pythonic idiom in such cases seems to be the (ab)use of a
default argument to the function, because these get evaluated at the
definition time:
def gen0():
for i in range(3):
def gen1(i = i):
Evren Esat Ozkan napisał(a):
> Hello,
>
> I'm trying to encrypt a string with RSA. But it needs to be compitable
> with Dave's JavaScript RSA implementation*. I'm already read and tried
> lots of different things about RSA and RSA in Python. But could not
> produce the same result with the javascri
Nicolas Girard napisał(a):
> prepend(C.f,pre)
This wraps f, returns wrapped and binds it to C.f (but the
method.__name__ is still wrapped).
> append(C.f,post)
This wraps wrapped (the one previously returned), returns wrapped (a
new one) and binds it to C.wrapped (since that is what its
meth
Neal Becker napisał(a):
> In an earlier post, I was interested in passing a pointer to a structure to
> fcntl.ioctl.
>
> This works:
>
> c = create_string_buffer (...)
> args = struct.pack("iP", len(c), cast (pointer (c), c_void_p).value)
> err = fcntl.ioctl(eos_fd, request, args)
>
> Now to do the
One solution may be to use globals():
>>> globals()['foo']()
Regards,
Marek
--
http://mail.python.org/mailman/listinfo/python-list
Martin v. Löwis napisał(a):
> > Or hexdigest_string.decode('hex')
>
> I would advise against this, as it's incompatible with Python 3.
I didn't know that, you actually made me look it up in the Python 3
FAQ. And yes, the difference is that decode will return bytes type
instead of a string. This ma
Martin v. Löwis napisał(a):
> > How can convert string from sha1.hexdigest() to string that is the
> > same, like from sha1.digest()
>
> Use binascii.unhexlify.
>
> HTH,
> Martin
Or hexdigest_string.decode('hex')
--
http://mail.python.org/mailman/listinfo/python-list
I love Paul's response.
[EMAIL PROTECTED] napisał(a):
>
My crystal ball broke a few days ago due to overuse, but I recall that
OpenGL likes to have power-of-two texture sizes. If that doesn't work,
please trim down your code as far as possible (so that it still
displays the error) and post it.
-
You can also do it with ctypes only; too bad it's not really well
documented. c_float is a type of a floating point number and it has *
operator defined, so that c_float*4 is a type of a 4-element array of
those numbers. So if you want to construct an array of floats from a
list of floats, you can
Everybody has already explained why this doesn't work and a possible
"solution" using metaclasses was suggested. I tried to implement it,
ended up with monkey-patching __bases__, which is certainly an
abomination (will it be possible in python 3.0?) but seems to do the
trick.
class _InheritFromOut
[EMAIL PROTECTED] napisał(a):
> [EMAIL PROTECTED]:
> > As for the original prooblem, why not use
> > defaultdict? I think it's the most idiomatic way to achieve what we
> > want. And also the fastest one, according to my quick-and-dirty tests:
>
> It adds the new keys, I can't accept that:
Right,
[EMAIL PROTECTED] napisał(a):
> It's slower still, despite doing the lookup two times half of the
> times (half keys are present in the test set). The "in" is an
> operator, it's faster than a method call, but I don't understand the
> other details. Now the difference between 1.78 and 1.56 is small
Hello. Please post the minimal code that can be run and demonstrates
what's wrong. I tried the following and it works fine, args and kwargs
are visible:
class MyFactory(object):
def __init__(self, *args, **kwargs):
self.args = args
self.kwargs = kwargs
clas
Not a bug. All languages implementing floating point numbers have the
same issue. Some just decide to hide it from you. Please read
http://docs.python.org/tut/node16.html and particularly
http://docs.python.org/tut/node16.html#SECTION001610
Regards,
Marek
--
http://mail.python.org
erikcw napisal(a):
> But that can't be reversed, right? I'd like to be able to decrypt the
> data instead of having to store the hash in my database...
In such case it seems you have no choice but to use a symmetric
encryption algorithm - in other words, your original method. If the
strings are ~20
erikcw napisal(a):
> Hi,
>
> I'm trying to devise a scheme to encrypt/obfuscate a short string that
> basically contains the user's username and record number from the
> database. I'm using this encrypted string to identify emails from a
> user. (the string will be in the subject line of the email
Iain Mackay napisal(a):
> Python Folks
>
> I'm a newbie to Python and am looking for a library / function that can help
> me fit a 1D data vector to a sine wave. I know the frequency of the wave,
> so its really only phase and amplitude information I need.
>
> I can't find anything in the most w
I decided to play with it a little bit, but take a different approach
than Steven. This seems actually one of the problems where regexp
might be a good solution.
import re
re_signednumber = r'([-+]?\d+)'
re_expression = '%s(?:([-+/*])[-+/*]*?%s)*' % (re_signednumber,
re_signednumber)
for test_cas
> class vec2d(ctypes.Structure):
> """2d vector class, supports vector and scalar operators,
>and also provides a bunch of high level functions
>"""
> __slots__ = ['x', 'y']
>
> def __init__(self, x_or_pair, y = None):
>
> if y == None:
> self.x = x_o
Nice challenge! I came up with something like this:
def find_repr(target, numbers):
org_reprs = dict((number, str(number)) for number in numbers)
curr_reprs = org_reprs
while target not in curr_reprs:
old_reprs, curr_reprs = curr_reprs, {}
fo
On 19 Gru, 13:08, Sharun <[EMAIL PROTECTED]> wrote:
> I am trying to find the substring starting with 'aaa', and ending with
> ddd OR fff. If ddd is found shouldnt the search stop? Shouldn't
> re5.search(str5).group(0) return 'aaa bbb\r\n ccc ddd' ?
The documentation for the re module (http://docs
Mario M. Mueller napisał(a):
> Personally I would expect simple counts (since other seismic formats don't
> even think of using floats because most digitizers deliver counts). But I
> was told that there are floats inside.
>
> But if I assume counts I get some reasonable numbers out of the file.
I
This is the expected behaviour. The reference on classes (http://
docs.python.org/ref/class.html) says:
> Variables defined in the class definition are class variables;
> they are shared by all instances. To define instance variables,
> they must be given a value in the __init__() method or in
> a
JamesHoward napisa (a):
> Does anyone know any method to have one program, acting as a server
> transfer a socket connection to another program? I looked into
> transferring the connection via xml rpc to no avail. It seems to be a
> problem of getting access to a programs private memory space and
>
Tim Golden napisa (a):
> It's only a moment before the metaclass and
> the Twisted solution come along. :)
I couldn't resist. It's not as elegant as I hoped, but hey, at least
it memoizes the intermediate classes :-)
class fact_0(object):
value = 1
class fact_meta(object):
def
BBands napisa (a):
> An example:
>
> class classA:
> def __init__(self):
> self.b = 1
>
> def doStuff():
> some calcs
> a..b = 0
>
> a = classA():
> print a.b
> doStuff()
> print a.b
>
> That works as hoped, printing 1, 0.
>
> But, if I move doStuff to another module and:
>
> im
attackwarningred napisa (a):
> The array F(n) is dynamically allocated earlier on and is sized with
> reference to shotcount, the number of iterations the model performs. The
> problem is I can't get something like this to run in Python using numpy,
> and for the size of the array to be sized dyn
Those methods of computing partial sums seem to be O(n^2) or worse.
What's wrong with an ordinary loop?
for i in xrange(1, len(l)):
l[i] += l[i - 1]
And as for the list of objects:
ll = [l[i - 1].method(l[i]) for i in xrange(1, len(l))] + l[-1]
--
http://mail.python.org/mailman/listinfo/py
My attempt uses a different approach: create two sorted arrays, n^2
elements each; and then iterate over them looking for matching
elements (only one pass is required). I managed to get 58,2250612857 s
on my 1,7 MHz machine. It requires numpy for decent performance,
though.
import numpy
import tim
Python documentation says:
>__cmp__( self, other)
> Called by comparison operations if rich comparison (see above) is not defined.
So it seems you have to redefine rich comparisons __lt__, __gt__,
__eq__ etc as well.
If all you need is change sorting order, why not use appropriate
parameters of so
nikie napisal(a):
> I'm a little bit stuck with NumPy here, and neither the docs nor
> trial&error seems to lead me anywhere:
> I've got a set of data points (x/y-coordinates) and want to fit a
> straight line through them, using LMSE linear regression. Simple
> enough. I thought instead of looking
Thank you all for your responses. That's exactly what I needed to know
- how to bind a function to an object so that it would comply with
standard calling syntax.
This is largely a theoretical issue; I just wanted to improve my
understanding of Python's OOP model. Using such features in real life
> hi;
> say i have a text file with a string ( say '(XYZ)') and I want to find
> the number of line where this string has occured. What is the best way
> to do that?
I would suggest:
# Read file contents
lines = file('filename.txt').readlines()
# Extract first line number containing 'XYZ' string
First of all, please don't flame me immediately. I did browse archives
and didn't see any solution to my problem.
Assume I want to add a method to an object at runtime. Yes, to an
object, not a class - because changing a class would have global
effects and I want to alter a particular object only.
43 matches
Mail list logo