Re: Newbie regular expression and whitespace question

2005-09-22 Thread Fredrik Lundh
Paul McGuire wrote:

> If you're absolutely stuck on using RE's, then others will have to step
> forward.  Meanwhile, here's a pyparsing solution (get pyparsing at
> http://pyparsing.sourceforge.net):

so, let's see.  using ...

from pyparsing import *
import re

data = """ ... table example from op ... """

def test1():
LT = Literal("<")
GT = Literal(">")
collapsableSpace = GT + LT
collapsableSpace.setParseAction( replaceWith("><") )
return collapsableSpace.transformString(data)

def test2():
return re.sub(">\s+<", "><", data)

I get

> timeit -s "import test" "test.test1()"
100 loops, best of 3: 6.8 msec per loop

> timeit -s "import test" "test.test2()"
1 loops, best of 3: 33.3 usec per loop

or in other words, five lines instead of one, and a 200x slowdown.

but alright, maybe we should precompile the expressions to get a
fair comparision.  adding

LT = Literal("<")
GT = Literal(">")
collapsableSpace = GT + LT
collapsableSpace.setParseAction( replaceWith("><") )

def test3():
return collapsableSpace.transformString(data)

p = re.compile(">\s+<")

def test4():
return p.sub("><", data)

to the first program, I get

> timeit -s "import test" "test.test3()"
100 loops, best of 3: 6.73 msec per loop

> timeit -s "import test" "test.test4()"
1 loops, best of 3: 27.8 usec per loop

that's a 240x slowdown.  hmm.

 



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


Re: Help on regular expression match

2005-09-22 Thread Fredrik Lundh
Johnny Lee wrote:

>   I've met a problem in match a regular expression in python. Hope
> any of you could help me. Here are the details:
>
>   I have many tags like this:
>  xxxhttp://xxx.xxx.xxx"; xxx>xxx
>  xx
>  xxxhttp://xxx.xxx.xxx"; xxx>xxx
>  .
>   And I want to find all the "http://xxx.xxx.xxx"; out, so I do it
> like this:
>  httpPat = re.compile("(http://.*)(\")")
>  result = httpPat.findall(data)
>   I use this to observe my output:
>  for i in result:
> print i[2]
>   Surprisingly I will get some output like this:
>  http://xxx.xxx.xxx";>xx
>   In fact it's filtered from this kind of source:
>  http://xxx.xxx.xxx";>xx"
>   But some result are right, I wonder how can I get the all the
> answers clean like "http://xxx.xxx.xxx";? Thanks for your help.

".*" gives the longest possible match (you can think of it as searching back-
wards from the right end).  if you want to search for "everything until a given
character", searching for "[^x]*x" is often a better choice than ".*x".

in this case, I suggest using something like

print re.findall("href=\"([^\"]+)\"", text)

or, if you're going to parse HTML pages from many different sources, a
real parser:

from HTMLParser import HTMLParser

class MyHTMLParser(HTMLParser):

def handle_starttag(self, tag, attrs):
if tag == "a":
for key, value in attrs:
if key == "href":
print value

p = MyHTMLParser()
p.feed(text)
p.close()

see:

http://docs.python.org/lib/module-HTMLParser.html
http://docs.python.org/lib/htmlparser-example.html
http://www.rexx.com/~dkuhlman/quixote_htmlscraping.html

 



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


Re: C#3.0 and lambdas

2005-09-23 Thread Fredrik Lundh
Reinhold Birkenfeld wrote:

>> And I think the discussion that followed proved your point perfectly
>> Fredrik. Big discussion over fairly minor things, but no "big picture".
>>  Where are the initiatives on the "big stuff" (common documentation
>> format, improved build system, improved web modules, reworking the
>> standard library to mention a few)  Hey, even Ruby is passing us here.
>
> This is Open Source. If you want an initiative, start one.

you know, this "you have opinions? fuck off!" attitude isn't really helping.

 



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


Re: Using distutils 2.4 for python 2.3

2005-09-23 Thread Fredrik Lundh
Noam Raphael wrote:

> I want to distribute a package. It's compatible with Python 2.3.
> Is there a way to use distutils 2.4 feature package_data, while
> maintaining the distribution compatible with python 2.3 ?

you can enable new metadata fields in older versions by assigning to
the DistributionMetadata structure:

try:
from distutils.dist import DistributionMetadata
DistributionMetadata.package_data = None
except:
pass

setup(
...
package_data=...
)

 



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


Re: Single type for __builtins__ in Py3.0

2005-09-23 Thread Fredrik Lundh
Collin Winter wrote:

> As it currently stands, the type of the global __builtins__ differs
> depending on whether you're in the __main__ namespace (__builtins__ is
> a module) or not (its a dict). I was recently tripped up by this
> discrepancy, and googling the issue brings up half-a-dozen or so c.l.p
> threads where others have been bitten by this, too.

__builtins__ is a CPython implementation detail.  why not just let it
be an implementation detail, and refrain from using it?  it's not that
hard, really.





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


Re: batch mkdir using a file list

2005-09-23 Thread Fredrik Lundh
DataSmash <[EMAIL PROTECTED]> wrote

> I think I've tried everything now and can't figure out how to do it.
> I want to read in a text list from the current directory,
> and for each line in the list, make a system directory for that name.
>
> My text file would look something like this:
> 1144
> 1145
> 1146
> 1147
>
> I simply want to create these 4 directories.
> It seems like something like the following
> code should work, but it doesn't.
>
> import os
>
> file = open("list.txt", "r")
> read = file.read()
> print "Creating directory " + str(read)
> os.mkdir(str(read))

read() returns *all* text in the file as a single string, but you
really want to process each line for itself.  try this:

for name in open("list.txt"):
name = name.strip() # get rid of extra whitespace
os.mkdir(name)

 



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


Re: Most direct way to strip unoprintable characters out of a string?

2005-09-25 Thread Fredrik Lundh
George Sakkis wrote:

> No there's not a stripUnprintable in a standard module AFAIK, and
> that's a good thing; if every little function that one might ever wanted
> made it to the standard library, the language would be overwhelming.

...and if there was a stripUnprintable function in the standard library that
was based on C's mostly brain-dead locale model, US programmers
would produce even more web applications that just don't work for non-
US users...

("sanitizing" HTML data by running filters over encoded 8-bit data is hardly
ever the right thing to do...)

 



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


Re: Extending Embedded Python

2005-09-25 Thread Fredrik Lundh
Richard Townsend wrote:

> In the "Extending and Embedding" part of the Python documentation: section
> 5.4 "Extending Embedded Python" - it describes how to use a Python
> extension module from Python that is embedded in a C application.
>
> Is it safe to call Py_InitModule() more than once in the same application -
> in order to be able to use more than one extension module?

yes.

 



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


Re: cElementTree clear semantics

2005-09-25 Thread Fredrik Lundh
Igor V. Rafienko wrote:

> Finally, I thought about keeping track of when to clear and when not
> to by subscribing to start and end elements (so that I would collect
> the entire -subtree in memory and only than release it):
>
> from cElementTree import iterparse
> clear_flag = True
> for event, elem in iterparse("data.xml", ("start", "end")):
> if event == "start" and elem.tag == "schnappi":
> # start collecting elements
> clear_flag = False
> if event == "end" and elem.tag == "schnappi":
> clear_flag = True
> # do something with elem
> # unless we are collecting elements, clear()
> if clear_flag:
> elem.clear()
>
> This gave me the desired behaviour, but:
>
> * It looks *very* ugly
> * It's twice as slow as version which sees 'end'-events only.
>
> Now, there *has* to be a better way. What am I missing?

the iterparse/clear approach works best if your XML file has a
record-like structure.  if you have toplevel records with lots of
schnappi records in them, iterate over the records and use find
(etc) to locate the subrecords you're interested in:

for event, elem in iterparse("data.xml"):
if event.tag == "record":
# deal with schnappi subrecords
for schappi in elem.findall(".//schnappi"):
process(schnappi)
elem.clear()

the collect flag approach isn't that bad ("twice as slow" doesn't
really say much: "raw" cElementTree is extremely fast compared
to the Python interpreter, so everything you end up doing in
Python will slow things down quite a bit).

to make your application code look a bit less convoluted, put the
logic in a generator function:

# in library
def process(filename, annoying_animal):
clear = True
start = "start"; end = "end"
for event, elem in iterparse(filename, (start, end)):
if elem.tag == annoying_animal:
if event is start:
clear = False
else:
yield elem
clear = True
if clear:
elem.clear()

# in application
for subelem in process(filename, "schnappi"):
 # do something with subelem

(I've reorganized the code a bit to cut down on the operations.
also note the "is" trick; iterparse returns the event strings you
pass in, so comparing on object identities is safe)

an alternative is to use the lower-level XMLParser class (which
is similar to SAX, but faster), but that will most likely result in
more and tricker Python code...





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


Re: Reinhold Birkenfeld [Re: "Re: cElementTree clear semantics"]

2005-09-25 Thread Fredrik Lundh
Doug Holton wrote:

> You're the only one making any association between this thread about
> celementree and boo.

really?  judging from the Original-From header in your posts, your internet
provider is sure making the same association...





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


Re: subprocess considered harmfull?

2005-09-25 Thread Fredrik Lundh
Steven Bethard wrote:

> >  Using the following snippet:
> >   p =
> > subprocess.Popen(nmake,stderr=subprocess.PIPE,stdout=subprocess.PIPE, \
> >universal_newlines=True, bufsize=1)
> >   os.sys.stdout.writelines(p.stdout)
> >   os.sys.stdout.writelines(p.stderr)
> >  Works fine on the command line, but fails when called from within
> > Visual Studio, with the following error:
> >   File "C:\Python24\lib\subprocess.py", line 549, in __init__
> > (p2cread, p2cwrite,
> >   File "C:\Python24\lib\subprocess.py", line 609, in _get_handles
> > p2cread = self._make_inheritable(p2cread)
> >   File "C:\Python24\lib\subprocess.py", line 650, in _make_inheritable
> > DUPLICATE_SAME_ACCESS)
> > TypeError: an integer is required
>
> This looks like these known bugs:
>  http://python.org/sf/1124861
>  http://python.org/sf/1126208
>
> Try setting stderr to subprocess.PIPE.  I think that was what worked for
> me.  (You might also try setting shell=True.  That's what I currently
> have in my code that didn't work before.)

if someone wants to investigate, is seeing this problem, and have the win32
extensions on their machine, try changing this line in subprocess.py:

if 0: # <-- change this to use pywin32 instead of the _subprocess driver

to:

if 1: # <-- change this to use _subprocess instead of the pywin32 driver

and see if it either fixes the problem (not very likely) or gives you a better
error message (very likely).





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


Re: cElementTree clear semantics

2005-09-25 Thread Fredrik Lundh
Igor V. Rafienko wrote:

> The problem is that the file looks like this:
>
> 
... lots of schnappi records ...

okay.  I think your first approach

from cElementTree import iterparse

for event, elem in iterparse("data.xml"):
if elem.tag == "schnappi":
count += 1
elem.clear()

is the right one for this case.  with this code, the clear call will
destroy each schnappi record when you're done with it, so you
will release all memory allocated for the schnappi elements.

however, you will end up with a single toplevel element that
contains a large number of empty subelements.  this is usually
no problem (it'll use a couple of megabytes), but you can get
rid of the dead schnappis too, if you want to.  see the example
that starts with "context = iterparse" on this page

http://effbot.org/zone/element-iterparse.htm

for more information.





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


Re: cElementTree clear semantics

2005-09-25 Thread Fredrik Lundh
Paul Boddie wrote:

> Regardless of anyone's alleged connection with Boo or newsgroup
> participation level, the advice to contact the package
> author/maintainer is sound. It happens every now and again that people
> post questions to comp.lang.python about fairly specific issues or
> packages that would be best sent to mailing lists or other resources
> devoted to such topics. It's far better to get a high quality opinion
> from a small group of people than a lower quality opinion from a larger
> group or a delayed response from the maintainer because he/she doesn't
> happen to be spending time sifting through flame wars amidst large
> volumes of relatively uninteresting/irrelevant messages.

well, for the record, I strongly recommend people to post questions in
public forums.  google is far more likely to pick up answers from mailing
list archives and newsgroups than from the "I really should do something
about all the mails in my support folder" part of my brain.

it's often a good idea to spend a little time looking for the right forum
(the xml-sig is a good place for elementtree-related questions), but
posting a question about a widely used Python library to c.l.python is
never wrong.





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


Re: cannot write to file after close()

2005-09-25 Thread Fredrik Lundh
Rainer Hubovsky wrote:

> Thank you Reinhold, that was the solution. But just because I am curious:
> what is this statement without the parentheses? After all it is a valid
> statement...

it's an expression that fetches the "close" method object, and throws
it away.  to see what it evaluates to, try running the code from the
interactive prompt (or add a print statement):

>>> f = open("foo", "w")
>>> f.close


also see

http://docs.python.org/ref/exprstmts.html
http://docs.python.org/ref/attribute-references.html





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


Re: number of python users

2005-09-26 Thread Fredrik Lundh
Bryan wrote:
> is there a rough estimate somewhere that shows currently how many python 1.5 
> vs
> 2.2 vs 2.3 vs 2.4 users there are?  have a majority moved to 2.4? or are they
> still using 2.3? etc...

Here are current PIL download statistics (last 10 days):

75.6% /downloads/PIL-1.1.5.win32-py2.4.exe
18.0% /downloads/PIL-1.1.5.win32-py2.3.exe
 2.2%  /downloads/PIL-1.1.5.win32-py2.2.exe
 4.2%  /downloads/PIL-1.1.5.win32-py2.1.exe

Note that these are fresh downloads for Windows, not users.  People
who run other systems, or are happy with their existing installation,
isn't included (so older versions are probably more common than they
appear).

(fwiw, I still have users on 1.5.2 for most of my libraries.  usually huge
Unix systems that nobody wants to break just because they can...)





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


Re: Need to pass Object by value into a list

2005-09-26 Thread Fredrik Lundh
Aaron wrote:

> I have a data sructure setup and I populate it in a loop like so:
>
> y=0
> while X:
>DS.name = "ASDF"
>DS.ID = 1234
>
>list[y] = DS;
>y = y + 1
>
> print list
>
> This does not work because DS is passed in by reference causing all
> entries into the list to change to the most current value.  I cannot
> find a "new" function in Python like there is in C++.  How do you do
> this in Python?

I assume DS is a class?

to create an instance of a class, call the class object:

L = []

while X:
ds = DS()
ds.name = "ASDF"
ds.id = 1234
L.append(ds)

spending some time with the tutorial might help:

http://docs.python.org/tut/tut.html

(lists are described in chapter 3, classes in chapter 9)





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


Re: Plotting points to screen

2005-09-26 Thread Fredrik Lundh
Jason wrote:

> Like I said, it's nothing complicated, no flashing wotsits or 3d
> quad-linear vertexes with bi-linear real-time shading, just simple
> 'points' a few lines or circles and nothing more.

all UI toolkits can do that.  just pick one, and read up on the
graphics API.  for Tkinter, you can use the Canvas widget or
the WCK:

http://effbot.org/zone/wck-3.htm

or a pixel canvas, or perhaps WCK+AGG:

http://effbot.org/zone/wck-pixelcanvas.htm
http://effbot.org/zone/draw-agg.htm

etc.  more links:

http://piddle.sourceforge.net/
http://www.wxpython.org/
http://matplotlib.sourceforge.net/
http://www.riverbankcomputing.co.uk/pyqt/index.php

 



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


Re: Plotting points to screen

2005-09-26 Thread Fredrik Lundh
Jay wrote:

> One question, that's twice in as many days that someone has said "YMMV".
>
> What's it mean!?

http://www.google.com/search?q=acronym+ymmv 



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


Re: A 'find' utility that continues through zipped directory structure?

2005-09-27 Thread Fredrik Lundh
"B Mahoney" wrote:

> Is there a Python 'find' -like utility that will continue the file
> search through any zippped directory structure on the find path?

something like this?

# File: zipfind.py
import fnmatch, os, sys, zipfile

program, root, name = sys.argv

for dirpath, dirnames, filenames in os.walk(root):
for file in fnmatch.filter(filenames, name):
print os.path.join(dirpath, file)
for file in fnmatch.filter(filenames, "*.zip"):
try:
zip = zipfile.ZipFile(os.path.join(dirpath, file))
except zipfile.BadZipfile:
pass # cannot read this file
else:
for f in fnmatch.filter(zip.namelist(), name):
print os.path.join(dirpath, file) + ":" + f

$ python zipfind.py aggdraw "README*"
aggdraw/README
aggdraw/agg2/README.txt
aggdraw/dist/aggdraw-1.1b3-20050925.zip:aggdraw-1.1b3-20050925/README.txt

 



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


Re: number of python users

2005-09-27 Thread Fredrik Lundh
Bryan wrote:

> just for fun, i looked at the top linux distros at distrowatch and looked at
> what version of python the latest released version is shipping with out of 
> the box:
>
> 1. ubuntu hoary - python 2.4.1
> 2. mandriva 2005 - python 2.4
> 3. suse 9.3 - python 2.4
> 4. fedora core 4 - python 2.4.1
> 5. mepis 3.3.1 - python 2.3.5
> 6. knoppix 4.0.2  - python 2.3.5
> 7. debian sarge - python 2.3.5
> 8. gentoo 2005.1 - python 2.3.5
> 9. slackware 10.2 - python 2.4.1
> 10.kubuntu hoary - python 2.4.1
> 11. freebsd 5.4 - python 2.4
> 12. xandros 3.0 - python 2.3.4
> 13. pclinuxos 0.91 - python 2.3.4

no RHEL?  (are they still stuck on 2.2, btw?)

 



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


Re: Memory stats

2005-09-27 Thread Fredrik Lundh
Tarek Ziadé wrote:

> > If you want a list of all objects (container or not), you have to
> > compile a debug build of Python.
>
> I am amazed not to find an existing implementation for this.

the debug build is an existing implementation, of course.

 



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

Re: What tools are used to write and generate Python Librarydocumentation.

2005-09-27 Thread Fredrik Lundh
Kenneth McDonald wrote:

> More seriously, there is a major problem with docstrings in that they
> can only document something that has a docstring; classes, functions,
> methods, and modules. But what if I have constants that are
> important? The only place to document them is in the module
> docstring, and everything else--examples, concepts, and so on--must
> be thrown in there as well. But there are no agreed on formats and
> processing pipelines that then allow such a large module docstring,
> plus other docstrings, to produce a good final document.

fwiw, that's one of reason why I developed PythonDoc (which supports
JavaDoc-style documentation for all the usual suspects, but also for con-
stants, attributes, and variables)

> It's too bad that there is no equivalent of d'oxygen for Python. That
> is a _nice_ program.

doesn't doxygen support Python?

 



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


Re: How can I set the size of a window with tkinter?

2005-09-27 Thread Fredrik Lundh
Tor Erik Sønvisen wrote:

> I create a canvas that is to big for the default window-size, so it gets cut 
> to fit...

what default window size?  what geometry management approach are
you using?

(if you're using pack or grid, your toplevel window should adapt itself
to the canvas size, unless you're using an obnoxious window manager.
if you do, Tkinter may not be able to do much about that...)

 



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

Re: Silly function call lookup stuff?

2005-09-27 Thread Fredrik Lundh
Lucas Lemmens wrote:

> Why isn't the result of the first function-lookup cached so that following
> function calls don't need to do the function-lookup at all?
>
> And if the context changes (an import-statement say) reset the
> cached 'function-lookups'.

import isn't the only way for the "context" to change.  how many
other ways can you think of ?

> This way any function would only need to be looked up once.

you haven't really thought this over, have you?

 



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


Re: __call__ in module?

2005-09-27 Thread Fredrik Lundh
"ncf" wrote.

>I have a feeling that this is highly unlikely, but does anyone in here
> know if it's possible to directly call a module

no.

 



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


Re: What tools are used to write and generate PythonLibrarydocumentation.

2005-09-27 Thread Fredrik Lundh
Robert Kern wrote:

> The one thing I dislike about PythonDoc is that it puts everything into
> comments and thus docstrings are usually neglected.

teaser:

>>> from elementtree import ElementTree
>>> help(ElementTree)
Help on module ElementTree:

NAME
ElementTree

DESCRIPTION
# ElementTree
# $Id: ElementTree.py 2324 2005-03-16 15:49:27Z fredrik $
#
# light-weight XML support for Python 1.5.2 and later.
...

CLASSES
Element
ElementTree
QName
TreeBuilder
XMLParser
iterparse

class Element
 |  Methods defined here:
 |
 |  __delitem__(self, index)
 |
 |  __delslice__(self, start, stop)
 |
 |  __getitem__(self, index)
 |
 |  __getslice__(self, start, stop)
 ...

>>> import pythondoc
>>> help(ElementTree)
Help on module ElementTree:

NAME
ElementTree

DESCRIPTION
The Element type is a flexible container object, designed to
store hierarchical data structures in memory.

CLASSES
Element
ElementTree
QName
TreeBuilder
XMLParser
iterparse

class Element
 |  Element class.
 |
 |  Methods defined here:
 |
 |  __delitem__(self, index)
 |  Deletes the given subelement.
 |
 |  __delslice__(self, start, stop)
 |  Deletes a number of subelements.
 |
 |  __getitem__(self, index)
 |  Returns the given subelement.
 |
 |  __getslice__(self, start, stop)
 |  Returns a list containing subelements in the given range.
 ...

now, if I could only motivate myself to write a PEP on adding a __help__
hook to pydoc, so that the "help" command can be taught to do this all by
itself...

 



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


Re: Silly function call lookup stuff?

2005-09-27 Thread Fredrik Lundh
Lucas Lemmens wrote:

>>> This way any function would only need to be looked up once.
>>
>> you haven't really thought this over, have you?
>
> You haven't really answered my questions have you?

no, because you proposed a major change to the Python semantics,
without spending any effort whatsoever researching how things work,
thinking about the consequences, or studying existing code to see how
it would be affected.  next time, you can at least do a little homework
before suggesting that a dynamically typed language should no longer
be dynamic.

 



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


Re: Overhead of individual python apps

2005-09-27 Thread Fredrik Lundh
Paul Rubin wrote:

>> Several apps using 4Mb each shouldn't be very much memory (maybe
>> 20Mb at most).  You didn't say how much memory was in your machine,
>> but 256Mb of memory will cost you no more than $50.  Not really
>> worth a lot of effort.
>
> That is bogus reasoning.

not if you're a professional software developer and someone's paying you
to develop an application that is to be run on a platform that they control.

people are expensive, but hardware is extremely cheap these days.

 



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


Re: Python 2.4 under WinXP, free VC71 toolkit and VC6 libraries

2005-09-28 Thread Fredrik Lundh
Berthold Höllmann wrote:

> OK, then. ctypes works under Linux and Solaris. But before I even
> think about converting my code to ctypes (and convert lots of Linux
> libraries from static to dynamic libraries), would the conversion
> really address my problem? As I understand it, if there is an
> incompatibility between VC6 and VC7 compiled libraries the issue comes
> turns up with ctypes as well as with my current extension modules?

this thread is getting more and more bizarre.  are you seeing VC6/VC7 com-
patibility issues on Linux and Solaris?

(to answer your original question, you can often link VC7 code against a
VC6 library, but not always; some C features are implemented as macros
that depend on internal struct layouts, and inlined code sometimes depend
on the exact semantics of support functions in the C runtime libraries, etc.
You can get the same kind of problems if you're mixing /M different options
under the same compiler.  And no, ctypes won't recompile your libraries
for you, so those issues are still there.  Since VC7 is the current offering
from Microsoft, you should ask for an up-to-date version from your library
provider. If they cannot provide a version for the current Microsoft com-
piler, you may have to stay with Python 2.3 for the time being...)

 



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

Re: Overhead of individual python apps

2005-09-28 Thread Fredrik Lundh
Paul Rubin wrote:

> An awful lot of Python targeted users are not in that situation, so if
> Python's usability suffers for them when it doesn't have to, then
> something is wrong with Python.

(and so we go from the OP:s "I'm setting up a system" to the usual c.l.python 
"but
I can come up with another example" crap...)

But back to the "memory measurements" and your claim that "something is wrong
with Python [if the task manager shows large numbers]"...

Have you looked at a task manager on a lightly loaded W2K or WXP system lately?
On this PC, I currently have a couple of browser windows open, a newsreader, and
a few other programs.  The only real app I have that uses less than 4 megabytes
*according to the task manager* is a 2.5 megabyte putty terminal window; most
apps are in the 15-50 megabyte range.

Even a trivial operation, like opening another Firefox tab, can make that 
process
grow by more than 4 megabytes, and if you browse around a little, you can easily
end up with 30-50 megabytes in "mem usage" -- until you minimize the browser,
and find that Firefox only uses 1.5 megabytes. Maximize it again, and it uses 12
megabytes.

Play the same games with a Python interpreter, and you'll find that the task 
manager
may report anything from just over 50 kilobytes to just under 5 megabytes.

Here's a random google link that discusses the task manager figures in a little 
more
detail:

http://www.itwriting.com/dotnetmem.php

"Newcomer to .NET says: I've just been looking at Task Manager. Why
does my simple VB.NET Windows application use 12MB RAM?"

"Don't worry. The app doesn't really use that much RAM."

(for python, the "private" memory use is usually ~1.5 megabytes for a "empty" 
2.4
process, and some of that will only occupy space in the paging file...  for 
firefox with
a simple page loaded into a single tab, the private space is ~10 megabytes)

 



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


Re: Will python never intend to support private, protected and public?

2005-09-28 Thread Fredrik Lundh
Tony Meyer wrote:

>> I thought about it, but I didn't mention it in the end because this
>> feature ("name mangling") isn't intended as a mechanism for making
>> things private - it's intended to prevent namespace clashes when doing
>> multiple inheritance.
>
> That's not what the documentation says:
>
> """
> 9.6 Private Variables
>
> There is limited support for class-private identifiers.
> [...]
> Name mangling is intended to give classes an easy way to define
> ``private'' instance variables and methods,
> [...]
> """
>
> 

the sentence you're quoting the first part of continues:

without having to worry about instance variables defined by derived
classes

and the paragraph later says:

Note that the mangling rules are designed mostly to avoid accidents

and both sentences are from the *tutorial*, which doesn't exactly
qualify as a design document.  if you want more rationale, here's the
post that led to the current design:

http://groups.google.com/group/comp.lang.python/msg/e79f875059d9a2ba

"In my version, private data has it's own scope, so that name clashes
will not occur if a private with the same name is used in a subclass."

see the rest of that thread for more about the history of __.

 



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


Re: Wits end with Python and cron

2005-09-28 Thread Fredrik Lundh
Justin Delvecchio wrote:

> I've researched this problem for the last few days.  Say I have
> the following script that I execute from cron on linux.  Yes, the
> following runs quite fine from the command line:

> And the error I continually get is:
>
> Traceback (most recent call last):
>   File "/home/oracle/rods_dbf_file/map_unix.py", line 29, in ?
> import cx_Oracle
> ImportError: libclntsh.so.10.1: cannot open shared object file:
> No such file or directory

> What is going on?  I've googled this thing to death and it seems like I've
> got two different solutions, PYTHONPATH and LD_LIBRARY_PATH,
> that should satisfy this.  /u01/app/oracle/product/10.1.0/Db_1/lib is where
> the lib resides.

have you read the cron documentation?  if you had done that, you would
perhaps have noticed that cron runs jobs with a rather minimal environment.

if you don't make sure to add the variables required by your program (in
this case, LD_LIBRARY_PATH), the cron job will fail. (this is true for any
program run under cron, not just Python programs).

if you're running a python program directly from cron, you can simply add
to the environment inside the Python program, before you start importing
stuff:

import os # make sure we can load the oracle libraries
os.environ["LD_LIBRARY_PATH"] = "/u01/app/oracle/..."

import cx_Oracle

other approaches include adding a small shell script that sets things up
properly before running the Python script (and running that shell script
from cron), and adding environment settings to the crontab file (see the
cron/crontab documentation for details).

 



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


Re: Wits end with Python and cron

2005-09-28 Thread Fredrik Lundh
I wrote:

> if you're running a python program directly from cron

and I should really learn to tell the difference between a shell script and
a python program (but hey, this is comp.lang.python).

see jepler's reply for the quickest way to fix your problems.

 



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


Re: Will python never intend to support private, protected and public?

2005-09-28 Thread Fredrik Lundh
Tony Meyer wrote:

> That elaborates on the intent, it doesn't change it.  The sentence
> clearly says that the intent is to easily define private variables,
> whereas Simon said that it the intent was not to provide a mechanism
> for making variables private.

Are you aware of the fact that computer terms might have slightly different
meanings in different languages, due to differences in language details and
semantics?  Of course they're "private variables", but they're "private" in the
Python sense, and they were added to Python to solve problems that were
observed in Python, not because someone thought it was important to cater
to confused C++ or Java programmers.

And as Simon said, and the original thread showed, the problem they were
(and are) intended to address is accidental namespace collisions when sub-
classing.

If we'd really needed "true" private variables, don't you think we would have
been able to come up with a design that provided that?  It just wasn't 
important,
because Python is Python.

 



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


Re: byte code generated under linux ==> bad magic number under

2005-09-28 Thread Fredrik Lundh
Shobha Rani wrote:

(I think more people might read your posts if you skip the HTML stuff;
if you insist on HTML, you could at least use a reasonable color)

> How byte code is generated? For example when we run the java
> program then the compiler generates the byte code?
> How the byte code is generated for the source code(java)?

the section "Compiled Python Files" in the tutorial explains this:

http://docs.python.org/tut/node8.html

byte code is portable between platforms, but it's not portable between
different major Python releases (2.4.2 can run 2.4.1 bytecodes, but not
2.3 bytecodes, etc).

 



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


Re: A quick c.l.p netiquette question

2005-09-29 Thread Fredrik Lundh
Peter Hansen wrote:

> Does it really have to be 158 lines to demonstrate these few issues?  I
> for one almost never take the time to dig through 158 lines of someone
> else's code, partly on the assumption that almost any interesting issue
> can be covered (using Python, specifically) in about a dozen lines of
> code.

did you click on the link he posted a little later?

> YMMV

no, YVFC.

 



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


Re: What python idioms for private, protected and public?

2005-09-29 Thread Fredrik Lundh
Michael Schneider wrote:

> 1) mark an object as dirty in a setter (anytime the object is changed,
> the dirty flag is set without requiring a user to set the dirty flag

properties.

> 2) enforce value constraints (even if just during debugging)

properties.  (when you no longer need to enforce things, switch back
to a plain attribute).

> 3) lazy init, don't bring the data in until needed

properties.

> 4) adding debug info

properties.

> 5)  more here

properties.

> It would be easy for me to say "Add public and private to python so I
> can code the way that I am used to".

huh?  what do "private" and "public" have to do with what you're describing?

> What are some python alternatives to achieve the design intents specified
> above above?

properties.

http://users.rcn.com/python/download/Descriptor.htm#properties

 



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


Re: Will python never intend to support private, protected and public?

2005-09-29 Thread Fredrik Lundh
Steve Holden wrote:

> To avoid naming conflicts, Python provides a mechanism (name mangling)
> which pretty much guarantees that your names won't conflict with anybody
> else's, *even if you subclass a class whose methods use the same name*.

as long as you don't cheat, that is:

# your code

class Secret:
def __init__(self):
self.__hidden = "very secret value"

# my code

from yourcode import Secret

class Secret(Secret):
def gethidden(self):
return self.__hidden

s = Secret()
print s.gethidden()

 



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


Re: Will python never intend to support private, protected and public?

2005-09-29 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> What if the access to that variable was forbidden for reasons you never
> foresaw? What if the class author decide to remove the variable in the next
> version of the class, because it's not an interface, but only a part of the
> class implementation?

you mean when he breaks into your computer and installs the new version
without you noticing?

if you think that once you've put private labels on all accidental stuff, 
nothing
will break during upgrades, you're clearly very new to this thing called pro-
gramming...

 



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


Re: A rather unpythonic way of doing things

2005-09-29 Thread Fredrik Lundh
"fraca7" wrote:

> print ''.join(map(lambda x: chrord(x) - ord('a')) + 13) % 26) + 
> ord('a')), 'yvfc'))

that's spelled

print "yvfc".decode("rot-13")

or, if you prefer,

print "yvfc".encode("rot-13")

, in contemporary python.

 



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


Re: Will python never intend to support private, protected and public?

2005-09-29 Thread Fredrik Lundh
could ildg wrote:

> Encapsulation or information hiding or whatever

You've got to be very careful if you don't know where you're looking
for, because you might not find it.

 



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


Re: Will python never intend to support private, protected and public?

2005-09-29 Thread Fredrik Lundh

>> Encapsulation or information hiding or whatever
>
> You've got to be very careful if you don't know where you're looking
> for, because you might not find it.

message.sub("where", "what") # argh! 



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


Re: grouping array

2005-09-29 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> hi if I have an array
>
> say x = [[2,2,0,0,1,1],
> [1,1,0,0,1,1],
> [1,1,0,0,1,1]]
> I basically want to group regions that are non zero like I want to get
> the coordinates of non zero regions..as (x1,y1,x2,y2)
> [(0,0,2,1),(0,4,2,5)] which show the top left(x1,y1) and bottom
> right(x2,y2) corners of each group.hope i am clear.

given your definitions, neither (0, 0, 2, 1) nor (0, 4, 2, 5) are clusters
in your data.  assuming that your description is wrong but your data is
correct, and your clusters are always this simple, here's a snippet that
does what I think you want:

x = [[2,2,0,0,1,1],
 [1,1,0,0,1,1],
 [1,1,0,0,1,1]]

# http://www.pythonware.com/products/pil/
import Image

h = len(x)
w = len(x[0])

data = []
for row in x:
data.extend(row)

im = Image.new("L", (w, h), None)
im.putdata(data)

def runlength(x):
out = []
u = 0
for i, v in enumerate(x):
if v:
if not u:
lo = i
elif u:
out.append((lo, i))
u = v
if u: out.append((lo, i+1))
return out

xx, yy = im.getprojection()

for y in runlength(yy):
y0, y1 = y
for x in runlength(xx):
x0, x1 = x
print (y0, x0, y1-1, x1-1)

 



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


Re: xml.sax removing newlines from attribute value?

2005-09-29 Thread Fredrik Lundh
Grant Edwards wrote:

> I'm using xml.sax to parse the "datebook" xml file generated by
> QTopiaDesktop.  When I look at the xml file, some of the
> attribute strings have newlines in them (as they are supposed
> to).
>
> However, when xml.sax passes the attributes to my
> startElement() method the newlines seem to have been deleted.
>
> How do I get the un-munged element attribute values?

newlines as in chr(10) rather than 
 ?

if so, the only way is to avoid XML:

http://www.w3.org/TR/REC-xml/#AVNormalize

if the "yes, I know, but I have good reasons" approach is okay with you,
and you're big enough to defend yourself against the XML-Is-The-Law
crowd, you can use a "sloppy" XML parsers such as sgmlop to deal with
your files:

http://effbot.org/zone/sgmlop-index.htm

 



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


Re: converting Word to MediaWiki

2005-09-29 Thread Fredrik Lundh
ChiTownBob wrote:

> does anyone know of a Python HTML - Wiki conversion
> program?

if your wiki markup isn't too complex, maybe you could adapt one
of the examples on this page:

http://effbot.org/librarybook/formatter.htm

 



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


Re: Will python never intend to support private, protected and public?

2005-09-29 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> Do you ever heard of that funny things named "an interface" and "an
> implementation"?

the "shared DLL:s ought to work" school of thought, you mean?

 



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


Re: xml.sax removing newlines from attribute value?

2005-09-29 Thread Fredrik Lundh
Grant Edwards wrote:

>> http://www.w3.org/TR/REC-xml/#AVNormalize
>
> I can't quite find it in the BNF, but I take it that chr(10)
> isn't really allowed in XML attribute strings.  IOW, the file
> generate by Trolltech's app is broken.

it's allowed, but the parser must not pass it on to the application.

(in other words, whitespace in attributes doesn't, in general, survive
roundtripping)

 



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


Re: python's performance

2005-09-29 Thread Fredrik Lundh
> > Have u been used such camera with PIL before?
> >
> > im_1= Image.fromstring("I", datasize, buf, 'raw', 'I;16')

running on a 700 MHz box:

c:\> timeit -s "import Image" -s "data = 1344*1024*2*'x'"
"im = Image.fromstring('I', (1344, 1024), data, 'raw', 'I;16')"
10 loops, best of 3: 102 msec per loop

running on a 3.0 GHz box:

c:\> timeit -s "import Image" -s "data = 1344*1024*2*'x'"
"im = Image.fromstring('I', (1344, 1024), data, 'raw', 'I;16')"
10 loops, best of 3: 34.7 msec per loop

I somehow doubt that this takes 1 full second on a 2.0 GHz PC.





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


Re: Feature Proposal: Sequence .join method

2005-09-29 Thread Fredrik Lundh
David Murmann wrote:

> I could not find out whether this has been proposed before (there are
> too many discussion on join as a sequence method with different
> semantics). So, i propose a generalized .join method on all sequences

so all you have to do now is to find the sequence base class, and
you're done...

 



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


Re: Will python never intend to support private, protected and public?

2005-09-29 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> Looks like you must know every one of the base classes of the NotSoSecret,
> whether there is some base class named Secret? And, if so, you must also
> know these classes _implementation_

that information isn't hidden, so there's nothing "you must know".  finding out
is a matter of writing a very small program, or tinkering at the interactive 
prompt
for a couple of seconds.  are you even aware that you're posting to a Python
group ?

 



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


Re: Will python never intend to support private, protected and public?

2005-09-29 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

>> > Do you ever heard of that funny things named "an interface" and "an
>> > implementation"?
>>
>> the "shared DLL:s ought to work" school of thought, you mean?
>
> No, the other way around: my app works when I upgrade libraries it depends
> on.

yeah, because it's only the visible interface that matters.  implementation 
semantics
don't exist.  you're clearly very new to this thing called programming...

 



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


Re: File Upload Script

2005-09-29 Thread Fredrik Lundh
"Chuck" wrote:

> Hi, can anyone provide or point me in the direction of a simple python
> file upload script?  I've got the HTML form part going but simply
> putting the file in a directory on the server is what I'm looking for.
> Any help would be greatly appreciated.

upload how?  WebDAV?  scp?  FTP?  if the latter, the third script
on this page is about as simple as things can get:

http://effbot.org/librarybook/ftplib.htm

 



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


Re: threads, periodically writing to a process

2005-09-29 Thread Fredrik Lundh
Adam Monsen wrote:

>I have a program that, when run, (1) does some task, then (2) prompts
> for input: "Press ENTER to continue...", then repeats for about ten
> different tasks that each take about 5 minutes to complete. There is no
> way to disable this prompt.
>
> How would I go about writing a Python program that would periodically
> (say, every 10 seconds or so) send a carriage return--"\r\n" (or
> whatever the ENTER key sends)--then exit when the subprocess is
> finished?

unless the program you're controlling is really odd, you might as well
send a whole bunch of newlines, and leave it to the other program to
read one at a time as it needs them.

to keep things really simple, you can just do:

import os

f = open("input.txt", "w")
f.write("\n" * 100)
f.close()

os.system("someprogram  



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


Re: Will python never intend to support private, protected and public?

2005-09-30 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> So you have read every line of the python std library, I guess?

yes, but that's irrelevant.  in python, you don't need the source to find hidden
stuff.  finding out is a matter of writing a very small program, or tinkering 
at the
interactive prompt for a couple of seconds.  are you even aware that you're
posting to a Python group ?

 



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


Re: Will python never intend to support private, protected and public?

2005-09-30 Thread Fredrik Lundh
Steve Holden wrote:

>> 1) Allow keywords like private (or implemetation) to mark certain
>> variables, functions or classes as an implementation detail.
>> Personnally I would prefer the opposite such as a interface
>> to mark objects which are not private, but that would break too
>> much code.

> Just an off-hand rejection.

fyi, an "access" mechanism was added in 1993, was only partially implemented,
was almost immediately deprecated, the supporting code were disabled in 1996,
and all traces were removed from the sources around 1997-89.

those who don't know history etc etc

 



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


Re: return (PyObject*)myPyType; ...segmentation fault!

2005-09-30 Thread Fredrik Lundh
"elho" <[EMAIL PROTECTED]> wrote:

> It is said that the object has a NULL-Pointer when I try to debug it?

what object?

> Here are the importent snips from my code:

where's the PySDLXMLNode code?  is the PySDLXMLNode constructor
really doing a proper PyObject initialization?  (PyObject subtypes are usually
allocated by Python's memory allocation layer, which does this for you).

 



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


Re: Soap Question (WSDL)

2005-09-30 Thread Fredrik Lundh
Armin wrote:

> I am trying to write a web app. that connects to flickr using SOAP. The
> book 'Dive into python' says I need to have a WSDL file to connect,
> while the only useful soap related url flickr api
> (flickr.com/services/api) provides is the following:
>
> The SOAP Server Endpoint URL is http://www.flickr.com/services/soap/
>
> What am I supposed to do here? Help is very much appreciated at this
> point.

any reason you cannot use one of the Python toolkits listed on this page ?

http://www.flickr.com/services/api/

(after all, if you find yourself stumbling on the first step, it might be better
to hitch a ride with someone else...)

 



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


Re: Font management under win32

2005-09-30 Thread Fredrik Lundh
Stefano Masini wrote:

> Do you think that is possible with win32 extensions?

you can do this via PIL's ImageFont module:

>>> import ImageFont
>>> f = ImageFont.truetype("arial.ttf")
>>> f.font.family
'Arial'
>>> f.font.style
'Regular'

or, if you don't want to ship the entire PIL library with your app, you
can grab the _imagingft module and use low-level functions:

>>> import _imagingft
>>> f = _imagingft.getfont("c:/windows/fonts/arial.ttf", 0)
>>> f.family
'Arial'
>>> f.style
'Regular'

 



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


Re: return (PyObject*)myPyType; ...segmentation fault!

2005-09-30 Thread Fredrik Lundh
"elho" wrote:

>> > It is said that the object has a NULL-Pointer when I try to debug it?
>> what object?
>   the python one  'myNewPyType'
>
> Sorry, I forgot to change:
>   PySDLXMLNodeType = PyMyType
> ..above the corrections

>self = new PyMyObject
>self->lAttribute = lAttribute;
>
>return (PyObject*)self;

unless you have some really clever C++ magic in there that I'm not seeing,
you cannot just use "new" plus a cast to get a valid Python object.

if you want to explicitly create an object, you can use PyObject_New:

http://www.python.org/doc/2.1.3/ext/dnt-basics.html

an alternative is to expose the type object, and leave the rest to Python:

http://www.python.org/doc/current/ext/dnt-basics.html

 



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


Re: 'ascii' codec can't encode character u'\u2013'

2005-09-30 Thread Fredrik Lundh
Thomas Armstrong wrote:

> I'm trying to parse a UTF-8 document with special characters like
> acute-accent vowels:
> 
> 
> ...
> ---
>
> But I get this error message:
> ---
> UnicodeEncodeError: 'ascii' codec can't encode character u'\u2013' in
> position 122: ordinal not in range(128)
> ---

> It works, but I don't want to substitute each special character, because there
> are always forgotten ones which can crack the program.

if you really want to use latin-1 in the database, and you don't mind dropping
unsupported characters, you can use

text_extrated = text_extrated.encode('iso-8859-1', 'replace')

or

text_extrated = text_extrated.encode('iso-8859-1', 'ignore')

a better approach is of course to convert your database to use UTF-8 and use

text_extrated = text_extrated.encode('utf-8')

it's also a good idea to switch to parameter substitution in your SQL queries:

cursor.execute ("update ... set text = %s where id = %s", text_extrated, id)

it's possible that your database layer can automatically encode unicode strings 
if
you pass them in as parameters; see the database API documentation for details.

 



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


Re: Overloading __init__ & Function overloading

2005-09-30 Thread Fredrik Lundh
"Iyer, Prasad C" wrote:

> a. Is there something like function overloading in python?

not in the usual sense, no.  function arguments are not typed, so there's 
nothing
to dispatch on.  there are several cute tricks you can use to add dispatching on
top of "raw" python, but that's nothing you should do unless you have very good
reasons.

> b. Can I overload __init__ method

not in the usual sense, no.  same reason as above.

also see:

http://www.python.org/doc/faq/programming.html#how-can-i-overload-constructors-or-methods-in-python

 



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


Re: [Info] PEP 308 accepted - new conditional expressions

2005-09-30 Thread Fredrik Lundh
Reinhold Birkenfeld wrote:

> after Guido's pronouncement yesterday, in one of the next versions of Python
> there will be a conditional expression with the following syntax:
>
> X if C else Y
>
> which is the same as today's
>
> (Y, X)[bool(C)]

hopefully, only one of Y or X is actually evaluated ?

> C and X or Y (only if X is True)

hopefully, "only if X is True" isn't in fact a limitation of "X if C else Y" ?

/... snip comment that the natural order is C, X, Y and that programmers that
care about readable code will probably want to be extremely careful with this
new feature .../

 



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


Re: Overloading & Overriden

2005-09-30 Thread Fredrik Lundh
"Iyer, Prasad C" wrote:

> Does python supports Overloading & Overriding  of the function?

Please avoid posting the same question over and over again with different
subjects.  Please read the replies to your original question before reposting
the question.  This is a mail list, not a chat channel; it may take a while be-
fore people see your question, and it may take a while before you see the
reply.

> This message contains information that may be privileged or confidential
> and is the property of the Capgemini Group. It is intended only for the
> person to whom it is addressed. If you are not the intended recipient,
> you are not authorized to read, print, retain, copy, disseminate, distribute,
> or use this message or any part thereof. If you receive this  essage in error,
> please notify the sender immediately and delete all  copies of this message.

Oops.  Ok.  Done. 



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


Re: Help with syntax warnings

2005-09-30 Thread Fredrik Lundh
Peter Hansen wrote:

> Wow... Python detects "dubious syntax"?  And here I thought programming
> was rather black and white, it's right or it's wrong.

SyntaxWarnings are issued for things that has never been valid nor well-
defined nor especially clever, but has been handled (in some more or less
reasonable way) by the CPython compiler.  In practice, syntax warnings
will turn into errors in future releases.

> (He notes examples such as assigning to None and "unqualified exec is
> not allowed in function" etc.)

Compare and contrast:

Python 2.3.4 (#53, May 25 2004, 21:17:02)
>>> None = "hello"
:1: SyntaxWarning: assignment to None

Python 2.4.1 (#65, Mar 30 2005, 09:13:57)
>>> None = "hello"
SyntaxError: assignment to None

 



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


Re: Overloading __init__ & Function overloading

2005-09-30 Thread Fredrik Lundh
Larry Bates wrote:

>I may be reading this question different than Fredrik.

it looks like you're using a non-standard definition of the word "overloading".
here are the usual definitions (quoting from a random google page):

"Overloading a method refers to having two methods which share the
same name but have different signatures."

"Overriding a method refers to having a new implementation of a method
with the same signature in a subclass."

 



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


Re: Overloading __init__ & Function overloading

2005-09-30 Thread Fredrik Lundh
"Iyer, Prasad C" wrote:

> Thanks a lot for the reply.
> But I want to do something like this
>
> class BaseClass:
> def __init__(self):
> # Some code over here
> def __init__(self, a, b):
> # Some code over here
> def __init__(self, a, b, c):
> # some code here

did you read the FAQ I pointed you to?  it shows how to deal with exactly
that case.

 



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


Re: getattr

2005-09-30 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> Is there any  way by which the __getattr__(self,attr) method can
> determine that in
> case a) attr == 'bar' is the final component in the reference unlike in
> case b) where attr=='bar' is NOT the ultimate(final) component of
> reference and is an intermediate component in the reference.

no.

if you want to control further accesses, your __getattr__ has to return a
proxy object, and use a suitable syntax to get the final value.

 



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


Re: getattr

2005-09-30 Thread Fredrik Lundh

> if you want to control further accesses, your __getattr__ has to return a
> proxy object, and use a suitable syntax to get the final value.

message.insert(index, "your users have to ")

 



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


Re: Help with syntax warnings

2005-10-01 Thread Fredrik Lundh
Ivan Shevanski wrote:

> Well I've been experimenting with the warning filter and it doesn't seem to
> be working. . .I think it has something to do with the fact that warnings
> are issued during the compiling and not during the excecution. . .So the
> filter would come in to late to block them? Any ideas?

fix your code.

fixing syntaxwarnings is almost always trivial; most of the time, all you
have to do is to remove (or rephrase) some statement that doesn't do
what you think it does anyways...

if you really cannot motivate yourself to fix your code, you have to add
an extra "bootstrap" module.  if your program is named "myprogram.py",
rename that file to "myactualprogram.py", and add a "myprogram.py" that
looks like this:

# File: myprogram.py

import warnings
warnings.simplefilter("ignore", SyntaxWarning)
import myprogram

(you may have to fix any __name__ == "__main__" clauses in your original
program).

but you really should fix your program, instead of wasting time on stupid
workarounds.





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


Re: Background process for ssh port forwarding

2005-10-01 Thread Fredrik Lundh
Jesse Rosenthal wrote:

> If I end this with 'connection.interact()', I will end up logged in to the
> forwarding server. But what I really want is to go on and run rsync to
> localhost port 2022, which will forward to my_server port 22. So, how can
> I put the ssh connection I set up in hostforward() in the background?
> I need to make sure that connection is made before I can run the rsync
> command.

$ man ssh

...

 -f  Requests ssh to go to background just before command execution.
 This is useful if ssh is going to ask for passwords or
 passphrases, but the user wants it in the background.  This
 implies -n.  The recommended way to start X11 programs at a
 remote site is with something like ssh -f host xterm.

...





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


Re: Statement orders

2005-10-02 Thread Fredrik Lundh
Monu Agrawal wrote:

> Hi I am making a gui based tool. When user preses a perticular button I
> am running a heavy command, before this I want to say user to wait with
> a image showing infront of her.
>
> My code is like:
>
> def loadData(self):
>top=Toplevel(self.parent)
>top.focus_set()
>self.parent.wm_title("Loading Data...")

+top.update() # flush the event queue

>os.system('a heavy command')
>os.system('another heavy command)
>top.destroy()





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


Re: Class Help

2005-10-02 Thread Fredrik Lundh
Ivan Shevanski wrote:

> To continue with my previous problems, now I'm trying out classes.  But I
> have a problem (which I bet is easily solveable) that I really don't get.
> The numerous tutorials I've looked at just confsed me.For intance:
>
> >>>class Xyz:
> ... def y(self):
> ... q = 2
> ...
> >>>Xyz.y()

what tutorial told you to write this last line?





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


Re: Problems posting with urlencode

2005-10-02 Thread Fredrik Lundh
Joseph Chase wrote:

> When I go and view the inserted record, the record exists, but the field
> values are null.  It is my thinking that the backend needs the "id" value
> for each input value; how do I add that data to the urlencode() call?

since the id isn't part of the form data set:

http://www.w3.org/TR/REC-html40/interact/forms.html#form-data-set

that's a bit unlikely.

printing the params string might help you figure out what's
missing.





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


Re: Distributing programs

2005-10-02 Thread Fredrik Lundh
Jason wrote:

> A non-python programming friend of mine has said that any programs made
> with Python must be distributed with, or an alternative link, to the source of
> the program.
>
> Is this true?

no.

the license is here:

http://www.python.org/doc/Copyright.html

   "Python is absolutely free, even for commercial use (including
resale). There is no GNU-like "copyleft" restriction."





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


Re: Distributing programs

2005-10-02 Thread Fredrik Lundh

> the license is here:
>
> http://www.python.org/doc/Copyright.html
>
>"Python is absolutely free, even for commercial use (including
> resale). There is no GNU-like "copyleft" restriction."

except that the current license is (no longer?) linked from that page.

the current license is here:

http://www.python.org/2.4.2/license.html

more words, but the summary remains the same:

"Python is absolutely free, even for commercial use (including
resale). There is no GNU-like "copyleft" restriction."





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


Re: struct.unpack

2005-10-02 Thread Fredrik Lundh
"g.franzkowiak" wrote:

> I've read a pipe and store it in a object.
> My next step was the separation from 4 bytes with
> obj = string.join(list(dataObject)[:4] ==> '\x16 \x00 \x00 \x00'
> and the converting  by
> value = struct.unpack('I', obj) generated the error
> "unpack str size does not match format"
>
> Unfortunately is len(obj) 7, but integer lengt 4.
> Why 7 ?

because string.join inserts a space between the bytes, by default (as
your example shows)

if you really need that join(list) thing (it's not clear how you read it, but
I find it a bit hard to believe that you've managed to read it into some-
thing that's supported by list but not unpack), you can do

obj = string.join(list(dataObject)[:4], "")

or

obj = "".join(list(dataObject[:4]))

or some variation thereof.





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


Re: A Moronicity of Guido van Rossum

2005-10-02 Thread Fredrik Lundh
"Michael" wrote:

> List comprehensions get their name (AFAICT) very clearly from set
> comprehensions in mathematics. As a result anyone who has ever seen
> a set comprehension in maths goes "oooh, I see". They're not the same, but
> IMO they're close enough to warrant that name.

fwiw, they've also been around for ages:

http://foldoc.doc.ic.ac.uk/foldoc/foldoc.cgi?list+comprehension

(the name goes back to the early eighties, the construct is older than that)





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


Re: Bwidget for tkinter

2005-10-02 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> hi can i use the bwidgets in tkinter? if so from where can i download
> the bwidget for tk inter. and i want to know the installation procedure

googling for "bwidget for tkinter" gives you a library announcement as
the first hit, which points to this page:

http://tkinter.unpythonic.net/bwidget/





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


Re: Bwidget for tkinter

2005-10-03 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> thanks u man. i am new to tk inter. i tried installing the lib. but
> while running the demo script am getting following error.
>
> python sam.py
> Traceback (most recent call last):
>   File "sam.py", line 1, in ?
> import bwidget, Tkinter, sys, os
>   File "/usr/local/lib/python2.2/site-packages/bwidget/__init__.py",
> line 149, in ?
> class _Frame:
>   File "/usr/local/lib/python2.2/site-packages/bwidget/__init__.py",
> line 152, in _Frame
> getframe = makeswidget(getframe, Tkinter.Frame)
>   File "/usr/local/lib/python2.2/site-packages/bwidget/__init__.py",
> line 74, in makeswidget
> return _wrap(w, f)
>   File "/usr/local/lib/python2.2/site-packages/bwidget/__init__.py",
> line 59, in _wrap
> oldfunc.func_name, wrapper.func_defaults, wrapper.func_closure)
> TypeError: function() takes at most 4 arguments (5 given)

it's likely that it simply doesn't support Python 2.2 (which was released
in 2001; we've had two major releases since then).





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


Re: python getopt functionality

2005-10-03 Thread Fredrik Lundh
"M.N.A.Smadi" wrote:

> I have a perl script that I need to port to python. The script takes
> input from the command line.  Is there a standard way of processing
> command line arguments based on the -flag preceeding the argument?

http://docs.python.org/lib/module-getopt.html
http://docs.python.org/lib/module-optparse.html





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


Re: Python Debug Build

2005-10-03 Thread Fredrik Lundh
"Celine & Dave" wrote:

> What happens if I build Python with debug option
> (--with-pydebug)? Do I see any changes in my program
> output? What is --with-pydebug good for?

from the README:

--with-pydebug:  Enable additional debugging code to help track down
memory management problems.  This allows printing a list of all
live objects when the interpreter terminates.





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


Re: Where to find python c-sources

2005-10-03 Thread Fredrik Lundh
Peter Hansen wrote:

> Sorry, but this defense is less than weak.  Using "python
> socketmodule.c" you actually get the right answer as the third result,
> while with the even-more-obvious-to-a-rookie "socketmodule.c" you get it
> as the *first* result.

using just "python" gives you a link to the source code download page as
part of the first result.





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


Re: question about smtplib

2005-10-03 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> cool. so this line
> server = smtplib.SMTP(localhost)
> is when i connect ?

http://www.python.org/doc/lib/module-smtplib.html

 "If the optional host and port parameters are given, the
SMTP connect() method is called with those parameters
during initialization."

"For normal use, you should only require the initialization/
connect, sendmail(), and quit() methods. An example is
included below."





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


Re: semi-newbie module namespace confusion

2005-10-03 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> The main jist of the problem is that I'm trying add data from one
> module to a list and a dictionary in another module, and it doesn't
> seem to stick over there.
>
> The programs below seem to illustrate the issue.  (The results follow
> the programs).
> Why are the results different from runs of the two programs?  The
> output of nameSpaceTestB.py makes sense to me, but I just don't get why
> nameSpaceTestA.py does what it does.
>
> I'm sure the reason is very simple, but I just don't see it.  Please,
> can someone shed some light on the issue for me?

running a piece of python code as a script isn't the same thing as
importing it as a module:

"If you run a module as a script (i.e. give its name to the inter-
preter, rather than importing it), it's loaded under the module
name __main__.

If you then import the same module from your program, it's re-
loaded and reexecuted under its real name. If you're not careful,
you may end up doing things twice."

http://effbot.org/zone/import-confusion.htm

try changing your "printing from"-statements to

print "printing from", __name__

to see what you're really doing.





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


Re: cgi relay for python cgi script

2005-10-04 Thread Fredrik Lundh
Amir Michail wrote:

> Is there an easy way to execute a python cgi script on a different
> machine from the cgi server?

http://www.google.com/search?q=reverse+proxy

 



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


Re: semi-newbie module namespace confusion

2005-10-04 Thread Fredrik Lundh
David Murmann wrote:

> I ran into the same problem some time ago and even wanted to post here
> about it, but found out that it had been reported as a bug three times
> at sourceforge (if i remember correctly). The comments there explained
> it of course, but I still think that this behavior is somehow "wrong".
>
> I like to think of the import statement as a way to provide the names
> defined in a module to the current namespace, so there is no "this gets
> evaluated twice".

are you sure you understand the problem?  import does exactly what you
say; it creates a module object and populates it by running the code in the
module.

the problem is that when you hand Python a chunk of code (a script), it
doesn't necessarily know where it came from.  and even if you know the
filename it came from, there's no way to know if that chunk actually corre-
sponds to a module somewhere out there (the import system can map a
module name to a file, but it cannot map a file to a module name).

> Now i wonder how difficult it would be to "correct" the behavior?

there's no way to "fix" it without introducing a huge number of inconsistencies.

> And would such a change break any code?

any code that uses the "if __name__ == "__main__" pydiom, for a start.

 



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


Re: What is executed when in a generator

2005-10-04 Thread Fredrik Lundh
Jerzy Karczmarczuk wrote:

> Could you tell me please where can I read something in depth about the
> semantics of generators? I feel a bit lost.

the behaviour is described in the language reference manual:

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

"When a generator function is called, it returns an iterator known as a
generator iterator, or more commonly, a generator. The body of the
generator function is executed by calling the generator's next()
method repeatedly until it raises an exception."

the above page points to the design document, which contains the full
story:

http://www.python.org/peps/pep-0255.html

"When a generator function is called, the actual arguments are bound to
function-local formal argument names in the usual way, but no code in
the body of the function is executed.  Instead a generator-iterator
object is returned; this conforms to the iterator protocol /.../

Each time the .next() method of a generator-iterator is invoked, the
code in the body of the generator-function is executed until a yield
or return statement (see below) is encountered, or until the end of
the body is reached."

 



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


Re: cgi relay for python cgi script

2005-10-04 Thread Fredrik Lundh
Amir Michail wrote:

> Is there an easy way to do this without modifying the configuration of
> the cgi server and without running a cgi server on the other machine
> where the script will actually run?
>
> Perhaps someone wrote a simple server that provides the required
> environment for the cgi script to run?
>
> I'm looking for something simple that does not require root access.

you could of course use something like

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

or some other light-weight web server, but you should probably have in mind
that doing things like this without coordinating with your server administrators
and security architects *before* you start tinkering can be a excellent way to
get fired...

 



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


Re: Dynamical loading of modules

2005-10-04 Thread Fredrik Lundh
Carsten Haese wrote:

> I don't see how to make __import__ do that.

hint: you might get more people to look at your problems/proposals if you
actually trim the replies a little.  (is 295 angle brackets in a single message
perhaps some kind of c.l.py record?)

 



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


Re: Dynamical loading of modules

2005-10-04 Thread Fredrik Lundh
>  (is 295 angle brackets in a single message perhaps some kind of c.l.py 
> record?)

oh, nevermind.

 



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


Re: ssh or other python editor

2005-10-04 Thread Fredrik Lundh
"projecktzero" wrote:

> If samba isn't available/set-up, you can try using FTP. You can then
> use Crimson Editor which does the syntax coloring and can ftp to/from a
> server.

are you guys for real?

is there any major text editor for Unix that doesn't support Python syntax
coloring and indentation these days?

 



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


Re: ssh or other python editor

2005-10-04 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:
>- I'm a newbie at freeBSD so I think there is , but I don't know where.

I just complained when someone included the entire message thread in their
replies, but not including anything at all is pretty annoying too.

> And i'm using putty on a windows OS what don't understand the syntax
> coloring.

Putty isn't doing any syntax coloring; it just draws things in the color 
specified
by your editor.  If you don't get any colors, it's probably because your editor
isn't properly configured.  Explicitly setting the TERM variable to "xterm" 
might
help:

http://www.chiark.greenend.org.uk/~sgtatham/putty/faq.html#faq-term

(but I'm pretty sure ssh does this for you, so it's probably an editor 
configuration
issue.  checking the FAQ for your editor might be a good idea)

 



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


Re: how to get any available port

2005-10-04 Thread Fredrik Lundh
Mohammed Smadi wrote:

> if am using s.bind for a tcp socket.  On the client side i dont really
> care which socket i use as long as i get an available socket.  Is there a
> funciton or a way to get an available socket?

why are you using bind if you're on the client side?

 



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


Re: Newbie regular expression ?

2005-10-04 Thread Fredrik Lundh
"len" <[EMAIL PROTECTED]> wrote:

>I have the following statement and it works fine;
>
>list1 = glob.glob('*.dat')

that's a glob pattern, not a regular expression.

> however I now have an additional requirement the the string must begin
> with any form of "UNQ,Unq,unq,..."

list1 = glob.glob('*.dat')
list1 = [file for file in list1 if file.lower().startswith("unq")]

 



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


Re: how to get any available port

2005-10-04 Thread Fredrik Lundh
Mohammed Smadi wrote:

> what else would you do?  I am using examples from the web and they all
> bind to a port at the localhost before connecting to the remote host.

pointers, please.

> my code is like this
>
> #transmission socket
> s = socket.socket(socket.AF_INET,  socket.SOCK_STREAM)
> s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
> s.bind(("",hp_port)) # do some error checking

that's a typical server setup.

> data="HI"
> print data
> s.connect(('192.168.2.13',port))
> s.send(data)

and this is typical client setup.

are you sure you're not cutting and pasting code from different examples?

> any suggestions for alternative implementation?

if you're writing a client, get rid of the setsockopt and bind stuff.

 



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


Re: how to get any available port

2005-10-04 Thread Fredrik Lundh
Grant Edwards wrote:

> IIRC, you just call bind() with a port number of zero, and then
> use some method-or-other on the bound socket to find out what
> port it's bound to.

>>> s = socket.socket()
>>> s.bind(("", 0))
>>> s.getsockaddr()
("0.0.0.0", 4711)

 



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


Re: Newbie Text Processing Question

2005-10-04 Thread Fredrik Lundh
Gregory Piñero wrote:

>That's how Python works. You read in the whole file, edit it, and write it
> back out.

that's how file systems work.  if file systems generally supported insert
operations, Python would of course support that feature.





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

Re: Help needed in OOP-Python

2005-10-04 Thread Fredrik Lundh
Toufeeq Hussain wrote:

> I have 3 modules which have class declarations in them and which implement
> multiple inheritance.

> Traceback (most recent call last):
> File "E:\PyPBM\PyPBM\test_case.py", line 7, in ?
>TH = constraint.Option1_Rule1()

there's no line that says "TH = constraint.Option1_Rule1()" in the
code you're posted.  looks like you didn't really post the code you
tested...





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


Re: While and If messing up my program?

2005-10-05 Thread Fredrik Lundh
"CJ" wrote:

>What does worry me, is that I can't seem to get the program by a
> certain spot. It keeps giving me the same error, and I don't know why.

quite often, exception messages means exactly what they say; if
you get an index error, it's because you're trying to fetch an item
that doesn't exist.

for simple debugging, the "print" statement is your friend:

> ttllst=[4,3,45,3]
> cnto=0
> cntt=1
> rept=-1
>
> print cnto
> print cntt
> print ttllst[cnto]
> print ttllst[cntt]
> choice=raw_input("Begin? ")
> if choice == "yes" or choice == "y":
> while cnto<>len(ttllst)+1:

   print cnto, cntt, len(ttllst)

> if ttllst[cnto]==ttllst[cntt]:
> rept=rept+1
> if cntt==len(ttllst):
> print ttllst[cnto],"appears in the list",rept,"times."
> cntt=-1
> cnto=cnto+1
> rept=-1
> cntt=cntt+1
> print "done."

with that in place, I get

Begin? y
0 1 4
0 2 4
0 3 4
0 4 4
Traceback (most recent call last):
  File "test.py", line 14, in ?
if ttllst[cnto]==ttllst[cntt]:
IndexError: list index out of range

which means that your second list index (cntt) is too large.

figuring out how to fix that is left as an etc etc.



PS.  when you've sorted this out, you might wish to check out the
"count" method on list objects:

>>> help(list.count)
Help on method_descriptor:

count(...)
L.count(value) -> integer -- return number of occurrences of value



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


Re: Help needed in OOP-Python

2005-10-05 Thread Fredrik Lundh
Toufeeq Hussain wrote:

> My coding is really really bad,that's why I changed the names to more human
> readable form(Module1,2.. etc).

the problem is that when you do that (and post using a tool that's not
smart enough to preserve leading whitespace), anyone who wants to help
will basically have to recreate your program -- and once they've done that,
chances are that they won't get the same error as you do.

consider this:

$ python test.py
Traceback (most recent call last):
  File "test.py", line 1, in ?
import module3
  File "module3.py", line 4, in ?
class Option1_Rule1(declaration.Option1):
NameError: name 'declaration' is not defined

oops. looks like you forgot to rename something.  that's easy to fix.

$ python test.py
Traceback (most recent call last):
  File "test.py", line 3, in ?
Test_Case = module3.Option1_Rule1()
  File "module3.py", line 6, in __init__
module2.Option1.__init__(self)
  File "module2.py", line 5, in __init__
module1.OptionClass.__init__('Blah Blah','OR0001','','')
TypeError: unbound method __init__() must be called with OptionClass instance as
 first argument (got str instance instead)

aha. that sure looks like a bug.  when you call the baseclass init method,
you must pass in the object instance as the first argument.  that's easy to
fix.

$ python test.py
Traceback (most recent call last):
  File "test.py", line 4, in ?
Test_Case.Option1_constraint()
AttributeError: Option1_Rule1 instance has no attribute 'Option1_constraint'

oops. looks like I got the indentation wrong when I fixed up that module.
that's easy to fix.

$ python test.py
condition satisfied
Traceback (most recent call last):
  File "test.py", line 4, in ?
Test_Case.Option1_constraint()
  File "module3.py", line 11, in Option1_constraint
self.FOO_warning.Fire()
AttributeError: Option1_Rule1 instance has no attribute 'FOO_warning'

FOO_warning?  there's no FOO_warning anywhere in the code.

:::

so, after four attempts, I've found four problems, three of which was present
in your posted code, but I still haven't seen the problem you reported:

Traceback (most recent call last):
  File "test_case.py", line 7, in ?
TH = constraint.Option1_Rule1()
  File "constraint.py", line 13, in __init__
declaration.Option1.__init__(self)
TypeError: __init__() takes no arguments (1 given)

which, in itself, looks like you've forgotten the self argument in some init
method somewhere (but the code you posted doesn't have that problem).

if you want to post code, 1) try to reduce the problem to as little code as you
possibly can, and 2) make sure that the code you post really has the problem
you're seeing... (i.e. run it at least once before you post it)





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


  1   2   3   4   5   6   7   8   9   10   >