Re: Tracking down DLL load errors in Windows ?

2009-10-16 Thread Mark Tolonen
"Fred P" wrote in message news:xns9ca5e52bec783pacmanr...@212.27.60.39... Hi, a bit of platform-specific advice sought here... I'm trying to diagnose one of those mysteries Windows is so fond of... Say that I have code that imports some binary Python module from site- packages (in this case,

Installation question 2.5.4

2009-10-16 Thread JimR
I just activated a new Mailman mailing list system on a Redhat virtual server. All was going well except the digests were not being delivered. The logged error was to the effect of decoding Unicode not being supported. In searching out this error, I found a reference that suggested upgrading

Re: how to write a unicode string to a file ?

2009-10-16 Thread Mark Tolonen
"Kee Nethery" wrote in message news:aaab63c6-6e44-4c07-b119-972d4f49e...@kagi.com... On Oct 16, 2009, at 5:49 PM, Stephen Hansen wrote: On Fri, Oct 16, 2009 at 5:07 PM, Stef Mientki wrote: snip The thing is, I'd be VERY surprised (neigh, shocked!) if Excel can't open a file that is in

Re: zipfile extracting png files corrupt

2009-10-16 Thread Gabriel Genellina
En Sat, 17 Oct 2009 02:22:03 -0300, escribió: Hi, I am using the zipfile in Python 2.4 to extract files from existing zips. It appears to work but the files extracted are corrupt. Have you tested the zip files with other tools? I can't spot anything obviously wrong in your code (except a te

Re: print()

2009-10-16 Thread Gabriel Genellina
En Sat, 17 Oct 2009 02:15:13 -0300, Grant Edwards escribió: On 2009-10-17, Dave Angel wrote: mattia wrote: Is there a way to print to an unbuffered output (like stdout)? I've seen that something like sys.stdout.write("hello") works but it also prints the number of characters! What the o

zipfile extracting png files corrupt

2009-10-16 Thread marks542004
Hi, I am using the zipfile in Python 2.4 to extract files from existing zips. It appears to work but the files extracted are corrupt. Here is my code : import zipfile import os, sys , shutil epath = "c:/ziptest/" fil = "J:/archives/xzips/duplicates/gothicfence_1470.zip" ferr = file((epath + "/err

Re: print()

2009-10-16 Thread Grant Edwards
On 2009-10-17, Dave Angel wrote: > mattia wrote: >> Is there a way to print to an unbuffered output (like stdout)? I've seen >> that something like sys.stdout.write("hello") works but it also prints >> the number of characters! >> >> > What the other responses (so far) didn't address is your

Re: python performance on Solaris

2009-10-16 Thread Dieter Maurer
Antoine Pitrou writes on Thu, 15 Oct 2009 16:25:43 + (UTC): > Le Wed, 14 Oct 2009 22:39:14 -0700, John Nagle a écrit : > > > > Note that multithreaded compute-bound Python programs really suck > > on multiprocessors. Adding a second CPU makes the program go slower, > > due to a lame mec

Re: a splitting headache

2009-10-16 Thread Paul Rubin
Mensanator writes: > Thanks, but what I wanted was > ['00','1','0','1','0','','00','1','0' '1']. >>> c = '00101000101' >>> list(''.join(g) for k,g in groupby(c)) ['00', '1', '0', '1', '0', '', '00', '1', '0', '1'] is really not that unnatural. -- http://mail.python.org/m

Re: Rename file if it exists.

2009-10-16 Thread Dave Angel
Stephen Reese wrote: The script is working and appending the date to newly uploaded files but it is not adding the count? Any recommendations? Is the problem due to os.path.isfile(fn): being just the file name and not the full path? Thanks. # strip leading path from file name to avoid

Re: a splitting headache

2009-10-16 Thread Mensanator
On Oct 16, 8:00�pm, Thomas wrote: > On Oct 15, 9:18�pm, Mensanator wrote: > > > > > > > All I wanted to do is split a binary number into two lists, > > a list of blocks of consecutive ones and another list of > > blocks of consecutive zeroes. > > > But no, you can't do that. > > > >>> c = '001000

Re: which "dictionary with attribute-style access"?

2009-10-16 Thread Aahz
In article , Andreas Balogh wrote: > >My question to the Python specialists: which one is the most correct? >Are there restrictions with regards to pickling or copy()? >Which one should I choose? What's your goal? I'd probably do the dirt simple myself: class AttrDict(dict): def __getattr_

Re: print()

2009-10-16 Thread Dave Angel
mattia wrote: Is there a way to print to an unbuffered output (like stdout)? I've seen that something like sys.stdout.write("hello") works but it also prints the number of characters! What the other responses (so far) didn't address is your comment about "prints the number of characters."

Re: putchar(8)

2009-10-16 Thread Dave Angel
Jason Tackaberry wrote: On Fri, 2009-10-16 at 12:01 -0700, gervaz wrote: Hi all, is there in python the equivalent of the C function int putchar (int c)? I need to print putchar(8). print '\x08' or: print chr(8) If I recall correctly, putchar() tak

Re: executing a function/method from a variable

2009-10-16 Thread Jon Clements
On Oct 17, 3:02 am, Yves wrote: > What is the best way to execute a function which name is stored in a variable > ? > > Right now I use an eval, but I'm wondering if there isn't a better way: > > Here is a simplified example, but what I use this for is to parse a formated > text file, and execute

Re: restriction on sum: intentional bug?

2009-10-16 Thread Alan G Isaac
Alan G Isaac gmail.com> writes: So of course join is better, as originally noted, but that does not constitute a reason to intentionally violate duck typing. On 10/16/2009 1:03 PM, Benjamin Peterson wrote: As Stephen pointed out, duck typing is not an absolute. I do not recall anyone sug

Re: SQL user function returning list for IN clause

2009-10-16 Thread pjcoup
On Oct 16, 9:50 am, Felix wrote: [snip] > I could create a new table matching each row in b to all values of > b.bar and use that to join but that would be inefficient and very > redundant. > [snip] Is foobar(b.bar) essentially static? (I'm guessing so if you considered this as an option). If so,

Re: executing a function/method from a variable

2009-10-16 Thread Carsten Haese
Yves wrote: > Right now I use an eval, but I'm wondering if there isn't a better way: There's (almost) always a better way than using eval. In this case, you should use getattr(). Here's your simplified example modified to use getattr: import sys class dummy(object): def __init__(self, arg):

Re: Are there any modules for IRC, that work with Python 3.1?

2009-10-16 Thread Ross Ridge
TerryP wrote: >Having recently been put into search for a new IRC client, and >everything I've thrown in the cauldron having become a >disappointment... Have you tried the IRC client script for Vim? Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [

executing a function/method from a variable

2009-10-16 Thread Yves
What is the best way to execute a function which name is stored in a variable ? Right now I use an eval, but I'm wondering if there isn't a better way: Here is a simplified example, but what I use this for is to parse a formated text file, and execute a different method depending on the patte

Re: Iterators

2009-10-16 Thread Simon Forman
On Fri, Oct 16, 2009 at 8:22 AM, Duncan Booth wrote: > Chris Rebert wrote: > >> Essentially, file iterators are dumb and don't keep track of where in >> the file the next line starts, instead relying on their associated >> file object to keep track of the current position in the file; the >> iter

Re: restriction on sum: intentional bug?

2009-10-16 Thread Alan G Isaac
On 10/16/2009 8:16 PM, Terry Reedy wrote: The fact that two or three people who agree on something agree on the thing that they agree on confirms nothing. One could just as well argue that summing anything but numbers is semantically incoherent, not correct. Certainly, my dictionary points in tha

Re: One class one file?

2009-10-16 Thread D'Arcy J.M. Cain
On Fri, 16 Oct 2009 19:53:37 -0400 Someone Something wrote: > I'm trying write a program that's going to be more than 100 lines or so but > I need it all in one class. Is there a painless way to have one class in two > files? I don't understand what the problem is with a 100 line class but if it

Re: a splitting headache

2009-10-16 Thread Carl Banks
On Oct 15, 6:57 pm, Ishwor Gurung wrote: > Too bad groupby is only available in Python2.6+ > Since you're here, any chance of getting your NDK team to look into > getting some small subset of STL, Boost into Android? Aren't Java collections bad enough? :) Carl Banks -- http://mail.python.org

Re: Rename file if it exists.

2009-10-16 Thread Stephen Reese
> This isn't working because the else: is dangling. And I think your logic is > flawed (I might be wrong of course) because you rename the *existing* file > instead of giving the new one a new data. > > Thus e.g. a link to the file (if it's a webserver) will suddenly deliver a > different file. I d

Re: how to write a unicode string to a file ?

2009-10-16 Thread Stephen Hansen
On Fri, Oct 16, 2009 at 6:02 PM, Kee Nethery wrote: > > On Oct 16, 2009, at 5:49 PM, Stephen Hansen wrote: > >> On Fri, Oct 16, 2009 at 5:07 PM, Stef Mientki >> wrote: >> > > snip > >> The thing is, I'd be VERY surprised (neigh, shocked!) if Excel can't open >> a file that is in UTF8-- it just m

Re: restriction on sum: intentional bug?

2009-10-16 Thread Jon Clements
On Oct 17, 1:16 am, Terry Reedy wrote: > Alan G Isaac wrote: > > > As Tim explained in detail, and as Peter > > explained with brevity, whether it will > > happen or not, it should happen.  This > > conversation has confirmed that current > > behavior is a wart: an error is raised > > despite corr

Re: a splitting headache

2009-10-16 Thread Thomas
On Oct 15, 9:18 pm, Mensanator wrote: > All I wanted to do is split a binary number into two lists, > a list of blocks of consecutive ones and another list of > blocks of consecutive zeroes. > > But no, you can't do that. > > >>> c = '001110' > >>> c.split('0') > > ['', '', '1', '', '', '', '1

Re: how to write a unicode string to a file ?

2009-10-16 Thread Kee Nethery
On Oct 16, 2009, at 5:49 PM, Stephen Hansen wrote: On Fri, Oct 16, 2009 at 5:07 PM, Stef Mientki wrote: snip The thing is, I'd be VERY surprised (neigh, shocked!) if Excel can't open a file that is in UTF8-- it just might need to be TOLD that its utf8 when you go and open the file, as

Re: set using alternative hash function?

2009-10-16 Thread Carl Banks
On Oct 15, 9:31 pm, Austin Bingham wrote: > Yes, what you've got there provides the interface of what I want. And > no doubt we could concoct countless ways to implement some version of > this. However, if set itself accepted an alternate hash function, then > I could do it with no extra overhead.

Re: More & More Fun w/ Pics & MySQL

2009-10-16 Thread Carsten Haese
Victor Subervi wrote: > I'm sorry. These scripts worked fine before and should have been > plug-and-play. I have wasted 2 frustrating weeks trying to figure out > why they don't work only to discover things that make no sense at all > that do the trick. I thought programming was straight-forward an

Re: how to write a unicode string to a file ?

2009-10-16 Thread Stephen Hansen
On Fri, Oct 16, 2009 at 5:07 PM, Stef Mientki wrote: Unfortunately, there is no simple answer to these questions. > Thanks guys, > I didn't know the codecs module, > and the codecs seems to be a good solution, > at least it can safely write a file. > But now I have to open that file in Excel 200

Re: How about adding slice notation to iterators/generators?

2009-10-16 Thread Carl Banks
On Oct 16, 2:28 pm, Eloff wrote: > As long as it breaks no rationally existing code, I can think of no > good reason why not to do this in a future python. You would burden everyone who writes a custom iterator to provide a __getitem__ method just because you're too lazy to type out the word isli

Re: How about adding slice notation to iterators/generators?

2009-10-16 Thread ryles
On Oct 16, 5:28 pm, Eloff wrote: > By giving iterators a default, overridable, __getitem__ that is just > syntactic sugar for islice, they would share a slightly larger > interface subset with the builtin container types. In a duck-typed > language like python, that's almost always a good thing.

Re: How about adding slice notation to iterators/generators?

2009-10-16 Thread Carl Banks
On Oct 16, 2:02 am, Bearophile wrote: > Terry Reedy: > > > 1. islice works with any iterator; generator method would only work with > > generators > > A slice syntax that's syntactic sugar for islice(some_iter,1,None) may > be added to all iterators. All custom iterators would then be burdened to

sqlite question

2009-10-16 Thread koranthala
Hi, I use sqlalchemy to use a sqlite db in my program. The program is working perfectly as of now. But now, a new requirement has come that the db has to be encrypted. I found two options while searching internet - SQLite Encryption Extension and Sqlite-Crypt. Now, buying the license is not a

Re: More & More Fun w/ Pics & MySQL

2009-10-16 Thread Victor Subervi
I'm sorry. These scripts worked fine before and should have been plug-and-play. I have wasted 2 frustrating weeks trying to figure out why they don't work only to discover things that make no sense at all that do the trick. I thought programming was straight-forward and "logical"...boy, am I disapp

Re: restriction on sum: intentional bug?

2009-10-16 Thread Terry Reedy
Alan G Isaac wrote: As Tim explained in detail, and as Peter explained with brevity, whether it will happen or not, it should happen. This conversation has confirmed that current behavior is a wart: an error is raised despite correct semantics. Ugly! The fact that two or three people who agre

Re: how to write a unicode string to a file ?

2009-10-16 Thread Stef Mientki
Stephen Hansen wrote: On Thu, Oct 15, 2009 at 4:43 PM, Stef Mientki > wrote: hello, By writing the following unicode string (I hope it can be send on this mailing list) Bücken to a file fh.write ( line ) I get the following err

Re: One class one file?

2009-10-16 Thread MRAB
Someone Something wrote: I'm trying write a program that's going to be more than 100 lines or so but I need it all in one class. Is there a painless way to have one class in two files? Python won't complain if you have more than 100 lines in one file, or even in one class in one file. There a

Re: restriction on sum: intentional bug?

2009-10-16 Thread Carl Banks
On Oct 16, 8:39 am, Alan G Isaac wrote: > I expected this to be fixed in Python 3: A word of advice: the Python maintainers don't regard anything that behaves as it is documented to as a "bug", no matter how wrong it seems. This is taken a lot more seriously than you would think. In future com

Re: More & More Fun w/ Pics & MySQL

2009-10-16 Thread Carsten Haese
Victor Subervi wrote: > I was trying all sorts of crap. I tried it without, too. Still didn't > work :( Please help us help you. "Still didn't work" tells us nothing. See http://catb.org/~esr/faqs/smart-questions.html for hints on how you can ask a questions in a way that makes them more likely to

Re: restriction on sum: intentional bug?

2009-10-16 Thread Carl Banks
On Oct 16, 12:40 pm, Tim Chase wrote: > Then I'm fine with sum() being smart enough to recognize this > horrid case and do the "right" thing by returning ''.join() > instead. You don't want Python to get into this business. Trust me. Just don't go there. If you want sum to call ''.join transpa

ftplib connection fails with multiple nics

2009-10-16 Thread Sean DiZazzo
Hi all, I'm trying to connect to an ftp site from a windows machine with two nics going to two different networks, but I keep getting the below exception: Traceback (most recent call last): File "ftp.pyo", line 70, in connect File "ftp.pyo", line 17, in __init__ File "ftplib.pyo", line 131,

One class one file?

2009-10-16 Thread Someone Something
I'm trying write a program that's going to be more than 100 lines or so but I need it all in one class. Is there a painless way to have one class in two files? -- http://mail.python.org/mailman/listinfo/python-list

Re: restriction on sum: intentional bug?

2009-10-16 Thread Carl Banks
On Oct 16, 9:59 am, Tim Chase wrote: > So I agree with Alan & Peter that this creates an unfortunate > language wart among (as Peter aptly puts it) "consenting adults". Perhaps, BUT... If, say, you were to accept that Python is going to guard against a small number of especially bad cases, this

Re: restriction on sum: intentional bug?

2009-10-16 Thread ryles
On Oct 16, 11:39 am, Alan G Isaac wrote: > I expected this to be fixed in Python 3: > > >>> sum(['ab','cd'],'') > > Traceback (most recent call last): >    File "", line 1, in > TypeError: sum() can't sum strings [use ''.join(seq) instead] Then you probably haven't read through these discussions

Re: restriction on sum: intentional bug?

2009-10-16 Thread Alan G Isaac
On 10/16/2009 5:03 PM, Christian Heimes wrote: It's not going to happen. That's a prediction, not a justification. As Tim explained in detail, and as Peter explained with brevity, whether it will happen or not, it should happen. This conversation has confirmed that current behavior is a wart:

Re: More & More Fun w/ Pics & MySQL

2009-10-16 Thread Victor Subervi
I was trying all sorts of crap. I tried it without, too. Still didn't work :( V On Fri, Oct 16, 2009 at 4:42 PM, Carsten Haese wrote: > Victor Subervi wrote: > > [snip...] > > > > print 'Content-type: image/jpeg' > > print 'Content-Encoding: base64' > > print > > print pic().encode('base64') > >

Re: print()

2009-10-16 Thread TerryP
On Oct 16, 9:04 pm, mattia wrote: > Is there a way to print to an unbuffered output (like stdout)? I've seen > that something like sys.stdout.write("hello") works but it also prints > the number of characters! http://docs.python.org/3.1/library/functions.html#print a suitable object passed that

Re: How about adding slice notation to iterators/generators?

2009-10-16 Thread Eloff
On Oct 16, 3:54 am, Terry Reedy wrote: > There is already an obvious standard way to do this. > > it = > next(it) #toss first item > for item in it: >   > That fails if there is no first item. You're taking one corner case and saying there's an easy way to do it, which is more or less true,

Re: Spawning Cmd Window via Subprocess

2009-10-16 Thread TerryP
On Oct 16, 8:15 pm, D wrote: > Hello, > > I would like to be able to spawn a new CMD window (specifing size, > color and placement of the window),  and write to it separately. > Specifically, I have a backup program that displays each file backed > up in the main window, and I would like to spawn

Re: The rap against "while True:" loops

2009-10-16 Thread Russ P.
On Oct 10, 1:15 pm, kj wrote: > I'm coaching a group of biologists on basic Python scripting.  One > of my charges mentioned that he had come across the advice never > to use loops beginning with "while True".  Of course, that's one > way to start an infinite loop, but this seems hardly a sufficie

Re: print()

2009-10-16 Thread Chris Rebert
On Fri, Oct 16, 2009 at 2:04 PM, mattia wrote: > Is there a way to print to an unbuffered output (like stdout)? Just follow your prints or stdout.write()s with calls to stdout.flush() to flush the buffer. You could alternatively use the -u option to the python interpreter to make the standard st

Re: Rename file if it exists.

2009-10-16 Thread Stephen Reese
> This isn't working because the else: is dangling. And I think your logic is > flawed (I might be wrong of course) because you rename the *existing* file > instead of giving the new one a new data. > > Thus e.g. a link to the file (if it's a webserver) will suddenly deliver a > different file. I d

print()

2009-10-16 Thread mattia
Is there a way to print to an unbuffered output (like stdout)? I've seen that something like sys.stdout.write("hello") works but it also prints the number of characters! -- http://mail.python.org/mailman/listinfo/python-list

Re: Tracking down DLL load errors in Windows ?

2009-10-16 Thread Fred Pacquier
Christian Heimes said : > Fred P wrote: >> Is there any tool and/or methodology I could use to at least pinpoint >> the exact DLL that libpyexiv2 is failing to load, and ideally also >> the reason why ?... > > The depencency walker http://www.dependencywalker.com/ works fine for > me. I'd neve

Re: restriction on sum: intentional bug?

2009-10-16 Thread Christian Heimes
Alan G Isaac schrieb: > On 10/16/2009 3:40 PM, Tim Chase wrote: >> What's always wrong is giving me an *error* when the semantics are >> perfectly valid. > > > Exactly. > Which is why I expected this to be fixed in Python 3. It's not going to happen. Christian -- http://mail.python.org/mailma

Re: More & More Fun w/ Pics & MySQL

2009-10-16 Thread Carsten Haese
Victor Subervi wrote: > [snip...] > > print 'Content-type: image/jpeg' > print 'Content-Encoding: base64' > print > print pic().encode('base64') > print '' > > [snip...] Why are you printing "" at the end of a page that is supposed to be a base64-encoded JPEG file? -- Carsten Haese http://informi

Re: how to write a unicode string to a file ?

2009-10-16 Thread Stephen Fairchild
Stef Mientki wrote: > hello, > > By writing the following unicode string (I hope it can be send on this > mailing list) > > Bücken > > to a file > > fh.write ( line ) > > I get the following error: > > UnicodeEncodeError: 'ascii' codec can't encode character u'\xfc' in > position

Re: Rename file if it exists.

2009-10-16 Thread Diez B. Roggisch
Stephen Reese schrieb: The script below uploads files to a web server. Currently it overwrites a file if it already exists. I'm instead trying to rename the old file with an appended date/timestamp before the new file is uploaded. I *think* I have the idea down but it's not be implemented in the

Re: id( ) function question

2009-10-16 Thread Erik Max Francis
Mel wrote: True, I don't see that exact expression going wrong. The actual poster, trimmed for that post, used to go: def broadcast (self, message): for p in players: if p is not self: p.send (message) This use of `is` is fine. For my fears to come tr

Re: restriction on sum: intentional bug?

2009-10-16 Thread Alan G Isaac
On 10/16/2009 3:40 PM, Tim Chase wrote: What's always wrong is giving me an *error* when the semantics are perfectly valid. Exactly. Which is why I expected this to be fixed in Python 3. Alan Isaac -- http://mail.python.org/mailman/listinfo/python-list

Spawning Cmd Window via Subprocess

2009-10-16 Thread D
Hello, I would like to be able to spawn a new CMD window (specifing size, color and placement of the window), and write to it separately. Specifically, I have a backup program that displays each file backed up in the main window, and I would like to spawn and continually update a second CMD windo

Re: The rap against "while True:" loops

2009-10-16 Thread Bearophile
Paul Rubin: >  http://scholar.google.com/scholar?cluster=17368311454828547380 > > Keep in mind that the article is 35 years old though, and is purely > imperative.  Lots of stuff done with cockamamie looping constructs is > more cleanly done with Python generators, itertools, higher-order > functi

Re: restriction on sum: intentional bug?

2009-10-16 Thread Tim Chase
Stephen Hansen wrote: There really is just a right way verses a wrong way to join strings together; using + is always the wrong way. Sometimes that level of 'wrong' is so tiny that no one cares, like if you are using it to join together two small strings. But when joining together a sequence of s

Re: An assessment of Tkinter and IDLE

2009-10-16 Thread Aahz
In article <87ljjhq7y7@benfinney.id.au>, Ben Finney wrote: >TerryP writes: >> >> One thing you should also learn about me, is I do not deal in >> absolutes. > >What, *never*? Well, hardly ever. -- Aahz (a...@pythoncraft.com) <*> http://www.pythoncraft.com/ "To me vi is

Rename file if it exists.

2009-10-16 Thread Stephen Reese
The script below uploads files to a web server. Currently it overwrites a file if it already exists. I'm instead trying to rename the old file with an appended date/timestamp before the new file is uploaded. I *think* I have the idea down but it's not be implemented in the script correctly. Any hin

More & More Fun w/ Pics & MySQL

2009-10-16 Thread Victor Subervi
Hi; Okay, here's the code: #! /usr/bin/python import cgitb; cgitb.enable() import MySQLdb import cgi import sys,os sys.path.append(os.getcwd()) from login import login def pic(): user, passwd, db, host = login() form = cgi.FieldStorage() db = MySQLdb.connect(host, user, passwd, db) cursor=

Re: putchar(8)

2009-10-16 Thread Jason Tackaberry
On Fri, 2009-10-16 at 12:01 -0700, gervaz wrote: > Hi all, is there in python the equivalent of the C function int putchar > (int c)? I need to print putchar(8). >>> print '\x08' or: >>> print chr(8) -- http://mail.python.org/mailman/listinfo/python-list

Re: The rap against "while True:" loops

2009-10-16 Thread Aahz
In article , Tim Rowe wrote: > >The understood meaning of throwing an exception is to say "something >happened that shouldn't have". If one uses it when something has >happened that *should* have, because it happens to have the right >behaviour (even if the overhead doesn't matter), then one is >

putchar(8)

2009-10-16 Thread gervaz
Hi all, is there in python the equivalent of the C function int putchar (int c)? I need to print putchar(8). Thanks, Mattia -- http://mail.python.org/mailman/listinfo/python-list

putchar(8)

2009-10-16 Thread gervaz
Hi all, is there a pythonic way to have the -- http://mail.python.org/mailman/listinfo/python-list

cx_freeze install_exe error

2009-10-16 Thread james27
hello im currently installed cx_freeze on linux. and want to make win32 exe file on linux by use cx_freeze. and then will distribute on widows platform. one of my problem is ,i can build with no problem. but whenever i run,it something weird error message was show. follow is my log file. anybody c

Re: restriction on sum: intentional bug?

2009-10-16 Thread Ethan Furman
Jon Clements wrote: On Oct 16, 5:59 pm, Tim Chase wrote: Stephen Hansen wrote: Why doesn't duck typing apply to `sum`? Because it would be so hideously slow and inefficient that it'd be way too easy a way for people to program something they think should work fine but really doesn't... al

Re: set using alternative hash function?

2009-10-16 Thread Anthony Tolle
On Oct 16, 12:24 pm, Ethan Furman wrote: > [snip] > As for what you want:  No, it's not currently possible.  If it's so big > a deal that the various methods presented don't meet with your approval, > break out the C and write your own.  Then you could give that back to > the community instead of

Re: restriction on sum: intentional bug?

2009-10-16 Thread Jon Clements
On Oct 16, 5:59 pm, Tim Chase wrote: > Stephen Hansen wrote: > >> Why doesn't duck typing apply to `sum`? > > > Because it would be so hideously slow and inefficient that it'd be way too > > easy a way for people to program something they think should work fine but > > really doesn't... alternativ

Re: restriction on sum: intentional bug?

2009-10-16 Thread Stephen Hansen
On Fri, Oct 16, 2009 at 9:59 AM, Tim Chase wrote: > Stephen Hansen wrote: > >> Why doesn't duck typing apply to `sum`? >>> >> >> Because it would be so hideously slow and inefficient that it'd be way too >> easy a way for people to program something they think should work fine but >> really doesn'

Re: The rap against "while True:" loops

2009-10-16 Thread Tim Rowe
2009/10/15 Steven D'Aprano : > Setting up a try...except block is cheap in Python. According to my > tests, the overhead is little more than that of a single pass statement. > > But actually raising and catching the exception is not cheap. If you use > a lot of exceptions for flow control, perform

Re: SQL user function returning list for IN clause

2009-10-16 Thread Peter Otten
Felix wrote: >> Define a function foobar_contains() as follows: >> >> def foobar_contains(foo, bar): >> return foo in foobar(bar) >> >> and change the query to >> >> select * from table a, table b where foobar_contains(a.foo, b.bar) > > I thought about that (see above), but it would not use an in

Re: set using alternative hash function?

2009-10-16 Thread Ethan Furman
Austin Bingham wrote: On Thu, Oct 15, 2009 at 7:49 PM, Ethan Furman wrote: Austin Bingham wrote: I'm feeling really dense about now... What am I missing? What you're missing is the entire discussion up to this point. I was looking for a way to use an alternative uniqueness criteria in a set

Re: The rap against "while True:" loops

2009-10-16 Thread Tim Rowe
2009/10/15 Steven D'Aprano : >> And with enough static analysis to guarantee that the break will be >> reached? I think it would be a bit much to expect Python to solve the >> halting problem! Not to what I thought was being proposed -- it seemed to make the break mandatory, not merely the only c

Re: SQL user function returning list for IN clause

2009-10-16 Thread Felix
> > Rewriting the query to say > > select * from table a, table b where foobar_predicate(a.foo, b.bar) > > would work (foobar_predicate checks if a.foo is in foobar(b.bar). But > > it does not allow to use an index on a.foo > Define a function foobar_contains() as follows: > > def foobar_contains(

Re: SQL user function returning list for IN clause

2009-10-16 Thread Peter Otten
Felix wrote: > I am using the Python SQLite3 interface, but the question is probably > general to python and SQL. > > I want to run a query like > > select * from table a, table b where a.foo IN foobar(b.bar) > > where foobar is a user function (registered by create_function in > pysqlite3) ret

Re: restriction on sum: intentional bug?

2009-10-16 Thread Benjamin Peterson
Alan G Isaac gmail.com> writes: > So of course join is better, as originally noted, > but that does not constitute a reason to intentionally > violate duck typing. As Stephen pointed out, duck typing is not an absolute. -- http://mail.python.org/mailman/listinfo/python-list

Re: restriction on sum: intentional bug?

2009-10-16 Thread Benjamin Peterson
MRAB mrabarnett.plus.com> writes: > It checks to see whether you're trying to sum strings, so it's already > treating them as a special case. Why can't it just use str.join > internally instead in that case instead of raising an exception? Because that violates explicit is better than implicit.

Re: restriction on sum: intentional bug?

2009-10-16 Thread Tim Chase
Stephen Hansen wrote: Why doesn't duck typing apply to `sum`? Because it would be so hideously slow and inefficient that it'd be way too easy a way for people to program something they think should work fine but really doesn't... alternatively, the function would have to do two /completely/ dif

Re: Yet Another Pic Problem

2009-10-16 Thread Victor Subervi
Well, I've spent the last 2 days chasing my tail just to discover that there was some screwy python deal going on. The following code works: sql = "update productsX set Name='%s', Title='%s', Description='%s', Price='%s', Bedrooms='%s', Bathrooms='%s', Conditions='%s', Acreage='%s', Construc

SQL user function returning list for IN clause

2009-10-16 Thread Felix
I am using the Python SQLite3 interface, but the question is probably general to python and SQL. I want to run a query like select * from table a, table b where a.foo IN foobar(b.bar) where foobar is a user function (registered by create_function in pysqlite3) returning a list of integers. Howev

Re: re.sub question (regular expressions)

2009-10-16 Thread MRAB
Chris Seberino wrote: What does this line do?... input_ = re.sub("([a-zA-Z]+)", '"\\1"', input_) Why don't you try it? Does it remove parentheses from words? e.g. (foo) -> foo ??? No, it puts quotes around them. I'd like to replace [a-zA-Z] with \w but \w makes it blow up. In other word

Re: re.sub question (regular expressions)

2009-10-16 Thread Jean-Michel Pichavant
Chris Seberino wrote: What does this line do?... input_ = re.sub("([a-zA-Z]+)", '"\\1"', input_) Does it remove parentheses from words? e.g. (foo) -> foo ??? I'd like to replace [a-zA-Z] with \w but \w makes it blow up. In other words, re.sub("(\w+)", '"\\1"', input_) blows up. Why? cs

Re: a splitting headache

2009-10-16 Thread Mensanator
On Oct 16, 10:30�am, John Posner wrote: > Mensenator said: > > c = '001110' > c.split('0') > > > ['', '', '1', '', '', '', '11', ''] > > > Ok, the consecutive delimiters appear as empty strings for > > reasons unknown (except for the first one). Except when they > > start or end the

Re: Iterators

2009-10-16 Thread Stephen Hansen
On Fri, Oct 16, 2009 at 9:24 AM, Harald Kraemer wrote: > Stephen Hansen wrote: > Nothing 'dumb' or 'smart' about it: it is simply that a file object is > >> already an iterator. Trying to create an iterator from an existing >>> iterator >>> in Python never duplicates the iterator. >>> >>> >>> f

Re: struct curiosity

2009-10-16 Thread pjcoup
Yes, this is basically what I expected as well. I would have expected some size that you can coax gcc to give, either 12 (as here), or 10 (with directives). Thanks to everyone for the responses! Pete On Oct 16, 4:30 am, Peter Otten <__pete...@web.de> wrote: > > I would have expected "native size

re.sub question (regular expressions)

2009-10-16 Thread Chris Seberino
What does this line do?... input_ = re.sub("([a-zA-Z]+)", '"\\1"', input_) Does it remove parentheses from words? e.g. (foo) -> foo ??? I'd like to replace [a-zA-Z] with \w but \w makes it blow up. In other words, re.sub("(\w+)", '"\\1"', input_) blows up. Why? cs -- http://mail.python.org/m

Re: restriction on sum: intentional bug?

2009-10-16 Thread MRAB
Stephen Hansen wrote: On Fri, Oct 16, 2009 at 8:39 AM, Alan G Isaac > wrote: I expected this to be fixed in Python 3: sum(['ab','cd'],'') Traceback (most recent call last): File "", line 1, in TypeError: sum() can't sum strings

Re: Iterators

2009-10-16 Thread Harald Kraemer
Stephen Hansen wrote: On Fri, Oct 16, 2009 at 5:22 AM, Duncan Booth wrote: Chris Rebert wrote: > Essentially, file iterators are dumb and don't keep track of where in > the file the next line starts, [snip] Nothing 'dumb' or 'smart' about it: it is simply that a file object is alread

Re: restriction on sum: intentional bug?

2009-10-16 Thread Peter Otten
Alan G Isaac wrote: > I expected this to be fixed in Python 3: > sum(['ab','cd'],'') > Traceback (most recent call last): >File "", line 1, in > TypeError: sum() can't sum strings [use ''.join(seq) instead] > > Of course it is not a good way to join strings, > but it should work, shoul

Re: Iterators

2009-10-16 Thread Aahz
In article , Duncan Booth wrote: >Chris Rebert wrote: >> >> Essentially, file iterators are dumb and don't keep track of where in >> the file the next line starts, instead relying on their associated >> file object to keep track of the current position in the file; the >> iterator's state is lit

Re: restriction on sum: intentional bug?

2009-10-16 Thread Alan G Isaac
Alan G Isaac schrieb: I expected this to be fixed in Python 3: sum(['ab','cd'],'') Traceback (most recent call last): File "", line 1, in TypeError: sum() can't sum strings [use ''.join(seq) instead] Of course it is not a good way to join strings, but it should work, should it not? Natur

  1   2   >