pyodbc utf-8

2012-12-06 Thread Markus Christen
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 change my view (of django 1.4.1) to change \xfc into ü

Re: Tcl wasn't installed properly

2012-12-06 Thread Gene Heskett
On Friday 07 December 2012 02:25:33 bhargavigosw...@gmail.com did opine: > I faced the same problem during my last installation of ns2.35 in ubuntu > 11.04. After I install ns2.35, got message of successful installation > of ns. Then I set path in /.bashrc. Then I gave ns command which gave > me s

Re: Tcl wasn't installed properly

2012-12-06 Thread bhargavigoswami
I faced the same problem during my last installation of ns2.35 in ubuntu 11.04. After I install ns2.35, got message of successful installation of ns. Then I set path in /.bashrc. Then I gave ns command which gave me same error which you got. The problem is because, ns executable is also at /usr

Re: Is __ne__ method autogenerated?

2012-12-06 Thread INADA Naoki
Thanks a million! On Fri, Dec 7, 2012 at 3:47 PM, Chris Rebert wrote: > On Thursday, December 6, 2012, INADA Naoki wrote: > >> The reference says: >> >> The truth of x==y does not imply that x!=y is false. >> Accordingly, when defining __eq__(), one should also >> define __ne__() so that

Re: Is __ne__ method autogenerated?

2012-12-06 Thread Chris Rebert
On Thursday, December 6, 2012, INADA Naoki wrote: > The reference says: > > The truth of x==y does not imply that x!=y is false. > Accordingly, when defining __eq__(), one should also > define __ne__() so that the operators will behave as expected. > > (http://docs.python.org/3/reference/dat

Re: Is __ne__ method autogenerated?

2012-12-06 Thread Ian Kelly
On Thu, Dec 6, 2012 at 11:03 PM, INADA Naoki wrote: > The reference says: > > The truth of x==y does not imply that x!=y is false. > Accordingly, when defining __eq__(), one should also > define __ne__() so that the operators will behave as expected. > > (http://docs.python.org/3/reference/d

Re: Problem using py-bt, py-locals, etc. during GDB debugging [solved]

2012-12-06 Thread Mark Shroyer
On Thu, Dec 06, 2012 at 07:37:22PM -0500, MRAB wrote: > On 2012-12-07 00:22, Mark Shroyer wrote: > > > > [...] > > > > 2. Patch Python 2.7.3's python-gdb.py as follows: > > > > === 8< = > > > > --- python-gdb.py.orig 2012-12-06 15:12:18.666760664 -0500 > > +++

Is __ne__ method autogenerated?

2012-12-06 Thread INADA Naoki
The reference says: The truth of x==y does not imply that x!=y is false. Accordingly, when defining __eq__(), one should also define __ne__() so that the operators will behave as expected. (http://docs.python.org/3/reference/datamodel.html#object.__eq__) But I saw different behavior on 3.3

Re: Cosine Similarity

2012-12-06 Thread Miki Tebeka
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 have a module but > did not find examples. Should be easy with numpy: import

Re: How to list a file which already created a 2 mins ago

2012-12-06 Thread wrw
On Dec 6, 2012, at 4:29 PM, Irmen de Jong wrote: > On 6-12-2012 17:49, moonhkt wrote: >> Hi All >> >> AIX.5.3 >> Python 2.6.2 >> >> File ftp to Machine A, need to rename then send to Machine B. >> >> How to list a file which already created a 2 mins ago ? If file aging >> more than 2 mins. I

Re: Confused compare function :)

2012-12-06 Thread Steven D'Aprano
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. > > If it's internal data, perhaps. Of course,

Re: Problem using py-bt, py-locals, etc. during GDB debugging [solved]

2012-12-06 Thread MRAB
On 2012-12-07 00:22, Mark Shroyer wrote: On Thu, Dec 06, 2012 at 04:39:41PM -0500, Mark Shroyer wrote: I'm having trouble with the py-bt, py-locals, etc. GDB commands (from Python's python-gdb.py) while using GDB 7.4 to debug Python 2.7.3; I was wondering if anyone here could offer advice. Brie

Re: Problem using py-bt, py-locals, etc. during GDB debugging [solved]

2012-12-06 Thread Mark Shroyer
On Thu, Dec 06, 2012 at 04:39:41PM -0500, Mark Shroyer wrote: > I'm having trouble with the py-bt, py-locals, etc. GDB commands (from > Python's python-gdb.py) while using GDB 7.4 to debug Python 2.7.3; I was > wondering if anyone here could offer advice. > > Briefly, py-bt seems to identify the p

Re: New tutorials

2012-12-06 Thread Mitya Sirenef
On 12/06/2012 12:16 PM, Jean-Michel Pichavant wrote: - Original Message - >> On 12/02/2012 09:54 AM, Mitya Sirenef wrote: >>> Hi everyone, I'm making a series of python tutorials and I've just >> > finished the introductory part: >> > http://lightbird.net/larks/intro.html >> > >> > Feedb

Re: The curses module and licensing

2012-12-06 Thread Chris Angelico
On Fri, Dec 7, 2012 at 9:37 AM, Benjamin Schnitzler wrote: > By the way: Sorry for posting the statement of Chris Angelico to > the list, it wasn't meant to be on it. Apology accepted :) It was off-list mainly because it strayed off-topic, not because there was anything particularly private in it

Re: paramiko.BadAuthenticationType

2012-12-06 Thread who
FWIW, I'm trying to write a python program that does the equivalent this perl program: http://devcentral.f5.com/downloads/iControl/SDK/sslvpn.public.pl.txt I don't see any code there that refers to a public key, but it works fine. -- http://mail.python.org/mailman/listinfo/python-list

The curses module and licensing

2012-12-06 Thread Benjamin Schnitzler
On 19:28 Thu 06 Dec , Alister wrote: > If I understand things correctly this means if you distribute the python > package (alone or as part of your application) then you need to include > the detailed section. > > if you provide just your own python code & require the user to install > pyth

Cosine Similarity

2012-12-06 Thread subhabangalore
Dear Group, I am looking for some example of implementing Cosine similarity in python. I searched for hours but could not help much. NLTK seems to have a module but did not find examples. If anyone of the learned members may kindly help out. Regards, Subhabrata. -- http://mail.python.org/ma

Problem using py-bt, py-locals, etc. during GDB debugging

2012-12-06 Thread Mark Shroyer
I'm having trouble with the py-bt, py-locals, etc. GDB commands (from Python's python-gdb.py) while using GDB 7.4 to debug Python 2.7.3; I was wondering if anyone here could offer advice. Briefly, py-bt seems to identify the python stack frames correctly, but shows "(unable to read python frame in

Re: Good use for itertools.dropwhile and itertools.takewhile

2012-12-06 Thread Paul Rubin
Nick Mellor writes: > I came across itertools.dropwhile only today, then shortly afterwards > found Raymond Hettinger wondering, in 2007, whether to drop [sic] > dropwhile and takewhile from the itertools module > Almost nobody else of the 18 respondents seemed to be using them. What? I'm am

Re: How to list a file which already created a 2 mins ago

2012-12-06 Thread Irmen de Jong
On 6-12-2012 17:49, moonhkt wrote: > Hi All > > AIX.5.3 > Python 2.6.2 > > File ftp to Machine A, need to rename then send to Machine B. > > How to list a file which already created a 2 mins ago ? If file aging > more than 2 mins. I want to rename file to other file name. > > moonhkt > ftpli

Re: Secretly passing parameter to function

2012-12-06 Thread Paul Rubin
Paul Rubin writes: > from functools import partial > do(partial(step1, param = None)) Or more directly: do(lambda: step1(param = None)) -- http://mail.python.org/mailman/listinfo/python-list

Re: Secretly passing parameter to function

2012-12-06 Thread Paul Rubin
Olivier Scalbert writes: > # We ask the framework to do some work. > do(step1, param = None) from functools import partial do(partial(step1, param = None)) -- http://mail.python.org/mailman/listinfo/python-list

Re: question about importing a package

2012-12-06 Thread Terry Reedy
On 12/6/2012 11:50 AM, Matt wrote: It works now. Steven and Alex, thanks for your help! I ended up leaving sample.py and foo.py and bar.p the way they were, and in __init__.py putting: from foo import * from bar import * So my mistake was not importing the foo and bar modules into sub_one/__

Re: problem with usbtmc-communication

2012-12-06 Thread Terry Reedy
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 filename ='mydata.txt' usbkeith = open('/dev/usbtmc1','r+') usbkeith.flush() usbkeith.

Re: mini browser with python

2012-12-06 Thread Terry Reedy
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 window or > > as part of my screen. > Could you open a shell window and run a text web

Re: problem with usbtmc-communication

2012-12-06 Thread wrw
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 "do the equivalent in Python" refered to "reading charac

Re: problem with usbtmc-communication

2012-12-06 Thread Dave Angel
On 12/06/2012 02:41 PM, Jean Dubois wrote: > On 6 dec, 15:50, w...@mac.com wrote: >> >> Sorry about the misunderstanding (and subsequent waste of bandwidth). >> However, if you will look at the serial reads and writes in that handler, >> you will see that it does things like "serial.read(n)" wh

Re: problem with usbtmc-communication

2012-12-06 Thread Jean Dubois
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 "do the equivalent in Python" refered to  "reading characters > > rather than lines". > > I have wr

Re: The curses module and licensing

2012-12-06 Thread Alister
On Thu, 06 Dec 2012 19:34:04 +0100, benjamin schnitzler wrote: > I think I have accidentially not sent this to the python list: > > On 02:17 Fri 07 Dec , Chris Angelico wrote: >> Hi! >> >> Here's some info on ncurses: >> >> http://invisible-island.net/ncurses/ncurses.faq.html >> >> I would ge

Re: Confused compare function :)

2012-12-06 Thread Rotwang
On 06/12/2012 04:32, Steven D'Aprano wrote: On Thu, 06 Dec 2012 03:22:53 +, Rotwang wrote: [...] Is there a problem with either of the above? If so, what should I do instead? They're fine. Never, ever say that people should never, ever do something. *cough* Thanks. -- I have made a

Re: Confused compare function :)

2012-12-06 Thread Rotwang
On 06/12/2012 08:49, Bruno Dupuis wrote: On Thu, Dec 06, 2012 at 04:32:34AM +, Steven D'Aprano wrote: On Thu, 06 Dec 2012 03:22:53 +, Rotwang wrote: On 06/12/2012 00:19, Bruno Dupuis wrote: [...] Another advice: never ever except XXXError: pass at least log, or count, or warn

Re: PyCharm messed up my PyDev

2012-12-06 Thread Jabba Laci
Dear All, I managed to solve the problem. Something got messed up in the .metadata directory. After renaming it, Aptana Studio re-created it and I could successfully specify the Python interpreter. In PyCharm I specified the same workspace to use, maybe that was the problem. Laszlo On Thu, Dec

Re: Confused compare function :)

2012-12-06 Thread Anatoli Hristov
> gmane.comp.python.general: > >> But basically, the code seems to run a pair of nested for-loops: >> >> for SKU in database: >> for SKU in csv file: >> if the two SKUs match: >> compare their prices and update the database >> > OUCH... > > I'm presuming the

Re: mini browser with python

2012-12-06 Thread inq1ltd
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 window or > > as part of my screen. > > Could you open a shell window and run a text web browser such as Lynx? That is a possibili

Re: The curses module and licensing

2012-12-06 Thread benjamin schnitzler
I think I have accidentially not sent this to the python list: On 02:17 Fri 07 Dec , Chris Angelico wrote: > Hi! > > Here's some info on ncurses: > > http://invisible-island.net/ncurses/ncurses.faq.html > > I would generally assume that it's safe to use any Python standard > library module wit

PyCharm messed up my PyDev

2012-12-06 Thread Jabba Laci
Hi, I have a strange problem. I've used PyDev for a long time and a few days ago I wanted to try PyCharm. When I wanted to create a new project in PyCharm, it asked me to select the interpreter. There was a possibility to upgrade packages so I selected all and pressed the upgrade button. For the u

Re: Confused compare function :)

2012-12-06 Thread Anatoli Hristov
Here is the product in the CSV: MONIIE2407HDS-B1;MON;II;E2407HDS-B1;E2407HDS-B1;IIYAMA LCD 24" Wide 1920x1080TN Speakers 2ms Black DVI HDMI;133;20;RECTD0.41;0,41; > [snip] > It's not saying that it's not found, it's saying that it wasn't updated > because: You are right

FitsStubImagePlugin

2012-12-06 Thread Colm Brazel
Hi Anybody got links to, eg how to use, FitsStubImagePlugin module part of PIL? thanks Colm -- http://mail.python.org/mailman/listinfo/python-list

Re: Confused compare function :)

2012-12-06 Thread MRAB
On 2012-12-06 17:31, Anatoli Hristov wrote: Here is the product in the CSV: MONIIE2407HDS-B1;MON;II;E2407HDS-B1;E2407HDS-B1;IIYAMA LCD 24" Wide 1920x1080TN Speakers 2ms Black DVI HDMI;133;20;RECTD0.41;0,41; This one is still not found and it is in the CSV file - I just don't get it why

Re: Confused compare function :)

2012-12-06 Thread Anatoli Hristov
>> Here is the product in the CSV: >> MONIIE2407HDS-B1;MON;II;E2407HDS-B1;E2407HDS-B1;IIYAMA LCD 24" Wide >> 1920x1080TN Speakers 2ms Black DVI HDMI;133;20;RECTD0.41;0,41; This one is still not found and it is in the CSV file - I just don't get it why ! >> if len(db_s

Re: mini browser with python

2012-12-06 Thread John Gordon
In inq1ltd writes: > Right now I need some way to display > 15 to 20 lines of html in its own window or > as part of my screen. Could you open a shell window and run a text web browser such as Lynx? -- John Gordon A is for Amy, who fell down the stairs gor...@panix.com

Re: New tutorials

2012-12-06 Thread Jean-Michel Pichavant
- Original Message - > On 12/02/2012 09:54 AM, Mitya Sirenef wrote: > > Hi everyone, I'm making a series of python tutorials and I've just > > finished the introductory part: > > http://lightbird.net/larks/intro.html > > > > Feedback is appreciated.. - mitya > >

Re: Confused compare function :)

2012-12-06 Thread MRAB
On 2012-12-06 14:22, Anatoli Hristov wrote: Guys I'm still confusing my script is working better, but not enough. I did a logfile to see which products are not found anymore in the CSV and I found some that are present but python says they are not ?? Here is the product in the CSV: MONIIE2407HDS

Re: Confused compare function :)

2012-12-06 Thread Anatoli Hristov
>> No one have an idea ? >> >> Thanks >> > > Basically because your code is crap. Others have already suggested > refactoring your code to make it easier to follow. Thank you Mark for your notes. I changed the name of the variables as was suggested before. I know my code should be crappy, but at

Re: New tutorials

2012-12-06 Thread Mitya Sirenef
On 12/02/2012 09:54 AM, Mitya Sirenef wrote: Hi everyone, I'm making a series of python tutorials and I've just > finished the introductory part: http://lightbird.net/larks/intro.html > > Feedback is appreciated.. - mitya > I've added two more tutorials

Re: question about importing a package

2012-12-06 Thread Matt
It works now. Steven and Alex, thanks for your help! I ended up leaving sample.py and foo.py and bar.p the way they were, and in __init__.py putting: from foo import * from bar import * So my mistake was not importing the foo and bar modules into sub_one/__init__.py. I also see how the __all_

Re: Confused compare function :)

2012-12-06 Thread Mark Lawrence
On 06/12/2012 16:16, Anatoli Hristov wrote: No one have an idea ? Thanks Basically because your code is crap. Others have already suggested refactoring your code to make it easier to follow. Try (diabolical pun very deliberate) following that advice. Failing that find out how much it'

How to list a file which already created a 2 mins ago

2012-12-06 Thread moonhkt
Hi All AIX.5.3 Python 2.6.2 File ftp to Machine A, need to rename then send to Machine B. How to list a file which already created a 2 mins ago ? If file aging more than 2 mins. I want to rename file to other file name. moonhkt -- http://mail.python.org/mailman/listinfo/python-list

Re: Confused compare function :)

2012-12-06 Thread Anatoli Hristov
On Thu, Dec 6, 2012 at 3:22 PM, Anatoli Hristov wrote: > Guys I'm still confusing my script is working better, but not enough. > I did a logfile to see which products are not found anymore in the CSV > and I found some that are present but python says they are not ?? > > Here is the product in the

Re: problem with usbtmc-communication

2012-12-06 Thread Jean Dubois
On 4 dec, 20:55, Terry Reedy wrote: > On 12/4/2012 7:14 AM, Jean Dubois wrote: > > > > > > > > > > > The following test program which tries to communicate with a Keithley > > 2200 programmable power supply using usbtmc in Python does not work as > > expected. I have connected a 10 ohm resistor to

RE: Dict comprehension help

2012-12-06 Thread Joseph L. Casale
>You could put the loop into a helper function, but if you are looping >through the same my_list more than once why not build a lookup table > >my_dict = {d["key"]: d for d in my_list} > >and then find the required dict with > >my_dict[value] I suppose, what I failed to clarify was that for each l

Re: mini browser with python

2012-12-06 Thread inq1ltd
On Thursday, December 06, 2012 01:52:15 AM Hans Mulder wrote: > On 5/12/12 22:44:21, inq1ltd wrote: > > I can connect to and download a web page, > > html code, and save it to a file. If connected > > to the web, I can change the settings on KWrite > > to open the file and navigate the page, > > (

The curses module and licensing

2012-12-06 Thread Benjamin Schnitzler
Hello everyone, I am new to this list. I have a question concerning the curses module (I am using python2.7). Which license does this module have? Is it bases completely on the curses library? In the documentation the following is stated: "The curses module provides an interface to the curses lib

Re: Confused compare function :)

2012-12-06 Thread peter
On 12/06/2012 10:58 AM, Chris Angelico wrote: On Fri, Dec 7, 2012 at 12:33 AM, Thomas Rachel wrote: Am 06.12.2012 09:49 schrieb Bruno Dupuis: The point is Exceptions are made for error handling, not for normal workflow. I hate when i read that for example: try: do_stuff(mydic

Re: problem with usbtmc-communication

2012-12-06 Thread wrw
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 "do the equivalent in Python" refered to "reading characters > rather than lines". > I have written working code myself for another Keithleu which does use > RS23

Re: Confused compare function :)

2012-12-06 Thread Dave Angel
On 12/06/2012 08:58 AM, Chris Angelico wrote: > On Fri, Dec 7, 2012 at 12:33 AM, Thomas Rachel > > wrote: >> Am 06.12.2012 09:49 schrieb Bruno Dupuis: >> >>> The point is Exceptions are made for error handling, not for normal >>> workflow. I hate when i read that for example: >>> >>> try: >>>

Re: Confused compare function :)

2012-12-06 Thread Chris Angelico
On Fri, Dec 7, 2012 at 1:21 AM, Hans Mulder wrote: > Errhm, no. Look again. The do_stuff(value) call is in the "else:" > clause, so it will only be done of there was no Exception of any > kind, and in that case the assignment to value must have succeeded. DOH! My bad. Sorry! I somehow didn't se

Re: Some help in refining this regex for CSV files

2012-12-06 Thread Tim Chase
On 12/06/12 01:21, Oltmans wrote: > Hi guys, > > I've to deal with CSVs that look like following > > CSV (with one header and 3 legit rows where each legit row has 3 columns) > > Some info > Date: 12/6/2012 > Author: Some guy > Total records: 100 > > header1, header2, header3 > one, two, th

Re: Confused compare function :)

2012-12-06 Thread Hans Mulder
On 6/12/12 14:58:01, Chris Angelico wrote: > On Fri, Dec 7, 2012 at 12:33 AM, Thomas Rachel > > wrote: >> > Am 06.12.2012 09:49 schrieb Bruno Dupuis: >> > >>> >> The point is Exceptions are made for error handling, not for normal >>> >> workflow. I hate when i read that for example: >>> >> >>> >>

Re: Confused compare function :)

2012-12-06 Thread Anatoli Hristov
Guys I'm still confusing my script is working better, but not enough. I did a logfile to see which products are not found anymore in the CSV and I found some that are present but python says they are not ?? Here is the product in the CSV: MONIIE2407HDS-B1;MON;II;E2407HDS-B1;E2407HDS-B1;IIYAMA LCD

Re: Good use for itertools.dropwhile and itertools.takewhile

2012-12-06 Thread Vlastimil Brom
2012/12/6 Neil Cerutti : > On 2012-12-05, Vlastimil Brom wrote: >> ... PARSNIP, certified organic > > I'm not sure on this one. > >> ('PARSNIP', ', certified organic') > > -- > Neil Cerutti > -- Well, I wasn't either, when I noticed this item, but given the specification: "2. Retain punctuation a

Re: problem with usbtmc-communication

2012-12-06 Thread Jean Dubois
On 4 dec, 20:55, Terry Reedy wrote: > On 12/4/2012 7:14 AM, Jean Dubois wrote: > > > > > > > > > > > The following test program which tries to communicate with a Keithley > > 2200 programmable power supply usingusbtmcin Python does not work as > > expected. I have connected a 10 ohm resistor to it

Re: Confused compare function :)

2012-12-06 Thread Chris Angelico
On Fri, Dec 7, 2012 at 12:33 AM, Thomas Rachel wrote: > Am 06.12.2012 09:49 schrieb Bruno Dupuis: > >> The point is Exceptions are made for error handling, not for normal >> workflow. I hate when i read that for example: >> >> try: >> do_stuff(mydict[k]) >> except KeyError: >>

Re: Confused compare function :)

2012-12-06 Thread Neil Cerutti
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. If it's internal data, perhaps. Of course, that would mean I had the option of *not* creating that stupid list_of_

Re: problem with usbtmc-communication

2012-12-06 Thread Jean Dubois
On 5 dec, 23:21, w...@mac.com wrote: > On Dec 5, 2012, at 3:38 PM, Jean Dubois wrote: > > [byte] > > > > >> I note that in your Octave example you are reading characters rather than > >> lines.  It seems to me that you have two choices here, either do the > >> equivalent in python or dig through

Re: Confused compare function :)

2012-12-06 Thread Chris Angelico
On Fri, Dec 7, 2012 at 12:32 AM, Hans Mulder wrote: > On 6/12/12 12:55:16, peter wrote: >> Is perfectly right to use try catch for a flow control. >> Just think in something more complex like this. >> >>try: >> self._conn = MySQLdb.connect(host=host, >> user=user, >

Re: Good use for itertools.dropwhile and itertools.takewhile

2012-12-06 Thread Alexander Blinne
Am 05.12.2012 18:04, schrieb Nick Mellor: > Sample data Well let's see what def split_product(p): p = p.strip() w = p.split(" ") try: j = next(i for i,v in enumerate(w) if v.upper() != v) except StopIteration: return p, '' return " ".join(w[:j]), " ".join(w[j:]

Re: Confused compare function :)

2012-12-06 Thread Thomas Rachel
Am 06.12.2012 09:49 schrieb Bruno Dupuis: The point is Exceptions are made for error handling, not for normal workflow. I hate when i read that for example: try: do_stuff(mydict[k]) except KeyError: pass I as well, but for other reasons (see below). But basically t

Re: Confused compare function :)

2012-12-06 Thread Hans Mulder
On 6/12/12 12:55:16, peter wrote: > Is perfectly right to use try catch for a flow control. > Just think in something more complex like this. > >try: > self._conn = MySQLdb.connect(host=host, > user=user, > passwd=passwd, > db=db) >

Re: Good use for itertools.dropwhile and itertools.takewhile

2012-12-06 Thread Neil Cerutti
On 2012-12-05, Vlastimil Brom wrote: > ... PARSNIP, certified organic I'm not sure on this one. > ('PARSNIP', ', certified organic') -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: Confused compare function :)

2012-12-06 Thread Chris Angelico
On Thu, Dec 6, 2012 at 10:47 PM, Steven D'Aprano wrote: > Not so. Which one is faster will depend on how often you expect to fail. > If the keys are nearly always present, then: > > try: > do_stuff(mydict[k]) > except KeyError: > pass > > will be faster. Setting up a try block is very fast

Re: Confused compare function :)

2012-12-06 Thread peter
On 12/06/2012 08:47 AM, Steven D'Aprano wrote: On Thu, 06 Dec 2012 09:49:26 +0100, Bruno Dupuis wrote: The point is Exceptions are made for error handling, not for normal workflow. That's certainly not the case in Python. Using exceptions for flow control is a standard part of the language. I

Re: Confused compare function :)

2012-12-06 Thread Steven D'Aprano
On Thu, 06 Dec 2012 09:49:26 +0100, Bruno Dupuis wrote: > The point is Exceptions are made for error handling, not for normal > workflow. That's certainly not the case in Python. Using exceptions for flow control is a standard part of the language. IndexError and StopIteration are used to dete

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

2012-12-06 Thread Steven D'Aprano
On Thu, 06 Dec 2012 02:07:51 -0800, iMath wrote: > the following code originally from > http://zetcode.com/databases/mysqlpythontutorial/ within the "Writing > images" part . > > > import MySQLdb as mdb > import sys > > try: > fin = open("Chrome_Logo.svg.png",'rb') > img = fin.read() >

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

2012-12-06 Thread 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 > > try: > fin = open("Chrome_Logo.svg.png",'rb') > img = fin.read() > fin.close()

RE: Dict comprehension help

2012-12-06 Thread Peter Otten
Joseph L. Casale wrote: [Ian Kelly] >> {k: v for d in my_list if d['key'] == value for (k, v) in d.items()} > > Ugh, had part of that backwards:) Nice! > >> However, since you say that all dicts have a unique value for >> z['key'], you should never need to actually merge two dicts, correct? >> I

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

2012-12-06 Thread Terry Reedy
On 12/6/2012 5:07 AM, iMath wrote: the following code originally from http://zetcode.com/databases/mysqlpythontutorial/ within the "Writing images" part . import MySQLdb as mdb Not part of stdlib. 'MySQLdb' should be in the subject line to get attention of someone who is familiar with it. I

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

2012-12-06 Thread iMath
the following code originally from http://zetcode.com/databases/mysqlpythontutorial/ within the "Writing images" part . import MySQLdb as mdb import sys try: fin = open("Chrome_Logo.svg.png",'rb') img = fin.read() fin.close() except IOError as e: print ("Error %d: %s" % (e.arg

Re: Confused compare function :)

2012-12-06 Thread Anatoli Hristov
On Thu, Dec 6, 2012 at 1:31 AM, Steven D'Aprano wrote: > On Wed, 05 Dec 2012 23:50:49 +0100, Anatoli Hristov wrote: > > >> def Change_price(): > > Misleading function name. What price does it change? > > >> total = 0 >> tnf = 0 > > "tnf"? Does that mean something? > > >> for row in DB:

Re: Confused compare function :)

2012-12-06 Thread Chris Angelico
On Thu, Dec 6, 2012 at 7:49 PM, Bruno Dupuis wrote: > > The point is Exceptions are made for error handling, not for normal > workflow. I hate when i read that for example: > > try: > do_stuff(mydict[k]) > except KeyError: > pass > > (loads of them in many libraries and fra

Re: Confused compare function :)

2012-12-06 Thread Bruno Dupuis
On Thu, Dec 06, 2012 at 04:32:34AM +, Steven D'Aprano wrote: > On Thu, 06 Dec 2012 03:22:53 +, Rotwang wrote: > > > On 06/12/2012 00:19, Bruno Dupuis wrote: > >> [...] > >> > >> Another advice: never ever > >> > >> except XXXError: > >> pass > >> > >> at least log, or count, or warn,

Re: Good use for itertools.dropwhile and itertools.takewhile

2012-12-06 Thread Vlastimil Brom
2012/12/5 Nick Mellor : > Neil, > > Further down the data, found another edge case: > > "Spring ONION from QLD" > > Following the spec, the whole line should be description (description starts > at first word that is not all caps.) This case breaks the latest groupby. > > N > -- > http://mail.pyth

Re: Some help in refining this regex for CSV files

2012-12-06 Thread Mark Lawrence
On 06/12/2012 07:21, Oltmans wrote: Hi guys, I've to deal with CSVs that look like following CSV (with one header and 3 legit rows where each legit row has 3 columns) Some info Date: 12/6/2012 Author: Some guy Total records: 100 header1, header2, header3 one, two, three one, "Python is gr