Re: Pickle __getstate__ __setstate__ and restoring n/w - beazley pg 172

2016-03-10 Thread dieter
"Veek. M" writes: > ... > what i wanted to know was, x = Client('192.168.0.1') will create an > object 'x' with the IP inside it. When I do: > pickle.dump(x) > pickle doesn't know where in the object the IP is, so he'll call > __getstate__ and expect the return value to be the IP, right? It doe

Re: Installing ibm_db package on Windows 7, 64-bit problem

2016-03-10 Thread Chris Angelico
On Thu, Mar 10, 2016 at 6:46 PM, Alexander Shmugliakov wrote: > Hello, has anybody successfully installed ibm_db package in the 32-bit Python > 3.5.0 environment? This is the error messages I'm receiving: > I know that the message about vcvarsall.bat is related to the Visual Studio > configurati

Pure Python routine for calculation of CRC of arbitrary length

2016-03-10 Thread wzab01
Hi, In my FPGA related work, I had to generate and verify different non-standard CRC sums in a Python based testbench. I was able to find a few CRC implementations for Python (e.g. crcmod or PyCRC), but none of them was able to work with arbitrary CRC polynomial and data of arbitrary length. Th

Re: pip install failure for cryptography, gnureadline

2016-03-10 Thread dieter
Pietro Paolini writes: > ... > I am not really familiar with the Py subsystem, even though I have got some > guidance from some colleague, I am getting stuck when installing a list of > packages contained in a file, running such command : > > > pip install -r /home/pietro/projects/cloud-provisioni

Re: Improving performance in matrix operations

2016-03-10 Thread Steven D'Aprano
On Thursday 10 March 2016 07:09, Drimades wrote: > I'm doing some tests with operations on numpy matrices in Python. As an > example, it takes about 3000 seconds to compute eigenvalues and > eigenvectors using scipy.linalg.eig(a) for a matrix 6000x6000. Is it an > acceptable time? I don't know w

Re: Installing ibm_db package on Windows 7, 64-bit problem

2016-03-10 Thread Mark Lawrence
On 10/03/2016 08:09, Chris Angelico wrote: On Thu, Mar 10, 2016 at 6:46 PM, Alexander Shmugliakov wrote: Hmm. I don't understand the warning there, but the final error is pretty straight-forward: you cannot build a package from source without having Visual Studio installed. Sadly, my usual go-t

Read and count

2016-03-10 Thread Val Krem via Python-list
Hi all, I am a new learner about python (moving from R to python) and trying read and count the number of observation by year for each city. The data set look like city year x XC1 2001 10 XC1 2001 20 XC1 2002 20 XC1 2002 10 XC1 2002 10 Yv2 2001 10 Yv2 2002 20 Yv2 2002

Simple exercise

2016-03-10 Thread Rodrick Brown
>From the following input 9 BANANA FRIES 12 POTATO CHIPS 30 APPLE JUICE 10 CANDY 5 APPLE JUICE 10 CANDY 5 CANDY 5 CANDY 5 POTATO CHIPS 30 I'm expecting the following output BANANA FRIES 12 POTATO CHIPS 60 APPLE JUICE 20 CANDY 20 However my code seems be returning incorrect value #!/usr/bin/env

Re: Read and count

2016-03-10 Thread Jussi Piitulainen
Val Krem writes: > Hi all, > > I am a new learner about python (moving from R to python) and trying > read and count the number of observation by year for each city. > > > The data set look like > city year x > > XC1 2001 10 > XC1 2001 20 > XC1 2002 20 > XC1 2002 10 > XC1 2002 10 >

Re: Read and count

2016-03-10 Thread Mark Lawrence
Hello and welcome. Please see my comments below. On 09/03/2016 21:30, Val Krem via Python-list wrote: Hi all, I am a new learner about python (moving from R to python) and trying read and count the number of observation by year for each city. The data set look like city year x XC1 2001

Re: Read and count

2016-03-10 Thread Peter Otten
Jussi Piitulainen wrote: > Val Krem writes: > >> Hi all, >> >> I am a new learner about python (moving from R to python) and trying >> read and count the number of observation by year for each city. >> >> >> The data set look like >> city year x >> >> XC1 2001 10 >> XC1 2001 20 >> XC1 2002

RE: Read and count

2016-03-10 Thread Joaquin Alzola
Try to do a .split(' ') and then add field 0 and 1 to an list. For open the file you can do it easier: with open(file) as f: for line in f: print('line') -Original Message- From: Python-list [mailto:python-list-bounces+joaquin.alzola=lebara@python.org] On Behalf Of Val Krem via Pyt

Re: Installing ibm_db package on Windows 7, 64-bit problem

2016-03-10 Thread Alexander Shmugliakov
On Thursday, March 10, 2016 at 10:09:26 AM UTC+2, Chris Angelico wrote: > On Thu, Mar 10, 2016 at 6:46 PM, Alexander Shmugliakov > wrote: > > Hello, has anybody successfully installed ibm_db package in the 32-bit > > Python 3.5.0 environment? This is the error messages I'm receiving: > > I know t

Re: Simple exercise

2016-03-10 Thread Erik
Hi. This looks a little like a homework problem, so I'll be cryptic ... :) On 10/03/16 09:02, Rodrick Brown wrote: From the following input 9 BANANA FRIES 12 POTATO CHIPS 30 APPLE JUICE 10 CANDY 5 APPLE JUICE 10 CANDY 5 CANDY 5 CANDY 5 POTATO CHIPS 30 if m: if m.group(1) not

Re: Simple exercise

2016-03-10 Thread Peter Otten
Rodrick Brown wrote: > From the following input > > 9 > BANANA FRIES 12 > POTATO CHIPS 30 > APPLE JUICE 10 > CANDY 5 > APPLE JUICE 10 > CANDY 5 > CANDY 5 > CANDY 5 > POTATO CHIPS 30 > > I'm expecting the following output > BANANA FRIES 12 > POTATO CHIPS 60 > APPLE JUICE 20 > CANDY 20 > > Howeve

Re: Simple exercise

2016-03-10 Thread Thomas 'PointedEars' Lahn
Rodrick Brown wrote: > […] > if m: > if m.group(1) not in od.keys(): > od[m.group(1)] = int(m.group(2)) > else: > od[m.group(1)] += int(od.get(m.group(1),0)) > […] This program logic appears to be wrong as you are not adding the value that you just read to the dic

Re: Text input with keyboard, via input methods

2016-03-10 Thread Marko Rauhamaa
Ben Finney : > As for how solved it is, that depends on what you're hoping for as a > solution. > > [...] > > Hopefully your operating system has a good input method system, with > many input methods available to choose from. May you find a decent > default there. I don't have an answer. I have r

Re: Simple exercise

2016-03-10 Thread Thomas 'PointedEars' Lahn
Thomas 'PointedEars' Lahn wrote: > key = m.group(1) > value = int(m.group(1)) value = int(m.group(2)) > if key not in od: > od[key] = value > else: > od[key] += value -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bit

looping and searching in numpy array

2016-03-10 Thread Heli
Dear all, I need to loop over a numpy array and then do the following search. The following is taking almost 60(s) for an array (npArray1 and npArray2 in the example below) with around 300K values. for id in np.nditer(npArray1): newId=(np.where(npArray2==id))[0][0]

Re: Question

2016-03-10 Thread Jon Ribbens
On 2016-03-10, Dennis Lee Bieber wrote: > On Wed, 9 Mar 2016 12:28:30 - (UTC), Jon Ribbens > declaimed the following: >>On 2016-03-09, Ian Kelly wrote: >>> It looks like the shell environment that comes with Git for Windows is >>> actually Windows Powershell [1], so presumably the activate.ps

Re: Pyhon 2.x or 3.x, which is faster?

2016-03-10 Thread BartC
On 10/03/2016 07:30, Mark Lawrence wrote: On 10/03/2016 00:58, BartC wrote: You think a bloody great compiler is a microbenchmark?! I have no interest in the speed of the compiler, I am interested in the run time speed of the applications that it produces which is what has been discussed thu

Re: Text input with keyboard, via input methods

2016-03-10 Thread Rustom Mody
On Thursday, March 10, 2016 at 4:21:15 PM UTC+5:30, Marko Rauhamaa wrote: > Ben Finney : > > > As for how solved it is, that depends on what you're hoping for as a > > solution. > > > > [...] > > > > Hopefully your operating system has a good input method system, with > > many input methods availa

Re: Pyhon 2.x or 3.x, which is faster?

2016-03-10 Thread Mark Lawrence
On 10/03/2016 11:50, BartC wrote: On 10/03/2016 07:30, Mark Lawrence wrote: On 10/03/2016 00:58, BartC wrote: You think a bloody great compiler is a microbenchmark?! I have no interest in the speed of the compiler, I am interested in the run time speed of the applications that it produces w

Re: Pyhon 2.x or 3.x, which is faster?

2016-03-10 Thread BartC
On 10/03/2016 01:59, Steven D'Aprano wrote: I think Bart is very old-school, and probably a bit behind the times when it comes to modern compiler and interpreter technologies. That's true. I've reached a dead-end with what I can do with interpreted, dynamically typed byte-code, but it stills

How to program round this poplib error?

2016-03-10 Thread cl
I have a (fairly simple) Python program that scans through a 'catchall' E-Mail address for things that *might* be for me. It sends anything that could be for me to my main E-Mail and discards the rest. However I *occasionally* get an error from it as follows:- Traceback (most recent call las

Re: How to program round this poplib error?

2016-03-10 Thread Mark Lawrence
On 10/03/2016 12:04, c...@isbd.net wrote: I have a (fairly simple) Python program that scans through a 'catchall' E-Mail address for things that *might* be for me. It sends anything that could be for me to my main E-Mail and discards the rest. However I *occasionally* get an error from it as fo

Re: Pyhon 2.x or 3.x, which is faster?

2016-03-10 Thread BartC
On 10/03/2016 12:15, Mark Lawrence wrote: On 10/03/2016 11:50, BartC wrote: Suppose you were on the development team that writes the optimising stages of a C compiler. You need to test the performance of the code it produces so that you can compare one optimisation with another. Would you: (a

Re: Installing ibm_db package on Windows 7, 64-bit problem

2016-03-10 Thread Chris Angelico
On Thu, Mar 10, 2016 at 8:31 PM, Alexander Shmugliakov wrote: > Thank you Chris! Actually I have received your response while in the process > (quite a lengthy one for some reason) of the VS Community Edition > installation. Will see if it will solve my problem (or at least brings me the > miss

Re: looping and searching in numpy array

2016-03-10 Thread Peter Otten
Heli wrote: > Dear all, > > I need to loop over a numpy array and then do the following search. The > following is taking almost 60(s) for an array (npArray1 and npArray2 in > the example below) with around 300K values. > > > for id in np.nditer(npArray1): > >newId=(n

Re: Pyhon 2.x or 3.x, which is faster?

2016-03-10 Thread Chris Angelico
On Thu, Mar 10, 2016 at 11:47 PM, BartC wrote: >> have no interest >> in run time speed as they are fully aware that they'll be wasting their >> precious development time, as they know that their code will be waiting >> on the file, the database or the network. What have you failed to grasp >> ab

Re: Pyhon 2.x or 3.x, which is faster?

2016-03-10 Thread Mark Lawrence
On 10/03/2016 12:47, BartC wrote: On 10/03/2016 12:15, Mark Lawrence wrote: On 10/03/2016 11:50, BartC wrote: Suppose you were on the development team that writes the optimising stages of a C compiler. You need to test the performance of the code it produces so that you can compare one optimi

Re: looping and searching in numpy array

2016-03-10 Thread Mark Lawrence
On 10/03/2016 11:43, Heli wrote: Dear all, I need to loop over a numpy array and then do the following search. The following is taking almost 60(s) for an array (npArray1 and npArray2 in the example below) with around 300K values. for id in np.nditer(npArray1): newId=(np.where(npArr

Re: How to program round this poplib error?

2016-03-10 Thread Jon Ribbens
On 2016-03-10, c...@isbd.net wrote: > # Read each message into a string and then parse with the email > module, if > # there's an error retrieving the message then just throw it away > # > try: > popmsg = pop3.retr(i+1) > except: >

Re: Pyhon 2.x or 3.x, which is faster?

2016-03-10 Thread Chris Angelico
On Fri, Mar 11, 2016 at 12:18 AM, Mark Lawrence wrote: > I have dealt with some complete dumbos in the years that I've been online, > but when it comes to thickos you're right up there with the RUE, and I can > assure you that this is meant to be an insult. > > To your way of thinking run time spe

Encapsulation in Python

2016-03-10 Thread Ben Mezger
Hi all, I've been studying Object Oriented Theory using Java. Theoretically, all attributes should be private, meaning no one except the methods itself can access the attribute; public class Foo { private int bar; ... Normally in Java, we would write getters and setters to set/get the at

Re: Pyhon 2.x or 3.x, which is faster?

2016-03-10 Thread Mark Lawrence
On 10/03/2016 13:08, Chris Angelico wrote: When people want better performance out of a number-crunching Python program, they have a few options. One is to rewrite their code in C or Fortran or something. Another is to make small tweaks so the bulk of the work is handled by numpy or Cython. A th

Re: Encapsulation in Python

2016-03-10 Thread Mark Lawrence
On 10/03/2016 13:41, Ben Mezger wrote: Hi all, I've been studying Object Oriented Theory using Java. Theoretically, all attributes should be private, meaning no one except the methods itself can access the attribute; I suggest that you read http://dirtsimple.org/2004/12/python-is-not-java.htm

Re: How to program round this poplib error?

2016-03-10 Thread cl
Jon Ribbens wrote: > On 2016-03-10, c...@isbd.net wrote: > > # Read each message into a string and then parse with the email > > module, if > > # there's an error retrieving the message then just throw it away > > # > > try: > > popmsg = pop3.retr(i

Re: How to program round this poplib error?

2016-03-10 Thread cl
Mark Lawrence wrote: > On 10/03/2016 12:04, c...@isbd.net wrote: > > I have a (fairly simple) Python program that scans through a > > 'catchall' E-Mail address for things that *might* be for me. It sends > > anything that could be for me to my main E-Mail and discards the rest. > > > > However I

EuroPython 2016: Talk voting will start on Monday

2016-03-10 Thread M.-A. Lemburg
Having received almost 300 great proposals for talks, trainings, helpdesks and posters, we now call out to all attendees to vote for what you want to see on the conference schedule. Please note that you have to have a ticket for EuroPython 2016, or have submitted a talk proposal yourself, in order

Re: Pyhon 2.x or 3.x, which is faster?

2016-03-10 Thread BartC
On 10/03/2016 13:08, Chris Angelico wrote: On Thu, Mar 10, 2016 at 11:47 PM, BartC wrote: You just don't get it. Both of you "just don't get" something that the other sees as critically important. Before this thread gets to fisticuffs, may I please summarize the points that probably nobody

Re: Pyhon 2.x or 3.x, which is faster?

2016-03-10 Thread BartC
On 10/03/2016 02:29, Ben Finney wrote: BartC writes: So long as /someone else/ uses the hard language to created the needed libraries, the speed of pure Python is irrelevant. New version of Python is now half the speed? Another shrug! Citation needed. I don't know of any released version of

Re: Text input with keyboard, via input methods

2016-03-10 Thread Jerry Hill
On Thu, Mar 10, 2016 at 5:51 AM, Marko Rauhamaa wrote: > I don't have an answer. I have requirements, though: > > * I should be able to get the character by knowing its glyph (shape). > > * It should be very low-level and work system-wide, preferably over the >network (I'm typing this over t

RE: Encapsulation in Python

2016-03-10 Thread Dan Strohl via Python-list
> I've been studying Object Oriented Theory using Java. Theoretically, all > attributes should be private, meaning no one except the methods itself can > access the attribute; > > public class Foo { > private int bar; > ... Why? I mean sure, lots of them should be, but if I am doing some

Re: Text input with keyboard, via input methods

2016-03-10 Thread Marko Rauhamaa
Jerry Hill : > On Thu, Mar 10, 2016 at 5:51 AM, Marko Rauhamaa wrote: >> I don't have an answer. I have requirements, though: >> >> * I should be able to get the character by knowing its glyph (shape). >> >> * It should be very low-level and work system-wide, preferably over the >>network (

Re: Encapsulation in Python

2016-03-10 Thread Ian Kelly
On Thu, Mar 10, 2016 at 6:41 AM, Ben Mezger wrote: > Hi all, > > I've been studying Object Oriented Theory using Java. Theoretically, all > attributes should be private, meaning no one except the methods itself > can access the attribute; > > public class Foo { > private int bar; > ... En

Re: Simple exercise

2016-03-10 Thread Thomas 'PointedEars' Lahn
Thomas 'PointedEars' Lahn wrote: [ > key = m.group(1) > value = int(m.group(2)) > > if key not in od: > od[key] = value > else: > od[key] += value > > But there is probably an even more pythonic way to do this. ] For example, based on the orig

Re: Simple exercise

2016-03-10 Thread Thomas 'PointedEars' Lahn
Thomas 'PointedEars' Lahn wrote: > od = OrderedDict() This is pointless, then. > […] > od = OrderedDict(map(lambda item: (item[0], 0), items)) > for item in items: od[item[0]] += item[1] -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail

Re: python domain in China. This showed up on Python list

2016-03-10 Thread Uri Even-Chen
I don't register domain names in countries - any domain name which ends with 2 letters. If you want you can register my name in .cn or any other country, I don't care. *Uri Even-Chen* [image: photo] Phone: +972-54-3995700 Email: u...@speedy.net Website: http://www.speedysoftware.com/uri/en/

Re: looping and searching in numpy array

2016-03-10 Thread Heli
On Thursday, March 10, 2016 at 2:02:57 PM UTC+1, Peter Otten wrote: > Heli wrote: > > > Dear all, > > > > I need to loop over a numpy array and then do the following search. The > > following is taking almost 60(s) for an array (npArray1 and npArray2 in > > the example below) with around 300K val

Re: looping and searching in numpy array

2016-03-10 Thread Heli
On Thursday, March 10, 2016 at 5:49:07 PM UTC+1, Heli wrote: > On Thursday, March 10, 2016 at 2:02:57 PM UTC+1, Peter Otten wrote: > > Heli wrote: > > > > > Dear all, > > > > > > I need to loop over a numpy array and then do the following search. The > > > following is taking almost 60(s) for an

HDF5 data set, unable to read contents

2016-03-10 Thread varun7rs
Hello everyone, I recently came across a package called matrix2latex which simplifies the creation of very large tables. So, I saved my data in .mat format using the '-v7.3' extension so that they can be read by python. Now, when I try to read these files, I'm having some problems in reproducin

Re: Read and count

2016-03-10 Thread Val Krem via Python-list
Thank you very much for the help. First I want count by city and year. City year count Xc1.2001. 1 Xc1.2002. 3 Yv1. 2001. 1 Yv2.2002. 4 This worked fine ! Now I want to count by city only City. Count Xc1. 4 Yv2. 5 Then combine these two objects with the original data and

Re: Review Request of Python Code

2016-03-10 Thread subhabangalore
On Wednesday, March 9, 2016 at 9:49:17 AM UTC+5:30, subhaba...@gmail.com wrote: > Dear Group, > > I am trying to write a code for pulling data from MySQL at the backend and > annotating words and trying to put the results as separated sentences with > each line. The code is generally running fin

Re: Simple exercise

2016-03-10 Thread Terry Reedy
On 3/10/2016 4:02 AM, Rodrick Brown wrote: From the following input 9 BANANA FRIES 12 POTATO CHIPS 30 APPLE JUICE 10 CANDY 5 APPLE JUICE 10 CANDY 5 CANDY 5 CANDY 5 POTATO CHIPS 30 I'm expecting the following output BANANA FRIES 12 POTATO CHIPS 60 APPLE JUICE 20 CANDY 20 However my code seems

context managers inline?

2016-03-10 Thread Neal Becker
Is there a way to ensure resource cleanup with a construct such as: x = load (open ('my file', 'rb)) Is there a way to ensure this file gets closed? -- https://mail.python.org/mailman/listinfo/python-list

Re: Review Request of Python Code

2016-03-10 Thread BartC
On 10/03/2016 18:12, subhabangal...@gmail.com wrote: On Wednesday, March 9, 2016 at 9:49:17 AM UTC+5:30, subhaba...@gmail.com wrote: Thank you Steve for writing the whole code. It is working full and fine. But speed is still an issue. We need to speed up. Which bit is too slow? (Perhaps the

Re: context managers inline?

2016-03-10 Thread sohcahtoa82
On Thursday, March 10, 2016 at 10:33:47 AM UTC-8, Neal Becker wrote: > Is there a way to ensure resource cleanup with a construct such as: > > x = load (open ('my file', 'rb)) > > Is there a way to ensure this file gets closed? with open('my file', 'rb') as f: x = load(f) -- https://mail.p

Re: Review Request of Python Code

2016-03-10 Thread Matt Wheeler
On 10 March 2016 at 18:12, wrote: > Matt, thank you for if...else suggestion, the data of NewTotalTag.txt > is like a simple list of words with unconventional tags, like, > > w1 tag1 > w2 tag2 > w3 tag3 > ... > ... > w3 tag3 > > like that. I suspected so. The way your code currently works, if y

Re: context managers inline?

2016-03-10 Thread Neal Becker
sohcahto...@gmail.com wrote: > On Thursday, March 10, 2016 at 10:33:47 AM UTC-8, Neal Becker wrote: >> Is there a way to ensure resource cleanup with a construct such as: >> >> x = load (open ('my file', 'rb)) >> >> Is there a way to ensure this file gets closed? > > with open('my file', 'rb')

Re: context managers inline?

2016-03-10 Thread Ian Kelly
On Thu, Mar 10, 2016 at 11:59 AM, Neal Becker wrote: > sohcahto...@gmail.com wrote: > >> On Thursday, March 10, 2016 at 10:33:47 AM UTC-8, Neal Becker wrote: >>> Is there a way to ensure resource cleanup with a construct such as: >>> >>> x = load (open ('my file', 'rb)) >>> >>> Is there a way to e

RE: Review Request of Python Code

2016-03-10 Thread Joaquin Alzola
SQL doesn't allow decimal numbers for LIMIT. Use decimal numbers it still work but is the proper way. Then clean up a bit your code and remove the commented lines # -Original Message- From: Python-list [mailto:python-list-bounces+joaquin.alzola=lebara@python.org] On Behalf Of subhab

Re: Pyhon 2.x or 3.x, which is faster?

2016-03-10 Thread Mark Lawrence
On 10/03/2016 14:22, BartC wrote: But during development, it doesn't hurt if the dynamic version isn't quite so slow! In [1]: import this The Zen of Python, by Tim Peters Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than c

Re: Encapsulation in Python

2016-03-10 Thread Mark Lawrence
On 10/03/2016 14:57, Dan Strohl via Python-list wrote: I've been studying Object Oriented Theory using Java. Theoretically, all attributes should be private, meaning no one except the methods itself can access the attribute; public class Foo { private int bar; ... For the benefit o

Re: context managers inline?

2016-03-10 Thread Mark Lawrence
On 10/03/2016 18:33, Neal Becker wrote: Is there a way to ensure resource cleanup with a construct such as: x = load (open ('my file', 'rb)) Is there a way to ensure this file gets closed? I don't see how there can be. Surely you must split it into two lines to use the context manager via

Re: Review Request of Python Code

2016-03-10 Thread Mark Lawrence
On 09/03/2016 04:18, subhabangal...@gmail.com wrote: Dear Group, I am trying to write a code for pulling data from MySQL at the backend and annotating words and trying to put the results as separated sentences with each line. The code is generally running fine but I am feeling it may be better

Re: Pyhon 2.x or 3.x, which is faster?

2016-03-10 Thread Chris Angelico
On Fri, Mar 11, 2016 at 1:22 AM, BartC wrote: >> >> 1) Unicode support, intrinsic to the language, is crucial, even if >> BartC refuses to recognize this. Anything released beyond the confines >> of his personal workspace will need full Unicode support, otherwise it >> is a problem to the rest of

Re: Review Request of Python Code

2016-03-10 Thread subhabangalore
On Friday, March 11, 2016 at 12:22:31 AM UTC+5:30, Matt Wheeler wrote: > On 10 March 2016 at 18:12, wrote: > > Matt, thank you for if...else suggestion, the data of NewTotalTag.txt > > is like a simple list of words with unconventional tags, like, > > > > w1 tag1 > > w2 tag2 > > w3 tag3 > > ... >

Re: context managers inline?

2016-03-10 Thread Chris Angelico
On Fri, Mar 11, 2016 at 5:33 AM, Neal Becker wrote: > Is there a way to ensure resource cleanup with a construct such as: > > x = load (open ('my file', 'rb)) > > Is there a way to ensure this file gets closed? Yep! def read_file(fn, *a, **kw): with open(fn, *a, **kw) as f: return f.

Re: Text input with keyboard, via input methods

2016-03-10 Thread Chris Angelico
On Fri, Mar 11, 2016 at 2:13 AM, Marko Rauhamaa wrote: > Jerry Hill : > >> On Thu, Mar 10, 2016 at 5:51 AM, Marko Rauhamaa wrote: >>> I don't have an answer. I have requirements, though: >>> >>> * I should be able to get the character by knowing its glyph (shape). >>> >>> * It should be very lo

Other difference with Perl: Python scripts in a pipe

2016-03-10 Thread Fillmore
when I put a Python script in pipe with other commands, it will refuse to let go silently. Any way I can avoid this? $ python somescript.py | head -5 line 1 line 3 line 3 line 4 line 5 Traceback (most recent call last): File "./somescript.py", line 50, in sys.stdout.write(row[0]) Broken

Re: Other difference with Perl: Python scripts in a pipe

2016-03-10 Thread Ian Kelly
On Thu, Mar 10, 2016 at 2:33 PM, Fillmore wrote: > > when I put a Python script in pipe with other commands, it will refuse to > let go silently. Any way I can avoid this? What is your script doing? I don't see this problem. ikelly@queso:~ $ cat somescript.py import sys for i in range(20):

Re: Text input with keyboard, via input methods

2016-03-10 Thread Ben Bacarisse
Marko Rauhamaa writes: > Ben Finney : > >> As for how solved it is, that depends on what you're hoping for as a >> solution. >> >> [...] >> >> Hopefully your operating system has a good input method system, with >> many input methods available to choose from. May you find a decent >> default ther

Re: Other difference with Perl: Python scripts in a pipe

2016-03-10 Thread Fillmore
On 3/10/2016 4:46 PM, Ian Kelly wrote: On Thu, Mar 10, 2016 at 2:33 PM, Fillmore wrote: when I put a Python script in pipe with other commands, it will refuse to let go silently. Any way I can avoid this? What is your script doing? I don't see this problem. ikelly@queso:~ $ cat somescript.p

Re: Other difference with Perl: Python scripts in a pipe

2016-03-10 Thread Peter Otten
Ian Kelly wrote: > On Thu, Mar 10, 2016 at 2:33 PM, Fillmore > wrote: >> >> when I put a Python script in pipe with other commands, it will refuse to >> let go silently. Any way I can avoid this? > > What is your script doing? I don't see this problem. > > ikelly@queso:~ $ cat somescript.py > i

Re: Other difference with Perl: Python scripts in a pipe

2016-03-10 Thread Ian Kelly
On Thu, Mar 10, 2016 at 3:09 PM, Peter Otten <__pete...@web.de> wrote: > I suppose you need to fill the OS-level cache: > > $ cat somescript.py > import sys > > for i in range(int(sys.argv[1])): > sys.stdout.write('line %d\n' % i) > $ python somescript.py 20 | head -n5 > line 0 > line 1 > line

Re: Text input with keyboard, via input methods

2016-03-10 Thread Marko Rauhamaa
Ben Bacarisse : > Marko Rauhamaa writes: >> * I should be able to get the character by knowing its glyph >>(shape). >> >> * It should be very low-level and work system-wide, preferably over >>the network (I'm typing this over the network). > > I think you are a Gnus user so you probably

Re: Simple exercise

2016-03-10 Thread Gregory Ewing
Rodrick Brown wrote: if m.group(1) not in od.keys(): od[m.group(1)] = int(m.group(2)) else: od[m.group(1)] += int(od.get(m.group(1),0)) Others have pointed out what's wrong with this, but here's a general tip: Don't repeat complicated subexpressions such as m.group(1

Re: Simple exercise

2016-03-10 Thread Chris Angelico
On Fri, Mar 11, 2016 at 10:24 AM, Gregory Ewing wrote: > Instead, pull them out and give them meaningful names. > Doing so with the above code gives: > > name = m.group(1) > value = m.group(2) > if name not in od.keys(): > od[name] = int(value) > else: > od[name] += int(od.get(name

Re: Other difference with Perl: Python scripts in a pipe

2016-03-10 Thread Fillmore
On 3/10/2016 5:16 PM, Ian Kelly wrote: Interesting, both of these are probably worth bringing up as issues on the bugs.python.org tracker. I'm not sure that the behavior should be changed (if we get an error, we shouldn't just swallow it) but it does seem like a significant hassle for writing co

Re: Other difference with Perl: Python scripts in a pipe

2016-03-10 Thread INADA Naoki
On Fri, Mar 11, 2016 at 8:48 AM, Fillmore wrote: > On 3/10/2016 5:16 PM, Ian Kelly wrote: > >> >> Interesting, both of these are probably worth bringing up as issues on >> the bugs.python.org tracker. I'm not sure that the behavior should be >> changed (if we get an error, we shouldn't just swall

Re: Simple exercise

2016-03-10 Thread BartC
On 10/03/2016 09:02, Rodrick Brown wrote: From the following input 9 BANANA FRIES 12 POTATO CHIPS 30 APPLE JUICE 10 CANDY 5 APPLE JUICE 10 CANDY 5 CANDY 5 CANDY 5 POTATO CHIPS 30 I'm expecting the following output BANANA FRIES 12 POTATO CHIPS 60 APPLE JUICE 20 CANDY 20 Here's a rather un-Py

non printable (moving away from Perl)

2016-03-10 Thread Fillmore
Here's another handy Perl regex which I am not sure how to translate to Python. I use it to avoid processing lines that contain funny chars... if ($string =~ /[^[:print:]]/) {next OUTER;} :) -- https://mail.python.org/mailman/listinfo/python-list

Re: non printable (moving away from Perl)

2016-03-10 Thread Ian Kelly
On Mar 10, 2016 5:15 PM, "Fillmore" wrote: > > > Here's another handy Perl regex which I am not sure how to translate to Python. > > I use it to avoid processing lines that contain funny chars... > > if ($string =~ /[^[:print:]]/) {next OUTER;} Python's re module doesn't support POSIX character c

Re: Other difference with Perl: Python scripts in a pipe

2016-03-10 Thread Fillmore
On 3/10/2016 7:08 PM, INADA Naoki wrote: No. I see it usually. Python's zen says: Errors should never pass silently. Unless explicitly silenced. When failed to write to stdout, Python should raise Exception. You can silence explicitly when it's safe: try: print(...) except Broken

Re: Encapsulation in Python

2016-03-10 Thread Rick Johnson
On Thursday, March 10, 2016 at 9:28:06 AM UTC-6, Ian wrote: > Encapsulation in Python is based on trust rather than the > authoritarian style of C++ / Java. The maxim in the Python > community is that "we're all consenting adults". If I > don't intend an attribute to be messed with, then I'll > ma

Re: A mistake which almost went me mad

2016-03-10 Thread Rick Johnson
On Thursday, March 10, 2016 at 12:13:39 AM UTC-6, Rustom Mody wrote: > As usual Rick I find myself agreeing with your direction [also it seems > Random832's direction] Somehow i missed Random's remark... Hmm, he does have a good idea! Introducing a new "import statement" would not break anything

Re: Simple exercise

2016-03-10 Thread Mark Lawrence
On 11/03/2016 00:05, BartC wrote: On 10/03/2016 09:02, Rodrick Brown wrote: From the following input 9 BANANA FRIES 12 POTATO CHIPS 30 APPLE JUICE 10 CANDY 5 APPLE JUICE 10 CANDY 5 CANDY 5 CANDY 5 POTATO CHIPS 30 I'm expecting the following output BANANA FRIES 12 POTATO CHIPS 60 APPLE JUICE 2

Re: non printable (moving away from Perl)

2016-03-10 Thread Mark Lawrence
On 11/03/2016 00:25, Ian Kelly wrote: On Mar 10, 2016 5:15 PM, "Fillmore" wrote: Here's another handy Perl regex which I am not sure how to translate to Python. I use it to avoid processing lines that contain funny chars... if ($string =~ /[^[:print:]]/) {next OUTER;} Python's re module

Re: Simple exercise

2016-03-10 Thread BartC
On 11/03/2016 01:21, Mark Lawrence wrote: On 11/03/2016 00:05, BartC wrote: def last(a): return a[-1] def init(a): # all except last element return a[0:len(a)-1] What is wrong with a[0:1] ? The returns the head of the list. I need everything except the last elem

Re: Simple exercise

2016-03-10 Thread Larry Martell
On Thu, Mar 10, 2016 at 8:45 PM, BartC wrote: > Any other way of traversing two lists in parallel? zip -- https://mail.python.org/mailman/listinfo/python-list

Re: Simple exercise

2016-03-10 Thread Martin A. Brown
>>> for i in range(len(names)): >>> print (names[i],totals[i]) >> >> Always a code smell when range() and len() are combined. > > Any other way of traversing two lists in parallel? Yes. Builtin function called 'zip'. https://docs.python.org/3/library/functions.html#zip Toy example: im

Re: Simple exercise

2016-03-10 Thread Mark Lawrence
On 11/03/2016 01:45, BartC wrote: On 11/03/2016 01:21, Mark Lawrence wrote: On 11/03/2016 00:05, BartC wrote: def last(a): return a[-1] def init(a): # all except last element return a[0:len(a)-1] What is wrong with a[0:1] ? The returns the head of the list. I ne

Re: Simple exercise

2016-03-10 Thread Mark Lawrence
On 11/03/2016 01:56, Martin A. Brown wrote: for i in range(len(names)): print (names[i],totals[i]) Always a code smell when range() and len() are combined. Any other way of traversing two lists in parallel? Yes. Builtin function called 'zip'. https://docs.python.org/3/library/fu

Re: Simple exercise

2016-03-10 Thread Chris Kaynor
On Thu, Mar 10, 2016 at 4:05 PM, BartC wrote: > Here's a rather un-Pythonic and clunky version. But it gives the expected > results. (I've dispensed with file input, but that can easily be added > back.) > > def last(a): > return a[-1] > > def init(a): # all except last elemen

Re: Simple exercise

2016-03-10 Thread BartC
On 11/03/2016 02:03, Mark Lawrence wrote: On 11/03/2016 01:45, BartC wrote: On 11/03/2016 01:21, Mark Lawrence wrote: On 11/03/2016 00:05, BartC wrote: def last(a): return a[-1] def init(a): # all except last element return a[0:len(a)-1] What is wrong with a[0:1]

Re: non printable (moving away from Perl)

2016-03-10 Thread Ian Kelly
On Mar 10, 2016 6:33 PM, "Mark Lawrence" wrote: > > On 11/03/2016 00:25, Ian Kelly wrote: >> >> On Mar 10, 2016 5:15 PM, "Fillmore" wrote: >>> >>> >>> >>> Here's another handy Perl regex which I am not sure how to translate to >> >> Python. >>> >>> >>> I use it to avoid processing lines that cont

Re: context managers inline?

2016-03-10 Thread Steven D'Aprano
On Fri, 11 Mar 2016 05:33 am, Neal Becker wrote: > Is there a way to ensure resource cleanup with a construct such as: > > x = load (open ('my file', 'rb)) > > Is there a way to ensure this file gets closed? Depends on what you mean by "ensure". Have load() call the file's close method may be g

Re: Text input with keyboard, via input methods

2016-03-10 Thread Larry Hudson via Python-list
On 03/09/2016 11:54 PM, Rustom Mody wrote: [...] In between these two extremes we have many possibilities - ibus/gchar etc - compose key - alternate keyboard layouts Using all these levels judiciously seems to me a good idea... FWIW -- in Mint Linux you can select the compose key with the foll

Re: Pyhon 2.x or 3.x, which is faster?

2016-03-10 Thread Steven D'Aprano
On Fri, 11 Mar 2016 07:07 am, Chris Angelico wrote: > You _need_ [emphasis in original] to make sure > that you're thinking about text as text, and that means being aware of > RTL vs LTR, combining characters, case conversions, collations, etc, > etc, etc, all in terms of Unicode rather than as ei

  1   2   >