Re: MSoffice metadata

2006-06-24 Thread Gary Herron
[EMAIL PROTECTED] wrote:
> hi
> is there a module in Python to extract metadata in MS office documents
> thanks
>
>   
Perhaps. OpenOffice can read and write MS office files, and OpenOffice
has an API (called UNO for Universal Network Objects) which has a Python
binding (called the Python-UNO bridge). This might (eventually) get you
what you want.

Here's a URL for it:
http://udk.openoffice.org/python/python-bridge.html

Good luck,
Gary Herron

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


MSoffice metadata

2006-06-24 Thread micklee74
hi
is there a module in Python to extract metadata in MS office documents
thanks

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


Re: String negative indices?

2006-06-24 Thread Erik Max Francis
Steven D'Aprano wrote:

> In mathematics, well, maybe... certainly in the Real number system, there
> is no difference, and +0 and -0 are just two ways of writing the same
> thing. In the hyperreals, +0 and -0 are the same, but there are
> infinitesimals which are different, and signed. I don't know enough about
> the surreals to comment. In matrix maths, there are an infinite number of
> different matrices where all the elements are zero -- they are all
> distinct, different, zeroes.

What do you even mean by that?  By "matrix maths," do you just mean 
matrices whose elements are reals, or something else?

-- 
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
  San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
   My heart is pure as the driven slush.
-- Tallulah Bankhead
-- 
http://mail.python.org/mailman/listinfo/python-list


pygame.draw deadline extended to Sunday midnight UTC

2006-06-24 Thread richard
I'm not going to be awake at midnight, so that means that entrants in the 
pygame.draw challenge have a few extra hours to get their entries in.

   http://media.pyweek.org/static/pygame.draw-0606.html

Get entries to me by email before UTC (GMT) 23:59 Sunday 25th June.


Richard

-- 
Visit the PyWeek website:
  http://www.pyweek.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is Expressiveness in a Computer Language

2006-06-24 Thread Chris Smith
Chris F Clark <[EMAIL PROTECTED]> wrote:
> Do you reject that there could be something more general than what a 
> type theorist discusses?  Or do you reject calling such things a type?

I think that the correspondence partly in the wrong direction to 
describe it that way.  If someone were to stand up and say "every 
possible but of reasoning about program correctness or behavior is type 
reasoning", then I'd be happy to say that formal type systems are a 
subset of that kind of reasoning.  However, that's quite the statement 
to ask of anyone.  So far, everyone has wanted to say that there are 
some kinds of reasoning that are type reasoning and some that are not.  
If that is the case, then a formal type system is in that sense more 
general than this intuitive notion of type, since formal type systems 
are not limited to verifying any specific category of statements about 
program behavior (except, perhaps that they are intended to verify 
guarantees, not possibilities; I don't believe it would fit all 
definitions of formal types to try to verify that it is possible for a 
program to terminate, for example).

What I can't agree to is that what you propose is actually more general.  
It is more general in some ways, and more limited in others.  As such, 
the best you can say is that is analogous to formal types in some ways, 
but certainly not that it's a generalization of them.

> Let you write: 
> > because we could say that anything that checks types is a type system,
> > and then worry about verifying that it's a sound type system without
> > worrying about whether it's a subset of the perfect type system. 
>  
> I'm particularly interested if something unsound (and perhaps 
> ambiguous) could be called a type system.

Yes, although this is sort of a pedantic question in the first place, I 
believe that an unsound type system would still generally be called a 
type system in formal type theory.  However, I have to qualify that with 
a clarification of what is meant by unsound.  We mean that it DOES 
assign types to expressions, but that those types are either not 
sufficient to prove what we want about program behavior, or they are not 
consistent so that a program that was well typed may reduce to poorly 
typed program during its execution.  Obviously, such type systems don't 
prove anything at all, but they probably still count as type systems.

(I'll point out briefly that a typical, but not required, approach to 
type theory is to define program semantics so that the evaluator lacks 
even the rules to continue evaluating programs that are poorly typed or 
that don't have the property of interest.  Hence, you'll see statements 
like one earlier in this thread that part of type-soundness is a 
guarantee that the evaluation or semantics doesn't get stuck.  I 
actually think this is an unfortunate confusion of the model with the 
thing being modeled, and the actual requirement of interest is that the 
typing relation is defined so that all well-typed terms have the 
interesting property which we are trying to prove.  It is irrelevant 
whether the definition of the language semantics happens to contain 
rules that generalize to ill-typed programs or not.)

I suspect, though, that you mean something else by unsound.  I don't 
know what you mean, or whether it could be considered formally a type 
system.

> > 1. The domain is the set of inputs to that expression which are going to 
> > produce a correct result. 
> > 
> > 2. The domain is the set of inputs that I expected this expression to 
> > work with when I wrote it. 
> > 
> > 3. The domain is the set of inputs for which the expression has a 
> > defined result within the language semantics. 

> Actually, I like 2 quite well.  There is some set in my mind when I'm
> writing a particular expression.  It is likely an ill-defined set, but
> I don't notice that.  That set is exactly the "type".

I don't actually mind #2 when we're talking about types that exist in 
the programmer's mind.  I suspect that it may get some complaint along 
the lines that in the presence of type polymorphism, programmers don't 
need to be (perhaps rarely are) thinking of any specific set of values 
when they write code.  I would agree with that statement, but point out 
that I can define at least my informal kind of set by saying, for 
instance, "the set of all inputs on which X operations make sense".

I believe there is more of a concrete difference between #1 and #2 than 
you may realize.  If we restrict types to considering the domain of 
functions without regard to the context in which they are called, then 
there are plenty of inputs on which this function does its own job quite 
well, but a global analysis tool may be able to conclude that if that 
input has been passed in, then this program already beyond the 
possibility of producing a correct result.  #1 would, therefore, be a 
more global form of analysis than #2, rather than being merely a 
question of whether 

Re: Saying "latently-typed language" is making a category mistake

2006-06-24 Thread Matthias Blume
David Hopwood <[EMAIL PROTECTED]> writes:

> Patricia Shanahan wrote:
>> Vesa Karvonen wrote:
>> ...
>> 
>>> An example of a form of informal reasoning that (practically) every
>>> programmer does daily is termination analysis.  There are type systems
>>> that guarantee termination, but I think that is fair to say that it is
>>> not yet understood how to make a practical general purpose language, whose
>>> type system would guarantee termination (or at least I'm not aware of
>>> such a language).  It should also be clear that termination analysis need
>>> not be done informally.  Given a program, it may be possible to formally
>>> prove that it terminates.
>> 
>> To make the halting problem decidable one would have to do one of two
>> things: Depend on memory size limits, or have a language that really is
>> less expressive, at a very deep level, than any of the languages
>> mentioned in the newsgroups header for this message.
>
> I don't think Vesa was talking about trying to solve the halting problem.
>
> A type system that required termination would indeed significantly restrict
> language expressiveness -- mainly because many interactive processes are
> *intended* not to terminate.

Most interactive processes are written in such a way that they
(effectively) consist of an infinitely repeated application of some
function f that maps the current state and the input to the new state
and the output.

   f : state * input -> state * output

This function f itself has to terminate, i.e., if t has to be
guaranteed that after any given input, there will eventually be an
output.  In most interactive systems the requirements are in fact much
stricter: the output should come "soon" after the input has been
received.

I am pretty confident that the f for most (if not all) existing
interactive systems could be coded in a language that enforces
termination.  Only the loop that repeatedly applies f would have to be
coded in a less restrictive language.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Absolute noob to Linux programming needs language choice help

2006-06-24 Thread Carl Banks
[EMAIL PROTECTED] wrote:
> Hey guys,
>
> I am absolutely new to Linux programming, with no w##s programming
> experience except a small amount of C++ console apps.
> Reasonably new to Linux, BSD etc, got good sound networking base of
> knowledge and dont have any problem working the command line etc.
>
> I want to learn a language that I can use in my networking duties that
> is most likely to be of use to me. I have a few choices I can think of
> being:
>
> Python
> Perl
> C
>
> Any other Langs out there that would be better suited?
>
> I want to be able to use the app's I write in OpenBSD and RH versions
> of Linux
>
> What would you reccomend (Unbiased opinion please, I'm after the
> functionality I'll love it later :) )

I'm known as a Perl hator, but I'll try to be as unbiased as I can.
I'm limiting myself to the three you mentioned.

C is a very simple (meaning "straightforward", not "easy to learn")
language.  Almost everything in C is reduced to basic building blocks
that are quite close to how the CPU itself runs.  For example, there's
no such thing as a "list" or even a "string" in C; instead, what you
have are pointers, arrays, and a small number of built-in types (and a
small standard library that provides more complex things like strings).
 This makes C an excellent language for programming hardware and
low-level stuff like that.  However, it's really not optimal for
application programming--it forces you to worry about stuff like
freeing memory and buffer overflows.

I was frustrated with C because I mostly do application stuff, so one
day I sat down to learn Perl.  I was amazed at the leap in
productivity--I was able to write an email autoresponder the very same
day I began the tutorial (granted, I was an expert programmer at the
time, but still).  Perl freed me from having to worry about stuff like
memory management, and it provided useful things like growable arrays
and dictionaries.  However, unlike C, Perl is not simple.  Perl is
complicated, ad hoc, and inconsistent.  It never really fit inside my
head--I was always afraid there was something going on, some obscure
rule or behavior was lurking.  In addition (and here the Perl hator in
me comes out), it's poorly designed as a language: it often makes you
do extra work to do things the better way (for example, local variables
have to be declared, but not globals).

So we have C, which is simple and straightforward but too low-level to
be efficicient at application programming.  We have Perl, which is
high-level enough for application programming, but is complicated and
inconsistent.

Then we have Python, which is both simple and high-level.

So, yeah, I like Python best of those three.  For someone new to
programming, I definitely recommend learning Python first, unless you
intend to be a expert or professional programmer or to do low-level
stuff, in which case I'd say start with C.  Definitely don't start
learning with Perl.  It might be the best choice for some people (in
some universes), but it encourages bad programming habits, so I don't
recommend it for newbies.  Learning to program in Perl is like learning
to do stand-up comedy by laughing at your own jokes.

For someone looking for looking to learn preferrably only one language,
I'd say Python, without knowing more about your intended problem
domain.


Carl Banks

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


Python is fun and useful (was: Python is fun (useless social thread) ; -))

2006-06-24 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Carl Trachte <[EMAIL PROTECTED]> wrote:
.
.
.
>Yes.  I was a production geologist in a copper mine in the mid 90's.  Our
>mine planning software vendor Mintec (www.mintec.com) had chosen it as
>their API for programmatic access to the three dimensional geologic block
>model and two dimensional polygons that defined geologic shapes on a level
>bench or in vertical cross section.
>
>>
>> Or did you just like what you saw and decided to learn it for fun?
>
>That too.  I had been using Visual Basic.  For what I was doing (mine
>engineering), there was just a lot more functionality available in Python
>and its external modules (numeric, for example).  Organizing a lot of
>engineering data dumped as text is easier in Python than it is in VB
>(IMO), because of the way Python handles lists and dictionaries.
>
>>
>> Also, how did you go about learning it? (i.e., like I described above, I
>started with the main stuff then moved on to the different available
>frameworks)
>
>I started with Mintec's mine planning software API, then realized that a
>lot of stuff was easier in Python.  VB was great for making GUI's quickly.
> Python (Tkinter) is harder because you have to code your windows
>(although once I got over that initial hump, it got a lot easier - there's
>decent documentation for Tkinter on the web, and it doesn't cost a
>thing!).
>
>My employer was good enough to send me to M. Lutz' 3 day course on Python
>in Colorado.  This was helpful.  Up until that time I had been coding VB
>in Python (a lot of it was "translating" code from one language to the
>other).  After that course I started to think in Python and make better
>use of the features Python had (OO, exception handling, etc.).
>
>>
>> Was there any necessity in the specifics you learned, or did you just
>dabble in something (e.g. wxPython) for fun?
>
>As I mentioned with the Tkinter example above, there was almost always
>necessity.  Fortunately the stuff we do necessitates a lot of different
>language features and modules.  The datetime module was something I didn't
>know about until I bought the latest version of the Python cookbook.  The
>thing is a huge productivity boost, especially for the stuff I do
>(daily/monthly/yearly production reports).
>
>>
>> Are there still some things you feel you need to learn or improve?
>
>Always.  Always.  Always.  Extending to Fortran and C are things I'd like
>to accomplish.  There is a lot of old, but useful Fortran code around.  If
>you can marry it with Python instead of trying to rewrite it, that's a lot
>of coding time (and money) saved.  There are accounts of this sort of
>thing out on the web, but I'm yet to accomplish it myself.  Langtangen's
>scientific Python book offers a start.  I've got a copy and have read
>through it, but I've got to work on some real examples before I have any
>success with it.  I'm not there yet.
>
>>
>> Additional comments/complains here:   :)
>
>Life's too short to use and enjoy everything Python's got to offer. :-)
.
.
.
Indeed.

Your testimony deserves particular attention, I think, because
I believe the applicability of Python and related techniques to
process control, engineering programming, and so on, is vastly
under-appreciated.  Conventional wisdom in these domains sees
Visual Basic, Visual C++, and Fortran as suitable vehicles.
You've seen how limiting this is.

For reasons that I can elaborate at more length later, I'd love
to diffuse awareness of Python's potential in mining and other
"real-world" industries.  The Agile Control Forum http://www.engcorp.com/acf/RecentChanges > is made for just
such purposes.  Although it's been rather quiet recently, that
might change soon.  It'd be great to have you tell your story
in the ACF Wiki.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 2Qs

2006-06-24 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
SuperHik  <[EMAIL PROTECTED]> wrote:
>1st question:
>
>If a make an exe with i.e. py2exe, can I get any kind of error/bug 
>report from the exe file saved into a file error.log and how?
.
.
.
Yes.

It's hard to know what more to say, in the absence of knowledge about
your background.  I *think* what you're after is this:  define a

  import sys

  def main():
  # All the real work starts here.
  do_first_important_thing()
  do_more()
  still_more()
  finish_it_all()

  try:
  main()
  except:
  problem = sys.exc_info()
  fp = open("error.log", "w")
  fp.write("The problem was '%s'.\n", str(problem[1]))
  fp.close()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is Expressiveness in a Computer Language

2006-06-24 Thread Marshall
Chris F Clark wrote:
>
> I'm particularly interested if something unsound (and perhaps
> ambiguous) could be called a type system.  I definitely consider such
> things type systems.

I don't understand. You are saying you prefer to investigate the
unsound over the sound?


> However, I like my definitions very general and
> vague.  Your writing suggests the opposite preference.

Again, I cannot understand this. In a technical realm, vagueness
is the opposite of understanding. To me, it sounds like you are
saying that you prefer not to understand the field you work in.


> To me if
> something works in an analogous way to how a known type system, I tend
> to consider it a "type system".  That probably isn't going to be at
> all satisfactory to someone wanting a more rigorous definition.

Analogies are one thing; definitions are another.


> Of
> course, to my mind, the rigorous definitions are just an attempt to
> capture something that is already known informally and put it on a
> more rational foundation.

If something is informal and non-rational, it cannot be said to
be "known." At best, it could be called "suspected." Even if you
think something which turns out to be true, we could not say
that you "knew" it unless your reasons for your thoughts were
valid.

I flipped a coin to see who would win the election; it came
up "Bush". Therefore I *knew* who was going to win the
election before it happened. See the probem?


Marshall

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


Re: 2Qs

2006-06-24 Thread Steven D'Aprano
On Sat, 24 Jun 2006 21:24:33 +0200, SuperHik wrote:

> 1st question:
> 
> If a make an exe with i.e. py2exe, can I get any kind of error/bug 
> report from the exe file saved into a file error.log and how?

Write the program to write a log file as it runs?



> 2nd question:
[snip]
> if x>10 and y>10 and z>10 and summ(tritup(x,y,z)): print "OK"

Others have already suggested you use the built-in sum() function.

I'll suggest you don't need it at all, because it is redundant.

If the sum is zero, either all three values are zero or at least one of
the values is negative. In either case the first test will fail.

There are no circumstances where each of x, y and z are greater than 10
but the sum is zero; nor are there any circumstances where the sum is
zero but x, y and z are still all greater than 10.



-- 
Steven.

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


Re: Absolute noob to Linux programming needs language choice help

2006-06-24 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Ben C  <[EMAIL PROTECTED]> wrote:
.
.
.
>My favourite's Python, but Tcl is definitely worth a look. It's been
>around a bit longer than Python (so more time for every conceivable
>problem to have been met by someone and fixed), and I'm not an expert
>but I think it's particularly good for things like sockets-- they're
>just sort of built in and are very easy to work with.

Tcl's maturity advantage is tiny--*maybe* two years.  Both began at
the end of the '80s.  There've been close to two decades since to
obscure any initial leads.

I entirely agree with you, though, that Tcl's [socket] command is
a wonderful thing.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Absolute noob to Linux programming needs language choice help

2006-06-24 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Alex Martelli <[EMAIL PROTECTED]> wrote:
><[EMAIL PROTECTED]> wrote:
>
>> Hey guys,
>> 
>> I am absolutely new to Linux programming, with no w##s programming
>> experience except a small amount of C++ console apps.
>> Reasonably new to Linux, BSD etc, got good sound networking base of
>> knowledge and dont have any problem working the command line etc.
>> 
>> I want to learn a language that I can use in my networking duties that
>> is most likely to be of use to me. I have a few choices I can think of
>> being:
.
.
.
>Python, Perl, and a third language you have not mentioned, Ruby, are
>very high level, and each is suitable for just about the same range of
>programming (almost any programming, except very low-level;-).  The
.
[more true and
pertinent obser-
vations]
.
.
Tcl is also in this category.  Even with Alex expanding the discussion
to encompass Ruby, I wouldn't mention Tcl--except that the original
questioner explicitly mentioned "networking duties".  While his intent
is ambiguous, it deserves to be said that, just as Alex has written, 
all four of these languages are rough equivalents, differing as much 
in subjective feel as objective functionality, but that
1.  Tcl, with its emphasis on event programming,
codes multi-processing TCP servers more com-
pactly than the other three;
2.  Tcl is the extension language for Cisco's 
IOS and several other networking products;
3.  Tcl-based Scotty is the single most mature
SNMP suite any of the four languages have
produced; 
4.  There's the whole BEEP story; and
5.  Tcl-based Expect has a special role in
system administration and network manage-
ment.

There's plenty to read on all these subjects, if you have an interest.
http://www-128.ibm.com/developerworks/linux/library/l-sc1/ > might
be a place to start.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is Expressiveness in a Computer Language

2006-06-24 Thread Chris F Clark
Chris Smith <[EMAIL PROTECTED]> writes: 
 
> Unfortunately, I have to again reject this idea.  There is no such
> restriction on type theory.  Rather, the word type is defined by type
> theorists to mean the things that they talk about. 
 
Do you reject that there could be something more general than what a 
type theorist discusses?  Or do you reject calling such things a type?
 
Let you write: 
> because we could say that anything that checks types is a type system,
> and then worry about verifying that it's a sound type system without
> worrying about whether it's a subset of the perfect type system. 
 
I'm particularly interested if something unsound (and perhaps 
ambiguous) could be called a type system.  I definitely consider such 
things type systems.  However, I like my definitions very general and 
vague.  Your writing suggests the opposite preference.  To me if 
something works in an analogous way to how a known type system, I tend
to consider it a "type system".  That probably isn't going to be at 
all satisfactory to someone wanting a more rigorous definition. Of 
course, to my mind, the rigorous definitions are just an attempt to 
capture something that is already known informally and put it on a
more rational foundation.
 
> So what is the domain of a function?  (Heck, what is a function? 
...
> (I need a word here that implies something like a set, but I don't care 
> to verify the axioms of set theory.  I'm just going to use set.  Hope 
> that's okay.) 
 
Yes, I meant the typical HS algebra definition of domain, which is a 
set, same thing for function.  More rigorous definitions can be 
sustituted as necessary and appropriate.
 
> 1. The domain is the set of inputs to that expression which are going to 
> produce a correct result. 
> 
> 2. The domain is the set of inputs that I expected this expression to 
> work with when I wrote it. 
> 
> 3. The domain is the set of inputs for which the expression has a 
> defined result within the language semantics. 
> 
> So the problem, then, more clearly stated, is that we need something 
> stronger than #3 and weaker than #1, but #2 includes some psychological 
> nature that is problematic to me (though, admittedly, FAR less 
> problematic than the broader uses of psychology to date.) 
 
Actually, I like 2 quite well.  There is some set in my mind when I'm
writing a particular expression.  It is likely an ill-defined set, but
I don't notice that.  That set is exactly the "type".  I approximate
that set and it's relationships to other sets in my program with the
typing machinery of the language I am using.  That is the static (and
well-founded) type.  It is however, only an approximation to the ideal
"real" type.  If I could make that imaginary mental set concrete (and
well-defined), that would be exactly my concept of type.
 
Now, that overplays the conceptual power in my mind.  My mental image
is influenced by my knowledge of the semantics of the language and
also any implementations I may have used.  Thus, I will weaken 2 to be
closer to 3, because I don't expect a perfectly ideal type system,
just an approximation.  To the extent that I am aware of gotchas in
the language or a relavent implementation, I amy write extra code to
try and limit things to model 1.  Note that in my fallible mind, 1 and
2 are identical.  In my hubris, I expect that the extra checks I have
made have restricted my inputs to where model 3 and 1 coincide.

Expanding that a little.  I expect the language to catch type errors
where I violate model 3.  To the extent model 3 differs from model 1
and my code hasn't added extra checks to catch it, I have bugs
resulting from undetected type errors or perhaps modelling errors.  To
me they are type errors, because I expect that there is a typing
system that captures 1 for the program I am writing, even though I
know that that is not generally true.

As I reflect on this more, I really do like 2 in the sense that I
believe there is some abstract Platonic set that is an ideal type
(like 1) and that is what the type system is approximating.  to the
sense that languages approximate either 1 or 2, those facilites are
type facilities of a language.  That puts me very close to your
(rejected) definition of type as the well-defined semantics of the
language.  Except I think of types as the sets of values that the
language provides, so it isn't the entire semantics of the language,
just that part which divides values into discrete sets which are
approriate to different operations (and detect inaapropriate values).

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


Re: String negative indices?

2006-06-24 Thread Steven D'Aprano
On Sat, 24 Jun 2006 05:36:17 -0700, Filip Wasilewski wrote:

> Steven D'Aprano wrote:
>> On Fri, 23 Jun 2006 02:17:39 -0700, Filip Wasilewski wrote:
>>
>> > [EMAIL PROTECTED] wrote:
>> >
>> >> Logically, I should be able to enter x[-2:-0] to get the last and next to 
>> >> last characters. However, since Python doesn't distinguish between 
>> >> positive and negative zero, this doesn't work. Instead, I have to enter 
>> >> x[-2:].
>> >
>> > Hooray! Logically there is no such thing as positive or negative zero,
>> > or did I miss something in the primary?
>>
>> No, not in the primary, or even in the secondary, but possibly in the
>> tertiary.
>>
>> For many purposes, it doesn't make sense to distinguish +0 from -0. But
>> for other purposes, it does.
> 
> I believe you will agree that this is mostly a matter of notation of
> some fact rather than really trying to sign zero.

No. 

In floating point, +0 *really is* different from -0 -- the two floats
have different bit patterns. Floating point libraries must be specifically
programmed to ignore that difference, making zero treated differently than
other floats. That's -- usually -- a good thing.

In mathematics, well, maybe... certainly in the Real number system, there
is no difference, and +0 and -0 are just two ways of writing the same
thing. In the hyperreals, +0 and -0 are the same, but there are
infinitesimals which are different, and signed. I don't know enough about
the surreals to comment. In matrix maths, there are an infinite number of
different matrices where all the elements are zero -- they are all
distinct, different, zeroes.

And in "the real world", all numbers are an abstraction anyway, so I'm
not too worried about correspondence to reality. If mathematicians find a
use for distinguishing +0 from -0 (as the statistical physicists have
done) they will treat them as "really" different. If they don't, they
won't.


-- 
Steven.

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


Re: 2Qs

2006-06-24 Thread Diez B. Roggisch
if x>10 and y>10 and z>10 and sum((x,y,z)): print "OK"

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


Re: Mix-In Class Methods At Run-Time

2006-06-24 Thread bearophileHUGS
I think it's possible, most of such kind of things are possible with
Python.
I'm not an expert yet in such kind of things, so this can be a starting
point for you (note the shadowing of m2, the class docstrings, etc).
Other people can give you something better or more correct.

class A:
def m1(self): return "m1"
def m2(self): return "m2"

class B:
def m3(self): return "m3"

class P:
def m2(self): return "m2b"
def m4(self): return"m4"

def mixin(object, *classes):
class NewClass(object.__class__):
pass
for C in classes:
NewClass.__dict__.update(C.__dict__)
object.__class__ = NewClass

foo = P()
print "Before:"
print "foo.__class__.__dict__.keys():", foo.__class__.__dict__.keys()
print "P.__dict__.keys():", P.__dict__.keys()
print "foo.m2():", foo.m2()
print "foo.m4():", foo.m4(), "\n"

mixin(foo, A, B)

print "After:"
print "foo.__class__.__dict__.keys():", foo.__class__.__dict__.keys()
print "P.__dict__.keys():", P.__dict__.keys()
print "foo.m1():", foo.m1()
print "foo.m2():", foo.m2()
print "foo.m3():", foo.m3()
print "foo.m4():", foo.m4()

Bye,
bearophile

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


Mix-In Class Methods At Run-Time

2006-06-24 Thread digitalorganics
Hi all. If I have an instance of class A, called say foo, and I need to
mix-in the functions and variables of another class (class B) to this
instance at runtime, how do I do it? In other words, I want to make foo
an instance of an anonymous and temporary class that inherits its
functionality from classes A and B, while at the same time I want the
pre-existing contents of foo to remain intact. Possible in Python?

Thanks

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


Re: Python to PHP Login System (HTTP Post)

2006-06-24 Thread John J. Lee
[EMAIL PROTECTED] (John J. Lee) writes:
[...]
> #---
> import mechanize
> 
> SHOW_COOKIES = True
> 
> br = mechanize.Browser()
> if SHOW_COOKIES:
> cj = mechanize.CookieJar()
> br.set_cookiejar(cj)
> br.open("http://www.magnetshare.com/main.php";)
> br.select_form(nr=0)
> br["user"] = "joe"
> br["pass"] = "password"
> r = br.submit()
> assert "Logged In" in r.get_data()
> if SHOW_COOKIES:
> for cookie in cj:
> print cj
> #---

That last line should of course have been:

print cookie

and not:

print cj


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


Re: What is Expressiveness in a Computer Language

2006-06-24 Thread David Hopwood
Marshall wrote:
> Joe Marshall wrote:
> 
>>Marshall wrote:
> 
>>>2) I want to run my program, even though it is broken, and I
>>>want to run right up to a broken part and trap there, so I can
>>>use the runtime facilities of the language to inspect what's
>>>going on.
>>
>>I do this quite often.  Sometimes I'll develop `in the debugger'.  I'll
>>change some piece of code and run the program until it traps.  Then,
>>without exiting the debugger, I'll fix the immediate problem and
>>restart the program at the point it trapped.  This technique takes a
>>bit of practice, but if you are working on something that's complex and
>>has a lot of state, it saves a lot of time because you don't have to
>>reconstruct the state every time you make a change.

The problem with this is that from that point on, what you're running
is neither the old nor the new program, since its state may have been
influenced by the bug before you corrected it.

I find it far simpler to just restart the program after correcting
anything. If this is too difficult, I change the design to make it
less difficult.

> Wow, interesting.
> 
> (I say the following only to point out differing strategies of
> development, not to say one or the other is right or bad or
> whatever.)
> 
> I occasionally find myself doing the above, and when I do,
> I take it as a sign that I've screwed up. I find that process
> excruciating, and I do everything I can to avoid it. Over the
> years, I've gotten more and more adept at trying to turn
> as many bugs as possible into type errors, so I don't have
> to run the debugger.
> 
> Now, there might be an argument to be made that if I had
> been using a dynamic language, the process wouldn't be
> so bad, and I woudn't dislike it so much. But mabe:
> 
> As a strawman: suppose there are two broad categories
> of mental strategies for thinking about bugs, and people
> fall naturally into one way or the other, the way there
> are morning people and night people. One group is
> drawn to the static analysis, one group hates it.
> One group hates working in the debugger, one group
> is able to use that tool very effectively and elegantly.
> 
> Anyway, it's a thought.

I don't buy this -- or at least, I am not in either group.

A good debugger is invaluable regardless of your attitude to type
systems. Recently I was debugging two programs written to do similar
things in the same statically typed language (C), but where a debugger
could not be used for one of the programs. It took maybe 5 times
longer to find and fix each bug without the debugger, and I found it
a much more frustrating experience.

-- 
David Hopwood <[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is Expressiveness in a Computer Language

2006-06-24 Thread David Hopwood
David Hopwood wrote:
> Anton van Straaten wrote:
> 
>>I'm suggesting that if a language classifies and tags values in a way
>>that supports the programmer in static reasoning about the behavior of
>>terms, that calling it "untyped" does not capture the entire picture,
>>even if it's technically accurate in a restricted sense (i.e. in the
>>sense that terms don't have static types that are known within the
>>language).
>>
>>Let me come at this from another direction: what do you call the
>>classifications into number, string, vector etc. that a language like
>>Scheme does?  And when someone writes a program which includes the
>>following lines, how would you characterize the contents of the comment:
>>
>>; third : integer -> integer
>>(define (third n) (quotient n 3))
> 
> I would call it an informal type annotation. But the very fact that
> it has to be expressed as a comment, and is not checked,

What I meant to say here is "and is not used in any way by the language
implementation,"

> means that
> the *language* is not typed (even though Scheme is dynamically tagged,
> and even though dynamic tagging provides *partial* support for a
> programming style that uses this kind of informal annotation).

-- 
David Hopwood <[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is Expressiveness in a Computer Language

2006-06-24 Thread David Hopwood
Anton van Straaten wrote:
> David Hopwood wrote:
> 
>> I can accept that dynamic tagging provides some support for latent typing
>> performed "in the programmer's head". But that still does not mean that
>> dynamic tagging is the same thing as latent typing
> 
> No, I'm not saying it is, although I am saying that the former supports
> the latter.

But since the relevant feature that the languages in question possess is
dynamic tagging, it is more precise and accurate to use that term to
describe them.

Also, dynamic tagging is only a minor help in this respect, as evidenced
by the fact that explicit tag tests are quite rarely used by most programs,
if I'm not mistaken. IMHO, the support does not go far enough for it to be
considered a defining characteristic of these languages.

When tag tests are used implicitly by other language features such as
pattern matching and dynamic dispatch, they are used for purposes that are
equally applicable to statically typed and non-(statically-typed) languages.

>> or that languages
>> that use dynamic tagging are "latently typed". This simply is not a
>> property of the language (as you've already conceded).
> 
> Right.  I see at least two issues here: one is that as a matter of
> shorthand, compressing "language which supports latent typing" to
> "latently-typed language" ought to be fine, as long as the term's
> meaning is understood.

If, for the sake of argument, "language which supports latent typing" is
to be compressed to "latently-typed language", then statically typed
languages must be considered also latently typed.

After all, statically typed languages support expression and
verification of the "types in the programmer's head" at least as well
as non-(statically-typed) languages do. In particular, most recent
statically typed OO languages use dynamic tagging and are memory safe.
And they support comments ;-)

This is not, quite obviously, what most people mean when they say
that a particular *language* is "latently typed". They almost always
mean that the language is dynamically tagged, *not* statically typed,
and memory safe. That is how this term is used in R5RS, for example.

> But beyond that, there's an issue here about the definition of "the
> language".  When programming in a latently-typed language, a lot of
> action goes on outside the language - reasoning about static properties
> of programs that are not captured by the semantics of the language.

This is true of programming in any language.

> This means that there's a sense in which the language that the
> programmer programs in is not the same language that has a formal
> semantic definition.  As I mentioned in another post, programmers are
> essentially mentally programming in a richer language - a language which
> has informal (static) types - but the code they write down elides this
> type information, or else puts it in comments.

If you consider stuff that might be in the programmer's head as part
of the program, where do you stop? When I maintain a program written
by someone I've never met, I have no idea what was in that programmer's
head. All I have is comments, which may be (and frequently are,
unfortunately) inaccurate.

(Actually, it's worse than that -- if I come back to a program 5 years
later, I probably have little idea what was in my head at the time I
wrote it.)

> We have to accept, then, that the formal semantic definitions of
> dynamically-checked languages are incomplete in some important ways.
> Referring to those semantic definitions as "the language", as though
> that's all there is to the language in a broader sense, is misleading.

Bah, humbug. The language is just the language.

> In this context, the term "latently-typed language" refers to the
> language that a programmer experiences, not to the subset of that
> language which is all that we're typically able to formally define.

I'm with Marshall -- this is way too mystical for me.

-- 
David Hopwood <[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Saying "latently-typed language" is making a category mistake

2006-06-24 Thread David Hopwood
Pascal Costanza wrote:
> Vesa Karvonen wrote:
> 
>> I think that we're finally getting to the bottom of things.  While
>> reading your reponses something became very clear to me: latent-typing and
>> latent-types are not a property of languages.  Latent-typing, also known as
>> informal reasoning, is something that all programmers do as a normal part
>> of programming.  To say that a language is latently-typed is to make a
>> category mistake, because latent-typing is not a property of languages.
> 
> I disagree with you and agree with Anton. Here, it is helpful to
> understand the history of Scheme a bit: parts of its design are a
> reaction to what Schemers perceived as having failed in Common Lisp (and
> other previous Lisp dialects).
> 
> One particularly illuminating example is the treatment of nil in Common
> Lisp. That value is a very strange beast in Common Lisp because it
> stands for several concepts at the same time: most importantly the empty
> list and the boolean false value. Its type is also "interesting": it is
> both a list and a symbol at the same time. It is also "interesting" that
> its quoted value is equivalent to the value nil itself. This means that
> the following two forms are equivalent:
> 
> (if nil 42 4711)
> (if 'nil 42 4711)
> 
> Both forms evaluate to 4711.
> 
> It's also the case that taking the car or cdr (first or rest) of nil
> doesn't give you an error, but simply returns nil as well.
> 
> The advantage of this design is that it allows you to express a lot of
> code in a very compact way. See
> http://www.apl.jhu.edu/~hall/lisp/Scheme-Ballad.text for a nice
> illustration.
> 
> The disadvantage is that it is mostly impossible to have a typed view of
> nil, at least one that clearly disambiguates all the cases. There are
> also other examples where Common Lisp conflates different types, and
> sometimes only for special cases. [1]
> 
> Now compare this with the Scheme specification, especially this section:
> http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-6.html#%25_sec_3.2
> 
> This clearly deviates strongly from Common Lisp (and other Lisp
> dialects). The emphasis here is on a clear separation of all the types
> specified in the Scheme standard, without any exception. This is exactly
> what makes it straightforward in Scheme to have a latently typed view of
> programs, in the sense that Anton describes. So latent typing is a
> property that can at least be enabled / supported by a programming
> language, so it is reasonable to talk about this as a property of some
> dynamically typed languages.

If anything, I think that this example supports my and Vesa's point.
The example demonstrates that languages
*that are not distinguished in whether they are called latently typed*
support informal reasoning about types to varying degrees.

-- 
David Hopwood <[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Termination and type systems

2006-06-24 Thread David Hopwood
Marshall wrote:
> David Hopwood wrote:
> 
>>A type system that required an annotation on all subprograms that do not
>>provably terminate, OTOH, would not impact expressiveness at all, and would
>>be very useful.
> 
> Interesting. I have always imagined doing this by allowing an
> annotation on all subprograms that *do* provably terminate. If
> you go the other way, you have to annotate every function that
> uses general recursion (or iteration if you swing that way) and that
> seems like it might be burdensome.

Not at all. Almost all subprograms provably terminate (with a fairly
easy proof), even if they use general recursion or iteration.

If it were not the case that almost all functions provably terminate,
then the whole idea would be hopeless. If a subprogram F calls G, then
in order to prove that F terminates, we probably have to prove that G
terminates. Consider a program where only half of all subprograms are
annotated as provably terminating. In that case, we would be faced with
very many cases where the proof cannot be discharged, because an
annotated subprogram calls an unannotated one.

If, on the other hand, more than, say, 95% of subprograms provably
terminate, then it is much more likely that we (or the inference
mechanism) can easily discharge any particular proof involving more
than one subprogram. So provably terminating should be the default,
and other cases should be annotated.

In some languages, annotations may never or almost never be needed,
because they are implied by other characteristics. For example, the
concurrency model used in the language E (www.erights.org) is such
that there are implicit top-level event loops which do not terminate
as long as the associated "vat" exists, but handling a message is
always required to terminate.

> Further, it imposes the
> annotation requirement even where the programer might not
> care about it, which the reverse does not do.

If the annotation marks not-provably-terminating subprograms, then it
calls attention to those subprograms. This is what we want, since it is
less safe/correct to use a nonterminating subprogram than a terminating
one (in some contexts).

There could perhaps be a case for distinguishing annotations for
"intended not to terminate", and "intended to terminate, but we
couldn't prove it".

I do not know how well such a type system would work in practice; it may
be that typical programs would involve too many non-trivial proofs. This
is something that would have to be tried out in a research language.

-- 
David Hopwood <[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 2Qs

2006-06-24 Thread bearophileHUGS
SuperHik, for the second question there is builtin sum():

>>> values = 10.5, 5, -12
>>> sum(values)
3.5

Your if becomes:

if x>10 and y>10 and z>10 and sum(tritup(x,y,z)):
print "OK"

Bye,
bearophile

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


Re: puzzlement about classmethod

2006-06-24 Thread Duncan Booth
Faheem Mitha wrote:

> Nearly everything behaves the way I would expect, except that setting
> x to 12 in A using class_setx at the beginning also sets the value for
> x in B. However, the converse (setting x in B using class_setx), does
> not change the value in A, which I would consider to be the expected
> behavior.
> 
> However, after that the two x variables appear to behave
> independently. Can anyone explain to me why this is so?

When you access a class variable B.x before it has been set in B then you 
see the value from the base class (A.x). Once you have set a separate value 
in the subclass that takes precedence.

Similarly accessing an instance variable b.x first looks in the instance 
(b), then in the class (B), then in the base class or classes (here A). The 
lookup stops as soon as it finds a value in any of these locations.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is Expressiveness in a Computer Language

2006-06-24 Thread Chris Smith
Chris F Clark <[EMAIL PROTECTED]> wrote:
> Chris Smith <[EMAIL PROTECTED]> writes: 
> > I thought about this in the context of reading Anton's latest post to
> > me, but I'm just throwing out an idea. 
>  
> I wrote:
> > I think there is some sense of convergence here.
> 
> Apologies for following-up to my own post, but I forgot to describe
> the convergence.
> 
> The convergence is there is something more general that what type
> theorists talk about when discussing types.  Type theory is an
> abstraction and systemization of reasoning about types.  This more
> general reasoning doesn't need to be sound, it just needs to be based
> aound "types" and computations.

Unfortunately, I have to again reject this idea.  There is no such 
restriction on type theory.  Rather, the word type is defined by type 
theorists to mean the things that they talk about.  Something becomes a 
type the instant someone conceives of a type system that uses it.  We 
could try to define a dynamic type system, as you seem to say, as a 
system that checks against only what can be known about some ideal type 
system that would be able to prove the program valid... but I 
immediately begin to wonder if it would ever be possible to prove that 
something is a dynamic type system for a general-purpose (Turing-
complete) language.

If you could define types for a dynamic type system in some stand-alone 
way, then this difficulty could be largely pushed out of the way, 
because we could say that anything that checks types is a type system, 
and then worry about verifying that it's a sound type system without 
worrying about whether it's a subset of the perfect type system.  So 
back to that problem again.

You also wrote:
> I consider any case where a program gives a function outside of its
> domain a "type error", because an ideal (but unacheivable) type system
> would have prevented it.  That does not make all errors, type errors,
> because if I give a program an input within its domain and it
> mis-computes the result, that is not a type error.

So what is the domain of a function?  (Heck, what is a function?  I'll 
neglect that by assuming that a function is just an expression; 
otherwise, this will get more complicated.)  I see three possible ways 
to look at a domain.

(I need a word here that implies something like a set, but I don't care 
to verify the axioms of set theory.  I'm just going to use set.  Hope 
that's okay.)

1. The domain is the set of inputs to that expression which are going to 
produce a correct result.

2. The domain is the set of inputs that I expected this expression to 
work with when I wrote it.

3. The domain is the set of inputs for which the expression has a 
defined result within the language semantics.

So the problem, then, more clearly stated, is that we need something 
stronger than #3 and weaker than #1, but #2 includes some psychological 
nature that is problematic to me (though, admittedly, FAR less 
problematic than the broader uses of psychology to date.)

Is that a fair description of where we are in defining types, then?

-- 
Chris Smith - Lead Software Developer / Technical Trainer
MindIQ Corporation
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is Expressiveness in a Computer Language

2006-06-24 Thread Chris F Clark
Chris Smith <[EMAIL PROTECTED]> writes: 
 
> I thought about this in the context of reading Anton's latest post to
> me, but I'm just throwing out an idea. 
 
I wrote:
> I think there is some sense of convergence here.

Apologies for following-up to my own post, but I forgot to describe
the convergence.

The convergence is there is something more general that what type
theorists talk about when discussing types.  Type theory is an
abstraction and systemization of reasoning about types.  This more
general reasoning doesn't need to be sound, it just needs to be based
aound "types" and computations.

My own reasoning uses such an unsound system.  It has clear roots in
sound reasoning, and I wish I could make it sound, but

In any case, dynamic tagging helps support my unsound reasoning by
providing evidence when I have made an error.

I hope this makes it less mystical for Marshall.

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


Re: What is Expressiveness in a Computer Language

2006-06-24 Thread Anton van Straaten
Marshall wrote:
> Anton van Straaten wrote:
> 
>>But beyond that, there's an issue here about the definition of "the
>>language".  When programming in a latently-typed language, a lot of
>>action goes on outside the language - reasoning about static properties
>>of programs that are not captured by the semantics of the language.
>>
>>This means that there's a sense in which the language that the
>>programmer programs in is not the same language that has a formal
>>semantic definition.  As I mentioned in another post, programmers are
>>essentially mentally programming in a richer language - a language which
>>has informal (static) types - but the code they write down elides this
>>type information, or else puts it in comments.
>>
>>We have to accept, then, that the formal semantic definitions of
>>dynamically-checked languages are incomplete in some important ways.
>>Referring to those semantic definitions as "the language", as though
>>that's all there is to the language in a broader sense, is misleading.
>>
>>In this context, the term "latently-typed language" refers to the
>>language that a programmer experiences, not to the subset of that
>>language which is all that we're typically able to formally define.
> 
> 
> That is starting to get a bit too mystical for my tastes.

It's informal, but hardly mystical.  The formal semantic definitions of 
dynamically-checked languages I'm referring to are the typical "untyped" 
definitions, in which the language has a single static type.

This means that when you as a programmer see a function that you "know" 
e.g. takes a number and returns a number, that knowledge is not 
something that's captured by the language's formal semantics or static 
type system.  All that can be expressed in the language's static type 
system is that the function takes a value and returns a value.

When you're programming in your favorite dynamically-typed language, 
I'll bet that you're not thinking of functions, or other expressions, in 
such a restricted way.  Your experience of programming in the language 
thus relies heavily on features that are not a "property of the 
language", if "the language" is taken to mean its formal semantic 
definition.

So in referring to a language as latently-typed, the word "language" can 
be taken to mean what a programmer thinks of as the language, rather 
than a formal definition that only captures a subset of what the 
programmer routinely deals with.

If we don't acknowledge this distinction between the part of the 
language that we can capture formally and the part that we haven't 
(yet), then we'll be forever stuck without accepted terminology for the 
informal bits, because such terminology can always be objected to on the 
grounds that it isn't supported by formal semantics.

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


puzzlement about classmethod

2006-06-24 Thread Faheem Mitha
Hi,

Consider the following small script.

My understanding of how this works is that, conceptually, class B
holds a separate copy of variable x from class A.

Nearly everything behaves the way I would expect, except that setting
x to 12 in A using class_setx at the beginning also sets the value for
x in B. However, the converse (setting x in B using class_setx), does
not change the value in A, which I would consider to be the expected
behavior.

However, after that the two x variables appear to behave
independently. Can anyone explain to me why this is so?

   Regards, Faheem Mitha.

**
#!/usr/bin/python

class A(object):
x = 0
def class_getx(cls):
return cls.x
class_getx = classmethod(class_getx)
def class_setx(cls, _x):
cls.x = _x
class_setx = classmethod(class_setx)
def getx(self):
return type(self).x
def setx(self, _x):
type(self).x = _x

class B(A):
pass

def printx():
print "*** begin printing values of x... ***"
print "Fetching from A using class_getx gives %s"%(A.class_getx())
print "Fetching from B using class_getx gives %s"%(B.class_getx())
print "Fetching from A using instance a and getx gives %s"%(a.getx())
print "Fetching from B using instance b and getx gives %s"%(b.getx())
print "*** end printing values of x... ***"

a = A()
b = B()
printx()
print "setting x to 12 in A using class_setx"; A.class_setx(12)
printx()
print "setting x to 15 in B using class_setx"; B.class_setx(15)
printx()
print "setting x to 10 in A using class_setx"
A.class_setx(10)
printx()
print "setting x to 44 in A using instance a and setx"; a.setx(55)
printx()
print "setting x to 22 in B using instance b and setx"; b.setx(22)
printx()
-- 
http://mail.python.org/mailman/listinfo/python-list


2Qs

2006-06-24 Thread SuperHik
1st question:

If a make an exe with i.e. py2exe, can I get any kind of error/bug 
report from the exe file saved into a file error.log and how?

2nd question:

is there a better way to do this:


def tritup(x,y,z):
#here is a while loop giving 3 results, i.e. r1,r2,r3
return r1,r2,r3

#I want to put sum of r1,r2,r3 as a condition in if statement
#so I created a function to do this, but I can't escape a feeling
#there is a more elegant solution, especially in python ;=)

def summm(a,b,c):
return a+b+c

if x>10 and y>10 and z>10 and summ(tritup(x,y,z)): print "OK"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is Expressiveness in a Computer Language

2006-06-24 Thread Pascal Costanza
Marshall wrote:
> Anton van Straaten wrote:
>> But beyond that, there's an issue here about the definition of "the
>> language".  When programming in a latently-typed language, a lot of
>> action goes on outside the language - reasoning about static properties
>> of programs that are not captured by the semantics of the language.
>>
>> This means that there's a sense in which the language that the
>> programmer programs in is not the same language that has a formal
>> semantic definition.  As I mentioned in another post, programmers are
>> essentially mentally programming in a richer language - a language which
>> has informal (static) types - but the code they write down elides this
>> type information, or else puts it in comments.
>>
>> We have to accept, then, that the formal semantic definitions of
>> dynamically-checked languages are incomplete in some important ways.
>> Referring to those semantic definitions as "the language", as though
>> that's all there is to the language in a broader sense, is misleading.
>>
>> In this context, the term "latently-typed language" refers to the
>> language that a programmer experiences, not to the subset of that
>> language which is all that we're typically able to formally define.
> 
> That is starting to get a bit too mystical for my tastes.

To paraphrase Abelson & Sussman: Programs must be written for people to 
read, and only incidentally for compilers to check their types.

;)


Pascal

-- 
3rd European Lisp Workshop
July 3 - Nantes, France - co-located with ECOOP 2006
http://lisp-ecoop06.bknr.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is Expressiveness in a Computer Language

2006-06-24 Thread Chris F Clark
Chris Smith <[EMAIL PROTECTED]> writes: 
 
> I thought about this in the context of reading Anton's latest post to
> me, but I'm just throwing out an idea. 
 
I think there is some sense of convergence here.  In particular, I 
reason about my program using "unsound types".  That is, I reason 
about my program using types which I can (at least partially) 
formalize, but for which there is no sound axiomatic system.  Now, 
these types are locally sound, i.e. I can prove properties that hold 
for regions of my programs.  However, the complexity of the programs 
prevent me from formally proving the entire program is correct (or 
even entirely type-safe)--I generally work in a staticly, but 
weakly-typed language.  Sometimes, for performance reasons, the rules
need to be bent--and the goal is to bend the rules, but not break 
them.  At other times, I want to strenghten the rules, make parts of 
the program more provably correct.
 
How does this work in practice?  Well, there is a set of ideal types, 
I would like to use in my program.  Those types would prove that my 
program is correct.  However, because there are parts of the program 
that for perfomnace reasons need me to widen the ideal types to 
something less tight, pragmatic types.  The system can validate that I 
have not broken the pragmatic types.  That is not tight enough to 
prove the program correct, but it provides some level of security.
 
To improve my confidence in the program, I borrow the tagging concept 
to supplement the static type system.  At key points in the program I 
can check the type tag to ensure that the data being manipulated 
actual matches the unprovable ideal type system.  If it doesn't, I 
have a witness to the error in my reasoning.  It is not perfect, but 
it is better than nothing.
 
Why am I in this state, because I believe that most interesting
programs are beyond my ability to formally prove them, or at least
prove them in "reasonable" time bounds.  Therefore, I prove
(universally quantify) some properties of my programs, but many other
(and most of the "interesting") properties, I can only existentially
quantify--it worked in the cases that it was tested on.  It is a
corrolary of this, that most programs have bugs--places where the
formal reasoning was incomplete (did not reason down to relevant
interesting property) and the informal reasoning was wrong.

Thus, the two forms of reasoning, static typing to check the formal
properties that it can, and dynamic tagging to catch the errors that
it missed work like a belt and suspenders system.  I would like the
static type system to catch more errors, but I need it to express more
to do so, and many of the properties that are interesting require
n-squared operations to validate.  Equally important, the dynamic tags
help when working in an essentially untrustworthy world.  Not only do
our own programs have bugs, so do the systems we run them on, both
hardware and software.  Moreover, alpha radiation and quantum effects
can change "constants" in a program (some of my work has to do with
soft-error rates on chips where we are trying to guarantee that the
chip will have a reasonable MBTF for certain algorithms).  That's not
to ignore the effects of malware and other ways your program can be
made less reliable.

Yes, I want a well-proven program, but I also want some guarantee that
the program is actually executing the algorithm specified.  That
requires a certain amount of "redundant" run-time checks.  Knuth had a
quote about a program only being proven and not tested that reflects
the appropriate cynicism.

I consider any case where a program gives a function outside of its
domain a "type error", because an ideal (but unacheivable) type system
would have prevented it.  That does not make all errors, type errors,
because if I give a program an input within its domain and it
mis-computes the result, that is not a type error.

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


Re: Python to PHP Login System (HTTP Post)

2006-06-24 Thread test
On Sat, 24 Jun 2006 01:28:29 GMT, [EMAIL PROTECTED] (John J. Lee)
wrote:

>[EMAIL PROTECTED] writes:
>
>> On 22 Jun 2006 16:19:50 -0700, "Justin  Azoff"
>> <[EMAIL PROTECTED]> wrote:
>> 
>> >Jeethu Rao wrote:
>> >> You need to use httplib.
>> >> http://docs.python.org/lib/httplib-examples.html
>> >>
>> >> Jeethu Rao
>> >
>> >Not at all.  They need to read the documentation for urrlib:
>> >
>> >http://docs.python.org/lib/module-urllib.html
>> >http://docs.python.org/lib/node483.html
>> >"The following example uses the "POST" method instead:"
>> >
>> >Additionally, they probably need to use cookielib, otherwise the logged
>> >in state will not be persistant.
>
>Or you may not be able to log in at all, for an everyday meaning of
>"log in".
>
>
>> Here's what's strange... I tried using urllib like this:
>> --
>> try:
>>  msparams = urllib.urlencode({'user':
>> self.components.User.text, 'pass':
>> self.components.MagnetSharePassword.text, 'sublogin': 1})
>>   f = urllib.urlopen("http://www.magnetshare.com/process.php";,
>> msparams)
>>  fc = f.read()
>>  fc.close()
>>  print fc
>> except:
>>  self.statusBar.text = "Disconnected"
>>  result = dialog.alertDialog(self, 'Couldn\'t connect to
>> MagnetShare.com! Please check your Internet connection, and then try
>> again.')
>> else:
>>  print fc
>> ---
>> ...and then I visited http://www.magnetshare.com/main.php to see if I
>> was logged in. Sure enough I was logged in, but the exception was
>
>That's not how it works (assuming you visited that URL in a browser,
>not using Python).  The "logged-in-ness" comes from a "session ID"
>cookie that is stored in your browser (or in your Python code).  The
>server sends a cookie when you log in (and usually stores your cookie
>in a database).  The browser keeps the cookie.  When you come back
>later using the same browser (maybe even after you've closed the
>browser, if it's the right kind of cookie), your browser sends the
>cookie back and the server looks up the session ID from that cookie in
>the database, and sees it's you.
>
>If you come back using a different browser (and your Python program is
>effectively just a different browser than your copy of Firefox or IE
>or whatever), then the server won't remember who you are, so you're
>not logged in *in that browser session*, even if the server has you
>recorded in its database as logged in from a different browser
>session.
>
>So, the fact that you saw yourself as logged in when you looked using
>your web browser doesn't really help your Python program -- it's still
>out in the cold.
>
>
>> thrown anyway. I commented out the urlopen, f, and fc  lines and
>> tested it again. This time I made it to "else:"
>> 
>> I'm stumped. I'm glad that the user can log in; however, the
>> MagnetShare application needs to read in the response from the server,
>> and then decide what to do with the information.
>
>Here's one way:
>
>easy_install mechanize
>
>(install easy_install first if you don't have that:
>
>http://peak.telecommunity.com/DevCenter/EasyInstall#installing-easy-install
>
>)
>
>#---
>import mechanize
>
>SHOW_COOKIES = True
>
>br = mechanize.Browser()
>if SHOW_COOKIES:
>cj = mechanize.CookieJar()
>br.set_cookiejar(cj)
>br.open("http://www.magnetshare.com/main.php";)
>br.select_form(nr=0)
>br["user"] = "joe"
>br["pass"] = "password"
>r = br.submit()
>assert "Logged In" in r.get_data()
>if SHOW_COOKIES:
>for cookie in cj:
>print cj
>#---
>
>
>(note the cookiejar is always there; you only need to create one and
>pass it in in order to get at it to e.g. print out the cookies you've
>collected)
>
>
>John

Thanks a lot John! This "mechanize" was exactly what I was looking
for. There are some key improvements over urllib2 and also, cookies
are turned on by default.

Just an FYI for others, PHP can set $SESSIONID when the user refuses
cookies. I haven't decided whether the application will use cookies or
not, but luckily I got the login page response I was looking for. Now,
I just parse the HTML using Python, and then go to the next screen in
the MagnetShare application.

Here's the test code I used.
---
import mechanize

br = mechanize.Browser()
br.open("http://www.magnetshare.com/main.php";)
br.select_form(nr=0)
br["user"] = "test2"
br["pass"] = "test2"
response1 = br.submit()
fc = response1.read()
print fc


Cheers!

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


Re: Saying "latently-typed language" is making a category mistake

2006-06-24 Thread Marshall
Gabriel Dos Reis wrote:
> "Marshall" <[EMAIL PROTECTED]> writes:
>
> | David Hopwood wrote:
> | >
> | > A type system that required an annotation on all subprograms that do not
> | > provably terminate, OTOH, would not impact expressiveness at all, and 
> would
> | > be very useful.
> |
> | Interesting. I have always imagined doing this by allowing an
> | annotation on all subprograms that *do* provably terminate. If
> | you go the other way, you have to annotate every function that
> | uses general recursion (or iteration if you swing that way) and that
> | seems like it might be burdensome. Further, it imposes the
> | annotation requirement even where the programer might not
> | care about it, which the reverse does not do.
>
> simple things should stay simple.  Recursions that provably terminate
> are among the simplest ones.  Annotations in those cases could be
> allowed, but not required.  Otherwise the system might become very
> irritating to program with.

Yes, exactly my point.


Marshall

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


Re: Saying "latently-typed language" is making a category mistake

2006-06-24 Thread Gabriel Dos Reis
"Marshall" <[EMAIL PROTECTED]> writes:

| David Hopwood wrote:
| >
| > A type system that required an annotation on all subprograms that do not
| > provably terminate, OTOH, would not impact expressiveness at all, and would
| > be very useful.
| 
| Interesting. I have always imagined doing this by allowing an
| annotation on all subprograms that *do* provably terminate. If
| you go the other way, you have to annotate every function that
| uses general recursion (or iteration if you swing that way) and that
| seems like it might be burdensome. Further, it imposes the
| annotation requirement even where the programer might not
| care about it, which the reverse does not do.

simple things should stay simple.  Recursions that provably terminate
are among the simplest ones.  Annotations in those cases could be
allowed, but not required.  Otherwise the system might become very
irritating to program with.

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


Re: Saying "latently-typed language" is making a category mistake

2006-06-24 Thread Marshall
David Hopwood wrote:
>
> A type system that required an annotation on all subprograms that do not
> provably terminate, OTOH, would not impact expressiveness at all, and would
> be very useful.

Interesting. I have always imagined doing this by allowing an
annotation on all subprograms that *do* provably terminate. If
you go the other way, you have to annotate every function that
uses general recursion (or iteration if you swing that way) and that
seems like it might be burdensome. Further, it imposes the
annotation requirement even where the programer might not
care about it, which the reverse does not do.


Marshall

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


Re: What is Expressiveness in a Computer Language

2006-06-24 Thread Marshall
Anton van Straaten wrote:
>
> But beyond that, there's an issue here about the definition of "the
> language".  When programming in a latently-typed language, a lot of
> action goes on outside the language - reasoning about static properties
> of programs that are not captured by the semantics of the language.
>
> This means that there's a sense in which the language that the
> programmer programs in is not the same language that has a formal
> semantic definition.  As I mentioned in another post, programmers are
> essentially mentally programming in a richer language - a language which
> has informal (static) types - but the code they write down elides this
> type information, or else puts it in comments.
>
> We have to accept, then, that the formal semantic definitions of
> dynamically-checked languages are incomplete in some important ways.
> Referring to those semantic definitions as "the language", as though
> that's all there is to the language in a broader sense, is misleading.
>
> In this context, the term "latently-typed language" refers to the
> language that a programmer experiences, not to the subset of that
> language which is all that we're typically able to formally define.

That is starting to get a bit too mystical for my tastes.


Marshall

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


Re: Python and cellular automata (It works this time!)

2006-06-24 Thread defcon8
blog-of-justin.blogspot.com

Sorry for the error.

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


Re: Kamaelia 0.4.0 RELEASED - Faster! More Tools! More Examples! More Docs! ; -)

2006-06-24 Thread Michael
Robin Becker wrote:
> Michael wrote:
>> I'm extremely pleased to say - Kamaelia 0.4.0 has been released!
> Windows users might see problems with the attempt at importing libc.so.6
> in the Axon Scheduler.
> 
> I changed the lines at line 44 of scheduler.py to something like this
[ .. patch .. ]

Many thanks!

Yes, this issue has also been raised on the Kamaelia mailing list in the
past couple of days by Stefan Rank (he had a solution based on using
win32.Sleep(0,0) which calls SleepEx[1]). I'm planning on an Axon 1.5.1
release shortly to deal with this issue.
   [1] 
http://www-128.ibm.com/developerworks/eserver/library/es-MigratingWin32toLinux.html?ca=dgr-lnxw09CPP2LinuxPower#N10364

I've got three options - I can either take the approach you've suggested,
the approach suggested on the list (which is to call win32.Sleep(0,0), or
actually remove this code from the scheduler completely. 

I'm actually most tempted by the final option, largely because this code
was added in an earlier release as a way of making Axon & the scheduler
more system friendly. Since we've now effectively gone from a busy wait
loop to a scheduler that /can/ sleep waiting for threads [2] this means
that code can be a lot more system friendly by default.

   [2] For example, rather than calling select with a timeout of zero in the
   main thread, it's now called with a timeout of 5s in a thread, which
   wakes up the scheduler when there's something to do. The pygame code
   does the same trick...

That said, there is still whole chunks of code that busy run (such as the
physics simulation, so I'm torn. Do I take the code you put forward, the
solution put forward on the the list which I can't really check (since I
don't have a windows box to test with right now (I will on Monday though)),
or yank it out.

I suppose the "correct" thing is to put your solution into Axon 1.5.1 - to
get rid of the failure, and then to test Stefan's solution locally. My
hesitation with regard to Stefan's solution is simply the fact that I
don't tend to do a huge amount of coding under windows, and hence have
greater concern there as a result.

I'll get a release out with that fix either today or tomorrow, and then
roll up Stefan's more detailed fix into the 1.5.2 release along with
anything else that crops up over the next few days (hopefully nothing,
but you never know).

> This allows  somethings to run eg
> 
> AxonVisualiser.py --navelgaze
> 
> but I'm not sure if the results are really unaffected by not having a
> real yielder. The diagram appears, but doesn't seem to settle down.

I don't think the AxonVisualiser would be particularly affected by
this - any wobbling you'll see there is probably more down to the
simple physics model the visualiser uses not having sufficient
dampening for the layout you see. (The physics model was apparently
originally written by Matt for a lava lamp simulator, but has turned
out to be incredibly useful as a simple layout tool :-)

A little bit of manual assistance to spread things out can sometimes
help it settle down though :)

> whoops, forgot to say thanks as I think this is very nice work

You're very welcome. If you have any other suggestions/ideas for
improvement they'd be very welcome :-)

Personally, I think some of the most fun stuff right now being done by
new people with it is coming from 2 of our summer of code students. One,
Thomas, is working on 3D components (eg putting pygame components into a
PyOpenGL display). 

The other is doing bittorrent related work, but has also written a webserver
and IRC bot - both pretty much from scratch (at the protocol level) over
the past month. (The other two students are working on encryption ideas for
tools for communications - eg encrypted VoIP type things)

Thomas's work (3D) is discussed here: http://thfsoc.blogspot.com/
Ryan's code (Bit Torrent, webserver/client, IRC bot) is sitting here:
   * http://kamaelia.cvs.sourceforge.net/kamaelia/Sketches/RJL/

Thanks for the bug fix/kind words!

Regards,


Michael.

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


Re: PyGTK and Py2Exe troubles

2006-06-24 Thread Tim N. van der Leeuw

[EMAIL PROTECTED] wrote:
> Tim N. van der Leeuw ha scritto:
>
> > I tried to create a windows executable of a pygtk program. My first
> > attempt worked, kinda, except that no themes were applied and no
> > readable fonts were found by pango; so all letters where just empty
> > squares. But the program worked.
> >
> > I looked up some docs, found the following recipe on the PyGTK Wiki
> > site:
> > http://starship.python.net/crew/theller/moin.cgi/Py2exeAndPyGTK
> >
> > I followed those instructions to convert my setup.py file; everything
> > still worked the same as before.
>
> versions of python,gtk,pygtk? wich windows?
> wich installer of gtk have you used?
> did you install pycairo too?
>
> try again with these one, if different from yours
> gtk -> http://gladewin32.sourceforge.net
> pygtk/pycairo  -> http://www.mapr.ucl.ac.be/~gustin/win32_ports/
>
> bye,
> Riccardo

Riccardo,

Thanks for your reply; sorry for omitting all the relevant details!

Python: 2.4.3 from python.org
Windows XP SP2
GTK 2.8.18 from gladewin32
pygtk & pycairo from Gustin's ports.
py2exe: 0.6.5

The program works when run under the interpreter; but crashes when
using py2exe and all shared files mentioned, are copied to the same dir
as the exe. (When I don't copy all those files, pango complains about
missing fonts and shows only empty squares for all leters. but the
program doesn't crash. It only crashes when GTK's shared files are with
the program)

Thanks,

--Tim

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


Re: What is Expressiveness in a Computer Language

2006-06-24 Thread Anton van Straaten
David Hopwood wrote:
> Anton van Straaten wrote:
...
>>When you get to more complex cases, though, most type inferencers for
>>Scheme assign traditional static-style types to terms.  If you think
>>about this in conjunction with the term "latent types", it's an obvious
>>connection to make that what the inferencer is doing is recovering types
>>that are latent in the source.
> 
> 
> But these types are not part of the Scheme language. If you combine Scheme
> with a type inferencer, you get a new language that is not R*RS Scheme,
> and *that* language is typed.

Sure.  So one obvious question, as I've just observed in another reply 
to you, is which language programmers actually program in.  I'd say that 
they certainly don't program in the completely untyped language as 
defined by RnRS.

> Note that different inferencers will give different type assignments.
> They may be similar, but they may also be quite dissimilar in some cases.
> This casts considerable doubt on the assertion that the inferencer is
> "recovering types latent in the source".

I mentioned this earlier, in a reply to Marshall where I gave an 
informal definition of latent typing, which read in part: "Terms in the 
program may be considered as having static types, and it is possible to 
infer those types, but it isn't necessarily easy to do so automatically, 
and there are usually many possible static type schemes that can be 
assigned to a given program."

As far as the term "recovering" goes, that perhaps shouldn't be taken 
too literally.  It's clearly not the case that a latently-typed program 
has a single formalizable type scheme which was put there deliberately 
by the programmer.  But programmers do reason about things like the 
types of functions and expressions, and the goal of soft type 
inferencers is to find an approximation to what the programmer intended.

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


Re: PyGTK and Py2Exe troubles

2006-06-24 Thread riquito

Tim N. van der Leeuw ha scritto:

> I tried to create a windows executable of a pygtk program. My first
> attempt worked, kinda, except that no themes were applied and no
> readable fonts were found by pango; so all letters where just empty
> squares. But the program worked.
>
> I looked up some docs, found the following recipe on the PyGTK Wiki
> site:
> http://starship.python.net/crew/theller/moin.cgi/Py2exeAndPyGTK
>
> I followed those instructions to convert my setup.py file; everything
> still worked the same as before.

versions of python,gtk,pygtk? wich windows?
wich installer of gtk have you used?
did you install pycairo too?

try again with these one, if different from yours
gtk -> http://gladewin32.sourceforge.net
pygtk/pycairo  -> http://www.mapr.ucl.ac.be/~gustin/win32_ports/

bye,
Riccardo

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


Re: Saying "latently-typed language" is making a category mistake

2006-06-24 Thread David Hopwood
Patricia Shanahan wrote:
> Vesa Karvonen wrote:
> ...
> 
>> An example of a form of informal reasoning that (practically) every
>> programmer does daily is termination analysis.  There are type systems
>> that guarantee termination, but I think that is fair to say that it is
>> not yet understood how to make a practical general purpose language, whose
>> type system would guarantee termination (or at least I'm not aware of
>> such a language).  It should also be clear that termination analysis need
>> not be done informally.  Given a program, it may be possible to formally
>> prove that it terminates.
> 
> To make the halting problem decidable one would have to do one of two
> things: Depend on memory size limits, or have a language that really is
> less expressive, at a very deep level, than any of the languages
> mentioned in the newsgroups header for this message.

I don't think Vesa was talking about trying to solve the halting problem.

A type system that required termination would indeed significantly restrict
language expressiveness -- mainly because many interactive processes are
*intended* not to terminate.

A type system that required an annotation on all subprograms that do not
provably terminate, OTOH, would not impact expressiveness at all, and would
be very useful. Such a type system could work by treating some dependent
type parameters as variants which must strictly decrease in a recursive
call or loop. For example, consider a recursive quicksort implementation.
The type of the 'sort' routine would take an array of length
(dependent type parameter) n. Since it only performs recursive calls to
itself with parameter strictly less than n, it is not difficult to prove
automatically that the quicksort terminates. The programmer would probably
just have to give hints in some cases as to which parameters are to be
treated as variants; the rest can be inferred.

-- 
David Hopwood <[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: subprocess.Popen on Windows

2006-06-24 Thread mmamsch
On 23.06.2006 23:12:02, "3c273" wrote:
>"madpython" <[EMAIL PROTECTED]> wrote in message
>news:[EMAIL PROTECTED]
>> playing with subprocess.Popen on Windows I stumbled into the following
>> problem:
>> Python 2.4.3 (#69, Mar 29 2006, 17:35:34)
>>
>> IDLE 1.1.3
>>
>> >>> import subprocess
>> >>> p1=subprocess.Popen("c:\\asd.bat") #works OK
>> >>> p2=subprocess.Popen("c:\\asd.bat",stdout=subprocess.PIPE)
>>
>> Traceback (most recent call last):
>>   File "", line 1, in -toplevel-
>> p2=subprocess.Popen("c:\\asd.bat",stdout=subprocess.PIPE)
>>   File "C:\Python24\lib\subprocess.py", line 533, in __init__
>> (p2cread, p2cwrite,
>>   File "C:\Python24\lib\subprocess.py", line 593, in _get_handles
>> p2cread = self._make_inheritable(p2cread)
>>   File "C:\Python24\lib\subprocess.py", line 634, in _make_inheritable
>> DUPLICATE_SAME_ACCESS)
>> TypeError: an integer is required
>> >>>
>> What do I do wrongly?
>>
>I get the same thing. This only happens when using IDLE. From a command
>prompt, everthing works as expected. Hopefully somebody else will know why.
>Louis
>
>

I think IDLE replaces the sys.stdin and sys.stdout by a class to redirect IO.
So when using IDLE stdin and stdout are not integer handles anymore.

Greetings, Mathias
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is Expressiveness in a Computer Language

2006-06-24 Thread Anton van Straaten
Chris Smith wrote:
> Dr.Ruud <[EMAIL PROTECTED]> wrote:
...
>>The 'dynamic type' is just another type.
> 
> 
> That's essentially equivalent to giving up.  I doubt many people would 
> be happy with the conclusion that dynamically typed languages are typed, 
> but have only one type which is appropriate for all possible operations.  

I'm not sure if this is what you're getting at, but what you've written 
is precisely the position that type theorists take.  Having "only one 
type which is appropriate for all possible operations" is exactly what 
the term "untyped" implies.

> That type system would not be implemented, since it's trivial and 
> behaves identically to the lack of a type system, and then we're back 
> where we started.

This is why I've suggested that "untyped" can be a misleading term, when 
applied to dynamically-typed languages.

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


Re: Python and cellular automata (It works this time!)

2006-06-24 Thread Terry Reedy

"defcon8" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>I thought people would be interested in this little script I wrote to
> reproduce the 256 simple automata that is shown in the first chapters
> of "A New Kind of Science". You can see a few results without running
> the script, at http://cooper-j.blogspot.com

404 not found.  typo?






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


Re: Python and cellular automata (It works this time!)

2006-06-24 Thread bearophileHUGS
Few coding suggestions:
- Don't mix spaces and tabs;
- Don't write line (comments) too much long;
- Don't post too much code here;
- For this program maybe Pygame is more fit (to show the images in real
time) instead of PIL;
- Maybe Psyco can help speed up this program;
- Maybe ShedSkin will support part of the cimg library, such kind of
programs is fit for it :-)

Bye,
bearophile

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


Re: What is Expressiveness in a Computer Language

2006-06-24 Thread Anton van Straaten
David Hopwood wrote:
> I can accept that dynamic tagging provides some support for latent typing
> performed "in the programmer's head". But that still does not mean that
> dynamic tagging is the same thing as latent typing

No, I'm not saying it is, although I am saying that the former supports 
the latter.

> or that languages
> that use dynamic tagging are "latently typed". This simply is not a
> property of the language (as you've already conceded).

Right.  I see at least two issues here: one is that as a matter of 
shorthand, compressing "language which supports latent typing" to 
"latently-typed language" ought to be fine, as long as the term's 
meaning is understood.

But beyond that, there's an issue here about the definition of "the 
language".  When programming in a latently-typed language, a lot of 
action goes on outside the language - reasoning about static properties 
of programs that are not captured by the semantics of the language.

This means that there's a sense in which the language that the 
programmer programs in is not the same language that has a formal 
semantic definition.  As I mentioned in another post, programmers are 
essentially mentally programming in a richer language - a language which 
has informal (static) types - but the code they write down elides this 
type information, or else puts it in comments.

We have to accept, then, that the formal semantic definitions of 
dynamically-checked languages are incomplete in some important ways. 
Referring to those semantic definitions as "the language", as though 
that's all there is to the language in a broader sense, is misleading.

In this context, the term "latently-typed language" refers to the 
language that a programmer experiences, not to the subset of that 
language which is all that we're typically able to formally define.

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


Re: What is Expressiveness in a Computer Language

2006-06-24 Thread David Hopwood
Anton van Straaten wrote:
> I'm suggesting that if a language classifies and tags values in a way
> that supports the programmer in static reasoning about the behavior of
> terms, that calling it "untyped" does not capture the entire picture,
> even if it's technically accurate in a restricted sense (i.e. in the
> sense that terms don't have static types that are known within the
> language).
> 
> Let me come at this from another direction: what do you call the
> classifications into number, string, vector etc. that a language like
> Scheme does?  And when someone writes a program which includes the
> following lines, how would you characterize the contents of the comment:
> 
> ; third : integer -> integer
> (define (third n) (quotient n 3))

I would call it an informal type annotation. But the very fact that
it has to be expressed as a comment, and is not checked, means that
the *language* is not typed (even though Scheme is dynamically tagged,
and even though dynamic tagging provides *partial* support for a
programming style that uses this kind of informal annotation).

-- 
David Hopwood <[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is Expressiveness in a Computer Language

2006-06-24 Thread David Hopwood
Chris Uppal wrote:
> David Hopwood wrote:
> 
>>>But some of the advocates of statically
>>>typed languages wish to lump these languages together with assembly
>>>language a "untyped" in an attempt to label them as unsafe.
>>
>>A common term for languages which have defined behaviour at run-time is
>>"memory safe". For example, "Smalltalk is untyped and memory safe."
>>That's not too objectionable, is it?
> 
> I find it too weak, as if to say: "well, ok, it can't actually corrupt memory
> as such, but the program logic is still apt go all over the shop"...

Well, it might ;-)

(In case anyone thinks I am being pejorative toward not-statically-typed
languages here, I would say that the program logic can *also* "go all over
the shop" in a statically typed, memory safe language. To avoid this, you
need at least a language that is "secure" in the sense used in capability
systems, which is a stronger property than memory safety.)

-- 
David Hopwood <[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter modifying multiple widgets with one scrollbar

2006-06-24 Thread Simon Forman
spohle wrote:
> hi
>
> how can i modify multiple widgets with one scrollbar ?
>
> thanks in advance
>
> sven

If you're using Tkinter check out:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52266

Peace,
~Simon

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


Re: dragging with Boa Constructor

2006-06-24 Thread icebear
icebear wrote:

> There's some non-obvious trick to being able to drag widgets around on a
> frame screen using Boa Constructor.  I'd appreciate hearing from anybody
> who knows what it is.


Sem to have figured it out myself here  the REAL widgets can be
dragged, and the ones which can't seem to correspond to base classes which
you don't want to be putting on a form anyhow  Strange..
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: HTTP server

2006-06-24 Thread Simon Forman
placid wrote:
> Hi all,
>
> Ive been reading about creating a HTTP server like the one pydoc
> creates (and studying pydoc source code). What i want to know, is it
> possible to create server that creates a webpage with hyperlinks that
> communicate back to the HTTP server, where each link accessed tells the
> server to execute some arbitrary command on local machine its running
> on?
>
> Cheers

Yes.   It is possible.


Ok, seriously,  I don't know how pydoc does it, but when I need a
quick-and-dirty http server [written in python] I use something like
this:

from BaseHTTPServer import HTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler

HTTPServer(('', 8000), SimpleHTTPRequestHandler).serve_forever()

For what you're asking about you'd probably want to use the
CGIHTTPRequestHandler from the CGIHTTPServer module instead.  Check out
http://docs.python.org/lib/module-CGIHTTPServer.html

Then you'd just write one or more cgi scripts (they can be in python
IIRC) to run the commands you want.

HTH,
~Simon

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


Re: What is Expressiveness in a Computer Language

2006-06-24 Thread David Hopwood
Dr.Ruud wrote:
> Marshall schreef:
>>Rob Thorpe:
> 
>>>Can I make a type in C that can only have values between 1 and 10?
>>>How about a variable that can only hold odd numbers, or, to make it
>>>more difficult, say fibonacci numbers?
>>
>>Well, of course you can't in *C*; you can barely zip you pants with C.
>>But I believe you can do the above in C++, can't you?
> 
> You can write self-modifying code in C, so I don't see how you can not
> do that in C. ;)

Strictly speaking, you can't write self-modifying code in Standard C.

-- 
David Hopwood <[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is Expressiveness in a Computer Language

2006-06-24 Thread David Hopwood
Rob Thorpe wrote:
> Andreas Rossberg wrote:
>>Rob Thorpe wrote:
>>
>>>Its easy to create a reasonable framework.
>>
>>Luca Cardelli has given the most convincing one in his seminal tutorial
>>"Type Systems", where he identifies "typed" and "safe" as two orthogonal
>>dimensions and gives the following matrix:
>>
>>   | typed | untyped
>>---+---+--
>>safe   | ML| Lisp
>>unsafe | C | Assembler
>>
>>Now, jargon "dynamically typed" is simply untyped safe, while "weakly
>>typed" is typed unsafe.
> 
> Consider a langauge something like BCPL or a fancy assembler, but with
> not quite a 1:1 mapping with machine langauge.
> 
> It differs in one key regard: it has a variable declaration command.
> This command allows the programmer to allocate a block of memory to a
> variable.  If the programmer attempts to index a variable outside the
> block of memory allocated to it an error will occur.  Similarly if the
> programmer attempts to copy a larger block into a smaller block an
> error would occur.
> 
> Such a language would be truly untyped and "safe", that is safe
> according to many peoples use of the word including, I think, yours.
> 
> But it differs from latently typed languages like python, perl or lisp.
> In such a language there is no information about the type the variable
> stores. The programmer cannot write code to test it, and so can't
> write functions that issue errors if given arguments of the wrong type.

So the hypothetical language, unlike Python, Perl and Lisp, is not
dynamically *tagged*.

-- 
David Hopwood <[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: adad

2006-06-24 Thread Tim Golden

edoardo batini wrote:
> dvsdfvsdfvsdfvsf

Oh no. Not another question about permutations!

TJG

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


Re: PIL problems

2006-06-24 Thread Fredrik Lundh
defcon8 wrote:

> The error I get is:
> 
> Traceback (most recent call last):
>   File "realautomata.py", line 72, in ?
> nim.putdata(y)
>   File "C:\Python24\Lib\site-packages\PIL\Image.py", line 1120, in
> putdata
> self.im.putdata(data, scale, offset)
> TypeError: too many data entries

the error means that you're passing in more items than there are pixels 
in the target image.  adding

 print nim.size, len(y)

before the putdata line should help you figure out what's wrong.



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


Re: What is Expressiveness in a Computer Language

2006-06-24 Thread David Hopwood
Anton van Straaten wrote:
> [EMAIL PROTECTED] wrote:
> 
>> I very much agree with the observation that every programmer performs
>> "latent typing" in his head 
[...]
>> But I also think that "latently typed language" is not a meaningful
>> characterisation. And for the very same reason! Since any programming
>> activity involves latent typing - naturally, even in assembler! - it
>> cannot be attributed to any language in particular, and is hence
>> useless to distinguish between them. (Even untyped lambda calculus
>> would not be a counter-example. If you really were to program in it,
>> you certainly would think along lines like "this function takes two
>> chuch numerals and produces a third one".)
> 
> Vesa raised a similar objection in his post 'Saying "latently typed
> language" is making a category mistake'.  I've made some relevant
> responses to that post.
> 
> I agree that there's a valid point in the sense that latent types are
> not a property of the semantics of the languages they're associated with.
> 
> But to take your example, I've had the pleasure of programming a little
> in untyped lambda calculus.  I can tell you that not having tags is
> quite problematic.  You certainly do perform latent typing in your head,
> but without tags, the language doesn't provide any built-in support for
> it.  You're on your own.

I can accept that dynamic tagging provides some support for latent typing
performed "in the programmer's head". But that still does not mean that
dynamic tagging is the same thing as latent typing, or that languages
that use dynamic tagging are "latently typed". This simply is not a
property of the language (as you've already conceded).

-- 
David Hopwood <[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python and cellular automata (It works this time!)

2006-06-24 Thread defcon8
Sorry about the code. It seems to have been truncated. I have it hosted
at

http://xahlee.org/x/realautomata.py

Thanks to Xah Lee.

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


Re: Kamaelia 0.4.0 RELEASED - Faster! More Tools! More Examples! More Docs! ;-)

2006-06-24 Thread Robin Becker
Robin Becker wrote:
> Michael wrote:
>> Hi!
>>
>>
>> (OK, slightly silly subject line :)
>>
>> I'm extremely pleased to say - Kamaelia 0.4.0 has been released!
>>
.
whoops, forgot to say thanks as I think this is very nice work
-- 
Robin Becker
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Kamaelia 0.4.0 RELEASED - Faster! More Tools! More Examples! More Docs! ;-)

2006-06-24 Thread Robin Becker
Michael wrote:
> Hi!
> 
> 
> (OK, slightly silly subject line :)
> 
> I'm extremely pleased to say - Kamaelia 0.4.0 has been released!
> 
...
Windows users might see problems with the attempt at importing libc.so.6 
in the Axon Scheduler.

I changed the lines at line 44 of scheduler.py to something like this

try:
 from ctypes import cdll
 try:
 libc = cdll.LoadLibrary("/lib/libc.so.6")
 except:
 raise ImportError
 sched_yield = libc.sched_yield
except ImportError:
 def sched_yield(): pass

as I have ctypes, but no libc.so.6 I get a Windows error from the statement
 libc = cdll.LoadLibrary("/lib/libc.so.6")

This allows  somethings to run eg

AxonVisualiser.py --navelgaze

but I'm not sure if the results are really unaffected by not having a 
real yielder. The diagram appears, but doesn't seem to settle down.
-- 
Robin Becker
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python and cellular automata (It works this time!)

2006-06-24 Thread placid

defcon8 wrote:
> I thought people would be interested in this little script I wrote to
> reproduce the 256 simple automata that is shown in the first chapters
> of "A New Kind of Science". You can see a few results without running
> the script, at http://cooper-j.blogspot.com . And here is the code (You
> will need PIL (Python Imaging Library)):
> 
> import Image
>
> # Contract:
> # To simulate simple cellular automata.
>
> class calculations:
> def __init__(self,which):
>   self.against = self.array_maker_2()[which]
>   self.check = self.array_maker_1()
>   self.array = self.array_maker_3(311)
>   self.calculator()
>
> def binary(self, n, size): ## This is the Int -> str(BINARY)
> converter
>   assert n >= 0
>   bits = []
>   while n:
>   bits.append('01'[n&1])
>   n >>= 1
>   bits.reverse()
>   result = ''.join(bits) or '0'
>   for iteration in range(len(result),size):
>   result = "0" + result
>   return result
>
> def array_maker_1(self): # This makes the array that represents the
> 8 different permutations of 3 cells. Itself, its left and its right.
>   return [self.binary(n, 3) for n in range(8)]
>
> def array_maker_2(self): # This makes the array that represents
> every single different rule. If for instance the second element in one
> # of these rules is 1, then the corresponding permutation that may
> be found in the result array (array_maker_3), will be 1 (black).
>   return [self.binary(n, 8) for n in range(256)]
>
> def array_maker_3(self, y): # This is the array for all the
> results. The automaton starts from the middle of the first row
>   x = [["0" for x in range((2*y)+1)] for n in range(y)]
>   x[0][(2*y+1)/2] = "1"
>   return x
>
> def calculator(self): # This cycles over all of the cells, and
> scans one row at a time, and changes the next row according to the
> current cell.
>   self.buff_result = ["0","0","0"] # This is the current permutation
> buffer to be checked against the corresponding arrays.
>   for i in range(len(self.array)-1):
>   for j in range(1, len(self.array[0])-1):
>   self.step1(j,i)
>   self.step2(j,i)
>   self.step3(j,i)
>   y = self.check.index(''.join(self.buff_result))
>   self.array[i+1][j] = self.against[y]
>
> # The steps update the result buffer.
> def step1(self, step, y):
>   self.buff_result[0] = self.array[y][step-1]
>
> def step2(self, step, y):
>   self.buff_result[1] = self.array[y][step]
>
> def step3(self, step, y):
>   self.buff_result[2] = self.array[y][step+1]
>
> for number in range(256):
> objo = calculations(number)
> x = objo.array
> y = []
> for num,zo in enumerate(x):
>   for com,wo in enumerate(zo):
>   x[num][com] = int(wo)
>
> nim = Image.new("1", (623,311))
>
> for n in x: #converting the array of arrays into a single array so
> putdata can take it.
>   for p in n:
>   y.append(p)
> nim.putdata(y)
> nim.resize((6230/2,3110/2)).save("output" + str(number) + ".png")
> print number
> 

>

Ah, celular automata! Another of my on-off interest! I shall run this
as soon as posible.

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


adad

2006-06-24 Thread edoardo batini
dvsdfvsdfvsdfvsf
-- 
http://mail.python.org/mailman/listinfo/python-list


Python and cellular automata (It works this time!)

2006-06-24 Thread defcon8
I thought people would be interested in this little script I wrote to
reproduce the 256 simple automata that is shown in the first chapters
of "A New Kind of Science". You can see a few results without running
the script, at http://cooper-j.blogspot.com . And here is the code (You
will need PIL (Python Imaging Library)):

import Image

# Contract:
# To simulate simple cellular automata.

class calculations:
def __init__(self,which):
self.against = self.array_maker_2()[which]
self.check = self.array_maker_1()
self.array = self.array_maker_3(311)
self.calculator()

def binary(self, n, size): ## This is the Int -> str(BINARY)
converter
assert n >= 0
bits = []
while n:
bits.append('01'[n&1])
n >>= 1
bits.reverse()
result = ''.join(bits) or '0'
for iteration in range(len(result),size):
result = "0" + result
return result

def array_maker_1(self): # This makes the array that represents the
8 different permutations of 3 cells. Itself, its left and its right.
return [self.binary(n, 3) for n in range(8)]

def array_maker_2(self): # This makes the array that represents
every single different rule. If for instance the second element in one
# of these rules is 1, then the corresponding permutation that may
be found in the result array (array_maker_3), will be 1 (black).
return [self.binary(n, 8) for n in range(256)]

def array_maker_3(self, y): # This is the array for all the
results. The automaton starts from the middle of the first row
x = [["0" for x in range((2*y)+1)] for n in range(y)]
x[0][(2*y+1)/2] = "1"
return x

def calculator(self): # This cycles over all of the cells, and
scans one row at a time, and changes the next row according to the
current cell.
self.buff_result = ["0","0","0"] # This is the current permutation
buffer to be checked against the corresponding arrays.
for i in range(len(self.array)-1):
for j in range(1, len(self.array[0])-1):
self.step1(j,i)
self.step2(j,i)
self.step3(j,i)
y = self.check.index(''.join(self.buff_result))
self.array[i+1][j] = self.against[y]

# The steps update the result buffer.
def step1(self, step, y):
self.buff_result[0] = self.array[y][step-1]

def step2(self, step, y):
self.buff_result[1] = self.array[y][step]

def step3(self, step, y):
self.buff_result[2] = self.array[y][step+1]

for number in range(256):
objo = calculations(number)
x = objo.array
y = []
for num,zo in enumerate(x):
for com,wo in enumerate(zo):
x[num][com] = int(wo)

nim = Image.new("1", (623,311))

for n in x: #converting the array of arrays into a single array so
putdata can take it.
for p in n:
y.append(p)
nim.putdata(y)
nim.resize((6230/2,3110/2)).save("output" + str(number) + ".png")
print number


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


Re: Python web server

2006-06-24 Thread Paul Boddie
arvind wrote:
> When I run the script on server,only HTML part gets executed.
> But the python code appears as it is on the screen in the text format.
> How to run the CGI script on web server using Python2.4.3?

We don't have much specific information from you here, but taking a few
guesses, it sounds like you have put a Python program in some directory
that your Web server knows about, but when you visit the address in
your browser that should let you use that program, you just see the
program text, not the output of the program when it is run.

What you need to do is to tell your Web server that the file is a
"script". With Apache, for example, instead of using configuration
directives like "Alias", you use "ScriptAlias" instead. Of course,
Apache has lots of different ways to make files behave like scripts,
and you may be using a completely different Web server, so a bit more
information would be welcome.

Still, one really simple method with Apache is to expose your program
like this:

ScriptAlias /myprogram "/home/me/programs/myprogram.py"

Provided you set the permissions of myprogram.py to be readable and
executable by the Web server user (if appropriate), and provided the
Web server user can navigate to the /home/me/programs directory, you
should at least get the program running. More configuration may be
needed - why not let us know how far you get?

Paul

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


Re: search engine

2006-06-24 Thread placid

Daniel Nogradi wrote:
> > hai all,
> >  i am student of computer science dept. i have planned to
> > design a search engine in python. i am seeking info about how to
> > proceed further.
> >   i need to know what r the modules that can be used.
>
> There are these two guys Sacha or Sergey and Larry (if I remember
> correctly) who already wrote a cute search engine in python, perhaps
> you could ask them for some help.

Sergey and Larry youre not talking about Google are you? 

*wink* ;)

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


Re: search engine

2006-06-24 Thread gene tani

George Sakkis wrote:
> vinodh kumar wrote:
> > hai all,
> >  i am student of computer science dept. i have planned to
> > design a search engine in python. i am seeking info about how to
> > proceed further.
> >   i need to know what r the modules that can be used.
>
> There is not a "search engine module" around AFAIK. You should do your
> homework first and learn about search engines in a language-independent
> way from some good textbook such as "Mining the Web"
> (http://http.cs.berkeley.edu/~soumen/mining-the-web/),

There are python bindings for lucene, swish, Xapian, etc.  As well as a
Zcatalog.  There *was* Pyndex, from Divmod, maybe they'll send you the
source.

More books: Manning and Schuetze "Statistical NLP", Berry and Browne's
"Understanding Search Engines"
http://www.ec-securehost.com/SIAM/SE17.html

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


Re: search engine

2006-06-24 Thread Daniel Nogradi
> hai all,
>  i am student of computer science dept. i have planned to
> design a search engine in python. i am seeking info about how to
> proceed further.
>   i need to know what r the modules that can be used.

There are these two guys Sacha or Sergey and Larry (if I remember
correctly) who already wrote a cute search engine in python, perhaps
you could ask them for some help.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: search engine

2006-06-24 Thread faulkner
http://www.voidspace.org.uk/cgi-bin/pysearch/search.py
http://www.voidspace.org.uk/
http://www.vex.net/parnassus/
http://cheeseshop.python.org/pypi
http://aspn.activestate.com/ASPN/Cookbook/Python
http://www.google.com

vinodh kumar wrote:
> hai all,
>  i am student of computer science dept. i have planned to
> design a search engine in python. i am seeking info about how to
> proceed further.
>   i need to know what r the modules that can be used.
> 
> 
> -

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


Re: sum fonction in gadfly

2006-06-24 Thread Robert Hicks
I haven't been keeping up. Is Gadfly still in development?

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


Re: search engine

2006-06-24 Thread placid

George Sakkis wrote:
> vinodh kumar wrote:
> > hai all,
> >  i am student of computer science dept. i have planned to
> > design a search engine in python. i am seeking info about how to
> > proceed further.
> >   i need to know what r the modules that can be used.
>
> There is not a "search engine module" around AFAIK. You should do your
> homework first and learn about search engines in a language-independent
> way from some good textbook such as "Mining the Web"
> (http://http.cs.berkeley.edu/~soumen/mining-the-web/), break the
> problem into subparts and decide which ones you will implement. By then
> you should have a much better idea of what modules to look for.
>

Anyway, if you are going to design a new search engine and implement it
then you will probably need to use modules only as a helper to your
algorithm.

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


dragging with Boa Constructor

2006-06-24 Thread icebear

There's some non-obvious trick to being able to drag widgets around on a
frame screen using Boa Constructor.  I'd appreciate hearing from anybody
who knows what it is.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: module docstring, documentation, anything? please note is the module type/object NOT some module

2006-06-24 Thread Maric Michaud
Le Samedi 24 Juin 2006 04:41, Jorge Vargas a écrit :
> On 6/23/06, Jorge Vargas <[EMAIL PROTECTED]> wrote:
> > Hi everyone I have wasted 2 hours trying to figure out how to get a
> > reference to the module object. that is the one returned by
> >
> > __import__ or when you call a module for name like
> >
> > >>> import sys
> > >>> sys
> >
> > 


In [16]: from types import ModuleType

In [17]: print ModuleType.__doc__
module(name[, doc])

Create a module object.
The name must be a string; the optional doc argument can have any type.

In [18]: ModuleType is type(sys)
Out[18]: True

> >
> > the reason I want this is that I want to introspec my module
> >
> > so I need some way to indentify what elements are inside the module, to
> > execute something like:
> >
> > ""for all the classes defined in this module do "
>

Like for any other object, use the __dict__ attribute :

In [19]: sys.__dict__.items()[:3]
Out[19]:
[('setrecursionlimit', ),
 ('getfilesystemencoding', ),
 ('stdout', ', mode 'w' at 0xa7ddc068>)]


Also, you''ll need these :

In [59]: from types import ClassType

In [60]: import subprocess

In [61]: subprocess.__dict__['Popen']
Out[61]: 

In [62]: isinstance(subprocess.__dict__['Popen'], type)
Out[62]: True

In [63]: isinstance(subprocess.__dict__['Popen'], ClassType)
Out[63]: False

In [64]: ClassType # old-style class
Out[64]: 



putting all togetther :


In [75]: def find_classes(mod) :
   : for k, v in mod.__dict__.iteritems() :
   : if isinstance(v, type) : print 'new style class : ', k
   : elif isinstance(v, ClassType) : print 'old style class : ', k
   :
   :

In [76]: find_classes(subprocess)
new style class :  Popen

In [77]: find_classes(sys)

In [78]: find_classes(os)
old style class :  _Environ
new style class :  stat_result
old style class :  error
new style class :  statvfs_result


> I found an ugly hack to the docs  help(type(sys))

This is not ugly, people used to do "type('')" rather than "import types; 
types.StringType", in prior versions of python (2.1).


-- 
_

Maric Michaud
_

Aristote - www.aristote.info
3 place des tapis
69004 Lyon
Tel: +33 426 880 097
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: String negative indices?

2006-06-24 Thread Filip Wasilewski
Steven D'Aprano wrote:
> On Fri, 23 Jun 2006 02:17:39 -0700, Filip Wasilewski wrote:
>
> > [EMAIL PROTECTED] wrote:
> >
> >> Logically, I should be able to enter x[-2:-0] to get the last and next to 
> >> last characters. However, since Python doesn't distinguish between 
> >> positive and negative zero, this doesn't work. Instead, I have to enter 
> >> x[-2:].
> >
> > Hooray! Logically there is no such thing as positive or negative zero,
> > or did I miss something in the primary?
>
> No, not in the primary, or even in the secondary, but possibly in the
> tertiary.
>
> For many purposes, it doesn't make sense to distinguish +0 from -0. But
> for other purposes, it does.

I believe you will agree that this is mostly a matter of notation of
some fact rather than really trying to sign zero.
For example I use to denote numbers that approach zero from "the right
side" by x -> [0 uppercase +], which is definitely harder to type and
display in poor man's text editor than x -> +0.
Otherwise I should also rethink the meaning of positive (>0) and
negative (<0) numbers (at least where such relations are defined).

[...]

> In statistical mechanics, some systems can have negative absolute
> temperatures, including negative zero. Counter-intuitively, negative
> absolute temperatures aren't colder than absolute zero, but hotter than
> any positive temperature. So, strangely enough, a temperature of -0K is
> hotter than a infinitely hot temperature!

Yeah, this is really cool ;-)

--
Filip

"During board meeting: We have great news. Our earnings reached highest
value ever - a positive 0."

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


Re: Python web server

2006-06-24 Thread Bruno Desthuilliers
arvind wrote:
> When I run the script

Which one ? And how ?

> on server,

Which one ?

> only HTML part gets executed.

HTML executed ???

> But the python code appears as it is on the screen in the text format.
> How to run the CGI script on web server using Python2.4.3?

Depends on your web server. But there's very probably all the needed
documention somewhere, and I'm pretty confident google will find it.


-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: templating languages for webdev

2006-06-24 Thread Bruno Desthuilliers
a wrote:
> cheetah vs django vs kid

You forgot SimpleTal and Myghty (and many others).

I don't like cheetah's syntax at all. I'm not in love with Django
templates choices for markup ( '{% tag %}' and '{{ var }}'), but it can
be customised, and I found the system very nice otherwise.

-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: search engine

2006-06-24 Thread George Sakkis
vinodh kumar wrote:
> hai all,
>  i am student of computer science dept. i have planned to
> design a search engine in python. i am seeking info about how to
> proceed further.
>   i need to know what r the modules that can be used.

There is not a "search engine module" around AFAIK. You should do your
homework first and learn about search engines in a language-independent
way from some good textbook such as "Mining the Web"
(http://http.cs.berkeley.edu/~soumen/mining-the-web/), break the
problem into subparts and decide which ones you will implement. By then
you should have a much better idea of what modules to look for.

George

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


Re: sum fonction in gadfly

2006-06-24 Thread Scott David Daniels
jean-jeanot wrote:
> After creating the table  I create the variables with
> varAmount = StringVar()
Maybe you want to use DoubleVar or IntVar here?

> With a function
> def treatment ():
>requete = "insert into transactions ( date,amount,,)
> values(..) "% (varDate.get(),
>varAmount.get
Or float(varAmount.get())  |
int(round(100 * float(varAmount.get( here

> cur.execute ("select sum(amount) from transactions").I get
> Sum.amout.transaction
> =
> 100-10.5...
> 
> instead of 110.5
> 
> It means that the select command does not add but concatenates the
> different amounts. Why ?
Sounds like you selected columns are strings, not numbers.
Remember '123.5' + '-23' is '123.5-23', while 123.5 + -23 is 100.5
You need the amount column of the transactions table in the gadfly
database to be a numeric type, not a string type.

--Scott David Daniels
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


FTPUTIL WITH TKFILEDIALOG

2006-06-24 Thread veki
HI,ALL I am new ftputil user and I need help about something:
my prog:

>>> import tkFileDialog
>>> import ftputil
>>> name=tkFileDialog.askopenfile()
>>>ftp=ftputil.FTPHost() #Please when you want try this prog
use  your ftp server
>>> nesto1=name.name
>>> ftp.upload(nesto1,nesto1,'b')
ERROR IS:

Traceback (most recent call last):
  File "", line 1, in -toplevel-
ftp.upload(nesto1,nesto1,'b')
  File "C:\Python24\lib\ftputil.py", line 463, in upload
self.__copy_file(source, target, mode, open, self.file)
  File "C:\Python24\lib\ftputil.py", line 452, in
__copy_file
target = target_open(target, target_mode)
  File "C:\Python24\lib\ftputil.py", line 282, in file
raise ftp_error.FTPIOError("directory '%s' is not
accessible" %
FTPIOError: directory '/C:/Python24' is not accessible


THANKS!!

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


Re: Absolute noob to Linux programming needs language choice help

2006-06-24 Thread Ben C
On 2006-06-21, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Hey guys,
>
> I am absolutely new to Linux programming, with no w##s programming
> experience except a small amount of C++ console apps.
> Reasonably new to Linux, BSD etc, got good sound networking base of
> knowledge and dont have any problem working the command line etc.
>
> I want to learn a language that I can use in my networking duties that
> is most likely to be of use to me. I have a few choices I can think of
> being:
>
> Python
> Perl
> C
>
> Any other Langs out there that would be better suited?
>
> I want to be able to use the app's I write in OpenBSD and RH versions
> of Linux
>
> What would you reccomend (Unbiased opinion please, I'm after the
> functionality I'll love it later :) )

My favourite's Python, but Tcl is definitely worth a look. It's been
around a bit longer than Python (so more time for every conceivable
problem to have been met by someone and fixed), and I'm not an expert
but I think it's particularly good for things like sockets-- they're
just sort of built in and are very easy to work with.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: USB and Python

2006-06-24 Thread Diez B. Roggisch
Sybren Stuvel schrieb:
> Philippe Martin enlightened us with:
>> I need to talk to a USB device (PC or other) from Python - I am not
>> talking about mounting a file system but sharing information as you
>> would though a TCP-IP socket layer or an RS232 interface.
> 
> You could wrap libusb on Linux.

PyUSB already does that.

OP seems to have a bad google day...

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


Python web server

2006-06-24 Thread arvind
When I run the script on server,only HTML part gets executed.
But the python code appears as it is on the screen in the text format.
How to run the CGI script on web server using Python2.4.3?

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


search engine

2006-06-24 Thread vinodh kumar
hai all,
 i am student of computer science dept. i have planned to
design a search engine in python. i am seeking info about how to
proceed further.
  i need to know what r the modules that can be used.


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


Re: reaching to the notification area

2006-06-24 Thread Bayazee
hi
i can fine somethings in google such this :
http://www-128.ibm.com/developerworks/linux/library/l-wrap/
but i can not copmile files !
Any idea !!!???

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


PyGTK and Py2Exe troubles

2006-06-24 Thread Tim N. van der Leeuw
I tried to create a windows executable of a pygtk program. My first
attempt worked, kinda, except that no themes were applied and no
readable fonts were found by pango; so all letters where just empty
squares. But the program worked.

I looked up some docs, found the following recipe on the PyGTK Wiki
site:
http://starship.python.net/crew/theller/moin.cgi/Py2exeAndPyGTK

I followed those instructions to convert my setup.py file; everything
still worked the same as before.

Then I copied GTK's 'etc', 'share' and 'lib' directories into the
directory of my executable, as per instructions.

That's when it all went wrong...

(See errors below)

Apart from the errors below, there were also multiple windows
error-reporting popup boxes telling me that the program crashed; do I
want to send info to Microsoft.

If anyone can help me getting a PyGTK GUI running as standalone
executable, that would be very much appreciated!

I know it's possible, BitTorrent had a PyGTK GUI on windows.

(I'm not that attached to PyGTK as such, but I'm somewhat familiar with
it and it has a good multi-column TreeView widget with inline editing.
That's what I need for my program, and wxPython didn't seem to have a
very workable solution for multicolumn treeviews...)


$ ./CBGui.exe

(CBGui.exe:1320): GLib-GObject-CRITICAL **: gtype.c:2215:
initialization assertion failed, use g_type_init() prior to this
function

(CBGui.exe:1320): GLib-GObject-CRITICAL **: gtype.c:2255:
initialization assertion failed, use g_type_init() prior to this
function

(CBGui.exe:1320): GLib-GObject-CRITICAL **: gtype.c:2215:
initialization assertion failed, use g_type_init() prior to this
function

(CBGui.exe:1320): GLib-GObject-CRITICAL **: gtype.c:2255:
initialization assertion failed, use g_type_init() prior to this
function

(CBGui.exe:1320): GLib-GObject-CRITICAL **: gtype.c:2215:
initialization assertion failed, use g_type_init() prior to this
function

(CBGui.exe:1320): GLib-GObject-CRITICAL **: gtype.c:2215:
initialization assertion failed, use g_type_init() prior to this
function

(CBGui.exe:1320): Gdk-CRITICAL **: gdk_window_new_internal: assertion
`GDK_IS_WINDOW (parent)' failed

(CBGui.exe:1320): GLib-GObject-CRITICAL **: g_object_new: assertion
`G_TYPE_IS_OBJECT (object_type)' failed

(CBGui.exe:1320): Gdk-CRITICAL **: _gdk_window_destroy_hierarchy:
assertion `window != NULL' failed

(CBGui.exe:1320): GLib-GObject-CRITICAL **: g_object_unref: assertion
`G_IS_OBJECT (object)' failed

(CBGui.exe:916): GLib-GObject-CRITICAL **: gtype.c:2215: initialization
assertion failed, use g_type_init() prior to this function

(CBGui.exe:916): GLib-GObject-CRITICAL **: gtype.c:2255: initialization
assertion failed, use g_type_init() prior to this function

(CBGui.exe:916): GLib-GObject-CRITICAL **: gtype.c:2215: initialization
assertion failed, use g_type_init() prior to this function

(CBGui.exe:916): GLib-GObject-CRITICAL **: gtype.c:2255: initialization
assertion failed, use g_type_init() prior to this function

(CBGui.exe:916): GLib-GObject-CRITICAL **: gtype.c:2215: initialization
assertion failed, use g_type_init() prior to this function

(CBGui.exe:916): GLib-GObject-CRITICAL **: gtype.c:2215: initialization
assertion failed, use g_type_init() prior to this function

(CBGui.exe:916): Gdk-CRITICAL **: gdk_window_new_internal: assertion
`GDK_IS_WINDOW (parent)' failed

(CBGui.exe:916): GLib-GObject-CRITICAL **: g_object_new: assertion
`G_TYPE_IS_OBJECT (object_type)' failed

(CBGui.exe:916): Gdk-CRITICAL **: _gdk_window_destroy_hierarchy:
assertion `window != NULL' failed

(CBGui.exe:916): GLib-GObject-CRITICAL **: g_object_unref: assertion
`G_IS_OBJECT (object)' failed

(CBGui.exe:5020): GLib-GObject-CRITICAL **: gtype.c:2215:
initialization assertion failed, use g_type_init() prior to this
function

(CBGui.exe:5020): GLib-GObject-CRITICAL **: gtype.c:2255:
initialization assertion failed, use g_type_init() prior to this
function

(CBGui.exe:5020): GLib-GObject-CRITICAL **: gtype.c:2215:
initialization assertion failed, use g_type_init() prior to this
function

(CBGui.exe:5020): GLib-GObject-CRITICAL **: gtype.c:2255:
initialization assertion failed, use g_type_init() prior to this
function

(CBGui.exe:5020): GLib-GObject-CRITICAL **: gtype.c:2215:
initialization assertion failed, use g_type_init() prior to this
function

(CBGui.exe:5020): GLib-GObject-CRITICAL **: gtype.c:2215:
initialization assertion failed, use g_type_init() prior to this
function

(CBGui.exe:5020): Gdk-CRITICAL **: gdk_window_new_internal: assertion
`GDK_IS_WINDOW (parent)' failed

(CBGui.exe:5020): GLib-GObject-CRITICAL **: g_object_new: assertion
`G_TYPE_IS_OBJECT (object_type)' failed

(CBGui.exe:5020): Gdk-CRITICAL **: _gdk_window_destroy_hierarchy:
assertion `window != NULL' failed

(CBGui.exe:5020): GLib-GObject-CRITICAL **: g_object_unref: assertion
`G_IS_OBJECT (object)' failed

(CBGui.exe:5936): GLib-GObject-CRITICAL **: gtype.c:2215:
initialization assertion failed, use g_type

sum fonction in gadfly

2006-06-24 Thread jean-jeanot
I am writing a prototype program whose aim is to collect bookkeeping
transactions in a Database ( Gadfly).
After creating the table  I create the variables with
varAmount = StringVar()
I then create labels in Tkinter to ease the input of data.
With a function
def treatment ():
   requete = "insert into transactions ( date,amount,,)
values(..) "% (varDate.get(),
   varAmount.get
I transfer data from the labels in Tkinter into the Database at the end
of the program
with a button named "End" . I print the Database with print cur.pp().
No problem up to now but then I try to use a select command:
cur.execute ("select sum(amount) from transactions").I get

Sum.amout.transaction
=
100-10.5...

instead of 110.5

It means that the select command does not add but concatenates the
different amounts. Why ?

Many thanks if you can help me.

Jean Moser

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


HTTP server

2006-06-24 Thread placid
Hi all,

Ive been reading about creating a HTTP server like the one pydoc
creates (and studying pydoc source code). What i want to know, is it
possible to create server that creates a webpage with hyperlinks that
communicate back to the HTTP server, where each link accessed tells the
server to execute some arbitrary command on local machine its running
on?

Cheers

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


Re: * in Python

2006-06-24 Thread placid

Bruno Desthuilliers wrote:
> placid wrote:
> > Bruno Desthuilliers wrote:
> >
> (snip)
> >>Why don't you try by yourself in the Python shell ? One of the nice
> >>things with Python is that it's quite easy to explore and experiment.
> >
> >
> > i did try it in a  Python shell after i learnt what it was. Like i said
> > *args will be a list, but when i try **args with the following code it
> > doesnt work
>
> "doesn't work" is the most useless description of a problem.
>
> > def test(**args):
> > keys = args.keys()
> > for key in keys:
> > print key+"="+args(key)
>
> you want args[key], not args(key)
>
> And you forget to tell how you called this code and what you got.

Too much world cup means sleepless nights down here in Australia or i
would have seen the error with args(key) which suppose to be args[key]
!

>
> FWIW:
> Python 2.4.3 (#1, Jun  3 2006, 17:26:11)
> [GCC 3.4.6 (Gentoo 3.4.6-r1, ssp-3.4.5-1.0, pie-8.7.9)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> def test(**kw):
> ... for item in kw.items():
> ... print "%s : %s" % item
> ...
> >>> test()
> >>> test(parrot="dead", walk="silly", nose="big")
> nose : big
> parrot : dead
> walk : silly
> >>> test(**{'answer':42})
> answer : 42
> >>>

Thanks for that now i know what * means.

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