Re: how to write a line in a text file

2005-07-25 Thread Wade
Steven D'Aprano wrote:
>I'm usually opposed to creeping featuritis in programming languages ("it
>would be really cool if Python had a built-in command to do my entire
>application") but safe over-writing of files does cry out for a "batteries
>included" approach:


How about the fileinput module?

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

"""
Optional in-place filtering: if the keyword argument inplace=1 is
passed to input() or to the FileInput constructor, the file is moved to
a backup file and standard output is directed to the input file (if a
file of the same name as the backup file already exists, it will be
replaced silently). This makes it possible to write a filter that
rewrites its input file in place. If the keyword argument
backup='.' is also given, it specifies the extension
for the backup file, and the backup file remains around; by default,
the extension is '.bak' and it is deleted when the output file is
closed. In-place filtering is disabled when standard input is read.
"""

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


Should I move to Amsterdam?

2005-08-24 Thread Wade
http://www.slate.com/id/2124561/entry/2124562/

Nice little series by Seth Stevenson for Americans daydreaming about
emigration. Somewhere, anywhere ... maybe Amsterdam?

I've never been to the Netherlands myself, but it sounds very
civilized.

Extra Python connection, besides the obvious one: Is "gezellig" related
to the Zen of Python? (
http://wordcraft.infopop.cc/eve/ubb.x/a/tpc/f/6351024471/m/2041067571/r/3901049571
)

-- Wade Leftwich
Ithaca, NY

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


Re: urllib.urlretireve problem

2005-03-31 Thread Wade

Diez B. Roggisch wrote:
> It makes no sense having urllib generating exceptions for such a
case. From
> its point of view, things work pefectly - it got a result. No network
error
> or whatsoever.
>
> Its your application that is not happy with the result - but it has
to
> figure that out by itself.
>
> You could for instance try and see what kind of result you got using
the
> unix file command - it will tell you that you received a html file,
not a
> deb.
>
> Or check the mimetype returned - its text/html in the error case of
yours,
> and most probably something like application/octet-stream otherwise.
>
> Regards,
>
> Diez

Also be aware that many webservers (especially IIS ones) are configured
to return some kind of custom page instead of a stock 404, and you
might be getting a 200 status code even though the page you requested
is not there. So depending on what site you are scraping, you might
have to read the page you got back to figure out if it's what you
wanted.

-- Wade Leftwich
Ithaca, NY

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


Re: After migrating from debian to ubuntu, tkinter "hello world" doesn't work

2005-11-30 Thread Wade Leftwich

[EMAIL PROTECTED] wrote:
> Hi
>
> My tkinter apps worked fine in debian linux (woody and sarge)
> I moved to ubuntu 5.10
>
> I follow the 'hello world' test as seen in
> http://wiki.python.org/moin/TkInter
> 

Ubuntu uses X.org. Did your Debian distro use xfree86?

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


Re: Pythonic wrappers for SQL?

2006-01-16 Thread Wade Leftwich
Steve Holden wrote:
> >
> SQLObject is a very popuar object-relational mapper that works with a
> range of databases including SQLite.
>
> But SQL isn't actually that complicated to someone who's already learned
> Python! I maintain this page for students on the classes I teach, and it
> has some useful pointers:
>
>http://www.holdenweb.com/students/database.html
>
> regards
>   Steve
> --

With all the buzz about ORM these days, you don't hear much about good
old DBAPI. Maybe it's a matter of what's currently hip, or maybe DBAPI
has not achieved a consistent interface across adapters (e.g. ? vs %s
for placeholders). But it seems like to some extent the ORMs achieve
back end interchangeability by limiting what you can say.

Or maybe that's just my frustration because I am a beginner with
SQLObject, using it on a rewrite of an old (1999 or so) application
that has a lot of MSSQL-specific SQL expressed via mxODBC. I keep
catching myself working backward from what I want the SQL statement to
be, which is not very object-oriented on my part. I suppose it's a
matter of learning a new language, after a while you stop mentally
translating. However, I agree with the earlier comment that you'd
better be comfortable with SQL before you start trying to make sense of
an ORM, especially for data structures more complicated than you see in
a 20 minute screencast.

I am persevering with SQLObject, having faith that the extra work I'm
putting in to design my table classes will pay off in a more robust and
portable application. The module itself is elegant and well written,
and it uses metaclasses to boot.

-- Wade Leftwich
Ithaca, NY

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


Re: ElementTree and proper identation?

2006-09-27 Thread Wade Leftwich
John Salerno wrote:
> John Salerno wrote:
> > I've been doing a little studying of ElementTree and it doesn't seem
> > very satisfactory for writing XML files that are properly
> > formatted/indented. I saw on the website that there is an
> > indent/prettyprint function, but this isn't listed in the Python docs
> > and I didn't see it after doing a dir(), so I guess it isn't a part of
> > the Python version.
> >
> > Did I miss something somewhere else, or can you just not use ElementTree
> > to write formatted XML files as they'd look if done by hand?
> >
> > Thanks.

You can roll your own by starting at the root and recursing through
child elements, increasing the indentation as you go:

But I do it the lazy way:

$ xmllint --format ugly.xml >pretty.xml

-- Wade Leftwich
Ithaca, NY

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


Re: merits of Lisp vs Python

2006-12-08 Thread Wade Humeniuk
Mark Tarver wrote:
> How do you compare Python to Lisp?  What specific advantages do you
> think that one has over the other?
> 

Since the late 1950's Lisp has participated in the development of
modern (present day) programming practises.  It has shaped and been
shaped by the minds of just not programmers, but people involved
in dealing with the larger impacts and possibilities.
Its been there, is here, and will continue to be there in the future.
Lisp is a human construct that is a force to be reckoned with.  Its
construction reflects something very deep and fundamental about
computing.  So, it depends on what you want.

What do you want?

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


Re: merits of Lisp vs Python

2006-12-09 Thread Wade Humeniuk
tmh wrote:
> This is from the perspective of an aerospace engineer who passed
> through python several years ago on the way to lisp. Futhermore, this
> is a 2 glass of wine response.
> 


Thanks for the comments.  I think it is great that you took a "harder
and less travelled way".  It may be that some people get to a point
where they are either tired or think they know everything. Or.. their
brains just harden up and they become old dogs.

There seems to be a recurring theme to many of the posts in this thread
about syntax and readability.  Some of it is "If I can not instantly
read and understand what the code is doing then something is wrong
with it".  As if holding oneself as the standard of what is good and
correct is the only way.  If you see something and it
is not readily apparent what it is, then that is a sign than something
interesting may be going on.  I got into Lisp because when I
looked at it, I did not understand.  I did not think WTF! but thought
that something was  going on and maybe I was cheating myself if I
brushed it aside.

There is also some disdain expressed about badly written programs.
Why?  They may be that way for some very good reasons, it is folly
to think that programs have to be simple, obvious and elegant.  I find
interesting that a programmer got out their comfort zone and attempted
something.  Its better than the ones with the big egos who play it safe
so they do not appear to be a fool.

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


Re: merits of Lisp vs Python

2006-12-09 Thread Wade Humeniuk
mystilleef wrote:

> 
> People only contribute to things they understand and appreciate. More
> people would be writing Lisp libraries if it was worthwhile.
> Apparently, it doesn't seem to be. A few years ago, I tried to write an
> editor is Scheme. The experience was appalling. I was able to write a
> fully functional prototype editor in less than a week in Python.
> Shockingly, at the time, I had no experience in Python. Guess which
> community I was inclined to contribute to afterwards. I hear stories
> similar to mine time and again, yet the Lisp community won't take heed.
> They'd rather squeal about the superiority of macros and whine about
> their frustrations in Python news groups.
> 

Hmm.. Here is my first prototype in Lisp.  It took 20 seconds
to write.

(defun display-editor ()
   (capi:contain (make-instance 'capi:editor-pane)))

CL-USER 1 > (display-editor)
#

CL-USER 2 >


W



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


Re: merits of Lisp vs Python

2006-12-15 Thread Wade Humeniuk
Paul Rubin wrote:

> 
> "nif" is even cleaner in Haskell, if I have this right:
> 
> nif x p z n | (x < 0) = n
> | (x == 0) = z
> | (x > 0)  = p
> 
> All Haskell evaluation is automatically lazy, so no lambdas etc. needed.

You can use that style in CL.

(defun nif (x p z n)
   (or (when (< x 0) n)
   (when (= x 0) z)
   (when (> x 0) p)))


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


Re: Iterate through list two items at a time

2007-01-03 Thread Wade Leftwich

Jeffrey Froman wrote:
> Dave Dean wrote:
>
> >  I'm looking for a way to iterate through a list, two (or more) items at a
> > time.
>
> Here's a solution, from the iterools documentation. It may not be the /most/
> beautiful, but it is short, and scales well for larger groupings:
>
> >>> from itertools import izip
> >>> def groupn(iterable, n):
> ... return izip(* [iter(iterable)] * n)
> ...
> >>> list(groupn(myList, 2))
> [(0, 1), (2, 3), (4, 5), (6, 7), (8, 9), (10, 11)]
> >>> list(groupn(myList, 3))
> [(0, 1, 2), (3, 4, 5), (6, 7, 8), (9, 10, 11)]
> >>> list(groupn(myList, 4))
> [(0, 1, 2, 3), (4, 5, 6, 7), (8, 9, 10, 11)]
> >>> for a,b in groupn(myList, 2):
> ... print a, b
> ...
> 0 1
> 2 3
> 4 5
> 6 7
> 8 9
> 10 11
> >>>
>
> Jeffrey

This works great except you lose any 'remainder' from myList:

>>> list(groupn(range(10),3))
[(0, 1, 2), (3, 4, 5), (6, 7, 8)]  # did not include (9,)

The following might be more complex than necessary but it solves the
problem, and like groupn()
it works on infinite lists.

from itertools import groupby, imap
def chunk(it, n=0):
if n == 0:
return iter([it])
grouped = groupby(enumerate(it), lambda x: int(x[0]/n))
counted = imap(lambda x:x[1], grouped)
return imap(lambda x: imap(lambda y: y[1], x), counted)

>>> [list(x) for x in chunk(range(10), 3)]
[[0, 1, 2], [3, 4, 5], [6, 7, 8], [9]]

Note the chunks are iterators, not tuples as in groupn():

>>> [x for x in chunk(range(10), 3)]
[,
 ,
 ,
 ]


-- Wade Leftwich
Ithaca, NY

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


Re: Iterate through list two items at a time

2007-01-04 Thread Wade Leftwich

Wade Leftwich wrote:
> Jeffrey Froman wrote:
> > Dave Dean wrote:
> >
> > >  I'm looking for a way to iterate through a list, two (or more) items at a
> > > time.
> >
> > Here's a solution, from the iterools documentation. It may not be the /most/
> > beautiful, but it is short, and scales well for larger groupings:
> >
> > >>> from itertools import izip
> > >>> def groupn(iterable, n):
> > ... return izip(* [iter(iterable)] * n)
> > ...
> > >>> list(groupn(myList, 2))
> > [(0, 1), (2, 3), (4, 5), (6, 7), (8, 9), (10, 11)]
> > >>> list(groupn(myList, 3))
> > [(0, 1, 2), (3, 4, 5), (6, 7, 8), (9, 10, 11)]
> > >>> list(groupn(myList, 4))
> > [(0, 1, 2, 3), (4, 5, 6, 7), (8, 9, 10, 11)]
> > >>> for a,b in groupn(myList, 2):
> > ... print a, b
> > ...
> > 0 1
> > 2 3
> > 4 5
> > 6 7
> > 8 9
> > 10 11
> > >>>
> >
> > Jeffrey
>
> This works great except you lose any 'remainder' from myList:
>
> >>> list(groupn(range(10),3))
> [(0, 1, 2), (3, 4, 5), (6, 7, 8)]  # did not include (9,)
>
> The following might be more complex than necessary but it solves the
> problem, and like groupn()
> it works on infinite lists.
>
> from itertools import groupby, imap
> def chunk(it, n=0):
> if n == 0:
> return iter([it])
> grouped = groupby(enumerate(it), lambda x: int(x[0]/n))
> counted = imap(lambda x:x[1], grouped)
> return imap(lambda x: imap(lambda y: y[1], x), counted)
>
> >>> [list(x) for x in chunk(range(10), 3)]
> [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9]]
>
> Note the chunks are iterators, not tuples as in groupn():
>
> >>> [x for x in chunk(range(10), 3)]
> [,
>  ,
>  ,
>  ]
>
>
> -- Wade Leftwich
> Ithaca, NY

Or, using generator expressions instead of imap and getting rid of the
lambdas --

from itertools import groupby

def chunk(it, n=0):
if n == 0:
return iter([it])
def groupfun((x,y)):
return int(x/n)
grouped = groupby(enumerate(it), groupfun)
counted = (y for (x,y) in grouped)
return ((z for (y,z) in x) for x in counted)

>>> [list(x) for x in chunk(range(10), 3)]
[[0, 1, 2], [3, 4, 5], [6, 7, 8], [9]]

>>> [x for x in chunk(range(10), 3)]
[,
 ,
 ,
 ]

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


Re: Iterate through list two items at a time

2007-01-04 Thread Wade Leftwich
Peter Otten wrote:
> Wade Leftwich wrote:
>
> > from itertools import groupby
> >
> > def chunk(it, n=0):
> > if n == 0:
> > return iter([it])
> > def groupfun((x,y)):
> > return int(x/n)
> > grouped = groupby(enumerate(it), groupfun)
> > counted = (y for (x,y) in grouped)
> > return ((z for (y,z) in x) for x in counted)
> >
> >>>> [list(x) for x in chunk(range(10), 3)]
> > [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9]]
> >
> >>>> [x for x in chunk(range(10), 3)]
> > [,
> >  ,
> >  ,
> >  ]
>
> Note that all but the last of these generators are useless:
>
> >>> chunks = [x for x in chunk(range(10), 3)]
> >>> [list(x) for x in chunks]
> [[], [], [], [9]] # did you expect that?
> In [48]: chunkgen = chunk(range(10), 3)

In [49]: for x in chunkgen:
   : print list(x)
   :
   :
[0, 1, 2]
[3, 4, 5]
[6, 7, 8]
[9]

> Peter

That's an interesting gotcha that I've never run into when using this
function, because in practice I never put the generator returned by
chunk() inside a list comprehension.

In [51]: chunkgen = chunk(range(10), 3)

In [52]: [list(x) for x in chunkgen]
Out[52]: [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9]]

But, as you pointed out --

In [57]: chunkgen = chunk(range(10), 3)

In [58]: chunks = list(chunkgen)

In [59]: [list(x) for x in chunks]
Out[59]: [[], [], [], [9]]

So apparently when we list(chunkgen), we are exhausting the generators
that are its members. And if we do it again, we get rid of the [9] --

In [60]: [list(x) for x in chunks]
Out[60]: [[], [], [], []]

I'll admit that chunk() is needlessly tricky for most purposes. I wrote
it to accept a really lengthy, possibly unbounded, iterator and write
out 10,000-line files from it, and also to play with Python's new
functional capabilities.

-- Wade

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


Re: I am giving up perl because of assholes on clpm -- switching to Python

2007-08-04 Thread Todd Wade
On Jul 22, 2:20 am, Bruno Desthuilliers
<[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] a écrit :
>
> > Python is a better language, with php support,
>
> Python has php support ? My, I'm a professional web developper using
> both, and I didn't knew this.
>

As an aside, perl DOES support PHP:

http://search.cpan.org/~gschloss/PHP-Interpreter/

trwww

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

Re: On Java's Interface (the meaning of interface in computer programing)

2007-03-22 Thread Nigel Wade
Lew wrote:

> Jim Burton wrote:
>> Or you could stop feeding the trolls.
> 
> People need to stop saying that. The original post was a detailed if 
> incorrect 
> exposition of Java information. How in the world do you rate that trollish?

a) Xah's posting history.
b) the cross-posting
c) the advocacy of the contents

> 
> I have absolutely no reason to rate the OP as a troll or their post as
trollish.
> 

In time you will learn...

It wasn't even a good troll. To be a good troll the message actually needs to be
interesting enough to get people to read it. 


-- 
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK 
E-mail :[EMAIL PROTECTED] 
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Modernization of Emacs: terminology buffer and keybinding

2007-10-08 Thread Wade Ward



"Damien Kick" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

> This thread of conversation also popped into my head when I was waiting in 
> line at the Starbucks in the building in which I work.  I've been ordering 
> a lot of Americanos lately.  I always ask for a small Americano and the 
> person taking my order always calls out my drink as a "tall". With respect 
> to Starbucks, calling a beverage which comes in the shortest cup used in 
> the store a "tall" has a perfectly well defined meaning.  But that doesn't 
> make it any less ridiculous.  Of course, it was mentioned elsewhere in 
> this thread that context is important.  And it is.  To use the Starbucks 
> analogy, for someone to criticize Starbucks because their tall drinks 
> really are actually quite short would be ignoring the significance of the 
> context of Starbucks' abuse of the English language.  But, again, that 
> doesn't make Starbuck's use of the word any less ridiculous.  However, at 
> least at Starbucks, when I use the "wrong" word, they don't start 
> lecturing me.  They know what I mean and simply go ahead and translate it 
> to Starbucks newspeak.

I, as a tall Americano, have always taken ordering the smallest espresso 
beverage possible as something describing the preference of the orderer, as 
opposed to the beverage itself.

-- 
wade ward
"Your boyfriend is not my boyfriend, doll."


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


Re: ACM SIGAPL / APL2007 Conference / Montreal / one week away

2007-10-21 Thread Wade Ward


"Gosi" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On Oct 20, 10:46 pm, rbe <[EMAIL PROTECTED]> wrote:
>> On Oct 15, 5:22 am, Mike Kent <[EMAIL PROTECTED]> wrote:
>>
>> > Conference page
>> > // with links to program details //
>> > (updated Friday 10/12)
>>
>> >http://www.sigapl.org/apl2007.html...
>>
>> At APL2007, I'll be announcing the release of the APEX APL compiler,
>> version 0.0.0, under GPL Version 2.
>> If you can't wait until then, you can download it for Dyalog Linux 
>> atwww.snakeisland.com.
>>
>> Bob
>
> Congratulations on your compiler.
>
> I looked through your pages and came across this
>
> "[This article originally appeared in the ACM SIGAPL Quote Quad, vol.
> 21, no.1, September 1990.]
>
> The APL character set has contributed, more than any other facet of
> the language, to its lack of acceptance in the computing community at
> large. The character set is a metaproblem -- not a problem in and of
> itself, but a creator of other recurring problems of hardware,
> software, ergonomics, and psychology. The adoption of new, ASCII-base
> dialects of APL, such as J, is suggested as one solution to the
> character set problem. "
>
> This is also the reason for why I will not be downloading your new
> compiler until there will be a J version of it, something I hope will
> be coming soon.
>
> I can not use the APL character set at all.
> It is too mixed up with my national characters.
>

witch ones?
-- 
wade ward
[EMAIL PROTECTED]
"Der Katze tritt die Treppe hoch;  Der Kater tritt sie krumm.%
% De Teufel geit um; er bringt de menschen allet dumm."
schau, schau 


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


Re: Jobs: Lisp and Python programmers wanted in the LA area

2007-02-27 Thread Wade Humeniuk
Tech HR wrote:
> In article <[EMAIL PROTECTED]>,
>  [EMAIL PROTECTED] wrote:
> 
>> On Feb 26, 6:32 am, Tech HR <[EMAIL PROTECTED]> wrote:
>>> Our
>>> website is currently a LAMP appication with P=Python. We are looking for
>>> bright motivated people who know or are willing to learn Python and/or
>>> Linux, Apache and MySQL system administration skills. (And if you want
>>> to convince us that we should switch over to Postgres, we're willing to
>>> listen.)
>> This is more out of curiosity, but does it mean that you wouldn't be
>> willing to listen about a switch from Python to Lisp?
> 
> No, it doesn't mean that.  In fact, there is a significant faction in 
> the technical staff (including the CTO) who would like nothing better 
> than to be able to use Lisp instead of Python.

Who is the CTO?

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


Excellent sci-fi novel featuring Python

2007-11-17 Thread Wade Leftwich
I'm about halfway through Charles Stross' excellent new novel,
"Halting State". It's set in Edinburgh in the year 2018, and one of
the main characters is a game programmer whose primary language is
something called "Python 3000".

The cover features blurbs from William Gibson, Vernor Vinge, John
Carnack, and Bruce Scheier.

What, they couldn't pop for an advance copy for Guido?

-- Wade Leftwich
Ithaca, NY



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


Re: Excellent sci-fi novel featuring Python

2007-11-17 Thread Wade Leftwich
On Nov 17, 10:37 am, Wade Leftwich <[EMAIL PROTECTED]> wrote:
> I'm about halfway through Charles Stross' excellent new novel,
> "Halting State". It's set in Edinburgh in the year 2018, and one of
> the main characters is a game programmer whose primary language is
> something called "Python 3000".
>
> The cover features blurbs from William Gibson, Vernor Vinge, John
> Carnack, and Bruce Scheier.
>
> What, they couldn't pop for an advance copy for Guido?
>
> -- Wade Leftwich
> Ithaca, NY

Damn keyboard. The last two endorsers are John Carmack and Bruce
Schneier.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Aggregate funuctions broken in MySQLdb?

2006-05-14 Thread Wade Leftwich
Works fine for me, and I certainly hope MySQLdb is ready for prime
time, because I use the heck out of it. Maybe you're getting fooled by
the fact that cursor.execute() returns the count of result rows. To
actually see the result rows, you have to say cursor.fetchone() or
fetchall() --

In [34]: cur.execute("select article_id from articles limit 10")
Out[34]: 10L

In [35]: cur.fetchall()
Out[35]: ((3L,), (4L,), (5L,), (6L,), (7L,), (8L,), (9L,), (10L,),
(11L,), (12L,))

In [36]: cur.execute("select count(article_id) from articles where
article_id < 13")
Out[36]: 1L

In [37]: cur.fetchall()
Out[37]: ((10L,),)

In [38]: cur.execute("select sum(article_id) from articles where
article_id < 13")
Out[38]: 1L

In [39]: cur.fetchone()
Out[39]: (75.0,)

In [40]: cur.execute("select avg(article_id) from articles where
article_id < 13")
Out[40]: 1L

In [41]: cur.fetchone()
Out[41]: (7.5,)

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


Re: Programming challenge: wildcard exclusion in cartesian products

2006-03-16 Thread Wade Humeniuk
Without much testing.  Common Lisp

Pattern exclusions are made lispy.


(defun all-lists (list length)
   (unless (zerop length)
 (if (= length 1) (mapcar #'list list)
   (loop for elt in list
 nconc
 (mapcar (lambda (rest)
   (cons elt rest))
 (loop for rest on list
   nconc (all-lists rest (1- length

(defun cp-without-wc (source-list &rest patterns)
   (let* ((length (length (first patterns)))
  (all-lists (all-lists source-list length)))
 (dolist (pattern patterns)
   (setf all-lists
 (set-difference all-lists
 (mapcar (lambda (insertion)
   (let ((cp (copy-list pattern)))
 (loop for place on cp
   when (eql :any (car place)) do
   (setf (car place) (pop 
insertion)))
 cp))
 (all-lists source-list (count :any 
pattern)))
 :test #'equal)))
 (remove-duplicates all-lists :test #'equal)))

CL-USER 22 > (cp-without-wc '(a b) '(a :any b) '(b :any a))
((A A A) (A B A) (B A B) (B B B))

CL-USER 23 > (cp-without-wc '(abc xyz) '(abc :any xyz))
((XYZ XYZ XYZ) (XYZ XYZ ABC) (XYZ ABC XYZ) (XYZ ABC ABC) (ABC XYZ ABC) (ABC ABC 
ABC))

CL-USER 24 > (cp-without-wc '(a b) '(a :any :any))
((B B B) (B B A) (B A B) (B A A))

CL-USER 25 > (cp-without-wc '(a b) '(a :any :any) '(b :any :any))
NIL

CL-USER 26 > (cp-without-wc '(a b) '(:any :any b))
((B B A) (B A A) (A B A) (A A A))

CL-USER 27 >

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


Re: Programming challenge: wildcard exclusion in cartesian products

2006-03-16 Thread Wade Humeniuk
[EMAIL PROTECTED] wrote:
> What I have in mind is the efficient,  generation of the
> complement S^n/WC(S^n). A good program should initialize, generate, and
> terminate.
> 
> T=cartprodex(S,n,WC); //initialize
> for all i in T do
>   what you want with i
>   test to see if any more
>   terminate if not
> 
> and it should do this without explicitly generating WC and then
> complementing. For example, if the cardinality of S is m, and the WC is
> just '*a*b*', with a != b, then EX(S^n):=S^n\WC(S^n) has cardinality
> (m-1)^(n-1)*(m+n-1). Specifically, if m=5 and n=10, then |EX|=3670016
> while |S^10|=9765625, so that |EX|/|S^10| is about 0.3758. In general
> the program should directly generate EX from arbitrary WC. Of course,
> in practice the WC should themselves occur in a logically consistent
> manner, but let's just assume they're a given.
> 

Another attempt.  I have made no special attempt to create an
exclusion language, just used an anonymous lambda predicate.


;; Wade Humeniuk

(defclass odometer ()
   ((base :initform 0 :accessor base)
(meter :initform nil :accessor meter)
(n-digits :initarg :n-digits :accessor n-digits)
(digit-set :initarg :digit-set :accessor digit-set)))

(defmethod initialize-instance :after ((obj odometer) &rest initargs)
   (setf (base obj) (length (digit-set obj))
 (meter obj) (make-array (n-digits obj) :initial-element 0)
 (digit-set obj) (coerce (digit-set obj) 'vector)))

(defun inc-odometer (odometer)
   (loop with carry = 1
 for i from (1- (n-digits odometer)) downto 0
 for digit = (incf (aref (meter odometer) i) carry)
 if (= digit (base odometer)) do
   (setf (aref (meter odometer) i) 0)
   (setf carry 1)
 else do
   (setf carry 0)
 while (not (zerop carry

(defun zero-meter-p (odometer)
   (every #'zerop (meter odometer)))

(defmethod next-set ((obj odometer))
   (prog1 (map 'list (lambda (digit)
   (aref (digit-set obj) digit))
   (meter obj))
 (inc-odometer obj)))

(defclass cs-with-wc (odometer)
   ((exclusion :initarg :exclusion :accessor exclusion)
(at-end :initform nil :accessor at-end)))

(defmethod next-set ((obj odometer))
   (tagbody
:next
(unless (at-end obj)
  (let ((set (call-next-method)))
(when (zero-meter-p obj) (setf (at-end obj) t))
(if (not (funcall (exclusion obj) set))
(return-from next-set set)
  (go :next))

(defun print-all-cs (set length exclusion)
   (let ((cs-with-wc (make-instance 'cs-with-wc :n-digits length :digit-set set
:exclusion exclusion)))
 (loop for set = (next-set cs-with-wc)
   while set do (print set

CL-USER 134 > (cs-with-wc '(a b) 3 (lambda (set)
  (destructuring-bind (x y z)
  set
(or (and (eql x 'a) (eql z 'b))
(and (eql x 'b) (eql z 'a))

(A A A)
(A B A)
(B A B)
(B B B)
NIL

CL-USER 135 > (cs-with-wc '(a b) 3 (lambda (set)
  (eql (second set) 'a)))

(A B A)
(A B B)
(B B A)
(B B B)
NIL

CL-USER 136 > (cs-with-wc '(abc xyz) 3 (lambda (set)
  (and (eql (first set) 'abc)
   (eql (third set) 'xyz

(ABC ABC ABC)
(ABC XYZ ABC)
(XYZ ABC ABC)
(XYZ ABC XYZ)
(XYZ XYZ ABC)
(XYZ XYZ XYZ)
NIL
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Programming challenge: wildcard exclusion in cartesian products

2006-03-16 Thread Wade Humeniuk
Oops, problems cutting an pasting, should be,

;; Wade Humeniuk

(defclass odometer ()
   ((base :initform 0 :accessor base)
(meter :initform nil :accessor meter)
(n-digits :initarg :n-digits :accessor n-digits)
(digit-set :initarg :digit-set :accessor digit-set)))

(defmethod initialize-instance :after ((obj odometer) &rest initargs)
   (setf (base obj) (length (digit-set obj))
 (meter obj) (make-array (n-digits obj) :initial-element 0)
 (digit-set obj) (coerce (digit-set obj) 'vector)))

(defun inc-odometer (odometer)
   (loop with carry = 1
 for i from (1- (n-digits odometer)) downto 0
 for digit = (incf (aref (meter odometer) i) carry)
 if (= digit (base odometer)) do
   (setf (aref (meter odometer) i) 0)
   (setf carry 1)
 else do
   (setf carry 0)
 while (not (zerop carry

(defun zero-meter-p (odometer)
   (every #'zerop (meter odometer)))

(defmethod next-set ((obj odometer))
   (prog1 (map 'list (lambda (digit)
   (aref (digit-set obj) digit))
   (meter obj))
 (inc-odometer obj)))

(defclass cs-with-wc (odometer)
   ((exclusion :initarg :exclusion :accessor exclusion)
(at-end :initform nil :accessor at-end)))

(defmethod next-set ((obj cs-with-wc))
   (tagbody
:next
(unless (at-end obj)
  (let ((set (call-next-method)))
(when (zero-meter-p obj) (setf (at-end obj) t))
(if (not (funcall (exclusion obj) set))
(return-from next-set set)
  (go :next))

(defun print-all-cs (set length exclusion)
   (let ((cs-with-wc (make-instance 'cs-with-wc :n-digits length :digit-set set
:exclusion exclusion)))
 (loop for set = (next-set cs-with-wc)
   while set do (print set

CL-USER 7 > (print-all-cs '(a b) 3 (lambda (set)
  (destructuring-bind (x y z)
  set
(or (and (eql x 'a) (eql z 'b))
(and (eql x 'b) (eql z 'a))

(A A A)
(A B A)
(B A B)
(B B B)
NIL

CL-USER 8 > (print-all-cs '(abc xyz) 3 (lambda (set)
  (and (eql (first set) 'abc)
   (eql (third set) 'xyz

(ABC ABC ABC)
(ABC XYZ ABC)
(XYZ ABC ABC)
(XYZ ABC XYZ)
(XYZ XYZ ABC)
(XYZ XYZ XYZ)
NIL

CL-USER 9 >
-- 
http://mail.python.org/mailman/listinfo/python-list


portable python

2017-04-28 Thread allen wade
is there a way to install python on a thumb drive that does not require an
administrator's password?  I have to use public computers and store all my
applications to the thumb drive, using the Portable Apps Platform to manage
the applications.
-- 
https://mail.python.org/mailman/listinfo/python-list


test_imaplib fail when installing python3.6.1 on centos6.9

2017-04-30 Thread Wade Wang
Hello, everyone. I'm trying to install Python 3.6.1 on my CentOS 6.9
server, but test_imaplib always fails its test when make test. Here is what
I got:

> ==
> ERROR: test_logincapa_with_client_certfile (test.test_imaplib.RemoteIMAP_
SSLTest)
> --
> Traceback (most recent call last):
>   File "/root/Python-3.6.1/Lib/test/test_imaplib.py", line 973, in
test_logincapa_with_client_certfile
> certfile=CERTFILE)
>   File "/root/Python-3.6.1/Lib/imaplib.py", line 1280, in __init__
> IMAP4.__init__(self, host, port)
>   File "/root/Python-3.6.1/Lib/imaplib.py", line 197, in __init__
> self.open(host, port)
>   File "/root/Python-3.6.1/Lib/imaplib.py", line 1293, in open
> IMAP4.open(self, host, port)
>   File "/root/Python-3.6.1/Lib/imaplib.py", line 294, in open
> self.sock = self._create_socket()
>   File "/root/Python-3.6.1/Lib/imaplib.py", line 1285, in _create_socket
> server_hostname=self.host)
>   File "/root/Python-3.6.1/Lib/ssl.py", line 401, in wrap_socket
> _context=self, _session=session)
>   File "/root/Python-3.6.1/Lib/ssl.py", line 808, in __init__
> self.do_handshake()
>   File "/root/Python-3.6.1/Lib/ssl.py", line 1061, in do_handshake
> self._sslobj.do_handshake()
>   File "/root/Python-3.6.1/Lib/ssl.py", line 683, in do_handshake
> self._sslobj.do_handshake()
> ssl.SSLError: [SSL: TLSV1_ALERT_UNKNOWN_CA] tlsv1 alert unknown ca
(_ssl.c:749)
>
> ==
> ERROR: test_logincapa_with_client_ssl_context
(test.test_imaplib.RemoteIMAP_SSLTest)
> --
> Traceback (most recent call last):
>   File "/root/Python-3.6.1/Lib/test/test_imaplib.py", line 979, in
> test_logincapa_with_client_ssl_context
> self.host, self.port, ssl_context=self.create_ssl_context())
>   File "/root/Python-3.6.1/Lib/imaplib.py", line 1280, in __init__
> IMAP4.__init__(self, host, port)
>   File "/root/Python-3.6.1/Lib/imaplib.py", line 197, in __init__
> self.open(host, port)
>   File "/root/Python-3.6.1/Lib/imaplib.py", line 1293, in open
> IMAP4.open(self, host, port)
>   File "/root/Python-3.6.1/Lib/imaplib.py", line 294, in open
> self.sock = self._create_socket()
>   File "/root/Python-3.6.1/Lib/imaplib.py", line 1285, in _create_socket
> server_hostname=self.host)
>   File "/root/Python-3.6.1/Lib/ssl.py", line 401, in wrap_socket
> _context=self, _session=session)
>   File "/root/Python-3.6.1/Lib/ssl.py", line 808, in __init__
> self.do_handshake()
>   File "/root/Python-3.6.1/Lib/ssl.py", line 1061, in do_handshake
> self._sslobj.do_handshake()
>   File "/root/Python-3.6.1/Lib/ssl.py", line 683, in do_handshake
> self._sslobj.do_handshake()
> ssl.SSLError: [SSL: TLSV1_ALERT_UNKNOWN_CA] tlsv1 alert unknown ca
(_ssl.c:749)
>
> --
> Ran 95 tests in 27.005s
>
> FAILED (errors=2)
> 1 test failed again:
> test_imaplib
>
> Total duration: 6 min 34 sec
> Tests result: FAILURE
> make: *** [test] Error 1

Any solution or suggestion?
-- 
https://mail.python.org/mailman/listinfo/python-list