assignment in a for loop

2006-05-16 Thread MackS
Hello everyone Consider the following >>> l = [1,2] >>> for i in l: ... i = i + 1 ... >>> l [1, 2] I understand (I think!) that this is due to the fact that in Python what looks like "assignment" really is binding a name to an object. The result is that inside the loop I am creating an objec

Re: assignment in a for loop

2006-05-16 Thread MackS
)] ... This would be awful when, eg, one adds an argument to the function definition. It would require edition of the code at two different locations. Thanks Mack MackS wrote: > Hello everyone > > Consider the following > > >>> l = [1,2] > >>> for i in l: >

Re: assignment in a for loop

2006-05-16 Thread MackS
Thank you for your reply. > > 1) Is what I wrote above (minimally) correct? > > Correct for what? You can tell if it's *syntactically* correct by > simply running it. > > As for any other "correct", define that. Does it do what you want it > to do? I was referring to my attempted explanation, no

[curses]: detecting modifier keys?

2005-11-10 Thread MackS
Hello I am writing a small app to learn how to use the curses module. I would like to know how I can get "composite" key presses, eg, Control+Q. Currently I am looking at the following code snippet: import curses.wrapper def main(stdscr): x = 0 while True: key = stdscr.getch(

Re: : detecting modifier keys?

2005-11-10 Thread MackS
Hi Dennis, Thanks for your help, what is happening is clear now. Just found that calling curses.raw() lets you get all scan codes. Cheers Mack -- http://mail.python.org/mailman/listinfo/python-list

modifying small chunks from long string

2005-11-13 Thread MackS
Hello everyone I am faced with the following problem. For the first time I've asked myself "might this actually be easier to code in C rather than in python?", and I am not looking at device drivers. : ) This program is meant to process relatively long strings (10-20 MB) by selectively modifying

Re: modifying small chunks from long string

2005-11-14 Thread MackS
Thank you all for your great help. One of the few things better than python is the knowledgeable community around it. : ) Regards, Mack -- http://mail.python.org/mailman/listinfo/python-list

global variables shared across modules

2005-09-09 Thread MackS
Hello everyone Consider the following two simple files. The first is my "program", the other a file holding some global variable definitions and code shared by this program and a "twin" program (not shown here): program1.py: from shared import * fun() print "at top level: " + glo

how to kill a python process?

2006-02-05 Thread MackS
Hello! This question does not concern programming in python, but how to manage python processes. Is there a way to "name" a python process? At least on Linux, if I have two python programs running, they both run under the name "python" #pidof program1.py [empty line] #pidof program1.py [empty lin

Re: how to kill a python process?

2006-02-05 Thread MackS
Hi Jorgen You wrote that: > $ head -1 foo3.py > #!/usr/bin/python > $ ./foo3.py > > This is the traditional shebang form used for shell and Perl scripts, > and it names the process 'foo3.py' so you can killall(1) it nicely. It doesn't work on my system; I just get yet another process called pyt

Re: how to kill a python process?

2006-02-07 Thread MackS
Hi Jorgen THanks for your help. I began writing a wrapper around python did (as Donn suggested), but then noticed that this was due to not having educated myself on the options you can pass to ps, pidof and top: running pidof -x and using the 'c' command in top work pretty nicely. That way I no l

_conditionally_ returning to point where exception was raised?

2005-03-16 Thread MackS
Hi I'm new to Python and would like to know if the following is possible. Say I have one lower-level object A and one user-interface object B. Suppose B.CallingMethod() calls A.CalledMethod(), the latter method stumbles upon an IO error and raises an exception. The calling method detects the exce

FAQ 1.7.3 : How can I have modules that mutually import each other

2005-03-19 Thread MackS
Hi I'm new to Python, I've read the FAQ but still can't get the following simple example working: # file main_mod.py: global_string = 'abc' def main(): import auxiliary_mod instance = auxiliary_mod.ClassA() instance.fun() return main() # file auxiliary_mod.py: class ClassA:

AttributeError: ClassA instance has no attribute '__len__'

2005-03-30 Thread MackS
I'm new to Python. In general I manage to understand what is happening when things go wrong. However, the small program I am writing now fails with the following message: AttributeError: ClassA instance has no attribute '__len__' Following the traceback,I see that the offending line is self.x =

converting a set into a sorted list

2005-05-14 Thread MackS
Dear all, I've got several large sets in my program. After performing several operations on these I wish to present one set to the user [as a list] sorted according to a certain criterion. Is there any direct way to do so? Or must I list = [] for item in set1: list.append(item) list.sort(...

Re: converting a set into a sorted list

2005-05-14 Thread MackS
Thank you for the pointer. I'll upgrade to 2.4. Best, Mack -- http://mail.python.org/mailman/listinfo/python-list

deleting the terminal prompt?

2005-05-15 Thread MackS
Dear all, I just noticed the following behavior when I run import os import sys import readline histfile = os.path.join(os.environ["HOME"], ".pyhist") try: readline.read_history_file(histfile) except IOError: pass import atexit atexit.register(readline.write_history_file, histfile) del

Re: deleting the terminal prompt?

2005-05-15 Thread MackS
Thanks, Dennis, that solved it. Cheers Mack Dennis Lee Bieber wrote: > On 15 May 2005 16:32:57 -0700, "MackS" <[EMAIL PROTECTED]> > declaimed the following in comp.lang.python: > > > > while cmd != "": > > > > sys.stdout.write(&qu

readline module and white-space

2005-05-19 Thread MackS
Dear all, I'm trying to use Python's readline module but I'm having some trouble. In particular, autocompletion seems to "get stuck" on white spaces. Please take a look at this code snippet: import readline def completer(text, state): text = text list = ['a dog', 'artsy'] if len