Re: Probably simple syntax error

2007-07-02 Thread John Machin
On Jul 2, 2:40 pm, Dustin  MacDonald <[EMAIL PROTECTED]> wrote:
> Hi everyone.
>
> This is my first time posting to this newsgroup, and although I
> maintain my netiquette I might've missed something specific to the
> newsgroup, so hopefully you can avoid flaming me if I have :) I
> apologize for the length of this post but I figure the more
> information the better.

The more relevant information the better. It would have helped had you
shown (a) the first use of weights_array (b) your import statements

>
> My problem is that I'm getting a syntax error in some Python code that
> looks quite simple. The original code was in Object Pascal as I'm a
> recent Delphi-turned-Python programmer.
>
> I took the code (which is only about 130 lines in OP) and 'translated'
> it the best I could into Python (ended up being one line shy of 80
> when I was done). I can't see any problems with the code but it's
> coming up with a bunch of errors, which I'm guessing are probably my
> assuming something is the same in Python as it is in Pascal, and being
> wrong.
>
> Anyway, here's the code I'm having trouble with (the same error comes
> up several times but this is the first part of the code it shows up
> in):

Others have pointed out that the likely source of your first problem
is using () instead of [] for list subscripting.

I'll move on to the next few ...

>
> [code]
> randomizing_counter = 0
> # Put the loop counter for the randomizing to zero.

Problem 2: excessive verbosity

> until_val = 36
> # Set the "until val" to 36. We'll compare them to make sure we're not
> at the end of our wordlist_both.
>
> while randomizing_counter < until_val:

Try this:

weights_array = []
assert len(wordlist_both) == 36 # ???
for _unused in range(len(wordlist_both)):
  # calculate something
  weights_array.append(something)


> big_randomized_int = RandRange(0,100)

Problem 3a:
You have an import statement like
import random
in which case you would get a runtime error, and should have:
  = random.randrange(0, 100)
or Problem 3b:
You have an import statement like:
from random import randrange as RandRange
which will not cause a runtime error, merely mass barfing among the
spectators :-)

> # Make a random value and store it.
> small_randomized_int = big_randomized_int / 100

Problem 5: putting comments after the code instead of on the same line
as the statement you think needs explanation (most don't) or before
it.

> # Divide that random value and store it in a different variable.

Problem 6: big_randomized_int can only have values in 0, 1, ..., 98,
99. So small_randomized_int will have the value 0, always.

Perhaps you meant:
small_randomised_float = big_randomized_int / 100.0

> small_randomized_int = Round(small_randomized_int, 2)
> # Round that value to 2 decimal places

Problem 7: even if you did intend big / 100.00, the above is
redundant. 1 / 100.0 is 0.01, 99 / 100.0 is 0.99 -- no rounding is
necessary.

Problem 8: it's round(), not Round()

> **weights_array(randomizing_counter) = small_randomized_int
> # Assign the first randomized value to our first word to be weighted.

First? It's done each time around the loop.

> randomizing_counter = randomizing_counter + 1
> # Up the counter and repeat.
> [/code]
>

So, here's the looping version:

weights_array = []
for _unused in range(len(wordlist_both)):
  weights_array.append(random.randrange(100) / 100.0)

and here's the obligatory one-liner, using a list comprehension:

weights_array = [random.randrange(100) / 100.0 for _unused in
range(len(wordlist_both))]

and here's an example of it in use:

>>> import random
>>> wordlist_both = 10 * ['foo']
>>> weights_array = [random.randrange(100) / 100.0 for _unused in 
>>> range(len(wordlist_both))]
>>> weights_array
[0.38, 0.12, 0.55004, 0.23999,
0.91003, 0.48999, 0.91003,
0.67004, 0.77002,
0.81995]
>>>

Problem 9: you were expecting "precise" values like 0.55 and 0.24.

Solution is to read this:
http://docs.python.org/tut/node16.html

HTH,
John

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


Re: howto resend args and kwargs to other func?

2007-07-02 Thread Nis Jørgensen
Bruno Desthuilliers skrev:

>> Why do people do this without posting what the actual solution is
> 
> Probably because those people think usenet is a free help desk ?

Usenet definitely isn't a help desk. You often get useful answers from
usenet, from people who are not reading from a script.

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


Re: howto resend args and kwargs to other func?

2007-07-02 Thread Nis Jørgensen
Bruno Desthuilliers skrev:

>> Why do people do this without posting what the actual solution is
> 
> Probably because those people think usenet is a free help desk ?

Usenet definitely isn't a help desk. You often get useful answers from
usenet, from people who are not reading from a script.

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


ann: Python at the IET

2007-07-02 Thread Tim Golden
If you're in London around 6.30pm this Thursday evening, July 5th 2007, you 
might want to drop in on The Institution of 
Engineering and Technology [1] on the Embankment near Waterloo Bridge [2] for 
"A Light byte of Python" [3]. Michael 
Grazebrook, Pete Ryland and I are flying the Python flag for the benefit of 
technologists who have not yet had the 
pleasure. Michael will be using ctypes to control a USB-interfaced sensor kit; 
Pete will be demoing user interfaces; 
I'll be using BeautifulSoup and sqlite3 to populate a database from a web page 
and (time permitting) using csv and 
ReportLab to push it back out again.

We're presenting the thing as a bring-a-laptop workshop, and it would be great 
if we had experienced Pythoneers along to 
  help afterwards (in addition to ourselves). The take-up's been quite high for 
the event and there's tea & coffee 
beforehand and sandwiches afterwards.

Tim Golden

[1] http://www.theiet.org/
[2] 
http://www.iee.org/OnComms/Branches/UK/england/SEastE/london/Venues/savoy.cfm
[3] http://www.iee.org/OnComms/Branches/UK/england/SEastE/london/Events/july.cfm

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


Re: howto resend args and kwargs to other func?

2007-07-02 Thread Nis Jørgensen
Bruno Desthuilliers skrev:

>> Why do people do this without posting what the actual solution is
> 
> Probably because those people think usenet is a free help desk ?

Usenet definitely isn't a help desk. You often get useful answers from
usenet, from people who are not reading from a script.

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


Re: howto resend args and kwargs to other func?

2007-07-02 Thread Nis Jørgensen
Bruno Desthuilliers skrev:

>> Why do people do this without posting what the actual solution is
> 
> Probably because those people think usenet is a free help desk ?

Usenet definitely isn't a help desk. You often get useful answers from
usenet, from people who are not reading from a script.

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


Re: urllib2 : https and proxy

2007-07-02 Thread cp . finances . gouv
On 2 juil, 05:04, "O.R.Senthil Kumaran"
<[EMAIL PROTECTED]> wrote:
> * Maric Michaud <[EMAIL PROTECTED]> [2007-06-28 23:38:39]:
>
> >  Hmmm, i've tried something similar but I get the same result.
>
> >  For the code example I gave, I've put correctly the http_proxy and
> >  https_proxy environment variables, the default ProxyHandler get them right
> >  as this is the proxy itself which returns the error. I checked this with
> >  wireshark, the proxy said that there is incompatibilities in some request
> >  methods, like POST, with some protocols, Gopher is the example it gave.
> >  That doesn't make much sense to me as the wget command I tried is intended
> >  to do exactly the same thing (POST over https and retrieve some cookies 
> > from
> >  the response), and go through with no problems.
>
> Maric, in the ActiveState urllib2 HOWTO which seems to apply for Python 2.5, I
> came across a point which mentions urllib2 does not support PROXY for HTTPS.

Yes, I realize this too, I think this should be considered as a bug in
the documentation.

> Your case seems the same, I would suggest you to look up the Python Tracker
> for any already open issues, or if not kindly log one yourself.


Didn't find one when i made a quick search, but i would suggest to
submit a documentation bug.

BTW, I find this recipe on python cookbook,
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/456195,
works fine for me (with the two additionals comments in my case). We
could add a pointer to this in the doc before fixing urllib2.

What would you suggest ?



> --
> O.R.Senthil Kumaranhttp://uthcode.sarovar.org


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


Re: String formatting for complex writing systems

2007-07-02 Thread Andy
Thanks guys!

I've used the HTML and the unicodedata suggestions, each on a
different report.  These worked nicely!

Andy

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


Bug in Python class static variable?

2007-07-02 Thread Bruza
I am trying to define a class static variable. But the value of the
static variable seems to be only defined inside the file that the
class is declared. See the code below. When I run "python w.py", I
got:

000===> Hello World
001===> Hello World
002===> Not Initialized
003===> Not Initialized
004===> Not Initialized
005===> Hello World

Looks like even though the class variable "ClassW.w_classStaticVar"
was set inside "startup()", the value never carried over to functions
in "a.py". Is this a bug in Python's static variable handling. I am
running Python 2.4.4.


Ben


#= file: w.py 
from a import *

class ClassW:
w_classStaticVar = "Not Initialized"

def initA(self):
print "001===>", ClassW.w_classStaticVar
obj = ClassA()
obj.init2()
print "005===>", ClassW.w_classStaticVar

def startup():
ClassW.w_classStaticVar = "Hello World"
wo = ClassW()
print "000===>", ClassW.w_classStaticVar
wo.initA()

if __name__ == '__main__':
startup()

#= file: a.py 
from w import *

class ClassA:
def __init__(self):
print "002===>", ClassW.w_classStaticVar

def init2(self):
print "003===>", ClassW.w_classStaticVar
w = ClassW()
print "004===>", ClassW.w_classStaticVar

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


Re: Bug in Python class static variable?

2007-07-02 Thread Duncan Booth
Bruza <[EMAIL PROTECTED]> wrote:

> I am trying to define a class static variable. But the value of the
> static variable seems to be only defined inside the file that the
> class is declared. See the code below. When I run "python w.py", I
> got:

When you run "python w.py" the *script* w.py is loaded as the module 
__main__. Importing a module called 'w' creates a new module which is 
unrelated to __main__. If you want access to variables defined in the main 
script then you need to import __main__.

Don't use 'from module import *':

The import statements are executed when the interpreter reaches them in the 
source. Even if you fix your code to import from __main__, the values you 
try to import from __main__ won't exist when the import statement executes: 
the first 'from a import *' will load and execute all of module 'a', but 
when that executes 'from __main__ import *' it just imports names defined 
in the main script *before* a was imported.

In general, don't try to do this: put all your classes into modules and 
just put minimal startup code into a script.
-- 
http://mail.python.org/mailman/listinfo/python-list


freeze: standard modules unknown

2007-07-02 Thread [EMAIL PROTECTED]
I am trying to use freeze to create a single binary executable for one
of my program. When I run freeze, it runs fine with the following
modules. These modules are available in the dyn-load directory and I
can import them from the python interpreter.
Warning: unknown modules remain: _bisect _heapq _locale _random
_socket
Make also runs fine, but when I run the program on another machine, it
compiles saying could not import these modules. Any idea how to get
this working...

Thanks.
-
Suresh

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


Re: The best platform and editor for Python

2007-07-02 Thread evil tabby cat
On Jul 2, 5:10 am, kimiraikkonen <[EMAIL PROTECTED]> wrote:
> Hi,
> For experienced with Pyhton users, which developing software and
> enviroment would you suggest for Pyhton programming? Compiler+Editor
> +Debugger.
>
> Also what are your suggestions for beginners of Pyhton programming?
>
> Thank you.

http://www.wingware.com/ is pretty impressive but non-free of both
beer & speech varieties

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


Re: good matlab interface

2007-07-02 Thread Brian Blais
On Jun 30, 2007, at 2:31 AM, felix seltzer wrote:

> Does any one know of a good matlab interface?
> I would just use scipy or numpy, but i also need to use
> the matlab neural network functions.  I have tried PyMat, but am  
> having
> a hard time getting it to install correctly.
>

What problems are you having installing?  I had one problem with the  
terrible matlab license server, which I had to solve by making site- 
packages world writable, installing pymat as a user, and then  
removing the world writable flag.  Root just didn't have access to  
matlab on my machine.  :P



bb

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


python svn pre-commit hook

2007-07-02 Thread evil tabby cat
This is a python script which is fired off from a batchfile pre-
commit.bat on Windows2000 server.

Everything I've read says that it should work & each part does work
when tested individually.

But when it runs within subversion this statement always ends with
this log_msg being an empty string.
log_msg = os.popen(log_cmd, 'r').readline().rstrip('\n')

Help. :-)


rem pre-commit.bat
c:\python23\python c:\repository\hooks\check-comments.py %1 %2

if errorlevel 1 goto :ERROR

exit 0



:ERROR

echo Error found in commit 1>&2

exit 1



#check-comments.py
import sys, os, string, re

SVNLOOK='c:\\subversion\\bin\\svnlook.exe'

# return true or false if this passed string is a valid comment
def check(comment):
#define regular expression
p = re.compile('\A[iI][sS][sS][uU][eE] \d+ - \w+')
return (p.match(comment) != None) #returns false if doesn't match

def result(r):
   if r == 1:
  sys.stderr.write ("Comments must have the format of 'Issue X -
Comment text' where X is the issue number.")
   sys.exit(r)

def main(repos, txn):
log_cmd = '%s log -t "%s" "%s"' % (SVNLOOK, txn, repos)
log_msg = os.popen(log_cmd, 'r').readline().rstrip('\n')

if check(log_msg):
result(0)
else:
   result(1)

if __name__ == '__main__':
if len(sys.argv) < 3:
sys.stderr.write("Usage: %s REPOS TXN\n" % (sys.argv[0]))
else:
main(sys.argv[1], sys.argv[2])

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


Re: Python changing keywords name

2007-07-02 Thread Michael Hoffman
Gabriel Genellina wrote:

> "except" is hard to translate, and 
> even in English I don't see what is the intended meaning (is it a noun? 
> a verb? an adverb? all look wrong).

It's a preposition.
-- 
Michael Hoffman
-- 
http://mail.python.org/mailman/listinfo/python-list


Interest in a one-day business conference for Python, Zope and Plone companies ?

2007-07-02 Thread eGenix Team: M.-A. Lemburg
Hello,

eGenix is looking into organizing a one day conference
specifically for companies doing business with Python, Zope and
Plone. The conference will likely be held in or close to
Düsseldorf, Germany, which is lively medium-sized city, with good
airport connections world-wide and specifically to all major
European  cities, so it's easy getting there and ideal for a one
day event.

The focus of the conference is on networking, meeting people,
exchanging experience and exploring ways of working together.

We are aiming at having a small conference program with just a few
talks. The main intent of the presentations should be to initiate
discussions among the attendees.

Since this will be a business-only event, we will likely get
professional help from a conference organizer and also try to
sign up with a hotel to do all the catering, conference room
maintenance, etc.

My questions to you:

* Would there be interest in such a conference event ?
* How many people from your company would likely attend ?
* Would a weekday or weekend conference date be more attractive ?
* Does the focus suit your needs ?

We will be giving a short presentation of what we have in mind
at EuroPython 2007 in Vilnius in the context of the Open Space
sessions:

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

If you're interested, please contact us.

Thanks,
-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Jul 02 2007)
>>> Python/Zope Consulting and Support ...http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/

2007-07-09: EuroPython 2007, Vilnius, Lithuania 6 days to go

 Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611

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


unify els database

2007-07-02 Thread luca72
Hello

How i can use to connect to a unify els database with python

Regards

Luca

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


Re: object references/memory access

2007-07-02 Thread dlomsak
Okay, Im back at work and got to put some of these suggestions to use.
cPickle is doing a great job a hiking up the serialization rate and
cutting out the +=data helped a lot too. The entire search process now
for this same data set is down to about 4-5 seconds from pressing
'search' to having the records posted to the browser. Only a fraction
of a second is spent transmitting the data now. Some of the time is
spent waiting for the sockets to actually make their connection. I'll
be now looking into FastCGI to see how much more time I can trim off
the total process.

Once again I would like to say thanks to everyone for the help and
taking the time out to give me some example code to study. I'm glad
that what I thought I wanted to do is not necessary and that the
sockets can send at the speed I hoped they could. This was my first
posting in this group and I plan to remain active and try to help out
where I can. I am fully statisfied with the responses and consider my
problem solved.

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


Re: Probably simple syntax error

2007-07-02 Thread ptn

>
> Problem 6: big_randomized_int can only have values in 0, 1, ..., 98,
> 99. So small_randomized_int will have the value 0, always.
>
> Perhaps you meant:
> small_randomised_float = big_randomized_int / 100.0
>
> > small_randomized_int = Round(small_randomized_int, 2)
> > # Round that value to 2 decimal places
>

PASCAL   -->PYTHON
5 div 2  -->   5/2
5 mod 2-->   5 % 2
5/2-->   5/2.(Notice the little dot at the end)

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


Python-URL! - weekly Python news and links (Jul 2)

2007-07-02 Thread Cameron Laird
QOTW:  "Modules are objects too - they're a good example of singletons. If you
want to create a class containing only static methods: use a module instead.
If you want to create a class having a single instance (a singleton), most of
the time you can use a module instead.  Functions don't *have* to be methods
in a class, and the resulting design may still be a good design from an OO
point of view." - Gabriel Genellina

"I recommend gmane.org's NNTP server for all your mailing list needs." - Grant
Edwards


A "new mailing list has been started to discuss and get help
with ... the Python/C api."
http://groups.google.com/group/comp.lang.python/msg/aaa4787b320aea0a

Ben Finney and others advertise the virtues of SQLAlchemy:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/31374383f59e321f/

IronPython Exception-handling involves a few new techniques:
http://groups.google.com/group/comp.lang.python/msg/a2b697f8e4628dca

Relative imports present a challenge for which there's no canonical 
solution.  Josiah and Gabriel help analyze the situation:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/c44c769a72ca69fa/

How can a report's columns be made to line up?

http://groups.google.com/group/comp.lang.python/browse_thread/thread/4256781d326edf8c/

It's common enough to see advertisements for employment,
contract development, authoring, ... in comp.lang.python;
now we're getting legitimate announcements of Python-based
higher-order businesses:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/f82f9ee231a99909/


Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily
Mygale is a news-gathering webcrawler that specializes in (new)
World-Wide Web articles related to Python.
 http://www.awaretek.com/nowak/mygale.html
While cosmetically similar, Mygale and the Daily Python-URL
are utterly different in their technologies and generally in
their results.

The Python Papers aims to publish "the efforts of Python enthusiats".
http://pythonpapers.org/

Readers have recommended the "Planet" sites:
http://planetpython.org
http://planet.python.org

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.

http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce

Python411 indexes "podcasts ... to help people learn Python ..."
Updates appear more-than-weekly:
http://www.awaretek.com/python/index.html

Steve Bethard continues the marvelous tradition early borne by
Andrew Kuchling, Michael Hudson, Brett Cannon, Tony Meyer, and Tim
Lesher of intelligently summarizing action on the python-dev mailing
list once every other week.
http://www.python.org/dev/summary/

The Python Package Index catalogues packages.
http://www.python.org/pypi/

The somewhat older Vaults of Parnassus ambitiously collects references
to all sorts of Python resources.
http://www.vex.net/~x/parnassus/

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
responsibility for Python's development and maintenance.
http://www.python.org/psf/
Among the ways you can support PSF is with a donation.
http://www.python.org/psf/donate.html

Kurt B. Kaiser publishes a weekly report on faults and patches.
http://www.google.com/groups?as_usubject=weekly%20python%20patch

Although unmaintained since 2002, the Cetus collection of Python
hyperlinks retains a few gems.
http://www.cetus-links.org/oo_python.html

Python FAQTS
http://python.faqts.com/

The Cookbook is a collaborative effort to capture useful and
interesting recipes.
http://aspn.activestate.com/ASPN/Cookbook/Python

Many Python conferences around the world are in preparation.
Watch this space for links to them.

Among several Python-oriented RSS/RDF feeds available are
http://www.python.org/channews.rdf

Re: Tiny/small/minimalist Python?

2007-07-02 Thread rtk
On Jul 1, 10:12 pm, Paul Rubin  wrote:
> You've gotten good suggestions about Python configurations.  Depending
> on your application you might look at alternative languages as well.
> Lua and Hedgehog Lisp both come to mind as small embedded interpreters.

PyMite will get a closer look from me eventually but I found that Lua
will fit my immediate needs quite nicely.  Thanks for the suggestion.

FYI.. I wanted a simple version of Python to run on an ancient DEC
Alpha box.  I got VMS Python 2.5 up and running but it is too slow to
use.  It takes *minutes* to get the interpreter prompt after typing
'python'!  Lua, on the other hand, compiled without changes (used the
ANSI switch) and runs nicely.  I'm always up for learning a new
language anyway.

Ron

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


Reading stdout and stderr of an external program

2007-07-02 Thread Murali
Hi Python programmers,

I need to be able to read the stdout and stderr streams of an external
program that I launch from my python script. os.system( 'my_prog' +
'>& err.log' ) and was planning on monitoring err.log and to display
its contents. Is this the best way to do this?

Thanks,
Murali.

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


Re: Tiny/small/minimalist Python?

2007-07-02 Thread Paul Rubin
rtk <[EMAIL PROTECTED]> writes:
> FYI.. I wanted a simple version of Python to run on an ancient DEC
> Alpha box.  I got VMS Python 2.5 up and running but it is too slow to
> use.  It takes *minutes* to get the interpreter prompt after typing
> 'python'! 

Something is wrong.  Maybe it's trying to DNS itself and timing out,
or something like that.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Reading stdout and stderr of an external program

2007-07-02 Thread Thomas Jollans
On Monday 02 July 2007, Murali wrote:
> Hi Python programmers,
>
> I need to be able to read the stdout and stderr streams of an external
> program that I launch from my python script. os.system( 'my_prog' +
> '>& err.log' ) and was planning on monitoring err.log and to display
> its contents. Is this the best way to do this?

No. The best way to do this is with Popen, as it is portable and avoids the 
extranous file.


-- 
  Regards,   Thomas Jollans
GPG key: 0xF421434B may be found on various keyservers, eg pgp.mit.edu
Hacker key :
v4sw6+8Yhw4/5ln3pr5Ock2ma2u7Lw2Nl7Di2e2t3/4TMb6HOPTen5/6g5OPa1XsMr9p-7/-6
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Reading stdout and stderr of an external program

2007-07-02 Thread Ben Cartwright
> I need to be able to read the stdout and stderr streams of an external
> program that I launch from my python script. os.system( 'my_prog' +
> '>& err.log' ) and was planning on monitoring err.log and to display
> its contents. Is this the best way to do this?

from subprocess import Popen
stdout, stderr = Popen('my_prog').communicate()

--Ben

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


Re: Portable general timestamp format, not 2038-limited

2007-07-02 Thread John W. Kennedy
Martin Gregorie wrote:
> Roedy Green wrote:
>>
>> To add to the confusion you have GPS, Loran and Julian day also used
>> as scientific times.
>  >
> GPS time is UTC time

No it isn't. GPS has never introduced a leap second, and is still on 
uncorrected UTC-as-of-1980. However, the GPS signal also includes an 
occasional UTC correction figure, so it can be used to obtain UTC.
-- 
John W. Kennedy
"The first effect of not believing in God is to believe in anything"
   -- Emile Cammaerts, "The Laughing Prophet"
-- 
http://mail.python.org/mailman/listinfo/python-list


need help with win32com

2007-07-02 Thread Thomas
I want to be able to access an excel file and extract the code from
the macro that is in the file.  How can I do this?

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


Re: Problem with PEXPECT in Python

2007-07-02 Thread Noah

Kevin Erickson wrote:
> On Jun 30, 5:50 pm, Kevin  Erickson <[EMAIL PROTECTED]> wrote:
> > #Begin Code
> >
> > import sys
> > import pexpect
> >
> > def GetServerData(self):
> > foo = pexpect.spawn('scp [EMAIL PROTECTED]:/home/config/
> > role{/file1,/files/file2,/files/file3} /tmp')
> > foo.expect('.*password:*')
> > foo.sendline('server_password')
> > foo.interact()
...
> I have found a work around for my problem.  I replace the following line:
>
> foo.interact()
> with
> foo.expect(pexpect.EOF)

That is correct. But why did you try using interact() method in the
first place?
I just want to know to see if I could improve the documentation.
After you send the password the 'scp' command should finish quickly
and exit,
so there would be nothing for a human to interact with.

You could also try using the run() function which is a simplified
interface to pexpect.
Something like this might work:
pexpect.run ('scp [EMAIL PROTECTED]:/home/config/role{/file1,/files/
file2,/files/file3} /tmp',
events={'(?i)password': 'server_password'})
That's all there is to it. The run() function will run the given scp
command.
When it see 'password' in the output it will send the server_password.

Yours,
Noah


Yours,
Noah

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


Re: Probably simple syntax error

2007-07-02 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Mark Peters  <[EMAIL PROTECTED]> wrote:
.
.
.
>Square brackets indicate the index into a sequence (like a list)
>

I'm wary of this line, especially in isolation.  I hope it reduces,
rather than exacerbates, the original questioner's confusion, for me
to observe that [] *also* mark dereferencing into a dictionary (hash,
associative array, ...), which is distinct from list indexing.
-- 
http://mail.python.org/mailman/listinfo/python-list


subprocess -- broken pipe error

2007-07-02 Thread 7stud
Hi,

Can someone explain what a broken pipe is?  The following produces a
broken pipe error:

--
import subprocess as sub

p = sub.Popen(["ls", "-al", "../"], stdin=sub.PIPE, stdout=sub.PIPE)

print p.stdout.read()
#outputs the files correctly

p.stdin.write("ls\n")
#IOError: [Errno 32] Broken pipe
---

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


Re: howto resend args and kwargs to other func?

2007-07-02 Thread Sion Arrowsmith
Frank Swarbrick  <[EMAIL PROTECTED]> wrote:
>dmitrey wrote:
>> Thanks all, I have solved the problem.
>Why do people do this without posting what the actual solution is

Hey, if we're expected to magically deduce what the problem is
without being told an error messages, surely we can magically
deduce the discovered solution too?

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

Re: Rappresenting infinite

2007-07-02 Thread andrea
Mm very interesting thread, for my needs from numpy import inf is more
than enough :)


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


Pretty Scheme, ??? Python

2007-07-02 Thread Neil Cerutti
The following simple language parser and interpreter is from
chapter 2 of the textbook: _Programming Languages: Application
and Interpretation_, by Shriram Krishnamurthi.

http://www.cs.brown.edu/~sk/Publications/Books/ProgLangs/

First, I'll show the Scheme version of the program, which uses
the cool define-type and type-case macros (I'd never heard of
them before reading this book, which is too bad). I think it is
beautiful.

; Our grammar:
;  ::= 
;   
;   | { +   }
;   | { -   }
;   | {with { } }
;   | 
(define-type WAE
  [num (n number?)]
  [add (lhs WAE?)
   (rhs WAE?)]
  [sub (lhs WAE?)
   (rhs WAE?)]
  [id (name symbol?)]
  [with (name symbol?) (named-expr WAE?) (named-body WAE?)])

;; parse : sexp --> WAE
;; To convert s-expressions into WAEs
(define (parse sexp)
  (cond
[(number? sexp) (num sexp)]
[(symbol? sexp) (id sexp)]
[(list? sexp)
 (case (first sexp)
   [(+) (if (= (length sexp) 3)
(add (parse (second sexp))
 (parse (third sexp)))
(error 'parse "add: expected 2 args"))]
   [(-) (if (= (length sexp) 3)
(sub (parse (second sexp))
 (parse (third sexp)))
(error 'parse "sub: expected 2 args"))]
   [(with) (with (first (second sexp))
 (parse (second (second sexp)))
 (parse (third sexp)))]
   [else (error 'parse "invalid expression")])]
[else (error 'parse "invalid expression")]))

;; subst : WAE symbol WAE --> WAE
;; substitutes second argument with third argument in first argument,
;; as per the rules of substitution; the resulting expression contains
;; no free instances of the second argument.
(define (subst expr sub-id val)
  (type-case WAE expr
[num (n) expr]
[add (lhs rhs) (add (subst lhs sub-id val)
(subst rhs sub-id val))]
[sub (lhs rhs) (sub (subst lhs sub-id val)
(subst rhs sub-id val))]
[with (bound-id named-expr bound-body)
  (if (symbol=? bound-id sub-id)
  (with bound-id
(subst named-expr sub-id val)
bound-body)
  (with bound-id
(subst named-expr sub-id val)
(subst bound-body sub-id val)))]
[id (v) (if (symbol=? v sub-id) val expr)]))

;; calc : WAE --> number
;; consumes a WAE and computes the corresponding number
(define (calc an-ae)
  (type-case WAE an-ae
[num (n) n]
[add (lhs rhs) (+ (calc lhs) (calc rhs))]
[sub (lhs rhs) (- (calc lhs) (calc rhs))]
[with (bound-id named-expr bound-body) 
  (calc (subst bound-body 
   bound-id 
   (num (calc named-expr]
[id (v) (error 'calc "free identifier")]))

(test (calc (parse '3)) 3)
(test (calc (parse '{+ 3 4})) 7)
(test (calc (parse '{+ {- 3 4} 7})) 6)
; etc... the rest of the tests omited

The following is a translation of the above program into Python,
as best as I could. I have not included the simple s-expression
parser that I had to write as a front-end, but I'll post if if
anyone's interested. The type-case is replaced with a class
hierarchy, resulting in some extra syntax. Most of the docstrings
and tests have been omited as irrelevant.

import sexp
import operator

class Wae(object):
""" An abstract base class for representing the abstract syntax tree of a
Wae expression.
   
"""
def calc(self):
raise NotImplementedError

class Num(Wae):
""" This subclass represents numbers.

"""
def __init__(self, number):
self.number = number
def __repr__(self):
return '' % self.number
def subst_(self, sub_id, value):
return self
def calc(self):
return self.number

class Id(Wae):
""" This subclass represents an identifier.

"""
def __init__(self, name):
self.name = name
def __repr__(self):
return '' % self.name
def subst_(self, sub_id, value):
if self.name == sub_id:
return value
return self
def calc(self):
raise SyntaxError('Free identifier '+self.name)

class BinOp(Wae):
""" This abstract class represents binary operations.

"""
def __init__(self, lhs, rhs):
self.lhs = lhs
self.rhs = rhs
def __repr__(self):
return '<%s %r %r>' % (self.__class__.__name__, self.lhs, self.rhs)
def subst_(self, sub_id, value):
return self.__class__(self.lhs.subst_(sub_id, value),
self.rhs.subst_(sub_id, value))
def calc(self):
return self.op(self.lhs.calc(), self.rhs.calc())

class Add(BinOp):
""" This subclass represents an addition expression.

"""
def __init__(self, lhs, rhs):
super(Add, self).__init__(lhs, rhs)
self.op = operator.add

class Sub(BinOp):
""" This subclass represents a substraction expression.

"""
def __init__(self, lhs, rhs):
sup

Re: The best platform and editor for Python

2007-07-02 Thread kimiraikkonen
On Jul 2, 3:49 pm, evil tabby cat <[EMAIL PROTECTED]> wrote:
> On Jul 2, 5:10 am, kimiraikkonen <[EMAIL PROTECTED]> wrote:
>
> > Hi,
> > For experienced with Pyhton users, which developing software and
> > enviroment would you suggest for Pyhton programming? Compiler+Editor
> > +Debugger.
>
> > Also what are your suggestions for beginners of Pyhton programming?
>
> > Thank you.
>
> http://www.wingware.com/is pretty impressive but non-free of both
> beer & speech varieties

Thanks for the replies so far. Also i have to learn:

What is the most reliable and easy way to start learning Ptyhon?
Books? Trusted code sammples(where?)?

I know the importance and eases of Python quite.

Thanks.

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


Re: subprocess -- broken pipe error

2007-07-02 Thread [EMAIL PROTECTED]
On Jul 2, 1:12 pm, 7stud <[EMAIL PROTECTED]> wrote:
> Hi,
>
> Can someone explain what a broken pipe is?  The following produces a
> broken pipe error:
>
> --
> import subprocess as sub
>
> p = sub.Popen(["ls", "-al", "../"], stdin=sub.PIPE, stdout=sub.PIPE)
>
> print p.stdout.read()
> #outputs the files correctly
>
> p.stdin.write("ls\n")
> #IOError: [Errno 32] Broken pipe
> ---

You are seeing this error because sub.Popen closes both stdin and
stdout once the subprocess terminates (which it must have done for
p.stdout.read() to return a result).

Consequently you are trying to write to a pipeline whose reader has
already closed it, hence the error message.

regards
 Steve

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


Re: Python's "only one way to do it" philosophy isn't good?

2007-07-02 Thread Douglas Alan
Lenard Lindstrom <[EMAIL PROTECTED]> writes:

>>> Explicitly clear the exception? With sys.exc_clear?

>> Yes.  Is there a problem with that?

> As long as nothing tries to re-raise the exception I doubt it breaks
> anything:
>
>  >>> import sys
>  >>> try:
>   raise StandardError("Hello")
> except StandardError:
>   sys.exc_clear()
>   raise
>
>
> Traceback (most recent call last):
>File "", line 5, in 
>  raise
> TypeError: exceptions must be classes, instances, or strings
> (deprecated), not NoneType

I guess I don't really see that as a problem.  Exceptions should
normally only be re-raised where they are caught.  If a piece of code
has decided to handle an exception, and considers it dealt with, there
is no reason for it not to clear the exception, and good reason for it
to do so.  Also, any caught exception is automatically cleared when
the catching procedure returns anyway, so it's not like Python has
ever considered a caught exception to be precious information that
ought to be preserved long past the point where it is handled.

> But it is like calling the garbage collector. You are tuning the
> program to ensure some resource isn't exhausted.

I'm not sure I see the analogy: Calling the GC can be expensive,
clearing an exception is not.  The exception is going to be cleared
anyway when the procedure returns, the GC wouldn't likely be.

It's much more like explicitly assigning None to a variable that
contains a large data structure when you no longer need the contents
of the variable.  Doing this sort of thing can be a wise thing to do
in certain situations.

> It relies on implementation specific behavior to be provably
> reliable*.

As Python is not a formally standardized language, and one typically
relies on the fact that CPython itself is ported to just about every
platform known to Man, I don't find this to be a particular worry.

> If this is indeed the most obvious way to do things in your
> particular use case then Python, and many other languages, is
> missing something. If the particular problem is isolated,
> formalized, and general solution found, then a PEP can be
> submitted. If accepted, this would ensure future and cross-platform
> compatibility.

Well, I think that the refcounting semantics of CPython are useful,
and allow one to often write simpler, easier-to-read and maintain
code.  I think that Jython and IronPython, etc., should adopt these
semantics, but I imagine they might not for performance reasons.  I
don't generally use Python for it's speediness, however, but rather
for it's pleasant syntax and semantics and large, effective library.

|>oug
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The best platform and editor for Python

2007-07-02 Thread kimiraikkonen
Thanks for the replies so far. Also i have to learn:

What is the most reliable and easy way to start learning Ptyhon?
Books? Trusted code sammples(where?)?


I know the importance and eases of Python quiet.


Thanks.


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


Re: Python's "only one way to do it" philosophy isn't good?

2007-07-02 Thread Douglas Alan
Lenard Lindstrom <[EMAIL PROTECTED]> writes:

>> You don't necessarily want a function that raises an exception to
>> deallocate all of its resources before raising the exception, since
>> you may want access to these resources for debugging, or what have
>> you.

> No problem:
>
> [...]
>
>  >>> class MyFile(file):
>   def __exit__(self, exc_type, exc_val, exc_tb):
>   if exc_type is not None:
>   self.my_last_posn = self.tell()
>   return file.__exit__(self, exc_type, exc_val, exc_tb)

I'm not sure I understand you here.  You're saying that I should have
the foresight to wrap all my file opens is a special class to
facilitate debugging?

If so, (1) I don't have that much foresight and don't want to have
to.  (2) I debug code that other people have written, and they often
have less foresight than me.  (3) It would make my code less clear to
ever file open wrapped in some special class.

Or are you suggesting that early in __main__.main(), when I wish to
debug something, I do something like:

   __builtins__.open = __builtins__.file = MyFile

?

I suppose that would work.  I'd still prefer to clear exceptions,
though, in those few cases in which a function has caught an exception
and isn't going to be returning soon and have the resources generally
kept alive in the traceback.  To me, that's the more elegant and
general solution.

|>oug
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: what is the PythonWin

2007-07-02 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
O.R.Senthil Kumaran <[EMAIL PROTECTED]> wrote:
>* [EMAIL PROTECTED] <[EMAIL PROTECTED]> [2007-07-01 15:53:30]:
>
>> In PythonWin, select Tools | COM MakePy utility | Microsoft Speech
>> Object Library 5.1).
>> 
>> I can't find PythonWin .. Does anybody know what this is.  I have the
>> Python shell gui but no "PythonWin".
>> 
>PythonWin is a separate project by Mark Hammond providing win32 extensions for
>python. 
>
>http://sourceforge.net/projects/pywin32/
.
.
.
I believe there's confusion afoot.

Pythonwin http://wiki.python.org/moin/PythonWin > is a
Python-oriented editor for Windows.  Mark bundles Pythonwin
with a couple of other equally-intriguing pieces to make
pywin32.  When I read, "win32 extensions for python", I think
of what Mark labels "win32api".  I'm reasonably certain that,
in this case, steve had in mind specifically the editor, and
*not* all of win32all--although he'll surely want to know that
the canonical way to retrieve it is as part of pywin32 as a
whole.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: subprocess -- broken pipe error

2007-07-02 Thread 7stud
On Jul 2, 11:32 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> On Jul 2, 1:12 pm, 7stud <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hi,
>
> > Can someone explain what a broken pipe is?  The following produces a
> > broken pipe error:
>
> > --
> > import subprocess as sub
>
> > p = sub.Popen(["ls", "-al", "../"], stdin=sub.PIPE, stdout=sub.PIPE)
>
> > print p.stdout.read()
> > #outputs the files correctly
>
> > p.stdin.write("ls\n")
> > #IOError: [Errno 32] Broken pipe
> > ---
>
> You are seeing this error because sub.Popen closes both stdin and
> stdout once the subprocess terminates (which it must have done for
> p.stdout.read() to return a result).
>
> Consequently you are trying to write to a pipeline whose reader has
> already closed it, hence the error message.
>
> regards
>  Steve

Hi,

Thanks for the response.  So are you saying that the only way you can
get data out of a pipe is when the subprocess has terminated?

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


Python compilation ??

2007-07-02 Thread Cathy Murphy

Is python a compiler language or interpreted language. If it is interpreter
, then why do we have to compile it?
Python newbie

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

Re: Python compilation ??

2007-07-02 Thread Evan Klitzke
On 7/2/07, Cathy Murphy <[EMAIL PROTECTED]> wrote:
> Is python a compiler language or interpreted language. If it is interpreter
> , then why do we have to compile it?

It's an interpreted language. It is compiled into bytecode (not
machine code) the first time a script is run to speed up subsequent
executions of a script.

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


Re: sort pygtk gtktreeview column containing dates

2007-07-02 Thread Jan Vorwerk
Hi,

I did something similar already in wxPython, but not yet in PyGTK.
Therefore I cannot provide the actual solution... Since noone answered, 
I will still give you a hint :

http://www.pygtk.org/pygtk2tutorial/sec-TreeModelInterface.html

See 14.2.9. Sorting TreeModel Rows
  and
set_sort_func(sort_column_id, sort_func, user_data=None)

Good luck!
Jan


psaroudakis a écrit , le 27.06.2007 16:28:
> Hello... I have been trying to sort a gtktreelist column that contains
> dates in the following format:
> 
> eg: 01-Jan-1993
>  12-Dec-1992 etc
> 
> i don't seem to be able to find any other solution than using dates in
> the format "-MM-DD" which is something i am trying to avoid..
> 
> Is there something very trivial that I am missing/overlooking? any
> suggestions?
> 
> Thanks,
> 
> Nik
> 
> Disclaimer: I am very new to Python and Pygtk
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Rappresenting infinite

2007-07-02 Thread [EMAIL PROTECTED]
On Jun 27, 6:41 am, andrea <[EMAIL PROTECTED]> wrote:
> I would like to have a useful rappresentation of infinite, is there
> already something??
>
> I was thinking to something like this
>
> class Inf(int):
> """numero infinito"""
> def __init__(self,negative=False):
> self.negative = negative
> def __cmp__(self,y):
> """infinito maggiore di qualasiasi cosa"""
> if self.negative:
> return -1
> else:
> return 1
> def __repr__(self):
> """docstring for __repr__"""
> if self.negative:
> return '-inf'
> else:
> return 'inf'
> def __add__(self,y):
> """addizione con infinito"""
> return self
> def __mul__(self,y):
> """moltiplicazione"""
> import types
> if isinstance(y,types.IntType):
> if y > 0:
> return self
> if y == 0:
> return 'indefinito'
> else:
> return Inf(negative)
>
> I'd like to be able to compare between any value and infinite always
> getting the right result, and paying attention to the special cases
> like
> inf / inf => not determinate

float('inf') works well, no?

   >>> inf = float('inf')
   >>> inf / inf
   nan
   >>> -inf
   -inf
   >>> inf / 0
   ZeroDivisionError: float division
   >>> 1 / inf
   0.0
   >>> 0 * float('inf')
   nan

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


Re: subprocess -- broken pipe error

2007-07-02 Thread 7stud
Why doesn't the following program write to the file?

driver.py
---
import subprocess as sub

p = sub.Popen(["python", "-u", "test1.py"], stdin=sub.PIPE,
stdout=sub.PIPE)


p.stdin.write("text3")

while True:
pass
---

test1.py:
-
import sys

data = sys.stdin.read()

f = open("aaa.txt", "w")
f.write(data + "\n")
f.close()
---


After I hit Ctrl+C to end the program and look in the file, the text
wasn't written to the file.  But, if I change driver.py to the
following it works:

driver.py:
--
import subprocess as sub

p = sub.Popen(["python", "-u", "test1.py"], stdin=sub.PIPE,
stdout=sub.PIPE)


p.stdin.write("text3")
---

Ok. So that looks like the data is caught in a buffer--even though the
pipes should be unbuffered by default.  But this doesn't work:

driver.py
--
import subprocess as sub

p = sub.Popen(["python", "-u", "test1.py"], stdin=sub.PIPE,
stdout=sub.PIPE)

p.stdin.write("text4")
p.stdin.flush()

while True:
pass
---

It just hangs, and then when I hit Ctrl+C and look in the file, the
data isn't in there.




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


Re: need help with win32com

2007-07-02 Thread kyosohma
On Jul 2, 11:38 am, Thomas <[EMAIL PROTECTED]> wrote:
> I want to be able to access an excel file and extract the code from
> the macro that is in the file.  How can I do this?
>
> --
> ~Thomas~

You should be able to use PythonWin and the makepy utility to get
handles to the Excel object. See the following article:

http://www.oreilly.com/catalog/pythonwin32/chapter/ch12.html

I also found an article on how to use Python as the scripting language
in Excel:

http://www.velocityreviews.com/forums/t319222-re-python-in-excel.html

Mike

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


Re: Rappresenting infinite

2007-07-02 Thread Robert Kern
[EMAIL PROTECTED] wrote:

> float('inf') works well, no?
> 
>>>> inf = float('inf')
>>>> inf / inf
>nan
>>>> -inf
>-inf
>>>> inf / 0
>ZeroDivisionError: float division
>>>> 1 / inf
>0.0
>>>> 0 * float('inf')
>nan

It is not cross-platform. The parsing of strings into floats and the string
representation of floats is dependent on your system's C library. For these
special values, this differs across platforms. Your code won't work on Windows,
for example. Fortunately, it doesn't matter all that much (at least for those
who just need to create such values; parsing them from files is another matter)
since infs and nans can be constructed in a cross-platform way (at least for
IEEE-754 platforms where these values make sense).

  inf = 1e200 * 1e200
  nan = inf / inf

-- 
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: Bug in Python class static variable?

2007-07-02 Thread Bruza
On Jul 2, 3:52 am, Duncan Booth <[EMAIL PROTECTED]> wrote:
> Bruza <[EMAIL PROTECTED]> wrote:
> > I am trying to define a class static variable. But the value of the
> > static variable seems to be only defined inside the file that the
> > class is declared. See the code below. When I run "python w.py", I
> > got:
>
> When you run "python w.py" the *script* w.py is loaded as the module
> __main__. Importing a module called 'w' creates a new module which is
> unrelated to __main__. If you want access to variables defined in the main
> script then you need to import __main__.
>
> Don't use 'from module import *':
>
> The import statements are executed when the interpreter reaches them in the
> source. Even if you fix your code to import from __main__, the values you
> try to import from __main__ won't exist when the import statement executes:
> the first 'from a import *' will load and execute all of module 'a', but
> when that executes 'from __main__ import *' it just imports names defined
> in the main script *before* a was imported.
>
> In general, don't try to do this: put all your classes into modules and
> just put minimal startup code into a script.

Duncan,

Thanks for replying. However, I am still confused...
Even if I put "from __main__ import *" in both "a.py" and "w.py", I
still got
the same results. So, how should I re-structure my program to make the
class
static variable works???

Thanks,

Ben

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


Re: subprocess -- broken pipe error

2007-07-02 Thread Bjoern Schliessmann
7stud wrote:

> Thanks for the response.  So are you saying that the only way you
> can get data out of a pipe is when the subprocess has terminated?

No, not only because Pipes aren't related to processes in any
special way.

He said that you can't write to a pipe whose reader has already
terminated.

Regards,


Björn

-- 
BOFH excuse #36:

dynamic software linking table corrupted

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


Re: subprocess -- broken pipe error

2007-07-02 Thread Bjoern Schliessmann
7stud wrote:

> Why doesn't the following program write to the file?
> [...]
> It just hangs, and then when I hit Ctrl+C and look in the file,
> the data isn't in there.

I suppose your running child process isn't closed cleanly if you
terminate the parent process. Also, the pipe may be unbuffered by
default; file access isn't.

Regards,


Björn

-- 
BOFH excuse #384:

it's an ID-10-T error

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


Re: subprocess -- broken pipe error

2007-07-02 Thread 7stud
On Jul 2, 1:58 pm, Bjoern Schliessmann  wrote:
> 7stud wrote:
> > Thanks for the response.  So are you saying that the only way you
> > can get data out of a pipe is when the subprocess has terminated?
>
> No, not only because Pipes aren't related to processes in any
> special way.
>
> He said that you can't write to a pipe whose reader has already
> terminated.
>

What he said was:

>...once the subprocess terminates (which it must have done for
>p.stdout.read() to return a result)

And based on the results of the examples I posted in my last post, it
seems to confirm that no data travels through a pipe until a program
on one side of the pipe has terminated.

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


Re: subprocess -- broken pipe error

2007-07-02 Thread 7stud
On Jul 2, 2:03 pm, Bjoern Schliessmann  wrote:
> 7stud wrote:
> > Why doesn't the following program write to the file?
> > [...]
> > It just hangs, and then when I hit Ctrl+C and look in the file,
> > the data isn't in there.
>
> Also, the pipe may be unbuffered by
> default; file access isn't.
>

f.close() flushes the buffer to a file.


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


Re: subprocess -- broken pipe error

2007-07-02 Thread Steve Holden
7stud wrote:
> Why doesn't the following program write to the file?
> 
> driver.py
> ---
> import subprocess as sub
> 
> p = sub.Popen(["python", "-u", "test1.py"], stdin=sub.PIPE,
> stdout=sub.PIPE)
> 
> 
> p.stdin.write("text3")
> 
> while True:
> pass
> ---
> 
> test1.py:
> -
> import sys
> 
> data = sys.stdin.read()
> 
Let me ask you a question: what conditions have to be true to this 
statement to terminate?

A: the Python driver.py process has to close its output file. Since it 
doesn't do this (instead writing a little bit of output then going into 
an infinite loop) the whole thing just sits there consuming CPU time.


> f = open("aaa.txt", "w")
> f.write(data + "\n")
> f.close()
> ---
> 
> 
> After I hit Ctrl+C to end the program and look in the file, the text
> wasn't written to the file.  But, if I change driver.py to the
> following it works:
> 
> driver.py:
> --
> import subprocess as sub
> 
> p = sub.Popen(["python", "-u", "test1.py"], stdin=sub.PIPE,
> stdout=sub.PIPE)
> 
> 
> p.stdin.write("text3")
> ---
> 
> Ok. So that looks like the data is caught in a buffer--even though the
> pipes should be unbuffered by default.  But this doesn't work:
> 
Who told you pipes should be unbuffered by default, and what difference 
does that make anyway?

The reason it works now is that your program closes its standard output 
by default when it terminates.

> driver.py
> --
> import subprocess as sub
> 
> p = sub.Popen(["python", "-u", "test1.py"], stdin=sub.PIPE,
> stdout=sub.PIPE)
> 
> p.stdin.write("text4")
> p.stdin.flush()
> 
> while True:
> pass
> ---
> 
> It just hangs, and then when I hit Ctrl+C and look in the file, the
> data isn't in there.
> 
Of course it does, for the reasons mentioned above. file.read() only 
returns when it has consumed *all* the data from the file (which means 
the write must close the file for the reader to be able to return).

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


Re: Python compilation ??

2007-07-02 Thread Steve Holden
Evan Klitzke wrote:
> On 7/2/07, Cathy Murphy <[EMAIL PROTECTED]> wrote:
>> Is python a compiler language or interpreted language. If it is interpreter
>> , then why do we have to compile it?
> 
> It's an interpreted language. It is compiled into bytecode (not
> machine code) the first time a script is run to speed up subsequent
> executions of a script.
> 
While the flavor of this answer is correct, in strict point of fact 
Python *doesn't* compile the scripts it executes, only the modules that 
are imported.

That's why you will occasionally see a very small Python program that 
just calls functions imported from much larger modules. This avoids 
spending the time that would otherwise have to be spent recompiling a 
large script at each execution.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


Re: object references/memory access

2007-07-02 Thread Karthik Gurusamy
On Jul 1, 12:38 pm, dlomsak <[EMAIL PROTECTED]> wrote:
> Thanks for the responses folks. I'm starting to think that there is
> merely an inefficiency in how I'm using the sockets. The expensive
> part of the program is definitely the socket transfer because I timed
> each part of the routine individually. For a small return, the whole
> search and return takes a fraction of a second. For a large return (in
> this case 21,000 records - 8.3 MB) is taking 18 seconds. 15 of those
> seconds are spent sending the serialized results from the server to
> the client. I did a little bit of a blind experiment and doubled the
> bytes on the client's socket.recv line. This improved the rate of
> transfer each time. The original rate when I was accepting 1024 bytes
> per recv took 47 seconds to send the 8.3 MB result. By doubling this
> size several times, I reduced the time to 18 seconds until doubling it
> further produced diminishing results. I was always under the
> impression that keeping the send and recv byte sizes around 1024 is a
> good idea and I'm sure that jacking those rates up is a lousy way to
> mitigate the transfer. It is also interesting to note that increasing
> the bytes sent per socket.send on the server side had no visible
> effect. Again, that was just a curious experiment.
>
> What bothers me is that I am sure sending data over the local loopback
> address should be blazing fast. 8.3 MB should be a breeze because I've
> transferred files over AIM to people connected to the same router as
> me and was able to send hundreds of megabytes in less than a two or
> three seconds. With that said, I feel like something about how I'm
> send/recv-ing the data is causing lots of overhead and that I can
> avoid reading the memory directly if I can speed that up.
>
> I guess now I'd like to know what are good practices in general to get
> better results with sockets on the same local machine. I'm only
> instantiating two sockets total right now - one client and one server,
> and the transfer is taking 15 seconds for only 8.3MB. If you guys have
> some good suggestions on how to better utilize sockets to transfer
> data at the speeds I know I should be able to achieve on a local
> machine, let me know what you do. At present, I find that using
> sockets in python requires very few steps so I'm not sure where I
> could really improve at this point.
>

I have found the stop-and-go between two processes on the same machine
leads to very poor throughput. By stop-and-go, I mean the producer and
consumer are constantly getting on and off of the CPU since the pipe
gets full (or empty for consumer). Note that a producer can't run at
its top speed as the scheduler will pull it out since it's output pipe
got filled up.

When you increased the underlying buffer, you mitigated a bit this
shuffling. And hence saw a slight increase in performance.

My guess that you can transfer across machines at real high speed, is
because there are no process swapping as producer and consumer run on
different CPUs (machines, actually).

Since the two processes are on the same machine, try using a temporary
file for IPC. This is not as efficient as real shared memory -- but it
does avoid the IPC stop-n-go. The producer can generate the multi-mega
byte file at one go and inform the consumer. The file-systems have
gone thru' decades of performance tuning that this job is done really
efficiently.

Thanks,
Karthik



> Thanks for the replies so far, I really appreciate you guys
> considering my situation and helping out.


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


Re: Pretty Scheme, ??? Python

2007-07-02 Thread Laurent Pointal
Neil Cerutti wrote:
...
> How can I make the Python more idiomatic Python?

Have you taken a look at pyparsing ?

http://pyparsing.wikispaces.com/


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


Re: Bug in Python class static variable?

2007-07-02 Thread Duncan Booth
Bruza <[EMAIL PROTECTED]> wrote:

> On Jul 2, 3:52 am, Duncan Booth <[EMAIL PROTECTED]> wrote:
>> Bruza <[EMAIL PROTECTED]> wrote:
>> > I am trying to define a class static variable. But the value of the
>> > static variable seems to be only defined inside the file that the
>> > class is declared. See the code below. When I run "python w.py", I
>> > got:
>>
>> When you run "python w.py" the *script* w.py is loaded as the module
>> __main__. Importing a module called 'w' creates a new module which is
>> unrelated to __main__. If you want access to variables defined in the
>> main script then you need to import __main__.
>>
>> Don't use 'from module import *':
>>
>> The import statements are executed when the interpreter reaches them
>> in the source. Even if you fix your code to import from __main__, the
>> values you try to import from __main__ won't exist when the import
>> statement executes: the first 'from a import *' will load and execute
>> all of module 'a', but when that executes 'from __main__ import *' it
>> just imports names defined in the main script *before* a was
>> imported. 
>>
>> In general, don't try to do this: put all your classes into modules
>> and just put minimal startup code into a script.
> 
> Duncan,
> 
> Thanks for replying. However, I am still confused...
> Even if I put "from __main__ import *" in both "a.py" and "w.py", I
> still got
> the same results. So, how should I re-structure my program to make the
> class
> static variable works???
> 
Option 1:
In w.py put:

import a

and then refer to a.ClassA

In a.py put:

import __main__

and then refer to __main__.ClassW

But better, option 2:

Create a new file script.py which contains:

import w
if __name__=='__main__':
w.startup()

then in a use 'import w' and in w use 'import a' and refer to a.ClassA and 
w.ClassW as above.

Try to think through the order in which Python interprets your code: 
remember everything is interpreted. Both 'import' statements and 'class' 
statements are really just variation on an assignment, so none of the names 
exist until the lines which declare them have been executed. A line 'import 
a' is roughly the same as:

   a = __import__(something)

and a statement such as 'class ClassA: whatever' is roughly the same as:

  ClassA = type('ClassA', baseclasses, dict)

You should never attempt to use the 'from X import *' form of import when 
you have modules which include each other (you might get away with it if 
you move the imports to the end of the module instead of the beginning, but 
it is much simpler just to import the modules, and good practice in any 
case).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python compilation ??

2007-07-02 Thread Michael Hoffman
Steve Holden wrote:
> Evan Klitzke wrote:
>> On 7/2/07, Cathy Murphy <[EMAIL PROTECTED]> wrote:
>>> Is python a compiler language or interpreted language. If it is 
>>> interpreter
>>> , then why do we have to compile it?
>>
>> It's an interpreted language. It is compiled into bytecode (not
>> machine code) the first time a script is run to speed up subsequent
>> executions of a script.
>>
> While the flavor of this answer is correct, in strict point of fact 
> Python *doesn't* compile the scripts it executes, only the modules that 
> are imported.

I think you mean that CPython doesn't save the results of the 
compilation of a script. The scripts are compiled every time they are 
run, as you go on to say.
-- 
Michael Hoffman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: howto resend args and kwargs to other func?

2007-07-02 Thread Duncan Booth
Sion Arrowsmith <[EMAIL PROTECTED]> wrote:

> Frank Swarbrick  <[EMAIL PROTECTED]> wrote:
>>dmitrey wrote:
>>> Thanks all, I have solved the problem.
>>Why do people do this without posting what the actual solution is
> 
> Hey, if we're expected to magically deduce what the problem is
> without being told an error messages, surely we can magically
> deduce the discovered solution too?
> 
Quite so. Meanwhile the OP is killfiled so can't expect any help from me in 
the future.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: subprocess -- broken pipe error

2007-07-02 Thread 7stud
On Jul 2, 2:12 pm, Steve Holden <[EMAIL PROTECTED]> wrote:
> a) Who told you pipes should be unbuffered by default, and b) what difference
> does that make anyway?
>

a) The docs.

b) If the pipes were buffered then writing a small amount of data like
"text3" to the pipe would cause the other side to hang forever thereby
providing a possible explanation for the results.

>
> > It just hangs, and then when I hit Ctrl+C and look in the file, the
> > data isn't in there.
>
> Of course it does, for the reasons mentioned above. file.read() only
> returns when it has consumed *all* the data from the file (which means
> the write must close the file for the reader to be able to return).
>

That doesn't seem like a very good explanation, since the only thing
written to the file(i.e. stdin) was "text3", and the write() was
unbuffered, so the read() could consume all the data without the
write() closing the file--there was no more data.

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


Re: Python compilation ??

2007-07-02 Thread Jean-Paul Calderone
On Mon, 02 Jul 2007 16:14:41 -0400, Steve Holden <[EMAIL PROTECTED]> wrote:
>Evan Klitzke wrote:
>> On 7/2/07, Cathy Murphy <[EMAIL PROTECTED]> wrote:
>>> Is python a compiler language or interpreted language. If it is interpreter
>>> , then why do we have to compile it?
>>
>> It's an interpreted language. It is compiled into bytecode (not
>> machine code) the first time a script is run to speed up subsequent
>> executions of a script.
>>
>While the flavor of this answer is correct, in strict point of fact
>Python *doesn't* compile the scripts it executes, only the modules that
>are imported.
>
>That's why you will occasionally see a very small Python program that
>just calls functions imported from much larger modules. This avoids
>spending the time that would otherwise have to be spent recompiling a
>large script at each execution.

Hey Steve,

To nit pick :)  Wouldn't you say it is more accurate to say that it
does compile the scripts (by which we mean the "main" file - either
the one passed as an argument to the interpreter on the command line,
or the one with a #! at the top which gets respected, or the .py file
on Windows which is associated with python.exe as its interpreter),
but that it doesn't save the results of this compilation to a file to
be used next time?

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


python script for monitoring input/output parameters of online gaming client

2007-07-02 Thread jj kk

Hi,

I'd like to be able to capture parameters of online gaming client
applications (the kind of client software you install to play poker,
backgammon... online) with the aim of writing python software that analyzes
this data.

I'm clueless, as I know next to nothing about python networking. Could
anyone please point out in what direction I should look to solve this, what
libraries I should look at, etc. ?

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

python script for monitoring input/output parameters of online gaming client

2007-07-02 Thread jj kk

Hi,

I'd like to be able to capture parameters of online gaming client
applications (the kind of client software you install to play poker,
backgammon... online) with the aim of writing python software that analyzes
this data.

I'm clueless, as I know next to nothing about python networking. Could
anyone please point out in what direction I should look to solve this, what
libraries I should look at, etc. ?

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

Dynamic Language Ninja (or Pirate) - Telecommuting Allowed

2007-07-02 Thread [EMAIL PROTECTED]
I searched for old messages containing job posts, and saw no one
complaining, so I assume it is ok to post here. Please accept my
apologies if it is not. That said, here's our position!

Dynamic Language Ninja (or Pirate)

Etsy is an online marketplace for buying and selling all things
handmade: clothing, music, furniture, software, jewelry, robots. We
launched on June 18, 2005, and ever since then have been empowering
our users to make a living doing what they love most.

We are seeking an experienced dynamic language devotee to join our web
development effort. You'll be using python, javascript and other
technologies to whip up innovative web applications in many
challenging and interesting domains: social and community, ecommerce,
search, and even software development.

Please take a moment to read through the more detailed requirements
listed below to insure that you are the right person for the job. If
so, send an email introducing yourself to [EMAIL PROTECTED], being sure to
include your resume and an answer to the programming challenge at the
bottom.

Required:
 * 5+ years of web development experience
 * 3+ years of writing production-level code with a dynamic language
(python, ruby, lisp, smalltalk, OO javascript, etc)
 * Strong OOP skills
 * Understanding of dynamic language idioms and patterns
 * Ability and willingness to pick up other languages and technologies

Desired:
 * Ability to write python code idiomatically
 * Experience with javascript
 * Experience with the django framework
 * Experience with java, postgresql and/or php

Neat:
 * Lives in South Bay California, New York City or South Florida
 * Plays guitar hero


Challenge:
A valid answer will be either a solution to the problem below, or a
link to some code of which you are particularly proud.

Problem: In the dynamic language of your choice, write a short program
that will:

 1. define a list of the following user ids 42346, 77290, 729 (you can
hardcode these, but it should still work with more or less ids)
 2. retrieve an xml document related to each user at this url "http://
api.etsy.com/feeds/xml_user_details.php?id="
 3. retrieve the data contained in the city element from each xml
document
 4. keep a running total of how many users are found in each city
 5. display the total count of users living in each city

You can assume user ids are valid and that the url is available. The
output should look something like:

Charlotte: 1
New York: 2

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


Re: PEP 3107 and stronger typing (note: probably a newbie question)

2007-07-02 Thread Donn Cave
In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] (Alex Martelli) wrote:

> "Dynamic typing is recommended", they conclude, "when programs must be 
> as flexible as possible".  I recommend reading the Agile Manifesto to 
> understand why maximal flexibility is crucial in most real-world 
> application programming -- and therefore why, in said real world rather
> than in the more academic circles Dr. Van Roy and Dr. Hadidi move in, 
> dynamic typing is generally preferable, and not such a tiny issue as 
> they make the difference to be.

I guess there may be more than one kind of flexibility.  The language
I fool around with sometimes that has strong static typing is Haskell.
Though a relatively elementary Haskell programmer (the learning curve
with this language is something you would have to experience to believe),
I feel that the type checking actually helps me program faster.
The compiler's check for structural correctness is after all for my
benefit, and expedites development and maintenance of code, in my
limited experience.  The more extensive my changes, the more useful
the type checking is - I'm much more casual about significant code
revision when writing in Haskell, somewhat more casual when writing
in C, and worried when writing Python.

This is the kind of flexibility where you make significant changes
to something, but the result is as structurally consistent as it
would have been if written that way from the start.  I have also
seen the kind of flexibility where you use expedient hacks to make
changes with relatively small amounts of code, and I've seen it in
Python applications.  It's flexibility when you're doing it, but
it paradoxically causes rigidity as the hacks create more points
of articulation and more things that aren't obvious to the person
making the changes.  If that's flexibility, you can have it.

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


Re: Pretty Scheme, ??? Python

2007-07-02 Thread Neil Cerutti
On 2007-07-02, Laurent Pointal <[EMAIL PROTECTED]> wrote:
> Neil Cerutti wrote:
>> How can I make the Python more idiomatic Python?
>
> Have you taken a look at pyparsing ?

Yes, I have it. PyParsing has, well, so many convenience features
they seem to shout down whatever the core features are, and I
don't know quite how to get started as a result.

Hardest of all was modifying a working PyParsing program.

As a result, I've found writing my own recursive descent parsers
much easier.

I'm probably wrong, though. ;)

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


Correct abstraction for TK

2007-07-02 Thread luke . hoersten
I'm looking for a good example of how to correctly abstract TK code
from the rest of my program. I want to just get some user info and
then get 4 values from the GUI. Right now I've written it OOP per the
examples on python.org but it doesn't seem to be meshing very well
with the rest of my project.

Can anyone suggest some examples so that I can get more ideas?

Thanks,
Luke

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


Re: PEP 3107 and stronger typing (note: probably a newbie question)

2007-07-02 Thread Steve Holden
Donn Cave wrote:
> In article <[EMAIL PROTECTED]>,
>  [EMAIL PROTECTED] (Alex Martelli) wrote:
> 
>> "Dynamic typing is recommended", they conclude, "when programs must be 
>> as flexible as possible".  I recommend reading the Agile Manifesto to 
>> understand why maximal flexibility is crucial in most real-world 
>> application programming -- and therefore why, in said real world rather
>> than in the more academic circles Dr. Van Roy and Dr. Hadidi move in, 
>> dynamic typing is generally preferable, and not such a tiny issue as 
>> they make the difference to be.
> 
> I guess there may be more than one kind of flexibility.  The language
> I fool around with sometimes that has strong static typing is Haskell.
> Though a relatively elementary Haskell programmer (the learning curve
> with this language is something you would have to experience to believe),
> I feel that the type checking actually helps me program faster.
> The compiler's check for structural correctness is after all for my
> benefit, and expedites development and maintenance of code, in my
> limited experience.  The more extensive my changes, the more useful
> the type checking is - I'm much more casual about significant code
> revision when writing in Haskell, somewhat more casual when writing
> in C, and worried when writing Python.
> 
> This is the kind of flexibility where you make significant changes
> to something, but the result is as structurally consistent as it
> would have been if written that way from the start.  I have also
> seen the kind of flexibility where you use expedient hacks to make
> changes with relatively small amounts of code, and I've seen it in
> Python applications.  It's flexibility when you're doing it, but
> it paradoxically causes rigidity as the hacks create more points
> of articulation and more things that aren't obvious to the person
> making the changes.  If that's flexibility, you can have it.
> 
Indeed you describe an arthritic design quite well, but I don't think 
it's fair to single Python out as a potential problem. As we have known 
for a long time you can write unstructured code in almost any language, 
and you can do structured programming in almost any language given 
discipline.

I certainly agree that if the programmer shows insufficient discipline 
the results will likely be bad, but in that light Haskell is really the 
ultimate bondage language. Some of us don't like to be tied that tightly.

I don't feel the same trepidation you appear to do when refactoring 
Python code. I suppose I might say that in my experience Python allows 
you to appreciate a better-engineered solution more easily, and so it 
tends to encourage better engineering.

In some ways C# is quite Python-like, and I am beginning to enjoy 
writing it from time to time, but when you are dealing with amorphous 
collections the casting and conversions can drive you almost insane. And 
since the collections are ultimately collections of Object, none of it 
actually gets you any nearer your programming goal.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


Re: object references/memory access

2007-07-02 Thread Steve Holden
Karthik Gurusamy wrote:
> On Jul 1, 12:38 pm, dlomsak <[EMAIL PROTECTED]> wrote:
[...]
> 
> I have found the stop-and-go between two processes on the same machine
> leads to very poor throughput. By stop-and-go, I mean the producer and
> consumer are constantly getting on and off of the CPU since the pipe
> gets full (or empty for consumer). Note that a producer can't run at
> its top speed as the scheduler will pull it out since it's output pipe
> got filled up.
> 
But when both processes are in the memory of the same machine and they 
communicate through an in-memory buffer, what's to stop them from 
keeping the CPU fully-loaded (assuming they are themselves compute-bound)?

> When you increased the underlying buffer, you mitigated a bit this
> shuffling. And hence saw a slight increase in performance.
> 
> My guess that you can transfer across machines at real high speed, is
> because there are no process swapping as producer and consumer run on
> different CPUs (machines, actually).
> 
As a concept that's attractive, but it's easy to demonstrate that (for 
example) two machines will get much better throughput using the 
TCP-based FTP to transfer a large file than they do with the UDP-based 
TFTP. This is because the latter protocol requires the sending unit to 
stop and wait for an acknowledgment for each block transferred. With 
FTP, if you use a large enough TCP sliding window and have enough 
content, you can saturate a link as ling as its bandwidth isn't greater 
than your output rate.

This isn't a guess ...

> Since the two processes are on the same machine, try using a temporary
> file for IPC. This is not as efficient as real shared memory -- but it
> does avoid the IPC stop-n-go. The producer can generate the multi-mega
> byte file at one go and inform the consumer. The file-systems have
> gone thru' decades of performance tuning that this job is done really
> efficiently.
> 
I'm afraid this comes across a bit like superstition. Do you have any 
evidence this would give superior performance?
> 
> 
>> Thanks for the replies so far, I really appreciate you guys
>> considering my situation and helping out.
> 
> 
regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


Re: Python compilation ??

2007-07-02 Thread Steve Holden
Jean-Paul Calderone wrote:
> On Mon, 02 Jul 2007 16:14:41 -0400, Steve Holden <[EMAIL PROTECTED]> wrote:
>> Evan Klitzke wrote:
>>> On 7/2/07, Cathy Murphy <[EMAIL PROTECTED]> wrote:
 Is python a compiler language or interpreted language. If it is interpreter
 , then why do we have to compile it?
>>> It's an interpreted language. It is compiled into bytecode (not
>>> machine code) the first time a script is run to speed up subsequent
>>> executions of a script.
>>>
>> While the flavor of this answer is correct, in strict point of fact
>> Python *doesn't* compile the scripts it executes, only the modules that
>> are imported.
>>
>> That's why you will occasionally see a very small Python program that
>> just calls functions imported from much larger modules. This avoids
>> spending the time that would otherwise have to be spent recompiling a
>> large script at each execution.
> 
> Hey Steve,
> 
> To nit pick :)  Wouldn't you say it is more accurate to say that it
> does compile the scripts (by which we mean the "main" file - either
> the one passed as an argument to the interpreter on the command line,
> or the one with a #! at the top which gets respected, or the .py file
> on Windows which is associated with python.exe as its interpreter),
> but that it doesn't save the results of this compilation to a file to
> be used next time?
> 
> Jean-Paul

Absolutely. I should, of course, have said that only imported modules 
have the results of the compilation stored as a .pyc file.

One must presume this is to save the file write time during development 
when the program is almost always different fro the last time you ran it.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: subprocess -- broken pipe error

2007-07-02 Thread Steve Holden
7stud wrote:
> On Jul 2, 1:58 pm, Bjoern Schliessmann  [EMAIL PROTECTED]> wrote:
>> 7stud wrote:
>>> Thanks for the response.  So are you saying that the only way you
>>> can get data out of a pipe is when the subprocess has terminated?
>> No, not only because Pipes aren't related to processes in any
>> special way.
>>
>> He said that you can't write to a pipe whose reader has already
>> terminated.
>>
> 
> What he said was:
> 
>> ...once the subprocess terminates (which it must have done for
>> p.stdout.read() to return a result)
> 
> And based on the results of the examples I posted in my last post, it
> seems to confirm that no data travels through a pipe until a program
> on one side of the pipe has terminated.
> 
No, you plonker!

No data is produced *by .read()* until the writer has closed it.

I really don't remember anyone in recent history as eager to willfully 
misunderstand any attempted assistance. Please try to read what is 
written more carefully. It's most annoying when "the better the advice 
the worse it's wasted", as the Scots say.

Please forgive my brusqueness.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


Re: subprocess -- broken pipe error

2007-07-02 Thread Steve Holden
7stud wrote:
> On Jul 2, 2:12 pm, Steve Holden <[EMAIL PROTECTED]> wrote:
>> a) Who told you pipes should be unbuffered by default, and b) what difference
>> does that make anyway?
>>
> 
> a) The docs.
> 
> b) If the pipes were buffered then writing a small amount of data like
> "text3" to the pipe would cause the other side to hang forever thereby
> providing a possible explanation for the results.
> 
>>> It just hangs, and then when I hit Ctrl+C and look in the file, the
>>> data isn't in there.
>> Of course it does, for the reasons mentioned above. file.read() only
>> returns when it has consumed *all* the data from the file (which means
>> the write must close the file for the reader to be able to return).
>>
> 
> That doesn't seem like a very good explanation, since the only thing
> written to the file(i.e. stdin) was "text3", and the write() was
> unbuffered, so the read() could consume all the data without the
> write() closing the file--there was no more data.
> 
[sigh].

So please explain how the receiving process mysteriously manages to look 
inside your producer process to know that it is never going to produce 
any more data. Let's (briefly) look at the docs for read():

"""
read( [size])

Read at most size bytes from the file (less if the read hits EOF before 
obtaining size bytes). If the size argument is negative or omitted, read 
all data until EOF is reached. ...
"""

I believe you omitted the argument. As I have explained, the read() call 
therefore waits until the writer has closed the file. Which is what 
makes the EOF indication appear.

And please stop dragging buffering into this as a red herring. You do 
know what buffering *is*, I take it? The read() call buffers even an 
unbuffered source, by definition.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


Re: Correct abstraction for TK

2007-07-02 Thread Adonis Vargas
[EMAIL PROTECTED] wrote:
> I'm looking for a good example of how to correctly abstract TK code
> from the rest of my program. I want to just get some user info and
> then get 4 values from the GUI. Right now I've written it OOP per the
> examples on python.org but it doesn't seem to be meshing very well
> with the rest of my project.
> 
> Can anyone suggest some examples so that I can get more ideas?
> 
> Thanks,
> Luke
> 

I would not consider this to be 'correct' as many have different 
philosophies on how to tackle certain projects. My way of doing 
programming with GUI is writing it in 'tiers' (using this word loosely).

i.e.

import Tkinter as tk

class UsersInfo:

 pass

class Events(UserInfo):

 pass

class GUI(Events):

 pass

This way your GUI class sends events to the Events class to act upon the 
UserInfo class. For the GUI class here all you do is code the actual 
display and the callbacks only. Then in the Events class you code the 
actions you want to happen when you interact the the GUI. Since the GUI 
class inherits the Events class, in the GUI class you would simply call 
a method found in the Events class when an event is triggered. Now the 
Events class which inherits the UserInfo class, you can start using the 
class to store/modify the user data you desire. Now your code is 
separated into more comprehensible, and easier to manage sections. In 
this example I am using inheritance, but if you prefer delegation, then 
that too can be done here. Also, by doing this it will simplify the 
moving to more robust graphic toolkits with little modification.

Hope this helps.

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


Programming Idiomatic Code

2007-07-02 Thread Nathan Harmston
Hi,

I m sorry but I m bored at work (and no ones looking so I can write
some Python) and following a job advertisement post,I decided to write
the code to do its for the one entitled Ninjas or something like that.
I was wondering what could be done to my following code to make it
more idiomatic...or whether it was idiomatic and to be honest what
idiomatic really means. All comments greatly appreciated and welcomed.

Thanks in advance

Nathan

import urllib2,sys
from elementtree.ElementTree import parse

base_url = "http://api.etsy.com/feeds/xml_user_details.php?id=";

def read_id_file(filename):
""" reads a file and generates a list of ids from it"""
ids = [ ]
try:
id_file = open(filename, "r")
for l in id_file:
ids.append( l.strip("\n") )
id_file.close()
except e:
print e
os._exit(99)
return ids

def generate_count(id_list):
""" takes a list of ids and returns a dictionary of cities with
associated counts"""
city_count = {}
for i in id_list:
url = "%s%s" %(base_url,i)
req = urllib2.Request(url)
try:
xml = parse(urllib2.urlopen(url)).getroot()
city  = xml.findtext('user/city')
except e:
print e.reason
os._exit(99)
try:
city_count[city] += 1
except:
city_count[city] = 1
return city_count

if __name__=='__main__':
if len(sys.argv) is 1:
id_list = [ 42346, 77290, 729 ]
else:
try: id_list = read_id_file(sys.argv[1])
except e: print e
for k, v in generate_count(id_list).items():
print "%s: %i" %(k, v)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to FTP a ASCII file

2007-07-02 Thread John Machin
On Jul 3, 9:02 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> Hi,
>
> My program has the following code to transfer a binary file
>
> f = open(pathanme+filename,'rb')
> print "start transfer"
> self.fthHandle.storbinary('STOR '+filename, f)
>
> How can I do an ASCII file transfer??
> -Ted

I'm really curious as to how you could find out how to upload a file
in binary mode, but not in ASCII mode.

According to The Fantastic Manual:
"""
storbinary( command, file[, blocksize])

Store a file in binary transfer mode. command should be an appropriate
"STOR" command: "STOR filename". file is an open file object which is
read until EOF using its read() method in blocks of size blocksize to
provide the data to be stored. The blocksize argument defaults to
8192. Changed in version 2.1: default for blocksize added.

storlines( command, file)

Store a file in ASCII transfer mode. command should be an appropriate
"STOR" command (see storbinary()). Lines are read until EOF from the
open file object file using its readline() method to provide the data
to be stored.
"""

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


Re: object references/memory access

2007-07-02 Thread Karthik Gurusamy
On Jul 2, 3:01 pm, Steve Holden <[EMAIL PROTECTED]> wrote:
> Karthik Gurusamy wrote:
> > On Jul 1, 12:38 pm, dlomsak <[EMAIL PROTECTED]> wrote:
> [...]
>
> > I have found the stop-and-go between two processes on the same machine
> > leads to very poor throughput. By stop-and-go, I mean the producer and
> > consumer are constantly getting on and off of the CPU since the pipe
> > gets full (or empty for consumer). Note that a producer can't run at
> > its top speed as the scheduler will pull it out since it's output pipe
> > got filled up.
>
> But when both processes are in the memory of the same machine and they
> communicate through an in-memory buffer, what's to stop them from
> keeping the CPU fully-loaded (assuming they are themselves compute-bound)?

If you are a producer and if your output goes thru' a pipe, when the
pipe gets full, you can no longer run. Someone must start draining the
pipe.
On a single core CPU when only one process can be running, the
producer must get off the CPU so that the consumer may start the
draining process.

>
> > When you increased the underlying buffer, you mitigated a bit this
> > shuffling. And hence saw a slight increase in performance.
>
> > My guess that you can transfer across machines at real high speed, is
> > because there are no process swapping as producer and consumer run on
> > different CPUs (machines, actually).
>
> As a concept that's attractive, but it's easy to demonstrate that (for
> example) two machines will get much better throughput using the
> TCP-based FTP to transfer a large file than they do with the UDP-based
> TFTP. This is because the latter protocol requires the sending unit to
> stop and wait for an acknowledgment for each block transferred. With
> FTP, if you use a large enough TCP sliding window and have enough
> content, you can saturate a link as ling as its bandwidth isn't greater
> than your output rate.
>
> This isn't a guess ...

What you say about a stop-n-wait protocol versus TCP's sliding window
is correct.
But I think it's totally orthogonal to the discussion here. The issue
I'm talking about is how to keep the end nodes chugging along, if they
are able to run simultaneously. They can't if they aren't on a multi-
core CPU or one different machines.


>
> > Since the two processes are on the same machine, try using a temporary
> > file for IPC. This is not as efficient as real shared memory -- but it
> > does avoid the IPC stop-n-go. The producer can generate the multi-mega
> > byte file at one go and inform the consumer. The file-systems have
> > gone thru' decades of performance tuning that this job is done really
> > efficiently.
>
> I'm afraid this comes across a bit like superstition. Do you have any
> evidence this would give superior performance?
>

I did some testing before when I worked on boosting a shell pipeline
performance and found using file-based IPC was very good.
(some details at 
http://kar1107.blogspot.com/2006/09/unix-shell-pipeline-part-2-using.html
)

Thanks,
Karthik

> >> Thanks for the replies so far, I really appreciate you guys
> >> considering my situation and helping out.
>
> regards
>   Steve
> --
> Steve Holden+1 571 484 6266   +1 800 494 3119
> Holden Web LLC/Ltd  http://www.holdenweb.com
> Skype: holdenweb  http://del.icio.us/steve.holden
> --- Asciimercial --
> Get on the web: Blog, lens and tag the Internet
> Many services currently offer free registration
> --- Thank You for Reading -


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


Re: Pretty Scheme, ??? Python

2007-07-02 Thread Paul McGuire
On Jul 2, 3:56 pm, Neil Cerutti <[EMAIL PROTECTED]> wrote:
> On 2007-07-02, Laurent Pointal <[EMAIL PROTECTED]> wrote:
>
> > Neil Cerutti wrote:
> >> How can I make the Python more idiomatic Python?
>
> > Have you taken a look at pyparsing ?
>
> Yes, I have it. PyParsing has, well, so many convenience features
> they seem to shout down whatever the core features are, and I
> don't know quite how to get started as a result.
>
> Hardest of all was modifying a working PyParsing program.
>
> As a result, I've found writing my own recursive descent parsers
> much easier.
>
> I'm probably wrong, though. ;)
>
> --
> Neil Cerutti

from pyparsing import *

"""
Neil -

Ok, here is the step-by-step, beginning with your posted BNF.  (Based
on your test cases, I think the '{}'s are really supposed to be
'()'s.)

;  ::=
;   
;   | { +   }
;   | { -   }
;   | {with { } }
;   | 

The most basic building blocks in pyparsing are Literal and Word.
With these, you compose "compound" elements using And and MatchFirst,
which are bound to the operators '+' and '|' (on occasion, Or is
required, bound to operator '^', but not for this simple parser).
Since you have a recursive grammar, you will also need Forward.
Whitespace is skipped implicitly.

Only slightly more advanced is the Group class, which will impart
hierarchy and structure to the results - otherwise, everything just
comes out as one flat list of tokens.  You may be able to remove these
in the final parser, depending on your results after steps 1 and 2 in
the "left for the student" part below, but they are here to help show
structure of the parsed tokens.

As convenience functions go, I think the most common are oneOf and
delimitedList.  oneOf might be useful here if you want to express id
as a single-char variable; otherwise, just use Word(alphas).

At this point you should be able to write a parser for this WAE
grammar.  Like the following 9-liner:
"""

LPAR = Literal("(").suppress()
RPAR = Literal(")").suppress()

wae = Forward()
num = Word(nums)
id = oneOf( list(alphas) )
addwae = Group( LPAR + "+" + wae + wae + RPAR )
subwae = Group( LPAR + "-" + wae + wae + RPAR )
withwae = Group( LPAR + "with" + LPAR + id + wae + RPAR + wae + RPAR )

wae << (addwae | subwae | withwae | num | id)

tests = """\
 3
 (+ 3 4)
 (with (x (+ 5 5)) (+ x x))""".splitlines()

for t in tests:
print t
waeTree = wae.parseString(t)
print waeTree.asList()
print

"""
If you extract and run this script, here are the results:
 3
['3']

 (+ 3 4)
[['+', '3', '4']]

 (with (x (+ 5 5)) (+ x x))
[['with', 'x', ['+', '5', '5'], ['+', 'x', 'x']]]


Left as an exercise for the student:
1. Define classes NumWAE, IdWAE, AddWAE, SubWAE, and WithWAE whose
__init__ methods take a ParseResults object named tokens (which you
can treat as a list of tokens), and each with a calc() method to
evaluate them accordingly.
2. Hook each class to the appropriate WAE class using setParseAction.
Hint: here is one done for you:  num.setParseAction(NumWAE)
3. Modify the test loop to insert an evaluation of the parsed tree.

Extra credit: why is id last in the set of alternatives defined for
the wae expression?

-- Paul
"""


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


Re: How to FTP a ASCII file

2007-07-02 Thread Adonis Vargas
[EMAIL PROTECTED] wrote:
> Hi,
> 
> My program has the following code to transfer a binary file
> 
> f = open(pathanme+filename,'rb')
> print "start transfer"
> self.fthHandle.storbinary('STOR '+filename, f)
> 
> How can I do an ASCII file transfer??
> -Ted
> 

Taken from online documentation:

http://docs.python.org/lib/ftp-objects.html

storlines(command, file)

Store a file in ASCII transfer mode. command should be an appropriate 
"STOR" command (see storbinary()). Lines are read until EOF from the 
open file object file using its readline() method to provide the data to 
be stored.

Hope this helps.

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


Re: Tiny/small/minimalist Python?

2007-07-02 Thread rtk
On Jul 2, 9:43 am, Paul Rubin  wrote:
> rtk <[EMAIL PROTECTED]> writes:
> > FYI.. I wanted a simple version of Python to run on an ancient DEC
> > Alpha box.  I got VMS Python 2.5 up and running but it is too slow to
> > use.  It takes *minutes* to get the interpreter prompt after typing
> > 'python'!
>
> Something is wrong.  Maybe it's trying to DNS itself and timing out,
> or something like that.

The trouble is that the Alpha is too old.  VMS Python is compiled for
a newer machine with a different instruction set and the Alpha is
emulating the machine instructions it does not have (a nice feature of
OpenVMS, but of dubious value).

For my needs, the effort of recompiling all of Python wasn't worth
it.  Since Lua runs under Unix it will be perfect for my project.  I'm
writing a compiler for a simple language to 6502 assembly code.  I've
already written one in Python for small PIC microcontrollers (see PIC0
at http://www.geocities.com/oneelkruns/) and was planning on using
Python for this compiler project as well but it will be fun to use
something new, too.  I am thinking of doing most of the development in
OpenVMS, just for the heck of it.

Ron

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


Re: Probably simple syntax error

2007-07-02 Thread John Machin
On Jul 3, 9:04 am, Dustin  MacDonald <[EMAIL PROTECTED]> wrote:

> And Cameron: Ah, yes. It does reduce the confusion. I do know that
> square brackets are used for *creating* a dictionary (blah = ["A",
> "B", "C"],

That's a list, not a dictionary.

> so I figured the same would apply to accessing it (which is
> why for my list, which I created with parenthesis I assumed I accessed
> with parenthesis).

If you created it with parentheses, it's not a list, it's a tuple.
Problem 10: Tuples are immutable.
atuple[index_variable] = something
and
atuple.append(something)
will fail.

Print this, cut it out, and paste it inside your hat:
"""
alist = ['foo', 42, True, 123.456]
assert alist[1] == 42

atuple = ('foo', 42, True, 123.456)
assert atuple[1] == 42

adict = {'bar': 'foo', 1: 42, 'abool': True, 'afloat': 123.456}
assert adict[1] == 42
"""

and, in general:

Abjure guesswork, read the documentation!

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


Re: Pretty Scheme, ??? Python

2007-07-02 Thread Paul McGuire
On Jul 2, 6:28 pm, Paul McGuire <[EMAIL PROTECTED]> wrote:
> On Jul 2, 3:56 pm, Neil Cerutti <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > On 2007-07-02, Laurent Pointal <[EMAIL PROTECTED]> wrote:
>
> > > Neil Cerutti wrote:
> > >> How can I make the Python more idiomatic Python?
>
> > > Have you taken a look at pyparsing ?
>
> > Yes, I have it. PyParsing has, well, so many convenience features
> > they seem to shout down whatever the core features are, and I
> > don't know quite how to get started as a result.
>
> > Hardest of all was modifying a working PyParsing program.
>
> > As a result, I've found writing my own recursive descent parsers
> > much easier.
>
> > I'm probably wrong, though. ;)
>
> > --
> > Neil Cerutti
>
> from pyparsing import *
>
> """
> Neil -
>
> Ok, here is the step-by-step, beginning with your posted BNF.  (Based
> on your test cases, I think the '{}'s are really supposed to be
> '()'s.)
>
> ;  ::=
> ;   
> ;   | { +   }
> ;   | { -   }
> ;   | {with { } }
> ;   | 
>
> The most basic building blocks in pyparsing are Literal and Word.
> With these, you compose "compound" elements using And and MatchFirst,
> which are bound to the operators '+' and '|' (on occasion, Or is
> required, bound to operator '^', but not for this simple parser).
> Since you have a recursive grammar, you will also need Forward.
> Whitespace is skipped implicitly.
>
> Only slightly more advanced is the Group class, which will impart
> hierarchy and structure to the results - otherwise, everything just
> comes out as one flat list of tokens.  You may be able to remove these
> in the final parser, depending on your results after steps 1 and 2 in
> the "left for the student" part below, but they are here to help show
> structure of the parsed tokens.
>
> As convenience functions go, I think the most common are oneOf and
> delimitedList.  oneOf might be useful here if you want to express id
> as a single-char variable; otherwise, just use Word(alphas).
>
> At this point you should be able to write a parser for this WAE
> grammar.  Like the following 9-liner:
> """
>
> LPAR = Literal("(").suppress()
> RPAR = Literal(")").suppress()
>
> wae = Forward()
> num = Word(nums)
> id = oneOf( list(alphas) )
> addwae = Group( LPAR + "+" + wae + wae + RPAR )
> subwae = Group( LPAR + "-" + wae + wae + RPAR )
> withwae = Group( LPAR + "with" + LPAR + id + wae + RPAR + wae + RPAR )
>
> wae << (addwae | subwae | withwae | num | id)
>
> tests = """\
>  3
>  (+ 3 4)
>  (with (x (+ 5 5)) (+ x x))""".splitlines()
>
> for t in tests:
> print t
> waeTree = wae.parseString(t)
> print waeTree.asList()
> print
>
> """
> If you extract and run this script, here are the results:
>  3
> ['3']
>
>  (+ 3 4)
> [['+', '3', '4']]
>
>  (with (x (+ 5 5)) (+ x x))
> [['with', 'x', ['+', '5', '5'], ['+', 'x', 'x']]]
>
> Left as an exercise for the student:
> 1. Define classes NumWAE, IdWAE, AddWAE, SubWAE, and WithWAE whose
> __init__ methods take a ParseResults object named tokens (which you
> can treat as a list of tokens), and each with a calc() method to
> evaluate them accordingly.
> 2. Hook each class to the appropriate WAE class using setParseAction.
> Hint: here is one done for you:  num.setParseAction(NumWAE)
> 3. Modify the test loop to insert an evaluation of the parsed tree.
>
> Extra credit: why is id last in the set of alternatives defined for
> the wae expression?
>
> -- Paul
> """- Hide quoted text -
>
> - Show quoted text -

Oops, that should be a 10-liner - I forgot the "from pyparsing import
*" line.

-- Paul

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


Re: Tiny/small/minimalist Python?

2007-07-02 Thread Irmen de Jong
Paul Rubin wrote:
> rtk <[EMAIL PROTECTED]> writes:
>> FYI.. I wanted a simple version of Python to run on an ancient DEC
>> Alpha box.  I got VMS Python 2.5 up and running but it is too slow to
>> use.  It takes *minutes* to get the interpreter prompt after typing
>> 'python'! 
> 
> Something is wrong.  Maybe it's trying to DNS itself and timing out,
> or something like that.

Something is definately wrong.

Back in the days my port of Python to the Commodore Amiga machine ran
quite comfortably on a 50 mhz CPU with 4 Mb of RAM. (ok ok it was
Python 1.5.2, that has to be said).
Python started in about 5 seconds on that Amiga if I remember
correctly. I'm quite sure your 'ancient' DEC Alpha box is way more
powerful than my Amiga back then.

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


Re: Python's "only one way to do it" philosophy isn't good?

2007-07-02 Thread Lenard Lindstrom
Douglas Alan wrote:
> Lenard Lindstrom <[EMAIL PROTECTED]> writes:
> 
 Explicitly clear the exception? With sys.exc_clear?
> 
>>> Yes.  Is there a problem with that?
> 
>> As long as nothing tries to re-raise the exception I doubt it breaks
>> anything:
>>
>>  >>> import sys
>>  >>> try:
>>  raise StandardError("Hello")
>> except StandardError:
>>  sys.exc_clear()
>>  raise
>>
>>
>> Traceback (most recent call last):
>>File "", line 5, in 
>>  raise
>> TypeError: exceptions must be classes, instances, or strings
>> (deprecated), not NoneType
> 
> I guess I don't really see that as a problem.  Exceptions should
> normally only be re-raised where they are caught.  If a piece of code
> has decided to handle an exception, and considers it dealt with, there
> is no reason for it not to clear the exception, and good reason for it
> to do so.

It is only a problem if refactoring the code could mean the exception is 
re-raised instead of handled at that point. Should the call to exc_clear 
be overlooked then the newly added raise will not work.

> Also, any caught exception is automatically cleared when
> the catching procedure returns anyway, so it's not like Python has
> ever considered a caught exception to be precious information that
> ought to be preserved long past the point where it is handled.
> 

That's the point. Python takes care of clearing the traceback. Calls to 
exc_clear are rarely seen. If they are simply a performance tweak then 
it's not an issue *. I was just concerned that the calls were necessary 
to keep resources from being exhausted.

>> But it is like calling the garbage collector. You are tuning the
>> program to ensure some resource isn't exhausted.
> 
> I'm not sure I see the analogy: Calling the GC can be expensive,
> clearing an exception is not.  The exception is going to be cleared
> anyway when the procedure returns, the GC wouldn't likely be.
> 

The intent of a high level language is to free the programmer from such 
concerns as memory management. So a call to the GC is out-of-place in a 
production program. Anyone encountering such a call would wonder what is 
so critical about that particular point in the execution. So 
encountering an exc_clear would make me wonder why it is so important to 
free that traceback. I would hope the comments would explain it.

> It's much more like explicitly assigning None to a variable that
> contains a large data structure when you no longer need the contents
> of the variable.  Doing this sort of thing can be a wise thing to do
> in certain situations.
> 

I just delete the name myself. But this is different. Removing a name 
from the namespace, or setting it to None, prevents an accidental access 
later. A caught traceback is invisible.

>> It relies on implementation specific behavior to be provably
>> reliable*.
> 
> As Python is not a formally standardized language, and one typically
> relies on the fact that CPython itself is ported to just about every
> platform known to Man, I don't find this to be a particular worry.
> 

But some things will make it into ISO Python. Registered exit handlers 
will be called at program termination. A context manager's __exit__ 
method will be called when leaving a with statement. But garbage 
collection will be "implementation-defined" **.

>> If this is indeed the most obvious way to do things in your
>> particular use case then Python, and many other languages, is
>> missing something. If the particular problem is isolated,
>> formalized, and general solution found, then a PEP can be
>> submitted. If accepted, this would ensure future and cross-platform
>> compatibility.
> 
> Well, I think that the refcounting semantics of CPython are useful,
> and allow one to often write simpler, easier-to-read and maintain
> code.

Just as long as you have weighed the benefits against a future move to a 
JIT-accelerated, continuation supporting PyPy interpreter that might not 
use reference counting.

> I think that Jython and IronPython, etc., should adopt these
> semantics, but I imagine they might not for performance reasons.  I
> don't generally use Python for it's speediness, however, but rather
> for it's pleasant syntax and semantics and large, effective library.
> 

Yet improved performance appeared to be a priority in Python 2.4 
development, and Python's speed continues to be a concern.


* I see in section 26.1 of the Python 2.5 /Python Library Reference/ as 
regards exc_clear: "This function can also be used to try to free 
resources and trigger object finalization, though no guarantee is made 
as to what objects will be freed, if any." So using exc_clear is not so 
much frowned upon as questioned.

** A term that crops up a lot in the C standard /ISO/IEC 9899:1999 (E)/. :-)

--
Lenard Lindstrom
<[EMAIL PROTECTED]>

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


Re: Python's "only one way to do it" philosophy isn't good?

2007-07-02 Thread Lenard Lindstrom
Douglas Alan wrote:
> Lenard Lindstrom <[EMAIL PROTECTED]> writes:
> 
>>> You don't necessarily want a function that raises an exception to
>>> deallocate all of its resources before raising the exception, since
>>> you may want access to these resources for debugging, or what have
>>> you.
> 
>> No problem:
>>
>> [...]
>>
>>  >>> class MyFile(file):
>>  def __exit__(self, exc_type, exc_val, exc_tb):
>>  if exc_type is not None:
>>  self.my_last_posn = self.tell()
>>  return file.__exit__(self, exc_type, exc_val, exc_tb)
> 
> I'm not sure I understand you here.  You're saying that I should have
> the foresight to wrap all my file opens is a special class to
> facilitate debugging?
> 
> If so, (1) I don't have that much foresight and don't want to have
> to.  (2) I debug code that other people have written, and they often
> have less foresight than me.  (3) It would make my code less clear to
> ever file open wrapped in some special class.
> 

Obviously you had the foresight to realize with statements could 
compromise debugging. I never considered it myself. I don't know the 
specifics of your particular project, what the requirements are. So I 
can't claim this is the right solution for you. But the option is available.

> Or are you suggesting that early in __main__.main(), when I wish to
> debug something, I do something like:
> 
>__builtins__.open = __builtins__.file = MyFile
> 
> ?
> 
> I suppose that would work.

No, I would never suggest replacing a builtin like that. Even replacing 
a definite hook like __import__ is risky, should more than one package 
try and do it in a program.

> I'd still prefer to clear exceptions,
> though, in those few cases in which a function has caught an exception
> and isn't going to be returning soon and have the resources generally
> kept alive in the traceback.  To me, that's the more elegant and
> general solution.
> 

As long as the code isn't dependent on explicitly cleared exceptions. 
But if it is I assume it is well documented.

--
Lenard Lindstrom
<[EMAIL PROTECTED]>

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


Re: Programming Idiomatic Code

2007-07-02 Thread Steve Lianoglou
I don't know about idiomatic, but here's a quick list of somethings
I'd change.

1) In general, I don't think it's a good idea for a called function to
blow out the system on error. So, in this example, I wouldn't have
raised errors be caught in the same function only to call os.exit. I'd
either deal with the exception in some sane way, or have it bubble up
to the caller to have it then decide what it should do in the face of
the error.


> def read_id_file(filename):
> """ reads a file and generates a list of ids from it"""
> ids = [ ]
> try:
> id_file = open(filename, "r")
> for l in id_file:
> ids.append( l.strip("\n") )
> id_file.close()
> except e:
> print e
> os._exit(99)
> return ids

Maybe use a list comprehension here (try/except clauses excluded in
reference to previous comment @ top)

def read_id_file(filename):
id_file = open(filename, 'r')
ids = [line.strip() for line in id_file.xreadlines()]
id_file.close()
return ids

If you're shooting for only Python 2.5, you can use ``with`` (see
http://docs.python.org/tut/node10.html#cleanup-with) to make that even
more concise.


> def generate_count(id_list):
> """ takes a list of ids and returns a dictionary of cities with
> associated counts"""
> city_count = {}
> for i in id_list:
> url = "%s%s" %(base_url,i)
> req = urllib2.Request(url)
> try:
> xml = parse(urllib2.urlopen(url)).getroot()
> city  = xml.findtext('user/city')
> except e:
> print e.reason
> os._exit(99)
> try:
> city_count[city] += 1
> except:
> city_count[city] = 1
> return city_count

I maybe wouldn't bail on the error raised when the ``parse`` function
is called ... I'd rather skip the error and try the next one (but
that's just my preference, not sure if it's good/bad style)

Also, instead of doing this:

> try:
>city_count[city] += 1
> except:
>city_count[city] = 1

I like using the dict.get() methods ... which would make that a one
liner:

city_count[city] = city_count.get(city, 0) + 1

Now I gotta get back to work, too ... good luck getting that job! ;-)

-steve

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


How to FTP a ASCII file

2007-07-02 Thread [EMAIL PROTECTED]
Hi,

My program has the following code to transfer a binary file

f = open(pathanme+filename,'rb')
print "start transfer"
self.fthHandle.storbinary('STOR '+filename, f)

How can I do an ASCII file transfer??
-Ted

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


Re: Probably simple syntax error

2007-07-02 Thread Dustin MacDonald
Ah. Thank you everyone. Sorry for not replying earlier, real life got
in the way :)

Gerry Herron, Tim Delaney, Mark Peters: Thank you. Switching from
parentheses to square brackets fixed the code, and yes, Tim, you were
right. It was a list I was working with. And thanks for those links
Tim.

John Machin: Thank you for all the pointers/code fixes there. They'll
help alot.

Ptn: I was unaware of that period added, Thanks, I'll have to watch
out for it. :)

And Cameron: Ah, yes. It does reduce the confusion. I do know that
square brackets are used for *creating* a dictionary (blah = ["A",
"B", "C"], so I figured the same would apply to accessing it (which is
why for my list, which I created with parenthesis I assumed I accessed
with parenthesis). Thank you =]

~Dustin

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


Re: Programming Idiomatic Code

2007-07-02 Thread attn . steven . kuo
On Jul 2, 5:22 pm, "Nathan Harmston" <[EMAIL PROTECTED]>
wrote:
> Hi,
>
> I m sorry but I m bored at work (and no ones looking so I can write
> some Python) and following a job advertisement post,I decided to write
> the code to do its for the one entitled Ninjas or something like that.
> I was wondering what could be done to my following code to make it
> more idiomatic...or whether it was idiomatic and to be honest what
> idiomatic really means. All comments greatly appreciated and welcomed.
>
> Thanks in advance
>
> Nathan
>
> import urllib2,sys
> from elementtree.ElementTree import parse
>
> base_url = "http://api.etsy.com/feeds/xml_user_details.php?id=";
>
> def read_id_file(filename):
> """ reads a file and generates a list of ids from it"""
> ids = [ ]
> try:
> id_file = open(filename, "r")
> for l in id_file:
> ids.append( l.strip("\n") )
> id_file.close()
> except e:
> print e
> os._exit(99)
> return ids
>




The expression in the except clause should
evaluate to an object that "matches" the exception.

For example,

import sys

try:
idfile = open(filename, "r")
except IOError, e
print >> sys.stderr, str(e)
# or look into the warnings module
# etc.


--
Hope this helps,
Steven

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


Re: Python's "only one way to do it" philosophy isn't good?

2007-07-02 Thread Douglas Alan
Lenard Lindstrom <[EMAIL PROTECTED]> writes:

>> I'm not sure I understand you here.  You're saying that I should have
>> the foresight to wrap all my file opens is a special class to
>> facilitate debugging?

> Obviously you had the foresight to realize with statements could
> compromise debugging. I never considered it myself.

It's not really so much a matter of having foresight, as much as
having had experience debugging a fair amount of code.  And, at times,
having benefited from the traditional idiomatic way of coding in
Python, where files are not explicitly closed.

Since there are benefits with the typical coding style, and I find
there to be no significant downside, other than if, perhaps some code
holds onto tracebacks, I suggest that the problem be idiomatically
addressed in the *few* code locations that hold onto tracebacks,
rather than in all the *myriad* code locations that open and close
files.

>> Or are you suggesting that early in __main__.main(), when I wish to
>> debug something, I do something like:
>>__builtins__.open = __builtins__.file = MyFile
>> ?
>> I suppose that would work.

> No, I would never suggest replacing a builtin like that. Even
> replacing a definite hook like __import__ is risky, should more than
> one package try and do it in a program.

That misinterpretation of your idea would only be reasonable while
actually debugging, not for standard execution.  Standard rules of
coding elegance don't apply while debugging, so I think the
misinterpretation might be a reasonable alternative.  Still I think
I'd just prefer to stick to the status quo in this regard.

> As long as the code isn't dependent on explicitly cleared
> exceptions. But if it is I assume it is well documented.

Typically the resource in question is an open file.  These usually
don't have to be closed in a particularly timely fashion.  If, for
some reason, a files absolutelys need to be closed rapidly, then it's
probably best to use "with" in such a case.  Otherwise, I vote for the
de facto standard idiom of relying on the refcounter along with
explicitly clearing exceptions in the situations we've previously
discusses.

If some code doesn't explicitly clear an exception, though, and holds
onto the the most recent one while running in a loop (or what have
you), in the cases we are considering, it hardly seems like the end of
the world.  It will just take a little bit longer for a single file to
be closed than might ideally be desired.  But this lack of ideal
behavior is usually not going to cause much trouble.

|>oug
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: object references/memory access

2007-07-02 Thread Steve Holden
Karthik Gurusamy wrote:
> On Jul 2, 3:01 pm, Steve Holden <[EMAIL PROTECTED]> wrote:
>> Karthik Gurusamy wrote:
>>> On Jul 1, 12:38 pm, dlomsak <[EMAIL PROTECTED]> wrote:
>> [...]
>>
>>> I have found the stop-and-go between two processes on the same machine
>>> leads to very poor throughput. By stop-and-go, I mean the producer and
>>> consumer are constantly getting on and off of the CPU since the pipe
>>> gets full (or empty for consumer). Note that a producer can't run at
>>> its top speed as the scheduler will pull it out since it's output pipe
>>> got filled up.
>> But when both processes are in the memory of the same machine and they
>> communicate through an in-memory buffer, what's to stop them from
>> keeping the CPU fully-loaded (assuming they are themselves compute-bound)?
> 
> If you are a producer and if your output goes thru' a pipe, when the
> pipe gets full, you can no longer run. Someone must start draining the
> pipe.
> On a single core CPU when only one process can be running, the
> producer must get off the CPU so that the consumer may start the
> draining process.
> 
Wrong. The process doesn't "get off" the CPU, it remains loaded, and 
will become runnable again once the buffer has been depleted by the 
other process (which is also already loaded into memory and will become 
runnable as soon as a filled buffer becomes available).

>>> When you increased the underlying buffer, you mitigated a bit this
>>> shuffling. And hence saw a slight increase in performance.
>>> My guess that you can transfer across machines at real high speed, is
>>> because there are no process swapping as producer and consumer run on
>>> different CPUs (machines, actually).
>> As a concept that's attractive, but it's easy to demonstrate that (for
>> example) two machines will get much better throughput using the
>> TCP-based FTP to transfer a large file than they do with the UDP-based
>> TFTP. This is because the latter protocol requires the sending unit to
>> stop and wait for an acknowledgment for each block transferred. With
>> FTP, if you use a large enough TCP sliding window and have enough
>> content, you can saturate a link as ling as its bandwidth isn't greater
>> than your output rate.
>>
>> This isn't a guess ...
> 
> What you say about a stop-n-wait protocol versus TCP's sliding window
> is correct.
> But I think it's totally orthogonal to the discussion here. The issue
> I'm talking about is how to keep the end nodes chugging along, if they
> are able to run simultaneously. They can't if they aren't on a multi-
> core CPU or one different machines.
> 
If you only have one CPU then sure, you can only run one process at a 
time. But your understanding of how multiple processes on the same CPU 
interact is lacking.
> 
>>> Since the two processes are on the same machine, try using a temporary
>>> file for IPC. This is not as efficient as real shared memory -- but it
>>> does avoid the IPC stop-n-go. The producer can generate the multi-mega
>>> byte file at one go and inform the consumer. The file-systems have
>>> gone thru' decades of performance tuning that this job is done really
>>> efficiently.
>> I'm afraid this comes across a bit like superstition. Do you have any
>> evidence this would give superior performance?
>>
> 
> I did some testing before when I worked on boosting a shell pipeline
> performance and found using file-based IPC was very good.
> (some details at 
> http://kar1107.blogspot.com/2006/09/unix-shell-pipeline-part-2-using.html
> )
> 
> Thanks,
> Karthik
> 
 Thanks for the replies so far, I really appreciate you guys
 considering my situation and helping out.

If you get better performance by writing files and reading them instead 
of using pipes to communicate then something is wrong.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


The file executing

2007-07-02 Thread Benjamin
How does one get the path to the file currently executing (not the
cwd). Thank you

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


Re: Python's "only one way to do it" philosophy isn't good?

2007-07-02 Thread Douglas Alan
Lenard Lindstrom <[EMAIL PROTECTED]> writes:

>> Also, any caught exception is automatically cleared when
>> the catching procedure returns anyway, so it's not like Python has
>> ever considered a caught exception to be precious information that
>> ought to be preserved long past the point where it is handled.

> That's the point. Python takes care of clearing the traceback. Calls
> to exc_clear are rarely seen.

But that's probably because it's very rare to catch an exception and
then not return quickly.  Typically, the only place this would happen
is in main(), or one of its helpers.

> If they are simply a performance tweak then it's not an issue *. I
> was just concerned that the calls were necessary to keep resources
> from being exhausted.

Well, if you catch an exception and don't return quickly, you have to
consider not only the possibility that there could be some open files
left in the traceback, but also that there could be a large and now
useless data structures stored in the traceback.

Some people here have been arguing that all code should use "with" to
ensure that the files are closed.  But this still wouldn't solve the
problem of the large data structures being left around for an
arbitrary amount of time.

> But some things will make it into ISO Python.

Is there a movement afoot of which I'm unaware to make an ISO standard
for Python?

> Just as long as you have weighed the benefits against a future move
> to a JIT-accelerated, continuation supporting PyPy interpreter that
> might not use reference counting.

I'll worry about that day when it happens, since many of my calls to
the standard library will probably break anyway at that point.  Not to
mention that I don't stay within the confines of Python 2.2, which is
where Jython currently is.  (E.g., Jython does not have generators.)
Etc.

>> I think that Jython and IronPython, etc., should adopt these
>> semantics, but I imagine they might not for performance reasons.  I
>> don't generally use Python for it's speediness, however, but rather
>> for it's pleasant syntax and semantics and large, effective
>> library.

> Yet improved performance appeared to be a priority in Python 2.4
> development, and Python's speed continues to be a concern.

I don't think the refcounting semantics should slow Python down much
considering that it never has aimed for C-level performance anyway.
(Some people claim it's a drag on supporting threads.  I'm skeptical,
though.)  I can see it being a drag on something like Jython, though,
were you are going through a number of different layers to get from
Jython code to the hardware.

Also, I imagine that no one wants to put in the work in Jython to have
a refcounter when the garbage collector comes with the JVM for free.

|>oug
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tiny/small/minimalist Python?

2007-07-02 Thread rtk
On Jul 2, 6:26 pm, Irmen de Jong <[EMAIL PROTECTED]> wrote:
> Back in the days my port of Python to the Commodore Amiga machine ran
> quite comfortably on a 50 mhz CPU with 4 Mb of RAM. (ok ok it was
> Python 1.5.2, that has to be said).
> Python started in about 5 seconds on that Amiga if I remember
> correctly. I'm quite sure your 'ancient' DEC Alpha box is way more
> powerful than my Amiga back then.

Yes, I agree (the box in question is an AlphaServer 1000 4/200), but
the killer is the fact that the Alpha is emulating *machine
instructions* that are part of the Python image which are not part of
the instruction set of that Alpha.  That's what kills performance.
When I asked about it on the VMS Python forum I was told to give my
Alpha to a museum and get a more powerful machine :)

I did look briefly at Python 1.5.2, since it is simpler, but I'm
taking the trouble I've had as an excuse to learn a new language.  So
far, I'm liking Lua, save the big pet peeve of starting indices at 1
and not 0 as all sane people do.  I'm currently using Python quite a
bit for other projects, so it won't be neglected.

Ron

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


Re: PEP 3107 and stronger typing (note: probably a newbie question)

2007-07-02 Thread Alex Martelli
Donn Cave <[EMAIL PROTECTED]> wrote:

> In article <[EMAIL PROTECTED]>,
>  [EMAIL PROTECTED] (Alex Martelli) wrote:
> 
> > "Dynamic typing is recommended", they conclude, "when programs must be
> > as flexible as possible".  I recommend reading the Agile Manifesto to
> > understand why maximal flexibility is crucial in most real-world 
> > application programming -- and therefore why, in said real world rather
> > than in the more academic circles Dr. Van Roy and Dr. Hadidi move in,
> > dynamic typing is generally preferable, and not such a tiny issue as
> > they make the difference to be.
> 
> I guess there may be more than one kind of flexibility.  The language
> I fool around with sometimes that has strong static typing is Haskell.
> Though a relatively elementary Haskell programmer (the learning curve
> with this language is something you would have to experience to believe),

I do have (some of:-) that experience, and am reasonably at ease in
Haskell (except when it comes to coding monads, which I confess I still
have trouble wrapping my head around).

> I feel that the type checking actually helps me program faster.
> The compiler's check for structural correctness is after all for my
> benefit, and expedites development and maintenance of code, in my
> limited experience.  The more extensive my changes, the more useful
> the type checking is - I'm much more casual about significant code
> revision when writing in Haskell, somewhat more casual when writing
> in C, and worried when writing Python.

Eckel's and Martin's well-known essays on why good testing can replace
strict static type checking:



Me, I'm always worried about significant code revision _unless I have
good tests in place_.  Strict static typechecks catch only a small
subset of frequent mistakes -- good tests catch a far higher quota.
Typechecks do catch some mistakes "faster", but, in my experience on
today's machines, that tiny difference is becoming insignificant,
particularly when you consider that typechecks typically require
whole-program analysis while, as Van Roy and Haridi point out, dynamic
typing affords "totally open coding".


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


Re: object references/memory access

2007-07-02 Thread Karthik Gurusamy
On Jul 2, 6:32 pm, Steve Holden <[EMAIL PROTECTED]> wrote:
> Karthik Gurusamy wrote:
> > On Jul 2, 3:01 pm, Steve Holden <[EMAIL PROTECTED]> wrote:
> >> Karthik Gurusamy wrote:
> >>> On Jul 1, 12:38 pm, dlomsak <[EMAIL PROTECTED]> wrote:
> >> [...]
>
> >>> I have found the stop-and-go between two processes on the same machine
> >>> leads to very poor throughput. By stop-and-go, I mean the producer and
> >>> consumer are constantly getting on and off of the CPU since the pipe
> >>> gets full (or empty for consumer). Note that a producer can't run at
> >>> its top speed as the scheduler will pull it out since it's output pipe
> >>> got filled up.
> >> But when both processes are in the memory of the same machine and they
> >> communicate through an in-memory buffer, what's to stop them from
> >> keeping the CPU fully-loaded (assuming they are themselves compute-bound)?
>
> > If you are a producer and if your output goes thru' a pipe, when the
> > pipe gets full, you can no longer run. Someone must start draining the
> > pipe.
> > On a single core CPU when only one process can be running, the
> > producer must get off the CPU so that the consumer may start the
> > draining process.
>
> Wrong. The process doesn't "get off" the CPU, it remains loaded, and
> will become runnable again once the buffer has been depleted by the
> other process (which is also already loaded into memory and will become
> runnable as soon as a filled buffer becomes available).
>

huh? "get off" when talking about scheduling and CPU implies you are
not running.
It is a common term to imply that you are not running -- doesn't mean
it goes away from main memory. Sorry where did you learn your CS
concepts?

>
>
> >>> When you increased the underlying buffer, you mitigated a bit this
> >>> shuffling. And hence saw a slight increase in performance.
> >>> My guess that you can transfer across machines at real high speed, is
> >>> because there are no process swapping as producer and consumer run on
> >>> different CPUs (machines, actually).
> >> As a concept that's attractive, but it's easy to demonstrate that (for
> >> example) two machines will get much better throughput using the
> >> TCP-based FTP to transfer a large file than they do with the UDP-based
> >> TFTP. This is because the latter protocol requires the sending unit to
> >> stop and wait for an acknowledgment for each block transferred. With
> >> FTP, if you use a large enough TCP sliding window and have enough
> >> content, you can saturate a link as ling as its bandwidth isn't greater
> >> than your output rate.
>
> >> This isn't a guess ...
>
> > What you say about a stop-n-wait protocol versus TCP's sliding window
> > is correct.
> > But I think it's totally orthogonal to the discussion here. The issue
> > I'm talking about is how to keep the end nodes chugging along, if they
> > are able to run simultaneously. They can't if they aren't on a multi-
> > core CPU or one different machines.
>
> If you only have one CPU then sure, you can only run one process at a
> time. But your understanding of how multiple processes on the same CPU
> interact is lacking.
>

huh?

>
>
>
>
> >>> Since the two processes are on the same machine, try using a temporary
> >>> file for IPC. This is not as efficient as real shared memory -- but it
> >>> does avoid the IPC stop-n-go. The producer can generate the multi-mega
> >>> byte file at one go and inform the consumer. The file-systems have
> >>> gone thru' decades of performance tuning that this job is done really
> >>> efficiently.
> >> I'm afraid this comes across a bit like superstition. Do you have any
> >> evidence this would give superior performance?
>
> > I did some testing before when I worked on boosting a shell pipeline
> > performance and found using file-based IPC was very good.
> > (some details 
> > athttp://kar1107.blogspot.com/2006/09/unix-shell-pipeline-part-2-using
> > )
>
> > Thanks,
> > Karthik
>
>  Thanks for the replies so far, I really appreciate you guys
>  considering my situation and helping out.
>
> If you get better performance by writing files and reading them instead
> of using pipes to communicate then something is wrong.
>

Why don't you provide a better explanation for the observed behavior
than to just claim that a given explanation is wrong? I did mention
using real shared memory is better. I do know the cost of using a file
("physical disk movements") - but with the amount of buffering that
goes on today's file-system implementations, for this problem, we will
see big improvement.

Karthik

> regards
>   Steve
> --
> Steve Holden+1 571 484 6266   +1 800 494 3119
> Holden Web LLC/Ltd  http://www.holdenweb.com
> Skype: holdenweb  http://del.icio.us/steve.holden
> --- Asciimercial --
> Get on the web: Blog, lens and tag the Internet
> Many services currently offer free registration
> --- Thank You for Reading -


-- 
http://mail.pyth

Re: The file executing

2007-07-02 Thread Justin Ezequiel
On Jul 3, 9:40 am, Benjamin <[EMAIL PROTECTED]> wrote:
> How does one get the path to the file currently executing (not the
> cwd). Thank you

os.path.dirname(sys.argv[0])

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


try/finally in threads

2007-07-02 Thread George Sakkis
I posted this on the Pyro list but I'm not sure if it's related
specifically to Pyro. The "finally" clause below is not executed when
f() runs on on a (daemon) thread and the program exits. DAEMON here is
a global Pyro.code.Daemon instance.

def f():
   try: DAEMON.requestLoop()
   finally:
   # nothing is printed if f() runs in a thread
   print "i am here!!"
   DAEMON.shutdown()
   print "i am over!!"

Is "finally" not guaranteed to be executed in a non-main thread or is
there something else going on ?

George

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


Re: Tiny/small/minimalist Python?

2007-07-02 Thread Paul Rubin
Irmen de Jong <[EMAIL PROTECTED]> writes:
> Back in the days my port of Python to the Commodore Amiga machine ran
> quite comfortably on a 50 mhz CPU with 4 Mb of RAM. (ok ok it was
> Python 1.5.2, that has to be said).

Even that sounds way too slow.  Kyoto Common Lisp started in a few
seconds on a Microvax-class machine, and an Alpha running Vax
emulation should be at least as fast as that.  Python shouldn't have
especially worse startup overhead than KCL unless it's doing something
silly.

I'd try running Python under a profiler and figure out what's slowing
it down.  I don't understand the point of developing something in Lua
on a Unix system.  Lua is a cute scripting language that's easier to
embed and sandbox than Python and is smaller, but the language itself
is not nearly as nice to code in.  I suggested Lua because I was
imagining some kind of memory-limited embedded application that needed
a lightweight extension language without too much of an OS interface,
and Lua is good for that.  Using it to write a compiler sounds
masochistic.  If there's an obstacle to using Python, I'd even
consider using KCL (or its current incarnation), which has its own
compiler (compiles Lisp to C code) among other things.  It does need
several MB of memory.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: good matlab interface

2007-07-02 Thread felix seltzer

my problems where more with scipy, which i needed for pymat.
scipy gives two import errors (but still imports), and then pymat
cant find the libraries that scipy provides.

ohwell...
i think i can just modify it to work with numpy untill
i can sort out the errors.

thanks,
-felix


On 7/2/07, Brian Blais <[EMAIL PROTECTED]> wrote:


On Jun 30, 2007, at 2:31 AM, felix seltzer wrote:

> Does any one know of a good matlab interface?
> I would just use scipy or numpy, but i also need to use
> the matlab neural network functions.  I have tried PyMat, but am
> having
> a hard time getting it to install correctly.
>

What problems are you having installing?  I had one problem with the
terrible matlab license server, which I had to solve by making site-
packages world writable, installing pymat as a user, and then
removing the world writable flag.  Root just didn't have access to
matlab on my machine.  :P



bb


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

Re: what is the PythonWin

2007-07-02 Thread O.R.Senthil Kumaran
* Cameron Laird <[EMAIL PROTECTED]> [2007-07-02 17:27:31]:

> >PythonWin is a separate project by Mark Hammond providing win32 extensions 
> >for
> >python. 
> >
> >http://sourceforge.net/projects/pywin32/
>   .
>   .
>   .
> I believe there's confusion afoot.
> 
> Pythonwin http://wiki.python.org/moin/PythonWin > is a
> Python-oriented editor for Windows.  Mark bundles Pythonwin
> with a couple of other equally-intriguing pieces to make
> pywin32.  When I read, "win32 extensions for python", I think
> of what Mark labels "win32api".  I'm reasonably certain that,

Thanks for the explaination, Cameron.
Yeah, there was a confusion from my end. 
I hope the OP, got what he needed from the URL tough.

-- 
O.R.Senthil Kumaran
http://uthcode.sarovar.org
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >