Re: How to check the exists of a name?

2009-10-17 Thread David
Il Sat, 17 Oct 2009 23:43:36 -0700 (PDT), StarWing ha scritto: > I got a idea, use a try...except statement. there are another way to > do it ? > > (I just curious now, because I solve my problem in another way :-) locals().has_key(myname) globals().has_key(myname) D. -- http://mail.python.or

Re: How to check the exists of a name?

2009-10-17 Thread StarWing
On 10月18日, 下午2时37分, Chris Rebert wrote: > On Sat, Oct 17, 2009 at 11:30 PM, StarWing wrote: > > Sometimes I want to make a simple flags. and i need to check there is > > a name in current scope or not (that is, we can visit this name, no > > matter where is it). and how to do that in python? > >

Re: How to check the exists of a name?

2009-10-17 Thread David
Il Sat, 17 Oct 2009 23:30:02 -0700 (PDT), StarWing ha scritto: > Sometimes I want to make a simple flags. and i need to check there is > a name in current scope or not (that is, we can visit this name, no > matter where is it). and how to do that in python? Just use it in a try..except block. tr

Re: The rap against "while True:" loops

2009-10-17 Thread Paul Rubin
Steven D'Aprano writes: > For the record, the four lines Paul implies are "confusing" are: > > try: > d[key] += value > except KeyError: > d[key] = value Consider what happens if the computation of "key" or "value" itself raises KeyError. -- http://mail.python.org/mailman/listinfo/pytho

Re: How to check the exists of a name?

2009-10-17 Thread Chris Rebert
On Sat, Oct 17, 2009 at 11:30 PM, StarWing wrote: > Sometimes I want to make a simple flags. and i need to check there is > a name in current scope or not (that is, we can visit this name, no > matter where is it). and how to do that in python? You should avoid needing to do that in the first pla

How to check the exists of a name?

2009-10-17 Thread StarWing
Sometimes I want to make a simple flags. and i need to check there is a name in current scope or not (that is, we can visit this name, no matter where is it). and how to do that in python? -- http://mail.python.org/mailman/listinfo/python-list

Re: weekdays in range

2009-10-17 Thread Ben Finney
Jive Dadson writes: > Can someone think of an easy way to calculate the number of weekdays > between two calendar dates (in Python)? That depends on what you mean by “weekdays”. >>> import datetime >>> begin_date = datetime.date(2009, 10, 9) >>> end_date = datetime.date(2009, 10, 22

Re: help to convert c++ fonction in python

2009-10-17 Thread Toff
On 18 oct, 02:13, geremy condra wrote: > 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 t

Re: list to tuple and vice versa

2009-10-17 Thread StarWing
On 10月18日, 下午1时32分, Ben Finney wrote: > StarWing writes: > > On 10月18日, 下午12时19分, Ben Finney wrote: > > > Jabba Laci writes: > > > > Right, it was my bad. After removal the tuple() function works > > > > perfectly. > > > > Note that, though it is callable, ‘tuple’ is not a function but a > > >

Re: restriction on sum: intentional bug?

2009-10-17 Thread Dieter Maurer
Christian Heimes writes on Fri, 16 Oct 2009 17:58:29 +0200: > 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] > >

Re: a gap of do....while?

2009-10-17 Thread StarWing
On 10月18日, 下午1时36分, Chris Rebert wrote: > On Sat, Oct 17, 2009 at 10:34 PM, Chris Rebert wrote: > > On Sat, Oct 17, 2009 at 10:22 PM, StarWing wrote: > > >> but in python, we only can: > >> cond = 1 > >> while cond: > >>    cond = 0 > >>    . > >>    if : cond = 1 > > >> has any polite

Re: list to tuple and vice versa

2009-10-17 Thread Ben Finney
StarWing writes: > On 10月18日, 下午12时19分, Ben Finney wrote: > > Jabba Laci writes: > > > Right, it was my bad. After removal the tuple() function works > > > perfectly. > > > > Note that, though it is callable, ‘tuple’ is not a function but a > > type: > > A type is always callable. Yes (modulo

Re: a gap of do....while?

2009-10-17 Thread Chris Rebert
On Sat, Oct 17, 2009 at 10:34 PM, Chris Rebert wrote: > On Sat, Oct 17, 2009 at 10:22 PM, StarWing wrote: >> but in python, we only can: >> cond = 1 >> while cond: >>    cond = 0 >>    . >>    if : cond = 1 >> >> has any polite way to handle this? > > It's essentially the same: > > while

Re: a gap of do....while?

2009-10-17 Thread Chris Rebert
On Sat, Oct 17, 2009 at 10:22 PM, StarWing wrote: > okay, I think somethings dowhile is useful, but why python didn't > have it? For simplicity of syntax and less duplication among the basic syntactic constructs. > in lisp, we can (while (progn )) > and in all other language we have do..

Re: a gap of do....while?

2009-10-17 Thread Stephen Hansen
On Sat, Oct 17, 2009 at 10:22 PM, StarWing wrote: > okay, I think somethings dowhile is useful, but why python didn't > have it? > > in lisp, we can (while (progn )) > and in all other language we have do...while. > but in python, we only can: > cond = 1 > while cond: >cond = 0 >.

Re: python along or bash combined with python (for manipulating files)

2009-10-17 Thread Aahz
In article <38890afc-c542-478a-bbe7-9a63dc6c9...@j9g2000vbp.googlegroups.com>, TerryP wrote: > >Very sophisticated scripts are possible using bash and ksh, there is >even a form of ksh that has tk capabilities! (tksh). The Python and >Bourne-derived languages are however fundamentally different >

a gap of do....while?

2009-10-17 Thread StarWing
okay, I think somethings dowhile is useful, but why python didn't have it? in lisp, we can (while (progn )) and in all other language we have do...while. but in python, we only can: cond = 1 while cond: cond = 0 . if : cond = 1 has any polite way to handle this? -- ht

Re: ftplib connection fails with multiple nics

2009-10-17 Thread Sean DiZazzo
On Oct 16, 4:51 pm, Sean DiZazzo wrote: > 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.

Re: The rap against "while True:" loops

2009-10-17 Thread Steven D'Aprano
On Sat, 17 Oct 2009 15:22:59 -0700, Paul Rubin wrote: > 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 al

Re: list to tuple and vice versa

2009-10-17 Thread StarWing
On 10月18日, 下午12时19分, Ben Finney wrote: > Jabba Laci writes: > > Right, it was my bad. After removal the tuple() function works > > perfectly. > > Note that, though it is callable, ‘tuple’ is not a function but a type: > >     >>> tuple >     >     >>> len >     > > You can use the built-in ‘typ

Re: slicing return iter?

2009-10-17 Thread StarWing
On 10月18日, 上午9时09分, Raymond Hettinger wrote: > [StarWing] > > > > > sometimes I want to iterate a part of a sequence. but don't want to > > > > copy it. i.e. > . . . > > I had checked it for serval times. maybe it's my inattention :-(. but > > what i could find the nearest thing is itertools.isli

Re: restriction on sum: intentional bug?

2009-10-17 Thread Steven D'Aprano
On Sat, 17 Oct 2009 07:27:44 -0700, Aahz 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? Not 100% -- I haven't read the CPython source code. But I have done timing tests for repeated con

Re: SimpleXMLRPCServer clobbering sys.stderr? (2.5.2)

2009-10-17 Thread Gabriel Genellina
En Sat, 17 Oct 2009 23:54:23 -0300, Joseph Turian escribió: I was having a mysterious problem with SimpleXMLRPCServer. (I am using Python 2.5.2) I'd start updating Python to the latest 2.5 release: 2.5.4 The request handlers were sometimes failing without any error message to the log outp

Re: list to tuple and vice versa

2009-10-17 Thread Ben Finney
Jabba Laci writes: > Right, it was my bad. After removal the tuple() function works > perfectly. Note that, though it is callable, ‘tuple’ is not a function but a type: >>> tuple >>> len You can use the built-in ‘type’ type to get the type of any object: >>> foo = 12

Re: list to tuple and vice versa

2009-10-17 Thread Jabba Laci
>> The error message is: "TypeError: 'tuple' object is not callable". > > You created a variable named "tuple" somewhere, which is shadowing the > built-in type. Rename that variable to something else. Right, it was my bad. After removal the tuple() function works perfectly. Thanks, Laszlo -- h

Re: list to tuple and vice versa

2009-10-17 Thread Ben Finney
Jabba Laci writes: > Hi, > > I have some difficulties with list -> tuple conversion: > > t = ('a', 'b') > li = list(t) # tuple -> list, works > print li # ['a', 'b'] > > tu = tuple(li) # list -> tuple, error > print tu # what I'd expect: ('a', 'b') Works fine for me: Python 2.5.4 (r

Re: list to tuple and vice versa

2009-10-17 Thread Chris Rebert
On Sat, Oct 17, 2009 at 8:24 PM, Jabba Laci wrote: > Hi, > > I have some difficulties with list -> tuple conversion: > > t = ('a', 'b') > li = list(t)   # tuple -> list, works > print li   # ['a', 'b'] > > tu = tuple(li)   # list -> tuple, error > print tu   # what I'd expect: ('a', 'b') > > The e

list to tuple and vice versa

2009-10-17 Thread Jabba Laci
Hi, I have some difficulties with list -> tuple conversion: t = ('a', 'b') li = list(t) # tuple -> list, works print li # ['a', 'b'] tu = tuple(li) # list -> tuple, error print tu # what I'd expect: ('a', 'b') The error message is: "TypeError: 'tuple' object is not callable". Thanks,

Re: restriction on sum: intentional bug?

2009-10-17 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. On 10/17/2009 7:03 PM, Terry Reedy wrote: If you disagree with this, I think *you* are being silly. Well, ... Alan G Isaac wrote: Of

Re: Installation question 2.5.4

2009-10-17 Thread ryles
On Sat, Oct 17, 2009 at 9:55 PM, JimR wrote: > Thanks. As it turned out, I needed /usr/local/python instead of /usr/local > as the prefix. After setting that, all worked as it should. -- http://mail.python.org/mailman/listinfo/python-list

SimpleXMLRPCServer clobbering sys.stderr? (2.5.2)

2009-10-17 Thread Joseph Turian
I was having a mysterious problem with SimpleXMLRPCServer. (I am using Python 2.5.2) The request handlers were sometimes failing without any error message to the log output. What I discovered was perplexing. I had some 'print' statements in the handers that, assuming the request would be handled,

Re: Multiple files

2009-10-17 Thread Benjamin Kaplan
On Sat, Oct 17, 2009 at 9:58 PM, Someone Something wrote: > I was trying to write a program with just one class and it was working fine. > Then, I seperated that class into two different files and made the objects > and called the methods in a third (client.py IO.py main.py). Now, when I use > the

Multiple files

2009-10-17 Thread Someone Something
I was trying to write a program with just one class and it was working fine. Then, I seperated that class into two different files and made the objects and called the methods in a third (client.py IO.py main.py). Now, when I use the command: python client.py IO.py main.py Nothing prints. I think

Re: umlauts

2009-10-17 Thread Diez B. Roggisch
Diez B. Roggisch schrieb: Arian Kuschki schrieb: 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

Re: umlauts

2009-10-17 Thread Diez B. Roggisch
Arian Kuschki schrieb: 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 e

Re: Threading from a class

2009-10-17 Thread MRAB
Someone Something wrote: 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

Re: print()

2009-10-17 Thread Mark Tolonen
"Terry Reedy" wrote in message news:hbdh51$g0...@ger.gmane.org... 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 m

Re: slicing return iter?

2009-10-17 Thread Raymond Hettinger
[StarWing] > > > sometimes I want to iterate a part of a sequence. but don't want to > > > copy it. i.e. . . . > 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 -- that's supporte

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

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: 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

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: 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: 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: 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: restriction on sum: intentional bug?

2009-10-17 Thread Aahz
In article , Mark Dickinson wrote: >On Oct 17, 9:49=A0pm, a...@pythoncraft.com (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: 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: 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 (a...@pythoncraft.com) <*> http://www.pythoncr

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: 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: 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: 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: a...@pythoncraft.com (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: restriction on sum: intentional bug?

2009-10-17 Thread Mark Dickinson
On Oct 17, 9:49 pm, a...@pythoncraft.com (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: 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 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: 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 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: The rap against "while True:" loops

2009-10-17 Thread Paul Rubin
a...@pythoncraft.com (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 Mark Dickinson
On Oct 17, 9:49 pm, a...@pythoncraft.com (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: 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 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: 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:7jub5rf37div...@mid.uni-berlin.de... > [snip] > >This is wierd. I looked at the site in Fi

Re: restriction on sum: intentional bug?

2009-10-17 Thread Mark Dickinson
On Oct 17, 3:27 pm, a...@pythoncraft.com (Aahz) wrote: > In article <0062f568$0$26941$c3e8...@news.astraweb.com>, > 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: The rap against "while True:" loops

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

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

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: umlauts

2009-10-17 Thread Mark Tolonen
"Diez B. Roggisch" wrote in message news:7jub5rf37div...@mid.uni-berlin.de... [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

Re: The rap against "while True:" loops

2009-10-17 Thread Paul Rubin
a...@pythoncraft.com (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 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: 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 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 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 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: 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: 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: 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: 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: 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: 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 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 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: how to write a unicode string to a file ?

2009-10-17 Thread Mark Tolonen
"Mark Tolonen" wrote in message news:hbbo6d$6u...@ger.gmane.org... "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

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: 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' >

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: 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: 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: 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 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: 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,

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: 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

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.

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: 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

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

  1   2   >