Re: Efficiently Split A List of Tuples

2005-07-17 Thread Ron Adam
Raymond Hettinger wrote:
>>Variant of Paul's example:
>>
>>a = ((1,2), (3, 4), (5, 6), (7, 8), (9, 10))
>>zip(*a)
>>
>>or
>>
>>[list(t) for t in zip(*a)] if you need lists instead of tuples.
> 
> 
> 
> [Peter Hansen]
> 
>>(I believe this is something Guido considers an "abuse of *args", but I
>>just consider it an elegant use of zip() considering how the language
>>defines *args.  YMMV]
> 
> 
> It is somewhat elegant in terms of expressiveness; however, it is also
> a bit disconcerting in light of the underlying implementation.
> 
> All of the tuples are loaded one-by-one onto the argument stack.  For a
> few elements, this is no big deal.  For large datasets, it is a less
> than ideal way of transposing data.
> 
> Guido's reaction makes sense when you consider that most programmers
> would cringe at a function definition with thousands of parameters.
> There is a sense that this doesn't scale-up very well (with each Python
> implementation having its own limits on how far you can push this
> idiom).
> 
>  
> Raymond


Currently we can implicitly unpack a tuple or list by using an 
assignment.  How is that any different than passing arguments to a 
function?  Does it use a different mechanism?



(Warning, going into what-if land.)

There's a question relating to the above also so it's not completely in 
outer space.  :-)


We can't use the * syntax anywhere but in function definitions and 
calls.  I was thinking the other day that using * in function calls is 
kind of inconsistent as it's not used anywhere else to unpack tuples. 
And it does the opposite of what it means in the function definitions.

So I was thinking, In order to have explicit packing and unpacking 
outside of function calls and function definitions, we would need 
different symbols because using * in other places would conflict with 
the multiply and exponent operators.  Also pack and unpack should not be 
the same symbols for obvious reasons.  Using different symbols doesn't 
conflict with * and ** in functions calls as well.

So for the following examples, I'll use '~' as pack and '^' as unpack.

~ looks like a small 'N', for put stuff 'in'.
^ looks like an up arrow, as in take stuff out.

(Yes, I know they are already used else where.  Currently those are 
binary operators.  The '^' is used with sets also. I did say this is a 
"what-if" scenario.  Personally I think the binary operator could be 
made methods of a bit type, then they ,including the '>>' '<<' pair, 
could be freed up and put to better use.  The '<<' would make a nice 
symbol for getting values from an iterator. The '>>' is already used in 
print as redirect.)


Simple explicit unpacking would be:

(This is a silly example, I know it's not needed here but it's just to 
show the basic pattern.)

x = (1,2,3)
a,b,c = ^x # explicit unpack,  take stuff out of x


So, then you could do the following.

zip(^a)# unpack 'a' and give it's items to zip.

Would that use the same underlying mechanism as using "*a" does?  Is it 
also the same implicit unpacking method used in an assignment using 
'='?.  Would it be any less "a bit disconcerting in light of the 
underlying implementation"?



Other possible ways to use them outside of function calls:

Sequential unpacking..

x = [(1,2,3)]
a,b,c = ^^x->  a=1, b=2, c=3

Or..

x = [(1,2,3),4]
a,b,c,d = ^x[0],x[1]   -> a=1, b=2, c=3, d=4

I'm not sure what it should do if you try to unpack an item not in a 
container.  I expect it should give an error because a tuple or list was 
expected.

a = 1
x = ^a# error!


Explicit packing would not be as useful as we can put ()'s or []'s 
around things.  One example that come to mind at the moment is using it 
to create single item tuples.

 x = ~1->   (1,)

Possible converting strings to tuples?

 a = 'abcd'
 b = ~^a   ->   ('a','b','c','d') # explicit unpack and repack

and:

 b = ~a->   ('abcd',)   # explicit pack whole string

for:

 b = a,->   ('abcd',)   # trailing comma is needed here.
# This is an error opportunity IMO


Choice of symbols aside, packing and unpacking are a very big part of 
Python, it just seems (to me) like having an explicit way to express it 
might be a good thing.

It doesn't do anything that can't already be done, of course.  I think 
it might make some code easier to read, and possibly avoid some errors.

Would there be any (other) advantages to it beside the syntax sugar?

Is it a horrible idea for some unknown reason I'm not seeing.  (Other 
than the symbol choices breaking current code.  Maybe other symbols 
would work just as well?)

Regards,
Ron

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


Re: list implementation

2005-07-17 Thread Raymond Hettinger
[sj]
> I believe the type "list" is implemented as an array of pointers.

Yes.


> Thus, random access is an O(1) operation while insertion/deletion is an
> O(n) operation.

Yes.


> 2. Implementing list as an array is part of language specification or
> implementation-dependent?

Implementation dependent but likely to be an array of pointers.


> 3. What if I actually need a doubly-linked list for constant-time
> insertion/deletion?  Is there a built-in type or a standard class?

Yes.  Use collections.deque().

  http://docs.python.org/tut/node13.html#SECTION001370
  http://docs.python.org/lib/module-collections.html


Raymond

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


Re: Ordering Products

2005-07-17 Thread Kay Schluehr


Ron Adam wrote:
> Kay Schluehr wrote:
> > Here might be an interesting puzzle for people who like sorting
> > algorithms ( and no I'm not a student anymore and the problem is not a
> > students 'homework' but a particular question associated with a
> > computer algebra system in Python I'm currently developing in my
> > sparetime ).
>
> 
>
> x = 7*a*b*a*9
> x.factors.sort()
> x
> >
> > a*a*b*7*9
> >
> > -> (a**2)*b*63
> >
> > Now lets drop the assumption that a and b commute. More general: let be
> > M a set of expressions and X a subset of M where each element of X
> > commutes with each element of M: how can a product with factors in M be
> > evaluated/simplified under the condition of additional information X?
> >
> > It would be interesting to examine some sorting algorithms on factor
> > lists with constrained item transpositions. Any suggestions?
> >
> > Regards,
> > Kay
>
> Looks interesting Kay.

I think so too :) And grouping by sorting may be interesting also for
people who are not dealing with algebraic structures.

> I think while the built in sort works as a convenience, you will need to
> write your own more specialized methods, both an ordering (parser-sort),
> and simplify method, and call them alternately until no further changes
> are made.  (You might be able to combine them in the sort process as an
> optimization.)
>
> A constrained sort would be a combination of splitting (parsing) the
> list into sortable sub lists and sorting each sub list, possibly in a
> different manner, then reassembling it back.  And doing that possibly
> recursively till no further improvements are made or can be made.

I think a comparison function which is passed into Pythons builtin
sort() should be sufficient to solve the problem. I guess the
comparison defines a total order on the set of elements defined by the
list to sort.

> On a more general note, I think a constrained sort algorithm is a good
> idea and may have more general uses as well.
>
> Something I was thinking of is a sort where instead of giving a
> function, you give it a sort key list.  Then you can possibly sort
> anything in any arbitrary order depending on the key list.
>
> sort(alist, [0,1,2,3,4,5,6,7,8,9])   # Sort numbers forward
> sort(alist, [9,8,7,6,5,4,3,2,1,0])   # Reverse sort
> sort(alist, [1,3,5,7,9,0,2,4,6,8])   # Odd-Even sort
> sort(alist, [int,str,float]) # sort types

Seems like you want to establish a total order of elements statically.
Don't believe that this is necessary.

> These are just suggestions, I haven't worked out the details.  It could
> probably be done currently with pythons built in sort by writing a
> custom compare function that takes a key list.

Exactly.

> How fine grained the key
> list is is also something that would need to be worked out.  Could it
> handle words and whole numbers instead of letters and digits?  How does
> one specify which?  What about complex objects?

In order to handle complex objects one needs more algebra ;)

Since the class M only provides one operation I made the problem as
simple as possible ( complex expressions do not exist in M because
__mul__ is associative  - this is already a reduction rule ).

Kay

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


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

2005-07-17 Thread Nathan Pinno
  I use input() all the time. I know many people say it ain't safe, but 
whose going to use it to crash their own comp? Only an insane person would, 
or a criminal trying to cover his/her tracks.

  Sorry if I waded into the debate, but this debate originated from one of 
my posts.

  Nathan Pinno
  - Original Message - 
  From: "Stephen Thorne" <[EMAIL PROTECTED]>
  To: <[EMAIL PROTECTED]>
  Cc: 
  Sent: Sunday, July 17, 2005 11:12 PM
  Subject: Re: Who uses input()? [was Re: question on "input"]


  > On 15/07/05, Terry Hancock <[EMAIL PROTECTED]> wrote:
  >> 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).
  >
  > I don't see as "break input() using code" -> "not until py3k" as a
  > logical cause/effect. No one should be using input() anyway, the only
  > place it's at-all appropriate is in a python tutorial, with the 'guess
  > the number' game.
  >
  > -- 
  > Stephen Thorne
  > Development Engineer
  > -- 
  > http://mail.python.org/mailman/listinfo/python-list
  >
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Ordering Products

2005-07-17 Thread Kay Schluehr
Diez B.Roggisch wrote:
> Kay Schluehr  gmx.net> writes:
>
> > Now lets drop the assumption that a and b commute. More general: let be
> > M a set of expressions and X a subset of M where each element of X
> > commutes with each element of M: how can a product with factors in M be
> > evaluated/simplified under the condition of additional information X?
> >
> > It would be interesting to examine some sorting algorithms on factor
> > lists with constrained item transpositions. Any suggestions?
>
> I don't think that sorting is the answer here.
> Firts of all IMHO you have to add an
> additional constraint -  associativity of the operation in question
>  So the problem could  be reduced to making the constant
> parts be more associative than the non-constant parts.
> which you should be able to
> do with a parser.

Hi Diez,

I have to admit that I don't understand what you mean with the
'constant parts' of an expression?

The associativity of __mul__ is trivially fullfilled for the dummy
class M if an additional __eq__ method is defined by comparing factor
lists because those lists are always flat:

def __eq__(self, other):
if isinstance(other,M):
return self.factors == other.factors
return False

The sorting ( or better 'grouping' which can be represented by sorting
in a special way ) of factors in question is really a matter of
(non-)commutativity. For more advanced expressions also group
properties are important:

If a,b are in a center of a group G ( i.e. they commute with any
element of G ) and G supplies an __add__ ( besides a __mul__ and is
therefore a ring ) also a+b is in the center of G and (a+b)*c = c*(a+b)
holds for any c in G.

It would be nice ( and much more efficient ) not to force expansion of
the product assuming distributivity of __add__ and __mul__ and
factorization after the transposition of the single factors but
recognizing immediately that a+b is in the center of G because the
center is a subgroup of G.


Regards,
Kay

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


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

2005-07-17 Thread Stephen Thorne
On 15/07/05, Terry Hancock <[EMAIL PROTECTED]> wrote:
> 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).

I don't see as "break input() using code" -> "not until py3k" as a
logical cause/effect. No one should be using input() anyway, the only
place it's at-all appropriate is in a python tutorial, with the 'guess
the number' game.

-- 
Stephen Thorne
Development Engineer
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: list implementation

2005-07-17 Thread Terry Reedy

"sj" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>I believe the type "list" is implemented as an array of pointers.

A Python list is sematically/behaviorally defined as a mutable extensible 
sequence of references to Python objects.  For the CPython reference 
implementation, the references are arrays of C pointers.  Since, on 
balance, this works well, I presume the other four active computer language 
implementations do something equivalent.  (How we humans execute Python 
code is a different question!)

> Thus, random access is an O(1) operation

Yes

> while insertion/deletion is an  O(n) operation.

At the front, yes.  (But modern CPUs with a one-instruction block mem move 
make the hidden multiplier relatively small.)  At the end of the list, no; 
it is O(1).  Making front insertion/deletion (but not in the middle) also 
O(1) has been considered but so far rejected.  (For apps that need the 
symmetry, there is collections.deque.)

 > 2. Implementing list as an array is part of language specification or
> implementation-dependent?

While I believe I have answered this, I recommend reading the relevant 
parts of the language and library manuals (see chapter 2 of the latter).

> 3. What if I actually need a doubly-linked list for constant-time
> insertion/deletion?  Is there a built-in type or a standard class?

I believe it is roll-your-own to your specific needs.  Of course, scanning 
thru such a list is still O(n).

Terry J. Reedy



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


list implementation

2005-07-17 Thread sj
I believe the type "list" is implemented as an array of pointers.
Thus, random access is an O(1) operation while insertion/deletion is an
O(n) operation.  That said, I have the following questions:

1. Am I correct in saying the above?

2. Implementing list as an array is part of language specification or
implementation-dependent?

3. What if I actually need a doubly-linked list for constant-time
insertion/deletion?  Is there a built-in type or a standard class?

Thanks.

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


list implementation

2005-07-17 Thread sj
I believe the type "list" is implemented as an array of pointers.
Thus, random access is an O(1) operation while insertion/deletion is an
O(n) operation.  That said, I have the following questions:

1. Am I correct in saying the above?

2. Implementing list as an array is part of language specification or
implementation-dependent?

3. What if I actually need a doubly-linked list for constant-time
insertion/deletion?  Is there a built-in type or a standard class?

Thanks.

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


Re: Parsing html :: output to comma delimited

2005-07-17 Thread samuels
Thanks for the replies,  I'll post here when/if I get it finally
working.

So, now I know how to extract the links for the big page, and extract
the text from the individual page.  Really what I need to find out is
how run the script on each individual page automatically, and get the
output in comma delimited format.  Thanks for solving the two problems
though :)

-Sam

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


Re: Efficiently Split A List of Tuples

2005-07-17 Thread Raymond Hettinger
[Richard]
> I know I can use a 'for' loop and create two new lists
> using 'newList1.append(x)', etc.  Is there an efficient way
> to create these two new lists without using a slow for loop?

If trying to optimize before writing and timing code, then at least
validate your assumptions.  In Python, for-loops are blazingly fast.
They are almost never the bottleneck.  Python is not Matlab --
"vectorizing" for-loops only pays-off when a high-speed functional
happens to exactly match you needs (in this case, zip() happens to be a
good fit).

Even when a functional offers a speed-up, much of the gain is likely
due to implementation specific optimizations which allocate result
lists all at once rather than building them one at time.

Also, for all but the most simple inner-loop operations, the for-loop
overhead almost always dominated by the time to execute the operation
itself.

Executive summary:  Python's for-loops are both elegant and fast.  It
is a mistake to habitually avoid them.



Raymond

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


Re: What is your favorite Python web framework?

2005-07-17 Thread Philippe C. Martin

http://cheetahtemplate.org/



Admin wrote:

> On Sun, 17 Jul 2005 19:15:49 -0300, Sybren Stuvel
> <[EMAIL PROTECTED]> wrote:
> 
>> http://www.unrealtower.org/mycheetah
> 
> "Error 404 while looking up your page AND when looking for a suitable 404
> page. Sorry!
> No such file /var/www/www.unrealtower.org/compiled/error404.py"
> 
> I can't express myself on Cheetah, sorry!!
> 

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


Re: Efficiently Split A List of Tuples

2005-07-17 Thread Raymond Hettinger
> Variant of Paul's example:
>
> a = ((1,2), (3, 4), (5, 6), (7, 8), (9, 10))
> zip(*a)
>
> or
>
> [list(t) for t in zip(*a)] if you need lists instead of tuples.


[Peter Hansen]
> (I believe this is something Guido considers an "abuse of *args", but I
> just consider it an elegant use of zip() considering how the language
> defines *args.  YMMV]

It is somewhat elegant in terms of expressiveness; however, it is also
a bit disconcerting in light of the underlying implementation.

All of the tuples are loaded one-by-one onto the argument stack.  For a
few elements, this is no big deal.  For large datasets, it is a less
than ideal way of transposing data.

Guido's reaction makes sense when you consider that most programmers
would cringe at a function definition with thousands of parameters.
There is a sense that this doesn't scale-up very well (with each Python
implementation having its own limits on how far you can push this
idiom).



Raymond

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


stdin/stdout fileno() always returning -1 from windows service

2005-07-17 Thread chuck
I have found that sys.stdin.fileno() and sys.stdout.fileno() always
return -1 when executed from within a win32 service written using the
win32 extensions for Python.

Anyone have experience with this or know why?

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


Re: Filtering out non-readable characters

2005-07-17 Thread Raymond Hettinger
[George Sakkis]
> It's only obvious in the sense that _after_ you see this idiom, you can go 
> back to the docs and
> realize it's not doing something special; OTOH if you haven't seen it, it's 
> not at all the obvious
> solution to "how do I get the first 256 characters". So IMO it should be 
> mentioned, given that
> string.translate often operates on the identity table. I think a single 
> sentence is adequate for the
> reference docs.

For Py2.5, I've accepted a feature request to allow string.translate's
first argument to be None and then run as if an identity string had
been provided.


Raymond Hettinger

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


Re: Ordering Products

2005-07-17 Thread Diez B.Roggisch
Kay Schluehr  gmx.net> writes:

> Now lets drop the assumption that a and b commute. More general: let be
> M a set of expressions and X a subset of M where each element of X
> commutes with each element of M: how can a product with factors in M be
> evaluated/simplified under the condition of additional information X?
> 
> It would be interesting to examine some sorting algorithms on factor
> lists with constrained item transpositions. Any suggestions?

I don't think that sorting is the answer here. 
Firts of all IMHO you have to add an 
additional constraint -  associativity of the operation in question
 So the problem could  be reduced to making the constant 
parts be more associative than the non-constant parts.
which you should be able to 
do with a parser.  The BNF grammar could look like this:

expr ::= v_expr "*" v_expr | v_expr
v_expr ::= variable | c_expr
c_expr ::= l_expr "*" literal | l_expr
l_expr ::= literal | "(" expr ")"

The trick is to create a stronger-binding multiplication operator on constants
 than on mixed 
expressions. 

This grammar is ambigue of course - so a LL(k) or maybe even LALR won't work. 
But earley's method 
implemented in spark should do the trick. 
If I find the time, I'll write an short implementation 
tomorrow.

Diez

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


Re: What is your favorite Python web framework?

2005-07-17 Thread Luis M. Gonzalez
I really like Karrigell ( http://karrigell.sourceforge.net ).
It is, IMHO, the most pythonic framework because all you need to know
is the python language.
You don't need to learn any template or special language, you only use
plain and regular python.
It also gives you a lot of freedom when choosing a programming style:
you can code python inside html (just like in PHP or ASP) or you can
code html within python.

It also lets you map databases to objects and you can use the included
database Gadfly or any other that has a python api.
The downside: it currectly works with its built-in server, and although
you can use it alongside Apache or Xitami, there's still no way to do
it with mod_python, and as far as I know, there's no hosting providers
with Karrigell instaled.
It is being used mainly by people who run their websites from their own
computers.

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


Re: Python Programming Contest

2005-07-17 Thread John Machin
John Hazen wrote:
> * Brian Quinlan <[EMAIL PROTECTED]> [2005-07-15 02:08]:
> 
>>You can find the first problem here:
>>http://www.sweetapp.com/pycontest/contest1
> 
> 
> I have one question about the problem.  Is the cost we are to minimize
> the cost of arriving in the target city at all, or the cost of arriving
> at the target city at the end of the final day of the schedule?
> 
> (If you were traveling to a conference, for example, you'd have a
> specific arrival time, and a cost to stay in the destination city until
> that time.  But, if you were going to sight-see, then you could arrive
> at any time, and begin your itinerary upon arrival.)
> 
> Say I can find a combination of flights that gets me to the target at
> the end of day 3 for 390 units, and a combination that gets me there at
> the end of day 4 for 400.  If you count the hostel cost from day 3 to
> day 4, the first combination costs 410.  So, which is preferred?
> 
> -John
> 
> P.S.  I just realized this may be answered be the test suite, but I'm
> still at the thinking stage.

What we really need is a problem *specification* contest.



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


Re: What is your favorite Python web framework?

2005-07-17 Thread Admin
On Sun, 17 Jul 2005 19:15:49 -0300, Sybren Stuvel  
<[EMAIL PROTECTED]> wrote:

> http://www.unrealtower.org/mycheetah

"Error 404 while looking up your page AND when looking for a suitable 
404  
page. Sorry!
No such file /var/www/www.unrealtower.org/compiled/error404.py"

I can't express myself on Cheetah, sorry!!

-- 
Thanks,

Admin.
Want to buy me a book? http://tinyurl.com/78xzb :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is your favorite Python web framework?

2005-07-17 Thread Sybren Stuvel
Admin enlightened us with:
> But I'd like to know your opinion on what you think is best. The
> Python  framework I'll use will be to build an e-commerce
> application looking like  Amazon.com

I'm greatly in favour of Cheetah. Also see
http://www.unrealtower.org/mycheetah. I need to put up way more
documentation & examples, but the basics are there.

Let me know what you think!

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


What is your favorite Python web framework?

2005-07-17 Thread Admin
I am doing some research for a Python framework to build web applications.
I have discarted Zope because from what I've read, the learning curve is  
too steep, and it takes more time to build applications in general with  
Zope.
I have kept the following:

  - PyWork - http://pywork.sourceforge.net (Not sure if it's mature)
  - Django - http://www.djangoproject.com (Looks interesting)
  - CherryPy - http://www.cherrypy.org (Unsure)

I have also found a more comprehensive list here:  
http://wiki.python.org/moin/WebProgramming
But I'd like to know your opinion on what you think is best. The Python  
framework I'll use will be to build an e-commerce application looking like  
Amazon.com
I favor speed of development, intensive OO development, performance under  
heavy load, short learning curve, good documentation and community.

-- 
Thanks,

Admin.
Want to buy me a book? http://tinyurl.com/78xzb :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Filtering out non-readable characters

2005-07-17 Thread Steven Bethard
Bengt Richter wrote:
> Thanks for the nudge. Actually, I know about generator expressions, but
> at some point I must have misinterpreted some bug in my code to mean
> that join in particular didn't like generator expression arguments,
> and wanted lists.

I suspect this is bug 905389 [1]:

 >>> def gen():
... yield 1
... raise TypeError('from gen()')
...
 >>> ''.join([x for x in gen()])
Traceback (most recent call last):
   File "", line 1, in ?
   File "", line 3, in gen
TypeError: from gen()
 >>> ''.join(x for x in gen())
Traceback (most recent call last):
   File "", line 1, in ?
TypeError: sequence expected, generator found

I run into this every month or so, and have to remind myself that it 
means that my generator is raising a TypeError, not that join doesn't 
accept generator expressions...

STeVe

[1] http://www.python.org/sf/905389
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Programming Contest

2005-07-17 Thread John Hazen
* Brian Quinlan <[EMAIL PROTECTED]> [2005-07-15 02:08]:
> 
> You can find the first problem here:
> http://www.sweetapp.com/pycontest/contest1

I have one question about the problem.  Is the cost we are to minimize
the cost of arriving in the target city at all, or the cost of arriving
at the target city at the end of the final day of the schedule?

(If you were traveling to a conference, for example, you'd have a
specific arrival time, and a cost to stay in the destination city until
that time.  But, if you were going to sight-see, then you could arrive
at any time, and begin your itinerary upon arrival.)

Say I can find a combination of flights that gets me to the target at
the end of day 3 for 390 units, and a combination that gets me there at
the end of day 4 for 400.  If you count the hostel cost from day 3 to
day 4, the first combination costs 410.  So, which is preferred?

-John

P.S.  I just realized this may be answered be the test suite, but I'm
still at the thinking stage.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Ordering Products

2005-07-17 Thread Ron Adam
Kay Schluehr wrote:
> Here might be an interesting puzzle for people who like sorting
> algorithms ( and no I'm not a student anymore and the problem is not a
> students 'homework' but a particular question associated with a
> computer algebra system in Python I'm currently developing in my
> sparetime ).



x = 7*a*b*a*9
x.factors.sort()
x
> 
> a*a*b*7*9
> 
> -> (a**2)*b*63
> 
> Now lets drop the assumption that a and b commute. More general: let be
> M a set of expressions and X a subset of M where each element of X
> commutes with each element of M: how can a product with factors in M be
> evaluated/simplified under the condition of additional information X?
> 
> It would be interesting to examine some sorting algorithms on factor
> lists with constrained item transpositions. Any suggestions?
> 
> Regards,
> Kay

Looks interesting Kay.

I think while the built in sort works as a convenience, you will need to 
write your own more specialized methods, both an ordering (parser-sort), 
and simplify method, and call them alternately until no further changes 
are made.  (You might be able to combine them in the sort process as an 
optimization.)

A constrained sort would be a combination of splitting (parsing) the 
list into sortable sub lists and sorting each sub list, possibly in a 
different manner, then reassembling it back.  And doing that possibly 
recursively till no further improvements are made or can be made.


On a more general note, I think a constrained sort algorithm is a good 
idea and may have more general uses as well.

Something I was thinking of is a sort where instead of giving a 
function, you give it a sort key list.  Then you can possibly sort 
anything in any arbitrary order depending on the key list.

sort(alist, [0,1,2,3,4,5,6,7,8,9])   # Sort numbers forward
sort(alist, [9,8,7,6,5,4,3,2,1,0])   # Reverse sort
sort(alist, [1,3,5,7,9,0,2,4,6,8])   # Odd-Even sort
sort(alist, [int,str,float]) # sort types

These are just suggestions, I haven't worked out the details.  It could 
probably be done currently with pythons built in sort by writing a 
custom compare function that takes a key list.  How fine grained the key 
list is is also something that would need to be worked out.  Could it 
handle words and whole numbers instead of letters and digits?  How does 
one specify which?  What about complex objects?


Here's a "quick sort" function that you might be able to play with.. 
There are shorter versions of this, but this has a few optimizations added.

Overall it's about 10 times slower than pythons built in sort for large 
lists, but that's better than expected considering it's written in 
python and not C.

Cheers,
Ron



# Quick Sort
def qsort(x):
 if len(x)<2:
 return x# Nothing to sort.

 # Is it already sorted?
 j = min = max = x[0]
 for i in x:
 # Get min and max while checking it.
 if imax: max=i
 if imid:
 gt.append(i)
 continue
 eq.append(i)

 # Recursively divide the lists then reassemble it
 # in order as the values are returned.
 return q(lt)+eq+q(gt)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SSL problem... SSL23_GET_SERVER_HELLO:unknown protocol

2005-07-17 Thread John Reese
On Sun, 17 Jul 2005 11:05:06 +0100, Stephen Illingworth <[EMAIL PROTECTED]> 
wrote:
> John Reese wrote:
>> Morning.  I've been running into an error message pertaining to SSL
>> that I don't understand, and I was hoping someone had some insight.
>> Gmail provides POP access over SSL on port 587, so I tried to use
>> poplib.POP_SSL, with the following results:
>
> GMail uses port 995.

Yeah.  I misread the instructions.  I apologize for being an idiot.
It works just fine on port 995.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I just wanna know about os.path module..

2005-07-17 Thread kimes
Thanks for all you  guys help..

But Peter,
You said 'At first os - module, or package, it doesn't matter here - is
imported.'

I'm still confused about that..
When I just call import os.path without calling import os..
In that case, you mean 'import os' is called implicitly?
Why? and How?

how python knows it should call import when we call import os?
Please make me clear.. :)
Thanks..

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


Re: ConfigParser : overwrite ?

2005-07-17 Thread cantabile
Robert Kern a écrit :
> cantabile wrote:
> 
>> Hi, I'm trying and updating an .ini file with ConfigParser but each time
>> I call 'write', it appends the whole options another time to the file.
>> For example :
>> Here's the inital ini file
>>
>> [section1]
>> foodir: %(dir)s/whatever
>> dir: foo
>>
>> Here's my code :
>> filename = ...
>> config = ConfigParser.ConfigParser()
>> config.read(filename)
>> config.set('section1', 'dir', 'anotherdir')
>> f = open(filename, 'r+')
>> config.write(f)
>> f.close()
>>
>> Then I get :
>>
>> [section1]
>> foodir: %(dir)s/whatever
>> dir: anotherdir
>>
>> [section1]
>> foodir: %(dir)s/whatever
>> dir: foo
>>
>> I tried also with 'w', 'w+', 'a' ...
> 
> 
> Are you sure you tried it with 'w' as the mode?
> 
> In [1]: !cat foo.ini
> [section1]
> foodir: %(dir)s/whatever
> dir: foo
> In [2]: fn = 'foo.ini'
> 
> In [3]: import ConfigParser
> 
> In [4]: cfg = ConfigParser.ConfigParser()
> 
> In [5]: cfg.read(fn)
> Out[5]: ['foo.ini']
> 
> In [6]: cfg.set('section1', 'dir', 'anotherdir')
> 
> In [7]: f = open(fn, 'w')
> 
> In [8]: cfg.write(f)
> 
> In [9]: f.close()
> 
> In [10]: !cat foo.ini
> [section1]
> foodir = %(dir)s/whatever
> dir = anotherdir
> 
You are right, it works.
I thought I had tried it ...
Thanks. :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ConfigParser : overwrite ?

2005-07-17 Thread Robert Kern
cantabile wrote:
> Hi, I'm trying and updating an .ini file with ConfigParser but each time
> I call 'write', it appends the whole options another time to the file.
> For example :
> Here's the inital ini file
> 
> [section1]
> foodir: %(dir)s/whatever
> dir: foo
> 
> Here's my code :
> filename = ...
> config = ConfigParser.ConfigParser()
> config.read(filename)
> config.set('section1', 'dir', 'anotherdir')
> f = open(filename, 'r+')
> config.write(f)
> f.close()
> 
> Then I get :
> 
> [section1]
> foodir: %(dir)s/whatever
> dir: anotherdir
> 
> [section1]
> foodir: %(dir)s/whatever
> dir: foo
> 
> I tried also with 'w', 'w+', 'a' ...

Are you sure you tried it with 'w' as the mode?

In [1]: !cat foo.ini
[section1]
foodir: %(dir)s/whatever
dir: foo
In [2]: fn = 'foo.ini'

In [3]: import ConfigParser

In [4]: cfg = ConfigParser.ConfigParser()

In [5]: cfg.read(fn)
Out[5]: ['foo.ini']

In [6]: cfg.set('section1', 'dir', 'anotherdir')

In [7]: f = open(fn, 'w')

In [8]: cfg.write(f)

In [9]: f.close()

In [10]: !cat foo.ini
[section1]
foodir = %(dir)s/whatever
dir = anotherdir

-- 
Robert Kern
[EMAIL PROTECTED]

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter

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


ConfigParser : overwrite ?

2005-07-17 Thread cantabile
Hi, I'm trying and updating an .ini file with ConfigParser but each time
I call 'write', it appends the whole options another time to the file.
For example :
Here's the inital ini file

[section1]
foodir: %(dir)s/whatever
dir: foo

Here's my code :
filename = ...
config = ConfigParser.ConfigParser()
config.read(filename)
config.set('section1', 'dir', 'anotherdir')
f = open(filename, 'r+')
config.write(f)
f.close()

Then I get :

[section1]
foodir: %(dir)s/whatever
dir: anotherdir

[section1]
foodir: %(dir)s/whatever
dir: foo


I tried also with 'w', 'w+', 'a' ...

What's the correct way to avoid this ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python vs. Access VBA

2005-07-17 Thread Chris Lambacher
If you are going to go with Python, don't include Access in the mix at all.
If you want a small light-weight, serverless database back-end, you would be
better to go with SQLite.  Its cross platform and well proven.  I think
Firebird will give you that too, though I have never used it.  

Most people who use Oracle don't need it.  Unless you REALLY need it (Think
terabytes of data), Oracle is like cracking a nut with a sledge hammer.  You
can do it.  But you have to slug around a lot more weight in order to do what
you can accomplish with a nut cracker.  In other words its overly complicated.

-Chris


On Sun, Jul 17, 2005 at 08:06:22AM -0400, Ed Leafe wrote:
> On Jul 15, 2005, at 11:19 PM, William Lodge wrote:
> 
> > Finally, does anybody know of any Web sites having examples of 
> > database apps
> > in Python?
> 
>   You might want to look at Dabo, which is a database application 
> framework for Python. In about 30 seconds you can create an application 
> that queries a database, displays the results, and allows for 
> editing/updating/inserting/deleting records.
> 
>   Currently we do not have an ODBC interface, which is what you'd need 
> if the data is in Access, since no one involved has written that 
> module. However, if you are interested in developing your app in Dabo, 
> we'd be glad to add that module as long as you're willing to give us 
> the feedback we need to get it working smoothly.
> 
>   BTW, I wouldn't suggest scaling up to Oracle - why get involved with 
> all that licensing? There are many open-source databases, such as 
> PostgreSQL, MySQL and Firebird that can handle large data sets without 
> getting stuck with huge license fees.
> 
>   ___/
>  /
> __/
>/
>   /
>   Ed Leafe
>   http://leafe.com/
>   http://dabodev.com/
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Environment Variable

2005-07-17 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Sybren Stuvel  <[EMAIL PROTECTED]> wrote:
>tuxlover enlightened us with:
>> No, the replies from Grant's and Sybren's do answer my question.
>
>It would be a lot more polite to actually thank the people helping
>you.
.
.
.
Expressing gratitude is indeed a courtesy.

As an old-time Usenetter, I also have a high regard for
economy or brevity; I generally communicate my thanks in
private e-mail, unless I can embed them in a comment which
I think is likely to interest a wider audience.  I have in
mind something on the order of, "Thanks, timbot!  I notice
that not only does that solution conform to IEEE 754, as 
requested, but it's compatible with the Rayleigh-Ritz
implementation found in ..."

I'm certain neither of Mr. Stuvel's point, nor of whether
it applied to tuxlover's actual behavior.  I wouldn't want
readers to think, though, that every well-formed clp thread
must necessarily terminate in a follow-up whose content is
limited to "Thx."
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ssh popen stalling on password redirect output?

2005-07-17 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Cantankerous Old Git  <[EMAIL PROTECTED]> wrote:
>[EMAIL PROTECTED] wrote:
>> In general, it is good idea to use expect kind of tool to deal with
>> interactive programs like ssh. You may try using pexpect
>> (http://pexpect.sourceforge.net).
>> 
>
>I tried tha once (on Solaris) and found that ssh could tell that 
>pexpect wasn't a real tty and refused to connect. In the end, I 
>had pexpect  do a telnet 127.0.0.1, log in, then so ssh to the 
>real destination. Pain in the ass but it worked.
>
>The Cog

1.  Pexpect is designed to do better than this.  Please
report specific deficiencies in its operation.
2.  (The original) Expect has had years of working out
pty vagaries.  In a pinch, I'd write in Expect, and,
if necessary, control the Expect process from Python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: beginner question fibonacci

2005-07-17 Thread Joon
Yes, i see.
Thank you very much for the fast help!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: beginner question fibonacci

2005-07-17 Thread ralobao
The case is that Python in attribution commands solves first the right
side, so he atributes the vars.

So the a+b expression is executed first.

Joon escreveu:
> >>> # Fibonacci series:
> ... # the sum of two elements defines the next
> ... a, b = 0, 1
>  >>> while b < 10:
> ...   print b
> ...   a, b = b, a+b
> ...
> 1
> 1
> 2
> 3
> 5
> 8
>
>
>
>  >>> a, b = 0, 1
>  >>> while b < 10:
>   print b
>   a = b
>   b = a+b
> 
>   
> 1
> 2
> 4
> 8
> 
> Why a, b = b, a+b isn't a = b; b = a+b ?

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


Re: beginner question fibonacci

2005-07-17 Thread Michael Hoffman
Joon wrote:

>  >>> a, b = 0, 1
>  >>> while b < 10:
> print b
> a = b
> b = a+b
> 
> 
> 1
> 2
> 4
> 8
> 
> Why a, b = b, a+b isn't a = b; b = a+b ?

Because you changed a before you added it to b.

Let's call your existing a and b "a0" and "b0", and the next a and b 
"a1" and "b1". When you do a, b = b, a+b you are assigning:

a1 = b0
b1 = a0 + b0

But when you use separate statements, you are assigning:

a1 = b0
b1 = a1 + b0 = b0 + b0 = 2*b0
-- 
Michael Hoffman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: beginner question fibonacci

2005-07-17 Thread Robert Kern
Joon wrote:
> 
>  >>> # Fibonacci series:
> ... # the sum of two elements defines the next
> ... a, b = 0, 1
>  >>> while b < 10:
> ...   print b
> ...   a, b = b, a+b
> ...
> 1
> 1
> 2
> 3
> 5
> 8
> 
>  >>> a, b = 0, 1
>  >>> while b < 10:
>   print b
>   a = b
>   b = a+b
>   
> 1
> 2
> 4
> 8
> 
> Why a, b = b, a+b isn't a = b; b = a+b ?

It's actually equivalent to:

temp = (b, a+b)
a = temp[0]
b = temp[1]

The temporary tuple object is created first, with the old values of a 
and b. Then a and b are reassigned. The value of a doesn't change until 
*after* a+b is calculated.

-- 
Robert Kern
[EMAIL PROTECTED]

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter

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


beginner question fibonacci

2005-07-17 Thread Joon


 >>> # Fibonacci series:
... # the sum of two elements defines the next
... a, b = 0, 1
 >>> while b < 10:
...   print b
...   a, b = b, a+b
...
1
1
2
3
5
8



 >>> a, b = 0, 1
 >>> while b < 10:
print b
a = b
b = a+b


1
2
4
8

Why a, b = b, a+b isn't a = b; b = a+b ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tuples in function argument lists

2005-07-17 Thread Robert Kern
Steven D'Aprano wrote:
> I'm trying to understand the use of tuples in function argument lists.
> 
> I did this:
> 
def tester(a, (b,c)):
> 
> ... print a, b, c
> ... 
> 
tester(1, 2)
> 
> Traceback (most recent call last):
>   File "", line 1, in ?
>   File "", line 1, in tester
> TypeError: unpack non-sequence
> 
> That was obvious result.
> 
tester(1, (2, 3))
> 
> 1 2 3
> 
tester('ab', 'ab')
> 
> ab a b
> 
> And so were those.
> 
> Then I tried this:
> 
def tester(a, (b,c)=None):
> 
> ... if (b,c) is None:
> ... print a, None
> ... else:
> ... print a, b, c
> 
> Needless to say, it did not do what I expected it to do. I didn't expect
> it to either :-)
> 
> I tried looking at the language reference here:
> 
> http://docs.python.org/ref/function.html
> 
> but I can't seem to find anything in their that says that tuples-as-args
> are legal. Am I misreading the docs, or is this accidental behaviour that
> shouldn't be relied on?

Tuples-as-arg are legal. Tuple-as-keyword, too *if* the default value is 
something that can actually unpack to a tuple. A default of None is...silly.

In [6]: def tester(a, (b,c)=(1,2)):
...: print a,b,c
...:

In [7]: tester(1)
1 1 2

Tuple-as-arg is probably pretty safe. Tuple-as-keyword, possibly 
not-so-much.

> Does anyone use this behaviour, and if so, under what circumstances is it
> useful?

import math
def distance((x1,y1), (x2,y2)):
 return math.sqrt((x2-x1)**2 + (y2-y1)**2)
distance(point1, point2)

Personally, I prefer to explicitly unpack the tuple in the function body.

-- 
Robert Kern
[EMAIL PROTECTED]

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter

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


Re: I just wanna know about os.path module..

2005-07-17 Thread gene tani
look at 'path' module too

http://www.jorendorff.com/articles/python/path/

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


Tuples in function argument lists

2005-07-17 Thread Steven D'Aprano
I'm trying to understand the use of tuples in function argument lists.

I did this:

>>> def tester(a, (b,c)):
... print a, b, c
... 
>>> tester(1, 2)
Traceback (most recent call last):
  File "", line 1, in ?
  File "", line 1, in tester
TypeError: unpack non-sequence

That was obvious result.

>>> tester(1, (2, 3))
1 2 3
>>> tester('ab', 'ab')
ab a b

And so were those.

Then I tried this:

>>> def tester(a, (b,c)=None):
... if (b,c) is None:
... print a, None
... else:
... print a, b, c

Needless to say, it did not do what I expected it to do. I didn't expect
it to either :-)

I tried looking at the language reference here:

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

but I can't seem to find anything in their that says that tuples-as-args
are legal. Am I misreading the docs, or is this accidental behaviour that
shouldn't be relied on?

Does anyone use this behaviour, and if so, under what circumstances is it
useful?


-- 
Steven


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


Re: Python vs. Access VBA

2005-07-17 Thread Ed Leafe
On Jul 15, 2005, at 11:19 PM, William Lodge wrote:

> Finally, does anybody know of any Web sites having examples of 
> database apps
> in Python?

You might want to look at Dabo, which is a database application 
framework for Python. In about 30 seconds you can create an application 
that queries a database, displays the results, and allows for 
editing/updating/inserting/deleting records.

Currently we do not have an ODBC interface, which is what you'd need 
if the data is in Access, since no one involved has written that 
module. However, if you are interested in developing your app in Dabo, 
we'd be glad to add that module as long as you're willing to give us 
the feedback we need to get it working smoothly.

BTW, I wouldn't suggest scaling up to Oracle - why get involved with 
all that licensing? There are many open-source databases, such as 
PostgreSQL, MySQL and Firebird that can handle large data sets without 
getting stuck with huge license fees.

  ___/
 /
__/
   /
  /
  Ed Leafe
  http://leafe.com/
  http://dabodev.com/

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


Re: Filtering out non-readable characters

2005-07-17 Thread Peter Hansen
Steven D'Aprano wrote:
> On Sat, 16 Jul 2005 16:42:58 -0400, Peter Hansen wrote:
>>Come on, Steven.  Don't tell us you didn't have access to a Python 
>>interpreter to check before you posted:
> 
> Er, as I wrote in my post:
> 
> "Steven
> who is still using Python 2.3, and probably will be for quite some time"

Sorry, missed that!  I don't generally notice signatures much, partly 
because Thunderbird is smart enough to "grey them out" (the main text is 
displayed as black, quoted material in blue, and signatures in a light 
gray.)

I don't have a firm answer (though I suspect the language reference 
does) about when "dedicated" parentheses are required around a generator 
expression.  I just know that, so far, they just work when I want them 
to.  Like most of Python. :-)

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


Re: SSL problem... SSL23_GET_SERVER_HELLO:unknown protocol

2005-07-17 Thread Stephen Illingworth
John Reese wrote:
> Morning.  I've been running into an error message pertaining to SSL
> that I don't understand, and I was hoping someone had some insight.
> Gmail provides POP access over SSL on port 587, so I tried to use
> poplib.POP_SSL, with the following results:

GMail uses port 995.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SSL problem... SSL23_GET_SERVER_HELLO:unknown protocol

2005-07-17 Thread Stephen Illingworth
John Reese wrote:
> Morning.  I've been running into an error message pertaining to SSL
> that I don't understand, and I was hoping someone had some insight.
> Gmail provides POP access over SSL on port 587, so I tried to use
> poplib.POP_SSL, with the following results:

[snip]

> Any suggestions or insight?

Try port 465.
-- 
http://mail.python.org/mailman/listinfo/python-list


Ordering Products

2005-07-17 Thread Kay Schluehr
Here might be an interesting puzzle for people who like sorting
algorithms ( and no I'm not a student anymore and the problem is not a
students 'homework' but a particular question associated with a
computer algebra system in Python I'm currently developing in my
sparetime ).

For motivation lets define some expression class first:

class Expr:
def __init__(self, name=""):
self.name = name
self.factors = [self]

def __mul__(self, other):
p = Expr()
if isinstance(other,Expr):
other_factors = other.factors
else:
other_factors = [other]
p.factors = self.factors+other_factors
return p

def __rmul__(self, other):
p = M()
p.factors = [other]+self.factors
return p

def __repr__(self):
if self.name:
   return self.name
else:
   return "*".join([str(x) for x in self.factors])

One can create arbitrary products of Expr objects ( and mixing numbers
into the products ):

>>> a,b,c = Expr("a"),Expr("b"),Expr("c")
>>> a*b
a*b
>>> 7*a*8*9
7*a*8*9

The goal is to evaluate such products and/or to simplify them.

For expressions like

>>> x = 7*a*8*9

this might be easy, because we just have to sort the factor list and
multiply the numbers.

>>> x.factors.sort()
>>> x
a*7*8*9

-> a*504

This can be extended to arbitrary products:

>>> x = 7*a*b*a*9
>>> x.factors.sort()
>>> x
a*a*b*7*9

-> (a**2)*b*63

Now lets drop the assumption that a and b commute. More general: let be
M a set of expressions and X a subset of M where each element of X
commutes with each element of M: how can a product with factors in M be
evaluated/simplified under the condition of additional information X?

It would be interesting to examine some sorting algorithms on factor
lists with constrained item transpositions. Any suggestions?

Regards,
Kay

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


Re: I just wanna know about os.path module..

2005-07-17 Thread Peter Otten
kimes wrote:

> But the only os.path doesn't have their own file..
> ye I know is has actually depending on os like in my case posixpath..
> 
> What I'd love to know is..
> when I call import os.path..
> how happened under the hood?

At first os - module, or package, it doesn't matter here - is imported.
In its code, it detects the proper path module and imports it. The module
cache is then manipulated and the name 'path' is bound to posixpath, too:

sys.modules["os.path"] = posixpath
path = posixpath

The second stage of the import then reduces to just a lookup in the cache
instead of a search for the inexistent .../os/path.py in the filesystem.

Both the module attribute and the cache update are necessary when you want
to pull off similar tricks. Here is an example of the odd behaviour that
results from them being out of sync:

>>> import os
>>> os.path = 42
>>> from os import path # binds the path attribute of module os
>>> path
42
>>> import os.path
>>> os.path
42
>>> old_globals = set(globals().keys())
>>> from os.path import * # looks up os.path module as found in the cache
>>> set(globals().keys()) - old_globals
set(['pardir', 'sameopenfile', 'exists', 'sep', 'splitext', 'basename',
'walk', 'expandvars', 'old_globals', 'expanduser', 'getmtime', 'defpath',
'dirname', 'isfile', 'supports_unicode_filenames', 'pathsep', 'getsize',
'samestat', 'split', 'devnull', 'islink', 'curdir', 'samefile', 'realpath',
'commonprefix', 'abspath', 'normcase', 'getatime', 'isdir', 'join',
'altsep', 'getctime', 'isabs', 'normpath', 'ismount', 'splitdrive',
'extsep'])

Peter

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


Re: I just wanna know about os.path module..

2005-07-17 Thread James


kimes wrote:
> I've just started digging into how python works..
> I found that other mudules are clearly declared like one file per a
> module..
>
> But the only os.path doesn't have their own file..
> ye I know is has actually depending on os like in my case posixpath..
>
> What I'd love to know is..
> when I call import os.path..
> how happened under the hood?
>
> I'm currently using python 2.4 in linux machine..
> I'd appreciate it

See line 5 of os.py (comment)
  - os.path is one of the modules posixpath, ntpath, or macpath
It says it sets os.path depending on the platform

and does so in line 132
sys.modules['os.path'] = path

In your case, os.path should be implemented in posixpath.py
See line 48 to see where it came from

In short, "use the source, Luke" :-)
especially when Python is exceptionally readable.

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


Re: SSL problem... SSL23_GET_SERVER_HELLO:unknown protocol

2005-07-17 Thread Paul Rubin
"Martin v. Löwis" <[EMAIL PROTECTED]> writes:
> [EMAIL PROTECTED]:~/doc$ telnet pop.gmail.com 587
> Trying 64.233.185.111...
> Connected to pop.gmail.com.
> Escape character is '^]'.
> 220 mx.gmail.com ESMTP 13sm5173422wrl
> 
> This rather looks like an unencrypted SMTP connection to me. Indeed,
> port 587 is the mail submission protocol.

It wants a STARTTLS command.
-- 
http://mail.python.org/mailman/listinfo/python-list


I just wanna know about os.path module..

2005-07-17 Thread kimes
I've just started digging into how python works..
I found that other mudules are clearly declared like one file per a
module..

But the only os.path doesn't have their own file..
ye I know is has actually depending on os like in my case posixpath..

What I'd love to know is..
when I call import os.path..
how happened under the hood?

I'm currently using python 2.4 in linux machine..
I'd appreciate it

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


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

2005-07-17 Thread J.Bijsterbosch
Hello James,

"James Dennett" <[EMAIL PROTECTED]> schreef in bericht
news:[EMAIL PROTECTED]
> J.Bijsterbosch wrote:
>
[ snip ]
> >>and didn't remember Windows uses path names which need special
> >>treatment.
> >
> > Hmm, what you call special treatment comes from pythons deep
underlying C
> > and C++ language heietidge I presume. A backslash in a C or C++ string
means
> > the following character is a so called escape character, like \n
represents
> > a newline and \r a return to the beginning of a line.
> > If you really want a backslash you need to type it twice like so \\. Has
> > nothing to do with Windows...;-))
>
> Actually, it does have a connection to Windows.
>
> On Unix, backslashes are rarely used for anything *except* escape
> characters.  Pathnames tend not to include backslashes, so in most
> cases it's not necessary to escape backslashes in path names.

I know, I've had mandrake installed for some time until that pc died on
me, the pc that is, not mandrake...

> On Windows, however, backslash is a valid path separator, and must be
> escaped.
>
> So, on Unix, for a path separator, you type "/".  On Windows you
> can either do the same, or type "\\".  (Or (ab)use raw strings.)

Okay, point taken, but I still think it's more a C(++) string thing than a
Windows
issue. I could of course argue that the backslash path separator is there
for backward
compatebility with Dos, but I won't, much to off topic...;-))

>  James

Greetings from overcast Amsterdam,

Jan


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


Re: SSL problem... SSL23_GET_SERVER_HELLO:unknown protocol

2005-07-17 Thread Martin v. Löwis
John Reese wrote:
> Morning.  I've been running into an error message pertaining to SSL
> that I don't understand, and I was hoping someone had some insight.
> Gmail provides POP access over SSL on port 587, so I tried to use
> poplib.POP_SSL, with the following results:
[...]
> socket.sslerror: (1, 'error:140770FC:SSL 
> routines:SSL23_GET_SERVER_HELLO:unknown protocol')
> 
> 
> Any suggestions or insight?

It appears that pop.gmail.com *doesn't* provide SSL on port 587.

[EMAIL PROTECTED]:~/doc$ telnet pop.gmail.com 587
Trying 64.233.185.111...
Connected to pop.gmail.com.
Escape character is '^]'.
220 mx.gmail.com ESMTP 13sm5173422wrl

This rather looks like an unencrypted SMTP connection to me. Indeed,
port 587 is the mail submission protocol.

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