Re: Python 3: dict & dict.keys()

2013-07-24 Thread Oscar Benjamin
On Jul 24, 2013 2:27 PM, "Peter Otten" <__pete...@web.de> wrote: > > Oscar Benjamin wrote: > > > On Jul 24, 2013 7:25 AM, "Peter Otten" <__pete...@web.de> wrote: > >> > >> Ethan Furman wrote: > >> > >> > So, m

Unexpected results comparing float to Fraction

2013-07-30 Thread Oscar Benjamin
On 29 July 2013 17:09, MRAB wrote: > On 29/07/2013 16:43, Steven D'Aprano wrote: >> >> Comparing floats to Fractions gives unexpected results: You may not have expected these results but as someone who regularly uses the fractions module I do expect them. >> # Python 3.3 >> py> from fractions im

Re: Read STDIN as bytes rather than a string

2012-06-18 Thread Benjamin Kaplan
On Mon, Jun 18, 2012 at 4:13 PM, Jason Friedman wrote: > I tried this: > > Python 3.2.2 (default, Feb 24 2012, 20:07:04) > [GCC 4.6.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. import sys import io fh = io.open(sys.stdin) > Traceback (most re

Re: "constant sharing" works differently in REPL than in script ?

2012-06-18 Thread Benjamin Kaplan
On Mon, Jun 18, 2012 at 7:52 PM, wrote: > Listening to 'Radio Free Python' episode 8 > (http://radiofreepython.com/episodes/8/ - around about the 30 minute mark) I > heard that Python pre creates some integer constants to avoid a proliferation > of objects with the same value. > > I was intere

Re: Read STDIN as bytes rather than a string

2012-06-19 Thread Oscar Benjamin
On 19 June 2012 00:53, Jason Friedman wrote: > Which leads me to another question ... how can I debug these things? > > $ echo 'hello' | python3 -m pdb ~/my-input.py > > /home/jason/my-input.py(2)() > -> import sys > (Pdb) *** NameError: name 'hello' is not defined > -- > http://mail.python.org/m

Re: None shown in output

2012-06-21 Thread Benjamin Kaplan
On Thu, Jun 21, 2012 at 8:42 PM, Xander Solis wrote: > Hello Python list, > > Noob here with a newbie question. I'm reading and working on the exercise of > the book, Learn Python the Hard way 2.0. When I use this code, I get "None" > on the output. My question is why does this happen? > > def get

Re: None shown in output

2012-06-21 Thread Benjamin Kaplan
damn On Thu, Jun 21, 2012 at 9:24 PM, Benjamin Kaplan wrote: > On Thu, Jun 21, 2012 at 8:42 PM, Xander Solis wrote: >> Hello Python list, >> >> Noob here with a newbie question. I'm reading and working on the exercise of >> the book, Learn Python the Hard way

Re: Faster way to map numpy arrays

2012-06-25 Thread Oscar Benjamin
On 25 June 2012 08:24, Stefan Behnel wrote: > Saurabh Kabra, 25.06.2012 05:37: > > I have written a script to map a 2D numpy array(A) onto another array(B) > of > > different dimension. more than one element (of array A) are summed and > > mapped to each element of array B. To achieve this I cre

Re: Executing Python Scripts on Mac using Python Launcher

2012-06-25 Thread Benjamin Kaplan
On Mon, Jun 25, 2012 at 11:19 AM, David Thomas wrote: > Hello, > This is my first post so go easy on me.  I am just beginning to program using > Python on Mac.  When I try to execute a file using Python Launcher my code > seems to cause an error in terminal, when I execute the exact same piece o

Re: Perl __DATA__ construct.

2012-06-25 Thread Benjamin Kaplan
On Mon, Jun 25, 2012 at 2:20 PM, Mladen Gogala wrote: > I have a script in Perl that I need to rewrite to Python. The script > contains __DATA__ at the end of the script, which enables Perl to access > all the data after that through a file descriptor, like this: > > usage() if ( !$stat or !define

Re: Faster way to map numpy arrays

2012-06-26 Thread Oscar Benjamin
On 26 June 2012 04:20, Saurabh Kabra wrote: > Thanks guys > > I implemented a numpy array with fancy indices and got rid of the list and > the loops. The time to do the mapping improved ~10x. As a matter of fact, > the number of elements in array A to be summed and mapped was different for > each

Re: Executing Python Scripts on Mac using Python Launcher

2012-06-26 Thread Benjamin Kaplan
On Tue, Jun 26, 2012 at 10:19 AM, David Thomas wrote: > I have installed Python 2.7.3 from Python.org also in Terminal it states that > I have 2.7.3. > How can I execute the script from Terminal?  I've tried typing python into > the window and then dragging the file to terminal but I get a synta

Re: Is there any way to decode String using unknown codec?

2012-06-27 Thread Benjamin Kaplan
On Wed, Jun 27, 2012 at 6:14 PM, wrote: > Hi > I'm a Korean and when I use modules like sys, os, &c, > sometimes the interpreter show me broken strings like > '\x13\xb3\x12\xc8'. > It mustbe the Korean "alphabet" but I can't decode it to the rightway. > I tried to decode it using codecs like cp94

Re: moving methods from class to instance of other class

2012-06-28 Thread Benjamin Kaplan
On Wed, Jun 27, 2012 at 11:59 PM, lars van gemerden wrote: > Hi all, > > I have some trouble with the following question: Let say i have the > following classes: > > class A(object): >    def __init__(self): >        self.name = 'a' >    def do(self): >        print 'A.do: self.name =', self.name

Re: how to compile pygtk in python2.7?

2012-07-07 Thread Benjamin Kaplan
On Sat, Jul 7, 2012 at 9:47 PM, contro opinion wrote: > 1.download pygtk > > 2.cd /home/tiger/pygtk-2.24.0 > > 3.PYTHON=/usr/bin/python2.7 ./configure --prefix=/usr > 4. make > 5. make install > > tiger@ocean:~$ python2.7 > Python 2.7.3 (default, Jul 1 2012, 14:13:18) > [GCC 4.4.5] on linux2 >

Re: Opening multiple Files in Different Encoding

2012-07-11 Thread Oscar Benjamin
On 11 July 2012 19:15, wrote: > On Tuesday, July 10, 2012 11:16:08 PM UTC+5:30, Subhabrata wrote: > > Dear Group, > > > > I kept a good number of files in a folder. Now I want to read all of > > them. They are in different formats and different encoding. Using > > listdir/glob.glob I am able to f

Re: help

2012-07-19 Thread Benjamin Kaplan
On Jul 19, 2012 4:04 PM, "Miriam Gomez Rios" wrote: > > Hello, sorry for bothering you, but I have a doubt, > > Is there a way to turn this string into a tuplelist??, I need it for gurobi > > ('per1','persona1.1','pro1'),('per1','persona1.1','pro2'),('per1','persona1.1','pro3'),('per1','person

Re: properly catch SIGTERM

2012-07-20 Thread Oscar Benjamin
What about Kushal's suggestion above? Does the following work for you? signal.signal(signal.SIGTERM, my_SIGTERM_handler) signal.siginterrupt(signal.SIGTERM, flag=False) According to the siginterrupt docs ( http://docs.python.org/library/signal.html) """ Change system call restart behaviour: if fl

Re: default repr?

2012-07-22 Thread Oscar Benjamin
On 22 July 2012 23:48, Dan Stromberg wrote: > > If a class has defined its own __repr__ method, is there a way of getting > the default repr output for that class anyway? > For new style classes you can just call object.__repr__ e.g.: In [1]: class A(object): ...: pass ...: In [2]: c

Re: default repr?

2012-07-23 Thread Oscar Benjamin
On 23 July 2012 01:24, Steven D'Aprano wrote: > On Mon, 23 Jul 2012 08:54:00 +1000, Chris Angelico wrote: > > > On Mon, Jul 23, 2012 at 8:48 AM, Dan Stromberg > > wrote: > >> If a class has defined its own __repr__ method, is there a way of > >> getting the default repr output for that class any

Re: argparse limitations

2012-07-27 Thread Oscar Benjamin
On 27 July 2012 15:26, Benoist Laurent wrote: > Hi, > > I'm impletting a tool in Python. > I'd like this tool to behave like a standard unix tool, as grep for > exemple. > I chose to use the argparse module to parse the command line and I think > I'm getting into several limitations of this modul

Re: argparse limitations

2012-07-31 Thread Oscar Benjamin
On Jul 31, 2012 10:32 AM, "Benoist Laurent" wrote: > > Well sorry about that but it seems I was wrong. > It was Friday evening and I guess I've not been careful. > > Actually when you specify nargs="?", the doc says "One argument will be consumed from the command line if possible, and produced as

Re: argparse limitations

2012-07-31 Thread Oscar Benjamin
type=int, default=10) > > # create the parser for the "bar" command > sum_parser = subparsers.add_parser("bar", help="bar help") > > return parser > > > if __name__ == '__main__': > args = define_options(

Re: profiling and optimizing

2012-07-31 Thread Oscar Benjamin
On 31 July 2012 13:13, Rita wrote: > hello, > > I recently inherented a large python process and everything is lovely. As > a learning experience I would like to optimize the code so I ran it thru > the profiler > > python -m cProfile myscript.py > > It seems majority of the time is taking in the

Re: argparse limitations

2012-07-31 Thread Oscar Benjamin
On 31 July 2012 13:51, Benoist Laurent wrote: > > Le Jul 31, 2012 à 1:45 PM, Oscar Benjamin a écrit : > > > > On 31 July 2012 12:03, Benoist Laurent wrote: > >> Finally. >> >> The code I proposed doesn't work in this case: if you add any positional &g

Re: looking for a neat solution to a nested loop problem

2012-08-06 Thread Oscar Benjamin
Are you familiar with the itertools module? itertools.product is designed for this purpose: http://docs.python.org/library/itertools#itertools.product Oscar. On 6 August 2012 16:52, Tom P wrote: > consider a nested loop algorithm - > > for i in range(100): > for j in range(100): >

Re: looking for a neat solution to a nested loop problem

2012-08-06 Thread Oscar Benjamin
On 6 August 2012 16:52, Tom P wrote: > consider a nested loop algorithm - > > for i in range(100): > for j in range(100): > do_something(i,j) > > Now, suppose I don't want to use i = 0 and j = 0 as initial values, but > some other values i = N and j = M, and I want to iterate through

Re: looking for a neat solution to a nested loop problem

2012-08-06 Thread Oscar Benjamin
On 6 August 2012 18:14, Tom P wrote: > On 08/06/2012 06:18 PM, Nobody wrote: > >> On Mon, 06 Aug 2012 17:52:31 +0200, Tom P wrote: >> >> consider a nested loop algorithm - >>> >>> for i in range(100): >>> for j in range(100): >>> do_something(i,j) >>> >>> Now, suppose I don't wan

Re: I thought I understood how import worked...

2012-08-07 Thread Benjamin Kaplan
On Aug 7, 2012 8:41 AM, "Roy Smith" wrote: > > On Tuesday, August 7, 2012 9:55:16 AM UTC-4, Ben Finney wrote: > > > The tutorial is misleading on this. It it says plainly: > > > > A module can contain executable statements as well as function > > definitions. […] They are executed only th

Re: Pickle file and send via socket

2012-08-08 Thread Oscar Benjamin
On 8 August 2012 16:07, lipska the kat wrote: > On 08/08/12 14:50, S.B wrote: > >> On Wednesday, August 8, 2012 3:48:43 PM UTC+3, lipska the kat wrote: >> >>> On 06/08/12 14:32, S.B wrote: >>> >>> > [snip] > > > Thank you so much ! >> The examples are very helpful. >> What happens if I have a re

Re: save dictionary to a file without brackets.

2012-08-09 Thread Oscar Benjamin
On Aug 9, 2012 9:17 PM, wrote: > > Hi, > I have a dict() unique > like this > {(4, 5): 1, (5, 4): 1, (4, 4): 2, (2, 3): 1, (4, 3): 2} > and i want to print to a file without the brackets comas and semicolon in order to obtain something like this? > 4 5 1 > 5 4 1 > 4 4 2 > 2 3 1 > 4 3 2 > Any ideas

Re: save dictionary to a file without brackets.

2012-08-09 Thread Oscar Benjamin
> What do you think? is there a way to speed up the process? > Thanks > Giuseppe Which part is slow? How slow is it? A simple test to find the slow part of your code is to print messages between the commands so that you can see how long it takes between each message. Oscar. -- http://mail.pytho

Re: save dictionary to a file without brackets.

2012-08-09 Thread Oscar Benjamin
On Aug 10, 2012 12:34 AM, "Giuseppe Amatulli" wrote: > > Ciao, > is 12 minutes for 5000x5000 pixel image. half of the time is for > reading the arrays. > and the other half for making the loop. > I will try again to incorporate the mask action in the loop > and > read the image line by line. > Tha

Re: Idle no longer works

2012-08-11 Thread Benjamin Kaplan
On Sat, Aug 11, 2012 at 4:09 PM, Opap-OJ wrote: > I can no longer open the Idle IDE for Python on Windows 7. > > For 3-5 years I used Idle for all my python work. But in January this > happens: > > When I right click on a python file and choose "open with Idle" nothing > happens. > > If I doubl

Re: how to fix error "Requires python(abi)=2.4"

2012-08-14 Thread Benjamin Kaplan
On Aug 14, 2012 4:51 AM, "sagarnikam123" wrote: > > i am installing numpy on fedora with python 2.6,2.7 & 3.1 > > > > -- Python bytecode and C interface are not compatible across versions. If you're trying to install a numpy binary that was compiled against 2.4, it won't work with newer versions.

Re: New internal string format in 3.3

2012-08-19 Thread Oscar Benjamin
On 19 August 2012 15:09, wrote: > I can not give you more numbers than those I gave. > As a end user, I noticed and experimented my random tests > are always slower in Py3.3 than in Py3.2 on my Windows platform. > Do the problems have a significant impact on any real application (rather than ran

Re: New internal string format in 3.3

2012-08-19 Thread Oscar Benjamin
On Aug 19, 2012 5:22 PM, wrote > > Py 3.2.3 > >>> timeit.timeit("('aœ€'*100).replace('a', 'œ€é')") > 4.99396356635981 > > Py 3.3b2 > >>> timeit.timeit("('aœ€'*100).replace('a', 'œ€é')") > 7.560455708007855 > > Maybe, not so demonstative. It shows at least, we > are far away from the 10-30% "annouc

Re: How to convert base 10 to base 2?

2012-08-20 Thread Benjamin Kaplan
On Mon, Aug 20, 2012 at 12:50 AM, wrote: > Hi, > as you can argue from the subject, i'm really,really new to python. > What is the best way to achieve that with python? Because the syntax > int('30',2) doesn't seem to work! That syntax goes the other way- from a string representing a number in

Re: Abuse of Big Oh notation

2012-08-20 Thread Oscar Benjamin
On Sun, 19 Aug 2012 16:42:03 -0700, Paul Rubin wrote: Steven D'Aprano writes: > Of course *if* k is constant, O(k) is constant too, but k is not > constant. In context we are talking about string indexing and slicing. > There is no value of k, say, k = 2, for which you can say "People will

Re: Abuse of Big Oh notation

2012-08-20 Thread Oscar Benjamin
On 20 August 2012 17:01, Paul Rubin wrote: > Oscar Benjamin writes: > > No it doen't. It is still O(k). The point of big O notation is to > > understand the asymptotic behaviour of one variable as it becomes > > large because of changes in other variables. > >

Re: Class.__class__ magic trick help

2012-08-21 Thread Oscar Benjamin
On Mon, 20 Aug 2012 21:17:15 -0700 (PDT), Massimo Di Pierro wrote: Consider this code: class SlowStorage(dict): def __getattr__(self,key): return self[key] def __setattr__(self,key): self[key]=value class FastStorage(dict): def __init__(self, __d__=None, *

Re: Class.__class__ magic trick help

2012-08-21 Thread Oscar Benjamin
On 21 August 2012 13:52, Massimo Di Pierro wrote: > On Aug 21, 2:40 am, Oscar Benjamin wrote: > > On Mon, 20 Aug 2012 21:17:15 -0700 (PDT), Massimo Di Pierro > > > > > > > > > > > > > > > > > > > > wrote: > > > Con

Re: Class.__class__ magic trick help

2012-08-21 Thread Oscar Benjamin
On 21 August 2012 14:50, Massimo Di Pierro wrote: > Hello Oscar, > > thanks for your help but your proposal of adding: > > def __setitem__(self,key,value): >self.__dict__[key] = value >dict.__setitem__(self, key, value) > > does not help me. > > What I have today is a class that works like

Class.__class__ magic trick help

2012-08-21 Thread Oscar Benjamin
On 21 August 2012 16:19, Oscar Benjamin wrote: > > On Aug 21, 2012 3:42 PM, "Massimo DiPierro" > wrote: > > > > Thanks again Oscar. I cannot do that. I have tight constraints. I am not > at liberty to modify the code that uses the class. The exposed API cannot &

Re: Guarding arithmetic

2012-08-23 Thread Oscar Benjamin
On 23 August 2012 10:05, Mark Carter wrote: > Suppose I want to define a function "safe", which returns the argument > passed if there is no error, and 42 if there is one. So the setup is > something like: > > def safe(x): ># WHAT WOULD DEFINE HERE? > > print safe(666) # prints 666 > print sa

Re: popen4 - get exit status

2012-08-27 Thread Benjamin Kaplan
On Aug 27, 2012 3:47 PM, "Tim Johnson" wrote: > > In bash I do the following: > linus:journal tim$ /home/AKMLS/cgi-bin/perl/processJournal-Photo.pl hiccup > -bash: /home/AKMLS/cgi-bin/perl/processJournal-Photo.pl: No such file or directory > linus:journal tim$ echo $? > 127 > > In python, use os.p

Re: What do I do to read html files on my pc?

2012-08-28 Thread Oscar Benjamin
On Tue, 28 Aug 2012 03:09:11 -0700 (PDT), mikcec82 wrote: f = open(fileorig, 'r') nomefile = f.read() for x in nomefile: if '' in nomefile: print 'NOK' else : print 'OK' You don't need the for loop. Just do: nomefile = f.read() if '' in nomefile: print('

Re: class object's attribute is also the instance's attribute?

2012-08-30 Thread Oscar Benjamin
On Thu, 30 Aug 2012 05:34:51 -0700 (PDT), Marco Nawijn wrote: If you want attributes to be local to the instance, you have to define them in the __init__ section of the class like this: class A(object): def __init__(self): d = 'my attribute' Except that in this case you'd need to

Re: Beginners question

2012-08-30 Thread Oscar Benjamin
On Thu, 30 Aug 2012 09:23:03 -0400, Dave Angel wrote: I haven't discovered why sometimes the type output shows type instead of class. There are other ways of defining classes, however, and perhaps this is using one of them. Still, it is a class, and stat() is returning an instance of that

Re: class object's attribute is also the instance's attribute?

2012-08-30 Thread Oscar Benjamin
On 30 August 2012 15:11, Marco Nawijn wrote: > > > Learned my lesson today. Don't assume you know something. Test it first > ;). I have done quite some programming in Python, but did not know that > class attributes are still local to the instances. It is also a little > surprising I must say. I a

Re: simple client data base

2012-09-03 Thread Oscar Benjamin
On 3 September 2012 15:12, Mark R Rivet wrote: > Hello all, I am learning to program in python. I have a need to make a > program that can store, retrieve, add, and delete client data such as > name, address, social, telephone number and similar information. This > would be a small client databas

Re: Comparing strings from the back?

2012-09-04 Thread Oscar Benjamin
On 4 September 2012 19:07, Steven D'Aprano < steve+comp.lang.pyt...@pearwood.info> wrote: > On Tue, 04 Sep 2012 18:32:57 +0200, Johannes Bauer wrote: > > > On 04.09.2012 04:17, Steven D'Aprano wrote: > > > >> On average, string equality needs to check half the characters in the > >> string. > > >

Re: Comparing strings from the back?

2012-09-04 Thread Oscar Benjamin
On 4 September 2012 22:59, Chris Angelico wrote: > On Wed, Sep 5, 2012 at 2:32 AM, Johannes Bauer > wrote: > > How do you arrive at that conclusion? When comparing two random strings, > > I just derived > > > > n = (256 / 255) * (1 - 256 ^ (-c)) > > > > where n is the average number of character

Re: is implemented with id ?

2012-09-04 Thread Benjamin Kaplan
On Tue, Sep 4, 2012 at 11:30 PM, Franck Ditter wrote: > Hi ! > a is b <==> id(a) == id(b) in builtin classes. > Is that true ? > Thanks, > > franck No. It is true that if a is b then id(a) == id(b) but the reverse is not necessarily true. id is only guaranteed to be unique among objects alive

Re: why did the WindowsError occur?

2012-09-04 Thread Benjamin Kaplan
On Tue, Sep 4, 2012 at 11:30 PM, Levi Nie wrote: > my code: > import os > os.startfile(r'C:\Program Files\Internet Explorer.exe') > > the error: > os.startfile(r'C:\Program Files\Internet Explorer.exe') > WindowsError: [Error 2] : 'C:\\Program Files\\Internet Explorer.exe' > There's no such thing

Re: Comparing strings from the back?

2012-09-05 Thread Oscar Benjamin
On 5 September 2012 10:48, Peter Otten <__pete...@web.de> wrote: > Chris Angelico wrote: > > > On Wed, Sep 5, 2012 at 6:29 PM, Peter Otten <__pete...@web.de> wrote: > >> comparing every pair in a sample of 1000 8-char words > >> taken from '/usr/share/dict/words' > >> > >> head > >> 1: 477222

Re: Comparing strings from the back?

2012-09-05 Thread Oscar Benjamin
In news.gmane.comp.python.general, you wrote: > On Wed, 05 Sep 2012 16:51:10 +0200, Johannes Bauer wrote: > [...] >>> You are making unjustified assumptions about the distribution of >>> letters in the words. This might be a list of long chemical compounds >>> where the words typically differ only

Re: Comparing strings from the back?

2012-09-06 Thread Oscar Benjamin
On Thu, 06 Sep 2012 06:07:38 -0400, Dave Angel wrote: For random strings (as defined below), the average compare time is effectively unrelated to the size of the string, once the size passes some point. Define random string as being a selection from a set of characters, with replacement.

Re: Accessing dll

2012-09-06 Thread Benjamin Kaplan
On Sep 6, 2012 8:15 AM, "Helpful person" wrote: > > I am a complete novice to Python. I wish to access a dll that has > been written to be compatible with C and VB6. I have been told that > after running Python I should enter "from ctypes import *" which > allows Python to recognize the dll str

Re: Comparing strings from the back?

2012-09-07 Thread Oscar Benjamin
On 2012-09-07, Steven D'Aprano wrote: > > > After further thought, and giving consideration to the arguments given by > people here, I'm now satisfied to say that for equal-length strings, > string equality is best described as O(N). > > 1) If the strings are equal, a == b will always compare a

Re: Comparing strings from the back?

2012-09-07 Thread Oscar Benjamin
On 2012-09-07, Oscar Benjamin wrote: > On 2012-09-07, Steven D'Aprano wrote: >> > > Since string comparison is only useful if the strings can be equal or unequal, > the average case depends on how often they are equal/unequal as well as the > average complexity of bo

Re: Comparing strings from the back?

2012-09-08 Thread Oscar Benjamin
On 2012-09-08, Steven D'Aprano wrote: > On Fri, 07 Sep 2012 19:10:16 +, Oscar Benjamin wrote: > >> On 2012-09-07, Steven D'Aprano >> wrote: >> >> >> Would you say, then, that dict insertion is O(N)? > > Pedantically, yes. >

Re: Is there any difference between print 3 and print '3' in Python ?

2012-09-10 Thread Benjamin Kaplan
On Sun, Sep 9, 2012 at 11:33 PM, Dwight Hutto wrote: > > > On Sun, Sep 9, 2012 at 10:41 AM, Ian Foote wrote: >> >> On 09/09/12 14:23, iMath wrote: >>> >>> 在 2012年3月26日星期一UTC+8下午7时45分26秒,iMath写道: I know the print statement produces the same result when both of these two instructions

Re: Newbie: where's the new python gone?

2012-09-10 Thread Benjamin Kaplan
On Sun, Sep 9, 2012 at 11:10 PM, Dwight Hutto wrote: > > I have several installations on my windows, so I use > c:\python27_64\python.exe module_file.py > > or > > c:\python26\python.exe module_file.py > > in the command line. > > > Not to show that this shouldn't be a discussion, but usually it's

Re: Standard Asynchronous Python

2012-09-10 Thread Oscar Benjamin
On 2012-09-10, Dennis Lee Bieber wrote: > On Sun, 9 Sep 2012 20:07:51 -0400, "Dustin J. Mitchell" > declaimed the following in > gmane.comp.python.general: > >> >> My proposal met with near-silence, and I didn't pursue it. Instead, I >> did what any self-respecting hacker would do - I wrote up a

Re: Comparing strings from the back?

2012-09-10 Thread Oscar Benjamin
On 2012-09-10, Steven D'Aprano wrote: > On Mon, 10 Sep 2012 08:59:37 +, Duncan Booth wrote: > >> Gelonida N wrote: >> >> so at the expense of a single dictionary >> insertion when the string is created you can get guaranteed O(1) on all >> the comparisons. > > What interning buys you is that

Re: Comparing strings from the back?

2012-09-10 Thread Oscar Benjamin
On 2012-09-10, Chris Angelico wrote: > On Tue, Sep 11, 2012 at 12:06 AM, Oscar Benjamin > wrote: >> On 2012-09-10, Steven D'Aprano wrote: >>> What interning buys you is that "s == t" is an O(1) pointer compare if >>> they are equal. But if s an

Re: Comparing strings from the back?

2012-09-10 Thread Oscar Benjamin
On 2012-09-10, Oscar Benjamin wrote: > On 2012-09-10, Chris Angelico wrote: >> On Tue, Sep 11, 2012 at 12:06 AM, Oscar Benjamin >> wrote: >>> On 2012-09-10, Steven D'Aprano wrote: >>>> What interning buys you is that "s == t" is an O(1) poi

Re: Comparing strings from the back?

2012-09-10 Thread Oscar Benjamin
On 2012-09-10, Dan Goodman wrote: > On 04/09/2012 03:54, Roy Smith wrote: >> Let's assume you're testing two strings for equality. You've already >> done the obvious quick tests (i.e they're the same length), and you're >> down to the O(n) part of comparing every character. >> >> I'm wondering if

Re: Comparing strings from the back?

2012-09-10 Thread Oscar Benjamin
On 2012-09-10, Dan Goodman wrote: > On 10/09/2012 18:07, Dan Goodman wrote: >> On 04/09/2012 03:54, Roy Smith wrote: >>> Let's assume you're testing two strings for equality. You've already >>> done the obvious quick tests (i.e they're the same length), and you're >>> down to the O(n) part of com

Re: a python license problem?

2012-09-10 Thread Benjamin Kaplan
On Mon, Sep 10, 2012 at 7:58 PM, Jayden wrote: > Python is under GPL compatible. If I develop a python code, convert it to > executable and distribute the executable as a commercial software. May I need > to make my source code open? > > If python is under GPL, is the answer different? Thanks a

Re: Comparing strings from the back?

2012-09-11 Thread Oscar Benjamin
On 11 September 2012 10:51, Duncan Booth wrote: > Oscar Benjamin wrote: > > >> What interning buys you is that "s == t" is an O(1) pointer compare > >> if they are equal. But if s and t differ in the last character, > >> __eq__ will still inspe

Re: submit jobs on multi-core

2012-09-11 Thread Oscar Benjamin
On 2012-09-11, Dhananjay wrote: > --===0316394162== > Content-Type: multipart/alternative; boundary=20cf30776bd309ffd004c96557e2 > > --20cf30776bd309ffd004c96557e2 > Content-Type: text/plain; charset=ISO-8859-1 > > Dear all, > > I have a python script in which I have a list of files to

Re: generators as decorators simple issue

2012-09-12 Thread Oscar Benjamin
On Wed, 12 Sep 2012 03:22:31 -0700 (PDT), pyjoshsys wrote: The output is still not what I want. Now runtime error free, however the output is not what I desire. def setname(cls): '''this is the proposed generator to call SetName on the object''' try: cls.SetName(cls.__name

Re: Boolean function on variable-length lists

2012-09-12 Thread Oscar Benjamin
On 12 September 2012 14:25, Libra wrote: > On Wednesday, September 12, 2012 3:11:42 PM UTC+2, Steven D'Aprano wrote: > > On Wed, 12 Sep 2012 05:48:09 -0700, Libra wrote: > > > > I need to implement a function that returns 1 only if all the values in > > > a list satisfy given constraints (at leas

Re: using subprocess.Popen does not suppress terminal window on Windows

2012-09-13 Thread Oscar Benjamin
On Thu, 13 Sep 2012 00:27:10 -0700 (PDT), janis.judvai...@gmail.com wrote: I'm making a little embedded system programming IDE so I need to run .exe(windows only), make commands, perl & python scripts etc(multiplatform). I'm using subprocess.Popen for all of them and it works fine except that

Re: Re: using subprocess.Popen does not suppress terminal window on Windows

2012-09-13 Thread Oscar Benjamin
On 13 September 2012 10:22, Oscar Benjamin wrote: > On Thu, 13 Sep 2012 00:27:10 -0700 (PDT), janis.judvai...@gmail.com wrote: > >> I'm making a little embedded system programming IDE so I need to >> > run .exe(windows only), make commands, perl & python scripts &g

Re: using subprocess.Popen does not suppress terminal window on Windows

2012-09-13 Thread Oscar Benjamin
On 13 September 2012 13:33, wrote: > It looks like normal terminal to me, could You define normal? > > Looks like it appears only when target script prints something, but it > shouldn't cus I'm using pipes on stdout and stderr. > > If anyone is interested I'm using function doPopen from here: > h

Re: gc.get_objects()

2012-09-17 Thread Oscar Benjamin
On 2012-09-17, Matteo Boscolo wrote: > from my gc.get_object() > I extract the sub system of the object that I would like to delete: > > this is the object: > Class name > win32com.gen_py.F4503A16-F637-11D2-BD55-00500400405Bx0x1x0.ITDProperty.ITDProperty > that is traked and the reference are: >

Re: Using dict as object

2012-09-19 Thread Oscar Benjamin
On 2012-09-19, Dave Angel wrote: > On 09/19/2012 06:24 AM, Pierre Tardy wrote: >> All implementation I tried are much slower than a pure native dict access. >> Each implementation have bench results in commit comment. All of them >> are 20+x slower than plain dict! > > Assuming you're talking ab

Re: subprocess call is not waiting.

2012-09-19 Thread Benjamin Kaplan
On Sep 19, 2012 9:37 AM, "andrea crotti" wrote: > Well there is a process which has to do two things, monitor > periodically some external conditions (filesystem / db), and launch a > process that can take very long time. > > So I can't put a wait anywhere, or I'll stop everything else. But at >

Re: Using dict as object

2012-09-19 Thread Oscar Benjamin
On 2012-09-19, Pierre Tardy wrote: > --===1362296571== > Content-Type: multipart/alternative; boundary=bcaec554d3229e814204ca105e50 > > --bcaec554d3229e814204ca105e50 > Content-Type: text/plain; charset=ISO-8859-1 > >> >> This has been proposed and discussed and even implemented many

Re: Installing Pip onto a mac os x system

2012-09-19 Thread Benjamin Kaplan
On Sep 19, 2012 6:37 PM, "John Mordecai Dildy" wrote: > > Does anyone know how to install Pip onto a mac os x ver 10.7.4? > > Ive tried easy_instal pip but it brings up this message (but it doesn't help with my problem): > > error: can't create or remove files in install directory > > The followin

For Counter Variable

2012-09-23 Thread Oscar Benjamin
On Sep 23, 2012 5:42 PM, "jimbo1qaz" wrote: > > Am I missing something obvious, or do I have to manually put in a counter in the for loops? That's a very basic request, but I couldn't find anything in the documentation. Have you seen the enumerate function? Oscar -- http://mail.python.org/mailm

Re: For Counter Variable

2012-09-23 Thread Oscar Benjamin
On Sep 23, 2012 6:52 PM, "jimbo1qaz" wrote: > > On Sunday, September 23, 2012 9:36:19 AM UTC-7, jimbo1qaz wrote: > > Am I missing something obvious, or do I have to manually put in a counter in the for loops? That's a very basic request, but I couldn't find anything in the documentation. > > Ya, t

Re: Anyone able to help on installing packages?

2012-09-23 Thread Oscar Benjamin
On Sep 23, 2012 6:56 PM, "John Mordecai Dildy" wrote: > > Hello everyone out there. Ive been trying to install packages like distribute, nose, and virturalenv and believe me it is a hard process to do. I tried everything I could think of to install. > > I have done the following: > > pip install

Re: Anyone able to help on installing packages?

2012-09-23 Thread Oscar Benjamin
Please send your reply to the mailing list (python-list@python.org) rather than privately to me. On 23 September 2012 20:57, John Dildy wrote: > When I give input at the start of terminal using the command pip install > virtualenv: > > Downloading/unpacking virtualenv > Running setup.py egg_i

Re: List Problem

2012-09-23 Thread Oscar Benjamin
On 23 September 2012 22:31, jimbo1qaz wrote: > I have a nested list. Whenever I make a copy of the list, changes in one > affect the other, even when I use list(orig) or even copy the sublists one > by one. I have to manually copy each cell over for it to work. > Link to broken code: http://jimbo

Re: Editing Inkscape SVG files with Python?

2012-09-23 Thread Oscar Benjamin
On 23 September 2012 23:53, Steven D'Aprano < steve+comp.lang.pyt...@pearwood.info> wrote: > I have some SVG files generated with Inkscape containing many text blocks > (over 100). I wish to programmatically modify those text blocks using > Python. Is there a library I should be using, or any othe

Re: Java singletonMap in Python

2012-09-23 Thread Oscar Benjamin
On 24 September 2012 00:14, Mark Lawrence wrote: > Purely for fun I've been porting some code to Python and came across the > singletonMap[1]. I'm aware that there are loads of recipes on the web for > both singletons e.g.[2] and immutable dictionaries e.g.[3]. I was > wondering how to combine

Re: Pass numeric arrays from C extensions to Python

2012-09-23 Thread Oscar Benjamin
On 24 September 2012 02:39, JBT wrote: > Hi, > > I am looking for a way to pass numeric arrays, such as *float a[100]; > double b[200];*, from C extension codes to python. The use case of this > problem is that you have data stored in a particular format, NASA common > data format (CDF) in my cas

Re: Anyone able to help on installing packages?

2012-09-24 Thread Oscar Benjamin
On 24 September 2012 21:27, John Mordecai Dildy wrote: > Anyone have Ideas on nose and distribute? Your post has no context and simply asks a very vague question. Had you explained what you tried and what happened and perhaps shown an error message I might have been able to answer your question

Re: python file API

2012-09-24 Thread Oscar Benjamin
On 24 September 2012 22:35, zipher wrote: > For some time now, I've wanted to suggest a better abstraction for the > type in Python. It currently uses an antiquated C-style interface > for moving around in a file, with methods like tell() and seek(). But > after attributes were introduced to P

Re: python file API

2012-09-24 Thread Oscar Benjamin
On 24 September 2012 23:41, Mark Adam wrote: > > seek() and tell() can raise exceptions on some files. Exposing pos as an > > attribute and allowing it to be manipulated with attribute access gives > the > > impression that it is always meaningful to do so. > > It's a good point, python already

Re: For Counter Variable

2012-09-24 Thread Oscar Benjamin
On 25 September 2012 01:17, Dwight Hutto wrote: > > Is the animated GIF on your website under 60MB yet? > yeah a command line called convert, and taking out a few jpegs used to > convert, and I can reduce it to any size, what's the fucking point of > that question other than ignorant rhetoric, th

Re: python file API

2012-09-25 Thread Oscar Benjamin
On Sep 25, 2012 9:28 AM, "Dennis Lee Bieber" wrote: > > On Tue, 25 Sep 2012 08:22:05 +0200, Ulrich Eckhardt > declaimed the following in > gmane.comp.python.general: > > > Am 24.09.2012 23:49, schrieb Dave Angel: > > > And what approach would you use for positioning relative to > > > end-of-file?

Re: python file API

2012-09-25 Thread Oscar Benjamin
On 25 September 2012 08:27, Mark Lawrence wrote: > On 25/09/2012 03:32, Mark Adam wrote: > >> On Mon, Sep 24, 2012 at 5:55 PM, Oscar Benjamin >> wrote: >> >>> try: >>> f.pos = 256 >>> except IOError: >>> print

Re: python file API

2012-09-25 Thread Oscar Benjamin
On 25 September 2012 11:51, Mark Lawrence wrote: > On 25/09/2012 11:38, Oscar Benjamin wrote: > >> On 25 September 2012 08:27, Mark Lawrence >> wrote: >> >> On 25/09/2012 03:32, Mark Adam wrote: >>> >>> On Mon, Sep 24, 2012 at 5:5

Re: Memory usage per top 10x usage per heapy

2012-09-25 Thread Oscar Benjamin
On 25 September 2012 00:58, Junkshops wrote: > Hi Tim, thanks for the response. > > > - check how you're reading the data: are you iterating over >>the lines a row at a time, or are you using >>.read()/.readlines() to pull in the whole file and then >>operate on that? >> > I'm using

Re: Python 3 crashes with 'Py_Initialize: can't initialize sys standard streams' + 'EOFError: EOF read where not expected'

2012-09-25 Thread Oscar Benjamin
On 25 September 2012 12:32, Robison Santos wrote: > Hello guys, > > I'm having a very serious problem with my python3 environment and I'm > completely lost about the problem. > In my server I run two python apps (custom apps) during system start time, > and sometime when the apps are starting a c

<    1   2   3   4   5   6   7   8   9   10   >