Re: yet another noob question

2006-08-13 Thread Rene Pijlman
Stargaming:
>Generally, it is range(1, 5)

Minus all numbers whose decimal string representation matches
[0-9]*[06-9][0-9]* Briljant!

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: yet another noob question

2006-08-13 Thread Rene Pijlman
mike_wilson1333:
>I would like to generate every unique combination of numbers 1-5 in 
>a 5 digit number [...] What would be the best way to do this?

Ask the Java newsgroup to design a clever algorithm and post it here for
pythonification. Ask for the pseudocode, not the Java code.

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: urllib (in thread) never returns

2006-07-17 Thread Rene Pijlman
Kingsley:
>it just sits in either the urlopen() or read() forever.
[...]
>I would have thought that some urllib-internal timeout 
>would fix this?!

Yes, but you'll need to enable it. See socket.setdefaulttimeout() :
http://docs.python.org/lib/module-socket.html

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: classes and interfaces

2006-07-02 Thread Rene Pijlman
Bruno Desthuilliers:
>Java interfaces are a workaround

Troll alert.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: classes and interfaces

2006-07-02 Thread Rene Pijlman
[EMAIL PROTECTED]:
>In python , how to implement interface like the above? 

Interfaces are lacking in Python, but an even more generic proposal is on
its way:
http://www.artima.com/weblogs/viewpost.jsp?thread=155123

In the mean time, interfaces have already been implemented in Zope 3:
http://www.zope.org/Products/ZopeInterface

-- 
René Pijlman

"To find out what you can do with interfaces, see the interface interface,
IInterface in the IInterface module."
- Comment in Zope's Interface/__init__.py
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Program slowing down with greater memory use

2006-06-23 Thread Rene Pijlman
Dan Stromberg:
>What's the deal here? 

The sketchy information in your post doesn't rule out any possibility.

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using PHP in Python

2006-06-12 Thread Rene Pijlman
Tgone:
>I have some custom PHP functions that I didn't want to re-write in
>Python. But maybe I should just rewrite them :)

Absolutely. 

The alternative is one of many IPC mechanisms that are available in both
Python and PHP (such as XML-RPC). But that may require more effort than
rewriting the functions.

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: An error ?

2006-06-11 Thread Rene Pijlman
Bo Yang:
>[Fri Jun 16 14:06:45 2006] [error] [client 10.10.110.17] malformed
>header from script. Bad header=Hello World!: a.py

"The output of a CGI script should consist of two sections, separated by a
blank line. The first section contains a number of headers, telling the
client what kind of data is following."
http://docs.python.org/lib/cgi-intro.html

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CENSORSHIP - Django Project (Schema Evolution Support)

2006-06-07 Thread Rene Pijlman
Ilias Lazaridis:
>What is the credibility and value of the provided "wikipedia" entry?

Wikipedia always tells the Absolute Truth, because if it doesn't, we can
edit it and fix it right away.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 10GB XML Blows out Memory, Suggestions?

2006-06-06 Thread Rene Pijlman
[EMAIL PROTECTED]:
>I wrote a program that takes an XML file into memory using Minidom. I
>found out that the XML document is 10gb.
>
>I clearly need SAX or something else?
>
>Any suggestions on what that something else is? 

PullDOM.
http://www-128.ibm.com/developerworks/xml/library/x-tipulldom.html
http://www.prescod.net/python/pulldom.html
http://docs.python.org/lib/module-xml.dom.pulldom.html (not much)

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Writing to a certain line?

2006-06-06 Thread Rene Pijlman
bruno at modulix:
>You can't do this in place with a text file (would be possible with a
>fixed-length binary format).

More precise: it's possible with any fixed-length change, in both binary
and text files, with both fixed and variable formats.

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Writing to a certain line?

2006-06-06 Thread Rene Pijlman
Tommy  B:
>I was wondering if there was a way to take a txt file and, while
>keeping most of it, replace only one line.

You'd need to read the file and parse it, to find the start position of
the line you want to change. Then seek output to that position and write
and flush the changes. You must keep the file locked during this
operation, to prevent other processes from changing the file in between
these steps. You can only replace a string with a string of the same
length.
http://docs.python.org/lib/bltin-file-objects.html

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python to C converter

2006-06-05 Thread Rene Pijlman
[EMAIL PROTECTED]:
>I have an application return in python. I want this to be
>converted to C. 

http://www.python.org/doc/faq/general/#can-python-be-compiled-to-machine-code-c-or-some-other-language

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: beginner code problem

2006-06-02 Thread Rene Pijlman
RJ:
>import random
>flip = random.randrange(2)
>heads = 0
>tails = 0
>count = 0
>while count < 100:
>   if flip == 0:
>   heads += 1
>   else:
>   tails += 1
>   count += 1

Since flip isn't changed in the loop, this is going to report 100 heads or
100 tails, depending on the zeroness of flip.

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Zope / Plone Groups

2006-06-01 Thread Rene Pijlman
[EMAIL PROTECTED]:
>are there any specific groups for zope / plone regarding questions?

Try plone-users: http://plone.org/support

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: what is the reasonable (best?) Exception handling strategy?

2006-06-01 Thread Rene Pijlman
Petr Jakes:
>What about unexpected exceptions? :(

I asked a similar question some time ago:
http://groups.google.nl/group/comp.lang.python/browse_thread/thread/25963b99da4b2653

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: HTMLParser chokes on bad end tag in comment

2006-05-29 Thread Rene Pijlman
Miki:
>You can also check out BeautifulSoup
>(http://www.crummy.com/software/BeautifulSoup/) which is less strict
>than the regular HTML parser.

Yes, thanks. Ik this case it was my sitechecker which checks for syntax
and broken links, so it was supposed to find the syntax error.
BeautifulSoup is not very well suited for validators :-)

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: HTMLParser chokes on bad end tag in comment

2006-05-29 Thread Rene Pijlman
Fredrik Lundh:
>Rene Pijlman:
>[end tag in html comment in script element]
>The end tag it chokes on is in comment, isn't it?
>
>no.  STYLE and SCRIPT elements contain character data, not parsed 
>character data, so comments are treated as characters, and the first 
>"if you have broken documents, you can tweak this by setting the 
>CDATA_CONTENT_ELEMENTS parser attribute before you start parsing.

... and in the mean time that's a good workaround.

Thank you very much Fredrik.

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why not in python 2.4.3

2006-05-28 Thread Rene Pijlman
Rocco:
>but does not work with 2.4.3.

Define "does not work".

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


HTMLParser chokes on bad end tag in comment

2006-05-28 Thread Rene Pijlman
The code below results in an exception (Python 2.4.2):

HTMLParser.HTMLParseError: bad end tag: "", at line 4,
column 6

Should it? The end tag it chokes on is in comment, isn't it?

import HTMLParser
HTMLParser.HTMLParser().feed("""



""")

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can Python installation be as clean as PHP?

2006-05-09 Thread Rene Pijlman
Jack:
>I have to run the installer to install dozens of directories and 
>hundreds of files, 

That's not unusual and not considered a problem by most people.

>and I don't really know if all of them are necessary.

Don't let that bother you. Life's too short.

>Plus, lots of libraries are in .py, which is of course not as 
>efficient/clean as having all of the core functions built-in in 
>the C/C++ core, like in PHP.

Performance-critical parts _are_ implemented in C/C++. But not everything
falls into this category. Yes, there's probably room for more performance
improvements. Just like there is with PHP. Did you know, for example, that
PHP doesn't store and re-use compiled versions of the scripts by default?
With PHP you need to fiddle with eAccelerator, Zend and the like. The
Python interpreter does this automatically.

There are advantages to having library code in Python too, such as being
able to seemlessly debug it in a Python debugger. Also, Python API's tend
to be a lot cleaner than PHP's. This probably reflects the language
they're implemented in.

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Upgrading Class Instances Automatically on Reload

2006-05-09 Thread Rene Pijlman
malv:
>At the statement b = Bar(), the following error occurs:
>The debugged program raised the exception unhandled AttributeError
>"type object 'Bar' has no attribute '__instance_refs__'"

I haven't studied it at all, but the code on
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/160164 seems to
run fine with Python 2.4.2 in WingIDE on Windows XP. There's no exception
and it prints:
1
2
3

Are you perhaps using an older dead tree version of the Cookbook?

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Upgrading Class Instances Automatically on Reload

2006-05-09 Thread Rene Pijlman
malv:
>Did anybody get this recipe to work?

Did you?

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ascii to latin1

2006-05-08 Thread Rene Pijlman
Luis P. Mendes:
>I'm developing a django based intranet web server that has a search page.
>
>Data contained in the database is mixed.  Some of the words are
>accented, some are not but they should be.  This is because the
>collection of data  began a long time ago when ascii was the only way to go.
>
>The problem is users have to search more than once for some word,
>because the searched word can be or not be accented.  If we consider
>that some expressions can have several letters that can be accented, the
>search effort is too much.

I guess the best solution is to index all data in ASCII. That is, convert
a field to ASCII (from accented character to its unaccented constituent)
and index that.

Then, on a search, you also need to unaccent the search phrase, and match
it against the asciified index.

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PYTHONPATH vs PATH?

2006-05-08 Thread Rene Pijlman
Fredrik Lundh:
>PATH is used by the operating system to find executables, and PYTHONPATH
>is used by Python to find Python modules.

Yes, but Python also finds modules in its own installation. So changing
PATH may cause another installation of Python to be run, which may have
some other set of installed modules.

"When a module named spam is imported, the interpreter searches for a file
named spam.py in the current directory, and then in the list of
directories specified by the environment variable PYTHONPATH. This has the
same syntax as the shell variable PATH, that is, a list of directory
names. When PYTHONPATH is not set, or when the file is not found there,
the search continues in an installation-dependent default path; on Unix,
this is usually .:/usr/local/lib/python."
http://docs.python.org/tut/node8.html

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting HTTP responses - a python linkchecking script.

2006-05-08 Thread Rene Pijlman
[EMAIL PROTECTED]:
>Rene Pijlman wrote:
>> [EMAIL PROTECTED]:
>> >with urllib2 it doesn't seem possible to get HTTP status codes.
>>
>> except urllib2.HTTPError, e:
>> if e.code == 403:
>
>Thanks.  Is there documentation for this available somewhere online, I
>can't see it to obviously in the library reference?

No, this seems to be missing from the documentation.

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting HTTP responses - a python linkchecking script.

2006-05-08 Thread Rene Pijlman
[EMAIL PROTECTED]:
>with urllib2 it doesn't seem possible to get HTTP status codes.

except urllib2.HTTPError, e:
if e.code == 403:

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: data regex match

2006-05-02 Thread Rene Pijlman
Gary Wessle:
>tx = "now 04/30/2006 then"
>data = re.compile('(\d{2})/\1/\1\1', re.IGNORECASE)
>d = data.search(tx)
>print d
>
>Nono
>I was expecting 04/30/2006

You should expect: NameError: name 're' is not defined

> what went wrong?

\1 matches the content of the first group, which is '04'. It doesn't match
'30', '20' and '06'.

Also, you'll need to use a raw string, or backslash your backslashes.

>>> import re
>>> tx = "now 04/04/0404 then"
>>> data = re.compile(r'(\d{2})/\1/\1\1', re.IGNORECASE)
>>> d = data.search(tx)
>>> print d
<_sre.SRE_Match object at 0x01287F60>

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: setting file permissions on a web server

2006-04-30 Thread Rene Pijlman
John Salerno:
>I always read about how you need to set certain file permissions (for 
>cgi files, for example), but it's never been clear to me *how* you do 
>this. I know you can run the line
>
>chmod 755 scriptname.py
>
>but *where* do you run this? 

This is a Unix/Linux command. You run it in a shell login on the server
(e.g. in Putty, SecureCRT, or some other ssh client you're using).

>Is there a way to put the above line within the script perhaps, so that 
>the script sets its permission automatically?

Not in the script itself via cgi of course, because it needs certain
permissions before it can be run as cgi script. But you could put the
command in an installation script that installs the cgi script.

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python "member of" function

2006-04-29 Thread Rene Pijlman
[EMAIL PROTECTED]:
>I was wondering if anyone knew of a built in Python function that will
>check if an item is a member of a list, i.e., if item i is a member of
>list l.

>>> 1 in [1,3,4]
True
>>> 2 in [1,3,4]
False

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: begging for a tree implementation

2006-04-26 Thread Rene Pijlman
Micah:
>I'd like a full-featured tree

What features?

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Zope 3

2006-04-25 Thread Rene Pijlman
Steve Juranich:
>is there some big master diff, along the lines of "What's new
>in Python X.X" that I could look at to get an idea of what z3 has that 2.9
>(which I'm currently still cutting my teeth on) doesn't? 

It's a redesign.
Z2: mixin base classes
Z3: component architecture with interfaces

>Where are the Zope3 docs?

Google!

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OOP / language design question

2006-04-25 Thread Rene Pijlman
[EMAIL PROTECTED]:
>I think I'll need some shift in thinking after C++.

+1 qotw

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OOP / language design question

2006-04-25 Thread Rene Pijlman
[EMAIL PROTECTED]:
>I was wondering, why you always have to remember to call bases'
>constructors explicitly from the derived class constructor? Why hasn't
>this been enforced by the language?

Probably because the language doesn't know whether the subclass wants to
override its base class's constructor, or enhance it.

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: need a thread to keep a socket connection alive?

2006-04-24 Thread Rene Pijlman
[EMAIL PROTECTED]:
>i have discovered that the server will send a request for the heartbeat
>ping if its almost timed out, so i use the length of the message to
>determine what to do with it.
>
>msg = sockobj.recv(1024)
>
>if len(msg) == 158:
>record the data
>elif len(msg) == (34): # length of request for ping
>ping the server

Incorrect. There are no 'messages' with TCP, only bytes.

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: threads and sys.exit()

2006-04-24 Thread Rene Pijlman
gangesmaster:
>(i forgot to say it didn't work)

It's the remaining threads that need to be daemon, when some thread
performs sys.exit. When no non-daemon thread remains, the application
terminates.

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problems when unpacking tuple ...

2006-04-22 Thread Rene Pijlman
harold:
>A similar error happens in an interpreter session, when typing
 for line in ["1 2 3 4"] :
>...for a,b,c,d in line.split() :
>...pass
>...
>Traceback (most recent call last):
>  File "", line 2, in ?
>ValueError: need more than 1 value tyo unpack
>
>maybe this might help to track down the error.

Suppose the code was:

for x in line.split():

line.split() yields one list with 4 items. The loop will be performed 4
times, assigning one value of the list to x with every iteration. In your
code, x is a tuple with 4 elements: a,b,c,d. So with every iteration one
value is assigned to that tuple. Since the value is not a sequence of 4
items, this fails.

There's two sensible things you can do:

for line in ["1 2 3 4"]:
a,b,c,d = line.split()

for line in ["1 2 3 4"]:
for a in line.split():

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problems when unpacking tuple ...

2006-04-22 Thread Rene Pijlman
harold:
>The output (when given the data I want to parse) is:

If you'd told us that data, and told us what version of Python you're
using, we could have reproduced the problem to look into it.

>ValueError: need more than 3 values to unpack
>
>Why does python think that I want to unpack the outcome of 
>line.split() into three values instead of four? 

That's not what it says. It says there are only 3 values in the outcome,
and it needs more (4 to be precise).

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: need a thread to keep a socket connection alive?

2006-04-22 Thread Rene Pijlman
[EMAIL PROTECTED]:
>i have a script that waits for message packets from a data server over
>a socket.

Using what network protocol?

>it works fine for a while, but the server requires that i send a
>heartbeat ping every 600 seconds or it will terminate the connection.
[...]
>should i do this with threads? i dont want to interrupt the listening
>cycle to send a ping.

If this is a TCP connection with a conversational protocol, you can't have
two threads reading bytes of the socket, without some sort of
coordination. When one thread parses the bytes it received, some bytes may
be part of the next message for the other thread.

You may be better off with asynchronous I/O and a state machine model.
http://squirl.nightmare.com/medusa/async_sockets.html
http://www.python.org/doc/lib/module-asyncore.html
http://twistedmatrix.com/projects/core/documentation/howto/clients.html

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Read and extract text from pdf

2006-04-21 Thread Rene Pijlman
Julien ARNOUX:
>I have a problem :), I just want to extract text from pdf file with
>python. There is differents libraries for that but it doesn't work...
>
>pyPdf and  pdfTools, I don't know why but it doesn't works with some
>pdf...

Text can be represented in different ways in PDF: as tagged text, bitmap
and vector images, and even algorithms (IIRC). Most tools will only be
able to retrieve text represented as tagged text. So some tools may work
on some texts in some files and fail on others.

-- 
René Pijlman

Wat wil jij leren?  http://www.leren.nl
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Missing interfaces in Python...

2006-04-19 Thread Rene Pijlman
Neal Becker:
>I see various answers that Python doesn't need interfaces.  OTOH, there are
>responses that some large Python apps have implemented them (e.g., zope). 
>Does anyone have an explanation of why these large systems felt they needed
>to implement interfaces?

A programming language doesn't need interfaces, unless it insists on
compile time checking of just about everything.

The idea of interfaces arises from the construction and maintenance of
large and complex software systems. It provides a level of abstraction
that makes it easier to talk about a component and document what it
requires from and offers to it's environment.

Also, interfaces can make this documentation first-class objects, so test
tools, IDE's and software design tools can take advantage of it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Missing interfaces in Python...

2006-04-19 Thread Rene Pijlman
Alex Martelli:
>PEAK is an interesting counterexample, particularly since Philip Eby
>tends to be "ahead of the curve":

I never noticed PEAK before. Is it well worth studying?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Missing interfaces in Python...

2006-04-19 Thread Rene Pijlman
Kay Schluehr:
>You won't find many deep class hierarchies and extensive frameworks. 

Zope comes to mind.

>This has the advantage that a classification you have done once at 
>the beginning of your project in the design phase is not considered 
>to be carved in stone.

Zope 3 comes to mind.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Uniquifying a list?

2006-04-18 Thread Rene Pijlman
Tim Chase:
>Is there an obvious/pythonic way to remove duplicates from a 
>list (resulting order doesn't matter,

Use a set.
http://www.python.org/doc/lib/types-set.html

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Missing interfaces in Python...

2006-04-18 Thread Rene Pijlman
[EMAIL PROTECTED]:
>If it looks like a duck, and quacks like a duck, then for all practical
>purposes it supports the 'duck' interface.

The problem with that of course, is that there's much more to being a duck
than being called 'duck'.

public interface JarFile {
void explode();
}
public interface NuclearBomb {
void explode();
}
http://www.beust.com/weblog/archives/000269.html

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: List of all syntactic sugar?

2006-04-14 Thread Rene Pijlman
Bas:
>just out of curiosity, is there a list of all the syntactic sugar that
>is used in python? 

http://docs.python.org/ref/specialnames.html

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sending email with charset utf-8 but subject is not coded properly

2006-04-14 Thread Rene Pijlman
Grzegorz ¦lusarek:
>I sending email using standard python modules smtplib, email, 
>coding email in utf but subject of message is not coded properly. In 
>subject i use my national characters (polish) and after send i get XX in 
>place these characters.
>Here is the code
>
>Message = email.message_from_string(pMessage)
>   Message.set_charset('utf-8')
>   Message['From'] = '[EMAIL PROTECTED]'
>   Message['To'] = '[EMAIL PROTECTED]'
>   SMTPServer=smtplib.SMTP(ConfigurationManager.SMTPServer)
>   SMTPServer.sendmail('[EMAIL PROTECTED]','[EMAIL PROTECTED]', 
> Message.as_string())

I see no subject in this code.

"If you want to include non-ASCII characters in your email headers, say in
the Subject: or To: fields, you should use the Header class and assign the
field in the Message object to an instance of Header instead of using a
string for the header value."
http://docs.python.org/lib/module-email.Header.html

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: FTP

2006-04-07 Thread Rene Pijlman
Arne:
>I want to connecto to a ftp server. There I woult like to read the 
>directiroy and getting the filename, file owner and the file size.
>
>How can I do this in python

http://docs.python.org/lib/module-ftplib.html

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Characters contain themselves?

2006-04-07 Thread Rene Pijlman
WENDUM Denis 47.76.11 (agent):
>While testing recursive algoritms dealing with generic lists I stumbled 
>on infinite loops which were triggered by the fact that (at least for my 
>version of Pyton) characters contain themselves.

No, strings contain characters. And 'a' is a string consisting of one
character.

"The items of a string are characters. There is no separate character
type; a character is represented by a string of one item."
http://docs.python.org/ref/types.html

(One item of what type, one might ask)

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: HTMLParser fragility

2006-04-05 Thread Rene Pijlman
Lawrence D'Oliveiro:
>I've been using HTMLParser to scrape Web sites. The trouble with this 
>is, there's a lot of malformed HTML out there. Real browsers have to be 
>written to cope gracefully with this, but HTMLParser does not. 

There are two solutions to this:

1. Tidy the source before parsing it.
http://www.egenix.com/files/python/mxTidy.html

2. Use something more foregiving, like BeautifulSoup.
http://www.crummy.com/software/BeautifulSoup/

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: socket connetion to url with port 80

2006-04-04 Thread Rene Pijlman
Sakcee:
>how can i get page response from a site e.g. google.com port 80
[...]
>can i do at socket level?

Yes, but you'll need to implement HTTP:
http://www.ietf.org/rfc/rfc2616.txt

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pickle or Mysql

2006-03-31 Thread Rene Pijlman
[EMAIL PROTECTED]:
>Can I use Pickle to store about 500,000 key value pairs.. 

Performance would be horrible. Use a BTree in ZODB instead:
http://www.zope.org/Wikis/ZODB/guide/node6.html#SECTION00063

>or should I use mySql.

You should use a relational database, such as PostgreSQL, when you want to
model your data as relations (tables) instead of objects, or when you want
to use SQL, or when another application needs to access the data that only
speaks SQL, or ...

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: instance and class-hierarchy ?

2006-03-29 Thread Rene Pijlman
Bror Johansson:
>I have a class-hierarchy (fairly deep and fairly wide).
>
>Is there a good and general way to test an instance-object obj for having a
>class belonging to a certain "sub-tree" of the hierarchy with a common
>parent class C?

isinstance(obj,C)

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: trying to use popen2() to communicate with C program

2006-03-28 Thread Rene Pijlman
I. Myself:
>I can't get this to work

With what versions of what software on what platform?

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Difference between 'is' and '=='

2006-03-27 Thread Rene Pijlman
Terry Reedy:
>The Python specification allows but does not require such behind-the-scenes 
>implementation optimization hacks.  As released, CPython 2.4 caches -5 to 
>99, I believe.  In 2.5, the upper limit was increased to 256.  The limits 
>are in a pair of #define statements in the int object source file.  Anyone 
>who compiles from source can adjust as desired (though the corresponding 
>test will fail unless also adjusted ;-).
>
>I think the visibility of this implementation detail from Python code is an 
>example of a leaky abstraction.  For more, see
>http://www.joelonsoftware.com/articles/LeakyAbstractions.html

Joel has his abstractions wrong. TCP doesn't guarantee reliable delivery,
unlike IP it delivers reliably or it tells you it cannot. SQL perormance
doesn't break abstraction, since performance isn't part of SQL. You _can_
drive as fast when it's raining. 

Now, about identity and equality. As you know, identity implies equality,
but equality doesn't imply identity. You seem to assume that when identity
is not implied, it should be undetectable. But why?

Here's A, there's B, they may or may not be identical, they may or may not
be equal.

What are you suggesting?

1. If A and B are of comparable types, and A equals B, we should not be
allowed to evaluate "A is B".

2. If A and B are of comparable types, and A equals B, A should be B.

3. If A and B are of comparable types, and A equals B, A should not be B.

4. If A and B are of comparable types, and A equals B, "A is B" should not
evaluate to a boolean value.

5. When A and B are of comparable types, we should not be allowed to
evaluate "A == B" :-)

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Difference between 'is' and '=='

2006-03-27 Thread Rene Pijlman
mwql:
>Hey guys, this maybe a stupid question, but I can't seem to find the
>result anywhere online. When is the right time to use 'is' and when
>should we use '=='? 

http://docs.python.org/ref/comparisons.html

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cookbook for beginners?

2006-03-26 Thread Rene Pijlman
Aahz:
>If you were going to name three or five essential recipes from the
>Python Cookbook suitable for beginners, what would you pick?
>Yes, this is for _Python for Dummies_, so idioms that aren't in the
>Cookbook are also fine.

Constants

Static methods / Class methods

Bunch

TaskQueue (Queue for easy and safe multithreading)

A decorator for type checking of function arguments, and/or for
require/ensure, and/or for similar features of other languages that people
find missing in Python.

Properties and in particular lazy properties. Why and how to avoid
getters/setters.

Dynamically import a module (name known at runtime, may or may not be
present).

Unittest/doctest.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Module documentation

2006-03-26 Thread Rene Pijlman
Tony Burrows:
>With something like Java I can find the syntax of a method call with no
>problems, how do I do the same with Python?

The basic syntax is just the name, with parameters in brakcets:

   object.method(par1, par2, ...)

This is explained in the documentation, of course.

>how do I find out what parameters are needed and what they represent?

This is documented in the library reference:
http://docs.python.org/modindex.html

You can also query the module for its docstrings:

>>>import os
>>>help(os)
...
>>>help(os.utime)
Help on built-in function utime in module nt:
...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT: unix newbie questions

2006-03-25 Thread Rene Pijlman
Gerard Flanagan:
>* To create an empty __init__.py file I do 'vim __init__.py' then
>immediately exit vim, is there a shell or vim command which will create
>an empty file without opening the editor?

touch __init__.py

>* cd ~ brings me to my home directory, is there a means by which I can
>set up a similar alias for, say, /usr/local/www, so I can do: eg. cd ^
>to get to that directory?

You could create an alias in your shell.

-- 
René Pijlman

Wat wil jij leren?  http://www.leren.nl
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Confused: appending to a list

2006-03-23 Thread Rene Pijlman
DataSmash:
>I'm confused.  Why is it that when I say "while len(list) < 5:", I get
>5 items in my list.

Because the last time when len(list) was < 5, the block of code following
the while executed and did something to the list to give it a length >= 5
(otherwise the block of code would be executed again and it wouldn't have
been the last time).

>list.append(num)

There you have it.

-- 
René Pijlman

Wat wil jij leren?  http://www.leren.nl
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Good thread pool module

2006-03-23 Thread Rene Pijlman
Dennis Lee Bieber:
>Raymond Hettinger:
>> Because of the GIL, thread pools are not as useful in Python as you
>> might expect -- they execute one at a time and do not take advantage of
>> hyper-threading or multiple processors.  If that kind of efficiency is
>
>   If the task is I/O bound (something like a web spider?), seems
>they'd still be useful...

Yes, I use a thread pool for that. But async I/O may be a more efficient
solution (e.g. Twisted).

-- 
René Pijlman

Wat wil jij leren?  http://www.leren.nl
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: COM Client / Server creation?

2006-03-22 Thread Rene Pijlman
Dan:
>New to python. Running under windows xp. Need help getting started
>writing COM server and client. 

Highly recommended:
http://safari.oreilly.com/?XmlId=1-56592-621-8
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TaskQueue

2006-03-21 Thread Rene Pijlman
Carl Banks:
>Rene Pijlman:
>> Ah yes, clever trick. But you'd have to worry about thread-safety of your
>> subclass though.
>
>Queue worries about this for you.  The Queue class only calls _get when
>it has the queue's mutex, so you can assume thread safety when
>subclassing it.

Ah yes, I overlooked the underscore. But you'd have to worry about
everything get() is doing before it calls _get() though :-)

>Say you were writing a FiniteQueue class that implemented the permament
>sentinel trick to indicate to all consumer threads that the queue is
>done.  For your own code, you may know that you'll never need to pass
>None through the queue, but you can't assume that for all code.

Ah, this is where assert proves its value.

class FiniteQueue(object):
def putTask(self,task):
assert task is not None
self.workQueue.put(task)
self.numberOfTasks += 1
# ...

-- 
René Pijlman

Wat wil jij leren?  http://www.leren.nl
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can XML-RPC performance be improved?

2006-03-21 Thread Rene Pijlman
Sion Arrowsmith:
>I've got an established client-server application here where there
>is now a need to shovel huge amounts of data (structured as lists of
>lists) between the two, and the performance bottleneck has become
>the amount of time spent parsing XML

http://xmlsucks.org/

>Anyone got any good ideas for tackling this problem?

cPickle.
http://docs.python.org/lib/module-cPickle.html

-- 
René Pijlman

Wat wil jij leren?  http://www.leren.nl
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I compare if 2 files has duplicate entries in python?

2006-03-21 Thread Rene Pijlman
[EMAIL PROTECTED]:
>I am new to python. How can I compare if 2 files has duplicate 
>entries in python?

What is an 'entry'?

-- 
René Pijlman

Wat wil jij leren?  http://www.leren.nl
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TaskQueue

2006-03-21 Thread Rene Pijlman
Carl Banks:
>Rene Pijlman:
>> for i in range(self.numberOfThreads):
>> self.workQueue.put(None)
>
>Or, you could just put one sentinel in the Queue, and subclass the
>Queue's _get method not to take the sentinel out.

Ah yes, clever trick. But you'd have to worry about thread-safety of your
subclass though.

>BTW, for sentinels, I recommend creating one using:
>
>sentinel = object()
>
>Because, although it's not applicable to your example, sometimes None
>is an object you want to pass through.  (I think Alex Martelli came up
>with that one.)

You mean this post, I guess:
http://mail.python.org/pipermail/python-list/2004-October/244750.html

I dunno, but I cannot think of a better way to say "this has no possible
use" than to pass None. Place yourself in the position of someone who
doesn't know exactly what object() is and who encounters it in the code.
I've just spent 5 minutes trying to find some reference information and I
gave up ("object" is a lousy search word).

-- 
René Pijlman

Wat wil jij leren?  http://www.leren.nl
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TaskQueue

2006-03-21 Thread Rene Pijlman
Raymond Hettinger:
>There are some competing approaches.  One is to attach sentinel objects
>to the end of the line as a way for consumer threads to know that they
>should shut down.  Then a regular t.join() can be used to block until
>the consumers threads have shut-down.  This approach is
>straight-forward, but it depends on 1) complicating the consumer logic
>to include sentinel detection and thread shut-down,

Writing this observation was way more complicated than writing the code
that's required to implement it :-)

if task is None:
break

I use 'None' as the sentinel. This is a larger snippet from my own
threadpool with the context of this code:

def run(self):
while True:
task = self.workQueue.get()
if task is None:
break
try:
task.do()
except:
task.unhandledException()
self.resultQueue.put(task)

>2) complicating the producer logic to append one sentinel for each consumer 
>when the data stream is done

for i in range(self.numberOfThreads):
self.workQueue.put(None)

Again, more characters in your observation than in the code.

>3) actually knowing when the data stream is done.  

def doingWork(self):
return self.numberOfTasks > 0

Which is possible because of:

def putTask(self,task):
self.workQueue.put(task)
self.numberOfTasks += 1

def getTask(self):
task = self.resultQueue.get()
self.numberOfTasks -= 1
return task

-- 
René Pijlman

Wat wil jij leren?  http://www.leren.nl
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Keeping a function from taking to long--threads?

2006-03-20 Thread Rene Pijlman
<[EMAIL PROTECTED]>:
>I'm using windows, and from what I've tried, the setdefaulttimeout 
>function doesn't work on my machine.

It should. It does on mine.

-- 
René Pijlman

Wat wil jij leren?  http://www.leren.nl
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Keeping a function from taking to long--threads?

2006-03-19 Thread Rene Pijlman
<[EMAIL PROTECTED]>:
>Just wondering if anyone knows of a way to keep a function,
>E.g. socket.gethostbyaddr("12.34.56.78"),
>>From taking to long-if it's run for more than 1 second, the function
>gethostbyaddr will be terminated?

import socket
socket.setdefaulttimeout(1)

-- 
René Pijlman

Wat wil jij leren?  http://www.leren.nl
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there such an idiom?

2006-03-19 Thread Rene Pijlman
Per:
>how to find whether there is/are common item(s) between two list
>in linear-time?

To find items in common between two lists, make the first into a
dictionary and then look for items in the second in it.

-- 
René Pijlman

Wat wil jij leren?  http://www.leren.nl
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need design advice. What's my best approach for storing this data?

2006-03-17 Thread Rene Pijlman
Mudcat:
>My initial thought was to put the data in large dictionaries and shelve
>them (and possibly zipping them to save storage space until the data is
>needed). However, these are huge files.

ZODB solves that problem for you.
http://www.zope.org/Wikis/ZODB/FrontPage

More in particular "5.3 BTrees Package":
http://www.zope.org/Wikis/ZODB/guide/node6.html#SECTION00063

But I've only used ZODB for small databases compared to yours. It's
supposed to scale very well, but I can't speak from experience.

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python compiler

2006-03-15 Thread Rene Pijlman
Rc:
>My question is where can I find a compiler for free.
>For Windows XP.

http://www.python.org/download/

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Queue limitations?

2006-03-15 Thread Rene Pijlman
[EMAIL PROTECTED]:
>I'm using Queue to send images from one thread to another, and some of
>the images are not appearing in the consumer threadmaybe 1 in 3
>arrive.

I find that hard to believe. Could there be a bug in your program,
somewhere, somehow?

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Debugger / IDE ??

2006-03-14 Thread Rene Pijlman
[EMAIL PROTECTED]:
>Is there any editor or IDE in Python (either Windows or Linux) which
>has very good debugging facilites like MS VisualStudio has or something
>like that.

Here's a recent thread about IDEs:
http://groups.google.nl/group/comp.lang.python/browse_frm/thread/fd9604e225252ad4

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: calling another python file within python

2006-03-14 Thread Rene Pijlman
Kevin:
>#!/usr/bin/python
>
>import os
>import urllib
>os.system("python pyq.py ibm > text1.txt")

Check the return value of os.system.

>note: currently the text1.txt outputted is just blank, however if i run 
>the command normally as 'python pyq.py ibm' in the command line, it 
>works correctly and gives me the price of ibm.

Same PATH, PYTHONPATH, current working directory, user,... ?

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python IDE: great headache....

2006-03-11 Thread Rene Pijlman
Sullivan WxPyQtKinter:
>I hope that an IDE should be featured with:

I use WingIDE 2.1.0 (beta1) and I'm pleased with it.
 
>1. Grammar Colored highlights.

Yes, Wing does that.

>2. Manage project in a tree view or something alike, ie, a project file
>navigator.

Yes.

>3. Code collapse and folding.

Yes.

>4. Code auto-completion: especially prompting function parameters when
>I am typing a function previously defined by myself. Like the one in
>Visual Studio series.

Yes (well, hints in a separate pane, no prompting).

>5. Debugging: Breakpoints, conditional pause. watch for variables.step
>into, over and out of a function.

Yes.

>6.Indentation management like in IDLE: press ctrl+[/] to modify the
>identation of a line or a block.

Yes.

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: accessors and lazy initialization

2006-03-10 Thread Rene Pijlman
Bill:
>In general I try to initialize the state of my objects as late as
>possible, in the accessor. [...]
>Is there a more Pythonic way of looking at this?

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/131495
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/363602

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Use python to process XML file

2006-03-10 Thread Rene Pijlman
[EMAIL PROTECTED]:
>Can you please tell me how Use python to process XML file?
>The example I find is build a DOM, but I just need to do it in SAX
>based, how can I do that?

http://docs.python.org/lib/module-xml.sax.html
http://pyxml.sourceforge.net/topics/howto/section-SAX.html

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to validate a proxy is alive?

2006-03-10 Thread Rene Pijlman
JuHui:
>If a proxy is alive then return true, else return fals after 1 second.

What kind of proxy? Design pattern? Protocol? Which one?

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: urlerror, urllib2: "no address" ... why or debug tips?

2006-03-10 Thread Rene Pijlman
[EMAIL PROTECTED]:
>Help please with a URLError.

Post your code (a small self-contained example, preferrably) and the URL.

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: linux clipboard?

2006-03-07 Thread Rene Pijlman
[EMAIL PROTECTED]:
>how can i copy text to the linux clipboard?

Linux is an operating system. It doesn't have a clipboard. The clipboard
is provided by desktop frameworks, such as KDE or Gnome.

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Confused by Method(function) of a module and method of a class/instance

2006-03-07 Thread Rene Pijlman
Sullivan WxPyQtKinter:
>Why do the three expression yield the same result "abc"?

Because all three converted "ABC" to lowercase, as per your request.

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: automatic referencing for variables?

2006-03-06 Thread Rene Pijlman
[EMAIL PROTECTED]:
>can you do something like that in python?

All you did is show us some string literals, but I guess you're looking
for string substitution:
http://docs.python.org/lib/typesseq-strings.html

This can be simplified, they say:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/305306

There's also Template strings:
http://www.python.org/dev/doc/newstyle/lib/node105.html

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: dual CPU-mode in python

2006-03-05 Thread Rene Pijlman
Astan Chee:
>I was wondering if there is a way to maximize CPU usage

Fork a Java app :-)

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to except the unexpected?

2006-03-05 Thread Rene Pijlman
Steven D'Aprano:
>The OP is doing it because catching all exceptions masks bugs. There are
>certain exceptions which should be allowed through, as they indicate a bug
>in the OP's code. Normally the tactic is to catch only the exceptions you
>are interested in, and let everything else through, but the OP needs to
>catch all exceptions because there are rare exceptions which he can't
>predict in advance.

To add to that explanation: this is in a multithreaded ZODB-application.
When an unexpected exception occurs and remains uncaught, a thread
terminates, causing the thread pool to wait forever since some thread is
not consuming its termination request from the queue, causing the app to
not terminate, causing the ZODB to remain locked, causing other apps to
fail, causing havoc on my server.

I don't mind this when it's caused by a bug in my code, since that creates
the sense of urgency required to fix the bug. But it's annoying when it
happens because of an I/O exception caused by some other guys bug on the
other side of the planet :-)

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to except the unexpected?

2006-03-04 Thread Rene Pijlman
Roy Smith:
>In theory, all exceptions which represent problems with the external 
>environment (rather than programming mistakes) should derive from 
>Exception, but not from StandardError.

Are you sure?

"""
The class hierarchy for built-in exceptions is:

Exception
 +-- StandardError
 |+-- KeyboardInterrupt
 |+-- ImportError
 |+-- EnvironmentError
 ||+-- IOError
"""
http://www.python.org/doc/current/lib/module-exceptions.html

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to except the unexpected?

2006-03-04 Thread Rene Pijlman
Jorge Godoy:
>Rene Pijlman:
>> my app was surprised by an
>> httplib.InvalidURL since I hadn't noticed this could be raised by
>> robotparser (this is undocumented).
>
>It isn't undocumented in my module.  From 'pydoc httplib':

That's cheating: pydoc is reading the source :-)

What I meant was, I'm calling robotparser, and there's no mention of
exceptions on http://docs.python.org/lib/module-robotparser.html

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to except the unexpected?

2006-03-04 Thread Rene Pijlman
Steven D'Aprano:
>ExpectedErrors = (URLError, IOError)
>ErrorsThatCantHappen =
>
>try:
>process_things()
>except ExpectedErrors:
>recover_from_error_gracefully()
>except ErrorsThatCantHappen:
>print "Congratulations! You have found a program bug!"
>print "For a $327.68 reward, please send the following " \
>"traceback to Professor Donald Knuth."
>raise
>except:
>print "An unexpected error occurred."
>print "This probably means the Internet is broken."
>print "If the bug still occurs after fixing the Internet, " \
>"it may be a program bug."
>log_error()
>sys.exit()

Yes, I think I'll do something like this. Perhaps combined with Peter's
advice to not micromanage, like so:

Reraise = (LookupError, ArithmeticError, AssertionError) # And then some

try:
process_things()
except Reraise:
raise
except:
log_error()

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to except the unexpected?

2006-03-04 Thread Rene Pijlman
Paul Rubin :
>We have to get Knuth using Python.

Perhaps a MIX emulator and running TeXDoctest on his books will convince
him..

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to except the unexpected?

2006-03-04 Thread Rene Pijlman
Peter Hansen:
>Good code should probably have a very small set of real exception 
>handling cases, and one or two catchalls at a higher level to avoid 
>barfing a traceback at the user.

Good point.

>> A catchall seems like a bad idea, since it also catches AttributeErrors
>> and other bugs in the program.
>
>Generally speaking this won't be a problem if you have your catchalls at 
>a fairly high level and have proper unit tests for the lower level code 
>which is getting called.  You are doing unit testing, aren't you? ;-)

With low coverage, yes. But unit testing isn't the answer for this
particular problem. For example, yesterday my app was surprised by an
httplib.InvalidURL since I hadn't noticed this could be raised by
robotparser (this is undocumented). If that fact goes unnoticed when
writing the exception handling, it will also go unnoticed when designing
test cases. I probably wouldn't have thought of writing a test case with a
first url with some external domain (that triggers robots.txt-fetching)
that's deemed invalid by httplib.

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to except the unexpected?

2006-03-04 Thread Rene Pijlman
James Stroud:
>Which suggests that "try: except HTTPException:" will be specific enough 
>as a catchall for this module.
>
>The following, then, should catch everything you mentioned except the 
>socket timeout:

Your conclusion may be (almost) right in this case. I just don't like this
approach. Basically this is reverse engineering the interface from the
source at the time of writing the app. Even if you get it right, it may
fail next week when someone added an exception to a module.

>But it seems to me that working with the internet as you are doing is 
>fraught with peril anyway.

Why? It shouldn't be.

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to except the unexpected?

2006-03-04 Thread Rene Pijlman
Roy Smith:
>I like to create a top-level exception class to encompass all the 
>possible errors in a given module, then subclass that.  This way, if you 
>want to catch anything to goes wrong in a call, you can catch the top-level 
>exception class without having to enumerate them all.

What do you propose to do with exceptions from modules called by the given
module?

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


How to except the unexpected?

2006-03-03 Thread Rene Pijlman
One of the things I dislike about Java is the need to declare exceptions
as part of an interface or class definition. But perhaps Java got this
right...

I've writen an application that uses urllib2, urlparse, robotparser and
some other modules in the battery pack. One day my app failed with an
urllib2.HTTPError. So I catch that. But then I get a urllib2.URLError, so
I catch that too. The next day, it encounters a urllib2.HTTPError, then a
IOError, a socket.timeout, httplib.InvalidURL,...

How do you program robustly with these modules throwing all those
different (and sometimes undocumented) exceptions at you?

A catchall seems like a bad idea, since it also catches AttributeErrors
and other bugs in the program.

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: socket freezes

2006-03-03 Thread Rene Pijlman
Luis P. Mendes:
>I've developed a program that uses a socket to receive information 24h a
>~ day.
>
>The problem is that the socket seems to freeze.  By that I mean the
>program stops getting information but doesn't raise any error.

That's weird. There's probably a bug in your program.

>I tried to solve this by writing the following functions, in order to
>try to start the socket connection again:

So now you have two problems. When there's a bug in your program, it's
usually best to hunt it down, rather than to add more code with more bugs
:-)

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sockets, where can I find documentation?

2006-03-03 Thread Rene Pijlman
John Pote:
>I want to use python on a server to access incoming TCP port accesses. So I 
>need to use the socket interface which is new to me. 

You may also want to look at Twisted:
http://twistedmatrix.com/trac/

>Where can I get the various papers mentioned in the manual? And as I like 
>books sitting on the shelf can someone recommend a book on sockets.

Stevens++

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Threading - will threads run in parallel?

2006-02-28 Thread Rene Pijlman
SolaFide:
>(get() is a function which waits for a ping on a specific port, thus
>stopping the program for a while.)
>
>Will these run together, 

Thread 2 can run while thread 1 is blocked for I/O and v.v.

>Also, is it possible to split off a program for the terminal that
>started it? As in I type in python test.py and test.py runs in the
>background and lets me do other things in that terminal?

Platform? Shell?

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ImportError in Unpickle

2006-02-26 Thread Rene Pijlman
Rene Pijlman:
>[EMAIL PROTECTED]:
>>ImportError: No module named __main__
>
>There are some posts in the Usenet archive

Also:
http://mail.python.org/pipermail/python-list/1999-April/000916.html

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ImportError in Unpickle

2006-02-26 Thread Rene Pijlman
[EMAIL PROTECTED]:
>I have a python script that pickles and unpickles a give object. It
>works without any problems on windows (the data was pickled on windows
>first). But when I try to run the script on Linux, I get the following
>error:
[...]
>ImportError: No module named __main__

There are some posts in the Usenet archive that suggest you need to open
the pickled file in binary mode.
http://groups.google.nl/group/comp.lang.python/browse_frm/thread/2da0dcfc0a414251/0885a7a5723f3b03

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [ANN] httpy 0.9.0 -- a sane and robust HTTP library for Python

2006-02-24 Thread Rene Pijlman
Chad Whitacre:
>I am pleased to announce the first public release of httpy -- a sane and 
>robust HTTP library for Python. With httpy, you write "responders," and 
>put them on the network with "couplers." Here is a trivial responder:
>
>   import httpy
>
>   class Responder:
> def respond(request):
>   raise httpy.Response(200, "Greetings, program!")
>
>
>And here is how to couple it:
>
>   responder = Responder()
>   coupler = httpy.couplers.StandAlone(responder)
>   coupler.go()
>
>httpy is so amazing, in fact, that with it I was able to write an entire 
>wiki in only 20 seconds!

Now that's what I call a short learning curve. So can this replace Zope
then? Or mod_python? Apache? CGI? All of those?

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A C-like if statement

2006-02-24 Thread Rene Pijlman
Roy Smith:
>How do you do any I/O in a functional language if side effects are 
>verboten?  

The user is a function. Output is its parameter, input its return value.
The user is not allowed to maintain state ;-)

>For that matter, how does a functional program ever stop running?

By returning to the caller.

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >