Re: Html or Pdf to Rtf (Linux) with Python

2004-12-16 Thread Axel Straschil
Hello!

> I've been able to successfully get konqueror to generate a pdf from a
> html file via dcop. It's something along the lines of:

For that stuff, I'm using htmloc (http://www.htmldoc.org/).

Lg,
AXEL.
-- 
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD",
"SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be
interpreted as described in RFC 2119 [http://ietf.org/rfc/rfc2119.txt]

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


Re: BASIC vs Python

2004-12-16 Thread Mike Meyer
Andrew Dalke <[EMAIL PROTECTED]> writes:

> Adam DePrince
> Given the hardware constraints of the early 1980s, which
> language do you think should have been used instead of BASIC?

Logo. It was invented in 1968, when mainframes weren't much more
powerfull than those '80s microcomputers. It had standard graphics
primitives that are *much* saner than hacking at a bitmapped
display. It was designed specifically to teach children how to think
logically.

You can find out more - including a list of current implementations
and example code - at http://en.wikipedia.org/wiki/Logo_programming_language >.

BASIC as implented by Microsoft for the Apple II and the TRS 80 (among
others) is simply the worst programming language I have ever
encountered. Assembler was better - at least you had recursion with
assembler.

  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Cool object trick

2004-12-16 Thread Doran_Dermot
I rather like it!  I prefer writing obj.spam to obj["spam"]!  I wonder if
there is a technical downside to this use of Python?

P.S.

Certainly makes writing 'print obj.spam, obj.spam, obj.eggs, obj.bacon,
obj.sausages, "and", obj.spam' a lot easier ;-)

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
Jive
Sent: 17 December 2004 06:29
To: [EMAIL PROTECTED]
Subject: Re: Cool object trick

Kinda cool.

It's occured to me that just about everything Pythonic can be done with
dicts and functions.  Your Obj is just a dict with an alternate syntax.  You
don't have to put quotes around the keys.  But that's cool.


class struct(object):
def __init__(self, **kwargs):
self.__dict__.update(kwargs)

# Indented this way, it looks like a struct:
obj = struct(  saying = "Nee"
   , something = "different"
   , spam = "eggs"
  )

print obj.spam

# Is that really much different from this?

obj2 = { "saying" : "Nee"
, "something" : "different"
, "spam" : "eggs"
   }

print obj2["spam"]


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


Re: Multithreading tkinter question

2004-12-16 Thread Oleg Paraschenko
Hello John,

> Mark,
>
> I tried your code snippet with Python 2.3.4. Worked fine. Only
problem was
> that the program fell off the end and terminated before the second
thread
> could open the Tkinter window. So I added these lines at the end to
make the
> main thread wait:-
>
> from msvcrt import kbhit, getch
> print "\n\nPress key to end"
> while not kbhit(): pass
> getch()

And I added

print "\n\nPress key to end"
l = sys.stdin.readline()

> Both your Hello and Quit buttons worked.

In my case "Hello" works and "Quit" doesn't (GUI stays frozen).
Linux, Python 2.3.3, pygtk-0.6.9.

> ...
>
> It is not optimal in that 'otherThread' runs continuously even when
the
> label is not being updated. What a waste of cpu cycles! This shows up
in
> that other windows apps slow right down. What is needed is a comms
method
> between threads that causes a thread to block while it's waiting for
data
> rather than my continuous polling approach. Would a Queue help here?
>

Yes, it should help. A time ago I tried to write a tkinter
application,
and my test code is available:

A complete Python Tkinter sample application for a long operation
http://uucode.com/texts/pylongopgui/pyguiapp.html
Maybe you find it interesting.

--
Oleg

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


Re: BASIC vs Python

2004-12-16 Thread Gregor Horvath
Hi,
Adam DePrince wrote:
computers of the day.   This was in a misguided effort to make computers
understandable to their target audience.  The goal of the day was to
build a system that a manager would want to buy; it was believed that
[..]
BASIC = Beginners all purpose symbolic instruction code
ABC = laerning language
Python = Follows IMHO the same goals as BASIC did,
make programming as simple as possible, they are related
Sure for people loving technology and complexity this goals (simplicity, 
easy to understand) are the opposite of their interests. Therefore both 
BASIC and Python do have the same opposition with very similar arguments.

Complexity is the evil of all programming. Reducing it is a win. 
Therefore BASIC was right and python is also because they follow the 
same philosophy.

For example: I even think that the meaningful identation in python is 
the continuation of the absence of a line delimiter in BASIC. Braces and 
semicolons are essentially useless and redundant because indentation and 
LF are already there, therefore leave it out; well this is indeed the 
meaning of the word basic.

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


Re: BASIC vs Python

2004-12-16 Thread It's me

"Adam DePrince" <[EMAIL PROTECTED]> wrote in message



>
> Don't do it, unless your goal is simply to embarrass and insult
> programmers.
>

I saw this code from an earlier post:

lst1 = ["ab", "ac", "ba", "bb", "bc"]
lst2 = ["ac", "ab", "bd", "cb", "bb"]
dct1 = dict.fromkeys(lst1)
print [x for x in lst1 if x not in dct1]
print [x for x in lst1 if x in dct1]

It's simply remarkable for somebody to be able to do it so cleanly (and so
obviously) - "out of the box", if you may.

Sure, you can do it in Basic.  Ur...sure?  Yes, sure...


>
>
> Adam DePrince
>
>


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


Re: BASIC vs Python

2004-12-16 Thread Andrew Dalke
Adam DePrince
> During the 1980's BASIC was the language to embedd into the ROM's of the
> computers of the day.   This was in a misguided effort to make computers
> understandable to their target audience.  The goal of the day was to
> build a system that a manager would want to buy; it was believed that
> the only way for a manager to see the value of a system was to make the
> language understandable to said manager.

That doesn't sound like the 1980s I remember but I was biased
because I those included my teenage years and I wasn't a manager.

I though part of the market was for parents of kids like me.
In my case I learned from the book that came along with the
computer.  I remember how confusing arrays were ("By default
it only takes numbers between 1 and 10, so I should be able
to use 2.5, right?").  I don't think I could have handled
UCSD Pascal on my own nor the other languages available at
the time.

Editing BASIC is also dead simple to read and to implement
on a machine with a few K of RAM.  Compare to EDLIN for
DOS or other editors of the era.  That's the era of WordStar
and the ^K^B and ^K^K control character commands.  Again,
not something a beginning solo student programmer can
likely pick up easily.

The BASICs of my youth also supported graphics and sounds.

  PLAY "CGFED>CC In BASIC you literally list the steps the computer will follow.  Each
> step gets a line number.  Decisions are controlled by jumping to
> different "line numbers."  No where in the language was there any notion
> of or ability to make your program remotely abstract.  You know those
> jokes on slashdot.org that read:

True, for the basics on those microcomputers.  In 1987
or so (maybe 1986) I switched over to Quickbasic which
got rid of those problems, included an IDE, and produced
fast compiled code.  TrueBasic was also available in 1987.


> That is BASIC in a nut shell.   Sure, modern versions have gotten a
> little better, dispensing of evils such as line numbers and the like,
> but they are only marginally better.

Modern = last 15+ years.  My experience with with the now
very dated Quickbasic which I last touched in .. 1993?  It
seemed quite comparable to Turbo Pascal in its capabilities.

> Each language carries with it a philosophy.  BASIC stands alone in being
> so utterly perverse that learning it will render you completely
> unmarketable, except as a basic programmer, as you unlearn its
> limitations and learn how to think in the abstractions of every other
> language.  

Which was just fine with me.  I learned Pascal in Sr. High,
C in college (and C++ and Fortran) and didn't get paid to be
a full-time programmer until 3 years after I graduated college.


> Perhaps I can best illustrate the difference between the two with an
> analogy.  Suppose you came to me and asked which was a better way of
> learning a foreign language, the python way or the BASIC way.  

> The Python way would be how a language is taught in any normal class
> you might find at a local college.  You learn the vocabulary, grammar,
> history and culture of the language.

Let's try this recasting of your analogy.

Suppose you had to learn Latin without a teacher or without
access to Latin speakers.  The only way you had to get feedback
was by typing a letter to the Latin Language Institute, fortunately
staffed by very patient folks but they only reply in Latin.
All you have is a book that came along with the typewriter.

You don't at this point know there is a culture or a history.
Rome?  What's that?  But you like horses so you start writing
about equus.  The LLI responds with a bit more about horses.
A conversation starts.  After a lot of practice you learn
you can do more with Latin than talk about horses and find
there's over 2,500 years of recorded history in Latin, including
stories about horses.

Finally you move to a place that has a language teacher and
you learn Latin more rigously, that it's "Romani ite domum"
and not "Romanes eunt domus", and find out about Greek, and
Swedish, and Japanese, and all sorts of other interesting
languages.

Given the hardware constraints of the early 1980s, which
language do you think should have been used instead of BASIC?

Andrew
[EMAIL PROTECTED]

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


Re: Cool object trick

2004-12-16 Thread Jive
Kinda cool.

It's occured to me that just about everything Pythonic can be done with
dicts and functions.  Your Obj is just a dict with an alternate syntax.  You
don't have to put quotes around the keys.  But that's cool.


class struct(object):
def __init__(self, **kwargs):
self.__dict__.update(kwargs)

# Indented this way, it looks like a struct:
obj = struct(  saying = "Nee"
   , something = "different"
   , spam = "eggs"
  )

print obj.spam

# Is that really much different from this?

obj2 = { "saying" : "Nee"
, "something" : "different"
, "spam" : "eggs"
   }

print obj2["spam"]


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


Question about Py C API implementation.

2004-12-16 Thread Adonis
I wrote a small script to flatten a list of lists without the need
of recursion, it works fine for the most part, but was wanting to 
reimplement it in C just for kicks, and would give me and excuse to 
learn the Python C API, but the C implementation does not function 
properly, I *think* it might be how I am trying to copy a sub list that 
is found to a list object for seperate processing (line 22, flatten.c), 
but also could be where I am trying to pop the topmost from the list 
(line 35, flatten.c), but it has me stooped, I lack in C skills so not 
many things may be apparent to me immediately, any help is greatly 
appreciated.

Adonis
http://home.earthlink.net/~adonisv/flatten.py
http://home.earthlink.net/~adonisv/flatten.c
--
http://mail.python.org/mailman/listinfo/python-list


Re: ".>>>" is a good idea! (OT, was: Re: do you master list comprehensions?)

2004-12-16 Thread Keith Dart
Fernando Perez wrote:

You might want to look at ipython:
http://ipython.scipy.org,

I did just recently install that. It looks very nice. Would make a great 
interactive prompt for an IDE, as well.


--
   \/ \/
   (O O)
-- oOOo~(_)~oOOo
Keith Dart <[EMAIL PROTECTED]>
vcard: 
public key: ID: F3D288E4   URL: 

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


Re: lies about OOP

2004-12-16 Thread Andy Salnikov

"Gregor Horvath" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Daniel T. wrote:
> > [EMAIL PROTECTED] wrote:
> >
> >
> >>A paper finding that OOP can lead to more buggy software is at
> >>http://www.leshatton.org/IEEE_Soft_98a.html
> >
> >
> > Sure, OOP *can* lead to more buggy software, that doesn't mean it always
> > does.
> >
>
> I think that costs(=time) to develop and maintain software depends not
> on wheter it is based on OOP or not but on two factors:
>
> * Number of NEW Code lines to solve the given problem
> * Complexity of this new code
>
  Complexity of the code in turn may depend on too many factors.
For me OOP is good because it gives me the means to manage the
complexities. Remember that OO is not only about objects and
things like encapsulation, important part of OO analysis and design
is making dependencies "right" which in turn reduces complexity.

> The anwser to the question if OOP is better is: it depends
>
> If the given problem is solved with less code and complexity in OOP then
> it is the better approach if not the reverse is true.
>
  For any given problem there could an infinite set of solutions
expressed in any methodology. If you take best non-OO and compare
it with he worst OO, the winner is pre-determined :) And then
chosing a winner is always subjective, we are all people :) When
programs will be written by robots they will chose objective
criteria which will tell if OO is better for particular task.
But then we won't need to disscuss itin c.l.py :)

> Thats why I like python because it does not force to use OOP or
> procedural programming.
>
> But isnt the main argument to code in Python (or other high level
> languages) easy of use and compact code?
>
> Therefore should Python code be less buggy and cheaper to develop and
> maintain. Are there any papers on that?
>
  Compact is not a synonim for less complex. It just means that you
can express a solution in fewer lines of code. COmplexity of the code
will remain the same as in any other language. And there is no bug-free
code, there is well-tested code.

  Andy.




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


Re: wxPython question

2004-12-16 Thread M.E.Farmer
Messed up it does need the dots.
This should handle bmp ico png gif and several other formats.
Still need to be 32 by 32

wx.InitAllImageHandlers()
image = wx.Image(file, wx.BITMAP_TYPE_ANY)
image = image.ConvertToBitmap()

icon = wxEmptyIcon()
icon.CopyFromBitmap(image)

frame.SetIcon(icon)

Hth,
 M.E.Farmer

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


Re: Is Python good for graphics?

2004-12-16 Thread John Hunter
> "djw" == djw  <[EMAIL PROTECTED]> writes:

djw> PyGame?

djw> http://www.pygame.org/

Seconded, despite the plethora of packages proposed in response to the
original query, pygame seems like a clear winner for the problem
described.

And this coming from the author a different graphics package!

JDH

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


Re: Is Python good for graphics?

2004-12-16 Thread djw
Esmail Bonakdarian wrote:
First of all, I *really* like Python ;-)
I need some help with the graphical side of things. I would like to do
some basic graphics with Python, but I am not sure what the best/most
effective way for me to do what I want.
Basically, I would like to be able to create some basic animations
where I can help visualize various sorting algorithms (for instance
http://ciips.ee.uwa.edu.au/~morris/Year2/PLDS210/sorting.html#insert_anim)
or graph searches (coloring nodes as each gets visited). (Something
like this: http://cs.smith.edu/~thiebaut/java/graph/Welcome.html)
Or to create and manipulate programmatically a simple 2-D block puzzle
(like this: http://www.johnrausch.com/SlidingBlockPuzzles/quzzle.htm).
Note, the ability to do this via the web would be nice, but definitely
is *not* required at the moment.
These would be used to help in learning/teaching.
I am aware of Tkinter and wxPython (by aware I mean I know of their
existence :-) Before investing (a lot?) of time to learn these, I
thought I’d ask the more experienced folks around here what would be
the best way to invest my time to get basic graphics going.
I really am not concerned so much with efficiency as easy of use.
Can anyone recommend what would suit my rather limited needs best?
Are there other graphics libraries I should consider that would be
more suitable?
Or is Python not the way to go for this?
Thanks!
Esmail
PyGame?
http://www.pygame.org/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Best book on Python?

2004-12-16 Thread Esmail Bonakdarian
Esmail Bonakdarian wrote:
> I myself am looking for a small portable quick
> reference,
Scott David Daniels wrote:
Look into Python Essential Reference for that kind of
book -- no fat, lotsa goodies.
Hi Scott,
Thanks for the recommendation. I didn't know about this
book but looking at amazon, it looks a bit big for my
purposes (400+ pages) and covers only up to 2.1.
http://www.amazon.com/exec/obidos/tg/detail/-/0735710910/ref=lpr_g_1/102-5580604-1195362?v=glance&s=books
I'll keep looking.
Cheers,
Esmail
--
http://mail.python.org/mailman/listinfo/python-list


Re: os.walk bug?

2004-12-16 Thread Tim Peters
[Adam DePrince]
> Each iteration of os.walk returns three parameters; one of those,
> dirs, is a list of directories within the current directory pointed at
> by root.

Right.

> Am I correct to assume that you beleve that by changing the
> contents of dir you will affect how os.walk traverses the
> directories.  If so, that is your problem.

Nope, mutating dirs is the intended way to prune (or even to augment)
os.walk's search tree on the fly  See the docs.  Gabriel's problem was
mutating dirs while iterating over it in another level of loop; while
os.walk() expects that its caller may mutate dirs, and "does the right
thing" if the caller does, Gabriel's own loop wasn't safe against
mutation during iteration.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is Python good for graphics?

2004-12-16 Thread Esmail Bonakdarian
Doug Holton wrote:
I'll tell you know it's not going to be so easy.  There isn't something 
in python like flash.  But here are some options:

See pyxel for python: http://bellsouthpwp.net/p/r/prochak/pyxel.html
and pygame: http://pygame.org/
Gato, the graph animation toolkit, is implemented in python and tkinter: 
http://www.zpr.uni-koeln.de/~gato/
cool, thanks for the links, I'll take a look.
You know you can use java with python, too.  It's called jython.  You 
could use jython to interface the open source physics toolkit, for 
example: http://www.opensourcephysics.org/
See also the Jython Environment for Students (JES).  A book about it is 
supposed to be published tomorrow actually.

And you can use a python-like language for .NET called boo with the 
Piccolo.NET structured graphics toolkit: http://www.cs.umd.edu/hcil/jazz/
or these graph drawing toolkits: http://netron.sourceforge.net/ewiki/
http://www.codeproject.com/cs/miscctrl/quickgraph.asp
hmm .. more options. I guess my preference would be to stick just with
Python if possible.
regards,
Esmail
--
http://mail.python.org/mailman/listinfo/python-list


Re: create lowercase strings in lists - was: (No subject)

2004-12-16 Thread Bengt Richter
On Fri, 17 Dec 2004 02:06:01 GMT, Steven Bethard <[EMAIL PROTECTED]> wrote:

>Michael Spencer wrote:
>>  ... conv = "".join(char.lower() for char in text if char not in 
>> unwanted)
>
>Probably a good place to use str.replace, e.g.
>
>conv = text.lower()
>for char in unwanted:
> conv = conv.replace(char, '')
>
>Some timings to support my assertion: =)
>
>C:\Documents and Settings\Steve>python -m timeit -s "s = 
>''.join(map(str, range(100)))" "s = ''.join(c for c in s if c not in '01')"
>1 loops, best of 3: 74.6 usec per loop
>
>C:\Documents and Settings\Steve>python -m timeit -s "s = 
>''.join(map(str, range(100)))" "for c in '01': s = s.replace(c, '')"
>10 loops, best of 3: 2.82 usec per loop
>
If unwanted has more than one character in it, I would expect unwanted as
deletechars in

 >>> help(str.translate)
 Help on method_descriptor:

 translate(...)
 S.translate(table [,deletechars]) -> string

 Return a copy of the string S, where all characters occurring
 in the optional argument deletechars are removed, and the
 remaining characters have been mapped through the given
 translation table, which must be a string of length 256.

to compete well, if table setup were for free
(otherwise, UIAM, table should be ''.join([chr(i) for i in xrange(256)])
for identity translation, and that might pay for a couple of .replace loops,
depending).

Regards,
Bengt Richter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is Python good for graphics?

2004-12-16 Thread Esmail Bonakdarian
Fredrik Lundh wrote:
WCK, Tk's Canvas, wxPython (do they have a canvas-style widget
available these days), any other self-respecting UI toolkit...
but if you're going to do animations, the drawing part isn't really the hard
bit -- and vpython is designed to do animations.  if you want things to look
pure 2D, all you have to do is to position the lights and the camera 
correctly...
(does vpython support orthographic views out of the box?  if it doesn't,
that shouldn't be hard to add).
Thanks again, I'll consider it (I need to find out about WCK, never
heard of that before either).
Esmail
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is Python good for graphics?

2004-12-16 Thread Esmail Bonakdarian
Robert Kern wrote:

do you (or anyone else) have a recommendation for 2D type
graphics?

I like Kiva (but then, I also help develop it). The best place to get it 
right now is the SVN repository, but it's fairly stable.

http://svn.enthought.com/svn/enthought/branches/converge/kiva/
thanks Robert, I'll check it out.
I'm really only looking for something very simple with minimal
learning curve so that I can concentrate on algorithms and not
have to worry too much about visualualizing things.
Esmail
--
http://mail.python.org/mailman/listinfo/python-list


WebDAV Server

2004-12-16 Thread Mark Hoffman



Jody - Is this you?
Pr. Mark A. Hoffman, S.T.S.St. John's Lutheran 
ChurchSan Antonio, Texas(210)223-2611 
Confidentiality Notice: This email message including any 
attachments is for the sole use of the intended recipient(s) and may contain 
confidential and privileged information. Any unauthorized review, use, 
disclosure, or distribution is prohibited.
 
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: os.walk bug?

2004-12-16 Thread Adam DePrince
On Thu, 2004-12-16 at 14:45, Gabriel Cosentino de Barros wrote: 
> Hi
> 
> I'm new to the list. i found a bad behaviour of os.walk that i can
> reproduce 100% but didn't find an answer to why it does that
> 
> I have the folowing tree:
> 
> t:\dir1
> t:\dir1\2000
> t:\dir1\2001
> t:\dir1\content
> t:\dir2
> t:\dir2\2000
> t:\dir2\2001
> t:\dir2\2002
> t:\dir2\2003
> t:\dir2\2004
> t:\dir2\content
> t:\dir2\templates
> 
> what i wanted was to loop in each dir and skip the years (i don't want
> to touch archive). So i wrote:
> 
> for root, dirs, files in os.walk('t:\'):
> # -- do stuff
> print "working on", root
> # -- stuff done
> 
> print 'DEBUG: dirs =', dirs
> for d in dirs:
> # -- remove archive
> if d[:2] == '20':
> print "--- removing:", d
> dirs.remove(d)
> 
> And when i run it i got the following output
> working on t:\
> working on t:\dir1
> DEBUG: dirs = ['2000', '2001', 'content']
> --- removing 2000
> --- removing 2001
> working on t:\dir1\content
> working on t:\dir2
> DEBUG: dirs = ['2000', '2001', '2003', '2002', '2004', 'content']  <-
> why is this in this sequence?
> --- removing 2000
> --- removing 2003
> --- removing 2004
> working on t:\dir2\2001
> .
> .
> .
> 
> I am nuts?
> 
> running as os.walk('t:\dir2')  make it ignore the same dirs.
> i'm using python 2.3 on windows 2000.
> The t: drive is a webdav mount.

Each iteration of os.walk returns three parameters; one of those, dirs,
is a list of directories within the current directory pointed at by
root. 

Am I correct to assume that you beleve that by changing the contents of
dir you will affect how os.walk traverses the directories.  If so, that
is your problem.

When looping in a for loop, it is generally good programming practice to
assume that nothing you do within your loop will affect which
root,dir,files tuples have been set aside to loop over.  It is likely
that once os.walk was called, the items to be iterated over are
predestined (i.e. assume you are iterating over a tuple.) 
 
Root contains the current path being visited, dirs contains a list of
directories that are within the current directory and files contains a
list of files withing the current directory.  It would seem that the
correect way of writing what you are tring to write is as follows:

test.py contains:
for root, dirs, files in os.walk('t:\'):
if root(-4:-2) == "20": continue 
# Do stuff 

[EMAIL PROTECTED] help]$ python test.py
.
./dir1
./dir1/content
./dir2
./dir2/content
./dir2/templates

Oh, and my directory structure is ... 
# bash -c 'mkdir -p dir1/200{0,1} dir1/content \
dir2/200{0,1,2,3,4} dir2/{content,templates}'

Does this help?

- Adam

> 

Adam DePrince 


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


Re: Permission

2004-12-16 Thread Peter Hansen
-g00t©- wrote:
I tried Python this weekend. I'm java coder and I was looking for handling
names in os. I tried the os.raname('file.ext','nuFile.ext') and I got a
Permission denied error. In the docs, it say that it should work only for
UNIX, than it shouldn't work on XP (if I understood). I'm on XP, should I
declare something to enable permission, or is it common error?
Always post the *actual* code you ran, and include the full
"traceback" that was printed when it failed.
If you don't, you're causing us to waste time guessing at
the possible answer, suggesting things that aren't relevant
to the particular problem you're having, and generally making
it hard for us to help you.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: create lowercase strings in lists - was: (No subject)

2004-12-16 Thread Steven Bethard
Michael Spencer wrote:
 ... conv = "".join(char.lower() for char in text if char not in 
unwanted)
Probably a good place to use str.replace, e.g.
conv = text.lower()
for char in unwanted:
conv = conv.replace(char, '')
Some timings to support my assertion: =)
C:\Documents and Settings\Steve>python -m timeit -s "s = 
''.join(map(str, range(100)))" "s = ''.join(c for c in s if c not in '01')"
1 loops, best of 3: 74.6 usec per loop

C:\Documents and Settings\Steve>python -m timeit -s "s = 
''.join(map(str, range(100)))" "for c in '01': s = s.replace(c, '')"
10 loops, best of 3: 2.82 usec per loop

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


Permission

2004-12-16 Thread -g00t©-
--( oo )--

I don't know if there's a beginner board, just tell me if it's the place;

I tried Python this weekend. I'm java coder and I was looking for handling
names in os. I tried the os.raname('file.ext','nuFile.ext') and I got a
Permission denied error. In the docs, it say that it should work only for
UNIX, than it shouldn't work on XP (if I understood). I'm on XP, should I
declare something to enable permission, or is it common error?

Sorry about that newCommer question, but it would help, I'm on that problem
for a while...

--( oo )--
guillaumeLaBelle [alias goo©] - Architecture CAAO


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


Re: BASIC vs Python

2004-12-16 Thread Adam DePrince
On Thu, 2004-12-16 at 13:42, It's me wrote:
> "abisofile" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> >
> > hi
> >
> > I'm new to programming.I've try a little BASIC so I want ask since
> > Python is also interpreted lang if it's similar to BASIC.
> >
> >
> >
> 
> Is a Ferrari similar to a horse-wagon?  Yes, they both have 4 wheels.

No, it is not better than a horse.  The horse is more reliable and on
any given day you can count on it going further before it needs service.

Or were you comparing a Ferrari to a Mustang ... in which case, yes,
good analogy.

- Adam

Adam DePrince 


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


Re: wxPython question

2004-12-16 Thread mefjr75
Jive wrote:
> How the heck do you set the icon on a frame using a .ico file, or a
.bmp
> file, or whatever?  How do you find out how to do something like
that?
> Apparently there is no documentation to speak of.  I tried looking
the in
> the demo program, but I didn't find the secret..
Hello Jive,
# this is a bit old but should still work
# might have to tweak the wx stuff
# because of the namespace change. ex. wxImage -> wx.Image
# image size must be 32h 32w
image = wxImage(file, wxBITMAP_TYPE_JPEG)
image = image.ConvertToBitmap()

icon = wxEmptyIcon()
icon.CopyFromBitmap(image)

frame.SetIcon(icon)

Be sure to look thru the demo it is very informative and is really the
best documention.
As they say use the source Luke.
Hth,
M.E.Farmer

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


Re: lies about OOP

2004-12-16 Thread Adam DePrince
On Thu, 2004-12-16 at 18:23, Jeff Shannon wrote:
> Peter Hansen wrote:
> 
> > P.S.: I'm only half Danish, but the other half is from
> > a particularly bloodthirsty line of Canadians.
> I thought it was physically impossible for Canadians to be bloodthirsty 
> outside of hockey games... ;)

When I read that I parsed it as reading "I'm Danish; my spouse plays a
mean game of hockey."

Adam DePrince 


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


Re: BASIC vs Python

2004-12-16 Thread Adam DePrince
On Thu, 2004-12-16 at 13:36, abisofile wrote:
> hi 
> 
> I'm new to programming.I've try a little BASIC so I want ask since 
> Python is also interpreted lang if it's similar to BASIC.

Nobody is answering this question because they are shuddering in fear
and revulsion. 

During the 1980's BASIC was the language to embedd into the ROM's of the
computers of the day.   This was in a misguided effort to make computers
understandable to their target audience.  The goal of the day was to
build a system that a manager would want to buy; it was believed that
the only way for a manager to see the value of a system was to make the
language understandable to said manager.  The expectation, of course,
that the manager would sit down and play with the computer instead of
delegating the tasks to somebody more qualified is somewhat misguided in
hindsight.  To do that, a language that closely resembled the process of
micromanaging an untrained worker was employed.

In BASIC you literally list the steps the computer will follow.  Each
step gets a line number.  Decisions are controlled by jumping to
different "line numbers."  No where in the language was there any notion
of or ability to make your program remotely abstract.  You know those
jokes on slashdot.org that read:

1. Do something
2. Do something else
3. Wash 
4. Repeat (goto step #1) 

That is BASIC in a nut shell.   Sure, modern versions have gotten a
little better, dispensing of evils such as line numbers and the like,
but they are only marginally better.

Each language carries with it a philosophy.  BASIC stands alone in being
so utterly perverse that learning it will render you completely
unmarketable, except as a basic programmer, as you unlearn its
limitations and learn how to think in the abstractions of every other
language.  

If you want to learn how to program, Python is a good start.  IIRC,
Python started its life as ABC, a language designed specifically as an
educational language.  In this sense alone it is similar to BASIC, but
this is where any similarity ends.

Perhaps I can best illustrate the difference between the two with an
analogy.  Suppose you came to me and asked which was a better way of
learning a foreign language, the python way or the BASIC way.  

The Python way would be how a language is taught in any normal class you
might find at a local college.  You learn the vocabulary, grammar,
history and culture of the language.

Now let us provide a contrast.  Imagine you are in a class and the
teacher only teaches you curse words.  You learn no grammar, no history,
no culture.  At best, you have only the slightest idea of what kind of
curse word each is (scatological, sexual, religious, etc.)  But you are
forced to memorize the same list of curse words over and over again in
order.  This is the BASIC way of learning to program.  

Don't do it, unless your goal is simply to embarrass and insult 
programmers.  



Adam DePrince 


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


regular expression for javadoc style comment

2004-12-16 Thread Alessandro Crugnola
Hi all,
i need to use a regular expression to match javadoc style comments in a file,
something like
/**
 * Constructs a new Call instance.
 *
 * @param object the object the Function shall be executed on
 * @param func the Function that shall be executed
 * @throws IllegalArgumentException if neigther the object or the 
function is not available.
 */
i'm finiding many difficulties to write a valid regular expression
ale
--
http://mail.python.org/mailman/listinfo/python-list


Re: Adding paths to sys.path permanently, and another problem...

2004-12-16 Thread Brian van den Broek
Jeff Shannon said unto the world upon 2004-12-16 17:54:
Amir Dekel wrote:
2. os.path.expanduser("~") always gives me "C:\\" instead of my 
homepath. I have tried to change my homepath in WinXP using set 
homepath(in command line), and alsaw using the "Environment Variables" 
in WinXP system properties, non helped. I really have to fix this 
somehow.

Well, according to os.path.expanduser()'s docstring, it uses the $HOME 
environment variable to determine how to expand ~.  I don't know what's 
standard on Windows, but I tried checking for a $HOME and found none.  
Here's (a slightly redacted copy of) what I *do* find (Win2K):

Judging from this, I think that os.environ['USERPROFILE'] seems like it 
may do what you want, though os.environ['APPDATA'] might be useful as 
well.  Of course, if you're trying to get something to work 
cross-platform, things may be more difficult -- but that's because 
Windows doesn't normally use ~ so its use is not supported very well.  
You may be able to create a $HOME that's equivalent to $USERPROFILE...

Jeff Shannon
Technician/Programmer
Credit International
Hi all,
some 'nix-world tool (probably xemacs) that I put on my WinMe box didn't 
like the lack of a HOME environment variable, either. This was easily 
solved by adding the line

SET HOME=D:\HOME
to my autoexec.bat file. (I don't know if this works in more recent 
versions of Windows, but I'd imagine so.) There to, I have added a line

SET PYTHONPATH=D:\List_Of_Dirs;D:\Use_a_semi_colon_to_sep_items_on_Win
Which puts those dirs into sys.path (at the front, I believe). I also 
used the .pth file trick because they two means differ as to where in 
the sys.path they add their entries.

Best to all,
Brian vdB
--
http://mail.python.org/mailman/listinfo/python-list


Re: Socket being garbage collected too early

2004-12-16 Thread David Bolen
Scott Robinson <[EMAIL PROTECTED]> writes:

> I have been having trouble with the garbage collector and sockets.

Are you actually getting errors or is this just theoretical?

> Unfortunately, google keeps telling me that the problem is the garbage
> collector ignoring dead (closed?) sockets instead of removing live
> ones.  My problem is
> 
> 
>   x.sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
>   do_stuff(x.sock)
> 
> 
> def do_stuff(sock):
>   sock_list.append(sock)
> 
> once do_stuff finishes, x.sock disappears, and I can only believe it
> is being garbage collected.

Can you clarify this?  What do you mean by "x.sock" disappears?  Are
you getting a NameError later when trying to use "x.sock"?  

x.sock is just a name binding, so it is not really involved in garbage
collection (GC applies to the objects to which names are bound). 

In this case, you need to include much more in the way of code (a
fully running, but smallest possible, snippet of code would be best),
since the above can be interpreted many ways.  At the least, it's very
important to include information about the namespace within which
those two code snippets run if anyone is likely to be able to give you
a good answer.  Also, being very precise about the error condition you
are experiencing (including actual error messages, tracebacks, etc...)
is crucial.

Is 'x' referencing a local or global object, and does that socket code
occur within a method, a function, or what?  Also, in do_stuff, where
is sock_list defined?  Is it local, global?

If, as written, sock_list is a local name to do_stuff, then that
binding is going to disappear when do_stuff completes, thus, the list
to which it is bound will be destroyed, including all references to
objects that the list may contain.  So at that point, when you return
from do_stuff, the only reference to the socket object will be in
x.sock.  But if 'x' is also local to the function/method where the
call to do_stuff is, the name binding will be removed when the
function/method returns, at which point there will be no references to
the socket object, and yes, it will be destroyed.

But if sock_list is global, and continues to exist when do_stuff
completes, then the reference it contains to the socket will keep the
socket object alive even if you remove the x.sock binding.

-- David

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


Re: Python IDE

2004-12-16 Thread Dan Perl

"Mike Meyer" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> "Dan Perl" <[EMAIL PROTECTED]> writes:
>
>> "Mike Meyer" <[EMAIL PROTECTED]> wrote in message
>> news:[EMAIL PROTECTED]
>>> A: What's the most obnoxious thing on Usenet?
>>> Q: topposting.
>>
>> What is "Jeopardy", Alex?  You got your Q&A mixed up.
>
> No, the Q&A in that order demonstrate what's wrong with top posting.
>
> -- 
> Mike Meyer <[EMAIL PROTECTED]> http://www.mired.org/home/mwm/
> Independent WWW/Perforce/FreeBSD/Unix consultant, email for more 
> information.
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

Yeah, you're right. 


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


Re: Python IDE

2004-12-16 Thread JanC
Mike Meyer schreef:

> There was a group that made a living porting GCC to vender-specific
> hardware platforms,

Cygnus.

-- 
JanC

"Be strict when sending and tolerant when receiving."
RFC 1958 - Architectural Principles of the Internet - section 3.9
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Winge IDE Issue - an suggestions?

2004-12-16 Thread David Bolen
Mike Thompson  writes:

(...)
> WingIDE bug seemed the only explanation, although it was puzzling me
> that something so obvious could make it through their QA. Thanks again.

I haven't used ElementTree, but if it includes an extension module
(likely for performance), it's important to realize that WingIDE's
debugger specifically catches exceptions that occur on the "far" side
of an extension module.  So even if that extension module would
normally suppress the exception, thus hiding it from the original
Python code that called the extension module, Wing's debugger will
stop at it, which is different than normal runtime.

This can actually be very helpful, since for example, debuggers that
can't do this can't stop on exceptions in cases such as wxPython event
handlers, since they occur from within a C extension too.

Wing has a bunch of default locations that it ignores (that would
otherwise trigger via normal standard library calls), but for your own
applications or libraries, you need to teach it a bit, by asking it to
ignore locations you know not to be relevent to your code.  Once you
mark such a location, it is remembered in your project so it won't
bother you again.

This was discussed a bit more in depth recently in the "False
Exceptions" thread on this group.  See:

http://groups-beta.google.com/group/comp.lang.python/browse_frm/thread/f996d6554334e350/e581bea434d3d248

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


Re: Python IDE

2004-12-16 Thread Mike Meyer
"Dan Perl" <[EMAIL PROTECTED]> writes:

> "Mike Meyer" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
>> A: What's the most obnoxious thing on Usenet?
>> Q: topposting.
>
> What is "Jeopardy", Alex?  You got your Q&A mixed up.

No, the Q&A in that order demonstrate what's wrong with top posting.

  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: BASIC vs Python

2004-12-16 Thread Mike Meyer
"Philippe C. Martin" <[EMAIL PROTECTED]> writes:

>>>and it was the only interpreter I've ever used that had no compilation
>>>phase whatsoever) is no easier to deal with than compiled C. Ditto for
>>>the various flavors of LISP I've worked with.
> I do find working with an interpreter easier than with a compiler.  A _long_ 
> time ago, I recall a boss telling me that I should write 5 lines of C a day 
> and compile/debug them twice at most (since it was so slow to get the stuff 
> compiled/linked anyway).

Have you tried working with an interpreter without an interactive mode?

And if your compiled code takes more than a few seconds to build the
program, then somethings wrong. Either your files are to big, or your
build system sucks.

> _one_ of the reasons why I intend to stick with python is because it's 
> interpreted/interactive

I still wish it had a compiler. My favorite work environment ever was
a Scheme system coupled with emacs. I'd write functions in emacs, ship
them to schem for instant evaluation and run a test. When I was done,
I'd compile the results to get a nice, fast binary. I've got all that
in Python, except the compiler.

 http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Accessing DB2 with Python

2004-12-16 Thread Grumman
Jarek Zgoda wrote:
Be aware, that it's a module for "normal" DB2, not a DB2/400. To access 
DB2/400 you have to use ClientAccess ODBC (from Windows or *nix 
platform) driver or iSeries port of Python (from AS/400).


And just to be complete, under windows, using win32all, you can also use 
the OLE DB driver supplied with ClientAccess (IBMDA400), which offers 
some improvements over plain ODBC.

Its been a long time since I did this, but it was *very* simple. I
could probably dig up an example or two if necessary.
Connection string basically looks like:
Provider=IBMDA400;User ID=USERNAME;Password=PASSWORD;Initial 
Catalog=DATABASE_NAME;Data
Source=AS_400_SERVER_NAME

Provider,User ID, Password, and Data Source are required. Data Source 
can be either an IP address, or a DNS defined hostname. I've never 
bothered with 'Initial Catalog', but it would be one of the database
names visible via WRKDBR. (Usually defaults to the default system name,
which is shipped set to the system serial#)

Optionally, you can add 'Catalog Library List=Lib1 Lib2 Lib3' to add
additional libraries to the current library list for the connection.
Last I knew, there were a few methods exposed by ADO that weren't 
supported via this driver, but like I said, its been a long time.

I'm sure there's a pretty complete python ADO wrapper out there as well.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python IDE

2004-12-16 Thread Dan Perl

"Mike Meyer" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> A: What's the most obnoxious thing on Usenet?
> Q: topposting.

What is "Jeopardy", Alex?  You got your Q&A mixed up.

So what, just because I wrote at the top of the posting you couldn't see my 
warning sign for the sarcasm impaired?

Dan 


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


Re: BASIC vs Python

2004-12-16 Thread Philippe C. Martin
>>and it was the only interpreter I've ever used that had no compilation
>>phase whatsoever) is no easier to deal with than compiled C. Ditto for
>>the various flavors of LISP I've worked with.


I do find working with an interpreter easier than with a compiler.  A _long_ 
time ago, I recall a boss telling me that I should write 5 lines of C a day 
and compile/debug them twice at most (since it was so slow to get the stuff 
compiled/linked anyway).

_one_ of the reasons why I intend to stick with python is because it's 
interpreted/interactive

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


wxPython question

2004-12-16 Thread Jive
How the heck do you set the icon on a frame using a .ico file, or a .bmp
file, or whatever?  How do you find out how to do something like that?
Apparently there is no documentation to speak of.  I tried looking the in
the demo program, but I didn't find the secret..



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


Re: Python IDE

2004-12-16 Thread Mike Meyer
A: What's the most obnoxious thing on Usenet?
Q: topposting.

"Dan Perl" <[EMAIL PROTECTED]> writes:
> "fuzzylollipop" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
>> no it was a sideways remark at all the software socialists that thing
>> EVERYTHING should be free, never said anything about Eclipse, just the
>> people that insist ALL software should be free.
> Interesting.  I've never met anyone like that.  If they are in high tech, 
> they must be hardware people, otherwise how would they make a living?  And 
> I'm not sure "socialists" is the correct term in this case, it sounds to me 
> more like "communists".  Or "liberals" for our friends in the US.

I have. They make a living supporting free software. Take a look at
www.zope.com and www.zope.org for an example (to be clear, I am *not*
claiming that the folks at zope believe that all software should be
free. Merely that they make a living off software they give away for
free.) There have been other examples of such before. There was a
group that made a living porting GCC to vender-specific hardware
platforms, one condition being that the port wound up in the GCC
suite. I believe they got bought by redhat.

Phillip Greenspun once ran a company on this model as well. It did
well until the venture capatalists took it over. You can read his
views on software pricing at http://philip.greenspun.com/research/software-pricing >.

  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Socket being garbage collected too early

2004-12-16 Thread Mike Meyer
Scott Robinson <[EMAIL PROTECTED]> writes:

> I have been having trouble with the garbage collector and sockets.
> Unfortunately, google keeps telling me that the problem is the garbage
> collector ignoring dead (closed?) sockets instead of removing live
> ones.  My problem is
>
>
>   x.sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
>   do_stuff(x.sock)
>
>
> def do_stuff(sock):
>   sock_list.append(sock)
>
>
> once do_stuff finishes, x.sock disappears, and I can only believe it
> is being garbage collected.  I'd like to hear the standard means for
> avoiding this issue (gc appears to have only the interface to declare
> something garbage, not to declare something not garbage).

The code as shown doesn't work:

 >> import socket
 >> def do_stuff(sock):
 ..   sock_list.append(sock)
 .. 
 >> sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
 >> do_stuff(sock)
Traceback (most recent call last):
  File "", line 1, in ?
  File "", line 2, in do_stuff
NameError: global name 'sock_list' is not defined
 >> 

If you add "sock_list = []" just before the def of do_stuff, the code
will work, and your sockets won't get garbage collected.

   http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python IDE

2004-12-16 Thread Mike Meyer
A: What's the most obnoxious thing on Usenet?
Q: topposting.

"Dan Perl" <[EMAIL PROTECTED]> writes:
> "fuzzylollipop" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
>> no it was a sideways remark at all the software socialists that thing
>> EVERYTHING should be free, never said anything about Eclipse, just the
>> people that insist ALL software should be free.
> Interesting.  I've never met anyone like that.  If they are in high tech, 
> they must be hardware people, otherwise how would they make a living?  And 
> I'm not sure "socialists" is the correct term in this case, it sounds to me 
> more like "communists".  Or "liberals" for our friends in the US.

I have. They make a living supporting free software. Take a look at
www.zope.com and www.zope.org for an example (to be clear, I am *not*
claiming that the folks at zope believe that all software should be
free. Merely that they make a living off software they give away for
free.) There have been other examples of such before. There was a
group that made a living porting GCC to vender-specific hardware
platforms, one condition being that the port wound up in the GCC
suite. I believe they got bought by redhat.

Phillip Greenspun once ran a company on this model as well. It did
well until the venture capata


-- 
Mike Meyer <[EMAIL PROTECTED]>  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: create lowercase strings in lists - was: (No subject)

2004-12-16 Thread Mike Meyer
Steve Holden <[EMAIL PROTECTED]> writes:

> Mark Devine wrote:
>
>> Actually what I want is element 'class-map match-all cmap1' from list 1 to 
>> match 'class-map cmap1 (match-all)' or 'class-map cmap1 mark match-all done' 
>> in list 2 but not to match 'class-map cmap1'.
>> Each element in both lists have multiple words in them. If all the words of 
>> any element of the first list appear in any order within any element of the 
>> second list I want a match but if any of the words are missing then there is 
>> no match. There are far more elements in list 2 than in list 1.
>>
> Well since that's the case it would seem you'd be best processing each
> item from the large list against the small list, though in truth it
> may not make any difference.
>
> It looks like the best way to proceed might be to reduce each line to
> a canonical form -- strip the parens and other irrelevant characters
> out, and sort the words in order. After that it'd be relatively simple
> to determine whether two lines match - they'd be the same!

No, that doesn't work. What happens if an element of the second list
has *more* words than the element in the first list? In that case, the
two canonical forms would be different, but it should still be a
match.

How about this (If I had sample data, I'd try it out directly...):

Create a dictionary of sets. For each word in an element in the small
list, insert into the set indexed by that word in the dictionary a
tuple version of the list (you'll want to create the tuples in
advance, and associate them with each list somehow).

Then go through the long list, and for each element collect all the
sets that are indexed by the words in that element, and take the
intersection of them all. If there are any tuples in the intersection,
then you have a match.

   http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: BASIC vs Python

2004-12-16 Thread Mike Meyer
"Thomas Bartkus" <[EMAIL PROTECTED]> writes:

> The "interpreted" nature of the existing Python language has little to do
> with how it compares to other languages.  Most languages, including BASIC,
> are available in either flavor - interpreted or compiled. And either way,
> it's still the same language.  That being said, one would expect an
> interpreted language (like Python!) to be a bit more approachable for
> beginners.  The mechanics of producing a working program are just simpler
> when the language is interpreted, no matter what that language might be.

On what basis do you think the mechanics of producing a working
language are easier because the language is interpreted? My experience
is that interpreted C (yes, I really did work with a C interpreter -
and it was the only interpreter I've ever used that had no compilation
phase whatsoever) is no easier to deal with than compiled C. Ditto for
the various flavors of LISP I've worked with.

Now, having an interactive environment with a REPL makes learning the
language and checking things a lot easier. Those tend to be rare for
compiled languages. But interpreted languages don't necessarily have
them, as witnessed by Java and Perl. You have to get your REPL as a
third party package for those languages.

http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Html or Pdf to Rtf (Linux) with Python

2004-12-16 Thread Stephen Thorne
On Thu, 16 Dec 2004 19:30:37 + (UTC), Axel Straschil
<[EMAIL PROTECTED]> wrote:
> > That's easy. Load the HTML in MS Word, and save it as RTF. Script it
> > via COM using the python win32all (I think that's what it's now
> > called) package.
> 
> As I wrote in my posting and the subject: linux ;-)
> I could try to do this with open office, by I'm afraid this will not
> be a performant solution ;-(
> I realy was spending hour's on that, the only thing I found was a
> spezifikation for reach text, maybe a good point to start a project ...

I've been able to successfully get konqueror to generate a pdf from a
html file via dcop. It's something along the lines of:
% dcop konqueror-25827 html-widget1 print 1
You can launch konq in a xvfb (X Virtual Framebuffer) then communicate
via dcop to send commands to the browser (load this url, print this
page, etc).

I've been investigating doing the same feat using JS/XUL/etc in
mozilla. It probably is possible. There's lots of documentation about
the XPCOM api available from http://xulplanet.com/

As for converting to RTF, someone has already pointed out PyRTF.

Regards,
Stephen Thorne
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: create lowercase strings in lists - was: (No subject)

2004-12-16 Thread Michael Spencer
Steve Holden wrote:
Mark Devine wrote:
Actually what I want is element 'class-map match-all cmap1' from list 
1 to match 'class-map cmap1 (match-all)' or 'class-map cmap1 mark 
match-all done' in list 2 but not to match 'class-map cmap1'.
Each element in both lists have multiple words in them. If all the 
words of any element of the first list appear in any order within any 
element of the second list I want a match but if any of the words are 
missing then there is no match. There are far more elements in list 2 
than in list 1.
 

sounds like a case for sets...
 >>> # NB Python 2.4
 ...
 >>> # Test if the words of list2 elements appear in any order in list1 elements
 >>> # disregarding case and parens
 ...
 >>> # Reference list
 >>> list1 = ["a b C (D)",
 ...   "D A B",
 ...   "A B E"]
 >>> # Test list
 >>> list2 = ["A B C D", #True
 ...   "A B D",  #True
 ...   "A E F",  #False
 ...   "A (E) B",#True
 ...   "A B",   #True
 ...   "E A B" ]
 ...
 >>> def normalize(text, unwanted = "()"):
 ... conv = "".join(char.lower() for char in text if char not in unwanted)
 ... return set(conv.split())
 ...
 >>> reflist = [normalize(element) for element in list1]
 >>> print reflist
 ...
[set(['a', 'c', 'b', 'd']), set(['a', 'b', 'd']), set(['a', 'b', 'e'])]
This is the list of sets to test against
 >>> def testmember(element):
 ... """is element a member of the reflist, according to the above rules?"""
 ... testelement = normalize(element)
 ... #brute force comparison until match - depends on small reflist
 ... for el in reflist:
 ... if el.issuperset(testelement):
 ... return True
 ... return False
 ...
 >>> for element in list2:
 ... print element, testmember(element)
 ...
A B C D True
A B D True
A E F False
A (E) B True
A B True
E A B True
 >>>
Michael
--
http://mail.python.org/mailman/listinfo/python-list


Re: Adding paths to sys.path permanently, and another problem...

2004-12-16 Thread Fernando Perez
Amir Dekel wrote:

> Hi everyone,
> 
> I have two problems:
> 
> 1. How can I keep my changes in sys.path after closing the interpreter?

As others said, use $PYTHONPATH

> 2. os.path.expanduser("~") always gives me "C:\\" instead of my
> homepath. I have tried to change my homepath in WinXP using set
> homepath(in command line), and alsaw using the "Environment Variables"
> in WinXP system properties, non helped. I really have to fix this somehow.

This is what ipython uses to try and get that information in a portable manner. 
Note that it uses _winreg, which is part of the win32 extensions.

In [1]: import IPython.genutils

In [2]: psource IPython.genutils.get_home_dir
def get_home_dir():
"""Return the closest possible equivalent to a 'home' directory.

For Posix systems, this is $HOME, and on NT it's $HOMEDRIVE\$HOMEPATH.

Currently only Posix and NT are implemented, a HomeDirError exception is
raised for all other OSes. """ #'

if os.name == 'posix':
return os.environ['HOME']
elif os.name == 'nt':
# For some strange reason, win9x returns 'nt' for os.name.
try:
return os.path.join(os.environ['HOMEDRIVE'],os.environ['HOMEPATH'])
except:
try:
# Use the registry to get the 'My Documents' folder.
import _winreg as wreg
key = wreg.OpenKey(wreg.HKEY_CURRENT_USER,
   
"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell
Folders")
homedir = wreg.QueryValueEx(key,'Personal')[0]
key.Close()
return homedir
except:
return 'C:\\'
elif os.name == 'dos':
# Desperate, may do absurd things in classic MacOS. May work under DOS.
return 'C:\\'
else:
raise HomeDirError,'support for your operating system not implemented.'

HTH,

f

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


Re: Why are tuples immutable?

2004-12-16 Thread Jeff Shannon
Antoon Pardon wrote:
Op 2004-12-16, Jeff Shannon schreef <[EMAIL PROTECTED]>:
 


nevermind the fact that I can't think of a case where I'm 
likely to "retrieve" a key from a dict, modify it, and then put it 
back.  (I can think of endless cases where I'd want to do that with 
*values*, but not with keys...)
   

Well neither can I, but yet the fact that lists are mutable and tuples
are not, is frequently presented as reason why tuples are allowed as
keys and tuples are not.
 

True -- in much the same way that the inability to see is why sighted 
people are allowed to get driver's licenses and blind people are not.  
The fact of mutability makes an object very poorly suited for use as a 
dict key, and therefore allowing them to be used as dict keys would be a 
dangerous thing.  I'm sure that, with careful guidance and supervision, 
a blind person could manage to operate a motor vehicle, but no matter 
how high my regard for that blind person was I'd be a bit hesitant to 
give them my car keys for a quick trip to the corner store...

(And if dicts were somehow changed so that keys were copied when added 
to a dict, just so that every once in a while someone might be able to 
avoid a few conversions to/from tuple, then you're adding the overhead 
of an object copy to *every* dict insertion, thus slowing down (possibly 
by a significant amount) a large proportion of Python operations.  How 
is that a gain?)
   

Well will look at two scenario's. In each we will work with mutable
objects that we would like to use a keys. In the first we transform
them into an immutable object, in the second we just allow mutables to
be inserted as keys, but insert a copy of the key instead of the key
itself in order to protect the programmer somewhat from mutating
dictionary keys.
Now in scenario one we will have a lot more copies then in scenario
two, because each time we want to use an object as a key we will
first have to transform it into an immutable. That means every
addition to the dictionary as well as every key access and each
such transform means a copy.
In scenario two we will only make a copy when a key is added to
the dictionary, we don't need to make copies with key accesses.
I think scenario two is a performance gain over scenario one.
 

Except that Python uses dicts internally, quite heavily.  Much of the 
speed gains of recent versions of Python have reportedly come 
specifically due to extensive and impressive optimization of 
dictionaries.  Forcing an (extra) object copy every time a variable name 
is bound (or rebound) would be hell on Python's performance across the 
board, not just in those rare cases where someone thinks that they'd 
benefit from using a mutable object as a key.

(And I have to reiterate, here, that I have *never* felt it a hardship 
to be unable to use lists as dictionary keys; it's just never come up 
that the data that I had in a list was something that I wanted to use 
as-is for a dict key, and I can't think of a situation where it *would* 
happen.  What you're saying, essentially, is that for the sake of one 
form of aesthetic purity with no significant practical benefits, we 
should break another form of aesthetic purity with massive practical 
benefits.)

Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list


Re: Html or Pdf to Rtf (Linux) with Python

2004-12-16 Thread Mike Meyer
Axel Straschil <[EMAIL PROTECTED]> writes:

> Hello!
>
>> That's easy. Load the HTML in MS Word, and save it as RTF. Script it
>> via COM using the python win32all (I think that's what it's now
>> called) package.
> As I wrote in my posting and the subject: linux ;-)
> I could try to do this with open office, by I'm afraid this will not
> be a performant solution ;-(
> I realy was spending hour's on that, the only thing I found was a
> spezifikation for reach text, maybe a good point to start a project ...

Sorry. I forgot the original subject.

You might take a look at PyRTF in PyPI. It's still in beta,
though. But it might be enough that coupled with the HTMLParser.py to
get you where you need to go.

  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Socket being garbage collected too early

2004-12-16 Thread Steve Holden
Scott Robinson wrote:
I have been having trouble with the garbage collector and sockets.
Unfortunately, google keeps telling me that the problem is the garbage
collector ignoring dead (closed?) sockets instead of removing live
ones.  My problem is
x.sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
do_stuff(x.sock)
def do_stuff(sock):
sock_list.append(sock)
once do_stuff finishes, x.sock disappears, and I can only believe it
is being garbage collected.  I'd like to hear the standard means for
avoiding this issue (gc appears to have only the interface to declare
something garbage, not to declare something not garbage).
Scott Robinson
Unfortunately, assuming it's being garbage collected might turn out to 
be incorrect. What evidence do you have that the socket "disappears"? Do 
you get a segmentation ault, or what?

If the socket simply fails to work that would be a different case 
altogether, but it seems to me that we need a bit more evodence that the 
anecdotal stuff you've provided so far.

Quite apart from anything else, by the way, the code you posted appears 
to use a global sock_list. A reference b y that list would in any case 
stop the socket from being garbage collected (quite apart from the fact 
that the socket module itself will do so as long as the socket is open).

So, could we see an error message, or some other evidence of what is 
going on. For example, after the call to do_stuff(), what do you see if you

print sock_list
for example. I think your initial hypothesis is insufficient.
regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why are tuples immutable?

2004-12-16 Thread Jeff Shannon
Adam DePrince wrote:
And how exactly do you propose to mutate an object without changing its
hash value?
* Create this mutate-able object type.  
* Create two objects that are different with different hash values.
* Mutate one so that it is the same as the other.
* Compare their hash values.  

If the hash values are the same, you lose because you didn't keep your
original promise.
If the hash values are different then you just broke your object because
two objects with the same value must have the same hash value, but yours
are different.
 

Correct me if I'm wrong, here, but I believe that what you're saying 
here (and my vague memories of the little bit that I've read about 
hashes) is that, for a well-behaved hash function, then A == B should 
imply that hash(A) == hash(B).  (The reverse is *not* true, however -- 
hash(A) == hash(B) does not necessarily say anything about whether A == B.)

If that is a correct condition for a well-behaved hash function, then it 
is indeed impossible to have a well-behaved hash function that can be 
useful in the face of object mutation.  For something like a list, one 
can only define a poorly-behaved hash-like function.

To take another approach -- given some function that allows lists to 
(pretend to be) hashable:

.>>> key = [1,2]
.>>> d[key] = 'foo'
.>>> d[[1,2]]

.>>> key.append(3)
.>>> d[key]
???
.>>>
As I understand it, it is impossible for there to be a hash function for 
which both of these cases can return the same object.  For most uses of 
dicts, it is necessary that the first case be valid -- a dict isn't 
going to be very useful to me if I have to pass around all of the 
objects used as keys in order to access it. Equality-based hashes are 
necessary, so the second case must then be disallowed.

But isn't it a bit nonsensical that, without ever rebinding key, one can 
do something like

.>>> d[key] = 'foo'
.>>> frombulate(key)
.>>> d[key]
Traceback (most recent call last):
 File "", line 1, in ?
KeyError: key
.>>>
In order to maintain the logical consistency that if an object is used 
as a dict key, that same object should reasonably be expected to 
retrieve the same value, identity-based hashes are necessary.  As a 
result, the first option must be disallowed.

In either case, if it's ever possible for equality to change while 
identity doesn't, then somewhere along the lines one of the core 
requirements, the contract if you will, of a dictionary *must* be 
broken.  And while it may be possible to get away with breaking that 
contract some of the time (by postulating, for example, that if one 
mutates a dict key then things will break), this will result in more 
bugs and more confusion over time.  There is no way for Python to be 
able to behave consistently in the face of mutable dict keys, therefore 
("In the face of ambiguity, refuse the temptation to guess.") Python 
declines the temptation of making it trivial to use mutable objects as 
dict keys.

Jeff Shannon
Technician/Programmer
Credit International

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


Re: ".>>>" is a good idea! (OT, was: Re: do you master list comprehensions?)

2004-12-16 Thread Fernando Perez
Kent Johnson wrote:

> Keith Dart wrote:
>> What I do is set Python's sys.ps1 variable to something else. I have a
>> module called "interactive" that I import implicitly by shell alias:
>> 
>> py='python -i -c '\''import interactive'\'
>> 
>> Which, among other things, sets the prompt to "Python> "
> 
> You can do the same thing using a PYTHONSTARTUP file - see
> http://docs.python.org/tut/node4.html#SECTION00424
> 
> You can change the prompts with
> import sys
> sys.ps1 = ' >>> '
> sys.ps2 = ' ... '



You might want to look at ipython:

http://ipython.scipy.org,

which provides you automatically with these prompts:

In [1]: for i in range(2):
   ...: print i,
   ...:
0 1

In [2]: 99*2
Out[2]: 198

In [3]: _2+1
Out[3]: 199

As a curiosity, ipython was actually born as a sys.ps1/2 hack, by assigning to
these objects whose __repr__ would give numbered prompts with results caching. 
These days it's a full-blown pure python interpreter, not a $PYTHONSTARTUP
customization anymore, but it's an interesting little historical curiosity. 
Especially if you start going very far with interactive customizations, you
might not want to rewrite all of ipython's 15K lines of code :)



Cheers,

f

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


Re: Adding paths to sys.path permanently, and another problem...

2004-12-16 Thread Amir Dekel
Jeff Shannon wrote:
Amir Dekel wrote:
2. os.path.expanduser("~") always gives me "C:\\" instead of my 
homepath. I have tried to change my homepath in WinXP using set 
homepath(in command line), and alsaw using the "Environment Variables" 
in WinXP system properties, non helped. I really have to fix this 
somehow.

Judging from this, I think that os.environ['USERPROFILE'] seems like it 
may do what you want, though os.environ['APPDATA'] might be useful as 
well.  Of course, if you're trying to get something to work 
cross-platform, things may be more difficult -- but that's because 
Windows doesn't normally use ~ so its use is not supported very well.  
You may be able to create a $HOME that's equivalent to $USERPROFILE...

Yet another reason not to use Windows and all it's silly system... 
Unfotunely, I am stuck with a USB ADSL modem on a family computer, which 
led to terrible headaches with my (quiet successful, actually) attempts 
to install Linux.

Well, so be it...
--
http://mail.python.org/mailman/listinfo/python-list


Re: Redirecting stdin, stdout, and stderr to a window

2004-12-16 Thread Michael Fuhr
Michael McGarry <[EMAIL PROTECTED]> writes:

> How do I redirect stdin, stdout and stderr to a window? I am using Qt 
> for GUI.

I don't know what specific mechanisms Qt provides, but the general
solution is to write a class that implements I/O methods like read,
readline, and write, and assign instances of that method to the
input and output filehandles.  For example, you could write a class
with a write() method that displays text in a window, then assign
an instance of that class to sys.stdout.  Subsequent calls to 'print'
would send output to the window.

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why no list heritable type?

2004-12-16 Thread Mike Meyer
"Robert Brewer" <[EMAIL PROTECTED]> writes:

>> Why aren't built 
>> in lists and dictionaries real heritable types that can save 
>> this kind of patchwork?
>
> They are since Python 2.2 (IIRC):

And before Python 2.2 there was the UserList class in the standard
library. Which is still there in 2.4. Shouldn't it be depreciated by
this point?

   http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Socket being garbage collected too early

2004-12-16 Thread Scott Robinson
I have been having trouble with the garbage collector and sockets.
Unfortunately, google keeps telling me that the problem is the garbage
collector ignoring dead (closed?) sockets instead of removing live
ones.  My problem is


x.sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
do_stuff(x.sock)


def do_stuff(sock):
sock_list.append(sock)


once do_stuff finishes, x.sock disappears, and I can only believe it
is being garbage collected.  I'd like to hear the standard means for
avoiding this issue (gc appears to have only the interface to declare
something garbage, not to declare something not garbage).

Scott Robinson

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


Re: lies about OOP

2004-12-16 Thread Jeff Shannon
Peter Hansen wrote:
P.S.: I'm only half Danish, but the other half is from
a particularly bloodthirsty line of Canadians.

I thought it was physically impossible for Canadians to be bloodthirsty 
outside of hockey games... ;)

Jeff Shannon
Technician/Programmer
Credit International

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


Re: Module question

2004-12-16 Thread Jeff Shannon
Simon Brunning wrote:
On Wed, 15 Dec 2004 18:10:40 -0800, Jeff Shannon <[EMAIL PROTECTED]> wrote:
 

The difference being that when Excel opens up a *.CSV, it goes through
the import wizard.
   

Are you sure that's true? When I open a *.csv file, Excel *appears* to
open it without running any kind of wizard. Certainly I don't see any
wizard dialogues.
 

You're right, my mistake -- I was thinking of tab-delimited *.txt files, 
which I deal with far more often than I do *.csv ... 

Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python IDE

2004-12-16 Thread Dan Perl
Interesting.  I've never met anyone like that.  If they are in high tech, 
they must be hardware people, otherwise how would they make a living?  And 
I'm not sure "socialists" is the correct term in this case, it sounds to me 
more like "communists".  Or "liberals" for our friends in the US.

;-)  (for the sarcasm challenged)

Dan

"fuzzylollipop" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> no it was a sideways remark at all the software socialists that thing
> EVERYTHING should be free, never said anything about Eclipse, just the
> people that insist ALL software should be free.
> 


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


Re: Adding paths to sys.path permanently, and another problem...

2004-12-16 Thread Jeff Shannon
Amir Dekel wrote:
2. os.path.expanduser("~") always gives me "C:\\" instead of my 
homepath. I have tried to change my homepath in WinXP using set 
homepath(in command line), and alsaw using the "Environment Variables" 
in WinXP system properties, non helped. I really have to fix this 
somehow.

Well, according to os.path.expanduser()'s docstring, it uses the $HOME 
environment variable to determine how to expand ~.  I don't know what's 
standard on Windows, but I tried checking for a $HOME and found none.  
Here's (a slightly redacted copy of) what I *do* find (Win2K):

>>> for key, val in os.environ.items():
... print '%15s   %s' % (key, val)
...
   TMP   C:\DOCUME~1\Jeff\LOCALS~1\Temp
  USERNAME   jeff
  COMPUTERNAME   ##
   LOGONSERVER   ##
   COMSPEC   C:\WINNT\system32\cmd.exe
USERDOMAIN   ###
COMMONPROGRAMFILES   C:\Program Files\Common Files
PROCESSOR_IDENTIFIER   x86 Family #...
  PROGRAMFILES   C:\Program Files
PROCESSOR_REVISION   0806
   PATHEXT   .COM;.EXE;.BAT;.CMD;#
SYSTEMROOT   C:\WINNT
  PATH   C:\Python22\.;C:\WINNT\system32;C:\WINNT;##
   APPDATA   C:\Documents and Settings\Jeff\Application Data
  TEMP   C:\DOCUME~1\Jeff\LOCALS~1\Temp
 HOMEDRIVE   C:
   SYSTEMDRIVE   C:
PROCESSOR_ARCHITECTURE   x86
NUMBER_OF_PROCESSORS   1
ALLUSERSPROFILE   C:\Documents and Settings\All Users.WINNT
PROCESSOR_LEVEL   6
  HOMEPATH   \
OS2LIBPATH   C:\WINNT\system32\os2\dll;
   USERPROFILE   C:\Documents and Settings\Jeff
OS   Windows_NT
WINDIR   C:\WINNT
>>>

Judging from this, I think that os.environ['USERPROFILE'] seems like it 
may do what you want, though os.environ['APPDATA'] might be useful as 
well.  Of course, if you're trying to get something to work 
cross-platform, things may be more difficult -- but that's because 
Windows doesn't normally use ~ so its use is not supported very well.  
You may be able to create a $HOME that's equivalent to $USERPROFILE...

Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list


Re: GPL and Python modules.

2004-12-16 Thread Scott Robinson
On Mon, 25 Oct 2004 20:13:46 -0700, Robert Kern <[EMAIL PROTECTED]>
wrote:

>Tim Churches wrote:
>> From: [EMAIL PROTECTED] 
>> 
>>>[mailto:[EMAIL PROTECTED]
>>> On Behalf Of Robert Kern
>>>Sent: Tuesday, 26 October 2004 11:34 AM
>>>To: [EMAIL PROTECTED]
>>>Subject: Re: GPL and Python modules.
>>>
>>>
>>>Tim Churches wrote:
>>>
On Tue, 2004-10-26 at 11:12, Robert Kern wrote:
>>>
>Whether just using system calls is simply "normal use" for a GPLd OS
>kernel or this is simply a special exception to the GPL for 
>>>
>>>Linux only 
>>>
>is something that a court will have to decide. But such a 
>>>
>>>suit would 
>>>
>have to be about some other GPL kernel, not Linux.


Looks like it is a special exception for the Linux kernel 
>>>
>>>(or whatever 
>>>
other Linux code is distributed with this COPYING file. 
>>>
>>>Doesn't apply 
>>>
to other GPLed code.
>>>
>>>Well, not necessarily. It certainly isn't phrased as one. It 
>>>is at least 
>>>a statement of someone's (Linus's?) belief that standard applications 
>>>that only use system calls and running on Linux are not 
>>>derivative works 
>>>with respect to Linux.
>> 
>> 
>> Yes, so it is a specific exemption to the GPL granted by the copyright
>> holder(s) of the Linux kernel code. The GPL allows the copyright holder to
>> grant exemptions to the GPL privisions as they see fit - but no-one else.
>
>It's still phrased as Linus's interpretation of what constitutes a 
>derivative work and what constitutes normal use of the GPLed kernel. 
>He's specifically saying that userland applications are not derivative 
>works not "even though they are derivative works, they are excepted from 
>the requirements of this license."
>
>>>Are Windows programs actual derivative 
>>>works of 
>>>the Windows kernel? Does the Windows EULA make a statement about the 
>>>derivative status of applications?
>> 
>> 
>> No, and no. An important point of difference between the world views held
>> by, say, Steve Ballmer and, say, Richard Stallman.
>
>The world views of Ballmer and Stallman are irrelevant to whether 
>something is a derivative or not. They may be relevant to whether one 
>may get sued or not, but that's a different issue.
>
>In any case, Stallman does not appear to believe that userland 
>applications are automatically derivative works of the kernel:
>
>http://www.fsf.org/licenses/gpl-faq.html#GPLInProprietarySystem
>
>"""If the two programs remain well separated, like the compiler and the 
>kernel, or like an editor and a shell, then you can treat them as two 
>separate programs--but you have to do it properly."""

I would be careful in taking legal advise from Richard Stallman.  The
GPL merely states that*:

 2. You may modify your copy or copies of the Program or 
any portion of it, thus forming a work based on the Program,
and copy and distribute such modifications or work under the
terms of Section 1 above, provided that you also meet all of
these conditions:

After that, all notion of "derived work" falls on the appropriate
copyright law of the country in question.  I suspect that following
Stallman's verdicts won't cause you to violate the GPL, but I would
hardly be willing to be certain about going to court over a GPLed
module imported into an unfree python program.

Scott Robinson

* note that I believe that this is fair use.  According to the GPL,
you can only distribute it unmodified.

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


Re: create lowercase strings in lists - was: (No subject)

2004-12-16 Thread Mark Devine
Actually what I want is element 'class-map match-all cmap1' from list 1 to 
match 'class-map cmap1 (match-all)' or 'class-map cmap1 mark match-all done' in 
list 2 but not to match 'class-map cmap1'.
Each element in both lists have multiple words in them. If all the words of any 
element of the first list appear in any order within any element of the second 
list I want a match but if any of the words are missing then there is no match. 
There are far more elements in list 2 than in list 1.
 



Steve Holden <[EMAIL PROTECTED]> wrote:

> 
> Mark Devine wrote:
> 
> > Sorry for not putting a subject in the last e-mail. The function lower 
> > suited my case exactly. Here however is my main problem:
> > Given that my new list is :
> > [class-map match-all cmap1', 'match ip any', 'class-map match-any cmap2', 
> > 'match any', 'policy-map policy1', 'class cmap1', 'policy-map policy2', 
> > 'service-policy policy1', 'class cmap2']
> > 
> > Each element in my new list could appear in any order together within 
> > another larger list (list1) and I want to count how many matches occur. For 
> > example the larger list could have an element 'class-map cmap2 (match any)' 
> > and I want to match that but if only 'class-map match-any' or 'class-map 
> > cmap2' appears I don't want it to match. 
> > 
> > Can anybody help?
> > Is my problem clearly stated?
> > 
> 
> Well, let's see: you'd like to know which strings occur in both lists, 
> right?
> 
> You might like to look at the "Efficient grep using Python?" thread for 
>   suggestions. My favorite would be:
> 
> .>>> lst1 = ["ab", "ac", "ba", "bb", "bc"]
> .>>> lst2 = ["ac", "ab", "bd", "cb", "bb"]
> .>>> dct1 = dict.fromkeys(lst1)
> .>>> [x for x in lst2 if x not in dct1]
> ['bd', 'cb']
> .>>> [x for x in lst2 if x in dct1]
> ['ac', 'ab', 'bb']
> 
> regards
>   Steve
> -- 
> Steve Holden   http://www.holdenweb.com/
> Python Web Programming  http://pydish.holdenweb.com/
> Holden Web LLC  +1 703 861 4237  +1 800 494 3119
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 



_
Sign up for eircom broadband now and get a free two month trial.*
Phone 1850 73 00 73 or visit http://home.eircom.net/broadbandoffer


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


Re: create lowercase strings in lists - was: (No subject)

2004-12-16 Thread Steve Holden
Mark Devine wrote:
Actually what I want is element 'class-map match-all cmap1' from list 1 to match 'class-map cmap1 (match-all)' or 'class-map cmap1 mark match-all done' in list 2 but not to match 'class-map cmap1'.
Each element in both lists have multiple words in them. If all the words of any element of the first list appear in any order within any element of the second list I want a match but if any of the words are missing then there is no match. There are far more elements in list 2 than in list 1.
 
Well since that's the case it would seem you'd be best processing each 
item from the large list against the small list, though in truth it may 
not make any difference.

It looks like the best way to proceed might be to reduce each line to a 
canonical form -- strip the parens and other irrelevant characters out, 
and sort the words in order. After that it'd be relatively simple to 
determine whether two lines match - they'd be the same!

The only slight wrinkle would be keeping the original lines for 
reference, but that's not difficult.

Does this give you enough of an idea, or do you need code samples?
regards
 Steve

Steve Holden <[EMAIL PROTECTED]> wrote:

Mark Devine wrote:

Sorry for not putting a subject in the last e-mail. The function lower suited 
my case exactly. Here however is my main problem:
Given that my new list is :
[class-map match-all cmap1', 'match ip any', 'class-map match-any cmap2', 
'match any', 'policy-map policy1', 'class cmap1', 'policy-map policy2', 
'service-policy policy1', 'class cmap2']
Each element in my new list could appear in any order together within another larger list (list1) and I want to count how many matches occur. For example the larger list could have an element 'class-map cmap2 (match any)' and I want to match that but if only 'class-map match-any' or 'class-map cmap2' appears I don't want it to match. 

Can anybody help?
Is my problem clearly stated?
Well, let's see: you'd like to know which strings occur in both lists, 
right?

You might like to look at the "Efficient grep using Python?" thread for 
 suggestions. My favorite would be:

.>>> lst1 = ["ab", "ac", "ba", "bb", "bc"]
.>>> lst2 = ["ac", "ab", "bd", "cb", "bb"]
.>>> dct1 = dict.fromkeys(lst1)
.>>> [x for x in lst2 if x not in dct1]
['bd', 'cb']
.>>> [x for x in lst2 if x in dct1]
['ac', 'ab', 'bb']
regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


_
Sign up for eircom broadband now and get a free two month trial.*
Phone 1850 73 00 73 or visit http://home.eircom.net/broadbandoffer


--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why no list heritable type?

2004-12-16 Thread Jeremy Bowers
On Thu, 16 Dec 2004 12:53:32 -0800, James Stroud wrote:
> Then it can be heritable and I can add or override methods. Why aren't
> built in lists and dictionaries real heritable types that can save this
> kind of patchwork? Is there a pythonic reason I am missing here?

Along with others pointing out that list *is* inheritable and we don't
quite know what you mean, I'd point out that any object that inherits the
appropriate "magic methods", as described at 
http://python.org/doc/2.4/ref/sequence-types.html
and 
http://python.org/doc/2.4/ref/sequence-methods.html
"is" a list for most things you care about. 

Want to iterate? Implement __iter__, and "for blah in yourObjType:" will
work as you'd want, even for things like trees if you like. Implement
__getitem__ and you get [] working right. 

Python makes matching its "internal protocols" very easy, and you should
definately take advantage of that.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: [ANN] [Hack] Import binary extensions from zipfiles, windows only

2004-12-16 Thread Delaney, Timothy C (Timothy)
Thomas Heller wrote:

> zipextimporter.py contains the ZipExtImporter class which allows to
> load Python binary extension modules contained in a zip.archive,
> without unpacking them to the file system.

I take it this was what you were talking about the other day when you
mentioned single-file applications produced by py2exe ...

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


Re: Why no list heritable type?

2004-12-16 Thread James Stroud
Steve Holden wrote:

> I think the thing you are really missing is the fact that list and the 
> other built-in types can be used as the basis for inheritance:

I've never seen this done in any manual that I can remember. Its so useful, 
that I thought I would have run into it before as an example somewhere, so It 
didn't occur to me that it could be done (too good to be true, even though it 
is obvious, phenomenon), and I never tried it, already /knowing/ the answer.

Thanks everyone for your answers.

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


Re: (No subject)

2004-12-16 Thread Steven Bethard
Jeremy Jones wrote:
Mark Devine wrote:
I'm brand new to python and I was wondering if anybody knew of a easy 
[snip]
You could use string.lower (make sure you "import string"):
string.lower is deprecated in Python 2.4.  Better to go with str.lower 
as Diez B. Roggisch suggested:

commands = [c.lower() for c in commands]
Steve
--
http://mail.python.org/mailman/listinfo/python-list


Re: BASIC vs Python

2004-12-16 Thread Thomas Bartkus
The "interpreted" nature of the existing Python language has little to do
with how it compares to other languages.  Most languages, including BASIC,
are available in either flavor - interpreted or compiled. And either way,
it's still the same language.  That being said, one would expect an
interpreted language (like Python!) to be a bit more approachable for
beginners.  The mechanics of producing a working program are just simpler
when the language is interpreted, no matter what that language might be.

It would be quite a stretch to call Python similar to any of the very many
flavors of BASIC that exist.  So - the answer is no, Python is not similar
to BASIC.

Python is, however, an excellent beginners language. In fact, a serious
programmer with several languages under his belt might actually be at a
disadvantage when learning Python. At least that is my personal experience.

So

Similar to BASIC - no!
Great language for beginning programmers - yes!

Thomas Bartkus

"abisofile" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>
> hi
>
> I'm new to programming.I've try a little BASIC so I want ask since
> Python is also interpreted lang if it's similar to BASIC.
>
>
>


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


Re: newbie: Datetime module for Python 2.2.x

2004-12-16 Thread Jarek Zgoda
Eric Azarcon wrote:
I'm fairly new to Python, and was wondering if someone might be able to
help. I'm doing something that requires the datetime module released in
2.3. Unfortunately, the target machines are running 2.2.x and there is
no easy way that I know of to install 2.3/2.4 (RHEL ES).
I've done some looking around, and located and downloaded a tarball
from Zope that seems to address this, but have no idea how I am to
install this. The file is a datetime.tar.
I've also downloaded the source from Python.org, and have the C source
for datetime. Of course, I have no idea how to compile just that
module. And installing it, if I ever get that far.
Most of DB-API modules use mx.DateTime module and for Python 2.2 this 
one is mos widely used. Go for it to http://www.egenix.com/.

--
Jarek Zgoda
http://jpa.berlios.de/ | http://www.zgodowie.org/
--
http://mail.python.org/mailman/listinfo/python-list


Re: ".>>>" is a good idea! (OT, was: Re: do you master list comprehensions?)

2004-12-16 Thread Steven Bethard
Kent Johnson wrote:
You can do the same thing using a PYTHONSTARTUP file - see 
http://docs.python.org/tut/node4.html#SECTION00424

You can change the prompts with
import sys
sys.ps1 = ' >>> '
sys.ps2 = ' ... '
Very cool.  I didn't know about this.  Does anyone know how to make it 
work with Pythonwin[1]?  (Obviously, I can type the above in manually 
every time, but I'd much rather have Pythonwin do this automatically for 
me.)

Steve
[1] I'd do my example code at the command prompt, but I can't live 
without copy-paste. ;)
--
http://mail.python.org/mailman/listinfo/python-list


Re: cmp of multiple attributes (WAS: Why are tuples immutable?)

2004-12-16 Thread Roy Smith
>Roy Smith wrote:
>> def __cmp__ (self, other):
>>  # I wish there was a less verbose way to do this!
>> if self.block < other.block:
>> return -1
>> if self.block > other.block:
>> return 1
>> if self.lot < other.lot:
>> return -1
>> if self.lot > other.lot:
>> return 1
>> return 0

Steven Bethard  <[EMAIL PROTECTED]> wrote:
>Does this do what you want?
>... def __cmp__(self, other):
>... return (cmp(self.block, other.block) or
>... cmp(self.lot, other.lot))

Yes, that's exactly what I was after.  Like so many things, it's
obvious once it's pointed out to you.  Thanks!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Adding paths to sys.path permanently, and another problem...

2004-12-16 Thread Amir Dekel
Jeff Shannon wrote:
Not only can one modify the environment variable PYTHONPATH, but one can 
also use a .pth file.  Under windows, when the interpreter starts up it 
will search its default sys.path for any files with extension .pth; if 
it finds any, then it will use each line of those files as a directory 
to add to sys.path.  Thus, if you drop a mymodule.pth file in 
site-packages, which contains a list of the directories you're 
interested in, sys.path will automatically be amended for you every time 
Python starts.

Works great! So simple, yet people get so confused...
Do you have a solution for my other problem?
Thanks,
Amir
--
http://mail.python.org/mailman/listinfo/python-list


[ANN] PySourceColor 1.9.6 much new code please review

2004-12-16 Thread mefjr75
Hello all ,
I have just finished PySourceColor.py ver 1.9.6.
I am near the end of this tool, and would appreciate a little bit of
review.
Please help me find the pesky little bugs that have escaped me.
I had much difficulty getting linenumbers to work properly.
If you see a simpler way to do linenumbers, by all means, please share.

Website: http://bellsouthpwp.net/m/e/mefjr75/
Here is the module docstring to start you off:

"""
#
# PySourceColor.py
#
# A python source to colorized html/css/xhtml converter.
# Hacked by M.E.Farmer Jr. 2004
# Python license
#
# Now supports two types of output markup:
# - HTML markup does not create w3c valid html, but it works on every
#   browser i've tried so far.
#   (I.E.,Mozilla/Firefox,Opera,Konqueror,wxHTML).
# - CSS markup is w3c validated html 4.01 strict,
#   but will not render correctly on all browsers.
# - XHTML markup is w3c validated xhtml 1.0 strict,
#   like html 4.01, will not render correctly on all browsers.
#
# Features:
# -Three types of markup:
#html (default)
#css/html 4.01 strict
#xhtml 1.0 strict
#
# -Can tokenize and colorize:
#12 types of strings
#2 comment types
#numbers
#operators
#brackets
#math operators
#class / name
#def / name
#decorator / name
#keywords
#arguments class/def/decorator
#text
#linenumbers
#
# -Eight colorschemes built-in:
#null
#mono
#dark (default)
#dark2
#lite
#idle
#viewcvs
#pythonwin
#
# -Header and footer
#set to '' for builtin header / footer
#or give path to a file containing the html
#you want added as header and footer
#
# -Linenumbers
#Supports all styles. New token is called LINE.
#Defaults to NAME if not defined
#
# Style options
# -ALL markups support these text styles:
# b = bold
# i = italic
# u = underline
# -CSS and XHTML has limited support  for borders:
# HTML markup functions will ignore these.
# Optional: Border color in RGB hex
# Defaults to the text forecolor.
# #rrggbb = border color
# Optional: specify one type only
# - = dashed
# . = dotted
# s = solid
# d = double
# g = groove
# r = ridge
# n = inset
# o = outset
# You can specify multiple sides,
# they will all use the same style.
# Optional: Default is full border.
# v = bottom
# < = left
# > = right
# ^ = top
# NOTE: Specify the styles you want.
#   The markups will ignore unsupported styles
#   Also note not all browsers can show these options
#
# -All tokens default to NAME if not defined
# so the only absolutely critical ones to define are:
# NAME, ERRORTOKEN, PAGEBACKGROUND
#
#
# Example usage:
#
# # import
# import PySourceColor as psc
# psc.convert('c:/Python22/PySourceColor.py', colors=psc.idle, show=1)
#
# # from module import *
# from PySourceColor import *
# convert('c:/Python22/Lib', colors=lite, markup="css", header='')
#
# # How to use a custom colorscheme, and most of the 'features'
# # Warning this is an *ugly* colorscheme it is just an example
# from PySourceColor import *
# new = {
#   ERRORTOKEN: ('bui','#FF8080',''),
#   DECORATOR_NAME: ('s','#AACBBC',''),
#   DECORATOR:  ('n','#33',''),
#   NAME:   ('t.','#00','#FF'),
#   TRIPLEDOUBLEQUOTE_R:('tub','#00','#FF'),
#   TRIPLEDOUBLEQUOTE_U:('-', '#CCAABB','#FFFAFF'),
#   LINE:   ('ib-','#ff66aa','#7733FF'),
#   PAGEBACKGROUND: '#FFFAAA',
# }
# if __name__ == '__main__':
# import sys
# convert(sys.argv[1], './css.html',colors=new,
#  markup='css', show=1, linenumbers=1)
# convert(sys.argv[1], './html.html',colors=new,
# markup='html', show=1, linenumbers=1)
#
"""
More details in the code.
And for all the commandline junkies there is a commandline interface
that covers every option.
website: http://bellsouthpwp.net/m/e/mefjr75/
thank you for your time,
M.E.Farmer

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


Re: Accessing DB2 with Python

2004-12-16 Thread Michel Claveau - abstraction méta-galactique non triviale en fuite perpétuelle.
Hi !

it's not a web site, it's FTP...



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


Re: [ANN] [Hack] Import binary extensions from zipfiles, windows only

2004-12-16 Thread Michel Claveau - abstraction méta-galactique non triviale en fuite perpétuelle.
I like this kind of gadget.



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


Re: Accessing DB2 with Python

2004-12-16 Thread Jarek Zgoda
Larry Bates wrote:
I just tried the link at it works from here.  Site has
source and Windows binary versions of software.  Looks
loke it is being maintained.  Windows binary for Python
2.3 was added in September 2004. No 2.4 binary.
Be aware, that it's a module for "normal" DB2, not a DB2/400. To access 
DB2/400 you have to use ClientAccess ODBC (from Windows or *nix 
platform) driver or iSeries port of Python (from AS/400).

--
Jarek Zgoda
http://jpa.berlios.de/ | http://www.zgodowie.org/
--
http://mail.python.org/mailman/listinfo/python-list


Re: High level SNMP

2004-12-16 Thread Ilya Etingof
Jeremy Sanders <[EMAIL PROTECTED]> wrote:
> On Thu, 09 Dec 2004 15:34:14 +0200, Petri Laakso wrote:

[skipped]

> The old versions of PySNMP (version 2.XX), seem to be a lot simpler to
> use than later ones, so I might do that. That's if I can work out how to

Recent versions tend to be more complex because they're following SNMPv3
model, which is complex. However, a simplistic high-level layer is
scheduled for implementation.

> convert the random string it produces to a floating point number. Somehow
> it manages to gain 3 bytes over a float...

Basic SNMP types don't seem to include floating point numbers. Maybe you're
decoding something defined by a TEXTUAL-CONVENTION at a MIB? The protocol
(for packing floating point value into some native SNMP type) might be 
specified by the TC then.

If you provide more details I'm willing to help.

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


cmp of multiple attributes (WAS: Why are tuples immutable?)

2004-12-16 Thread Steven Bethard
Roy Smith wrote:
class Property:
def __init__ (self, block, lot, zoning="Unknown"):
self.block = block
self.lot = lot
self.zoning = zoning
def __hash__ (self):
return (self.block + self.lot)
def __cmp__ (self, other):
# I wish there was a less verbose way to do this!
if self.block < other.block:
return -1
if self.block > other.block:
return 1
if self.lot < other.lot:
return -1
if self.lot > other.lot:
return 1
return 0
Does this do what you want?
>>> class Property(object):
... def __init__(self, block, lot):
... self.block, self.lot = block, lot
... def __cmp__(self, other):
... return (cmp(self.block, other.block) or
... cmp(self.lot, other.lot))
...
>>> for i in (0, 1):
... for j in (0, 1):
... for k in (0, 1):
... for l in (0, 1):
... print i, j, k, l, cmp(Property(i,j),Property(k,l))
...
0 0 0 0 0
0 0 0 1 -1
0 0 1 0 -1
0 0 1 1 -1
0 1 0 0 1
0 1 0 1 0
0 1 1 0 -1
0 1 1 1 -1
1 0 0 0 1
1 0 0 1 1
1 0 1 0 0
1 0 1 1 -1
1 1 0 0 1
1 1 0 1 1
1 1 1 0 1
1 1 1 1 0
Steve
--
http://mail.python.org/mailman/listinfo/python-list


Re: Adding paths to sys.path permanently, and another problem...

2004-12-16 Thread Jeff Shannon
Lenard Lindstrom wrote:
Amir Dekel <[EMAIL PROTECTED]> writes:
 

Hi everyone,
I have two problems:
1. How can I keep my changes in sys.path after closing the interpreter?
   

Saving sys.path changes between interpreter runs would be more involved.
On Windows Python loads the initial module search path from the registry.
Python's registry entries are made during installation and are left alone
afterwards. Changing these entries is probably not a good idea. But
if you need sys.path persistence I can try writing an example that does
it automatically using the atexit module and a history file.
 

Not only can one modify the environment variable PYTHONPATH, but one can 
also use a .pth file.  Under windows, when the interpreter starts up it 
will search its default sys.path for any files with extension .pth; if 
it finds any, then it will use each line of those files as a directory 
to add to sys.path.  Thus, if you drop a mymodule.pth file in 
site-packages, which contains a list of the directories you're 
interested in, sys.path will automatically be amended for you every time 
Python starts.

Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why no list heritable type?

2004-12-16 Thread Steve Holden
James Stroud wrote:
The thread "why not arrays" got me thinking. I would really like to inherit 
from a list so that I can add methods based on its contents, say if I filled 
it with a type of object and wanted to iterate over all objects. I have built 
a wrapper around a list like this for general use:

class list_of_objects:
  def __init__(self):
self.data = []
  def __len__(self):
return len(self.data)
  etc ...
Then it can be heritable and I can add or override methods. Why aren't built 
in lists and dictionaries real heritable types that can save this kind of 
patchwork? Is there a pythonic reason I am missing here?

I think the thing you are really missing is the fact that list and the 
other built-in types can be used as the basis for inheritance:

Python 2.4 (#1, Dec  4 2004, 20:10:33)
[GCC 3.3.3 (cygwin special)] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
 >>> class fooList(list):
 ...   def bar(self):
 ... for item in self:
 ...   print "Bar:", item
 ...
 >>> fl = fooList(('one', 'two', 'three'))
 >>> fl.append("four")
 >>> fl.bar()
Bar: one
Bar: two
Bar: three
Bar: four
 >>> type(fl)

 >>>
You do need to be somewhat careful, though, to understand the 
initialisation mechanism of the new object-based types if you are going 
to get the best out of them.

regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: Html or Pdf to Rtf (Linux) with Python

2004-12-16 Thread Axel Straschil
Hello!

> That's easy. Load the HTML in MS Word, and save it as RTF. Script it
> via COM using the python win32all (I think that's what it's now
> called) package.

As I wrote in my posting and the subject: linux ;-)
I could try to do this with open office, by I'm afraid this will not
be a performant solution ;-(
I realy was spending hour's on that, the only thing I found was a
spezifikation for reach text, maybe a good point to start a project ...

Lg
AXEL.

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


Re: Winge IDE Issue - an suggestions?

2004-12-16 Thread Mike Thompson
Marco Aschwanden wrote:
Without further checking I would propose you let WingIDE ignore this  
exception - most probably WingIDE is choking on a exception that was  
thrown intentionally by the module writer.

I hope you know how to let WingIDE ignore exceptions? (In the upper 
part  of the Exceptions-tool click on 'Ignore this exception 
location')... hope  this helps.

Goan. It does help, thanks Marco.  I was working with totally the wrong 
paradigm. I was assuming the reported exception was uncaught (that's how 
Komodo works) ... it was a very confusing place to be late at night - 
WingIDE bug seemed the only explanation, although it was puzzling me 
that something so obvious could make it through their QA. Thanks again.

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


Re: BASIC vs Python

2004-12-16 Thread Jeff Shannon
Doug Holton wrote:
If you want to make applications with a graphical user interface 
(GUI), check out wxpython, although they haven't yet released a 
version that works with the new python 2.4 however: http://wxpython.org/

Actually, Robin *has* released 2.4 binaries, he just hasn't updated the 
website yet. ;) But Windows installers for 2.4 are available on 
Sourceforge...

Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list


Re: Programming/Modeling Contract

2004-12-16 Thread Steve Holden
expecthealth wrote:
MODELING/Programming Opportunity:
Do you know anyone for a 3-6 month assignment who is a
mathematician/Programmer – possibly a queuing theory person? We need
someone to help understand staffing models, depending on the time of
day, number of order points, seasonally,
We are finding that our end user is way overstaffed at certain times
because they cannot afford to be caught short of staff.  As they go
forward, they want to build a staffing model that is well constructed
and  tracks history accurately.
This role could be filled by an HR person, scheduler or more a
conventional programmer.
The rate is open. Immediate need. Please forward your resume to me.
Please contact:
Bill Norris 
[EMAIL PROTECTED]
815-301-3189

Bill:
Note you can post this job on the board - see 
http://www.python.org/Jobs-howto.html for further details.

regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why no list heritable type?

2004-12-16 Thread Jeff Shannon
James Stroud wrote:
The thread "why not arrays" got me thinking. I would really like to inherit 
from a list so that I can add methods based on its contents, say if I filled 
it with a type of object and wanted to iterate over all objects. I have built 
a wrapper around a list like this for general use:

class list_of_objects:
 def __init__(self):
   self.data = []
 def __len__(self):
   return len(self.data)
 etc ...
Then it can be heritable and I can add or override methods. Why aren't built 
in lists and dictionaries real heritable types that can save this kind of 
patchwork? Is there a pythonic reason I am missing here?

James
 

But they *are* subclassable, since 2.2 at least:
PythonWin 2.2.1 (#34, Apr 15 2002, 09:51:39) [MSC 32 bit (Intel)] on win32.
Portions Copyright 1994-2001 Mark Hammond ([EMAIL PROTECTED]) - 
see 'Help/About PythonWin' for further copyright information.
>>> type(list)

>>> class my_list(list):
... pass
...
>>> type(my_list)

>>> l = my_list()
>>> l.append('foo')
>>> l.extend(['bar', 'baz'])
>>> l[2]
'baz'
>>> l
['foo', 'bar', 'baz']
>>> type(l)

>>>

Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list


Re: os.walk bug?

2004-12-16 Thread Tim Peters
[Gabriel Cosentino de Barros]
...
> for root, dirs, files in os.walk('t:\'): 
> # -- do stuff 
> print "working on", root
> # -- stuff done 
> 
> print 'DEBUG: dirs =', dirs 
> for d in dirs: 
> # -- remove archive 
> if d[:2] == '20': 
> print "--- removing:", d 
> dirs.remove(d) 

You're mutating a list while iterating over it.  This has odd effects.
 They're defined in the Language Reference Manual, but it's best to
avoid them.  Change

for d in dirs:

to

for d in dirs[:]:

and you should stop getting surprised.  That avoids surprise by
iterating over a copy of the list.  Then it doesn't matter that you
mutate the original list inside the loop.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Why no list heritable type?

2004-12-16 Thread Robert Brewer
James Stroud wrote:
> The thread "why not arrays" got me thinking. I would really 
> like to inherit 
> from a list so that I can add methods based on its contents, 
> say if I filled 
> it with a type of object and wanted to iterate over all 
> objects. I have built 
> a wrapper around a list like this for general use:
> 
> class list_of_objects:
>   def __init__(self):
> self.data = []
>   def __len__(self):
> return len(self.data)
>   etc ...
> 
> Then it can be heritable and I can add or override methods. 
> Why aren't built 
> in lists and dictionaries real heritable types that can save 
> this kind of patchwork?

They are since Python 2.2 (IIRC):

class mylist(list):
def mymethod(self):
self.x = 5

...etc.

What problems are you running into?


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


Re: Python mascot proposal

2004-12-16 Thread kdahlhaus
I just noticed the link - are you at Case in Cleveland?  I'm in
Brooklyn (OH).

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


Why no list heritable type?

2004-12-16 Thread James Stroud
The thread "why not arrays" got me thinking. I would really like to inherit 
from a list so that I can add methods based on its contents, say if I filled 
it with a type of object and wanted to iterate over all objects. I have built 
a wrapper around a list like this for general use:

class list_of_objects:
  def __init__(self):
self.data = []
  def __len__(self):
return len(self.data)
  etc ...

Then it can be heritable and I can add or override methods. Why aren't built 
in lists and dictionaries real heritable types that can save this kind of 
patchwork? Is there a pythonic reason I am missing here?

James


-- 
James Stroud, Ph.D.
UCLA-DOE Institute for Genomics and Proteomics
611 Charles E. Young Dr. S.
MBI 205, UCLA 951570
Los Angeles CA 90095-1570
http://www.jamesstroud.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why are tuples immutable?

2004-12-16 Thread Jarek Zgoda
Fredrik Lundh wrote:
how does the dictionary know if you want key value equality or key
identity equality?
By the __hash__ and __eq__ methods you provide on your object.
so what you're saying is that Python dictionaries should work just like
Python dictionaries work today.
sorry for wasting my time.
Don't be sorry, reading your posts was a real pleasure.
No, really.
--
Jarek Zgoda
http://jpa.berlios.de/ | http://www.zgodowie.org/
--
http://mail.python.org/mailman/listinfo/python-list


ElementTree.write() question

2004-12-16 Thread Stephen Waterbury
[If there is a separate list for elementtree, please someone
clue me ... I didn't see one.]
Fredrik or other xml / elementtree gurus:
I see from the source that ElementTree.write() writes

at the beginning of the xml output if an encoding
other than utf-8 or us-ascii is selected.  Shouldn't
it also write that if utf-8 or us-ascii is being
used?  Or at least the

?
Thanks,
Steve
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python mascot proposal

2004-12-16 Thread kdahlhaus
> http://exogen.cwru.edu/python2.png

Wow, that's sharp!

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


Programming/Modeling Contract

2004-12-16 Thread expecthealth

MODELING/Programming Opportunity:


Do you know anyone for a 3-6 month assignment who is a
mathematician/Programmer – possibly a queuing theory person? We need
someone to help understand staffing models, depending on the time of
day, number of order points, seasonally,

We are finding that our end user is way overstaffed at certain times
because they cannot afford to be caught short of staff.  As they go
forward, they want to build a staffing model that is well constructed
and  tracks history accurately.

This role could be filled by an HR person, scheduler or more a
conventional programmer.

The rate is open. Immediate need. Please forward your resume to me.

Please contact:

Bill Norris
[EMAIL PROTECTED]
815-301-3189




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


Re: create lowercase strings in lists - was: (No subject)

2004-12-16 Thread Mike Meyer
"Mark Devine" <[EMAIL PROTECTED]> writes:

> Sorry for not putting a subject in the last e-mail. The function lower suited 
> my case exactly. Here however is my main problem:
> Given that my new list is :
> [class-map match-all cmap1', 'match ip any', 'class-map match-any cmap2', 
> 'match any', 'policy-map policy1', 'class cmap1', 'policy-map policy2', 
> 'service-policy policy1', 'class cmap2']
>
> Each element in my new list could appear in any order together within another 
> larger list (list1) and I want to count how many matches occur. For example 
> the larger list could have an element 'class-map cmap2 (match any)' and I 
> want to match that but if only 'class-map match-any' or 'class-map cmap2' 
> appears I don't want it to match. 
>
> Can anybody help?
> Is my problem clearly stated?

Yes. Here's how to use the count method of a list to do it.

[(list1.count(element), element) for element in small]

is one way, but the dictionary method posted by Steve Holden will be
faster.

  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.walk bug?

2004-12-16 Thread Terry Reedy
os.walk bug?---
for d in dirs:
# -- remove archive
if d[:2] == '20':
print "--- removing:", d
dirs.remove(d)
--
Please post in plain text, not html/rtf.  It is easier to reply to.

Without looking at your output, I suspect the above is one of your 
problems.  Do not add/or remove items from a list that you are iterating 
over unless you are *very* sure it actually gives you what you really want 
(and then a comment might be in order).  This is a common new-to-Python 
mistake.  Try 'for d in list(dirs):' and see if your output improves.

Terry J. Reedy



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


Re: getopt: Make argument mandatory

2004-12-16 Thread Kent Johnson
Frans Englich wrote:
On Wednesday 15 December 2004 14:07, Diez B. Roggisch wrote:
In my use of getopt.getopt, I would like to make a certain parameter
mandatory. I know how to specify such that a parameter must have a value
if it's specified, but I also want to make the parameter itself
mandatory(combined with a mandatory value, the result is that the user
must specify a value).
Use optparse - in the examples section you'll find what you need.

I'm slow here, do you mean in of the callback examples in 6.21.4?
http://docs.python.org/lib/module-optparse.html
No, try here - this section seems to have been deleted from the Python 2.4 
docs!
http://www.python.org/doc/2.3.4/lib/optparse-extending-examples.html
Kent
--
http://mail.python.org/mailman/listinfo/python-list


newbie: Datetime module for Python 2.2.x

2004-12-16 Thread Eric Azarcon

Hello!

I'm fairly new to Python, and was wondering if someone might be able to
help. I'm doing something that requires the datetime module released in
2.3. Unfortunately, the target machines are running 2.2.x and there is
no easy way that I know of to install 2.3/2.4 (RHEL ES).

I've done some looking around, and located and downloaded a tarball
from Zope that seems to address this, but have no idea how I am to
install this. The file is a datetime.tar.

I've also downloaded the source from Python.org, and have the C source
for datetime. Of course, I have no idea how to compile just that
module. And installing it, if I ever get that far.

Any help would be much appreciated!

Thanks,

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


Re: Best book on Python?

2004-12-16 Thread Jean Brouwers

The text of David Mertz' book is available on line at



/jean Brouwers


In article <[EMAIL PROTECTED]>, Mirko Zeibig
<[EMAIL PROTECTED]> wrote:

> Maurice LING said the following on 12/12/2004 11:13 PM:
> >>Google for Dive Into Python. Its a free online publication, see if is 
> >>any good for you.
> >>
> >>Cheers,
> > 
> > 
> > I like "Dive into Python" for the fact that it tends to explain examples 
> > line by line in an annotated form but it may just be my personal 
> > preference.
> I second this. Another one I like is "Textprocessing  in Python" by 
> "David Mertz".
> 
> > If the focus is only on printed books and there is some experience with 
> > programming, "programming python" by Lutz from O'Reilly might be a good 
> > one.
> So what, "Dive into Python" is available in a printed version as well 
> ;-) (e.g. 
> http://www.amazon.com/exec/obidos/tg/detail/-/1590593561/103-2217423-3565410).
> 
> Regards
> Mirko
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   >