ANN: pyFltk-1.1

2006-02-22 Thread andreas
This is to announce the first official release of pyFltk-1.1,
the Python bindings for the cross platform GUI toolkit fltk-1.1

This release candidate has been tested with fltk-1.1.7
and requires Python2.4.
pyFltk is a lighweight, easy-to-use GUI toolkit for Python. It
can be used where simplicity, speed, small footprint, and ease-of-use
are
important.
Changes:
* Now it is possible to extend all widgets in Python
* Fl_Preferences has been added.
* Various bug fixes
* Faster dispatch (thanks to SWIG)
* Improved stability
* Added port of FLTK sudoku program
A source distribution, a Windows installer, and a Linux binary
(including fltk) can be
downloaded from http://pyfltk.sourceforge.net.

Regards

Andreas Held
http://pyfltk.sourceforge.net

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

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


Re: Python vs. Lisp -- please explain

2006-02-22 Thread Donn Cave
Quoth Steven D'Aprano [EMAIL PROTECTED]:
...
| Do you honestly believe that the CPU doesn't have to interpret the machine
| code, or are you just deliberately playing silly buggers with language?

I don't care whether the CPU has to interpret machine code.  Are
you suggesting that we might in normal conversation wish to use
the term interpreter to mean CPU, like what kind of interpreter
does your computer have?, that kind of thing?

|  Your paragraph above that starts with No of course not,
|  even omits a point that everyone understands, you can in
|  fact expect a .py file will work independent of machine
|  architecture - like any interpreted language.
|
| Amazing. In your previous post you were telling everybody how the
| *disadvantage* of interpreted programs is that they won't run unless the
| interpreter is present, and in this post you are telling us that
| interpreted languages will just work. What happened to the requirement for
| an interpreter?

Look, this is my last post on this matter, because you have evidently
reached a point where every statement has to be spelled out in excruciating
detail to avoid absurd interpretations.  will work independent of machine
architecture does not declare that it is absolutely guaranteed to work -
after all, it may have some other flaw that will prevent it from working
anywhere.  It just says that if it doesn't work, it isn't because it
tried to execute on the wrong machine architecture - the file is machine
architecture independent.  You know that, you know I know that.  What
is the fucking problem?

| In order to force interpreted language and compiled language into two
| distinct categories, rather than just two overlapping extremes of a single
| unified category, you have to ignore reality. You ignore interpreted
| languages that are compiled, you ignore the reality of how machine code is
| used in the CPU, you ignore the existence of emulators, and you ignore
| virtual machines.

Anyone with an interest in computer programming is likely to know what
microcode means, that there are emulators, virtual machines, etc.  You
might find the UCSD Pascal system interesting, to harken back to the
early days of my experience with computers, a fascinating twist on the
interpreted/compiled story.  Interesting as perspective, but it wouldn't
change the way we apply these words to Python.

Donn Cave, [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: yet another python graphviz binding (yapgvb) 1.1.1

2006-02-22 Thread Lonnie Princehouse
Introducing Yapgvb, a Python wrapper around the ATT's graph layout
library Graphviz.

Features:
  - A nice clean Pythonic interface
  - Boost.Python wrapper around the C libraries; no more fiddling with
system calls to dot.
  - Read and write .dot files using Graphviz's own library routines.
  - Translation to and from Boost.Graph; do your computation using
Boost, and draw it with Graphviz.
  
URL:   http://yapgvb.sourceforge.net

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


Re: redirecting to a content page

2006-02-22 Thread bruno at modulix
Shreyas wrote:
 I am a new user writing some scripts to store data entered via a
 browser into a database.  I have several content pages, and one
 processing page.  A content page often has a form like this:
 
 form method=POST action=processing.py
 input type=text name=username
 ...
 
 And the processing page goes like this:
 
 form = cgi.FieldStorage()
 ## do some work, put data into the db
 
 The thing is, processing.py doesn't have any content that I want to
 display to the user.

And this is a GoodThing(tm). A successful post should always be followed
by a redirect.

  I would ideally like processing.py to seamlessly
 send the user back to the content page that it came from, perhaps with
 some parameter tweaks.

import cgi

print Location: %s\n\n % url_of_the_page_you_want_to_redirect_to

(snip)

 Please let me know if there's a way to do this, or if my general
 approach (having such a processing page) is off.

Nope, having a separate script doing the form processing, then
redirecting  is the right thing to do.

 
 - I did try searching for this in the archive but am not even entirely
 sure what it is called...

It's a redirection. If you are to work with CGI (or any other web
programming solution FWIW), you'd better know the HTTP protocol.


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


new wooden door step - fixing and finishing

2006-02-22 Thread jkn
Hi all
I'm considering having a go at replacing the wooden door step to
our back door. The original is loose and rotting.

I'm sure some of this will be clearer when I remove the (metal) door
frame - how is such a step fixed? Vertical frame fixings?

Also, any suggestions for treating/finishing such an item, subject to
heavy use, to prevent future rot? I was wondering about treating it
wilth liberal amounts of Teak Oil or similar...

Thanks
Jon N

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


Re: cPAMIE 2.0 released!!

2006-02-22 Thread Fabrizio Milo
you forgot the link :)

http://pamie.sourceforge.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: number ranges (was Re: Matlab page on scipy wiki)

2006-02-22 Thread Antoon Pardon
Op 2006-02-20, Steven D'Aprano schreef [EMAIL PROTECTED]:
 John Zenger wrote:

 I strongly agree that Python should promote range or xrange to syntax. I 
 favor [0..10] rather than [0:10] because 0..10 is inherently easier to 
 understand.

 Inherently?

 You mean people are born with an instinctive, unlearnt 
 understanding of ..? Or that our brains are constructed 
 in such a way that .. is easier to understand?

 For what it is worth, even after years of Python 
 programming, I still sometimes write this:

 for i in len(myList):
  # Oops.

 I too prefer range() or xrange() over magic syntax, but 
 I'm not especially a lover of the range() idiom. How 
 about this? With the introduction of a single keyword, 
 we could do this:

 for i in 2 to 5:
  print i,
 which would print 2 3 4 5

 (I'm open to arguments that it should be more Pythonic 
 and less mathematical, and halt at 4.)


My suggestion would be to use what we already have and
extend that.

Python has slices. We could extend slices in two steps.

a) Let slices be iterable, so we could have something
   like:

   for i in slice(2,5):
 print i,
 
which would print 2 3 4,

Now I agree this wouldn't be a big advantage over the
range and xrange function, so the next point

b) Allow slice notation in arbitrary places. So we
   could write the above as:

   for i in (2:5):
 print i,

 A second keyword downto would allow easy backwards 
 loops, and a third step will absolutely kill any 
 chance of Guido agreeing to this whatsoever.

Well with iterable slices we wouldn't need any new
keyword nor any real new syntax. Just lift the 
limitation that slice notation is only allowed when
indexing.

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


gmail written in python?

2006-02-22 Thread ongkokleong
any idea?

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


Re: number ranges

2006-02-22 Thread Antoon Pardon
Op 2006-02-21, Tim Hochberg schreef [EMAIL PROTECTED]:

 [Lots of proposals snipped]

 90% of my gripes with range disappeared with the addition of enumerate. 
 However, if there's going to be another round of range literal proposals 
 I might as well throw out what seems (to me anyway) like the only 
 halfway obvious choice in the context of Python.

 1. a:b:c is equivalent to slice(a,b,c) with the usual rules that missing 
 values are mapped to None: Parentheses would be required where this 
 construct would otherwise be ambiguous.

I think this would be the way to go if want a chance of having it in
python 2.x.

However I would think that a Bottom and Top value (respectively being
smaller and larger than all other objects) would be better suited as
default values for python 3000

 2. slice(a,b,c) grows an __iter__ method that returns a generator that 
 produces an appropriate sequence of integers. This is easy to define for 
 positive steps, but tricky for negative steps (more on that in a second).

 Thus:

 for i in (1::2): print i,
= 1 3 5 ...

 and

 for i in (:10:3): print i,
= 0 3 6 9


 The tricky part is deciding what to with negative steps when the start 
 is undefined. It's tempting to use 0 as the start, but I think -1 is 
 actually better if slightly odd. The reason is that I think the 
 following invariant should hold.

In python 2.x I would either throw an exception or continuely return
None if the start value isn't given.

For python 3000 I would continously return Bottom or Top if the start
value wasn't given, depending on step being positive or negative.

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


interpreting the fractional portion of time.clock() vs time.time(0 measurements

2006-02-22 Thread john peter
let's say i'm taking timing measurements in Windows XPt1 = time.clock()  ...  t2 = time.clock()t3 = t2 - t1 = say, 0.018  what is the unit of measurement for t3?is it correct to say thatt3 = 18 milliseconds?  microsends?what if the timing function used for t1 and t2 was time.time()? is it still correct to say  that t3 = 18 milliseconds? i kinda know that in Windows, time.clock() has higher  resolution than time.time(), and all i need is millisecond resolution. which of these  functions would be easier to translate into millisecond units of measurement?
		 Yahoo! Autos. Looking for a sweet ride? Get pricing, reviews, & more on new and used cars.-- 
http://mail.python.org/mailman/listinfo/python-list

Re: gmail written in python?

2006-02-22 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

 any idea?

http://panela.blog-city.com/python_at_google_greg_stein__sdforum.htm

/F 



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


Re: Python vs. Lisp -- please explain

2006-02-22 Thread Torsten Bronger
Hallöchen!

Peter Mayne [EMAIL PROTECTED] writes:

 Torsten Bronger wrote:

 My definiton would be that an interpreted language has in its
 typical implementation an interpreting layer necessary for typical
 hardware.  Of couse, now we could discuss what is typical,
 however, in practice one would know it, I think.  In case of Python:
 CPython and all important modern processors.

 In a previous century, I used something called UCSD Pascal, which at
 the time was a typical implementation of Pascal.

Not a typical implementation but its.

 [...]

 And, as someone in this thread has pointed out, it is likely that
 your important modern (x86) processor is not natively executing
 your x86 code, and indeed meets your definition of having in its
 typical implementation an interpreting layer necessary for typical
 hardware.

Only if you deliberately misunderstand me.

 Another example: is Java the bytecode, which is compiled from Java
 the language, interpreted or not? Even when the HotSpot JIT cuts
 in?

It is partly interpreted and partly compiled.  That's why it's
faster than Python.

 [...]

 Personally, in practice I don't care, so don't ask me. Ponder on
 getting angels to dance on the head of a pin before you worry
 about whether the dance can be interpreted or not.

I agree that the term interpreted is bad Python advocacy because
its implications are often misunderstood.  However, I think that
it's fair to make a distiction between compiled and interpreted
languages because it may affect one's decision for one or the other.
Although I'm surely not ingenious, I can make this distinction.

The reason why Python is slower than C is because there is an
interpreting layer that C doesn't have.  And the reason for this is
that Python's nature is incompatible with today's CPUs (which was a
deliberate and advantageous design decision).  I'm sure that a
willing CS person could define this more clearly.

Anyway, if we drop scripting and drop interpreted, what do you
want to tell people asking why Python is so slow?  Because it is
dynamic?  ;-)

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetusICQ 264-296-646
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pyserial never read

2006-02-22 Thread luca72

Thanks to all for the help,

here you find the code, pls note if i use handshaking = 1 the
application don't start.
in the delphi configuratio of com port if i use or not handshaking the
application work.
Best Regards at all

Luca

import serial
import win32file
port = 2
baudrate = 38400
bytesize =serial.EIGHTBITS
parity =serial.PARITY_ODD
stopbits =serial.STOPBITS_TWO
timeout = 1
ser = serial.Serial(2, baudrate=38400, bytesize=8,
parity=serial.PARITY_ODD, stopbits=2, timeout=3)
ct = ''
ch = ''
a = self.textCtrl1.GetValue()
ind = 0
ind1 = 2
lunghezza = len(a)
while ind  lunghezza :
b = a[ind:ind1]
b = int(b,16)
b = ~b
c = ''.join([str((b  Digit)  1) for Digit in range(7,
-1, -1)])
c1 = c[0:4]
c2 = c[4:]
c1 = c1[3:] + c1[2:3] + c1[1:2] + c1[0:1]
c2 = c2[3:] + c2[2:3] + c2[1:2] + c2[0:1]
c1 = hex(int(c1,2))
c2 = hex(int(c2,2))
c1 = c1[2:]
c2 = c2[2:]
c = c2+c1
ct = ct + c
ind = ind + 2
ind1 = ind1 + 2
c = int(c,16)
c = chr(c)
ch = ch + c


ser.write(ch)

elf.textCtrl2.SetValue(ct)
ser.readline()



Pls.Note i hove also try with read(number of byte ) with inWaiting(),
flush  etc


But no result.

Thanks Luca

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


Re: warning for google api users

2006-02-22 Thread William
Isn't this because the index that the api uses is (a lot) older than
the index used by www.google.com? total results are always estimated,
so they are not reliable (seen the variance)

Gabriel B. schreef:

 the google webservices (aka google API) is not even close for any kind
 of real use yet

 if you search for the same term 10 times, you get 3 mixed totals. 2
 mixed result order. and one or two 502 bad gateway

 i did an extensive match agains the API and the regular search
 service. the most average set of results:

 results 1-10; total: 373000
 results 11-20; total: 151000
 results 21-30; total: 151000
 results 31-40; total: 373000
 results 41-50; total: 373000
 results 51-60; total: 373000
 results 61-70; total: 151000
 ( 502 bad gateway. retry)
 results 71-80; total: 373000
 results 81-90; total: 151000
 ( 502 bad gateway. retry)
 results 91-100; total: 373000

 on the regular google search, total:  2,050,000 (for every page, of
 course)

 besides that, the first and third result on the regular google search,
 does not apear in the 100 results from the API in this query, but this
 is not average, more like 1 chance in 10 :-/

 So, no matter how much google insists that this parrot is sleeping,
 it's simply dead.


 now, what i presume that is happening, is that they have a dozen of
 machine pools, and each one has a broken snapshot of the production
 index (probably they have some process to import the index and or it
 explode in some point or they simply kill it after some time). and
 they obviously don't run that process very often.

 Now... anyone has some implementation of pygoogle.py that scraps the
 regular html service instead of using SOAP? :)
 
 Gabriel B.

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


cookielib

2006-02-22 Thread sri2097
Hi, I need to get to a particular page in a website. The site uses
cookeis and naturally I had to use cookielib since urllib2 does not
support cookies. But even after adding the cookies to the headers, I
keep getting a error message from the web-site saying that - 'My
Browser has disabled cookies and I cannot access the page'. Here is the
code I wrote -

cookie_obj = cookielib.CookieJar()

# First page
socket = urllib2.Request(http://www.zap2it.com/index;)
cookie_obj.add_cookie_header(socket)
data = urllib2.urlopen(socket).read()
print data

# Second page
socket =
urllib2.Request(http://tvlistings2.zap2it.com/index.asp?partner_id=nationalmash=mash1zipcode=01810submit1=Continue;)
cookie_obj.add_cookie_header(socket)
data = urllib2.urlopen(socket).read()
print data

# Third Page
socket =
urllib2.Request(http://tvlistings2.zap2it.com/system.asp?partner_id=nationalzipcode=01810;)
cookie_obj.add_cookie_header(socket)
data = urllib2.urlopen(socket).read()
print data


Is there anything wrong in the above done code. I printed out the all
the HTML headers in each stage to see if the cookie is getting added or
not. I found out that the cookies are not getting added. But when I do
socket.info().headers I get a list of all the headers wherein I can
see 'Set-Cookie' tag and the cookie value.

Anyone got any suggestions ?

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


Re: question about scope

2006-02-22 Thread Magnus Lycka
John Salerno wrote:
 But as far as ifs and loops, is there such a thing as scope in them? 

No.

Local scopes are introduced with def or class, nothing
else (or did I forget something?). There is nothing in Python
that corresponds directly to the { } in C and C++. If you want
data to exist in some other scope, put them in a dictionary
(there you have your { } ;^) and use that explicitly.

Each Python module/file is a global scope in Python.

Something to consider if you come from C, is that variables
and assignments in Python are conceptually different from C.

Your objects/values are never created in a local scope. They
are always created on the heap, as if you would use malloc in
C or new in C++. All variables are pointers/references, and
the objects/values are automatically garbage collected. From
a C perspective, the only kind of variables you have are void
pointers, but that's ok, because you can only point these
pointers to managed objects that are handled by the runtime
systems. The runtime system handles both memory allocation
and deallocation and type checks for you. In some particular
cases (e.g. numeric types) it will also perform casting when
you need it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: May i customize basic operator (such as 1==3)?

2006-02-22 Thread Carl Friedrich Bolz
kanchy kang wrote:
 many people write test cases with python scripts.
 in these test scripts, there are many validation statements,
 for example, in unittest, failUnless(a == b),(a/b may be stringType or 
 intType...)
 
 during running test scripts, if there is one exception raised from 
 failUnless, i still do not know a =?, b= ?... i have to add one statment 
 print a or print b again...
 
 as i know, there are many validation statements if using python as one 
 test tool...
 i think my suggestion or requirement may benefit users greatly...
 

you could use the py.test testing framework 
(http://codespeak.net/py/current/doc/test.html), which tries to print 
useful information if a test fails. So if your test contains

assert a == b

and this is False, it will print the values of a and b. For example the test

def test_fail():
 a = 1
 b = 2
 assert a == b

would result in the following failure:


 def test_fail():
 a = 1
 b = 2
E   assert a == b
assert 1 == 2


This has the drawback that your expressions need to be side-effect free 
(because they will be re-evaluated) but it is quite useful.

Cheers,

Carl Friedrich Bolz

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


Re: cookielib

2006-02-22 Thread Paul Rubin
sri2097 [EMAIL PROTECTED] writes:
 Hi, I need to get to a particular page in a website. The site uses
 cookeis and naturally I had to use cookielib since urllib2 does not
 support cookies.

It's poorly documented but urllib2 does support cookies now.

http://docs.python.org/lib/http-cookie-processor.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: May i customize basic operator (such as 1==3)?

2006-02-22 Thread Thomas Heller
Carl Friedrich Bolz wrote:
 kanchy kang wrote:
 many people write test cases with python scripts.
 in these test scripts, there are many validation statements,
 for example, in unittest, failUnless(a == b),(a/b may be stringType or 
 intType...)

 during running test scripts, if there is one exception raised from 
 failUnless, i still do not know a =?, b= ?... i have to add one statment 
 print a or print b again...

 as i know, there are many validation statements if using python as one 
 test tool...
 i think my suggestion or requirement may benefit users greatly...

 
 you could use the py.test testing framework 
 (http://codespeak.net/py/current/doc/test.html), which tries to print 
 useful information if a test fails.

The standard unittest module can do this also:  replace
calls to failUnless(a == b) with failUnlessEqual(a, b).

Thomas

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


Re: No

2006-02-22 Thread Fredrik Lundh
Gaz wrote:

 Aye, but the file is in MY drive, not the server. Perhaps  thats the
 issue? I bet it's so... how should i deal with it? Perhaps should be a
 script that uploads the files to the server and then emails it...

assuming that the web server can read files on your local disk is perhaps
a bit too optimistic.

how did you upload your program to the server in the first place ?

any reason you cannot use the same approach to upload the image ?

/F 



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


Re: Determing whether two ranges overlap

2006-02-22 Thread Magnus Lycka
Fredrik Lundh wrote:
 def overlap(a, b):
 return a[1]  b[0] and a[0]  b[1]

Assuming that x[1] can't be smaller than x[0], this
is the right way to compare two ranges. Well, I guess
you need to figure out the borderline cases. Is it
a[1]  b[0] or a[1] = b[0] which is relevant?

Anyway,  if we have N ranges and N is big, we'll get
lots of comparisions: N*(N-1)/2.

For large values of N, it might be better to somehow
cache/aggregate the intervals if this makes it possible
to make this into an N*M comparision where M is smaller
than (N-1)/2

E.g, with discrete values for the intervals such as with
(10, 15), one might consider something like (untested):

hits = sets.Set()

for interval in intervals:
 for i in range(interval[0], interval[1]+1):
 if i in hits:
 raise ValueError('%s overlaps previous interval.'
   % interval)
 hits.add(i)

E.g. if we have 1000 intervals where the average size of
an interval is 10, you get 1 i in hits and hits.add(i)
instead of 499500 'a[1]  b[0] and a[0]  b[1]'.

As always, it's good to measure...assuming you have fairly
realistic data to test with.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: May i customize basic operator (such as 1==3)?

2006-02-22 Thread Kent Johnson
Thomas Heller wrote:

 The standard unittest module can do this also:  replace
 calls to failUnless(a == b) with failUnlessEqual(a, b).

or assertEquals(a, b)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Writing my own typing monitor program for RSI sufferers...

2006-02-22 Thread Carl Friedrich Bolz
[EMAIL PROTECTED] wrote:
 I want to write a program that will let me know after thirty minutes of
 typing that I need to take a five minute typing break.  But when I stop
 typing it's smart enough to pause the 30 minute timer automatically.
 This is under the X-Window System (Linux).
 
 The tricky part is obviously knowing when the mouse and keyboard are
 being usedespecially when my application doesn't have the focus.
 
 Obviously I can't do this with just the base python install.  Is there
 an add on library that I can use to monitor the keyboard and mouse?
 Which is it?  Maybe one of the graphical libraries, like wx, or qt, or
 gtk?  Which functions do I need?

You can do a bit of X hackery. Look for example at

http://www.softlab.ece.ntua.gr/~sivann/src/misc/xkey.c

which is a C program that prints keypresses (in any application). Should 
be fairly easy to turn into a Python extension module to monitor X activity.

Cheers,

Carl Friedrich Bolz

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


Re: Python vs. Lisp -- please explain

2006-02-22 Thread Steven D'Aprano
On Wed, 22 Feb 2006 10:15:21 +0100, Torsten Bronger wrote:

 And, as someone in this thread has pointed out, it is likely that
 your important modern (x86) processor is not natively executing
 your x86 code, and indeed meets your definition of having in its
 typical implementation an interpreting layer necessary for typical
 hardware.
 
 Only if you deliberately misunderstand me.

If the words you choose to use have implications which you failed to
realise before saying them, don't blame the reader for spotting those
implications.



 Another example: is Java the bytecode, which is compiled from Java the
 language, interpreted or not? Even when the HotSpot JIT cuts in?
 
 It is partly interpreted and partly compiled.  That's why it's faster
 than Python.

But Python is partly interpreted and partly compiled too, so that can't be
the answer. 

I think we all know what the answer is. The Python interpreter isn't as
fast as the Java interpreter, or most machine code interpreters built into
hardware.

On the other hand, I'm pretty sure that interpreted Python runs faster on
my current PC than compiled code runs on the 20 year old Macintosh in my
cupboard. So compiled isn't a magic wand that makes code run faster.



 [...]

 Personally, in practice I don't care, so don't ask me. Ponder on
 getting angels to dance on the head of a pin before you worry about
 whether the dance can be interpreted or not.
 
 I agree that the term interpreted is bad Python advocacy because its
 implications are often misunderstood.  However, I think that it's fair
 to make a distiction between compiled and interpreted languages because
 it may affect one's decision for one or the other. Although I'm surely
 not ingenious, I can make this distinction.

Would you rather use a blindingly fast interpreted language, or a
slow-as-continental drift compiled one?

This isn't a rhetorical question. In the mid-80s, Apple and Texas
Instruments collaborated on a Macintosh II computer with a Lisp
coprocessor. The problem was, according to benchmarks at the time, Lisp
compiled and run natively on the coprocessor was actually slower than Lisp
interpreted on a standard Macintosh II.

I'm sure that's hardly the only example of a speedy interpreted language
beating a glacial compiled one.


 The reason why Python is slower than C is because there is an
 interpreting layer that C doesn't have.

The primary reason Python is slower than C is because C compilers have
been optimized to create fast code, while Python has been created to
optimize programmer productivity instead. That means that a simple
instruction like x + y does a lot more work in Python than it does in C.

There are other languages that, like Python, are dynamic, interpreted,
interactive and the rest, and they execute faster than Python. (By the
same token, there are also some that execute slower than Python.) Let's be
honest here: it isn't that Python can't be as fast as C, it is that the
Python Dev team have had other priorities.

But over time, as PyPy, Psycho, and other technologies bear fruit, Python
will speed up, even though it will remain interpreted. 


 And the reason for this is that
 Python's nature is incompatible with today's CPUs (which was a
 deliberate and advantageous design decision).  I'm sure that a willing
 CS person could define this more clearly.
 
 Anyway, if we drop scripting and drop interpreted, what do you want
 to tell people asking why Python is so slow?  Because it is dynamic? ;-)

Who says Python is so slow? I've just got Python to count from 0 up to
100,000, and it only took 7 milliseconds. That's at least 12 milliseconds
faster than I can count on my fingers.

But seriously... why not tell them the truth? Python is slower than some
other languages because optimization for execution speed has not been the
primary focus of Python's development. If you tell them that Python is
slow because it is interpreted, they will believe that Python will always
be slow. If you tell them that Python is slow because speed has not been
the priority, they will believe that some day it will become the priority,
and then Python will get faster. And they will be right. That is the aim
of PyPy after all.




-- 
Steven.

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


Re: No

2006-02-22 Thread Steven D'Aprano
On Wed, 22 Feb 2006 11:42:19 +0100, Fredrik Lundh wrote:

 Gaz wrote:
 
 Aye, but the file is in MY drive, not the server. Perhaps  thats the
 issue? I bet it's so... how should i deal with it? Perhaps should be a
 script that uploads the files to the server and then emails it...
 
 assuming that the web server can read files on your local disk is perhaps
 a bit too optimistic.

Come on, Gaz is running Windows. Chances are *everyone* can read files on
his local disk.

*wink*


-- 
Steven.

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


Path (graph) shower utility

2006-02-22 Thread Durumdara
Hi !

I need to create a program that read eml file headers, analyze the
receive tags and create a path database. I finished with this program
section.

But I want to show a graphical summary about the paths.

This is (what I want to show) like a graph - show ways, stations, etc,
and I want to show the strength of lines (how many of mails use this way).

Can anyone known about a freeware tool, software, or python module that
can show graphs with best alignments ?

Please help me. Thanx for it:
dd


Ps:
The OS is Windows XP:
I tryed with pydot, but this code created many 0 length files.

import pydot

print pydot.find_graphviz()

edges=[(1,2), (1,3), (1,4), (3,4)]
g=pydot.graph_from_edges(edges)
g.write_svg('graph_from_edges_dot.svg', prog='dot')
g.write_svg('graph_from_edges_neato.svg', prog='neato')
g.write_jpeg('graph_from_edges_dot.jpg', prog='dot')
g.write_jpeg('graph_from_edges_neato.jpg', prog='neato')

 

{'fdp': 'c:\\Program Files\\ATT\\Graphviz\\bin\\fdp.exe', 'twopi': 
'c:\\Program Files\\ATT\\Graphviz\\bin\\twopi.exe', 'neato': 
'c:\\Program Files\\ATT\\Graphviz\\bin\\neato.exe', 'dot': 'c:\\Program 
Files\\ATT\\Graphviz\\bin\\dot.exe', 'circo': 'c:\\Program 
Files\\ATT\\Graphviz\\bin\\circo.exe'}


Thanx for help: dd


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


Re: With pyMinGW

2006-02-22 Thread A.B., Khalid
[EMAIL PROTECTED] wrote:
 To use Pyrex, SWIG and the like on a Win2K I have followed this way:

 http://jove.prohosting.com/iwave/ipython/pyMinGW.html

 I already had MinGW 3.4.2, so I have decompressed the Python 2.4.2
 sources, I have merged in the pyMinGW patch, and I have run the global
 compilation with:

 make -f python24.mak all

 It has compiled most things, but not zlibmodule.c
 It has stopped the compilation with:

 c:\..\bin\dllwrap.exe: no export definition file provided.
 Creating one, but that may not be what you want
 make[1]: Leaving directory `/.../PyminGW/Python-2.4.2/MinGW'
 make -f zlib.mak
 make[1]: Entering directory `/.../PyminGW/Python-2.4.2/MinGW'
 gcc.exe -c ../Modules/zlibmodule.c -o ../Modules/zlibmodule.o
 -I../Include -I../Pc -I../../../d
 ist/zlib-1.2.3  -Wall -s -DNDEBUG -D_USRDLL -O2
 ../Modules/zlibmodule.c:8:18: zlib.h: No such file or directory
 ../Modules/zlibmodule.c:66: error: syntax error before z_stream

 ... etc etc.

 Anyway, probably 98% was compiled and this Python works, I have tried
 the standard tests and most of them pass.
 Then I have downloaded the pyMinGW Extensions V. 0.0.6.6, so zip and
 other things now work.

 The link to the Tcl-Tkinter extension doesn't work (the free site
 hosting the file doesn't accept this file format anymore), so I cannot
 use Tkinter.

 I have decompressed SWIG and put it in a temporary Path.

 I have then tried a basic SWIG example, (called example) coming from
 this obsolete but probably still interesting page:
 http://sebsauvage.net/python/mingw.html

 But I have had problems durign the module creation:

 C:\...\PyminGW\Python-2.4.2\MinGWpython setup.py build -cmingw32
 running build
 running build_ext
 building 'example' extension
 swigging example.i to example_wrap.c
 C:\...\PyminGW\swigwin-1.3.28\swig.exe -python -o example_wrap.c
 example.i
 creating build
 creating build\temp.win32-2.4
 creating build\temp.win32-2.4\Release
 C:\..\bin\gcc.exe -mno-cygwin -mdll -O -Wall -Ic:\python24\include
 -Ic:\pytho
 n24\PC -c example_wrap.c -o build\temp.win32-2.4\Release\example_wrap.o
 example_wrap.c: In function `My_variable_set':
 example_wrap.c:2550: error: `My_variable' undeclared (first use in this
 function)

 ... ecc.


 So I have had 3 problems, maybe some of you can suggest me how to solve
 some of them.

 (Can the standard Python site accept to distribuite an installer with
 MinGW-compiled Python + minGW + SWIG for people using Windows that want
 such system prebuilt? Maybe me or another person can assemble it).

 Thank you,
 bearophile


It seems you may be using an old version of pyMinGW, because in the one
I have the directory issue of zlib was fixed and the relevant part
dealing with include directories in zlib.mak should read now as
follows:

LIBS =  -L. -lpython24 -L../../../dist/zlib-1.2.3 -lz
--image-base,0x1e1B
INCS =  -I../Include -I../Pc -I../../../dist/zlib-1.2.3
CXXINCS =  -I../Include  -I../Pc -I../../../dist/zlib-1.2.3

The idea is to make INCS point at the location of your zlib sources.

As to the Tkinter-Tcl point, then please remember that this was a
binary build extension distribution that had nothing to do with the
core Python that pyMinGW is supposed to address. And if you download
the extension sources then you can certainly build the libraries
yourself, and then the python extensions, especially since you have
make files ready to use for the later in the pyMinGW sources. The
binary distribution was meant to make things a bit easier for people,
but since the site stopped the hosting of zip files and since many
people do not download that particular file anyway when it was hosted
elsewhere, letting the file expire (inactive files are removed after
one week from last download), then I hope you'd agree it would be much
work for me to keep track of expired and unexpired files and so keep on
uploading the files.

As to your SWIG problem, then I suggest you look into the pyMinGW's
extensions' directory. There you will find two examples of building C
and CPP extensions using SWIG and MinGW.

Regards,
Khalid



pyMinGW:
http://jove.prohosting.com/iwave/ipython/pyMinGW.html

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


Re: Video Capture modules in linux

2006-02-22 Thread [EMAIL PROTECTED]
ok..i'll check with that...but wait libfg binaries arent available in
any software repos..and Diez, I would like to mention that there is a
VideoCapture lib exclusively for python..(only that its for win32)..
So - that _is_ a
C-domain.

So can i kinda embed that code into C using the libraries that are
available..plz guyz any links would be appreciated

Sudharshan S

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


Re: Python vs. Lisp -- please explain

2006-02-22 Thread Kay Schluehr

Steven D'Aprano wrote:

 But over time, as PyPy, Psycho, and other technologies bear fruit, Python
 will speed up, even though it will remain interpreted.

I talked to Richard Emslie recently and he told me that the PyPy team
works on a mechanism to create CPython-extension modules written in
RPython i.e. a statically translateable subset of Python. So even
without dynamic code specialization there will be an optimization path
based on the PyPy toolchain that is amazing. 

Kay

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


Re: embedding python in HTML

2006-02-22 Thread Magnus Lycka
John Salerno wrote:
 Thanks, that makes much more sense to me now. But does this mean I can 
 still write HTML normally? What would an example be of having HTML 
 within a Python script? I have a hard time picturing this, because I 
 imagine that most of my pages will be almost all HTML, with just a bit 
 of Python here and there, perhaps to insert headers and footers. Is all 
 the HTML just wrapped in a big print statement, or something like that?

Imagine for instance, that you have an HTML file where you
want to print a current timestamp when the page is displayed.

A simple way to do this would be to just give your HTML file
another extension (e.g. .tmpl, short for template). Keep the
file as it is, just put the text

%(timestamp)s

in the place(s) where you want your timestamp to appear
in the HTML file.

In your CGI script you can then do something like this:

#!/usr/bin/python -u
import time
print Content-type: text/html\n
text = open('myfile.tmpl).read()
print text % ('timestamp':time.asctime())

The inital Content-type line is important, and it must be
followed by a blank line before the actual content.

Look at the cgitb module too.

Instead of the common Python % interpolation, you could use
string.Template (with a current Python) or one of the many
templating systems around. Since your needs are likely to
grow, you might also want to have a look at one of the many
tool kits for Python and the web. Right now, it seems that
django and turbogears are the most popular. Cherrypy and
web.py are somewhat smaller and simpler systems. Unless you
use one of these tool kits, your homegrown code might turn
into yet another web tool kit eventually, and we have enough
of them already... (Too many I'd say...)

You should also note that traditional CGI scripts are rather
slow with Python, since Python's startup time is significant.
A system where the Python interpreter is already running, as
mod_python embedded in Apache is faster. But by all means, try
it as CGI. It might well be enough for your needs. It's been
ok for me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python vs. Lisp -- please explain

2006-02-22 Thread Paul Rubin
Kay Schluehr [EMAIL PROTECTED] writes:
 I talked to Richard Emslie recently and he told me that the PyPy team
 works on a mechanism to create CPython-extension modules written in
 RPython i.e. a statically translateable subset of Python. So even
 without dynamic code specialization there will be an optimization path
 based on the PyPy toolchain that is amazing. 

Sounds great but is that a whole lot different from pyrex?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: odt - pdf

2006-02-22 Thread LB
pyUNO ia a bridge between python and Openoffice.org. Nothing directly
to do with export in pdf format. If you prefer you can print a pdf
file from a.odt or .doc or .* source with external freeware/shareware
or business utilities as pdf creator, adobe acrobat etc. sometimes with
more control on results.

LB

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


Re: Little tool - but very big size... :-(

2006-02-22 Thread Sion Arrowsmith
BJ in Texas [EMAIL PROTECTED] wrote:
[EMAIL PROTECTED] wrote:
|| 11MB is seldom a concern for today's machine.
A good windows/microsoft attitude.. :-)

I wish 8-( :

  PID USER  PR  NI  VIRT  RES  SHR S %CPU %MEMTIME+  COMMAND
 3715 root  15   0  288m 128m 154m S  1.0  6.3  14902:42 XFree86
  735 user15   0  156m  84m  40m S  0.3  4.2   3:55.48 firefox-bin
 3533 root  16   0 85652  74m 1572 S  0.0  3.7   0:00.22 pcscd
 3904 user15   0 67768  49m  17m S  0.3  2.4   4:48.16 gnome-terminal
  449 user16   0 58484  41m  39m S  0.0  2.1  16:18.60 kmail
 4010 user16   0 49056  34m  22m S  0.0  1.7   0:01.63 kdeinit
31724 user16   0 94708  32m  34m S  0.0  1.6   0:49.03 epiphany
 3892 user15   0 41696  22m  19m S  0.0  1.1   0:20.60 nautilus
28992 user15   0 57984  19m  22m S  0.0  1.0   5:53.66 kdeinit
 3902 user16   0 26948  18m  11m S  0.0  0.9   1:50.81 xemacs
 4237 user15   0 29784  15m  22m S  0.0  0.8   0:01.24 python
  444 user16   0 24384  15m  20m S  0.0  0.7   0:08.99 gaim
 4026 user15   0 29924  14m  28m S  0.0  0.7   0:12.59 kdeinit
 4012 user16   0 27352  14m  25m S  0.0  0.7   0:33.24 kdeinit
 5388 user15   0 26008  13m  24m S  0.0  0.7   0:02.06 kdeinit
  350 user15   0 20456  12m  17m S  0.0  0.6   0:05.05 gnome-panel

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

[OT] Re: number ranges

2006-02-22 Thread Sion Arrowsmith
Steven D'Aprano  [EMAIL PROTECTED] wrote:
 Colin J. Williams [EMAIL PROTECTED] wrote:
1. Why not treat '2 to 5' or '(2 to 5)' as a semi-open interval?
I intellectually understand that semi-open intervals 
are the only way to go. But reading the words, the part 
of my brain that speaks English cries out for a closed 
interval. Bad brain.

My native British-English speaking brain has never been able to
decide whether to indicates a closed or semi-open interval.
Whenever I can get away with it, I've adopted the Americanism
through (but always retaining that spelling) when describing
a closed interval.

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

What's happened to Jython?

2006-02-22 Thread aprasad21k
Jython does not seem to have been updated for more than a year. Any
idea whether Jython enhancements are likely to be released in the near
future?

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


Re: Python vs. Lisp -- please explain

2006-02-22 Thread Kay Schluehr

Paul Rubin wrote:
 Kay Schluehr [EMAIL PROTECTED] writes:
  I talked to Richard Emslie recently and he told me that the PyPy team
  works on a mechanism to create CPython-extension modules written in
  RPython i.e. a statically translateable subset of Python. So even
  without dynamic code specialization there will be an optimization path
  based on the PyPy toolchain that is amazing.

 Sounds great but is that a whole lot different from pyrex?

RPython is Python code not a different language. In a sense RPython
consists of a set of rules usual Python has to conform to make complete
type-inference feasible. Here is an overview of those rules.

http://codespeak.net/pypy/dist/pypy/doc/coding-guide.html#restricted-python

Kay

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


Python CGI not working in Firefox but does in IE

2006-02-22 Thread Harlin Seritt
I have this Python CGI script running:

[CODE]
print 'Content-type: text/plain\n'

location = 'http://server1.com'

page = '''
html
head
meta http-equiv=Refresh content=0; URL='''+location+'''
/head
body/body
/html'''

print page
[/CODE]

It works fine and redirects perfectly when using Internet Explorer but
only shows this in a Firefox window:

[OUTPUT]
html
head
meta http-equiv=Refresh content=0; URL=http://server1.com;
/head
/html
[/OUTPUT]

Is there anything I can do to fix this?

Also, is there a redirect command somewhere within Python CGI that can
get this done instead as I would actually prefer to have the CGI code
execute this rather than depend on the HTML to do it.

Thanks,

Harlin Seritt

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


Re: Komodo - Will it Lock Me In?

2006-02-22 Thread Ilias Lazaridis
Matt Trivisonno wrote:
 Hi Everybody,
 
 If I were to use Komodo to write in Python, would it add a lot of goo to my 
 code such that I would not be able to switch to another IDE without having to 
 claw my way out of a tarpit first?
 
 Any other thoughts on Komodo? I am considering it because I am hoping to find 
 a solution to the install-packages-until-you-go-blind aspect of Python. 
 Setting up a serious, cross-platform, gui development environment is quite a 
 struggle for a newbie.

I work myself currently with the Kommodo IDE (but have not done an 
thorough evaluation of the market before choosing it).

The lock-in question would be solved, if Active State would go 
open-source with Kommodo.

Even a partial open-source would solve this: If the project-management 
subsystems would go open-source, other IDE's could adopt them, ensuring 
a cohesive standard across the dynamic communities.

-

I have made a compact review of Active State, which will possibly give 
you some relevant information:

http://lazaridis.com/samples/com/ActiveState/index.html

Note that some things have changed since the review, which could 
simplify the process of going open source even more:

Active State, a Division of Sophos has become

ActiveState Software Inc.

http://activestate.com/Corporate/Communications/Releases/Press1140209595.html

.

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


Re: Python vs. Lisp -- please explain

2006-02-22 Thread Torsten Bronger
Hallöchen!

Steven D'Aprano [EMAIL PROTECTED] writes:

 On Wed, 22 Feb 2006 10:15:21 +0100, Torsten Bronger wrote:

 And, as someone in this thread has pointed out, it is likely
 that your important modern (x86) processor is not natively
 executing your x86 code, and indeed meets your definition of
 having in its typical implementation an interpreting layer
 necessary for typical hardware.
 
 Only if you deliberately misunderstand me.

 If the words you choose to use have implications which you failed
 to realise before saying them, don't blame the reader for spotting
 those implications.

To me it sounds like Some hardware is harder than other.

 Another example: is Java the bytecode, which is compiled from
 Java the language, interpreted or not? Even when the HotSpot JIT
 cuts in?
 
 It is partly interpreted and partly compiled.  That's why it's
 faster than Python.

 But Python is partly interpreted and partly compiled too

It's byte-compiled for a VM, that's not the same, and you know it.
Sorry but I think we've exchanged all arguments that are important.
Any further comment from me would be redundant, so I leave it.

 [...]

 [...]  However, I think that it's fair to make a distiction
 between compiled and interpreted languages because it may affect
 one's decision for one or the other.  [...]

 Would you rather use a blindingly fast interpreted language, or a
 slow-as-continental drift compiled one?

 This isn't a rhetorical question. [example]

 I'm sure that's hardly the only example of a speedy interpreted
 language beating a glacial compiled one.

I agree that the distinction between interpreted and compiled
languages is not as clear as between positiv and negative numbers,
however, neither anybody has claimed that so far, nor it is
necessary.  It must be *practical*, i.e. a useful rule of thumb for
decision making.  If you really know all implications (pros and
cons) of interpreted languages, it's are very useful rule in my
opinion.

 [...]

 But seriously... why not tell them the truth? Python is slower
 than some other languages because optimization for execution speed
 has not been the primary focus of Python's development. If you
 tell them that Python is slow because it is interpreted, they will
 believe that Python will always be slow.

I don't think that Python's developers don't focus primarily on
speed sounds better than Python is interpreted.  Both suggests
that you must circumvent problems with Python's execution speed (we
all know that this works and how) because you can't count on
language improvements.  Even worse, evading interpreted may sound
like an euphemism and as if you want to hide unloved implementation
features, depending on your audience.

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetusICQ 264-296-646
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python vs. Lisp -- please explain

2006-02-22 Thread Torsten Bronger
Hallöchen!

Steven D'Aprano [EMAIL PROTECTED] writes:

 On Wed, 22 Feb 2006 10:15:21 +0100, Torsten Bronger wrote:

 And, as someone in this thread has pointed out, it is likely
 that your important modern (x86) processor is not natively
 executing your x86 code, and indeed meets your definition of
 having in its typical implementation an interpreting layer
 necessary for typical hardware.
 
 Only if you deliberately misunderstand me.

 If the words you choose to use have implications which you failed
 to realise before saying them, don't blame the reader for spotting
 those implications.

To me it sounds like Some hardware is harder than other.

 Another example: is Java the bytecode, which is compiled from
 Java the language, interpreted or not? Even when the HotSpot JIT
 cuts in?
 
 It is partly interpreted and partly compiled.  That's why it's
 faster than Python.

 But Python is partly interpreted and partly compiled too

It's byte-compiled for a VM, that's not the same, and you know it.
Sorry but I think we've exchanged all arguments that are important.
Any further comment from me would be redundant, so I leave it.

 [...]

 [...]  However, I think that it's fair to make a distiction
 between compiled and interpreted languages because it may affect
 one's decision for one or the other.  [...]

 Would you rather use a blindingly fast interpreted language, or a
 slow-as-continental drift compiled one?

 This isn't a rhetorical question. [example]

 I'm sure that's hardly the only example of a speedy interpreted
 language beating a glacial compiled one.

I agree that the distinction between interpreted and compiled
languages is not as clear as between positiv and negative numbers,
however, neither anybody has claimed that so far, nor it is
necessary.  It must be *practical*, i.e. a useful rule of thumb for
decision making.  If you really know all implications (pros and
cons) of interpreted languages, it's are very useful rule in my
opinion.

 [...]

 But seriously... why not tell them the truth? Python is slower
 than some other languages because optimization for execution speed
 has not been the primary focus of Python's development. If you
 tell them that Python is slow because it is interpreted, they will
 believe that Python will always be slow.

I don't think that Python's developers don't focus primarily on
speed sounds better than Python is interpreted.  Both suggests
that you must circumvent problems with Python's execution speed (we
all know that this works and how) because you can't count on
language improvements.  Even worse, evading interpreted may sound
like an euphemism and as if you want to hide unloved implementation
features, depending on your audience.

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetusICQ 264-296-646
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python CGI not working in Firefox but does in IE

2006-02-22 Thread Richard Brodie

Harlin Seritt [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]

 [CODE]
 print 'Content-type: text/plain\n'

That's your problem. You've said text/plain when you meant text/html.



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


Re: why does close() fail miserably on popen with exit code -1 ?!

2006-02-22 Thread Jeffrey Schwab
Atanas Banov wrote:
 Jeffrey Schwab wrote:
 
_PyPclose returns the exit status of the popened process (the popenee?),
or -1 on error.  Of course, if the status is supposed to be -1, there's
some confusion.
 
 
 yes, that's what i thought the root of the problem is.
 
 
In the snippet of code below (from Modules/posixmodule.c), result has
been initialized to the output of fclose, which in your case is 0.  The
comment is particularly handy.

 
 
 
  /* Indicate failure - this will cause the file object
   * to raise an I/O error and translate the last
   * error code from errno.  We do have a problem with
   * last errors that overlap the normal errno table,
   * but that's a consistent problem with the file object.
   */
 
 
 the piece you quoted is from the unix #ifdef part, i think. there is
 another version of the pypclose for windows below that.
 
 in any event i think such behaviour is a bug - just because in unix
 exit codes are limited to 0..255 (and returned multiplied by 256)
 doesnt mean other OSes should suffer because of design flow in
 _PyPclose, right?
 
 throwing an IOError no error doesnt help.
 
 is there a bug database for python where i can check if this was
 discussed?

Yes, there's a bug database linked from python.org; search the main page 
for Bugs.

Here's the most (seemingly) relevant bug report I can find:
http://sourceforge.net/tracker/index.php?func=detailaid=602245group_id=5470atid=105470
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python CGI not working in Firefox but does in IE

2006-02-22 Thread Iain King

Harlin Seritt wrote:
 I have this Python CGI script running:

 [CODE]
 print 'Content-type: text/plain\n'

 location = 'http://server1.com'

 page = '''
 html
 head
 meta http-equiv=Refresh content=0; URL='''+location+'''
 /head
 body/body
 /html'''

 print page
 [/CODE]

 It works fine and redirects perfectly when using Internet Explorer but
 only shows this in a Firefox window:

 [OUTPUT]
 html
 head
 meta http-equiv=Refresh content=0; URL=http://server1.com;
 /head
 /html
 [/OUTPUT]

 Is there anything I can do to fix this?

 Also, is there a redirect command somewhere within Python CGI that can
 get this done instead as I would actually prefer to have the CGI code
 execute this rather than depend on the HTML to do it.

 Thanks,

 Harlin Seritt

this snippet works (from code I wrote to implement a shoutbox):

print '''html
head
meta http-equiv=refresh content=0;URL='''+HOME+''' /
/head
body
pPlease wait.../p
/body
/html'''

I assume your version doesn't work because of the uppercase 'R'.

Iain

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


Re: Python CGI not working in Firefox but does in IE

2006-02-22 Thread Harlin Seritt
Ack... I'm an idiot... Thanks Richard -- You're the Man!

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


Re: Which is faster? (if not b in m) or (if m.count(b) 0)

2006-02-22 Thread Farel
Thank you, Peter!  Please understand, I was attempting to get more info
on the WHY x is faster than y...  from those with more experience.
Timer cannot give me that info.

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


Re: interpreting the fractional portion of time.clock() vs time.time(0 measurements

2006-02-22 Thread Peter Hansen
john peter wrote:
 let's say i'm taking timing measurements in Windows XP
  
 t1 = time.clock()
 ...
 t2 = time.clock()
  
 t3 = t2 - t1 = say, 0.018
 what is the unit of measurement for t3? is it correct to say that t3 = 
 18 milliseconds?
 microsends?
  
 what if the timing function used for t1 and t2 was time.time()? is it 
 still correct to say
 that t3 = 18 milliseconds? i kinda know that in Windows, time.clock() 
 has higher
 resolution than time.time(), and all i need is millisecond resolution. 
 which of these
 functions would be easier to translate into millisecond units of 
 measurement?

This looks like a repost of a previous question, to which I already 
posted an answer.

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


Re: Python vs. Lisp -- please explain

2006-02-22 Thread Paul Boddie
Kay Schluehr wrote:
 Paul Rubin wrote:
  Kay Schluehr [EMAIL PROTECTED] writes:
   I talked to Richard Emslie recently and he told me that the PyPy team
   works on a mechanism to create CPython-extension modules written in
   RPython i.e. a statically translateable subset of Python.
 
  Sounds great but is that a whole lot different from pyrex?

I've wondered that as well.

 RPython is Python code not a different language. In a sense RPython
 consists of a set of rules usual Python has to conform to make complete
 type-inference feasible. Here is an overview of those rules.

 http://codespeak.net/pypy/dist/pypy/doc/coding-guide.html#restricted-python

But does that make it proper Python? Having, for example, only one
type associated with a name (they use the term variable, though) at
any given time makes it more like various statically typed or
functional languages, although I can fully understand why you'd want
this restriction.

Paul

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


Re: That's really high-level: bits of beautiful python

2006-02-22 Thread Jeffrey Schwab
Max wrote:
 I have a friend who has been programming in C for many years, and he is 
 a great fan of the language. However, he (and I) are about to start a 
 python course, and he has been asking me a lot of questions. He often 
 responds to my answers with Urgh! Object-orientation! and suchlike.

After many years of C programming, he's still wary of object orientation?

 But today we were discussing the problem of running externally-provided 
 code (e.g. add-on modules). Neither of us knew how to do it in C, though 
 I suggested using DLLs.

It depends on how the module was provided, and on the platform and tool 
chain being used to build the code.  It's typically not too hard on a 
given platform, once you get used to it, but there's certainly no single 
correct answer.

 However, I quickly installed python on his 
 laptop and coded this:
 
 exec import %s as ext_mod % raw_input(Module: )
 ext_mod.do()

exec'ing raw_input'd code gives me the willies.

 And created to sample modules with do() functions to demonstrate. He was 
 impressed (That's really high-level were his words).

It is cool, isn't it?  :)

 I was just thinking perhaps we should create some kind of collection of 
 bits of impressive code like this.

Do you mean something like the ASPN Cookbooks?

http://aspn.activestate.com/ASPN/Cookbook/

If you keep track of some examples of cool stuff, I'll format them and 
get some web space to post them.  Try to give credit for each example.

 He also liked 99 Bottles in one line:
 
 print '\n'.join([%d bottles of beer on the wall. % i for i in 
 range(100,0,-1)])

A little shorter:

for i in range(99, 0, -1): print(%d bottles of beer on the wall. % i)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pyserial never read

2006-02-22 Thread Grant Edwards
On 2006-02-22, Nick Craig-Wood [EMAIL PROTECTED] wrote:

  Anything's possible, but given that in his original post he says it 
  works when he uses Delphi, it seems unlikely making a change to the 
  hardware is necessary.

 Sorry missed that bit!

 Pyserial works very well in my experience (under linux).

I've used it extensively under both Linux and Win32, and it
works very well under both.  

 Serial ports are generally a pain though ;-)

That's the truth.

-- 
Grant Edwards   grante Yow!  Somewhere in Tenafly,
  at   New Jersey, a chiropractor
   visi.comis viewing Leave it to
   Beaver!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python vs. Lisp -- please explain

2006-02-22 Thread Carl Friedrich Bolz
Paul Rubin wrote:
 Kay Schluehr [EMAIL PROTECTED] writes:
 
I talked to Richard Emslie recently and he told me that the PyPy team
works on a mechanism to create CPython-extension modules written in
RPython i.e. a statically translateable subset of Python. So even
without dynamic code specialization there will be an optimization path
based on the PyPy toolchain that is amazing. 

Well. ... the PyPy team works on ... is definitively much too strong. 
It is more like ... the PyPy team is thinking about  It is very 
unclear whether it will work on a technical level and whether the EU 
will allow us to allocate resources accordingly.

 Sounds great but is that a whole lot different from pyrex?

Indeed, there are similarities to pyrex. Of course in pyrex you have to 
give the types yourself, but since the type inference engine of PyPy can 
sometimes be hard to understand this is maybe not the worst trade-off. A 
nice advantage of the PyPy approach would be that you can test your 
RPython code by running it on top of CPython until it works and only 
then translating it into C. Plus it would be possible to use the same 
extension module for PyPy, CPython and potentially even Stackless or 
Jython (if somebody writes a Java backend).

But as I said, this is all pretty unclear at the moment (and getting 
really quite off-topic for this thread).

Cheers,

Carl Friedrich

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


Question about struct.unpack

2006-02-22 Thread Eric Jacoboni
Hi,

To experiment with unpacking, i've written a little C code which
stores one record in a file. Then, i try to reread this file to unpack
the record.

Here's the struct of a record:

typedef struct {
  char nom[30];
  double taille;
  int age;
  char plop;
  } enreg_t;

The whole size, as given by sizeof() is 48, due to byte alignment.

I was first thinking that 32sdic would make the job, but calcsize()
reports only 45 for this format. So, without knowing what, i've tried
32sdicxxx to reach the 48 expected... Now it works...

The same file, re-read with a Ruby script needs a
str.unpack(Z32dIc).

So, i don't know why i need to pad the format string in Python. Any
clue?

BTW: how to get rid of all this stuff after the \0 in the first field
in Python? (Ruby has Z and A, but it seems that the Python 's'
specifier is like 'A' and there is no 'Z' equivalent)
-- 
Eric Jacoboni, ne il y a 1444057108 secondes
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python CGI not working in Firefox but does in IE

2006-02-22 Thread Kent Johnson
Harlin Seritt wrote:
 Also, is there a redirect command somewhere within Python CGI that can
 get this done instead as I would actually prefer to have the CGI code
 execute this rather than depend on the HTML to do it.

http://groups.google.com/group/comp.lang.python/msg/6e929fab0d414b2c 
shows how do do a redirect with HTTP headers.

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


Re: With pyMinGW

2006-02-22 Thread bearophileHUGS
Thank you for your answers, Khalid.

 It seems you may be using an old version of pyMinGW,

I have downloaded it yesterday from your site.


 the relevant part dealing with include directories in zlib.mak
 should read now as follows:

I have checked, and that relevant part is the same in my zlib.mak.


 but since the site stopped the hosting of zip files and since many
 people do not download that particular file anyway when it was hosted
 elsewhere, letting the file expire (inactive files are removed after
 one week from last download), then I hope you'd agree it would be much
 work for me to keep track of expired and unexpired files and so keep on
 uploading the files.

You can probably remove the dead link from your page.
(Maybe I can build a complete package (with Tkinter, minGW and Swig
too), and put it in some official Python site.)


 As to your SWIG problem, then I suggest you look into the pyMinGW's
 extensions' directory. There you will find two examples of building C
 and CPP extensions using SWIG and MinGW.

I don't want to use/waste too much of your time, I have succed with the
C++ example, but the C example has given me some problems:

C:\...\PyminGW\Python-2.4.2\MinGW\Extensions\pyExt_C_exmaplepython24
setupMingW.py build --compile
r=mingw32
running build
running build_ext
building '_example' extension
swigging example.i to example_wrap.c
C:\...\PyminGW\swigwin-1.3.28\swig.exe -python -o example_wrap.c
example.i
C:\..\bin\gcc.exe -mno-cygwin -mdll -O2 -Wall -s
-IC:\...\PyminGW\Python-2.4
.2\include -IC:\...\PyminGW\Python-2.4.2\PC -c example_wrap.c -o
build\temp.win32-2.4\Release\examp
le_wrap.o
example_wrap.c: In function `PySwigClientData_New':
example_wrap.c:1205: warning: dereferencing type-punned pointer will
break strict-aliasing rules
example_wrap.c: In function `PySwigObject_own':
example_wrap.c:1456: warning: dereferencing type-punned pointer will
break strict-aliasing rules
example_wrap.c:1456: warning: dereferencing type-punned pointer will
break strict-aliasing rules
example_wrap.c: In function `My_variable_set':
example_wrap.c:2515: error: `My_variable' undeclared (first use in this
function)

Bye,
bearophile

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


Re: cookielib

2006-02-22 Thread Rene Pijlman
sri2097:
urllib2 does not support cookies. 

It does in 2.4. This code enables cookie support in all consequent calls
through urrlib2:

import cookielib, urllib2
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor())
urllib2.install_opener(opener)

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python vs. Lisp -- please explain

2006-02-22 Thread bearophileHUGS
Carl Friedrich Bolz:
 Indeed, there are similarities to pyrex. Of course in pyrex you have to
 give the types yourself, but since the type inference engine of PyPy can
 sometimes be hard to understand this is maybe not the worst trade-off.
 A nice advantage of the PyPy approach would be that you can test your
 RPython code by running it on top of CPython until it works and only
 then translating it into C. [...]
 But as I said, this is all pretty unclear at the moment

Maybe PyPy can be used to allow a better linking between interpreted
Python code and code compiled by ShedSkin.
SS contains a good type inferencer that maybe can be useful to compile
RPython too, aren't PyPy people interested in SS and its capabilities?

Bye,
bearophile

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


Re: That's really high-level: bits of beautiful python

2006-02-22 Thread gene tani

Jeffrey Schwab wrote:
 Max wrote:
  I was just thinking perhaps we should create some kind of collection of
  bits of impressive code like this.

 Do you mean something like the ASPN Cookbooks?

   http://aspn.activestate.com/ASPN/Cookbook/


repositories, indexes and search engines for py code (pardon the small
number ;-}

http://www.vex.net/parnassus/
http://directory.google.com/Top/Computers/Programming/Languages/Python/Modules/

http://cheeseshop.python.org/

http://dmoz.org/Computers/Programming/Languages/Python/Modules/

http://aspn.activestate.com/ASPN/Cookbook/Python
http://python.codezoo.com/
http://sourceforge.net/softwaremap/trove_list.php?form_cat=178xdiscrim=178

http://www.bigbold.com/snippets/

http://www.voidspace.org.uk/cgi-bin/pysearch/search.py
http://koders.com/
http://krugle.com/
http://www.codefetch.com/

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


Re: No

2006-02-22 Thread Gaz
@ Steven: LOL =P

@ Frederik: aye, i uploaded the script by FTP, but the idea of this
little program is to allow a technician on field to upload photos from
their laptops when they get into a hotel, along with some text, anywere
in the world. We need the reports to be daily. Email is not an option,
because due my experience, they always lack of info, with a form, i can
put some conditions for sending the report.

So, they can not upload the photos by FTP because its too geek for
them. And i need to have a standarized form to handle the reports,
because otherwise its a organizational mess.

The program should handle the upload thingie in the backstage. I'll
look for a script like this in these forums...

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


bunding options

2006-02-22 Thread msoulier
I work at home on Linux desktops, but would like to bundle a
Python/wxPython application for Windows desktops, Linux desktops, etc.
I am currently using py2exe to distribute a zipfile that is then usable
by anyone on win32.

On Linux, a source tarball is available, and the users can sync up with
the various versions of tools that I used (python, wxpython, sqlite,
pysqlite, etc) to run the code, but considering that Python moves so
fast and drops backwards compatibility so fast, what is available on
the Linux desktops is not recent enough.

I would like to be able to compile a Linux version for distribution as
well, perhaps a Mac OSX version too.

If I used Java I could distribute an executable jar file and require
the JRE = someversion to be installed, and my work would be done.

What options do I have with Python? Can I take an existing app and
generate C code with freeze.py, and build it?

I'm having a hard time arguing against Java with my coworkers due some
of these distribution issues. py2exe saved me on Windows, although it
does require a win32 build host, and I work on Linux.

Suggestions appreciated.

Thanks,
Mike

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


Re: What's happened to Jython?

2006-02-22 Thread Ravi Teja
According to
http://sourceforge.net/project/showfiles.php?group_id=12867
The last release of 2.2a was on July 17, 2005 - about 7 months.

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


Re: Basic coin flipper program - logical error help

2006-02-22 Thread Jeffrey Schwab
wes weston wrote:
 DannyB wrote:
 
 I'm just learning Python.  I've created a simple coin flipper program -

...

 Dan,
Looping is easier with:
 for x in range(100):
if random.randint(0,1) == 0:
   heads += 1
else:
   tails += 1
 

Or, continuing with that theme:

for x in range(N):
heads += random.randint(0, 1)

As in:

import random
N = 100
heads = 0
for x in range(N):
heads += random.randint(0, 1)
print %d heads and %d tails. % (heads, N - heads)
-- 
http://mail.python.org/mailman/listinfo/python-list


can't use NetcdfFile

2006-02-22 Thread [EMAIL PROTECTED]
Hi,
I'm trying to open a Netcdf file using NetcdfFile but I always get an
import error DLL failed
even though I've tried using all these:

import Numeric
from Scientific.IO.NetCDF import NetCDFFile
from Scientific.IO import NetCDF
from Scientific import *
from Scientific.IO.NetCDF import *

I've got Scientific,Numeric and numpy installed
I'd appreciate anyone's help

Thanks
Vishal.

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


Re: a little more help with python server-side scripting

2006-02-22 Thread John Salerno
Steve Holden wrote:

 Note that purists might suggest this isn't the best way to use Python on 
 the web. If it gets you where you want to be, feel free to ignore them :-)

Thanks for the info. Basically I don't plan to do big stuff with Python 
on the internet (at least not right now while I'm still learning the 
language). I already know how to use a PHP include, so I could just keep 
doing that, but I figure since I'm learning Python, I might as well 
start using it wherever I can, assuming that it is okay to use it this way.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What are COM-enabled applications?

2006-02-22 Thread Cameron Laird
In article [EMAIL PROTECTED],
Tempo [EMAIL PROTECTED] wrote:
As the subject of this post suggests, I have one question; what are
COM-enabled applications? I believe Microsoft Word is one of these
apps, but what else? Is a web browser, Paint, Solitare, games, etc? I'm
not sure if it varies from operating system to operating system, but I
am talking about COM applications in Windows. Thanks for any and all of
your help and time.


As Mr. Teja has already written in response, COM is a big, and 
in some ways dated, subject.  To answer your specific questions:
yes, most Web browsers I know for Windows *are* COM-enabled, 
Solitaire typically isn't, and I'm not near a Win* machine now
to confirm that Paint is.

Python has good COM abilities.  While, to my surprise, I just
realized that I'm unaware of anyone having put together a COM
explorer with Python, it would be a straightforward project.
In the meantime, URL:
http://aspn.activestate.com/ASPN/docs/ActivePython/2.3/PyWin32/html/com/win32com/HTML/QuickStartClientCom.html#UsingComConstants
 
might interest you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Basic coin flipper program - logical error help

2006-02-22 Thread Brian van den Broek
DannyB said unto the world upon 21/02/06 06:14 PM:
 I'm just learning Python.  I've created a simple coin flipper program -
 here is the code:
 
 [source]
 #Coin flipper
 import random
 
 heads = 0
 tails = 0
 counter = 0
 
 coin = random.randrange(2)
 
 while (counter  100):
 if (coin == 0):
 heads += 1
 counter += 1
 else:
 tails += 1
 counter += 1
 
 coin = random.randrange(2)

snip


 The program runs - however - it will give me 100 heads OR 100 tails.
 Can someone spot the logic error?  

snip

Your original question is long since answered. But I've a style point. 
As Dennis Lee Bieber pointed out, you don't need all three 
accumulators. If you keep to the overall style of your code, you can 
avoid repeating yourself as:


while (counter  100):
  counter += 1   # No point in putting this in each branch
  coin = random.randrange(2)
  if (coin == 0):
  heads += 1
  else:
  tails += 1


For roughly the same style, I'd go with:

heads = 0
count = 100

for i in range(count):
 if random.randrange(2):
 heads += 1

tails = count - heads

HTH,

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


Re: No

2006-02-22 Thread Kent Johnson
Gaz wrote:
 Aye, but the file is in MY drive, not the server. Perhaps  thats the
 issue? I bet it's so... how should i deal with it? Perhaps should be a
 script that uploads the files to the server and then emails it... i
 believed this was handled using the root in my PC, but now i see this
 is not correct.
 
 Now i need a script for uploading the files from MY pc and then use the
 sendmail thingie. Any tips about that script?
 
google 'python cgi file upload' for many examples.

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


Re: Python vs. Lisp -- please explain

2006-02-22 Thread Michele Simionato
I replied to this message yesterday, but it did not appear, so let's
try again.

I agree with your points, but I would not say that Lisp is
intrinsically more dynamic than Python
as a language; it is just more interactive and has more features (and
more complexities too).
BTW, regarding your first point on interactive sessions, are you aware
of Michael Hudson's recipe
automatically upgrade class instances on reload()
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/160164 ?

   Michele Simionato

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


Re: Python vs. Lisp -- please explain

2006-02-22 Thread Daniel Harding
Steven D'Aprano wrote:
 Who says Python is so slow? I've just got Python to count from 0 up to
 100,000, and it only took 7 milliseconds. That's at least 12 milliseconds
 faster than I can count on my fingers.

+1 QOTW

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


PyUNO with different Python

2006-02-22 Thread Katja Süss
Hi!
maybe somebody can give me an hint to my problem setting up PyUNO on my 
Mac to work with my Python not the Python delivered with OpenOffice.
As said in installation instructions I've set
   OPENOFFICE_PATH=/usr/lib/openoffice/program
   export PYTHONPATH=$OPENOFFICE_PATH
   export LD_LIBRARY_PATH=$OPENOFFICE_PATH
according to my environment.

importing uno gives me this error:

 import uno
Traceback (most recent call last):
 File stdin, line 1, in ?
 File /Applications/OpenOffice.org 
2.0.app/Contents/openoffice.org2.0/program/uno.py, line 37, in ?
   import pyuno
ImportError: No module named pyuno

which means python finds uno but not pyuno (pyuno.dylib).

Any hints?
Regards, Katja
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: No

2006-02-22 Thread Sion Arrowsmith
Gaz [EMAIL PROTECTED] wrote:
So, they can not upload the photos by FTP because its too geek for
them. And i need to have a standarized form to handle the reports,
because otherwise its a organizational mess.

Am I missing something here, or is all you need a
INPUT TYPE=FILE ... 
on your form? Then you don't worry about filenames, you just get
their data supplied to your cgi script.

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

Re: define loop statement?

2006-02-22 Thread Magnus Lycka
David Isaac wrote:

 PS Here's the motivation.  Python closely resembles pseudocode.  With
 a very little LaTeX hacking, it is often possible to write algorithms is
 Python that typeset as reasonable pseudocode.  A simple repetitive
 loop is a bit of a sticking point.

With slightly more LaTeX hacking or possibly Python hacking on your
script before passing it to LaTeX, you might just be able to change 
occurences of

for x in range(a, b):

to

for x in [a, b):

or whatever, and get away with plain vanilla Python
in your code...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Basic coin flipper program - logical error help

2006-02-22 Thread Paul McGuire

Paul McGuire [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]

 sort, then groupby.


 import itertools
 import random
 h,t = [len(list(g)) for k,g in
itertools.groupby(sorted([random.randrange(2)
 for i in xrange(100)]))]
 print h,t


By the way, sort + groupby generalizes beyond just coin-flipping.  Here is a
modified version that simulates die rolls.

-- Paul

import itertools
import random

NUM_ROLLS = 1000
dieRolls = [random.randrange(6)+random.randrange(6)+2 for i in
xrange(NUM_ROLLS)]

# create dummy list entries for impossible rolls of 0 and 1
rolls = [None,None]

rolls += [len(list(g)) for k,g in itertools.groupby(sorted(dieRolls))]

# print out nice histogram
for i,r in enumerate(rolls):
if i  1:
print %2d - %s % (i,**int(round(r/10.0)))


prints:

 2 - ***
 3 - *
 4 - *
 5 - **
 6 - ***
 7 - **
 8 - **
 9 - *
10 - ***
11 - ***
12 - ***



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


Re: a little more help with python server-side scripting

2006-02-22 Thread John Salerno
John Salerno wrote:
 I contacted my domain host about how Python is implemented on their 
 server, and got this response:

Uh, okay, I asked a related question to them and now I got this:


Hello John,

There are some corrections based on last reply.

The python installation on our windows hosting is not configured as 
mod_python. Howevet, it is directly map with a website extensions 
mapping in IIS. Save your python script as .py file on the wwwroot and 
you may call the scripts using http://www.yourdomain.com/yourfile.py

If you have any enquiries, please do not hesitate to contact.

Best regards,

Mackenzie S.
Support Executive
---

Does that really change anything?

What I had asked was if I could just embed Python code within my HTML 
files, like you do with PHP, but they didn't address that yet.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a little more help with python server-side scripting

2006-02-22 Thread Sybren Stuvel
John Salerno enlightened us with:
 What I had asked was if I could just embed Python code within my
 HTML files, like you do with PHP, but they didn't address that yet.

Check out PSP.

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


except clause not catching IndexError

2006-02-22 Thread Derek Schuff
I'm sorry if this is a FAQ or on an easily-accesible RTFM style page, but
i couldnt find it.

I have some code like this:
for line in f:
toks = line.split()
try:
if int(toks[2],16) == qaddrs[i]+0x1000 and toks[0] == 
200: #producer
write
prod = int(toks[3], 16)
elif int(toks[2],16) == qaddrs[i]+0x1002 and toks[0] == 
200:
#consumer write
cons = int(toks[3], 16)
else:
continue
except IndexError: #happens if theres a partial line at the end 
of file
print indexerror
break

However, when I run it, it seems that I'm not catching the IndexError:
Traceback (most recent call last):
  File /home/dschuff/bin/speeds.py, line 202, in ?
if int(toks[2],16) == qaddrs[i]+0x1000 and toks[0] == 200: #producer
write
IndexError: list index out of range

If i change the except IndexError to except Exception, it will catch it (but
i believe it's still an IndexError).
this is python 2.3 on Debian sarge.

any ideas?

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


Re: can't use NetcdfFile

2006-02-22 Thread Rocco Moretti
[EMAIL PROTECTED] wrote:
 Hi,
 I'm trying to open a Netcdf file using NetcdfFile but I always get an
 import error DLL failed
 even though I've tried using all these:
 
 import Numeric
 from Scientific.IO.NetCDF import NetCDFFile
 from Scientific.IO import NetCDF
 from Scientific import *
 from Scientific.IO.NetCDF import *

Copy  Pasting the exact error message helps tremendously.

 
 I've got Scientific,Numeric and numpy installed

Are you sure you have them installed successfully? How did you install 
them? (Precompiled or from source, and if so, with which compiler?) 
IIRC, Scientific doesn't come with the NetCDF, you have to install the 
NetCDF library separately.
(See http://www.unidata.ucar.edu/software/netcdf/ for download.) After 
installing the NetCDF library, you might need to reinstall Scientific to 
  get it to recognize the NetCDF install.

You might also want to check out 
http://dirac.cnrs-orleans.fr/mmtk_wiki/WindowsInstallation - strictly 
speaking, it's installation instructions for MMTK, but you can ignore 
the final steps of installing MMTK, if you want.

If you need further help, you can always try a more specific resource, 
like the MMTK mailing list - 
http://starship.python.net/mailman/listinfo/mmtk (MMTK is written by the 
same person (Konrad Hinsen) as Scientific, and depends on Scientific.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Tkinter canvas size determination

2006-02-22 Thread Dean Allen Provins
I need to determine the size of a canvas while the process is running.
Does anyone know of a technique that will let me do that?

Thanks,

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


Re: getting the line just before or after a pattern searched

2006-02-22 Thread Magnus Lycka
[EMAIL PROTECTED] wrote:
 hi
 
 i have a file something like this
 
 abcdefgh
 ijklmnopq
 12345678
 rstuvwxyz
 .
 .
 .
 12345678
 .
 
 whenever i search the file and reach 12345678, how do i get the line
 just above and below ( or more than 1 line above/below) the pattern
 12345678 and save to variables? thanks

For gigantic files (i.e. can't put all in RAM at once)
just make sure you always remember the previously read line.
Something like this:

old = None
f = open('mybigfile.txt')
for line in f:
 if line == '12345678\n':
 print old,
 print line,
 print f.next(),
 old=line
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pyserial never read

2006-02-22 Thread Petr Jakes
Well, I think it is better to start with some simple code first.
Try to read serial port and print it out.
something like this could work:

import serial

s = serial.Serial(port=2,baudrate=38400, timeout=20)

while 1:
print s.readline()

Petr Jakes

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


cx_Oracle and UTF8

2006-02-22 Thread Harald Armin Massa
Hello,

I am looking for a method to convince cx_Oracle and oracle to encode
it's replies in UTF8.

For the moment I have to...

cn=cx_Oracle.connect(user,password, database)
cs=cn.Cursor()

cs.execute(select column1, column2, column3 from table)

for row in cs.fetchall():
   t=[]
   for i in range(0,len(row)):
  if hasattr(row[i],encode):
t.append(row[i].encode(utf8))
  else:
t.append(row[i])
print t

Guess I am to much accustomed to postgresql which just allows set
client_encoding='utf8'...

Harald

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


Re: except clause not catching IndexError

2006-02-22 Thread Erwin S. Andreasen
Derek Schuff [EMAIL PROTECTED] writes:

 I have some code like this:

[...]

 except IndexError: #happens if theres a partial line at the 
 end of file
 print indexerror
 break

 However, when I run it, it seems that I'm not catching the IndexError:
 Traceback (most recent call last):
   File /home/dschuff/bin/speeds.py, line 202, in ?
 if int(toks[2],16) == qaddrs[i]+0x1000 and toks[0] == 200: #producer
 write
 IndexError: list index out of range

Did you by any chance do something like:

except ValueError, IndexError:

at some point earlier in this function? That, when catching ValueError
assigns the resulting exception to IndexError (and so the following
except IndexError: wouldn't work as IndexError is no longer what you
think it is). The correct syntax for catching multiple exceptions is:

except (ValueError, IndexError), targetVariable:

You could verify this by doing a print repr(IndexError) before your
line 202, to see that it really is the IndexError builtin.



-- 
===
[EMAIL PROTECTED]London, E14
URL:http://www.andreasen.org/ *   
===

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


Re: Question about struct.unpack

2006-02-22 Thread Scott David Daniels
Eric Jacoboni wrote:
 Hi,
 
 To experiment with unpacking, i've written a little C code which
 stores one record in a file. Then, i try to reread this file to unpack
 the record.
 
 Here's the struct of a record:
 
 typedef struct {
   char nom[30];
   double taille;
   int age;
   char plop;
   } enreg_t;
 
 The whole size, as given by sizeof() is 48, due to byte alignment.
 ...i've tried 32sdicxxx to reach the 48 expected... Now it works...
 
 The same file, re-read with a Ruby script needs a
 str.unpack(Z32dIc).
 
 So, i don't know why i need to pad the format string in Python. Any
 clue?
 
 BTW: how to get rid of all this stuff after the \0 in the first field
 in Python? (Ruby has Z and A, but it seems that the Python 's'
 specifier is like 'A' and there is no 'Z' equivalent)

OK, the correct translation of your format is: '30sdic' (size 45) or
'30sdic3x' if you are passing the entire 48-char block.  The reason
it is not size 48 is that '30sdicc' (size 46) in C takes no more room.
the alignment to the end shows up in a C sizeof.

 data = struct.pack('30sdic', 'John Q. Public', 57123.25, 43, 'M')
 nomz, taille, age, plop = struct.unpack('30sdic', data)
 nom = nomz.rstrip('\0')



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


Re: except clause not catching IndexError

2006-02-22 Thread Ben Cartwright
Derek Schuff wrote:
 I have some code like this:
 for line in f:
 toks = line.split()
 try:
 if int(toks[2],16) == qaddrs[i]+0x1000 and toks[0] == 
 200: #producer
 write
 prod = int(toks[3], 16)
 elif int(toks[2],16) == qaddrs[i]+0x1002 and toks[0] == 
 200:
 #consumer write
 cons = int(toks[3], 16)
 else:
 continue
 except IndexError: #happens if theres a partial line at the 
 end of file
 print indexerror
 break

 However, when I run it, it seems that I'm not catching the IndexError:
 Traceback (most recent call last):
   File /home/dschuff/bin/speeds.py, line 202, in ?
 if int(toks[2],16) == qaddrs[i]+0x1000 and toks[0] == 200: #producer
 write
 IndexError: list index out of range

 If i change the except IndexError to except Exception, it will catch it (but
 i believe it's still an IndexError).
 this is python 2.3 on Debian sarge.

 any ideas?


Sounds like IndexError has been redefined somewhere, e.g.:
  IndexError = 'something entirely different'
  foo = []
  try:
  foo[42]
  except IndexError: # will not catch the real IndexError; we're
shadowing it
  pass

Try adding print IndexError right before your trouble spot, and see
if it outputs exceptions.IndexError.

--Ben

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


Re: No

2006-02-22 Thread Gaz
(the Input type = FILE is in the field)

please check this out

import ftplib
import os

...

def upload(ftp, file):
ext = os.path.splitext(file)[1]
if ext in (.txt, .htm, .html):
ftp.storlines(STOR  + file, open(file))
else:
ftp.storbinary(STOR  + file, open(file, rb), 1024)

ftp = ftplib.FTP(ftp..f2o.org)
ftp.login(X, X)

upload(ftp, c:\check.jpg)

I'm still getting the file not found error:

http://img153.imageshack.us/img153/2720/error3ps.jpg

I believe the path is kinda wrong or something. But this time, the
script is supposed to fetch the file from my pc.

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


Re: Python vs. Lisp -- please explain

2006-02-22 Thread Alexander Schmolck
Michele Simionato [EMAIL PROTECTED] writes:

 I replied to this message yesterday, but it did not appear, so let's
 try again.
 
 I agree with your points, but I would not say that Lisp is
 intrinsically more dynamic than Python as a language;

Neither would I -- I don't think either is obviously more dynamic than the
other.

But since it has been implied that python's comparatively poor performance is
simply due to it being more dynamic than other languages, I wanted to point
out that one could with just as much justification claim CL to be more dynamic
than python (it is in some regards, but not in others -- how to weight them to
achieve some overall score is not obvious. I really doubt that python will
ever come remotely close to the level of dynamism that now defunct lispmachine
technology achieved, though).

 it is just more interactive and has more features (and more complexities
 too).

Indeed -- CL is much more complex than python and has many, many more warts.

As for common lisp being just more interactive -- all things being equal I
fail to see how more interactive cannot imply more dynamic -- IMO it doesn't
get much more dynamic than changing and inspecting things interactively. Also
not all the ways in which CL is more dynamic represent features that increase
complexity. For example in CL you could just write

  def foo(x, l=[], N=len(l)): [...]

and have it work as expected because defaults are evaluated on call (this is
one of the very rare occassions of an obvious design wart in python, IMO).

In other cases, of course, more dynamism seems to involve added complexity.
For example CL has sane (dynamically scoped) global variables (and local ones,
if you declare them special). I think python is somewhat broken in this
regard, but I must admit I have no idea how to implement dynamically scoped
variables simply and pythonically, so I wouldn't call it an obvious design
flaw.

 BTW, regarding your first point on interactive sessions, are you aware
 of Michael Hudson's recipe
 automatically upgrade class instances on reload()
 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/160164 ?

Thanks, it's nice to be aware of other solutions, I'll have a closer look at
some point. I've of course also written my own code for that purpose -- apart
from ipython.el and a couple of private utilities I even got sufficiently
pissed off by bugs introduced by python's poor support for serious interactive
work that I started writing some sort of versioned module system that kept
track of what was being imported from where to where, but I ran out of time
and ultimately for this and unrelated reasons switched to matlab in this
particular case.

Matlab sucks in countless ways, but it gives a superior interactive
environment. If you do experimental work where state is expensive to recompute
from scratch but where you need to tune various parameters to obtain the
desired results, problems introduced by changes not properly propagating are
very, very irritating -- especially if you want to keep a record of what changes
effected what, so that your experiments are repeatable.

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


Re: Pyserial never read

2006-02-22 Thread sam
luca72 wrote:
 Thanks to all for the help,

 here you find the code, pls note if i use handshaking = 1 the
 application don't start.
 in the delphi configuratio of com port if i use or not handshaking the
 application work.
 Best Regards at all

 Luca

 import serial
 import win32file
 port = 2

Is port = 2 correct?
I thought that com ports under windows are designated as a string
com1,com2,..etc.

 baudrate = 38400
 bytesize =serial.EIGHTBITS
 parity =serial.PARITY_ODD
 stopbits =serial.STOPBITS_TWO
 timeout = 1
 ser = serial.Serial(2, baudrate=38400, bytesize=8,
 parity=serial.PARITY_ODD, stopbits=2, timeout=3)
 ct = ''
 ch = ''
 a = self.textCtrl1.GetValue()
 ind = 0
 ind1 = 2
 lunghezza = len(a)
 while ind  lunghezza :
 b = a[ind:ind1]
 b = int(b,16)
 b = ~b
 c = ''.join([str((b  Digit)  1) for Digit in range(7,
 -1, -1)])
 c1 = c[0:4]
 c2 = c[4:]
 c1 = c1[3:] + c1[2:3] + c1[1:2] + c1[0:1]
 c2 = c2[3:] + c2[2:3] + c2[1:2] + c2[0:1]
 c1 = hex(int(c1,2))
 c2 = hex(int(c2,2))
 c1 = c1[2:]
 c2 = c2[2:]
 c = c2+c1
 ct = ct + c
 ind = ind + 2
 ind1 = ind1 + 2
 c = int(c,16)
 c = chr(c)
 ch = ch + c


 ser.write(ch)

 elf.textCtrl2.SetValue(ct)
 ser.readline()
 You might want to try using ser.read() instead of ser.readline() as
you may not be getting  linefeed carrage return characters . I usually
setup a buffer to scan for the characters I expect.




 Pls.Note i hove also try with read(number of byte ) with inWaiting(),
 flush  etc
 
 
 But no result.
 
 Thanks Luca

Hope this helps
Sam Schulenburg

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


Re: except clause not catching IndexError

2006-02-22 Thread Scott David Daniels
Derek Schuff wrote:
 I have some code like this:
 code nobody else can run

 However, when I run it, it seems that I'm not catching the IndexError:
 Traceback (most recent call last):
   File /home/dschuff/bin/speeds.py, line 202, in ?
 if int(toks[2],16) == qaddrs[i]+0x1000 and toks[0] == 200: #producer
 write
 IndexError: list index out of range

This was good, the actual error; I suspect you overwrote IndexError.
The general principal is to boil down your code to the smallest code
that exhibits the problem.  This is not just to aid us, since usually
at some point you delete a block of lines and the problem goes
magically away.

 If i change the except IndexError to except Exception, it will catch it (but
 i believe it's still an IndexError). This is python 2.3 on Debian sarge.
More points for identifying Python version and OS.

 any ideas?
As above, but to test my theory:

...
 except Exception, e:
 print 'caught %r: %r (IndexError is %r)' % (
  e, e.__class__, IndexError)

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


Re: except clause not catching IndexError

2006-02-22 Thread Derek Schuff
Erwin S. Andreasen wrote:

 Did you by any chance do something like:
 
 except ValueError, IndexError:
 
 at some point earlier in this function? That, when catching ValueError
 assigns the resulting exception to IndexError (and so the following
 except IndexError: wouldn't work as IndexError is no longer what you
 think it is). The correct syntax for catching multiple exceptions is:
 
 except (ValueError, IndexError), targetVariable:
 
 You could verify this by doing a print repr(IndexError) before your
 line 202, to see that it really is the IndexError builtin.
 

hey, nice catch. In fact I did exactly that. in my search for a solution for
this problem i discovered the catch-a-tuple-of-exceptions error, and in
fact fixed it, but didn't realize that it was related to the one I posted.
(the idea that exceptions can be redefined caught me off guard).

thanks (to both of you who responded),
-derek
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pyserial never read

2006-02-22 Thread Grant Edwards
On 2006-02-22, sam [EMAIL PROTECTED] wrote:
 luca72 wrote:
 Thanks to all for the help,

 here you find the code, pls note if i use handshaking = 1 the
 application don't start.
 in the delphi configuratio of com port if i use or not handshaking the
 application work.
 Best Regards at all

 Luca

 import serial
 import win32file
 port = 2

 Is port = 2 correct?

Read the fine documentation at http://pyserial.sourceforge.net/:

 Parameters for the Serial class
 
 ser = serial.Serial(
 port=None,  #number of device, numbering starts at
 #zero. if everything fails, the user
 #can specify a device string, note
 #that this isn't portable anymore
 #if no port is specified an unconfigured
 #an closed serial port object is created
 baudrate=9600,  #baudrate
 bytesize=EIGHTBITS, #number of databits
 parity=PARITY_NONE, #enable parity checking
 stopbits=STOPBITS_ONE,  #number of stopbits
 timeout=None,   #set a timeout value, None for waiting forever
 xonxoff=0,  #enable software flow control
 rtscts=0,   #enable RTS/CTS flow control
 )
 
 I thought that com ports under windows are designated as a string
 com1,com2,..etc.

You can use those as well, but they're non-portable.  
serial.Serial(port=0) will open the first serial port on either
windows or linux.

-- 
Grant Edwards   grante Yow!  Ha ha  Ha ha Ha ha
  at   Ha Ha Ha Ha -- When will I
   visi.comEVER stop HAVING FUN?!!
-- 
http://mail.python.org/mailman/listinfo/python-list


How to force creation of a .pyc?

2006-02-22 Thread mrstephengross
I would like to distribute a python program, but only in .pyc form (so
that people cannot simply look at my code). Is there a way to do this?
I've read up a little on the logic by which python creates .pyc's, and
it sounds like python requires the main executed program to be in .py
format. Any ideas?

Thanks
--Steve ([EMAIL PROTECTED])

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


Re: Pyserial never read

2006-02-22 Thread sam
Thanks for the info Grant. It'll teach me not to read the documentation
:) 

Sam

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


Re: No

2006-02-22 Thread Gerard Flanagan

Gaz wrote:
 (the Input type = FILE is in the field)

 please check this out

 import ftplib
 import os

 ...

 def upload(ftp, file):
 ext = os.path.splitext(file)[1]
 if ext in (.txt, .htm, .html):
 ftp.storlines(STOR  + file, open(file))
 else:
 ftp.storbinary(STOR  + file, open(file, rb), 1024)

 ftp = ftplib.FTP(ftp..f2o.org)
 ftp.login(X, X)

 upload(ftp, c:\check.jpg)

 I'm still getting the file not found error:

 http://img153.imageshack.us/img153/2720/error3ps.jpg

 I believe the path is kinda wrong or something. But this time, the
 script is supposed to fetch the file from my pc.

Gaz

Google file upload cgi.

Gerard

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


Re: Tkinter canvas size determination

2006-02-22 Thread Cameron Laird
In article [EMAIL PROTECTED],
Dean Allen Provins  [EMAIL PROTECTED] wrote:
I need to determine the size of a canvas while the process is running.
Does anyone know of a technique that will let me do that?
.
.
.
Does
   import Tkinter
   c = Tkinter.Canvas()
   c.create_oval(13, 51, 80, 130)
  1
   c.pack()
   print c.cget(width)
  284
help?

There are actually several different notions of the size of a
canvas.  The example abovve should be a good starting point,
though.  

There's also a mailing list specifically for Tkinter URL:
http://tkinter.unpythonic.net/wiki/mailing_20lists  ; that
might interest you.
-- 
http://mail.python.org/mailman/listinfo/python-list


graph display(please help)

2006-02-22 Thread questions?
I heard from my friend who used to program in JAVA, it is really easy
to do graph display in JAVA.

I wonder whether there are similiar packages in Python I can use. Since
I know a little bit Python syntax  already, I can easily learn more in
Python.

I want to display connected graph(directed or undirected, most often
trees) with coloring on them.

Thanks for any suggestions!!!

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


Re: Exiting os.spawnv's subroutine

2006-02-22 Thread IamIan
Strange but removing the try/except part of the second script (leaving
only the processing) removed the 2 minute lag at the end of each
subroutine.

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


Re: PyUNO with different Python

2006-02-22 Thread Michele Petrazzo
� wrote:
 Hi! maybe somebody can give me an hint to my problem setting up PyUNO
 on my Mac to work with my Python not the Python delivered with
 OpenOffice. As said in installation instructions I've set 
 OPENOFFICE_PATH=/usr/lib/openoffice/program export
 PYTHONPATH=$OPENOFFICE_PATH export
 LD_LIBRARY_PATH=$OPENOFFICE_PATH according to my environment.
 
 importing uno gives me this error:
 
 import uno
 Traceback (most recent call last): File stdin, line 1, in ? File
 /Applications/OpenOffice.org 
 2.0.app/Contents/openoffice.org2.0/program/uno.py, line 37, in ? 
 import pyuno ImportError: No module named pyuno
 
 which means python finds uno but not pyuno (pyuno.dylib).
 

Do you want to use system python inside OOo (inside a macro, or...), or
system python outside OOo?

For the first, follow this:
http://udk.openoffice.org/python/python-bridge.html#replacing

for the second:
http://udk.openoffice.org/python/python-bridge.html#modes

 Any hints? Regards, Katja

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

Re: graph display(please help)

2006-02-22 Thread Bill Scherer
questions? wrote:

 I heard from my friend who used to program in JAVA, it is really easy
 to do graph display in JAVA.

 I wonder whether there are similiar packages in Python I can use. Since
 I know a little bit Python syntax  already, I can easily learn more in
 Python.

 I want to display connected graph(directed or undirected, most often
 trees) with coloring on them.

The just released yapgvb would seem to fit: 
http://sourceforge.net/projects/yapgvb

 Thanks for any suggestions!!!

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


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


Re: Python vs. Lisp -- please explain

2006-02-22 Thread Luis M. González
Carl Friedrich Bolz wrote:
 Paul Rubin wrote:
 Well. ... the PyPy team works on ... is definitively much too strong.
 It is more like ... the PyPy team is thinking about  It is very
 unclear whether it will work on a technical level and whether the EU
 will allow us to allocate resources accordingly.

In this thread
http://groups.google.com/group/comp.lang.python/msg/5132f0d48c9e7be9
Christian Tismer said that he would work on this, even if this is not
pursued by the Pypy team, because he has personal reasons for doing it.

So I'm confident that sooner or later, it will be possible to create
extension modules written in Rpython.

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


Re: How to force creation of a .pyc?

2006-02-22 Thread Nick Smallbone
mrstephengross wrote:
 I would like to distribute a python program, but only in .pyc form (so
 that people cannot simply look at my code). Is there a way to do this?
 I've read up a little on the logic by which python creates .pyc's, and
 it sounds like python requires the main executed program to be in .py
 format. Any ideas?


If your main program is in main.py, you could perhaps launch it with
python -c import main, or make another file which just does import
main. Then you could keep just the .pycs/.pyos.

But it's possible for a determined user to recover a lot of information
about the source code. For example, if I write

def foo(a):
   for i in range(a):
  print i

then

 dis.dis(foo)
  2   0 SETUP_LOOP  25 (to 28)
  3 LOAD_GLOBAL  0 (range)
  6 LOAD_FAST0 (a)
  9 CALL_FUNCTION1
 12 GET_ITER
   13 FOR_ITER11 (to 27)
 16 STORE_FAST   1 (i)

  3  19 LOAD_FAST1 (i)
 22 PRINT_ITEM
 23 PRINT_NEWLINE
 24 JUMP_ABSOLUTE   13
   27 POP_BLOCK
   28 LOAD_CONST   0 (None)
 31 RETURN_VALUE

where 0..12 makes an iterator for range(a), 16..19 updates i and 22..23
prints it out. It would be possible to turn it into equivalent source
code. Decompyle (from
http://ftp.debian.org/debian/pool/main/d/decompyle/decompyle_2.3.2.orig.tar.gz)
can even do that.

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


Re: Python vs. Lisp -- please explain

2006-02-22 Thread Isaac Gouy

Steven D'Aprano wrote:
 On Tue, 21 Feb 2006 09:46:27 -0800, Donn Cave wrote:

  In article [EMAIL PROTECTED],
   Steven D'Aprano [EMAIL PROTECTED] wrote:
  ...
  Hey Donn, here is a compiled program for the PowerPC,
  or an ARM processor, or one of IBM's Big Iron
  mainframes. Or even a Commodore 64. What do you think
  the chances are that you can execute it on your
  x86-compatible PC? It's compiled, it should just
  work!!! Right?
 
  No of course not. If your CPU can't interpret the
  machine code correctly, the fact that the code is
  compiled makes NO difference at all.

 [snip for brevity]

  Sure, all this is true, except for the term interpreter.
  You would surely not use the word that way, unless you
  just didn't want to communicate.

 Do you honestly believe that the CPU doesn't have to interpret the machine
 code, or are you just deliberately playing silly buggers with language?

 In modern CPUs, there is an intermediate layer of micro-code between the
 machine code your C compiler generates and the actual instructions
 executed in hardware. But even if we limit ourselves to obsolete hardware
 without micro-code, I ask you think about what an interpreter does, and
 what the CPU does, in the most general way possible.

 Both take a stream of instructions. Both have to take each instruction,
 and execute it. In both cases the link between the instruction and the
 effect is indirect: for example, the machine code 0101 on the
 Zilog Z80 processor causes the CPU to decrement the B processor register.
 In assembly language this would be written as DEC B. There is absolutely
 nothing fundamental about the byte value 5 that inherently means
 decrement B processor register.

 In other words, machine language is a language, just like it says, and
 like all languages, it must be interpreted.

  Your paragraph above that starts with No of course not,
  even omits a point that everyone understands, you can in
  fact expect a .py file will work independent of machine
  architecture - like any interpreted language.

 Amazing. In your previous post you were telling everybody how the
 *disadvantage* of interpreted programs is that they won't run unless the
 interpreter is present, and in this post you are telling us that
 interpreted languages will just work. What happened to the requirement for
 an interpreter?

 Let's see you run that Python program on a Zilog Z80 without a Python
 interpreter. Can't be done. No interpreter, whether in hardware or
 software, and the program won't run, whether in source code or byte code
 or machine code.

 If I allow that the machines have an interpreter, perhaps you'll return
 the favour and install an interpreter for machine language (often called
 an emulator). Now your compiled C or Lisp code also will run independent
 of machine architecture.

 In order to force interpreted language and compiled language into two
 distinct categories, rather than just two overlapping extremes of a single
 unified category, you have to ignore reality. You ignore interpreted
 languages that are compiled, you ignore the reality of how machine code is
 used in the CPU, you ignore the existence of emulators, and you ignore
 virtual machines.


  We all know
  what native code compilation buys you and what it doesn't.

 Did you fail to learn *anything* from my parable of interpreted Lisp on a
 Macintosh II running faster than compiled Lisp running on a Mac II fitted
 with a Lisp processor?


 --
 Steven

A different perspective:

Although we refer to Lua as an interpreted language, Lua always
precompiles source code to an intermediate form before running it.
(This is not a big deal: Most interpreted languages do the same.) The
presence of a compilation phase may sound out of place in an
interpreted language like Lua. However, the distinguishing feature of
interpreted languages is not that they are not compiled, but that any
eventual compiler is part of the language runtime and that, therefore,
it is possible (and easy) to execute code generated on the fly. We may
say that the presence of a function like dofile is what allows Lua to
be called an interpreted language.

p57 Programming in Lua

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


Re: How to force creation of a .pyc?

2006-02-22 Thread Jeffrey Schwab
mrstephengross wrote:
 I would like to distribute a python program, but only in .pyc form (so
 that people cannot simply look at my code). Is there a way to do this?
 I've read up a little on the logic by which python creates .pyc's, and
 it sounds like python requires the main executed program to be in .py
 format. Any ideas?

Make a dummy script to import your main module.  The resulting pyc can 
be fed directly to the Python interpreter.

--
# main.py : My main source code.  I cleverly will distribute only the
# byte code, such that no one knows my secrets.  D'oh!  You caught me
# monologging again...

if __name__ == __main__:
print Ha!  Now you can't see me.
--
# dummy.py : Imports the main module to create main.pyc.

import main
--
[some client's prompt]% python main.py
Ha!  Now you can't see me.
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   >