Re: python & osgi

2007-09-13 Thread Marc 'BlackJack' Rintsch
On Wed, 12 Sep 2007 18:13:13 -0700, Andreas Wapf wrote:

> Is there something like a osgi implementation in python? I am really
> impressed by the bundle system and the possibility to load and unload
> bundles without wasting memory.

I'm really impressed by the about 1000 pages OSGi specification.  8-)

> Is it even possible to do something like that in python? Would be nice to
> have a very small python interpreter and just load the modules as needed.

Modules are only loaded as you import them, so you can make it as "lazy"
as you want.  I don't know if it's possible to unload them again.  But is
code really a memory problem?  I've never thought "OMG memory is getting
low, I wish I could unload a module to get some space."  In my experience
it's always data that eats my RAM.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: An ordered dictionary for the Python library?

2007-09-13 Thread Antoon Pardon
On 2007-09-12, Mark Summerfield <[EMAIL PROTECTED]> wrote:
> On 12 Sep, 13:46, Michele Simionato <[EMAIL PROTECTED]>
> wrote:
>> On Sep 12, 2:42 pm, Steven D'Aprano <[EMAIL PROTECTED]
>>
>> cybersource.com.au> wrote:
>> > On Wed, 12 Sep 2007 07:33:45 +, Mark Summerfield wrote:
>> > In fact, I'm not sure what people mean by ordered dicts. I assume they
>> > mean the keys are ordered, not the values. But ordered by what? Insertion
>> > order? Modification order? Alphabetical order?
>>
>> Insertion order.
>>
>>  M.S.
>
>
> Actually I meant by key order, so insertion order doesn't matter at
> all. If you need a dictionary-like data structure that respects
> insertion order you could use a list of (key, value) tuples.

If you want a dictionary that iterates over his keys and does so
in a sorted manner you probably want a tree.

One posible implemenation can be found here:

  http://www.pardon-sleeuwaegen.be/antoon/avltree.html


I hope it is usefull to you.

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


Re: Parallel/Multiprocessing script design question

2007-09-13 Thread A.T.Hofkamp
On 2007-09-13, Amit N <[EMAIL PROTECTED]> wrote:
> Hi guys,
>
> I tend to ramble, and I am afraid none of you busy experts will bother 
> reading my long post, so I will try to summarize it first:

I haven't read the details, but you seem to aim for a single python program
that does 'it'. A single sequential thread is not fast enough, so you want
parallel execution (and yes there are a zillion ways of doing that).

Why don't you start at the other end?

Write a program for each task that you have, then fork/spawn/chain/whatever
enough processes at OS level to eat all your data. The OS is usually much
better at balancing CPU's. The Python module 'subprocess' would be your friend
in that case.

In addition, you can run each program independently, which will come in handy
one day.


Sincerely,
Albert

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


Re: Python 3K or Python 2.9?

2007-09-13 Thread Bruno Desthuilliers
TheFlyingDutchman a écrit :
> On Sep 12, 4:40 am, Bjoern Schliessmann  [EMAIL PROTECTED]> wrote:
>> Ivan Voras wrote:
>>> What does "self" have to do with an object model? It's an
>>> function/method argument that might as well be hidden in the
>>> compiler without ever touching the role it has (if not, why?). I
>>> agree that it's needless noise in a language.
>> If this was needless, why do C++ and Java have the "this" pointer?
>>
> "this" in C++ and Java is not shown in the parameter list, which was
> what he was
> complaining about.  He wants
> 
> class MyClass:
> def SomeFunction(someParameter):
>self.someParameter = someParameter
> 
> not
> 
> class MyClass:
> def SomeFunction(self, someParameter):
>self.someParameter = someParameter
> 
> 
> The confusing way about the current Python method when you first
> encounter it is
>  why is "self" being passed in when you write the function

At this stage, it's not "passed in", it's declared in the arguments list.

> but not
> when you call it.

It *is* passed when you call the function.

> If the compiler is smart enough to know that

The compiler has absolutely nothing to do with it. It's the object model 
that takes care of this. Quick explanation:

- functions objects implement the descriptor protocol.
- when a function which is an attribute of a class is looked up on an 
instance of that class, the  __get__ method of the function object is 
called with the instance (and class) as arguments.
- this method returns a closure wrapping the instance, the class and the 
function object itself
- when this closure is called, it itself prepends the instance to the 
args it receives, calls the function with these args, and returns the 
result.

This is why you need tho declare the instance as the first argument, but 
don't need to pass it explicitely *when calling the function as a method 
of an object*. Notice that you can still use the function directly, 
passing the instance by yourself. And that you can define a function 
outside a class and then attach it to a class. To make a long story 
short, Python's methods are just thin temporary wrappers around plain 
functions.

> a = MyClass()
> a.SomeFunction(12)
> 
> SomeFunction() has a "self" implicitly added to the parameter list,  it
> seems that it should be smart enough to know that a function defined
> in a class has a "self" implicitly added to the parameter list.

The compiler has nothing to do with it, and where you define the 
function is totally orthogonal:

def truc(obj):
   print obj

class Toto(object):
   pass

Toto.trac = truc

t = Toto()
t.trac()

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


Re: Implementing a fixed size stack for an RPN Calculator

2007-09-13 Thread Diez B. Roggisch
[EMAIL PROTECTED] schrieb:
> On Sep 12, 2:55 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
>> On Wed, 12 Sep 2007 20:55:22 +, [EMAIL PROTECTED] wrote:
>>> I have implemented an RPN calculator in python but now I would like to
>>> make the stack size fixed. how can I transform the user's RPN
>>> expression from a stack overflow to a computable expression.
>>> For instance, if my stack size is 2 then the some expression can't be
>>> computed but could be transformed as following:
>>> Non computable expression: 1 2 3 + +   --> stack size of 3 is needed
>>> Computable expression: 1 2 + 3 + --> stack size of 2 is needed
>>> How can I define a formal way of transforming the non computable
>>> expression to computable one.
>>> My RPN only implements: + - x %
>> Why does this homework assignment limit the stack so severely!?  ;-)
>>
>> Ciao,
>> Marc 'BlackJack' Rintsch
> 
> 
> The problem is not with the stack being severely small or not, it
> could be 1000 but it should be fixed and that's the limitation.

It can't be fixed. You can algebraic rewrite expressions of the form

(a + (b + (c + d))

because of the commutativity of the +-operation to

(a+b) + (c + d)

and this can be done automatically.

But for arbitrary expressions, you will _always_ need arbitrary stack-sizes.

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


Re: Python 3K or Python 2.9?

2007-09-13 Thread Bruno Desthuilliers
TheFlyingDutchman a écrit :
>> >>> Foo.bar(foo, "spam")
>> >>> foo.bar("spam")
> 
> That looks like a case of "There's more than one way to do it". ;)

Nope, on the contrary. The nice thing with this model is that you don't 
have distinct rules for functions and methods, since methods are just 
plain functions.

>> The latter two statements are equivalent. The 'instance.method(args)'
>> syntax is just sugar for 'Class.method(instance, args)'.
> 
> I think I saw where Guido Van Rossum had referred to something as
> "syntactic sugar" in some python.org page. I am not familiar with
> sugar as related to syntax. Is it being used as a synonym for "easier
> way of doing it"?

Yes. "syntactic sugar" mostly means "nicer, simpler syntax for something 
that could be done without". And one of the *great* strength of Python 
is that it exposes both the syntactic sugar for the most common uses 
case and the underlying implementation for most advanced tricks.
-- 
http://mail.python.org/mailman/listinfo/python-list


cannot declare global vars!

2007-09-13 Thread Konstantinos Pachopoulos
Hi,
i had posted earlier for not being able to declare global vars. No i 
followed the suggestions and created a class, but still the vars do not 
seem to have a global scope. I have tried pretty much everything. Any 
advice appreciated... Here:


#!/usr/bin/env jython

#imports
...


class SVNLogs2DBParser:   

#svnLogging_
#dbTable_
#cmterID_
#projID_
#fileIDNumber_
#Commiter_
#Commit_
#StoredProject_
#ProjectVersion_
#entryList_
   
def 
__init__(self,svnLogging_=SVNLogging(SVN_REPOS),dbTable_=DBTablesHandler(),cmterID_=0,projID_=0,

fileIDNumber_=0,Commiter_={},Commit_={},StoredProject_={},ProjectVersion_={},entryList_={}):

  

pass
#svnLogging_=SVNLogging(SVN_REPOS)  
#print "Connection established to SVN repository..."   
#dbTable_=DBTablesHandler()   
#cmterID_=0
#projID_=0
#fileIDNumber_=0
#Commiter_={}
#Commit_={}
#StoredProject_={}   
#ProjectVersion_={}
#entryList_={}



#reads all the revision logs (traversing them PIVOT at a time) and
#processes each log entry
def getLogsLoop(self):
   
   
while 
svnLogging_.getCurrentRevisionNumber()!=svnLogging_.getLatestRevisionNumber():  
  
   
entryList_=svnLogging_.getNextLogs(PIVOT);
#print "Attempting to go over the HEAD revision..."   

for entry in self.entryList:
print "processing new SVN entry..."
processLogEntry(entry)

entryList_.clear()   



#processes each log entry
#
#"entry" is of type SVNLogEntry. See SVNKit API   
#"changedPaths" is returned as a java.util.HashMap
#with key strings (paths) and values SVNLogEntryPath objects
#"entry.getDates()" returns a java.util.Date object
def processLogEntry(self, entry):
revision = int(entry.getRevision())
commiter = str(entry.getAuthor()) 
datetime = getTimeStamp(entry.getDate())
message = str(entry.getMessage())   
changedPaths = entry.getChangedPaths()  
   
#array passed for updating the  Commiter DB table
Commiter_[0] = cmterID_
Commiter_[1] = commiter
dbTable_.updateCommiterTable(Commiter_)

#array passed for updating the Commit DB table
Commit_[0] = projID_
Commit_[1] = datetime   
Commit_[2] = cmterID_
Commit_[3] = 0.0
Commit_[4] = "" #properties
fileStats=getFileTypes(changedPaths)
Commit_[5] = fileStats[0]
Commit_[6] = fileStats[2]
Commit_[7] = fileStats[1]
Commit_[8] = fileStats[3]
Commit_[9] = fileStats[4]   
dbTable_.updateCommitTable(self.Commit_)


ProjectVersion_[0]=projID_
ProjectVersion_[1]=0.0
dbTable_.updateProjectVersionTable(ProjectVersion_)


Project[0]=projID_
Project[1]=""
Project[2]=""
Project[3]=""
Project[4]=""

dbTable_.updateProjectTable(Project_) 

cmterID_+=1   
projID_+=1



##HELPER##METHODS###

 


##HELPER##METHODS###

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


hang in multithreaded program / python and gdb.

2007-09-13 Thread Jd
Hi
   I want to debug a locking situation in my program.

   http://wiki.python.org/moin/DebuggingWithGdb

   Where do I get binaries for ?
 - debug python 2.5 binary/rpm for FC7

   Also, the description of the hang is as follows.

   2 therads waiting in [EMAIL PROTECTED] ... from PyThread_acquire_lock()

   1 thread in _poll from _socketmodule.so.

   Any ideas what might be going on. (Isnt PyThread_acquire_lock()
trying to get the global interpreter lock ?)

  Any help.. pointers are welcome.

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


Re: Coming from Perl

2007-09-13 Thread Amer Neely
TheFlyingDutchman wrote:
> On Sep 12, 5:30 pm, Amer Neely <[EMAIL PROTECTED]> wrote:
>> I'm a complete newbie with Python, but have several years experience
>> with Perl in a web environment.
>>
>> A question I have, if someone here is familiar with Perl, does Python
>> have something like Perl's 'here document'? I've just searched and read
>> some postings on generating HTML but they all seem to refer to various
>> template utilities. Is this the only way, or am I missing something? I'm
>> used to generating X/HTML by hand, which makes the here document in Perl
>> ideal for me. Also, many times a client already existing HTML code that
>> I can use in a script.
>>
>> --
>> Amer Neely
>> w:www.webmechanic.softouch.on.ca/
>> Perl | MySQL programming for all data entry forms.
>> "Others make web sites. We make web sites work!"
> 
> I am not sure if this is what you are looking for, but Python has a
> special string with 3 quotes that I believe duplicates part of the
> functionality of a here document:
> 
> myHmtlHeader = """
> 
> My Page
> 
> """
> 
> print myHtmlHeader
> 
> 
> outputs:
> 
> 
> 
> My Page
> 
> 

Well, I have checked everything I can but I'm getting '500 Internal 
Server Error'. The log files aren't helpful:
[Thu Sep 13 03:43:00 2007] [error] [client 24.235.184.39] Premature end 
of script headers: /home/softouch/public_html/cgi-bin/scratch/hello.py

I can't even get it to run on my home PC running Apache + Win2K. Same error.

My script:
#!/usr/bin/python
import cgitb; cgitb.enable(display=0, logdir=".")
import sys
sys.stderr = sys.stdout
print "Content-Type: text/html"
print

print """


Hello 
from Python

Goodbye.


"""

-- 
Amer Neely
w: www.webmechanic.softouch.on.ca/
Perl | MySQL programming for all data entry forms.
"Others make web sites. We make web sites work!"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: MemoryError on reading mbox file

2007-09-13 Thread Christoph Krammer
On 12 Sep., 16:39, Istvan Albert <[EMAIL PROTECTED]> wrote:
> This line reads an entire message into memory as a string. Is it
> possible that you have a huge email in there (hundreds of MB) with
> some attachment encoded as text?

No, the largest single message with the mbox is about 100KB large.


> For now I would recommend that you split your mbox file into several
> smaller ones. (I think all you need is to split at the To: fields) and
> run your script on these individual files.

I get it to work with splitting the mbox file into single files, one
for each message, with the git-mailsplit tool, that is included in the
gitk package. This solved the problem for now.

Thanks for all your help.

Christoph


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


read part of jpeg file by pure python

2007-09-13 Thread Pacino
Hi, everyone,

I am wondering whether it's possible to read part (e.g. 1000*1000) of
a huge jpeg file (e.g. 3*3) and save it to another jpeg file
by pure python. I failed to read the whole file and split it, because
it would cost 2GB memory.

Can anyone help me? Any comments would be appreciated.

Thanks.

Robert

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


Re: Coming from Perl

2007-09-13 Thread Amer Neely
Amer Neely wrote:
> TheFlyingDutchman wrote:
>> On Sep 12, 5:30 pm, Amer Neely <[EMAIL PROTECTED]> wrote:
>>> I'm a complete newbie with Python, but have several years experience
>>> with Perl in a web environment.
>>>
>>> A question I have, if someone here is familiar with Perl, does Python
>>> have something like Perl's 'here document'? I've just searched and read
>>> some postings on generating HTML but they all seem to refer to various
>>> template utilities. Is this the only way, or am I missing something? I'm
>>> used to generating X/HTML by hand, which makes the here document in Perl
>>> ideal for me. Also, many times a client already existing HTML code that
>>> I can use in a script.
>>>
>>> -- 
>>> Amer Neely
>>> w:www.webmechanic.softouch.on.ca/
>>> Perl | MySQL programming for all data entry forms.
>>> "Others make web sites. We make web sites work!"
>>
>> I am not sure if this is what you are looking for, but Python has a
>> special string with 3 quotes that I believe duplicates part of the
>> functionality of a here document:
>>
>> myHmtlHeader = """
>> 
>> My Page
>> 
>> """
>>
>> print myHtmlHeader
>>
>>
>> outputs:
>>
>>
>> 
>> My Page
>> 
>>
> 
> Well, I have checked everything I can but I'm getting '500 Internal 
> Server Error'. The log files aren't helpful:
> [Thu Sep 13 03:43:00 2007] [error] [client 24.235.184.39] Premature end 
> of script headers: /home/softouch/public_html/cgi-bin/scratch/hello.py
> 
> I can't even get it to run on my home PC running Apache + Win2K. Same 
> error.
> 
> My script:
> #!/usr/bin/python
> import cgitb; cgitb.enable(display=0, logdir=".")
> import sys
> sys.stderr = sys.stdout
> print "Content-Type: text/html"
> print
> 
> print """
> 
> 
> Hello 
> from Python
> 
> Goodbye.
> 
> 
> """
> 

I should have added that it runs from the command line OK.

-- 
Amer Neely
w: www.webmechanic.softouch.on.ca/
Perl | MySQL programming for all data entry forms.
"Others make web sites. We make web sites work!"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Possible suggestion for removing the GIL

2007-09-13 Thread Diez B. Roggisch
Prateek wrote:

> Hi,
> 
> Recently there was some talk on removing the GIL and even the BDFL has
> written a blog post on it.
> I was trying to come up with a scalable and backwards compatible
> approach for how to do it.
> 
> I've put my thoughts up in a blog post - and I'd really like to hear
> what the community thinks of it.
> Mainly it revolves around dedicating one core for executing
> synchronized code and doing context switches instead of acquiring/
> releasing locks.

Where is the gain? Having just one core doesn't give you true parallelism -
which is the main reason behind the cries for a GIL-less Python.

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


Re: Python 3K or Python 2.9?

2007-09-13 Thread Piet van Oostrum
> TheFlyingDutchman <[EMAIL PROTECTED]> (T) wrote:

>T> The confusing way about the current Python method when you first
>T> encounter it is
>T>  why is "self" being passed in when you write the function but not
>T> when you call it. 

It *is* passed when you call it, but it is written before the method name
instead of after it. Some people have called this an "infix" call similar
to infix operators.
-- 
Piet van Oostrum <[EMAIL PROTECTED]>
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3K or Python 2.9?

2007-09-13 Thread Piet van Oostrum
> Ben Finney <[EMAIL PROTECTED]> (BF) wrote:

>BF> The latter two statements are equivalent. The 'instance.method(args)'
>BF> syntax is just sugar for 'Class.method(instance, args)'.

It is more than just syntactic sugar because the Class is derived from the
instance at runtime. 
-- 
Piet van Oostrum <[EMAIL PROTECTED]>
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: cannot declare global vars!

2007-09-13 Thread Peter Otten
Konstantinos Pachopoulos wrote:

> i had posted earlier for not being able to declare global vars. No i 

Post a followup in that thread then rather than starting a new one.

> followed the suggestions and created a class, but still the vars do not
> seem to have a global scope. I have tried pretty much everything. Any
> advice appreciated... Here:

[snip mess]

What Guillaume C. meant is:

To make a variable that is assigned within a function global you have to
declare it global

def foo():
global x
x = 42
foo()
print x

but that having many of these globals is a bad design and you should
use instance attributes instead:

class A(object):
def foo(self):
self.x = 42
a = A()
a.foo()
print a.x

Personally, I often prefer

def foo():
   return 42
x = foo()
print x

which is both explicit and concise.

These are basic considerations in Python, so I suggest that you read an
introductory text on the language before you proceed with your endeavours.

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


Re: Python+Expect+Win32 = Not Possible?

2007-09-13 Thread half . italian
On Sep 12, 9:27 pm, gamename <[EMAIL PROTECTED]> wrote:
> Hi,
>
> Is it still the case there is no practical Expect-like module for
> win32? I know that cygwin can support pexpect, but that isn't an
> option here --- I have to use a native win32 Python version.
>
> Are there alternatives, or is it simply not an option to replicate
> Expect on win32 with python?
>
> All I'm trying to do is start a couple processes, wait for each to say
> "done" on stdout and then quit (or timeout if something went wrong).
>
> TIA,
> -T

I had planned on using telnet to do the same thing on windows.  I
don't think I ever proved it, but I'm pretty sure it will work.

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52228

~Sean

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


Re: read part of jpeg file by pure python

2007-09-13 Thread Laurent Pointal
Pacino a écrit :
> Hi, everyone,
> 
> I am wondering whether it's possible to read part (e.g. 1000*1000) of
> a huge jpeg file (e.g. 3*3) and save it to another jpeg file
> by pure python. I failed to read the whole file and split it, because
> it would cost 2GB memory.
> 
> Can anyone help me? Any comments would be appreciated.
> 
> Thanks.
> 
> Robert
> 

Just reading parts of the *file* is easy (see tell() seek() and read()
methods on files).
But to extract a part of the *picture*, you must uncompress the picture
in memory, grab the sub-picture, and save it back - generally with
compression. I can't see how you can bypass the uncompress/compress
phases and the corresponding memory use.

A+

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

Re: read part of jpeg file by pure python

2007-09-13 Thread Pacino
On 9 13 ,   4 43 , Laurent Pointal <[EMAIL PROTECTED]> wrote:
> Pacino a écrit :
>
> > Hi, everyone,
>
> > I am wondering whether it's possible to read part (e.g. 1000*1000) of
> > a huge jpeg file (e.g. 3*3) and save it to another jpeg file
> > by pure python. I failed to read the whole file and split it, because
> > it would cost 2GB memory.
>
> > Can anyone help me? Any comments would be appreciated.
>
> > Thanks.
>
> > Robert
>
> Just reading parts of the *file* is easy (see tell() seek() and read()
> methods on files).
> But to extract a part of the *picture*, you must uncompress the picture
> in memory, grab the sub-picture, and save it back - generally with
> compression. I can't see how you can bypass the uncompress/compress
> phases and the corresponding memory use.
>
> A+
>
> Laurent.

The most difficult part is the uncompress part. I don't want the whole
picture to be uncompressed in the memory, because it will consume a
lot of memory (2GB, as I mentioned). My goal is to uncompress part of
the picture into the memory.

I just read some article on this subject (http://mail.python.org/
pipermail/image-sig/1999-April/000713.html) , but haven't test it out
yet.

Robert

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

Re: Get the complete command line as-is

2007-09-13 Thread Tim Golden
wangzq wrote:
> On Sep 12, 3:20 pm, Laurent Pointal <[EMAIL PROTECTED]> wrote:
>> wangzq a écrit :
>>
>>> Hello,
>>> I'm passing command line parameters to my browser, I need to pass the
>>> complete command line as-is, for example:
>>> test.py "abc def" xyz
>>> If I use ' '.join(sys.argv[1:]), then the double quotes around "abc
>>> def" is gone, but I need to pass the complete command line ("abc def"
>>> xyz) to the browser, how can I do this?
>>> I'm on Windows.
>> As Windows command-line parsing seem to remove some chars, maybe you can
>> try to use the GetCommandLine() function from Win32 API (I dont know if
>> it is available in pywin32 package - you may need to write a wrapper
>> with ctypes).
>>
>> Seehttp://msdn2.microsoft.com/en-us/library/ms683156.aspx
>>
>> A+
>>
>> Laurent.
> 
> Thank you for the tip. It works:
> 
> import ctypes
> 
> p = ctypes.windll.kernel32.GetCommandLineA()
> print ctypes.c_char_p(p).value
> 
> Now I only need to split the whole command line into 3 parts and get
> the last one.

Well, FWIW, it is exposed by pywin32:


import win32api
print win32api.GetCommandLine ()



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


Re: Get the complete command line as-is

2007-09-13 Thread Thomas Heller
wangzq schrieb:
> On Sep 12, 3:20 pm, Laurent Pointal <[EMAIL PROTECTED]> wrote:
>> wangzq a écrit :
>>
>> > Hello,
>>
>> > I'm passing command line parameters to my browser, I need to pass the
>> > complete command line as-is, for example:
>>
>> > test.py "abc def" xyz
>>
>> > If I use ' '.join(sys.argv[1:]), then the double quotes around "abc
>> > def" is gone, but I need to pass the complete command line ("abc def"
>> > xyz) to the browser, how can I do this?
>>
>> > I'm on Windows.
>>
>> As Windows command-line parsing seem to remove some chars, maybe you can
>> try to use the GetCommandLine() function from Win32 API (I dont know if
>> it is available in pywin32 package - you may need to write a wrapper
>> with ctypes).
>>
>> Seehttp://msdn2.microsoft.com/en-us/library/ms683156.aspx
>>
>> A+
>>
>> Laurent.
> 
> Thank you for the tip. It works:
> 
> import ctypes
> 
> p = ctypes.windll.kernel32.GetCommandLineA()
> print ctypes.c_char_p(p).value
> 

Better would be this code:

import ctypes
ctypes.windll.kernel32.GetCommandLineA.restype = ctypes.c_char_p
print ctypes.windll.kernel32.GetCommandLineA()

Thomas

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


Re: Get the complete command line as-is

2007-09-13 Thread Tim Golden
Thomas Heller wrote:
> Better would be this code:
> 
> import ctypes
> ctypes.windll.kernel32.GetCommandLineA.restype = ctypes.c_char_p
> print ctypes.windll.kernel32.GetCommandLineA()

Or you could use pywin32:


import win32api

print win32api.GetCommandLine ()



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


Re: Coming from Perl

2007-09-13 Thread Ben Finney
Amer Neely <[EMAIL PROTECTED]> writes:

> Well, I have checked everything I can but I'm getting '500 Internal
> Server Error'.

This is the HTTP response code saying that the program that should
have served the response document instead exited with an error.

To debug, you should first run the program (or at least the part that
you're trying to implement) *outside* the context of a web server. Do
it at a command line, and any errors will show up as exception
tracebacks.

Only when you have something that performs correctly outside a web
server context should you consider how to wrap it in that new
(harder-to-debug) context.

-- 
 \"What if the Hokey Pokey IS what it's all about?" —anonymous |
  `\   |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: I want py2exe not to create library.zip

2007-09-13 Thread Laszlo Nagy

>> I want py2exe not to create library.zip.
>> 
>
> setup (
>[...]
>options = {"py2exe": {"skip_archive":1}}
>   )   
>   
Cool! Just what I needed. Where it is documented? Ah, in the source. :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I want py2exe not to create library.zip

2007-09-13 Thread Laszlo Nagy

> That is correct.  People want less files to distribute not more.  People 
> complain on py2exe list that it doesn't create a single .EXE file.  Don't
> try to update the program via patching "pieces".  Wrap everything in a proper 
> installer (I use and highly recommend Inno Setup).  It can handle version 
> control, there is a plug-in for over-the-wire updates, etc.  Best way I know 
> of 
> to automate everything.
>   
It would be the best way for Windows. My program must work on different 
platforms: FreeBSD, Linux MS Windows and possibly Mac OS.

1. It would be too difficult to create an different auto updating method 
for MS Windows.
2. My auto update method updates only the changed .py files. Hopefully I 
will have many users. I do not want them to download a 10MB inno setup 
file after a small change in a py file.

The skip_archive option is the best. Thank you so much!

   Laszlo

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


Can You Program?

2007-09-13 Thread hatspin
We are offering $2000 USD for the best website developed with www.hatspin.com

Are you up to it??

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


Make money to share your videos

2007-09-13 Thread amit
Make money to share your videos
Goodtolove.com is sharing their 50% adsense revenue with you to post
videos of anything.
Just keep up logging in and start posting now to make money...

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


Re: Python+Expect+Win32 = Not Possible?

2007-09-13 Thread gamename
On Sep 13, 1:42 am, [EMAIL PROTECTED] wrote:
> On Sep 12, 9:27 pm, gamename <[EMAIL PROTECTED]> wrote:
>
> > Hi,
>
> > Is it still the case there is no practical Expect-like module for
> > win32? I know that cygwin can support pexpect, but that isn't an
> > option here --- I have to use a native win32 Python version.
>
> > Are there alternatives, or is it simply not an option to replicate
> > Expect on win32 with python?
>
> > All I'm trying to do is start a couple processes, wait for each to say
> > "done" on stdout and then quit (or timeout if something went wrong).
>
> > TIA,
> > -T
>
> I had planned on using telnet to do the same thing on windows.  I
> don't think I ever proved it, but I'm pretty sure it will work.

Thanks, Sean.  The problem is that telnet is generally disabled on
most hosts nowadays.

>
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52228
>
> ~Sean


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


Re: Setting stdout encoding

2007-09-13 Thread Fabio Zadrozny
>
> But I don't think it's a good idea. Changing the default encoding will
> change it for *all* scripts, *all* users, *all* objects. And AFAIK you
> have trouble ONLY with sys.std* - one should fix those objects, not mess
> with a global configuration.
>

Makes sense... Do you think that creating a new object, setting it as
sys.stdout and overriding its write() method to check for a unicode string
to do original_stdout.write(unicode_str.encode(my_encoding)) would do it?
(the ctypes version is not really an option as it is not available on lots
of installs -- although I can try to use it if it's available, but it can't
be the only solution).

Thanks,

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

wxstyledtextctrl and xml markup

2007-09-13 Thread OpenPavilion Team

Hello community,

I want to create an editor for a self defined xml markup language. I want to
use wxpython with wxstyledtextctrl and I have looked around at yellowbrain
site, but there are no examples. I also watched the styledtextctrl examples
with wxpython 2.8.4.

What I am looking for is an example of how to do the autocompletion part for
the styledtextctrl based on my self defined XML language.

example:

 
 
  
 
 [...]



Since I don't know styledtextctrl, I fear that I am about to write a complex
handler for the autocompletion part, whereas there could be some easy to use
features built into styledtextctrl. My problem is that I don't want to
externalize the grammar of the XML instead of coding it inside the
autocompletion handler.

Are there any examples for wxstyledtextctrl, xml and autocompletion ?

Regards
Pavilion
-- 
View this message in context: 
http://www.nabble.com/wxstyledtextctrl-and-xml-markup-tf4435096.html#a12652955
Sent from the Python - python-list mailing list archive at Nabble.com.

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


wx.ToplevelWindow.SetIcon: Native MS Windows error dialog pops up in wxPython app, no exception raised, no stack trace

2007-09-13 Thread Laszlo Nagy

  Hello,

I wrote a small program that works uses wxPython. The same application 
works on Linux and Windows. When I start it from MS Windows, I see this 
error message appearing each time I open a window:

---
Warehouseclient Error
---
Can't load image from file '': file does not exist.
---
OK  
---


The message box itself is a native MS Windows dialog. Otherwise the 
program works fine, just here is this annoying message. There is no 
exception raised in the Python program. Nothing printed on console. I 
figured out that this happens only when I set the icon of the window 
using this code:

self.SetIcon(icon)

However, the error dialog is not displayed right after the SetIcon call 
and no exception is raised. The dialog is displayed after __init__ has 
been called, and probably before EVT_SHOW gets called. Documentation of 
SetIcon 
(http://wxwidgets.org/manuals/stable/wx_wxtoplevelwindow.html#wxtoplevelwindowseticon)
 
says that it is safe to delete the icon after calling this function. Now 
here are the wreid things:

1. The icon is displayed correctly in the left top corner, so where is 
the error?
2. The error message complains about a file. What has 
wx.ToplevelFrame.SetIcon do with files?

I'm using: Windows XP Professional, Python 2.5, wxPython 2.8

Thanks,

   Laszlo

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


RE: Setting stdout encoding

2007-09-13 Thread Ryan Ginstrom
> On Behalf Of Fabio Zadrozny
> Makes sense... Do you think that creating a new object, 
> setting it as sys.stdout and overriding its write() method to 
> check for a unicode string to do 
> original_stdout.write(unicode_str.encode(my_encoding)) would 
> do it?

Here's an output stream encoder I have used. It might be kind of screwball,
so I'd welcome any feedback on it, but it does work for encoding output
streams.

import sys

class OutStreamEncoder(object):
"""Wraps an out stream with an encoder"""

def __init__(self, outstream, encoding=None):
self.stdout = outstream
if not encoding:
self.encoding = sys.getfilesystemencoding()
else:
self.encoding = encoding

def write(self, obj):
"""Wraps the output stream's write method, encoding it with
the specified encoding"""

self.stdout.write(obj.encode(self.encoding))

def __getattr__(self, attr):
"""Delegate everything but write to the stream"""

if attr != "write":
return getattr(self.stdout, attr)
return self.write


>>> from cStringIO import StringIO as si
>>> out = si()
>>> nihongo = unicode("日本語", "sjis")
>>> print >> out, nihongo

Traceback (most recent call last):
  File "", line 1, in 
print >> out, nihongo
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2:
ordinal not in range(128)
>>> out = OutStreamEncoder(out, "utf-8")
>>> print >> out, nihongo
>>> val = out.getvalue()
>>> print val.decode("utf-8")
日本語

>>> 

Regards,
Ryan Ginstrom

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

Re: read part of jpeg file by pure python

2007-09-13 Thread michal . zaborowski
On 13 Wrz, 10:48, Pacino <[EMAIL PROTECTED]> wrote:
> On 9 13 ,   4 43 , Laurent Pointal <[EMAIL PROTECTED]> wrote:
>
> > Pacino a écrit :
>
> > > Hi, everyone,
>
> > > I am wondering whether it's possible to read part (e.g. 1000*1000) of
> > > a huge jpeg file (e.g. 3*3) and save it to another jpeg file
> > > by pure python. I failed to read the whole file and split it, because
> > > it would cost 2GB memory.
>
> > > Can anyone help me? Any comments would be appreciated.
>
>
> > Just reading parts of the *file* is easy (see tell() seek() and read()
> > methods on files).
> > But to extract a part of the *picture*, you must uncompress the picture
> > in memory, grab the sub-picture, and save it back - generally with
> > compression. I can't see how you can bypass the uncompress/compress
> > phases and the corresponding memory use.
>
>
> The most difficult part is the uncompress part. I don't want the whole
> picture to be uncompressed in the memory, because it will consume a
> lot of memory (2GB, as I mentioned). My goal is to uncompress part of
> the picture into the memory.
>
> I just read some article on this subject (http://mail.python.org/
> pipermail/image-sig/1999-April/000713.html) , but haven't test it out
> yet.
>
  I have no idea what it does. Anyway - jpeg:
1. RGB -> HLV
2. divide data into 8x8 - blocks of data.
3. blocks are treated with discrete cosine transform.
4. Result is filtered to remove "fast changes".
5. Then result is compressed with Huffman alg.

So to get part of image - you can take smaller image before step 4.
As far as I understand code presented at:
http://mail.python.org/pipermail/image-sig/1999-April/000713.html
- full image will be loaded, and cutted.

--
Regards,
  Michał Zaborowski (TeXXaS)

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


Re: Python+Expect+Win32 = Not Possible?

2007-09-13 Thread Philem
On Sep 13, 12:27 am, gamename <[EMAIL PROTECTED]> wrote:
> Hi,
>
> Is it still the case there is no practical Expect-like module for
> win32? I know that cygwin can support pexpect, but that isn't an
> option here --- I have to use a native win32 Python version.
>
> Are there alternatives, or is it simply not an option to replicate
> Expect on win32 with python?
>
> All I'm trying to do is start a couple processes, wait for each to say
> "done" on stdout and then quit (or timeout if something went wrong).
>
> TIA,
> -T

You could try this link: 
http://www.activestate.com/Products/activetcl/features.plex
and see if that gives you what you need.

Luck!
-J

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


Re: struct is saving 4 bytes instead of 2

2007-09-13 Thread Bjoern Schliessmann
TonyB wrote:
> I tried
> 
> f.write(struct.pack('=h',thevariable))
> 
> and it works.

Great! :) 

Regards,


Björn

-- 
BOFH excuse #45:

virus attack, luser responsible

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


Re: newbie: self.member syntax seems /really/ annoying

2007-09-13 Thread [EMAIL PROTECTED]
Why not use '_' as the self variable.  It is minimal and achieves
close to '.var', as '_.var' isn't that different.  I know its a little
perl-esque, but its not a bad convention if you are aiming to up
readability of your code.

class test:
   def __init__(self):
  _ = self;
  _.a = 0;
  _.u = 0;
  _.a_dot = 0;
   def k(self, val):
  return val**2; #not sure what k does
   def getA_Dot(self):
  _ = self;
  _.a_dot = _.k(_.a-_.u);

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


Re: Python 3K or Python 2.9?

2007-09-13 Thread Bjoern Schliessmann
TheFlyingDutchman wrote:

> I am not talking about how the implementation of a C++ or Java
> compiler uses the this pointer/this reference internally. I am
> talking about how an author describes in English the "this"
> pointer/reference in their book on programming C++ or Java.

Ah, okay.
 
> I don't think you will find them saying that under the covers
> "this" was passed to the method (if in fact it is). They just say
> that it refers to the current object inside that object's method.

Mh, in my book, there is (quickly translated from german):

| Instance pointer (C++ only) 
| 
| The /this/ pointer is a feature of all non-static class methods.
| Every non static method is extended internally by a /this/
| argument. To that argument the compiler passes a pointer to the
| instance for which the method is being called.
(Dirk Louis, C/C++-Kompendium, Markt&Technik-Verlag, 2000)

And that's only from the pointer chapter. The OOP chapters are more
detailed. And no, it's no book about compiler architecture, it's a
compendium.

> Here is a link to a tutorial where Sun is talking about the this
> reference:
> http://java.sun.com/docs/books/tutorial/java/javaOO/thiskey.html

That's a tutorial for getting you started, no reference
documentation or in-depth course.

> I am referring to C++. If someone is trying to learn the language,
> knowledge of the internal implemenation is counter-productive in
> my opinion because it distracts from the details they need to
> learn. 

In a language like C++ it is beneficial to know some inner
workings -- in the same way like it's beneficial to know some inner
workings of a computer if you want to use it.

BTW, C is not for nothing called "portable assembler" :)

> If they are experienced and want to learn about the internals to
> potentially help them code in the most blazingingly fast manner
> they ideally would just be reminded they are using C++ and not
> some slower byte-code executed language where it could possibly
> matter. ;) 

I don't know if it's just me, but I tend to understand stuff like
virtual methods much better if I know *why* they exist, and not
just *that* they do. That makes judging if and when I need them
easier.

Regards,


Björn

-- 
BOFH excuse #192:

runaway cat on system.

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


Re: customizing a logging logger

2007-09-13 Thread Vinay Sajip
On 12 Sep, 19:17, [EMAIL PROTECTED] wrote:
> It seems like using something other than a literal string in the
> message is the way to go, since I assume that its __repr__() won't get
> called unless the logger is actually going to log a message for it.
> Is that right?
>
> Are any of the other methods likely to provide as-good or better
> performance?

You're almost right - it's __str__() rather than __repr__() that gets
called, when str() is called on the msg object passed in the logging
call. The str() call happens in LogRecord.getMessage(), which is
called (indirectly) from a handler's emit() when the message needs to
be formatted.

So - I don't think that the other methods will provide better
performance, as this approach is the simplest and most direct. I
haven't done any tests to confirm this, though :-(

Note that in order to avoid computation of *other* data passed to the
logging call - i.e. other arguments - you should still use the
logger.isXXXEnabled() idiom to avoid unnecessary computation, where
performance is an issue.

Best regards,


Vinay Sajip

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


lxml + mod_python: cannot unmarshal code objects in restricted execution mode

2007-09-13 Thread Dmitri Fedoruk
Hello everyone,

I'm developing a mod_python application that is based on XML\XSLT
transforming.

I used 4Suite libraries for that, but as the speed was unacceptable
for me, I switched to lxml. Everything became much easier and 10 times
faster, but I've encountered the subject problem.

In brief - all my data and xslt are stored and transferred in UTF-8.
With 4Suite everything was fine all the time. With lxml it works fine
from the console, but inside mod_python it occasionaly dies, ~ one
time out of three. Strange - the same code with the same data works or
dies by its own means.

As far as I have found, there was a similar problem with PyXML and
encodings module, but there was no clear solution.

So, my configuration is the following:
Python 2.5.1
Server version: Apache/2.2.4 (FreeBSD)
mod_python-3.3.1

And the relevant parts of my code are these:

def extApplyXslt(xslt, data, logger ):
try:
strXslt = urllib2.urlopen(xslt).read()
# i have to read the xslt url to the python string
except urllib2.HTTPError, e:
   ...
except urllib2.URLError, e:
   .
try:
xslt_parser = etree.XMLParser()
xslt_parser.resolvers.add( PrefixResolver("XSLT") )

# and now I have to use the string; a more elegant solution,
anyone?
f = StringIO(strXslt)
xslt_doc = etree.parse(f, xslt_parser)

# and here where the problem comes
transform = etree.XSLT(xslt_doc)

except Exception, exc:
logger.log(logging.CRITICAL, exc.__str__() )

try:
  result_tree = transform(data)
  return etree.tostring(result_tree, 'utf-8')
except Exception, exc:
  print "xslt processing error!", exc.__str__()
  return ""

It dies with the message 'cannot unmarshal code objects in restricted
execution mode'. By profiling I detected the point where problem
occurs:
 transform = etree.XSLT(xslt_doc)

So, I would be grateful for any suggestions how to get rid of this.
I'd really like to use lxml. Maybe I should initialize the xslt
processor in somehow other way?

Thanks in advance,
Dmitri

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


Re: wx.ToplevelWindow.SetIcon: Native MS Windows error dialog pops up in wxPython app, no exception raised, no stack trace

2007-09-13 Thread kyosohma
On Sep 13, 6:29 am, Laszlo Nagy <[EMAIL PROTECTED]> wrote:
>   Hello,
>
> I wrote a small program that works uses wxPython. The same application
> works on Linux and Windows. When I start it from MS Windows, I see this
> error message appearing each time I open a window:
>
> ---
> Warehouseclient Error
> ---
> Can't load image from file '': file does not exist.
> ---
> OK
> ---
>
> The message box itself is a native MS Windows dialog. Otherwise the
> program works fine, just here is this annoying message. There is no
> exception raised in the Python program. Nothing printed on console. I
> figured out that this happens only when I set the icon of the window
> using this code:
>
> self.SetIcon(icon)
>
> However, the error dialog is not displayed right after the SetIcon call
> and no exception is raised. The dialog is displayed after __init__ has
> been called, and probably before EVT_SHOW gets called. Documentation of
> SetIcon
> (http://wxwidgets.org/manuals/stable/wx_wxtoplevelwindow.html#wxtoplev...)
> says that it is safe to delete the icon after calling this function. Now
> here are the wreid things:
>
> 1. The icon is displayed correctly in the left top corner, so where is
> the error?
> 2. The error message complains about a file. What has
> wx.ToplevelFrame.SetIcon do with files?
>
> I'm using: Windows XP Professional, Python 2.5, wxPython 2.8
>
> Thanks,
>
>Laszlo

Normally I would recommend posting to the wxPython list, but it's down
at the moment. Keep an eye on their website as I'm sure they'll let
the community know when it's back up.

In the meantime, I'd look at how the demo does the icon displaying. It
looks like they created the icon they use using the img2py script
which basically creates a python file representation of the image.

See main.py of the Demo, line 1129. img2py is in the following default
location:
C:\Python24\Lib\site-packages\wx-2.8-msw-unicode\wxPython\tools

Without seeing how you create the image, it's hard to troubleshoot,
but I would guess that you have an absolute path that you're using in
your script that is different than what the exe is looking for.

Mike

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


Re: File Parsing Question

2007-09-13 Thread Shankarjee Krishnamoorthi
Great. That worked for me. I had some of my routines implemented in
Perl earlier. Now that I started using Python I am trying to do all my
automation scripts with Python. Thanks a ton

Jee

On 9/13/07, Peter Otten <[EMAIL PROTECTED]> wrote:
> Dennis Lee Bieber wrote:
>
> >  for line in inp:
> >
> > will read one line at a time (I'm fairly sure the iterator doesn't
> > attempt to buffer multiple lines behind the scenes)
>
> You are wrong:
>
> >>> open("tmp.txt", "w").writelines("%s\n" % (9*c) for c in "ABCDE")
> >>> instream = open("tmp.txt")
> >>> for line in instream:
> ... print instream.tell(), line.strip()
> ...
> 50 A
> 50 B
> 50 C
> 50 D
> 50 E
> >>>
>
> Here's the workaround:
>
> >>> instream = open("tmp.txt")
> >>> for line in iter(instream.readline, ""):
> ... print instream.tell(), line.strip()
> ...
> 10 A
> 20 B
> 30 C
> 40 D
> 50 E
> >>>
>
> Peter
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxstyledtextctrl and xml markup

2007-09-13 Thread kyosohma
On Sep 13, 6:23 am, OpenPavilion Team <[EMAIL PROTECTED]>
wrote:
> Hello community,
>
> I want to create an editor for a self defined xml markup language. I want to
> use wxpython with wxstyledtextctrl and I have looked around at yellowbrain
> site, but there are no examples. I also watched the styledtextctrl examples
> with wxpython 2.8.4.
>
> What I am looking for is an example of how to do the autocompletion part for
> the styledtextctrl based on my self defined XML language.
>
> example:
> 
>  
>  
>   
>  
>  [...]
> 
>
> Since I don't know styledtextctrl, I fear that I am about to write a complex
> handler for the autocompletion part, whereas there could be some easy to use
> features built into styledtextctrl. My problem is that I don't want to
> externalize the grammar of the XML instead of coding it inside the
> autocompletion handler.
>
> Are there any examples for wxstyledtextctrl, xml and autocompletion ?
>
> Regards
> Pavilion
> --
> View this message in 
> context:http://www.nabble.com/wxstyledtextctrl-and-xml-markup-tf4435096.html#...
> Sent from the Python - python-list mailing list archive at Nabble.com.

The demo for the StyledTextCtrl_2 mentions something about
autocomplete in the code. Not sure what it's talking about though. The
docs for it seem to link to Scintilla, so reading up on Scintilla's
usage would probably be valuable.

The wiki has one recipe on it for this control:
http://wiki.wxpython.org/Using_Python_Regular_Expressions_with_StyledTextCtrl

I highly recommend the wxPython mailing list. Right now it is down
(see their website), but when it's back up (check their website for
news), that's where I'd post this question if no one else here
answers.

Mike


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


Re: wxstyledtextctrl and xml markup

2007-09-13 Thread stef

> I highly recommend the wxPython mailing list. Right now it is down
> (see their website), 
its'up again.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Coming from Perl

2007-09-13 Thread Amer Neely
Ben Finney wrote:
> Amer Neely <[EMAIL PROTECTED]> writes:
> 
>> Well, I have checked everything I can but I'm getting '500 Internal
>> Server Error'.
> 
> This is the HTTP response code saying that the program that should
> have served the response document instead exited with an error.
> 
> To debug, you should first run the program (or at least the part that
> you're trying to implement) *outside* the context of a web server. Do
> it at a command line, and any errors will show up as exception
> tracebacks.
> 
> Only when you have something that performs correctly outside a web
> server context should you consider how to wrap it in that new
> (harder-to-debug) context.
> 

That is where I'm stuck. It runs fine on my home computer, but I don't 
have shell access to my hosted site.

Can you or anyone see anything in the posted code that might be the 
cause? Why is it so much harder to debug? There is no syntax error that 
I can tell. I've set the file permissions to rwxr-xr-x. I've printed the 
correct content type. It's a simple print statement, as per several 
examples I've seen.

Is it an Apache thing? I've not seen any mention in the documentation on 
that.

-- 
Amer Neely
w: www.webmechanic.softouch.on.ca/
Perl | MySQL programming for all data entry forms.
"Others make web sites. We make web sites work!"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxstyledtextctrl and xml markup

2007-09-13 Thread kyosohma
On Sep 13, 8:27 am, stef <[EMAIL PROTECTED]> wrote:
> > I highly recommend the wxPython mailing list. Right now it is down
> > (see their website),
>
> its'up again.

That's not what the website says, but I'll take your word for it.

Mike

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


Re: wxstyledtextctrl and xml markup

2007-09-13 Thread limodou
> I highly recommend the wxPython mailing list. Right now it is down
> (see their website), but when it's back up (check their website for
> news), that's where I'd post this question if no one else here
> answers.
>
wxPython mail list already comes back!

-- 
I like python!
UliPad <>: http://code.google.com/p/ulipad/
My Blog: http://www.donews.net/limodou
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python+Expect+Win32 = Not Possible?

2007-09-13 Thread Tim Golden
gamename wrote:
> On Sep 13, 1:42 am, [EMAIL PROTECTED] wrote:
>> On Sep 12, 9:27 pm, gamename <[EMAIL PROTECTED]> wrote:
>>
>>> Hi,
>>> Is it still the case there is no practical Expect-like module for
>>> win32? I know that cygwin can support pexpect, but that isn't an
>>> option here --- I have to use a native win32 Python version.
>>> Are there alternatives, or is it simply not an option to replicate
>>> Expect on win32 with python?
>>> All I'm trying to do is start a couple processes, wait for each to say
>>> "done" on stdout and then quit (or timeout if something went wrong).
>>> TIA,
>>> -T
>> I had planned on using telnet to do the same thing on windows.  I
>> don't think I ever proved it, but I'm pretty sure it will work.
> 
> Thanks, Sean.  The problem is that telnet is generally disabled on
> most hosts nowadays.

I'm not sure whether the need you describe above "start a
couple [of] processes, wait for each to say 'done' and
then quit (or timeout...)" is *all* of your requirements
or just an example. And are these processes running on
remote machines? Or just locally?

Depending on those things, maybe there are other ways
to do what you want under Windows?

(I've checked back through the archives and I can't find
any earlier posts describing the requirement more clearly).

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


Re: wx.ToplevelWindow.SetIcon: Native MS Windows error dialog pops up in wxPython app, no exception raised, no stack trace

2007-09-13 Thread Laszlo Nagy

> See main.py of the Demo, line 1129. img2py is in the following default
> location:
> C:\Python24\Lib\site-packages\wx-2.8-msw-unicode\wxPython\tools
>   

> Without seeing how you create the image, it's hard to troubleshoot,
> but I would guess that you have an absolute path that you're using in
> your script that is different than what the exe is looking for.
>   
I actually do have a wx.Icon instance loaded from a file. This problem 
is not about loading a file into a wx.Icon instance. This why I'm 
suprised about the message ("cannot load image file"). I already have 
both the icon and the top level window in memory. If I comment out the

self.SetIcon(icon)

line in my code then there is no error message (and no icon on the 
frame). The SetIcon method will call the Windows API at the end, and it 
has nothing to do with files. It accepts a window handle and a pointer 
to an icon resource. I cannot think about anything that would need to 
read from a file while setting the icon of the frame.  Moreover, the 
icon is showing on the frame, looks like there is no error, so why am I 
getting a message? It is not a python Exception, it pops out from 
nowhere. :-) I suspect it will be an internal error in wxWidgets or 
wxPython. But their mailing list is not working. :-(

Thanks anyway.

   Laszlo

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


Re: Coming from Perl

2007-09-13 Thread Richie Hindle

[Amer]
> Can you or anyone see anything in the posted code that might be the 
> cause?

> #!/usr/bin/python
> import cgitb; cgitb.enable(display=0, logdir=".")
> import sys
> sys.stderr = sys.stdout
> print "Content-Type: text/html"
> print

My guess would be that you don't have cgitb in your server environment, or
that you have a bogus one.  Rearrange things like this:

#!/usr/bin/python
print "Content-Type: text/html"
print
import sys
sys.stderr = sys.stdout
import cgitb; cgitb.enable(display=0, logdir=".")

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Parallel/Multiprocessing script design question

2007-09-13 Thread Ivan Voras

Amit N wrote:

About 800+ 10-15MB files are generated daily that need to be processed. The 
processing consists of different steps that the files must go through:


-Uncompress
-FilterA
-FilterB
-Parse
-Possibly compress parsed files for archival


You can implement one of two easy straightforward approaches:

1 - Create one program, start N instances of it, where N is the number 
of CPUs/cores, and let each process one file to completion. You'll 
probably need an "overseer" program to start them and dispatch jobs to 
them. The easiest is to start your processes with first N files, then 
monitor them for completion and when any of them finishes, start another 
with the next file in queue, etc.


2 - Create a program / process for each of these steps and let the steps 
operate independently, but feed output from one step to the input of the 
next. You'll probably need some buffering and more control, so that if 
(for example) "FilterA" is slower then "Uncompress", the "Uncompress" 
process is signaled to wait a little until "FilterA" needs more data. 
The key is that, as long as all the steps run at approximatly the same 
speed, they can run in parallel.


Note that both approaches are in principle independent on whether you 
use threads or processes, with the exception of communication between 
the steps/stages, but you can't use threads in python if your goal is 
parallel execution of threads.





signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: newbie: self.member syntax seems /really/ annoying

2007-09-13 Thread Steven D'Aprano
On Thu, 13 Sep 2007 12:10:03 +, [EMAIL PROTECTED] wrote:

> Why not use '_' as the self variable.  It is minimal and achieves close
> to '.var', as '_.var' isn't that different.  I know its a little
> perl-esque, but its not a bad convention if you are aiming to up
> readability of your code.

I think the definitions of "up" or "readability" you are using are very 
different from mine. To me, to up something means to increase it, and 
readability means the ease of comprehension when reading something. You 
seem to be using the opposite definition for one or the other.


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


recursion

2007-09-13 Thread Gigs_
Can someone explain me this

 >>> def f(l):
if l == []:
return []
else:
return f(l[1:]) + l[:1]  # <= cant figure this, how is all sum 
at the end?



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


Re: wx.ToplevelWindow.SetIcon: Native MS Windows error dialog pops up in wxPython app, no exception raised, no stack trace

2007-09-13 Thread kyosohma
On Sep 13, 8:41 am, Laszlo Nagy <[EMAIL PROTECTED]> wrote:
> > See main.py of the Demo, line 1129. img2py is in the following default
> > location:
> > C:\Python24\Lib\site-packages\wx-2.8-msw-unicode\wxPython\tools
>
> > Without seeing how you create the image, it's hard to troubleshoot,
> > but I would guess that you have an absolute path that you're using in
> > your script that is different than what the exe is looking for.
>
> I actually do have a wx.Icon instance loaded from a file. This problem
> is not about loading a file into a wx.Icon instance. This why I'm
> suprised about the message ("cannot load image file"). I already have
> both the icon and the top level window in memory. If I comment out the
>
> self.SetIcon(icon)
>
> line in my code then there is no error message (and no icon on the
> frame). The SetIcon method will call the Windows API at the end, and it
> has nothing to do with files. It accepts a window handle and a pointer
> to an icon resource. I cannot think about anything that would need to
> read from a file while setting the icon of the frame.  Moreover, the
> icon is showing on the frame, looks like there is no error, so why am I
> getting a message? It is not a python Exception, it pops out from
> nowhere. :-) I suspect it will be an internal error in wxWidgets or
> wxPython. But their mailing list is not working. :-(
>
> Thanks anyway.
>
>Laszlo

I'm told the mailing list is now up. Sorry I wasn't more helpful.

Mike

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


Re: recursion

2007-09-13 Thread Tom Wright
Gigs_ wrote:
> Can someone explain me this
> def f(l):
>   if l == []:
> return []
>   else:
> return f(l[1:]) + l[:1]  # <= cant figure this, how is 
>   all sum at the end? 

If you think about building up from the simplest case:
f([]) = []
f(['a']) = f([]) + ['a'] = [] + ['a'] = ['a']

Now f(['a', 'b']) is going to be:
f(['b']) + ['a']
= ['b'] + ['a']
= ['b', 'a']

Similarly, for f(['a', 'b', 'c']), that will be:
f(['b', 'c']) + ['a']

Of course, if you want to do this you can always use list.reverse() but I
guess you're trying to get a handle on recursion rather than just reverse a
list.  I find thinking up from the base case helps when trying to
understand recursive code but when writing it, I tend to work the other way
around.


-- 
I'm at CAMbridge, not SPAMbridge
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: newbie: self.member syntax seems /really/ annoying

2007-09-13 Thread Wildemar Wildenburger
Steven D'Aprano wrote:
> On Thu, 13 Sep 2007 12:10:03 +, [EMAIL PROTECTED] wrote:
> 
>> Why not use '_' as the self variable.  It is minimal and achieves close
>> to '.var', as '_.var' isn't that different.  I know its a little
>> perl-esque, but its not a bad convention if you are aiming to up
>> readability of your code.
> 
> I think the definitions of "up" or "readability" you are using are very 
> different from mine. To me, to up something means to increase it, and 
> readability means the ease of comprehension when reading something. You 
> seem to be using the opposite definition for one or the other.
> 
> 
OK, making a pointless reply to pointless reply, but anyway:

I see merit in using

   (_.foo + _.bar) * _.baz

instead of

   (s.foo + s.bar) * s.baz

because I'm trained to interpret the underscore as a synonym for one 
space. It's not particularly beautiful, but that is probably a matter of 
habituation. And that exact word is probably the reason why I'd still 
use self or s (explained by a comment, because I can get very dumb if I 
have to).

It's a matter of taste, so there is no point in bashing a valid suggestion.

/W (I am aware that I'm banging a philosophy on people's heads just as 
Steven did, so I'm no better, I know.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Help to start python

2007-09-13 Thread python_lover
Hi All,

I'm new  to python. I installed python 2.5  and IDLE 1.2.1 . I'm able
to run shell commands.

But I don't know how to execute a python program using this. When I'm
opeing a py program a seperate IDLE window opeing with program text.
But I don't know to to execute the prg.

Please help me on this .

thank you

regards
Sat

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


Re: Help to start python

2007-09-13 Thread kyosohma

python_lover wrote:
> Hi All,
>
> I'm new  to python. I installed python 2.5  and IDLE 1.2.1 . I'm able
> to run shell commands.
>
> But I don't know how to execute a python program using this. When I'm
> opeing a py program a seperate IDLE window opeing with program text.
> But I don't know to to execute the prg.
>
> Please help me on this .
>
> thank you
>
> regards
> Sat

When in IDLE, you can go to the Run menu and choose Run Module (or
press F5) in the window that has the program code.

Hope that helps!

Mike

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


Re: newbie: self.member syntax seems /really/ annoying

2007-09-13 Thread BJörn Lindqvist
On 9/12/07, Dave Hansen <[EMAIL PROTECTED]> wrote:
> The name "self" is just a convention.  You can give it any name you
> wish.  Using "s" is common.

Not it's not common. And the name "self" is a convention codified in
PEP8 which you shouldn't violate.

And I agree with the OP that the convention is really annoying.

  self.rect.width = self.foo(self.rect.x + self.rect.y) * self.boo()

is much less concise than

  s.rect.width = s.foo(s.rect.x + s.rect.y) * s.boo()

-- 
mvh Björn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Possible suggestion for removing the GIL

2007-09-13 Thread Prateek
On Sep 13, 1:36 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> Prateek wrote:
> > Hi,
>
> > Recently there was some talk on removing the GIL and even the BDFL has
> > written a blog post on it.
> > I was trying to come up with a scalable and backwards compatible
> > approach for how to do it.
>
> > I've put my thoughts up in a blog post - and I'd really like to hear
> > what the community thinks of it.
> > Mainly it revolves around dedicating one core for executing
> > synchronized code and doing context switches instead of acquiring/
> > releasing locks.
>
> Where is the gain? Having just one core doesn't give you true parallelism -
> which is the main reason behind the cries for a GIL-less Python.
>
> Diez

Diez,

I was talking of dedicating one core for synchronized code. In the
case of a threaded app on two cores, one core would be dedicated to
synchronized code and the other would run non-sync code (effectively
behaving like a single threaded machine). However, on machines with n
cores where n > 2 cores, we would have n-1 cores available to run code
in parallel.

Prateek

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


Re: Help to start python

2007-09-13 Thread python_lover
On Sep 13, 7:23 pm, [EMAIL PROTECTED] wrote:
> python_lover wrote:
> > Hi All,
>
> > I'm new  to python. I installed python 2.5  and IDLE 1.2.1 . I'm able
> > to run shell commands.
>
> > But I don't know how to execute a python program using this. When I'm
> > opeing a py program a seperate IDLE window opeing with program text.
> > But I don't know to to execute the prg.
>
> > Please help me on this .
>
> > thank you
>
> > regards
> > Sat
>
> When in IDLE, you can go to the Run menu and choose Run Module (or
> press F5) in the window that has the program code.
>
> Hope that helps!
>
> Mike- Hide quoted text -
>
> - Show quoted text -

Thankx mike.

It is working well.

Please guide me some good sites to start web based programing on
python.

thank you.

sat

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


Re: newbie: self.member syntax seems /really/ annoying

2007-09-13 Thread Eduardo O. Padoan
On 9/13/07, Wildemar Wildenburger <[EMAIL PROTECTED]> wrote:
> because I'm trained to interpret the underscore as a synonym for one
> space. It's not particularly beautiful, but that is probably a matter of
> habituation. And that exact word is probably the reason why I'd still
> use self or s (explained by a comment, because I can get very dumb if I
> have to).

Have you worked with code using gettext functions imported as "_"?
When I see a single underscore as a name, i18n comes to mind.


-- 
http://www.advogato.org/person/eopadoan/
Bookmarks: http://del.icio.us/edcrypt
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Coming from Perl

2007-09-13 Thread Amer Neely
Richie Hindle wrote:
> [Amer]
>> Can you or anyone see anything in the posted code that might be the 
>> cause?
> 
>> #!/usr/bin/python
>> import cgitb; cgitb.enable(display=0, logdir=".")
>> import sys
>> sys.stderr = sys.stdout
>> print "Content-Type: text/html"
>> print
> 
> My guess would be that you don't have cgitb in your server environment, or
> that you have a bogus one.  Rearrange things like this:
> 
> #!/usr/bin/python
> print "Content-Type: text/html"
> print
> import sys
> sys.stderr = sys.stdout
> import cgitb; cgitb.enable(display=0, logdir=".")
> 

Nope. Same error. Is cgitb not in the standard distribution? Is it 
needed to print HTML?

On my home PC I changed the Apache error logging to 'debug' and got this 
nugget:
[Thu Sep 13 04:16:03 2007] [error] [client 0.0.0.0] (OS 2)The system 
cannot find the file specified.  : couldn't create child process: 
720002: hello.py

I suspect it would be similar on my hosting server. Is this saying it 
can't find hello.py or one of the modules?

-- 
Amer Neely
w: www.webmechanic.softouch.on.ca/
Perl | MySQL programming for all data entry forms.
"Others make web sites. We make web sites work!"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Possible suggestion for removing the GIL

2007-09-13 Thread Chris Mellon
On 9/13/07, Prateek <[EMAIL PROTECTED]> wrote:
> On Sep 13, 1:36 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> > Prateek wrote:
> > > Hi,
> >
> > > Recently there was some talk on removing the GIL and even the BDFL has
> > > written a blog post on it.
> > > I was trying to come up with a scalable and backwards compatible
> > > approach for how to do it.
> >
> > > I've put my thoughts up in a blog post - and I'd really like to hear
> > > what the community thinks of it.
> > > Mainly it revolves around dedicating one core for executing
> > > synchronized code and doing context switches instead of acquiring/
> > > releasing locks.
> >
> > Where is the gain? Having just one core doesn't give you true parallelism -
> > which is the main reason behind the cries for a GIL-less Python.
> >
> > Diez
>
> Diez,
>
> I was talking of dedicating one core for synchronized code. In the
> case of a threaded app on two cores, one core would be dedicated to
> synchronized code and the other would run non-sync code (effectively
> behaving like a single threaded machine). However, on machines with n
> cores where n > 2 cores, we would have n-1 cores available to run code
> in parallel.
>

What you're describing would have the same characteristics as the
current code - code that is able to execute without the GIL held
already will run in parallel on a multi-core machine.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Coming from Perl

2007-09-13 Thread Richie Hindle

> [Amer]
> #!/usr/bin/python
> [...] On my home PC [...]
> [Thu Sep 13 04:16:03 2007] [error] [client 0.0.0.0] (OS 2)The system 
> cannot find the file specified.

That's because on your home PC Python is somewhere like
C:\Python25\python.exe, not /usr/bin/python.

Are you sure /usr/bin/python is correct for your hosting environment?

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


My first Python CGI (was: Coming from Perl)

2007-09-13 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Amer Neely  <[EMAIL PROTECTED]> wrote:
>Amer Neely wrote:
>> TheFlyingDutchman wrote:
>>> On Sep 12, 5:30 pm, Amer Neely <[EMAIL PROTECTED]> wrote:
 I'm a complete newbie with Python, but have several years experience
 with Perl in a web environment.

 A question I have, if someone here is familiar with Perl, does Python
 have something like Perl's 'here document'? I've just searched and read
 some postings on generating HTML but they all seem to refer to various
 template utilities. Is this the only way, or am I missing something? I'm
 used to generating X/HTML by hand, which makes the here document in Perl
 ideal for me. Also, many times a client already existing HTML code that
 I can use in a script.

 -- 
 Amer Neely
 w:www.webmechanic.softouch.on.ca/
 Perl | MySQL programming for all data entry forms.
 "Others make web sites. We make web sites work!"
>>>
>>> I am not sure if this is what you are looking for, but Python has a
>>> special string with 3 quotes that I believe duplicates part of the
>>> functionality of a here document:
>>>
>>> myHmtlHeader = """
>>> 
>>> My Page
>>> 
>>> """
>>>
>>> print myHtmlHeader
>>>
>>>
>>> outputs:
>>>
>>>
>>> 
>>> My Page
>>> 
>>>
>> 
>> Well, I have checked everything I can but I'm getting '500 Internal 
>> Server Error'. The log files aren't helpful:
>> [Thu Sep 13 03:43:00 2007] [error] [client 24.235.184.39] Premature end 
>> of script headers: /home/softouch/public_html/cgi-bin/scratch/hello.py
>> 
>> I can't even get it to run on my home PC running Apache + Win2K. Same 
>> error.
>> 
>> My script:
>> #!/usr/bin/python
>> import cgitb; cgitb.enable(display=0, logdir=".")
>> import sys
>> sys.stderr = sys.stdout
>> print "Content-Type: text/html"
>> print
>> 
>> print """
>> 
>> 
>> Hello 
>> from Python
>> 
>> Goodbye.
>> 
>> 
>> """
>> 
>
>I should have added that it runs from the command line OK.
.
.
.
Yes, it should work fine.  Do the things you'd do if it were Perl source:
when you say "it runs from the command line OK", do you mean invocation of
/home/softouch/public_html/cgi-bin/scratch/hello.py gives sensible results?
Does your Web server recognize that .py is a CGI extension?  What are the
permissions on /home/softouch/public_html/cgi-bin/scratch/hello.py?

Might your server have an issue with "Content-Type" vs. "Content-type"?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: newbie: self.member syntax seems /really/ annoying

2007-09-13 Thread [EMAIL PROTECTED]
On Sep 12, 10:05 am, [EMAIL PROTECTED] (Alex Martelli) wrote:

...

> into a function and a call to it:
>
> def f():
> with implicit_self(t):
> print a
> print b
> a = 40
> b = a * 2
> f()
>
> ...even with different values for the argument to _getframe.  You just
> can't "dynamically" add local variables to a function, beyond the set
> the compiler has determined are local (and those are exactly the ones
> that are *assigned to* in the function's body -- no less, no more --
> where "assigned to" includes name-binding statements such as 'def' and
> 'class' in addition to plain assignment statements, of course).
>
> Making, say, 'a' hiddenly mean 'x.a', within a function, requires a
> decorator that suitably rewrites the function's bytecode... (after
> which, it WOULD still be terrible and horrible and not to be used, just
> as you say, but it might at least _work_;-).  Main problem is, the
> decorator needs to know the set of names to be "faked out" in this
> terrible and horrible way at the time the 'def' statement executes: it
> can't wait until runtime (to dynamically determine what's in var(self))
> before it rewrites the bytecode (well, I guess you _could_ arrange a
> complicated system to do that, but it _would_ be ridiculously slow).
>
> You could try defeating the fundamental optimization that stands in your
> way by adding, say,
> exec 'pass'
> inside the function-needing-fakeouts -- but we're getting deeper and
> deeper into the mire...;-)



What about abusing 'import' like this:

def f():
with implicit_self(t):
sys.modules['__the_mire__'] = t
from __the_mire__ import a, b
print a
print b
a = 40
b = a * 2


If the list of attributes is long then
'import' can save some typing compared to

a = self.a
b = self.b
...
z = self.z


--
Regards,
Steven

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


Re: Python 3K or Python 2.9?

2007-09-13 Thread Alex Martelli
TheFlyingDutchman <[EMAIL PROTECTED]> wrote:

> > >>> Foo.bar(foo, "spam")
> > >>> foo.bar("spam")
> 
> That looks like a case of "There's more than one way to do it". ;)
> The first form is definitely consistent with the
> method declaration, so there's a lot to be said for using that style
> when teaching people to make classes -> send self, receive self.

On the other hand, the second form is not polymorphic: it doesn't allow
for foo to be an instance of some OTHER class (possibly subclassing Foo
and overriding bar) -- it will call the Foo version of bar anyway.

type(foo).bar(foo, "spam") *IS* almost semantically equivalent to the
obviousy simpler foo.bar("spam") -- but doesn't cover the possibility
for foo to do a *per-instance* override of 'bar'.

getattr(foo, 'bar', functools.partial(type(foo).bar, foo))("spam") is
getting closer to full semantic equivalence.  And if you think that's
"another OBVIOUS way of doing it" wrt foo.bar("spam"), I think your
definition of "obvious" may need a reset (not to mention the fact that
the "equivalent" version is way slower;-).

Foo.bar(foo, "spam")'s different semantics are important when any
implementation of type(foo).bar (or other method yet) wants to BYPASS
polymorphism to redirect part of the functionality to a specific type's
implementation of bar ('super' may help in some cases, but it keeps some
polymorphic aspects and pretty often you just want to cut all
polymorphism off and just redirect to ONE specific implementation).


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


Re: newbie: self.member syntax seems /really/ annoying

2007-09-13 Thread Steven D'Aprano
On Thu, 13 Sep 2007 16:30:36 +0200, BJörn Lindqvist
wrote:


> And I agree with the OP that the convention is really annoying.
> 
>   self.rect.width = self.foo(self.rect.x + self.rect.y) * self.boo()
> 
> is much less concise than
> 
>   s.rect.width = s.foo(s.rect.x + s.rect.y) * s.boo()


Y do u thnk bng cncis is lwys a gd thng?

Being concise is not always a good thing. I notice that you separate 
terms with spaces, even when Python itself doesn't need them. You also 
are happy to use infix notation, which requires brackets, instead of a 
postfix or RPN language that doesn't. You also have attributes named 
"rect" and "width" instead of "r" and "w":

s.r.w=s.f(s.r.x+s.r.y)*s.b()

There. See how much more readable that isn't?


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

Re: I want py2exe not to create library.zip

2007-09-13 Thread Grant Edwards
On 2007-09-13, Laszlo Nagy <[EMAIL PROTECTED]> wrote:
>
>>> I want py2exe not to create library.zip.
>>> 
>>
>> setup (
>>[...]
>>options = {"py2exe": {"skip_archive":1}}
>>   )   
>
> Cool! Just what I needed. Where it is documented? Ah, in the source. :-)

That's pretty much it. :)

I found on WorkingWithVariousPackagesAndModules Wiki page a
reference to a command-line option --skip-archive.  Then
googling for "py2exe skip archive" found an example similar to
the above.  I haven't ever found any documentation for the
py2exe options.  The documentation for the some of general
setup options tends to be a bit vague as well.

I've added a few things to the py2exe Wiki pages, but somebody
needs to start a page that just describes each of the py2exe
options and what problem they're intended to solve...

-- 
Grant Edwards   grante Yow! Let's all show human
  at   CONCERN for REVERAND MOON's
   visi.comlegal difficulties!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lxml + mod_python: cannot unmarshal code objects in restricted execution mode

2007-09-13 Thread Stefan Behnel
Dmitri Fedoruk wrote:
> def extApplyXslt(xslt, data, logger ):
> try:
> strXslt = urllib2.urlopen(xslt).read()
> # i have to read the xslt url to the python string
> except urllib2.HTTPError, e:
>...
> except urllib2.URLError, e:
>.
> try:
> xslt_parser = etree.XMLParser()
> xslt_parser.resolvers.add( PrefixResolver("XSLT") )
> 
> # and now I have to use the string; a more elegant solution,
> anyone?

Sure, lxml.etree can parse from file-like objects. Just hand in the result of
urlopen().

Apart from that, I saw that you found your way to the lxml mailing list, I'll
respond over there.

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


Re: Coming from Perl

2007-09-13 Thread Amer Neely
Richie Hindle wrote:
>> [Amer]
>> #!/usr/bin/python
>> [...] On my home PC [...]
>> [Thu Sep 13 04:16:03 2007] [error] [client 0.0.0.0] (OS 2)The system 
>> cannot find the file specified.
> 
> That's because on your home PC Python is somewhere like
> C:\Python25\python.exe, not /usr/bin/python.
> 
> Are you sure /usr/bin/python is correct for your hosting environment?
> 

It's my understanding that the Windows shell doesn't pay much attention 
to the shebang line if the file type is associated with the proper 
application.

But I tried your suggestion and got the same results.

-- 
Amer Neely
w: www.webmechanic.softouch.on.ca/
Perl | MySQL programming for all data entry forms.
"Others make web sites. We make web sites work!"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Generating HTML

2007-09-13 Thread Nikita the Spider
In article <[EMAIL PROTECTED]>,
 "Sebastian Bassi" <[EMAIL PROTECTED]> wrote:

> Hello,
> 
> What are people using these days to generate HTML? I still use
> HTMLgen, but I want to know if there are new options. I don't
> want/need a web-framework a la Zope, just want to produce valid HTML
> from Python.
> Best,
> SB.

Spyce. Works fine server side (like PHP) and also run from the command line.

http://spyce.sourceforge.net/

-- 
Philip
http://NikitaTheSpider.com/
Whole-site HTML validation, link checking and more
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Coming from Perl

2007-09-13 Thread Amer Neely
Amer Neely wrote:
> Richie Hindle wrote:
>>> [Amer]
>>> #!/usr/bin/python
>>> [...] On my home PC [...]
>>> [Thu Sep 13 04:16:03 2007] [error] [client 0.0.0.0] (OS 2)The system 
>>> cannot find the file specified.
>>
>> That's because on your home PC Python is somewhere like
>> C:\Python25\python.exe, not /usr/bin/python.
>>
>> Are you sure /usr/bin/python is correct for your hosting environment?
>>
> 
> It's my understanding that the Windows shell doesn't pay much attention 
> to the shebang line if the file type is associated with the proper 
> application.
> 
> But I tried your suggestion and got the same results.
> 

My BAD! I changed the shebang all right, but entered a typo. With the 
correct path it did work just fine.

So, perhaps the path to python on my host is wrong? I got that one right 
from the techs.

-- 
Amer Neely
w: www.webmechanic.softouch.on.ca/
Perl | MySQL programming for all data entry forms.
"Others make web sites. We make web sites work!"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Coming from Perl

2007-09-13 Thread Tim Golden
Amer Neely wrote:
> Richie Hindle wrote:
>>> [Amer]
>>> #!/usr/bin/python
>>> [...] On my home PC [...]
>>> [Thu Sep 13 04:16:03 2007] [error] [client 0.0.0.0] (OS 2)The system 
>>> cannot find the file specified.
>> That's because on your home PC Python is somewhere like
>> C:\Python25\python.exe, not /usr/bin/python.
>>
>> Are you sure /usr/bin/python is correct for your hosting environment?
>>
> 
> It's my understanding that the Windows shell doesn't pay much attention 
> to the shebang line if the file type is associated with the proper 
> application.
> 
> But I tried your suggestion and got the same results.

The Windows shell doesn't, but Apache does. (Haven't followed
this thread closely, but I seem to remember it has to do with
running CGI scripts).

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


Re: recursion

2007-09-13 Thread Neil Cerutti
On 2007-09-13, Gigs_ <[EMAIL PROTECTED]> wrote:
> Can someone explain me this
>
> >>> def f(l):
>   if l == []:
>   return []
>   else:
>   return f(l[1:]) + l[:1]  # <= cant figure this, how is all sum 
> at the end?

In plain English, the above program says:

The sum of the items in list l is zero if the list is empty.
Otherwise, the sum is the value of the first item plus the sum of
the rest of the items in the list.

Well, it would say that if it weren't somewhat buggy. l[:1]
doesn't evaluate to a number, but to a list containing one
number, so the above program doesn't do what you say it does.

It should read something like:

 def my_sum(seq):
   if len(seq) == 0:
 return 0
   else:
 return seq[0] + my_sum(seq[1:])

The tough part of recursion is the leap of faith required to
believe that it works. However, you can often use an inductive
proof of correctness to help obviate the faith.

Proof that my_sum(seq) computes the sum of the items in seq (this
proof is modeled on proofs written by Max Hailperin, Barbara
Kaiser, and Karl Knight, in _Concrete Abstractions_):

  Base case: my_sum(seq) terminates with value 0 when len(seq) is
  zero, because of the evaluation rules for if, len and ==.

  Induction hypothesis: Assume that my_sum(subseq) evaluates to
  the sum of all the items in subsequence of seq, where 0 <=
  len(subseq) < len(seq).

  Inductive step: Consider evaluating my_sum(seq) where the
  length of seq is greater than 0. This will terminate if
  my_sum(seq[1:]) terminates, and will have the value of seq[0] +
  my_sum(seq[1:]). Because seq[1:] evaluates to the subsequence of
  the rest of the items in seq (all except the first), and 0 <=
  len(subseq) < len(seq), we can assume by our induction
  hypothesis that my_sum(seq[1:]) does terminate, with a value
  equal to the sum of the the rest of the items in seq.
  Therefore, seq[0] + my_sum(seq[1:]) evaluates to seq[0] + the
  sum of all the items in seq[1:]. Because seq[0] + the sum of
  the rest of the items in seq equals the sum of all the items in
  seq, we see that my_sum(seq) does terminate with the correct
  value for any arbitrary length of seq, under the inductive
  hypothesis of correct operation for subsequences of seq.

  Conclusion: Therefore, by mathematical induction on the length
  of seq, my_sum(seq) terminates with the value of the sum of all
  the items in seq for any length of seq.

But really I prefer the first first plain English version. ;)

-- 
Neil Cerutti
For those of you who have children and don't know it, we have a nursery
downstairs. --Church Bulletin Blooper
-- 
http://mail.python.org/mailman/listinfo/python-list


Extended slicing and Ellipsis - where are they used?

2007-09-13 Thread Rodney Maxwell
The following are apparently legal Python syntactically:
   L[1:3, 8:10]
   L[1, ..., 5:-2]

But they don't seem to work on lists:
>>> l = [0,1,2,3]
>>> l[0:2,3]
Traceback (most recent call last):
  File "", line 1, in 
TypeError: list indices must be integers
>>> l[...]
Traceback (most recent call last):
  File "", line 1, in 
TypeError: list indices must be integers

So where is this extended slicing used?

--
Rodney

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


Re: newbie: self.member syntax seems /really/ annoying

2007-09-13 Thread Charles Fox
hmm, I guess this is the difference between numerical programming and
the rest -- sure, if I was writing a database server or something it
would be great to have thisObject.veryLongName to know what everything
is -- however when you are implementing a model from a published
paper, the variables tend to be single greek or roman letter names,
possibly with subscripts and superscripts, and it helps if the name
you see on the screen is the same as the name on the paper, as is the
case in matlab.  You want the equation on screen to look as similar to
the one on the paper as possible, especially if its going to be read
by another programmer who is familiar with the paper.

Maybe for now I will just fix up my emacs to display the world 'self'
in 10% gray...   :-)


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


Re: Coming from Perl

2007-09-13 Thread Amer Neely
Tim Golden wrote:
> Amer Neely wrote:
>> Richie Hindle wrote:
 [Amer]
 #!/usr/bin/python
 [...] On my home PC [...]
 [Thu Sep 13 04:16:03 2007] [error] [client 0.0.0.0] (OS 2)The system 
 cannot find the file specified.
>>> That's because on your home PC Python is somewhere like
>>> C:\Python25\python.exe, not /usr/bin/python.
>>>
>>> Are you sure /usr/bin/python is correct for your hosting environment?
>>>
>>
>> It's my understanding that the Windows shell doesn't pay much 
>> attention to the shebang line if the file type is associated with the 
>> proper application.
>>
>> But I tried your suggestion and got the same results.
> 

See my reply to this post - I had a typo in the shebang line and it now 
works on my home PC.

> The Windows shell doesn't, but Apache does. (Haven't followed
> this thread closely, but I seem to remember it has to do with
> running CGI scripts).

This seems to indicate that maybe my host needs to configure Apache to 
run python scripts? But I didn't need to do anything with mine.

-- 
Amer Neely
w: www.webmechanic.softouch.on.ca/
Perl | MySQL programming for all data entry forms.
"Others make web sites. We make web sites work!"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Error in random module, bad installation?

2007-09-13 Thread Andrew F
On Sep 13, 12:57 am, Tim Roberts <[EMAIL PROTECTED]> wrote:
> Andrew F <[EMAIL PROTECTED]> wrote:
> >I'm a linux user and I just upgraded from 2.1 to 2.5 and changed the
> >location of a number of libraries and tools.
>
> >So far I've tracked most errors, but this one has me scratching my
> >head :
>
> >$ which python
> >/usr/local/bin/python
> >$ echo $PYTHONPATH
> >/usr/local/bin/python
>
> PYTHONPATH is supposed to point to the directory containing modules, NOT
> the directory containing the executable.  It should be /lib/python2.5.
>

Thank you both -- it was a combination of the problems.

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


Re: recursion

2007-09-13 Thread Ian Clark
Neil Cerutti wrote:
> On 2007-09-13, Gigs_ <[EMAIL PROTECTED]> wrote:
>> Can someone explain me this
>>
> def f(l):
>>  if l == []:
>>  return []
>>  else:
>>  return f(l[1:]) + l[:1]  # <= cant figure this, how is all sum 
>> at the end?
> 
> In plain English, the above program says:
> 
> The sum of the items in list l is zero if the list is empty.
> Otherwise, the sum is the value of the first item plus the sum of
> the rest of the items in the list.

Am I missing something? What does this have to do with summing?

 >>> def f(l):
 ... if l == []:
 ... return []
 ... else:
 ... return f(l[1:]) + l[:1]
 ...
 >>> f([1, 2, 3, 4])
 [4, 3, 2, 1]

Ian

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


Re: Extended slicing and Ellipsis - where are they used?

2007-09-13 Thread Robert Kern
Rodney Maxwell wrote:
> The following are apparently legal Python syntactically:
>L[1:3, 8:10]
>L[1, ..., 5:-2]
> 
> But they don't seem to work on lists:
 l = [0,1,2,3]
 l[0:2,3]
> Traceback (most recent call last):
>   File "", line 1, in 
> TypeError: list indices must be integers
 l[...]
> Traceback (most recent call last):
>   File "", line 1, in 
> TypeError: list indices must be integers
> 
> So where is this extended slicing used?

numpy for multidimensional arrays.

http://numpy.scipy.org/

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


Re: newbie: self.member syntax seems /really/ annoying

2007-09-13 Thread Steven D'Aprano
On Thu, 13 Sep 2007 16:16:03 +0200, Wildemar Wildenburger wrote:

> I see merit in using
> 
>(_.foo + _.bar) * _.baz
> 
> instead of
> 
>(s.foo + s.bar) * s.baz
> 
> because I'm trained to interpret the underscore as a synonym for one
> space. It's not particularly beautiful, but that is probably a matter of
> habituation. And that exact word is probably the reason why I'd still
> use self or s (explained by a comment, because I can get very dumb if I
> have to).
> 
> It's a matter of taste, so there is no point in bashing a valid
> suggestion.

It's not just a matter of taste.

Reading comprehensibility is an objective, measurable quantity, and I 
would bet that "(self.foo + self.bar) * self.baz" would be measurably 
more readable on average than either of your two alternatives _even for 
those people who claim to hate it_. 

But what do I care? If people are writing code that only they will see, 
they can use any conventions they feel like. It's no skin off my nose.

But if you're writing code that is going to be seen by others in the 
wider community, perhaps because it's open source, or because you're 
working in a team of coders, or even because you're posting snippets to 
comp.lang.python asking for assistance, then it is wise to write using 
conventions that others use. The harder you make it for people to read 
your code, the fewer people will be willing or able or bothered to read 
it.


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


Re: Python+Expect+Win32 = Not Possible?

2007-09-13 Thread gamename
On Sep 13, 4:18 am, Tim Golden <[EMAIL PROTECTED]> wrote:
> gamename wrote:
> > On Sep 13, 1:42 am, [EMAIL PROTECTED] wrote:
> >> On Sep 12, 9:27 pm, gamename <[EMAIL PROTECTED]> wrote:
>
> >>> Hi,
> >>> Is it still the case there is no practical Expect-like module for
> >>> win32? I know that cygwin can support pexpect, but that isn't an
> >>> option here --- I have to use a native win32 Python version.
> >>> Are there alternatives, or is it simply not an option to replicate
> >>> Expect on win32 with python?
> >>> All I'm trying to do is start a couple processes, wait for each to say
> >>> "done" on stdout and then quit (or timeout if something went wrong).
> >>> TIA,
> >>> -T
> >> I had planned on using telnet to do the same thing on windows.  I
> >> don't think I ever proved it, but I'm pretty sure it will work.
>
> > Thanks, Sean.  The problem is that telnet is generally disabled on
> > most hosts nowadays.
>
> I'm not sure whether the need you describe above "start a
> couple [of] processes, wait for each to say 'done' and
> then quit (or timeout...)" is *all* of your requirements
> or just an example. And are these processes running on
> remote machines? Or just locally?
>
Good question.  That's part of the requirements.  The rest are:  The
processes need to be async (i.e. the script doesn't stop while waiting
for the process to complete). They also need some kind of timeout
mechanism so that the processes don't run forever. All processes are
local.

> Depending on those things, maybe there are other ways
> to do what you want under Windows?
>
> (I've checked back through the archives and I can't find
> any earlier posts describing the requirement more clearly).
>
> TJG


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


Re: Python+Expect+Win32 = Not Possible?

2007-09-13 Thread gamename
On Sep 13, 4:51 am, Philem <[EMAIL PROTECTED]> wrote:
> On Sep 13, 12:27 am, gamename <[EMAIL PROTECTED]> wrote:
>
> > Hi,
>
> > Is it still the case there is no practical Expect-like module for
> > win32? I know that cygwin can support pexpect, but that isn't an
> > option here --- I have to use a native win32 Python version.
>
> > Are there alternatives, or is it simply not an option to replicate
> > Expect on win32 with python?
>
> > All I'm trying to do is start a couple processes, wait for each to say
> > "done" on stdout and then quit (or timeout if something went wrong).
>
> > TIA,
> > -T
>
> You could try this 
> link:http://www.activestate.com/Products/activetcl/features.plex
> and see if that gives you what you need.

It absolutely gives me what I need.  But the requirement is to use
Python specifically. :)  Tcl is a great language, but not an option in
this case.
>
> Luck!
> -J


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


Re: Python 3K or Python 2.9?

2007-09-13 Thread TheFlyingDutchman
Well I'm with Bruce Eckel - there shouldn't be any argument for the
object in the class method parameter list. But since Python 3 was
"code-named" 3000 (implying but not delivering big changes... I don't
think it required big changes) and since it still has an explicit
object parameter it's a given that it's not gonna happen in any
revisions.

Bruce said that no other mainstream OO language is explicitly passing
the object as a parameter to class methods. But Perl does it as well.
I think the label "mainstream OO language" is as valid being applied
to Perl as it is to Python.

What I would like to have seen added to class definitions was the
forced declaration of all object variables in the class outside of
methods. I don't like the fact that they have to be, and can be
created in any method on the fly.

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


Re: lxml + mod_python: cannot unmarshal code objects in restricted execution mode

2007-09-13 Thread Dmitri Fedoruk
On Sep 13, 5:05 pm, Dmitri Fedoruk <[EMAIL PROTECTED]> wrote:
> So, my configuration is the following:
> Python 2.5.1
> Server version: Apache/2.2.4 (FreeBSD)
> mod_python-3.3.1
update:
lxml-1.3.4
libxslt-1.1.21
libxml2-2.6.29


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


Re: newbie: self.member syntax seems /really/ annoying

2007-09-13 Thread Wildemar Wildenburger
Charles Fox wrote:
> Maybe for now I will just fix up my emacs to display the world 'self'
> in 10% gray...   :-)
> 
> 
Now *that* is a clever idea! (And that's no irony.)

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


Re: newbie: self.member syntax seems /really/ annoying

2007-09-13 Thread Wildemar Wildenburger
Eduardo O. Padoan wrote:
> On 9/13/07, Wildemar Wildenburger <[EMAIL PROTECTED]> wrote:
>> because I'm trained to interpret the underscore as a synonym for one
>> space. It's not particularly beautiful, but that is probably a matter of
>> habituation. And that exact word is probably the reason why I'd still
>> use self or s (explained by a comment, because I can get very dumb if I
>> have to).
> 
> Have you worked with code using gettext functions imported as "_"?
> When I see a single underscore as a name, i18n comes to mind.
> 
> 
See? Habituation. Just what I'm saying. :)

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


Re: Help to start python

2007-09-13 Thread Wildemar Wildenburger
python_lover wrote:
> Please guide me some good sites to start web based programing on
> python.
> 

Here's a good one:


Always remember: GIYF
If you don't know what that means: 


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


Re: Python 3K or Python 2.9?

2007-09-13 Thread TheFlyingDutchman

>
> > Here is a link to a tutorial where Sun is talking about the this
> > reference:
> >http://java.sun.com/docs/books/tutorial/java/javaOO/thiskey.html
>
> That's a tutorial for getting you started, no reference
> documentation or in-depth course.
>
Here's a FAQ item where they refer to it as I think Python should have
done it - a special predefined variable:

http://www.faqs.org/docs/javap/c5/s5.html

"Java provides a special, predefined variable named "this" that you
can use for such purposes. The variable, this, is used in the source
code of an instance method to refer to the object that contains the
method. This intent of the name, this, is to refer to "this object,"
the one right here that this very method is in. If x is an instance
variable in the same object, then this.x can be used as a full name
for that variable. If otherMethod() is an instance method in the same
object, then this.otherMethod() could be used to call that method.
Whenever the computer executes an instance method, it automatically
sets the variable, this, to refer to the object that contains the
method."



"this" is hard to query on but I would be interested in seeing some
site talking about Java where "this" is mentioned as being "passed
in".



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


Re: Python 3K or Python 2.9?

2007-09-13 Thread Wildemar Wildenburger
TheFlyingDutchman wrote:
> What I would like to have seen added to class definitions was the
> forced declaration of all object variables in the class outside of
> methods. I don't like the fact that they have to be, and can be
> created in any method on the fly.
> 
Isn't one of the main ideas behind python that it doesn't force you to 
do (well, declare) anything? And by "ideas" I mean "design decisions".
Thats exactly what makes python great for prototyping; you just do it 
and see if it works. As soon as you need to declare things you have to 
change stuff in at least 2 places for every change of heart you have.

(Can you tell I'm currently forced to developing in Java? ;) (Which I'm 
currently avoiding to do, by wasting my time on usenet.))

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


Re: newbie: self.member syntax seems /really/ annoying

2007-09-13 Thread J. Clifford Dyer
On Thu, Sep 13, 2007 at 04:21:36PM -, Steven D'Aprano wrote regarding Re: 
newbie: self.member syntax seems /really/ annoying:
> 
> It's not just a matter of taste.
> 
> Reading comprehensibility is an objective, measurable quantity, and I 
> would bet that "(self.foo + self.bar) * self.baz" would be measurably 
> more readable on average than either of your two alternatives _even for 
> those people who claim to hate it_. 
> 

It may be measurable, but it is also contextual.  Depending on what you've been 
trained in, one way or the other might be more readable.  For a teenager in a 
major city, tagging is far more readable than a Fraktur font, but for Mad King 
Ludwig, it was certainly quite the opposite.  Objectively, measurably so, to be 
sure.  Also depending on what you are looking for in the source code.  
Readability can in most cases be enhanced by minimizing those things that serve 
only to distract from the meaning.  Hence the OP's desire to see his formulae, 
uncluttered by the word self.  Now will such a change make his code less 
readable for other python programmers who may look at it later?  Indubitably.  
But that's a different issue.

Moreover, it may be that the best solution is to stop trying for an 
object-oriented solution.  Why not use a functional programming style to 
represent mathematical functions?

Cheers,
Cliff

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


Re: Python 3K or Python 2.9?

2007-09-13 Thread TheFlyingDutchman

>
> Isn't one of the main ideas behind python that it doesn't force you to
> do (well, declare) anything? And by "ideas" I mean "design decisions".
> Thats exactly what makes python great for prototyping; you just do it
> and see if it works. As soon as you need to declare things you have to
> change stuff in at least 2 places for every change of heart you have.
>
> (Can you tell I'm currently forced to developing in Java? ;) (Which I'm
> currently avoiding to do, by wasting my time on usenet.))
>
But if you are looking at code you didn't write, it's nice to be able
to see all the member variables that a class has listed separate from
method code.

I think static typing helps in trying to deduce what code is doing,
particularly when you are looking at function definitions. You don't
have to work to find out what type of variables it takes.


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


Re: Python 3K or Python 2.9?

2007-09-13 Thread Stefan Bellon
On Thu, 13 Sep, TheFlyingDutchman wrote:

> Bruce said that no other mainstream OO language is explicitly passing
> the object as a parameter to class methods.

Ada 95 does. And Ada 95 was the first standardized OO language. Now
with Ada 2005 you can either pass the the object explicitly as first
parameter (like in Ada 95) or you can call the method on the object
(like in Java, C++, Python, ...) and the object is passed implicitly.

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


Re: recursion

2007-09-13 Thread James Stroud
Ian Clark wrote:
> Neil Cerutti wrote:
>> On 2007-09-13, Gigs_ <[EMAIL PROTECTED]> wrote:
>>> Can someone explain me this
>>>
>> def f(l):
>>> if l == []:
>>> return []
>>> else:
>>> return f(l[1:]) + l[:1]  # <= cant figure this, how is all 
>>> sum at the end?
>>
>> In plain English, the above program says:
>>
>> The sum of the items in list l is zero if the list is empty.
>> Otherwise, the sum is the value of the first item plus the sum of
>> the rest of the items in the list.
> 
> Am I missing something? What does this have to do with summing?
> 
> >>> def f(l):
> ... if l == []:
> ... return []
> ... else:
> ... return f(l[1:]) + l[:1]
> ...
> >>> f([1, 2, 3, 4])
> [4, 3, 2, 1]
> 
> Ian

Add it up!

Round   Sum

   0 f([1, 2, 3, 4])
   1 f([2, 3, 4]) + [1]
   2 f([3, 4]) + [2] + [1]
   3 f([4]) + [3] + [2] + [1]
   4 f([]) + [4] + [3] + [2] + [1]

Total   [] + [4] + [3] + [2] + [1] = [4, 3, 2, 1]

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


Re: newbie: self.member syntax seems /really/ annoying

2007-09-13 Thread OKB (not okblacke)
Steven D'Aprano wrote:

>> And I agree with the OP that the convention is really annoying.
>> 
>>   self.rect.width = self.foo(self.rect.x + self.rect.y) * self.boo()
>> 
>> is much less concise than
>> 
>>   s.rect.width = s.foo(s.rect.x + s.rect.y) * s.boo()
> 
> 
> Y do u thnk bng cncis is lwys a gd thng?

No, but the point being made is that it would be better IN THIS 
CASE.

-- 
--OKB (not okblacke)
Brendan Barnwell
"Do not follow where the path may lead.  Go, instead, where there is
no path, and leave a trail."
--author unknown
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: An ordered dictionary for the Python library?

2007-09-13 Thread [EMAIL PROTECTED]
On Sep 13, 1:27 am, Mark Summerfield <[EMAIL PROTECTED]>
wrote:
> On 13 Sep, 00:03, Paul Rubin  wrote:
>
> > Mark Summerfield <[EMAIL PROTECTED]> writes:
> > > I feel that Python lacks one useful data structure: an ordered
> > > dictionary.
> > > Do other Python programmers feel this lack? Is this worth a PEP?
>
> > Yes.  It should use a functional data structure.
>
> Could you elaborate?
>
> Here's my impression of the postings so far: there are 3 categories of
> response:
>
> (A) There is no need for such a thing.
>
> (B) It is useful, but so easy to implement that it needn't be in the
> library.
>
> (C) It is worth having an ordered data structure of some kind.
>
> Regarding (A) and (B): I remember Python before it had the sets
> module. "There's no need for sets, you can do them with dicts".
> Thankfully sets are in the language and I for one use them
> extensively.
>
> For (C) what I had in mind was:
>
> An API that is identical to a dict, with the few additional methods/
> behaviours listed below:
> - If an item is inserted it is put in the right place (because the
> underlying data structure, b*tree, skiplist or whatever is
> intrinsically ordered by < on the key)
> - Extra methods
> key_at(index : int) -> key
> item_at(index : int) -> (key, value)
> value_at(index : int) -> value
> set_value_at(index : int, value) # no return value necessary but
> maybe key if convenient
> od[x:y:z] -> list of values ordered by key # can read a slice but
> not assign a slice
>   and maybe
> keys_for(fromindex : int, uptobutexcludingindex : int) -> ordered
> list of keys
>
> I've given examples of the use cases I envisage (and that I use in
> both Python with my own ordered dict and in C++ with the map class) in
> a previous posting, and I've shown the  API I envisage above. I know
> that some people might prefer ordering by value or the option of case-
> insensitive ordering, but both these can be achieved using the API
> above, e.g.,
> od[value.lower()] = value # case-insensitive ordering of list of
> values
> And as for duplicates there are two approaches I use: (1) make each
> string unique as I showed in my previous post, or (2) use a value that
> itself is a list, dict or set.
> (As for those who have suggested an ordered data structure that isn't
> a dict, I don't see a conflict, I'd be happy to see more data
> structures in the collections module.)
>
> Is what I've suggested sufficient (and sufficiently general) for the
> standard library?

Is the index the insertion order? The only use I have an ordered
dictionary is to quickly determine that a sequence value is the
first duplicate found (the structure can have millions of numbers)
and then play back (so they don't have to be re-calculated) the
sequence from the first duplicate to the end.

So I would get the index when I find the duplicate and then
iterate data[index:] to get the sequence in insertion order?


> If it is not, what should be done, or is there some
> other approach and API that would better provide the functionality
> envisaged?


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


Re: recursion

2007-09-13 Thread Neil Cerutti
On 2007-09-13, Ian Clark <[EMAIL PROTECTED]> wrote:
> Neil Cerutti wrote:
>> On 2007-09-13, Gigs_ <[EMAIL PROTECTED]> wrote:
>>> Can someone explain me this
>>>
>> def f(l):
>>> if l == []:
>>> return []
>>> else:
>>> return f(l[1:]) + l[:1]  # <= cant figure this, how is all sum 
>>> at the end?
>> 
>> In plain English, the above program says:
>> 
>> The sum of the items in list l is zero if the list is empty.
>> Otherwise, the sum is the value of the first item plus the sum of
>> the rest of the items in the list.
>
> Am I missing something? What does this have to do with summing?
>
>  >>> def f(l):
>  ... if l == []:
>  ... return []
>  ... else:
>  ... return f(l[1:]) + l[:1]
>  ...
>  >>> f([1, 2, 3, 4])
>  [4, 3, 2, 1]

It says: You need to read more than the first sentence of a
message before responsing:

> Well, it would say that if it weren't somewhat buggy. l[:1]
> doesn't evaluate to a number, but to a list containing one
> number, so the above program doesn't do what you say it does.
>
> It should read something like:
>
>  def my_sum(seq):
>if len(seq) == 0:
>  return 0
>else:
>  return seq[0] + my_sum(seq[1:])

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


Re: Python 3K or Python 2.9?

2007-09-13 Thread Marc 'BlackJack' Rintsch
On Thu, 13 Sep 2007 10:10:57 -0700, TheFlyingDutchman wrote:

>> Isn't one of the main ideas behind python that it doesn't force you to
>> do (well, declare) anything? And by "ideas" I mean "design decisions".
>> Thats exactly what makes python great for prototyping; you just do it
>> and see if it works. As soon as you need to declare things you have to
>> change stuff in at least 2 places for every change of heart you have.
>>
>> (Can you tell I'm currently forced to developing in Java? ;) (Which I'm
>> currently avoiding to do, by wasting my time on usenet.))
>>
> But if you are looking at code you didn't write, it's nice to be able
> to see all the member variables that a class has listed separate from
> method code.

That information is usually in the `__init__()` method and the class
docstring.

> I think static typing helps in trying to deduce what code is doing,
> particularly when you are looking at function definitions. You don't
> have to work to find out what type of variables it takes.

This should either be obvious or in the docstring.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help to start python

2007-09-13 Thread kyosohma
On Sep 13, 9:39 am, python_lover <[EMAIL PROTECTED]> wrote:
> On Sep 13, 7:23 pm, [EMAIL PROTECTED] wrote:
>
>
>
> > python_lover wrote:
> > > Hi All,
>
> > > I'm new  to python. I installed python 2.5  and IDLE 1.2.1 . I'm able
> > > to run shell commands.
>
> > > But I don't know how to execute a python program using this. When I'm
> > > opeing a py program a seperate IDLE window opeing with program text.
> > > But I don't know to to execute the prg.
>
> > > Please help me on this .
>
> > > thank you
>
> > > regards
> > > Sat
>
> > When in IDLE, you can go to the Run menu and choose Run Module (or
> > press F5) in the window that has the program code.
>
> > Hope that helps!
>
> > Mike- Hide quoted text -
>
> > - Show quoted text -
>
> Thankx mike.
>
> It is working well.
>
> Please guide me some good sites to start web based programing on
> python.
>
> thank you.
>
> sat

Check out
http://wiki.python.org/moin/WebProgramming
http://www.boddie.org.uk/python/HTML.html
http://www.crummy.com/software/BeautifulSoup/

And the many Python web frameworks, like Django, TurboGears, Zope/
Plone, etc.

Mike


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


  1   2   >