Toronto and Area Python Users Group (PyGTA) Meeting Tuesday, 7pm at the Linux Caffe

2006-03-28 Thread Mike C. Fletcher
We will be holding our regular meeting at our regular time, on the 
Fourth Tuesday of the Month from 7pm to 9pm at the (very cool) Linux 
Caffe (located at the Corner of Grace and Harbord).

We're going with small topical discussions (and/or lightning talks) this 
time around, with more socialising and mingling time to let you swap 
stories and experiences.  Likely topics:

* Upcoming 2.5 features (generator coroutines, ctypes, cElementTree)
* DebugHang module for Twisted
* FibraNet

Those who would like to do a short (impromptu or prepared) talk on a 
topic, just drop me a note (or tell me at the meeting) and I'll try to 
get things put together for you (at the very least we should have a 
net-attached laptop with Linux and Python 2.4).  For the presenters; 
this is a good opportunity to work on your presentation skills in front 
of a friendly and forgiving audience.  For the audience; this is a good 
opportunity to work on being a friendly and forgiving audience :) .

Map with instructions on reaching LinuxCaffe is available off the 
official next meeting page in the Wiki:

http://web.engcorp.com/pygta/wiki/NextMeeting

Have fun all,
Mike

-- 

  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://www.vrplumber.com
  http://blog.vrplumber.com

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

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


Graphs from Python

2006-03-28 Thread DurumDara
Hi !

I want to create graphs (edges, nodes) from python.
In the last project I used graph.py that create dot files - and then I 
can convert these dot files with ATT neato command line tool.
But ATT code is instable, sometimes need to reinstalling, and it is use 
horizontal layouts. This cause the reports are unprintable (27 meter 
length), and jpeg export failed.
Then I search for another solution.

I see that GML language is very good, but I don't see any viewer for 
this except yEd.
yEd is GUI app, so I cannot use for batch convert GML files to another 
format (SVG, JPEG, etc.).

Is anybody have a solution to big graph creation ?

Please help me !

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


Re: Difference between 'is' and '=='

2006-03-28 Thread Felipe Almeida Lessa
Em Seg, 2006-03-27 às 23:02 -0800, alex23 escreveu:
 Felipe Almeida Lessa wrote:
  I said [constants defined in your code] can (maybe should?) be used with 
  is, and
  AFAICT I'm right as well:
   b = a
   b is a
  True
 
 You should _never_ use 'is' to check for equivalence of value. Yes, due
 to the implementation of CPython the behaviour you quote above does
 occur, but it doesn't mean quite what you seem to think it does.

/me not checking for value. I'm checking for identity. Suppose a is a
constant. I want to check if b is the same constant.

 Try this:
 
  UPPERLIMIT = 100
  i = 0
  while not (i is UPPERLIMIT):
  i+=1
  print i
 
 Comparing a changing variable to a pre-defined constant seems a lot
 more general a use case than sequential binding  comparison...and as
 this should show, 'is' does _not_ catch these cases.

That's *another* kind of constant. I gave you the example of
socket.AF_UNIX, the kind of constant I'm talking about. Are you going to
sequentially create numbers until you find it? Of couse not.

The problem with Python (and other languages like Jave) is that we don't
have a type like an enum (yet) so we have to define constants in our
code. By doing an is instead of a == you *can* catch some errors.
For example, a very dummy function (picked MSG_EOR as its value is
greater than 99):

---
from socket import MSG_EOR, MSG_WAITALL

def test(type):
if type is MSG_EOR:
print This *is* MSG_EOR
elif type == MSG_EOR:
print This maybe be MSG_EOR
else:
print *Not MSG_EOR
---

Now testing it:

 test(MSG_EOR)
This *is* MSG_EOR

Fine, but:

 print MSG_EOR
128
 test(128)
This maybe be MSG_EOR

This is a mistake. Here I knew 128 == MSG_EOR, but what if that was a
coincidence of some other function I created? I would *never* catch that
bug as the function that tests for MSG_EOR expects any integer. By
testing with is you test for *that* integer, the one defined on your
module and that shouldn't go out of it anyway.

Of course using an enum should make all said here obsolete.

-- 
Felipe.

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

Re: How to inplement Session in CGI

2006-03-28 Thread bruno at modulix
Sullivan WxPyQtKinter wrote:
 Python disappointly failed to provide a convinient cgi session
 management module. 

Probably because there are much better options for web programming in
Python ?

 Not willing to use external modules, I would like to
 implement a simplest Session object on my own.
 
 The basic problem is: how could a python CGI program understand several
 requests are in the same session? 

Just like anyone else: by setting a session cookie. This is not related
to CGI, it's just how HTTP works.

-- 
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: instantiate a class with a variable

2006-03-28 Thread bruno at modulix
John wrote:
 Hi, is it possible to instantiate a class with a variable.
 
 example
 
 class foo:
 def method(self):
 pass
 
 x='foo'
 
 Can I use variable x value to create an instance of my class?

You got examples using string 'foo', now if all you need is to store or
pass around the class, just use it as any other object (yes, classes
*are* objects):

class Foo(object): pass

x = Foo

f = x()
assert type(f) is Foo


-- 
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: object references

2006-03-28 Thread bruno at modulix
DrConti wrote:
 Hi Bruno, hi folks!
 thank you very much for your advices.
 I didn't know about  the property function.
 I learned also quite a lot now about references.
 Ok everything is a reference but you can't get a reference of a
 reference...
 
 I saw a lot of variations on how to solve this problem, but I find
 actually that the property approach is the most natural of all.

So I need to add a little correction to the code snippet (sorry, got
confused by your namings - ie 'ObjectClass' - and some recent
exploration I did about per-instance descriptors) : Actually, using a
property as an *instance* attribute won't work - unless the class
redefine __getattribute__ this way:

class ObjectClass(object):
  def __getattribute__(self, name):
v = object.__getattribute__(self, name)
if not isinstance(v, types.FunctionType) \
   and hasattr(v, '__get__'):
  return v.__get__(self, self.__class__)
return v


 Basically the idea there is that you build up this list of class
 attributes

These are not *class* attributes, but *instance* attributes.

I think you should really take some time to learn more about Python's
object model, attribute lookup rules,  descriptors and metaclasses.


-- 
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: Graphs from Python

2006-03-28 Thread [EMAIL PROTECTED]
Metapost: http://cm.bell-labs.com/who/hobby/MetaPost.html
Examples:
http://tex.loria.fr/prod-graph/zoonekynd/metapost/metapost.html
ImageMagick: http://www.imagemagick.org/script/index.php

Metapost presupposes you know TeX/LaTeX. If you need help in converting
metapost output to eps or pdf, let me know.

Walter Kehowski

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


Python VBR to CBR

2006-03-28 Thread timsspamaddress
Hi,

I'm currently downloading podcasts using Juice, and I want to get them
more easily transferred to my music player (Creative Zen).

I'm currently writing something that will rename and alter the ID tags
to be more friendly (in Python), but in the process, I'd like to
convert from Variable Bit Rate to Constant Bit Rate.

Is there a library for doing this, or alternatively, what would be the
stages for converting from vbr to cbr and what python code is out there
that can help?

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


Re: Plone or TurboGears for Intranet

2006-03-28 Thread Ravi Teja
They are very different tools, apples and oranges. Plone is built for
content management needs and TurboGears is built for general
application development purposes.

Both can work behind Apache but are not based on Apache. They use their
own servers.

Plone gives you a lot out of the box, but building Plone products, for
your custom needs, has a steep learning curve to it. TurboGears is
fairly simple to use and a good dev will probably take a day or so to
get the hang of it. On the other hand, it will take as much time to
learn to use Plone as an admin, let alone develop with it.

There are several case studies for Plone on the web. Just Google for
them. TurboGears won't have any since it is not officially production
software yet. Personally, I don't take software case studies seriously.
They are often too contextual, context that does not get adequately
communicated in the document all too often.

I would choose Plone to manage documents in the Intranet but stick to
TurboGears (or some other framework - there are several good ones) for
app development.

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


Re: How do clients(web browser) close a python CGI program that is not responding?

2006-03-28 Thread Ben Sizer
Sullivan WxPyQtKinter wrote:
 Hi,there. Sometimes a python CGI script tries to output great
 quantities of HTML responce or in other cases, it just falls into a
 dead loop. How could my client close that CGI script running on the
 server?

Generally speaking, remote users don't have control over your local
processes, and if there is some problem with that local process that
causes it to loop indefinitely, the chance that it could react
appropriately to the browser is slim anyway. So the answer is to fix
the problem with the CGI program.

 In addition, how could I configure that if a CGI program do not finish
 its task in 20sec or so, it will be automatically terminated?

I suppose you could run it in a background thread or process,
terminating it after the allotted time has expired, but I suspect you'd
be better off addressing whatever is causing the problem in the first
place. What sort of CGI program is this?

-- 
Ben Sizer

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


Converting Time question

2006-03-28 Thread Math
Hello PythonPeople..

Can anybody help me out?
How do I convert a time of day from milliseconds?
For example:
I got the following time in milliseconds: 1,090516451769E+15
And I want to print it like: 17:14:11.769
I'm on WinXP
Time zone: GMT +01:00

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


Re: Difference between 'is' and '=='

2006-03-28 Thread Joel Hedlund
 This does *not* also mean constants and such:
snip
  a = 123456789
  a == 123456789
 True
  a is 123456789
 False
  

I didn't mean that kind of constant. I meant named constants with defined 
meaning, as in the example that I cooked up in my post. More examples: os.R_OK, 
or more complex ones like mymodule.DEFAULT_CONNECTION_CLASS.

Sorry for causing unneccessary confusion.

Cheers!
/Joel Hedlund
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Difference between 'is' and '=='

2006-03-28 Thread Joel Hedlund
You should _never_ use 'is' to check for equivalence of value. Yes, due
to the implementation of CPython the behaviour you quote above does
occur, but it doesn't mean quite what you seem to think it does.
 
 
 /me not checking for value. I'm checking for identity. Suppose a is a
 constant. I want to check if b is the same constant.

/me too. That's what my example was all about. I was using identity to a known 
CONSTANT (in caps as per python naming conventions :-) to sidestep costly value 
equality computations.

 By doing an is instead of a == you *can* catch some errors.
 snip
 By
 testing with is you test for *that* integer, the one defined on your
 module and that shouldn't go out of it anyway.

I totally agree with you on this point. Anything that helps guarding against 
stealthed errors is a good thing by my standards.

Cheers!
/Joel Hedlund
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do clients(web browser) close a python CGI program that is not responding?

2006-03-28 Thread Jon Ribbens
In article [EMAIL PROTECTED], Sullivan WxPyQtKinter wrote:
 Hi,there. Sometimes a python CGI script tries to output great
 quantities of HTML responce or in other cases, it just falls into a
 dead loop. How could my client close that CGI script running on the
 server? I tried to use the STOP button in the web browser button, but
 it does not work.

It depends on what CGI framework you're using. If the user hits
'stop', the client browser should close its connection and your web
server should close the pipe to your CGI process. I'd expect you to
get a SIGPIPE when next trying to output data.

 In addition, how could I configure that if a CGI program do not finish
 its task in 20sec or so, it will be automatically terminated?

Do you mean a specific CGI, or all CGIs in general? If it's in general
then you need to see if your web server can be configured to do that.
If it's a specific CGI, check out signal.alarm() or
resource.setrlimit(resource.RLIMIT_CPU, ...). Apache has a RLimitCPU
directive, but be careful with it since it may well not do what you
expect.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Difference between 'is' and '=='

2006-03-28 Thread Joel Hedlund
Not those kind of constants, but this one:
 
 
Python 2.4.2 (#2, Nov 20 2005, 17:04:48)
[GCC 4.0.3 2005 (prerelease) (Debian 4.0.2-4)] on linux2
Type help, copyright, credits or license for more information.

CONST = 123456789
a = CONST
a == CONST

True

a is CONST

True

 
 That's a little misleading, and goes back to the questions of what is
 assignment in Python? and What does it mean for an object to be
 mutable?
 
 The line a = CONST simply gives CONST a new name.  After that, a is
 CONST will be True no matter what CONST was.  Under some circumstances,
 I can even change CONST, and a is CONST will *still* be True.

Anyone who thinks it's a good idea to change a CONST that's not in a module 
that they have full control over must really know what they're doing or suffer 
the consequences. Most often, the consequences will be nasty bugs.

Cheers!
/Joel Hedlund
-- 
http://mail.python.org/mailman/listinfo/python-list


To run a python script in all the machines from one server

2006-03-28 Thread muttu2244
Hi Everyone

I want to run a python script in all the machines that are connected
through local network and collect the information about that machine
such as HDD size, RAM capacity(with number of slots)  ,processer speed
etc.

But i want to run a script from just the server, so that it should
start scripts in all other machines, and get their local machines
information and dump the same information in some FTP.

Could you please let me know how can i do this??

Thanks 
Yogi

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


Re: How to inplement Session in CGI

2006-03-28 Thread Piet van Oostrum
 Sullivan WxPyQtKinter [EMAIL PROTECTED] (SW) wrote:

SW Python disappointly failed to provide a convinient cgi session
SW management module. Not willing to use external modules, I would like to
SW implement a simplest Session object on my own.

SW The basic problem is: how could a python CGI program understand several
SW requests are in the same session? Definately, request from different IP
SW would be easy to identified to be in different sessions, but request
SW from the same IP would not. 

http://starship.python.net/~davem/cgifaq/faqw.cgi?req=showfile=faq02.011.htp
or google for python cgi session for more.
But why write it yourself if someone else has already done the work?
-- 
Piet van Oostrum [EMAIL PROTECTED]
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: To run a python script in all the machines from one server

2006-03-28 Thread Martin P. Hellwig
[EMAIL PROTECTED] wrote:
 Hi Everyone
 
 I want to run a python script in all the machines that are connected
 through local network and collect the information about that machine
 such as HDD size, RAM capacity(with number of slots)  ,processer speed
 etc.
 
 But i want to run a script from just the server, so that it should
 start scripts in all other machines, and get their local machines
 information and dump the same information in some FTP.
 
 Could you please let me know how can i do this??
 
 Thanks 
 Yogi
 
You could create a xmlrpc server on all clients, that listens for such a 
request, then your server (which is an xmlrpc client) calls all the 
clients on the appropriate exposed function, then the client proceeds on 
gathering the required information and puts it using ftplib on the ftp 
share. It is also possible to return all info via the xmlrpc call and 
let the server do the ftp part, all depends on your requirements.

If your on a NT only network a better route would be to use WMI.

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


Re: Difference between 'is' and '=='

2006-03-28 Thread Joel Hedlund
 a is None
 
 is quicker than
 
 a == None

I think it's not such a good idea to focus on speed gains here, since they 
really are marginal (max 2 seconds total after 1000 comparisons):

  import timeit
  print timeit.Timer(a == None, a = 1).timeit(int(1e7))
4.19580316544
  print timeit.Timer(a == None, a = None).timeit(int(1e7))
3.20231699944
  print timeit.Timer(a is None, a = 1).timeit(int(1e7))
2.37486410141
  print timeit.Timer(a is None, a = None).timeit(int(1e7))
2.48372101784

Your observation is certainly correct, but I think it's better applied to more 
complex comparisons (say for example comparisons between gigantic objects or 
objects where value equality determination require a lot of nontrivial 
computations). That's where any real speed gains can be found. PEP8 tells me 
it's better style to write a is None and that's good enough for me. Otherwise 
I try to stay away from speed microoptimisations as much as possible since it 
generally results in less readable code, which in turn often results in an 
overall speed loss because code maintenance will be harder.

Cheers!
/Joel Hedlund
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: To run a python script in all the machines from one server

2006-03-28 Thread Eyal Lotem
[EMAIL PROTECTED] wrote:

 Hi Everyone
 
 I want to run a python script in all the machines that are connected
 through local network and collect the information about that machine
 such as HDD size, RAM capacity(with number of slots)  ,processer speed
 etc.
 
 But i want to run a script from just the server, so that it should
 start scripts in all other machines, and get their local machines
 information and dump the same information in some FTP.
 
 Could you please let me know how can i do this??
 
 Thanks
 Yogi

Take a look at: http://pybuild.sf.net/pyinvoke.html or
http://rpyc.sourceforge.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Link to Daily Python-URL from www.python.org?

2006-03-28 Thread Tim Churches
Am I correct in thinking that there is no longer any link from anywhere
on the Python Web site at http;//www.python.org to the Daily Python-URL
at http://www.pythonware.com/daily/ ? There is no sign of it on the
Community page, nor any reference to it at http://planet.python.org/

I'm sure there was a link to it last time I looked.

Tim C




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


Re: New Python logo in high resolution format

2006-03-28 Thread Brian Quinlan
The new Python logo is available in high-resolution format here:
http://tinyurl.com/n4rge

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


Re: Python VBR to CBR

2006-03-28 Thread Matthias Bläsing
timsspamaddress wrote:

 I'm currently writing something that will rename and alter the ID tags to
 be more friendly (in Python), but in the process, I'd like to convert from
 Variable Bit Rate to Constant Bit Rate.
 
 Is there a library for doing this, or alternatively, what would be the
 stages for converting from vbr to cbr and what python code is out there
 that can help?

It depends on the platform you are using - at least running Linux it would
make sense to take a look at gstreamer, which is a pretty complete
multimedia framework. Juding from a mp3/vorbis/flac player I wrote, its
nice to use.

HTH

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


Re: New Python logo in high resolution format

2006-03-28 Thread Tim Parkin
Brian Quinlan wrote:

The new Python logo is available in high-resolution format here:
http://tinyurl.com/n4rge

Cheers,
Brian
  

Thats the old logo, the new logo is at the same address but swap the
last url segment from 'logo' to 'newlogo'

There still isn't a 'usage' guide for the new logo but I'll get onto one
soon hopefully.

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


Re: Link to Daily Python-URL from www.python.org?

2006-03-28 Thread Peter Otten
Tim Churches wrote:

 Am I correct in thinking that there is no longer any link from anywhere
 on the Python Web site at http;//www.python.org to the Daily Python-URL
 at http://www.pythonware.com/daily/ ? There is no sign of it on the
 Community page, nor any reference to it at http://planet.python.org/

See http://www.python.org/links/
All links provided on that page would benefit from a short description.

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


Re: Converting Time question

2006-03-28 Thread Math
Me again..
I guess I ask it wrong..
I measure a time at racing events.this tracktime is measures in the format 
hh:mm:ssDDD
where DDD = thousands of a second...like 17:14:11.769
This format is being saved as a number of micro seconds since 1970..
like 1,090516451769E+15
How do I convert from the micros seconds back to time format above?

thanks again
Hope someone can help me out..




 Hello PythonPeople..

 Can anybody help me out?
 How do I convert a time of day from milliseconds?
 For example:
 I got the following time in milliseconds: 1,090516451769E+15
 And I want to print it like: 17:14:11.769
 I'm on WinXP
 Time zone: GMT +01:00

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

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


Re: multiple assignment

2006-03-28 Thread bruno at modulix
Anand wrote:
Wouldn't it be nice to say
id, *tokens = line.split(',')


id, tokens_str = line.split(',', 1)
 
 
 But then you have to split tokens_str again.
 
 id, tokens_str = line.split(',', 1)
 tokens = tokens_str.split(',')
 
 this is too verbose.
 

head_tail = lambda seq: seq[0], seq[1:]

...
id, tokens = head_tail(line.split(','))


but I do like the syntax you're proposing !-)

-- 
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: To run a python script in all the machines from one server

2006-03-28 Thread Nick Craig-Wood
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
  I want to run a python script in all the machines that are connected
  through local network and collect the information about that machine
  such as HDD size, RAM capacity(with number of slots)  ,processer speed
  etc.
 
  But i want to run a script from just the server, so that it should
  start scripts in all other machines, and get their local machines
  information and dump the same information in some FTP.
 
  Could you please let me know how can i do this??

If these are unix machines then I would use ssh/scp.

Use scp to copy the script to /tmp then run it and collect the output
with ssh (and os.popen/subprocess)

You can set ssh/scp up with keys too.

Number of RAM slots is reasonably hard to obtain.  You might want to
investigate dmidecode for unix which queries the bios.  It gives you
stuff like this showing my machine has 4 slots, with 2x512 MB in.

Handle 0x0007, DMI type 6, 12 bytes
Memory Module Information
Socket Designation: A0
Bank Connections: 1 2
Current Speed: Unknown
Type: ECC DIMM SDRAM
Installed Size: 512 MB (Double-bank Connection)
Enabled Size: 512 MB (Double-bank Connection)
Error Status: OK

Handle 0x0008, DMI type 6, 12 bytes
Memory Module Information
Socket Designation: A1
Bank Connections: 3 4
Current Speed: Unknown
Type: Unknown
Installed Size: Not Installed
Enabled Size: Not Installed
Error Status: OK

Handle 0x0009, DMI type 6, 12 bytes
Memory Module Information
Socket Designation: A2
Bank Connections: 5 6
Current Speed: Unknown
Type: ECC DIMM SDRAM
Installed Size: 512 MB (Double-bank Connection)
Enabled Size: 512 MB (Double-bank Connection)
Error Status: OK

Handle 0x000A, DMI type 6, 12 bytes
Memory Module Information
Socket Designation: A3
Bank Connections: 7 8
Current Speed: Unknown
Type: Unknown
Installed Size: Not Installed
Enabled Size: Not Installed
Error Status: OK

-- 
Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Converting Time question

2006-03-28 Thread Sybren Stuvel
Math enlightened us with:
 How do I convert a time of day from milliseconds?

Milliseconds since what?

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: To run a python script in all the machines from one server

2006-03-28 Thread Sybren Stuvel
Nick Craig-Wood enlightened us with:
 If these are unix machines then I would use ssh/scp.

 Use scp to copy the script to /tmp then run it and collect the output
 with ssh (and os.popen/subprocess)

I'd use ssh only. Just give a 'cat  /tmp/myscript.sh' command, then
output the contents of the script, followed by CTRL+D. That also
enables you to get the output directly (by giving the result of the
script on stdout) instead of having to create an FTP server too.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Converting Time question

2006-03-28 Thread Sybren Stuvel
Math enlightened us with:
 I measure a time at racing events.this tracktime is measures in the format 
 hh:mm:ssDDD
 where DDD = thousands of a second...like 17:14:11.769
 This format is being saved as a number of micro seconds since 1970..
 like 1,090516451769E+15
 How do I convert from the micros seconds back to time format above?

Use the datetime.datetime.fromtimestamp() function, after dividing the
number of milliseconds by 1000 to create seconds.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: doctest, unittest, or if __name__='__main__'

2006-03-28 Thread Roy Smith
In article [EMAIL PROTECTED],
 Paul Rubin http://[EMAIL PROTECTED] wrote:

 [EMAIL PROTECTED] [EMAIL PROTECTED] writes:
   I have noticed some distinctly funny and confused feelings I get when
  using the unittest module, stuff that feels clunky and odd about how it
  is set-up, however I thought that this was just  due to *my personal*
  lack of understanding of the deep magic and sophisticated design
  patterns used in this module!
  
  If it turns out to be 'unpythonic' 
 
 The unpythonicness stems from it being basically a reimplementation of
 JUnit, which was designed for use with Java.

JUnit, in turn, is based on a package first implemented in SmallTalk 
(http://www.xprogramming.com/testfram.htm).

On stuff like this, I'm not opposed to things being slightly unpythonic.  
PyUnit does have some clunkyness to it, but there is some value in having 
all the unit test frameworks have a similar feel across languages.  
Unfortunately, it has become fashionable to call any sort of unit test 
framework xxxUnit, whether or not it resembles the original or not.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problems with looping, i suppose

2006-03-28 Thread Sion Arrowsmith
John Salerno  [EMAIL PROTECTED] wrote:
Does what I originally pasted in my message look incorrect? To me, it 
all seems indented properly.

Yes. Somewhere or other you've got your tabstop set to 4, and python
treats literal tabs as being of equivalent indent to 8 spaces. As
does my newsreader, so the problem was obvious:

while True:
tries += 1
^ This was a tab (my cutpaste has turned it back into spaces)
try:
^ This was a tab too.
if guess == number:
 This was eight spaces even before I cutpasted.

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

Re: New development windows, IronPython or PythonWin

2006-03-28 Thread Magnus Lycka
Dan wrote:
 Just starting to do some windows Client / Server programming. Which
 would you recommend? I need to create a server to fire events and
 communicate with clients over a lan. Thanks

There are plenty of Python solutions for this, most of them
work with Windows, but aren't locked to it.

You might want to look at one of these:
http://pyro.sourceforge.net/
http://dabodev.com/

See also
http://wiki.python.org/moin/DistributedProgramming
and
http://www.thinkware.se/cgi-bin/thinki.cgi/UsingPythonWithOtherLanguages
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Suggestion for Web App

2006-03-28 Thread Magnus Lycka
Harlin Seritt wrote:
 I want to make a recommendation to a group of internal customers where
 I work concerning a Python web framework. They are seeking to build a
 portal that can handle around 5000 total users  but probably no more
 than 100-200 simultaneous users. This is supposed to serve mainly
 static content - the content will hold references, tutorials and
 examples for different technologies, a forum (similar probably to
 phpbb) and podcasts (rss and mp3 files). Also I believe it will
 definitely need a decent DB server for this.
 
 They have some other suggestions ranging from Websphere/JSP's to PHP. I
 personally don't think the PHP will scale well for growth and I also
 think that using Java/JSPs will be too slow for this sort of thing.

There are certainly big PHP sites (Wikipedia?) and I'm not sure
Python is faster than Java/JSP (given enough memory on the server).
I'd use Python too, but that's more due to maintainablility and
rapid development than performance.

 I normally work as system and application admin and use Python in a
 number of ways to get the job done. Naturally, I am naturally inclined
 to suggest something that uses Python or something Pythonic. I wanted
 to suggest Zope but there are also other ones I'm thinking of as well
 like CherryPy and Karrigell. Which one of these (or other ones you guys
 know of) would do the best job in this situation?

I never felt Zope was very pythonic... You certainly get a lot out
of the box with Zope, but there seems to be a big learning curve as
soon as you go beyond the most obvious things. Knowing Python won't
mean that you feel at home in Zope. Zope 3 seems to improve things,
but almost all existing Zope products today are Zope 2 thingies, so
it seems a year early or so to jump onto the Zope 3 train if you don't
want a lot of work.

It seems the popular tool kits these days are Django and Turbo Gears.
I have heard a lot of good things about both. I think both have video
tutorials and other introduction docs that are easy to digest.

 Also do you guys know if MySQL would work with this or should they use
 something more robust like DB2 (IBM shop)?

Typically, I warn people about MySQL, since it's not very mature in
the role as a full RDBMS, but it's been very successful for use as
container for web site content. This role, with lots of simple reads,
no complex transactions and relatively few updates is just where
MySQL shines. Don't use it for mission critical OLTP applications
such as booking or accounting systems though. I think MySQL is robust.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: embed notepad into a frame widget

2006-03-28 Thread Diez B. Roggisch
Matt wrote:

 all,
 
 trying to load an application (notepad for instance) and have it sit
 inside a Python application window. When the main window maximises or
 minimises, the (notepad) app follows.
 
 I am pretty sure I need to use a frame widget under tkinter (win32) but
 not exactly sure how to do it.

You are pretty wrong being sure :) Under windows, it is indeed possible to
embed certain applications into others - the related technical term is
conveniently called OLE (Object lining and embedding). 

But the application has to be prepared for doing so - and this is deep
windows stuff, so I guess you can't do that with Tkinter. 

Another technique is to use so-called activex-controls. The IEfor instance
is available as such a control. But that also isn't doable with Tkinter
(AFAIK, I'm not totally sure on that). But wxPython can:

http://www.wxpython.org/MigrationGuide.html

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


Re: Difference between 'is' and '=='

2006-03-28 Thread Peter Hansen
Joel Hedlund wrote:
This does *not* also mean constants and such:
 
 snip
 
 a = 123456789
 a == 123456789
True
 a is 123456789
False
 
 I didn't mean that kind of constant. I meant named constants with defined 
 meaning, as in the example that I cooked up in my post. More examples: 
 os.R_OK, 
 or more complex ones like mymodule.DEFAULT_CONNECTION_CLASS.

If it weren't for the current CPython optimization (caching small 
integers) this code which it appears you would support writing, would fail:

   if (flags  os.R_OK) is os.R_OK:
   # do something

while this, on the other hand, is not buggy, because it correctly uses 
equality comparison when identity comparison is not called for:

   if (flags  os.R_OK) == os.R_OK:
   # do something

(I think you should give it up... you're trying to push a rope.)

-Peter

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


Re: What's the best way to learn perl for a python programmer?

2006-03-28 Thread Magnus Lycka
vj wrote:
 I've been given a project which requires writing scripts that need to
 be run on over 3000 servers. Only about 15% of them have python
 installed on them. While all/most of them will have perl.
 
 I'll try and do as much as possible in pexpect but am sure I'll have do
 some significant perl. Any suggestions on what is the best way to get
 upto speed on perl?

The thing that really bit me when I tried to go back to Perl after
years with Python was dereferencing. Completely obvious things in
Python, such as extracting an element from a list inside a dict in
another list felt like black magic. I actually gave up, but later I
realized that there is an entire chapter in Programming Perl about
the stumbling blocks with dereferencing in Perl.

I don't think people in this group :) will disagree if I claim that
Python software is much more maintainable and easier to develop and
debug than Perl scripts. That's probably relevant if they are to
run on thousands of servers.

I'd make a real effort to investigate if it's possible to either
install Python on all boxes or use something like cx_Freeze to make
executables out of the scripts.
-- 
http://mail.python.org/mailman/listinfo/python-list


in-place string reversal

2006-03-28 Thread Sathyaish
How would you reverse a string in place in python? I am seeing that
there are a lot of operations around higher level data structures and
less emphasis on primitive data. I am a little lost and can't find my
way through seeing a rev() or a reverse() or a strRev() function around
a string object.

I could traverse from end-to-beginning by using extra memory:

strText = foo
strTemp = 
for chr in strText:
   strTemp = chr + strTemp


but how would I do it in place?


Forget it! I got the answer to my own question. Strings are immutable,
*even* in python. Why not! The python compiler is written in C, right?
It is amazing how just writing down your problem can give you a
solution.


PS: Or, if my assumption that strings are immutable and an in-place
reversal is possible, is wrong, please correct me.

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


Re: How to inplement Session in CGI

2006-03-28 Thread Peter Hansen
Sullivan WxPyQtKinter wrote:
 Python disappointly failed to provide a convinient cgi session
 management module. Not willing to use external modules, I would like to
 implement a simplest Session object on my own.
 
 The basic problem is: how could a python CGI program understand several
 requests are in the same session? Definately, request from different IP
 would be easy to identified to be in different sessions, but request
 from the same IP would not. 
 
 Anyone has any idea?

Maybe you could get over your irrational fear of external modules just 
long enough to download one or two and examine them, to learn how they 
do it.  Then you could answer your own question...

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


Re: in-place string reversal

2006-03-28 Thread Sathyaish
And that the extra-memory operation I've given above is expensive, I
believe. Is there an efficient way to do it?

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


String split

2006-03-28 Thread Michele Petrazzo
Hello ng,
I don't understand why split (string split) doesn't work with the same
method if I can't pass values or if I pass a whitespace value:

 .split()
[]
 .split( )
['']

But into the doc I see:
 If sep is not specified or is None, any whitespace string is a
separator.


In this two cases, split would to return the _same_ result?

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


Re: Nevow LivePage tutorial

2006-03-28 Thread Jean-Paul Calderone
On 27 Mar 2006 23:00:56 -0800, Mir Nazim [EMAIL PROTECTED] wrote:
I really appriciate the help a lot, the but the problems is that i have
already real those. What i was looking for was some kind of detailed
tutorial, that explains the basic ideas about live page and
formhandling etc.
(my be it the time some nevow know guy got onto it)


You might want to ask on the twisted web mailing list, then.

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

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


Re: in-place string reversal

2006-03-28 Thread Sybren Stuvel
Sathyaish enlightened us with:
 How would you reverse a string in place in python?

You wouldn't, since strings are immutable.

 Forget it! I got the answer to my own question. Strings are
 immutable, *even* in python.

Indeed :)

 Why not! The python compiler is written in C, right?

Yup. But what's got that to do with it? Strings are very mutable in C.

 It is amazing how just writing down your problem can give you a
 solution.

:)

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Quick Question regarding Frames

2006-03-28 Thread Chris S
Hello All,
Just starting out with Python and wxPython.  I have two Frames, FrameA
and FrameB.  FrameA opens FrameB when a button on FrameA is clicked.  I
can get this.  Now I want a button on FrameB to update a control on
FrameA.  I am having an issue with this.  Can anyone point me in the
right direction?

Thanks.

Chris

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


Re: in-place string reversal

2006-03-28 Thread Jean-Paul Calderone
On 28 Mar 2006 06:08:51 -0800, Sathyaish [EMAIL PROTECTED] wrote:
How would you reverse a string in place in python? I am seeing that
there are a lot of operations around higher level data structures and
less emphasis on primitive data. I am a little lost and can't find my
way through seeing a rev() or a reverse() or a strRev() function around
a string object.

I could traverse from end-to-beginning by using extra memory:

strText = foo
strTemp = 
for chr in strText:
   strTemp = chr + strTemp


This is much slower than strText[::-1] (or any other squence), but which also 
isn't in-place.

In-place operations on strings aren't support.  You may want to consider a 
different datatype if this is important.  For example, an array of characters.

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


1.090516455488E9 / 1000000.000 ???

2006-03-28 Thread Math
Hello,

I got a simple and probably stupid newby question..
When I compute: 
1.090516455488E9 / 100
the result is 1090516455.49
Should be 1090516455.488

I know something with float and //...

Anybody?
How do I get correct number?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: in-place string reversal

2006-03-28 Thread Martin P. Hellwig
Sathyaish wrote:
 And that the extra-memory operation I've given above is expensive, I
 believe. Is there an efficient way to do it?
 
If i recall correctly a string is an immutable list.
I would do it this way:
  strTXT = foo
  strREV = strTXT[::-1]
  strREV
'oof'

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


Re: in-place string reversal

2006-03-28 Thread Sathyaish
But what's got that to do with it? Strings are very mutable in C.

I realized after posting that I'd said something incorrect again. The
concept of mutability itself is a high-level concept compared to C.
Memory allocation for strings is expensive because of the way malloc()
works to find a best-fit against a first-fit in traditional memory
management systems. Because of the performance hit, high level
languages and frameworks, such as the Common Type System of the .NET
Framework for example, considers strings as immutable. That, unlike
Python, doesn't however, make them impossible to modify in-place.

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


Re: 1.090516455488E9 / 1000000.000 ???

2006-03-28 Thread Math
Should be 1.090516455488E15

- Original Message - 
From: Math [EMAIL PROTECTED]
To: python-list@python.org
Sent: Tuesday, March 28, 2006 4:29 PM
Subject: 1.090516455488E9 / 100.000 ???


 Hello,
 
 I got a simple and probably stupid newby question..
 When I compute: 
 1.090516455488E9 / 100
 the result is 1090516455.49
 Should be 1090516455.488
 
 I know something with float and //...
 
 Anybody?
 How do I get correct number?
 -- 
 http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Converting Time question

2006-03-28 Thread Nick Craig-Wood
Math [EMAIL PROTECTED] wrote:
  I measure a time at racing events.this tracktime is measures in the format 
  hh:mm:ssDDD
  where DDD = thousands of a second...like 17:14:11.769
  This format is being saved as a number of micro seconds since 1970..
  like 1,090516451769E+15
  How do I convert from the micros seconds back to time format above?

This is probably what you want

 import datetime 
 t=datetime.datetime.fromtimestamp(1.090516451769E+15/1E6)
 t 
datetime.datetime(2004, 7, 22, 18, 14, 11, 769000)
 t.isoformat()
'2004-07-22T18:14:11.769000'
 t.isoformat(' ').split()[1]
'18:14:11.769000'

Note that this converts using the PCs time zone (hence it says 18:14
not 17:14).  You can pass your own timezone in (but it isn't easy!),
or you can use utcfromtimestamp()

 datetime.datetime.utcfromtimestamp(1.090516451769E+15/1E6).isoformat()[-15:]
'17:14:11.769000'

-- 
Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 1.090516455488E9 / 1000000.000 ???

2006-03-28 Thread [EMAIL PROTECTED]
 1.090516455488E9 / 100
1090.516455488

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


Re: Quick Question regarding Frames

2006-03-28 Thread Chris S
A little further clarification.  FrameA and FrameB are in different
modules. 

Thanks.

Chris

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


Threads and sys.excepthook

2006-03-28 Thread Jesus Rivero - (Neurogeek)
Hello guys,

   I have this problem and i don't know any workarounds yet. Im
implementing a DB Connection pool, which initially creates 20
connections and keep them in a dictionary. It also implements a method
for allowing external method/classes to get a connection from that pool.
he main issue is that, from a testing app, I create a loop like this to
test the pool:

import thread
import sys
import seen #this is my module

DB = seen.DBManager()

def test(name):
   try :
  idc,conn = DB.get_conn()
  print Thread: ,name, -- ,DB, ID: ,idc

   except :
  print sys.exc_info()[0]
  print sys.exc_info()[1]
  print ERROR IN HERE
   return

for i in xrange(20) :
   try:
  name = 'THREAD' + str(i)except:
  thread.start_new(test, (name,)) #(1)
   except:
  print 'An Exception Ocurred'
  print sys.exc_info()[0]
  print sys.exc_info()[1]

 
But when i run this code, The code works fine the first 5 times. the
rest, all i get is this:

SIZE:  20
Thread:  THREAD0  --  seen.DBManager object at 0x403ca7ec  ID:  0
SIZE:  19
Unhandled exception in thread started by
Error in sys.excepthook:

Original exception was:
Unhandled exception in thread started by
Error in sys.excepthook:

Original exception was:
Unhandled exception in thread started by
Error in sys.excepthook:

Original exception was:
Unhandled exception in thread started by
Error in sys.excepthook:

Original exception was:

And if put a time.sleep(1) after the   thread.start_new(test,
(name,)) #(1) part, then it does it all perfectly.

I dont know what is causing the problem, maybe the threads are spawning
too fast? OS issues?? python issues??

Im running Gentoo GNU/Linux and Python2.4

Thanks in advance,

Jesús Rivero - (Neurogeek)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 1.090516455488E9 / 1000000.000 ???

2006-03-28 Thread Georg Brandl
Math wrote:
 Hello,
 
 I got a simple and probably stupid newby question..
 When I compute: 
 1.090516455488E9 / 100
 the result is 1090516455.49
 Should be 1090516455.488
 
 I know something with float and //...
 
 Anybody?
 How do I get correct number?

Python 2.4.2 (#1, Mar 12 2006, 00:14:41)
[GCC 3.4.5 (Gentoo 3.4.5-r1, ssp-3.4.5-1.0, pie-8.7.9)] on linux2
Type help, copyright, credits or license for more information.
 1.090516455488E15 / 100
1090516455.487
 print 1.090516455488E15 / 100
1090516455.49

print is using str() which formats the float number with 12 digits
precision and therefore rounds the result.
repr() however, which is used by the interpreter when printing
out expression results, uses 17 digits precision which is why
you can see how the result is stored in the computer's memory
(1090516455.487).

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


Re: 1.090516455488E9 / 1000000.000 ???

2006-03-28 Thread Fredrik Lundh
Math wrote:

 I got a simple and probably stupid newby question..
 When I compute:
 1.090516455488E9 / 100
 the result is 1090516455.49
 Should be 1090516455.488

assuming you meant ~1090, it is:

 1.090516455488E9 / 100
1090.516455488

unless you round it off to 12 significant digits, which is
what str() does:

 str(1.090516455488E9 / 100)
'1090.51645549'

on the other hand, if you meant E15 instead, you get
another problem:

 1.090516455488E15 / 100
1090516455.487 # oops!

 str(1.090516455488E15 / 100)
'1090516455.49'

the reason is of course that floating point are stored as a limited
number of base 2-digits internally.  what you get when you con-
vert that back to decimal depends on the resulting number itself,
not on the number of significant digits you used on the original
expression.

for more on this topic, see

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

and consider using

http://www.python.org/doc/lib/module-decimal.html

instead.

 I know something with float and //...

if you know how floats work, how come you're surprised by
rounding issues ?

/F



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


Re: String split

2006-03-28 Thread Peter Otten
Michele Petrazzo wrote:

 Hello ng,
 I don't understand why split (string split) doesn't work with the same
 method if I can't pass values or if I pass a whitespace value:
 
 .split()
 []
 .split( )
 ['']
 
 But into the doc I see:
  If sep is not specified or is None, any whitespace string is a
 separator.
 

The documentation for Python 2.4 has a better explanation.


split([sep [,maxsplit]])

Return a list of the words in the string, using sep as the delimiter string.
If maxsplit is given, at most maxsplit splits are done. (thus, the list
will have at most maxsplit+1 elements). If maxsplit is not specified, then
there is no limit on the number of splits (all possible splits are made).
Consecutive delimiters are not grouped together and are deemed to delimit
empty strings (for example, '1,,2'.split(',')returns ['1', '', '2']).
The sep argument may consist of multiple characters (for example, '1, 2,
3'.split(', ') returns ['1', '2', '3']). Splitting an empty string with
a specified separator returns ['']. 

If sep is not specified or is None, a different splitting algorithm is
applied. First, whitespace characters (spaces, tabs, newlines, returns, and
formfeeds) are stripped from both ends. Then, words are separated by
arbitrary length strings of whitespace characters. Consecutive whitespace
delimiters are treated as a single delimiter ('1 2 3'.split() returns
['1', '2', '3']). Splitting an empty string or a string consisting of
just whitespace returns an empty list. 

Quoted after http://docs.python.org/lib/string-methods.html#l2h-202.

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


Re: in-place string reversal

2006-03-28 Thread Sion Arrowsmith
Sathyaish [EMAIL PROTECTED] wrote:
How would you reverse a string in place in python?
 [ ... ]
Forget it! I got the answer to my own question. Strings are immutable,
*even* in python.

I'm not sure what that *even* is about, but glad that You can't,
strings are immutable is a satisfactory answer. Rather than writing
your own reversing code, you might like to look at:

 .join(reversed(foo))

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

Problem with httplib and HEAD request

2006-03-28 Thread Mitch . Garnaat
Hi -

I'm writing some Python code to interact with Amazon's S3 service.  One
feature of S3 is that it will allow you to use the HTTP HEAD request to
retrieve metadata about an S3 object without actually retrieving the
content of the object.  In trying to use this feature, I'm running into
what I think is a bug in httplib.py.

If the resource I perform the HEAD request on exists within S3 then
everything is fine.  If, however, the resource doesn't exist then a 404
is returned.  If the request had been a GET rather than a HEAD the body
of the response would be some XML that gave further information about
the error status returned.  However, for a HEAD request no body can be
returned so the body is empty.  The error response, for either HEAD or
GET, does include the following header:

transfer-encoding: chunked

And this seems to be causing confusion in httplib.py.  I have to call
the read method of the response or else I get a ResponseNotReady
exception on my next request.  When I attempt to read the body of the
error response to the HEAD request it is passed onto the _read_chunked
method where it immediately tries to do a readline() on the connection
which, of course, hangs because no body has been sent in the response.

So, I know this is kind of a boundary condition and perhaps it hasn't
come up before but it seems that the behavior of httplib is incorrect.
I think something needs to be added to the _read_chunked method which
checks if the request is a GET and, if so, just reads zero bytes from
the socket and returns.

Any comments?  Thanks,

Mitch

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


Re: in-place string reversal

2006-03-28 Thread Yu-Xi Lim
Sathyaish wrote:
 But what's got that to do with it? Strings are very mutable in C.
 
 I realized after posting that I'd said something incorrect again. The
 concept of mutability itself is a high-level concept compared to C.
 Memory allocation for strings is expensive because of the way malloc()
 works to find a best-fit against a first-fit in traditional memory
 management systems. Because of the performance hit, high level
 languages and frameworks, such as the Common Type System of the .NET
 Framework for example, considers strings as immutable. That, unlike
 Python, doesn't however, make them impossible to modify in-place.
 

I believe part of the reason for their immutability is so that they can 
be used as dictionary keys, which is a very common use.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: To run a python script in all the machines from one server

2006-03-28 Thread Yu-Xi Lim
Nick Craig-Wood wrote:

 If these are unix machines then I would use ssh/scp.

Even if they are Windows PCs, you could just install cygwin, openssh, 
and python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: String split

2006-03-28 Thread Fredrik Lundh
Michele Petrazzo wrote:

 I don't understand why split (string split) doesn't work with the same
 method if I can't pass values or if I pass a whitespace value:

  .split()
 []
  .split( )
 ['']

 But into the doc I see:
  If sep is not specified or is None, any whitespace string is a
 separator.
 

 In this two cases, split would to return the _same_ result?

split(None) strips the string before splitting it (on runs of whitespace,
not on individual whitespace characters).  see the library reference for
a complete description:

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

/F



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


Dr. Dobb's Python-URL! - weekly Python news and links (Mar 27)

2006-03-28 Thread Peter Otten
QOTW: Testing real examples in doctstrings, or external documentation like
tutorials, is important because it's very frustrating for people reading
the docs if the examples don't work as advertised. - Marc Rintsch

If you don't document what the sundry variables are FOR, you're really
not documenting your code at all -- just listing the names of some
attributes is far too weak. - Alex Martelli


If unittest is the standard way to write testing code, why do we
still have doctest? Because serious testers use both.

http://groups.google.com/group/comp.lang.python/browse_frm/thread/b49d428f5c47f728/9f2348ceaf88d5a5?tvc=1

Coincidentally, Terry Hancock dedicates a large portion of his
report from PyCON 2006 to the power and simplicity of doctest.
http://blog.freesoftwaremagazine.com/users/t.hancock/2006/03/18/title_3

Do you have any recipes that you find indispensable in your daily
work but that are not obvious to a beginner? Contribute them to
Aahz' collection.

http://groups.google.com/group/comp.lang.python/browse_frm/thread/8b752d91a7b83140/3dee683b0daa700b?tvc=1

When using eval() is too dangerous you may still be able to
facilitate Python's parsing infrastructure as Michael Spencer shows:

http://groups.google.com/group/comp.lang.python/browse_frm/thread/789f2c8f7196e6e5/5c7a4f8438ec948c?tvc=1

Want to squeeze your precious unicode data into ASCII strings?
FLundh's solution builds on character decomposition and
unicode.translate()'s ability to replace one character with many.
http://groups.google.com/group/comp.lang.python/msg/77196f64a90ea9bc

Andrew Dalke explores the performance implications of various
approaches to class instantiation and has collected a few quotes
on the __slots__ feature.

http://www.dalkescientific.com/writings/diary/archive/2006/03/19/class_instantiation_performance.html

Andrew Clover has derived nice Windows Icons from the new Python logo.
http://groups.google.com/group/comp.lang.python/msg/0ad44c95e81b93cb

The mythical Python 3000 is mythical no more as you can watch it
evolve on its own mailing list. Rumour has it that there is also
a branch in subversion, only slighly obfuscated by its name.
http://mail.python.org/pipermail/python-3000/2006-March/thread.html



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

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

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

For far, FAR more Python reading than any one mind should
absorb, much of it quite interesting, several pages index
much of the universe of Pybloggers.
http://lowlife.jp/cgi-bin/moin.cgi/PythonProgrammersWeblog
http://www.planetpython.org/
http://mechanicalcat.net/pyblagg.html

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

http://groups.google.com/groups?oi=djqas_ugroup=comp.lang.python.announce

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

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

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

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

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

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

Kurt B. Kaiser publishes a weekly report on 

Re: Plone or TurboGears for Intranet

2006-03-28 Thread Yu-Xi Lim
[EMAIL PROTECTED] wrote:
 Hi all,
 
 Just wondering which technology would best suit the development of
 custom intranets in general, things that may be industry specific would
 need to be included (say for an industrial design company the addition
 of internal memos and even extrememly business specific apps such as
 simple inventory control reporting). The other big issue is ease of
 templating as the only Plone examples I've seen have seemed to
 basically use the original template or a slightly customised version of
 it so I'm wondering whether it would be quicker to build it from the
 ground up with TurboGears.
 
 Any thoughts on the matter are greatly appreciated and any examples of
 EITHER used extensively in case studies or the like would be fantastic!
 
 Thanks in advance!
 

For custom applications, you'd be better off looking at Plone's 
underlying Zope app server. As an alternative to TG, you may want to 
consider Django.

Memos and non-database apps would probably be okay with just Plone. In 
fact, for memos, design notes, developer documentation, you'd be best 
off considering a collaborative editing solution such as Wiki (of which 
there are numerous variants in any programming language you want).

Though some may suggest a single system to fit all needs, unless you 
require tight integration (e.g. memos reflect real-time inventory 
information), you'd probably do well deploying them as separate best of 
breed applications. You can customize the UI to make the differences 
less apparent.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What's the best way to learn perl for a python programmer?

2006-03-28 Thread Sion Arrowsmith
Magnus Lycka  [EMAIL PROTECTED] wrote:
The thing that really bit me when I tried to go back to Perl after
years with Python was dereferencing. Completely obvious things in
Python, such as extracting an element from a list inside a dict in
another list felt like black magic.

Not that long ago I had to make some enhancements to someone else's
Perl script which was handling that kind of data structure. I
stared and stared at a particularly long and messy dereference, and
eventually figured out what it was doing. I then wrote what the
equivalent Python would have been. Even forgiving the Perl's initial
my, thanks to the line noise characters the Python was over 10%
shorter, as well as more readable. So much for the myth of verbosity.

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

Looking for a language/framework

2006-03-28 Thread walterbyrd
Way back when, I got a lot of training and experience in highly
structued software development.  These days, I dabble with
web-development, but I may become more serious.

I consider php to be an abombination, the backward compatibility issues
alone are reason enough to make me hate it. Rail looks promising, but
it's difficult to find inexpensive hosting that supports rails.

I like python much better, but I'm not certain it's as well suited for
web developement. I'm not sure how th e apache module thing works. I am
using shared hosting, they provide python, but I'm not sure how limited
I'll be.

Ideally, I would like to be able to develop a database driven web-app,
in much the same manner as I could develop an ms-access app. As much as
I dislike msft, I have to admit, an ms-access app can be put together
quickly, without any steep learning curve.

I've been looking at python web frameworks, and I'm not sure what to
think. It seems like these frameworks would allow me to do a lot of
work, with a small amount of code, but the learning curve seems very
steep.

I wouldn't even mind the steep learning curves, so much, except, it
seems to me that anything developed with one framework, would not work
with another. So if I changed my mind about which framework, I'd have
to start all over again - re-learning everything, re-writing
everything. Of course, everybody says their framework is the best. But
how can I know for sure? I don't have time to try them all.

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


Re: doctest, unittest, or if __name__='__main__'

2006-03-28 Thread skip

Paul The unpythonicness stems from it being basically a
Paul reimplementation of JUnit, which was designed for use with Java.

I think there are a few modules in Python which suffer that affliction.

Skip

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


Re: To run a python script in all the machines from one server

2006-03-28 Thread skip

Yogi I want to run a python script in all the machines that are
Yogi connected through local network and collect the information about
Yogi that machine such as HDD size, RAM capacity(with number of slots)
Yogi ,processer speed etc.

Yogi But i want to run a script from just the server, so that it should
Yogi start scripts in all other machines, and get their local machines
Yogi information and dump the same information in some FTP.

Yogi Could you please let me know how can i do this??

Take a look at Nagios and plugins line nrpe.

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


Perforce p4c.run(print error - AttributeError: OutputBinary

2006-03-28 Thread kbperry
Hi all,
I am getting an error message when trying to use the P4 print command
via the python api for perforce.

Anytime that I run p4c.run(print,-q, eachFile), I keep getting an
error message: AttributeError:  OutputBinary.

Here is my code below:  Please Help.


import p4
#import perforce module
#For complete API see
http://public.perforce.com/guest/robert_cowham/perforce/API/python/index.html
p4c = p4.P4()
p4c.port = perforce.ic.ncs.com:1424
p4c.user = perrk9
p4c.parse_forms()
p4c.connect()
path = //practice/perrk9/...
localTemp = c:\perforce_temp_dir\\


first = p4c.run( counter, galloway_deploy )[0]
# here 'last_change_record' is a dictionary
last_change_record  = p4c.run( changes, -m, 1, path )[0]
print last change record
print last_change_record
last = last_change_record['change']
print last \n
print last

status_dict = { right only :add, left only :delete, content
:edit,  identical :no change  }

result = p4c.run( diff2, -q, path + @ + first , path + @ + last
)
# result is an Array, each element is a Dictionary

#Find out which files were add/edited/deleted and throw them into lists
deploy   = []  # add/edit list
undeploy = []  # delete list
for changed_file in result:
 action = status_dict[ changed_file['status'] ]
 print action
 if ((action =='add') or (action == 'edit')):
  print Changed file = 
  print changed_file['depotFile']
  deploy.append(changed_file['depotFile'])  #appending each file to our
'deploy' list
 elif action == delete:
  undeploy.append(changed_file['depotFile'])  #appending each file to
our 'undeploy' list

#print the deploy list
print deploy list
print deploy
for eachFile in deploy :
 print eachFile
 
 file = p4c.run(print,-q, eachFile)

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


Re: 1.090516455488E9 / 1000000.000 ???

2006-03-28 Thread Nick Craig-Wood
Math [EMAIL PROTECTED] wrote:
  I got a simple and probably stupid newby question..
  When I compute: 
  1.090516455488E9 / 100
  the result is 1090516455.49
  Should be 1090516455.488
 
  I know something with float and //...

http://www.python.org/doc/faq/general/#why-are-floating-point-calculations-so-inaccurate

Eg

 a=1.090516455488E9 / 100
 print a
1090.51645549
 print repr(a)
1090.516455488
 

If you want a given number of decimal places you can use a formatter,
eg

 print %.20f % a
1090.5164554881961354

-- 
Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: To run a python script in all the machines from one server

2006-03-28 Thread jao
Quoting [EMAIL PROTECTED]:


Yogi I want to run a python script in all the machines that are
Yogi connected through local network and collect the information about
Yogi that machine such as HDD size, RAM capacity(with number of slots)
Yogi ,processer speed etc.

Yogi But i want to run a script from just the server, so that it should
Yogi start scripts in all other machines, and get their local machines
Yogi information and dump the same information in some FTP.

Yogi Could you please let me know how can i do this??

 Take a look at Nagios and plugins line nrpe.

Another possibility is osh (http://geophile.com/osh). You could do something
like this:

osh @your_cluster [ f 'your_function' ] $

- your_cluster: logical name for the cluster.
- your_function: A python function you write to be run on each host.
- $: Prints information from each node as a python tuple.

You could, instead of printing with $, pipe the result to other
osh commands to further process the tuples containing information
from each host.

I wouldn't recommend this if the hosts are Windows since osh hasn't
been tested on Windows.

Jack Orenstein
(author of osh)

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


how to use ez_setup on a machine which does not have access to the internet

2006-03-28 Thread vj
I did the following:

1. Downloaded ez_setup.py
2. Downloaded the setuptools-0.6a10-py2.4.egg
3. Downloaded the pysqlite-2.0.6-py2.4-linux-i686(2).egg

Transferred all the files to the computer which is behind a firewall
(with no access to the internet).

I then did the following:

path_to_python ez_setup.py setuptools-0.6a10-py2.4.egg

it failed even though the setuptools-0.6a10-py2.4.egg was in the same
directory. It gives me an error:

urllib2.URLError: urlopen error (-2, 'Name or service not known')

I looked at the documentation and it talked about a -f flag which
allows you to specify the directory to look for the files and that did
not work either.

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


Re: in-place string reversal

2006-03-28 Thread Felipe Almeida Lessa
Em Ter, 2006-03-28 às 16:03 +0100, Sion Arrowsmith escreveu:
 Rather than writing
 your own reversing code, you might like to look at:
 
  .join(reversed(foo))

Or not:


$ python2.4
Python 2.4.2 (#2, Nov 20 2005, 17:04:48)
[GCC 4.0.3 2005 (prerelease) (Debian 4.0.2-4)] on linux2
Type help, copyright, credits or license for more information.
 .join(reversed(foo))
'oof'
 foo[::-1]
'oof'

$ python2.4 -mtimeit '.join(reversed(foo))'
10 loops, best of 3: 2.58 usec per loop

$ python2.4 -mtimeit 'foo[::-1]'
100 loops, best of 3: 0.516 usec per loop

$ calc 2.58/0.516
5


foo[::-1] is cleaner and performs 5 times better -- 'nuff said.

Cheers,

-- 
Felipe.

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

Re: Looking for a language/framework

2006-03-28 Thread Alex Martelli
walterbyrd [EMAIL PROTECTED] wrote:
   ...
 I consider php to be an abombination, the backward compatibility issues
 alone are reason enough to make me hate it. Rail looks promising, but
 it's difficult to find inexpensive hosting that supports rails.

What's your budget?  DreamHost offers Rails hosting for $7.95 per month,
which definitely falls within what I would call inexpensive, just for
example.  I'm sure you can find others in similar price ranges.

 I like python much better, but I'm not certain it's as well suited for
 web developement. I'm not sure how th e apache module thing works. I am
 using shared hosting, they provide python, but I'm not sure how limited
 I'll be.

What Python server-side frameworks does your shared hosting service
support?  Or do they only offer Python as a CGI language?

 I wouldn't even mind the steep learning curves, so much, except, it
 seems to me that anything developed with one framework, would not work
 with another. So if I changed my mind about which framework, I'd have
 to start all over again - re-learning everything, re-writing
 everything. Of course, everybody says their framework is the best. But
 how can I know for sure? I don't have time to try them all.

Nobody does, which is the main advantage of Rails -- it so dominates the
scene of web frameworks for Ruby, that nobody seriously wonders what
framework to pick for that language (there exist others, but their mind
share is close to zero).  Python frameworks may interoperate at several
levels (e.g. through the WSGI middleware layer) but that's not the same
as having a single framework.

OTOH, different frameworks may cater for different audiences: at one
extreme, the webjockey who knows and loves the underlying technologies,
from HTTP to SQL, and only wants high productivity without (what he or
she perceives as) cruft on top and definitely without any conceptual
blockage impeding access to the underlying technologies when that access
is wanted; at the other extreme, somebody who doesn't even know the
difference between SQL and HTTP, doesn't want to learn anything hard,
and just wants to point and grunt and make three websites a day -- and,
of course, anything in-between.

For example, I've never seen an object-relational mapping (technical
term for cruft that tries to avoid people having to learn and use SQL)
which doesn't drive me into a murderous, foam-at-mouth rage in a very
short time -- I *WANT* my SQL, I *LOVE* SQL, it's *WAY* more powerful
and suitable for access to data than all those simulated OO DB people
lay on top of it (of course, that does depend on having a REAL
relational DB underneath, not, say, MySQL;-).  Other people disagree
very, very deeply with my preferences (as proven by the existence of a
begazillion ORMs, including general-purpose ones as well as ones that
are part of web-application frameworks).  How is a poor web framework to
make both groups happy (me on one side, all the rest of the world on the
other;-) without becoming ridiculously complex and ungainly?


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


Re: 1.090516455488E9 / 1000000.000 ???

2006-03-28 Thread Felipe Almeida Lessa
Em Ter, 2006-03-28 às 16:59 +0200, Fredrik Lundh escreveu:
 and consider using
 
 http://www.python.org/doc/lib/module-decimal.html
 
 instead.

$ python2.4
Python 2.4.2 (#2, Nov 20 2005, 17:04:48)
[GCC 4.0.3 2005 (prerelease) (Debian 4.0.2-4)] on linux2
Type help, copyright, credits or license for more information.
 from decimal import Decimal
 a = Decimal(1.090516455488E15)
 a
Decimal(1.090516455488E+15)
 b = a / 100
 b
Decimal(1090516455.488)
 str(b)
'1090516455.488'

*But*,

$ python2.4 -mtimeit -s 'from decimal import Decimal; a =
Decimal(1.090516455488E15)' 'a/100'
1000 loops, best of 3: 222 usec per loop
$ python2.4 -mtimeit -s 'a=1.090516455488E15' 'a/100' 100 loops,
best of 3: 0.234 usec per loop
$ calc 222/0.234
~948.71794871794871794872

Decimal is almost one thousand times slower. Do you really need this
accuracy?

HTH,

-- 
Felipe.

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

Re: in-place string reversal

2006-03-28 Thread Adam DePrince
On Tue, 2006-03-28 at 06:15 -0800, Sathyaish wrote:
 And that the extra-memory operation I've given above is expensive, I
 believe. Is there an efficient way to do it?
 

How big is your string?  

For short strings (i.e. where large means you don't have enough RAM to
hold one extra copy.) 

 Abc[::-1]
'cbA'



Also, anytime you reach for a for-loop to build a string step by step,
you are making a mistake.  Consider your example. 

strText = foo
strTemp = 
for chr in strText:
   strTemp = chr + strTemp

Each loop you are copying the string again, the timing behavior of your
function is O(n^2).  

If you are really concerned about memory allocation, well, I don't know
if you realize this, but every time you call

strTemp = chr + strTemp 

you are throwing away your old copy and building a new copy.   Ouch.

Forgive me for preaching, but you just committed the grievous act of
premature optimization.   Don't worry about that first malloc, if Python
is going to call malloc, it has a lot of opportunity to do so later.
And malloc isn't as evil as you make it out to be.

One of the advantages of using a high level language is you get to leave
the issue of how to implement the small stuff up to the language
designer and focus on the bigger picture - algorithmic appropriateness
and overall correctness.  

In my experience I've found that when under time pressure python
programs tend to out perform C because doing it right is so much easier
in the former.  

As for mutability, immutability is a big virtue and performance gain.
If I have two pointers to immutable strings, once I compare them I can
know for eternity which is larger, so long as I don't let go of my
references to them.  Thus I can use them as keys in a complicated and
efficient data structure.  If Python strings were mutable the best
implementation we could hope for dict would be a linked list.   

Also, consider some other side effects of mutable strings.


 s = Abc
 myfancy_structre.add_somehow( s )
 t = s[::-1]
 print s
Abc
 print t
cbA

Now if strings were mutable:

 s = Abc
 myfancy_structre.add_somehow( s )
 s.reverseme()
 print s
cbA

Other users of s between assignment and reversal (like
myfancy_structure) might not be happy that is was reversed when they
next must use it.  

Cheers - Adam DePrince


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


Re: 1.090516455488E9 / 1000000.000 ???

2006-03-28 Thread Adam DePrince
On Tue, 2006-03-28 at 16:29 +0200, Math wrote:
 Hello,
 
 I got a simple and probably stupid newby question..
 When I compute: 
 1.090516455488E9 / 100
 the result is 1090516455.49
 Should be 1090516455.488

 repr( 1.090516455488E9/100 )
'1090.516455488'


Works for me.  Code snippet?  Print does seem to round at 12 digits.  

 print  1.090516455488E9/100
1090.51645549



Cheers - Adam DePrince

 
 I know something with float and //...
 
 Anybody?
 How do I get correct number?

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


File objects and seek

2006-03-28 Thread Tommy Grav
I have a file object that contains a binary read in file. I would like to move to another position in the file to read in a record. seek seemsto work fine with a positive value, but not a negative one (moving back from the current relative position). Is this the intended behavior?How do I move backwards (towards the beginning) in the file? CheersTommy[EMAIL PROTECTED]http://homepage.mac.com/tgrav/"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction"                         -- Albert Einstein -- 
http://mail.python.org/mailman/listinfo/python-list

Re: freeze.py and GTK apps

2006-03-28 Thread Adam DePrince
On Mon, 2006-03-27 at 16:15 -0800, [EMAIL PROTECTED] wrote:
 After freezing a PYGTK app, I am unable to run it.  It this a common
 problem, because I could not find any documentation on it at all.
 
 I tried freezing this example, which gets by the make as well, but
 running it results in a failure.  This is on Ubuntu Linux:
 http://www.moeraki.com/pygtktutorial/pygtk2tutorial/examples/helloworld.py
 
 $ ./helloworld
 Traceback (most recent call last):
   File helloworld.py, line 7, in ?
 import gtk
   File /usr/lib/python2.4/site-packages/gtk-2.0/gtk/__init__.py, line
 37, in ?from _gtk import *
 ImportError: No module named _gtk
 
 Any suggestions?
 --
 Kristian Hermansen
 

From the freeze README

A warning about shared library modules
--

When your Python installation uses shared library modules such as
_tkinter.pyd, these will not be incorporated in the frozen program.
 Again, the frozen program will work when you test it, but it won't
 work when you ship it to a site without a Python installation.

Freeze prints a warning when this is the case at the end of the
freezing process:

Warning: unknown modules remain: ...

When this occurs, the best thing to do is usually to rebuild Python
using static linking only. Or use the approach described in the previous
section to declare a library path using sys.path, and place the modules
such as _tkinter.pyd there.

Same applies here ... 

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


Re: Looking for a language/framework

2006-03-28 Thread bruno at modulix
walterbyrd wrote:
 Way back when, I got a lot of training and experience in highly
 structued software development.  These days, I dabble with
 web-development, but I may become more serious.
 
 I consider php to be an abombination, the backward compatibility issues
 alone are reason enough to make me hate it. Rail looks promising, but
 it's difficult to find inexpensive hosting that supports rails.
 
 I like python much better, but I'm not certain it's as well suited for
 web developement. 

It is. Much more than PHP.

The problem then is: which solution/framework. And there quite a few
Python web developpment solutions...

 I'm not sure how th e apache module thing works.

It exposes most of the Apache API to Python, and provides hooks to take
control over request processing.

 I am
 using shared hosting, they provide python, but I'm not sure how limited
 I'll be.

You can bet it'll be plain old cgi - possibly with an outdated Pyton
version.

 Ideally, I would like to be able to develop a database driven web-app,
 in much the same manner as I could develop an ms-access app. As much as
 I dislike msft, I have to admit, an ms-access app can be put together
 quickly, without any steep learning curve.
 
 I've been looking at python web frameworks, and I'm not sure what to
 think. It seems like these frameworks would allow me to do a lot of
 work, with a small amount of code, but the learning curve seems very
 steep.

Which frameworks have you looked at ?

 I wouldn't even mind the steep learning curves, so much, except, it
 seems to me that anything developed with one framework, would not work
 with another. 

heck, this is true of all frameworks ever (web or not, Python or not).

 So if I changed my mind about which framework, I'd have
 to start all over again - re-learning everything, re-writing
 everything. Of course, everybody says their framework is the best. But
 how can I know for sure? 

Trying them ?

 I don't have time to try them all.

Then only try the ones that *may* fit your needs !-)


-- 
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


Seems like I want a pre-processor, but...

2006-03-28 Thread Russell Warren
After some digging it seems that python does not have any equivalent to
C's #if directives, and I don't get it...

For example, I've got a bit of python 2.3 code that uses
collections.deque.pop(0) in order to pop the leftmost item.  In python
2.4 this is no longer valid - there is no argument on pop (rightmost
only now) and you call .popleft() instead.

I would like my code to work in both versions for now and simply want
to add code like:

if sys.version[:3] == 2.3:
  return self.myDeque.pop(0)
else:
  return self.myDeque.popleft()

but am recoiling a bit at the unnecessary conditional in there that I
think will be run on every execution - unless the compiler has some
magic detection of things like sys.version to compile out the
conditional as if it were a preprocessor directive (seems highly
unlikely!)?.

What is the pythonic thing to do?  This is in a generally usable file,
not a package, so I don't want to make a version for each (which seems
to be what every package out there does).  It seems to be begging for a
pre-processor directive set.

Thanks,
Russ

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


Re: Seems like I want a pre-processor, but...

2006-03-28 Thread Fredrik Lundh
Russell Warren wrote:

 For example, I've got a bit of python 2.3 code that uses
 collections.deque.pop(0) in order to pop the leftmost item.  In python
 2.4 this is no longer valid - there is no argument on pop (rightmost
 only now) and you call .popleft() instead.

the collections module was added in 2.4, so it's not clear what code you're
really using under 2.3.  but since it's not a standard module, maybe you could
add the missing method yourself ?

 I would like my code to work in both versions for now and simply want
 to add code like:

 if sys.version[:3] == 2.3:
   return self.myDeque.pop(0)
 else:
   return self.myDeque.popleft()

 but am recoiling a bit at the unnecessary conditional in there that I
 think will be run on every execution - unless the compiler has some
 magic detection of things like sys.version to compile out the
 conditional as if it were a preprocessor directive (seems highly
 unlikely!)?.

 What is the pythonic thing to do?

fork the function/method:

if sys.version_info  (2, 4):
def myfunc(self):
# using deque emulation
return self.myDeque.pop(0)
else:
def myfunc(self):
return self.myDeque.popleft()

or wrap the non-standard deque class in a compatibility wrapper:

if sys.version_info  (2, 4):
class mydequeclass(deque):
def popleft(self):
return self.pop(0)

...

return self.myDeque.popleft()

/F



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


Re: String split

2006-03-28 Thread Michele Petrazzo
Peter Otten wrote:
 The documentation for Python 2.4 has a better explanation.
 

-cut-

 Quoted after http://docs.python.org/lib/string-methods.html#l2h-202.
 
 Peter

Thanks, I haven't see it.
Just a question about that different algorithm, because it force the
developer to do other work for make the split result more logically
compatible:

S =  # this can become from an external source like config parser

for s n S.split():
   do the work... # don't go inside

that isn't compatible, so python split it into two different methods
the string, with:

for s n S.split(','):
   do the work... # run one time into this


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


Re: in-place string reversal

2006-03-28 Thread Sion Arrowsmith
Felipe Almeida Lessa  [EMAIL PROTECTED] wrote:
Em Ter, 2006-03-28 às 16:03 +0100, Sion Arrowsmith escreveu:
  .join(reversed(foo))
$ python2.4 -mtimeit '.join(reversed(foo))'
10 loops, best of 3: 2.58 usec per loop

But note that a significant chunk is the join():

$ python2.4 -mtimeit '.join(reversed(foo))'
10 loops, best of 3: 2.72 usec per loop
$ python2.4 -mtimeit 'reversed(foo)'
100 loops, best of 3: 1.69 usec per loop

$ python2.4 -mtimeit 'foo[::-1]'
100 loops, best of 3: 0.516 usec per loop

Yeah, I forget about [::-1] due to the high profile of the introduction
of reversed(). Well, of sorted(), and reversed() coming along for the
ride. And at some point reversed() will become a win:

$ python2.4 -mtimeit 'reversed(range(200))'
10 loops, best of 3: 6.65 usec per loop
$ python2.4 -mtimeit 'range(200)[::-1]'
10 loops, best of 3: 6.88 usec per loop

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

Re: Seems like I want a pre-processor, but...

2006-03-28 Thread Kent Johnson
Russell Warren wrote:
 After some digging it seems that python does not have any equivalent to
 C's #if directives, and I don't get it...
 
 For example, I've got a bit of python 2.3 code that uses
 collections.deque.pop(0) in order to pop the leftmost item.  In python
 2.4 this is no longer valid - there is no argument on pop (rightmost
 only now) and you call .popleft() instead.
 
 I would like my code to work in both versions for now and simply want
 to add code like:
 
 if sys.version[:3] == 2.3:
   return self.myDeque.pop(0)
 else:
   return self.myDeque.popleft()

Often you can make these tests one-time by defining an appropriate 
object whose value depends on the test, then using that object instead 
of repeatedly making the test. In this case, I assume the code above is 
inside a class method. You could have the class conditionally define a 
myPopLeft() method like this (not tested):

class MyClass(object):
   ...
   if sys.version[:3] == 2.3:
 def myPopLeft(self):
   return self.myDeque.pop(0)
   else:
 def myPopLeft(self):
   return self.myDeque.popleft()

Now the class has a myPopLeft() method that does the right thing, and 
sys.version is only tested once, at class declaration time.

You might want to make the condition explicitly on the deque class, 
also, using has_attr(deque, 'popleft').

Another example is the common code used to define 'set' portably across 
Python 2.3 and 2.4:

try:
   set
except NameError:
   from sets import Set as set


In general the idea is to move the test from 'every time I need to do 
something' to 'once when some name is defined'.

Kent

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


Re: Seems like I want a pre-processor, but...

2006-03-28 Thread Peter Otten
Russell Warren wrote:

 After some digging it seems that python does not have any equivalent to
 C's #if directives, and I don't get it...
 
 For example, I've got a bit of python 2.3 code that uses
 collections.deque.pop(0) in order to pop the leftmost item.  In python
 2.4 this is no longer valid - there is no argument on pop (rightmost
 only now) and you call .popleft() instead.

collections is new in 2.4 -- I assume you mean list.pop(0) versus
collections.deque.popleft().

 I would like my code to work in both versions for now and simply want
 to add code like:
 
 if sys.version[:3] == 2.3:
   return self.myDeque.pop(0)
 else:
   return self.myDeque.popleft()
 
 but am recoiling a bit at the unnecessary conditional in there that I
 think will be run on every execution - unless the compiler has some
 magic detection of things like sys.version to compile out the
 conditional as if it were a preprocessor directive (seems highly
 unlikely!)?.
 
 What is the pythonic thing to do?  This is in a generally usable file,
 not a package, so I don't want to make a version for each (which seems
 to be what every package out there does).  It seems to be begging for a
 pre-processor directive set.

Here's how I would rewrite your example:

try:
from collections import deque
except ImportError:
class deque(list):
def popleft(self):
return self.pop(0)

# in your method:
return self.myDeque.popleft()

That way the performance impact almost vanishes for the newer python and
your code is less cluttered with if ... else statements that are only there
to pick the version specific code.

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


Re: How do clients(web browser) close a python CGI program that is not responding?

2006-03-28 Thread Sullivan WxPyQtKinter
Actually my project is converting certain specially costomized  XML
file to HTML to display and edit. Sometimes the XML file is too big, or
the client upload a very huge file for the server to process, which
exceeds the processing ability of my server.(after all, it is a small
server on my poor laptopwhich use winXP and IIS..not
professional, huh?)

I configures IIS to terminate CGI program if it do not complete in 20
sec. But it does not workPerhaps I should go to a IIS or apache
forum for answer.

Thank you.

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


Re: How to inplement Session in CGI

2006-03-28 Thread Sullivan WxPyQtKinter

bruno at modulix 写道:

 Sullivan WxPyQtKinter wrote:
  Python disappointly failed to provide a convinient cgi session
  management module.

 Probably because there are much better options for web programming in
 Python ?
 
Really? Then what is it?

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

Re: Seems like I want a pre-processor, but...

2006-03-28 Thread Russell Warren
 the collections module was added in 2.4

Ah... sorry about that.  I should have checked my example more closely.
What I'm actually doing is rebinding some Queue.Queue behaviour in a
safe location like this:

def _get(self):
  ret = self.queue.popleft()
  DoSomethingSimple()
  return ret

And self.queue.popleft() used to be self.queue.pop(0).  self.queue is a
deque object in 2.4 so I just used transferred that unluckily to the
post in a poor attempt to simplify it - I had no clue that it was new.
Should have made one up from scratch.

Anyway - it worked... you've answered my question perfectly, thanks.  I
hadn't considered that the module loading phase could basically used
for preprocessing.  You even helped by subtly providing a better
version checker... I didn't even know you could use  with a tuple like
that.  I'll have to look into the logic rules there.

Russ

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


Re: String split

2006-03-28 Thread Peter Otten
Michele Petrazzo wrote:

 Just a question about that different algorithm, because it force the
 developer to do other work for make the split result more logically
 compatible:
 
 S =  # this can become from an external source like config parser
 
 for s n S.split():
 do the work... # don't go inside
 
 that isn't compatible, so python split it into two different methods
 the string, with:
 
 for s n S.split(','):
 do the work... # run one time into this

No question.

 def split_any(s, seps):
... for sep in seps:
... parts = s.split(sep)
... if len(parts)  1:
... return parts
... raise ValueError
...
 split_any( alpha beta , [,, None])
['alpha', 'beta']
 split_any(alpha,beta, [,, None])
['alpha', 'beta']
 split_any(alpha_beta, [,, None])
Traceback (most recent call last):
  File stdin, line 1, in ?
  File stdin, line 6, in split_any
ValueError

The answer :-)

Seriously, I think you have to be a bit more explicit on what you want to
know.

Peter

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


Re: in-place string reversal

2006-03-28 Thread Fredrik Lundh
Sion Arrowsmith wrote:

 But note that a significant chunk is the join():

 $ python2.4 -mtimeit '.join(reversed(foo))'
 10 loops, best of 3: 2.72 usec per loop
 $ python2.4 -mtimeit 'reversed(foo)'
 100 loops, best of 3: 1.69 usec per loop

your second benchmark doesn't do any reversal, though.  it only
creates a bunch of reversed() iterator objects.

it's a little like my old faster-than-the-speed-of-light XML parser
benchmark:

 dir test.xml
...
2005-05-04  20:41   12 658 399 test.xml
...
 python -m timeit -s import cElementTree matches = (elem.get('value')
for event, elem in cElementTree.iterparse('test.xml') if elem.get('name')
== 'reselectApi')
1000 loops, best of 3: 198 usec per loop
 python -c print 12658399 / 198e-6
63931308080.8

(64 gigabytes per second?  who said XML was a performance hog ?)

/F



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


Re: in-place string reversal

2006-03-28 Thread olsongt

Sathyaish wrote:
 How would you reverse a string in place in python? I am seeing that
 there are a lot of operations around higher level data structures and
 less emphasis on primitive data. I am a little lost and can't find my
 way through seeing a rev() or a reverse() or a strRev() function around
 a string object.

 I could traverse from end-to-beginning by using extra memory:

 strText = foo
 strTemp = 
 for chr in strText:
strTemp = chr + strTemp


 but how would I do it in place?


 Forget it! I got the answer to my own question. Strings are immutable,
 *even* in python. Why not! The python compiler is written in C, right?
 It is amazing how just writing down your problem can give you a
 solution.


 PS: Or, if my assumption that strings are immutable and an in-place
 reversal is possible, is wrong, please correct me.

If you are using strings that are long enough where you're going to run
into memory issues, you can create a character array from the array
module.  This will basically create a mutable string.

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


Re: win32com: error 80004005

2006-03-28 Thread ago
I solved it. If someone else is in the same situation...

It was due to a defective installation. I reinstalled python and pywin,
re-registered the server and everything worked well.

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


Re: Seems like I want a pre-processor, but...

2006-03-28 Thread Russell Warren
Thanks guys - all great responses that answered my question in a few
different ways with the addition of some other useful tidbits!

This is a nice summary:
 In general the idea is to move the test from 'every time I need to do
 something' to 'once when some name is defined'.

Gotta love the response time of this newsgroup...

Russ

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


Re: Threads and sys.excepthook

2006-03-28 Thread Jonathan Ellis
Jesus Rivero - (Neurogeek) wrote:
 Original exception was:
 Unhandled exception in thread started by
 Error in sys.excepthook:

 Original exception was:

 And if put a time.sleep(1) after the   thread.start_new(test,
 (name,)) #(1) part, then it does it all perfectly.

Looks like the interpreter is shutting down before all the exception
processing finishes.

-Jonathan

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


Re: How to inplement Session in CGI

2006-03-28 Thread bruno at modulix
Sullivan WxPyQtKinter wrote:
 bruno at modulix 写道:
 
 
Sullivan WxPyQtKinter wrote:

Python disappointly failed to provide a convinient cgi session
management module.

Probably because there are much better options for web programming in
Python ?

 
 Really? Then what is it?

Please notice the 's' at the end of 'options'. For a quick and
incomplete overview, you can start here:

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


-- 
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

values turning into object instances

2006-03-28 Thread Clayton Hablinski








I am trying to convert a tuple into a list using the list
function. Before I do this I have this:



print CurSht.Range(A2:A63)

((45666.0,), (45777.0,), (45888.0,), (None,), (None,),
(None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,),
(None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,),
(None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,),
(None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,),
(None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,),
(None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,),
(None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,),
(None,))



Then I get this:



print list(CurSht.Range(A2:A63))

[win32com.gen_py.Microsoft Excel 11.0 Object
Library.Range instance at 0x16031176, win32com.gen_py.Microsoft Excel
11.0 Object Library.Range instance at 0x16031216,
win32com.gen_py.Microsoft Excel 11.0 Object Library.Range instance at
0x16031256]



(It has many more instances than this. I shortened it in
order to make this less lengthy)



Not sure why the values turn into these instances that dont
have the attributes I need. Any help for this noob would be much appreciated.



Thanks,



Clayton






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

Re: in-place string reversal

2006-03-28 Thread Felipe Almeida Lessa
Em Ter, 2006-03-28 às 17:32 +0100, Sion Arrowsmith escreveu:
 ride. And at some point reversed() will become a win:
 
 $ python2.4 -mtimeit 'reversed(range(200))'
 10 loops, best of 3: 6.65 usec per loop
 $ python2.4 -mtimeit 'range(200)[::-1]'
 10 loops, best of 3: 6.88 usec per loop

Not fair:

$ python2.4
Python 2.4.2 (#2, Nov 20 2005, 17:04:48)
[GCC 4.0.3 2005 (prerelease) (Debian 4.0.2-4)] on linux2
Type help, copyright, credits or license for more information.
 range(200)[::-1]
[199, 198, ..., 1, 0]
 reversed(range(200))
listreverseiterator object at 0xb7d1224c
 list(reversed(range(200)))
[199, 198, ..., 1, 0]
 list(reversed(range(200))) == range(200)[::-1]
True
^D

Now we're in a fair competition:
$ python2.4 -mtimeit -s 'a=range(200)' 'a[::-1]'
10 loops, best of 3: 2.23 usec per loop
$ python2.4 -mtimeit -s 'a=range(200)' 'list(reversed(a))'
10 loops, best of 3: 5.62 usec per loop
$ calc 5.62/2.23
~2.52017937219730941704
$ python2.4 -mtimeit -s 'a=range(20)' 'a[::-1]'
100 loops, best of 3: 10.7 msec per loop
$ python2.4 -mtimeit -s 'a=range(20)' 'list(reversed(a))'
100 loops, best of 3: 11.5 msec per loop
$ calc 11.5/10.7
~1.07476635514018691589

But:
$ python2.4 -mtimeit 'range(199, -1, -1)'
10 loops, best of 3: 4.8 usec per loop
$ python2.4 -mtimeit 'range(200)[::-1]'
10 loops, best of 3: 7.05 usec per loop
$ calc 7.05/4.8
1.46875
$ python2.4 -mtimeit 'range(19, -1, -1)'
100 loops, best of 3: 13.7 msec per loop
$ python2.4 -mtimeit 'range(20)[::-1]'
10 loops, best of 3: 24 msec per loop
$ calc 24/13.7
~1.75182481751824817518

And worse:
$ python2.4 -mtimeit 'list(reversed(range(200)))'
10 loops, best of 3: 10.5 usec per loop
$ calc 10.5/4.8
2.1875
$ python2.4 -mtimeit 'list(reversed(range(20)))'
10 loops, best of 3: 24.5 msec per loop
$ calc 24.5/13.7
~1.78832116788321167883


HTH,

-- 
Felipe.

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

Re: Obtaining the remote ip address

2006-03-28 Thread EP
While on the subject of network identity, does anyone have a scheme to 
get the MAC address of the end device?  I've never come up with a way to 
do it, but I haven't had it proven to me that it is impossible (yet).


Justin Ezequiel wrote:

os.environ['REMOTE_ADDR']
os.environ['REMOTE_HOST']

  

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


Re: CGI redirection: let us discuss it further

2006-03-28 Thread and-google
Sullivan WxPyQtKinter wrote:

 1. Are there any method (in python of course) to redirect to a web page
 without causing a Back button trap... rather than the redirection page
 with a Location: url head

What's wrong with the redirection page?

If there's really a necessary reason for not using an HTTP redirect
(for example, needing to set a cookie, which doesn't work cross-browser
on redirects), the best bet is a page containing a plain link and
script-redirect, using location.replace() to avoid the back button
trap.

 2. Are there any method to use relative path, rather than full absolute
 URI path in Location: url? It is very essential for later transplant
 work, e.g.,transplant a folder of cgi scripts from one web server to
 another, with different URL.

Just read the name of the server (os.environ['SERVER_NAME']) to work
out what absolute URL to redirect to, whist still being portable.

Here's some code I dug up that should also cope with non-default ports
and SSL, if that's of any use:

  ssl= os.environ.get('HTTPS', 'off') not in ('', 'off', 'false', 'no')
  scheme= ['http', 'https'][ssl]
  port= ['80', '443'][ssl]
  host= os.environ.get('SERVER_NAME', 'localhost')
  url= '%s://%s:%s' % (scheme, host, os.environ.get('SERVER_PORT',
port))
  if url.endswith(':'+port):
server= server[:-(len(port)+1)]
  url+= path

(You *can* pass relative URLs back to the web server in a Location:
header, but this should do an internal redirect inside the server,
which may not be what you want.)

-- 
And Clover
mailto:[EMAIL PROTECTED]
http://www.doxdesk.com/

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


  1   2   3   >