Re: [Tutor] can't see emacs timer in action
Hello Max, the problem with running in a dos console terminal is that I have to switch back and forth from terminal and my xemacs. and I found that in windows dos console we have to specify buffer page. I do need a dynamic buffer control so I don't need to specify the buffer if my program run big things. Do you have an advice? pujo On 6/15/05, Max Noel <[EMAIL PROTECTED]> wrote: > > On Jun 14, 2005, at 23:17, Pujo Aji wrote: > > > I just use Ctrl+C Ctrl+C to run the code. > > The code wait for 3 second and show all i all together. > > > > I can't feel every second pass. > > > > pujo > > Try running your script from a terminal (outside of emacs, that > is). > > -- Max > maxnoel_fr at yahoo dot fr -- ICQ #85274019 > "Look at you hacker... A pathetic creature of meat and bone, panting > and sweating as you run through my corridors... How can you challenge > a perfect, immortal machine?" > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] can't see emacs timer in action
Hallo Danny, I tried the emacs folding customization, but it doesn't work. After I did it, my xemacs show tripple dot '...' near the method of class it should be folded. I don't know how to open my method. Sincerely Yours, pujo On 6/15/05, Danny Yoo <[EMAIL PROTECTED]> wrote: > > > On Wed, 15 Jun 2005, Pujo Aji wrote: > > > Thanks Danny, > > > > Btw, I use xemacs now does it has folding class and method capabilities? > > Hi Pujo, > > [Note: in replies, please make sure to put tutor@python.org in CC.] > > > According to: > > > http://groups.google.ca/group/comp.lang.python/msg/956f1c2d37f93995?q=emacs+folding+python&hl=en&lr=&ie=UTF-8&oe=UTF-8&rnum=2 > > Yes. *grin* > > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] can't see emacs timer in action
Hello Alan, thanks for the advice, but I don't understand why xemacs doesn't fix C-c C-c so we don't have to do such many things. in fact C-c C-c is fail to represent the well 'run' behaviour of python ? It would be nice to people who use python get the same benefit of typing C-c C-c and get the result it supposed to have in other languages. pujo On 6/16/05, Alan G <[EMAIL PROTECTED]> wrote: > > buffer/output pane before running my program, so I always do > > this to start my program: > > ... > > ...6 steps listed > > ... > > > This is one cycle of running. > > Is that normal ??? > > I doubt it, I've never user python mode in emacs but I have > used SQL and C++ modes and usually you just call C-c C-c from > the code window and the rest all happens magically. > > But even if you do have to do all of that the sionple solution > is to record it as a macro > > C-x ( > keys to press here > C-x ) > > You can execute it again with > > C-x e > > And you can save it so that it will be available next time > you start emacs. You can also bind it to a shortcut of your > own - after all this is emacs you can do anything! :-) > > > I need to make shortcut for starting interpreter do you have any > idea. > > record and save a macro > > M-x apropos macro > > is your friend... > > Alan G. > A one time emacs user... > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Checking if value exist in a '2D array'
Olli Rajala wrote: > Hi again, > > I have a '2D array', I mean a list inside a list ([[][],[][],...]) and > would need to check if the value exists in it. Of course I could do a > for loop, but that just seem to be a little overkill, so is there any > other way to do it? I have to check the first cell of every insider > list. With Python 2.4: >>> l= [ [1], [2,3], [4,5], [6]] >>> 2 in (i[0] for i in l) True >>> 3 in (i[0] for i in l) False with Python 2.3 use [i[0] for i in l] instead which is a little less efficient. > > Here's a little pseudo code if that helps. > > if list[[x][0]] == 'value': # where x can be anything > 0 >print 'found' > > So, is there a similar method like list.count('value') that I use for 1D > lists? I would use 'value' in list rather than list.count('value') because it will stop when it finds 'value'; list.count() will always inspect the whole list. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] max(len(item)) for cols
Dear Guys, I have a 2D array: >>>[['1', '2 ', '3'], ['longer ', 'longer', 'sort']] How can I get what is the max(len(item)) for the columns ? I would like to get a list with the max_col_width values. I hope that, it can wrote with some nice list comprehension, but I can't do that :( Yours sincerely, __ János Juhász ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] max(len(item)) for cols
On Jun 17, 2005, at 11:58, János Juhász wrote: > > Dear Guys, > > I have a 2D array: > [['1', '2 ', '3'], ['longer ', 'longer', 'sort']] > > > How can I get what is the max(len(item)) for the columns ? > I would like to get a list with the max_col_width values. > > I hope that, it can wrote with some nice list comprehension, but I > can't do > that :( >>> a = [[1, 2], [1, 2, 3], [1, 2, 3, 4], [1]] >>> max(len(item) for item in a) 4 If you're running Python 2.3 or lower, add brackets in the last line: >>> max([len(item) for item in a]) 4 -- Max maxnoel_fr at yahoo dot fr -- ICQ #85274019 "Look at you hacker... A pathetic creature of meat and bone, panting and sweating as you run through my corridors... How can you challenge a perfect, immortal machine?" ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] max(len(item)) for cols
Max Noel wrote: > On Jun 17, 2005, at 11:58, János Juhász wrote: >>I have a 2D array: >> >> >[['1', '2 ', '3'], ['longer ', 'longer', 'sort']] > >> >> >>How can I get what is the max(len(item)) for the columns ? >>I would like to get a list with the max_col_width values. > > >>> a = [[1, 2], [1, 2, 3], [1, 2, 3, 4], [1]] > >>> max(len(item) for item in a) > 4 > > If you're running Python 2.3 or lower, add brackets in the last > line: > >>> max([len(item) for item in a]) > 4 another way: >>> a = [[1, 2], [1, 2, 3], [1, 2, 3, 4], [1]] >>> max(map(len, a)) 4 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] max(len(item)) for cols
Quoting János Juhász <[EMAIL PROTECTED]>: > > Dear Guys, > > I have a 2D array: > >>>[['1', '2 ', '3 '], ['longer ', 'longer ', 'sort']] > > > How can I get what is the max(len(item)) for the columns ? > I would like to get a list with the max_col_width values. > > I hope that, it can wrote with some nice list comprehension, but I can't > do that :( There is a magic trick: You can use zip(* ) to transpose a two-dimensional array. eg: >>> arr = [[1,2,3], [4,5,6]] >>> zip(*arr) [(1, 4), (2, 5), (3, 6)] >>> zip(*zip(*arr)) [(1, 2, 3), (4, 5, 6)] (if this is not obvious to you, I recommend spending the time to figure out how this works) You can use this to easily get at the columns of your array. And once you have the columns, you can use a list comprehension to get the lengths of the elements and find the max. eg: >>> arr = [['a'*random.randint(1, 10) for i in range(5)] for j in range(10)] >>> pprint.pprint(arr) [['aa', 'a', 'aa', '', ''], ['aaa', 'aa', 'aa', 'aaa', 'aaa'], ['aa', 'aaa', '', 'aa', 'aaa'], ['', 'aa', 'aa', 'aa', 'aa'], ['aa', 'a', 'aa', 'a', ''], ['aaa', 'a', 'aa', 'a', 'aa'], ['', 'a', 'a', '', 'aa'], ['a', 'aaa', 'a', 'aa', 'aaa'], ['', 'aa', 'aa', 'a', 'a'], ['a', 'aa', 'aa', 'aaa', 'aa']] >>> [max([len(s) for s in l]) for l in zip(*arr)] [10, 9, 10, 6, 10] HTH! -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] max(len(item)) for cols
János Juhász wrote: > Dear Guys, > > I have a 2D array: > [['1', '2 ', '3'], ['longer ', 'longer', 'sort']] > > > > How can I get what is the max(len(item)) for the columns ? > I would like to get a list with the max_col_width values. > > I hope that, it can wrote with some nice list comprehension, but I can't do > that :( Ah, thanks jfouhy for correctly understanding the question! If you are doing this because you want to pretty-print a table, you may be interested in this recipe: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/267662 Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] max(len(item)) for cols
Thanks Max, it is sort, but it gives back the max(len(item)) for the rows > I have a 2D array: > [['1', '2 ', '3'], ['longer ', 'longer', 'sort']] > > > How can I get what is the max(len(item)) for the columns ? > I would like to get a list with the max_col_width values. > > I hope that, it can wrote with some nice list comprehension, but I > can't do > that :( Here is the array: [['1', '2 ', '3 '], [ 'longer','longer','sort'] ] it is len(item) for that: [[ 1, 2, 3], [ 10,10, 4] ] I would have that is the next: (10,10,4) or [10,10,4] As I remeneber it is somewhere in numpy, but I am not sure. I would like to have it simply. Yours sincerely, __ János Juhász Max Noel <[EMAIL PROTECTED]> To János Juhász <[EMAIL PROTECTED]> 2005.06.17 13:35 cc tutor@python.org Subject Re: [Tutor] max(len(item)) for cols On Jun 17, 2005, at 11:58, János Juhász wrote: > > Dear Guys, > > I have a 2D array: > [['1', '2 ', '3'], ['longer ', 'longer', 'sort']] > > > How can I get what is the max(len(item)) for the columns ? > I would like to get a list with the max_col_width values. > > I hope that, it can wrote with some nice list comprehension, but I > can't do > that :( >>> a = [[1, 2], [1, 2, 3], [1, 2, 3, 4], [1]] >>> max(len(item) for item in a) 4 If you're running Python 2.3 or lower, add brackets in the last line: >>> max([len(item) for item in a]) 4 -- Max maxnoel_fr at yahoo dot fr -- ICQ #85274019 "Look at you hacker... A pathetic creature of meat and bone, panting and sweating as you run through my corridors... How can you challenge a perfect, immortal machine?" ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] test
Hi All I have a very simple problem and I am looking for the simplest solution. I have a list of elements in a file. I like to find the total occurance of each element in the list like this 10 string1 7 string2 1 string3 from a list which has only string1,string2 and string3 like this string1 .. string2 ... string1 .. string3 ... ... I have a list of 3 lines and I think I have only 615 unique elements. So I like the script not to take too much memory of the system. I will be running it on Solaris 8 Thanks a lot -- Asif Iqbal PGP Key: 0xE62693C5 KeyServer: pgp.mit.edu "..there are two kinds of people: those who work and those who take the credit...try to be in the first group;...less competition there." - Indira Gandhi ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Checking if value exist in a '2D array'
Kent Johnson wrote: >Olli Rajala wrote: > > >>Hi again, >> >>I have a '2D array', I mean a list inside a list ([[][],[][],...]) and >>would need to check if the value exists in it. Of course I could do a >>for loop, but that just seem to be a little overkill, so is there any >>other way to do it? I have to check the first cell of every insider >>list. >> >> > >With Python 2.4: > >>> l= [ [1], [2,3], [4,5], [6]] > >>> 2 in (i[0] for i in l) >True > >>> 3 in (i[0] for i in l) >False > >with Python 2.3 use [i[0] for i in l] instead which is a little less efficient. > The second case you show should be true because I believe that's what he asked for. Here is I believe the correct way to do this. >>> l= [ [1], [2,3], [4,5], [6]] >>> def isin(test,alist): ... return bool([x for x in alist if test in x]) ... >>> isin(2,l) True >>> isin(3,l) True >>> isin(10,l) False >>> def isin2(test,alist): ... for x in alist: ... if test in x: ... return True ... return False >>> isin2(2,l) True >>> isin2(10,l) False >>> __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] test
How about this. >>> from random import choice >>> alist=[choice(range(100)) for x in range(1000)] #just making a list to look at pretend this is a file >>> >>> counter={} >>> for item in alist: ... if item in counter.keys(): ... counter[item]+=1 ... else: ... counter[item]=1 ... >>> counter {0: 9, 1: 9, 2: 9, 3: 14, 4: 15, 5: 15, 6: 13, 7: 5, 8: 11, 9: 12, 10: 9, 11: 12, 12: 13, 13: 8, 14: 5, 15: 12, 16: 14, 17: 9, 18: 11, 19: 8, 20: 6, 21: 13, 22: 11, 23: 10, 24: 8, 25: 15, 26: 19, 27: 11, 28: 13, 29: 13, 30: 12, 31: 18, 32: 10, 33: 5, 34: 9, 35: 5, 36: 9, 37: 12, 38: 8, 39: 11, 40: 8, 41: 12, 42: 6, 43: 13, 44: 11, 45: 8, 46: 8, 47: 6, 48: 9, 49: 6, 50: 5, 51: 11, 52: 11, 53: 12, 54: 15, 55: 15, 56: 10, 57: 12, 58: 13, 59: 6, 60: 6, 61: 7, 62: 8, 63: 13, 64: 14, 65: 7, 66: 7, 67: 12, 68: 5, 69: 10, 70: 8, 71: 7, 72: 12, 73: 12, 74: 6, 75: 13, 76: 12, 77: 13, 78: 9, 79: 5, 80: 13, 81: 14, 82: 4, 83: 6, 84: 8, 85: 12, 86: 8, 87: 10, 88: 10, 89: 7, 90: 7, 91: 9, 92: 12, 93: 14, 94: 8, 95: 7, 96: 10, 97: 11, 98: 8, 99: 8} >>> Asif Iqbal wrote: >Hi All > >I have a very simple problem and I am looking for the simplest solution. > >I have a list of elements in a file. I like to find the total occurance >of each element in the list like this > >10 string1 >7 string2 >1 string3 > >from a list which has only string1,string2 and string3 like this > >string1 >.. >string2 >... >string1 >.. >string3 >... >... > > >I have a list of 3 lines and I think I have only 615 unique >elements. So I like the script not to take too much memory of the >system. I will be running it on Solaris 8 > >Thanks a lot > > > Yahoo! Sports Rekindle the Rivalries. Sign up for Fantasy Football http://football.fantasysports.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Checking if value exist in a '2D array'
Chad Crabtree wrote: > The second case you show should be true because I believe that's what > he > asked for. Here is I believe the correct way to do this. > > l= [ [1], [2,3], [4,5], [6]] def isin(test,alist): > > ... return bool([x for x in alist if test in x]) I don't think so, the OP says "I have to check the first cell of every insider list." Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] test
On Fri, Jun 17, 2005 at 07:41:17AM, Chad Crabtree wrote: > How about this. > >>> from random import choice > >>> alist=[choice(range(100)) for x in range(1000)] #just making a How do I do this in python? alist < /tmp/logfile The logfile has the list of entries. -- Asif Iqbal PGP Key: 0xE62693C5 KeyServer: pgp.mit.edu "..there are two kinds of people: those who work and those who take the credit...try to be in the first group;...less competition there." - Indira Gandhi ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] max(len(item)) for cols
Thanks for jfouhy and Kent! Both the zip and the recipe are suit for me. I looked for these. Yours sincerely, __ János Juhász ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Clearing the Console Screen
> > That having been said Fred Lundh has written a console module > > that tries to hide the diffeent trminal types in a common set > > of commands - you can download it from his site. > > The only one I can find there is for Windows: > http://www.effbot.org/zone/console-handbook.htm My bad. You are right. I've seen it used for windows console control and was told it worked for "any console", I assumed that included *nix but obviously not! Its not as impressive a feat as I thought in that case. Apologies for the bad steer. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] can't see emacs timer in action
> but I don't understand why xemacs doesn't fix C-c C-c Neither do I. BTW Do you know if this is specific to xemacs? Or does it also apply to python mode in vanilla GNU emacs too? I really should get around to loading python-mode and trying it some day... Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] max(len(item)) for cols
I have a 2D array: >>>[['1', '2 ', '3'], ['longer ', 'longer', 'sort']] > How can I get what is the max(len(item)) for the columns ? > I would like to get a list with the max_col_width values. >>> tda = [['1', '2 ', '3'], ['longer ', 'longer', 'sort']] >>> mcw = [[len(r) for r in c] for c in tda] >>> mcw [[1, 2, 5], [11, 10, 4]] >>> mcw = [max([len(r) for r in c]) for c in tda] >>> mcw [5, 11] >>> widest = max(mcw) >>> widest 11 Is that what you mean? Alan G Author of the Learn to Program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] test
Asif Iqbal wrote: >On Fri, Jun 17, 2005 at 07:41:17AM, Chad Crabtree wrote: > > >>How about this. >> >>> from random import choice >> >>> alist=[choice(range(100)) for x in range(1000)] #just making a >> >> > >How do I do this in python? > alist < /tmp/logfile > >The logfile has the list of entries. > > > ok sorry filehandle=open('/tmp/logfile','r').readlines() Look here http://docs.python.org/lib/built-in-funcs.html#built-in-funcs and http://docs.python.org/lib/bltin-file-objects.html __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Logging stdout and stderr
Hi there - I'm trying to log the results of a command that I'm running via the popen2 module to a file, while at the same time displaying its progress on the screen. So, at the end of the run, I should have the entire output (stdout and stderr) on the screen, but also have two file objects each with the contents of one of stdout and stderr. I can figure out how to write the results to a file, and then process or log it, but what I can't do is figure out a way to simultaneously display it to the screen, kind of like how unix's "tee" utility works. Can anyone help? -Cs ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] can't see emacs timer in action
Before I use xemacs I use emacs and both are the same. I don't know if there is connection between cpython and problem in showing real time console, because both use cpython. I also want to hear people who use python and emacs/xemacs concerning this problem. pujo On 6/17/05, Alan G <[EMAIL PROTECTED]> wrote: > > but I don't understand why xemacs doesn't fix C-c C-c > > Neither do I. BTW Do you know if this is specific to xemacs? > Or does it also apply to python mode in vanilla GNU emacs too? > > I really should get around to loading python-mode and > trying it some day... > > Alan G. > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Logging stdout and stderr
Hi, Why don't you print it while you get it..? import os, sys logfile = open("logfile.txt", "r") input, output = os.popen2("your command") while True: temp = output.read(1) #or whatever fits you, more bytes is faster if not temp: //EOF reached break logfile.write(temp) sys.stdout.write(temp) [EMAIL PROTECTED] wrote: > > Hi there - > > I'm trying to log the results of a command that I'm running via the > popen2 module to a file, while at the same time displaying its progress > on the screen. So, at the end of the run, I should have the entire > output (stdout and stderr) on the screen, but also have two file objects > each with the contents of one of stdout and stderr. I can figure out > how to write the results to a file, and then process or log it, but what > I can't do is figure out a way to simultaneously display it to the > screen, kind of like how unix's "tee" utility works. > > Can anyone help? > > -Cs > > > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor