filelike 0.3.0

2009-01-16 Thread Ryan Kelly

Hi All,


  I'm pleased to announce the v0.3.0 release of filelike, a module for
easy creation and manipulation of objects that provide a rich file-like
interface.  New in this version we have:

  * support for seek() and tell() in FileLikeBase
  * much better support for intermingling reads and writes
  * rearranged filelike.wrappers to provide consistent naming scheme
  * filelike.join function: concatenate several file-like objects so
they behave like a single file
  * filelike.slice function: access a portion of a file-like object as
if it were an independent file
  * Buffered wrapper class: emulate seekability on streaming
input/output


 Along with a host of small fixes and new test cases.  All the details
are available at the project website:

   http://www.rfk.id.au/software/projects/filelike/


  Cheers,

 Ryan



-- 
Ryan Kelly
http://www.rfk.id.au  |  This message is digitally signed. Please visit
r...@rfk.id.au|  http://www.rfk.id.au/ramblings/gpg/ for details



signature.asc
Description: This is a digitally signed message part
--
http://mail.python.org/mailman/listinfo/python-announce-list

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


Re: Suggested improvements for IDLE (non-official)

2009-01-16 Thread Terry Reedy

Tim H wrote:

r wrote:

On Jan 14, 4:43 pm, Terry Reedy tjre...@udel.edu wrote:



OFF-TOPIC:(but related)
What is the state of Tkinter at this point. Is an active effort under
way to port TK 8.5 into Python? Tkinter and IDLE are very important to
Python, but i understand there are much more important areas where the
GURU's are concentrating. Should there be a calling for others to
get involved here? I would like to help out.
Thanks


Maybe I'm misunderstanding something here, but About Idle in Python 
2.6.1 (win32) says Tk version: 8.5


Same in 3.0.  I check .../python30/tcl/ and it has tck8/ tcl8.5, tix8.4, 
tk8.5 subdirs.


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


Re: Does Python really follow its philosophy of Readability counts?

2009-01-16 Thread Paul Rubin
Terry Reedy tjre...@udel.edu writes:
  Have you looked at Tim Sweeney's talk that I mentioned in another post?
  http://www.st.cs.uni-saarland.de/edu/seminare/2005/advanced-fp/docs/s...
 
 I did.  He gives a really nice use case for Python's ability to
 dynamically modify classes imported from a library.  (Were not you
 arguing against that?  Or was is someone else?)

He is talking about extending classes by something like inheritance,
not modifying them dynamically.  This is also in the context of an
extremely powerful static type system with existential and dependent
types, and totality proofs for just about everything.  That is about a
billion light years away from anything anyone has ever proposed for
Python.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Alphametric fun with Python

2009-01-16 Thread bearophileHUGS
Terry Reedy:
It illustrates well the point you intended.

I don't know what my point was.

A suggestion: with that solver, to find solution in a faster way you
have to write many equations.

Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list


Re: Does Python really follow its philosophy of Readability counts?

2009-01-16 Thread Hendrik van Rooyen
James Mills prolo...tcircuit.net.au wrote:

 At the most basic level do you really think a machine
 really cares about whether -you- the programmer
 has illegally accessed something you shouldn't have ?

Yes it does - this is exactly why some chips have supervisor
and user modes - to keep the monkeys away from the typewriter.

- Hendrik



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


Re: Convention vs. fascism

2009-01-16 Thread Hendrik van Rooyen

 Aaron Brady cas@gmail.com wrote:

On Jan 15, 6:41 pm, Steven D'Aprano st...@remove-this-
cybersource.com.au wrote:
 On Fri, 16 Jan 2009 10:24:19 +1100, Ben Finney wrote:
  Steven D'Aprano st...@remove-this-cybersource.com.au writes:

  On Fri, 16 Jan 2009 07:58:49 +1100, Ben Finney wrote:

   Steven D'Aprano st...@remove-this-cybersource.com.au writes:

   On Thu, 15 Jan 2009 10:08:37 +0100, Diez B. Roggisch wrote:

Familiarize yourself with PEP8 for naming and coding-conventions
first.

 8 -- stuff giving Diez a hard time for the
above 

Oh come on you lot - you are carrying on as if Diez were wearing his
skull socks again - do me a favour and give him a break!

- Hendrik



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


Re: spam on the list - how are things now?

2009-01-16 Thread Hendrik van Rooyen

Terry Reedy tjre...@udel.edu wrote:

 James Mills wrote:
  On Fri, Jan 16, 2009 at 1:30 PM,  s...@pobox.com wrote:
  We've been running SpamBayes on the news-to-mail gateway on mail.python.org
  for a couple weeks now.  To me it seems like the level of spam leaking onto
  the list has dropped way down but I'd like some feedback from people who
  read the python-list@python.org mailing list on the topic.
 
  Agreed. It has gone down. Thank you for taking the
  time to do something about it :)

 Reading from gmane, there has not been much obvious spam lately.  Thanks.

I read this solely via the mailing list - and Yes, whatever was done has helped
a lot.

- Hendrik

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


Re: [Python-Dev] multiprocessing vs. distributed processing

2009-01-16 Thread James Mills
On Fri, Jan 16, 2009 at 6:30 PM, Matthieu Brucher
matthieu.bruc...@gmail.com wrote:
 2009/1/16 James Mills prolo...@shortcircuit.net.au:
 I've noticed over the past few weeks lots of questions
 asked about multi-processing (including myself).

 Funny, I was going to blog about this, but not just for Python.

 For those of you new to multi-processing, perhaps this
 thread may help you. Some things I want to start off
 with to point out are:

 multiprocessing will not always help you get things done faster.

 Of course. There are some programs that are I/O or memory bandwidth
 bound. So if one of those bottlenecks is common to the cores you use,
 you can't benefit from their use.

 be aware of I/O bound applications vs. CPU bound

 Exactly. We read a lot about fold...@home, s...@home, they can be
 distributed, as it is more or less take a chunk, process it somewhere
 and when you're finish tell me if there something interesting in it.
 Not a lot of communications between the nodes. Then, there are other
 applications that process a lot of data, they must read data from
 memory, make one computation, read other data, compute a little bit
 (finite difference schemes), and here we are memory bandwidth bound,
 not CPU bound.

 multiple CPUs (cores) can compute multiple concurrent expressions -
 not read 2 files concurrently

 Let's say that this is true for the usual computers. Clusters can make
 concurrent reads, as long as there is the correct architecture behind.
 Of course, if you only have one hard disk, you are limited.

 in some cases, you may be after distributed processing rather than
 multi or parallel processing

 Of course. Clusters can be expensive, their interconnections even
 more. So if your application is made of independent blocks that can
 run on small nodes, without much I/Os, you can try distributed
 computing. If you need big nodes with high-speed interconnections, you
 will have to use parallel processing.

 This is just what my thoughts on the sucjet are, but I think I'm not
 far from the truth. Of course, if I'm proved wrong, I'll be glad to
 hear why.

Thank you Matthieu for your  response.
Very good comments on some of the points
I raised. Hopefully those interested in the topic
will learn from this thread.

cheers
James

PS: I assumed you meant to post back to the list and not just me :)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Convention vs. fascism

2009-01-16 Thread Steven D'Aprano
On Fri, 16 Jan 2009 10:03:28 +0200, Hendrik van Rooyen wrote:

 Oh come on you lot - you are carrying on as if Diez were wearing his
 skull socks again - do me a favour and give him a break!

Well, for what it's worth, I should say one final thing:

I didn't disagree with what Diez said, only the way he said it. I thought 
my original post made that clear, but perhaps I should have said so 
explicitly. And I certainly don't think less of him because of it.

And... skull socks? Cool. Where can I get some?


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


Re: reverse dict lookup Relation class

2009-01-16 Thread Aaron Brady
On Jan 14, 7:04 pm, Chris Rebert c...@rebertia.com wrote:
 On Wed, Jan 14, 2009 at 4:30 PM, Aaron Brady castiro...@gmail.com wrote:
  Hi, this is a continuation of something that comes up now and again
  about reverse lookups on dictionaries, as well as a follow-up to my
  pursuit of a Relation class from earlier.
snip
  Or, and this is the interesting part, use the ('identificationally')
  same tuples in both mappings, since the object is only mentioned, not
  used.

  phone[ '555-963' ]= [ ( 'Joan', '555-963', '9a-5p' ) ]
  phone[ '555-964' ]= [ ( 'Joan', '555-964', '5p-11p' ) ]
  name[ 'Joan' ]= [ ( 'Joan', '555-963', '9a-5p' ), ( 'Joan', '555-964',
  '5p-11p' ) ]
  hourstocall[ '9a-5p' ]= [ ( 'Joan', '555-963', '9a-5p' ) ]
  hourstocall[ '5p-11p' ]= [ ( 'Joan', '555-964', '5p-11p' ) ]

  What's the best way to construct this class?  Or, do you have an
  argument that it could not be simpler than using a relational db?
  Brainstorming, not flamestorming.

 Once you get beyond a main dict (e.g. name2phone) and one that's its
 inverse (e.g. phone2name), yeah, I'd probably say you should be using
 a relational DB for this. You could also use objects, but it sounds
 like you really want to use SQL-like querying, which isn't well-suited
 to plain objects (though it'd be fine with an ORM).

I want the simplest data structure that can hold a relation.  In this
case, I would declare a new record as:

PhoneInfo( 'Joan', '555-963', '9a-5p' )
PhoneInfo( 'Joan', '555-964', '5p-11p' )

However the syntax is flexible, such as in 'PhoneInfo.add' etc.

I can query the structure myself if I can access it as an iterable of
tuples.  I think I want to use named tuples.

for rec in PhoneInfo.records:
if rec.name== 'Joan':
something

Or I can just use itertools.ifilter.

recset= ifilter( lambda rec: rec.name== 'Joan', PhoneInfo.records )
for rec in recset:
something

Using objects is one advantage, since they are live (unserialized)
and native, such as a relation of socket connections.  (SQL would
require an additional mapping object and a key to accomplish it.)
--
http://mail.python.org/mailman/listinfo/python-list


RE: problem in implementing multiprocessing

2009-01-16 Thread gopal mishra
I create two heavy objects sequentially without using multipleProcessing
then creation of the objects takes 2.5 sec.if i create these two objects in
separate process then total time is 6.4 sec.

i am thinking it is happening due to the pickling and unpickling of the
objects.if i am right then what could be the sollution.

my system configuration:
dual-core processor
winXP
python2.6.1


gopal mishra wrote:
 Hello, 
 
 I am trying to implement the multiprocessing in my application to take
 advantage of multiple cores. I have created two
 
 Separate process something like this.
 
 que = Queue
 Process(target = getData, args=(que , section, MdbFile,)).start()
 Process(target = getData, args=(que , section, MdbFile,)).start()
 
 In getData function I create the object(max 7MB size) and add in to queue
 (que.put (object)).
 
 After that I fetch the object using que.get () and use in my application.
 but it takes more time to get the data.

More time than what?  Than not getting the date?  Than getting it some 
other way?

CPU, OS, and Python version may also be relevant.

 Any one can help me out this problem.
 
 Thanks,
 Sibtey
 
 My code
 from multiprocessing import Process, Queue
 
 def getData(queue, section, mdbFile):
 
 This function returns the gapappdata for the given mdb file.
 
 app  = MdbFile(mdbFile)
 mdbData = app.data#it is a heavy object
 queue.put((section,mdbData))
 
 def getData2(mdbFile):
 
 This function returns the gapappdata for the given mdb file.
 
 app  = MdbFile(mdbFile)
 mdbData = app.data#it is a heavy object
 return mdbData
 
 def test_multipleProcess(fromMdbFile, toMdbFile):
 #multipleProcess
 t1 = time.time()
 queue = Queue()
 sections = ['From', 'To']
 Process(target= getData_1, args=(queue, 'From',fromMdbFile,)).start()
 Process(target= getData_1, args=(queue, 'To',toMdbFile,)).start()
 section, gapAppData = queue.get()
 section, gapAppData = queue.get()
 t2 = time.time()
 print total time using multiProcessing:,t2-t1
 d1 = getData2(fromMdbFile)
 d2 = getData2(toMdbFile)
 print total time withought multiProcessing:, time.time()-t2
 
 
 
 
 
 if __name__=='__main__':
 f1 =r a.mdb
 f2 =rb.mdb
 test_multipleProcess(f1,f2)
 
 --
 http://mail.python.org/mailman/listinfo/python-list
 



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


Re: Does Python really follow its philosophy of Readability counts?

2009-01-16 Thread Éric Daigneault
Hendrik van Rooyento keep the monkeys away from the typewriter.
Love it... just fully describes why we should keep some parts hidden from
the pointyHairedBossHired Code monkeys...

I'd like to think I know what I am doing...   can't say the same of all
people that have access to the code unfortunately... also I have very little
control over who has access to what.. if pointy haired boss says monkey A
has access to all then gotta live with it.  So this is why,
however shameful it may be, I will not use python here for production stuff.
 --- God I miss it, however scary the ride may feel to a hardcore Java guy..
it sure was fun.

Terry Reedy
 I did.  He gives a really nice use case for Python's ability to
 dynamically modify classes imported from a library.  (Were not you
 arguing against that?  Or was is someone else?)

There is a place for these kind of hacks, however, see code monkeys above, I
would want to make sure it is very well encapsulated (wrapper library for
example) before I release it as a lib to the internal zoo.  The thing that
gets me with all this talk about dynamic access to private wannabe
variables...

What happens to your coupling, I like my code nice and tidy, high internal
coupling is allowed but from the wild I would tend to want to reduce it as
much as possible.  Dynamically replaced code is a nice idea indeed and I
could think of a few really nice uses for this (good luck for this kind of
flexibility in Java) but doing so you willingly break the encapsulation
convention, thus you must also manage the possible consequences
that arise from this break.

Python is nice quick and flexible... but it provides so much rope a monkey
would hang the whole ecosystem with it.

Me I like the big spool, but as some wise dude once said with great power
comes great responsibilities.



On Fri, Jan 16, 2009 at 3:53 PM, Hendrik van Rooyen m...@microcorp.co.zawrote:

 James Mills prolo...tcircuit.net.au wrote:

  At the most basic level do you really think a machine
  really cares about whether -you- the programmer
  has illegally accessed something you shouldn't have ?

 Yes it does - this is exactly why some chips have supervisor
 and user modes - to keep the monkeys away from the typewriter.

 - Hendrik



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

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


Re: reverse dict lookup Relation class

2009-01-16 Thread Aaron Brady
On Jan 14, 7:54 pm, MRAB goo...@mrabarnett.plus.com wrote:
 Aaron Brady wrote:
  Hi, this is a continuation of something that comes up now and again
  about reverse lookups on dictionaries, as well as a follow-up to my
  pursuit of a Relation class from earlier.

  For a reverse lookup, you just need two lookups.
  name= {}
  phone= {}
  name[ '555-963' ]= 'Joan'
  phone[ 'Joan' ]= '555-963'

  Though maybe the keys in 'name' should be names, instead of the
  values in it.  The variable name doesn't clarify that.  (What is more
  natural to you in reading code?  Is one obviously wrong?)

  phone[ '555-963' ]= 'Joan'
  name[ 'Joan' ]= '555-963'

 Consider str(x). It isn't saying x is a string, it's saying x as a
 string. Similarly, ord(x) says the ordinal value of x. So,
 phone[x] means the phone number of x.

That's true.  However, I want to map individual fields of records to
the tuples (named tuples) containing the records themselves (unless I
just need a set of tuples).

I think what you are talking about is accessing the 'phone' field,
which was not what I was thinking.  (You see that in algorithm
pseudocode a bit.)  For that, you could use 'name[ tuple1 ]' to obtain
the name.  However, in relational data, there is no single key, of
which the rest of the fields are just accessories.  (Does that make
sense?)  I think I want to use the multiple mappings for different
ways to have access to the data.

 [snip] What's the best way to construct this class?  Or, do you have an
  argument that it could not be simpler than using a relational db?
  Brainstorming, not flamestorming.

 You could imagine an object where you provide a field name and a value
 and it returns all those entries where that field contains that value.
 That, basically, is a database.

That's true.  The mapping objects wouldn't be particularly helpful if
I had patterns to match instead of exact values... as now I'm thinking
you usually would.  In other words, providing the mapping objects,
even grouped together in a provider object, would only handle a small
subset of possible queries, specifically exact equality.  For example,
the 'hourstocall' object is basically useless as specified.  Even
separating the fields wouldn't help in a hash.  The separate fields
would need to be stored in sorted lists, using 'bisect' to test
inequality.  (How does an SQL service implement inequality checks
anyway?)

However, it's interesting that my first thought was to start out with
a mapping object, instead of just a set of 'namedtuple's.
--
http://mail.python.org/mailman/listinfo/python-list


Re: List comprehension - NameError: name '_[1]' is not defined ?

2009-01-16 Thread Peter Otten
Terry Reedy wrote:

 Peter Otten wrote:
 
 List comprehensions delete the helper variable after completion:
 
 I do not believe they did in 2.4.  Not sure of 2.5.  

As Mario said, 2.4, 2.5, and 2.6 all show the same behaviour.

 There is certainly 
   a very different implementation in 3.0 and, I think, 2.6.  OP
 neglected to mention Python version he tested on. Code meant to run on
 2.4 to 3.0 cannot depend on subtle listcomp details.

3.0 behaves different. Like generator expressions listcomps no longer leak
the loop variable, and this is implemented by having each listcomp execute
as a nested function:

 In 3.0
   def f(): [i for i in [1]]
 
   import dis
   dis.dis(f)
1   0 LOAD_CONST   1 (code object listcomp at
 0x01349BF0, file pyshell#12, line 1)
3 MAKE_FUNCTION0
6 LOAD_CONST   2 (1)
9 BUILD_LIST   1
   12 GET_ITER
   13 CALL_FUNCTION1
   16 POP_TOP
   17 LOAD_CONST   0 (None)
   20 RETURN_VALUE

This is more robust (at least I can't think of a way to break it like the
2.x approach) but probably slower due to the function call overhead. The
helper variable is still there, but the possibility of a clash with another
helper is gone (disclaimer: I didn't check this in the Python source) so
instead of

# 2.5 and 2.6 (2.4 has the names in a different order)

 def f():
... [[i for i in ()] for k in ()]
...
 f.func_code.co_varnames
('_[1]', 'k', '_[2]', 'i')

we get

# 3.0

 def f():
... [[i for i in ()] for k in ()]
...
 f.__code__.co_varnames
()

The variables are gone from f's scope, as 3.x listcomps no longer leak their
loop variables.

 f.__code__.co_consts
(None, code object listcomp at 0x2b8d7f6d7530, file stdin, line 2,
())
 outer = f.__code__.co_consts[1]
 outer.co_varnames
('.0', '_[1]', 'k')

Again the inner listcomp is separated from the outer.

 outer.co_consts
(code object listcomp at 0x2b8d7f6d26b0, file stdin, line 2, ())
 inner = outer.co_consts[0]
 inner.co_varnames
('.0', '_[1]', 'i')


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


Re: lazy evaluation is sometimes too lazy... help please.

2009-01-16 Thread James Stroud

Ken Pu wrote:

Hi,  below is the code I thought should create two generates, it[0] =
0,1,2,3,4,5, and it[1] = 0,10,20,30,..., but they turn out to be the
same!!!

from itertools import *
itlist = [0,0]
for i in range(2):
  itlist[i] = (x+(i*10) for x in count())

print what's in the bags:
print list(islice(itlist[0], 5))
print list(islice(itlist[1], 5))

The output is:
[10, 11, 12, 13, 14]
[10, 11, 12, 13, 14]

I see what Python is doing -- lazy evaluation doesn't evaluate
(x+(i*10) for x in count()) until the end.


It doesn't evaluate it until you ask it to, which is the right behavior. 
However, when evaluated, it evaluates i also, which is the last value 
to which i was assigned, namely the integer 1. I'm going to get flamed 
pretty hard for this, but it doesn't seem to be the intuitive behavior 
to me either. However, in a purely functional language, you wouldn't be 
able to construct a list of generators in this way.


With python, you have to remember to adopt a purely functional design 
and then pray for best results. You can store generators in a list, but 
they need to be constructed properly. I can't perfectly transmogrify 
your code into functional code because I don't think making the 
particular anonymous generator you want is possible in python. However 
this is how I would make a close approximation:



from itertools import *

def make_gen(i):
  for x in count():
yield x + (i * 10)

itlist = [make_gen(i) for i in xrange(2)]

print what's in the bags:
print list(islice(itlist[0], 5))
print list(islice(itlist[1], 5))


James

--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

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


Re: Possible bug in Tkinter - Python 2.6

2009-01-16 Thread Eric Brunel

On Thu, 15 Jan 2009 19:09:00 +0100, José Matos jaoma...@gmail.com wrote:


On Thursday 15 January 2009 15:28:36 r wrote:

First of all be very careful using from module import * or you will
have name conflicts. Tkinter is made to be imported this way and i do
it all the time. for the others do.

import tkMessageBox as MB
import tkFileDialog as FD
or whatever floats your boat.


Importing explicitly works for me in Fedora 11 (rawhide):
-
from Tkinter import *
from tkMessageBox import askyesno
from tkFileDialog import askopenfilename

[snip]

What do you mean by 'works'...? You don't have the problem? It doesn't  
change a thing for me...

--
python -c print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])

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


Re: Possible bug in Tkinter - Python 2.6

2009-01-16 Thread Eric Brunel

On Thu, 15 Jan 2009 23:49:22 +0100, Terry Reedy tjre...@udel.edu wrote:

Eric Brunel wrote:

[snip]  And BTW, if this is actually a bug, where can I report it?


bugs.python.org


Thanks. I reported the problem.
--
python -c print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])

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


Re: Client Socket Connection to Java server

2009-01-16 Thread bieffe62
On 16 Gen, 08:10, TechieInsights gdoerm...@gmail.com wrote:
 I am having problems with a socket connection to a Java server.  In
 java I just open the socket, pass the length and then pass the bits
 across the socket.

 I created a socket object:

 import socket

 class MySocket:
         def __init__(self, host='localhost', port = 28192, buffsize = 1024):
                 socket.setdefaulttimeout(10)

                 self.host = host
                 self.port = port
                 self.buffsize = buffsize
                 self.socket = socket.socket(socket.AF_INET, 
 socket.SOCK_STREAM)
                 self.socket.connect((host, port))

         def send(self, data):
                 self.socket.send(data)

         def receive(self):
                 return self.socket.recv(self.buffsize)

         def sendAndReceive(self, data):
                 self.send(data)
                 return self.receive()

         def close(self):
                 self.socket.close()

 But the java server gives the error:
 WARNING: Incoming Message length invalid.  Discarding

 The data is of type string (xml).  Am I doing something wrong?  I know
 you have to reverse the bits when communicating from C++ to Java.
 Could this be the problem? I figured it would not because it said the
 length was invalid.  I just started looking at python sockets
 tonight... and I don't have a real deep base with socket connections
 as it is... any help would be greatly appreciated.

 Greg

What is the server protocol? What are you sending? Saying 'xml' is not
enough to understand the problem ...
byte order could be a problem only if the message include binary
representations
of 2-bytes or 4-bytes integer. With XML this should not be the case

Ciao

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


Re: Python 3 isinstance

2009-01-16 Thread Duncan Booth
Carl Banks pavlovevide...@gmail.com wrote:

 On Jan 15, 1:08 pm, Duncan Booth duncan.bo...@invalid.invalid wrote:
 Carl Banks pavlovevide...@gmail.com wrote:
  I don't see what the big deal is.  Right now isinstance accepts a
  typ 
 e
  or a tuple of types.  The code could be changed to allow a type, or
  any iterable the returns types (wherein every items of the sequence
  is required to be a type).  What's messy about that?

 No, it isn't restricted to a type or a tuple of types: right now
 isinstan 
 ce
 accepts X where X is a type or a tuple of X. The definition is
 recursive, and the data structure can be deeply nested, but (because
 tuples are immutable) it cannot be infinite.

 e.g. isinstance('x', (int, (float, str)),),),),))

 True
 
 Oh.  Not sure what the use case for THAT was, but that would make
 things messy.
 
Duck typing purism?

If you can use it to specify an exception you want to handle, then you 
can put it in a tuple with other exception specifications you can also 
handle. If you had to check whether it was a class or tuple to work out 
which sort of concatenation to use then you are breaking the first law 
of ducks.

I think exception specifications came first and isinstance/issubclass 
followed suit, except of course exception specification were more 
complex as they could be classes, strings, or tuples of exception 
specifications.

That still leaves the question whether anyone has ever actually taken 
advantage of this feature. You can do isinstance(x, (IntType, LongType, 
StringTypes)) but I didn't even know that StringTypes existed until a 
couple of moments ago, and I intend to forget about it again 
immediately. Grepping through the Python libraries on my system it looks 
like a lot of programmers don't even realise you can combine types into 
a tuple.


-- 
Duncan Booth http://kupuguy.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Alphametric fun with Python

2009-01-16 Thread Terry Reedy

bearophileh...@lycos.com wrote:

Terry Reedy:

It illustrates well the point you intended.


I don't know what my point was.


I quoted and was responding to Raymond.



A suggestion: with that solver, to find solution in a faster way you
have to write many equations.


I did... one for each column + plus the implied one that digits 
represented by the same letter get same value and that those represented 
by different letters gets different values.


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


Re: lazy evaluation is sometimes too lazy... help please.

2009-01-16 Thread Michael Hartl

James Stroud schrieb:

Ken Pu wrote:

Hi,  below is the code I thought should create two generates, it[0] =
0,1,2,3,4,5, and it[1] = 0,10,20,30,..., but they turn out to be the
same!!!

from itertools import *
itlist = [0,0]
for i in range(2):
  itlist[i] = (x+(i*10) for x in count())

print what's in the bags:
print list(islice(itlist[0], 5))
print list(islice(itlist[1], 5))

The output is:
[10, 11, 12, 13, 14]
[10, 11, 12, 13, 14]

I see what Python is doing -- lazy evaluation doesn't evaluate
(x+(i*10) for x in count()) until the end.


It doesn't evaluate it until you ask it to, which is the right 
behavior. However, when evaluated, it evaluates i also, which is the 
last value to which i was assigned, namely the integer 1. I'm going 
to get flamed pretty hard for this, but it doesn't seem to be the 
intuitive behavior to me either. However, in a purely functional 
language, you wouldn't be able to construct a list of generators in 
this way.


With python, you have to remember to adopt a purely functional design 
and then pray for best results. You can store generators in a list, 
but they need to be constructed properly. I can't perfectly 
transmogrify your code into functional code because I don't think 
making the particular anonymous generator you want is possible in 
python. However this is how I would make a close approximation:



from itertools import *

def make_gen(i):
  for x in count():
yield x + (i * 10)

itlist = [make_gen(i) for i in xrange(2)]

print what's in the bags:
print list(islice(itlist[0], 5))
print list(islice(itlist[1], 5))


James


You could just as well use the original expression in make_gen, too:

from itertools import *
def make_gen(i):
 return (x + (i*10) for x in count())

itlist = [make_gen(i) for i in xrange(2)]

print what's in the bags:
print list(islice(itlist[0], 5))
print list(islice(itlist[1], 5))

what's in the bags:
[0, 1, 2, 3, 4]
[10, 11, 12, 13, 14]
--
http://mail.python.org/mailman/listinfo/python-list


Re: English-like Python

2009-01-16 Thread alex23
On Jan 16, 5:39 pm, Erik Max Francis m...@alcyone.com wrote:
 Inform 7 has some
 interesting ideas, but I think the general problem with English-like
 programming language systems is that once you get into the nitty gritty
 details, you end up having to know exactly the right things to type,

This has always been my impression of Inform 7. I have a lot of
respect for what they've set out to achieve but English isn't exactly
known for its lack of ambiguity. This is great for literature but not
so helpful for programming.

 which ultimately get just as complicated as a more traditional
 programming language syntax.

And much more verbose, as well.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Does Python really follow its philosophy of Readability counts?

2009-01-16 Thread Terry Reedy

Paul Rubin wrote:

Terry Reedy tjre...@udel.edu writes:

Have you looked at Tim Sweeney's talk that I mentioned in another post?
http://www.st.cs.uni-saarland.de/edu/seminare/2005/advanced-fp/docs/s...

I did.  He gives a really nice use case for Python's ability to
dynamically modify classes imported from a library.  (Were not you
arguing against that?  Or was is someone else?)


He is talking about extending classes by something like inheritance,
not modifying them dynamically.  This is also in the context of an
extremely powerful static type system with existential and dependent
types, and totality proofs for just about everything.  That is about a
billion light years away from anything anyone has ever proposed for
Python.


If the library framework were written in Python, one would have a choice 
between creating a parallel class hierachy (through inheritance) that 
dupicates *every* class in the original hierachy and dynamically 
patching just those classes that need to be changed.  He only discussed 
the former option because that was the only one available.  If, for 
instance, one only needed to change the base class, patching just that 
would be much easier.  Hence my comment.


tjr

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


PyPlot

2009-01-16 Thread Shah Sultan Alam
Hi ,
 I need Pyplot module ,
 How to get and install ( plug in with my python 2.4 distribution ) !!!
 TIA.


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


Problem using python C API

2009-01-16 Thread shi dingan
Hi,
I'm trying to use the Python C API but I have
a problem when importing my new module.
Here is my (short) code:
#include Python.h
long sumList(PyObject *list) {
  int i, n;
  long total = 0;
  PyObject *item;

  n = PyList_Size(list);
  if (n  0) return NULL;

  for (i = 0; i  n; i++) {
  item = PyList_GetItem(list, i);
  if (!PyInt_Check(item)) continue;
  total += PyInt_AsLong(item);
  }
  return total;
}

PyObject *wrap_sumList(PyObject *self, PyObject *args) {
  PyObject *list;
  PyObject *total;
  if (!PyArg_ParseTuple(args, 0, list)) {
  return NULL;
  }
  total = Py_BuildValue(l, sumList(list));
  return total;
}

static PyMethodDef exampleMethods[] = {
  {sumList, wrap_sumList, METH_O},
  {NULL}
};

void initexample() {
  PyObject *m;
  m = Py_InitModule(example, exampleMethods);
}

My compilations lines:
gcc -Wall -fpic -c  -I/usr/include/python2.4 -I/usr/lib/python2.4/config
mytest.c
gcc -shared mytest.o -o examplemodule.so

When I try to import examplemodule, I obtain the following message:
 import examplemodule
Traceback (most recent call last):
  File stdin, line 1, in ?
ImportError: dynamic module does not define init function
(initexamplemodule)

Someone has an idea ?
Thx,
Marc.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Does Python really follow its philosophy of Readability counts?

2009-01-16 Thread Paul Rubin
Terry Reedy tjre...@udel.edu writes:
 If the library framework were written in Python, one would have a
 choice between creating a parallel class hierachy (through
 inheritance) that dupicates *every* class in the original hierachy and
 dynamically patching just those classes that need to be changed. 

I think I understand what you're saying, but it could be handled with
generics.
--
http://mail.python.org/mailman/listinfo/python-list


Re: lazy evaluation is sometimes too lazy... help please.

2009-01-16 Thread Boris Borcic

The minimal correction, I guess, is to write

   itlist[i] = (x+(i*10) for i in [i] for x in count())

instead of

   itlist[i] = (x+(i*10) for x in count())

although

   itlist[i] = (x+(i*10) for i,s in (i,count()) for x in s)

will better mimic generalizations in the sense that the minimal correction 
delays the evaluation of count(), which doesn't matter in the case of count(), 
but might make a difference if you replace it with some other expression.


The point is that the first iterator-producing expression in a generator 
expression - eg the X in (exp for vars in X...) - is evaluated immediately 
in the surrounding context, in contrast to the rest of the genexp.


Cheers, BB

Ken Pu wrote:

Hi,  below is the code I thought should create two generates, it[0] =
0,1,2,3,4,5, and it[1] = 0,10,20,30,..., but they turn out to be the
same!!!

from itertools import *
itlist = [0,0]
for i in range(2):
  itlist[i] = (x+(i*10) for x in count())

print what's in the bags:
print list(islice(itlist[0], 5))
print list(islice(itlist[1], 5))

The output is:
[10, 11, 12, 13, 14]
[10, 11, 12, 13, 14]

I see what Python is doing -- lazy evaluation doesn't evaluate
(x+(i*10) for x in count()) until the end.  But is this the right
behaviour?  How can I get the output I want:
[0, 1, 2, 3, 4]
[10, 11, 12, 13, 14]

Thanks.

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



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


Re: lazy evaluation is sometimes too lazy... help please.

2009-01-16 Thread Boris Borcic

   itlist[i] = (x+(i*10) for i,s in (i,count()) for x in s)


oops, that would be

 itlist[i] = (x+(i*10) for i,s in [(i,count())] for x in s)

or equivalent, kind of ugly anyway.

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


Re: lazy evaluation is sometimes too lazy... help please.

2009-01-16 Thread alex23
James Stroud jstr...@mbi.ucla.edu wrote:
 I'm going to get flamed
 pretty hard for this, but it doesn't seem to be the intuitive behavior
 to me either.

Given this is the second time this issue has come up today, I'd have
to agree with you.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Ordering of urlencoded tuples incorrect

2009-01-16 Thread benlucas99
On Jan 16, 1:44 am, John Machin sjmac...@lexicon.net wrote:
 On Jan 16, 11:59 am, benluca...@googlemail.com wrote:

  I'm having problems with the ordering of the tuples produced by
  urllib.urlencode.  Taking an example straight from the docs and so
  doing the following:

 What are the docs you are reading that include such an example? The
 docs distributed with Python 2.5.1 fromwww.python.orghave only this:
 
 urlencode( query[, doseq])

 Convert a mapping object or a sequence of two-element tuples to a
 ``url-encoded'' string, suitable to pass to urlopen() above as the
 optional data argument. This is useful to pass a dictionary of form
 fields to a POST request. The resulting string is a series of
 key=value pairs separated by  characters, where both key and value
 are quoted using quote_plus() above. If the optional parameter doseq
 is present and evaluates to true, individual key=value pairs are
 generated for each element of the sequence. When a sequence of two-
 element tuples is used as the query argument, the first element of
 each tuple is a key and the second is a value. The order of parameters
 in the encoded string will match the order of parameter tuples in the
 sequence. The cgi module provides the functions parse_qs() and
 parse_qsl() which are used to parse query strings into Python data
 structures.
 



  import urllib
  ...
  params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0})
  print params

  The documentation for urlencode( query[, doseq]) says: The order of
  parameters in the encoded string will match the order of parameter
  tuples in the sequence but I'm getting:

 query can be either a mapping object (e.g. a dictionary, as you have
 used) or a sequence of 2-tuples. No such guarantee as you quote above
 can be made for a mapping; mappings are just not orderable.
 If you want order, give it a sequence, like this:

 |  import urllib
 |  urllib.urlencode((('spam', 1), ('eggs', 2), ('bacon', 0)))
 | 'spam=1eggs=2bacon=0'

 HTH,
 John

Thanks guys, the explanations really helped. I knew I was missing
something fundamental.

The docs I'm referring is section 18.7.3 Examples in the Python
Library Reference, 18th April, 2007, Release 2.5.1  But looking at it
now I guess the server side procsssing that post request may not care
about ordering (unlike the web API I'm trying to call).

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


Re: reverse dict lookup Relation class

2009-01-16 Thread Steven D'Aprano
On Wed, 14 Jan 2009 16:30:36 -0800, Aaron Brady wrote:

 Hi, this is a continuation of something that comes up now and again
 about reverse lookups on dictionaries, as well as a follow-up to my
 pursuit of a Relation class from earlier.

[...]

 What's the best way to construct this class?  Or, do you have an
 argument that it could not be simpler than using a relational db?
 Brainstorming, not flamestorming.

Here's a lightweight solution that uses lazy calculation of the reverse 
dict. It makes a number of assumptions:

- both keys and values will be hashable and unique;
- the dict won't be so large that calculating the reverse dictionary will 
be time consuming;
- modifications to instance.reverse are undefined.


Usage:


 d = ReverseDict(x=2, y=3, z=4)
 d['x']
2
 d.reverse[2]
'x'
 d['a'] = 0
 d.reverse[0]
'a'





def make_dirty(func):
from functools import wraps
@wraps(func)
def f(self, *args, **kwargs):
self._dirty = True
return func(self, *args, **kwargs)
return f


# only tested a little bit
class ReverseDict(dict):
def __init__(self, *args, **kwargs):
super(ReverseDict, self).__init__(*args, **kwargs)
self._dirty = True
@make_dirty
def clear():
super(ReverseDict, self).clear()
@make_dirty
def __setitem__(self, key, value):
super(ReverseDict, self).__setitem__(key, value)
@make_dirty
def __delitem__(self, key):
super(ReverseDict, self).__delitem__()
@make_dirty
def pop(self, key, *arg):
return super(ReverseDict, self).pop(key, *arg)
@make_dirty
def popitem(self):
return super(ReverseDict, self).popitem()
@make_dirty
def setdefault(self, key, value=None):
return super(ReverseDict, self).setdefault(key, value)
@make_dirty
def update(self, other):
return super(ReverseDict, self).update(other)
@property
def reverse(self):
if self._dirty:
# Modify this to support repeated and non-hashable values.
self._reverse = dict((value, key) for 
(key, value) in self.iteritems())
self._dirty = False
return self._reverse




An even more lightweight solution is to give up O(1) for the reverse 
lookup:


# untested
class ReversableDict(dict):
def lookupvalue(self, value):
for k,v in self.iteritems():
if v == value: return k
raise ValueError('value not found')
def lookupallvalues(self, value):
results = []
for k,v in self.iteritems():
if v == value: results.append(k)
return results




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


Re: Python 3 isinstance

2009-01-16 Thread Steven D'Aprano
On Fri, 16 Jan 2009 09:58:53 +, Duncan Booth wrote:

 That still leaves the question whether anyone has ever actually taken
 advantage of this feature. You can do isinstance(x, (IntType, LongType,
 StringTypes)) but I didn't even know that StringTypes existed until a
 couple of moments ago, and I intend to forget about it again
 immediately. Grepping through the Python libraries on my system it looks
 like a lot of programmers don't even realise you can combine types into
 a tuple.


I do it a lot, except I don't bother with IntType, LongType etc (I assume 
you imported them from the types module). I just do:

isinstance(x, (int, float))  # or whatever



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


multiprocessing question/error

2009-01-16 Thread Eduardo Lenz
Hi,

I was using the former processing package with python 2.5 with no problems. 
After switching to python 2.6.1 I am having some problems with the same code.
The problem seems to be related to the fact that I am using Pool.map
with a bounded method, since it is inside a class. To clarify a little bit, 
let me show some parts of the code 

class Pygen3(self)



def calcula(self,indiv):




   def evaluate(self):
 
  
indiv = range(mult*self.popsize,(mult+1)*self.popsize)
   pool = Pool(processes=nproc)
   results = pool.map(self.calcula,indiv)
   ...
   ...

the error is the following

Exception in thread Thread-1:
Traceback (most recent call last):
  File /usr/lib/python2.6/threading.py, line 522, in __bootstrap_inner
self.run()
  File /usr/lib/python2.6/threading.py, line 477, in run
self.__target(*self.__args, **self.__kwargs)
  File /usr/lib/python2.6/multiprocessing/pool.py, line 225, in 
_handle_tasks
put(task)
PicklingError: Can't pickle type 'instancemethod': attribute lookup 
__builtin__.instancemethod failed


Thanks for your help. 

-- 

 Eduardo Lenz Cardoso
 Dr.  Eng.
 Associate Professor
 
 State University of Santa Catarina
 Department of Mechanical Engineering
 89223-100 - Joinville-SC - Brasil

 Tel: +55 47 4009-7971 - Fax: +55 47 4009-7940
 E-mail: l...@joinville.udesc.br  
 -

-- 
Esta mensagem foi verificada pelo sistema de antiv�rus e
 acredita-se estar livre de perigo.

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


Re: lazy evaluation is sometimes too lazy... help please.

2009-01-16 Thread Steven D'Aprano
On Fri, 16 Jan 2009 02:51:43 -0500, Ken Pu wrote:

 Hi,  below is the code I thought should create two generates, it[0] =
 0,1,2,3,4,5, and it[1] = 0,10,20,30,..., but they turn out to be the
 same!!!
[...]
 I see what Python is doing -- lazy evaluation doesn't evaluate (x+(i*10)
 for x in count()) until the end.  But is this the right behaviour?  How
 can I get the output I want: [0, 1, 2, 3, 4]
 [10, 11, 12, 13, 14]

The solution I would use is:

itlist = [0,0]
for i in range(2):
itlist[i] = ( lambda i: (x+(i*10) for x in count()) )(i)


Or pull the lambda out of the loop:


itlist = [0,0]
def gen(i):
return (x+(i*10) for x in count())

for i in range(2):
itlist[i] = gen(i)



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


Re: mimetypes oddity

2009-01-16 Thread Sion Arrowsmith
In article mailman.7301.1232043685.3487.python-l...@python.org,
 s...@pobox.com wrote:
[mimetype weirdness reported]
Sion Is this a bug?
Might be.  Can you file a bug report in the Python issue tracker with a
small script that demonstrates the behavior?

http://bugs.python.org/issue4963

(It's tagged as being 2.4 and 2.5 because those are the versions I
have to hand to confirm it on, but I'd be rather surprised if it's
not still like this in 2.6.)

-- 
\S -- si...@chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
   Frankly I have no feelings towards penguins one way or the other
-- 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: multiprocessing vs. distributed processing

2009-01-16 Thread Jesse Noller
On Fri, Jan 16, 2009 at 12:52 AM, James Mills
prolo...@shortcircuit.net.au wrote:
 I've noticed over the past few weeks lots of questions
 asked about multi-processing (including myself).

 For those of you new to multi-processing, perhaps this
 thread may help you. Some things I want to start off
 with to point out are:

 multiprocessing will not always help you get things done faster.

 be aware of I/O bound applications vs. CPU bound

 multiple CPUs (cores) can compute multiple concurrent expressions -
 not read 2 files concurrently

 in some cases, you may be after distributed processing rather than
 multi or parallel processing

 cheers
 James

James is quite correct, and maybe I need to amend the multiprocessing
documentation to reflect this fact.

While distributed programming and parallel programming may cross paths
in a lot of problems/applications, you have to know when to use one
versus the other. Multiprocessing only provides some basic primitives
to help you get started with distributed programming, it is not it's
primary focus, nor is it a complete solution for distributed
applications.

That being said, there is no reason why you could not use it in
conjunction with something like Kamaelia, pyro, $ipc mechanism/etc.

Ultimately, it's a tool in your toolbox, and you have to judge and
experiment to see which tool is best applied to your problem. In my
own work/code, I use both processes *and* threads - one works better
than the other depending on the problem.

For example, a web testing tool. This is something that needs to
generate hundreds of thousands of HTTP requests - not a problem you
want to use multiprocessing for given that A It's primarily I/O bound
and B You can generate that many threads on a single machine.
However, if I wanted to say, generate hundreds of threads across
multiple machines, I would (and do) use multiprocessing + paramiko to
construct a grid of machines and coordinate work.

That all being said: multiprocessing isn't set in stone - there's room
for improvement in the docs, tests and code, and all patches are
welcome.

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


Integrating awk in Python

2009-01-16 Thread Alfons Nonell-Canals
Hello,
I'm developing a software package using python. I've programmed all
necessary tools but I have to use other stuff from other people. Most of
these external scripts are developed using awk.

At the beggining I thought to translate them and program them in
python but I prefer to avoid it because it means a lot of work and I
should do it after each new version of this external stuff. I would like
to integrate them into my python code.

I know I can call them using the system environment but it is slower
than if I call them inside the package. I know it is possible with C, do
you have experience on integrate awk into python calling these awk
scripts from python?

Thanks in advance!

Regards,
Alfons.


-- 

Alfons Nonell-Canals, PhD
Chemogenomics Lab
Research Group on Biomedical Informatics (GRIB) - IMIM/UPF
Barcelona Biomedical Research Park (PRBB)
C/ Doctor Aiguader, 88 - 08003 Barcelona 
alfons.non...@upf.edu - http://cgl.imim.es
Tel. +34933160528

http://alfons.elmeuportal.cat
http://www.selenocisteina.info
--
http://mail.python.org/mailman/listinfo/python-list


Re: process/thread instances and attributes

2009-01-16 Thread Jesse Noller
On Thu, Jan 15, 2009 at 10:37 PM, James Mills
prolo...@shortcircuit.net.au wrote:
 After some work ... I've taken Laszlo's suggestion of using Value
 (shared memory) objects
 to share state between the -pseudo- Process (manager) object and it's
 underlying multiprocessing.Process
 instance (and subsequent process):

 Here is the code:

 
 #!/usr/bin/env python

 import os
 from time import sleep

 from threading import activeCount as threads
 from threading import Thread as _Thread

 from multiprocessing import Value
 from multiprocessing import Process as _Process
 from multiprocessing import active_children as processes

 class Process(object):

def __init__(self, *args, **kwargs):
super(Process, self).__init__(*args, **kwargs)

self.running = Value(b, False)
self.thread = _Thread(target=self.run)
self.process = _Process(target=self._run, args=(self.running,))

def _run(self, running):
self.thread.start()

try:
while running.value:
try:
sleep(1)
print !
except SystemExit:
running.acquire()
running.value = False
running.release()
break
except KeyboardInterrupt:
running.acquire()
running.value = False
running.release()
break
finally:
running.acquire()
running.value = False
running.release()
self.thread.join()

def start(self):
self.running.acquire()
self.running.value = True
self.running.release()
self.process.start()

def run(self):
pass

def stop(self):
print %s: Stopping ... % self
self.running.acquire()
self.running.value = False
self.running.release()

def isAlive(self):
return self.running.value

 class A(Process):

def run(self):
while self.isAlive():
sleep(5)
self.stop()

 a = A()
 a.start()

 N = 0

 while a.isAlive():
sleep(1)
print .
print threads:   %d % threads()
print processes: %d % len(processes())

 print DONE
 

 Here is the result of running this:

 
 $ python test3.py
 !
 .
 threads:   1
 processes: 1
 .
 threads:   1
 processes: 1
 !
 !
 .
 threads:   1
 processes: 1
 .
 threads:   1
 processes: 1
 !
 .
 threads:   1
 processes: 1
 !
 __main__.A object at 0x80de42c: Stopping ...
 !
 .
 threads:   1
 processes: 0
 DONE
 

 This appears to work as I intended.

 Thoughts / Comments ?

 cheers
 James


Personally, rather then using a value to indicate whether to run or
not, I would tend to use an event to coordinate start/stop state.

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


Re: Integrating awk in Python

2009-01-16 Thread Willi Richert
Hi,

take a look at the 5th link at http://tinyurl.com/7s8kfq
It's called pyawk.

Regards,
wr

Am Freitag, 16. Januar 2009 13:02:59 schrieb Alfons Nonell-Canals:
 Hello,
 I'm developing a software package using python. I've programmed all
 necessary tools but I have to use other stuff from other people. Most of
 these external scripts are developed using awk.

 At the beggining I thought to translate them and program them in
 python but I prefer to avoid it because it means a lot of work and I
 should do it after each new version of this external stuff. I would like
 to integrate them into my python code.

 I know I can call them using the system environment but it is slower
 than if I call them inside the package. I know it is possible with C, do
 you have experience on integrate awk into python calling these awk
 scripts from python?

 Thanks in advance!

 Regards,
 Alfons.



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


Re: List comprehension - NameError: name '_[1]' is not defined ?

2009-01-16 Thread ajaksu
On Jan 16, 5:09 am, mario ruggier mario.rugg...@gmail.com wrote:
 Laboriously doing all these
 checks on each expr eval will be very performance heavy, so I hope to
 be able to limit access to all these more efficiently. Suggestions?

None regarding the general issue, a try:except to handle this one:

'(x for x in ()).throw(bork)'

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


Re: Does Python really follow its philosophy of Readability counts?

2009-01-16 Thread Steve Holden
Russ P. wrote:
[...]
 I spent *way* too much time on that post. I really need to quit
 spending my time refuting the baloney that passes for wisdom here.

He who cannot ignore baloney is doomed to refute it.

regards
 Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


vb2py status?

2009-01-16 Thread axtens
G'day everyone

So is vb2py dead? If not, any idea when it'll support python 3?

Kind regards,
Bruce.
--
http://mail.python.org/mailman/listinfo/python-list


Experiment: Church lists in Python

2009-01-16 Thread Ertugrul Söylemez
Hello there Pythoners,

It was almost a week ago, when I got bored and thought, Python is quite
a boring language, so I'd need to do some evil functional programming
again.  I thought, I'd share the result. ;)

This time, I added a Church style representation for lists [1] to
Python.  The problem they solve:  What do you do, if you've got only
scalar values, functions and function application, but you need lists?
Here is the solution:  Represent lists as higher order functions:

  def empty():
return lambda f, z: z

  def cons(x, xs):
return lambda f, z: f(x, xs(f, z))

  def fold(f, z, xs):
return xs(f, z)

The empty() function returns an empty list and the cons() function
returns the list in its second argument with the element in its first
argument prepended, so cons(x, xs) is equivalent to the list [x] + xs.
The 'fold' function is actually superfluous, but it makes much clearer
what you're doing, when using this type of lists.  It's the
right-associative version of the 'reduce' function.  All other list
operations can be defined in terms of these three functions.  I've done
that for you [2] (mostly).

If Python implements closures efficiently, this list representation is
actually very fast for list folding, i.e. consuming an entire list to
construct a value (which may be anything, including lists or functions).
However, it's slow for extracting individual elements, because this
operation must be a fold, too, as folding is the only way to access the
elements of a list.

An interesting property of this representation is that it gets along
without any impure functions, i.e. all functions are completely free of
side effects.  Unless you use an impure fold function, everything is
perfectly purely functional.

Have fun. =)


Greets,
Ertugrul.


[1] http://en.wikipedia.org/wiki/Church_encoding#Higher-order-function,
a representation of a list as a higher order function.

[2] http://ertes.de/python/fun/chlists.py, a little library of Python
functions implementing Church style lists using higher order
functions.  The way the 'range' function is defined, was an
experiment: how to emulate partial application in Python.


Greets,
Ertugrul.


-- 
nightmare = unsafePerformIO (getWrongWife = sex)
http://blog.ertes.de/

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


Re: Soap Client

2009-01-16 Thread Doug

I believe that I have answered my own question.  If anyone else is
interested in what I did ... using iPython's code completion (. then
hit tab tab) I noticed that msg had a _request attribute.  I set that
attribute to GetEventListMonth1/Month/GetEventList and that
sent the message that I needed!

Hope everyone has a great day!

Doug

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


Re: English-like Python

2009-01-16 Thread John Roth
On Jan 16, 3:15 am, alex23 wuwe...@gmail.com wrote:
 On Jan 16, 5:39 pm, Erik Max Francis m...@alcyone.com wrote:

  Inform 7 has some
  interesting ideas, but I think the general problem with English-like
  programming language systems is that once you get into the nitty gritty
  details, you end up having to know exactly the right things to type,

 This has always been my impression of Inform 7. I have a lot of
 respect for what they've set out to achieve but English isn't exactly
 known for its lack of ambiguity. This is great for literature but not
 so helpful for programming.

  which ultimately get just as complicated as a more traditional
  programming language syntax.

 And much more verbose, as well.

Since I've used Inform 7 I can say that the syntactic problem isn't
that great: once you get far enough into a project to matter the
specialized constraints just sink in. It's more work to learn, but no
stranger than Python's indentation scheme.

The bigger problem for the comparison is that Inform 7 is a Domain
Specific Language (DSL), not a general purpose language. Not only
that, but the domain is pretty much everyday experience (with a large
dollop of fantasy, of course). All the feedback is that the results
are quite readable to non-programmers. This is why well over half of
the mailing list posts on the authoring mailing list are about Inform
7.

I really don't think that using natural language for a general purpose
programming language is a good idea, for reasons that several other
people have already said. I think it's a great idea for DSLs, at least
in some cases.

The other really major problem is that I don't think anyone really
knows how to process natural language. The direction that natural
language processing has taken in the last 50 years has come up lacking
big-time. It does a good job in a single domain, but try to build
something that crosses domains and nothing works. There isn't a good
alternative in sight

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


Re: Readline and Python 2.6.1 on a Mac

2009-01-16 Thread James Brady

 s/bind ^I rl_complete/tab: complete/

 http://tiswww.case.edu/php/chet/readline/readline.html

 --
  Ned Deily,
  n...@acm.org

Perfect, thanks Ned!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3 isinstance

2009-01-16 Thread Duncan Booth
Steven D'Aprano st...@remove-this-cybersource.com.au wrote:

 On Fri, 16 Jan 2009 09:58:53 +, Duncan Booth wrote:
 
 That still leaves the question whether anyone has ever actually taken
 advantage of this feature. You can do isinstance(x, (IntType,
 LongType, StringTypes)) but I didn't even know that StringTypes
 existed until a couple of moments ago, and I intend to forget about
 it again immediately. Grepping through the Python libraries on my
 system it looks like a lot of programmers don't even realise you can
 combine types into a tuple.
 
 
 I do it a lot, except I don't bother with IntType, LongType etc (I
 assume you imported them from the types module). I just do:
 
 isinstance(x, (int, float))  # or whatever
 
Yes, I do that too, and naturally I don't use the types module. The 
question though was whether anyone, anywhere, has ever taken advantage of 
the fact that isinstance accepts *nested* tuples.

My point was intended to be that perhaps if someone imported from the types 
module they might just use StringTypes in a tuple along with the single 
type names, but it seems pretty unlikely to be common usage.


-- 
Duncan Booth http://kupuguy.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Does Python really follow its philosophy of Readability counts?

2009-01-16 Thread Luis Zarrabeitia

Quoting Russ P. russ.paie...@gmail.com:

 On Jan 15, 12:21 pm, Bruno Desthuilliers
 bdesth.quelquech...@free.quelquepart.fr wrote:
 
  Once again, the important point is that there's a *clear* distinction
  between interface and implementation, and that you *shouldn't* mess with
  implementation.
 
 If you *shouldn't* mess with the implementation, then what is wrong
 with enforcing that shouldn't in the language itself?

Because, as a library user, it should be my power to chose when and how I
_should_ mess with the implementation, not the compiler, and definitely not you.

 So let's take the airplane example. Boeing and its contractors
 probably has hundreds of programmers working on millions of lines of
 code. If they believed you, they would abandon enforced data hiding,
 and programmers would have much more discretion to screw around with
 code that they don't work on directly. An FMS programmer could perhaps
 decide to change the parameters of the engine controls, for example.

I really hope that, at Boeing, they do a lot of unit tests and code reviews
before the code is commited. Messing with the internals wouldn't be the only bad
thing that could happen, you know... And I'd say that x._private where x is
not 'self', would be very easy to catch on those code reviews.

And, as someone else pointed out, even with 'strong' enforcement of data-hiding,
you can usually access the privates anyway - it's just a bit harder to do, and a
lot harder to discover.

You pointed out previously that Python wasn't up to the task of running
untrusted code on my own application, and I agreed. _That_ is what you seem
need, and enforced data hiding does very little towards it. 

-- 
Luis Zarrabeitia
Facultad de Matemática y Computación, UH
http://profesores.matcom.uh.cu/~kyrie
--
http://mail.python.org/mailman/listinfo/python-list


Re: Does Python really follow its philosophy of Readability counts?

2009-01-16 Thread mk

Paul Rubin wrote:


1) Parallelism.  Commodity desktop computers now have 8 effective cpu
cores or maybe even 16 soon (Mac Pro, Intel Core i7) but Python still
has the evil GIL that forces all threads to run on one core.  Java,
Erlang, and Haskell (GHC) all beat Python in this area.  By the time
Python 4 comes out, we will probably all be using PC's with 32 or more
cores, so the current limitations will be intolerable.  Even today,
since no one doing anything serious uses single core machines any
more, the GIL is a huge pain in the neck which the multiprocessing
module helps only slightly.  (While we are at it, lightweight threads
like Erlang's or GHC's would be very useful.)


+100 for this one


2) Native-code compilation.  Per the Alioth shootouts, Python is much
slower (even on single cores) than Java, Haskell, ML, or even Scheme.
PyPy is addressing this but it will be a while before it replaces
CPython.  


The lack of this already causes some pains at my company.

I was flabbergasted to read that optional static typing was dropped by 
Guido due to lack of interest in community IIRC.


Why!! Among other reasons, this could have provided for very easy 
performance optimizations of the small portions of the code! This could 
have been a huge gain acquired for little effort!


Regards,
mk



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


Re: English-like Python

2009-01-16 Thread MRAB

[Hit Reply instead of Reply All. Sorry alex23.]

alex23 wrote:

On Jan 16, 5:39 pm, Erik Max Francis m...@alcyone.com wrote:
Inform 7 has some interesting ideas, but I think the general 
problem with English-like programming language systems is that once
you get into the nitty gritty details, you end up having to know 
exactly the right things to type,


This has always been my impression of Inform 7. I have a lot of 
respect for what they've set out to achieve but English isn't exactly
known for its lack of ambiguity. This is great for literature but 
not so helpful for programming.


which ultimately get just as complicated as a more traditional 
programming language syntax.


And much more verbose, as well.


I once had to do something in AppleScript. The problem I found was that
it tried so much to resemble English that it wasn't always clear what
was valid!

Programming languages need to look artificial to remind you that the
computers aren't intelligent. Python, for example, is clearly
artificial but with a clear syntax and short (but not too short)
reserved words.

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


Re: Client Socket Connection to Java server

2009-01-16 Thread MRAB

TechieInsights wrote:

I am having problems with a socket connection to a Java server.  In
java I just open the socket, pass the length and then pass the bits
across the socket.

I created a socket object:

import socket

class MySocket:
def __init__(self, host='localhost', port = 28192, buffsize = 1024):
socket.setdefaulttimeout(10)

self.host = host
self.port = port
self.buffsize = buffsize
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.socket.connect((host, port))

def send(self, data):
self.socket.send(data)


I recommend sendall() instead of send():

self.socket.sendall(data)

send() doesn't guarantee to send all the data, so multiple sends might 
be needed to send it all. sendall() does that for you.




def receive(self):
return self.socket.recv(self.buffsize)

def sendAndReceive(self, data):
self.send(data)
return self.receive()

def close(self):
self.socket.close()

But the java server gives the error:
WARNING: Incoming Message length invalid.  Discarding

The data is of type string (xml).  Am I doing something wrong?  I know
you have to reverse the bits when communicating from C++ to Java.
Could this be the problem? I figured it would not because it said the
length was invalid.  I just started looking at python sockets
tonight... and I don't have a real deep base with socket connections
as it is... any help would be greatly appreciated.

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



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


Re: Start two threads in same time

2009-01-16 Thread koranthala
On Jan 16, 7:36 pm, vedrandeko...@gmail.com wrote:
 Hello,

 Does anybody know how can I start two threads in same time?

 Regards,
 John

Use threading module.
Creating a new thread is as easy as --
---
import threading

class ThreadedClass(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)

def run(self):
 **Do whatever you want do in the new thread here**

threaded_obj = ThreadedClass()
threaded_obj.setDaemon(True)  # If you want a daemon thread
threaded_obj.start() # Start the new thread

Do whatever you want to do in main thread here%%%

threaded_obj.join() #Close the new thread by joining it with the main
thread



The following document might be of help:
http://heather.cs.ucdavis.edu/~matloff/Python/PyThreads.pdf
--
http://mail.python.org/mailman/listinfo/python-list


Re: Convention vs. fascism [OT]

2009-01-16 Thread Hendrik van Rooyen

Steven D'Aprano st...@remove-thisurce.com.au wrote:

And... skull socks? Cool. Where can I get some?

Don't you remember? - Google the group - there was some
dust raised about them some time ago.  I think he got them 
from KDW  - Kaufhaus Der Welt  aka  Klau Dir Was

:-)

- Hendrik


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


Re: Start two threads in same time

2009-01-16 Thread koranthala
On Jan 16, 7:46 pm, koranthala koranth...@gmail.com wrote:
 On Jan 16, 7:36 pm, vedrandeko...@gmail.com wrote:

  Hello,

  Does anybody know how can I start two threads in same time?

  Regards,
  John

 Use threading module.
 Creating a new thread is as easy as --
 ---
 import threading

 class ThreadedClass(threading.Thread):
     def __init__(self):
         threading.Thread.__init__(self)

     def run(self):
          **Do whatever you want do in the new thread here**

 threaded_obj = ThreadedClass()
 threaded_obj.setDaemon(True)  # If you want a daemon thread
 threaded_obj.start() # Start the new thread

 Do whatever you want to do in main thread here%%%

 threaded_obj.join() #Close the new thread by joining it with the main
 thread

 

 The following document might be of 
 help:http://heather.cs.ucdavis.edu/~matloff/Python/PyThreads.pdf

If you want to create n threads, just create and call the threaded_obj
n times.
So, the code will look like:

threaded_obj = []

for i in range(n):
   threaded_obj[i] = ThreadedClass()
   threaded_obj[i].setDaemon(True)  # If you want a daemon thread
   threaded_obj[i].start() # Start the new thread

Do whatever you want to do in main thread here%%%

#To close the threads
for o in threaded_obj:
   o.join()

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


Re: Problem using python C API

2009-01-16 Thread Philip Semanchuk


On Jan 16, 2009, at 5:31 AM, shi dingan wrote:


void initexample() {
 PyObject *m;
 m = Py_InitModule(example, exampleMethods);
}

When I try to import examplemodule, I obtain the following message:

import examplemodule

Traceback (most recent call last):
 File stdin, line 1, in ?
ImportError: dynamic module does not define init function
(initexamplemodule)


Hi Marc,
The tutorial says, The initialization function must be named  
initname(), where name is the name of the module. The error message  
you got is very accurate: module does not define init function  
(initexamplemodule). Since your module is called examplemodule,  
Python is looking for a function called initexamplemodule.


Change your build step to build a module called example and not  
examplemodule and I think you'll be OK.


bye
Philip

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


Re: English-like Python

2009-01-16 Thread sturlamolden
On Jan 16, 8:39 am, Erik Max Francis m...@alcyone.com wrote:

 I was thinking of this as well when I saw his post.  Inform 7 has some
 interesting ideas, but I think the general problem with English-like
 programming language systems is that once you get into the nitty gritty
 details, you end up having to know exactly the right things to type,
 which ultimately get just as complicated as a more traditional
 programming language syntax.  In the big picture I don't think it helps
 much.  After all, there's a reason that most modern programming
 languages don't look like COBOL or AppleScript.

COBOL looks like English to facilitate reading programs, not writing
them. COBOL is for use in places where programs must be read and
verified by possibly computer-illiterate personnel. E.g. in bank and
finance where (at least in some countries) everything must be
supervised and approved by professional accountants. COBOL is still
the dominating language in that domain.

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


bubblefishymon

2009-01-16 Thread Andy Goldschmidt
Hi Guys

I am trying to get bubblefishymon to work as a gdesklet. (app is written
in python)

The app seems to work, but it does display any water. I'm assuming its
because it cant poll the network card etc.

If I try run it on the command line it shows this error :

$ python __init__.py

Traceback (most recent call last):
  File __init__.py, line 3, in module
from sensor.Sensor import Sensor
ImportError: No module named sensor.Sensor

In the dekslets log it also shows this :
  Deprecation: Sensors are deprecated since v0.30.  
  Please consider using controls and inline scripts.

Does that mean Sensors is no longer used / supported ?
If so , what do I use in place of it ?

Please note, I don't know how to code in Python (yet!) so any help would
be much appreciated.

Regards
Andy


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


Re: Problem using python C API

2009-01-16 Thread marcglec
Right, thx for your reply, I completely overlooked examplemodule.so
in the building step. Maybe I should sleep more these days :)
Btw, I've now an other problem with PyArg_ParseTuple but I guess
it is better to post in the capi-sig mailing list.
Thx again,
Marc.



 On Jan 16, 2009, at 5:31 AM, shi dingan wrote:

  void initexample() {
   PyObject *m;
   m = Py_InitModule(example, exampleMethods);
  }
 
  When I try to import examplemodule, I obtain the following message:
  import examplemodule
  Traceback (most recent call last):
   File stdin, line 1, in ?
  ImportError: dynamic module does not define init function
  (initexamplemodule)

 Hi Marc,
 The tutorial says, The initialization function must be named
 initname(), where name is the name of the module. The error message
 you got is very accurate: module does not define init function
 (initexamplemodule). Since your module is called examplemodule,
 Python is looking for a function called initexamplemodule.

 Change your build step to build a module called example and not
 examplemodule and I think you'll be OK.

 bye
 Philip

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



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


Re: Does Python really follow its philosophy of Readability counts?

2009-01-16 Thread mk

Paul Rubin wrote:

But, if something is done by convention, then departing from the
convention is by definition unconventional.  If you do something
unconventional in a program, it could be on purpose for a reason, or
it could be by accident indicating a bug.


I for one would love to see at least compiler warning (optionally, 
error) for situation where attributes are added to self outside of 
__init__. I consider it generally evil and hate to see code like that.



Regards,
mk

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


confused about publishing more than one class in twisted server.

2009-01-16 Thread Krishnakant
hello,
I am writing a twisted based rpc service where I am implementing a
complete application as a service.
I have many modules which make a package.  Now when we publish a service
in twisted, we have to create one instance of a certain class and then
publish it with the help of reactor.
but in my application, there are more than one class in different .py
files.  Now I want to know how do i create a package where all the
classes in different modules get published so that the entire package
can be used as the rpc server application and the client can be used to
query any module.

for example I have classes to get and set vendor, product, bills etc.
now all this has to be   accessed through the xml rpc service.
Can some one tell me how to manage the entire twisted package as a
service.
happy hacking.
Krishnakant.


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


Start multiple listening servers in one file

2009-01-16 Thread Thomas W
I`m working on a django-project where I`m using the awsome pyftpdlib
for ftpserver-functionality. I also have a simple worker deamon
running in the background, but not listening to any port. How can I
start all of these processes on one file? Tried using subprocess and
popen but that resulted in an eternal loop starting the servers over
and over until all resources were used, then crash.

Any hint on how to do this would be highly appreciated.
--
http://mail.python.org/mailman/listinfo/python-list


Start two threads in same time

2009-01-16 Thread vedrandekovic
Hello,

Does anybody know how can I start two threads in same time?

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


Skull Socks (was Re: Convention vs. fascism)

2009-01-16 Thread J. Cliff Dyer


On Fri, 2009-01-16 at 08:57 +, Steven D'Aprano wrote:
 On Fri, 16 Jan 2009 10:03:28 +0200, Hendrik van Rooyen wrote:
 
  Oh come on you lot - you are carrying on as if Diez were wearing his
  skull socks again - do me a favour and give him a break!

 And... skull socks? Cool. Where can I get some?
 
 

http://www.letmegooglethatforyou.com/search?q=skull+socks

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


Re: Skull Socks (was Re: Convention vs. fascism)

2009-01-16 Thread Steven D'Aprano
On Fri, 16 Jan 2009 11:01:18 -0500, J. Cliff Dyer wrote:

 On Fri, 2009-01-16 at 08:57 +, Steven D'Aprano wrote:
 On Fri, 16 Jan 2009 10:03:28 +0200, Hendrik van Rooyen wrote:
 
  Oh come on you lot - you are carrying on as if Diez were wearing his
  skull socks again - do me a favour and give him a break!
 
 And... skull socks? Cool. Where can I get some?
 
 
 
 http://www.letmegooglethatforyou.com/search?q=skull+socks

Not Found
The requested URL /search was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use 
an ErrorDocument to handle the request.



You know, it was just a throw-away comment to lighten the mood. I don't 
really need to see 18,000+ links to places that sell socks with skulls 
printed on them.

On the other hand, if they were socks made from actual skulls, that would 
be something...



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


Re: Client Socket Connection to Java server

2009-01-16 Thread Venkatraman.S.
Hint: Java sends a '\n' character at the end.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Does Python really follow its philosophy of Readability counts?

2009-01-16 Thread Paul Rubin
mk mrk...@gmail.com writes:
 I was flabbergasted to read that optional static typing was dropped by
 Guido due to lack of interest in community IIRC.

I don't remember that happening.  PEP 3107 still lists type checking
as a use case for Python 3.0 function annotations.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Integrating awk in Python

2009-01-16 Thread Terry Reedy

Willi Richert wrote:

Hi,

take a look at the 5th link at http://tinyurl.com/7s8kfq
It's called pyawk.


Stupid link wanting to set yet another useless cookie.  Answer will not 
always be 5th.

Just say 'Google pyawk' or better give link
http://pyawk.sourceforge.net/


Am Freitag, 16. Januar 2009 13:02:59 schrieb Alfons Nonell-Canals:

Hello,
I'm developing a software package using python. I've programmed all
necessary tools but I have to use other stuff from other people. Most of
these external scripts are developed using awk.

At the beggining I thought to translate them and program them in
python but I prefer to avoid it because it means a lot of work and I
should do it after each new version of this external stuff. I would like
to integrate them into my python code.

I know I can call them using the system environment but it is slower
than if I call them inside the package. I know it is possible with C, do
you have experience on integrate awk into python calling these awk
scripts from python?


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


Re: English-like Python

2009-01-16 Thread Dotan Cohen
2009/1/16 The Music Guy music...@alphaios.net:
 Just out of curiousity, have there been any attempts to make a version
 of Python that looks like actual English text? I mean, so much of Python
 is already based on the English language that it seems like the next
 natural step would be to make a programming language which is actually a
 spoken one.


This one is close:
http://en.wikipedia.org/wiki/Brainfuck

-- 
Dotan Cohen

http://what-is-what.com
http://gibberish.co.il

א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ-ל-ם-מ-ן-נ-ס-ע-ף-פ-ץ-צ-ק-ר-ש-ת
ا-ب-ت-ث-ج-ح-خ-د-ذ-ر-ز-س-ش-ص-ض-ط-ظ-ع-غ-ف-ق-ك-ل-م-ن-ه‍-و-ي
А-Б-В-Г-Д-Е-Ё-Ж-З-И-Й-К-Л-М-Н-О-П-Р-С-Т-У-Ф-Х-Ц-Ч-Ш-Щ-Ъ-Ы-Ь-Э-Ю-Я
а-б-в-г-д-е-ё-ж-з-и-й-к-л-м-н-о-п-р-с-т-у-ф-х-ц-ч-ш-щ-ъ-ы-ь-э-ю-я
ä-ö-ü-ß-Ä-Ö-Ü
--
http://mail.python.org/mailman/listinfo/python-list


Re: mimetypes oddity

2009-01-16 Thread Terry Reedy

Sion Arrowsmith wrote:

In article mailman.7301.1232043685.3487.python-l...@python.org,
 s...@pobox.com wrote:

   [mimetype weirdness reported]
   Sion Is this a bug?
Might be.  Can you file a bug report in the Python issue tracker with a
small script that demonstrates the behavior?


http://bugs.python.org/issue4963

(It's tagged as being 2.4 and 2.5 because those are the versions I
have to hand to confirm it on, but I'd be rather surprised if it's
not still like this in 2.6.)


Trying to reproduce a bug, as this report requires, is easier if you 
give code that can be copy and pasted into the interpreter or even into 
an edit window (as with IDLE) to be run from there. (3.0 version)


import mimetypes
print(mimetypes.guess_extension('image/jpeg'))
mimetypes.init()
print(mimetypes.guess_extension('image/jpeg'))

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


Python 2.6's multiprocessing lock not working on second use?

2009-01-16 Thread Frédéric Sagnes
Hi,

I ran a few tests on the new Python 2.6 multiprocessing module before
migrating a threading code, and found out the locking code is not
working well. In this case, a pool of 5 processes is running, each
trying to get the lock and releasing it after waiting 0.2 seconds
(action is repeated twice). It looks like the multiprocessing lock
allows multiple locking after the second pass. Running the exact same
code with threads works correctly.

Further down is the test code, output is great when running with
threads (the sequence of lock/unlock looks good), but the output gets
mixed up (mutliple locks in a row) when running with processes.

My setup is : Mac OS X 10.5 running Python 2.6.1 from MacPython

Did I do something wrong, or is there a limitation for multiprocessing
locks that I am not aware of?

Thank you for your help!

-- Fred

---

#!/usr/bin/python
# -*- coding: utf-8 -*-

from multiprocessing import Process, Queue, Lock
from Queue import Empty
from threading import Thread
import time

class test_lock_process(object):
def __init__(self, lock, id, queue):
self.lock = lock
self.id = id
self.queue = queue
self.read_lock()

def read_lock(self):
for i in xrange(2):
self.lock.acquire()
self.queue.put('[proc%d] Got lock' % self.id)
time.sleep(.2)
self.queue.put('[proc%d] Released lock' % self.id)
self.lock.release()

def test_lock(processes=10, lock=Lock(), process=True, queue=None):
print_result = False
if queue == None:
print_result = True
queue = Queue()

threads = []
for i in xrange(processes):
if process: threads.append(Process(target=test_lock_process,
args=(lock,i,queue,)))
else: threads.append(Thread(target=test_lock_process, args=
(lock,i,queue,)))

for t in threads:
t.start()

for t in threads:
t.join()

if print_result:
try:
while True: print queue.get(block=False)
except Empty:
pass

if __name__ == __main__:
#test_lock(processes=5, process=True)
test_lock(processes=5)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Possible bug in Tkinter - Python 2.6

2009-01-16 Thread Terry Reedy

Eric Brunel wrote:

On Thu, 15 Jan 2009 23:49:22 +0100, Terry Reedy tjre...@udel.edu wrote:

Eric Brunel wrote:

[snip]  And BTW, if this is actually a bug, where can I report it?


bugs.python.org


Thanks. I reported the problem.


When you report that you reported to problem to the tracker (a good 
idea), please include link so anyone reading this thread can jump there 
to continue with followup there.


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


Re: optimizing large dictionaries

2009-01-16 Thread pruebauno
On Jan 15, 4:39 pm, Per Freem perfr...@yahoo.com wrote:
 hello

 i have an optimization questions about python. i am iterating through
 a file and counting the number of repeated elements. the file has on
 the order
 of tens of millions elements...

 i create a dictionary that maps elements of the file that i want to
 count
 to their number of occurs. so i iterate through the file and for each
 line
 extract the elements (simple text operation) and see if it has an
 entry in the dict:

 for line in file:
   try:
     elt = MyClass(line)# extract elt from line...
     my_dict[elt] += 1
   except KeyError:
     my_dict[elt] = 1

 i am using try/except since it is supposedly faster (though i am not
 sure
 about this? is this really true in Python 2.5?).

 the only 'twist' is that my elt is an instance of a class (MyClass)
 with 3 fields, all numeric. the class is hashable, and so my_dict[elt]
 works well.
 the __repr__ and __hash__ methods of my class simply return str()
 representation
 of self, while __str__ just makes everything numeric field into a
 concatenated string:

 class MyClass

   def __str__(self):
     return %s-%s-%s %(self.field1, self.field2, self.field3)

   def __repr__(self):
     return str(self)

   def __hash__(self):
     return hash(str(self))

 is there anything that can be done to speed up this simply code? right
 now it is taking well over 15 minutes to process, on a 3 Ghz machine
 with lots of RAM (though this is all taking CPU power, not RAM at this
 point.)

 any general advice on how to optimize large dicts would be great too

 thanks for your help.

I am willing to bet a beer that the slow performance has nothing to do
with the dict but is either because of MyClass or the read from disk.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Beginner: Data type conversion question

2009-01-16 Thread flagg
On Jan 15, 11:35 pm, Terry Reedy tjre...@udel.edu wrote:
 flagg wrote:
  I am still fairly new to python and programming in general.  My
  question is regardingdataconversion, I am working on a script that
  will edit dns zone files, one of the functions i wrote handles
  updating the serial number.
  Our zone files use the date as the first part of the serial and a two
  digit integer as the last two.

  i.e. 2009011501.  The next update would be 2009011502, etc
  Here is the function I wrote, I am using dnspython for reading in zone
  files as Zone objects.  Because dnspython's built-in serial updater
  will not work with how we format our serial's, I have to re-write it.

  def checkSerial():
      
      Checks the current 'date' portion of the serial number and
      checks the current 'counter'(the two digit number at the end of
      the serial number), then returns a complete new serial
      
      currentDate =  time.strftime(%Y%m%d, time.localtime())
      for (name, ttl, rdata) in zone.iterate_rdatas(SOA):
          date = str(rdata.serial)[0:8]
          inc = str(rdata.serial)[8:10]

 If rdate.serial is already a string, as name would imply, the str() call
 is pointless.  If not, can you get inc as int more directly?



      if date == currentDate:
          int(inc) + 1
          print inc
          newInc = str(inc).zfill(2)
          serial = date + newInc
          print date is the same
          return serial
      elif date  currentDate:
          newInc = 01.zfill(2)
          serial = currentDate + newInc
          print date is different
          return serial

  Through all of this I am doing a lot ofdatatypeconversion. string -
  integer, integer back to string, etc.  Is this an efficient way of
  handling this?  I have to perform basic addition on the inc
  variable, but also need to expose that value as a string.   What I
  have above does work, but I can't help but think there is a more
  efficient way. I guess I am not used todatatypes being converted so
  easily.

 Other than that, you are perhaps worrying too much, even if code could
 be squeezed more.  The idea that every object knows how to convert
 itself to a string representation is basic to Python.

 tjr

Actually when i run a type(serial) on that variable it returns a
long  which i am not sure why dnspython uses a long variable to
store the serial.   But you could be right about me worrying to much.
The other languages I have dabbled in (java, perl) I don't remember
type conversion being as simple.   But again I am still new, so don't
quote me on that :)
--
http://mail.python.org/mailman/listinfo/python-list


Re: lazy evaluation is sometimes too lazy... help please.

2009-01-16 Thread Scott David Daniels

Ken Pu wrote:

Hi,  below is the code I thought should create two generates, it[0] =
0,1,2,3,4,5, and it[1] = 0,10,20,30,..., but they turn out to be the
same!!!

from itertools import *
itlist = [0,0]
for i in range(2):
  itlist[i] = (x+(i*10) for x in count())
...
print list(islice(itlist[0], 5))
print list(islice(itlist[1], 5))
... -- lazy evaluation doesn't evaluate
 (x+(i*10) for x in count())   until the end. 

Nope, that generator expression is evaluated in your assignment.
The expression   x+(i*10)  is evaluated at each step of the generator.
 But is this the right behaviour?
It is the defined behavior.

For what you want:
import itertools as it

def count_from(base):
for n in it.count():
yield n + base

itlist = [count_from(n) for n in range(2)]


--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: Integrating awk in Python

2009-01-16 Thread mk

Alfons Nonell-Canals wrote:

At the beggining I thought to translate them and program them in 
python but I prefer to avoid it because it means a lot of work and I 
should do it after each new version of this external stuff. I would like 
to integrate them into my python code.



That's kind of like retrofitting steam engine onto a Mach 2 jetfighter.

Well there's always awk2c..

Regards,
mk

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


Re: Beginner: Data type conversion question

2009-01-16 Thread flagg
On Jan 15, 11:43 pm, Marc 'BlackJack' Rintsch bj_...@gmx.net wrote:
 On Thu, 15 Jan 2009 21:09:43 -0800, flagg wrote:
  def checkSerial():
      
      Checks the current 'date' portion of the serial number and checks
      the current 'counter'(the two digit number at the end of the serial
      number), then returns a complete new serial 
      currentDate =  time.strftime(%Y%m%d, time.localtime())

 The format string can be written as *one* string literal instead of
 three: %Y%m%d.

      for (name, ttl, rdata) in zone.iterate_rdatas(SOA):
          date = str(rdata.serial)[0:8]
          inc = str(rdata.serial)[8:10]

 Here you are converting `rdata.serial` twice.

           tmp = str(rdata.serial)
           date = tmp[0:8]
           inc = int(tmp[8:10])

 As `inc` is conceptually a number, you should do theconversionhere and
 treat it as number from now on.

      if date == currentDate:
          int(inc) + 1
          print inc
          newInc = str(inc).zfill(2)
          serial = date + newInc
          print date is the same
          return serial
      elif date  currentDate:
          newInc = 01.zfill(2)
          serial = currentDate + newInc
          print date is different
          return serial

 Both branches do almost the same.  You should try to avoid such code
 duplication.

       if date == currentDate:
           inc += 1
       elif date  currentDate:
           inc = 1
       else:
           assert False   # Should never happen.

       return %s%02d % (date, inc)

 That's it.

 Ciao,
         Marc 'BlackJack' Rintsch

Ah

return %s%02d % (date, inc)


This piece is what I was missing in my original design.  I couldn't
figure out hot to take and integer and force it to my double digit.
i.e. 01 instead of 1.   Which is why I was using strings to make that
happen. (obviously incorrectly).  Thanks

Could you explain what assert does in the if statement.  I am
assuming if the first two conditions are not met, it will hit assert
false and exit the program?
--
http://mail.python.org/mailman/listinfo/python-list


Python 3: range objects cannot be sliced

2009-01-16 Thread Alan G Isaac

Is the behavior below expected? Documented?
(The error msg is misleading.)
Thanks,
Alan Isaac

 x = range(20)
 s = slice(None,None,2)
 x[s]
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: sequence index must be integer, not 'slice'
--
http://mail.python.org/mailman/listinfo/python-list


Re: List comprehension - NameError: name '_[1]' is not defined ?

2009-01-16 Thread mario ruggier
On Jan 16, 1:35 pm, ajaksu aja...@gmail.com wrote:
 On Jan 16, 5:09 am, mario ruggier mario.rugg...@gmail.com wrote:

  Laboriously doing all these
  checks on each expr eval will be very performance heavy, so I hope to
  be able to limit access to all these more efficiently. Suggestions?

 None regarding the general issue, a try:except to handle this one:

 '(x for x in ()).throw(bork)'

What is the potential security risk with this one?

To handle this and situations like the ones pointed out above on this
thread, I will probably affect the following change to the
evoque.evaluator.RestrictedEvaluator class, and that is to replace the
'if name.find(__)!=-1:' with an re.search... where the re is defined
as:

restricted = re.compile(r|\..join([
__, func_, f_, im_, tb_, gi_, throw]))

and the test becomes simply:

if restricted.search(name):

All the above attempts will be blocked this way. Any other disallow-
sub-strings to add to the list above?

And thanks a lot Daniel, need to find a way to get somebeer over to
ya... ;-)

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


Re: Start multiple listening servers in one file

2009-01-16 Thread MRAB

Thomas W wrote:
I`m working on a django-project where I`m using the awsome pyftpdlib 
for ftpserver-functionality. I also have a simple worker deamon 
running in the background, but not listening to any port. How can I 
start all of these processes on one file? Tried using subprocess and 
popen but that resulted in an eternal loop starting the servers over 
and over until all resources were used, then crash.


Any hint on how to do this would be highly appreciated.


Do you mean that your script is invoking itself? If yes, then could you
pass something on the commandline to say you're not the initial
instance, so don't invoke yourself and then check that?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3: range objects cannot be sliced

2009-01-16 Thread Fuzzyman
On Jan 16, 5:45 pm, Alan G Isaac alan.is...@gmail.com wrote:
 Is the behavior below expected? Documented?
 (The error msg is misleading.)
 Thanks,
 Alan Isaac

   x = range(20)
   s = slice(None,None,2)
   x[s]
 Traceback (most recent call last):
    File stdin, line 1, in module
 TypeError: sequence index must be integer, not 'slice'

Well, it has the same behaviour as the iterator returned by xrange in
Python 2.X - so expected I guess. The error message is also the same
in Python 2.X.

Michael Foord
--
http://www.ironpythoninaction.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3: range objects cannot be sliced

2009-01-16 Thread Paul Rubin
Alan G Isaac alan.is...@gmail.com writes:
   x = range(20)
   s = slice(None,None,2)
   x[s]
 Traceback (most recent call last):
File stdin, line 1, in module
 TypeError: sequence index must be integer, not 'slice'

range is an iterator now.  Try itertools.islice.
--
http://mail.python.org/mailman/listinfo/python-list


Re: List comprehension - NameError: name '_[1]' is not defined ?

2009-01-16 Thread Paul Rubin
mario ruggier mario.rugg...@gmail.com writes:
 All the above attempts will be blocked this way. Any other disallow-
 sub-strings to add to the list above?

I think what you are trying to do is fundamentally hopeless.  You
might look at web.py (http://webpy.org) for another approach, that
puts a complete interpreter for a Python-like language into the
template engine.

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


Re: Integrating awk in Python

2009-01-16 Thread Grant Edwards
Am Freitag, 16. Januar 2009 13:02:59 schrieb Alfons Nonell-Canals:
 Hello,
 I'm developing a software package using python. I've programmed all
 necessary tools but I have to use other stuff from other people. Most of
 these external scripts are developed using awk.

 At the beggining I thought to translate them and program
 them in python but I prefer to avoid it because it means a lot
 of work and I should do it after each new version of this
 external stuff. I would like to integrate them into my python
 code.

 I know I can call them using the system environment but it is
 slower than if I call them inside the package.

So you've tried system(), and it didn't meet your requirements?

 I know it is possible with C,

What is possible with C?

 do you have experience on integrate awk into python calling
 these awk scripts from python?

Just like in C, you can call them directory using fork/exec to
eliminate the shell spawned by system(), but the difference in
time is probably going to be negligible.  If you're not able to
meet your timing requirements using os.system(), then I suspect
it's the awk programs that are too slow. 

I'd probably use the subprocess module to avoid the shell for
security reasons.

First, get it working.  Then, after you've established that the
program isn't meeting the timing specification _measure_ where
the time is going. It's silly trying optimize the part of the
program that's only taking up 1% of the execution time.

Premature optimization...

-- 
Grant Edwards   grante Yow! They collapsed
  at   ... like nuns in the
   visi.comstreet ... they had no
   teen appeal!
--
http://mail.python.org/mailman/listinfo/python-list


minidom, drilling down to a low node in one line?

2009-01-16 Thread Matt Brown - nyc
Hello,


I hope this isn't completely redundant...

I'm working with an example found of parsing XML with xml.dom.minidom
and am having some issues getting a node down three levels.

Here is the tutorial:
http://diveintopython.org/xml_processing/parsing_xml.html

Given the XML:
_
?xml version=1.0 ?
grammar
ref id=bit
  p0/p
  p1/p
/ref
/grammar
_

How do I address the textNode.data that = 0?

The only way I figured out is to recursively childNode from the parsed
down (as following the guide).  Is there no way to simply address the
item by something along the lines of:

_
xmldoc = minidom.parse(example.xml)
xmldoc.getElementsByTagName(grammar:ref:p:)
_


Any input or direction is appreciated.


Thanks!

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


Re: Python 3: range objects cannot be sliced

2009-01-16 Thread Alan G Isaac

On 1/16/2009 1:15 PM Paul Rubin apparently wrote:

range is an iterator now.  Try itertools.islice.


Well yes, it behaves like xrange did.
But (also like xrange) it supports indexing. (!)
So why not slicing?
I expected this (to keep it functionally
more similar to the old range).

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


Re: Python 3: range objects cannot be sliced

2009-01-16 Thread Christian Heimes
Alan G Isaac schrieb:
 On 1/16/2009 1:15 PM Paul Rubin apparently wrote:
 range is an iterator now.  Try itertools.islice.
 
 Well yes, it behaves like xrange did.
 But (also like xrange) it supports indexing. (!)
 So why not slicing?
 I expected this (to keep it functionally
 more similar to the old range).

The old range function returned a list. If you need the old
functionality you can use list(range(...))[].

Why do you want to slice a range anyway? The range type supports a
start, stop and step argument.

Christian

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


Re: why o/p is different ???

2009-01-16 Thread Lie
On Jan 15, 1:34 pm, asit lipu...@gmail.com wrote:
 I recently faced a peculiar o/p.

 My objective is to remove the command name(my script name) from
 sys.argv[0].
 I coded like this

 import urllib
 import sys

 print \n\n\t\tlipun4u[at]gmail[dot]com
 print \t\t

 apppath = sys.argv[0].split(/)
 appname = apppath[len(apppath)-1]
 print appname

 if len(sys.argv) not in [2,3]:
     print Usage :  + appname +  url [options]
     print e.g. :  + appname + www.google.com--verbose
     print \n\t[option]
     print \t\t--verbose/-V for verbose output
     print \t\t-r for recursive scan
     sys.exit(1)

 site = appname.replace(http://,;).rsplit(/,1)[0]
 site = http://; + site.lower()
 print site

 It showed the required o/p in the IDLE
 here is the o/p

                 lipun4u[at]gmail[dot]com
                 
 linkscan.py
 Usage : linkscan.py url [options]
 e.g. : linkscan.pywww.google.com--verbose

         [option]
                 --verbose/-V for verbose output
                 -r for recursive scan

 Traceback (most recent call last):
   File I:/Python26/linkscan.py, line 18, in module
     sys.exit(1)
 SystemExit: 1

 But in command prompt the o/p is still faulty

                 lipun4u[at]gmail[dot]com
                 
 I:\Python26\linkscan.py
 Usage : I:\Python26\linkscan.py url [options]
 e.g. : I:\Python26\linkscan.pywww.google.com--verbose

         [option]
                 --verbose/-V for verbose output
                 -r for recursive scan

 I:\Python26

 regards
 asit dhal

Of course the pragmatic approach is just to include

appname = 'linkscan.py'

at the top of the document.

I agree apppath might change (because you copied the program to
different places, different bin directory on different machine), but
there is no reason linkscan.py should change. And if you have to
change the invoking name, sometimes it might be more useful for users
to know the REAL name of the program (probably the user friendly
version, e.g. Link Scanner or Link Scanner 1.0), instead of the
name of the script it is run from (without the apppath). It is trivial
for human user to guess where the script is located and what the
appname is from the full apppath (path+name)
--
http://mail.python.org/mailman/listinfo/python-list


FileCookieJar has not attribute _self_load

2009-01-16 Thread Dragos
I am trying to make a testing script to load/save cookies to a file
with FileCookieJar, but it results in this error: FileCookieJar has
not attribute _self_load

This is my script:

import urllib.request, urllib.parse,http.cookiejar
url=http://localhost/test.php;
cs=http.cookiejar.FileCookieJar()
cs.load(cookies.txt,ignore_discard=False, ignore_expires=False)
opener=urllib.request.build_opener(urllib.request.HTTPCookieProcessor
(cs))
y=opener.open(url)
print(y.read())

Thanks for helping.
--
http://mail.python.org/mailman/listinfo/python-list


Differences between class and function decorator

2009-01-16 Thread mk

Hello everyone,

I rewrote an example someone posted here recently from:

 def print_method_name(method):
def new_meth(*args, **kwargs):
print method.func_name
return method(*args, **kwargs)
return new_meth

 @print_method_name
def f2():
pass

 f2()
f2


..to:

 class MyMethod(object):
def __init__(self, func):
self.name = func.func_name
self.func = func
def __call__(self):
print self.name
return self.func


 @MyMethod
def f():
pass

 f()
f
function f at 0x017CDA70

Note that function decorator returned None, while class decorator 
returned function.


Why the difference in behavior? After all, print_method_name decorator 
also returns a function (well it's a new function but still a function)?


Regards,
mk

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


Re: Differences between class and function decorator

2009-01-16 Thread Duncan Booth
mk mrk...@gmail.com wrote:

 Note that function decorator returned None, while class decorator 
 returned function.
 
 Why the difference in behavior? After all, print_method_name decorator 
 also returns a function (well it's a new function but still a function)?

That would be because the function decorator returns the result of calling 
the function whereas your class decorator simply returns the function 
without calling it.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Does Python really follow its philosophy of Readability counts?

2009-01-16 Thread Russ P.
On Jan 16, 5:22 am, Steve Holden st...@holdenweb.com wrote:
 Russ P. wrote:

 [...]

  I spent *way* too much time on that post. I really need to quit
  spending my time refuting the baloney that passes for wisdom here.

 He who cannot ignore baloney is doomed to refute it.

 regards
  Steve
 --
 Steve Holden+1 571 484 6266   +1 800 494 3119
 Holden Web LLC  http://www.holdenweb.com/


Yeah, and I should really learn to leave off those little zingers. If
Mr. D weren't obviously an intelligent person and a Python expert, I
wouldn't care what he writes. I just think that he, along with a few
others here, love Python so much that they refuse to recognize its
limitations. It's an easy trap to fall into.
--
http://mail.python.org/mailman/listinfo/python-list


Re: are there some special about '\x1a' symbol

2009-01-16 Thread Matthew Woodcraft
Steve Holden st...@holdenweb.com writes:

 Unknown wrote:
 On 2009-01-12, John Machin sjmac...@lexicon.net wrote:

 I didn't think your question was stupid. Stupid was (a) CP/M recording
 file size as number of 128-byte sectors, forcing the use of an in-band
 EOF marker for text files (b) MS continuing to regard Ctrl-Z as an EOF
 decades after people stopped writing Ctrl-Z at the end of text files.

 I believe that feature was inherited by CP/M from DEC OSes
 (RSX-11 or RSTS-11). AFAICT, all of CP/M's file I/O API
 (including the FCB) was lifted almost directly from DEC's
 PDP-11 stuff, which probably copied it from PDP-8 stuff.

 Perhaps in the early 60's somebody at DEC had a reason.  The
 really interesting thing is that we're still suffering because
 of it 40+ years later.

 I suspect this is probably a leftover from some paper tape data formats,
 when it was easier to detect the end of a file with a sentinel byte than
 it was to detect run-off as end of file. It could easily date back to
 the PDP-8.

I think it was a reasonable way for CP/M to work. It's a nice simple
interface for reading and writing files: you always read and write
from/to a fixed 128-byte buffer.

Allowing files to be arbitrary-length byte sequences would have made the
system calls more complicated, and it would also have needed another
byte in the on-disk file control block (so 7.3 filenames rather than
8.3, or some other compromise).

For CP/M programs, it's hard to see what the gain would have been; it's
easy to design a binary file format so that it doesn't matter whether or
not there's junk on the end, and CP/M didn't have a tradition of storing
data in 'plain text' files (for good reasons of disk space).


It certainly is a shame that we didn't leave all this behind when
MS/DOS 2 appeared, though.

-M-

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


Re: Lazy List Generator Problem

2009-01-16 Thread Gerald Britton
For those interested in the Sieve of Eratosthenes, have a look at:

http://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf

The examples in the paper are in Haskell, but I have been
corresponding with the author who provided this Python version:

def sieve():
innersieve = sieve()
prevsquare = 1
table  = {}
i = 2
while True:
if (table.has_key(i)):
prime = table[i]
del(table[i])
next = i+prime
while next in table:
 next = next + prime
table[next] = prime
else:
yield i
if i  prevsquare:
j = innersieve.next()
prevsquare = j * j
table[prevsquare] = j
i = i + 1

Only of 65056 bytes (less than 1/16 MB) of heap is used when
calculating the millionth prime.  It is also very fast but can be even
further optimized using a wheel as described in the paper.  FWIW I was
so intrigued I went off to learn Haskell just so I could follow the
paper properly.
--
http://mail.python.org/mailman/listinfo/python-list


Re: English-like Python

2009-01-16 Thread has
On 16 Jan, 05:42, Chris Rebert c...@rebertia.com wrote:
 On Thu, Jan 15, 2009 at 5:02 PM, The Music Guy music...@alphaios.net wrote:



  Just out of curiousity, have there been any attempts to make a version
  of Python that looks like actual English text?
  [...]
 Does the name AppleScript mean anything to you? ;-)

[quoting myself on the subject]

The big advantage of AppleScript syntax is that it makes it easy to
get a broad idea of what an existing AppleScript does, even if you
don't know the AppleScript language in particular or programming in
general.

The big disadvantage of AppleScript syntax is that it makes it very
difficult to form an accurate understanding of how it actually does
it. For example, is 'foo bar' a property name, a constant name, a
command name, a command name followed by a property/constant/variable
name, or something else again?

With more conventional language syntaxes, you have the opposite
situation: in order to make any sense at all of an existing script,
you first have to learn to read the syntax and know some basic
programming. OTOH, once you're past that initial hurdle, it's easier
to understand exactly what makes it tick, e.g. x.foo_bar is a property
name, :foo_bar is a constant, foo_bar() is a command, foo(bar) is a
command name followed by a variable name, and so on.

The upshot of this is that AppleScript has a lower barrier to entry
but higher cost of use compared to other languages. It's a trade-off,
but one that probably fits quite well with the needs of many
AppleScripters, who write relatively small programs on an irregular
basis. A high cost of entry will be harder to justify if you don't
actually use the language very often. OTOH, if you write large
programs on a daily basis then what matters most is long-term
productivity, and you'll recoup the time taken to learn a language
fairly quickly by comparison.

...

If you really want an end-user language that has the legibility of
already-familiar natural languages while retaining all the precision
provided by traditional programming syntax and adding a lot of much-
needed interactive help and guidance, I think the best approach would
be to go with an 'intelligent' structure editor a-la Scratch or Alice,
rather than 'dumb' character-based source code as found in Python,
AppleScript, Inform-7, C, et-al. See:

http://scratch.mit.edu/
http://www.alice.org/

If you eliminate the need for syntax to describe structure, you can
present programs in whatever way suits users best - be it English
words in coloured blocks, or traditional brackets and braces. Plus it
becomes an awful lot easier to help and correct novice users as they
put together their first programs - much as the original Mac GUI
provided much better input guidance and error prevention over previous
DOS-style command lines.

HTH

has
--
Control AppleScriptable applications from Python, Ruby and ObjC:
http://appscript.sourceforge.net

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


Re: English-like Python

2009-01-16 Thread Erik Max Francis

alex23 wrote:

On Jan 16, 5:39 pm, Erik Max Francis m...@alcyone.com wrote:

Inform 7 has some
interesting ideas, but I think the general problem with English-like
programming language systems is that once you get into the nitty gritty
details, you end up having to know exactly the right things to type,


This has always been my impression of Inform 7. I have a lot of
respect for what they've set out to achieve but English isn't exactly
known for its lack of ambiguity. This is great for literature but not
so helpful for programming.


which ultimately get just as complicated as a more traditional
programming language syntax.


And much more verbose, as well.


Agreed.  I, too, am impressed with what the authors tried to do for 
Inform 7.


--
Erik Max Francis  m...@alcyone.com  http://www.alcyone.com/max/
 San Jose, CA, USA  37 18 N 121 57 W  AIM, Y!M erikmaxfrancis
  Laws are silent in time of war.
   -- Cicero
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3: range objects cannot be sliced

2009-01-16 Thread Alan G Isaac

It is documented:
http://docs.python.org/3.0/library/stdtypes.html#sequence-types-str-bytes-bytearray-list-tuple-range
--
http://mail.python.org/mailman/listinfo/python-list


Class decorator with argument

2009-01-16 Thread mk

Hello,

I wrote this class decorator with argument:

 class ChangeDoc(object):
def __init__(self, docstring):
self.docstring = docstring
def __call__(self, func):
func.__doc__ = self.docstring
return func

It seems to work:

 @ChangeDoc(bulba)
def f():
pass

 f.__doc__
'bulba'

Can someone please debug my reasoning if it's incorrect?

1. First, the decorator @ChangeDoc('bulba') instantiates with 
__init__(self, 'bulba'), to some class instance, let's call it _decor.


2. Then _decor's __call__ method is called with function f as argument, 
changing the docstring and returning the changed f object, like f = 
_decor(f) .


Am I missing smth important / potentially useful in typical real-world 
applications in that picture?


Regards,
mk

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


Finding the full path of an executable

2009-01-16 Thread Michael Hoffman
Is there a portable way to find the full path of a filename that would 
be called by os.execvp()?


Thanks,
Michael Hoffman

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


tuple methods: documentation missing

2009-01-16 Thread Alan G Isaac

http://docs.python.org/3.0/library/stdtypes.html#sequence-types-str-bytes-bytearray-list-tuple-range

I see no mention of the tuple methods?

Right after the paragraph
Most sequence types support the following operations.
it seems appropriate to have one stating
Most sequence types support the following methods: index() and count().

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


*Advanced* Python book?

2009-01-16 Thread mk

Hello everyone,

I looked for it I swear, but just can't find it.

Most Python books seem to focus on examples of how to call functions 
from standard library. I don't need that, I have online Python 
documentation for that.


I mean really advanced mental gymnastics, like gory details of how 
Python objects operate, how to exploit its dynamic capabilities, dos and 
donts with particular Python objects, advanced tricks, everything from 
chained decorators to metaprogramming. Dive Into Python comes closest to 
this ideal from what I have found, but still not far enough.


Anybody found such holy grail?

Regards,
mk

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


  1   2   3   >