Re: sqlite question

2009-10-17 Thread Roger Binns
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Dennis Lee Bieber wrote: > I suspect, besides building an sqlite3.dll (if Windows), you might > have to modify the pysqlite DB-API adapter to support whatever new > arguments have been added to various calls (most like the db.connect() > paramete

Re: restriction on sum: intentional bug?

2009-10-17 Thread Steven D'Aprano
On Fri, 16 Oct 2009 18:01:41 -0700, Jon Clements wrote: > Sum should return a *numeric* result, it has no way to do anything > sensible > with strings -- that's up to the coder and I think it'd be an error in > Python > to not raise an error. That's obviously wrong in Python. Mathematically, su

Pretty Print Python Data Structures to HTML

2009-10-17 Thread Sam
I'm looking for something like the pprint module but that can take a Python data structure and turn it into HTML (or better xHTML). It would read through the data structure but instead of formatting it using spaces it would format it using either dd/dt or ordered/ unordered lists or even as a html

Re: restriction on sum: intentional bug?

2009-10-17 Thread Steven D'Aprano
On Fri, 16 Oct 2009 11:06:30 -0700, Jon Clements wrote: > For instance, sum(['1', '2', '3']); it's not completely unreasonable for > someone to expect > a result of 6. This is Python, not Perl -- Python never tries to perform numeric arithmetic on strings. '1'+'2' will return '12' and not 3. It

Re: multi-threaded performance

2009-10-17 Thread Antoine Pitrou
Le Sat, 17 Oct 2009 06:54:29 +0200, Dieter Maurer a écrit : > > It is also true that adding CPUs may in fact reduce performance for > compute bound multithreaded Python programs. While the additional > computational resources cannot be use by Python, the additional overhead > (switching between CP

using cx_freeze on linux

2009-10-17 Thread james27
hi.. im new to cx_freeze . i was searched much of time.but i couldn't found solution. i want to make exe file which can run on windows. is it possible to make windows exe file by use cx_freeze on linux? if anyone can help ,much appreciate. thanks -- View this message in context: http://www.nabb

Re: The rap against "while True:" loops

2009-10-17 Thread Steven D'Aprano
On Fri, 16 Oct 2009 18:30:50 +0100, Tim Rowe wrote: >> Also, using exceptions this way is a structured form of GOTO -- it's >> easy to abuse and turn it into spaghetti code. Actually, not that easy >> to abuse, because you can't jump back into the try block. It's more >> like a multi-level break o

Re: a splitting headache

2009-10-17 Thread Mensanator
On Oct 16, 11:41�pm, Paul Rubin wrote: > 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', '

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

2009-10-17 Thread Steven D'Aprano
On Thu, 15 Oct 2009 18:29:51 -0700, Eloff wrote: > I was just working with a generator for a tree that I wanted to skip the > first result (root node.) > > And it occurs to me, why do we need to do: > > import sys > from itertools import islice > > my_iter = islice(my_iter, 1, sys.maxint) > >

Re: Pretty Print Python Data Structures to HTML

2009-10-17 Thread Mensanator
On Oct 17, 2:25�am, Sam wrote: > I'm looking for something like the pprint module but that can take a > Python data structure and turn it into HTML (or better xHTML). > > It would read through the data structure but instead of formatting it > using spaces it would format it using either dd/dt or o

Re: How to schedule system calls with Python

2009-10-17 Thread [email protected]
And if you have this commands :alias ,ll ? This commands not working , see "sh: ll: command not found" and for "watch" and "top" need to use something to out from loops . On Oct 15, 11:15 pm, TerryP wrote: > On Oct 15, 7:42 pm, Jeremy wrote: > > > I need to write a Python script that will call

Re: Pretty Print Python Data Structures to HTML

2009-10-17 Thread Diez B. Roggisch
Sam schrieb: I'm looking for something like the pprint module but that can take a Python data structure and turn it into HTML (or better xHTML). It would read through the data structure but instead of formatting it using spaces it would format it using either dd/dt or ordered/ unordered lists or

Re: zipfile extracting png files corrupt

2009-10-17 Thread marek . rocki
Have you tried opening the zip file in binary mode? Regards, Marek -- http://mail.python.org/mailman/listinfo/python-list

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

2009-10-17 Thread Stef Mientki
Stephen Hansen wrote: although this is a very good explanation, and showing character encoding isn't that easy ;-) thanks very much ! Wasn't aware of the SQLite pragma. also thanks to the others who replied. cheers, Stef -- http://mail.python.org/mailman/listinfo/python-list

py2exe and croatian letters

2009-10-17 Thread Samir aluko...@work
I am making a simple program in Croatian. In the beginning I set "# - *- coding: cp1250 -*-" code and when i run it in Python shell it comes out fine, but when i compile it with py2exe he doesn't print out croatian letters but he prints out tottaly other letters. I checked the CMD and it supports c

Re: restriction on sum: intentional bug?

2009-10-17 Thread Christian Heimes
Alan G Isaac wrote: > On 10/16/2009 5:03 PM, Christian Heimes wrote: >> It's not going to happen. > > That's a prediction, not a justification. It's not a prediction, it's a statement. It's not going to happend because it violates Guido's gut feeling as well as the Zen of Python. -- http://mail

Re: restriction on sum: intentional misfeature?

2009-10-17 Thread Tim Chase
Carl Banks wrote: 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. Well python is already

Re: restriction on sum: intentional bug?

2009-10-17 Thread Tim Chase
Christian Heimes wrote: Alan G Isaac wrote: On 10/16/2009 5:03 PM, Christian Heimes wrote: It's not going to happen. That's a prediction, not a justification. It's not a prediction, it's a statement. It's not going to happend because it violates Guido's gut feeling as well as the Zen of Pyth

Re: print()

2009-10-17 Thread mattia
Il Fri, 16 Oct 2009 22:40:34 -0700, Dennis Lee Bieber ha scritto: > On Fri, 16 Oct 2009 23:39:38 -0400, Dave Angel > declaimed the following in gmane.comp.python.general: > > >> You're presumably testing this in the interpreter, which prints extra >> stuff. In particular, it prints the result

Re: putchar(8)

2009-10-17 Thread Dave Angel
Dave Angel wrote: 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 correct

Re: sqlite question

2009-10-17 Thread koranthala
On Oct 17, 12:18 pm, Roger Binns wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > Dennis Lee Bieber wrote: > >    I suspect, besides building an sqlite3.dll (if Windows), you might > > have to modify the pysqlite DB-API adapter to support whatever new > > arguments have been added to v

Re: restriction on sum: intentional misfeature?

2009-10-17 Thread Carl Banks
On Oct 17, 2:15 am, Tim Chase wrote: > Carl Banks wrote: > > 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 busines

Re: putchar(8)

2009-10-17 Thread mattia
Il Sat, 17 Oct 2009 06:48:10 -0400, Dave Angel ha scritto: > Dave Angel wrote: >> >> 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). >

Re: print()

2009-10-17 Thread Dave Angel
Grant Edwards wrote: On 2009-10-17, Dave Angel wrote: Except sys.stdout.write("hello") doesn't return 5. It returns None. I don't know what the OP is talking about when he says "prints the number of characters": You're right of course, I should have just tried it. I must have been t

Re: print()

2009-10-17 Thread mattia
Il Fri, 16 Oct 2009 21:04:08 +, mattia ha scritto: > 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! Another question (always py3). How can I print only the first numb

Re: restriction on sum: intentional bug?

2009-10-17 Thread Carl Banks
On Oct 16, 7:41 pm, Alan G Isaac wrote: > > 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 ou

Re: zipfile extracting png files corrupt

2009-10-17 Thread Dave Angel
[email protected] wrote: 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 done any analysis to see in what sense they are corrupt? For example, do text files work, but not binary ones? If the f

Re: Installation question 2.5.4

2009-10-17 Thread ryles
On Oct 17, 2:22 am, JimR wrote: > I completed the configure, the make and the make install.  However, the > last instruction in README is to perform > pkgmanager -a /usr/python > > As you may have guessed, Redhat does not have pkgmanager.  What can I do > to work-around this problem and get this l

Re: The rap against "while True:" loops

2009-10-17 Thread Tim Rowe
2009/10/17 Steven D'Aprano : > No, you have a fundamental misunderstanding. They're called exceptions, > not errors, because they represent exceptional cases. Often errors are > exceptional cases, but they're not the only sort of exceptional case. The whole reason for the mechanism, across all la

Re: using cx_freeze on linux

2009-10-17 Thread Diez B. Roggisch
james27 schrieb: hi.. im new to cx_freeze . i was searched much of time.but i couldn't found solution. i want to make exe file which can run on windows. is it possible to make windows exe file by use cx_freeze on linux? if anyone can help ,much appreciate. No, that's what py2exe *on windows* is

Re: using cx_freeze on linux

2009-10-17 Thread elca
thanks diez paul, Diez B. Roggisch-2 wrote: > > james27 schrieb: >> hi.. >> im new to cx_freeze . >> i was searched much of time.but i couldn't found solution. >> i want to make exe file which can run on windows. >> is it possible to make windows exe file by use cx_freeze on linux? >> if anyone

Re: Tracking down DLL load errors in Windows ?

2009-10-17 Thread Fred Pacquier
"Mark Tolonen" said : > That error message is returned from executables built with later > versions of Visual Studio (at least 2005 and 2008...not sure about > 2003). The Windows application event log will indicate what DLL is > missing. > > In addition to tools others have noted, depends.exe

Re: executing a function/method from a variable

2009-10-17 Thread Yves
Carsten Haese 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. Yes I agree, every time I use eval, I feel like the language is missing something, fair enough to shell type languages, but usually not the cas

Re: Rename file if it exists.

2009-10-17 Thread Stephen Reese
> Clearly, the os.path.isfile() is never returning true, because once it does, > you'll get a string error on the next line.  You need > >     fn = basename + "." + str(count) > > or something similar. > > Anyway, isfile() needs a complete path, there's no way it can guess what > directory you plan

Re: print()

2009-10-17 Thread Dave Angel
mattia wrote: Il Fri, 16 Oct 2009 21:04:08 +, mattia ha scritto: 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! Another question (always py3). How can I print

Re: py2exe and croatian letters

2009-10-17 Thread Benjamin Kaplan
On Sat, Oct 17, 2009 at 4:58 AM, Samir aluko...@work wrote: > I am making a simple program in Croatian. In the beginning I set "# - > *- coding: cp1250 -*-" code and when i run it in Python shell it comes > out fine, but when i compile it with py2exe he doesn't print out > croatian letters but he

Re: sqlite question

2009-10-17 Thread Diez B. Roggisch
Roger Binns schrieb: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Dennis Lee Bieber wrote: I suspect, besides building an sqlite3.dll (if Windows), you might have to modify the pysqlite DB-API adapter to support whatever new arguments have been added to various calls (most like the db.

Re: restriction on sum: intentional bug?

2009-10-17 Thread Aahz
In article <[email protected]>, Steven D'Aprano wrote: > >Mathematically, sum() is defined as the repeated application of the + >operator. In Python, the + operator is well-defined for strings and lists >as well as numbers. Since you can say "ab" + "cd" + "ef" and get a

Re: The rap against "while True:" loops

2009-10-17 Thread Aahz
In article , Tim Rowe wrote: > >The point is that an exception causes a change in program flow, so of >course they're used for flow control. It's what they do. The question >is in what cases it's appropriate to use them. Standard Python idiom: try: d[key] += value except KeyError: d[key

Re: print()

2009-10-17 Thread Dave Angel
mattia wrote: Il Fri, 16 Oct 2009 22:40:34 -0700, Dennis Lee Bieber ha scritto: On Fri, 16 Oct 2009 23:39:38 -0400, Dave Angel declaimed the following in gmane.comp.python.general: You're presumably testing this in the interpreter, which prints extra stuff. In particular, it prints

slicing return iter?

2009-10-17 Thread StarWing
hello everyone, I'm new here :-) sometimes I want to iterate a part of a sequence. but don't want to copy it. i.e. a = list(...) # now a is a list, and a[:] is another list, and so a[m:n] # now we do something with the 0~len(a)-3 elements of a for val in a[:-2]: #do something but, this w

Re: More & More Fun w/ Pics & MySQL

2009-10-17 Thread Victor Subervi
Let me clarify. This prints out "all sorts of crap", which means an image string, the image as a string, to the screen: print 'Content-type: image/jpeg' print 'Content-Encoding: base64' print print pic().encode('base64') print '' The following once upon a time printed images, but now it doesn't.

Re: print()

2009-10-17 Thread Lie Ryan
mattia wrote: Another question (always py3). How can I print only the first number after the comma of a division? e.g. print(8/3) --> 2.667 I just want 2.6 (or 2.66) Are you sure you don't want that to be 2.7 or 2.67? Then you can use: n = int(n * 10**2) / 10**2 else if 2.7 pr 2.67 is

umlauts

2009-10-17 Thread Arian Kuschki
Hi all this has been bugging me for a long time and I do not seem to be able to understand what to do. I always have problems when dealing input text that contains umlauts. Consider the following: In [1]: import urllib In [2]: f = urllib.urlopen("http://www.google.de/ig/api?weather=Muenchen";)

Re: More & More Fun w/ Pics & MySQL

2009-10-17 Thread Carsten Haese
Victor Subervi wrote: > Let me clarify. This prints out "all sorts of crap", which means an > image string, the image as a string, to the screen: > > print 'Content-type: image/jpeg' > print 'Content-Encoding: base64' > print > print pic().encode('base64') > print '' This has no hope of working,

Re: umlauts

2009-10-17 Thread Diez B. Roggisch
Arian Kuschki schrieb: Hi all this has been bugging me for a long time and I do not seem to be able to understand what to do. I always have problems when dealing input text that contains umlauts. Consider the following: In [1]: import urllib In [2]: f = urllib.urlopen("http://www.google.de/

Re: slicing return iter?

2009-10-17 Thread Arnaud Delobelle
On Oct 17, 3:40 pm, StarWing wrote: > hello everyone, I'm new here :-) > > sometimes I want to iterate a part of a sequence. but don't want to > copy it. i.e. > > a = list(...) > # now a is a list, and a[:] is another list, and so a[m:n] > # now we do something with the 0~len(a)-3 elements of a >

Re: umlauts

2009-10-17 Thread MRAB
Arian Kuschki wrote: Hi all this has been bugging me for a long time and I do not seem to be able to understand what to do. I always have problems when dealing input text that contains umlauts. Consider the following: In [1]: import urllib In [2]: f = urllib.urlopen("http://www.google.de/ig

Re: umlauts

2009-10-17 Thread StarWing
On 10月17日, 下午9时54分, Arian Kuschki wrote: > Hi all > > this has been bugging me for a long time and I do not seem to be able to > understand what to do. I always have problems when dealing input text that > contains umlauts. Consider the following: > > In [1]: import urllib > > In [2]: f = urllib.u

Re: py2exe and croatian letters

2009-10-17 Thread Mark Tolonen
"Samir aluko...@work" wrote in message news:ab6475d0-133c-478d-8f08-eafea0733...@j39g2000yqh.googlegroups.com... I am making a simple program in Croatian. In the beginning I set "# - *- coding: cp1250 -*-" code and when i run it in Python shell it comes out fine, but when i compile it with py2

Re: More & More Fun w/ Pics & MySQL

2009-10-17 Thread Victor Subervi
in line... On Sat, Oct 17, 2009 at 11:33 AM, Carsten Haese wrote: > Victor Subervi wrote: > > Let me clarify. This prints out "all sorts of crap", which means an > > image string, the image as a string, to the screen: > > > > print 'Content-type: image/jpeg' > > print 'Content-Encoding: base64' >

help to convert c++ fonction in python

2009-10-17 Thread Toff
hello I'm trying to convert 2 c++ functions in python they come from wpkg client https://wpkg.svn.sourceforge.net/svnroot/wpkg/wpkg-client/Sources/Components/XmlSettings.cpp they are CString CXmlSettings::Crypt(CString str) CString CXmlSettings::Decrypt(CString str) CAn someone help me? i

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

2009-10-17 Thread Mark Tolonen
"Mark Tolonen" wrote in message news:[email protected]... "Kee Nethery" wrote in message news:[email protected]... 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

Re: umlauts

2009-10-17 Thread Diez B. Roggisch
StarWing schrieb: On 10月17日, 下午9时54分, Arian Kuschki wrote: Hi all this has been bugging me for a long time and I do not seem to be able to understand what to do. I always have problems when dealing input text that contains umlauts. Consider the following: In [1]: import urllib In [2]: f = ur

Re: umlauts

2009-10-17 Thread Diez B. Roggisch
StarWing schrieb: On 10月17日, 下午9时54分, Arian Kuschki wrote: Hi all this has been bugging me for a long time and I do not seem to be able to understand what to do. I always have problems when dealing input text that contains umlauts. Consider the following: In [1]: import urllib In [2]: f = ur

Re: umlauts

2009-10-17 Thread Diez B. Roggisch
MRAB schrieb: Arian Kuschki wrote: Hi all this has been bugging me for a long time and I do not seem to be able to understand what to do. I always have problems when dealing input text that contains umlauts. Consider the following: In [1]: import urllib In [2]: f = urllib.urlopen("http://

Re: umlauts

2009-10-17 Thread Diez B. Roggisch
MRAB schrieb: Arian Kuschki wrote: Hi all this has been bugging me for a long time and I do not seem to be able to understand what to do. I always have problems when dealing input text that contains umlauts. Consider the following: In [1]: import urllib In [2]: f = urllib.urlopen("http://

Re: umlauts

2009-10-17 Thread StarWing
On 10月18日, 上午12时14分, MRAB wrote: > Arian Kuschki wrote: > > Hi all > > > this has been bugging me for a long time and I do not seem to be able to > > understand what to do. I always have problems when dealing input text that > > contains umlauts. Consider the following: > > > In [1]: import urllib

Re: umlauts

2009-10-17 Thread StarWing
On 10月18日, 上午12时50分, "Diez B. Roggisch" wrote: > StarWing schrieb: > > > > > On 10月17日, 下午9时54分, Arian Kuschki > > wrote: > >> Hi all > > >> this has been bugging me for a long time and I do not seem to be able to > >> understand what to do. I always have problems when dealing input text that > >

Re: slicing return iter?

2009-10-17 Thread StarWing
On 10月17日, 下午11时56分, Arnaud Delobelle wrote: > On Oct 17, 3:40 pm, StarWing wrote: > > > > > hello everyone, I'm new here :-) > > > sometimes I want to iterate a part of a sequence. but don't want to > > copy it. i.e. > > > a = list(...) > > # now a is a list, and a[:] is another list, and so a[m

Re: More & More Fun w/ Pics & MySQL

2009-10-17 Thread Carsten Haese
Victor Subervi wrote: > in line... > > On Sat, Oct 17, 2009 at 11:33 AM, Carsten Haese > wrote: > Why would turning a comment into a statement NOT make a difference?!? > > > You misunderstood. Leaving in the __commented__ line __commented__ and > __not__unco

Re: More & More Fun w/ Pics & MySQL

2009-10-17 Thread Lie Ryan
Carsten Haese wrote: 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? I'm testing my "psych

Re: slicing return iter?

2009-10-17 Thread Arnaud Delobelle
On Oct 17, 6:05 pm, StarWing wrote: > On 10月17日, 下午11时56分, Arnaud Delobelle wrote: > > thanks for attention :-) > > > Check the itertools module. > > > HTH > > > -- > > Arnaud > > I had checked it for serval times. maybe it's my inattention :-(. but > what i could find the nearest thing is iterto

Re: umlauts

2009-10-17 Thread Diez B. Roggisch
StarWing schrieb: On 10月18日, 上午12时50分, "Diez B. Roggisch" wrote: StarWing schrieb: On 10月17日, 下午9时54分, Arian Kuschki wrote: Hi all this has been bugging me for a long time and I do not seem to be able to understand what to do. I always have problems when dealing input text that contains u

Re: umlauts

2009-10-17 Thread I V
On Sat, 17 Oct 2009 18:54:10 +0200, Diez B. Roggisch wrote: > This is wierd. I looked at the site in FireFox - and it was displayed > correctly, including umlauts. Bringing up the info-dialog claims the > page is UTF-8, the XML itself says so as well (implicit, through the > missing declaration of

Re: umlauts

2009-10-17 Thread Arian Kuschki
Whoa, that was quick! Thanks for all the answers, I'll try to recapitulate >What does this show you in your interactive interpreter? > print "\xc3\xb6" >ö > >For me, it's o-umlaut, ö. This is because the above bytes are the >sequence for ö in utf-8. > >If this shows something else, you need t

Re: umlauts

2009-10-17 Thread Arian Kuschki
I just checked and I see the following in the headers: Content-Type text/xml; charset=UTF-8 Where does it say ISO-8859-1? On Sat 17, 20:57 +0200, I V wrote: > On Sat, 17 Oct 2009 18:54:10 +0200, Diez B. Roggisch wrote: > > > This is wierd. I looked at the site in FireFox - and it was displayed

Re: umlauts

2009-10-17 Thread I V
On Sat, 17 Oct 2009 21:24:59 +0330, Arian Kuschki wrote: > I just checked and I see the following in the headers: Content-Type > text/xml; charset=UTF-8 > > Where does it say ISO-8859-1? In the headers returned via urllib (and via wget). But checking in Firefox, it does indeed specify UTF-8 in t

Re: The rap against "while True:" loops

2009-10-17 Thread Paul Rubin
[email protected] (Aahz) writes: > Standard Python idiom: > > try: > d[key] += value > except KeyError: > d[key] = value > > Maybe you need to re-think "appropriate". But more recent style prefers: d = collections.defaultdict(int) ... d[key] += value -- http://mail.python.o

Re: umlauts

2009-10-17 Thread Mark Tolonen
"Diez B. Roggisch" wrote in message news:[email protected]... [snip] This is wierd. I looked at the site in FireFox - and it was displayed correctly, including umlauts. Bringing up the info-dialog claims the page is UTF-8, the XML itself says so as well (implicit, through the

Threading from a class

2009-10-17 Thread Someone Something
I'm trying to write a IRC client that has to have a method inside class Client that has to start a new thread that goes to run() which is in the same class. I'm not really understanding all the threading tutorials i've found. Can someone help? p.s. trying to use the threading module, not the threa

Re: More & More Fun w/ Pics & MySQL

2009-10-17 Thread Neo
Hi, Victor Subervi schrieb: > Let me clarify. This prints out "all sorts of crap", which means an > image string, the image as a string, to the screen: > > print 'Content-type: image/jpeg' > print 'Content-Encoding: base64' > print > print pic().encode('base64') > print '' > > The following on

Re: The rap against "while True:" loops

2009-10-17 Thread Aahz
In article <[email protected]>, Paul Rubin wrote: >[email protected] (Aahz) writes: >> >> Standard Python idiom: >> >> try: >> d[key] += value >> except KeyError: >> d[key] = value >> >> Maybe you need to re-think "appropriate". > >But m

Re: restriction on sum: intentional bug?

2009-10-17 Thread Mark Dickinson
On Oct 17, 3:27 pm, [email protected] (Aahz) wrote: > In article <[email protected]>, > Steven D'Aprano   wrote: > > (For the record, summing lists is O(N**2), and unlike strings, there's no > > optimization in CPython to avoid the slow behaviour.) > > Are you sure? The

Re: umlauts

2009-10-17 Thread Arian Kuschki
Hm yes, that is true. In Firefox on the other hand, the response header is "Content-Type text/xml; charset=UTF-8" On Sat 17, 13:16 -0700, Mark Tolonen wrote: > > "Diez B. Roggisch" wrote in message > news:[email protected]... > [snip] > >This is wierd. I looked at the site in Fi

Re: restriction on sum: intentional bug?

2009-10-17 Thread Aahz
In article <7e905311-c561-4b93-9414-f873e6fee...@j19g2000yqk.googlegroups.com>, Mark Dickinson wrote: > >For some reason that I don't really understand, the CPython source does >the equivalent of concat2 instead of concat3. See the builtin_sum >function in > >http://svn.python.org/view/python/tr

Re: print()

2009-10-17 Thread Dave Angel
Lie Ryan wrote: mattia wrote: Another question (always py3). How can I print only the first number after the comma of a division? e.g. print(8/3) --> 2.667 I just want 2.6 (or 2.66) Are you sure you don't want that to be 2.7 or 2.67? Then you can use: n = int(n * 10**2) / 10**2 else i

Re: restriction on sum: intentional bug?

2009-10-17 Thread Mark Dickinson
On Oct 17, 9:49 pm, [email protected] (Aahz) wrote: > Ahhh, I vaguely remember there being some discussion of this when sum() > was introduced -- I think that using InPlaceAdd would have caused bad > behavior when the initial list was referred to by multiple names. Ah yes. Good point. With my

Re: The rap against "while True:" loops

2009-10-17 Thread Paul Rubin
[email protected] (Aahz) writes: > > d = collections.defaultdict(int) > > ... > > d[key] += value > > That was a trivial example; non-trivial examples not addressed by > defaultdict are left as an exercise for the reader. Even in the "nontrivial" examples, I think avoiding the exception

Re: restriction on sum: intentional bug?

2009-10-17 Thread Alan G Isaac
On 10/17/2009 7:06 AM, Carl Banks wrote: I'm basically saying here is, by shutting out strings from sum, you don't really lose much in terms of duck typing, because duck typing wouldn't have been that helpful anyway. That boils down to an argument for type checking whenever you cannot imagine m

Re: umlauts

2009-10-17 Thread Neil Hodgson
The server is sniffing the User-Agent header to decide whether to send UTF-8 or ISO-8859-1. Try this code: import urllib2 r = urllib2.Request("http://www.google.de/ig/api?weather=Muenchen";, None, {"User-Agent":"Mozilla/5.0"}) f = urllib2.urlopen(r) i = f.info() print(i) xml = f.read()

Re: restriction on sum: intentional bug?

2009-10-17 Thread Carl Banks
On Oct 17, 2:22 pm, Alan G Isaac wrote: > On 10/17/2009 7:06 AM, Carl Banks wrote: > > > I'm basically saying here is, by shutting out strings from sum, > > you don't really lose much in terms of duck typing, because duck > > typing wouldn't have been that helpful anyway. > > That boils down to an

Re: slicing return iter?

2009-10-17 Thread Terry Reedy
StarWing wrote: > I had checked it for serval times. maybe it's my inattention :-(. but > what i could find the nearest thing is itertools.islice. but it can't > process negative index A negative index -n is an abbreviation for len(sequence) - n. Since iterables in general do not have a length,

Re: restriction on sum: intentional bug?

2009-10-17 Thread Mark Dickinson
On Oct 17, 9:49 pm, [email protected] (Aahz) wrote: > Ahhh, I vaguely remember there being some discussion of this when sum() > was introduced -- I think that using InPlaceAdd would have caused bad > behavior when the initial list was referred to by multiple names. Thanks for the pointer: I've

Re: help to convert c++ fonction in python

2009-10-17 Thread Tim Roberts
Toff wrote: > >I'm trying to convert 2 c++ functions in python > >they come from wpkg client >https://wpkg.svn.sourceforge.net/svnroot/wpkg/wpkg-client/Sources/Components/XmlSettings.cpp > >they are >CString CXmlSettings::Crypt(CString str) >CString CXmlSettings::Decrypt(CString str) > >CAn some

Re: The rap against "while True:" loops

2009-10-17 Thread Terry Reedy
Paul Rubin wrote: [email protected] (Aahz) writes: Standard Python idiom: try: d[key] += value except KeyError: d[key] = value Maybe you need to re-think "appropriate". But more recent style prefers: d = collections.defaultdict(int) ... d[key] += value Yes, the motivat

Re: help to convert c++ fonction in python

2009-10-17 Thread Tim Roberts
Toff wrote: > >I'm trying to convert 2 c++ functions in python > >they come from wpkg client >https://wpkg.svn.sourceforge.net/svnroot/wpkg/wpkg-client/Sources/Components/XmlSettings.cpp > >they are >CString CXmlSettings::Crypt(CString str) >CString CXmlSettings::Decrypt(CString str) > >CAn some

Re: The rap against "while True:" loops

2009-10-17 Thread Terry Reedy
Steven D'Aprano wrote: On Fri, 16 Oct 2009 18:30:50 +0100, Tim Rowe wrote: Also, using exceptions this way is a structured form of GOTO -- it's easy to abuse and turn it into spaghetti code. Actually, not that easy to abuse, because you can't jump back into the try block. It's more like a multi

Re: The rap against "while True:" loops

2009-10-17 Thread Paul Rubin
Terry Reedy writes: > >d[key] += value > > Yes, the motivation was to reduce 4 lines to 1 line for a common use > case, and not because of any sense of 'inappropriateness'. Reducing 4 confusing lines to 1 clear one is almost always appropriate. -- http://mail.python.org/mailman/listinfo/pyt

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

2009-10-17 Thread Terry Reedy
Aahz wrote: 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

Re: id( ) function question

2009-10-17 Thread Aahz
In article , Laszlo Nagy wrote: > >All right, I see your point now. So can we say, that the id function can >be used to tell if two mutable objects are different as long as they are >both alive during the comparison? Yes -- Aahz ([email protected]) <*> http://www.pythoncr

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

2009-10-17 Thread Aahz
In article , Terry Reedy wrote: >Aahz wrote: >> 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 probabl

Re: restriction on sum: intentional bug?

2009-10-17 Thread Aahz
In article , Mark Dickinson wrote: >On Oct 17, 9:49=A0pm, [email protected] (Aahz) wrote: >> >> Ahhh, I vaguely remember there being some discussion of this when sum() >> was introduced -- I think that using InPlaceAdd would have caused bad >> behavior when the initial list was referred to by

Re: print()

2009-10-17 Thread Terry Reedy
Gabriel Genellina wrote: Presumably he's using Python 3: And apparently not IDLE Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. p3> import sys p3> sys.stdout.write("hello") hello5

Re: executing a function/method from a variable

2009-10-17 Thread Terry Reedy
Yves wrote: What is the best way to execute a function which name is stored in a variable ? One standard way is a dict mapping names to function objects. >>> numfuncs = {'int':int, 'float':float} >>> f='int' >>> numfuncs[f]('33') 33 Since attributes gets mapped to a dict, this is similar to p

Re: restriction on sum: intentional bug?

2009-10-17 Thread Terry Reedy
Alan G Isaac wrote: 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. If you disagree with this, I think *you* are being silly. >> One could just as well argue that summing anything but n

Re: restriction on sum: intentional bug?

2009-10-17 Thread MRAB
Carl Banks wrote: On Oct 17, 2:22 pm, Alan G Isaac wrote: On 10/17/2009 7:06 AM, Carl Banks wrote: I'm basically saying here is, by shutting out strings from sum, you don't really lose much in terms of duck typing, because duck typing wouldn't have been that helpful anyway. That boils down t

Re: help to convert c++ fonction in python

2009-10-17 Thread geremy condra
On Sat, Oct 17, 2009 at 6:15 PM, Tim Roberts wrote: > Toff wrote: >> >>I'm trying to convert  2 c++ functions  in python >> >>they come from wpkg client >>https://wpkg.svn.sourceforge.net/svnroot/wpkg/wpkg-client/Sources/Components/XmlSettings.cpp >> >>they are >>CString CXmlSettings::Crypt(CStri

help to convert c++ fonction in python

2009-10-17 Thread geremy condra
On Sat, Oct 17, 2009 at 7:57 PM, David Robinow wrote: > On Sat, Oct 17, 2009 at 7:48 PM, geremy condra wrote: >> For the love of baby kittens, please, please, please tell me that >> you do not believe this securely encrypts your data. >  Yeah, I think it's pretty good. > Can you do better? > Tri

Re: Threading from a class

2009-10-17 Thread Someone Something
anyone? On Sat, Oct 17, 2009 at 4:26 PM, Someone Something wrote: > I'm trying to write a IRC client that has to have a method inside class > Client that has to start a new thread that goes to run() which is in the > same class. I'm not really understanding all the threading tutorials i've > foun

  1   2   >