Re: urllib.urlopen() with pages that requires cookies.

2006-04-27 Thread mwt
Fredrik Lundh wrote: Øyvind Østlund wrote: I am trying to visit a limited amount of web pages that requires cookies. I will get redirected if my application does not handle them. I am using urllib.urlopen() to visit the pages right now. And I need a push in the right direction to find

Finding Module Dependancies

2006-04-21 Thread mwt
When I'm rewriting code (cutting and pasting pieces from earlier modules), is there a quick way to determine if I have imported all the necessary modules? I am used to working in Java, where the compiler will tell you if you haven't imported everything, and also Eclipse, which has the handy

Re: Finding Module Dependancies

2006-04-21 Thread mwt
John Machin wrote: This is called testing. Yes, it could take a long time. Thanks for the clarification. ;) Actually, I've done hellish amounts of testing on these code pieces, which is why I don't want to have to do it all over again just to check the imports. Consider pychecker and

Re: Finding Module Dependancies

2006-04-21 Thread mwt
Wow! Just ran pychecker on a couple of modules. I'm blown away by how much information I'm getting. Thanks again! -- http://mail.python.org/mailman/listinfo/python-list

Re: Finding Module Dependancies

2006-04-21 Thread mwt
Wow! Just ran pychecker on a couple of modules. I'm blown away by how much information I'm getting. Thanks again! -- http://mail.python.org/mailman/listinfo/python-list

Method Call in Exception

2006-04-19 Thread mwt
In my latest attempt at some Python code, I've been tempted to write something in the form of: try: [...] #doing some internet stuff except IOError: alternate_method_that_doesnt_need_internet() This works when I try it, but I feel vaguely uneasy about putting method calls in exception

Re: Method Call in Exception

2006-04-19 Thread mwt
Felipe Almeida Lessa wrote: Em Qua, 2006-04-19 às 16:54 -0700, mwt escreveu: This works when I try it, but I feel vaguely uneasy about putting method calls in exception blocks. What do you put in exception blocks?! Usually I just print an error message. So tell me, Brave Pythoneers

Re: Tkinter vs PyGTK

2006-04-13 Thread mwt
I've had a good experience with Pygtk. I made a small app called Protein Think that monitors a [EMAIL PROTECTED] client. The front end is extremely simple - basically a notebook with five small pages. It runs well and was a breeze to create. Looks much better than Tkinter, if that matters at all

Re: Locate command in Python

2006-04-10 Thread mwt
On my system, files.cache ended up being 45.9 Mb (800,000+ lines)! Pretty fun script. I can imagine some interesting variations. Thanks! -- http://mail.python.org/mailman/listinfo/python-list

Locate command in Python

2006-04-09 Thread mwt
Is there a function in python that does what locate does in a bash shell? I know I could do it by using os.popen('locate'), but I'm curious if there's a Python native way to go about it. Only needs to work in Unix, but would be interesting if it was cross-platform. Thanks. --

Parsing Hints

2006-03-17 Thread mwt
/Core_82.fah CPU: 1,0 x86; OS: 4,0 Linux assignment info (le): Wed Mar 15 18:32:19 2006; A0F3AAD2 CS: 171.65.103.100; P limit: 5241856 user: MWT; team: 0; ID: 1A2BFB75B7B; mach ID: 2 work/wudata_04.dat file size: 82814; WU type: [EMAIL PROTECTED] Average download rate 97.552 KB/s (u=4

Re: Parsing Hints

2006-03-17 Thread mwt
OK. I think the solution was much easier than I thought. The key is the semicolon. I'm doing it in 3 steps: 1) Break string into 13 lines 2) Split each line by the semi-colon 3) Ummm... done already. Time to wake up. ;) -- http://mail.python.org/mailman/listinfo/python-list

Little Help with Exceptions and ConfigParser

2006-03-14 Thread mwt
in the right direction here? I know that there are many possibilities, but what would be a sane and reasonable set of exceptions to throw? Meanwhile, I will be reading pages 337-339 in my copy of Python in a Nutshell to try to get clearer about exceptions and how to use them. Thanks. mwt -- http

Re: Little Help with Exceptions and ConfigParser

2006-03-14 Thread mwt
Whoops. Those page numbers are from Cookbook. As well as the Except section in Nutshell. Still stewing away here. ;) -- http://mail.python.org/mailman/listinfo/python-list

Re: Little Help with Exceptions and ConfigParser

2006-03-14 Thread mwt
Would something like this be more useful? def __init__(self, config_file): self.fahdata = fahdata.FAHData() self.INI = ConfigParser.ConfigParser() if os.path.exists(config_file): try: self.INI.read(config_file) except

Re: Little Help with Exceptions and ConfigParser

2006-03-14 Thread mwt
(Whoops, again.) def __init__(self, config_file): self.fahdata = fahdata.FAHData() self.INI = ConfigParser.ConfigParser() if os.path.exists(config_file): try: self.INI.read(config_file) except ConfigParser.Error, err:

Re: Help Create Good Data Model

2006-03-13 Thread mwt
to be working fine. #!/usr/bin/python # author mwt # Mar '06 import copy, threading, observable class FAHData(observable.Observable): The data model for the [EMAIL PROTECTED] monitor. def __init__(self): observable.Observable.__init__(self) self.data = {}#this dict will hold all

Re: Help Create Good Data Model

2006-03-12 Thread mwt
there are already a zillion perfectly working versions out there. It's just about the right level of complexity for me now. mwt (Michael Taft) -- http://mail.python.org/mailman/listinfo/python-list

Re: Help Create Good Data Model

2006-03-12 Thread mwt
The Queue won't work for this app, because it removes the data from the Queue when you query (the way I understand it). -- http://mail.python.org/mailman/listinfo/python-list

Python Love :)

2006-03-11 Thread mwt
I've only been goofing around with Python for about a month now, but already I am in love. I never get that feeling -- so common with Java -- that I'm swimming upstream, struggling to force the language to do what I want. Python makes it feel effortless and easy. --

Help Create Good Data Model

2006-03-11 Thread mwt
.* Thanks! #!/usr/bin/python # author mwt # Mar '06 import copy, threading class FAHData(object): The data model for the [EMAIL PROTECTED] monitor. def __init__(self): self.data = {}#this dict will hold all data self.mutex = threading.RLock() def get_all_data(self

Re: Help Create Good Data Model

2006-03-11 Thread mwt
/python # author mwt # Mar '06 import copy, threading, observable class FAHData(Observable): The data model for the [EMAIL PROTECTED] monitor. def __init__(self): Observable.__init__(self) self.data = {}#this dict will hold all data self.mutex = threading.RLock

Re: Help Create Good Data Model

2006-03-11 Thread mwt
Well, thank the gods for unit testing. Here's the fah_data module with fewer errors: import copy, threading, observable class FAHData(observable.Observable): The data model for the [EMAIL PROTECTED] monitor. def __init__(self): observable.Observable.__init__(self)

Re: New python.org website

2006-03-06 Thread mwt
Wow. That does look fantastic. Thumbs up! -- http://mail.python.org/mailman/listinfo/python-list

Re: Default Section Values in ConfigParser

2006-03-01 Thread mwt
Thanks, Terry. That's an interesting way to go about it. -- http://mail.python.org/mailman/listinfo/python-list

Default Section Values in ConfigParser

2006-02-28 Thread mwt
I want to set default values for a ConfigParser. So far, its job is very small, so there is only one section heading, ['Main']. Reading the docs, I see that in order to set default values in a ConfigParser, you initialize it with a dictionary or defaults. However, I'm not quite sure of the syntax

Re: Clearing the screen

2006-02-15 Thread mwt
You know, for now, I just would like it to work in a standard Gnome terminal (my version is 2.12.0). -- http://mail.python.org/mailman/listinfo/python-list

Re: Clearing the screen

2006-02-14 Thread mwt
It clears the screen by scrolling all the characters out of sight at the top of the terminal window. So the screen is blank, but not cleared in the sense that I mean it. The behavior I want is for the display to be effectively erased and ready to receive the next wave of data -- like you would do

Re: Clearing the screen

2006-02-12 Thread mwt
No guessing needed. If I just use os.system(clear) on its own, no problem. Also, if I use the magic formula you gave on its own, that works to. But in the app, (see below), neither command works. I'm missing something obvious, but I'm... missing it. def run(self, userinfo): Time when to

Re: Clearing the screen

2006-02-12 Thread mwt
Arrgghh... Is there any way to edit posts on this thing? The os.system(clear) doesn't work at all in a module. -- http://mail.python.org/mailman/listinfo/python-list

Downloading Large Files -- Feedback?

2006-02-12 Thread mwt
This code works fine to download files from the web and write them to the local drive: import urllib f = urllib.urlopen(http://www.python.org/blah/blah.zip;) g = f.read() file = open(blah.zip, wb) file.write(g) file.close() The process is pretty opaque, however. This downloads and writes the

Re: Downloading Large Files -- Feedback?

2006-02-12 Thread mwt
Pardon my ignorance here, but could you give me an example of what would constitute file that is unreasonably or dangerously large? I'm running python on a ubuntu box with about a gig of ram. Also, do you know of any online examples of the kind of robust, real-world code you're describing?

Re: Downloading Large Files -- Feedback?

2006-02-12 Thread mwt
It isn't written in C, but get your hands on wget. It is probably already on your Linux distro, but if not, check it out here: http://www.gnu.org/software/wget/wget.html Thanks. I'm checking it out. -- http://mail.python.org/mailman/listinfo/python-list

Re: Downloading Large Files -- Feedback?

2006-02-12 Thread mwt
So, I just put this little chunk to the test, which does give you feedback about what's going on with a file download. Interesting that with urlretrieve, you don't do all the file opening and closing stuff. Works fine: -- import urllib def download_file(filename, URL): f =

Clearing the screen

2006-02-11 Thread mwt
I'm doing some python programming for a linux terminal (just learning). When I want to completely redraw the screen, I've been using os.system(clear) This command works when using python in terminal mode, and in IDLE. However, when running a little .py file containing that command, the screen

Re: Clearing the screen

2006-02-11 Thread mwt
I can't seem to get that to behave properly. It works fine in a python shell, like you're demonstrating it, but not as a command in a module. -- http://mail.python.org/mailman/listinfo/python-list

Re: 450 Pound Library Program

2006-02-09 Thread mwt
BTW - I can't find any code examples of how to interrupt a beast like this. A regular ctrl-c doesn't work, since the separate threads just keep executing. Is this a case where you need to iterate through all threads and stop each one individually? How would that look? --

Re: 450 Pound Library Program

2006-02-08 Thread mwt
A million thanks for in-depth critique. I look forward to figuring out half of what you're talking about ;) -- http://mail.python.org/mailman/listinfo/python-list

Re: Code Feedback

2006-02-07 Thread mwt
Jorgen Grahn wrote: You might want to look into using doc strings properly. You have comments at the start of functions, but they read more like implementation notes than what this method does and why. But I only had a quick look. Yeah. They were just my scaffolding notes to myself. I'd

450 Pound Library Program

2006-02-07 Thread mwt
probably got some unconscious Javanese in there somewhere. Help me get rid of it! Here's the new, improved program: [code] #!/usr/bin/python # Filename: Library.py # author: mwt # Feb, 2006 import thread import time import threading import random class Library2: def __init__(self, listOfBooks

Code Feedback

2006-02-06 Thread mwt
: #!/usr/bin/python # Filename: Library.py # author: MWT # 5 Feb, 2006 import thread import time import threading import random class Library: #The goal here is to create a synchronized list of books def __init__(self): self.stacks = [Heart of Darkness, Die Verwandlung, Lord of the Flies

Re: Code Feedback

2006-02-06 Thread mwt
Thanks for all the feedback. Interestingly, I can't seem to get Dan M's code: [code] try: while 1: pass except KeyboardInterrupt: break [/code] to work, no matter how many variations I try (including adding in time.sleep(0.1) as Peter Hansen suggested. The