Re: Consecutive Character Sequences

2005-07-14 Thread Aries Sun
I have tested George's solutions, it seems not complete. When pass (s,
3) to the function hasConsequent(), it returns the wrong result.

The following is my approach. The performence may be not so good. There
must be better ones.

>>> from re import findall
>>> def hasConsequent(aString, minConsequent):
for ch in aString:
result = findall(ch*minConsequent, aString)
if len(result) >= 1:
return True
return False

>>> hasConsequent(s, 2)
True
>>> hasConsequent(s, 3)
True
>>> hasConsequent(s, 4)
False

Aries Sun

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


Re: extend for loop syntax with if expr like listcomp&genexp ?

2005-07-14 Thread Paul Rubin
Terry Hancock <[EMAIL PROTECTED]> writes:
> But of course that's not equivalent.  It's hard to imagine a
> use case for an enumerated loop when the object being
> iterated over is anonymous (will be lost as soon as the loop exits).

Huh?  Not at all.

  print 'List of Python fans:'
  for i,x in enumerate([p for p in people if p.favorite_language == 'Python']):
print '%d. %s'% (i, x.name)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: constructor list slice confusion

2005-07-14 Thread Simon Morgan
On Thu, 14 Jul 2005 08:38:36 +0200, Peter Otten wrote:

> Maybe, after a little renaming you can see it yourself:
> 
> class SomeClass:
> def __init__(self, default_contents=[]):
> # make a copy of default_contents that is # kept in a SomeClass
> instance
> self.contents = default_contents[:]
> def add(self, element):
> # modify the *copy* of default_contents...
> self.contents.append(element)

Aha, I think I get it now. default_contents will always be an empty list
because before anything is added to it, a copy is made.

I think I was focusing too hard on the constructor. :)

Thanks for your help.

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


how to get rate of pop3 receiving progress?

2005-07-14 Thread Leo Jay
when i use POP3.retr() in poplib module, the retr() function will not
return until the  receiving progress is finished

so, is there any way to get the rate of receiving progress?

Thanks

-- 
Best Regards,
Leo Jay
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: all possible combinations

2005-07-14 Thread Thorsten Kampe
* Thomas Bartkus (2005-07-13 20:20 +0100)
> "George Sakkis" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>> "rbt" <[EMAIL PROTECTED]> wrote:
>>
>>> Say I have a list that has 3 letters in it:
>>>
>>> ['a', 'b', 'c']
>>>
>>> I want to print all the possible 4 digit combinations of those 3
>>> letters:
>>>
>>> 4^3 = 64
>>
>>
>> It's actually 3^4 = 81 (3 candidates/choice ** 4 choices)
> 
> Yes.  You get a cigar!
> 
> Someone else (Jack Diederich) also mentioned "This is called a cartesian
> product, ..."
> Right again.

In set theory it's called "cartesian product" while in combinatorics
it's called "variation with repetition". There is some "die-hard"
terminology confusion about permutations, combinations and variations
(see [1] for example).

(luckily at least most of the Python "officials" (GvR and Frederik
Lundh) seem to agree about this terminology)

Thorsten

[1] 
http://groups-beta.google.com/group/comp.lang.python/msg/dea80dec0192eda6?hl=en&;
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: more newbie list questions

2005-07-14 Thread Ali
It's not really clear what you mean?

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


Re: more newbie list questions

2005-07-14 Thread Bernhard Holzmayer
googleboy wrote:

> Hi there.
Hi googleboy!
> 
> I am doing a bunch of processing over a list of lists,  and am
> interested in doing several things taht don't seem to be working for me
> just at the moment.
> 
> I have a list of books with several fields (Title, Author1, Author2,
> Publisher, ISBN) in a csv.
> 
> I have a cell.txt file that looks like this:
> 
> ++
> The title is %title%.  
> The author is %author1% %author2% 
> The Publisher is %publisher1% %publisher2% 
> The ISBN is %ISBN% 
> ++

This looks like a DOS-batch-file. Maybe you'd better just leave it to
DOS to populate it, just by exec-uting it  in an environment which 
has title, authort1, ... set. ??

On the other hand, if you need not relate to the cell.txt file, 
you could just use something like
 
sAuth = "The author is %s" % author1

> 
> I know how to do something like sAuth = re.sub('%author1%', author1,
> sTemplate), but I can't figure out to populate variables within python
> from the list of fields.

I guess, that you open the csv-file and then use readline for each record.
Since csv files are ; separated (or ,), just do
recordlist = current_line.split(';')
which provides all entries from the read line in a list.
Or even better:
(title,author1,author2,publisher1,publisher2,ISBN) = current_line.split(';')
Now you can do something like
sAuth = "The author is %s" % recordlist[1]  in the first case, or
sAuth = "The author is %s" % author1in the second

> 
> The second thing I am trying to figure out is how to add a field (or
> populate an empty field) called filename with the value of ISBN +
> '.txt', though I hope this becomes pretty self evident after someone
> helps me with the above.

You're certainly right about the evidence of the following:
filename="%s.txt" % ISBN

> 
> The last thing that is vexing me at the moment is something I am not
> sure if it is possible.  Once I have populated this filename field, I
> will want to try to do something like:
> 
> for book in all_books
> open(r'd:\path\to\files\%filename%', 'a')
> some_function
> 
> 
> Where I replace %filename% with the value of the filename field for
> each book.  Is it possible to do some sort of search and replace like
> that over a command within python?
> 
> Or is there another way entirely different to accomplish such a task,
> like maybe assigning the path/filename to a variable... ?
> 
I'd try like this:
0. Initialize an empty list   all_books=[]
1. While reading in the csv file line by line, you received the ISBN
   for that line(book). (Look above the line with the split command)
   Now add this ISBN to the list by:
all_books.append(ISBN)

2. After the list is complete (all records read, file closed),
   you can do this as you assumed:
for book in all_books:
f=open(r"d:\path\to\files\%s.txt" % book, 'a')
some_function...
f.close()
> TIA!
> 
> Googleboy
Bernhard

P.S: 
1. Looking into the Python tutorial which is available online at
www.python.org, would have answered most of your questions.

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


Re: exec method WMI

2005-07-14 Thread future_retro
Got it working, removed spawninstance and the driver path should have
been "C:\\test\\"

Cheers for your help Roger.

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


Python Newbie

2005-07-14 Thread linuxfreak
Hi all,
   I came accross this article by Eric Raymond in which he has sung
peans about the python language. Well that has whetted my appetite...
So I decided to get down and dirty. But alas I got down but not dirty..
i cant seem to find a good tutorial to help me get started. Whats the
next best thing to do? Ask the pros and where do you find them...in a
mailing list of course. So heres me asking if anyone has any pointers
to some good basic python tutorial. Something that teaches one to get
going.
Thanks a ton guys,



Linuxfreak

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


Ann: Tkinter drag and drop module

2005-07-14 Thread klappnase
I wrote a wrapper for the tkdnd Tk extension
(), which adds native drag and
drop support to Tkinter (windows and unix only).
It was the first time for me to try wrapping a Tk extension, and I
couldn't find any documentation on this, so I would still consider it
experimental; however at least for the most part it seems to work well.
The module can be used with both standard Tkinter and Tix, and makes it
quite easy to e.g. drop a bunch of files from a file manager onto any
Tkinter widget.
It comes with a basic reference manual and a small demo app.
It can be found at
.

Any feedback is much appreciated.

Best regards

Michael

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


Re: Python Newbie

2005-07-14 Thread Simon Brunning
On 14 Jul 2005 03:24:29 -0700, linuxfreak <[EMAIL PROTECTED]> wrote:
> Hi all,
>I came accross this article by Eric Raymond in which he has sung
> peans about the python language. Well that has whetted my appetite...
> So I decided to get down and dirty. But alas I got down but not dirty..
> i cant seem to find a good tutorial to help me get started. Whats the
> next best thing to do? Ask the pros and where do you find them...in a
> mailing list of course. So heres me asking if anyone has any pointers
> to some good basic python tutorial. Something that teaches one to get
> going.

http://wiki.python.org/moin/BeginnersGuide

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


Re: Splitting on a word

2005-07-14 Thread Bernhard Holzmayer
[EMAIL PROTECTED] wrote:

> Hi all,
> I am writing a script to visualize (and print)
> the web references hidden in the html files as:
> ' underlined reference'
> Optimizing my code, I found that an essential step is:
> splitting on a word (in this case 'href').
> 
> I am asking if there is some alternative (more pythonic...):

Sure. The htmllib module provides HTMLparser.
Here's an example, run it with your HTML file as argument
and you'll see a list of all href's in the document.

#
#!/usr/bin/python
import htmllib

def test():
import sys, formatter

file = sys.argv[1]
f = open(file, 'r')
data = f.read()
f.close()

f = formatter.NullFormatter()
p = htmllib.HTMLParser(f)
p.feed(data)

for a_link in p.anchorlist:
print a_link

p.close()

test()
#

I'm sure that this is far more Pythonic!

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


Mail System Error - Returned Mail

2005-07-14 Thread Mail Administrator
The original message was received at Thu, 14 Jul 2005 14:08:08 +0300
from python.org [157.76.199.159]

- The following addresses had permanent fatal errors -




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

Re: Frankenstring

2005-07-14 Thread Thomas Lotze
Andreas Lobinger wrote:

>  >>> t2 = f.find('2')+1

This is indeed faster than going through a string char by char. It doesn't
make for a nice character-based state machine, but of course it avoids
making Python objects for every character and uses the C implementation of
str for searching.

However, it's only fine if you are looking for single characters. As soon
as you're looking for classes of characters, you need the (slower) regex
machinery (as you well know, but for the sake of discussion...).

> A string, and a pointer on that string. If you give up the boundary
> condition to tell backwards, you can start to eat up the string via f =
> f[p:]. There was a performance difference with that, in fact it was faster
> ~4% on a python2.2.

When I tried it just now, it was the other way around. Eating up the
string was slower, which makes sense to me since it involves creating new
string objects all the time.

> I dont't expect any iterator solution to be faster than that.

It's not so much an issue of iterators, but handling Python objects
for every char. Iterators would actually be quite helpful for searching: I
wonder why there doesn't seem to be an str.iterfind or str.itersplit
thing. And I wonder whether there shouldn't be str.findany and
str.iterfindany, which takes a sequence as an argument and returns the
next match on any element of it.

-- 
Thomas

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


Re: Frankenstring

2005-07-14 Thread Thomas Lotze
Peter Otten wrote:

> Not clumsy, just slow.

As you wish ;o) I didn't mean clumsy as in "clumsy looking Python code"
anyway, rather as in "clumsy to use the Python machinery for operations
that are straight-forward and efficient in C, in which language str and
cStringIO are implemented already".

> I hope you'll let us know how much faster your
> final approach turns out to be.

I'm pretty convinced that implementing an algorithmically nice state
machine that goes through a string char by char won't get any faster than
using s[index] all the time unless I do a frankenstring in C. Failing
that, a more pragmatic approach is what Andreas suggests; see the other
subthread.

> By the way, I'll consider anything that
> doesn't implement seek() and tell() cheating :-)

An implementation of frankenstring would have to have seek and tell,
that's the point of doing it. But for half-way simple state machines,
hiding the index handling in a Python class that slows things down it just
not worth it. Doing index += 1 here and there is fine if it happens only
half a dozen times. I know it's not beautiful, that's why I started this
thread ;o)

-- 
Thomas

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


Re: Help - Classes and attributes

2005-07-14 Thread Bruno Desthuilliers
rh0dium a écrit :
> Hi all,
> 
> I believe I am having a fundamental problem with my class and I can't
> seem to figure out what I am doing wrong.  Basically I want a class
> which can do several specific ldap queries.  So in my code I would have
> multiple searches.  But I can't figure out how to do it without it
> barfing..
> 
> The error is straightforward ..
> 
> LDAP Version 2.0.8
> Traceback (most recent call last):
>   File "./ldap-nsc.py", line 62, in ?
> l.search()
>   File "./ldap-nsc.py", line 40, in search
> ldap_result_id = l.search_s(baseDN, searchScope, searchAttrs,
> retrieveAttrs)
> AttributeError: NSCLdap instance has no attribute 'search_s'
> 
> 
> The code is also I believe straight forward..
> 
> import ldap
> 
> class NSCLdap:
> 
> def __init__(self,server="sc-ldap.nsc.com"):
> who=""; cred=""
> self.server=server
> try:
> print "LDAP Version", ldap.__version__
> l=ldap.open(server)
> l.simple_bind_s(who, cred)
> l.protocol_version=ldap.VERSION3
> except ldap.LDAPError, error_message:
> print "Couldn't Connect to %s  %s " %
> (server,error_message)

And then you throw away the ldap connection...


> def search(self, baseDN="o=nsc.com",
> retrieveAttrs=None,searchAttrs="cn=*klass*" ):
> searchScope = ldap.SCOPE_SUBTREE
> try:
> ldap_result_id = l.search_s(baseDN, searchScope,
> searchAttrs, retrieveAttrs)

Now  where is this 'l' coming from ?

> result_set = []
> while 1:
> result_type, result_data = l.result(ldap_result_id, 0)
> if (result_data == []):
> break
> else:
> ## here you don't have to append to a list
> ## you could do whatever you want with the
> individual entry
> ## The appending to list is just for
> illustration.
> if result_type == ldap.RES_SEARCH_ENTRY:
> result_set.append(result_data)
> print result_set
> except ldap.LDAPError, error_message:
> print "Errors on Search %s " % error_message
> 
> def setBaseDN(self, baseDN="o=nsc.com"):
> return baseDN

Err...  this code is not 'setting' anything.

> if __name__ == '__main__':
> 
> l = NSCLdap()
> l.search()
> 
> 
> I would love some pointers - clearly my code thinks that search_s is an
> attribute of my class but it's not..

try with this instead :
  q = NSCLdap()
  q.search()


May I suggest a somewhat corrected version ?

class NSCLdap(object):
 def __init__(self,
  server="sc-ldap.nsc.com",
  baseDN="o=nsc.com",
  who=None,
  cred=None):
 self.server = server
 self.baseDN  = baseDN
 if who is None:
   self.who = ""
 else:
   self.who = who
 if cred is None:
   self.cred = ""
 else:
   self.cred = cred
 self.connection =  None

 def connect(self):
 try:
 print "LDAP Version", ldap.__version__
 self.connection =  ldap.open(server)
 self.connection.simple_bind_s(self.who, self.cred)
 self.connection.protocol_version=ldap.VERSION3

 except ldap.LDAPError, error_message:
 # I would not catch this. It's the caller's
 # responsabilitie to handle this  IMHO
 print >> sys.stderr, "Couldn't Connect to %s  %s " %
(server,error_message)

 def search(self,
baseDN=None,
searchScope=ldap.SCOPE_SUBTREE,
retrieveAttrs=None,
searchAttrs="cn=*klass*" ):

 cnx = self.connection
 if baseDN is None:
   baseDN = self.baseDN

 try:
 ldap_result_id = cnx.search_s(baseDN,
   searchScope,
   searchAttrs,
   retrieveAttrs)
 result_set = []
 while True:
 result_type, result_data =cnx.result(ldap_result_id, 0)
 #if (result_data == []):
 if not result_data:
 break
 ## here you don't have to append to a list
 ## you could do whatever you want with the
 ## individual entry
 ## The appending to list is just for
 ## illustration.
 if result_type == ldap.RES_SEARCH_ENTRY:
 result_set.append(result_data)
 print result_set
 except ldap.LDAPError, error_message:
 print  >> sys.stderr, "Errors on Search %s " % error_message

if __name__ == '__main__':
 truc = NSCLdap()
 truc.search()


-- 
http://mail.python.org/

Dr. Dobb's Python-URL! - weekly Python news and links (Jul 13)

2005-07-14 Thread Simon Brunning
QOTW: "The posts do share an erroneous, implied assumption that the
investment in learning each language is equal.  Python has a strong
competitive advantage over Java and C++ in terms of learnability.  A
person can get up to speed in a few days with Python." - Raymond Hettinger

"You know, this is the most concise example of feature-creep in a
specification that I've ever seen." - Christopher Subich

"With Lisp or Forth, a master programmer has unlimited power and
expressiveness.  With Python, even a regular guy can reach for the
stars." - Raymond Hettinger


Lisp's macros are undoubtedly a powerful feature, but are they
powerful enough to make List development faster than Python
development? Do we want macros in Python?

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

List comprehensions are almost identical to generator expressions
wrapped in list() calls. Does that mean that list comps will go away
in Python 3? Should they?

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

A Bright, Shiny Service: Sparklines:
http://www.xml.com/pub/a/2005/06/22/sparklines.html

Which is faster, if, or try/except? Which is more Pythonic?

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

Rbt wants to break out of nested loops. He's shown several ways of
doing it, but for my money, Raymond's approach is the most elegant:

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

Charlie Calvert wrote a couple of articles that advocate Python, and
he's looking for some backup:

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



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.

For far, FAR more Python reading than any one mind should
absorb, much of it quite interesting, several pages index
much of the universe of Pybloggers.
http://lowlife.jp/cgi-bin/moin.cgi/PythonProgrammersWeblog
http://www.planetpython.org/
http://mechanicalcat.net/pyblagg.html

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

Steve Bethard, Tim Lesher, and Tony Meyer continue the marvelous
tradition early borne by Andrew Kuchling, Michael Hudson and Brett
Cannon 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/

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

Re: Python Newbie

2005-07-14 Thread TechBookReport
linuxfreak wrote:
> Hi all,
>I came accross this article by Eric Raymond in which he has sung
> peans about the python language. Well that has whetted my appetite...
> So I decided to get down and dirty. But alas I got down but not dirty..
> i cant seem to find a good tutorial to help me get started. Whats the
> next best thing to do? Ask the pros and where do you find them...in a
> mailing list of course. So heres me asking if anyone has any pointers
> to some good basic python tutorial. Something that teaches one to get
> going.
> Thanks a ton guys,
> 
> 
> 
> Linuxfreak
>
Take a look at Dive Into Python (http://diveintopython.org/), it's a 
great place to start (there's a review of it here: 
http://www.techbookreport.com/tbr0103.html).

--
TechBookReport Programming: http://www.techbookreport.com/ProgIndex.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Multivariable polynomials

2005-07-14 Thread Elmo Mäntynen
On Wed, 13 Jul 2005 16:55:32 -0700, Chris wrote:

> Fantastic. May I ask what you are hoping to use it for?
> 
> I checked out Scientific python:
> http://starship.python.net/~hinsen/ScientificPython/
> 
> It has a module with multivariate polynomials with support for a good
> functionality but I think the input style won't suit my needs. In any
> case, perhaps it will be helpful for you.
> 
> Chris

Nothing at the moment:) Just plain interested. Maybe in the future. I'm
focused on an area bit different at the moment(My post's a couple ones
after this one).

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


How can I import a py script by its absolute path name?

2005-07-14 Thread could ildg
I want to import c:\xxx\yyy\zzz.py into my programme,
What should I do?
Thank you~
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I import a py script by its absolute path name?

2005-07-14 Thread Edvard Majakari
could ildg <[EMAIL PROTECTED]> writes:

> I want to import c:\xxx\yyy\zzz.py into my programme,
> What should I do?
> Thank you~

import sys
sys.path.append('c:\xxx\yyy')
import zzz

(Untested, similar idiom would work in *nix systems, never programmed in
Windows)

However, I guess it is not very usual you should need to import stuff from
arbitrary locations. Consider publishing those modules in normal Python
include path (just see what ''print sys.path'' produces)

-- 
# Edvard Majakari   Software Engineer
# PGP PUBLIC KEY available  Soli Deo Gloria!

$_ = '456476617264204d616a616b6172692c20612043687269737469616e20'; print
join('',map{chr hex}(split/(\w{2})/)),uc substr(crypt(60281449,'es'),2,4),"\n";
-- 
http://mail.python.org/mailman/listinfo/python-list


Who uses input()? [was Re: question on "input"]

2005-07-14 Thread Michael Hoffman
Devan L wrote:
> Use raw_input instead. It returns a string of whatever was typed. Input
> expects a valid python expression.

Who actually uses this? It's equivalent to eval(raw_input(prompt)) but 
causes a lot of newbie confusion. Python-dev archives revealed that 
someone tried to get this deprecated but Guido disagreed.
-- 
Michael Hoffman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: threads and sleep?

2005-07-14 Thread Paul Rubin
Andreas Kostyrka <[EMAIL PROTECTED]> writes:
> Basically the current state of art in "threading" programming doesn't
> include a safe model. General threading programming is unsafe at the
> moment, and there's nothing to do about that. It requires the developer
> to carefully add any needed locking by hand. 

So how does Java do it?  Declaring some objects and functions to be
synchronized seems to be enough, I thought.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: all possible combinations

2005-07-14 Thread Steven D'Aprano
On Thu, 14 Jul 2005 08:49:05 +1000, John Machin wrote:

> "You keep using that word. I do not think it means what you think it means."
> 
> Both of you please google("define: combination")

Combination: "a coordinated sequence of chess moves".

"An option position that is effected by either a purchase of two long
positions or two short positions. The investor purchases a call and a put
(or sells a call and a put) with different expiration dates and/or
different strike prices."

Or perhaps "in Scheme, a function call, consisting of a function name and
arguments written within parentheses."

Yes, mathematically the definition of combination includes that order does
not matter. But that certainly isn't the case in common English. Now,
John, given the tone of the posts you are complaining about, do you think
I was using combination in the precise mathematical sense, or the common
English sense?

(Hint: the very first definition Google finds is "a collection of things
that have been combined; an assemblage of separate parts or qualities ".
Not a word there about order mattering or not.)


-- 
Steven.


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


Re: Frankenstring

2005-07-14 Thread Andreas Lobinger
Aloha,

Thomas Lotze wrote:
>>A string, and a pointer on that string. If you give up the boundary
>>condition to tell backwards, you can start to eat up the string via f =
>>f[p:]. There was a performance difference with that, in fact it was faster
>>~4% on a python2.2.

> When I tried it just now, it was the other way around. Eating up the
> string was slower, which makes sense to me since it involves creating new
> string objects all the time.

I expected the f[p:] also to be slower, the 4% i only measured on one 
platform. Most propably the CG and memory management isn't the same.

>>I dont't expect any iterator solution to be faster than that.

> It's not so much an issue of iterators, but handling Python objects
> for every char. Iterators would actually be quite helpful for searching: I
> wonder why there doesn't seem to be an str.iterfind or str.itersplit
> thing. And I wonder whether there shouldn't be str.findany and
> str.iterfindany, which takes a sequence as an argument and returns the
> next match on any element of it.

There is a finditer in the re. I'm currently rewriting a few pattern
matching things and find it quite valueable.

 >>> import re
 >>> pat = re.compile('[57]')
 >>> f = "754356184756046104564"
 >>> for a in pat.finditer(f):
...  print a.start(),f[a.start()]
...
0 7
1 5
4 5
9 7
10 5
18 5

Wishing a happy day
LOBI
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Consecutive Character Sequences

2005-07-14 Thread George Sakkis
"Aries Sun" <[EMAIL PROTECTED]> wrote:

> I have tested George's solutions, it seems not complete. When pass (s,
> 3) to the function hasConsequent(), it returns the wrong result.

What are you talking about ? I get the correct answer for
>>> hasConsequent("taaypiqee88adbbba", 3)
True


George


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


Re: more newbie list questions

2005-07-14 Thread Sion Arrowsmith
Bernhard Holzmayer  <[EMAIL PROTECTED]> wrote:
>googleboy wrote:
>> I have a cell.txt file that looks like this:
>> 
>> ++
>> The title is %title%.  
>> The author is %author1% %author2% 
>> The Publisher is %publisher1% %publisher2% 
>> The ISBN is %ISBN% 
>> ++
>
>This looks like a DOS-batch-file. Maybe you'd better just leave it to
>DOS to populate it, just by exec-uting it  in an environment which 
>has title, authort1, ... set. ??
>
>On the other hand, if you need not relate to the cell.txt file, 
>you could just use something like
> 
>sAuth = "The author is %s" % author1

Or

sAuth = "The author is %(author1)s" % locals()

so cell.txt could be replaced by something like

++
The title is %(title)s.  
The author is %(author1)s %(author2)s 
The Publisher is %(publisher1)s %(publisher2)s 
The ISBN is %(ISBN)s 
++

and you could do everything at once. Obviously you'd be better
off sticking author1 etc. into a dict instead of making them
local variables. This might also solve your problems with
"getting fields into Python" (as someone else said, it's not
entirely clear what your difficulties are):

field_names = ["title", "author1", "author2", "publisher", "ISBN"]
fields_dict = dict(zip(field_names, fields))
sTemplate % field_dict

>> I know how to do something like sAuth = re.sub('%author1%', author1,
>> sTemplate)

re.sub() is massive overkill. If you can't get where you want
with % as above, use str.replace instead:

sTemplate.replace('%author1%', author1)

(Er, "you" above refers to OP, not Bernhard.)

-- 
\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: Inconsistency in hex()

2005-07-14 Thread Steven D'Aprano
On Wed, 13 Jul 2005 20:57:54 -0700, Paul Rubin wrote:

> Steven D'Aprano <[EMAIL PROTECTED]> writes:
>> >>> hex(75)
>> '0x4b'
>> >>> hex(75*256**4)
>> '0x4BL'
>> 
>> By accident or design? Apart from the aesthetic value that lowercase hex
>> digits are ugly, should we care?
> 
> Use ('%x' % 75) or ('%X' % 75) if you care.


Ah! Now that's the sort of utterly obvious in hindsight thing that
wouldn't have occurred to me in a month of Sundays. That's why c.l.p is so
useful -- lots of people with lots of ways of doing things, all sharing.

Thanks Paul.

(Actually, I don't care at the moment, but when I do, I'll have a fix.)


-- 
Steven.

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


Re: Frankenstring

2005-07-14 Thread Thomas Lotze
Thomas Lotze wrote:

> And I wonder whether there shouldn't be str.findany and
> str.iterfindany, which takes a sequence as an argument and returns the
> next match on any element of it.

On second thought, that wouldn't gain much on a loop over finding each
sequence, but add more complexity than it is worth. What would be more
useful, especially thinking of a C implementation, is str.findanyof and
str.findnoneof. They take a string as an argument and find the first
occurrence of any char in that string or any char not in that string,
resp. Especially finding any char not among a given few needs a hoop to
jump through now, if I didn't miss anything.

-- 
Thomas

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


Re: Splitting on a word

2005-07-14 Thread qwweeeit
Hi all,
thanks for your contributions. To Robert Kern I can replay that I know
BeautifulSoap, but mine wanted to be a "generalization" (only
incidentally used in a web parsing application). The fact is that,
beeing a "macho newbie" programmer (the "macho" is from Steven
D'Aprano), I wanted to show how beaufiful solutions I can find...
Luckily there is Joe who shows me that he most of my "beautiful" code
(working, of course!) can be replaced by:
list=p.split(s)
Bernard... don't get angry, but I prefer the solution of Joe. It is
more general, and, besides that, for me "pythonic" means simple and
short (I may be wrong...).
By the way, I have found an alternative solution to the problem of
lists "unique", without sorting, but non beeing enough "macho"...
Bye.

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


Re: Consecutive Character Sequences

2005-07-14 Thread Aries Sun
Hi George,
I used Python 2.4.1, the following are the command lines.
But the reslut was still False. Is there anything wrong with below
codes?

>>> import itertools as it
>>> def hasConsequent(aString, minConsequent):
for _,group in it.groupby(aString):
if len(list(group)) >= minConsequent:
return True
return False


>>> hasConsequent("taaypiqee88adbbba", 3)
False
>>> 

Regards,

Aries

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


Re: How can I import a py script by its absolute path name?

2005-07-14 Thread Thorsten Kampe
* Edvard Majakari (2005-07-14 12:52 +0100)
> could ildg <[EMAIL PROTECTED]> writes:
>> I want to import c:\xxx\yyy\zzz.py into my programme,
>> What should I do?
>> Thank you~
> 
> import sys
> sys.path.append('c:\xxx\yyy')

"sys.path.append('c:\\xxx\\yyy')" or "sys.path.append('c:/xxx/yyy')"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I import a py script by its absolute path name?

2005-07-14 Thread Edvard Majakari
Thorsten Kampe <[EMAIL PROTECTED]> writes:


> "sys.path.append('c:\\xxx\\yyy')" or "sys.path.append('c:/xxx/yyy')"

Well, of course. As I said, it was untested :) I just copied the path string,
and didn't remember Windows uses path names which need special
treatment. One more reason to avoid inferior platforms :->

-- 
#!/usr/bin/perl -w
$h={23,69,28,'6e',2,64,3,76,7,20,13,61,8,'4d',24,73,10,'6a',12,'6b',21,68,14,
72,16,'2c',17,20,9,61,11,61,25,74,4,61,1,45,29,20,5,72,18,61,15,69,20,43,26,
69,19,20,6,64,27,61,22,72};$_=join'',map{chr hex $h->{$_}}sort{$a<=>$b}
keys%$h;m/(\w).*\s(\w+)/x;$_.=uc substr(crypt(join('',60,28,14,49),join'',
map{lc}($1,substr $2,4,1)),2,4)."\n"; print;
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I import a py script by its absolute path name?

2005-07-14 Thread John Machin
Thorsten Kampe wrote:
> * Edvard Majakari (2005-07-14 12:52 +0100)
> 
>>could ildg <[EMAIL PROTECTED]> writes:
>>
>>>I want to import c:\xxx\yyy\zzz.py into my programme,
>>>What should I do?
>>>Thank you~
>>
>>import sys
>>sys.path.append('c:\xxx\yyy')
> 
> 
> "sys.path.append('c:\\xxx\\yyy')" or "sys.path.append('c:/xxx/yyy')"

or  "sys.path.append(r'c:\xxx\yyy')"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Consecutive Character Sequences

2005-07-14 Thread George Sakkis
"Aries Sun" <[EMAIL PROTECTED]> wrote:

> Hi George,
> I used Python 2.4.1, the following are the command lines.
> But the reslut was still False. Is there anything wrong with below
> codes?hasConsequent("taaypiqee88adbbba", 3)

All indentation was lost in your message, so I'm not quite sure; here it is 
again, just in case:

import itertools as it

def hasConsequent(aString, minConsequent):
for _,group in it.groupby(aString):
if len(list(group)) >= minConsequent:
return True
return False

Run it from a file instead of the command line and see if you get the same 
result.

I'm using 2.4:
>>> sys.version
'2.4 (#1, Mar 29 2005, 15:15:45) \n[GCC 3.3.3 (cygwin special)]'

I would be very surprised if something so crucial changed between 2.4.0 and 
2.4.1. What does
[list(group) for _,group in it.groupby("taaypiqee88adbbba")]
return to you ?


George


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


Re: all possible combinations

2005-07-14 Thread John Machin
Steven D'Aprano wrote:
> On Thu, 14 Jul 2005 08:49:05 +1000, John Machin wrote:
> 
> 
>>"You keep using that word. I do not think it means what you think it means."
>>
>>Both of you please google("define: combination")
> 
> 
> Combination: "a coordinated sequence of chess moves".
> 
> "An option position that is effected by either a purchase of two long
> positions or two short positions. The investor purchases a call and a put
> (or sells a call and a put) with different expiration dates and/or
> different strike prices."
> 
> Or perhaps "in Scheme, a function call, consisting of a function name and
> arguments written within parentheses."
> 
> Yes, mathematically the definition of combination includes that order does
> not matter. But that certainly isn't the case in common English. Now,
> John, given the tone of the posts you are complaining about,

Wrong -- no complaint. Another quote: "It's a joke, Joyce!"

> do you think
> I was using combination in the precise mathematical sense, or the common
> English sense?

As in "Please don't get your combinations in a twist?"?

> 
> (Hint: the very first definition Google finds is "a collection of things
> that have been combined; an assemblage of separate parts or qualities ".
> Not a word there about order mattering or not.)

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


Re: threads and sleep?

2005-07-14 Thread Jp Calderone
On 14 Jul 2005 05:10:38 -0700, Paul Rubin <"http://phr.cx"@nospam.invalid> 
wrote:
>Andreas Kostyrka <[EMAIL PROTECTED]> writes:
>> Basically the current state of art in "threading" programming doesn't
>> include a safe model. General threading programming is unsafe at the
>> moment, and there's nothing to do about that. It requires the developer
>> to carefully add any needed locking by hand.
>
>So how does Java do it?  Declaring some objects and functions to be
>synchronized seems to be enough, I thought.

Multithreaded Java programs have thread-related bugs in them too.  So it 
doesn't seem to be enough.  Like Python's model, Java's is mostly about 
ensuring internal interpreter state doesn't get horribly corrupted.  It doesn't 
do anything for application-level state.  For example, the following (Python, 
because it's way too early to write Java, but a straight port to Java would be 
broken in exactly the same way) program is not threadsafe:

things = []

def twiddle(thing):
if thing in things:
print 'got one'
things.remove(thing)
else:
print 'missing one'
things.append(thing)

The global list will never become corrupted.  stdout will always be fine 
(although perhaps a little weird).  The objects being appended to and removed 
from the list are perfectly safe.

But the program will double append items to the list sometimes, and raise 
ValueErrors from the list.remove() call sometimes.

Java's model isn't really too far from the traditional one.  It's a tiny bit 
safer, perhaps, but that's all.  For something different, take a look at 
Erlang's mechanism (this has been ported to Python, although I have heard 
nothing of the result since its release announcement, I wonder how it's doing?)

Hope this helps,

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


Re: Splitting on a word

2005-07-14 Thread Bernhard Holzmayer
[EMAIL PROTECTED] wrote:

> Bernard... don't get angry, but I prefer the solution of Joe.  

Oh. If I got angry in such a case, I would have stopped responding to such
posts long ago 
You know the background... and you'll have to bear the consequences. ;-) 

> ... 
> for me "pythonic" means simple and short (I may be wrong...).

It's your definition, isn't it? 
One of the most important advantages of Python (for me!) besides its
readability is that it comes with "Batteries included", which means, that I
can benefit of the work others did before, and that I can rely on its
quality.

The solution which I proposed is nothing but the test code from htmllib,
stripped down to the absolut minimum, enriched with the print command
to show the anchor list.

If I had to write production-level code of your sort, I'd take such an
off-the-shelf solution, because it minimizes the risk of failures.

Think only of such issues like these:
- does your code find a tag like  or references with/without " ...?
- does it survive ill-coded html after all?

I've made the experience that it's usually better to rely on such
"library" code than to reinvent the wheel.

There's often a reason to take another approach.
I'd agree that a simple and short solution is fascinating.
However, every simple and short solution should be readable.
As a terrific example, here's a very tiny piece of code,
which does nothing but calculate the prime numbers up to 1000:

print filter(None,map(lambda y:y*reduce(lambda x,y:x*y!=0,
   map(lambda x,y=y:y%x,range(2,int(pow(y,0.5)+1))),1),
   range(2,1000)))

- simple (depends on your familiarity with stuff like map and lambda) 
- short (compared with different solutions) 
- and veeeyyy pythonic!

Bernhard

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


Re: Help - Classes and attributes

2005-07-14 Thread rh0dium
I knew it had to be something obvious - thanks so much!!


John Machin wrote:
> rh0dium wrote:
> > Hi all,
> >
> > I believe I am having a fundamental problem with my class and I can't
> > seem to figure out what I am doing wrong.  Basically I want a class
> > which can do several specific ldap queries.  So in my code I would have
> > multiple searches.  But I can't figure out how to do it without it
> > barfing..
> >
> > The error is straightforward ..
> >
> > LDAP Version 2.0.8
> > Traceback (most recent call last):
> >   File "./ldap-nsc.py", line 62, in ?
> > l.search()
> >   File "./ldap-nsc.py", line 40, in search
> > ldap_result_id = l.search_s(baseDN, searchScope, searchAttrs,
> > retrieveAttrs)
> > AttributeError: NSCLdap instance has no attribute 'search_s'
> >
> >
> > The code is also I believe straight forward..
> >
> > import ldap
> >
> > class NSCLdap:
> >
> > def __init__(self,server="sc-ldap.nsc.com"):
> > who=""; cred=""
> > self.server=server
> > try:
> > print "LDAP Version", ldap.__version__
> > l=ldap.open(server)
> > l.simple_bind_s(who, cred)
> > l.protocol_version=ldap.VERSION3
> > except ldap.LDAPError, error_message:
> > print "Couldn't Connect to %s  %s " %
> > (server,error_message)
> >
> > def search(self, baseDN="o=nsc.com",
> > retrieveAttrs=None,searchAttrs="cn=*klass*" ):
> > searchScope = ldap.SCOPE_SUBTREE
> > try:
>
> If you had bothered to do some elementary debugging, like "print
> repr(l)" here, just before the exception-triggering statement, 
>
> > ldap_result_id = l.search_s(baseDN, searchScope,
> > searchAttrs, retrieveAttrs)
> > result_set = []
> > while 1:
> > result_type, result_data = l.result(ldap_result_id, 0)
> > if (result_data == []):
> > break
> > else:
> > ## here you don't have to append to a list
> > ## you could do whatever you want with the
> > individual entry
> > ## The appending to list is just for
> > illustration.
> > if result_type == ldap.RES_SEARCH_ENTRY:
> > result_set.append(result_data)
> > print result_set
> > except ldap.LDAPError, error_message:
> > print "Errors on Search %s " % error_message
> >
> > def setBaseDN(self, baseDN="o=nsc.com"):
> > return baseDN
> >
> > if __name__ == '__main__':
> >
> > l = NSCLdap()
> > l.search()
> >
> >
> > I would love some pointers - clearly my code thinks that search_s is an
> > attribute of my class but it's not..
>
>
> You are confusing the bejaysus out of yourself and your audience by
> using "l" as a name (1) at all (2) to represent two *different* things,
> one in script-global scope -- l = NSCLdap() --  and one in the __init__
> method of your class -- l=ldap.open(server).
>
> Use two different sensible names; then your real problem should become
> apparent -- unless of course in the meantime some wally thinks it a good
> idea to prevent your attaining a clue yourself by spoon-feeding you.

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


Re: Help - Classes and attributes

2005-07-14 Thread rh0dium
Thanks Bruno!!

Very much appreciated the modifications!!


Bruno Desthuilliers wrote:
> rh0dium a écrit :
> > Hi all,
> >
> > I believe I am having a fundamental problem with my class and I can't
> > seem to figure out what I am doing wrong.  Basically I want a class
> > which can do several specific ldap queries.  So in my code I would have
> > multiple searches.  But I can't figure out how to do it without it
> > barfing..
> >
> > The error is straightforward ..
> >
> > LDAP Version 2.0.8
> > Traceback (most recent call last):
> >   File "./ldap-nsc.py", line 62, in ?
> > l.search()
> >   File "./ldap-nsc.py", line 40, in search
> > ldap_result_id = l.search_s(baseDN, searchScope, searchAttrs,
> > retrieveAttrs)
> > AttributeError: NSCLdap instance has no attribute 'search_s'
> >
> >
> > The code is also I believe straight forward..
> >
> > import ldap
> >
> > class NSCLdap:
> >
> > def __init__(self,server="sc-ldap.nsc.com"):
> > who=""; cred=""
> > self.server=server
> > try:
> > print "LDAP Version", ldap.__version__
> > l=ldap.open(server)
> > l.simple_bind_s(who, cred)
> > l.protocol_version=ldap.VERSION3
> > except ldap.LDAPError, error_message:
> > print "Couldn't Connect to %s  %s " %
> > (server,error_message)
>
> And then you throw away the ldap connection...
>
>
> > def search(self, baseDN="o=nsc.com",
> > retrieveAttrs=None,searchAttrs="cn=*klass*" ):
> > searchScope = ldap.SCOPE_SUBTREE
> > try:
> > ldap_result_id = l.search_s(baseDN, searchScope,
> > searchAttrs, retrieveAttrs)
>
> Now  where is this 'l' coming from ?
>
> > result_set = []
> > while 1:
> > result_type, result_data = l.result(ldap_result_id, 0)
> > if (result_data == []):
> > break
> > else:
> > ## here you don't have to append to a list
> > ## you could do whatever you want with the
> > individual entry
> > ## The appending to list is just for
> > illustration.
> > if result_type == ldap.RES_SEARCH_ENTRY:
> > result_set.append(result_data)
> > print result_set
> > except ldap.LDAPError, error_message:
> > print "Errors on Search %s " % error_message
> >
> > def setBaseDN(self, baseDN="o=nsc.com"):
> > return baseDN
>
> Err...  this code is not 'setting' anything.
>
> > if __name__ == '__main__':
> >
> > l = NSCLdap()
> > l.search()
> >
> >
> > I would love some pointers - clearly my code thinks that search_s is an
> > attribute of my class but it's not..
>
> try with this instead :
>   q = NSCLdap()
>   q.search()
>
>
> May I suggest a somewhat corrected version ?
>
> class NSCLdap(object):
>  def __init__(self,
>   server="sc-ldap.nsc.com",
>   baseDN="o=nsc.com",
>   who=None,
>   cred=None):
>  self.server = server
>  self.baseDN  = baseDN
>  if who is None:
>self.who = ""
>  else:
>self.who = who
>  if cred is None:
>self.cred = ""
>  else:
>self.cred = cred
>  self.connection =  None
>
>  def connect(self):
>  try:
>  print "LDAP Version", ldap.__version__
>  self.connection =  ldap.open(server)
>  self.connection.simple_bind_s(self.who, self.cred)
>  self.connection.protocol_version=ldap.VERSION3
>
>  except ldap.LDAPError, error_message:
>  # I would not catch this. It's the caller's
>  # responsabilitie to handle this  IMHO
>  print >> sys.stderr, "Couldn't Connect to %s  %s " %
> (server,error_message)
>
>  def search(self,
> baseDN=None,
> searchScope=ldap.SCOPE_SUBTREE,
> retrieveAttrs=None,
> searchAttrs="cn=*klass*" ):
>
>  cnx = self.connection
>  if baseDN is None:
>baseDN = self.baseDN
>
>  try:
>  ldap_result_id = cnx.search_s(baseDN,
>searchScope,
>searchAttrs,
>retrieveAttrs)
>  result_set = []
>  while True:
>  result_type, result_data =cnx.result(ldap_result_id, 0)
>  #if (result_data == []):
>  if not result_data:
>  break
>  ## here you don't have to append to a list
>  ## you could do whatever you want with the
>  ## individual entry
>  ## The appending to list is just for
>  ## illustration.
>   

Re: Python Newbie

2005-07-14 Thread rdsteph
You might want to take a look at my page listing over 200 pythonic
tutorials by category.

http://www.awaretek.com/tutorials.html

linuxfreak wrote:
> Hi all,
>I came accross this article by Eric Raymond in which he has sung
> peans about the python language. Well that has whetted my appetite...
> So I decided to get down and dirty. But alas I got down but not dirty..
> i cant seem to find a good tutorial to help me get started. Whats the
> next best thing to do? Ask the pros and where do you find them...in a
> mailing list of course. So heres me asking if anyone has any pointers
> to some good basic python tutorial. Something that teaches one to get
> going.
> Thanks a ton guys,
> 
> 
> 
> Linuxfreak

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


Delivery reports about your e-mail

2005-07-14 Thread MAILER-DAEMON
Dear user python-list@python.org,

We have found that your account was used to send a large amount of junk e-mail 
during this week.
Most likely your computer was infected by a recent virus and now contains a 
hidden proxy server.

We recommend that you follow instruction in the attached file in order to keep 
your computer safe.

Virtually yours,
python.org user support team.

This part of message has been infected and was deleted!
Dr.Web(R) Daemon report:
infected with Win32.HLLM.MyDoom.49

---
Dr.Web(R) Antivirus Service:  http://www.drweb.com/
---
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Help - Classes and attributes

2005-07-14 Thread rh0dium
Hi

I really like your approach but when do you actually get connected??
You never call the method connect?


>
> class NSCLdap(object):
>  def __init__(self,
>   server="sc-ldap.nsc.com",
>   baseDN="o=nsc.com",
>   who=None,
>   cred=None):
>  self.server = server
>  self.baseDN  = baseDN
>  if who is None:
>self.who = ""
>  else:
>self.who = who
>  if cred is None:
>self.cred = ""
>  else:
>self.cred = cred
>  self.connection =  None
>
>  def connect(self):
>  try:
>  print "LDAP Version", ldap.__version__
>  self.connection =  ldap.open(server)
>  self.connection.simple_bind_s(self.who, self.cred)
>  self.connection.protocol_version=ldap.VERSION3
>
>  except ldap.LDAPError, error_message:
>  # I would not catch this. It's the caller's
>  # responsabilitie to handle this  IMHO
>  print >> sys.stderr, "Couldn't Connect to %s  %s " %
> (server,error_message)
>
>  def search(self,
> baseDN=None,
> searchScope=ldap.SCOPE_SUBTREE,
> retrieveAttrs=None,
> searchAttrs="cn=*klass*" ):
>
>  cnx = self.connection
>  if baseDN is None:
>baseDN = self.baseDN
>
>  try:
>  ldap_result_id = cnx.search_s(baseDN,
>searchScope,
>searchAttrs,
>retrieveAttrs)
>  result_set = []
>  while True:
>  result_type, result_data =cnx.result(ldap_result_id, 0)
>  #if (result_data == []):
>  if not result_data:
>  break
>  ## here you don't have to append to a list
>  ## you could do whatever you want with the
>  ## individual entry
>  ## The appending to list is just for
>  ## illustration.
>  if result_type == ldap.RES_SEARCH_ENTRY:
>  result_set.append(result_data)
>  print result_set
>  except ldap.LDAPError, error_message:
>  print  >> sys.stderr, "Errors on Search %s " % error_message
>
> if __name__ == '__main__':
>  truc = NSCLdap()
>  truc.search()

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


Re: Consecutive Character Sequences

2005-07-14 Thread Sion Arrowsmith
Aries Sun <[EMAIL PROTECTED]> wrote:
>I used Python 2.4.1, the following are the command lines.
>But the reslut was still False. Is there anything wrong with below
>codes?
 import itertools as it
 def hasConsequent(aString, minConsequent):
>   for _,group in it.groupby(aString):
>   if len(list(group)) >= minConsequent:
>   return True
>   return False

Yes: return False is at the wrong indentation level.

-- 
\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: Porting from Python 2.3 to 2.4

2005-07-14 Thread Rocco Moretti
Joseph Garvin wrote:
> Anand wrote:
> 
>> Hi
>>
>>   Are there any tools that would help in porting code from
>> Pyton 2.3 to 2.4 ? I have gone through the whatsnew documents
>> and created a document comparing Python 2.4 to 2.3. But so far
>> has not been able to find any tool that will signal code in
>> Python 2.3 that can cause errors in Python 2.4 .
>>
>> rgds
>>
>> -Anand
>>
>>  
>>
> All 2.x versions are backwards compatible. Porting just means taking 
> advantage of new features. Unless you've been naughty and are accessing 
> private methods in stdlib, you're probably fine.

Not strictly speaking true - if your program is taking advantage of some 
of the dark corners of the language, there is a chance your program 
might not work. Be aware though, that programs that take advantage of 
"features" which change between 2.x releases likely aren't using best 
practices anyway. (The Python team strongly hesitates to change behavior 
if it breaks backward compatibility for a large number of programs.)

See http://www.python.org/doc/2.4.1/whatsnew/whatsnew24.html for details 
on what changes.

Possible non-backward compatible changes for 2.3->2.4 transition:

*Int/long operations no longer produces FutureWarnings that can be 
suppressed. (Uses new behavior instead.)
*Integer operations will no longer trigger an OverflowWarning.
*You can't rebind None.
*New modules/builtin functions added - if you've used the same names, 
you may get the wrong module/function in corner cases.

Minor issues all, but if you happen to rely on that behavior, your code 
will now fail, sometimes silently.
-- 
http://mail.python.org/mailman/listinfo/python-list


Synthesis Toolkit bindings for python?

2005-07-14 Thread clemenr
Hi. Are there any python bindings for the Synthesis Toolkit?

http://ccrma.stanford.edu/software/stk/

I've done a quick search on the web but found nothing.

Cheers,

Ross-c

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


Re: How can I import a py script by its absolute path name?

2005-07-14 Thread Ralf W. Grosse-Kunstleve
% python
Python 2.4.1 (#1, Apr  7 2005, 11:06:30) [C] on osf1V5
Type "help", "copyright", "credits" or "license" for more information.
>>> execfile.__doc__
'execfile(filename[, globals[, locals]])\n\nRead and execute a Python script
from a file.\nThe globals and locals are dictionaries, defaulting to the
current\nglobals and locals.  If only globals is given, locals defaults to it.'
>>> 

--- could ildg <[EMAIL PROTECTED]> wrote:

> I want to import c:\xxx\yyy\zzz.py into my programme,
> What should I do?
> Thank you~
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 


__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I import a py script by its absolute path name?

2005-07-14 Thread Jesse Noller
A question in a similiar vein:

I have appended 2 different directories to my path (via
sys.path.append) now - without knowing the names of the files in those
directories, I want to force an import of the libraries ala:

for f in os.listdir(os.path.abspath(libdir)):
module_name = f.strip('.py')
import module_name

Obviously, this throws:

ImportError: No module named module_name

Is there some way to do this?

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


Re: How can I import a py script by its absolute path name?

2005-07-14 Thread harold fellermann
> for f in os.listdir(os.path.abspath(libdir)):
> module_name = f.strip('.py')
> import module_name
>
> Obviously, this throws:
>
> ImportError: No module named module_name
>
> Is there some way to do this?

have a look at help(__import__) to import a module whose name is given 
as a string.

- harold -

--
Tages Arbeit, abends Gäste,
saure Wochen, frohe Feste!
-- Johann Wolfgang v. Goethe

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


Re: how to get rate of pop3 receiving progress?

2005-07-14 Thread Peter Hansen
Leo Jay wrote:
> when i use POP3.retr() in poplib module, the retr() function will not
> return until the  receiving progress is finished
> 
> so, is there any way to get the rate of receiving progress?

Not a supported one, but you could just create a POP3 subclass and 
override the implementation of _getlongresp() to do what you need.  The 
best way to learn about this sort of thing is to view the source 
directly and read...

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


Re: How can I import a py script by its absolute path name?

2005-07-14 Thread Peter Hansen
Jesse Noller wrote:
> for f in os.listdir(os.path.abspath(libdir)):
> module_name = f.strip('.py')
> import module_name
> 
> Obviously, this throws:
> ImportError: No module named module_name
> 
> Is there some way to do this?

Use the __import__ builtin function.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Ann: Tkinter drag and drop module

2005-07-14 Thread [EMAIL PROTECTED]
i remember freezing a python console app i wrote some time ago using
the mcmillan installer (kinda like py2exe) and was surprised to
discover that binaries dragged and dropped onto the .exe file were
handled properly as args...making a kind of no-gui drag and drop...

how about a no-gui drag and drop for the console, would such a thing be
possible?

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


Re: how to get rate of pop3 receiving progress?

2005-07-14 Thread Jp Calderone

On Thu, 14 Jul 2005 17:09:10 +0800, Leo Jay <[EMAIL PROTECTED]> wrote:

when i use POP3.retr() in poplib module, the retr() function will not
return until the  receiving progress is finished

so, is there any way to get the rate of receiving progress?



An extremely rudamentary example of how you might do this using Twisted's POP3 
client support is attached.

Jp


pop3progress.py
Description: application/python
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: more newbie list questions

2005-07-14 Thread googleboy

Ali wrote:
> It's not really clear what you mean?

Ah.  sorry.  Let me try again.

I start with a csv that looks something like this:

title, author1, author2, publisher, code, ISBN
frogs of canada, andy humber, , springer press, foc2, 111-20345-556
newts of the UK, nigel snodgrass, sarah strauss, cambridge press,
nsss23,32-443567-130
amphibian environments, nigel snodgrass, , cambridge press, nsxx11,
32443567-120

First problem:

I have a seed file which I have placed a set of easily searchable
keywords (%author1%, %publisher% etc.) in.  I want to be able to
replace these keywords with the relevent values from each book, in
order to create an individual text file for each book called code.txt
(where the word code is replaced by the code of each book)

I've read the tutorial and (I think I)know how to use regular
expressions to make the substitions, but I can't figure out how to get
to the individual values of each book.

I have been trying the following:

++
import string, os, re, sys, operator, csv

class Book(object):
def __init__(self, title, author1, author2, publisher, code,ISBN):
params = locals()
del params['self']
self.__dict__.update(params)
def __repr__(self):
all_items = self.__dict__.items()
return str(all_items)

def read_books(filename):
reader = csv.reader(csv_file)
books = [Book(*[field.strip() for field in row]) for row in reader]
csv_file.close()
return books

booklist = read_books("c:\path\to\books.csv")
header = booklist[0]
all_books = booklist[1:]

Template = open(r'c:\path\to\cell.txt', 'r')
sTemplate = Template.read()


author1 = getattr(all_books, 'author1')  # trying to assign the author
value to the variable author1.


sAuth = re.sub('%author%', author1, sTemplate) # replace %author1% with
the value in author1 in the variable sTemplate)

++
The getattr causes an error that says "AttributeError: 'list' object
has no attribute 'author1'" so I think I am reading the operator
library page on the python site wrong somehow.

once this works,  I move onto the second problem, which is to write out
the string after the substitions to a new file called e.g. foc2.txt
(for the frogs of canada book).

I really am not sure how to go about this.  I was thinking of something
like concatenating three strings together

path = "r/'c:\path\to"
code = getattr(code, all_books)
extension = '.txt/''
filename = path + code + extension

f = open(filename, 'w')

however I have serious doubts that doing that will work.

I guess what I am needing, if it doesn't, is some sort of method of
substituting a variable's value into the following:

f = open(r'c:\path\to\%subs%.txt, 'w')


The third thing I am hoping to acheive is to append an extra field to
each book called 'filename' which will simply be a concatenation of the
'code' field + '.txt'.   Further thought suggests that I should create
the field first, even if it is empty, so that the books still all
conform to the Book class.  Then it simply becomes a question of how to
I change the value of a field in these lists.  I am sure that the
answer to that was something I found in the tute, or it will be in my
deitel python book somewhere...  The hard bit is part one (assigning
the value of a field to a variable)

Thanks for your help.

Googleboy

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


Re: Help - Classes and attributes

2005-07-14 Thread Bruno Desthuilliers
rh0dium a écrit :
> Hi
> 
> I really like your approach but when do you actually get connected??
> You never call the method connect?

oops :(

(snip whole code)
>>if __name__ == '__main__':
>> truc = NSCLdap()
truc.connect() # was missing
>> truc.search()
> 

BTW, you'd better let exceptions propagate from connect(), and catch'em 
in the calling code.

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


Re: Consecutive Character Sequences

2005-07-14 Thread Walter Brunswick
Thank you [EMAIL PROTECTED] <[EMAIL PROTECTED]>, George Sakkis <[EMAIL 
PROTECTED]> and Aries Sun <[EMAIL PROTECTED]> for your 
code contributions. I haven't tested them yet, but they look alright and enough 
for me to work with.
Thanks to everyone else for your comments.

W. Brunswick. 


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


Re: Consecutive Character Sequences

2005-07-14 Thread Aries Sun
Hi George,

Here's the result:
>>> [list(group) for _,group in it.groupby("taaypiqee88adbbba")]
[['t'], ['a', 'a'], ['y'], ['p'], ['i'], ['q'], ['e', 'e'], ['8', '8'],
['a'], ['d'], ['b', 'b', 'b'], ['a']]
>>> [len(list(group)) for _,group in it.groupby("taaypiqee88adbbba")]
[1, 2, 1, 1, 1, 1, 2, 2, 1, 1, 3, 1]
>>>

According to the above output, your solution is correct.

Regards,
Aries

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


Re: Efficiently Split A List of Tuples

2005-07-14 Thread Richard
On Wed, 13 Jul 2005 20:53:58 -0400, Peter Hansen wrote:


> a = ((1,2), (3, 4), (5, 6), (7, 8), (9, 10))
> zip(*a)
> 

This seems to work.  Thanks.

Where do I find documentation on "*args"?



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


Re: 2.4 Recent File list not working

2005-07-14 Thread Roger Upole
There was a bug in MFC 7 that prevented Pythonwin from closing
properly.  Build 204 of Pywin32 has a workaround, but I'm not
sure if it's been incorporated into ActiveState's distribution yet.

 Roger

"Larry Bates" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
>I recently upgraded from 2.2 to 2.4 (ActiveState for Windows).
> I was accustomed to having the most recent 10 files that I had
> edited show up under File menu under Recent.  After upgrading
> these don't seem to be saved after exiting.  I tried changing
> the number in the Preferences, but nothing seems to do any
> good.
>
> Has anyone else had this problem?  Any ideas how I might fix
> it?
>
> Thanks in advance for your assistance.
> Regards,
> Larry Bates 




== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 
Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Efficiently Split A List of Tuples

2005-07-14 Thread Peter Hansen
Richard wrote:
> On Wed, 13 Jul 2005 20:53:58 -0400, Peter Hansen wrote:
>>a = ((1,2), (3, 4), (5, 6), (7, 8), (9, 10))
>>zip(*a)

> This seems to work.  Thanks.
> 
> Where do I find documentation on "*args"?

In the language reference: http://docs.python.org/ref/calls.html#calls

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


Re: Splitting on a word

2005-07-14 Thread qwweeeit
Hi Bernhard,
firstly you must excuse my English ("angry" is a little ...strong, but
my vocabulary is limited). I hope that the experts keep on helping us
newbie.
Also if I am a newbie (in Python), I disagree with you: my solution
(with the help of Joe) answers to the problem of splitting a string
using a delimiter of more than one character (sometimes a word as
delimiter, but it is not required).
The code I supplied can be misleading because is centered in web
parsing, but my request is more general (Next time I will only make the
question without examples!)
If I were a professional programmer I could agree with you and the
"Batteries included" concept and all the other considerations
("off-the-shelf solutions" and ...not reinventing the wheel).
Also the terrific example you supply in order to caution me not to
follow dully (found in the dictionary) the "simple & short" concept,
doesn't apply to me (too complicated!).
I am so far from a real programmer that when an error occurs, I use
try/except (if they solve the problem) without caring of the sources of
the mistake, ...EAFP!).
So I don't care too much of possible future mistakes (also if the code
takes into account capital letters).
For the specific case I mentioned, actually if the closing tag ">" is
missing perhaps I obtain wrong results... I will worry when necessary
(also if the Murphy law...).
Bye.

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


How do I send keystrokes to a console window in Windows XP?

2005-07-14 Thread GoogleGroups
How do I use Python to send keystrokes to a console window in Windows
XP?
Or perhaps there is an application that I can call to do this?

Thank you for your help.

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


Re: Synthesis Toolkit bindings for python?

2005-07-14 Thread Cappy2112
Have you tried emailing the authors?

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


Python Installation error on Solaris-9-SPARC

2005-07-14 Thread Madhu R. Vajrala
Hello All,

I am very new to Python, trying to install it from source
(ftp://ftp.sunfreeware.com/pub/freeware/SOURCES/python-2.3.3.tar.gz) on
Sun Solaris-9 (SPARC). But getting the below error message during
configure. Also while uncompressing, it is returning the checksum doesnt
match error as well.

Configure Error:

config.status: error: cannot find input file: Modules/Setup.config.in

untar error:
.
.
.
.
.
.
x
Python-2.3.3/Mac/OSXResources/app/Resources/English.lproj/Documentation/doc, 0 
bytes, 0 tape blocks
x
Python-2.3.3/Mac/OSXResources/app/Resources/English.lproj/Documentation/doc/index.html,
 882 bytes, 2 tape blocks
x
Python-2.3.3/Mac/OSXResources/app/Resources/English.lproj/Documentation/ide, 0 
bytes, 0 tape blocks
x
Python-2.3.3/Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/index.html,
 9909 bytes, 20 tape blocks
x
Python-2.3.3/Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/IDE.gif,
 10249 bytes, 21 tape blocks
tar: directory checksum error

Can someone help me understand why it is returning error, Also I do not
'root' privileges on the server that i am trying install. So I will be
installing my home directory.

Thank You,
Madhu


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


trouble importing modules

2005-07-14 Thread Brandon Metcalf
I come from a Perl and C background and have been given an application
written in Python to maintain and I know very little about Python.
I'm having trouble at run time with importing modules.  Specifically,
in several places time.strptime() is being used and Freeze is being
used to produce binaries for each platform where this application
runs.  _strptime.py is also being supplied with the binaries.

The first problem I encountered coming from _strptime.py was:

  ImportError: No module named calendar

_strptime.py imports calendar, but my thought was that since freeze
isn't being run against _strptime.py directly, the calendar module may
not be getting built into the resulting binary.  So, I added "import
calendar" to the file I'm running freeze against.  This fixed
(probably not in the proper way) the above error, but now I'm getting
from calendar.py:

  ImportError: No module named datetime

So, my question is how can I ensure that all modules that
_strptime.py, calendar.py, etc. rely are built in the resulting
binaries without having to import everything explicitly in my code?

I'm using Python 2.3.4.

Thanks.

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


Re: all possible combinations

2005-07-14 Thread rbt
Thanks to all who were helpful... some of you guys are too harsh and
cynical. Here's what I came up with. I believe it's a proper
combination, but I'm sure someone will point out that I'm wrong ;)

groups = [list('abc'),list('abc'),list('abc'),list('abc')]

already = []

while 1:

LIST = []

for g in groups:
sample = random.sample(g, 1)
LIST.append(sample[0])

STRING = ''.join(LIST)
if STRING not in already:
print STRING
already.append(STRING)
if len(already) == 81:
break

On Thu, 2005-07-14 at 23:18 +1000, John Machin wrote:
> Steven D'Aprano wrote:
> > On Thu, 14 Jul 2005 08:49:05 +1000, John Machin wrote:
> > 
> > 
> >>"You keep using that word. I do not think it means what you think it means."
> >>
> >>Both of you please google("define: combination")
> > 
> > 
> > Combination: "a coordinated sequence of chess moves".
> > 
> > "An option position that is effected by either a purchase of two long
> > positions or two short positions. The investor purchases a call and a put
> > (or sells a call and a put) with different expiration dates and/or
> > different strike prices."
> > 
> > Or perhaps "in Scheme, a function call, consisting of a function name and
> > arguments written within parentheses."
> > 
> > Yes, mathematically the definition of combination includes that order does
> > not matter. But that certainly isn't the case in common English. Now,
> > John, given the tone of the posts you are complaining about,
> 
> Wrong -- no complaint. Another quote: "It's a joke, Joyce!"
> 
> > do you think
> > I was using combination in the precise mathematical sense, or the common
> > English sense?
> 
> As in "Please don't get your combinations in a twist?"?
> 
> > 
> > (Hint: the very first definition Google finds is "a collection of things
> > that have been combined; an assemblage of separate parts or qualities ".
> > Not a word there about order mattering or not.)
> 

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


Re: Python Installation error on Solaris-9-SPARC

2005-07-14 Thread Grig Gheorghiu
Why don't you donwload the source from python.org? Also, on Solaris tar
is sometimes broken (i.e. can't deal with long directory names etc.)
You may want to donwload and install gnu tar.

Grig

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


Re: Who uses input()? [was Re: question on "input"]

2005-07-14 Thread Terry Hancock
On Thursday 14 July 2005 07:00 am, Michael Hoffman wrote:
> Devan L wrote:
> > Use raw_input instead. It returns a string of whatever was typed. Input
> > expects a valid python expression.
> 
> Who actually uses this? It's equivalent to eval(raw_input(prompt)) but 
> causes a lot of newbie confusion. Python-dev archives revealed that 
> someone tried to get this deprecated but Guido disagreed.

I don't think it should disappear, but it *does* seem more sensible for
"raw_input" to be called "input" (or "readstring" or some such thing) and
"input" to vanish into greater obscurity as "eval_input" or something.

Unfortunately, that would break code if anything relied on "input", so I
guess that would be a Py3K idea, and maybe the whole I/O concept
will be rethought then (if the "print" statement is going to go away,
anyway).

--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com

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


Re: threads and sleep?

2005-07-14 Thread Christopher Subich
Jp Calderone wrote:
> On 14 Jul 2005 05:10:38 -0700, Paul Rubin 
> <"http://phr.cx"@nospam.invalid> wrote:
> 
>> Andreas Kostyrka <[EMAIL PROTECTED]> writes:
>>
>>> Basically the current state of art in "threading" programming doesn't
>>> include a safe model. General threading programming is unsafe at the
>>> moment, and there's nothing to do about that. It requires the developer
>>> to carefully add any needed locking by hand.
>>
>>
>> So how does Java do it?  Declaring some objects and functions to be
>> synchronized seems to be enough, I thought.
> 
> 
> Multithreaded Java programs have thread-related bugs in them too.  So it 
> doesn't seem to be enough.  Like Python's model, Java's is mostly about 
> ensuring internal interpreter state doesn't get horribly corrupted.  It 
> doesn't do anything for application-level state.  For example, the 

Hrm... this would suggest the possibility of designing a metaclass, 
perhaps, that would ensure synchronous access to an object.  Perhaps 
"wrap" the class in another, that gets and releases a mutex on any 
external get/set access (except, possibly, for a specified list of 
"asynchronous" data members and methods).

This, of course, wouldn't elminate deadlocks, but that's a problem that 
arises from interaction from multiple objects, rather than within a 
single one.
-- 
http://mail.python.org/mailman/listinfo/python-list


Differences between RDFlib - 4RDF and Redfoot - 4Suite?

2005-07-14 Thread Elmo Mäntynen
I was wondering about the differences with the referred libs and servers.
Since the documentation isn't so thorough(and a bit because of my laziness),
I thought I'd make request for usage accounts etc. stating the pros and
cons of the aforementioned. Any notes would be appreciated.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Installation error on Solaris-9-SPARC

2005-07-14 Thread Madhu R. Vajrala
I did...

1. wget http://www.python.org/ftp/python/2.4.1/Python-2.4.1.tgz

2. gunzip -c Python-2.4.1.tgz | tar xvf -

the above step errors:

tar: directory checksum error
gunzip: stdout: Broken pipe


3. Later in ./configure step...
 This step also fails...(I did run this by ignoring the checksum error
in the previous step).

checking for build directories... done
configure: creating ./config.status
config.status: creating Makefile.pre
config.status: creating Modules/Setup.config
**config.status: error: cannot find input file:
Modules/Setup.config.in**


Thank You,
madhu

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


Re: more newbie list questions

2005-07-14 Thread googleboy
Thanks for this.  It ahs been very helpful.

I realised that my problem using getattr were because I was trying to
use it over the list of lists, instead of each book.  I have written up
a for loop now, and I think I am a lot closer:

for book in all_books:
author1 = getattr(book, 'author1')
sTemplate.replace('author1', author1)
found = sTemplate.find('%author1%')
print '\n.\n.\n'
print author1
print '\n'
print found
print sTemplate


You will notice that I print out various things. I am having some
troubles.

The resulting output of this loop is as follows:

andy humber

47
The title is %title%.  

The author is %author1% %author2% 

The Publisher is %publisher1% %publisher2% 

The ISBN is %ISBN% 

This is obviously correctly assigning the author's name to the author1
variable, which I was my problem.

It is finding my search string at teh 47th character of the sTemplate
string, which is great.

But it doesn't seem to want to replace the search string with the value
of the author1 variable.

Is there something else I am missing here?

Thanks for the advice.

regards,

googleboy

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


Re: Python Installation error on Solaris-9-SPARC

2005-07-14 Thread casevh


Madhu R. Vajrala wrote:
>
> 2. gunzip -c Python-2.4.1.tgz | tar xvf -
>

Use gtar. The Solaris tar does not hnadle long file names correctly.
gtar should be found in /usr/sfw/bin.

cvh

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


unbuffer script using pexpect

2005-07-14 Thread Krutibas Biswal
Hi,
 I am using a script 'unbuffer' for unbuffering my outputs when using
pipes.
This script is based on expect and looks like this :
--
#!/usr/bin/expect --
# Description: unbuffer stdout of a program
# Author: Don Libes, NIST

eval spawn -noecho $argv
set timeout -1
expect
--

Now if you do

% unbuffer 
it works fine.

I am trying to write a similar similar script in python (pexpect) and
it
looks like this :


#!/usr/bin/env python
# Description: unbuffer stdout of a program and return program's error
code

import pexpect
import sys

child = pexpect.spawn(' '.join(sys.argv[1:]))
child.expect('(.+\n)+')
sys.stdout.flush()
child.interact() # Escape character defaults to ^]

sys.exit(child.exitstatus)


This script works fine except that after the output is displayed
on the screen, it expects me to press  to comeback to the
prompt. What is wrong here ? (I am a newbie)

Thanks,
Krutibas

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


Native ODBC access for python on linux?

2005-07-14 Thread callmebill
I'm getting my feet wet with making Python talk to MySQL via ODBC.  I
started on Windows, and it went smoothly enough due to the ODBC stuff
that apparently is native to Python at least on windows (I've been
following ch. 13 of Mark Hammond's py on win32 book).

But now I'm trying to do equivalent stuff on linux (Fedora Core 3) with
python 2.3.5 and mysql.  I'd like to stick with packages that are
native to python, rather than relying on external stuff (e.g., MySQLdb
and mxODBC).  Is this possible, or do I have to use 3rd party pieces to
use ODBC with Python under linux?


As an aside, I've only used ODBC to access db's, period.  I've never
used, for example, MySQL's API for working with a MySQL db.  I'm
curious to see what that looks like, if anyone has any examples
(python, c, or otherwise).

Thanks in advance for any help.
-Bill

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


Re: Python Installation error on Solaris-9-SPARC

2005-07-14 Thread Skip Montanaro

Madhu> I did...
Madhu> 1. wget http://www.python.org/ftp/python/2.4.1/Python-2.4.1.tgz

Madhu> 2. gunzip -c Python-2.4.1.tgz | tar xvf -

Madhu> the above step errors:
Madhu> 
Madhu> tar: directory checksum error
Madhu> gunzip: stdout: Broken pipe
Madhu> 

You can't use Sun's tar to unpack the tarfile.  The directory structure is
too deep.  Get ahold of GNU tar instead.

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


Why does python break IEEE 754 for 1.0/0.0 and 0.0/0.0?

2005-07-14 Thread Grant Edwards
I've read over and over that Python leaves floating point
issues up to the underlying platform.  

This seems to be largely true, but not always.  My underlying
platform (IA32 Linux) correctly handles 1.0/0.0 and 0.0/0.0
according to the IEEE 754 standard, but Python goes out of its
way to do the wrong thing.

1/0 is defined by the standard as +Inf and 0/0 is NaN.

That's what my platform does for programs written in C.  Python
apparently checks for division by zero and throws and exception
rather than returning the correct value calculated by the
underlying platform.

Is there any way to get Python to return the correct results
for those operations rather than raising an exception?

There's no way to "resume" from the exception and return a 
value from an exception handler, right?  [This is the other
option allowed by the IEEE 754 standard.]

-- 
Grant Edwards   grante Yow!  ... I want a COLOR
  at   T.V. and a VIBRATING BED!!!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Tkinter Button widget

2005-07-14 Thread Shankar Iyer ([EMAIL PROTECTED])
Hi,

 I have another Tkinter-related question.  At the beginning of my program, 
a tkinter window is created with six buttons.  Each of these buttons is 
assigned a function that should be executed only when the button is pressed.  
However, it seems that these functions are all executed once when the button 
widgets are first created.  Why is this the case and how do I prevent this from 
happening?

Shankar

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


Re: Native ODBC access for python on linux?

2005-07-14 Thread Larry Bates
ODBC is a vanilla interface that puts a layer between the program
and the database.  In theory, this would allow you to write a
program that supports ODBC compliant databases and it would work
with any of them.  In practice it always seems like this doesn't
work as well as everyone had hoped (performance is quite often a
problem with ODBC interface and time/date handling can be an
issue).

There are people that provide ODBC drivers for Linux but normally
they are used to communcate back to MSSQL servers or other Windows
applications from Linux box.

The native interfaces are almost always better performing and
support more features because ODBC is basically a lowest common
denominator approach.  The native API can provide access to all
the (even unique) features of the particular database

IMHO-For Python to MySQL on Linux use the native interface is
the way to go.

Larry Bates

[EMAIL PROTECTED] wrote:
> I'm getting my feet wet with making Python talk to MySQL via ODBC.  I
> started on Windows, and it went smoothly enough due to the ODBC stuff
> that apparently is native to Python at least on windows (I've been
> following ch. 13 of Mark Hammond's py on win32 book).
> 
> But now I'm trying to do equivalent stuff on linux (Fedora Core 3) with
> python 2.3.5 and mysql.  I'd like to stick with packages that are
> native to python, rather than relying on external stuff (e.g., MySQLdb
> and mxODBC).  Is this possible, or do I have to use 3rd party pieces to
> use ODBC with Python under linux?
> 
> 
> As an aside, I've only used ODBC to access db's, period.  I've never
> used, for example, MySQL's API for working with a MySQL db.  I'm
> curious to see what that looks like, if anyone has any examples
> (python, c, or otherwise).
> 
> Thanks in advance for any help.
> -Bill
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter Button widget

2005-07-14 Thread Peter Otten
Shankar Iyer ([EMAIL PROTECTED]) wrote:

>  I have another Tkinter-related question.  At the beginning of my
>  program, a tkinter window is created with six buttons.  Each of these
>  buttons is assigned a function that should be executed only when the
>  button is pressed.  However, it seems that these functions are all
>  executed once when the button widgets are first created.  Why is this
>  the case and how do I prevent this from happening?

Change your source code from 

# wrong
button = Tkinter.Button(..., command=some_function(),...)

to

# correct
button = Tkinter.Button(..., command=some_function,...)

to pass the *function* to the widget instead of the *result* of a function
call. And, next time, remember to post some code alongside with your
question.

Peter




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


Re: Why does python break IEEE 754 for 1.0/0.0 and 0.0/0.0?

2005-07-14 Thread Tim Peters
[Grant Edwards]
> I've read over and over that Python leaves floating point
> issues up to the underlying platform.
>
> This seems to be largely true, but not always.  My underlying
> platform (IA32 Linux) correctly handles 1.0/0.0 and 0.0/0.0
> according to the IEEE 754 standard, but Python goes out of its
> way to do the wrong thing.

Python does go out of its way to raise ZeroDivisionError when dividing by 0.

> 1/0 is defined by the standard as +Inf and 0/0 is NaN.
>
> That's what my platform does for programs written in C.

IOW, that's what your platform C does (the behavior of these cases is
left undefined by the C89 standard, so it's not the case that you can
write a _portable_ C89 program relying on these outcomes).  What does
your platform C return for the integer expression 42/0?  Is any other
outcome "wrong"?

> Python apparently checks for division by zero and throws and exception
> rather than returning the correct value calculated by the
> underlying platform.
>
> Is there any way to get Python to return the correct results
> for those operations rather than raising an exception?

No, except when using the decimal module.  The latter provides all the
facilities in IBM's proposed standard for decimal floating-point,
which intends to be a superset of IEEE 854:

http://www2.hursley.ibm.com/decimal/

It's relatively easy to do this in the decimal module because it
emulates, in software, all the gimmicks that most modern FPUs provide
in hardware.

Note that support for 754 was rare on Python platforms at the time
Python was designed, and nobody mentioned 754 support as even a vague
desire in those days.  In the absence of user interest, and in the
absence of HW support for NaNs or infinities on most Python platforms,
the decision to raise an exception was quite sensible at the time. 
Python could not have implemented 754 semantics without doing
emulating fp arithmetic in SW on most platforms (as the decimal module
does today), and for much the same reasons you can't give a non-silly
answer to my earlier "what does your platform C return for the integer
expression 42/0?" question today .

> There's no way to "resume" from the exception and return a
> value from an exception handler, right?

Correct.

Note that there's a huge, current, informed discussion of these issues
already in the math.nroot thread.
-- 
http://mail.python.org/mailman/listinfo/python-list


Changing size of Win2k/XP console?

2005-07-14 Thread Sheeps United
Hi, I'm quite a newbie but I've managed to google around before asking 
stupid Q's here.

I'm wrestling with little (amateurish) console program and I would like 
change its size. I also know that it could be done with Windows API call. I 
tried doing that myself but no good.

Could anyone help me?



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


Re: Why does python break IEEE 754 for 1.0/0.0 and 0.0/0.0?

2005-07-14 Thread Grant Edwards
On 2005-07-14, Tim Peters <[EMAIL PROTECTED]> wrote:

> Python does go out of its way to raise ZeroDivisionError when
> dividing by 0.
>
>> 1/0 is defined by the standard as +Inf and 0/0 is NaN.
>>
>> That's what my platform does for programs written in C.
>
> IOW, that's what your platform C does (the behavior of these
> cases is left undefined by the C89 standard, so it's not the
> case that you can write a _portable_ C89 program relying on
> these outcomes).

True, but as a paracial matter, all of the C platforms I care
about all do obey IEEE 754.

> What does your platform C return for the integer expression
> 42/0?  Is any other outcome "wrong"?

I guess I though it was obvious from my reference to IEEE 754
that I was referring to floating point operations.  I don't
know (or generally care) what my C platform does for integer
divide by zero.

>> Python apparently checks for division by zero and throws and
>> exception rather than returning the correct value calculated
>> by the underlying platform.
>>
>> Is there any way to get Python to return the correct results
>> for those operations rather than raising an exception?
>
> No, except when using the decimal module.  The latter provides
> all the facilities in IBM's proposed standard for decimal
> floating-point, which intends to be a superset of IEEE 854:
>
> http://www2.hursley.ibm.com/decimal/
>
> It's relatively easy to do this in the decimal module because
> it emulates, in software, all the gimmicks that most modern
> FPUs provide in hardware.
>
> Note that support for 754 was rare on Python platforms at the
> time Python was designed, and nobody mentioned 754 support as
> even a vague desire in those days.

I often foget how old Python is.  Still, I've been using IEEE
floating point in C programs (and depending on the proper
production and handling of infinities and NaNs) for more than
20 years now.  I had thought that Python might have caught up.

> In the absence of user interest, and in the absence of HW
> support for NaNs or infinities on most Python platforms,

Really?  I would have guessed that most Python platforms are
'586 or better IA32 machines running either Windows or Linux.
They all have HW support for NaNs and Infinities.

> the decision to raise an exception was quite sensible at the
> time. Python could not have implemented 754 semantics without
> doing emulating fp arithmetic in SW on most platforms (as the
> decimal module does today), and for much the same reasons you
> can't give a non-silly answer to my earlier "what does your
> platform C return for the integer expression 42/0?" question
> today .
>
>> There's no way to "resume" from the exception and return a
>> value from an exception handler, right?
>
> Correct.
>
> Note that there's a huge, current, informed discussion of
> these issues already in the math.nroot thread.

-- 
Grant Edwards   grante Yow!  It's OKAY --- I'm an
  at   INTELLECTUAL, too.
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter Button widget

2005-07-14 Thread Fuzzyman


Peter Otten wrote:
> Shankar Iyer ([EMAIL PROTECTED]) wrote:
>
[snip..]
>
> Change your source code from
>
> # wrong
> button = Tkinter.Button(..., command=some_function(),...)
>
> to
>
> # correct
> button = Tkinter.Button(..., command=some_function,...)
>
> to pass the *function* to the widget instead of the *result* of a function
> call. And, next time, remember to post some code alongside with your
> question.
>

Nice spot of mind reading there ;-)
I remember getting bitten by this one a while ago

Regards,


Fuzzy

> Peter

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


Re: Native ODBC access for python on linux?

2005-07-14 Thread Grig Gheorghiu
I concur with Larry. I find that by properly abstracting the database
connection code in my own class, I can then use any DB-API-compliant
Python module to connect to a variety of databases. I use for example
cxOracle to connect to Oracle and kinterbasdb to connect to firebird. I
haven't tried connecting to MySQL natively yet, but I don't think it
would be any different.

Grig

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


Re: all possible combinations

2005-07-14 Thread Paul Rubin
rbt <[EMAIL PROTECTED]> writes:
> Say I have a list that has 3 letters in it:
> 
> ['a', 'b', 'c']
> 
> I want to print all the possible 4 digit combinations of those 3
> letters:

for i in xrange(81):
  print ''.join(['abcd'[j]  
 for j in [(i//d)%3 for d in (27,9,3,1)]])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Native ODBC access for python on linux?

2005-07-14 Thread Thomas Bartkus

<[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> I'm getting my feet wet with making Python talk to MySQL via ODBC.  I
> started on Windows, and it went smoothly enough due to the ODBC stuff
> that apparently is native to Python at least on windows (I've been
> following ch. 13 of Mark Hammond's py on win32 book).
>
> But now I'm trying to do equivalent stuff on linux (Fedora Core 3) with
> python 2.3.5 and mysql.  I'd like to stick with packages that are
> native to python, rather than relying on external stuff (e.g., MySQLdb
> and mxODBC).  Is this possible, or do I have to use 3rd party pieces to
> use ODBC with Python under linux?
>
>
> As an aside, I've only used ODBC to access db's, period.  I've never
> used, for example, MySQL's API for working with a MySQL db.  I'm
> curious to see what that looks like, if anyone has any examples
> (python, c, or otherwise).
>
> Thanks in advance for any help.
> -Bill

We have a Linux/Apache/MySQL server.  We use the ODBC driver to write
Windows clients using VB.  I only understand ODBC as a means to bring the
Linux/Apache/MySQL to speaking terms with the Microsoft world. ODBC serves
as the translator between these 2 alien systems.

Although I hear rumors about ODBC drivers on Linux, I confess I don't
understand the need. Certainly you can use Python with the MySQLdb module
from any Linux machine and query away at the server.  As long as the MySQL
server accepts your IP/usr/pwd, it will respond to the SQL you pass it from
Python.

IOW - who/what needs an ODBC driver here?
Thomas Bartkus


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


Python and MySQL server

2005-07-14 Thread Unknown
Python 2.4
Linux kernel 2.6.12

Hi,

1. How do I make the following statement to search for all Strings I
input from console?

for example, with the code below I need to enter %hello world% (yeah,
including the % symbols) to find all entries for hello world on the
tableName. But I want to set the % symbols on the code itself so I don't
have to input manually the % at the prompt.

searchWhat = raw_input ('Search for : ')
cursor.execute('select * from tableName where contentField like
%s',(searchWhat))

2. I'm entering data by copying and pasting. Much of the text is in
multiple lines and some formated sections such as paragraphs,
indentations, double lines and what not.

How do I enter keep the formated text intact if entering from console? Now
it loses all formatting and I have to copy and paste text line by line
because it won't take the multiple lines.

insertEntryId = raw_input('New Entry ID: ')
insertEntryContent = raw_input('New Entry Content: ')
insertEntryCategory = raw_input('New Category: ')

cursor.execute('insert into tableName values (%s,%s,%s)',
(insertEntryId,insertEntryContent,insertEntryCategory))

Thanks, Any help is appreciate it.

Mr. Frodo

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


Re: Native ODBC access for python on linux?

2005-07-14 Thread callmebill
Can you tell me what I have to use in order to utilize the MySQL native
API?  There's some gap (chasm, really) in my knowledge that is keeping
me from following that route.  If you could provide a small example or
a couple names, that would be extremely helpful.

Thanks again for your time.

Larry Bates wrote:
> ODBC is a vanilla interface that puts a layer between the program
> and the database.  In theory, this would allow you to write a
> program that supports ODBC compliant databases and it would work
> with any of them.  In practice it always seems like this doesn't
> work as well as everyone had hoped (performance is quite often a
> problem with ODBC interface and time/date handling can be an
> issue).
>
> There are people that provide ODBC drivers for Linux but normally
> they are used to communcate back to MSSQL servers or other Windows
> applications from Linux box.
>
> The native interfaces are almost always better performing and
> support more features because ODBC is basically a lowest common
> denominator approach.  The native API can provide access to all
> the (even unique) features of the particular database
>
> IMHO-For Python to MySQL on Linux use the native interface is
> the way to go.
>
> Larry Bates
>
> [EMAIL PROTECTED] wrote:
> > I'm getting my feet wet with making Python talk to MySQL via ODBC.  I
> > started on Windows, and it went smoothly enough due to the ODBC stuff
> > that apparently is native to Python at least on windows (I've been
> > following ch. 13 of Mark Hammond's py on win32 book).
> >
> > But now I'm trying to do equivalent stuff on linux (Fedora Core 3) with
> > python 2.3.5 and mysql.  I'd like to stick with packages that are
> > native to python, rather than relying on external stuff (e.g., MySQLdb
> > and mxODBC).  Is this possible, or do I have to use 3rd party pieces to
> > use ODBC with Python under linux?
> >
> >
> > As an aside, I've only used ODBC to access db's, period.  I've never
> > used, for example, MySQL's API for working with a MySQL db.  I'm
> > curious to see what that looks like, if anyone has any examples
> > (python, c, or otherwise).
> > 
> > Thanks in advance for any help.
> > -Bill
> >

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


Re: Changing size of Win2k/XP console?

2005-07-14 Thread Peter Hansen
Sheeps United wrote:
> Hi, I'm quite a newbie but I've managed to google around before asking 
> stupid Q's here.
> 
> I'm wrestling with little (amateurish) console program and I would like 
> change its size. I also know that it could be done with Windows API call. I 
> tried doing that myself but no good.
> 
> Could anyone help me?

Which Windows API call did you try using?  Can you show us a line or two 
of code that you tried?  Most likely then someone will be able to point 
out what went wrong and it will work.  (Chances are that very few here 
know the API call required, so by not mentioning it you're severely 
limiting the number of answers you are likely to get.)

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


Re: Why does python break IEEE 754 for 1.0/0.0 and 0.0/0.0?

2005-07-14 Thread Tim Peters
[Tim Peters]
...
>> What does your platform C return for the integer expression
>> 42/0?  Is any other outcome "wrong"?

[Grant Edwards] 
> I guess I though it was obvious from my reference to IEEE 754
> that I was referring to floating point operations.

Yes, that was obvious.  Since I thought my point would be equally
obvious, I won't spell it out <0.7 wink>.

...

>> Note that support for 754 was rare on Python platforms at the
>> time Python was designed, and nobody mentioned 754 support as
>> even a vague desire in those days.

> I often foget how old Python is.  Still, I've been using IEEE
> floating point in C programs (and depending on the proper
> production and handling of infinities and NaNs) for more than
> 20 years now.  I had thought that Python might have caught up.

It has not.  Please see the other thread I mentioned.

>> In the absence of user interest, and in the absence of HW
>> support for NaNs or infinities on most Python platforms,

> Really?

Yes, but looks like you didn't finish reading the sentence.  Here's
the rest, with emphasis added:

>> the decision to raise an exception was quite sensible AT THE TIME.

You may have forgotten how much richer the "plausible HW" landscape
was at the time too.  I was deeply involved in implementing Kendall
Square Research's HW and SW 754 story at the time, and it was all
quite novel, with little prior art to draw on to help resolve the
myriad language issues 754 didn't address (e.g., what should Fortran's
3-branch Arithmetic IF statement do if fed a NaN?  there were hundreds
of headaches like that, and no cooperation among compiler vendors
since the language standards ignored 754).  The C standards didn't
mention 754 until C99, and then left all support optional (up to the
compiler implementer whether to do it).  That didn't help much for a
bigger reason:  major C vendors (like Microsoft and Borland) are still
ignoring C99.  "Subset" HW implementations of 754 were also common,
like some that didn't support denorms at all, others that didn't
implement the non-default rounding modes, some that ignored signed
zeroes, and several that implemented 754 endcases by generating kernel
traps to deal with infinities and NaNs, making them so much slower
than normal cases that users avoided them like death.

If I had to bet at the time, I would have put my money on 754 dying
out due to near-universal lack of language support, and incompatible
HW implementations.  Most programming languages still have no sane 754
story, but the remarkable dominance of the Pentium architecture
changed everything on the HW side.

>  I would have guessed that most Python platforms are
> '586 or better IA32 machines running either Windows or Linux.

Today, yes, although there are still Python users on many other OSes
and architectures.  Most of the latter support 754 too now.

> They all have HW support for NaNs and Infinities.

Yes, Intel-based boxes certainly do (and have for a long time), and so
do most others now.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter Button widget

2005-07-14 Thread William Park
Peter Otten <[EMAIL PROTECTED]> wrote:
> Shankar Iyer ([EMAIL PROTECTED]) wrote:
> 
> >  I have another Tkinter-related question.  At the beginning of my
> >  program, a tkinter window is created with six buttons.  Each of these
> >  buttons is assigned a function that should be executed only when the
> >  button is pressed.  However, it seems that these functions are all
> >  executed once when the button widgets are first created.  Why is this
> >  the case and how do I prevent this from happening?
> 
> Change your source code from 
> 
> # wrong
> button = Tkinter.Button(..., command=some_function(),...)
> 
> to
> 
> # correct
> button = Tkinter.Button(..., command=some_function,...)
> 
> to pass the *function* to the widget instead of the *result* of a
> function call. And, next time, remember to post some code alongside
> with your question.

Hmm, maybe I should learn Tk + Python.  Telepathetic powers of Python
programmers are amazing.

-- 
William Park <[EMAIL PROTECTED]>, Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
   http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
  http://freshmeat.net/projects/bashdiff/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: all possible combinations

2005-07-14 Thread Rocco Moretti
rbt wrote:
> Say I have a list that has 3 letters in it:
> 
> ['a', 'b', 'c']
> 
> I want to print all the possible 4 digit combinations of those 3
> letters:

When I have occasion to do an iteration of iterations, I either use 
recursion (already posted) or use an accumulator type loop:

items = ['a','b','c']
accume = [[],]

for pos in range(4):
   old_accume, accume = accume, []
   for comb in old_accume:
 for item in items:
   accume.append(comb + [item])

accume = [''.join(x) for x in accume]
print accume

['', 'aaab', 'aaac', 'aaba', 'aabb', 'aabc', 'aaca', 'aacb', 'aacc', 
'abaa', 'abab', 'abac', 'abba', 'abbb', 'abbc', 'abca', 'abcb', 'abcc', 
'acaa', 'acab', 'acac', 'acba', 'acbb', 'acbc', 'acca', 'accb', 'accc', 
'baaa', 'baab', 'baac', 'baba', 'babb', 'babc', 'baca', 'bacb', 'bacc', 
'bbaa', 'bbab', 'bbac', 'bbba', '', 'bbbc', 'bbca', 'bbcb', 'bbcc', 
'bcaa', 'bcab', 'bcac', 'bcba', 'bcbb', 'bcbc', 'bcca', 'bccb', 'bccc', 
'caaa', 'caab', 'caac', 'caba', 'cabb', 'cabc', 'caca', 'cacb', 'cacc', 
'cbaa', 'cbab', 'cbac', 'cbba', 'cbbb', 'cbbc', 'cbca', 'cbcb', 'cbcc', 
'ccaa', 'ccab', 'ccac', 'ccba', 'ccbb', 'ccbc', 'ccca', 'cccb', '']

Optimize as you see fit.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing size of Win2k/XP console?

2005-07-14 Thread Sheeps United
"Peter Hansen" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Which Windows API call did you try using?  Can you show us a line or two 
> of code that you tried?  Most likely then someone will be able to point 
> out what went wrong and it will work.  (Chances are that very few here 
> know the API call required, so by not mentioning it you're severely 
> limiting the number of answers you are likely to get.)

No actual code, yet.

I'm far from sure if it's the right one, but I think it could be 
SetConsoleScreenBufferSize from Kernel32. Hrr, for some reason I have nasty 
feeling in back of my head... That could also be totally wrong way of 
approaching.



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


Re: Why does python break IEEE 754 for 1.0/0.0 and 0.0/0.0?

2005-07-14 Thread Grant Edwards
On 2005-07-14, Tim Peters <[EMAIL PROTECTED]> wrote:

> You may have forgotten how much richer the "plausible HW" landscape
> was at the time too.

I've probably blocked most of it out intentionally.  I seem to
have vague, repressed, memories of working on a Sperry machine
that used base 4 floating point.  And of course there was the
VAX.

> If I had to bet at the time, I would have put my money on 754
> dying out due to near-universal lack of language support, and
> incompatible HW implementations.  Most programming languages
> still have no sane 754 story, but the remarkable dominance of
> the Pentium architecture changed everything on the HW side.

As messed up as I think the IA32 architecture is, I do think
Intel got FP mostly right. :)

-- 
Grant Edwards   grante Yow!  If I felt any more
  at   SOPHISTICATED I would DIE
   visi.comof EMBARRASSMENT!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing size of Win2k/XP console?

2005-07-14 Thread Jason Drew
SetConsoleWindowInfo looks like a better candidate. See
http://tinyurl.com/budzk
(I.e.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/setconsolewindowinfo.asp)

Haven't tried it though. Good luck!

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


Re: Why does python break IEEE 754 for 1.0/0.0 and 0.0/0.0?

2005-07-14 Thread Grant Edwards
On 2005-07-14, Grant Edwards <[EMAIL PROTECTED]> wrote:
> On 2005-07-14, Tim Peters <[EMAIL PROTECTED]> wrote:
>
>> You may have forgotten how much richer the "plausible HW" landscape
>> was at the time too.
>
> I've probably blocked most of it out intentionally.  I seem to
> have vague, repressed, memories of working on a Sperry machine
> that used base 4 floating point.

No, on second thought, I think it was base-16.

-- 
Grant Edwards   grante Yow!  Yow! I want my nose
  at   in lights!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: all possible combinations

2005-07-14 Thread William Park
rbt <[EMAIL PROTECTED]> wrote:
> Say I have a list that has 3 letters in it:
> 
> ['a', 'b', 'c']
> 
> I want to print all the possible 4 digit combinations of those 3
> letters:
> 
> 4^3 = 64
> 
> 
> abaa
> aaba
> aaab
> acaa
> aaca
> aaac
> ...
> 
> What is the most efficient way to do this? 

Since you're doing cross product (ie. 3*3*3*3), manual loop of 4 level
deep would be the fastest in terms of algorithm.  C vs. Python is
implementation detail.

In Bash shell, this is one-liner,
echo {a,b,c}{a,b,c}{a,b,c}{a,b,c}
or maybe two,
abc=(a b c)
echo {^abc}{^abc}{^abc}{^abc}

-- 
William Park <[EMAIL PROTECTED]>, Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
   http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
  http://freshmeat.net/projects/bashdiff/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: all possible combinations

2005-07-14 Thread Erik Max Francis
William Park wrote:

> Since you're doing cross product (ie. 3*3*3*3), manual loop of 4 level
> deep would be the fastest in terms of algorithm.

That's a Cartesian product, actually :-).

-- 
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
   All generalizations are dangerous, even this one.
   -- Dumas Fils
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing size of Win2k/XP console?

2005-07-14 Thread Chris Lambacher
Referring to the documenation you will have to use that function and
SetConsoleWindowInfo to get the effect you want.  Basically
SetConsoleScreenBufferSize sets the size for the console and
SetConsoleWindowInfo sets the size for the window containing the console.  The
window size can't be bigger that the console size.  If the console size is
bigger than the window, you will end up with scrollbars.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/setconsolescreenbuffersize.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/setconsolescreenbuffersize.asp

You might want the get function as well:
GetConsoleScreenBufferInfo
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/setconsolescreenbuffersize.asp

When in doubt about the Microsoft API see the MSDN.

-Chris



-Chris


On Thu, Jul 14, 2005 at 11:48:09PM +0300, Sheeps United wrote:
> "Peter Hansen" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
> > Which Windows API call did you try using?  Can you show us a line or two 
> > of code that you tried?  Most likely then someone will be able to point 
> > out what went wrong and it will work.  (Chances are that very few here 
> > know the API call required, so by not mentioning it you're severely 
> > limiting the number of answers you are likely to get.)
> 
> No actual code, yet.
> 
> I'm far from sure if it's the right one, but I think it could be 
> SetConsoleScreenBufferSize from Kernel32. Hrr, for some reason I have nasty 
> feeling in back of my head... That could also be totally wrong way of 
> approaching.
> 
> 
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >