Re: Replace string except inside quotes?

2004-12-04 Thread M.E.Farmer
"Raymond Hettinger" <[EMAIL PROTECTED]> wrote in message 
> The source for the tokenize module covers all these bases.

> Raymond Hettinger

# tokenize text replace

import keyword, os, sys, traceback
import string, cStringIO
import token, tokenize

##

class Parser:
"""python source code tokenizing text replacer
"""
def __init__(self, raw, out=sys.stdout):
''' Store the source text & set some flags.
'''
self.raw = string.strip(string.expandtabs(raw))
self.out = out

def format(self, search='' ,replace='',
replacetokentype=token.NAME):
''' Parse and send text.
'''
# Store line offsets in self.lines
self.lines = [0, 0]
pos = 0
self.temp = cStringIO.StringIO()
self.searchtext = search
self.replacetext  = replace
self.replacetokentype = replacetokentype

# Gather lines
while 1:
pos = string.find(self.raw, '\n', pos) + 1
if not pos: break
self.lines.append(pos)
self.lines.append(len(self.raw))

# Wrap text in a filelike object
self.pos = 0
text = cStringIO.StringIO(self.raw)

# Parse the source.
## Tokenize calls the __call__ 
## function for each token till done.
try:
tokenize.tokenize(text.readline, self)
except tokenize.TokenError, ex:
traceback.print_exc()


def __call__(self, toktype, toktext, 
 (srow,scol), (erow,ecol), line):
''' Token handler.
'''
# calculate new positions
oldpos = self.pos
newpos = self.lines[srow] + scol
self.pos = newpos + len(toktext)

# handle newlines
if toktype in [token.NEWLINE, tokenize.NL]:
self.out.write('\n')
return

# send the original whitespace, if needed
if newpos > oldpos:
self.out.write(self.raw[oldpos:newpos])

# skip indenting tokens
if toktype in [token.INDENT, token.DEDENT]:
self.pos = newpos
return

# search for matches to our searchtext
# customize this for your exact needs 
if (toktype == self.replacetokentype and
toktext == self.searchtext):
toktext = self.replacetext

# write it out
self.out.write(toktext)
return

##
# just an example
def Main():
import sys
if sys.argv[0]:
filein = open(sys.argv[0]).read()
Parser(filein, out=sys.stdout).format('tokenize', 'MyNewName')

##

if __name__ == '__main__':
Main()

# end of code


This is an example of how to use tokenize to replace names
 that match a search string.
If you wanted to only replace strings and not
 names then change the replacetokentype to 
 token.STRING instead of token.NAME etc...
HTH,
 M.E.Farmer
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help me asap!!

2004-12-04 Thread Nick Coghlan
the_proud_family wrote:
HELP ME PLEASE!!
I can't get the ball to go up right side and then I need it to turn 
around and keep turning until velocity=0 I have been at it for the 
past 2 weeks now i give up and call for help. Please if anyone can 
gide me through i will be so grateful!! I have pasted my code below
A few comments in the code stating what each section is *meant* to be doing 
might mean you actually got some useful responses (no guarantees, though).

However, the current state of the code, where the reader is left entirely to 
guess as to what the overall program is for, and what each section of the 
program is meant to be doing virtually guarantees that you *won't* get any help.

You could start by interpreting the cryptic comment above into something 
meaningful for anyone who doesn't already know what your assignment is.

You might even find that articulating things clearly lets you identify the 
problem for yourself.

Alternately, implement little pieces at a time, to make sure they work 
individually, then combine them to form the complete behaviour - don't try to 
write the whole thing in one hit (or you will get your current situation of "it 
doesn't work" with no idea which *bit* isn't working)

Cheers,
Nick.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python2.4: building '_socket' extension fails with `INET_ADDRSTRLEN' undeclared

2004-12-04 Thread Michael Ströder
Martin v. Löwis wrote:
Michael Ströder wrote:
I'm trying to build Python2.4 on a rather old Debian machine. I only 
have a shell account there. That's why I'm very limited in my actions.

Building _socket fails (see below) although I tried to use
configure --disable-ipv6
Any clue?
Hard to say, since you don't indicate what clues you are lacking.
My wanted clue: How to build it without modifying the Python 2.4 sources?
In general, when the C compiler gives an error message, it is best
to try to understand the error message. The message reads
socketmodule.c:3350: `INET_ADDRSTRLEN' undeclared (first use this function)
Thanks for your answer. I do understand the message. I searched some 
archives and found similar bug reports in the SF issue tracker which 
were for Python 2.3 on Irix and seemed to be fixed.

Looking at a more recent system in /usr/include, I get
/usr/include$ grep -r ADDRSTRLEN .
./netinet/in.h:#define INET_ADDRSTRLEN 16
Note that building Python2.2 worked on the very same machine. I've added
#define INET_ADDRSTRLEN 16
to socketmodule.h and it worked. But I think there might be something 
wrong with the autoconf stuff.

I filed bug [ 1078245 ]:
http://sourceforge.net/tracker/index.php?func=detail&aid=1078245&group_id=5470&atid=105470
Ciao, Michael.
--
http://mail.python.org/mailman/listinfo/python-list


Re: PyQT Licensing and plugins/scripting

2004-12-04 Thread Michael Sparks
On Fri, 3 Dec 2004, Phil Thompson wrote:
...
> The key is access to the Qt API. If your applications gives the users access
> to the API then those users are developers and need their own licenses. On
> the other hand if the API is sufficiently removed from the Qt API then you
> shouldn't have a problem. Your API should restrict itself to extending the
> capabilities of your application - the more general purpose you make it, the
> more you risk a visit from the lawyers.

What about, for example, a XUL processor? Suppose I wanted to rewrite
Mozilla's front end to us Qt, I'd clearly need to implement a XUL
processor. Obviously such a thing is possible to do with PyQT as well.
Would I be able to do such a thing with a standard windows license for Qt
and PyQt? Everything I've read suggests that this would not be possible.

Users wouldn't have direct access to the Qt API, but they may have access
to the aspects Qt system, assuming a XUL type system, including the
ability to create new applications with new user interfaces (as one can
using Mozilla, XUL and Javascript).

ie one could envisage writing a wrapper around every part of the Qt API,
and then expose that as an API - is that breaking the rules? I'd assume
yes. Suppose then I simply change this to an XML processor (say a
tokenising on)that when it gets a directive it simply calls the Qt API,
and allow a user to change things in a config file. Is that too far? To me
they seem equivalent.

I don't tend to use windows much, if ever, and wouldn't want to do this at
present. However, it's fairly close to something I would like to do under
Linux (where this isn't a problem obviously), fairly close to the wind
having read the commercial licenses I could see and it just concerns me
that if I ever wanted to port such a system to windows I could get
extremely stung (Suppose I was redistributing an executeable).

It's a hypothetical question at present, due to using Linux, but it's
(realistically) possible at some point it may become less hypothetical.

Regards,


Michael.

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


Re: Newby Q: nested classes, access of upper method

2004-12-04 Thread Nick Coghlan
Gregor Horvath wrote:
Hello,
class A(self):
  def A1():
pass
class B(self):
  def B1():
#
#***  How can I access A1 here ***
#
self.A1() # doesnet work because self references to  B
self.self.A1() #doesnt work either
Renanimg class B(self1): doesnt work either because self is not bound.
OK, I suspect you're a little confused about how classes work. The items in 
brackets after a class name are the *base* classes of a class, not the way the 
class refers to itself. So Python will complain if the listed items can't be 
inherited from for one reason or another.

I suggest having another read of the tutorial section on classes to figure out 
exactly what you want to be doing:
http://www.python.org/doc/2.3.4/tut/node11.html

How can I access a method of a "upper" class?
Merely defining one class inside another class does not automatically give 
instances of that inner class a reference to an instance of the outer class - if 
such a reference is needed, it must be provided in the inner class's constructor.

E.g.
class A(object):
  class B(object):
def __init__(self, owner):
  self._owner = owner
def B1(self):
  self._owner.A1()
  def A1(self):
pass
  def makeB(self):
return A.B(self)
Cheers,
Nick.
--
http://mail.python.org/mailman/listinfo/python-list


Audio interviews of Guido or other Python advocates?

2004-12-04 Thread Dave Benjamin
Ever since I heard Paul Graham's OSCON speech as audio, I've been somewhat
interested in hearing what all these voices of computer culture sound like,
and what they talk about. I enjoyed a few of Larry Wall's speeches as well
as Tim O'Reilly's, here: http://technetcast.ddj.com/

I looked around for recordings of Guido, but couldn't find any. Does anyone
know of any streamable audio (or video) interviews or speeches featuring
Guido, the bots, or any other interesting people in the Python community?
I've seen a video of a Bruce Eckels presentation; that's about the closest
I've found so far.

-- 
 .:[ dave benjamin: ramen/[sp00] -:- spoomusic.com -:- ramenfest.com ]:.
"talking about music is like dancing about architecture."
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pre-PEP generic objects

2004-12-04 Thread Steven Bethard
Istvan Albert wrote:
but what are you saying? that a man cannot exaggerate and
fudge the facts in order to embellish his argument? :-)
Heh heh.  Yeah, something like that. ;)
Steve
--
http://mail.python.org/mailman/listinfo/python-list


Re: Newby Q: nested classes, access of upper method

2004-12-04 Thread Gregor Horvath
Hello Nick,
thank you, your answer really helped me..
--
Greg
Nick Coghlan wrote:
Gregor Horvath wrote:
Hello,
class A(self):
  def A1():
pass
class B(self):
  def B1():
#
#***  How can I access A1 here ***
#
self.A1() # doesnet work because self references to  B
self.self.A1() #doesnt work either
Renanimg class B(self1): doesnt work either because self is not bound.

OK, I suspect you're a little confused about how classes work. The items 
in brackets after a class name are the *base* classes of a class, not 
the way the class refers to itself. So Python will complain if the 
listed items can't be inherited from for one reason or another.

I suggest having another read of the tutorial section on classes to 
figure out exactly what you want to be doing:
http://www.python.org/doc/2.3.4/tut/node11.html

How can I access a method of a "upper" class?

Merely defining one class inside another class does not automatically 
give instances of that inner class a reference to an instance of the 
outer class - if such a reference is needed, it must be provided in the 
inner class's constructor.

E.g.
class A(object):
  class B(object):
def __init__(self, owner):
  self._owner = owner
def B1(self):
  self._owner.A1()
  def A1(self):
pass
  def makeB(self):
return A.B(self)
Cheers,
Nick.

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


Re: How is Python designed?

2004-12-04 Thread Limin Fu
> If you want cutting-edge, mind twisting stuff, look
> into
> Psyco extension (Armin Rigo, 1.3 just announced
> here)
> Stackless extension (Christian Tismer)
> PyPy (new interpreter written in Python, several
> people, has EU funding)

That would be interesting. However I am designing and
implementing another interpreter. The techniques I'm
using seems to be different from most of current
interpreters (I hope so, I'm not very sure, that why I
come to ask questions about interpretation
techniques). The programming language is C++. 

The basic idea of this technique is to create a class
to represent each type of script phrase(that's the
term I used in the program, it's just a piece of code
for particular task such assignment,logical/loop
control,function call, whatever). In the phase of
compiling, phrase instances of such classed are made,
and in the execution phase, starting from the first,
each phrase instance is executed and jump to the next
phrase instance for subsequential execution,
like a finite state automa I would say. Currently the
interpretation efficiency is comparable to most
popular interpreters. 

For more information, please have a look at:
http://yuan-language.sourceforge.net/

Honest saying, it has just come out for a few monthes,
it's not well tested and there is much things to be
improved. So don't be surprised if some bugs come out
when you run it. In this case, please let me known.
Cheers,

Limin



__ 
Do you Yahoo!? 
Yahoo! Mail - Easier than ever with enhanced search. Learn more.
http://info.mail.yahoo.com/mail_250
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Audio interviews of Guido or other Python advocates?

2004-12-04 Thread Jimmy Retzlaff
Dave Benjamin wrote:
> I looked around for recordings of Guido, but couldn't find any. Does
> anyone know of any streamable audio (or video) interviews or speeches
> featuring Guido, the bots, or any other interesting people in the
Python
> community?

There's a video with a few folks in it at:

http://www.ibiblio.org/obp/pyBiblio/pythonvideo.php

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


ANN: PyTables 0.9.1 is out

2004-12-04 Thread Francesc Altet
Announcing PyTables 0.9.1
-

This release is mainly a maintenance version. In it, some bugs has
been fixed and a few improvements has been made. One important thing
is that chunk sizes in EArrays has been re-tuned to get much better
performance and compression rations. Besides, it has been tested
against the latest Python 2.4 and all test units seems to pass fine.

What it is
--

PyTables is a solid hierarchical database package designed to
efficiently manage extremely large amounts of data (with support for
full 64-bit file addressing). It features an object-oriented interface
that, combined with C extensions for the performance-critical parts of
the code, makes it a very easy-to-use tool for high performance data
storage and retrieval.

It is built on top of the HDF5 library and the numarray package, and
provides containers for both heterogeneous data (Tables) and
homogeneous data (Array, EArray) as well as containers for keeping
lists of objects of variable length (like Unicode strings or general
Python objects) in a very efficient way (VLArray). It also sports a
series of filters allowing you to compress your data on-the-fly by
using different compressors and compression enablers.

But perhaps the more interesting features are its powerful browsing
and searching capabilities that allow you to perform data selections
over heterogeneous datasets exceeding gigabytes of data in just tenths
of second. Besides, all the PyTables I/O is buffered, implemented in C
and carefully tuned so that you can reach much better performance with
PyTables than with your own home-grown wrappings to the HDF5 library.

Changes more in depth
-

Improvements:

- The chunksize computation for EArrays has been re-tuned to allow
  better performance and *much* better compression rations.

- New --unpackshort and --quantize flags has been added to nctoh5
  script. --unpackshort unpack short integer variables to float
  variables using scale_factor and add_offset netCDF variable
  attributes. --quantize quantize data to improve compression using
  least_significant_digit netCDF variable attribute (not active by
  default).  See
  http://www.cdc.noaa.gov/cdc/conventions/cdc_netcdf_standard.shtml
  for further explanation of what this attribute means. Thanks to Jeff
  Whitaker for providing this.

- Table.itersequence has received a new parameter called "sort". This
  allows to disable the sorting of the sequence in case the user wants
  so.

Backward-incompatible changes:

- Now, the AttributeSet class throw an AttributeError on __getattr__
  for nonexistent attributes in it. Formerly, the routine returned
  None, which is pretty much against convention in Python and breaks
  the built-in hasattr() function. Thanks to Norbert Nemec for noting
  this and offering a patch.

- VLArray.read() has changed its behaviour. Now, it always returns a
  list, as stated in documentation, even when the number of elements
  to return is 0 or 1. This is much more consistent when representing
  the actual number of elements on a certain VLArray row.

API additions:

- A Row.getTable() has been added. It is an accessor for the associated
  Table object.

- A File.copyAttrs() has been added. It allows copying attributes from
  one leaf to other. Properly speaking, this was already there, but not
  documented :-/

Bug fixes:

- Now, the copy of hierarchies works even when there are scalar Arrays
  (i.e. Arrays which shape is ()) on it. Thanks to Norbert Nemec for
  providing a patch.

- Solved a memory leak regarding the Filters instance associated with
  the File object, that was not released after closing the file. Now,
  there are no known leaks on PyTables itself.

- Fixed a bug in Table.append() when the table was indexed. The problem
  was that if table was in auto-indexing mode, some rows were lost in
  the indexation process and hence, not indexed correctly.

- Improved security of nodes name checking. Closes #1074335


Important note for Python 2.4 and Windows users
---

If you are willing to use PyTables with Python 2.4 in Windows
platforms, you will need to get the HDF5 library compiled for MSVC
7.1, aka .NET (and possible LZO and UCL as well, if you want support
for LZO and UCL at all). It can be found at:
ftp://ftp.ncsa.uiuc.edu/HDF/HDF5/current/bin/windows/5-163-winxp-net2003.zip


Where can PyTables be applied?
--

PyTables is not designed to work as a relational database competitor,
but rather as a teammate. If you want to work with large datasets of
multidimensional data (for example, for multidimensional analysis), or
just provide a categorized structure for some portions of your
cluttered RDBS, then give PyTables a try. It works well for storing
data from data acquisition systems (DAS), simulation software, network
data monitoring systems (for example, traffic measurements of IP
packets on routers), very large XML

Re: Pythonic use of CSV module to skip headers?

2004-12-04 Thread Michael Hoffman
Skip Montanaro wrote:
Assuming the header line has descriptive titles, I prefer the DictReader
class.  Unfortunately, it requires you to specify the titles in its
constructor.  My usual idiom is the following:
I deal so much with tab-delimited CSV files that I found it useful to 
create a subclass of csv.DictReader to deal with this, so I can just write:

for row in tabdelim.DictReader(file(filename)):
...
I think this is a lot easier than trying to remember this cumbersome 
idiom every single time.
--
Michael Hoffman
--
http://mail.python.org/mailman/listinfo/python-list


Re: using cmd.exe as a telnet client

2004-12-04 Thread Eyal Lotem
I think I have a much simpler solution for you guys..
Assuming you can run arbitrary code on the proprietary
server.

I wrote PyInvoke, and I use it as a much-easier-to-use
replacement for telnet control of computers.

It does require installing Python on the target server
though.

You simple have to run PyInvoke's server.py on the
server, and then in the client, you can Pythonically
control anything on the server:

client = pyinvoke.connect(('some_server', some_port))
client.modules.shutil().rmtree('/tmp/blah')

As easy as that :-)

PyInvoke is at: http://pybuild.sf.net/pyinvoke.html

There are a few improvements I have to put back into
the source, like the ability to run the server on
Windows (currently it depends on fork'ability), but
otherwise it is already very complete and works well.

--- Grant Edwards <[EMAIL PROTECTED]> wrote:
> On 2004-12-03, Donnal Walter <[EMAIL PROTECTED]>
> wrote:
> 
> > Several months ago I tried using the telnet module
> (on Windows XP) to 
> > communicate with a proprietary host on our
> network. This was 
> > unsuccessful due to problems with "option
> negotiation", and I gave up on 
> > the project for a while. I still have need for
> this, however, so I 
> > recently started thinking about alternatives. I
> suppose I could dig deep 
> > enough into option negotiation to use the socket
> module (with telnet as 
> > a guide), but I am hoping to find a way to use
> fewer synapses.
> 
> You don't have to start from scratch. The telnet
> module has
> hooks built-into it1 so that you can have it call
> your routines
> to handle option negotiation.  I did it once to
> impliment some
> extra Telnet protocol features, and it wasn't
> difficult.




__ 
Do you Yahoo!? 
Yahoo! Mail - now with 250MB free storage. Learn more.
http://info.mail.yahoo.com/mail_250
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyQT Licensing and plugins/scripting

2004-12-04 Thread Phil Thompson
On Saturday 04 December 2004 10:30 am, Michael Sparks wrote:
> On Fri, 3 Dec 2004, Phil Thompson wrote:
> ...
>
> > The key is access to the Qt API. If your applications gives the users
> > access to the API then those users are developers and need their own
> > licenses. On the other hand if the API is sufficiently removed from the
> > Qt API then you shouldn't have a problem. Your API should restrict itself
> > to extending the capabilities of your application - the more general
> > purpose you make it, the more you risk a visit from the lawyers.
>
> What about, for example, a XUL processor? Suppose I wanted to rewrite
> Mozilla's front end to us Qt, I'd clearly need to implement a XUL
> processor. Obviously such a thing is possible to do with PyQT as well.
> Would I be able to do such a thing with a standard windows license for Qt
> and PyQt? Everything I've read suggests that this would not be possible.
>
> Users wouldn't have direct access to the Qt API, but they may have access
> to the aspects Qt system, assuming a XUL type system, including the
> ability to create new applications with new user interfaces (as one can
> using Mozilla, XUL and Javascript).
>
> ie one could envisage writing a wrapper around every part of the Qt API,
> and then expose that as an API - is that breaking the rules? I'd assume
> yes. Suppose then I simply change this to an XML processor (say a
> tokenising on)that when it gets a directive it simply calls the Qt API,
> and allow a user to change things in a config file. Is that too far? To me
> they seem equivalent.
>
> I don't tend to use windows much, if ever, and wouldn't want to do this at
> present. However, it's fairly close to something I would like to do under
> Linux (where this isn't a problem obviously), fairly close to the wind
> having read the commercial licenses I could see and it just concerns me
> that if I ever wanted to port such a system to windows I could get
> extremely stung (Suppose I was redistributing an executeable).
>
> It's a hypothetical question at present, due to using Linux, but it's
> (realistically) possible at some point it may become less hypothetical.

At this point I would take the coward's way out and say "ask Trolltech". As a 
matter of course I follow their model for PyQt (ie. if they are happy/unhappy 
then I'm happy/unhappy).

I suspect that you are right. Borland had to come to a special arrangement for 
Kylix - it wasn't just a case of buying a Qt license for each of their 
developers.

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


Re: Pythonic use of CSV module to skip headers?

2004-12-04 Thread Nick Coghlan
Michael Hoffman wrote:
I deal so much with tab-delimited CSV files that I found it useful to 
create a subclass of csv.DictReader to deal with this, so I can just write:

for row in tabdelim.DictReader(file(filename)):
...
I think this is a lot easier than trying to remember this cumbersome 
idiom every single time.
Python 2.4 makes the fieldnames paramter optional:
  "If the fieldnames parameter is omitted, the values in the first row of the 
csvfile will be used as the fieldnames."

i.e. the following should work fine in 2.4:
for row in csv.DictReader(file(filename)):
  print sorted(row.items())
Cheers,
Nick.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Need help on program!!!

2004-12-04 Thread Miklós P
"Dan Perl" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>
>
> I'm not sure what you mean by "benignity" here, but I think I agree with
> you.  Sympathy for TAs is not really my reason for how I feel towards

I meant that I think the real (or long term) interest of the OP is to
*learn* things as opposed to
(the short term interest in) submitting that homework without his devoting
any effort.

> reason to give him the solution).  I guess that is not the best argument I
> could have made.
>
> Dan
>

Yes, I agree and I had thought you actually meant it similarly like I do.

 Best regards,
  Miklós



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


help needed

2004-12-04 Thread the_proud_family

HELP ME PLEASE!!
I can't get the ball to go up right side and then I need it to turn
around and keep turning until velocity=0 I have been at it for the
past 2 weeks now i give up and call for help. Please if anyone can
gide me through i will be so grateful!! I have pasted my code below








from cmath import *
from visual import *

floor1 = box(length=10, height=0.5, width=4, color=color.blue)
floor1.pos = (-6,4,0)
floor1.axis= (5,-5,0)

floor2 = box(length=10, height=0.5, width=4, color=color.blue)
floor2.pos = (6,4,0)
floor2.axis= (-5,-5,0)

floor3 = box(length=7, height=0.5, width=4, color=color.blue)
floor3.pos = (0,1.25,0)

ball= sphere(radius=0.5, color=color.red)
ball.pos=(-8.6,7.5,0)
m=3. #kg
angle=asin(3.6/5.)#radians
g=-9.8
mu=.2
N=m*g*cos(angle)
F=m*g*sin(angle)
f=mu*N
lax=(-N*sin(angle)+f*cos(angle))/m
lay=(-N*cos(angle)-f*sin(angle)+m*g)/m
rax=(+N*sin(angle)+f*cos(angle))/m
ray=(-N*cos(angle)-f*sin(angle)+m*g)/m
ds=0.01
dt=0.01
vx=lax*dt
vy=lay*dt
ball.velocity=vector(vx,vy,0)

#print a

while 1:
rate(100)
ball.velocity.x=ball.velocity.x+lax*dt
ball.velocity.y=ball.velocity.y+lay*dt
ball.pos=ball.pos+ball.velocity*dt
if ball.x>-3.5 and ball.x<=3.5:
vx=sqrt(2*(-g*ball.y+0.5*(vx**2+vy**2)-f*ds))
ball.velocity.x=ball.velocity.x+mu*g*dt
ball.velocity.y=0
ball.pos=ball.pos+ball.velocity*dt
if ball.x>3.5 and ball.x<8.6:
vx=vx*cos(angle)
vy=sqrt(2/m*(m*-g*ball.y-f*ds))
#print vy
vy=vy*sin(angle)
#print vy
ball.velocity.x=ball.velocity.x+rax*dt
ball.velocity.y=ball.velocity.y+ray*dt
ball.pos=ball.pos+ball.velocity*dt
#print ball.pos




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


Re: [Python-Dev] PEP: __source__ proposal

2004-12-04 Thread Nick Coghlan
Stelios Xanthakis wrote:
It appears that there are the 'module people' who
find this feature irrelevant. Indeed. If we are interested
in distributing modules and increasing the number of
people who use python programs,then  __source__ is redundant.
OTOH, programming python is easy and fun and I think
the proposed feature will make it even more fun and it
aims in increasing the number of people who program
python for their every day tasks. It'd be interesting to
hear if the developers of IDLE/ipython/etc could use this.
The feedback here (and the initial response on py-dev a while back) suggests to 
me that you should look at making this a feature of the interactive mode. 
Something that affects both Python's main interactive shell, plus the relevant 
class in the standard library (CommandInterpreter or whatever it is called).

A late-night-train-of-thought example of what might be handy is below - keep in 
mind that I haven't looked at what enhanced Python shells like IPython can do, 
so it may be there are tools out there that do something like this already. It 
would be handy to have a standard library module that supported "on-the-fly" 
editing, though (this capability would then be available to anyone embedding 
Python as a scripting engine).

Cheers,
Nick.
==
>>>import source
>>>class bob:
...  def mary():
...pass
...  def tim():
...print 'Tim'
...
>>>print bob.__source__
class bob:
  def mary():
pass
  def tim():
print 'Tim'
>>>print bob.mary.__source__
def mary():
  pass
>>> source.edit(bob.mary)
bob.mary(1)>def mary(text): # [1]
bob.mary(2)>  print "Mary:", text
bob.mary(3)>\save
>>> source.edit(bob.tim)
bob.tim(1)>\help
Commands: \help \cancel \save \deleteline
bob.tim(2)>\cancel
>>>print bob.__source__
"class bob:
  def mary(text):
print "Mary:", text
  def tim():
print 'Tim'
"
>>> bob().mary("Hi!")
Mary: Hi!
The basic ideas of the above:
"import source" triggers the storage of the __source__ attributes (e.g. via 
installation of appropriate hooks in the class and function definition process)

The 'edit' function is then able to take advantage of the stored source code to 
present each line of the original source for modification (e.g. to fix a minor 
bug in one function of a class definition). When the 'edit' is complete, it can 
be saved or cancelled.

1. The feature mentioned in the last paragraph is hard to show in the expected 
output :)

--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


os.listdir("\\\\delta\\public")

2004-12-04 Thread Egor Bolonev
import os
print os.listdir("delta\\public")
outputs
['Bases', 'Docs', 'Drivers', 'Soft', '\xc7\xe0\xec\xe5\xed\xe0 
\xd1\xe5\xf2\xe5\xe2\xee\xec\xf3 \xce\xea\xf0\xf3\xe6\xe5\xed\xe8\xfe', 
'Games']

and
import os
print os.listdir("delta")
outputs
Traceback (most recent call last):
 File "C:\Documents and Settings\Егор\My Documents\Scripts\test.py", line 
4, in ?
   print os.listdir("delta")
WindowsError: [Errno 53] : 'delta/*.*'

so how to get list of delta's shares? 

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


Re: How is Python designed?

2004-12-04 Thread Diez B. Roggisch
Hi,

> The basic idea of this technique is to create a class
> to represent each type of script phrase(that's the
> term I used in the program, it's just a piece of code
> for particular task such assignment,logical/loop
> control,function call, whatever). In the phase of
> compiling, phrase instances of such classed are made,
> and in the execution phase, starting from the first,
> each phrase instance is executed and jump to the next
> phrase instance for subsequential execution,
> like a finite state automa I would say. Currently the
> interpretation efficiency is comparable to most
> popular interpreters.

I'd say that's pretty much standard interpreter technique - an expression
like this:

foo = a + b * c

is translated and reduced to an abstract-syntax-tree something like this:

Assignment("foo", BinaryOp("+", Get("a"), BinaryOp("*", Get("b"),
Get("c"

Then on Assignment one can invoke eval(), and get the result. Assignment
will invoke eval on its children, which in turn will do that for their
operands, until something can be computed. The result is returned.

By using an emulated stack or register-machine, you can flatten that to
something like this:

push Get("c")
push Get("b")
push BinaryOp("*")
push Get("a")
push BinaryOp("+")
pop  Assignment("foo")

This is of course very makeshift - but you'll get the idea.

This doesn't mean I want to discourage you - on the contraire. Developing
your own language is highly educating, and I personally love it when I
"invent" something and then later find out that people much cleverer than
me did so before - it shows that I went down the same paths of thought :)

-- 
Regards,

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


Re: help needed

2004-12-04 Thread Nick Coghlan
In response to your first message, I offered some ideas on how to get more 
useful responses, along with a couple of general techniques for finding the 
problem yourself.

Reposting almost exactly the same message 8 or so hours later wasn't a 
suggestion featured in either category.

Cheers,
Nick.
--
http://mail.python.org/mailman/listinfo/python-list


Re: python-mode question

2004-12-04 Thread Skip Montanaro

Thomas> When I edit a Python script with XEmacs, then hit C-c C-c, the
Thomas> script is executed, the output is shown in a *Python Output*
Thomas> buffer, and the cursor is moved into this buffer.

Thomas> How can I change the behaviour so that the cursor stays where it
Thomas> was before?  I'm using Revision 4.29, if it matters.

I'd class this behavior as a bug.  It's not fixed in the latest version.
Can you file a bug report on SF ?

Thanks,

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


Bug in py32win manual for file_locking for Python 2.4

2004-12-04 Thread Pekka Niiranen
Hi,
I tried to lock file in w2k using example
directly from pyWin32 manual:
#--
>>> import pywintypes
>>> ov=pywintypes.OVERLAPPED() #used to indicate starting region to lock
>>> highbits=0x
>>> file="c:wilma.txt"
>>> import win32file
>>> import win32security
>>> import win32api
>>> secur_att = win32security.SECURITY_ATTRIBUTES()
>>> secur_att.Initialize()
>>> hfile=win32file.CreateFile( file, \
... win32con.GENERIC_READ|win32con.GENERIC_WRITE, \
... win32con.FILE_SHARE_READ|win32con.FILE_SHARE_WRITE, \
... secur_att, \
... win32con.OPEN_ALWAYS, \
... win32con.FILE_ATTRIBUTE_NORMAL , 0 )
>>> 
win32file.LockFileEx(hfile,win32con.LOCKFILE_EXCLUSIVE_LOCK,0,highbits,ov)
Traceback (most recent call last):
  File "", line 1, in ?
OverflowError: long int too large to convert to int
#-

However, using
highbits=0x7fff # equals hex(sys.maxint)
gives no errors, but does locking work if
highbits are not exactly 0x?
Does anybody have example of locking the whole directory
in one go without looping thru its files?
-pekka-
--
http://mail.python.org/mailman/listinfo/python-list


Re: assymetry between a == b and a.__eq__(b)

2004-12-04 Thread Mel Wilson
In article <[EMAIL PROTECTED]>,
Steven Bethard <[EMAIL PROTECTED]> wrote:
>Mel Wilson wrote:
>> In article <[EMAIL PROTECTED]>,
>> Steven Bethard <[EMAIL PROTECTED]> wrote:
>>
>>>I believe what Peter Otten was pointing out is that calling __eq__ is
>>>not the same as using ==, presumably because the code for == checks the
>>>types of the two objects and returns False if they're different before
>>>the __eq__ code ever gets called.
>>
>>
>> Doesn't seem to:
>[snip]
>
>Hmm... maybe it only shows up with subclassing?

:) Seems to:


Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> class Eq(object):
... def __eq__(self, other):
... return True
...
>>> class Neq(Eq):
... def __eq__(self, other):
... print "(according to Neq)"
... return False
...
>>> eq,neq=Eq(),Neq()
>>> eq==neq
(according to Neq)
False
>>> neq==eq
(according to Neq)
False
>>>



Regards.Mel.














































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


Re: Bug in py32win manual for file_locking for Python 2.4

2004-12-04 Thread Nick Coghlan
Pekka Niiranen wrote:
However, using
highbits=0x7fff # equals hex(sys.maxint)
gives no errors, but does locking work if
highbits are not exactly 0x?
Try using highbits=-0x7fff as your mask. That should set the MSB without 
tripping over the sys.maxint limit.

Cheers,
Nick.
--
http://mail.python.org/mailman/listinfo/python-list


Import Semantics, or 'What's the scope of an import?', and class attribute instantiation

2004-12-04 Thread Andrew James
All,
I'm having some trouble with understanding python's importing behaviour
in my application. I'm using psyco to optimise part of my code, but I'm
not sure whether it inherits throughout the rest of my application (read
this as for any imported module) if I import in in a 'higher-level'
module. For example:

A.py


import psyco
from B import BClass
class AClass():
...
...
b = BClass()

B.py


class BClass():
...
...

In general, I've noticed that if import X and B in A.py and want to
reference X.* from B.py, I need to import X again in B. Is this a hard
and fast rule, or is there a way I can import the common libs, etc. in
the starting .py file and have those inherited by other classes I
import/instantiate? How would I do this?

It seems to be the general consensus that it's best to keep a Python app
in fewer files in the same directory rather than spreading them out, a
few (or one) classes to a file in a directory hierarchy as in Java. I
understand this is due to Python's, self.* and import  operations
having a relatively high cost (traversing directories, etc. etc.)

What I don't see mentioned is that when I step through a Python script
(say, in Eric3), if the structure of the file is like this:

X.py


class myX():
att1 = 'Test'
att2 = []
att3 = MemoryHungryClass()

class myY():
a = 'Another test'

...

if __name__ == 'main':
x = myX()

Python loads all the class attributes into memory (or, at least, cycles
through them) at runtime *even if I never instantiate the class*. This
has lead me to write code like:

class myX():
att3 = None
def __init__(self):
att3 = MemoryHungryClass()

Which seems to work a little better, but it seems rather ugly. I guess
the reason Python does this is because it's interpreted, not statically
compiled (and so needs to know whether myX.attr3 exists when called),
but I don't understand why the interpreter can't parse/instantiate the
attributes on the first call to instantiate the class. Surely this would
be a reason *for* splitting your code up into multiple files?

Being relatively new to Python, I'm trying to avoid coding things in an
un-Python (read C++/Java) manner, and am looking for some tutorials on
python-specific advanced features I can use (things like closures,
lambda forms, map(), etc. etc.). Could anyone point me towards some good
resources?

I would much appreciate some assistance in finding some answers to these
questions, as the research I've done seems to be inconclusive, if not
downright confusing.

Many thanks,
Andrew 



-- 
Andrew James <[EMAIL PROTECTED]>

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


Re: Pythonic use of CSV module to skip headers?

2004-12-04 Thread Skip Montanaro

>> Assuming the header line has descriptive titles, I prefer the
>> DictReader class.  Unfortunately, it requires you to specify the
>> titles in its constructor.  My usual idiom is the following:

Michael> I deal so much with tab-delimited CSV files that I found it
Michael> useful to create a subclass of csv.DictReader to deal with
Michael> this, so I can just write:

Michael> for row in tabdelim.DictReader(file(filename)):
Michael>  ...

Michael> I think this is a lot easier than trying to remember this
Michael> cumbersome idiom every single time.

I'm not sure what the use of TABs as delimiters has to do with the OP's
problem.  In my example I flubbed and failed to specify the delimiter to the
constructors (comma is the default delimiter).

You can create a subclass of DictReader that plucks the first line out as a
set of titles:

class SmartDictReader(csv.DictReader):
def __init__(self, f, *args, **kwds):
rdr = csv.reader(*args, **kwds)
titles = rdr.next()
csv.DictReader.__init__(self, f, titles, *args, **kwds)

Is that what you were suggesting?  I don't find the couple extra lines of
code in my original example all that cumbersome to type though.

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


Re: Pythonic use of CSV module to skip headers?

2004-12-04 Thread Michael Hoffman
Skip Montanaro wrote:
I'm not sure what the use of TABs as delimiters has to do with the OP's
problem.
Not much. :) I just happen to use tabs more often than commas, so my 
subclass defaults to

You can create a subclass of DictReader that plucks the first line out as a
set of titles:
class SmartDictReader(csv.DictReader):
def __init__(self, f, *args, **kwds):
rdr = csv.reader(*args, **kwds)
titles = rdr.next()
csv.DictReader.__init__(self, f, titles, *args, **kwds)
Is that what you were suggesting?
Exactly.
I don't find the couple extra lines of
code in my original example all that cumbersome to type though.
If you started about half of the programs you write with those extra 
lines, you might . I'm a strong believer in OnceAndOnlyOnce.

Thanks to Nick Coghlan for pointing out that I no longer need do this in 
Python 2.4.
--
Michael Hoffman
--
http://mail.python.org/mailman/listinfo/python-list


Error in previous post - Import behaviour

2004-12-04 Thread Andrew James
All,
The example given in the previous e-mail I sent was wrong (and makes the
question look stupid). In the attribute instantiation example, the
__main__ declaration should read:

> if __name__ == 'main':
>   y = myY()

I meant it to show that even if I never instantiate X, its attributes
still get created.

Regards,
Andrew

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


Refactoring a generator function

2004-12-04 Thread Kent Johnson
Here is a simple function that scans through an input file and groups the lines of the file into 
sections. Sections start with 'Name:' and end with a blank line. The function yields sections as 
they are found.

def makeSections(f):
currSection = []
for line in f:
line = line.strip()
if line == 'Name:':
# Start of a new section
if currSection:
yield currSection
currSection = []
currSection.append(line)
elif not line:
# Blank line ends a section
if currSection:
yield currSection
currSection = []
else:
# Accumulate into a section
currSection.append(line)
# Yield the last section
if currSection:
yield currSection
There is some obvious code duplication in the function - this bit is repeated 
2.67 times ;-):
if currSection:
yield currSection
currSection = []
As a firm believer in Once and Only Once, I would like to factor this out into a separate function, 
either a nested function of makeSections(), or as a separate method of a class implementation. 
Something like this:

def makeSections(f):### DOESN'T WORK ###
currSection = []
def yieldSection():
if currSection:
yield currSection
del currSection[:]
for line in f:
line = line.strip()
if line == 'Name:':
# Start of a new section
yieldSection()
currSection.append(line)
elif not line:
# Blank line ends a section
yieldSection()
else:
# Accumulate into a section
currSection.append(line)
# Yield the last section
yieldSection()
The problem is that yieldSection() now is the generator, and makeSections() is not, and the result 
of calling yieldSection() is a new iterator, not the section...

Is there a way to do this or do I have to live with the duplication?
Thanks,
Kent
Here is a complete program:
data = '''
Name:
City:




Name:
City:


'''
import cStringIO# just for test
def makeSections(f):
''' This is a generator function. It will return successive sections
of f until EOF.
Sections are every line from a 'Name:' line to the first blank line.
Sections are returned as a list of lines with line endings stripped.
'''
currSection = []
for line in f:
line = line.strip()
if line == 'Name:':
# Start of a new section
if currSection:
yield currSection
currSection = []
currSection.append(line)
elif not line:
# Blank line ends a section
if currSection:
yield currSection
currSection = []
else:
# Accumulate into a section
currSection.append(line)
# Yield the last section
if currSection:
yield currSection
f = cStringIO.StringIO(data)
for section in makeSections(f):
print 'Section'
for line in section:
print '   ', line
print
--
http://mail.python.org/mailman/listinfo/python-list


Re: Import Semantics, or 'What's the scope of an import?', and class attribute instantiation

2004-12-04 Thread Diez B. Roggisch
Hi,

> I'm having some trouble with understanding python's importing behaviour
> in my application. I'm using psyco to optimise part of my code, but I'm
> not sure whether it inherits throughout the rest of my application (read
> this as for any imported module) if I import in in a 'higher-level'
> module. For example:
 
In the psyco doc it says that you can do full() - but it will bloat the
memory consumption, so its better to use either explicit or profile-based
optimization. I suggest reading the docs for psyco on thate.
> 
> A.py
> 
> 
> import psyco
> from B import BClass
> class AClass():
> ...
> ...
> b = BClass()
> 
> B.py
> 
> 
> class BClass():
> ...
> ...
> 
> In general, I've noticed that if import X and B in A.py and want to
> reference X.* from B.py, I need to import X again in B. Is this a hard
> and fast rule, or is there a way I can import the common libs, etc. in
> the starting .py file and have those inherited by other classes I
> import/instantiate? How would I do this?

No, you can't - and as you say later on that you come from java: That's not
possible there, either.

Generally speaking, for each unit/file for interpretation or compilation (in
java/c++), you have to import all names that should be known there.

> It seems to be the general consensus that it's best to keep a Python app
> in fewer files in the same directory rather than spreading them out, a
> few (or one) classes to a file in a directory hierarchy as in Java. I
> understand this is due to Python's, self.* and import  operations
> having a relatively high cost (traversing directories, etc. etc.)

No - the cost for importing are not so high, and occur only once. A second
import will make python recognize that this module is already known, so it
won't be imported again.

So they don't add much to your runtime - only startup time. Which is still
way faster than java's

Java simply limits you to one class per file so the can maintain a
bijektive .java <-> .class  mapping. I guess for make-like dependency
checking.

And as in java the class is the only unit of code you can write, there is no
way to declare functions outside of classes. Which you can do in python.

If you really want to, you can go the way way java does it. But then you
have to manually update the __init__.py for a module to make all declared
names visible, like this:

foo/__init__.py
from A import A

foo/A.py
class A:
pass

This is of course somewhat tedious. Instead putting all classes and
functions directly into a file called foo.py will rid you of these
complications, and keep belonging code in one file.

> Python loads all the class attributes into memory (or, at least, cycles
> through them) at runtime *even if I never instantiate the class*. This
> has lead me to write code like:
> 
> class myX():
> att3 = None
> def __init__(self):
> att3 = MemoryHungryClass()
> 
> Which seems to work a little better, but it seems rather ugly. I guess
> the reason Python does this is because it's interpreted, not statically
> compiled (and so needs to know whether myX.attr3 exists when called),
> but I don't understand why the interpreter can't parse/instantiate the
> attributes on the first call to instantiate the class. Surely this would
> be a reason *for* splitting your code up into multiple files?

I'm not totally sure that I understand what you are doing here - it seems to
me that you confuse class attributes with instance attributes. The latter
are (usually) created in the __init__-method, like this:

class Foo:
def __init__(self):
self.bar = 1


a = Foo()
b = Foo()
a.bar += 1

print a.bar, b.bar

yield 2 for a.bar and  1 for b.bar

The former are attributes created while importing (so far you're right), but
they are created only once - for the _class_, not the objects of that
class. So you can compare them to static properties in java. Which will
also be created at the first import, and consume whatever resources they
need - time- and memorywise.

You can of course instaniate them lazily - like this:

class Foo:
bar = None
def __init__(self):
if Foo.bar is None:   
 Foo.bar = SomeMemoryConsumingObject()

So bar gets filled only when you actually instantiate a Foo. But this is no
different from java:

class Foo {

static Bar bar = null;

public Foo() {
if (bar == null) {
bar = new SomeMemoryConsumingObject();
}
}
}

> Being relatively new to Python, I'm trying to avoid coding things in an
> un-Python (read C++/Java) manner, and am looking for some tutorials on
> python-specific advanced features I can use (things like closures,
> lambda forms, map(), etc. etc.). Could anyone point me towards some good
> resources?

http://docs.python.org/tut/tut.html

Especially

http://docs.python.org/tut/node8.html

-- 
Regards,

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


Re: Dr. Dobb's Python-URL! - weekly Python news and links (Dec 2)

2004-12-04 Thread chriskreuzer

David Fraser wrote:
> Rocco Moretti wrote:



> > I'm sorry I'm not able to give a direct URL, but it seems they've
> > switched over to a horrendously long, stateful URL system which
doesn't
> > lend itself to direct linkage.
>
> Doesn't seem stateful to me, just has different thread / message ids
to
> the old system:

Using different message IDs is bad.
Usenet already has a header for this: Message ID.

>
http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/1db72429a2b05ce0/2c1679d365ffe9dd#2c1679d365ffe9dd
>
> The syntax is thread/$threadid/$messageid#$messageid
> At least for me, these URLs are transferable between computers /
browsers

But if Google ever moves away from maintaining a Usenet archive, then
any links involving Google IDs will be broken. This happened with
DejaNews and will happen with links to old URLs with the GG1 (Google
Groups 1) system (unless they maintain continuity). Even then, all was
not lost because you could extract the Usenet message ID from the URL.
It looks like you can't do this with the new GG2 message references.

> You can also access the message directly:
>
>
http://groups-beta.google.com/group/comp.lang.python/msg/2c1679d365ffe9dd

I would also *always* add the Usenet message ID.
This timeproofs it against any future changes.

Christopher

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


Re: os.listdir("\\\\delta\\public")

2004-12-04 Thread Michael Hoffman
Egor Bolonev wrote:
   print os.listdir("delta")
WindowsError: [Errno 53] : 'delta/*.*'
so how to get list of delta's shares?
I'm sure someone will post the answer shortly, but you shouldn't expect 
that to work.

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\>hostname
MINIMOO
C:\>dir \\MINIMOO
The filename, directory name, or volume label syntax is incorrect.
--
Michael Hoffman
--
http://mail.python.org/mailman/listinfo/python-list


Re: Dr. Dobb's Python-URL! - weekly Python news and links (Dec 2)

2004-12-04 Thread Gustavo Córdova Avila
Thomas Heller wrote:
Gerrit <[EMAIL PROTECTED]> writes:
 

Cameron Laird wrote:
   

Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Dec  2)
 

What is the frequency of the weekly Python-URL? (-;
   

According to the name, about 1.6 µHz.
Thomas
 

NOW you've done it!!
Made me spill me hot-choco on me keyboard you did!!
Damn that was good, thanks for the laugh... :-D
-gus
--
http://mail.python.org/mailman/listinfo/python-list


Re: Help with modules/packages.

2004-12-04 Thread Steve Holden
Christopher J. Bottaro wrote:
Hello,
I want to be able to say stuff like "import CJB.ClassA" and "import
CJB.ClassB" then say "c = CJB.ClassA()" or "c = CJB.ClassB()".  CJB will be
a directory containing files "ClassA.py" and "ClassB.py".
Now that I think about it, that can't work because Python allows you 
import
different things from the same module (file).  If I said "import
CJB.ClassA", I'd have to instantiate ClassA like "c = CJB.ClassA.ClassA()".
I guess I could say "from CJB.ClassA import ClassA", but then I'd
instantiate like "c = ClassA()".  What I really want is to say "c =
CJB.ClassA()"...is that possible?
Is my understand of modules/packages correct or am I way off?
Thanks for the help.
Your understanding appears to be roughly correct, but you are 
overlooking the possibility that the package could manage its own namespace.

One thing you could try is, in the __init__.py for CJB, do
from ClassA import ClassA
from ClassB import ClassB
You can then refer to the classes using the names you want.
regards
 Steve
--
http://www.holdenweb.com
http://pydish.holdenweb.com
Holden Web LLC +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: using cmd.exe as a telnet client

2004-12-04 Thread Jp Calderone
On Sat, 4 Dec 2004 03:31:12 -0800 (PST), Eyal Lotem <[EMAIL PROTECTED]> wrote:
> 
> You simple have to run PyInvoke's server.py on the
> server, and then in the client, you can Pythonically
> control anything on the server:
> 
> client = pyinvoke.connect(('some_server', some_port))
> client.modules.shutil().rmtree('/tmp/blah')

  This seems terribly, terribly insecure; the kind of thing no one should ever 
run on any server or desktop anywhere for any reason.

  What am I missing?

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


Atlanta Area Pythonistas

2004-12-04 Thread Jeremy Jones
We will be having an informal gathering of Atlanta-area Pythonistas on 
Thursday, December 9 at 7:30PM at the Caribou at N. Druid Hills and 
LaVista.  Anyone interested (even if you can't come), please email me 
(zanesdad at bellsouth dot net) so I can know how many people to expect 
(or, how many are interested, but cannot make it this round).  I can 
provide directions to anyone needing them.

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


Re: Quixote+Nevow+LivePage

2004-12-04 Thread Jp Calderone
On 3 Dec 2004 22:02:51 -0800, Mir Nazim <[EMAIL PROTECTED]> wrote:
>Hi
> 
> I am a PHP developer and in trying to get a better tool for developing
> web apps, I have been strugling with zope for past few months and
> still could not get anything useful work up and going. I really felt
> that "Z" shaped learning curve. Yesterday I was looking at quixote. I
> was surprized how simple it is. I think quiote gives the power without
> getting into the way. And in just a few hours I had quite a good
> understanding of framework and actually got something up and working
> (http://www.quixote.ca/learn/1). I feel  quixote is the simplest way
> to develop powerful web apps. I needed a simple and powerfull web
> framework to develop web apps that are NOT content oriented and where
> mostly GUI clients have ruled. And I think quixote is just the tool
> for me.
> 
> I also came across nevow. Its is also good, rather very good.
> Especially Live Page is really cool idea. It really help separate
> logic and presentation and is simpler than MVC thing that I could
> never get a nack of.
> 
> Now I have three questions:
> 
> Q1) Is it possibe to use "Nevow + LivePage + Quixote" together in a
> web app. Live Page is really important for me as I am not into content
> oriented web apps.
> 
> Q2) Is is nessary that LivePage only with Twisted or can work with any
> web server like Apache.
> 

  I haven't used LivePage myself, but someone in the know tells me 
that LivePage requires an extra, non-HTTP connection to operate, so
will pretty much only work with Twisted.

> Q3) I cannot understand how to get quixote up and working under Apache
> using mod_python, FastCGI, SCGI (I have used only mod_php). A link to
> a tutorial will be good.
> 
> I saw a paper A. M. Kuchling (http://www.amk.ca/talks/quixote/) that
> said that nevow can be used with quixote but it did not mention
> anything of LivePage.
> 
> Please provide comments, Pros and Cons of the aproach. Links to
> relevent articles and tutorials are really appreciated
> 
> Thanks in advance.

  You might get more in the way of helpful responses on this list:

http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web

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


Re: Audio interviews of Guido or other Python advocates?

2004-12-04 Thread Fredrik Lundh
Dave Benjamin wrote:

> I looked around for recordings of Guido, but couldn't find any.

http://www.python.org/~guido/guido.au

 



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


os.listdir("\\\\delta\\public")

2004-12-04 Thread Ishwor
hi check your seperator variable in the os module.
:)
for example

>>> import os
>>> os.sep
'\\'
Now what you do is :-
>> os.listdir("D:" + os.sep + "any_other_folder_name" + os.sep);
:)

Have a look at the error below which is same as yours. The seperator
variable is put after the drive name and not before the drive name.
>>> os.listdir("\\c");

Traceback (most recent call last):
 File "", line 1, in -toplevel-
   os.listdir("\\c");
WindowsError: [Errno 3] The system cannot find the path specified: '\\c/*.*'

In Linux this would be somewhat like this
>>> os.listdir("/dev");
In general use the most platform independent variable names (e.g
os.sep) unless you intend the program to be used only by yourself. :)

[snip]

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


Re: Audio interviews of Guido or other Python advocates?

2004-12-04 Thread Peter Hansen
Dave Benjamin wrote:
Ever since I heard Paul Graham's OSCON speech as audio, I've been somewhat
interested in hearing what all these voices of computer culture sound like,
and what they talk about. I enjoyed a few of Larry Wall's speeches as well
as Tim O'Reilly's, here: http://technetcast.ddj.com/
I looked around for recordings of Guido, but couldn't find any. Does anyone
know of any streamable audio (or video) interviews or speeches featuring
Guido, the bots, or any other interesting people in the Python community?
I've seen a video of a Bruce Eckels presentation; that's about the closest
I've found so far.
The canonical recording of Guido's voice can be found on his
own web page at http://www.python.org/~guido/ .   ;-)
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: os.listdir("\\\\delta\\public")

2004-12-04 Thread Peter Hansen
Egor Bolonev wrote:
import os
print os.listdir("delta")
outputs
Traceback (most recent call last):
 File "C:\Documents and Settings\Егор\My Documents\Scripts\test.py", 
line 4, in ?
   print os.listdir("delta")
WindowsError: [Errno 53] : 'delta/*.*'

so how to get list of delta's shares?
As Michael points out, there's no reason to think that should
have worked.  You can't do a directory of a computer, only
a drive on the computer, and likewise you can't do a directory
of a computer on a network, only of the resources is shares.
Try grabbing the output of os.popen(r"net view \\delta") and
parse it to get a list of the shares:
c:\>net view \\monolith
Shared resources at \\monolith
Share name  Type   Used as  Comment
---
Printer Print   Microsoft Office Document Image Writer
Printer2Print   hp psc 1310 series
Printer3Print   HP LaserJet 4
shared  Disk   I:
SharedDocs  Disk
The command completed successfully.
No doubt you can also do this much more easily with the pywin32
package, or via COM (using pywin32 or ctypes), but I'll leave
that response to someone else.  Or you could figure it out yourself
if you are motivated enough.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Refactoring a generator function

2004-12-04 Thread Steven Bethard
Kent Johnson wrote:
Here is a simple function that scans through an input file and groups 
the lines of the file into sections. Sections start with 'Name:' and end 
with a blank line. The function yields sections as they are found.

def makeSections(f):
currSection = []
for line in f:
line = line.strip()
if line == 'Name:':
# Start of a new section
if currSection:
yield currSection
currSection = []
currSection.append(line)
elif not line:
# Blank line ends a section
if currSection:
yield currSection
currSection = []
else:
# Accumulate into a section
currSection.append(line)
# Yield the last section
if currSection:
yield currSection
There is some obvious code duplication in the function - this bit is 
repeated 2.67 times ;-):
if currSection:
yield currSection
currSection = []
You can write:
for section in yieldSection():
yield section
in both places, but I assume you still don't like the code duplication 
this would create.

How about something like (completely untested):
if line == 'Name:' or not line:
if currSection:
yield currSection
currSection = []
if line == 'Name:'
currSection.append(line)
Another consideration: in Python 2.4, itertools has a groupby function 
that you could probably get some benefit from:

>>> class Sections(object):
... def __init__(self):
... self.is_section = False
... def __call__(self, line):
... if line == 'Name:\n':
... self.is_section = True
... elif line == '\n':
... self.is_section = False
... return self.is_section
...
>>> def make_sections(f):
... for _, section in itertools.groupby(f, Sections()):
... result = ''.join(section)
... if result != '\n':
... yield result
...
>>> f = 'Name:\nA\nx\ny\nz\n\nName:\nB\na\nb\nc\n'.splitlines(True)
>>> list(make_sections(f))
['Name:\nA\nx\ny\nz\n', 'Name:\nB\na\nb\nc\n']
--
http://mail.python.org/mailman/listinfo/python-list


Re: assymetry between a == b and a.__eq__(b)

2004-12-04 Thread Tim Peters
[Mel Wilson]
> :) Seems to:
> 
> 
> Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> class Eq(object):
> ... def __eq__(self, other):
> ... return True
> ...
> >>> class Neq(Eq):
> ... def __eq__(self, other):
> ... print "(according to Neq)"
> ... return False
> ...
> >>> eq,neq=Eq(),Neq()
> >>> eq==neq
> (according to Neq)
> False
> >>> neq==eq
> (according to Neq)
> False
> >>>

See the Python (language, not library) reference manual, section 3.3.8
("Coercion rules"), bullet point starting with:

Exception to the previous item: if the left operand is an
instance of a built-in type or a new-style class, and the right
operand is an instance of a proper subclass of that type or
class, ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Audio interviews of Guido or other Python advocates?

2004-12-04 Thread Fredrik Lundh
Dave Benjamin wrote:

> I looked around for recordings of Guido, but couldn't find any. Does anyone
> know of any streamable audio (or video) interviews or speeches featuring
> Guido, the bots

a bot-owned horse is featured on this DVD:

http://www.discshop.se/LIVE/shop/ds_produkt.php?lang=&id=39726

 



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


Opening a file in Python using windows.

2004-12-04 Thread Ishwor
On 3 Dec 2004 08:38:37 -0800, ed <[EMAIL PROTECTED]> wrote:
> I do have  permission toa ccess the file as that file is careted and read my 
> me.
> I have read/write access to that location. regards

That shouldn't be really hard. :)
okay imagine you have a file called test.txt in C:\Python24\
now go to the IDLE prompt if you have one or just use Python prompt.
I am assuming you know what they are & how to do them. :) If you don't
then go read some books. :)

There  are two basic in-built operations to open a file.
The first one is open & the the obvious other one is called file.
file is just an alias for open.

type these lines in the prompt

>>> open("C:\\Python24\\test.txt",'r').readlines()
['This is test file. :)']

So thats there.. the whole file in a line :).. However remember that
it returns a list for further processing if you want to or just forget
it. if you break up those above line into 2 lines then they become

>>> test = open("C:\\Python24\\test.txt",'r') # read-only
>>> test.readlines()
['This is test file. :)']

So there you have it. The power of Python. The first line opens a file
object & places
the output at certain address in the computer memory & test
*references* that address. The second line (test.readlines()) reads
the actuall stream of bytes from that location. :)

> > If you do not have permission to access the files, switching to a
> > different language will not help you.  You need to determine the cause
> > of your access errors first.

Agreed but the OP does have permission so this assumption doesn't hold!

[snip]


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


Re: os.listdir("\\\\delta\\public")

2004-12-04 Thread Ishwor
On Sat, 04 Dec 2004 11:40:15 -0500, Peter Hansen <[EMAIL PROTECTED]> wrote:

> As Michael points out, there's no reason to think that should
> have worked.  You can't do a directory of a computer, only
> a drive on the computer, and likewise you can't do a directory
> of a computer on a network, only of the resources is shares.
> 
> Try grabbing the output of os.popen(r"net view \\delta") and
> parse it to get a list of the shares:
> 
> c:\>net view \\monolith
> Shared resources at \\monolith
> Share name  Type   Used as  Comment
> ---
> Printer Print   Microsoft Office Document Image Writer
> Printer2Print   hp psc 1310 series
> Printer3Print   HP LaserJet 4
> shared  Disk   I:
> SharedDocs  Disk
> The command completed successfully.
> 
> No doubt you can also do this much more easily with the pywin32
> package, or via COM (using pywin32 or ctypes), but I'll leave
> that response to someone else.  Or you could figure it out yourself
> if you are motivated enough.
> 
> -Peter
[snip]

sorry my mistake :)
-- 
cheers,
Ishwor Gurung
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: assymetry between a == b and a.__eq__(b)

2004-12-04 Thread Peter Otten
Tim Peters wrote:

> See the Python (language, not library) reference manual, section 3.3.8
> ("Coercion rules"), bullet point starting with:
> 
> Exception to the previous item: if the left operand is an
> instance of a built-in type or a new-style class, and the right
> operand is an instance of a proper subclass of that type or
> class, ...

So that is settled then. Not the most likely place to investigate when one
has just read that "Arguments to rich comparison methods are never coerced"
in 3.3.1 ("Basic customization"), though.

Peter

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


Re: Quixote+Nevow+LivePage

2004-12-04 Thread Jp Calderone
On Sat, 4 Dec 2004 15:40:44 -0200, Carlos Ribeiro <[EMAIL PROTECTED]> wrote:
>On Sat, 04 Dec 2004 16:17:06 GMT, Jp Calderone <[EMAIL PROTECTED]> wrote:
> >   I haven't used LivePage myself, but someone in the know tells me
> > that LivePage requires an extra, non-HTTP connection to operate, so
> > will pretty much only work with Twisted.
> 
> The basic technique is to use a "persistent" & hidden client-side
> frame that holds the JavaScript glue code. This code is not reloaded;
> it talks to the server using XMLRPC, which is an extension that is
> supported by many HTTP servers, and then uses the data to update the
> view (that is in another frame). A clever hack -- a "client-pull"
> model at its best. IOW: as far as the server is concerned, if it
> supports XMLRPC, then it's possible to implement something similar to
> LivePage.

  LivePage is more about server-push than client-pull.

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


Re: Audio interviews of Guido or other Python advocates?

2004-12-04 Thread Carlos Ribeiro
On Sat, 4 Dec 2004 18:04:36 +0100, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> Dave Benjamin wrote:
> 
> > I looked around for recordings of Guido, but couldn't find any. Does anyone
> > know of any streamable audio (or video) interviews or speeches featuring
> > Guido, the bots
> 
> a bot-owned horse is featured on this DVD:
> 
> http://www.discshop.se/LIVE/shop/ds_produkt.php?lang=&id=39726
> 
>  

Nice to see that you didn't lose your sense of humour. BTW, do bots
have a sense of humour? :-)

-- 
Carlos Ribeiro
Consultoria em Projetos
blog: http://rascunhosrotos.blogspot.com
blog: http://pythonnotes.blogspot.com
mail: [EMAIL PROTECTED]
mail: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Refactoring a generator function

2004-12-04 Thread max
Kent Johnson <[EMAIL PROTECTED]> wrote in
news:[EMAIL PROTECTED]: 

> Here is a simple function that scans through an input file and
> groups the lines of the file into sections. Sections start with
> 'Name:' and end with a blank line. The function yields sections
> as they are found.
> 
> def makeSections(f):
>  currSection = []
> 
>  for line in f:
>  line = line.strip()
>  if line == 'Name:':
>  # Start of a new section
>  if currSection:
>  yield currSection
>  currSection = []
>  currSection.append(line)
> 
>  elif not line:
>  # Blank line ends a section
>  if currSection:
>  yield currSection
>  currSection = []
> 
>  else:
>  # Accumulate into a section
>  currSection.append(line)
> 
>  # Yield the last section
>  if currSection:
>  yield currSection
> 
> There is some obvious code duplication in the function - this bit
> is repeated 2.67 times ;-): 
>  if currSection:
>  yield currSection
>  currSection = []
> 
> As a firm believer in Once and Only Once, I would like to factor
> this out into a separate function, either a nested function of
> makeSections(), or as a separate method of a class
> implementation. Something like this:
> 
> 
> The problem is that yieldSection() now is the generator, and
> makeSections() is not, and the result of calling yieldSection()
> is a new iterator, not the section... 
> 
> Is there a way to do this or do I have to live with the
> duplication? 
> 
> Thanks,
> Kent
> 
>

This gets rid of some duplication by ignoring blanklines altogether, 
which might be a bug...

 def makeSections2(f):
currSection = []
for line in f:
line = line.strip()
if line:
if line == 'Name:':
if currSection:
yield cs
currSection = []
currSection.append(line)
if currSection:
yield currSection

but 

 def makeSections2(f):
currSection = []
for line in f:
line = line.strip()

if line:
if line == 'Name:':
if currSection:
yield currSection
currSection = []
currSection.append(line)

elif currSection:
yield currSection

if currSection:
yield currSection

should be equivalent.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: HTTP response code

2004-12-04 Thread Carlos Ribeiro
On Fri, 3 Dec 2004 17:28:43 -0200, Jonas Galvez <[EMAIL PROTECTED]> wrote:
> Hi list, here's a question about urllib. Is it possible to simply
> retrieve the HTTP responde code for a given URL? I don't want to
> download the body of the HTTP message. I simply want to check the
> response code, like, if it is 200, 301 etc. Something like:
> 
> if urllib.urlopen(the_url).response_code == 200:
> # ...
> 
> Is there an easy way to do this?
> Should I be using urllib2 instead?

Jonas, check this link:

http://mail.python.org/pipermail/web-sig/2004-September/000814.html

There was a discussion on the WebSig about adding support for HEAD
requests on urllib2 (they were still not implemented at that time,
three months ago). Perhaps there is a patch somewhere for it...


-- 
Carlos Ribeiro
Consultoria em Projetos
blog: http://rascunhosrotos.blogspot.com
blog: http://pythonnotes.blogspot.com
mail: [EMAIL PROTECTED]
mail: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Quixote+Nevow+LivePage

2004-12-04 Thread Carlos Ribeiro
On Sat, 04 Dec 2004 17:46:02 GMT, Jp Calderone <[EMAIL PROTECTED]> wrote:
> On Sat, 4 Dec 2004 15:40:44 -0200, Carlos Ribeiro <[EMAIL PROTECTED]> wrote:
> 
> 
> >On Sat, 04 Dec 2004 16:17:06 GMT, Jp Calderone <[EMAIL PROTECTED]> wrote:
> > >   I haven't used LivePage myself, but someone in the know tells me
> > > that LivePage requires an extra, non-HTTP connection to operate, so
> > > will pretty much only work with Twisted.
> >
> > The basic technique is to use a "persistent" & hidden client-side
> > frame that holds the JavaScript glue code. This code is not reloaded;
> > it talks to the server using XMLRPC, which is an extension that is
> > supported by many HTTP servers, and then uses the data to update the
> > view (that is in another frame). A clever hack -- a "client-pull"
> > model at its best. IOW: as far as the server is concerned, if it
> > supports XMLRPC, then it's possible to implement something similar to
> > LivePage.
> 
>   LivePage is more about server-push than client-pull.

Strange, but when I was writing my own message, i *did* use
"server-push", at first, but then stopped -- it's really client-pull,
only that the client does it automatically. Client-pull is simple: the
JavaScript code simply fetches data from time to time, or when some
other kind of event happen.

Said that, a disclaimer: I'm just starting to study these tricks, so
my knowledege about it is far from definitive. For example: I'm not
sure if you can leave an open socket in the JavaScript code and wait
for the server to send more data to you in a server-push manner.
Perhaps you can do it using an persistent HTTP connection... but I'm
not sure if this will work with XMLRPC. I guess no, but I may be
wrong.

-- 
Carlos Ribeiro
Consultoria em Projetos
blog: http://rascunhosrotos.blogspot.com
blog: http://pythonnotes.blogspot.com
mail: [EMAIL PROTECTED]
mail: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Quixote+Nevow+LivePage

2004-12-04 Thread Carlos Ribeiro
On Sat, 04 Dec 2004 16:17:06 GMT, Jp Calderone <[EMAIL PROTECTED]> wrote:
>   I haven't used LivePage myself, but someone in the know tells me
> that LivePage requires an extra, non-HTTP connection to operate, so
> will pretty much only work with Twisted.

The basic technique is to use a "persistent" & hidden client-side
frame that holds the JavaScript glue code. This code is not reloaded;
it talks to the server using XMLRPC, which is an extension that is
supported by many HTTP servers, and then uses the data to update the
view (that is in another frame). A clever hack -- a "client-pull"
model at its best. IOW: as far as the server is concerned, if it
supports XMLRPC, then it's possible to implement something similar to
LivePage.

-- 
Carlos Ribeiro
Consultoria em Projetos
blog: http://rascunhosrotos.blogspot.com
blog: http://pythonnotes.blogspot.com
mail: [EMAIL PROTECTED]
mail: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pythonwin broke

2004-12-04 Thread Jean Brouwers


I'm not sure what Pythonwin is.  The Python start menu shows "Python
(command line)" and "IDLE (Python GUI)" plus docs, etc.

Your experiment with IDLE works just fine.  Both windows closed on
clickin X.  This is Windows XP SP2 with Python 2.3.4 from the
Python.org site.

/Jean Brouwers



In article <[EMAIL PROTECTED]>, Jive
<[EMAIL PROTECTED]> wrote:

> Do an experiment for me.  Open Pythonwin from the start menu.  Use the FILE
> menu to open a .py file.  Now try to close the window you just opened using
> the X button in the upper right.  Did it close?  Try closing Pythonwin using
> its X button.
> 
> 
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Python-Dev] PEP: __source__ proposal

2004-12-04 Thread John Roth
"Nick Coghlan" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
Stelios Xanthakis wrote:
It appears that there are the 'module people' who
find this feature irrelevant. Indeed. If we are interested
in distributing modules and increasing the number of
people who use python programs,then  __source__ is redundant.
OTOH, programming python is easy and fun and I think
the proposed feature will make it even more fun and it
aims in increasing the number of people who program
python for their every day tasks. It'd be interesting to
hear if the developers of IDLE/ipython/etc could use this.
I don't see enough here to make a very intelligent comment,
so I'll risk it and make what might be a rather uninformed
comment.
Are you trying to create a Smalltalkish environment where
you can simply edit anything on the fly, and then it's
immediately effective? While I don't know Smalltalk,
the ones I do know indicate that they liked that environment
very much.
However, this might have real problems with the dangling
references issue. Or maybe not: there may be ways of
redesigning the function object so that you can replace
the embedded code object on the fly.
John Roth
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net 
--
http://mail.python.org/mailman/listinfo/python-list


Re: PyQt on a Server

2004-12-04 Thread Bob Parnes
On 03 Dec 2004 11:15:26 -0500, Jerry Sievers <[EMAIL PROTECTED]> wrote:
> Bob Parnes <[EMAIL PROTECTED]> writes:
>> my /etc/ld.so.conf file already has that lib in it. So something else is
>> happening, but it clearly has nothing to do with python.
> 
> Have you run ldconfig (probably /sbin/ldconfig) since the line was
> added to the /etc ld config file?
> 

Good question. I have not done this often, and the need to run ldconfig after 
mounting the server /usr directory did not occur to me. So I tried
again, running ldconfig, and it still didn't work. After more checking,
I found that the entry in /etc/ld.so.conf was "usr/X11R6/lib", instead
of "/usr/X11R6/lib". I guess that was good enough during bootup. So adding 
the slash and running ldconfig again fixed everything. Thanks very much.

-- 
Bob Parnes
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pythonwin broke

2004-12-04 Thread Jean Brouwers

One more test, but after selecting "Modules Doc" from the start menu.  

The small pydoc window shows up, "Python documentation server ..." etc. 
Clicking the X button results in a "pythonw.exe Application Error" with
the message:

   The instruction at "0x..." referenced memory at "0x0..014".  The
memory could not be "read".  Click on OK to terminate the program.

Same Window XP SP2 machine running Python 2.3.4 downloaded from the
Python website (with just one extension, wxPython 2.4.2.4).

/Jean Brouwers



In article <[EMAIL PROTECTED]>,
Jean Brouwers <[EMAIL PROTECTED]> wrote:

> I'm not sure what Pythonwin is.  The Python start menu shows "Python
> (command line)" and "IDLE (Python GUI)" plus docs, etc.
> 
> Your experiment with IDLE works just fine.  Both windows closed on
> clickin X.  This is Windows XP SP2 with Python 2.3.4 from the
> Python.org site.
> 
> /Jean Brouwers
> 
> 
> 
> In article <[EMAIL PROTECTED]>, Jive
> <[EMAIL PROTECTED]> wrote:
> 
> > Do an experiment for me.  Open Pythonwin from the start menu.  Use the FILE
> > menu to open a .py file.  Now try to close the window you just opened using
> > the X button in the upper right.  Did it close?  Try closing Pythonwin using
> > its X button.
> > 
> > 
> >
-- 
http://mail.python.org/mailman/listinfo/python-list


about python advanced/new features documentation

2004-12-04 Thread Kl
Hi, python is really easy to learn in my opinion. There are loads of
tutorials/books on the web talking about the most common python features.
The problem comes when they add something new to the language or you want to
use advanced features. Since python is still evolving its difficult to find
good documentation on these new features/language changes.
Where can i find always up-to-date documentation about python? Unfortunately
the official tutorial and books become obsolete really fast.

Thanks.


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


Re: Help with modules/packages.

2004-12-04 Thread M.E.Farmer
"Christopher J. Bottaro" <[EMAIL PROTECTED]> wrote in message 
Hello Christopher,
You probably know this but I will mention it here for
completeness, if you want to be able to make a dir a package you also
need to add an __init__.py in the folder you wish to import from. The
__init__.py makes the dir a package.
Example:
 CJB
 __init__.py
 ClassA.py
 ClassB.py
 
> I want to be able to say stuff like "import CJB.ClassA" and "import
> CJB.ClassB" then say "c = CJB.ClassA()" or "c = CJB.ClassB()".  CJB will be
> a directory containing files "ClassA.py" and "ClassB.py".
Let us clarify a few things first.
"import CJB.ClassA" imports MODULE ClassA from PACKAGE CJB into the
namespace, but it is a MODULE and therefore not callable ;)
"c = CJB.ClassA()" is attempting to call the module ClassA , but you
want to call a ClassA CLASS in the ClassA MODULE
"c=CJB.ClassA.ClassA()"
BTW the names you have used makes this less understandable.
Maybe CJB.ModuleA.ClassA() would make this clearer.

> Now that I think about it, that can't work because Python allows you 
> import
> different things from the same module (file).  If I said "import
> CJB.ClassA", I'd have to instantiate ClassA like "c = CJB.ClassA.ClassA()".
> 
> I guess I could say "from CJB.ClassA import ClassA", but then I'd
> instantiate like "c = ClassA()".  What I really want is to say "c =
> CJB.ClassA()"...is that possible?

Yes it is possible.
I will show you how, BUT I must mention that it makes it VERY UNCLEAR
where the code comes from. The beauty of packages is code seperation
and modularity, and you are going to find aliasing makes for an
interesting debug session trying to guess where it all went wrong. You
should probably just bite the bullet and use
name = package.module.class it is easier to grasp 1 year from now and
makes it easier for others to read. The time you saved typing the
extra letters is less then the time you will spend looking at your
code. READABILITY counts.

Ok now onto the imports.
This is just *A* way to do it, there are others.
In your __init__.py you need to do your imports and aliasing:

# __init__.py
# this __init__.py file makes this dir a python package
import CJB.ClassA
import CJB.ClassB
classA = CJB.ClassA.ClassA
classB = CJB.ClassB.ClassB
# end of __init__.py

Now all you do is import.

import CJB
dir(CJB)
CJB.ClassA()
CJB.ClassB()

> Is my understand of modules/packages correct or am I way off?

Not to far off :)

> Thanks for the help.

HTH,
M.E.Farmer
-- 
http://mail.python.org/mailman/listinfo/python-list


Importing class from file in package

2004-12-04 Thread Florian Lindner
Hello,
I've two files in my package.
In the first file I want to inport a class which is declared in the 
second file. How can do that without stating the absolute path to the 
file, just the relative one?

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


Re: about python advanced/new features documentation

2004-12-04 Thread Kent Johnson
Kl wrote:
Hi, python is really easy to learn in my opinion. There are loads of
tutorials/books on the web talking about the most common python features.
The problem comes when they add something new to the language or you want to
use advanced features. Since python is still evolving its difficult to find
good documentation on these new features/language changes.
Where can i find always up-to-date documentation about python? Unfortunately
the official tutorial and books become obsolete really fast.
The "What's New" documents that are bundled with the last several Python releases are very helpful. 
They link to the PEPs which generally give a lot of detail about a change.

Quite a few recipes were contributed to the online Python Cookbook 
demonstrating Python 2.4 features.
Kent
Thanks.

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


Re: How is Python designed?

2004-12-04 Thread Limin Fu
Hi,

Probably you didn't understand well what I meant or
maybe I didn't express clearly what I meant. So I
think I need to spend more words to make it clear.

First, there is no abstract syntax tree generated for
the whole program, except for arithmetic
expression(even for this, it is slightly different
from what you said, I will come back to this point).
The Yuan (the name of the interpreter I designed)
interpreter first scans the source script, when it see
a pattern, for example "if(a>1)", it generates a
phrase object containing the arithmetic expression and
the ID (it is determined after all phrase objects are
created) of other two phrase objects. This phrase
object has a member method "execute()", whose
execution will return one of the IDs depending on the
value of "a>1". Then the next phrase object with that
ID is executed, and so on. I don't know how is the AST
for a whole program, I think it should be more
complicated than this.

Then about arithmetic expression, indeed, it is
represented as tree. But in Yuan each node contains
all the information it need for evaluation. For
example, the leaves contains either a variable or a
constant value or a function call, and other nodes
contains the operators. So far it is more or less the
same as what you mentioned. But the evaluation is
performed on this tree directly with deep first
search, which is different from the two methods you
mentioned. The first one you mentioned is the same as
my first implementation, which results an unefficient
recursive function call. The second is the standard
way of evaluating arithmetic expressions. I guess I am
not the first one to evaluate arithmetic expression by
deep-first search on the tree (I would be surprised if
I am). Any way it is enough efficient.

Your further comments and discussion are welcome, I'm
not that type who is afraid of negative opinions :)
Any way I will continue to improve that interpreter,
it's an interesting thing for me.

Regards,

Limin

> I'd say that's pretty much standard interpreter
> technique - an expression
> like this:
> 
> foo = a + b * c
> 
> is translated and reduced to an abstract-syntax-tree
> something like this:
> 
> Assignment("foo", BinaryOp("+", Get("a"),
> BinaryOp("*", Get("b"),
> Get("c"
> 
> Then on Assignment one can invoke eval(), and get
> the result. Assignment
> will invoke eval on its children, which in turn will
> do that for their
> operands, until something can be computed. The
> result is returned.
> 
> By using an emulated stack or register-machine, you
> can flatten that to
> something like this:
> 
> push Get("c")
> push Get("b")
> push BinaryOp("*")
> push Get("a")
> push BinaryOp("+")
> pop  Assignment("foo")
> 
> This is of course very makeshift - but you'll get
> the idea.
> 
> This doesn't mean I want to discourage you - on the
> contraire. Developing
> your own language is highly educating, and I
> personally love it when I
> "invent" something and then later find out that
> people much cleverer than
> me did so before - it shows that I went down the
> same paths of thought :)
> 
> -- 
> Regards,
> 
> Diez B. Roggisch
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 




__ 
Do you Yahoo!? 
Read only the mail you want - Yahoo! Mail SpamGuard. 
http://promotions.yahoo.com/new_mail 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Importing class from file in package

2004-12-04 Thread Peter Hansen
Florian Lindner wrote:
I've two files in my package.
In the first file I want to inport a class which is declared in the 
second file. How can do that without stating the absolute path to the 
file, just the relative one?
Assuming you mean by "package" that you have a folder named, say,
"mypkg" and an __init__.py file in it (that last part is required
for it to be a package in Python), and files a.py and b.py, this
works just fine if you do nothing special:
file mypkg/a.py contains:
class A:
pass
file mypkg/b.py contains:
import a
print a.A()
If I run the interpreter in the folder above mypkg,
this works just fine:
>>> import mypkg.b

So that leads me to think that either you didn't try this,
or I misunderstood the question...
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: xml.sax in Python 2.3.4

2004-12-04 Thread Uche Ogbuji
Gustaf Liljegren <[EMAIL PROTECTED]> wrote in message news:<[EMAIL 
PROTECTED]>...
> After a long break with Python I'm trying to get started again. I need 
> to do some SAX processing, but it seems things have changed, and I can't 
> find any docs describing how to make things work *today*. The SAX 
> example in the XML HOWTO [1] doesn't work anymore. I get this error:
> 
> D:\Test>python comics.py
> Traceback (most recent call last):
>File "comics.py", line 5, in ?
>  class FindIssue(saxutils.DefaultHandler):
> AttributeError: 'module' object has no attribute 'DefaultHandler'
> 
> I hope someone here can explain what has changed and how a working 
> example looks today. My needs are very simple, so don't want to install 
> any packages on top of the standard distribution.
> 
> 1. http://pyxml.sourceforge.net/topics/howto/node12.html

Things have certainly changed since all that.  You can easily correct
your own sample code using the standard Python docs:

http://python.org/doc/current/lib/module-xml.sax.html

Which I admit could be better organized (nor would more examples
hurt).  See also my Akara page on Python/SAX

http://uche.ogbuji.net/tech/akara/nodes/2003-01-01/sax

I have a lot on SAX in recent installments of my column:

http://www.xml.com/pub/au/84


-- 
Uche OgbujiFourthought, Inc.
http://uche.ogbuji.nethttp://4Suite.orghttp://fourthought.com
Use CSS to display XML -
http://www.ibm.com/developerworks/edu/x-dw-x-xmlcss-i.html
Location, Location, Location -
http://www.xml.com/pub/a/2004/11/24/py-xml.html
The State of Python-XML in 2004 -
http://www.xml.com/pub/a/2004/10/13/py-xml.html
Be humble, not imperial (in design) -
http://www.adtmag.com/article.asp?id=10286XMLOpen and more XML Hacks -
http://www.ibm.com/developerworks/xml/library/x-think27.html
A survey of XML standards -
http://www-106.ibm.com/developerworks/xml/library/x-stand4/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pythonic use of CSV module to skip headers?

2004-12-04 Thread Skip Montanaro

>> I don't find the couple extra lines of code in my original example
>> all that cumbersome to type though.

Michael> If you started about half of the programs you write with those
Michael> extra lines, you might . I'm a strong believer in
Michael> OnceAndOnlyOnce.

You're right of course.  I do use csv a lot, but only from a couple
specialized programs.

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


Article on updates to gnosis.xml.objectify

2004-12-04 Thread David Mertz, Ph.D.
Python/XML users might be interested in:

http://www-106.ibm.com/developerworks/xml/library/x-matters39.html

Title:
  Get the most out of gnosis.xml.objectify

Subtitle:
  Use utility functions for enhanced object behavior

Abstract:
  The XML binding gnosis.xml.objectify was designed, in many ways, more
  as a toolkit than as a final tool.  But this leaves some (potential)
  users confused about how to specialize it for some common tasks.  In
  this article, David shows readers how very thin wrappers can customize
  gnosis.xml.objectify to perform actions such as:  Provide XPath access
  to child objects; automatically reserialize objects to XML; modify the
  syntax of access to nodes.  Some of these techniques involve rather
  trivial specialization of provided parent classes.  Others involve
  small utility functions.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Audio interviews of Guido or other Python advocates?

2004-12-04 Thread Dave Benjamin
In article <[EMAIL PROTECTED]>, Fredrik Lundh wrote:
> Dave Benjamin wrote:
> 
>> I looked around for recordings of Guido, but couldn't find any.
> 
> http://www.python.org/~guido/guido.au

I found a few--slightly longer--video interviews here today:
http://technetcast.ddj.com/tnc_catalog.html?item_id=90

But thanks, the woodpecker was inspiring.

-- 
 .:[ dave benjamin: ramen/[sp00] -:- spoomusic.com -:- ramenfest.com ]:.
"talking about music is like dancing about architecture."
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Audio interviews of Guido or other Python advocates?

2004-12-04 Thread Dave Benjamin
In article <[EMAIL PROTECTED]>, Jimmy Retzlaff wrote:
> Dave Benjamin wrote:
>> I looked around for recordings of Guido, but couldn't find any. Does
>> anyone know of any streamable audio (or video) interviews or speeches
>> featuring Guido, the bots, or any other interesting people in the
> Python
>> community?
> 
> There's a video with a few folks in it at:
> 
> http://www.ibiblio.org/obp/pyBiblio/pythonvideo.php

Ohh, man, the geek love story was almost too much to bear. =)
Cool, so that covers Guido, Tim Peters, Eric Raymond, Jim Fulton...

-- 
 .:[ dave benjamin: ramen/[sp00] -:- spoomusic.com -:- ramenfest.com ]:.
"talking about music is like dancing about architecture."
-- 
http://mail.python.org/mailman/listinfo/python-list


Programming help

2004-12-04 Thread Alfred Canoy




Dear Sir/Madam,
Hello! I'm just new to programming and 
would like to ask for help..
Can you please give me clue how I 
should start solving the following problem below? 
-Build a module that contains three functions that do the 
following:

  

  Compute the average of a list of numbers

  Finds the statistical median value of a list of 
numbers

  Finds the mode of a list of 
numbers
Greatly appreciates it!
Al _ __ _Alfred CanoyAgana, 
GuamPacific time[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list

problem solving help

2004-12-04 Thread Alfred Canoy



Dear Sir/Madam,
Hello! I'm just new to programming and 
would like to ask for help..
Can you please give me clue how I 
should start solving the following problem below? 
Write a program that allows you to do the following five 
operations:

  

  Prompt the user to input a list of numbers (Hint: be sure to have a 
  way for the user to indicate that they are done finished providing the 
  list of numbers)

  Open a file that contains a list of numbers

  Compute the average, statistical median, and mode of the list of 
  numbers

  Store your answers in another file

  Asks the user whether they want to see the answers and if the answer 
  is yes, opens the file and displays the numbers
Greatly appreciates it!
Al _ __ _Alfred CanoyAgana, 
GuamPacific time[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list

some pointers for a newbie

2004-12-04 Thread John Evans
Hi, I have decided to play around with python, for the simple reason 
there appears nothing better to do at 2am on a sunday morning ;)

Anyway I am familiar with languages similar to PHP, javaa script, and 
also languages which have similarities on the surface to python such as 
Lingo (macromedia Director). so python is looking fairly straight 
forward, but what i am noticing is a complete lack of basic starter 
knowledge from myself - to be expected one would think :D

So what i ask is, for someone who wants to dip his toe in the pond and 
runs a powerbook with os x what tools, resources should I look into as 
being the most useful?

Also is it best to use an IDE like the one which comes from installing 
macPython, or is it best to use a basic text editor, or perhaps even 
xcode could be recommended (esp if I wanted to build some simple UI 
using interface builder?)

Any and all responses greatly received.
cheers
john
--
http://mail.python.org/mailman/listinfo/python-list


Re: assymetry between a == b and a.__eq__(b)

2004-12-04 Thread Nick Coghlan
Peter Otten wrote:
Tim Peters wrote:

See the Python (language, not library) reference manual, section 3.3.8
("Coercion rules"), bullet point starting with:
   Exception to the previous item: if the left operand is an
   instance of a built-in type or a new-style class, and the right
   operand is an instance of a proper subclass of that type or
   class, ...

So that is settled then. Not the most likely place to investigate when one
has just read that "Arguments to rich comparison methods are never coerced"
in 3.3.1 ("Basic customization"), though.


Nothing is getting coerced. It's just that "A binop B" gets translated to a 
method call differently depending on the types of A and B. The options being:

A.__binop__(B)  # 1 - the usual case
B.__binop__(A)  # 2.1 - commutative op, and B is a proper subclass of A
B.__rbinop__(A) # 2.2 - possibly non-commutative op, and B is a proper subclass 
of A
This is so that things like the following work:
.>>> class SillyAdd(long):
   __add__ = long.__mul__
   __radd__ = __add__

.>>> a = SillyAdd(4)
.>>> a
.4L
.>>> a + 5
.20L
.>>> 5 + a
.20L
Cheers,
Nick.
--
http://mail.python.org/mailman/listinfo/python-list


Re: some pointers for a newbie

2004-12-04 Thread Roy Smith
John Evans <[EMAIL PROTECTED]> wrote:
> So what i ask is, for someone who wants to dip his toe in the pond and 
> runs a powerbook with os x what tools, resources should I look into as 
> being the most useful?

I'm also running OSX on a PowerBook, so I guess we're kindred spirits.  
To a large extent, what tools you want to get depends on what you want 
to do with your new reptilian friend.

Are you interested in databases?  Then you might want to get mySQL 
running on your machine, and explore Python's database API.

Are you interested in web applications?  Then you might want to get 
Apache installed, and play with mod_python.

If you're interested in GUI programming, there are several Python GUI 
packages you can look at.  I'm not really into that kind of stuff, so 
I'll leave it to others to suggest which ones are the best.
 
> Also is it best to use an IDE like the one which comes from installing 
> macPython, or is it best to use a basic text editor, or perhaps even 
> xcode could be recommended (esp if I wanted to build some simple UI 
> using interface builder?)

Personally, I'm a big fan of emacs for programming, and ignore all the 
various IDE's.  That's not to say that they're not good or useful or 
powerful, just that they're not my cup of tea.  If you decide to go the 
emacs route, you definitely want to download the python mode support for 
emacs (it's on www.python.org somewhere).

Once you get a bit more serious and start to work on large-scale 
applications, I would certainly look at the junit module that now comes 
standard with Python.

The one major deficiency with the Python that Apple ships with OSX is 
that it doesn't come with readline support.  Readline is the thing that 
lets you interactive input editing and history processing (like bash and 
several other shells support on the command line).  I can't live without 
it, so I rebuilt Python from source (after downloading the GNU readline 
package and building that).  Getting a Python built with readline 
support will really improve your Pythonic experience.  I have no clue 
why Apple doesn't ship it that way.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Python-Dev] PEP: __source__ proposal

2004-12-04 Thread Nick Coghlan
John Roth wrote:
I don't see enough here to make a very intelligent comment,
so I'll risk it and make what might be a rather uninformed
comment.
This was a misdirected reply on my part - the rest of the discussion can be 
found in the python-dev archives on python.org or gmane.

I think your comments were basically on target, though - the idea is to be able 
to 'recompile' portions of the interactive session, replacing the code objects 
inside the function structure. (or adding entries to class dictionaries, etc, etc)

Cheers,
Nick.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Help with modules/packages.

2004-12-04 Thread Nick Coghlan
Christopher J. Bottaro wrote:
Hello,
I want to be able to say stuff like "import CJB.ClassA" and "import
CJB.ClassB" then say "c = CJB.ClassA()" or "c = CJB.ClassB()".  CJB will be
a directory containing files "ClassA.py" and "ClassB.py".
Now that I think about it, that can't work because Python allows you 
import
different things from the same module (file).  If I said "import
CJB.ClassA", I'd have to instantiate ClassA like "c = CJB.ClassA.ClassA()".
I guess I could say "from CJB.ClassA import ClassA", but then I'd
instantiate like "c = ClassA()".  What I really want is to say "c =
CJB.ClassA()"...is that possible?
Is my understand of modules/packages correct or am I way off?
To collapse the namespace locally (i.e. in the module you're currently writing, 
rather than in the package you're referring to), you can use a convention like:

from CJB.ModuleA import ClassA as CJB_A
from CJB.ModuleB import ClassB as CJB_B
This also has the advantage of being slightly faster - each '.' in a name 
represents another namespace lookup, which happens at run time, not compile 
time. This can end up mattering if the lookup is being done inside a loop.

The above idiom gives you a reference directly to the classes you want to use, 
thus allowing them to be found directly in the module's own dictionary.

Cheers,
Nick.
--
http://mail.python.org/mailman/listinfo/python-list


Please help here: python <==> COM

2004-12-04 Thread mep
Hi,all
I'm scripting flashget (A download management tool,
http://www.amazesoft.com/) using
python win32 extension, opening a downloading dialog.
The following pythong code NOT work:
CODE BEGIN
 #!/usr/bin/env python
 # -*- coding: cp936 -*-

 import win32com.client

 flashget = win32com.client.Dispatch('JetCar.Netscape')
 params = ('http://test.com/1',
   'http://test.com/2',
   'http://test.com/3',
   'http://test.com/4',
   'http://test.com/5')

 flashget.AddUrlList(params)
CODE END

It complaints the following:
  File "", line 2, in AddUrlList
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None,
None,  0, -2146828283), None)

But the following VBS code does the tricky:
CODE BEGIN
 Dim params(4)
 set flashget=CreateObject("JetCar.Netscape")

 params(0) = "http://test.com/1";
 params(1) = "http://test.com/2";
 params(2) = "http://test.com/3";
 params(3) = "http://test.com/4";
 params(4) = "http://test.com/5";

 flashget.AddUrlList params
CODE END

Any hints?

-- 
Best Regards,
Wang Kebo

http://www.huihoo.org/~mep


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


Re: HTTP response code

2004-12-04 Thread Ian Bicking
Jonas Galvez wrote:
Hi list, here's a question about urllib. Is it possible to simply 
retrieve the HTTP responde code for a given URL? I don't want to 
download the body of the HTTP message. I simply want to check the 
response code, like, if it is 200, 301 etc. Something like:

if urllib.urlopen(the_url).response_code == 200:
# ...
Is there an easy way to do this?
Should I be using urllib2 instead?
I'd recommend using httplib instead of urllib, and running a HEAD request.
>>> import httplib
>>> conn = httplib.HTTPConnection('localhost')
>>> conn.request('HEAD', '/whatever')
>>> res = conn.getresponse()
>>> res.status
404
--
Ian Bicking  /  [EMAIL PROTECTED]  / http://blog.ianbicking.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: some pointers for a newbie

2004-12-04 Thread Jon Mercer
On the matter of IDEs, I've found that Eclipse (http://www.eclipse.org)
is amazing, although I suspect that it takes a bit of learning to get
used to it and I'm nowhere near making full use of all it can do. It has
a really useful plugin in the shape of PyDev. I strongly recommend
having a play, although at 2am on a Sunday morning it may be peripheral
to what you are trying to achieve!

Another post here has recommended playing with the JUnit that ships with
Python. Has anyone else looked into integrating this in an Eclipse IDE?
I'de be very interested to know. I'm a bit of a newbie to Python myself
and didn't even know there was a unit testing module/facility/whatever
available. Where can I find more info???

Best to all,

Jon

On Sun, 2004-12-05 at 02:33 +0200, John Evans wrote:
> Hi, I have decided to play around with python, for the simple reason 
> there appears nothing better to do at 2am on a sunday morning ;)
> 
> Anyway I am familiar with languages similar to PHP, javaa script, and 
> also languages which have similarities on the surface to python such as 
> Lingo (macromedia Director). so python is looking fairly straight 
> forward, but what i am noticing is a complete lack of basic starter 
> knowledge from myself - to be expected one would think :D
> 
> So what i ask is, for someone who wants to dip his toe in the pond and 
> runs a powerbook with os x what tools, resources should I look into as 
> being the most useful?
> 
> Also is it best to use an IDE like the one which comes from installing 
> macPython, or is it best to use a basic text editor, or perhaps even 
> xcode could be recommended (esp if I wanted to build some simple UI 
> using interface builder?)
> 
> Any and all responses greatly received.
> 
> cheers
> 
> john
> 

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


Re: How is Python designed?

2004-12-04 Thread Robert
Sorry for my interrupting the discussion : ).  I am a graduate student
in a chinese  university, and i am very interested in the Yuan
language. I'd like to join in the development of Yuan and do some work
for this language. BTW, i like this word, "Yuan" : )

I have 3 or 4 years experience in C++, and i have strong programming
skills about C++(at least in my opinion :) ) . I am interested in the
compiling technology and virtual machine technology. And i am reading
the  written by
Bill Blunden now. I had the thought of starting an open source project
which contains a virtual machine and a scripting language a few days
ago, just like a very simple python. Well, i know it is very difficult,
but it is my dream : ). Luckly i  found "Yuan" here. So it is my
pleasure if i can become a member of "Yuan" :)

Waiting for your reply. :)

Best regards.


Ru Chen

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


Re: Quixote+Nevow+LivePage

2004-12-04 Thread Dave Brueck
Jp Calderone wrote:
On 3 Dec 2004 22:02:51 -0800, Mir Nazim <[EMAIL PROTECTED]> wrote:
Q1) Is it possibe to use "Nevow + LivePage + Quixote" together in a
web app. Live Page is really important for me as I am not into content
oriented web apps.
Q2) Is is nessary that LivePage only with Twisted or can work with any
web server like Apache.

  I haven't used LivePage myself, but someone in the know tells me 
that LivePage requires an extra, non-HTTP connection to operate, so
will pretty much only work with Twisted.
Do you have a reference that says this - I'd like to know for sure. I did a 
quick perusal of the code and thought that all the communication was via the 
XmlHttpRequest functionality available in a lot of modern browsers (IE, Mozilla, 
Safari).

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


Re: Quixote+Nevow+LivePage

2004-12-04 Thread Jp Calderone
On Sat, 04 Dec 2004 20:05:59 -0700, Dave Brueck <[EMAIL PROTECTED]> wrote:
>Jp Calderone wrote:
> > On 3 Dec 2004 22:02:51 -0800, Mir Nazim <[EMAIL PROTECTED]> wrote:
> >>Q1) Is it possibe to use "Nevow + LivePage + Quixote" together in a
> >>web app. Live Page is really important for me as I am not into content
> >>oriented web apps.
> >>
> >>Q2) Is is nessary that LivePage only with Twisted or can work with any
> >>web server like Apache.
> >>
> > 
> > 
> >   I haven't used LivePage myself, but someone in the know tells me 
> > that LivePage requires an extra, non-HTTP connection to operate, so
> > will pretty much only work with Twisted.
> 
> Do you have a reference that says this - I'd like to know for sure. I did a 
> quick perusal of the code and thought that all the communication was via the 
> XmlHttpRequest functionality available in a lot of modern browsers (IE, 
> Mozilla, 
> Safari).

  Just this:

[11:11]  exarkun: if you are on that list, will you reply and
mention that livepage requires access to the raw socket apis and thus only
works with twisted.web
[11:13]  raw as in "non-http" right, not "non-tcp"?
[11:14]  right

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


long number multiplication

2004-12-04 Thread I.V. Aprameya Rao
hi

i have been wondering, how does python store its very long integers and 
perform aritmetic on it.

i needed to implement this myself and was thinking of storing the digits 
of an integer in a list.

however this would be very slow for operations like division etc.

so if anyone can point me to some links or some method on how to do this i 
would appreciate it

aprameya rao

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


Re: pre-PEP generic objects

2004-12-04 Thread Ian Bicking
Steven Bethard wrote:
Ian Bicking wrote:
class bunch(object):
def __init__(self, **kw):
for name, value in kw.items():
# IMPORTANT!  This is subclass friendly: updating __dict__
# is not!
setattr(self, name, value)

Good point about being subclass friendly...  I wonder if there's an easy 
way of doing what update does though...  Update (and therefore __init__) 
allows you to pass in a Bunch, dict, (key, value) sequence or keyword 
arguments by taking advantage of dict's update method.  Is there a clean 
way of supporting all these variants using setattr?
class bunch(object):
def __init__(self, __seq=None, **kw):
if __seq is not None:
if hasattr(__seq, 'keys'):
for key in __seq:
setattr(self, key, __seq[key])
else:
for name, value in __seq:
setattr(self, name, value)
for name, value in kw.items():
setattr(self, name, value)
That should match dict.update, at least from the 2.4 help(dict.update). 
 I'm not sure that will work for updating from a bunch object; also, 
bunch objects could have a 'keys' attribute without being dictionaries. 
 Do you get attributes from non-iterables through their __dict__?  I 
don't care for that at all.  Are bunch objects iterable?

--
Ian Bicking  /  [EMAIL PROTECTED]  / http://blog.ianbicking.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: [Python-Help] (fwd)

2004-12-04 Thread Alfred Canoy
Hello,
I'm just new to programming and would like to ask for help..
Build a module that contains three functions that do the following:
 a.. Compute the average of a list of numbers
 b.. Finds the statistical median value of a list of numbers
 c.. Finds the mode of a list of numbers
Can you please give me clue how I should start solving the following problem
below? Here's the source code that I did so far:
# compute the average of a list of numbers:
# Keeps asking for numbers until 0 is entered
# Prints the average value
count = 0
sum = 0
number = 1
print 'Enter 0 to exit the loop'
while number != 0:
   number = input ('Enter a number: ')
   count = count + 1
   sum = sum + number
count = count -1
print ' The average is:', sum/count

Greatly appreciates it!
Al
_ _
_ _
Alfred Canoy
Agana, Guam
Pacific time
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


RE: [Python-Help] (fwd)

2004-12-04 Thread Robert Brewer
Alfred Canoy wrote:
>  I'm just new to programming and would like to ask for help..
> 
> Build a module that contains three functions that do the following:
> 
>   a.. Compute the average of a list of numbers
>   b.. Finds the statistical median value of a list of numbers
>   c.. Finds the mode of a list of numbers
> 
> Can you please give me clue how I should start solving the 
> following problem
> below? Here's the source code that I did so far:
> 
> # compute the average of a list of numbers:
> # Keeps asking for numbers until 0 is entered
> # Prints the average value
> 
> count = 0
> sum = 0
> number = 1
> 
> print 'Enter 0 to exit the loop'
> while number != 0:
> number = input ('Enter a number: ')
> count = count + 1
> sum = sum + number
> count = count -1
> print ' The average is:', sum/count

Looks good to me (well, I'd write the loop differently, but...). What is
happening that you dislike?

>>> count = sum = 0
>>> number = 1
>>> while number != 0:
... number = input('Enter a number: ')
... count += 1
... sum += number
... 
[Enters 3, 5, and 7]
>>> sum, count
(15, 4)
>>> count -= 1
>>> sum/count
5


Robert Brewer
MIS
Amor Ministries
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: [Python-Help] (fwd)

2004-12-04 Thread Paul Rubin
"Alfred Canoy" <[EMAIL PROTECTED]> writes:
>  I'm just new to programming and would like to ask for help..
> 
> Build a module that contains three functions that do the following:
> 
>   a.. Compute the average of a list of numbers
>   b.. Finds the statistical median value of a list of numbers
>   c.. Finds the mode of a list of numbers
> 
> 
> Can you please give me clue how I should start solving the following problem
> below? Here's the source code that I did so far:

Looks like your computation of the average (mean) is ok.

To find the median and mode, the simplest approach is to learn about
arrays (also called lists) in Python.  Python arrays support various
built-in operations, and you'll want to be sure to read about those,
since some of them may be able to save you some work.

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


Re: Delphi/Kylix and Python

2004-12-04 Thread Tim Roberts
"John Tiedeman" <[EMAIL PROTECTED]> wrote:
>
> Translating to Kylix might be quite easy. There have been articles 
>about writing code so that it will run on either by sensing whether Windows 
>or Linux and automatically using the appropriate directives.
> My problem with both Delphi and Kylix is in getting them to connect 
>with PostgreSQL and SQLite. Any suggestions? From what I have read, ODBC or 
>JDBC may do it, but I have experience with neither.

There are direct Delphi components for both databases.  Google is your
friend.
-- 
- Tim Roberts, [EMAIL PROTECTED]
  Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: long number multiplication

2004-12-04 Thread Terry Reedy

"I.V. Aprameya Rao" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> i have been wondering, how does python store its very long integers and
> perform aritmetic on it.

The only real documention for stuff like this, other than random posts on 
c.l.p., is the source code itself.  It is generally pretty readable.

TJR



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


Re: long number multiplication

2004-12-04 Thread Nick Coghlan
I.V. Aprameya Rao wrote:
hi
i have been wondering, how does python store its very long integers and 
perform aritmetic on it.

i needed to implement this myself and was thinking of storing the digits 
of an integer in a list.

however this would be very slow for operations like division etc.
so if anyone can point me to some links or some method on how to do this i 
would appreciate it

aprameya rao
I don't know of any design docs, but the source itself is easily available:
http://cvs.sourceforge.net/viewcvs.py/python/python/dist/src/Objects/longobject.c?rev=1.165&view=markup
Look at Python 2.4's decimal.py for something which is still pretty slow (heavy 
number crunching in Python code just ain't pretty), but alleviates that somewhat 
by using long objects to do the grunt work in most of the numerical operations.

(Random aside: actually having Decimal store long objects instead of a list of 
digits slows it down. The arithmetic is faster, but the exponentiation + 
division required for rounding is significantly slower than the list slicing 
that the current implementation is able to use).

Cheers,
Nick.
--
http://mail.python.org/mailman/listinfo/python-list


notification for cd insertion

2004-12-04 Thread Qiangning Hong
I want one of my function to execute when a cdrom is inserted.  How can 
I achieve that?

Further more, I want to do different things depend on the inserted disc 
type: if it is a normal cd-rom, read from it; if it is a recordable cd, 
write data on it.  So, how can I get the inserted disc type infomation 
in Python code?

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


Re: notification for cd insertion

2004-12-04 Thread Qiangning Hong
Qiangning Hong wrote:
I want one of my function to execute when a cdrom is inserted.  How can 
I achieve that?

Further more, I want to do different things depend on the inserted disc 
type: if it is a normal cd-rom, read from it; if it is a recordable cd, 
write data on it.  So, how can I get the inserted disc type infomation 
in Python code?

thanks in advance.
Sorry I forgot the important info:  my platform is a Windows 2000 box.
--
http://mail.python.org/mailman/listinfo/python-list


Re: [Python-Help] (fwd)

2004-12-04 Thread Joe Raul

"Alfred Canoy" <[EMAIL PROTECTED]> 
news:[EMAIL PROTECTED]
> Hello,
>
>  I'm just new to programming and would like to ask for help..
>
> Build a module that contains three functions that do the following:
>
>   a.. Compute the average of a list of numbers
>   b.. Finds the statistical median value of a list of numbers
>   c.. Finds the mode of a list of numbers
>
>
> Can you please give me clue how I should start solving the following
problem
> below? Here's the source code that I did so far:
>
> # compute the average of a list of numbers:
> # Keeps asking for numbers until 0 is entered
> # Prints the average value
>
> count = 0
> sum = 0
> number = 1
>
> print 'Enter 0 to exit the loop'
> while number != 0:
> number = input ('Enter a number: ')
> count = count + 1
> sum = sum + number
> count = count -1
> print ' The average is:', sum/count
>
>
>
> Greatly appreciates it!
> Al
>  _ _
> _ _
> Alfred Canoy
> Agana, Guam
> Pacific time
> [EMAIL PROTECTED]
>
it is a eligible and right program for python syntax, and what`s your
problem?


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


Re: notification for cd insertion

2004-12-04 Thread Joe Raul

"Qiangning Hong" <[EMAIL PROTECTED]> 
news:[EMAIL PROTECTED]
> Qiangning Hong wrote:
> > I want one of my function to execute when a cdrom is inserted.  How can
> > I achieve that?
> >
> > Further more, I want to do different things depend on the inserted disc
> > type: if it is a normal cd-rom, read from it; if it is a recordable cd,
> > write data on it.  So, how can I get the inserted disc type infomation
> > in Python code?
> >
> > thanks in advance.
> >
>
> Sorry I forgot the important info:  my platform is a Windows 2000 box.
>
~~~

what is it ?


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


Re: notification for cd insertion

2004-12-04 Thread Fredrik Lundh
Qiangning Hong <[EMAIL PROTECTED]> wrote:

>I want one of my function to execute when a cdrom is inserted.  How can I 
>achieve that?
>
> Further more, I want to do different things depend on the inserted disc type: 
> if it is a normal 
> cd-rom, read from it; if it is a recordable cd, write data on it.  So, how 
> can I get the inserted 
> disc type infomation in Python code?

1) figure out how notifications work.  typing your subject line into a google
   search box and clicking "I feel lucky" brings up this page:

http://support.microsoft.com/default.aspx?scid=kb;en-us;163503

2) figure out how to handle an WM_DEVICECHANGE event in the UI
   framework you're using; this is a framework issue, not a Python issue
   (Python doesn't process Windows events by itself).

3) check the "REFERENCES" section on the above page for more details.

hope this helps!

 



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