RE: Writting to file from file and printing using python

2006-07-28 Thread atanas Cosmas Nkelame
Hi,I have a task to write a program that will do the following.1. Run from the command line2. Get data from a text file (say data.txt) in the following format  111: peter edward  
[EMAIL PROTECTED] 112: John sykes[EMAIL PROTECTED] 113: edward  mutaga  
[EMAIL PROTECTED]3. Write that data in a prepared word document (which is essentially a letter)4. Print the letters for the listed people (111,112,113) on a printer.The program has to be called like this
c:/program/callprogram inputfile.txt  c:/program/data/outputfile.docSomeone has done this in VB.Net but I would like to do it in python.Can someone advice on the best way to start.atanas
atanas
-- 
http://mail.python.org/mailman/listinfo/python-list

War chest for writing web apps in Python?

2006-07-28 Thread Vincent Delporte
Hello

I'm thinking of using Python to build the prototype for a business web
appplication. The development and test machine is XP, while ultimate
deployment will be on a shared Unix web host.

What would you recommend I get, besides the Python engine itself? Good
IDE (Kodomo?) ? Some kind of GUI designer? Add-on's? Other tools?

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


Re: War chest for writing web apps in Python?

2006-07-28 Thread faulkner
cygwin
http://www.cygwin.com/
try a few IDEs out to see which fits you best. IDLE ships with python,
and isn't significantly objectively worse than any other python IDE,
afaik.
GUI designers aren't necessary because there's usually so little
boilerplate code in any python toolkit, but, again, whatever works best
for you.
[wait, will you be running a GUI on a webhost?]
if you haven't selected a web framework, may i steer you towards
cherrypy? it stays out of your way more than any other web framework
i've tried. and i'm using it now to build a databased web-app for my
college.
http://www.cherrypy.org/


Vincent Delporte wrote:
 Hello

 I'm thinking of using Python to build the prototype for a business web
 appplication. The development and test machine is XP, while ultimate
 deployment will be on a shared Unix web host.

 What would you recommend I get, besides the Python engine itself? Good
 IDE (Kodomo?) ? Some kind of GUI designer? Add-on's? Other tools?
 
 Thank you.

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


Re: a print bug?

2006-07-28 Thread Summercoolness
Steve Holden wrote:
 You obviously haven't yet passed your floating-point number proficiency
 test yet. Please restrict yourself to integers until you understand the
 difficulties that inaccuracies in floating-point can create ;-)

hm, actually, i understand the limitation of floating point.
but my real concern is, how come print favors one version over the
other...
the first version will favor the correct rounding, while the second
doesn't favor it.  to me, this is biased computing  i will feel
happier if the behavior is consistent.  (such as the first line
printing out as 1.23449) .  if most people favor the behavior
of line 1, that is, silently rounding off to about the 11th decimal
places, then why doesn't printing with formatting also use that same
behavior, which is rounding off to the 11th places first, and then
round off to whatever the user wants.

print 1.2345

 1.2345

print %10.3f % 1.2345

  1.234

but then again, i just realize even if i do a

 round(1.2344999, 6)

1.2344

so even if you round it off, it is still represented the same way
still, how print handles 1.2345 and treating it and printing it as
1.2345, i wonder why we don't make the print with formatting the same
behavior, treating it as 1.2345 first and round it off to 1.235

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


Re: Zipping Files to user defined Directory

2006-07-28 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED],
OriginalBrownster wrote:

 I'm very new to python, and I have been using the TurboGears Framework
 to use python to power my application.
 
 […]
 
 my problems is that when I want to download that file from the server I
 want to zip the files selected. but how does a user specify where they
 want to save that file?.

Usually the browser asks the user for a target directory.  So that's not
your business.

After the user selected the files you have to zip them on the server, for
instance in a temporary in the `/tmp/` directory and then deliver that
archive to the user.

Ciao,
Marc 'BlackJack' Rintsch


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

Re: Nested function scope problem

2006-07-28 Thread Bruno Desthuilliers
Gerhard Fiedler a écrit :
 On 2006-07-27 17:10:55, Bruno Desthuilliers wrote:
 
 
Isn't being on the LHS the only way to write to a non-mutable object? 

You *don't* write to a non-mutable object. You rebind the name to 
another object (mutable or not, that's not the problem).
 
 
 Ok, sloppy writing (sloppy thinking, or probably incomplete understanding
 :) on my part. Let me rephrase the three original questions:
 
 
Isn't being on the LHS the only way to write to a non-mutable object? Are
there situations where binding happens without writing to a variable? Are
there write accesses to non-mutable objects where the name is not on the
LHS?
 
 
 Rephrased as:
 
 Isn't being on the LHS (of an assignment) the only way to (re)bind a
 variable?

pedantic
s/variable/name/
/pedantic

 Are there situations where binding happens without an explicit
 assignment with the variable name being on the LHS?

Assignment aside, binding occurs:

1/ on evaluation of import, class and def statement
see Dennis answer for an example with import. Here are examples with def 
and class:

  a
Traceback (most recent call last):
   File stdin, line 1, in ?
NameError: name 'a' is not defined
  a = []
  a
[]
  id(a)
1078043820
  def a(): pass
...
  a
function a at 0x404162cc
  id(a)
1078026956
  class a: pass
...
  a
class __main__.a at 0x4040dadc
  id(a)
1077992156
 

2/ on function call for the function's arguments

This second case won't obviously *re*bind existing names in the 
function's namespace, nor in the caller namespace, so we don't care here.


3/ as a result of a list comp or for loop:

  a
Traceback (most recent call last):
   File stdin, line 1, in ?
NameError: name 'a' is not defined
  for a in range(3): pass
...
  a
2
  b
Traceback (most recent call last):
   File stdin, line 1, in ?
NameError: name 'b' is not defined
  [b for b in range(3)]
[0, 1, 2]
  b
2
 

AFAICT and IIRC, this should cover most cases - please someone correct 
me if I forgot something here...


  Can the object
  referenced by a variable name get changed without the variable name
  appearing on the LHS?

  a = []
  id(a)
1078043820
  def change(l):
... l.append(42)
...
  change(a)
  a
[42]
  id(a)
1078043820
 

First assignment aside, the *name* 'a' is never on the LHS of an 
assignment, yet the object referenced by name 'a' got 'changed' : it was 
initially empty, after call to change() it contains an int.

Yes, I know, this is not what you meant (and no, name 'a' has not been 
rebound) - but that's really what you asked :  the object referenced by 
name 'a' got changed without name 'a' being on the LHS !-) Hence the 
emphasis on the difference between mutating (modifying/changing/...) an 
object and rebinding a name...

I think your intented question was more like : can a name be rebound 
without that name being on the LHS of an assignment, and it's addressed 
above

 (I hope I got this right now... 

Almost !-)

 asking the correct questions is not so easy
 sometimes :)

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


Re: Newbie Q: Class Privacy (or lack of)

2006-07-28 Thread Steve Jobless
Bruno Desthuilliers wrote:
 
 Steve Jobless wrote:
  Sybren Stuvel wrote:
 
 Steve Jobless enlightened us with:
 
 The first case can be just a typo, like:
 
   x.valeu = 5
 
 I make typos all the time. Without a spell checker, this message
 would be unreadable :).
 
 Then learn to read what you type, as you type it. Typing without
 errors can be trained.
 
 
  I'd rather let a machine to do that. Wasn't computer created for tasks
  like this? (No, not really. But...)
 
 There's obviously a trade-off between 'security' and flexibility. As I
 said, I do make lots of typo too, but OTOH the edit/test cycle in Python
 is usually so short that such errors are not a problem for me - they're
 caught almost immediatly.

I hope you are right. But I have yet to see the proof. Just empirical arguments.

 
 
 The second case can be like:
 
   x.next = y
   y.next = None
 
 to create a linked list by piggybacking next to the class. It will
 overwrite the iterater for the class if defined.
 
 You shouldn't simply pick a name and assign something to it without
 checking the current use of that name. It's pretty much true for
 everything in life.
 
 
  Well, the choice of next was not a good example. Sure, no one with
  decent Python knowledge would do that.
  But what about adding a method to the class? Am I supposed to ask Is
  anyone using name xxx?
 
 assert 'xxx' not in dir(SomeClassOrObject)
 
  The class may be used by  developers I don't
  even know and some of them may be on the other side of the planet...
 
 How could this be a problem ? What's added/changed at runtime in a given
 app doesn't impact the source code.

Say you are a 3rd party library developer. You can tell your customers
to check dir(MyClass), but you can't enforce it. Even if they do, just
updating your library could break THEIR code. It's not your fault, but
you have to patiently diagnose their problem and nicely tell them it's
their fault. It's not a good idea to call them idiots. This may be an
extreme case, but it could happen within a single organization. You may
be in the framework group supporting several application groups.

 
 
 If I was working on a large project with many engineers, I'd assume
 someone will do things like this sooner or later. I've seen many
 horrendous code in my life and I have no control over who I work
 with.
 
 Long live a versioning system. With that, you can find the person
 writing the horrible code, and slap them on the back of the head.
 People, like all animals, can be trained into doing the right thing.
 
 
  I'd like to. But often those people are long gone for one reason or
  another. Sometimes, it happens to be my boss...
 
 If your boss is a bad programmer and doesn't know it, then you're in for
 trouble whatever the language.
 
 
  Maybe I should ask the question in a different way:
 
  What are the benefits from this? There must be something really good
  (and hopefully safe) you can do with it only from the outside. I don't
  have much problem over-riding functions from the inside of the class.
  But from the outside, I fail to see why anyone needs to add attributes
  or over-ride functions.
 
 Just one example : suppose you're working with a framework. Suppose
 you'd need to customize some objects (including classes - Python classes
 are objects too) of the framework, but the framework has no hook for
 this and you definitively don't wan't to bother patching the code and
 maintaining your own branch.
 

IMHO

Maybe it's cultural. But one aspect of OO is that you only need to know
what the object does (interface), but you don't have to (and better not)
know how it does (implementation). This is important because the class
implementor can enhance and/or optimize the class without breaking
users' code as long as the interface is compatible. (This is why most,
if not all, instance variables should be private. You can use
__getattr__/__setattr__, but they don't always work.) If you need to
customize a class, you should sub-class it using the public interface of
the base class. You better not mess with it from the outside because
updating the class can break your code. Unfortunately, I don't see a way
to separate interface from implementation in Python. So, it may not make
much difference whether you subclass it or hack it from the outside.

Python has some good features. The memory management using reference
counting with garbage collection is very attractive. It can even do
delegation! Unfortunately, it seems to be taking unnecessary risk. I was
hoping someone shows me a compelling reason to sacrifice the safety, but
I don't hear much. It looks pretty good as long as it is used by a small
group, especially for a small project. (Or Python is meant just for such
projects?) But I don't feel comfortable enough for a large project that
involves multiple groups including 3rd parties in a long duration. I
just wish those features would be removed or at least made optional.

/IMHO

Have a good weekend, 

Re: Fastest Way To Loop Through Every Pixel

2006-07-28 Thread Simon Forman
Chaos wrote:
 Simon Forman wrote:
  Chaos wrote:
   As my first attempt to loop through every pixel of an image, I used
  
   for thisY in range(0, thisHeight):
   for thisX in range(0, thisWidth):
 #Actions here for Pixel thisX, thisY
  
   But it takes 450-1000 milliseconds
  
   I want speeds less than 10 milliseconds
  
   I have tried using SWIG, and pypy but they all are unsuccessfull in
   compiling my files.
 
  You could try the PIL package.
 
  From the docs at
  http://www.pythonware.com/library/pil/handbook/image.htm
 
  Image.eval(function, image) = image
 
  Applies the function (which should take one argument) to each pixel in
  the given image. If the image has more than one band, the same function
  is applied to each band. Note that the function is evaluated once for
  each possible pixel value, so you cannot use random components or other
  generators.
 
  HTH,
  ~Simon

 I have tried PIL. Not only that, but the Image.eval function had no
 success either. I did some tests and I found out that Image.eval only
 called the function a certain number of times either 250, or 255.

It says the function is evaluated once for each possible pixel value,
so if it's only calling the function 250 or 255 times it's because your
image only has 250 or 255 colors.

Obviously Image.eval() caches the results of your function for each
color/pixel-value and reuses them rather than recomputing them.

I take it that whatever you're doing to those pixels involves more
information than just the pixel values?  What are you doing to the
pixels? That's probably wher you should look to improve the speed of
the loop.

Peace,
~Simon

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


Re: How to force a thread to stop

2006-07-28 Thread H J van Rooyen

Dennis Lee Bieber [EMAIL PROTECTED] Wrote:

| On Thu, 27 Jul 2006 08:48:37 -0400, Jean-Paul Calderone
| [EMAIL PROTECTED] declaimed the following in comp.lang.python:
|
| 
|  If a thread never performs any I/O operations, signal handlers will still
|  get invokes on the arrival of a signal.
| 
| I thought I'd qualified that scenario -- from the point of view of
| one OS I've programmed, where signals were only handled as part of the
| I/O system (or, in more general, as part of any /blocking/ system call
| from an application -- not even a ctrl-c would have an effect unless
| the application invoked a blocking call, or explicitly polled the signal
| bits of its task header)
| --

I have to support this - a processor is only doing one instruction at a time, if
its not a multi core device - and the only ways that the operating system part
of the system can get control back from the *user program part* of the system
are:

a) when the User makes an OS call (like blocking I/O, or any OS request)
b) when the user code is interrupted by some hardware thingy and the OS part
handles the interrupt.

So on a processor that does not have protected instructions - if an idiot writes
something to the following effect :

*instructions to disable interrupts*

followed by :

*instructions that go into an infinite loop AND that make no OS calls*

the whole bang shoot stops dead - Reset your machine...

Dennis - did your OS not have a ticker running?

- Hendrik


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


Re: Threads vs Processes

2006-07-28 Thread H J van Rooyen
Dennis Lee Bieber [EMAIL PROTECTED] Wrote:

| On Thu, 27 Jul 2006 09:17:56 -0700, Carl J. Van Arsdall
| [EMAIL PROTECTED] declaimed the following in comp.lang.python:
|
|  Ah, alright, I think I understand, so threading works well for sharing
|  python objects.  Would a scenario for this be something like a a job
|  queue (say Queue.Queue) for example.  This is a situation in which each
|  process/thread needs access to the Queue to get the next task it must
|  work on.  Does that sound right?  Would the same apply to multiple
|  threads needed access to a dictionary? list?
| 
| Python's Queue module is only (to my knowledge) an internal
| (thread-shared) communication channel; you'd need something else to work
| IPC -- VMS mailboxes, for example (more general than UNIX pipes with
| their single reader/writer concept)
|
|  shared memory mean something more low-level like some bits that don't
|  necessarily mean anything to python but might mean something to your
|  application?
| 
| Most OSs support creation and allocation of memory blocks with an
| attached name; this allows multiple processes to map that block of
| memory into their address space. The contents of said memory block is
| totally up to application agreements (won't work well with Python native
| objects).
|
| mmap()
|
| is one such system. By rough description, it maps a disk file into a
| block of memory, so the OS handles loading the data (instead of, say,
| file.seek(somewhere_long) followed by file.read(some_data_type) you
| treat the mapped memory as an array and use x = mapped[somewhere_long];
| if somewhere_long is not yet in memory, the OS will page swap that part
| of the file into place). The file can be shared, so different
| processes can map the same file, and thereby, the same memory contents.
|
| This can be useful, for example, with multiple identical processes
| feeding status telemetry. Each process is started with some ID, and the
| ID determines which section of mapped memory it is to store its status
| into. The controller program can just do a loop over all the mapped
| memory, updating a display with whatever is current -- doesn't matter if
| process_N manages to update a field twice while the monitor is
| scanning... The display always shows the data that was current at the
| time of the scan.
|
| Carried further -- special memory cards can (at least they were
| where I work) be obtained. These cards have fiber-optic connections. In
| a closely distributed system, each computer has one of these cards, and
| the fiber-optics link them in a cycle. Each process (on each computer)
| maps the memory of the card -- the cards then have logic to relay all
| memory changes, via fiber, to the next card in the link... Thus, all the
| closely linked computers share this block of memory.

This is nice to share inputs from the real world - but there are some hairy
issues if it is to be used for general purpose consumption - unless there are
hardware restrictions to stop machines stomping on each other's memories - i.e.
the machines have to be *polite* and *well behaved* - or you can easily have a
major smash...
A structure has to agreed on, and respected...

 - Hendrik


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


Re: Newbie Q: Class Privacy (or lack of)

2006-07-28 Thread Ray

Bruno Desthuilliers wrote:
  I'd rather let a machine to do that. Wasn't computer created for tasks
  like this? (No, not really. But...)

 There's obviously a trade-off between 'security' and flexibility. As I
 said, I do make lots of typo too, but OTOH the edit/test cycle in Python
 is usually so short that such errors are not a problem for me - they're
 caught almost immediatly.

Actually Bruno,  don't you think that the notion of flexibility in
Python comes at the expense of security is simply due to the fact
that the syntax of screw up is exactly the same as the syntax of I
mean it this way and I do want it?

Perhaps if we use a different syntax when we want to say I really want
this, it'll be better (so Python can differentiate between a typo and
a conscious decision). So going back to the original example, you won't
be able to say:

x.func = 789 and destroy the function func--Python will raise an error.
Instead you have to type a different syntax to tell Python that yes, I
do want to overwrite a function with 789.

Dunno, just throwing out ideas here :)

Cheers
Ray

snip
 --
 bruno desthuilliers
 python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
 p in '[EMAIL PROTECTED]'.split('@')])

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


Re: non-blocking PIPE read on Windows

2006-07-28 Thread Simon Forman
placid wrote:
 Hi all,

 I have been looking into non-blocking read (readline) operations on
 PIPES on windows XP and there seems to be no way of doing this. Ive
 read that you could use a Thread to read from the pipe, but if you
 still use readline() wouldnt the Thread block too?

Yes it will, but that's ok.  In this case that's what it's for.  While
the thread waits for the readline(), the rest of your program continues
to carry on.


 What i need to do is, create a process using subprocess.Popen, where
 the subprocess outputs information on one line (but the info
 continuesly changes and its always on the same line) and read this
 information without blocking, so i can retrieve other data from the
 line i read in then put this in a GUI interface.


 readline() blocks until the newline character is read, but when i use
 read(X) where X is a number of bytes then it doesnt block(expected
 functionality) but i dont know how many bytes the line will be and its
 not constant so i cant use this too.
 
 Any ideas of solving this problem?
 
 
 Cheers

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


Re: Fastest Way To Loop Through Every Pixel

2006-07-28 Thread H J van Rooyen
Paul McGuire [EMAIL PROTECTED] wrote:

| Even downer-and-dirtier, you could approximate 30 with 32, 59 with 64, and
| 11 with 8, and do bit-shifting instead of multiplying:
|
| def darkness(img,x,y):
| return  (RedVal(img,x,y)  5) + (GreenVal(img,x,y)  6) +
| (BlueVal(img,x,y)  3)
|
|
| -- Paul

*grin* - a man after my own heart! - how do you multiply by ten? - shift, save a
copy, shift twice more and add the copy...

- Hendrik

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


Re: using names before they're defined

2006-07-28 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit :
Hiya, you might be interested in this alternative config parsing
program:
http://www.voidspace.org.uk/python/configobj.html

Yes, I know it. But I don't like it. Either a simple ini file do the
trick, or I need a full blown app-specific DSL - which can be as simple
as a Python file with dicts, lists, etc !-)


 
 
 What do you mean? I don't really understand. 

It's not a criticism of configobj - which is a quite nice package -, 
it's just a matter of personal tastes (I don't like configobj's 
[[[some-nested-sub-sub-section]]] syntax) and specific needs.

Most of the time, I don't need nothing more than a plain ini file - and 
in this case, I prefer to use configparser because it's in the standard 
lib (so I avoid a dependency on a 3rd part package).

When an ini file won't do, it's usually because what the app need is 
really complex and specific enough to justify a domain specific language.

And sometimes, this DSL can be expressed with Python's syntax, like for 
example:

schema = {'turbine1': {'class': 'Turbine',
'upstream' : ('frobnicator2',),
'downstream' : () # nothing,
},
   'frobnicator2' : {'class' : 'Frobnicator',
 'upstream' : (),
 'downstream' : ('frobnicator2',),
},
  }

FWIW, the package's end user is not even supposed to know this is in 
fact Python code !-)

FWIW, JSON can be a good candidate for this kind of stuff too.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SocketServer and timers

2006-07-28 Thread Simon Forman
alf wrote:
 Hi,

 I have one thread app using SocketServer and use server_forever() as a
 main loop. All works fine, but now I need certain timer checking let's
 say every 1 second something and stopping the main loop. So questions are:
   -how to stop serve_forever
   -how to implement timers

 thx, alf

Do you really need a timer, or do you just want to check something
every second or so?

If the latter, then something like this would do it:

from time import time

INTERVAL = 1.0

RUN = True

while RUN:

# Get a time in the future.
T = time() + INTERVAL

# Serve requests until then.
while time()  T:
server.handle_request()

# Check whatever.
if check():
# Do something, for example, stop running.
RUN = False

HTH,
~Simon

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


Re: locked file

2006-07-28 Thread Simon Forman

Kirt wrote:
 By locked files i mean Outlook PST file while Outlook has it open

 Simon Forman wrote:
  Kirt wrote:
   i have a code that backsup file from src to dest.
Now if some of the files are locked , i need to skip those files..
   I was trying to use fctl module but it can be used only in unix i
   suppose.
  
   is there anyother way? i am using windows os.
 
  What does locked mean in this case?  No read permissions? In use by
  another program?
 
  I haven't used windows in a long time, and I wasn't aware that one
  could lock files in it.
 
  Peace,
  ~Simon

So what happens when you try to back that up while outlook is messing
with it?  What are you doing to back it up? Copying?

If all you want to do is skip it...  can't you try to copy it and then
when that doesn't work just skip it?

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


Re: How to force a thread to stop

2006-07-28 Thread Paul Rubin
H J van Rooyen [EMAIL PROTECTED] writes:
 So on a processor that does not have protected instructions - if an
 idiot writes something to the following effect :
 
 *instructions to disable interrupts*
 
 followed by :
 
 *instructions that go into an infinite loop AND that make no OS calls*
 
 the whole bang shoot stops dead - Reset your machine...

A common recovery mechanism in embedded systems is a watchdog timer,
which is a hardware device that must be poked by the software every
so often (e.g. by writing to some register).  If too long an interval
goes by without a poke, the WDT hard-resets the cpu.  Normally the
software would poke the WDT from its normal periodic timing routine.
A loop like you describe would stop the timing routine from running,
eventually resulting in a reset.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fastest Way To Loop Through Every Pixel

2006-07-28 Thread Simon Forman
Simon Forman wrote:
 Chaos wrote:
  Simon Forman wrote:
   Chaos wrote:
As my first attempt to loop through every pixel of an image, I used
   
for thisY in range(0, thisHeight):
for thisX in range(0, thisWidth):
  #Actions here for Pixel thisX, thisY
   
But it takes 450-1000 milliseconds
   
I want speeds less than 10 milliseconds
   
I have tried using SWIG, and pypy but they all are unsuccessfull in
compiling my files.
  
   You could try the PIL package.
  
   From the docs at
   http://www.pythonware.com/library/pil/handbook/image.htm
  
   Image.eval(function, image) = image
  
   Applies the function (which should take one argument) to each pixel in
   the given image. If the image has more than one band, the same function
   is applied to each band. Note that the function is evaluated once for
   each possible pixel value, so you cannot use random components or other
   generators.
  
   HTH,
   ~Simon
 
  I have tried PIL. Not only that, but the Image.eval function had no
  success either. I did some tests and I found out that Image.eval only
  called the function a certain number of times either 250, or 255.

 It says the function is evaluated once for each possible pixel value,
 so if it's only calling the function 250 or 255 times it's because your
 image only has 250 or 255 colors.

 Obviously Image.eval() caches the results of your function for each
 color/pixel-value and reuses them rather than recomputing them.

 I take it that whatever you're doing to those pixels involves more
 information than just the pixel values?  What are you doing to the
 pixels? That's probably wher you should look to improve the speed of
 the loop.

 Peace,
 ~Simon

Oops, sorry.  I didn't see where you had already posted the actions
you're taking on the pixels..

He is the code #Actions here

myCol = (0.3 * image.GetRed(thisX, thisY)) + (0.59 *
image.GetGreen(thisX, thisY)) + (0.11 * image.GetBlue(thisX, thisY))
if myCol  darkestCol:
   darkestCol = myCol
   possX = thisX
   possY = thisY

Hmm,  if you're just trying to find the darkest color and one of it's
pixel coordinates after applying your weighting calculation, and you
don't mind if the coordinates are of the first encountered pixel of
that color, then I think you might be able to use Image.eval() after
all.

What format are the images in?


Peace,
~Simon

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


Re: Newbie Q: Class Privacy (or lack of)

2006-07-28 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], Steve Jobless wrote:

 Bruno Desthuilliers wrote:
 
 Steve Jobless wrote:
  But what about adding a method to the class? Am I supposed to ask Is
  anyone using name xxx?
 
 assert 'xxx' not in dir(SomeClassOrObject)
 
  The class may be used by  developers I don't
  even know and some of them may be on the other side of the planet...
 
 How could this be a problem ? What's added/changed at runtime in a given
 app doesn't impact the source code.
 
 Say you are a 3rd party library developer. You can tell your customers
 to check dir(MyClass), but you can't enforce it. Even if they do, just
 updating your library could break THEIR code. It's not your fault, but
 you have to patiently diagnose their problem and nicely tell them it's
 their fault.

But if they mess with the objects of your library I expect them to check
first if this is the cause of the failures.  They hopefully *know* where
they crossed the line into my implementation.  Because adding a method to
a foreign class is semantically the same as writing it directly into the
source code of that library.

This should be done only when it's really needed and it should be
documented.  Just because it's possible doesn't mean it's the way to solve
most problems that may be better solved by inheritance.

 Just one example : suppose you're working with a framework. Suppose
 you'd need to customize some objects (including classes - Python classes
 are objects too) of the framework, but the framework has no hook for
 this and you definitively don't wan't to bother patching the code and
 maintaining your own branch.
 
 
 IMHO
 
 Maybe it's cultural. But one aspect of OO is that you only need to know
 what the object does (interface), but you don't have to (and better not)
 know how it does (implementation). This is important because the class
 implementor can enhance and/or optimize the class without breaking
 users' code as long as the interface is compatible. (This is why most,
 if not all, instance variables should be private. You can use
 __getattr__/__setattr__, but they don't always work.) If you need to
 customize a class, you should sub-class it using the public interface of
 the base class. You better not mess with it from the outside because
 updating the class can break your code. Unfortunately, I don't see a way
 to separate interface from implementation in Python. So, it may not make
 much difference whether you subclass it or hack it from the outside.

It makes a difference.  If you subclass the chances that your modification
breaks if the implementation of the library class changes is much lower. 
Pythonistas expect a programmer to know this and act accordingly.

Separating interface and implementation is done by naming conventions in
Python.  If a name starts with an underscore it's not part of the API.

 I was hoping someone shows me a compelling reason to sacrifice the
 safety, but I don't hear much.

 It looks pretty good as long as it is used by a small
 group, especially for a small project. (Or Python is meant just for such
 projects?)

Please prove that the safety is sacrificed to the extent that you fear. 
This if you don't have `private`, everything starts to fall apart and
explodes right in your face if the project starts to get bigger arguments
aren't backed by empirical data either but often seems to be just learned
by heart in Java and C++ courses.

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


Py2exe for packaging installers?

2006-07-28 Thread K.S.Wong
Hi all,

I am trying to find out what tools (platform-independent if possible) that I 
can use to package a goup (few) of installers to become an exe application. 
I have heard of Py2exe but have not use it before.  Could it be used to wrap 
different installers (for example Python and Leo, python-based application) 
together? Does the installers have to be python-based to be able to use 
Py2exe? Are there any other alternatives?

Many thanks in advance for your advice

regards
Casey Wong 


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


Re: a print bug?

2006-07-28 Thread Roel Schroeven
[EMAIL PROTECTED] schreef:
 Steve Holden wrote:
 You obviously haven't yet passed your floating-point number proficiency
 test yet. Please restrict yourself to integers until you understand the
 difficulties that inaccuracies in floating-point can create ;-)
 
 hm, actually, i understand the limitation of floating point.
 but my real concern is, how come print favors one version over the
 other...
 the first version will favor the correct rounding, while the second
 doesn't favor it.  to me, this is biased computing  i will feel
 happier if the behavior is consistent.  (such as the first line
 printing out as 1.23449) .  if most people favor the behavior
 of line 1, that is, silently rounding off to about the 11th decimal
 places, then why doesn't printing with formatting also use that same
 behavior, which is rounding off to the 11th places first, and then
 round off to whatever the user wants.
 
 print 1.2345
 
 1.2345
 
 print %10.3f % 1.2345
 
  1.234
 
 but then again, i just realize even if i do a
 
 round(1.2344999, 6)
 
 1.2344
 
 so even if you round it off, it is still represented the same way
 still, how print handles 1.2345 and treating it and printing it as
 1.2345, i wonder why we don't make the print with formatting the same
 behavior, treating it as 1.2345 first and round it off to 1.235

You do realize that your formatting uses less decimal places than the 
print statement, do you?

  print 1.2345
1.2345
  print %0.3f % 1.2345
1.234
  print %0.4f % 1.2345
1.2345

If you use 4 decimals after the decimal sign, you get the same result as 
with a plain print statement (at least in this case). That means that 
print is not treating it as 1.2345 first and then rounding it off to 
1.235; it is just using the actual internal representation and rounding 
it off to 1.2345. Which IMO is the only sensible thing one can do.


-- 
If I have been able to see further, it was only because I stood
on the shoulders of giants.  -- Isaac Newton

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


WSAStartup failed: error code 10107

2006-07-28 Thread ralphdepping
Trying to get moinmoin wiki working on Windows 2000 using IIS and
python.  I get the following error when trying to view the start page
after insalling moinmoin and python - key error seems to be at the end
related to socket.py (ImportError: WSAStartup failed: error code
10107).  10107 is A system call that should never fail has
failed...which isn't very helpful.  Any ideas what the problem may be?

 Thanks,
Ralph

CGI Error
The specified CGI application misbehaved by not returning a complete
set of HTTP headers. The headers it did return are:


Traceback (most recent call last):
  File C:\Moin\wiki\moin.cgi, line 40, in ?
from MoinMoin.request import RequestCGI
  File C:\Moin\Lib\site-packages\MoinMoin\request.py, line 10, in ?
import os, re, time, sys, cgi, StringIO
  File C:\Python\lib\cgi.py, line 39, in ?
import urllib
  File C:\Python\lib\urllib.py, line 26, in ?
import socket
  File C:\Python\lib\socket.py, line 44, in ?
import _socket 
ImportError: WSAStartup failed: error code 10107

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


Re: Py2exe for packaging installers?

2006-07-28 Thread Tim N. van der Leeuw

K.S.Wong wrote:
 Hi all,

 I am trying to find out what tools (platform-independent if possible) that I
 can use to package a goup (few) of installers to become an exe application.
 I have heard of Py2exe but have not use it before.  Could it be used to wrap
 different installers (for example Python and Leo, python-based application)
 together? Does the installers have to be python-based to be able to use
 Py2exe? Are there any other alternatives?

 Many thanks in advance for your advice

 regards
 Casey Wong

Hi Casey Wong,

If you download py2exe, you'll find a number of examples of how to use
py2exe to create installers using InnoSetup.
On the wiki, you'll also find examples of how to do this -- even with
pygtk applications.

However, it's not platform independant -- it'll be for windows only.

Cheers,

--Tim

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


Re: Connecting to internet under proxy

2006-07-28 Thread Schronos
I don't know where is the problem, but I tried the same that you put
and it failed.

I tested it under cygwin, a cmd, linux with 2.2, 2.3 and 2.4 python
version. I think taht the problem is my corporate proxy. In this
sentences we use always a http proxy, but perhaps is not the suitable
kind of proxy. :-( I don't know, it is only an idea, 'cause in my other
programs I always use an http proxy and it work properly.

thank's for all.

 Chema.

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


Re: a print bug?

2006-07-28 Thread Duncan Booth
 wrote:

 
 Duncan Booth wrote:
 But you wouldn't complain about this would you?

  print %10.4f % 1.23445
 1.2345
  print %10.3f % 1.23445
  1.234

 A value which is slightly than 1.2345 prints to 4 decimal places as
 1.2345 and to 3 decimal places as 1.234.

 That's all that happens with your value as well: 1.2345 is not
 exactly representable as a floating point number, and the nearest
 representable number is less than 1.2345.
 
 This is the expected behavior though... even school when they first
 teach rounding off, they will tell you 1.23445 rounding off to 3
 decimal places is not 1.235 and i don't see anything weird about
 the two lines above.
 
At least where I went to school they taught that the correct rounding was 
to the even digit, so 1.2335 and 1.2345 would both round to 1.234. 

However, that is irrelevant. The number in question here is 
1.2344 and however you were taught to round numbers that ought 
to round to 1.234 for 3 decimals, and 1.2345 for 4.

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


Re: How to find difference in years between two dates?

2006-07-28 Thread Bruno Desthuilliers
thebjorn wrote:
 Bruno Desthuilliers wrote:
 Which conversion ? How do you get the data ? as a datetime object ? as a
 (y,m,d) tuple ? as a y-m-d string ? Else ?
 
 All input routines, whether they're from a web-form, database, command
 line, or anywhere else, only produce objects from the datetime module
 for calendar data.

Seems quite sensible.

 That way the program logic doesn't have to guess
 which format it's getting... I suppose I could do something like:
 
def age(born):
 mx_born = mx.DateTime.Date(born.year, born.month, born.day)
 ...

Yes, I was thinking of something like this.

 -- bjorn
 


-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need a compelling argument to use Django instead of Rails

2006-07-28 Thread Ben Sizer
Roman Susi wrote:
 Ben Sizer wrote:
  The problem is that Python is the 2nd best language for everything. ;)

 Is it a bad thing?

I don't know. I suppose that depends on how you define 'bad'! For me,
it is often inconvenient, because I'd prefer to use Python but
generally find that I have to choose something else if I want to do the
best possible for any particular project.

In my case, multimedia and game support is patchy, and web development
support is still oriented towards the Java/enterprise user - if CGI
doesn't suffice, that is. In the original poster's case, it's seemingly
because specific database support seems to be lacking. Improving the
libraries in these areas would hopefully increase the diversity of
Python's potential applications rather than diminish it.

-- 
Ben Sizer

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


Re: Fastest Way To Loop Through Every Pixel

2006-07-28 Thread Paul McGuire
H J van Rooyen [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Paul McGuire [EMAIL PROTECTED] wrote:

 | Even downer-and-dirtier, you could approximate 30 with 32, 59 with 64,
and
 | 11 with 8, and do bit-shifting instead of multiplying:
 |
 | def darkness(img,x,y):
 | return  (RedVal(img,x,y)  5) + (GreenVal(img,x,y)  6) +
 | (BlueVal(img,x,y)  3)
 |
 |
 | -- Paul

 *grin* - a man after my own heart! - how do you multiply by ten? - shift,
save a
 copy, shift twice more and add the copy...

 - Hendrik

Sadly, my timeit results show this saves only a little time, and
shift-copy-shiftsomemore-and-add is even slower then just doing the original
floating point multiply.  The biggest win is in prelookup of Image.GetXXX
functions.

-- Paul


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


Re: Py2exe for packaging installers?

2006-07-28 Thread Mr BigSmoke

 However, it's not platform independant -- it'll be for windows only.


Yeah, u'll have to use py2exe similars for mac (should be py2app, if i
remember right). py2exe is a Python distutils extension which
converts python scripts into executable windows programs

cheers

Fabio

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


Re: War chest for writing web apps in Python?

2006-07-28 Thread Mr BigSmoke
For IDEs i recommend Wing IDE (its really good but comercial.. :(  ),
pydev for eclipse and also SPE.

For GUI designer... it depends of wich kind of app u'll develop.

For web apps try cherrypy.. it's wonderfull and simple... U can also
try zope and plone (the they are less simple)

cheers

Fabio




Vincent Delporte wrote:
 Hello

 I'm thinking of using Python to build the prototype for a business web
 appplication. The development and test machine is XP, while ultimate
 deployment will be on a shared Unix web host.

 What would you recommend I get, besides the Python engine itself? Good
 IDE (Kodomo?) ? Some kind of GUI designer? Add-on's? Other tools?
 
 Thank you.

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


Re: Writting to file from file and printing using python

2006-07-28 Thread Simon Brunning
On 7/28/06, atanas Cosmas Nkelame [EMAIL PROTECTED] wrote:
 Hi,
 I have  a task to write a program that will do the following.

 1. Run from the command line

Check out the optparse module for this.

http://docs.python.org/lib/module-optparse.html

 2. Get data from a text file (say data.txt) in the following format

   111:  peter  edward  [EMAIL PROTECTED]
   112:  John  sykes[EMAIL PROTECTED]
   113: edwardmutaga [EMAIL PROTECTED]

Read the text file as normal, and use split to seperate the fields.

http://tinyurl.com/8w8vo

http://docs.python.org/lib/string-methods.html

 3. Write that data in a prepared word document (which is essentially a
 letter)

 4. Print the letters for the listed people (111,112,113) on a printer.

Word can be driven via COM, so this should be easy enough. See
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/279003 for a
simple example. To find out what you'll need to do, the simplest thing
might be to record a Word macro, and look at the VBA code that it
generates for you. You can convert this to Python and generalise the
bits you need to.

There, that's a starting point. Let us know what you come up with!
Give us a shout if you have any problems.

-- 
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: WSAStartup failed: error code 10107

2006-07-28 Thread Rob Wolfe

[EMAIL PROTECTED] wrote:
 Trying to get moinmoin wiki working on Windows 2000 using IIS and
 python.  I get the following error when trying to view the start page
 after insalling moinmoin and python - key error seems to be at the end
 related to socket.py (ImportError: WSAStartup failed: error code
 10107).  10107 is A system call that should never fail has
 failed...which isn't very helpful.  Any ideas what the problem may be?

  Thanks,
 Ralph

 CGI Error
 The specified CGI application misbehaved by not returning a complete
 set of HTTP headers. The headers it did return are:


 Traceback (most recent call last):
   File C:\Moin\wiki\moin.cgi, line 40, in ?
 from MoinMoin.request import RequestCGI
   File C:\Moin\Lib\site-packages\MoinMoin\request.py, line 10, in ?
 import os, re, time, sys, cgi, StringIO
   File C:\Python\lib\cgi.py, line 39, in ?
 import urllib
   File C:\Python\lib\urllib.py, line 26, in ?
 import socket
   File C:\Python\lib\socket.py, line 44, in ?
 import _socket
 ImportError: WSAStartup failed: error code 10107

I'm not sure if that helps but check if you have multiple
winsock.dll files on the machine.
Maybe in the system path you have some old winsock.dll.

regards,
Rob

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


Re: Newbie Q: Class Privacy (or lack of)

2006-07-28 Thread Ben Sizer
Ray wrote:
 Actually Bruno,  don't you think that the notion of flexibility in
 Python comes at the expense of security is simply due to the fact
 that the syntax of screw up is exactly the same as the syntax of I
 mean it this way and I do want it?

 Perhaps if we use a different syntax when we want to say I really want
 this, it'll be better (so Python can differentiate between a typo and
 a conscious decision).

Surely the very nature of a typo is that you don't know at the time of
typing that you've done the wrong thing. Therefore it's impossible to
signal to Python that you don't want what you've actually typed!

The only way statically-typed languages prevent these errors is
typically by prohibiting the operation entirely. Since Python doesn't
want to do that, you can't effectively prevent this type of error.
Luckily, I find that they don't actually arise in practice, and I've
spent orders of magnitude more time in C++ having to coerce objects
from one type to another to comply with the static typing than I
probably ever will spend debugging Python programs where a typo caused
an error of this type.

-- 
Ben Sizer

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


Re: Newbie Q: Class Privacy (or lack of)

2006-07-28 Thread Ray

Ben Sizer wrote:
 Ray wrote:
  Actually Bruno,  don't you think that the notion of flexibility in
  Python comes at the expense of security is simply due to the fact
  that the syntax of screw up is exactly the same as the syntax of I
  mean it this way and I do want it?
 
  Perhaps if we use a different syntax when we want to say I really want
  this, it'll be better (so Python can differentiate between a typo and
  a conscious decision).

 Surely the very nature of a typo is that you don't know at the time of
 typing that you've done the wrong thing. Therefore it's impossible to
 signal to Python that you don't want what you've actually typed!

Exactly! So what I'm saying is that if the syntax of rebinding a method
*has* to be different then assignment, maybe it'll catch typos more
often. (Of course if you STILL make a typo error while using a
different syntax...)

 The only way statically-typed languages prevent these errors is
 typically by prohibiting the operation entirely. Since Python doesn't
 want to do that, you can't effectively prevent this type of error.
 Luckily, I find that they don't actually arise in practice, and I've
 spent orders of magnitude more time in C++ having to coerce objects
 from one type to another to comply with the static typing than I
 probably ever will spend debugging Python programs where a typo caused
 an error of this type.

Yeah, I fully agree. Even Java is heaven compared to C++.

 
 -- 
 Ben Sizer

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


Re: How to force a thread to stop

2006-07-28 Thread Paul Boddie
Paul Rubin wrote:
 Paul Boddie [EMAIL PROTECTED] writes:
  Whether this solves the questioner's problems remains to be seen, but
  issues of handling SSH-based communications streams do seem to be
  addressed.

 Actually I don't understand the need for SSH.  This is traffic over a
 LAN, right?  Is all of the LAN traffic encrypted?  That's unusual; SSH
 is normally used to secure connections over the internet, but the
 local network is usually trusted.  Hopefully it's not wireless.

I don't run any wireless networks, but given the apparently poor state
of wireless network security (as far as the actual implemented
standards in commercially available products are concerned), I'd want
to be using as much encryption as possible if I did.

Anyway, the py.execnet thing is presumably designed to work over the
Internet and over local networks, with the benefit of SSH being that it
applies well to both domains. Whether it's a better solution for the
questioner's problem than established alternatives such as PVM (which
I've never had the need to look into, even though it seems
interesting), various distributed schedulers or anything else out
there, I can't really say.

Paul

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


Re: Need a compelling argument to use Django instead of Rails

2006-07-28 Thread Paul Boddie
Ben Sizer wrote:

 In my case, multimedia and game support is patchy,

There are lots of multimedia and game frameworks for Python. Which ones
have you tried and why are they insufficient?

 and web development support is still oriented towards the Java/enterprise 
 user - if CGI
 doesn't suffice, that is.

Certainly, some Web frameworks have some element of Java flavouring,
but there's also considerable diversity at least at certain levels.

 In the original poster's case, it's seemingly because specific database 
 support seems to
 be lacking. Improving the libraries in these areas would hopefully increase 
 the diversity
 of Python's potential applications rather than diminish it.

Last time I checked, which was admittedly a long time after I actually
needed the modules concerned, support for Oracle with Python was
actually pretty good. I suppose it's a case of the Django people
getting round to gluing the Oracle modules to their object-relational
mapper and making sure that it all still works, and perhaps some
motivated member of the Django community can step forward and do the
work to get it going. Otherwise, no amount of complaining will put the
two technologies together.

Paul

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


Re: Newbie Q: Class Privacy (or lack of)

2006-07-28 Thread Timo
Steve Jobless kirjoitti:

 Let's say the class is defined as:

   class MyClass:
 def __init__(self):
   pass
 def func(self):
   return 123

 But from the outside of the class my interpreter let me do:

   x = MyClass()
   x.instance_var_not_defined_in_the_class = 456

 or even:

   x.func = 789

 After x.func = 789, the function is totally shot.


You can avoid the problem by using the __slots__ definition and
new-style classes (inherit from object):

class MyClass(object):

__slots__ = ('bar',)

def func(self):
return 123

x = MyClass()
x.instance_var_not_defined_in_the_class = 456
==
AttributeError: 'MyClass' object has no attribute
'instance_var_not_defined_in_the_class'

x.func = 789
==
AttributeError: 'MyClass' object attribute 'func' is read-only

Only the bar-attribute can be set:

x.bar = 'foo'

-- timo

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


Re: Newbie Q: Class Privacy (or lack of)

2006-07-28 Thread Ben Sizer
Steve Jobless wrote:
 Unfortunately, I don't see a way
 to separate interface from implementation in Python. So, it may not make
 much difference whether you subclass it or hack it from the outside.

Documentation. (And name-mangling, underscore prepending, all the stuff
the others said.) Whenever I use a 3rd party library, I consult the
docs to see how it works and which functions do what. The interface is
what is published and the implementation is what you find if you dig
around in the module. Yes, there's little in the way of run-time
enforcement of this divide. But that's because Python gives you other
benefits that come from run-time assignment and re-assignment of
attributes. It's a common and powerful idiom that you find in several
languages, especially that are wholly or partially prototype-based,
such as Javascript.

 Unfortunately, it seems to be taking unnecessary risk. I was
 hoping someone shows me a compelling reason to sacrifice the safety, but
 I don't hear much.

I think the main issue is that tracking whether an attribute is public
or private and whether an accessing scope is allowed to access it would
impose a burden on the language developers, extra typing for users, and
a run-time performance penalty, in the pursuit of some degree of
'safety' that isn't universally agreed to be useful. With this in mind,
the name-mangling approach is a very reasonable middle ground. Every
language has a philosophy and Python's differs from that of (for
example) Java. It may not be suitable for large teams of mediocre
programmers who require the compiler to keep them in line, but might
produce better results than Java in other circumstances.

-- 
Ben Sizer

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


Re: Fastest Way To Loop Through Every Pixel

2006-07-28 Thread Ben Sizer
Chaos wrote:
 As my first attempt to loop through every pixel of an image, I used

 for thisY in range(0, thisHeight):
 for thisX in range(0, thisWidth):
   #Actions here for Pixel thisX, thisY

 But it takes 450-1000 milliseconds

 I want speeds less than 10 milliseconds

The main question is: why do you want to do this? I ask because with
performance requirements like that, you almost certainly need another
approach, one which I may be able to suggest.

-- 
Ben Sizer

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


Re: Newbie Q: Class Privacy (or lack of)

2006-07-28 Thread Bruno Desthuilliers
Steve Jobless wrote:
 Bruno Desthuilliers wrote:
 Steve Jobless wrote:
 Sybren Stuvel wrote:

 Steve Jobless enlightened us with:

 The first case can be just a typo, like:

  x.valeu = 5

 I make typos all the time. Without a spell checker, this message
 would be unreadable :).
 Then learn to read what you type, as you type it. Typing without
 errors can be trained.

 I'd rather let a machine to do that. Wasn't computer created for tasks
 like this? (No, not really. But...)
 There's obviously a trade-off between 'security' and flexibility. As I
 said, I do make lots of typo too, but OTOH the edit/test cycle in Python
 is usually so short that such errors are not a problem for me - they're
 caught almost immediatly.
 
 I hope you are right. But I have yet to see the proof. Just empirical 
 arguments.

Well, I'm only talking about my own experience here - I do not pretend
to prove anything.

 The second case can be like:

  x.next = y
  y.next = None

 to create a linked list by piggybacking next to the class. It will
 overwrite the iterater for the class if defined.
 You shouldn't simply pick a name and assign something to it without
 checking the current use of that name. It's pretty much true for
 everything in life.

 Well, the choice of next was not a good example. Sure, no one with
 decent Python knowledge would do that.
 But what about adding a method to the class? Am I supposed to ask Is
 anyone using name xxx?
 assert 'xxx' not in dir(SomeClassOrObject)

 The class may be used by  developers I don't
 even know and some of them may be on the other side of the planet...
 How could this be a problem ? What's added/changed at runtime in a given
 app doesn't impact the source code.
 
 Say you are a 3rd party library developer. You can tell your customers
 to check dir(MyClass), but you can't enforce it.

No, you can't.

 Even if they do, just
 updating your library could break THEIR code. It's not your fault, but
 you have to patiently diagnose their problem and nicely tell them it's
 their fault.

If they monkeypatch my code, they are of course responsible for what may
happen then. And FWIW, I don't have to diagnose their problem. Let's
put it the other way : I'm the one monkeypatching some 3rd part lib, and
following an update, it happens that my monkeypatch now breaks the lib.
I *know* I monkeypatched it, so my first take will be to inspect this
part.

 It's not a good idea to call them idiots. 

No 'idiocy' here, just willingness to assume one's own responsabilities.

 This may be an
 extreme case, but it could happen within a single organization. You may
 be in the framework group supporting several application groups.
 
 If I was working on a large project with many engineers, I'd assume
 someone will do things like this sooner or later. I've seen many
 horrendous code in my life and I have no control over who I work
 with.
 Long live a versioning system. With that, you can find the person
 writing the horrible code, and slap them on the back of the head.
 People, like all animals, can be trained into doing the right thing.

 I'd like to. But often those people are long gone for one reason or
 another. Sometimes, it happens to be my boss...
 If your boss is a bad programmer and doesn't know it, then you're in for
 trouble whatever the language.

 Maybe I should ask the question in a different way:

 What are the benefits from this? There must be something really good
 (and hopefully safe) you can do with it only from the outside. I don't
 have much problem over-riding functions from the inside of the class.
 But from the outside, I fail to see why anyone needs to add attributes
 or over-ride functions.
 Just one example : suppose you're working with a framework. Suppose
 you'd need to customize some objects (including classes - Python classes
 are objects too) of the framework, but the framework has no hook for
 this and you definitively don't wan't to bother patching the code and
 maintaining your own branch.

 
 IMHO
 
 Maybe it's cultural. But one aspect of OO is that you only need to know
 what the object does (interface), but you don't have to (and better not)
 know how it does (implementation).

Depends on what you're doing, but globally agreed.

 This is important because the class
 implementor can enhance and/or optimize the class without breaking
 users' code as long as the interface is compatible.

Yes.

 (This is why most,
 if not all, instance variables should be private.

No. Well, not exactly !-)

Attributes (instance or class, callable or not) that are implementation
should be marked as such, attributes (idem) that makes the API should be
marked as such. Any name starting with an underscore is implementation,
any name starting with a letter is API.

 You can use
 __getattr__/__setattr__, but they don't always work.) If you need to
 customize a class, you should sub-class it using the public interface of
 the base class.

Yes, of course. When it's possible. Sometimes it's not.

 You 

Re: Fastest Way To Loop Through Every Pixel

2006-07-28 Thread c d saunter
Chaos ([EMAIL PROTECTED]) wrote:

: He is the code #Actions here

: myCol = (0.3 * image.GetRed(thisX, thisY)) + (0.59 *
: image.GetGreen(thisX, thisY)) + (0.11 * image.GetBlue(thisX, thisY))
: if myCol  darkestCol:
:darkestCol = myCol
:possX = thisX
:possY = thisY

You really don't want to do this in interpreted Python code.  Way to slow.
I don't know PIL but probably you can do it their.

Another aproach is to use one of the array/maths libraries e.g. Numeric or 
NumPy.

You'll need to move the image data between PIL and the array package with 
the data being a (y,x,3) array for input array and (y,x) for the output 
array.  .tostirng() methods and fromstring() can be usefull here.

Then...

1.  Colour map it
newImage = 0.3 * image[:,:,0] + 0.59 * image[:,:,1] + 0.11 * image[:,:,2]

2. Mask of pixels less than your threshold

newImage = clip(newImage, myCol, MAX_COLOUR)

3. Find the coordinates of the last minimum colour - possX, possY (do you 
really need/mean to do this?) 

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


Re: How to find difference in years between two dates?

2006-07-28 Thread thebjorn
John Machin wrote:
 Jan 31 to Feb 27: 27d (ex) 28d (in)
 Jan 31 to Feb 28: 28d (ex) 1m 1d (in)
 Jan 31 to Mar 01: 1m 1d (ex) 1m 2d (in)
 So 1 day short of 1m 1d is not 1m 0 d???

Exactly. Just as a person born on 1999-3-1 isn't a year old on
2000-2-29. Perfectly regular, consistent and reasonable.

 I'd call this unreasonable, inconsistent, anomalous -- especially
 when on the same website you do 1993-01-31 plus 1 month, it
 gives you 1993-02-28 (as I'd expect).

You're entitled to your opinion.

-- bjorn

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


Re: Newbie Q: Class Privacy (or lack of)

2006-07-28 Thread Bruno Desthuilliers
Ray wrote:
 Bruno Desthuilliers wrote:
 I'd rather let a machine to do that. Wasn't computer created for tasks
 like this? (No, not really. But...)
 There's obviously a trade-off between 'security' and flexibility. As I
 said, I do make lots of typo too, but OTOH the edit/test cycle in Python
 is usually so short that such errors are not a problem for me - they're
 caught almost immediatly.
 
 Actually Bruno,  don't you think that the notion of flexibility in
 Python comes at the expense of security is simply due to the fact
 that the syntax of screw up is exactly the same as the syntax of I
 mean it this way and I do want it?

(patient) Doctor, it hurts when I do this...
(doctor) Then don't do it.

!-)

-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: micro authoritative dns server

2006-07-28 Thread xan2

Jack wrote:
 No, it's very low level :)
 Please post back if you find a good solution (or have built something that
 you want to
 open source :)


The same if you find or create it

Xan.

  Well, thanks, but I think it's so few for beginning. ,-(
  Is it not any high-level DNS class? E!!!
 
  Regards,
  Xan.
 
  Jack wrote:
  I was looking for something like that. I came across this:
  http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/491264
  It's not ready to use but you can modify it.

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


Re: War chest for writing web apps in Python?

2006-07-28 Thread Dan Sommers
On Fri, 28 Jul 2006 10:22:55 +0200,
Sybren Stuvel [EMAIL PROTECTED] wrote:

 Vincent Delporte enlightened us with:

 The development and test machine is XP, while ultimate deployment
 will be on a shared Unix web host.

 That's just begging for huge problems. No insult intended, but it's
 downright stupid to develop and test on one platform, and then deploy
 on another. Every system nowadays is a Unix, except Windows. I suggest
 you pick another system for development and testing.

We just did that at work (developed on the corporate-issued non-Unix
computers and then deployed on a Linux box), and had no problems at all.
In a former life, I was a long-time embedded system developer, where we
*always* developed on one platform and deployed on another.  My
experience with developing on your deployment platform is that it's too
easy for platform dependencies to sneak in without being caught.

Regards,
Dan

-- 
Dan Sommers
http://www.tombstonezero.net/dan/
I wish people would die in alphabetical order. -- My wife, the genealogist
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie Q: Class Privacy (or lack of)

2006-07-28 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], Timo wrote:

 Steve Jobless kirjoitti:
 
 Let's say the class is defined as:

   class MyClass:
 def __init__(self):
   pass
 def func(self):
   return 123

 But from the outside of the class my interpreter let me do:

   x = MyClass()
   x.instance_var_not_defined_in_the_class = 456

 or even:

   x.func = 789

 After x.func = 789, the function is totally shot.

 
 You can avoid the problem by using the __slots__ definition and
 new-style classes (inherit from object):
 
 class MyClass(object):
 
 __slots__ = ('bar',)
 
 def func(self):
 return 123
 
 x = MyClass()
 x.instance_var_not_defined_in_the_class = 456
 ==
 AttributeError: 'MyClass' object has no attribute
 'instance_var_not_defined_in_the_class'
 
 x.func = 789
 ==
 AttributeError: 'MyClass' object attribute 'func' is read-only
 
 Only the bar-attribute can be set:
 
 x.bar = 'foo'

This avoids the problem but you get others in return.  And it's an abuse
of `__slots__` which is meant as a way to save memory if you need really
many objects of that type and not as protection.

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


Comma is not always OK in the argument list?!

2006-07-28 Thread Roman Susi
Hi!

it is interesting that I found this syntax error:

 a = {}
 str('sdfd', **a,)
  File stdin, line 1
str('sdfd', **a,)
   ^
SyntaxError: invalid syntax


I just wonder is it intentional or by-product (bug or feature)?
(The behaviour makes sense, of course... I tend to leave commas when I
expect a list to be added to (i.e. almost always ;-)))


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


Re: War chest for writing web apps in Python?

2006-07-28 Thread Kjell Magne Fauske
Django(http://www.djangoproject.com/) is a nice Python based framework
for writing web applications. It comes bundled with a simple web server
that is usefull for local developing. A desciption on how to install
Django on windows can be found at
http://effbot.org/zone/django.htm#installing


- Kjell Magne


Vincent Delporte wrote:
 Hello

 I'm thinking of using Python to build the prototype for a business web
 appplication. The development and test machine is XP, while ultimate
 deployment will be on a shared Unix web host.

 What would you recommend I get, besides the Python engine itself? Good
 IDE (Kodomo?) ? Some kind of GUI designer? Add-on's? Other tools?
 
 Thank you.

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


Re: WSAStartup failed: error code 10107

2006-07-28 Thread ralphdepping
Thanks for the suggestion Rob.  All I can find are 2 copies of
winsock.dll:
c:/WINNT/system32/winsock.dll
c:/WINNT/system32/dllcache/winsock.dll
They're both the same version 3.10.0.13

I assume it's ok to have a copy in the dllcach directory and that's not
a source of the problem?

Does python require a specific version of winsock.dll?  The OS is
windows 2000 5.00.2195 Service Pack 4.

Cheers,
Ralph

Rob Wolfe wrote:
 [EMAIL PROTECTED] wrote:
  Trying to get moinmoin wiki working on Windows 2000 using IIS and
  python.  I get the following error when trying to view the start page
  after insalling moinmoin and python - key error seems to be at the end
  related to socket.py (ImportError: WSAStartup failed: error code
  10107).  10107 is A system call that should never fail has
  failed...which isn't very helpful.  Any ideas what the problem may be?
 
   Thanks,
  Ralph
 
  CGI Error
  The specified CGI application misbehaved by not returning a complete
  set of HTTP headers. The headers it did return are:
 
 
  Traceback (most recent call last):
File C:\Moin\wiki\moin.cgi, line 40, in ?
  from MoinMoin.request import RequestCGI
File C:\Moin\Lib\site-packages\MoinMoin\request.py, line 10, in ?
  import os, re, time, sys, cgi, StringIO
File C:\Python\lib\cgi.py, line 39, in ?
  import urllib
File C:\Python\lib\urllib.py, line 26, in ?
  import socket
File C:\Python\lib\socket.py, line 44, in ?
  import _socket
  ImportError: WSAStartup failed: error code 10107

 I'm not sure if that helps but check if you have multiple
 winsock.dll files on the machine.
 Maybe in the system path you have some old winsock.dll.
 
 regards,
 Rob

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


Re: War chest for writing web apps in Python?

2006-07-28 Thread Nick Vatamaniuc
Vincent,

If you plant to deploy on Unix/Linux, why develop on Windows? I would
suggest to make a partition on your Windows machine and install some
popular Linux distribution (I use Ubuntu but there are others too.)

The biggest benefit will come from the fact that you will have access
to a large pre-packaged set of IDEs, utilities, libraries, python
modules, all kinds of Apache modules and so on. Mind you, there are
probably more Python IDEs and tools that work better(natively) in Linux
than in Windows (ipython and Eric3 are the ones that come to mind).
This way you can quickly try various IDEs and tools for a couple of
days to find what you like, just do 'apt-get install my_new_ide' (for
Debian based distros like Debian and Ubuntu that is) and your new IDE
will appear in the Programming menu.

As far as a specific IDE, I already mentioned Eric3, I think it is the
most polished one.  I have tried Komodo, SPE, pydev and Emacs. I have
settled on Eric3 and sometimes I use Emacs (please don't start editor
wars over this, these are just my personal views!). I found Komodo to
be too slow on my machine, SPE was also slow, was crashing on me and
had strange gui issues, pydev works  with Eclipse so you have to
install that too, also found it to have quite a few rough edges. Emacs
is actaully pretty good if you got used to the keys, but lacks basic
refactoring and other small helper tools  that  IDEs have. Also  I
found ipython to be a very useful replacement for the standard Python
prompt.

Not sure what kind of a GUI designer you would want for a web based
application. Or is it for an administration module with a gui? In that
case you'll first have to choose the GUI toolkit. The default one that
comes with Python is Tk (Tkinter) and there are others like wxPython,
PyGTK, PyQT and so on. In general though, the time spent learning how
to design a gui with a designer could probably be used to just write
the code yourself in Python (now for Java or C++ it is a different
story... -- you can start a war over this ;-)

Hope this helps,
Nick Vatamaniuc








Vincent Delporte wrote:
 Hello

 I'm thinking of using Python to build the prototype for a business web
 appplication. The development and test machine is XP, while ultimate
 deployment will be on a shared Unix web host.

 What would you recommend I get, besides the Python engine itself? Good
 IDE (Kodomo?) ? Some kind of GUI designer? Add-on's? Other tools?
 
 Thank you.

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


Python Projects Continuous Integration

2006-07-28 Thread Dave Potts
Hi,

I'm just starting a development project in Python having spent time in
the Java world.  I was wondering what tool advice you could give me
about setting up a continuous integration environment for the python
code: get the latest source, run all the tests, package up, produce the
docs, tag the code repository.  I'm used to things like Maven and
CruiseControl in the Java world.

Cheers,

Dave.

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


Re: Comma is not always OK in the argument list?!

2006-07-28 Thread Nick Vatamaniuc
Roman,

According to the Python call syntax definition
(http://docs.python.org/ref/calls.html) commas should be allowed, so it
seems like a minor bug.  Here are the  lines in question:
-http://docs.python.org/ref/calls.html---
call ::= primary ( [argument_list [,]] )
argument_list::=positional_arguments [, keyword_arguments] [, *
expression] [, ** expression]
| keyword_arguments [, * expression] [, ** expression]
| * expression [, ** expression]
| ** expression
--
If you notice in the 'call' definition, no matter what the
'argument_list' is, it can be followed by an optional ',' right before
the closing ')'. Your code is a counterexample to this. Here is a more
exhaustive example:

 def f(a,b):
... pass
...
 f(1,2)
 f(1,2,)
 f(1,*[2])
 f(1,*[2],)
  File stdin, line 1
f(1,*[2],)
 ^
SyntaxError: invalid syntax
 f(1,**{'b':2})
 f(1,**{'b':2},)
  File stdin, line 1
f(1,**{'b':2},)
 ^
SyntaxError: invalid syntax
 f(*[1,2])
 f(*[1,2],)
  File stdin, line 1
f(*[1,2],)
 ^
SyntaxError: invalid syntax
 f(**{'a':1,'b':2})
 f(**{'a':1,'b':2},)
  File stdin, line 1
f(**{'a':1,'b':2},)
 ^
SyntaxError: invalid syntax

 f(1,b=2)
 f(1,b=2,)
 f(a=1,b=2,)

-

Anybody else knows more about this?
/invoking the spirit of GvR... ;-)

Nick Vatamaniuc






Roman Susi wrote:
 Hi!

 it is interesting that I found this syntax error:

  a = {}
  str('sdfd', **a,)
   File stdin, line 1
 str('sdfd', **a,)
^
 SyntaxError: invalid syntax


 I just wonder is it intentional or by-product (bug or feature)?
 (The behaviour makes sense, of course... I tend to leave commas when I
 expect a list to be added to (i.e. almost always ;-)))
 
 
 Regards,
 Roman

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


Re: WSAStartup failed: error code 10107

2006-07-28 Thread Rob Wolfe

[EMAIL PROTECTED] wrote:
 Thanks for the suggestion Rob.  All I can find are 2 copies of
 winsock.dll:
 c:/WINNT/system32/winsock.dll
 c:/WINNT/system32/dllcache/winsock.dll
 They're both the same version 3.10.0.13

 I assume it's ok to have a copy in the dllcach directory and that's not
 a source of the problem?

 Does python require a specific version of winsock.dll?  The OS is
 windows 2000 5.00.2195 Service Pack 4.

No, python doesn't require specific version of winsock.dll.

On my XP I have:

winsock.dll  - 3.10.0.103
ws2_32.dll   - 5.1.2600.2180
wsock32.dll - 5.1.2600.2180

and everything works fine.

No other idea, but I'm almost sure that problem
is on the OS side not on python side.

Regards,
Rob

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


Re: Threads vs Processes

2006-07-28 Thread Tobias Brox
[mark]
 http://twistedmatrix.com/projects/core/documentation/howto/async.html .

At my work, we started writing a web app using the twisted framework,
but it was somehow too twisted for the developers, so actually they
chose to do threading rather than using twisted's async methods.

-- 
Tobias Brox, 69°42'N, 18°57'E
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Zipping Files to user defined Directory

2006-07-28 Thread OriginalBrownster

Marc 'BlackJack' Rintsch wrote:
 In [EMAIL PROTECTED],
 OriginalBrownster wrote:

  I'm very new to python, and I have been using the TurboGears Framework
  to use python to power my application.
 
  [...]
 
  my problems is that when I want to download that file from the server I
  want to zip the files selected. but how does a user specify where they
  want to save that file?.

 Usually the browser asks the user for a target directory.  So that's not
 your business.

 After the user selected the files you have to zip them on the server, for
 instance in a temporary in the `/tmp/` directory and then deliver that
 archive to the user.

 Ciao,
   Marc 'BlackJack' Rintsch


THanks Marc,

That makes sense. I can zip the files to a temp directory. However,
How do I deliver the archive to them?...

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


Re: Zipping Files to user defined Directory

2006-07-28 Thread OriginalBrownster

Marc 'BlackJack' Rintsch wrote:
 In [EMAIL PROTECTED],
 OriginalBrownster wrote:

  I'm very new to python, and I have been using the TurboGears Framework
  to use python to power my application.
 
  [...]
 
  my problems is that when I want to download that file from the server I
  want to zip the files selected. but how does a user specify where they
  want to save that file?.

 Usually the browser asks the user for a target directory.  So that's not
 your business.

 After the user selected the files you have to zip them on the server, for
 instance in a temporary in the `/tmp/` directory and then deliver that
 archive to the user.

 Ciao,
   Marc 'BlackJack' Rintsch


THanks Marc,

That makes sense. I can zip the files to a temp directory. However,
How do I deliver the archive to them?...

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


Suppressing banner on interactive startup?

2006-07-28 Thread Tim Chase
A couple of hopefully short (interrelated) questions:

1) is there a way to suppress the banner when starting Python 
interactively?  Something like a --quiet that would just drop 
you straight to a prompt?  I like to use Python as a 
nuclear-powered calculator, and am working on a couple little 
projects where it would be quite handy to suppress the banner 
version/help information (namely, if it gets piped to a 
text-to-speech front end, the less noise the better)

2) is there a way to change the two prompts from  and ... 
to other options?  Namely, again with the TTS option, something 
that is more TTS friendly than hearing greater-than greater-than 
greater-than.  The dot dot dot isn't nearly as bad.

I'm not sure what sorts of queries to google for to find this 
out.  I've tried things like

site:python.org changing interactive interpreter prompt -idle

and

site:python.org suppress start-up banner
site:python.org banner interactive

along with a few such variants, and had no results that seemed to 
be what I wanted.

Short of editing CPython source, is there something I've 
overlooked?  Some command-line option that doesn't get listed in 
python -h or an environment variable?

Thanks,

-tkc





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


problem with regex

2006-07-28 Thread abcd
I have a regex: '[A-Za-z]:\\([^/:\*\?\|])*'

when I do, re.compile('[A-Za-z]:\\([^/:\*\?\|])*') ...I get

sre_constants.error: unbalanced parenthesis

do i need to escape something else?  i see that i have matching
parenthesis.

thx

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


Re: Suppressing banner on interactive startup?

2006-07-28 Thread Simon Brunning
On 7/27/06, Tim Chase [EMAIL PROTECTED] wrote:
 2) is there a way to change the two prompts from  and ...
 to other options?  Namely, again with the TTS option, something
 that is more TTS friendly than hearing greater-than greater-than
 greater-than.  The dot dot dot isn't nearly as bad.

Change sys.ps1 and sys.ps2: http://tinyurl.com/lgqth.

-- 
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Threads vs Processes

2006-07-28 Thread mark
On Thu, 27 Jul 2006 20:53:54 -0700, Nick Vatamaniuc wrote:
 Debugging all those threads should be a project in an of itself.

Ahh, debugging - I forgot to bring that one up in my argument! Thanks
Nick ;)

Certainly I agree of course that there are many applications which suit
a threaded design. I just think there is a general over-emphasis on
using threads and see it applied very often where an event based
approach would be cleaner and more efficient. Thanks for your comments
Bryan and Nick, an interesting debate.

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


Re: problem with regex

2006-07-28 Thread Barry
On 28 Jul 2006 05:45:05 -0700, abcd [EMAIL PROTECTED] wrote:
 I have a regex: '[A-Za-z]:\\([^/:\*\?\|])*'

 when I do, re.compile('[A-Za-z]:\\([^/:\*\?\|])*') ...I get

 sre_constants.error: unbalanced parenthesis

 do i need to escape something else?  i see that i have matching
 parenthesis.

 thx

 --

Try making the argument a raw string:
re.compile(r'[A-Za-z]:\\([^/:\*\?\|])*')
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Suppressing banner on interactive startup?

2006-07-28 Thread Tim Chase
 Change sys.ps1 and sys.ps2: http://tinyurl.com/lgqth.

Thanks!  I knew I had seen a solution to this involving something 
like ps1 and ps2, but the things I kept finding referred to the 
bash/sh PS1 and PS2 prompt level variables.  All it took was 
learning that they *really were* ps1 and ps2...just namespaced 
off into the sys module.

Works like a charm.

-tim


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


Re: problem with regex

2006-07-28 Thread Rob Wolfe

abcd wrote:
 I have a regex: '[A-Za-z]:\\([^/:\*\?\|])*'

 when I do, re.compile('[A-Za-z]:\\([^/:\*\?\|])*') ...I get

 sre_constants.error: unbalanced parenthesis

 do i need to escape something else?  i see that i have matching
 parenthesis.

You should use raw string:

re.compile(r'[A-Za-z]:\\([^/:\*\?\|])*')

Regards,
Rob

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


Re: problem with regex

2006-07-28 Thread Tim Chase
 when I do, re.compile('[A-Za-z]:\\([^/:\*\?\|])*') ...I get
 
 sre_constants.error: unbalanced parenthesis


Because you're not using raw strings, the escapables become 
escaped, making your regexp something like

[A-Za-z]:\([^/:\*\?\|])*

(because it knows what \\ is, but likely doesn't attribute 
significance to \? or \|, and thus leaves them alone).

Thus, you have \( in your regexp, which is a literal 
open-paren.  But you have a ), which is a close a grouping 
paren.  The error is indicating that the close a grouping paren 
doesn't close some previously opened paren.

General good practice shoves all this stuff in a raw string:

r[A-Za-z]:\\([^/:\*\?\|])*

which solves much of the headache.

-tkc




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


Re: problem with regex

2006-07-28 Thread abcd
well thanks for the quick replies, but now my regex doesn't work.

[code]
import re
p = re.compile(r'[A-Za-z]:\\([^/:\*?\|])*')

x = p.match(c:\test)
[/code]

x is None

any ideas why?  i escape the back-slash, the asterisk *, and the PIPE |
b/c they are regex special characters.

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


Re: Fastest Way To Loop Through Every Pixel

2006-07-28 Thread H J van Rooyen

 Paul McGuire [EMAIL PROTECTED] wrote:

| H J van Rooyen [EMAIL PROTECTED] wrote in message
| news:[EMAIL PROTECTED]
|  Paul McGuire [EMAIL PROTECTED] wrote:
| 
|  | Even downer-and-dirtier, you could approximate 30 with 32, 59 with 64,
| and
|  | 11 with 8, and do bit-shifting instead of multiplying:
|  |
|  | def darkness(img,x,y):
|  | return  (RedVal(img,x,y)  5) + (GreenVal(img,x,y)  6) +
|  | (BlueVal(img,x,y)  3)
|  |
|  |
|  | -- Paul
| 
|  *grin* - a man after my own heart! - how do you multiply by ten? - shift,
| save a
|  copy, shift twice more and add the copy...
| 
|  - Hendrik
| 
| Sadly, my timeit results show this saves only a little time, and
| shift-copy-shiftsomemore-and-add is even slower then just doing the original
| floating point multiply.  The biggest win is in prelookup of Image.GetXXX
| functions.
|
| -- Paul

I was not seriously suggesting this for use in python on a pc - its the sort of
rubbish you do on a small embedded machine that has a reduced instruction set
and no multiplier...

- Hendrik



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


Re: How to force a thread to stop

2006-07-28 Thread H J van Rooyen
Paul Rubin http://[EMAIL PROTECTED] Wrote:


| H J van Rooyen [EMAIL PROTECTED] writes:
|  So on a processor that does not have protected instructions - if an
|  idiot writes something to the following effect :
| 
|  *instructions to disable interrupts*
| 
|  followed by :
| 
|  *instructions that go into an infinite loop AND that make no OS calls*
| 
|  the whole bang shoot stops dead - Reset your machine...
|
| A common recovery mechanism in embedded systems is a watchdog timer,
| which is a hardware device that must be poked by the software every
| so often (e.g. by writing to some register).  If too long an interval
| goes by without a poke, the WDT hard-resets the cpu.  Normally the
| software would poke the WDT from its normal periodic timing routine.
| A loop like you describe would stop the timing routine from running,
| eventually resulting in a reset.

*grin* - Yes of course - if the WDT was enabled - its something that I have not
seen on PC's yet...

- Hendrik



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


Re: problem with regex

2006-07-28 Thread Tim Chase
 p = re.compile(r'[A-Za-z]:\\([^/:\*?\|])*')
 
 x = p.match(c:\test)

 any ideas why?  i escape the back-slash, the asterisk *, and the PIPE |
 b/c they are regex special characters.


Same problem, only now in the other string:

  s = c:\test
  print s
c:  est

Your \t is interpreted as as tab character.  Thus, you want

s = rc:\test

or

s = c:\\test

which you'll find should now be successfully found with

p.match(s)

-tkc




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


Re: Need a compelling argument to use Django instead of Rails

2006-07-28 Thread Ben Sizer
Paul Boddie wrote:
 Ben Sizer wrote:
 
  In my case, multimedia and game support is patchy,

 There are lots of multimedia and game frameworks for Python. Which ones
 have you tried and why are they insufficient?

PyGame was barely maintained for a year, and is based on SDL which was
also barely maintained for a year, and which hasn't kept up with
hardware advances at all. On the graphical side you can opt for OpenGL,
the Python library for which is also barely maintained (though I hear
work is underway behind the scenes) and doesn't provide much more than
a minimal layer over the C interface anyway. DirectX support only
appeared this year unless you used IronPython, and it doesn't seem very
popular.

Which other frameworks are you thinking of? I know of a variety of
wrappers around individual libraries, and of wrappers around 3D engines
such as Irrlicht and Ogre, but not much else.

 Certainly, some Web frameworks have some element of Java flavouring,
 but there's also considerable diversity at least at certain levels.

Pretty much every Python web offering revolves around you having your
own server with the luxury of running your own long-running processes
on it. Great for business apps, not much use for the hobbyist or
independent site. There are probably some hosts that will provide
shared hosting for your Django or Turbogears app, but they are not
exactly numerous. The barrier to entry here is much higher than with
PHP or ASP, for example. And even with the full framework approach, the
field has been so fragmented until recently that in terms of community
support, you'd be better off opting for another language. I appreciate
there's a diversity vs. standardisation argument there which may never
be settled, so I accept this is just a personal opinion, but I do think
a critical mass of users is important with any technology.

I'm in a similar situation to the original poster; I'd like to use
Turbogears for an app I want to write, but will probably end up doing
it in PHP instead, because I can't get dedicated hardware or a local
host for Turbogears. (Never mind the lack of documentation.)

 Otherwise, no amount of complaining will put the
 two technologies together.

It's a fair point, but on the other hand, saying if you want it doing,
do it yourself doesn't objectively improve the status quo. If
something doesn't exist, it doesn't exist, and it's valid to comment
upon that fact.

-- 
Ben Sizer

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


Re: problem with regex

2006-07-28 Thread abcd
sorry i forgot to escape the question mark...

 [code]
 import re
 p = re.compile(r'[A-Za-z]:\\([^/:\*?\|])*')

even when I escape that it still doesnt work as expected.

p = re.compile(r'[A-Za-z]:\\([^/:\*\?\|])*')

p.match('c:\test')  still returns None.

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


Possible error in 'dive into Python' book, help!

2006-07-28 Thread Ben Edwards
I have been going through Dive into Python which up to now has been
excellent.  I am now working through Chapter 9, XML Processing.  I am 9
pages in (p182) in the 'Parsing XML section.  The following code is
supposed to return the whole XML document (I have put ti at the end of
this email):

from xml.dom import minidom
 
xmldoc =
minidom.parse('/home/ben/diveintopython-5.4/py/kgp/binary.xml') 
grammerNode = xmldoc.firstChild
 
print grammerNode.toxml()

But it only returns:

!DOCTYPE grammar
  PUBLIC '-//diveintopython.org//DTD Kant Generator Pro v1.0//EN'
  'kgp.dtd'

The next line is then 

grammerNode.childNodes

And it returns an empty tuples;(

Kind of stuck here as I don't really want to continue.  Has anyone any
idea what is going on?

Ben

binary.xml

?xml version=1.0?
!DOCTYPE grammar PUBLIC -//diveintopython.org//DTD Kant Generator Pro
v1.0//EN kgp.dtd
grammar
ref id=bit
  p0/p
  p1/p
/ref
ref id=byte
  pxref id=bit/xref id=bit/xref id=bit/xref
id=bit/xref id=bit/xref id=bit/xref id=bit/xref
id=bit//p
/ref
/grammar




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


Re: Comma is not always OK in the argument list?!

2006-07-28 Thread olsongt

Nick Vatamaniuc wrote:
 Roman,

 According to the Python call syntax definition
 (http://docs.python.org/ref/calls.html) commas should be allowed, so it
 seems like a minor bug.  Here are the  lines in question:
 -http://docs.python.org/ref/calls.html---
 call ::= primary ( [argument_list [,]] )
 argument_list::=positional_arguments [, keyword_arguments] [, *
 expression] [, ** expression]
   | keyword_arguments [, * expression] [, ** expression]
 | * expression [, ** expression]
 | ** expression
 --
 If you notice in the 'call' definition, no matter what the
 'argument_list' is, it can be followed by an optional ',' right before
 the closing ')'. Your code is a counterexample to this. Here is a more
 exhaustive example:
 

Actually, in the real BNF it's not allowed:

http://svn.python.org/view/python/trunk/Grammar/Grammar?rev=46209view=markup

parameters: '(' [varargslist] ')'
varargslist: ((fpdef ['=' test] ',')*
  ('*' NAME [',' '**' NAME] | '**' NAME) |
  fpdef ['=' test] (',' fpdef ['=' test])* [','])
fpdef: NAME | '(' fplist ')'

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


Newbie..Needs Help

2006-07-28 Thread Graham Feeley
Hi this is a plea for some help.
I am enjoying a script that was written for me and its purpose is to collect 
data from a web site and puts it into a access database table.
It works fine, however it is a sports info table but now I need to collect 
the results of those races.

I simply can't keep up putting the results in manually.
I dont care if it is a access table or a text file ( whichever is easiest)
there are only 12 fields to extract
The person who wrote the script is not available as he is engrossed in 
another project which is talking all his time.
I hope someone has a little time on his hands willing to help me
Regards
Graham
 


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


Re: problem with regex

2006-07-28 Thread abcd
Sybren Stuvel wrote:
 Yes, because after the c: you expect a backslash, and not a tab
 character. Read the manual again about raw strings and character
 escaping, it'll do you good.


doh.  i shall do that.

thanks.

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


Re: How to force a thread to stop

2006-07-28 Thread Paul Rubin
Paul Boddie [EMAIL PROTECTED] writes:
 Anyway, the py.execnet thing is presumably designed to work over the
 Internet and over local networks, with the benefit of SSH being that it
 applies well to both domains. Whether it's a better solution for the
 questioner's problem than established alternatives such as PVM (which
 I've never had the need to look into, even though it seems
 interesting), various distributed schedulers or anything else out
 there, I can't really say.

You could use ssh's port forwarding features and just open a normal
TCP connection to a local port that the local ssh server listens to.
Then the ssh server forwards the traffic through an encrypted tunnel
to the other machine.  Your application doesn't have to know anything
about ssh.

In fact there's a VPN function (using tun/tap) in recent versions of
ssh that should make it even simpler, but I hvean't tried it yet.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie Q: Class Privacy (or lack of)

2006-07-28 Thread Ray
Bruno Desthuilliers wrote:
 Ray wrote:
  Bruno Desthuilliers wrote:
  Actually Bruno,  don't you think that the notion of flexibility in
  Python comes at the expense of security is simply due to the fact
  that the syntax of screw up is exactly the same as the syntax of I
  mean it this way and I do want it?

 (patient) Doctor, it hurts when I do this...
 (doctor) Then don't do it.

 !-)

Yeah, I know... but the thing is that it's easy to do it. Say in C++,
you can rebind the method of a class to another function if you want
to, you can muck around with the vtable and stuff, but you've gotta do
something different than, say, a normal assignment.


 --
 bruno desthuilliers
 python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
 p in '[EMAIL PROTECTED]'.split('@')])

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


Possible error in 'dive into Python' book, help!

2006-07-28 Thread Ben Edwards (lists)
I have been going through Dive into Python which up to now has been
excellent.  I am now working through Chapter 9, XML Processing.  I am 9
pages in (p182) in the 'Parsing XML section.  The following code is
supposed to return the whole XML document (I have put ti at the end of
this email):

from xml.dom import minidom
 
xmldoc =
minidom.parse('/home/ben/diveintopython-5.4/py/kgp/binary.xml') 
grammerNode = xmldoc.firstChild
 
print grammerNode.toxml()

But it only returns:

!DOCTYPE grammar
  PUBLIC '-//diveintopython.org//DTD Kant Generator Pro v1.0//EN'
  'kgp.dtd'

The next line is then 

grammerNode.childNodes

And it returns an empty tuples;(

Kind of stuck here as I don't really want to continue.  Has anyone any
idea what is going on?

Ben

binary.xml

?xml version=1.0?
!DOCTYPE grammar PUBLIC -//diveintopython.org//DTD Kant Generator Pro
v1.0//EN kgp.dtd
grammar
ref id=bit
  p0/p
  p1/p
/ref
ref id=byte
  pxref id=bit/xref id=bit/xref id=bit/xref
id=bit/xref id=bit/xref id=bit/xref id=bit/xref
id=bit//p
/ref
/grammar




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


Re: problem with regex

2006-07-28 Thread abcd
not sure why this passes:


 regex = r'[A-Za-z]:\\([^/:\*\?\|])*'
 p = re.compile(regex)
 p.match('c:\\test')
_sre.SRE_Match object at 0x009D77E0
 p.match('c:\\test?:/')
_sre.SRE_Match object at 0x009D7720


the last example shouldnt give a match

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


SWIG, Python and C structures

2006-07-28 Thread RocketIII
Hi,

I have structures like the following:

typedef struct _SX
{
  int   i;
  char  str[10];
} SX;

typedef struct _SXA
{
  int num_elements;
  SX  sa[10];
} SXA;

void myfunc1( SX *sx_p );
void myfunc2( SXA *sxa_p );

The swig interface file simply includes the .h-file with the '%include'
statement.

I'm having problems when sending elements of SX within the SXA as an
argument to myfunc2!

The Python codes is like following:
...
  sx1 = pymod.SX()
  sx1.i = 1
  sx1.str = string1
  sx2 = pymod.SX()
  sx2.i = 2
  sx2.str = string2

  sxl = []
  sxl.append( sx1 )
  sxl.append( sx2 )

  sxa = pymod.SXA()
  sxa.num_elements = len(sxl)
  sxa.sa = sxl  # -triggers the
following error

Traceback (most recent call last):
  File pymod_test.py, line 34, in ?
test()
  File pymod_test.py, line 31, in test
test2()
  File pymod_test.py, line 25, in test2
sxa.sa = sxl
  File /home/user/utv/misc/pymods/pymod.py, line 70, in lambda
__setattr__ = lambda self, name, value: _swig_setattr(self, SXA,
name, value)
  File /home/user/utv/misc/pymods/pymod.py, line 22, in _swig_setattr
return _swig_setattr_nondynamic(self,class_type,name,value,0)
  File /home/user/utv/misc/pymods/pymod.py, line 15, in
_swig_setattr_nondynamic
if method: return method(self,value)
TypeError: argument number 2: a 'SX *' is expected, 'list([pymod.SX;
proxy of C SX instance at _a0211708_p__SX, pymod.SX; proxy of C SX
instance at _70b21408_p__SX])' is received

I've tried to add a %typemap (in) SX { ... } without any success.

The following assignment with call to myfunc2 works though.
sxa.sa = sx1 

Can anyone please advise

Regards
- Ingi

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


Re: Newbie..Needs Help

2006-07-28 Thread Nick Vatamaniuc
Your description is too general. The way to 'collect the results'
depends largely in what format the results are. If they are in an html
table you will have to parse the html data if they are in a simple
plaintext you might use a different method, and if the site renders the
numbers to images and adds some noise and font effects to them, then
you can abandon the idea altogether unless you have a good background
in OCR.

But let's assume that you data is embedded an html sourse. Even so you,
it would largely depend on the specific syntax used. Sometimes you
could  just use regular expressions, other times a full HTML parser
will be needed. Then you could have the issue of 'how to get to the
right page' and/or 'how to uniquely identify and match each of the
previously parsed rows of data to the new set of rows of data that also
have the results added to them?'

Perhaps if you post the website plus a clear and exact description of
what you want to accomplish and what has already been accomplished you
might find someone to help.

-Nick V.





Graham Feeley wrote:
 Hi this is a plea for some help.
 I am enjoying a script that was written for me and its purpose is to collect
 data from a web site and puts it into a access database table.
 It works fine, however it is a sports info table but now I need to collect
 the results of those races.

 I simply can't keep up putting the results in manually.
 I dont care if it is a access table or a text file ( whichever is easiest)
 there are only 12 fields to extract
 The person who wrote the script is not available as he is engrossed in
 another project which is talking all his time.
 I hope someone has a little time on his hands willing to help me
 Regards
 Graham

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


Re: War chest for writing web apps in Python?

2006-07-28 Thread Vincent Delporte
On Fri, 28 Jul 2006 08:06:10 +0200, Vincent Delporte
[EMAIL PROTECTED] wrote:
(snip)

Thanks everyone for the input!

For the IDE: Ideally, I'd like something modern that uses language
wordlists (to show syntax, variables, etc. in different colors), a
window that lists all the procedures so I can easily jump from on to
the other, possibly an edit window that can fold code with the
familiar + sign in the left side, etc. I'll check out WingIDE and
Eric3.

For the GUI builder: It's just that I'm used to Delphi, ie. drawing
the interface with a mouse, but I guess the equivalent is just a
WYSIWYG HTML editor like DreamWeaver etc.

For the application engine: Indeed, I hesitate between CherryPy and
Django, as I've read a lot of nice things about both.

Hopefully, finding web hosters that support Python and those
frameworks won't be an issue?

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


Re: problem with regex

2006-07-28 Thread Tim Chase
 regex = r'[A-Za-z]:\\([^/:\*\?\|])*'
 p = re.compile(regex)
 p.match('c:\\test')
 _sre.SRE_Match object at 0x009D77E0
 p.match('c:\\test?:/')
 _sre.SRE_Match object at 0x009D7720
 
 the last example shouldnt give a match

Ah, but it should, because it *does* match.

  m = p.match('c:\\test?:/')
  m.group(0)
'c:\\test'
  # add a $ at the end to anchor it
  # to the end of the line
  regex = r'[A-Za-z]:\\([^/:\*\?\|])*$'
  p = re.compile(regex)
  m = p.match('c:\\test?:/')
  m

By adding the $ to ensure that you're matching the whole string 
passed to match() and not just as much as possible given the 
regexp, you solve the problem you describe.

-tkc



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


Re: Newbie Q: Class Privacy (or lack of)

2006-07-28 Thread Ben Sizer
Ray wrote:
 Yeah, I know... but the thing is that it's easy to do it. Say in C++,
 you can rebind the method of a class to another function if you want
 to, you can muck around with the vtable and stuff, but you've gotta do
 something different than, say, a normal assignment.

But remember, at no point did they think to make that stuff
deliberately hard so that it would give you safety. It's hard because
the implementation is relatively complex. The flipside of that is
writing function objects in C++, which are an ugly hack to get around
the fact that you can't just assign functions or define them in-place
in that language. Python makes it trivial by comparison. And as another
example, if you use the STL in C++ regularly, you will be familiar with
the hoops you have to jump through in order to use generic functions.
eg. try to call a polymorphic member function on each pointer in an
std::map, while passing a fixed parameter to that function... this sort
of thing is trivial in Python as a side-effect of the fact that the
attributes are looked up at run-time.

-- 
Ben Sizer

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


Re: New release of Diet Python (Beta 0.2)

2006-07-28 Thread david_wahler
I'll be out of the office until approximately August 20th. If you have any 
questions, please email [EMAIL PROTECTED]

-- David Wahler


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


Re: Possible error in 'dive into Python' book, help!

2006-07-28 Thread Tim Chase
 !DOCTYPE grammar
   PUBLIC '-//diveintopython.org//DTD Kant Generator Pro v1.0//EN'
   'kgp.dtd'

I tried to reproduce your problem with the sample file you gave, 
but it gasped, wheezed and died with a traceback about entities. 
  Likely for not also having this kgp.dtd file (and any other 
external files it references in turn).

Care to post that file too? (of copyright allows...)

-tkc



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


Re: how best to check a value? (if/else or try/except?)

2006-07-28 Thread John Salerno
John McMonagle wrote:

 Have a look at using a wx.Validator in your wx.TextCtrl.

Ah, good thinking! I wasn't even considering another option like that, 
which probably makes more sense anyway!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how best to check a value? (if/else or try/except?)

2006-07-28 Thread John Salerno
Nick Vatamaniuc wrote:
 John,
 
 The way I do it is, is I ask myself  'is there a more common (basic)
 base between the code paths or do they both have about a 50/50 chance
 on average?' or 'will one code path be taken during an error and the
 other one during the normal processing?'.  If there is a clear single
 common/usual/basic case or I try to detect an error I use 'try/except',
 if it could go either way on average I use 'if'.

Thanks, that's something good to think about. This issue came up once 
before and I remember someone saying something like you're using a 
try/except statement, but i wouldn't really consider that situation 
'exceptional', so thinking of it in your terms might help a lot.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to force a thread to stop

2006-07-28 Thread Paul Rubin
H J van Rooyen [EMAIL PROTECTED] writes:
 *grin* - Yes of course - if the WDT was enabled - its something that
 I have not seen on PC's yet...

They are available for PC's, as plug-in cards, at least for the ISA
bus in the old days, and almost certainly for the PCI bus today.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: HERE I BUILT A QUICK MATRIX TOOOK 5 MINS

2006-07-28 Thread Grant Edwards
On 2006-07-28, Paul McGuire [EMAIL PROTECTED] wrote:
 ...USING A INFINITE MAGENTIC
 FIELD!!!

 I have a vision of a sweeping magenta fabric rippling through the cosmos.

 Perhaps a mauvic, cyanic, or even aubergenic field would be more stylish.

depends on what shoes you choose to go with it.

-- 
Grant Edwards   grante Yow!  My uncle Murray
  at   conquered Egypt in 53
   visi.comB.C. And I can prove
   it too!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem with regex

2006-07-28 Thread Rob Wolfe

abcd wrote:
 not sure why this passes:


  regex = r'[A-Za-z]:\\([^/:\*\?\|])*'
  p = re.compile(regex)
  p.match('c:\\test')
 _sre.SRE_Match object at 0x009D77E0
  p.match('c:\\test?:/')
 _sre.SRE_Match object at 0x009D7720
 

 the last example shouldnt give a match

If you want to learn RE I suggest to use great tool redemo.py (tk app).
Then you can play with regular expressions to find the result
you are looking for.
It can be found in Python 2.4 in Tools\Scripts.

Regards,
Rob

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


Re: Newbie Q: Class Privacy (or lack of)

2006-07-28 Thread Ray

Ben Sizer wrote:
 Ray wrote:
 But remember, at no point did they think to make that stuff
 deliberately hard so that it would give you safety. It's hard because
 the implementation is relatively complex. The flipside of that is
 writing function objects in C++, which are an ugly hack to get around
 the fact that you can't just assign functions or define them in-place
 in that language. Python makes it trivial by comparison. And as another
 example, if you use the STL in C++ regularly, you will be familiar with
 the hoops you have to jump through in order to use generic functions.
 eg. try to call a polymorphic member function on each pointer in an
 std::map, while passing a fixed parameter to that function... this sort
 of thing is trivial in Python as a side-effect of the fact that the
 attributes are looked up at run-time.

Yeah, I know what you mean. Perhaps that wasn't a good example, but
what I meant was simply that it's different. It doesn't even have to be
complicated like in the C++ case, just different, so say the
interpreter would be able to tell: oh, this guy wants to rebind the
method, and oh, that is an error. Right now it can't tell because
both look the same.

I really did like C++ btw. Now I had to force myself really hard just
to get through one chapter off a good book like Effective STL, because
all the time something at the back of my head was telling me like that
that was basically a book about jumping through hoops :)

 
 -- 
 Ben Sizer

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


Re: Comma is not always OK in the argument list?!

2006-07-28 Thread Nick Vatamaniuc
True, that is why it behaves the way it does, but which way is the
correct way? i.e. does the code need updating or the documentation?

-Nick V.

[EMAIL PROTECTED] wrote:
 Nick Vatamaniuc wrote:
  Roman,
 
  According to the Python call syntax definition
  (http://docs.python.org/ref/calls.html) commas should be allowed, so it
  seems like a minor bug.  Here are the  lines in question:
  -http://docs.python.org/ref/calls.html---
  call ::= primary ( [argument_list [,]] )
  argument_list::=positional_arguments [, keyword_arguments] [, *
  expression] [, ** expression]
  | keyword_arguments [, * expression] [, ** expression]
  | * expression [, ** expression]
  | ** expression
  --
  If you notice in the 'call' definition, no matter what the
  'argument_list' is, it can be followed by an optional ',' right before
  the closing ')'. Your code is a counterexample to this. Here is a more
  exhaustive example:
  

 Actually, in the real BNF it's not allowed:

 http://svn.python.org/view/python/trunk/Grammar/Grammar?rev=46209view=markup

 parameters: '(' [varargslist] ')'
 varargslist: ((fpdef ['=' test] ',')*
   ('*' NAME [',' '**' NAME] | '**' NAME) |
   fpdef ['=' test] (',' fpdef ['=' test])* [','])
 fpdef: NAME | '(' fplist ')'

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


Re: Need a compelling argument to use Django instead of Rails

2006-07-28 Thread Ray

Ben Sizer wrote:
 Roman Susi wrote:
  Ben Sizer wrote:
   The problem is that Python is the 2nd best language for everything. ;)
 
  Is it a bad thing?

 I don't know. I suppose that depends on how you define 'bad'! For me,
 it is often inconvenient, because I'd prefer to use Python but
 generally find that I have to choose something else if I want to do the
 best possible for any particular project.

Exactly. It's bad because Python is the language you'd love to use at
work but can't :) Don't tell me to look for a job in a Python shop,
there's none. OTOH, there IS at least one RoR shop that I know of and
they're doing pretty well!

 In my case, multimedia and game support is patchy, and web development
 support is still oriented towards the Java/enterprise user - if CGI
 doesn't suffice, that is. In the original poster's case, it's seemingly
 because specific database support seems to be lacking. Improving the
 libraries in these areas would hopefully increase the diversity of
 Python's potential applications rather than diminish it.

Yep, (support in Django, specifically, not Python).

 
 -- 
 Ben Sizer

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


Re: Python Projects Continuous Integration

2006-07-28 Thread Harry George
Dave Potts [EMAIL PROTECTED] writes:

 Hi,
 
 I'm just starting a development project in Python having spent time in
 the Java world.  I was wondering what tool advice you could give me
 about setting up a continuous integration environment for the python
 code: get the latest source, run all the tests, package up, produce the
 docs, tag the code repository.  I'm used to things like Maven and
 CruiseControl in the Java world.
 
 Cheers,
 
 Dave.
 

First, sorry to hear you have had to use Java. You should recover
after a few months in Python.  Second, welcome to Python.  Third, some
of us emacs as our IDE.

I presume you often have several packages open at once, each with its
own regression tests, own documentation, and own CVS or SVN module.
You may also have multiple coding languages going at once (e.g.,
Python, C, C++, FORTRAN, Lisp, PROLOG).  Doing this in emacs:

1. Make a separate instance for each package being edited.  In the
   instance make separate frames for a) code buffers, b) test case
   buffers, c) doc buffers.  In the test frame, make a shell window
   where you can run go_test, thus running your testsuite for that
   package.  In the doc frame, make a shell window where you can run
   go_doc.  (Must of couse have written those go_ scripts, also done
   in emacs of course.).  

   If there are too many things happening for one desktop, run each
   package in a separate desktop (you are working in an OS which has
   virtual screens, right?).

2. Do CVS checkin/checkout in tool of your choice.  Emacs can do it. I
   prefer tkcvs, with editor set to emacs and diff set to emacs's'
   ediff.  Personal preference.

3. Do documentation in the tool of your choice.  Emacs can support
   pretty much any natural language, and has markups for just about
   any markup mechanism (SGML, XHTML, etc.).  I use my own Pdx, edited
   in emacs, and thus autogenerate HTML, PDF, LaTeX, etc.  Again,
   personal preference.  At a minimum, use some mechanism which allow
   autogeneration of documentation, auto inclusion of code snippets,
   and hyperlinking.  Since the go_doc is run in an emacs shell, use
   alt-P-return to rerun the line.  Redocumenting is thus a 2
   keystroke effort.

4. Do testing using a batch go_test script, running a suite built from
   unittest.  As needed, write debug statements to another buffer in
   that frame, where you can use full emacs functionallity to search
   it.  Since the go_test is run in an emacs shell, use alt-P-return
   to rerun the line.  Retesting is thus a 2 keystroke effort.

5. Oh, yes, coding.  Emacs's python-mode.el works fine.  Colorize or
   not as you see fit.  There are ways to set up code-completion, but
   personally I never do it.  You can setup etags but I never do --
   emacs search and grep-find do what I need.  Personal preference.

6. Use exactly the same setup for language after language, decade
   after decade, platform after platform.  Use your brain cells form
   something useful, like learning new technologies and new
   algorithms.


-- 
Harry George
PLM Engineering Architecture
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need a compelling argument to use Django instead of Rails

2006-07-28 Thread Ray
Ben Sizer wrote:
 a minimal layer over the C interface anyway. DirectX support only
 appeared this year unless you used IronPython, and it doesn't seem very
 popular.

IronPython is not released yet, I do hope it will become popular
though. It's in RC1 now and should be released soon. I'm really looking
forward to it!

  Certainly, some Web frameworks have some element of Java flavouring,
  but there's also considerable diversity at least at certain levels.

 Pretty much every Python web offering revolves around you having your
 own server with the luxury of running your own long-running processes
 on it. Great for business apps, not much use for the hobbyist or
 independent site. There are probably some hosts that will provide
 shared hosting for your Django or Turbogears app, but they are not
 exactly numerous. The barrier to entry here is much higher than with
 PHP or ASP, for example. And even with the full framework approach, the
 field has been so fragmented until recently that in terms of community
 support, you'd be better off opting for another language. I appreciate
 there's a diversity vs. standardisation argument there which may never
 be settled, so I accept this is just a personal opinion, but I do think
 a critical mass of users is important with any technology.

Diversity can be a pain in the ass sometimes. Instead of ending up with
something really good you end up with a lot of mediocre stuff (Note:
I'm not saying anything about Django or Turbogears here, mind!).
Reminds me of the time when I was installing Linux for the first time
and finding out that there were tons of text editor included in the
distro. I only need vi so that wasn't a problem, but I could imagine
someone from a strictly Windows world would wish that there was only
one text editor :)

 I'm in a similar situation to the original poster; I'd like to use
 Turbogears for an app I want to write, but will probably end up doing
 it in PHP instead, because I can't get dedicated hardware or a local
 host for Turbogears. (Never mind the lack of documentation.)

Yep. And my case now is pretty much shot with no Oracle/SQL Server
support.

  Otherwise, no amount of complaining will put the
  two technologies together.

 It's a fair point, but on the other hand, saying if you want it doing,
 do it yourself doesn't objectively improve the status quo. If
 something doesn't exist, it doesn't exist, and it's valid to comment
 upon that fact.

Couldn't agree more. A lot of would-be users, upon being told that,
would simply turn to another framework/language/platform/whatever that
does provide the feature in question. This is especially true for
companies with fast moving projects like the one I'm working for at the
moment.

Of course, then we can always say, sur, go ahead, your loss blah
blah blah Well maybe. But how does it help ourselves really?

 
 -- 
 Ben Sizer

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


metaclass : parse all class once before doing anything else ?

2006-07-28 Thread Laurent Rahuel
Hi,

I have a much to smart problem for my brain.

Here is the deal :

I got a metaclass named Foo

Then I got two others classes:

class Bar(Foo):
pass

class Baz(Foo):
pass

I know how to add some attrs, methods to Bar and Baz when the module is
loaded but I need to do something more :

Before adding anything to these classes, 
1 - I need to parse all defined Foo classes
2 - sort them 
3 - parse this sorted list to add attrs and methods.

This seems to be really to clever for me ;-(

Any idea ?

Regards,

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


Re: Nested function scope problem

2006-07-28 Thread Gerhard Fiedler
On 2006-07-28 04:07:20, Bruno Desthuilliers wrote:

 Gerhard Fiedler a écrit :
 Isn't being on the LHS (of an assignment) the only way to (re)bind a
 variable?
 
 pedantic
 s/variable/name/
 /pedantic

Ok, I missed this one :)

 Are there situations where binding happens without an explicit
 assignment with the variable name being on the LHS?
 
 Assignment aside, binding occurs:
 
 1/ on evaluation of import, class and def statement
 2/ on function call for the function's arguments
 3/ as a result of a list comp or for loop:

Sounds intuitive enough.

 Can the object referenced by a variable name get changed without the
 variable name appearing on the LHS?
 
   a = []
   id(a)
 1078043820
   def change(l):
 ... l.append(42)
 ...
   change(a)
   a
 [42]
   id(a)
 1078043820
  
 
 First assignment aside, the *name* 'a' is never on the LHS of an 
 assignment, yet the object referenced by name 'a' got 'changed' : it was 
 initially empty, after call to change() it contains an int.
 
 Yes, I know, this is not what you meant (and no, name 'a' has not been 
 rebound) - but that's really what you asked :  the object referenced by 
 name 'a' got changed without name 'a' being on the LHS !-) 

What I meant here is whether the object can be a different one than before
(the object gets changed like a shirt before dinner, not like the color of
crabs during cooking), without it being caused by being on the LHS of an
assignment (or any of the other possibilities you listed above). That was
more an ambiguity in the language...

 I think your intented question was more like : can a name be rebound 
 without that name being on the LHS of an assignment, [...]

Yes. 

 and it's addressed above

I'll have to experiment a bit and come up with an example of what I'm
thinking of. But it seems that what I was thinking of doesn't make sense in
the light of my better understanding of binding :)

Thanks for your help. Binding seems to be one of the more crucial concepts
to master before understanding how Python works. One of the first things I
wondered (this is slightly related) is whether it wouldn't be really good
to make the difference between mutable and immutable objects more obvious. 

Gerhard

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


Re: SocketServer and timers

2006-07-28 Thread bryanjugglercryptographer

Simon Forman wrote:
 alf wrote:
  Hi,
 
  I have one thread app using SocketServer and use server_forever() as a
  main loop. All works fine, but now I need certain timer checking let's
  say every 1 second something and stopping the main loop. So questions are:
  -how to stop serve_forever
  -how to implement timers
 
  thx, alf

 Do you really need a timer, or do you just want to check something
 every second or so?

 If the latter, then something like this would do it:

 from time import time

 INTERVAL = 1.0

 RUN = True

 while RUN:

 # Get a time in the future.
 T = time() + INTERVAL

 # Serve requests until then.
 while time()  T:
 server.handle_request()
 # Check whatever.
 if check():
 # Do something, for example, stop running.
 RUN = False

That alone does not work. If server.handle_request() blocks,
you don't get to the check(). You need some kind of timeout
in handle_request().


-- 
--Bryan

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


Re: Changing a value for each folder while traversing a file system

2006-07-28 Thread PipedreamerGrey
Perfect.  That's exactly what I wanted.  Thanks.

For those reading this later on, the following script will crawl
through a directory, select all the text files, dump them into seperate
numbered html files in the parent directory (in which the python script
is executed).  In this example, the first line of the text file is
placed into a table with a randomly colored background.  With a little
work, the text files can be complexly formatted, each folder can be
color coded, etc.

#! /usr/bin/python
import glob
import fileinput
import os
import string
import sys

count == 1
number == 1

class DirectoryWalker:
# a forward iterator that traverses a directory tree, and
# returns the filename

def __init__(self, directory):
self.stack = [directory]
self.files = []
self.index = 0

def __getitem__(self, index):
while 1:
try:
file = self.files[self.index]
self.index = self.index + 1
except IndexError:
# pop next directory from stack
self.directory = self.stack.pop()
self.files = os.listdir(self.directory)
self.index = 0
else:
# get a filename, eliminate directories from list
fullname = os.path.join(self.directory, file)
if os.path.isdir(fullname) and not
os.path.islink(fullname):
self.stack.append(fullname)
else:
return fullname

for file in DirectoryWalker(.):
 last_directory = None
for file in DirectoryWalker(.):
issue = number +.html
directory = os.path.dirname(file)
if directory != last_directory:
color = random.choice([#99, #009900, #99])
last_directory = directory

# divide files names into path and extention
path, ext = os.path.splitext(file)
# choose the extention you would like to see in the list
if ext == .txt:
print file
file = open(file)
fileContent = file.readlines()
   # just for example, let's say I want to print the color here as
if in an html tag...
issue.write(htmlhead/headbody)
for line in fileContent:
if not line.startswith(\n):
if count == 1:
issue.write('table bgcolor='+color+' width=100%
border=0 cellspacing=0 cellpadding=0trtd')
issue.write(line)
issue.write(/td/tr/table)
count = count + 1
else:
issue.write(p)
issue.write(line)
issue.write(/p)
issue.write(/body/html)
issue.close()

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


Re: Need a compelling argument to use Django instead of Rails

2006-07-28 Thread Paul Boddie
Ben Sizer wrote:
 Paul Boddie wrote:
  Ben Sizer wrote:
  
   In my case, multimedia and game support is patchy,
 
  There are lots of multimedia and game frameworks for Python. Which ones
  have you tried and why are they insufficient?

 PyGame was barely maintained for a year, and is based on SDL which was
 also barely maintained for a year, and which hasn't kept up with
 hardware advances at all. On the graphical side you can opt for OpenGL,
 the Python library for which is also barely maintained (though I hear
 work is underway behind the scenes) and doesn't provide much more than
 a minimal layer over the C interface anyway. DirectX support only
 appeared this year unless you used IronPython, and it doesn't seem very
 popular.

I can only profess familiarity with Pygame which still seems to do more
or less what it always did, although I haven't kept up with the
community, but I have recently released a simple game which seems to
work quite well. By simple, I mean two-dimensional playing areas,
pre-recorded soundtracks, retro-style gameplay.

If I were to get into OpenGL, I'd look at stuff like PyQt alongside
other traditional bindings, mostly because such frameworks - certainly
Qt, as far as I've seen from various reports - usually incorporate a
lot of effort resulting from a serious amount of developer attention to
integrating such technologies and making them work reliably in a number
of environments.

 Which other frameworks are you thinking of? I know of a variety of
 wrappers around individual libraries, and of wrappers around 3D engines
 such as Irrlicht and Ogre, but not much else.

If I were to consider other three-dimensional rendering technologies,
I'd probably look at things like Soya 3D, Panda3D and whatever other
people have dug up:

http://www.vrplumber.com/py3d.py

You also mentioned multimedia frameworks, and this is probably another
area where there are so many projects that it's hard to pick the good
ones.

  Certainly, some Web frameworks have some element of Java flavouring,
  but there's also considerable diversity at least at certain levels.

 Pretty much every Python web offering revolves around you having your
 own server with the luxury of running your own long-running processes
 on it. Great for business apps, not much use for the hobbyist or
 independent site.

Once upon a time I used to advocate my WebStack framework as a solution
to this problem situation: WebStack applications run on BaseHTTPServer
or other monolithic servers (Webware, Twisted, Zope 2, Java Servlet),
but can also be deployed as CGI or in mod_python environments. The
apparent response to this advocacy (which was backed up by an actual
implementation) was that no-one needed such flexibility: an opinion
somewhat at odds with actual practice if you consider widely-deployed
applications such as ViewCVS/ViewVC, Trac, MoinMoin, and so on, where
all of these have provided their own server abstractions at least until
very recently.

Since that time, WSGI has emerged as an interoperability technology,
but the fundamental platform fragmentation issues remain, as everyone
attempts to show how easy it is to write WSGI middleware. Moreover,
the server abstractions required by widely-deployed applications are
still necessary, and it is in precisely this area that framework
proliferation has occurred.

 There are probably some hosts that will provide
 shared hosting for your Django or Turbogears app, but they are not
 exactly numerous. The barrier to entry here is much higher than with
 PHP or ASP, for example.

I think the attitude has been that if you're not willing to lay out the
bucks (albeit not quite as much as it used to be now that virtual
private servers are becoming commonplace), the big players in the
frameworks scene aren't willing to pay you much attention. But as
applications like ViewCVS show, many people appreciate Web application
deployment on low-end hosting, and that not all Web applications are
part of some big Web 2.0 rollout.

 And even with the full framework approach, the
 field has been so fragmented until recently that in terms of community
 support, you'd be better off opting for another language. I appreciate
 there's a diversity vs. standardisation argument there which may never
 be settled, so I accept this is just a personal opinion, but I do think
 a critical mass of users is important with any technology.

I've said this a few times now, but it's worth repeating: when WSGI was
proposed as the next great thing in Python Web standardisation (a topic
in which no-one had any substantial interest until PHP/Ruby were
considered ahead of Python in certain much-discussed decisions), it was
formulated in such a way as to stay off the turf already occupied by
the significant Python frameworks of the time. The consequence of that
decision has been a slight, one centimetre upward movement of the
Python Web scene's healthy competition in the entire framework
stack.

 I'm in a similar situation to the 

  1   2   3   >