Hello group,
I'm looking for a Python function but have forgotten it's name.
Essentially what I want is:
class Foo():
def bar(self):
pass
x = Foo()
y = x.MAGIC(bar)
print(y)
bound method Foo.bar of __main__.Foo instance at 0xb7e11fcc
So the question is: How is the magic
Peter Otten schrieb:
encoding = sys.stdout.encoding or ascii
for row in rows:
id, address = row[:2]
print id, address.encode(encoding, replace)
Example:
uähnlich lölich üblich.encode(ascii, replace)
'?hnlich l?lich ?blich'
A very good tip, Peter - I've also had this problem
Sebastian Bassi schrieb:
No, there is no certification for Python. Maybe in the future...
I'll hand out the Johannes Bauer Python Certificate of Total
Awesomeness for anyone who can write a hello world in python and hands
me $25000 in cash.
This whole certified foobar programmer is complete
Hello group,
I'm trying to use a htmllib.HTMLParser derivate class to parse a website
which I fetched via
httplib.HTTPConnection().request().getresponse().read(). Now the problem
is: As soon as I pass the htmllib.HTMLParser UTF-8 code, it chokes. The
code is something like this:
prs =
Terry Reedy schrieb:
Johannes Bauer wrote:
Hello group,
I'm trying to use a htmllib.HTMLParser derivate class to parse a website
which I fetched via
httplib.HTTPConnection().request().getresponse().read(). Now the problem
is: As soon as I pass the htmllib.HTMLParser UTF-8 code, it chokes
Hello group,
I'm just starting with Python and am extremely unexperienced with it so
far. Having a strong C/C++ background, I wish to do something like
if (q = getchar()) {
printf(%d\n, q);
}
or translated to Python:
if (p = myfunction()):
print p
However, this assignment
Carl Banks schrieb:
p = myfunction()
if p:
print p
(I recommend doing it this way in C, too.)
This is okay for if-clauses, but sucks for while-loops:
while (fgets(buf, sizeof(buf), f)) {
printf(%s\n, buf);
}
is much shorter than
char *tmp;
tmp = fgets(buf, sizeof(buf), f);
George Sakkis schrieb:
However, this assignment and comparison is not working. What's the
Python way of doing this kind of thing?
The most obvious and readable of course: use two statements, as one
should do regardless of the language, instead of resorting to error-
prone hacks.
As I said
TheSaint schrieb:
On 06:59, sabato 24 maggio 2008 Johannes Bauer wrote:
However, this assignment and comparison is not working. What's the
Python way of doing this kind of thing?
If you want speak a language that isn't understood mostly you'll face
unexpected risults.
When you got started
[EMAIL PROTECTED] schrieb:
ok where does the 1 in the come from?
Conversion to floating point values, which have no precise
representation for all numbers that have such in the decimal system.
Read more on http://en.wikipedia.org/wiki/IEEE_754-1985
Regards,
Johannes
--
Wer etwas
Hello group,
I'm currently doing something like this:
import time
localtime = time.localtime(1234567890)
fmttime = %04d-%02d-%02d %02d:%02d:%02d % (localtime[0], localtime[1],
localtime[2], localtime[3], localtime[4], localtime[5])
print fmttime
For the third line there is, I suppose, some
Hans Nowak schrieb:
In this case, you can just use a slice, as localtime is a tuple:
fmttime = %04d-%02d-%02d %02d:%02d:%02d % localtime[:6]
Hope this helps! ^_^
Ahh, how cool! That's *exactly* what I meant with awesome Python magic :-)
Amazing language, I have to admit.
Regards,
David C. Ullrich schrieb:
-- care to tell us what a certain re.sub is, and
false in what way?
Read the OP.
Well, aren't you funny. Maybe you should have referenced the other
thread so one can find the OP?
Regards,
Johannes
--
Wer etwas kritisiert muss es noch lange nicht selber besser
Hello group,
I've run into a small problem with pgdb which is actually not PostgreSQL
specific - I just do not understand the Python syntax at one point.
I'm trying to initialize a connection to a PG database. So help(pgdb) says:
pgdb.connect(connect_string) - connection
Hello group,
I'm having a seemingly simple problem. I want to generate a hierarchy of
modules, like this one:
GenerationScripts/
GenerationScripts/dhcp
GenerationScripts/bind9
And the files:
GenerationScripts/dhcp/__init__.py
GenerationScripts/bind9/generator.py
Hello list,
since I've read so much about Python 3 and ran into some trouble which
was supposed to be fixed with 3k, I yesterday came around to compile it
and try it out.
To sum it up: It's awesome. All the promised things like Unicode support
just work, all significant changes in the lanugage
Hi group,
if I remember correctly, wasn't there a way to quickly iterate through
nested loops? Something like
a = { a, b, c }
b = { 4, 9, 13}
for (x, y) in someoperator(a, b):
print(x, y)
which would print all tuples of
a, 4
a, 9
a, 13
b, 4
b, 9
b, 13
c, 4
c, 9
c, 13
(not nececssarily
Hello group,
I'm porting some code of mine to Python 3. One class has the __cmp__
operator overloaded, but comparison doesn't seem to work anymore with that:
Traceback (most recent call last):
File ./parse, line 25, in module
print(x y)
TypeError: unorderable types: IP() IP()
Was there
[EMAIL PROTECTED] schrieb:
On Nov 20, 1:18 pm, Johannes Bauer [EMAIL PROTECTED] wrote:
Hello group,
I'm porting some code of mine to Python 3. One class has the __cmp__
operator overloaded, but comparison doesn't seem to work anymore with that:
Traceback (most recent call last):
File
Steve Holden schrieb:
If it's not present then it would be worth reporting it as a 3.0 bug -
there's still time to get it in, as the release isn't due until early
December.
Seems it was removed on purpose - I'm sure there was a good reason for
that, but may I ask why? Instead of the sleek
[EMAIL PROTECTED] schrieb:
I know it sounds ridiculous
Not only that - it also sounds as if there's spring break in Trollland.
Regards,
Johannes
--
Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit,
verlästerung von Gott, Bibel und mir und bewusster Blasphemie.
--
Hello group,
I'm having trouble reading a utf-16 encoded file with Python3.0. This is
my (complete) code:
#!/usr/bin/python3.0
class AddressBook():
def __init__(self, filename):
f = open(filename, r, encoding=utf16)
while True:
J Kenneth King schrieb:
It probably means what it says: that the input file contains characters
it cannot read using the specified encoding.
No, it doesn't. The file is just fine, just as the example.
Are you generating the file from python using a file object with the
same encoding? If
Terry Reedy schrieb:
Johannes Bauer wrote:
Hello group,
I'm having trouble reading a utf-16 encoded file with Python3.0. This is
my (complete) code:
what OS. This is often critical when you have a problem interacting
with the OS.
It's a 64-bit Linux, currently running:
Linux joeserver
[EMAIL PROTECTED] schrieb:
2 problems: endianness and trailing zer byte.
This works for me:
This is very strange - when using utf16, endianness should be detected
automatically. When I simply truncate the trailing zero byte, I receive:
Traceback (most recent call last):
File ./modify.py,
John Machin schrieb:
On Dec 6, 5:36 am, Johannes Bauer [EMAIL PROTECTED] wrote:
So UTF-16 has an explicit EOF marker within the text? I cannot find one
in original file, only some kind of starting sequence I suppose
(0xfeff). The last characters of the file are 0x00 0x0d 0x00 0x0a,
simple \r
John Machin schrieb:
He did. Ugly stuff using readline() :-) Should still work, though.
Well, well, I'm a C kinda guy used to while (fgets(b, sizeof(b), f))
kinda loops :-)
But, seriously - I find that whole while True: and if line ==
construct ugly as hell, too. How can reading a file line
Hello group,
is there anything like a frozen dict in Python3, so I could do a
foo = { FrozenDict({a : b}): 3 }
or something like that?
Regards,
Johannes
--
Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit,
verlästerung von Gott, Bibel und mir und bewusster Blasphemie.
Steven D'Aprano schrieb:
On Tue, 16 Dec 2008 17:59:30 +0100, Johannes Bauer wrote:
Hello group,
is there anything like a frozen dict in Python3, so I could do a
foo = { FrozenDict({a : b}): 3 }
or something like that?
If *all* you want is to use it as a key, then:
tuple(sorted
bearophileh...@lycos.com schrieb:
Johannes Bauer:
is there anything like a frozen dict in Python3, so I could do a
foo = { FrozenDict({a : b}): 3 }
You can adapt this code to Python3 (and post a new recipe? It may be
positive to create a new section of the Cookbook for Py3 only):
http
Aaron Brady schrieb:
This is basically an invitation for everyone to brainstorm. (No
hijackings, good humor digression ok.) Lastly, ...
Even if it took (as you mentioned) a semester of SQL studies - which it
does not - why do you think your syntax is easier? The only person your
proposed
Hello group,
I've come from C/C++ and am now trying to code some Python because I
absolutely love the language. However I still have trouble getting
Python code to run efficiently. Right now I have a easy task: Get a
file, split it up into a million chunks, count the most prominent
character in
James Mills schrieb:
I have tested this against a randomly generated
file from /dev/urandom (10M). Yes the Python
one is much slower, but I believe it's bebcause
the Python implementation is _correct_ where
teh C one is _wrong_ :)
The resulting test.bin.pgm from python is exactly
3.5M
Marc 'BlackJack' Rintsch schrieb:
f = open(sys.argv[1], r)
Mode should be 'rb'.
Check.
filesize = os.stat(sys.argv[1])[6]
`os.path.getsize()` is a little bit more readable.
Check.
print(Filesize : %d % (filesize)) print(Image size : %dx%d
% (width, height)) print(Bytes per
James Mills schrieb:
What does this little tool do anyway ?
It's very interesting the images it creates
out of files. What is this called ?
It has no particular name. I was toying around with the Princeton Cold
Boot Attack (http://citp.princeton.edu/memory/). In particular I was
interested in
Marc 'BlackJack' Rintsch schrieb:
On Fri, 09 Jan 2009 04:04:41 +0100, Johannes Bauer wrote:
As this was horribly slow (20 Minutes for a 2GB file) I coded the whole
thing in C also:
Yours took ~37 minutes for 2 GiB here. This just ~15 minutes:
Ah, ok... when implementing your suggestions
mk schrieb:
Johannes Bauer wrote:
Which takes about 40 seconds. I want the niceness of Python but a little
more speed than I'm getting (I'd settle for factor 2 or 3 slower, but
factor 30 is just too much).
This probably doesn't contribute much, but have you tried using Python
profiler
Curt Hash schrieb:
You just need to change your User-Agent so that Google doesn't know a
Python script is making the request:
Why would Google not send a response if the User-Agent header field is
not a recognized browser? I doubt that's what's happening and the OP
would just like the
Dear all,
I've some applciations which fetch HTML docuemnts off the web, parse
their content and do stuff with it. Every once in a while it happens
that the web site administrators put up files which are encoded in a
wrong manner.
Thus my Python script dies a horrible death:
File ./update_db,
Bruno Desthuilliers schrieb:
Is that possible? If so, how?
This might get you started:
help(str.decode)
decode(...)
S.decode([encoding[,errors]]) - object
Hmm, this would work nicely if I called decode explicitly - but what
I'm doing is:
#!/usr/bin/python3
for line in
Hello group,
with this following program:
#!/usr/bin/python3
import gzip
x = gzip.open(testdatei, wb)
x.write(ä)
x.close()
I get a broken .gzip file when decompressing:
$ cat testdatei |gunzip
ä
gzip: stdin: invalid compressed data--length error
As it only happens with UTF-8 characters, I
David schrieb:
If I want an octal I'll use oct()!
Explicit is better than implicit...
A leading 0 *is* explicit.
Implicit would be when some functions would interpret a 0 prefix as
octal and others wouldn't.
Regards,
Johannes
--
Meine Gegenklage gegen dich lautet dann auf bewusste
Hello list,
I'm having trouble with a incredibly simple sort of a list containing
ints and tuples:
def myorder(x):
if type(x) == int:
return x
else:
return x[0]
odata = sorted([ (a, b) for (a, b) in data[description].items() ],
key=myorder)
still
MRAB schrieb:
Johannes Bauer wrote:
Hello list,
I'm having trouble with a incredibly simple sort of a list containing
ints and tuples:
def myorder(x):
if type(x) == int:
return x
else:
return x[0]
odata = sorted([ (a, b) for (a, b) in data[description].items
Am 15.11.2010 18:27, schrieb Duncan Booth:
Comparing directly against True or False is error prone: a value in
Python can be false without actually being equal to False.
Well, you can always use is instead of ==, which makes a comparison
to True or False perfectly safe.
Regards,
Johannes
--
Hello group,
I'm developing a GUI application in Python and having a blast so far :-)
What I'd like to add: I want the GUI users to supply plugin scripts,
i.e. offer some kind of API. That is, I want the user to write short
Python pieces which look something like
import guiapp
class
Aaron Watters schrieb:
This was posted just after someone on the same
computer (somewhere in Texas)
tried and failed to inject some javascript
into the page using a comment.
Script-kid moron. Delete and enjoy your life.
I don't see how this comment is helpful to
me or anyone reading the
Hi group,
I'm confused, kind of. The application I'm writing currently reads data
from a FITS file and should display it on a gtk window. So far I have:
[...]
pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, width, height)
pb_pixels = pb.get_pixels_array()
print(type(fits_pixels))
MRAB schrieb:
type 'numpy.ndarray'
type 'array'
So now I want to copy the fits_pixels - pb_pixels. Doing
pb_pixels = fits_pixels
This simply makes pb_pixels refer to the same object as fits_pixels. It
doesn't copy the values into the existing pb_pixels object.
Oh okay, I was thinking of
Hi group,
I have a very simple about sets. This is a minimal example:
#!/usr/bin/python
class x():
def __init__(self, y):
self.__y = y
def __eq__(self, other):
return self.__y == other.__y
def __hash__(self):
return
Steven D'Aprano schrieb:
How do I do that at runtime with Python?
Untested:
[Code]
Hope this is useful.
Very, very, very useful. Works like a charm, just like that. Thanks a
whole bunch!
Kind regards,
Johannes
--
Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit,
Johannes Bauer schrieb:
Is there something like the getelement function? How can I do what I want?
One side note: The obvious trivial solution:
def findset(s, e):
for i in s:
if e == i:
return i
return None
is because of its complexity
Peter Otten schrieb:
class Grab:
def __init__(self, value):
self.search_value = value
def __hash__(self):
return hash(self.search_value)
def __eq__(self, other):
if self.search_value == other:
self.actual_value = other
return
Hello group,
I'm trying to write a function in Python which does the following: For a
number of arguments which are all lists, return a list (or generator)
which yields all tuples of combination. E.g:
foofunction()
# returns [ ]
foofunction([1, 2, 3])
# returns [ (1), (2), (3) ]
Hello group,
I just wanted to switch from Py3.0 to Py3.1. No luck here:
[...]
ar rc libpython3.1.a Python/_warnings.o Python/Python-ast.o
Python/asdl.o Python/ast.o Python/bltinmodule.o Python/ceval.o
Python/compile.o Python/codecs.o Python/errors.o Python/frozen.o
Python/frozenmain.o
Martin v. Löwis schrieb:
What can I do about that?
Remove the non-ASCII characters from db.h.
Ehh...
$ find -type f | grep -i db.h
./Modules/unicodename_db.h
./Modules/unicodedata_db.h
./Objects/unicodetype_db.h
There's no db.h file in the Python-3.1rc1 distribution. The ones above
contain
Hello group,
when I read in a XML document with the xml.dom.minidom parser and write
it out again, an attribute is lost:
Input:
?xml version=1.0 encoding=utf-8 ?
[...]
Output:
?xml version=1.0 ?
How can I fix this? Python is Python 3.0rc2 (r30rc2:67114, Nov 16 2008,
15:24:36)
Kind regards,
Stefan Behnel schrieb:
Johannes Bauer wrote:
when I read in a XML document with the xml.dom.minidom parser and write
it out again, an attribute is lost:
Input:
?xml version=1.0 encoding=utf-8 ?
[...]
Output:
?xml version=1.0 ?
How can I fix this?
You don't have to. UTF-8
Stefan Behnel schrieb:
Can I somehow force Python to generate it anyways?
Did you try passing encoding='UTF-8' on serialisation?
Uhm... nope - how can I do that?
I have software which
complains if an explicit encoding is missing...
Well, to parse XML, it's best to use an XML parser.
Stefan Behnel schrieb:
Johannes Bauer wrote:
Stefan Behnel schrieb:
Can I somehow force Python to generate it anyways?
Did you try passing encoding='UTF-8' on serialisation?
Uhm... nope - how can I do that?
Well, depends on what your code currently does.
Maybe you could use something
David Robinow schrieb:
On Thu, Jun 11, 2009 at 9:20 AM, Johannes Bauerdfnsonfsdu...@gmx.de wrote:
Well, I'm not speaking about my software :-) Actually it's Gnucash which
complains if the tag is not explicitly set. This is because they
appearently had a ancient version which did not specify
Stefan Behnel schrieb:
So I need to build hyperlinks (a elements) with href attribute and
replace the text elements (numbers) somehow.
Try lxml.html instead. It makes it really easy to do these things. For
example, you can use XPath to find all table cells that contain numbers:
Hello group,
I'm pretty despereate right now and apologize for my diffuse question in
advance - but I do not know how to continue right now.
I'm writing a GUI client (pygtk) which talks to a server (TCP/IP),
fetches pictures (FITS format) and displays them. This works nicely.
Now I have a
On 25.07.2013 07:48, Steven D'Aprano wrote:
Then you aren't looking very closely. d.keys() returns a set-like view
into the dict, which is great for comparing elements:
py d1 = dict.fromkeys([1, 2, 3, 4])
py d2 = dict.fromkeys([3, 4, 5, 6])
py d1.keys() d2.keys() # keys that are in both
On 21.08.2013 11:11, Ulrich Eckhardt wrote:
That said, there is never a need for deriving
from the Thread class, you can also use it to run a function without
that. That way is IMHO clearer because the threading.Thread instance is
not the thread, just like a File instance is not a file. Both
On 22.08.2013 00:50, Fábio Santos wrote:
That said, there is never a need for deriving
from the Thread class, you can also use it to run a function without
that. That way is IMHO clearer because the threading.Thread instance is
not the thread, just like a File instance is not a file. Both
On 22.08.2013 02:06, Ned Batchelder wrote:
I cannot tell whether you are trolling or are just new to this, but
you don't always have to use threads. You use threads when you need
multiple parts of your program running concurrently. Don't inherit
Thread if all you are doing is a simple object
On 24.10.2013 09:07, Chris Angelico wrote:
On Thu, Oct 24, 2013 at 4:22 PM, Paul Pittlerson menkomig...@gmail.com
wrote:
msg = cipher.encrypt(txt)
'|s\x08\xf2\x12\xde\x8cD\xe7u*'
msg = cipher.encrypt(txt)
'\xa1\xed7\xb8hl\x7f\xd7\xba\xed'
# etc
AES is a stream cipher;
No, it is
On 24.10.2013 07:22, Paul Pittlerson wrote:
What am I doing wrong?
You're not reinitializing the internal state of the crypto engine. When
you recreate cipher with the same IV every time, it will work.
Best regards,
Joe
--
Wo hattest Du das Beben nochmal GENAU vorhergesagt?
Zumindest
On 24.10.2013 09:33, Johannes Bauer wrote:
On 24.10.2013 07:22, Paul Pittlerson wrote:
What am I doing wrong?
You're not reinitializing the internal state of the crypto engine. When
you recreate cipher with the same IV every time, it will work.
Code that works:
#!/usr/bin/python3
import
Hi group,
in http://docs.python.org/3/reference/datamodel.html#customization the
doc reads:
There are no swapped-argument versions of these methods (to be used when the
left argument does not support the operation but the right argument does);
rather, __lt__() and __gt__() are each other’s
Am 28.10.2013 13:23, schrieb Chris Angelico:
On Mon, Oct 28, 2013 at 11:00 PM, Johannes Bauer dfnsonfsdu...@gmx.de wrote:
There are no swapped-argument versions of these methods (to be used when
the left argument does not support the operation but the right argument
does); rather, __lt__
On 04.09.2012 04:17, Steven D'Aprano wrote:
On average, string equality needs to check half the characters in the
string.
How do you arrive at that conclusion? When comparing two random strings,
I just derived
n = (256 / 255) * (1 - 256 ^ (-c))
where n is the average number of character
On 04.09.2012 20:07, Steven D'Aprano wrote:
A reasonable, conservative assumption is to calculate the largest
possible value of the average for random strings. That largest value
occurs when the alphabet is as small as possible, namely two characters.
In practice, strings come from a larger
On 04.09.2012 23:59, Chris Angelico wrote:
n = (256 / 255) * (1 - 256 ^ (-c))
where n is the average number of character comparisons and c. The
rationale as follows: The first character has to be compared in any
case. The second with a probability of 1/256, the third with 1/(256^2)
and so
On 05.09.2012 11:24, Johannes Bauer wrote:
Consider sorting a large dictionary. Sorting is in O(n log(n)), but this
assumes O(1) comparisons! If the comparison operation itself were in
O(n), the total sorting complexity would be O(n^2 log(n)), which is
definitely false. Most comparisons
On 05.09.2012 04:18, Neil Hodgson wrote:
The memcpy patch was controversial as it broke Adobe Flash which
assumed memcpy was safe like memmove.
Adobe Flash was broken before, making an assumption that is not
guaranteed by the standard. The patch only showed the problem.
Regards,
Johannes
On 05.09.2012 16:30, Steven D'Aprano wrote:
Since these are *completely different Ns*, you can't combine them to get
O(N**2 log N) as the overall algorithmic complexity. Doing so is sheer
nonsense. If you state it like this:
Yes, you are correct here.
You are making unjustified
On 05.09.2012 18:24, Steven D'Aprano wrote:
On Wed, 05 Sep 2012 16:51:10 +0200, Johannes Bauer wrote:
[...]
You are making unjustified assumptions about the distribution of
letters in the words. This might be a list of long chemical compounds
where the words typically differ only
On 06.09.2012 10:33, Steven D'Aprano wrote:
But you know, it really doesn't make a difference. Equality testing will
*still* be O(N) since the asymptomatic behaviour for sufficiently large
string comparisons will be bounded by O(N). Multiplicative constants
(half the string versus 0.001 of
On 06.09.2012 16:23, Dave Angel wrote:
On 09/06/2012 09:43 AM, Johannes Bauer wrote:
snip
Yes, worst-case is O(N), best case O(1). Average is O(n log n).
Can't see how you came up with an average of n log(n). Fourteen minutes
before you made this post, you demonstrated it was less than 2
On 06.09.2012 15:43, Johannes Bauer wrote:
Wrong, at least for randomized strings (i.e. every character with the
same probability). O(N) is worst-case, O(log N) is correct for
randomized strings.
^^
Here I write the right thing. Then further below...
Yes, worst-case is O(N), best case O(1
On 06.09.2012 16:23, Dave Angel wrote:
On 09/06/2012 09:43 AM, Johannes Bauer wrote:
snip
Yes, worst-case is O(N), best case O(1). Average is O(n log n).
Can't see how you came up with an average of n log(n). Fourteen minutes
before you made this post, you demonstrated it was less than 2
On 06.09.2012 16:39, Chris Angelico wrote:
In any case, it'll be far FAR more useful than arguing from
totally random, or random word selection, or anything.
Who's game?
Okay, patched against Python 3.2.3: http://pastebin.com/PRRN53P6
To invoke display of the stats, compare the string
On 06.09.2012 17:36, Johannes Bauer wrote:
pleasedumpstats
And against a XML-reading C code generator that uses mako:
strCmpEq 39670
strCmpLt 2766215
strCmpGt 2744002
strCmpTc 37430821
strCmpCc 14048656
Compared strings: 5549887
Equal: 0.7%
Average wordlength: 6.74 chars
Average
Hi there,
I'm currently looking for a good solution to the following problem: I
have two classes A and B, which interact with each other and which
interact with the user. Instances of B are always created by A.
Now I want A to call some private methods of B and vice versa (i.e. what
C++ friends
On 29.10.2012 17:47, Chris Angelico wrote:
The usual convention for private methods is a leading underscore on the name:
Yup, that's what I'm using.
It's only a convention, though; it doesn't make it hard to call
them, it just sends the message this is private, I don't promise that
it'll be
On 29.10.2012 17:52, Grant Edwards wrote:
By decleare them privide do you mean using __ASDF__ name-munging?
It sounds to me like you're just making life hard on yourself.
Gaah, you are right. I just noticed that using the single underscore
(as I do) does not restrict usage in any
Hi list,
I've these two minor problems which bothered me for quite some time,
maybe you can help me. I'm using Python 3.2.
For some project I have a component in its own package. Let's say the
structure looks like this:
pkg/__init__.py
pkg/Foo.py
pkg/Bar.py
Foo.py and Bar.py contain their
On 14.11.2012 01:41, Richard Baron Penman wrote:
I found the MD5 and SHA hashes slow to calculate.
Slow? For URLs? Are you kidding? How many URLs per second do you want to
calculate?
The builtin hash is fast but I was concerned about collisions. What
rate of collisions could I expect?
MD5
On 14.11.2012 02:39, Roy Smith wrote:
The next step is to reduce the number of bits you are encoding. You
said in another post that 1 collision in 10 million hashes would be
tolerable. So you need:
math.log(10*1000*1000, 2)
23.25349666421154
24 bits worth of key.
Nope :-)
Base64
On 14.11.2012 13:33, Dave Angel wrote:
Te birthday paradox could have been important had the OP stated his goal
differently. What he said was:
Ideally I would want to avoid collisions altogether. But if that means
significant extra CPU time then 1 collision in 10 million hashes would be
Hi list,
I have a problem with Python3.2's argparse module. The following sample:
parser = argparse.ArgumentParser(prog = sys.argv[0])
parser.add_argument(-enc, metavar = enc, nargs = +, type = str,
default = [ utf-8 ])
parser.add_argument(pattern, metavar = pattern, type = str, nargs = 1)
On 19.12.2012 15:23, wxjmfa...@gmail.com wrote:
I was using the German word Straße (Strasse) — German
translation from street — to illustrate the catastrophic and
completely wrong-by-design Unicode handling in Py3.3, this
time from a memory point of view (not speed):
On 19.12.2012 16:18, Johannes Bauer wrote:
How do those arbitrary numbers prove anything at all? Why do you draw
the conclusion that it's broken by design? What do you expect? You're
very vague here. Just to show how ridiculously pointless your numers
are, your example gives 84 on Python3.2
Hi group,
I've run into a problem using Python3.2 and sqlite3 db access that I
can't quite wrap my head around. I'm pretty sure there's a bug in my
program, but I can't see where. Help is greatly appreciated. I've
created a minimal example to demonstrate the phaenomenon (attached at
bottom).
On 19.12.2012 16:40, Chris Angelico wrote:
You may not be familiar with jmf. He's one of our resident trolls, and
he has a bee in his bonnet about PEP 393 strings, on the basis that
they take up more space in memory than a narrow build of Python 3.2
would, for a string with lots of BMP
On 20.12.2012 16:05, Chris Angelico wrote:
On Fri, Dec 21, 2012 at 1:52 AM, Johannes Bauer dfnsonfsdu...@gmx.de wrote:
def fetchmanychks(cursor):
cursor.execute(SELECT id FROM foo;)
while True:
result = cursor.fetchmany()
if len(result) == 0
Hi group,
it's somewhat OT here, but I have a puzzle to which I would like a
solution -- but I'm unsure how I should tackle the problem with Python.
But it's a fun puzzle, so maybe it'll be appreciated here.
The question is: How do you design a boolean circuit that contains at
most 2 NOT gates,
On 09.12.2013 14:25, Chris Angelico wrote:
I found this puzzle again and was thinking about: How would I code a
brute-force approach to this problem in Python?
Ooooh interesting!
Ha, I thought so too :-)
Well, here's a start: There's no value in combining the same value in
an AND or an
1 - 100 of 211 matches
Mail list logo