[Tutor] Python debugger/IDE that can be launched from a remote command line
I am working on a project in which the code and data I am working with are all on an Amazon EC2 machine. So far I have been ssh'ing to the EC2 machine in two terminal windows, running emacs or vi in one of them to view and update the code and running the "python -m pdb ..." debugger in the other one to step through the code. I would prefer to work with an IDE that displays and updates program state automatically, but I don't know which ones I could launch from a remote machine and have it display within a terminal window or use XWindows or GTK to display in its own window. Are there any Python debuggers or IDEs that can be used in this kind of setting? Thanks, Mike ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Setting log directory from a command line argument
I have added logging to a Python program I have been working on by putting this in the module's __init__.py file: ## import logging logger = logging.getLogger('ranking_factors') formatter = logging.Formatter('[%(asctime)s] %(levelname)s in %(module)s:%(funcName)s@%(lineno)s => %(message)s') handler = logging.FileHandler('ranking_factors.log') handler.setLevel(logging.DEBUG) handler.setFormatter(formatter) logger.addHandler(handler) logger.setLevel(logging.INFO) ## I would like to provide a way for different users to specify the directory where the log files are written, and perhaps also the log file names, through command line arguments. Is there a way that I can do that? I can access the logger variable in the files of the application with from . import logger logger.info("Some message") Could I import logger in the file where the command line arguments are processed and change its handler to use a different filename? If I can do that, will that change logger globally, so that logging statements in other files of the application also write logging to the new file location? If this wouldn't work, is there a different way that I could accomplish this task? Thanks, Mike ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Class-based generator
I wrote some code to create tasks to be run in a queue based system last week. It consisted of a big monolithic function that consisted of two parts: 1) read data from a file and create dictionaries and lists to iterate through 2) iterate through the lists creating a job data file and a task for the queue one at a time until all of the data is dealt with My boss reviewed my code and said that it would be more reusable and Pythonic if I refactored it as a generator that created job data files and iterated by calling the generator and putting a task on the queue for each job data file that was obtained. This made sense to me, and since the code does a bunch of conversion of the data in the input file(s) to make it easier and faster to iterate through the data, I decided to create a class for the generator and put that conversion code into its __init__ function. So the class looked like this: class JobFileGenerator: def __init__(self, filedata, output_file_prefix, job_size): def next(self): while : The problem is that the generator object is not created until you call next(), so the calling code has to look like this: gen = JobFileGenerator(data, "output_", 20).next() for datafile in gen.next(): This code works OK, but I don't like that it needs to call next() once to get a generator and then call next() again repeatedly to get the data for the jobs. If I were to write this without a class as a single generator function, it would not have to do this, but it would have the monolithic structure that my boss objected to. Would it work to do this: for datafile in JobFileGenerator(data, "output_", 20).next(): or would that cause the JobFileGenerator's __init__ function to be called more than once? Are there examples I could look at of generator functions defined on classes similar to this, or is it considered a bad idea to mix the two paradigms? Thanks, Mike ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor