e same book twice.
Here's the code:
#!/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
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. Th
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
t from Java, so I've
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:
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
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?
--
http://mail.python.org/ma
I want to do programmatic terminal commands on unix with python - i.e.
I want my program to issue commands to start and stop scripts, other
programs, etc. I'm sure this must be fairly straightforward, but
haven't been able to find a reference for it. Any help?
--
http://mail.python.org/mailman/li
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 doe
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
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
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
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 t
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?
Thank
Thanks for the explanation. That is exactly what I'm looking for. In a
way, it's kind of neat that urlopen just *does* it, no questions asked,
but I'd like to just know the basics, which is what it sounds like
urlretrieve covers. Excellent. Now, let's see what I can whip up with
that.
-- just bou
>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
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 = ur
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
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
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 t
Thanks, Terry. That's an interesting way to go about it.
--
http://mail.python.org/mailman/listinfo/python-list
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 blo
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.
>
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 "organi
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 an
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
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
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
Wow. That does look fantastic. Thumbs up!
--
http://mail.python.org/mailman/listinfo/python-list
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.
--
http://mail.python.org/mailman
includes the *why's.* 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
et a
chance, please let me know what you think.
#!/usr/bin/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__
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)
s
web spider, that lots of people want to create, even though
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
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
ool.
Here's the latest incarnation of this code. I haven't implemented the
lock you suggested yet, although this version seems to be working fine.
#!/usr/bin/python
# author mwt
# Mar '06
import copy, threading, observable
class FAHData(observable.Observable):
&q
kind as to point me 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.
T
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
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 ConfigParser.Err
(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:
//www.stanford.edu/~pande/Linux/x86/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]
Ave
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
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.
--
http://mail.p
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
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
44 matches
Mail list logo