Re: Confused compare function :)

2012-12-07 Thread Chris Angelico
On Sat, Dec 8, 2012 at 6:01 PM, Terry Reedy wrote: > Unfortunately, catching exceptions may be and often is as slow as the > redundant check and even multiple redundant checks. It depends on how often you're going to catch and how often just flow through. In Python, as in most other modern langua

Re: Confused compare function :)

2012-12-07 Thread Terry Reedy
On 12/7/2012 5:16 PM, Steven D'Aprano wrote: On Thu, 06 Dec 2012 23:14:17 +1100, Chris Angelico wrote: Setting up the try/except is a constant time cost, It's not just constant time, it's constant time and *cheap*. Doing nothing inside a try block takes about twice as long as doing nothing:

Re: python 3.3 urllib.request

2012-12-07 Thread Terry Reedy
On 12/7/2012 12:27 PM, Hans Mulder wrote: On 7/12/12 13:52:52, Steeve C wrote: hello, I have a python3 script with urllib.request which have a strange behavior, here is the script : + #!/usr/bin/env python3 # -*- c

Re: wrong ImportError message printed by python3.3 when it can't find a module?

2012-12-07 Thread Irmen de Jong
On 7-12-2012 22:20, Peter Otten wrote: > A paragon of clarity -- ye lurkers, this is how a bug report should be. :-) > >> Is there a problem with the rewritten import logic in Python 3.3? >> >> Thanks >> Irmen de Jong > > I believe this is fixed, see http://bugs.python.org/issue15111 Argh, wh

Re: Confused compare function :)

2012-12-07 Thread Steven D'Aprano
On Thu, 06 Dec 2012 23:14:17 +1100, Chris Angelico wrote: > Setting up the try/except is a constant time cost, It's not just constant time, it's constant time and *cheap*. Doing nothing inside a try block takes about twice as long as doing nothing: [steve@ando ~]$ python2.7 -m timeit "try: pas

Re: wrong ImportError message printed by python3.3 when it can't find a module?

2012-12-07 Thread Peter Otten
Irmen de Jong wrote: > I'm seeing that Python 3.3.0 is not printing the correct ImportError when > it can't import a module that is imported from another module. Instead of > printing the name of the module it can't import, it prints the name of the > module that is doing the faulty import. > > B

wrong ImportError message printed by python3.3 when it can't find a module?

2012-12-07 Thread Irmen de Jong
Hi, I'm seeing that Python 3.3.0 is not printing the correct ImportError when it can't import a module that is imported from another module. Instead of printing the name of the module it can't import, it prints the name of the module that is doing the faulty import. Behold: I have created: i

Re: A question about readability

2012-12-07 Thread rusi
On Dec 7, 6:46 pm, Marco wrote: > Hi all, do you think this code: > > $ more myscript.py > for line in open('data.txt'): >      result = sum(int(data) for data in line.split(';')) >      print(result) > > that sums the elements of the lines of this file: > > $ more data.txt > 30;44;99;88 > 11;17;1

Re: empty object from C

2012-12-07 Thread Stefan Behnel
Eric Frederich, 07.12.2012 16:42: > From C, I'd like to call a Python function that takes an object and sets > some attributes on it. > Lets say this is the function... > > def foo(msg): > msg.bar = 123 > msg.spam = 'eggs' > > How do I create an empty object in C? > In Python I would do s

Re: KAJOL SEX VIDEOS'''''''''''''''''''

2012-12-07 Thread shahabuddinbkb
On Thursday, November 29, 2012 8:17:27 PM UTC-8, mentham...@gmail.com wrote: > -- http://mail.python.org/mailman/listinfo/python-list

Re: python 3.3 urllib.request

2012-12-07 Thread Hans Mulder
On 7/12/12 13:52:52, Steeve C wrote: > hello, > > I have a python3 script with urllib.request which have a strange > behavior, here is the script : > > + > #!/usr/bin/env python3 > # -*- coding: utf-8 -*- > > import

Re: mini browser with python

2012-12-07 Thread inq1ltd
On Thursday, December 06, 2012 03:15:42 PM Terry Reedy wrote: > On 12/6/2012 1:15 PM, inq1ltd wrote: > > On Thursday, December 06, 2012 05:19:38 PM John Gordon wrote: > > > In inq1ltd > > > > writes: > > > > Right now I need some way to display > > > > 15 to 20 lines of html in its own wind

Re: Confused compare function :)

2012-12-07 Thread Neil Cerutti
On 2012-12-07, Steven D'Aprano wrote: > On Thu, 06 Dec 2012 13:51:29 +, Neil Cerutti wrote: > >> On 2012-12-06, Steven D'Aprano >> wrote: >>> total = 0 >>> for s in list_of_strings: >>> try: >>> total += int(s) >>> except ValueError: >>> pass # Not a number, ignore it

empty object from C

2012-12-07 Thread Eric Frederich
Hello, >From C, I'd like to call a Python function that takes an object and sets some attributes on it. Lets say this is the function... def foo(msg): msg.bar = 123 msg.spam = 'eggs' How do I create an empty object in C? In Python I would do something like this... class Msg(object):

Re: Cosine Similarity

2012-12-07 Thread subhabangalore
T On Friday, December 7, 2012 9:47:46 AM UTC+5:30, Miki Tebeka wrote: > On Thursday, December 6, 2012 2:15:53 PM UTC-8, subhaba...@gmail.com wrote: > > > I am looking for some example of implementing Cosine similarity in python. > > I searched for hours but could not help much. NLTK seems to hav

Re: pyodbc utf-8

2012-12-07 Thread Ian Kelly
On Fri, Dec 7, 2012 at 12:41 AM, Markus Christen wrote: > good morning > > i am using pyodbc 3.0.6 for win32 python 2.7.3 > i used it to connect with a MsSql db. Now i have a little problem with the > umlaut. i cant change anything in the db and there are umlauts like "ä", "ö" > and "ü" saved. s

Re: pyodbc utf-8

2012-12-07 Thread Mark Lawrence
On 07/12/2012 15:47, Markus Christen wrote: My webpage is using UTF-8 and utf-8 or unicode is on the DB. When i read out this files with Excel, i have no problems with the umlauts. I heared its a problem of pyodbc itself, cause it is only using ascii i think. I found this page here, but it was

Re: pyodbc utf-8

2012-12-07 Thread Markus Christen
My webpage is using UTF-8 and utf-8 or unicode is on the DB. When i read out this files with Excel, i have no problems with the umlauts. I heared its a problem of pyodbc itself, cause it is only using ascii i think. I found this page here, but it was not really helpful for me. :( maybe i have no

Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte

2012-12-07 Thread iMath
在 2012年12月6日星期四UTC+8下午7时07分35秒,Hans Mulder写道: > On 6/12/12 11:07:51, iMath wrote: > > > the following code originally from > > http://zetcode.com/databases/mysqlpythontutorial/ > > > within the "Writing images" part . > > > > > > > > > import MySQLdb as mdb > > > import sys > > > > > >

Python-UK Community on google+

2012-12-07 Thread Martin P. Hellwig
Hi All, I created the Python-UK Community on google+, so if you are using google+ and you are interested in Python and you are interested in the UK, I heartily invite you to join. My intention is to transfer the ownership to the PyCon UK organization, which I already have contacted a member of

Re: Problem with __str__ method and character encoding

2012-12-07 Thread gialloporpora
Risposta al messaggio di Chris Angelico : Your __str__ method is not returning a string. It's returning a Unicode object. Under Python 2 (which you're obviously using, since you use print as a statement), strings are bytes. The best thing to do would be to move to Python 3.3, in which the defaul

Re: Problem with __str__ method and character encoding

2012-12-07 Thread Chris Angelico
On Sat, Dec 8, 2012 at 1:14 AM, gialloporpora wrote: print a > UnicodeError print a.__str__() > OK By the way, it's *much* more helpful to copy and paste the actual error message and output, rather than retyping like that. Spending one extra minute in the interactive interpreter before

Re: Problem with __str__ method and character encoding

2012-12-07 Thread peter
On 12/07/2012 11:17 AM, gialloporpora wrote: Risposta al messaggio di gialloporpora : This is the code in my test.py: Sorry, I have wrongly pasted the code: class msgmarker(object): def __init__(self, msgid, msgstr, index, encoding="utf-8"): self._encoding =encoding self

Re: Problem with __str__ method and character encoding

2012-12-07 Thread Chris Angelico
On Sat, Dec 8, 2012 at 1:14 AM, gialloporpora wrote: > Dear all, > I have a problem with character encoding. > I have created my class and I have redefined the __str__ method for pretty > printing. I have saved my file as test.py, > I give these lines: > from test import * a = msgmarker

Re: Problem with __str__ method and character encoding

2012-12-07 Thread gialloporpora
Risposta al messaggio di gialloporpora : This is the code in my test.py: Sorry, I have wrongly pasted the code: class msgmarker(object): def __init__(self, msgid, msgstr, index, encoding="utf-8"): self._encoding =encoding self.set(msgid, msgstr)

Re: A question about readability

2012-12-07 Thread Steven D'Aprano
On Fri, 07 Dec 2012 14:46:03 +0100, Marco wrote: > Hi all, do you think this code: > > $ more myscript.py > for line in open('data.txt'): > result = sum(int(data) for data in line.split(';')) > print(result) [...] > is explicit enough? Do you prefer a clearer solution? Thanks in advance

Re: A question about readability

2012-12-07 Thread Roy Smith
In article , Marco wrote: > Hi all, do you think this code: > > $ more myscript.py > for line in open('data.txt'): > result = sum(int(data) for data in line.split(';')) > print(result) That sum() line is a bit of a mouthful. I would refactor it into something like this: > for line

Re: problem with usbtmc-communication

2012-12-07 Thread Jean Dubois
On 6 dec, 21:28, Terry Reedy wrote: > On 12/6/2012 10:44 AM, Jean Dubois wrote: > > > > > > > > > > > I followed your suggestion an now the code looks like this: > > #!/usr/bin/python > > import time > > import os > > import sys > > measurementcurr='' > > measurementvolt='' > > timesleepdefault=2

Re: problem with usbtmc-communication

2012-12-07 Thread Jean Dubois
On 6 dec, 21:15, w...@mac.com wrote: > On Dec 6, 2012, at 2:41 PM, Jean Dubois wrote: > > > > > > > > > > > On 6 dec, 15:50, w...@mac.com wrote: > >> On Dec 6, 2012, at 8:50 AM, Jean Dubois wrote: > > >> [byte] > > >>> It seems there is some misunderstanding here. What I meant with  how > >>> to

A question about readability

2012-12-07 Thread Marco
Hi all, do you think this code: $ more myscript.py for line in open('data.txt'): result = sum(int(data) for data in line.split(';')) print(result) that sums the elements of the lines of this file: $ more data.txt 30;44;99;88 11;17;16;50 33;91;77;15 $ python3.3 myscript.py 261 94 216 is

Re: Confused compare function :)

2012-12-07 Thread Anatoli Hristov
>> Calling it 'found' is misleading, because it's True only if it updated. >> If it found a match but didn't update, 'found' will still be False. >> Using a loop within a loop like this could be the cause of your >> problem. It's certainly not the most efficient way of doing it. > > I will keep you

python 3.3 urllib.request

2012-12-07 Thread Steeve C
hello, I have a python3 script with urllib.request which have a strange behavior, here is the script : + #!/usr/bin/env python3 # -*- coding: utf-8 -*- import urllib.request import sys, time url = 'http://google.co

Re: pyodbc utf-8

2012-12-07 Thread Hans Mulder
On 7/12/12 08:41:27, Markus Christen wrote: > good morning > > i am using pyodbc 3.0.6 for win32 python 2.7.3 > i used it to connect with a MsSql db. Now i have a little problem with the > umlaut. > i cant change anything in the db and there are umlauts like "ä", "ö" and "ü" saved. > so i have to

MVC web-framework with RESTfully Decoupled Views?

2012-12-07 Thread Alec Taylor
I have used a variety of different MVC web-frameworks. My current methodology for web and mobile [PhoneGap/Cordova] development is as follows: Web framework (MVC) 1. Write the Models (db schema stuff) 2. Write the Controllers (manage interface between models and views, or just expose certain dat