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

2004-12-17 Thread Axel Straschil
Hello!

> You might take a look at PyRTF in PyPI. It's still in beta,

I think PyRTF would be the right choice, thanks. Yust had a short look
at it.

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: [ANN] [Hack] Import binary extensions from zipfiles, windows only

2004-12-17 Thread Thomas Heller
"Delaney, Timothy C (Timothy)" <[EMAIL PROTECTED]> writes:

> 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 ...

It's a step in this direction only.

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


Potential improvement on delegation via explicit calls and super

2004-12-17 Thread Robert Dick
Derived classes sometimes need to delegate portions of the work in overridden 
methods to methods in their base classes.  This was traditionally done with 
explicit calls in python, e.g.,

class Derived(Left, Right):
  def __init__(self, myarg, larg, rarg):
Left.__init__(self, larg)
Right.__init__(self, rarg)
self.data = myarg
print 'derived'

This worked great.  It was possible to grab the appropriate arguments and send 
them off to the right point.  However, there was a problem.

class Base:
  def __init__(self):
print 'base'

class Left(Base):
  def __init__(self, arg):
Base.__init__(self)
print 'left'

class Right(Base):
  def __init__(self, arg):
Base.__init__(self)
print 'right'

Now, when Derived(Left, Right) is initialized, Base.__init__ is called twice.  
Sometimes that's O.K.  Usually, it's a bad thing.  Along came new-style 
classes and 'super'.  Unfortunately, super-based delegation doesn't play 
nicely with traditional classes.
  http://www.ai.mit.edu/people/jknight/super-harmful/
Moreover, it undermines any attempts to control which subset of arguments go 
to which base class.  This second problem is serious.  In real life, base 
classes differ from each other: I need to be able to send the right arguments 
to each.

What I really want to do is explicitly delegate tasks to base classes, 
choosing the arguments to send to each, but avoid double-calls resulting from 
reconverging paths in the inheritance directed acyclic (pray it's acyclic) 
graph.

I think the appended code may solve this problem, play nicely with traditional 
classes, and allow the coder to send the right arguments to the right base 
classes.

However, I'm new to python so I need some help.

1) Is my thinking reasonable or is there an better way to solve the 
reconvergent path problem in python without undermining control over 
arguments?

2) What's the proper way to rewrite the appended code.  I'm sure it's 
dreadfully inefficient.  There are also probably ways to make its use more 
intuitive, but I'm new to the language so I don't know the tricks yet.

Thanks for any tips,

-Robert Dick-


'''See the example at the bottom.'''

import inspect

def flatten_tree(tree):
  '''Flatten a tree represented by nested lists'''
  if isinstance(tree, list):
return [j for i in tree for j in flatten_tree(i)]
  else:
return (tree,)

# Cache for delegation decisions.
call_cache = set()

def should_call(self, pos, supr):
  '''Examines the inheritance DAG (might work for DCGs, too... haven't
  checked) for 'self' to determine whether 'pos' is the leftmost derived
  for 'supr'.  Returns bool.  Caches results for performance.'''
  if (self.__class__, pos, supr) in call_cache: return True
  ct = flatten_tree(inspect.getclasstree(inspect.getmro(self.__class__), 
True))
# ct is a list of (class, (base classes)) tuples
# Find the first instance of the supr as a base class
  do_call = pos is [cls for cls, bases in ct if supr in bases][0]
  if do_call: call_cache.add((self.__class__, pos, supr))
  return do_call

def delegate(self, pos, s_call, *pargs, **kargs):
  '''If 'pos' is the leftmost derived for 's_call' in the 'self' inheritance
  DAG, call s_call with 'pargs' and 'kargs'.'''
  if inspect.ismethoddescriptor(s_call):
supr = s_call.__objclass__
  else:
supr = s_call.im_class
  if should_call(self, pos, supr):
s_call(self, *pargs, **kargs)

if __name__ == '__main__':
  class Base(object):
def __init__(self):
  delegate(self, Base, object.__init__)
  print 'base'

  class Left(Base):
def __init__(self):
  delegate(self, Left, Base.__init__)
  print 'left'

  class Right(Base):
def __init__(self):
  delegate(self, Right, Base.__init__)
  print 'right'

  class Der(Left, Right):
def __init__(self):
  delegate(self, Der, Left.__init__)
  delegate(self, Der, Right.__init__)
  print 'der'

  der = Der()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Winge IDE Issue - an suggestions?

2004-12-17 Thread Fredrik Lundh
Mike Thompson wrote:

> File "C:\Python23\Lib\site-packages\elementtree\ElementTree.py", line 709, in 
> _write
>   for n in node:
> File "C:\Python23\Lib\site-packages\elementtree\ElementTree.py", line 227, in 
> __getitem__
>   return self._children[index]
>
> The exception is triggered in ElementTree but the code is fine. Something 
> about the Wing IDE 
> debuger is causing this exception to be thrown.

note that the code is using a for-loop to process all items in a container 
object.  the
IndexError is supposed to tell the for-loop to stop; having a Python IDE report 
this
as an error is remarkably brain-dead...

(do they stop on StopIteration exceptions too?  or IOError exceptions from 
open?)

 



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


Re: ElementTree.write() question

2004-12-17 Thread Fredrik Lundh
Stephen Waterbury wrote:

> [If there is a separate list for elementtree, please someone
> clue me ... I didn't see one.]

the xml-sig is preferred, I think.

> 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
>
> 

this is mostly for historical reasons; early versions only supported UTF-8 
output,
and never generated encoding directives, so people ended up writing:

print >>myfile, ""
for elem in list_of_elements:
ElementTree(elem).write(myfile)
print >>myfile, ""

version 1.3 will probably include an option to always write the header.

(note that the XML header isn't needed for UTF-8 and ASCII; if it's not there,
a proper XML parser will treat the stream as UTF-8, and ASCII is a compatible
subset of UTF-8).

 



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


sgmllib problem & proposed fix.

2004-12-17 Thread C. Titus Brown
Hi all,
while playing with PBP/mechanize/ClientForm, I ran into a problem with 
the way htmllib.HTMLParser was handling encoded tag attributes.

Specifically, the following HTML was not being handled correctly:
Small (6)
The 'value' attr was being given the escaped value, not the
correct unescaped value, 'Small (6")'.
It turns out that sgmllib.SGMLParser (on which htmllib.HTMLParser is 
based) does not unescape tag attributes.  However, HTMLParser.HTMLParser 
(the newer, more XHTML-friendly class) does do so.

My proposed fix is to change sgmllib to unescape tags in the same way 
that HTMLParser.HTMLParser does.  A context diff to sgmllib.py from 
Python 2.4 is at the bottom of this message.

I'm posting to this newsgroup before submitting the patch because I'm 
not too familiar with these classes and I want to make sure this 
behavior is correct.

One question I had was this: as you can see from the code below, a 
simple string.replace is done to replace encoded strings with their 
unencoded translations.  Should handle_entityref be used instead, as 
with standard HTML text?

Another question: should this fix, if appropriate, be back-ported to 
older versions of Python?  (I doubt sgmllib has changed much, so it 
should be pretty simple to do.)

thanks for any advice,
--titus
*** /u/t/software/Python-2.4/Lib/sgmllib.py 2004-09-08 
18:49:58.0 -0700
--- sgmllib.py  2004-12-16 23:30:51.0 -0800
***
*** 272,277 
--- 272,278 
  elif attrvalue[:1] == '\'' == attrvalue[-1:] or \
   attrvalue[:1] == '"' == attrvalue[-1:]:
  attrvalue = attrvalue[1:-1]
+ attrvalue = self.unescape(attrvalue)
  attrs.append((attrname.lower(), attrvalue))
  k = match.end(0)
  if rawdata[j] == '>':
***
*** 414,419 
--- 415,432 
  def unknown_charref(self, ref): pass
  def unknown_entityref(self, ref): pass

+ # Internal -- helper to remove special character quoting
+ def unescape(self, s):
+ if '&' not in s:
+ return s
+ s = s.replace("<", "<")
+ s = s.replace(">", ">")
+ s = s.replace("'", "'")
+ s = s.replace(""", '"')
+ s = s.replace("&", "&") # Must be last
+
+ return s
+
  class TestSGMLParser(SGMLParser):
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why are tuples immutable?

2004-12-17 Thread Antoon Pardon
Op 2004-12-17, Jeff Shannon schreef <[EMAIL PROTECTED]>:
> 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.

You are looking at it in a too limited way. You are not forced to
have an == operator that behaves in standard ways. For instance
you can have objects that are only equal if they are the same
and thus can be unequal even if all components are equal.

Even if 

> 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.

How about:

  hash = id


You also make the fault that because people ask for the possibility of
keys being mutable objects, that they want to mutate those object while 
being a key.

> 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 you should be carefull not to limit people to what you think is
usefull.

> 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
> .>>>

It is just as nonsensical that, without ever rebinding an element, one
can unsort a list, or violate the heap invariant of a list.

> 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.

Then why don't we disallow lists of mutable objects to be sorted or
to be made into a heap. In fact each time we have a structure that
relies on some invariant among its members we should disallow mutable
members because with mutable members the invariant can be violated
without ever rebinding one of the elements.

> 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.

As it turns out, python makes no difference in difficulty for making
either mutable or immutable objects usable as dictionary keys. The
only difference is that python only made its standard immutable
types hashable and not its standard mutable objects.

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


Re: sgmllib problem & proposed fix.

2004-12-17 Thread C. Titus Brown
Whoops!  Forgot an executable example ;).
Attached, and also available at
http://issola.caltech.edu/~t/transfer/test-enc.py
http://issola.caltech.edu/~t/transfer/test-enc.html
Run 'python test-enc.py test-enc.html' and note that 
htmllib.HTMLParser-based parsers give different output than 
HTMLParser.HTMLParser-based parsers.

cheers,
--titus
#!/usr/bin/env python2.4
import htmllib
import HTMLParser
import formatter

### a simple mix-in to demonstrate the problem.

class MixinTest:
def start_option(self, attrs):
print '==> OPTION starting', attrs

# Definition of entities -- derived classes may override
entitydefs = \
{'lt': '<', 'gt': '>', 'amp': '&', 'quot': '"', 'apos': '\''}

def handle_entityref(self, name):
print '==> HANDLING ENTITY', name
table = self.entitydefs
if name in table:
self.handle_data(table[name])
else:
self.unknown_entityref(name)
return



class htmllib_Parser(MixinTest, htmllib.HTMLParser):
def __init__(self):
htmllib.HTMLParser.__init__(self, formatter.NullFormatter())

class nonhtmllib_Parser(MixinTest, HTMLParser.HTMLParser):
def handle_starttag(self, name, attrs):
"Redirect OPTION tag ==> MixinTest.start_option"
if name == 'option':
self.start_option(attrs)

pass

###

import sys
data = open(sys.argv[1]).read()

print 'PARSING with htmllib.HTMLParser'

htmllib_p = htmllib_Parser()
htmllib_p.feed(data)

print '\nPARSING with HTMLParser.HTMLParser'

nonhtmllib_p = nonhtmllib_Parser()
nonhtmllib_p.feed(data)

Size of pizza (measured in "):


Small (6)
Medium (10)
Large (14)


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

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

2004-12-17 Thread Michael Spencer
Bengt Richter wrote:
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

Well, sure, if it's just speed, conciseness and backwards-compatibility that you 
want ;-)

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
Good point - and there is string.maketrans to set up the table too.  So 
normalize can be rewritten as:

def normalize1(text, unwanted = "()", table = maketrans("","")):
text = text.lower()
text.translate(table,unwanted)
return set(text.split())
which gives:
>>> t= timeit.Timer("normalize1('(UPPER CASE) lower case')", "from listmembers 
import normalize1")
 >>> t.repeat(3,1)
[0.29812783468287307, 0.29807782832722296, 0.3021370034462052]	

But, while we're at it, we can use str.translate to do the case conversion 
too:
So:
def normalize2(text, unwanted = "()", table = 
maketrans(ascii_uppercase,ascii_lowercase)):
text.translate(table,unwanted)
return set(text.split())

 >>> t= timeit.Timer("normalize2('(UPPER CASE) lower case')", "from listmembers 
import normalize2")
 >>> t.repeat(3,1)
[0.24295154831133914, 0.24174497038029585, 0.25234855267899547]

...which is a little faster still
Thanks for the comments: they were interesting for me - hope some of this is 
useful to OP

Regards
Michael



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


Re: Multithreading tkinter question

2004-12-17 Thread Eric Brunel
Oleg Paraschenko wrote:
[snip]
In my case "Hello" works and "Quit" doesn't (GUI stays frozen).
Linux, Python 2.3.3, pygtk-0.6.9.
That's not a multithreading issue, but just the way the quit method works. 
Try:
-
import time
from Tkinter import *
root = Tk()
b = Button(root, text='Quit')
b.configure(command=root.quit)
b.pack()
root.mainloop()
time.sleep(2)
-
When you click the "Quit" button, the GUI stays there until the time.sleep ends. 
root.quit just goes out of the mainloop; it doesn't destroy the widgets. To do 
that, you have to add an explicit root.destroy() after root.mainloop()
--
- Eric Brunel  -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python IDE

2004-12-17 Thread Fuzzyman

Dan Perl wrote:
> "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.
.






























If it's a short reply to a long post - in context - top posting is
often *significantly * less annoying..

Isn't there a quote that includes 'hobgobline of little minds'..

Regards,
Fuzzy
http://www.voidspace.org.uk/atlantibots/pythonutils.html

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


Re: Step by step: Compiling extensions with MS Visual C++ Toolkit 2003 - msvccompiler-patch.txt (0/1)

2004-12-17 Thread wjb131
Having done steps 1 to 10, I tried building Numeric-23.6. And got the
following error-msg:

F:\install\Numeric-23.6>python setup.py build
running build
running build_py
running build_ext
building '_numpy' extension
D:\Programme\Microsoft Visual C++ Toolkit 2003\bin\cl.exe /c /nologo
/Ox /MD /W3
/GX /DNDEBUG -I/usr/include/atlas -IInclude -IPackages\FFT\Include
-IPackages\R
NG\Include -ID:\Python24\include -ID:\Python24\PC /TcSrc\_numpymodule.c
/Fobuild
\temp.win32-2.4\Release\Src\_numpymodule.obj
_numpymodule.c
d:\Python24\include\pyconfig.h(30) : fatal error C1083: Cannot open
include file
: 'io.h': No such file or directory
error: command '"D:\Programme\Microsoft Visual C++ Toolkit
2003\bin\cl.exe"' fai
led with exit status 2

why?
Regards
Wolfgang

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


Re: Why are tuples immutable?

2004-12-17 Thread Antoon Pardon
Op 2004-12-17, Jeff Shannon schreef <[EMAIL PROTECTED]>:
> 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.

In the same way as mutability makes an object poorly suited to be
a member of a sorted list.

Mutability doesn't make an object unsuitable to be used in a structure
that depends on some invariant, as dictionaries are one example. We
only need to ensure that the object is stable while it is used in
such a way.

Is it such a rare occasion that objects are mutated during some time
in a program after which they remain stable? And while we have collected
a number of such stable objects couldn't it be usefull to be able to
sort them, use them as a dict key or in some other structure that
requires an invariant?

Would you have us construct two related classes each time we find
ourselves in such a situation and copy an object from one
class to the other depending on the circumstances?

> 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.

No it wouldn't.

1) A copy wouldn't be needed on a rebind of a variable name because
the name would then already be in the directory.

2) Some techniques could be used so that even a lot of binds will
not require a copie.

3) Nothing stops python from checking if one of its standard immutables
is used as a key and then proceed as it does now.


Now I'm not asking that the people oblige me and implement this.
I'm more then happy to take my own resposibility as a programmer
and provide a copy myself to the dictionary when I have use of
a mutable object as 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.)

You shouldn't limit the usefullness of a language to your ability
to imagine what is usefull and what not.

Besides python doesn't provide such an aesthetic purity. Even if
it

pywhich script - where is that module?

2004-12-17 Thread Keith Dart
Have you ever wondered where your python modules get imported from?
Here is a little script, called "pywhich", that will tell you.


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

#!/usr/bin/env python

"""pywhich 
Tell which Python module is imported.
"""

import sys

def main(argv):
if len(argv) < 2:
print __doc__
return
for modname in argv[1:]:
try:
mod = __import__(modname)
except:
print "No module or package by named '%s' found." % modname
else:
print "%15s : %s" % (modname, mod.__file__)

main(sys.argv)
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Why are tuples immutable?

2004-12-17 Thread Steven Bethard
jfj wrote:
Why can't we __setitem__ for tuples?
It seems from your suggestions here that what you really want is a 
single sequence type, list, instead of two sequence types: tuple and 
list.  Under your design, list would support hash, and it would be up to 
the programmer to make sure not to modify a list when using it as a key 
to a dict.  The important thing to understand is that, while this is not 
an unreasonable design decision, it's not the design decision that's 
been made for Python.

Reading the docs and some of GvR's comments on python-dev, my 
understanding is that, while a single sequence type would have sufficed, 
the belief was that there were two mostly non-overlapping sets of tasks 
that one might want to do with sequences.  One set of tasks dealt with 
"small collections of related data which may be of different types which 
are operated on as a group"[1] (tuples), while the other set of tasks 
dealt with "hold[ing] a varying number of objects all of which have the 
same type and which are operated on one-by-one"[1] (lists).

Now, when you use a sequence as a key to a dict, you're operating on the 
sequence as a group, not one-by-one.  Given the above conceptions of 
tuple and list then, it is natural to provide tuple with hash support, 
while leaving it out of list.

Note also that tuples being immutable also falls out of the tuple 
description above too.  If you're operating on the sequence as a group, 
then there's no need for __setitem__; __setitem__ is used to operate on 
a sequence one-by-one.

I understand that you'd like a type that is operated on one-by-one, but 
can also be considered as a group (e.g. is hashable).  Personally, I 
don't have any use for such a type, but perhaps others do.  The right 
solution in this case is not to try to redefine tuple or list, but to 
write a PEP[2] and suggest a new datatype that serves your purposes. 
I'll help you out and provide you with an implementation: =)

class hashablelist(list):
def __hash__(self):
return hash(tuple(self))
Now all you need to do is write the Abstract, Motivation and Rationale, 
and persuade the people on c.l.py and python-dev that this is actually a 
useful addition to the language.

Steve
[1] 
http://www.python.org/doc/faq/general.html#why-are-there-separate-tuple-and-list-data-types
[2] http://www.python.org/peps/pep-0001.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: lies about OOP

2004-12-17 Thread Alex Stapleton
To canadians there is no "outside" of hockey games.
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... ;)

Jeff Shannon
Technician/Programmer
Credit International

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


Re: BASIC vs Python

2004-12-17 Thread TZOTZIOY
On Fri, 17 Dec 2004 01:43:56 -0600, rumours say that Mike Meyer
<[EMAIL PROTECTED]> might have written:

>Assembler was better - at least you had recursion with
>assembler.

You had recursion with BASIC --what you probably mean is that you had no
stacked parameters (unless you imitated that with using an indexed
array).

90 rem recursion
100 print "beautiful colours"
110 gosub 100
-- 
TZOTZIOY, I speak England very best.
"Be strict when sending and tolerant when receiving." (from RFC1958)
I really should keep that in mind when talking with people, actually...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cool object trick

2004-12-17 Thread Alex Stapleton
Except what if you want to access elements based on user input or something?
you can't do
var = "varA"
obj = struct(varA = "Hello")
print obj.var
and expect it to say Hello to you.
objects contain a __dict__ for a reason :P
> Certainly makes writing 'print obj.spam, obj.spam, obj.eggs, obj.bacon,
> obj.sausages, "and", obj.spam' a lot easier ;-)
then why dont you have a breakfast class? if you have this many 
properties associated with the same thing you might as well stick them 
in a class anyway.

[EMAIL PROTECTED] wrote:
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


MDaemon Warning - virus found: RETURNED MAIL: DATA FORMAT ERROR

2004-12-17 Thread apetchame

*** WARNING **
Este mensaje ha sido analizado por MDaemon AntiVirus y ha encontrado 
un fichero anexo(s) infectado(s).  Por favor revise el reporte de abajo.

AttachmentVirus name   Action taken
--
mail.zip  I-Worm.Mydoom.m  Removed


**


The original message was received at Fri, 17 Dec 2004 10:33:14 +0100
from [221.69.228.236]

- The following addresses had permanent fatal errors -
<[EMAIL PROTECTED]>



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

Python RSS aggregator?

2004-12-17 Thread Erik Max Francis
Back in 2000 I made a news aggregation site (REALpolitik, 
http://www.realpolitik.com/) since I didn't find anything that fit my 
needs.  (REALpolitik is unfortunately made in Perl; it was my last 
significant project before I started using Python for most of my work.) 
 At the time, RSS had not reached the near-universality that it has 
now, so RP itself uses a combination of custom scraping and whatever 
XML-type feeds that were available.

I've checked and all the feeds _I_ care about :-) are available in RSS 
now, so it would make sense to move to an RSS aggregator if it has the 
same features.  I've looked around at some that are available, both in 
Python and not, and haven't found anything that had the feature set I 
want.  One in Python would obviously be a huge benefit.

I'm not looking for anything all that fancy, but there are a combination 
of some seemingly basic features I just can't seem to find in other 
aggregators.  They are:

- one-page display:  It's awkward going back and forth between multiple 
feeds in a hierarchical format, and so it's much nicer if they're all 
presented on one page available for perusal.

- filtering news items:  Preferably for filtering out as well as 
highlighting, and also being able to selectively pass on, say, the first 
item in an RSS feed, since some popular feeds use that slot as an 
advertisement.

- caching news items:  I read news sporadically throughout the day, so 
one feature I really like is the ability to queue up new items over 
time, as distinguished by unique GUID.  For example, if an RSS feed only 
provided one (unique) item at all in its feed and that was updated once 
a day, letting the system run for several days would collect them all, 
each stored uniquely and available.

- recent items:  When you check for news, it only shows you the news 
items in each category that are new since you last caught up (catching 
up is the equivalent of a "mark all as read" feature).  That way, new 
news accumulates, and it's only news you haven't seen before.

Somewhat surprisingly to me, I can't seem to find an aggregator that 
supports all these features (using Mozilla).  Is it possible it's time 
for another Yet Another-type project?

--
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
  If love be good, from whence cometh my woe?
  -- Chaucer
--
http://mail.python.org/mailman/listinfo/python-list


Re: Cool object trick

2004-12-17 Thread Steven Bethard
Alex Stapleton wrote:
you can't do
var = "varA"
obj = struct(varA = "Hello")
print obj.var
and expect it to say Hello to you.
The Bunch object from the PEP can take parameters in the same way that 
dict() and dict.update() can, so this behavior can be supported like:

>>> b = Bunch({"varA":"Hello!"})
>>> b.varA
'Hello!'
or
>>> b = Bunch([("varA", "Hello!")])
>>> b.varA
'Hello!'
Steve
--
http://mail.python.org/mailman/listinfo/python-list


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

2004-12-17 Thread Mark Devine
Thanks for the help. This is the final script:

#!/usr/bin/env python
import os
import sys
import time
import string
import pexpect
import commands


# 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", "A B D", "A E F", "A (E) B", "A B", "E A B" ]

def normalize(text, unwanted = "()", table = 
string.maketrans(string.ascii_uppercase,string.ascii_lowercase)):
text.translate(table,unwanted)
return set(text.split())


reflist = [normalize(element) for element in list1]
print reflist

#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)


the trouble is it throws up the following error for set:

$ ./test.py
Traceback (most recent call last):
  File "./test.py", line 23, in ?
reflist = [normalize(element) for element in list1]
  File "./test.py", line 20, in normalize
return set(text.split())
NameError: global name 'set' is not defined

when I checked http://docs.python.org/lib/genindex.html#letter-s

it said that
set() (built-in function) 

The python I use is the one that comes with cygwin. Does anybody know if the 
following version of python is incomplete or do I need to call built in 
functions in a different way?
 
$ python
Python 2.3.4 (#1, Jun 13 2004, 11:21:03)
[GCC 3.3.1 (cygming special)] on cygwin
Type "help", "copyright", "credits" or "license" for more information.


Michael Spencer <[EMAIL PROTECTED]> wrote:

> 
> 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
> 



_
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: Cool object trick

2004-12-17 Thread Alex Stapleton
Steven Bethard wrote:
Alex Stapleton wrote:
you can't do
var = "varA"
obj = struct(varA = "Hello")
print obj.var
and expect it to say Hello to you.

The Bunch object from the PEP can take parameters in the same way that 
dict() and dict.update() can, so this behavior can be supported like:

 >>> b = Bunch({"varA":"Hello!"})
 >>> b.varA
'Hello!'
or
 >>> b = Bunch([("varA", "Hello!")])
 >>> b.varA
'Hello!'
Steve
thats nothing like what i described.
you are setting the variable name in your code (b.varA), not generating 
the variable name in a string (var = "varA") (dictionary key) at 
run-time and fetching it from the __dict__ like i was attempting to 
describe.

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


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

2004-12-17 Thread Steven Bethard
Mark Devine wrote:
the trouble is it throws up the following error for set:
$ ./test.py
Traceback (most recent call last):
  File "./test.py", line 23, in ?
reflist = [normalize(element) for element in list1]
  File "./test.py", line 20, in normalize
return set(text.split())
NameError: global name 'set' is not defined
The set type became a builtin in Python 2.4.  I would suggest upgrading, 
but if this is not an option, you can put this at the top of the file, 
and it should get rid of the NameError:

from sets import Set as set
Steve
--
http://mail.python.org/mailman/listinfo/python-list


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

2004-12-17 Thread Mark Devine
Thanks. This version is the version that comes with cygwin. They must be behind.

Steven Bethard <[EMAIL PROTECTED]> wrote:

> 
> Mark Devine wrote:
> > the trouble is it throws up the following error for set:
> > 
> > $ ./test.py
> > Traceback (most recent call last):
> >   File "./test.py", line 23, in ?
> > reflist = [normalize(element) for element in list1]
> >   File "./test.py", line 20, in normalize
> > return set(text.split())
> > NameError: global name 'set' is not defined
> > 
> 
> The set type became a builtin in Python 2.4.  I would suggest upgrading, 
> but if this is not an option, you can put this at the top of the file, 
> and it should get rid of the NameError:
> 
> from sets import Set as set
> 
> Steve
> -- 
> 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: Cool object trick

2004-12-17 Thread Steven Bethard
Alex Stapleton wrote:
you are setting the variable name in your code (b.varA), not generating 
the variable name in a string (var = "varA") (dictionary key) at 
run-time and fetching it from the __dict__ like i was attempting to 
describe.
Ahh.  Well if you just want to get an attribute, I don't see why you 
wouldn't do it the normal way:

>>> b = Bunch(varA="Hello!")
>>> getattr(b, "varA")
'Hello!'
That's what getattr's for. ;)  No need to go poking around in __dict__.
Steve
--
http://mail.python.org/mailman/listinfo/python-list


Re: BASIC vs Python

2004-12-17 Thread Peter Hickman
Mike Meyer wrote:
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.
Basic has progressed much since you last looked at it, time to update your 
facts. Basic has recursion, it compiles to native code, it has objects, can be 
event driven and everything else you would expect of a language.

Computing changes too fast to allow you to think you know it all. Keep up to 
date granddad.

However what basic doesn't have is a portable language definition.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Cool object trick

2004-12-17 Thread Alex Stapleton
Steven Bethard wrote:
Alex Stapleton wrote:
you are setting the variable name in your code (b.varA), not 
generating the variable name in a string (var = "varA") (dictionary 
key) at run-time and fetching it from the __dict__ like i was 
attempting to describe.

Ahh.  Well if you just want to get an attribute, I don't see why you 
wouldn't do it the normal way:

 >>> b = Bunch(varA="Hello!")
 >>> getattr(b, "varA")
'Hello!'
That's what getattr's for. ;)  No need to go poking around in __dict__.
Steve
Hmm true, (i had forgotten about getattr :/) in that case im indifferent 
to Bunch() not that i really see why it's useful except for making code 
look a bit nicer occasionaly.

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


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

2004-12-17 Thread Mark Devine
I got the script working. Thanks for all your help everyone. Trouble is its not 
showing the correct results. Here is the script and results:

#!/usr/bin/env python
import os
import sys
import time
import string
import pexpect
import commands
from sets import Set as set


# 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", "A B D", "A E F", "A (E) B", "A B", "E A B" ]

def normalize(text, unwanted = "()", table = 
string.maketrans(string.ascii_uppercase,string.ascii_lowercase)):
text.translate(table,unwanted)
return set(text.split())

reflist = [normalize(element) for element in list1]
print reflist

#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)

Here is the results:

$ ./test.py
[Set(['a', 'C', 'b', '(D)']), Set(['A', 'B', 'D']), Set(['A', 'B', 'E'])]
A B C D False
A B D True
A E F False
A (E) B False
A B True
E A B True

The results should be:

> A B C D True
> A B D True
> A E F False
> A (E) B True
> A B False
> E A B True





Michael Spencer <[EMAIL PROTECTED]> wrote:

> 
> 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
> 



_
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: Step by step: Compiling extensions with MS Visual C++ Toolkit 2003 - msvccompiler-patch.txt (0/1)

2004-12-17 Thread Fuzzyman
[EMAIL PROTECTED] wrote:
> Having done steps 1 to 10, I tried building Numeric-23.6. And got the
> following error-msg:
>
> F:\install\Numeric-23.6>python setup.py build
> running build
> running build_py
> running build_ext
> building '_numpy' extension
> D:\Programme\Microsoft Visual C++ Toolkit 2003\bin\cl.exe /c /nologo
> /Ox /MD /W3
> /GX /DNDEBUG -I/usr/include/atlas -IInclude -IPackages\FFT\Include
> -IPackages\R
> NG\Include -ID:\Python24\include -ID:\Python24\PC
/TcSrc\_numpymodule.c
> /Fobuild
> \temp.win32-2.4\Release\Src\_numpymodule.obj
> _numpymodule.c
> d:\Python24\include\pyconfig.h(30) : fatal error C1083: Cannot open
> include file
> : 'io.h': No such file or directory
> error: command '"D:\Programme\Microsoft Visual C++ Toolkit
> 2003\bin\cl.exe"' fai
> led with exit status 2
>
> why?
> Regards
> Wolfgang

If you look at the instructions on :
http://www.vrplumber.com/programming/mstoolkit/

It mentions that you probably need the .NET 2.0beta runtime and SDK.

Regards,

Fuzzy
http://www.voidspace.org.uk/atlantibots/pythonutils.html

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


Re: Is Python good for graphics?

2004-12-17 Thread not [quite] more i squared
Esmail Bonakdarian wrote:
do you (or anyone else) have a recommendation for 2D type
graphics?
A possible approach is jython that gives you access to Java2D. Makes it easy 
to deploy your animated or interactive graphics as a java-compatible applet.

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


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

2004-12-17 Thread Mark Devine
If I use:
if el.issubset(testelement):
I get a closer anwser but the brackets cause a problem. They are optional in 
the test list so (D) in the test list is equal to D or (D) in the reference 
list. 



"Mark Devine" <[EMAIL PROTECTED]> wrote:

> 
> I got the script working. Thanks for all your help everyone. Trouble is its 
> not showing the correct results. Here is the script and results:
> 
> #!/usr/bin/env python
> import os
> import sys
> import time
> import string
> import pexpect
> import commands
> from sets import Set as set
> 
> 
> # 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", "A B D", "A E F", "A (E) B", "A B", "E A B" ]
> 
> def normalize(text, unwanted = "()", table = 
> string.maketrans(string.ascii_uppercase,string.ascii_lowercase)):
>   text.translate(table,unwanted)
>   return set(text.split())
> 
> reflist = [normalize(element) for element in list1]
> print reflist
> 
> #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)
> 
> Here is the results:
> 
> $ ./test.py
> [Set(['a', 'C', 'b', '(D)']), Set(['A', 'B', 'D']), Set(['A', 'B', 'E'])]
> A B C D False
> A B D True
> A E F False
> A (E) B False
> A B True
> E A B True
> 
> The results should be:
> 
> > A B C D True
> > A B D True
> > A E F False
> > A (E) B True
> > A B False
> > E A B True
> 
> 
> 
> 
> 
> Michael Spencer <[EMAIL PROTECTED]> wrote:
> 
> > 
> > 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
> > 
> 
> 
> 
> _
> 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
> 



_
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


setup.py - just what is it for ?

2004-12-17 Thread Richard Shea
Hi - This is probably quite a stupid question but I've never
understood what setup.py does. I've got a situation at the moment
where I would like to use a script (which someone else has written and
made available) to do CGI on a shared webserver to which I do not have
shell access.

The install instructions say "run python setup.py" but as far as I'm
aware I cannot do that.

There is only one script involved (except for the setup.py !) and so
I'm probably just going to copy it into my cgi-bin and give it a go
but I'd like to know for future reference just how bad could it be if
I did this ? Are there circumstances where you must use setup.py to
have any hope of the code working ?

BTW here is the setup.py in question ...

from distutils.core import setup

classifiers = """\
Development Status :: 5 - Production/Stable
Environment :: Web Environment
Intended Audience :: Developers
License :: OSI Approved :: GNU General Public License (GPL)
Operating System :: OS Independent
Topic :: Internet :: WWW/HTTP
Topic :: Internet :: WWW/HTTP :: Dynamic Content :: CGI
Tools/Libraries
"""
import sys
if sys.version_info < (2, 3):
_setup = setup
def setup(**kwargs):
if kwargs.has_key("classifiers"):
del kwargs["classifiers"]
_setup(**kwargs)

setup(name="cgi_app",py_modules=["cgi_app"],
version="1.3",
maintainer="Anders Pearson",
maintainer_email="[EMAIL PROTECTED]",
url = "http://thraxil.org/code/cgi_app/";,
license = "http://www.gnu.org/licenses/gpl.html";,
platforms = ["any"],
description = "CGI and mod_python MVC application framework",
long_description = """framework for building MVC CGI and
mod_python
applications. based on the perl CGI::Application module but
more
pythonic.""",
classifiers = filter(None, classifiers.split("\n")))


... I would appreciate any information about this (or any tips on how
to deal with no shell access).

thanks

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


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

2004-12-17 Thread Peter Otten
Mark Devine wrote:

> I got the script working. Thanks for all your help everyone. Trouble is
> its not showing the correct results. Here is the script and results:

In my book it is not working then.

> def normalize(text, unwanted = "()", table =
> string.maketrans(string.ascii_uppercase,string.ascii_lowercase)):
> text.translate(table,unwanted) 

Strings are immutable in Python. Make that

  text = text.translate(table, unwanted)

This line of the script's output could have given you a clue:

> [Set(['a', 'C', 'b', '(D)']), Set(['A', 'B', 'D']), Set(['A', 'B', 'E'])]

(I didn't look any further, so there may be other problems)

Peter

PS: Do us a favour and (a) don't top-post (b) use space not tabs in your
source code (c) remove all text quoted from the parent that is not relevant
to your current problem.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: BASIC vs Python

2004-12-17 Thread Peter Otten
Peter Hickman wrote:

> Mike Meyer wrote:
>> 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.
> 
> Basic has progressed much since you last looked at it, time to update your
> facts. Basic has recursion, it compiles to native code, it has objects,
> can be event driven and everything else you would expect of a language.
> 
> Computing changes too fast to allow you to think you know it all. Keep up
> to date granddad.
> 
> However what basic doesn't have is a portable language definition.

May you could give us an idea of the current state of basic affairs then by
translating the following example snippet:

It's me wrote:

> 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...

Peter

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


Re: setup.py - just what is it for ?

2004-12-17 Thread Fredrik Lundh
Richard Shea wrote:

> Hi - This is probably quite a stupid question but I've never
> understood what setup.py does. I've got a situation at the moment
> where I would like to use a script (which someone else has written and
> made available) to do CGI on a shared webserver to which I do not have
> shell access.
>
> The install instructions say "run python setup.py" but as far as I'm
> aware I cannot do that.

http://www.python.org/doc/current/inst/

> There is only one script involved (except for the setup.py !) and so
< I'm probably just going to copy it into my cgi-bin and give it a go
> but I'd like to know for future reference just how bad could it be if
> I did this ? Are there circumstances where you must use setup.py to
> have any hope of the code working ?

depends on the package, of course.  e.g. a package that includes C extensions
won't work if you don't compile the C extensions...

 



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


Re: Help need with converting Hex string to IEEE format float

2004-12-17 Thread Ian Vincent
Max M <[EMAIL PROTECTED]> wrote in news:41bf121e$0$280
[EMAIL PROTECTED]:
> 
> ##
> st = '80 00 00 00'
> 
> import binascii
> import struct
> 
> s = ''.join([binascii.a2b_hex(s) for s in st.split()])
> v = struct.unpack("f", s)[0]
> print v
> ##

This one worked great for what I was trying to do.

Thanks to everybody for your help.

TTFN

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


Re: BASIC vs Python

2004-12-17 Thread Gerhard Haering
On Fri, Dec 17, 2004 at 11:49:22AM +0100, Peter Otten wrote:
> Peter Hickman wrote:
> > [..] Basic has progressed much since you last looked at it, time
> > to update your facts. Basic has recursion, it compiles to native
> > code, it has objects, can be event driven and everything else you
> > would expect of a language.
> > 
> > Computing changes too fast to allow you to think you know it all. Keep up
> > to date granddad.
> > 
> > However what basic doesn't have is a portable language definition.
> 
> May you could give us an idea of the current state of basic affairs then by
> translating the following example snippet: [...]

IIRC BASIC does have a portable language definition:
ANSI BASIC, which is the old crap with GOTO and GOSUB that nobody in
their right mind would want to use nowadays ...

I only know about Visual Basic 5.0/6.0 and a little about Visual Basic
.NET and thanks to the .NET standard library it's possible to write
the Python code you gave us in relatively clean VB.NET with the
collections classes.

In VB6, it would an exercise of working around the limitations of the
data structures.

-- Gerhard
-- 
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


signature.asc
Description: Digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Why no list heritable type?

2004-12-17 Thread Sion Arrowsmith
In article <[EMAIL PROTECTED]>, Mike Meyer  <[EMAIL PROTECTED]> wrote:
>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?

Apart from compatibility issues as mentioned in the UserList
documentation, deriving from it will give you a classic class,
whereas deriving from list will give you a new style class.
There may be circumstances under which this is important
(exercise left to more twisted minds than mine). Same applies
to dict/UserDict.

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
  ___  |  "Frankly I have no feelings towards penguins one way or the other"
  \X/  |-- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pywhich script - where is that module?

2004-12-17 Thread Thomas Guettler
Am Fri, 17 Dec 2004 09:09:25 + schrieb Keith Dart:

> Have you ever wondered where your python modules get imported from?
> Here is a little script, called "pywhich", that will tell you.

Nice, you could add it to the python cookbook.

 Thomas


-- 
Thomas Güttler, http://www.thomas-guettler.de/


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


Re: BASIC vs Python

2004-12-17 Thread Gregor Horvath
Peter Otten wrote:
May you could give us an idea of the current state of basic affairs then by
translating the following example snippet:
yes you can do it in VB6, but pythons lists and dictionarys are superior 
to those built in in VB and I think to those in most other languages.

It's me wrote:

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]
I think line3 should be
>>dct1 = dict.fromkeys(lst2)
correct?
VB6 Code:
Sub xy()
Dim lst1 As New Collection
Dim lst2 As New Collection
lst1.Add "ab", "ab": lst1.Add "ac", "ac": lst1.Add "ba", "ba": lst1.Add 
"bb", "bb": lst1.Add "bc", "bc"
lst2.Add "ac", "ac": lst2.Add "ab", "ab": lst2.Add "bd", "bd": lst2.Add 
"cb", "cb": lst2.Add "bb", "bb"

For Each item In lst1
  If ColHasKey(lst2, item) Then Debug.Print "in:" & item
Next
For Each item In lst1
  If Not ColHasKey(lst2, item) Then Debug.Print "not in:" & item
Next
End Sub
Function ColHasKey(col As Collection, item) As Boolean
On Error GoTo er
  A = col(item)
  ColHasKey = True
Exit Function
er:
  If Err.Number = 5 Then
ColHasKey = False
  Else
Err.Raise Err.Number
  End If
End Function
--
http://mail.python.org/mailman/listinfo/python-list


Re: BASIC vs Python

2004-12-17 Thread Peter Hickman
Gerhard Haering wrote:
IIRC BASIC does have a portable language definition:
ANSI BASIC, which is the old crap with GOTO and GOSUB that nobody in
their right mind would want to use nowadays ...
True, I forgot about that. The nearest to portable I have seen is Bywater Basic. 
At least it is written in C and can be ported to most machines. However it is 
still old school - though less so than ANSI BASIC.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Efficient grep using Python?

2004-12-17 Thread P
Christos TZOTZIOY Georgiou wrote:
On Thu, 16 Dec 2004 14:28:21 +, rumours say that [EMAIL PROTECTED]
I challenge you to a benchmark :-)

Well, the numbers I provided above are almost meaningless with such a
small set (and they easily could be reverse, I just kept the
convenient-to-me first run :).  Do you really believe that sorting three
files and then scanning their merged output counting duplicates is
faster than scanning two files (and doing lookups during the second
scan)?
$ python
Python 2.3.3 (#1, Aug 31 2004, 13:51:39)
[GCC 3.3.3 (SuSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
x=open('/usr/share/dict/words').readlines()
len(x)
45378
import random
random.shuffle(x)
open("/tmp/A", "w").writelines(x)
random.shuffle(x)
open("/tmp/B", "w").writelines(x[:1000])
$ time sort A B B | uniq -u >/dev/null
real0m0.311s
user0m0.315s
sys 0m0.008s
$ time grep -Fvf B A >/dev/null
real0m0.067s
user0m0.064s
sys 0m0.003s
(Yes, I cheated by adding the F (for no regular expressions) flag :)
Also you only have 1000 entries in B!
Try it again with all entries in B also ;-)
Remember the original poster had 100K entries!
and finally destroys original line
order (should it be important).
true
That's our final agreement :)
Note the order is trivial to restore with a
"decorate-sort-undecorate" idiom.
--
Pádraig Brady - http://www.pixelbeat.org
--
--
http://mail.python.org/mailman/listinfo/python-list


Re: pywhich script - where is that module?

2004-12-17 Thread Dennis Benzinger
Thomas Guettler wrote:
> [...]
> Nice, you could add it to the python cookbook.
> [...]

Just in the case the OP doesn't know where to find the cookbook:
http://aspn.activestate.com/ASPN/Cookbook/Python/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: BASIC vs Python

2004-12-17 Thread Peter Otten
Gerhard Haering wrote:

> In VB6, it would an exercise of working around the limitations of the
> data structures.
 
In MS Access I would probably end up with two database tables. The
juxtaposition of incredibly polished and virtually unusable features is
amazing.

Peter

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


Re: wxPython question

2004-12-17 Thread André

M.E.Farmer wrote:
> 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

I needed to scale the image down to 16 by 16 on my Windows computer to
make it work.
hth,
André

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


Re: do you master list comprehensions?

2004-12-17 Thread aleks90210
Thought you might enjoy my super-small flatten function: (though google
groups seems to be munging my whitespace today)

def flatten(d):
"flatten([[[1,[2,3],[4,5]],6],[7]])==[1,2,3,4,5,6,7]"
return reduce(lambda a,b:a+b,[(type(x) in (list, tuple) \
and flatten(x) or [x]) for x in d])

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


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

2004-12-17 Thread Kent Johnson
Steven Bethard wrote:
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. ;)
You can copy and paste from a Windows command prompt. It's a bit bizarre, but
- In the system menu for a command window, pick Properties
- On the Options tab, turn on Quick Edit mode
- Now you can copy and paste with right-click (!). If you have text selected, right-click will copy, 
otherwise paste. It's a bit strange but it works.

I think it's wonderfully ironic that in Windows - which takes such pains to make everything keyboard 
accessible - in a *command line* window, which is using keyboard input by its nature - you have to 
use the mouse for copy and paste!!

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


Re: Efficient grep using Python?

2004-12-17 Thread sf
The point is that when you have 100,000s of records, this grep becomes
really slow?

Any comments?

Thats why I looked for python :)


> that would be
>
> grep -vf B A
>
> and it is a rare use of grep, indeed.
> -- 
> TZOTZIOY, I speak England very best.
> "Be strict when sending and tolerant when receiving." (from RFC1958)
> I really should keep that in mind when talking with people, actually...


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


Re: setup.py - just what is it for ?

2004-12-17 Thread Fuzzyman
You could *try* writing a cgi which did something like
os.spawnv('python', ['setup.py', 'install']) (or whatever would be
right without looking up the docs)...

You sometimes don't need admin rights to run setup.py

I would be interested in the results.

Regards,

Fuzzy
http://www.voidspace.org.uk/atlantibots/pythonutils.html

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


Re: setup.py - just what is it for ?

2004-12-17 Thread Fuzzyman
You could *try* writing a cgi which did something like
os.spawnv('python', ['setup.py', 'install']) (or whatever would be
right without looking up the docs)...

You sometimes don't need admin rights to run setup.py

I would be interested in the results.

Regards,

Fuzzy
http://www.voidspace.org.uk/atlantibots/pythonutils.html

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


Re: Efficient grep using Python? [OT]

2004-12-17 Thread TZOTZIOY
On Fri, 17 Dec 2004 12:21:08 +, rumours say that [EMAIL PROTECTED]
might have written:

[snip some damn lie aka "benchmark"]

[me]
>> (Yes, I cheated by adding the F (for no regular expressions) flag :)
>
>Also you only have 1000 entries in B!
>Try it again with all entries in B also ;-)
>Remember the original poster had 100K entries!

Well, that's the closest I can do:

$ py
Python 2.4c1 (#3, Nov 26 2004, 23:39:44)
[GCC 3.3.3 (SuSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys; sys.ps1='.>>'
.>> alist=[line.strip() for line in open('/usr/share/dict/words')]
.>> words=set()
.>> for word in alist:
... words.add(word + '\n')
... words.add(word[::-1] + '\n')
...
.>> len(words)
90525
.>> words=list(words)
.>> open('/tmp/A', 'w').writelines(words)
.>> import random; random.shuffle(words)
.>> open('/tmp/B', 'w').writelines(words[:9])
.>>
$ time sort A B B | uniq -u >/dev/null

real0m2.408s
user0m2.437s
sys 0m0.037s
$ time grep -Fvf B A >/dev/null

real0m1.208s
user0m1.161s
sys 0m0.035s

What now?-)

Mind you, I only replied in the first place because you wrote (my
emphasis) "...here is *the* unix way..." and it's the bad days of the
month (not mine, actually, but I suffer along...)

and finally destroys original line
order (should it be important).
>>>
>>>true
>> 
>> That's our final agreement :)
>
>Note the order is trivial to restore with a
>"decorate-sort-undecorate" idiom.

Using python or unix tools (eg 'paste -d', 'sort -k', 'cut -d')?
Because the python way has been already discussed by Friedrik, John and
Tim, and the unix way gets overly complicated (aka non-trivial) if DSU
is involved.

BTW, the following occurred to me:

[EMAIL PROTECTED]/tmp
$ cat >A
aa
ss
dd
ff
gg
hh
jj
kk
ll
aa
[EMAIL PROTECTED]/tmp
$ cat >B
ss
ff
hh
kk
[EMAIL PROTECTED]/tmp
$ sort A B B | uniq -u
dd
gg
jj
ll
[EMAIL PROTECTED]/tmp
$ grep -Fvf B A
aa
dd
gg
jj
ll
aa

Note that 'aa' is contained twice in the A file (to be filtered by B).
So our methods do not produce the same output.  As far as the OP wrote:

>Essentially, want to do efficient grep, i..e from A remove those lines which
>are also present in file B.

grep is the unix way to go for both speed and correctness.

I would call this issue a dead horse.
-- 
TZOTZIOY, I speak England very best.
"Be strict when sending and tolerant when receiving." (from RFC1958)
I really should keep that in mind when talking with people, actually...
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2004-12-17 Thread Amir Dekel
Jeff Shannon wrote:
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...

Both problems solved! The .pth seems like the best solution for the 
first one, and for the expanduser("~") I just added a $HOME variable to 
the Environment variables of WinXP. Simple solutions. Thanks Jeff

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


Re: BASIC vs Python

2004-12-17 Thread Richards Noah (IFR LIT MET)

"Christos TZOTZIOY Georgiou" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> On Fri, 17 Dec 2004 01:43:56 -0600, rumours say that Mike Meyer
> <[EMAIL PROTECTED]> might have written:
>
> >Assembler was better - at least you had recursion with
> >assembler.
>
> You had recursion with BASIC --what you probably mean is that you had no
> stacked parameters (unless you imitated that with using an indexed
> array).
>
> 90 rem recursion
> 100 print "beautiful colours"
> 110 gosub 100

I think he means that you had no recursive function calls in BASIC.  I
suppose, to most of us, "recursion" doesn't mean "doing things more than
once," since by that definition, iteration is also recursion.  Recursion
generally means some type of self reference, like in functional languages,
where the simplest recursion is base case/recurring step.  BASIC didn't do
this, without a bit of unsightly hackery.  Then again, I don't believe that
it was really a concern at the time, so I don't suppose its too important of
an issue :)


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


Re: BASIC vs Python

2004-12-17 Thread It's me

"Gregor Horvath" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Peter Otten wrote:
>
> > May you could give us an idea of the current state of basic affairs then
by
> > translating the following example snippet:
>
> yes you can do it in VB6, but pythons lists and dictionarys are superior
> to those built in in VB and I think to those in most other languages.
>
> >
> > It's me wrote:
> >
> >
> >>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]
>
> I think line3 should be
>
>  >>dct1 = dict.fromkeys(lst2)
>
> correct?
>

Correct.

> VB6 Code:
>
> Sub xy()
>
> Dim lst1 As New Collection
> Dim lst2 As New Collection
>
> lst1.Add "ab", "ab": lst1.Add "ac", "ac": lst1.Add "ba", "ba": lst1.Add
> "bb", "bb": lst1.Add "bc", "bc"
> lst2.Add "ac", "ac": lst2.Add "ab", "ab": lst2.Add "bd", "bd": lst2.Add
> "cb", "cb": lst2.Add "bb", "bb"
>
> For Each item In lst1
>If ColHasKey(lst2, item) Then Debug.Print "in:" & item
> Next
>
> For Each item In lst1
>If Not ColHasKey(lst2, item) Then Debug.Print "not in:" & item
> Next
>
> End Sub
>
>
> Function ColHasKey(col As Collection, item) As Boolean
> On Error GoTo er
>A = col(item)
>ColHasKey = True
> Exit Function
> er:
>If Err.Number = 5 Then
>  ColHasKey = False
>Else
>  Err.Raise Err.Number
>End If
> End Function

Absolutely *ugly*!

But still, your point is well taken.  Thank you for pointing this out.

Adam was right:

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




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


Re: Cool object trick

2004-12-17 Thread Steve Holden
[EMAIL PROTECTED] wrote:
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 ;-)
Of course this whole thing of substituting attribute access for 
dictionary keys only works as long as the keys are strings with the same 
syntax as Python identifiers, so one shouldn't go completely overboard. 
"To the man with a hammer everything looks like a nail", and so on.

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: BASIC vs Python

2004-12-17 Thread Peter Otten
Gregor Horvath wrote:

> Peter Otten wrote:
> 
>> May you could give us an idea of the current state of basic affairs then
>> by translating the following example snippet:
> 
> yes you can do it in VB6, but pythons lists and dictionarys are superior
> to those built in in VB and I think to those in most other languages.
> 
>> 
>> It's me wrote:
>> 
>> 
>>>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]
> 
> I think line3 should be
> 
>  >>dct1 = dict.fromkeys(lst2)
> 
> correct?

Either that or lst2 in the list comprehensions.

> VB6 Code:

[snip]

> Function ColHasKey(col As Collection, item) As Boolean
> On Error GoTo er
>A = col(item)
>ColHasKey = True
> Exit Function
> er:
>If Err.Number = 5 Then
>  ColHasKey = False
>Else
>  Err.Raise Err.Number
>End If
> End Function

Almost an exception handler ;-)
Thank you for taking the time to show me. I had VB.Net in mind when I wrote
"current state", though.

Peter

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


Re: BASIC vs Python

2004-12-17 Thread Gregor Horvath
It's me wrote:
Absolutely *ugly*!
But still, your point is well taken.  Thank you for pointing this out.
Adam was right:
"Don't do it, unless your goal is simply to embarrass and insult
programmers".

OK. Then please schow me, how you can create a complex form with grids, 
explorer like trees etc. in 2 minutes in standard python.

Or make any given standard python object accessible from MS Excel in 2 
minutes.

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


Re: Performance (pystone) of python 2.4 lower then python 2.3 ???

2004-12-17 Thread Andreas Kostyrka
Ok, here are my results, all python Versions supplied by Debian:

[EMAIL PROTECTED]:~> python1.5 /usr/lib/python1.5/test/pystone.py
Pystone(1.1) time for 1 passes = 1.33
This machine benchmarks at 7518.8 pystones/second
[EMAIL PROTECTED]:~> python2.2 /usr/lib/python1.5/test/pystone.py
Pystone(1.1) time for 1 passes = 1.03
This machine benchmarks at 9708.74 pystones/second
[EMAIL PROTECTED]:~> python2.3 /usr/lib/python1.5/test/pystone.py
Pystone(1.1) time for 1 passes = 0.73
This machine benchmarks at 13698.6 pystones/second
[EMAIL PROTECTED]:~> python2.4 /usr/lib/python1.5/test/pystone.py
Pystone(1.1) time for 1 passes = 0.66
This machine benchmarks at 15151.5 pystones/second

Run on a Knoppix/Debian based Duron 700 (Sony PCG-FX201 laptop).

I guess there must be differences in how your pythons got compiled, even
if you didn't specifies explicitly options.

Andreas

Am Mo, den 13.12.2004 schrieb Lucas Hofman um 17:09:
> Hi,
> 
> Just installed Python 2.4 on a machine (RH8.0 Linux) that also has python 2.3
> and python 2.2 installed. The latter came with the linux distribution, the 
> other
> are compiled from source tarballs.
> 
> Comparing them gives the following unexpected result:
> 
> [EMAIL PROTECTED] test]$ /usr/bin/python pystone.py
> Pystone(1.1) time for 5 passes = 1.86
> This machine benchmarks at 26881.7 pystones/second
> [EMAIL PROTECTED] test]$ /usr/local/bin/python2.3 pystone.py
> Pystone(1.1) time for 5 passes = 1.22
> This machine benchmarks at 40983.6 pystones/second
> 
> This is ok, a 52% speed increase, but:
> 
> [EMAIL PROTECTED] test]$ /usr/local/bin/python2.4 pystone.py
> Pystone(1.1) time for 5 passes = 1.31
> This machine benchmarks at 38167.9 pystones/second
> 
> A 7% speed DECREASE??? According to the documentation it should be a 5% 
> increase?
> 
> The machine is a 3.0 GHz Xeon box.
> 
> Both python 2.3 and 2.4 where configure without any options.
> 
> Anyone who understands what is going on?
> 
> Regards, Lucas


signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil
-- 
http://mail.python.org/mailman/listinfo/python-list

decorator peculiarity

2004-12-17 Thread Diez B. Roggisch
Hi,

I just wrote my first decorator example - and  I already love them.

However I've encountered one peculiarity that strikes me odd:

When one writes a decorated function like this:

@decorate
def foo():
pass

the function decorate usually looks like this:

def decorate(func):
def _d(*args, **kwargs):
do_something()
# call func
func(*args, **kwargs)
return _d

So the function decorator has to return a function that is bound to the name
foo in the originating context (module or class) and gets the function
passed as argument.

But if I want my decorator to be parametrized, it looks like this:

@decorate(arg)
def foo():
pass

def decorate(arg):
def f(func):
def _d(*args, **kwargs):
do_something(arg)
# call func
func(*args, **kwargs)
return _d

So what happens is that an decorater with arguments is called with these,
returns a callable that then is called with foo, and the result is stored
under foo.

Now why this layer of indirection? I would have supposed that things look
like this:


def decorate(func, arg):
def _d(*args, **kwargs):
do_something(arg)
# call func
func(*args, **kwargs)
return _d

A sideeffect of this behaviour is that for a fully keyword-argumentized
function I still have to write parentheses:

@decorate()
def foo():
pass

def decorate(arg=None):
def f(func):
def _d(*args, **kwargs):
do_something(arg)
# call func
func(*args, **kwargs)
return _d

I don't mind the extra parentheses too much - it just made me wonder what
the rationale behind this is.

-- 
Regards,

Diez B. Roggisch
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2004-12-17 Thread Steve Holden
Mark Devine wrote:
I got the script working. Thanks for all your help everyone. Trouble is its not 
showing the correct results. Here is the script and results:
Well, that's a pretty unusual interpretation of the word "working" :-)
> [...]
I see from later postings you are getting closer to an answer, but 
obviously you still have to strip out the characters that you don't want 
to affect the match (such as "(" and ")").

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: Accessing DB2 with Python

2004-12-17 Thread Simon Brunning
On Thu, 16 Dec 2004 20:20:09 -0500, Grumman <[EMAIL PROTECTED]> wrote:
> I'm sure there's a pretty complete python ADO wrapper out there as well.

http://adodbapi.sourceforge.net/

-- 
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lies about OOP

2004-12-17 Thread Peter Hansen
Alex Stapleton wrote:
To canadians there is no "outside" of hockey games.
Some Canadians aren't so fanatical about hockey, or any sport.
For example, I've still never figured out how "conversions" work...
or switch-hitters.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Efficient grep using Python?

2004-12-17 Thread P
sf wrote:
The point is that when you have 100,000s of records, this grep becomes
really slow?
There are performance bugs with current versions of grep
and multibyte characters that are only getting addressed now.
To work around these do `export LANG=C` first.
In my experience grep is not scalable since it's O(n^2).
See below (note A and B are randomized versions of
/usr/share/dict/words (and therefore worst case for the
sort method)).
$ wc -l A B
  45427 A
  45427 B
$ export LANG=C
$ time grep -Fvf B A
real0m0.437s
$ time sort A B B | uniq -u
real0m0.262s
$ rpm -q grep coreutils
grep-2.5.1-16.1
coreutils-4.5.3-19
--
Pádraig Brady - http://www.pixelbeat.org
--
--
http://mail.python.org/mailman/listinfo/python-list


Re: BASIC vs Python

2004-12-17 Thread Steve Holden
Adam DePrince wrote:
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.
But that language was COBOL, not BASIC. BASIC is actually an acronym for 
"Beginners' All-purpose Symbolic Instruction Code", which the initial 
implementations at Dartmouth weren't, really. The big innovation was the 
use of line-numbering to allow interactive editing and testing of a program.

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: BASIC vs Python

2004-12-17 Thread Steve Holden
Gregor Horvath wrote:
It's me wrote:
Absolutely *ugly*!
But still, your point is well taken.  Thank you for pointing this out.
Adam was right:
"Don't do it, unless your goal is simply to embarrass and insult
programmers".

OK. Then please schow me, how you can create a complex form with grids, 
explorer like trees etc. in 2 minutes in standard python.

Or make any given standard python object accessible from MS Excel in 2 
minutes.

If only one could. That would be a system worth using.
For what it's worth, the estimable "Win32 Programming in Python" by 
Hammond anf Robinson does spend quite a lot of space explaiing how to 
build Python functionality with VB-style front-ends.

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: Permission

2004-12-17 Thread Larry Bates
The function is os.rename(old, new).  If you actually
tried 'os.raname' (as your post suggests) that is an illegal
function.  I suspect that you mistyped it in your post,
but Peter's replys is correct.  Always copy and paste your
code and your traceback error message so it will be precise.
Permisssion denied means that you don't have permission to
rename this file.  Normally this is a rights issue.
BTW-os.rename works on XP.
Larry Bates
Syscon, Inc.
-g00t©- wrote:
--( 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: Cool object trick

2004-12-17 Thread Fredrik Lundh
Steve Holden wrote:

>> Certainly makes writing 'print obj.spam, obj.spam, obj.eggs, obj.bacon,
>> obj.sausages, "and", obj.spam' a lot easier ;-)
>>
> Of course this whole thing of substituting attribute access for dictionary 
> keys only works as long 
> as the keys are strings with the same syntax as Python identifiers, so one 
> shouldn't go completely 
> overboard.

unless you're willing to use getattr() for thos oddball cases, of course.

>>> class Dummy:
... pass
...
>>> x = Dummy()
>>> setattr(x, "spam&egg", "hello")
>>> getattr(x, "spam&egg")
'hello'
>>> x.spam&egg
Traceback (most recent call last):
  File "", line 1, in ?
AttributeError: Dummy instance has no attribute 'spam'

but seriously, turning container elements into attributes should only be done
if it makes sense from a design perspective.  (and vice versa; you shouldn't
use a dictionary if an object would make more sense -- but attribute abuse
is a lot more common)

 



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


Re: Potential improvement on delegation via explicit calls and super

2004-12-17 Thread Thomas Guettler
Am Fri, 17 Dec 2004 02:17:38 -0600 schrieb Robert Dick:

> Derived classes sometimes need to delegate portions of the work in overridden 
> methods to methods in their base classes.  This was traditionally done with 
> explicit calls in python, e.g.,
> 
> class Base:
>   def __init__(self):
> print 'base'
> 
> class Left(Base):
>   def __init__(self, arg):
> Base.__init__(self)
> print 'left'
> 
> class Right(Base):
>   def __init__(self, arg):
> Base.__init__(self)
> print 'right'

If you can change the source of Base, I would do it like
this:

class Base:
_init_done=0
def __init__(self):
if self._init_done:
return
self._init_done=1

# ... do init


 Thomas

-- 
Thomas Güttler, http://www.thomas-guettler.de/


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


Re: BASIC vs Python

2004-12-17 Thread Hans Nowak
Gregor Horvath wrote:
It's me wrote:
Absolutely *ugly*!
But still, your point is well taken.  Thank you for pointing this out.
Adam was right:
"Don't do it, unless your goal is simply to embarrass and insult
programmers".
OK. Then please schow me, how you can create a complex form with grids, 
explorer like trees etc. in 2 minutes in standard python.
To be fair, this is more a property of a GUI builder than of a language...
--
Hans Nowak
http://zephyrfalcon.org/
--
http://mail.python.org/mailman/listinfo/python-list


Request for Help in OpenSourcing a Project

2004-12-17 Thread Colin Meeks
I love Python and started back when 1.52 was the popular version.
Whilst learning Python, I created a website framework called [EMAIL PROTECTED],
which I run at the following two sites :

http://www.meeks.ca
All content is done in [EMAIL PROTECTED] and static pages are created.

http://www.programmedintegration.com
All content is created dynamically.

[EMAIL PROTECTED] is a mix between a CMS and web framework.  I've been
personally using it for more than 5 years, however it's never formally
been completed and has a lot of rough edges. I created [EMAIL PROTECTED] to
handle all data as straight text files, as my provider at the time,
had no facilities for databases, so this is a definite area that
[EMAIL PROTECTED] could be expanded.

What I'm basically after is someone to assist in polishing up the
product and ultimately releasing as OpenSource or some similar kind of
license, whereby I retain copyright, but the use of the product is
free. Also if anyone has any tips or advice, I'd be most grateful. 
I'm loathe to release the code at present, as it's really quite
embarassing in places, and has a strong need for markup code to be
removed from within program code and placed as separate files.

Anyway if anyone is able to assist or advise, I'd be more than happy
to discuss things futher.

Regards

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


Re: BASIC vs Python

2004-12-17 Thread Fredrik Lundh
Richards Noah wrote:

>> You had recursion with BASIC --what you probably mean is that you had no
>> stacked parameters (unless you imitated that with using an indexed
>> array).
>>
>> 90 rem recursion
>> 100 print "beautiful colours"
>> 110 gosub 100
>
> I think he means that you had no recursive function calls in BASIC.  I
> suppose, to most of us, "recursion" doesn't mean "doing things more than
> once," since by that definition, iteration is also recursion.  Recursion
> generally means some type of self reference

Note that he uses gosub, not goto.  The code block that starts at line 100
and ends at line 110 calls itself recursively.  Works just fine in many (most?)
BASIC implementations (at least until you run out of call stack).

(the original BASIC was a different thing, though: quoting from the 1964 hand-
book: "the user must be very careful not to write a program in which GOSUB
appars inside a subroutine which itself is entered via a GOSUB; it just won't
work".  The handbook also states that the program size is limited to "two feet
of teletype paper"...)

 



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


Dr. Dobb's Python-URL! - weekly Python news and links (Dec 15)

2004-12-17 Thread Cameron Laird
QOTW:  "[Python demands more thought in optimization, because i]n
other languages, by the time you get the bloody thing working it's
time to ship, and you don't have to bother worrying about making
it optimal." -- Simon Brunning

"One of the best features of c.l.py is how questions phrased in the
most ambiguous terms are often slowly elaborated into meaningful
enquiries." -- Steve Holden


Martin Bless summarizes in an extremely valuable post what
you need to know to generate Python-related executable binaries
targeted for Windows*.

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/73f29284d1e031c7/

John Hunter, Fredrik Lundh, Pádraig Brad, and Tim Peters
work out in public on a model problem of textual analysis.

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/b009627e9a5abc64/7d75f531ba8a7fe2

Amidst the usual combination of heat and light (in this case,
on commercial acceptance and applicability of OO), Mike Meyer
narrates from his own experience an example of how good object
orientation can be.

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/16590f4138b6a978/

gDesklets are attention-grabbing Py-scriptable desktop decorations.
http://gdesklets.gnomedesktop.org/index.php

Sure, a list comprehension can comprise multiple "for"-s.

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/ee5f7f8c227b22ff/

Mac OS X makes for highly-desired (at least by some) development
hosts; moreover "there are three killer features in MacPython
that you can't get anywhere else ..."
http://mail.python.org/pipermail/pythonmac-sig/2004-December/012298.html



Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily  
Mygale is a news-gathering webcrawler that specializes in (new)
World-Wide Web articles related to Python.
 http://www.awaretek.com/nowak/mygale.html 
While cosmetically similar, Mygale and the Daily Python-URL
are utterly different in their technologies and generally in
their results.

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.

http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce

Brett Cannon continues the marvelous tradition established by 
Andrew Kuchling and Michael Hudson of intelligently summarizing
action on the python-dev mailing list once every other week.
http://www.python.org/dev/summary/

The Python Package Index catalogues packages.
http://www.python.org/pypi/

The somewhat older Vaults of Parnassus ambitiously collects references
to all sorts of Python resources.
http://www.vex.net/~x/parnassus/   

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

The Python Business Forum "further[s] the interests of companies
that base their business on ... Python."
http://www.python-in-business.org

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
responsibility for Python's development and maintenance. 
http://www.python.org/psf/
Among the ways you can support PSF is with a donation.
http://www.python.org/psf/donate.html

Kurt B. Kaiser publishes a weekly report on faults and patches.
http://www.google.com/groups?as_usubject=weekly%20python%20patch
   
Cetus collects Python hyperlinks.
http://www.cetus-links.org/oo_python.html

Python FAQTS
http://python.faqts.com/

The Cookbook is a collaborative effort to capture useful and
interesting recipes.
http://aspn.activestate.com/ASPN/Cookbook/Python

Among several Python-oriented RSS/RDF feeds available are
http://www.python.org/channews.rdf
http://bootleg-rss.g-blog.net/pythonware_com_daily.pcgi
http://python.de/backend.php
For more, see
http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all
The old Python "To-Do List" now lives principally in a
SourceForge reincarnation.
http://sourceforge.net/tracker/?atid=355470&group_id

Email filters in python

2004-12-17 Thread sf
Would someome like to post their email filters code. Its so common that
probably some standard library
supports it or many would have written it already. If I have basic
structure, I can take from there.

( Essentially I want get rid of XP by getting rid of powerful mail client
"TheBat!" )

..
- open POP-SSL connection to pop.someserver.com
- Get all mails and store as Unix mail file (mymails)
- do not delete mails from server
- close connection.
..
- open mymails file

- Do following for each mail in mymails file (one by one)
{
- get header fields:  {FROM, TO, CC, Subject,... more ... }
- some conditons (FROM is found my addresslist.txt but not part of
my rejectlist.txt )
append that mail to some existing file.
}


..
- open SMTP-TLS connection to smtp.someserver.com
- send all mails in my unix mail file
- close connection
..


Thanks.


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


Re: Cool object trick

2004-12-17 Thread Steve Holden
Fredrik Lundh wrote:
Steve Holden wrote:

Certainly makes writing 'print obj.spam, obj.spam, obj.eggs, obj.bacon,
obj.sausages, "and", obj.spam' a lot easier ;-)
Of course this whole thing of substituting attribute access for dictionary keys only works as long 
as the keys are strings with the same syntax as Python identifiers, so one shouldn't go completely 
overboard.

unless you're willing to use getattr() for thos oddball cases, of course.
Of course.
>>> class Dummy:
... pass
...
>>> x = Dummy()
>>> setattr(x, "spam&egg", "hello")
>>> getattr(x, "spam&egg")
'hello'
>>> x.spam&egg
Traceback (most recent call last):
  File "", line 1, in ?
AttributeError: Dummy instance has no attribute 'spam'
but seriously, turning container elements into attributes should only be done
if it makes sense from a design perspective.  (and vice versa; you shouldn't
use a dictionary if an object would make more sense -- but attribute abuse
is a lot more common)
Really we are talking about the outer limits here. Anyone preferring
setattr(x, "spam&egg", "hello")
to
x["spam&egg"] = "hello"
when it isn't necessary clearly doesn't share our two principal 
attributes: an elegant sense of design, fine knowledge of Python and an 
   inherent modesty.

Sorry: out *three* principal attributes. Bugger, I'll come in again.
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: Cool object trick

2004-12-17 Thread has
Jive wrote:

> # Is that really much different from this?

Functionally, no. However it can help make code more readable when
dealing with complex data structures, e.g. compare:

obj.spam[1].eggs[3].ham

to:

obj["spam"][1]["eggs"][3]["ham"]

I've used it a couple times for this particular reason and it
definitely has its niche; though I'm not sure it's sufficiently common
or useful to justify its inclusion it in the standard library, and it's
trivial to whip up as-and-when it's needed.

BTW & FWIW, I think the usual name for this kind of structure is
'record' (or 'struct' in C).

HTH

has

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


Re: decorator peculiarity

2004-12-17 Thread Scott David Daniels
Diez B. Roggisch wrote:
def decorate(func):
def _d(*args, **kwargs):
do_something()
# call func
func(*args, **kwargs)
return _d
@decorate
def foo():
pass
[T]he function decorator has to return a function that is bound to the name
foo in the originating context (module or class) and gets the function
passed as argument. If I want my decorator ... parametrized...:
@decorate(arg)
def foo():
pass
def decorate(arg):
def f(func):
def _d(*args, **kwargs):
do_something(arg)
# call func
func(*args, **kwargs)
return _d
Now why this layer of indirection?
Let's rewrite your example a bit, it may become obvious.
 def decorate(func):
 def replacement(argspec):
 do_something()
 return func(argspec)
 return replacement
 @decorate
 def foo(argspec): pass
---
 def decorate2():
 def _decorate(func):
 def replacement(argspec):
 do_something()
 return func(argspec)
 return replacement
 return _decorate
 @decorate()
 def foo(argspec): pass
---
 def decorate3(arg):
 def _decorate(func):
 def replacement(argspec):
 do_something()
 return func(argspec)
 return replacement
 return _decorate
 @decorate3(arg)
 def foo(argspec): pass
---
Clear now? there is no extra indirection.  If you call something on
the @ line, the _result_of_that_call_ should be a decorator function.
If you use my curry recipe in the python cookbook, you can use curry
lower the apparent "indirection":
 def decorate4(arg, func):
 def replacement(argspec):
 do_something()
 return func(argspec)
 return replacement
 @curry(decorate4, arg)
 def foo(argspec): pass
By the way, I _do_ think curry is an appropriate name.  The Curry-Howard
isomorphism shows the equivalence of a functions on tuples with single-
argument functions returning functions.  In a functional language, where
there is no distinction made between a a function with no arg and its
result, the transformation is clear.  With a language like Python, which
pays attention to when a function is invoked, you are better off
returning a function which can take the remaining arguments, and
controlling when the final function is called by returning a function
that can take all the remaining arguments at once.
-Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: BASIC vs Python

2004-12-17 Thread Steve Holden
Steve Holden wrote:
Adam DePrince wrote:
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.
But that language was COBOL, not BASIC. BASIC is actually an acronym for 
"Beginners' All-purpose Symbolic Instruction Code", which the initial 
implementations at Dartmouth weren't, really. The big innovation was the 
use of line-numbering to allow interactive editing and testing of a 
program.

Which, now I remember, Digital Equipment extended to floating-point in 
their FOCAL language. I never did discover whether the number of 
insertions required was limited by the floating-point precision, but 
Focal was unique in my experience in allowing insertion of statement 1.5 
between statements 1 and 2.

(mumbles into beard and drools quietly in the corner).
talking-to-myself-again-ly y'rs  - 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: ftp

2004-12-17 Thread hawkmoon269
It turns out that the retrlines method strips of EOL CRLF and \n.  My
solution was to create a new method in ftplib that doesn't do this.
I'm assuming that there is a better OOP solution to this, e.g. some
kind of subclassing, but do not have the expertise as yet to implement
that.  At any rate, just thought I'd post in case others encountered
the same issue.  Incidentally, though, I'm wondering about the slightly
different transfer results.  Specifically, when I use DOS, the file
transfers like this --

string, string, string (hidden CRLF)
string, string, string (hidden CRLF)
...

but when I use Python in transfers like this --

string, string, string (hidden CRLF) string, string, string (hidden
CRLF).

If it's not obvious, the source file (sitting on a mainframe somewhere)
is in comma-delimited format.

As it is now, I've coded an Access application to automatically
"import" the file, clean it for my purposes, and "export" it's contents
appropriately etc.  But for whatever reason the import wizard inserts a
blank record for each CRLF.  When I use DOS and get the format
indicated above, this doesn't occur.  Any ideas as to how I could
resolve this?  It's not a big deal as I can just have Access refuse to
import blank lines.  However, the general procedure does take longer to
execute etc

hawk

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


Re: Email filters in python

2004-12-17 Thread Simon Brunning
On Fri, 17 Dec 2004 15:07:26 GMT, sf <[EMAIL PROTECTED]> wrote:
> Would someome like to post their email filters code. Its so common that
> probably some standard library
> supports it or many would have written it already. If I have basic
> structure, I can take from there.

http://spambayes.sourceforge.net/

-- 
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: BASIC vs Python

2004-12-17 Thread Thomas Bartkus
"Mike Meyer" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> "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. 

Because:
   Type code
   Run code.

Is easier to explain to the uninitiated than
   Type Code,
   compile code,
   make executable,
   run executable.

And - if a beginner is asking the question, there is no point getting mired
in an arcane discussion about all the in between mix and match flavors that
are constantly at play in the programming world.

As I said -
"Interpreted languages are bit more approachable for beginners"
Thomas Bartkus



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


Time Difference

2004-12-17 Thread GMane Python
Hello
  I was wondering if there is an existing function that would let me
determine the difference in time.  To explain:

Upon starting a program:

startup = time.time()

After some very long processing:
now = time.time()

print, now - startup

So, to print in a formatted way (D-H-M-S) the difference in time of startup
and now.

Thanks!
Dave



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


Re: decorator peculiarity

2004-12-17 Thread Diez B. Roggisch
Hi

> Clear now? there is no extra indirection.  If you call something on
> the @ line, the _result_of_that_call_ should be a decorator function.
> If you use my curry recipe in the python cookbook, you can use curry
> lower the apparent "indirection":

Ok - that makes it clear, thanks.

-- 
Regards,

Diez B. Roggisch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Time Difference

2004-12-17 Thread Fredrik Lundh
"GMane Python" <[EMAIL PROTECTED]> wrote:

>  I was wondering if there is an existing function that would let me
> determine the difference in time.  To explain:
>
> Upon starting a program:
>
> startup = time.time()
>
> After some very long processing:
> now = time.time()
>
> print, now - startup
>
> So, to print in a formatted way (D-H-M-S) the difference in time of startup
> and now.

now - startup gives you the difference in seconds; turning that into (days,
hours, minutes, seconds) isn't that hard (hint: lookup the divmod function
in the manual).

or you could use the datetime module:

>>> from datetime import datetime
>>> startup = datetime.today()
>>> now = datetime.today()
>>> print now - startup
0:00:06.625000

(see the library reference for details).

 



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


Re: Email filters in python

2004-12-17 Thread Diez B. Roggisch
> ..
> - open POP-SSL connection to pop.someserver.com
> - Get all mails and store as Unix mail file (mymails)
> - do not delete mails from server
> - close connection.
> ..
> - open mymails file
> 
> - Do following for each mail in mymails file (one by one)
> {
> - get header fields:  {FROM, TO, CC, Subject,... more ... }
> - some conditons (FROM is found my addresslist.txt but not part of
> my rejectlist.txt )
> append that mail to some existing file.
> }

For these two, use fetchmail and procmail.
> ..
> - open SMTP-TLS connection to smtp.someserver.com
> - send all mails in my unix mail file
> - close connection

I'm not totally sure how to do this best - but here python might indeed
help, using smtplib and mailbox.

-- 
Regards,

Diez B. Roggisch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ftp

2004-12-17 Thread Fredrik Lundh
"hawkmoon269" <[EMAIL PROTECTED]> wrote:

> It turns out that the retrlines method strips of EOL CRLF and \n.  My
> solution was to create a new method in ftplib that doesn't do this.
> I'm assuming that there is a better OOP solution to this, e.g. some
> kind of subclassing, but do not have the expertise as yet to implement
> that.

reading the documentation might help, somewhat:

  retrlines( command[, callback])


Retrieve a file or directory listing in ASCII transfer mode. command should
be an appropriate "RETR" command (see retrbinary()) or a "LIST" command
(usually just the string 'LIST'). The callback function is called for each 
line,
with the trailing CRLF stripped.

so if you want line endings, just use a callback that adds line endings:

def mycallback(line):
print line

ftp.retrlines("RETR ...", mycallback)

or, perhaps:

file = open("output.txt", "w")

def mycallback(line):
# note: file is a global variable
file.write(line)
file.write("\n")

ftp.retrlines(...)

(since the file is opened in text mode, the write method will automatically
convert "\n" to "\r\n" on windows).

 



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


Re: Time Difference

2004-12-17 Thread Frans Englich
On Friday 17 December 2004 15:40, Fredrik Lundh wrote:
> "GMane Python" <[EMAIL PROTECTED]> wrote:
> >  I was wondering if there is an existing function that would let me
> > determine the difference in time.  To explain:
> >
> > Upon starting a program:
> >
> > startup = time.time()
> >
> > After some very long processing:
> > now = time.time()
> >
> > print, now - startup
> >
> > So, to print in a formatted way (D-H-M-S) the difference in time of
> > startup and now.
>
> now - startup gives you the difference in seconds; turning that into (days,
> hours, minutes, seconds) isn't that hard (hint: lookup the divmod function
> in the manual).

I've been struggling with that too. Here's some more documentation:

http://pleac.sourceforge.net/pleac_python/datesandtimes.html

I have a followup question on this, slightly off-topic:

What is the best/simplest method to transfer a time to W3C XML Schema's type 
duration[1]? Is there any helper function for that?


Cheers,

Frans



1.
http://www.w3.org/TR/xmlschema-2/#duration
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ftp

2004-12-17 Thread Fredrik Lundh
"hawkmoon269" <[EMAIL PROTECTED]> wrote:

> Specifically, when I use DOS, the file transfers like this --
>
> string, string, string (hidden CRLF)
> string, string, string (hidden CRLF)
> ...
>
> but when I use Python in transfers like this --
>
> string, string, string (hidden CRLF) string, string, string (hidden
> CRLF).

what's a "(hidden CRLF)", and how does that differ from a line feed?

 



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


Re: BASIC vs Python

2004-12-17 Thread Jeremy Bowers
On Fri, 17 Dec 2004 13:53:15 +, Gregor Horvath wrote:
> OK. Then please schow me, how you can create a complex form with grids, 
> explorer like trees etc. in 2 minutes in standard python.
> 
> Or make any given standard python object accessible from MS Excel in 2 
> minutes.

Boa, gtkglade, or, I forget what the equivalent is for QT but I'm pretty
sure it has one.

Of course, I never use them because I find static forms anathema, and I
build my forms dynamically from metadata; more flexible, more powerful,
ultimately more maintainable. (I have *never* experienced the "Oh , I
have to change 25 forms in 5 minutes for the demo!" moment; I've only
heard about the horrors of programs with umpteen hundreds of distinct
static forms second hand.) Try *that* in VB. It can be done, but you lose
so fast it isn't even funny. 

One of the Facts of Life is that a sufficient quantitative change
*becomes* a qualitative change. Python makes enough things easier that you
do things that you'd never even imagine in VB.

I speak of VB 6, but knowing the language I'd still expect VB to be about
the worst .Net language to work in. BASIC bears only surface resemblance
to the BASIC of 30+ years ago but the philosophy hasn't changed. Static
forms are only a win if you need a program cranked out by one programmer
in less than a week; sadly, BASIC makes everything else so hard that few
people have realized this... but they have paid for it. Yes sir, you
always pay the piper.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Efficient grep using Python?

2004-12-17 Thread TZOTZIOY
On Fri, 17 Dec 2004 14:22:34 +, rumours say that [EMAIL PROTECTED]
might have written:

sf:

>sf wrote:
>> The point is that when you have 100,000s of records, this grep becomes
>> really slow?
>
>There are performance bugs with current versions of grep
>and multibyte characters that are only getting addressed now.
>To work around these do `export LANG=C` first.

You also should use the -F flag that Pádraig suggests, since you don't
have regular expressions in the B file.

>In my experience grep is not scalable since it's O(n^2).
>See below (note A and B are randomized versions of
>/usr/share/dict/words (and therefore worst case for the
>sort method)).
>
>$ wc -l A B
>   45427 A
>   45427 B
>
>$ export LANG=C
>
>$ time grep -Fvf B A
>real0m0.437s
>
>$ time sort A B B | uniq -u
>real0m0.262s
>
>$ rpm -q grep coreutils
>grep-2.5.1-16.1
>coreutils-4.5.3-19

sf, you better do your own benchmarks (there is quick, sample code in
other posts of mine and Pádraig's) on your machine, since on my test
machine the numbers are reversed re to these of Pádraig's (grep takes
half the time).

package versions (on SuSE 9.1 64-bit):

$ rpm -q grep coreutils
grep-2.5.1-427
coreutils-5.2.1-21

language:
$ echo $LANG
en_US.UTF-8

Caution: both solutions are interexchangeable as long as you don't have
duplicate lines in the A file.  If you do, use the grep version.
-- 
TZOTZIOY, I speak England very best.
"Be strict when sending and tolerant when receiving." (from RFC1958)
I really should keep that in mind when talking with people, actually...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [OT] Python IDE

2004-12-17 Thread Dan Perl

"Fuzzyman" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>
> Dan Perl wrote:
>> "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.
> .
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> If it's a short reply to a long post - in context - top posting is
> often *significantly * less annoying..
>
> Isn't there a quote that includes 'hobgobline of little minds'..
>
> Regards,
> Fuzzy
> http://www.voidspace.org.uk/atlantibots/pythonutils.html
>

That was my point.  I was being sarcastic again but I didn't put a warning 
anymore.  As I'm doing now, still posting at the bottom of a long posting.

I'm not sure whether you were attacking me too (am I the "little mind"?) or 
supporting me, Fuzzy.  Anyway, I think that Mike Meyer was more annoyed by 
my jab at US politics than by my top posting.  But it was safer for him to 
pick on the latter.

Dan 


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


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

2004-12-17 Thread Mark Devine
I got this working now. Thanks everybody for your help.

_
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

--- Begin Message ---
Happy to help. Pass it on.
regards
 Steve
Mark Devine wrote:
I got it working correctly now thanks. I was on the right track it was a subset not a superset that was required in the end and all has worked out fine for me. Thank you for all your help 

Steve Holden <[EMAIL PROTECTED]> wrote:

Mark Devine wrote:

I got the script working. Thanks for all your help everyone. Trouble is its not 
showing the correct results. Here is the script and results:
Well, that's a pretty unusual interpretation of the word "working" :-)
> [...]
I see from later postings you are getting closer to an answer, but 
obviously you still have to strip out the characters that you don't want 
to affect the match (such as "(" and ")").

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



_
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
--- End Message ---
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: ftp

2004-12-17 Thread hawkmoon269
I just wanted to indicate that a carriage return is present but not
visible.

hawk

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


RE: Cool object trick

2004-12-17 Thread Robert Brewer
Alex Stapleton wrote:
> you can't do
>
> var = "varA"
> obj = struct(varA = "Hello")
> print obj.var
>
> and expect it to say Hello to you.

Did you mean "print obj.varA"? I can't think of any use case for the way
you wrote it, so I'm naively guessing you've got a typo. Feel free to
correct me. ;)

>>> class struct(object):
... def __init__(self, **kwargs):
... self.__dict__.update(kwargs)
... 
>>> var = "varA"
>>> obj = struct(**{str(var): "Hello"})
>>> print obj.varA
Hello


Robert Brewer
MIS
Amor Ministries
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: ftp

2004-12-17 Thread hawkmoon269
That's a good idea.  Thanks! :-)

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


Troubleshooting: re.finditer() creates object even when no match found

2004-12-17 Thread Chris Lasher
Hello,
I really like the finditer() method of the re module. I'm having
difficulty at the moment, however, because finditer() still creates a
callable-iterator oject, even when no match is found. This is
undesirable in cases where I would like to circumvent execution of code
meant to parse out data from my finditer() object.

I know that if I place a finditer() object in an iterative for loop,
the loop will not execute, but is there some way I can test to see if
the object contains no matches in the first place? I thought about
using .next() but I don't want to lose the ability to process the first
(sometimes only) match in the finditer() object.
Thanks in advance,
Chris

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


Re: wxPython question

2004-12-17 Thread M.E.Farmer

André wrote:
> I needed to scale the image down to 16 by 16 on my Windows computer
to
> make it work.

Hello André,

# I actually ran this code ;)
import wx
app = wx.PySimpleApp()
class myframe(wx.Frame):
def __init__(self):
wx.Frame.__init__(self,None,-1,"Icon Frame",
size=(100,100),pos=(-1,-1))
frame = myframe()
wx.InitAllImageHandlers()
# this image is 32*32 on my computer
image = wx.Image('c:/Python22/pycon.ico', wx.BITMAP_TYPE_ANY)
image = image.ConvertToBitmap()

icon = wx.EmptyIcon()
icon.CopyFromBitmap(image)

frame.SetIcon(icon)

frame.Show()
app.MainLoop()

This works fine for me I am on windows 2000, and pycon.py is 32*32*24
Wonder why you had to resize?

On another note, be sure to check out the tools dir in either the
wxpython dir or wx dir it has a script called img2py.py.

img2py.py  --  Convert an image to PNG format and embed it in a Python
module with appropriate code so it can be loaded into
a program at runtime.  The benefit is that since it is
Python source code it can be delivered as a .pyc or
'compiled' into the program using freeze, py2exe, etc.

Be sure to use the -i flag so it will convert it to a wxIcon
Once you convert your icon to source using img2py.py you can do this:
import Icon
ICON = Icon.getIcon()
 frame.SetIcon(ICON)

Hth, 
 M.E.Farmer

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


A completely silly question

2004-12-17 Thread Amir Dekel
This must be the silliest question ever:
What about user input in Python? (like stdin)
Where can I find it? I can't find any references to it in the documentation.
Amir
--
http://mail.python.org/mailman/listinfo/python-list


Re: A completely silly question

2004-12-17 Thread Frans Englich
On Friday 17 December 2004 16:40, Amir Dekel wrote:
> This must be the silliest question ever:
>
> What about user input in Python? (like stdin)
> Where can I find it? I can't find any references to it in the
> documentation.

See sys.stdin


Cheers,

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


RE: A completely silly question

2004-12-17 Thread Batista, Facundo
Title: RE: A completely silly question





[Amir Dekel]


#- What about user input in Python? (like stdin)
#- Where can I find it? I can't find any references to it in 
#- the documentation.


sys.stdin


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


.   Facundo


  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

ADVERTENCIA.


La información contenida en este mensaje y cualquier archivo anexo al mismo, son para uso exclusivo del destinatario y pueden contener información confidencial o propietaria, cuya divulgación es sancionada por la ley.

Si Ud. No es uno de los destinatarios consignados o la persona responsable de hacer llegar este mensaje a los destinatarios consignados, no está autorizado a divulgar, copiar, distribuir o retener información (o parte de ella) contenida en este mensaje. Por favor notifíquenos respondiendo al remitente, borre el mensaje original y borre las copias (impresas o grabadas en cualquier medio magnético) que pueda haber realizado del mismo.

Todas las opiniones contenidas en este mail son propias del autor del mensaje y no necesariamente coinciden con las de Telefónica Comunicaciones Personales S.A. o alguna empresa asociada.

Los mensajes electrónicos pueden ser alterados, motivo por el cual Telefónica Comunicaciones Personales S.A. no aceptará ninguna obligación cualquiera sea el resultante de este mensaje.

Muchas Gracias.



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

  1   2   3   >