Re: Python is not a good name, should rename to Athon

2007-12-05 Thread Hendrik van Rooyen
Gabriel Genellina [EMAIL PROTECTED] wrote:

En Tue, 04 Dec 2007 14:49:36 -0300, Dennis Lee Bieber
[EMAIL PROTECTED] escribió:

 How about the cognate: Kulkukan?

You meant Kukulkan. If you got it wrong from Apocalypto (Mel Gibson),
well, it's just one of many errors in the film...

Either way its no good - sounds too much like Kalkul

- Hendrik


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


Re: Python is not a good name, should rename to Athon

2007-12-05 Thread Hendrik van Rooyen
Dennis Lee Bieber [EMAIL PROTECTED] wrote:

 Euler? (most non-tech types would probably think that's a reference
 to someone who squirts lubricants into the workings of a steam engine)

You have just destroyed a long held image in my mind with this 
horrible homophone - I used to conjure up images of a wise owl.

- Hendrik

-- 
For the linguistically challenged: Eule is German for Owl

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


Why did no one tell me about import antigravity?

2007-12-05 Thread Ant
Python on xkcd:

http://xkcd.com/353/

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


Re: Getting wxPython to work on a Mac

2007-12-05 Thread cmpython
On Dec 4, 9:35 pm, Timothy Smith [EMAIL PROTECTED] wrote:
 Not sure exactly what I need to do to get wxPython to work on either of
 my Macs. (One's a notebook running Tiger (OS X 10.4.11), the other a Mac
 Pro running Leopard (10.5.1.))

 I downloaded what should be the latest binary, and it installed without
 error. So Python comes up as

 $ python -V
 Python 2.5.1
 $ ls -l /usr/bin/python
 lrwxr-xr-x  1 root  wheel  72 Oct 26 17:59 /usr/bin/python@ -
 ../../System/Library/Frameworks/Python.framework/Versions/2.5/bin/python
 $

 I set PYTHONPATH to
 System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5

 The Python interpreter works OK, far as I can tell. wx sort of works,
 but all the functionality is not there. For example, working through the
 exercises in WxPython in Action by Noel Rappin, I find that while I
 can create and display a frame, and create an app, stuff like
 wx.MessageBox() just doesn't work.

 The same exercises work just fine on a Python 2.5.1 installation on my
 wife's Windows XP machine.

 Any help appreciated. (I am obviously both a Python and a Wx beginner.
 And not much of a Unix expert either. :-)

If you don't get an answer here, you should try the wxPython mailing
list:
http://www.wxpython.org/maillist.php
I'm sure they'll be able to help you out (I don't have a Mac, so I
don't know).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Timezones in python

2007-12-05 Thread Matt Nordhoff
[EMAIL PROTECTED] wrote:
 Is there any build in solution in python to handle timezones? My
 problem is I have to convert +4 time to +0. In the worst case i can
 just add +4 to the houer but I'm not very happy about that. Another
 problem is the summer/winter timechange which happen with one week
 difference. I am looking for something what can convert different
 timezone to localtime.

There's the pytz library [1] [2], which uses the tz database popular on
Unix systems, and python-dateutil [3] [4] also includes support for it,
among doing other date- and time-related things.

Those support time zone names (America/New_York or EST5EDT), and also
converting between them. If you only want to convert between +4 and +0,
without giving names for them, you don't need them, but I don't know how
to do it. Using UTC internally and only converting to other zones when
reading data in and displaying it makes things simpler . .

[1] http://pytz.sourceforge.net/
[2] http://pypi.python.org/pypi/pytz
[3] http://labix.org/python-dateutil
[4] http://pypi.python.org/pypi/dateutil
-- 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Standalone USB Web Server and Python Interpeter

2007-12-05 Thread Johny
Or you can look at
http://www.portablepython.com/
L.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting wxPython to work on a Mac

2007-12-05 Thread Timothy Smith
In article 
[EMAIL PROTECTED],
 [EMAIL PROTECTED] wrote:

 If you don't get an answer here, you should try the wxPython mailing
 list:
 http://www.wxpython.org/maillist.php
 I'm sure they'll be able to help you out (I don't have a Mac, so I
 don't know).

OK, will try there. Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why Python 3?

2007-12-05 Thread A.T.Hofkamp
On 2007-12-05, Chris Gonnerman [EMAIL PROTECTED] wrote:
 I spent some time today reading about Python 3, and specifically the 
 differences between Python 3 and Python 2, and I was left with a 
 question... why?  Why bother to change to Python 3, when the CPython 
 implementation is slower, and probably will be for a while?

I think to preserve the smoothness of switching versions, like you do now.

As user, you can smoothly 'upgrade' to using new Python features in the pace
that you like. Unfortunately for the developers, not all users do that at the
same rate and switch to the same sub-set (and that is good, I think). As a
result, the developers have to be very backwards compatible. In other words,
you can probably run a lot of the Python 1.5.2 code you wrote several years ago
using today's Python 2.5. To make that possible, all 1.5.2 stuff is still in
today's Python 2.5 interpreter, even though there are not many users that code
in 1.5.2 style any more.

As you can imagine, this old stuff piles up as we progress in Python versions.
Python 3 is the breaking point where the old stuff (that (almost) nobody uses
any more, since everybody is using new coding styles) is really gone.
That gives room for a new design of the interpreter from the ground up, using
today's coding practices and ideas as starting point.


For you as user, the transition to Python 3 will probably be smooth too. Unless
you stopped reading about new Python versions after 1.5.2, and are still using
that old 1.5.2 book as ultimate Python reference, your coding style has changed
too towards newer Python versions (and ultimately towards Python 3).

In addition, knowing the Python development cycle, as the features of Python 3
become more clear, they will first be implemented in the Python 2.x range for
testing and for giving users the chance to already pick up the new coding
styles, so by the time the last 2.x version is retired, Python 3 will have
(almost) no sudden transitions for you.

 But... almost all of my old 1.5 code ported painlessly to 2.x.  No need 
 for a 1.5to2 script, whereas I see that there is a 2to3 script for 

Well, Python 3 design is from the ground up, and aimed at the future, so they
are quite a few steps ahead of today's coding practice, let alone today's code
base (which is still 1.5 compatible as you discovered).
To run any form of practical experiments, one needs a way to quickly convert
the current code to the new conventions/ideas. Since programmers rather let the
computer do boring repetitive tasks, they write a script for the conversions.
Since Python is open source, you may also want to experiment with Python 3, and
in that case the script is very handy.

Imho, existence of such a script today does not automatically mean that you
will need to use a script at the moment you (or I) switch to Python 3.

 programming knowledge.  In fact, the things I rarely or never use in 
 Python tend to be those things I find hardest to read (like list 
 comprehensions).  Few of the changes along the way have required me to 

I use them a lot, and they are very powerful. On the other hand, I never use
generators, which is probably a loss for me.

 change how I *write* code; probably the worst was the integer division 

I think you change the way you write code continuously. I have been programming
computers for 20+ years, and are still changing the way I code.

 change, which I disagreed with, but I went along with the community.

Some changes are for your own good, even though you do not realize it now :)
For you it is the integer division. For me, I have a problem with new-style
classes, where the __eq__ method is already implemented, blurring the
difference between 'is' and '=='.

Ah well, no language is perfect, and there is probably a very good reason for
the change even if I don't see it.
(and if there is really none, the change will be undone with Python 4... :) )

 I don't see myself using Python 3 for a long time.  Probably as long as 
 I can hold out.  Where are my goodies?  What is my payoff for learning 
 how to write code the new way?  I can't see it.  Many things seem a lot 

A lot of the new goodies give you more punch per line, ie less lines to
express what you want to calculate. This is good, since the chance making an
error is a constant per line, so less lines is less errors.

 less obvious... like, what was wrong with dict.keys() returning a 
 list?  Now it returns some strange object type.

In addition, Python is generalizing programming. Why would you want to write a
for-loop yourself if you can push the loop into that strange object type? This
may look useless, but what actually happens here is that the level of
abstraction in programming is raised further (just like the main benefit of
switching from eg C to Python is the step up in abstraction (you get eg
dictionaries and lists built in, rather than having to program them yourself
from struct's for the umpteenth time).

Ultimately, when you start 

Re: Why did no one tell me about import antigravity?

2007-12-05 Thread Jarek Zgoda
Adrian Cherry napisał(a):

 Python on xkcd:

 http://xkcd.com/353/

 
 Another good comic from xkcd, I'm surprised by the muted response 
 on here. Don't forget to check out the alt. text on the comic
 
 Alt text: I wrote 20 short programs in Python yesterday. It was 
 wonderful. Perl, I'm leaving you.

XKCD is greatly undervaluated. Overall, it's very intelligent.

-- 
Jarek Zgoda
Skype: jzgoda | GTalk: [EMAIL PROTECTED] | voice: +48228430101

We read Knuth so you don't have to. (Tim Peters)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why did no one tell me about import antigravity?

2007-12-05 Thread Tim Leslie
On 5 Dec 2007 10:08:48 GMT, Adrian Cherry [EMAIL PROTECTED] wrote:
 Ant [EMAIL PROTECTED] wrote in news:52f0eca3-e807-4890-b21d-
 [EMAIL PROTECTED]:

  Python on xkcd:
 
  http://xkcd.com/353/
 

 Another good comic from xkcd, I'm surprised by the muted response
 on here. Don't forget to check out the alt. text on the comic

 Alt text: I wrote 20 short programs in Python yesterday. It was
 wonderful. Perl, I'm leaving you.


+1 QOTW

Tim


 Regards

 Adrian




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

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


pl see the beautiful pitcure

2007-12-05 Thread rosi
pl see the beautiful pitcure
http://ribodire.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why did no one tell me about import antigravity?

2007-12-05 Thread Richard Jones
Ant wrote:
 http://xkcd.com/353/

I laughed :)


Richard

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


Re: Getting wxPython to work on a Mac

2007-12-05 Thread Piet van Oostrum
 Timothy Smith [EMAIL PROTECTED] (TS) wrote:

TS Not sure exactly what I need to do to get wxPython to work on either of 
TS my Macs. (One's a notebook running Tiger (OS X 10.4.11), the other a Mac 
TS Pro running Leopard (10.5.1.))

TS I downloaded what should be the latest binary, and it installed without 
TS error. So Python comes up as

TS $ python -V
TS Python 2.5.1
TS $ ls -l /usr/bin/python
TS lrwxr-xr-x  1 root  wheel  72 Oct 26 17:59 /usr/bin/python@ - 
TS ../../System/Library/Frameworks/Python.framework/Versions/2.5/bin/python
TS $

Did you also install the latest wxPython, with the proper version,
corresponding to your python version?

TS I set PYTHONPATH to 
TS System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5

Why would you do that?

TS The Python interpreter works OK, far as I can tell. wx sort of works, 
TS but all the functionality is not there. For example, working through the 
TS exercises in WxPython in Action by Noel Rappin, I find that while I 
TS can create and display a frame, and create an app, stuff like 
TS wx.MessageBox() just doesn't work.

TS The same exercises work just fine on a Python 2.5.1 installation on my 
TS wife's Windows XP machine.

I tried the example (python_compare.py) and it just works, including the
MessageBox, on Tiger with python 2.5.1. I run the in Terminal (pythonw
python_compare.py) both with and without your PYTHONPATH.

How did you run the examples?
-- 
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: How to debug Python program with GUI (Tkinter)?

2007-12-05 Thread Nir
On Nov 28, 11:18 am, Davy [EMAIL PROTECTED] wrote:
 Hi all,

 How todebugPython program with GUI, especially Tkinter? Mydebug
 environment is PythonWin.

 For example, when I single step in the program, the step will go to
 mainloop() and always loop there. How can I know where the program is
 processed?

 Any suggestions are welcome!
 Best regards,
 Davy


Try Winpdb
http://www.digitalpeers.com/pythondebugger/

With Winpdb you can pause (break into) and inspect the state of the
Python script even if it is doing some C code.

Nir

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


Re: Python surpasses Perl in TIOBE index

2007-12-05 Thread BlueBird
On Dec 4, 4:08 pm, [EMAIL PROTECTED] wrote:
 This is *not* an attempt to start yet another Python-versus-
 AnyOtherProgrammingLanguage flame war, but I thought people might be
 interested in this:

 http://www.tiobe.com/tpci.htm

 Marc

I find Ohloh comparisons also useful:
http://www.ohloh.net/languages/compare?commit=Updatel0=pythonl0_0=-1l1=rubyl2=perlmeasure=commits

What it highlights is that the number of python programmer is growing
quicker than the number of perl programmers.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Omitting results with id3reader [Beginner]

2007-12-05 Thread Chris
Ok, just noticed you linked the id3reader.  I tested my code and it
worked fine.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Omitting results with id3reader [Beginner]

2007-12-05 Thread Chris
On Dec 5, 1:43 pm, Ionis [EMAIL PROTECTED] wrote:
 Hey guys, hope you can help me here. I've been playing with python for
 about a week or two and I've been reading A Byte Of Python to get me
 on my feet. I've decided to write a program which will list all ID3
 information in a directory of .mp3 files into a .html file.

 The python script I'm using for this, along with album art (Example)
 are in the same directory as the music. The output I am getting when
 it reads these files is None so I tried to set up a way to get rid
 of these results and move onto the next file.

 The omitting I'm attempting is within the If statement half way down
 the code, easy to find. Could anyone point me in the right direction
 on how to stop these None results showing in the result .html file.

 Thanks in advance.

 ==
 import os
 import id3reader

 songartist = str()
 songtrack = str()
 html_bulkadd = str()
 html_start = str(
 !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN 
 http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd;
 html xmlns=http://www.w3.org/1999/xhtml;
 head
 meta http-equiv=Content-Type content=text/html; 
 charset=utf-8 /

 titleTest Document/title
 /head
 body
 )
 html_end = str(
 /body
 /html
 )

 output = file(output.html, w)
 output.write()
 output.write(html_start)
 output.close

 path = 
 dirList = os.listdir(path)
 for fname in dirList:
 songartist = str()
 songtrack = str()
 id3r = id3reader.Reader(fname)
 if id3r.getValue('performer') == None:
 break
 elif id3r.getValue('title') == None:
 break
 else:
 songartist = id3r.getValue('performer')
 songtrack = id3r.getValue('title')
 output = file(output.html, a)
 output.write(p + str(songartist) +  -  + str(songtrack)
 + /p\n)
 output.close

 output = file(output.html, a)
 output.write(\n+html_end)
 output.close
 ==

 If anyone is curious on the module you can find it 
 here:http://nedbatchelder.com/code/modules/id3reader.html

Untested code

import os, fnmatch
for each_file in fnmatch.filter(os.listdir(path), '*.mp3'):
  id3r = id3reader.Reader(each_file)
  if id3r.getValue('performer') and id3r.getValue('title'):
output = open('output.html','ab')
output.write('p%s - %s/p\n' % (id3r.getValue('performer'),
id3r.getValue('title')) )
output.close()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.access() under windows

2007-12-05 Thread Tim Golden
[apologies if this double-posts; my email server's playing up]

Martin v. Löwis wrote:
  In a POSIX world, you need read permission on the directory.
  In Windows, with the bypass-traversal-check privilege,
  you only need read permission on the directory if you want
  to list it, not to access a file in the directory. Is it
  actually possible for GetFileAttributes to ever fail for
  security reasons?

After a little experimentation I can confirm:

* R_OK: A process with bypass-traversal-check priv. enabled
doesn't need any access to intervening directories in order
to get the attributes of a file within them. This means that
our existing R_OK result is accurate for any file: if we can
get its attributes then you can open the file for reading.

* W_OK: If a user has *only* read permission on a file
(regardless of the intervening directories), we'll still return
True for a W_OK check, as long the file doesn't have its read-only
bit set. This means that it's possible for os.access to return True
for a W_OK check on a file which can't then be opened for, say,
appending.

* X_OK: No idea what we should do with this.

In short, no further fiddling with the existing GetFileAttributes
solution is likely to achieve anything useful. The way to go would
be to use an AccessCheck solution which mirrors the approach used
on *nix: we ask the OS to check for r/w/x and return whatever it
returns. The exact semantics of that (eg on directories) are o/s
dependent and you need to refer to the docs for more info.

I hope to make time in the next few days to put forward a patch
to implement this in posixmodule.c.

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


Re: os.access() under windows

2007-12-05 Thread Tim Golden
Martin v. Löwis wrote:
 In a POSIX world, you need read permission on the directory.
 In Windows, with the bypass-traversal-check privilege,
 you only need read permission on the directory if you want
 to list it, not to access a file in the directory. Is it
 actually possible for GetFileAttributes to ever fail for
 security reasons?

After a little experimentation I can confirm:

* R_OK: A process with bypass-traversal-check priv. enabled
doesn't need any access to intervening directories in order
to get the attributes of a file within them. This means that
our existing R_OK result is accurate for any file: if we can
get its attributes then you can open the file for reading.

* W_OK: If a user has *only* read permission on a file
(regardless of the intervening directories), we'll still return
True for a W_OK check, as long the file doesn't have its read-only
bit set. This means that it's possible for os.access to return True
for a W_OK check on a file which can't then be opened for, say,
appending.

* X_OK: No idea what we should do with this.

In short, no further fiddling with the existing GetFileAttributes
solution is likely to achieve anything useful. The way to go would
be to use an AccessCheck solution which mirrors the approach used
on *nix: we ask the OS to check for r/w/x and return whatever it
returns. The exact semantics of that (eg on directories) are o/s
dependent and you need to refer to the docs for more info.

I hope to make time in the next few days to put forward a patch
to implement this in posixmodule.c.

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


Re: Why did no one tell me about import antigravity?

2007-12-05 Thread Adrian Cherry
Ant [EMAIL PROTECTED] wrote in news:52f0eca3-e807-4890-b21d-
[EMAIL PROTECTED]:

 Python on xkcd:
 
 http://xkcd.com/353/
 

Another good comic from xkcd, I'm surprised by the muted response 
on here. Don't forget to check out the alt. text on the comic

Alt text: I wrote 20 short programs in Python yesterday. It was 
wonderful. Perl, I'm leaving you.


Regards

Adrian



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


Re: Standalone USB Web Server and Python Interpeter

2007-12-05 Thread Shane Geiger

mcl wrote:
 I would like to have a USB pen drive, which can execute python scripts
 including CGI versions, which I can take to any Windows PC and run
 without having to install anything on the PC.

 My days of hacking are past so I am looking for something very simple.

 I would envisage a batch file which would ask if the USB web server
 needed to be started or just python scripts and it would return the IP
 address of the server or even some local host name such as 'bobserver'
 which I could give it.

 I need v2.3 python.

 Is this possible

 Thanks

 Richard
   


To the best of my knowledge you should be squared away if you have
Movable Python and the script below.  Let me know whether it works for
you.  (You might have to adjust the path somewhat.)


Movable Python:  http://www.voidspace.org.uk/python/movpy/



#!/usr/bin/python


The CGIHTTPServer module
This is a simple HTTP server that can call external scripts through the
common gateway interface
(CGI).
Example: Using the CGIHTTPServer module
# File:cgihttpserver-example-1.py

If you are reading this, you have all the source code necessary to run
your own Web server.
Run this with Python.

Note:  This script allows symlinks to places outside the document root.


try:
from mywebserver_config import *
except:
print No mywebserver_config module found.  Using defaults.
pass

import CGIHTTPServer
import BaseHTTPServer
class Handler(CGIHTTPServer.CGIHTTPRequestHandler):
cgi_directories = [/cgi]


def writefile(f, data, perms=750): open(f, 'w').write(data) and
os.chmod(f, perms)
def readfile(f): return open(f, 'r').read()

html_template = !DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.0
Transitional//EN
HTML
HEAD
  TITLEtemp/Title
/HEAD
BODY

H1 ALIGN=CENTERTemporary Server/H1
This is a temporary server.  Do not expect to have access to this
indefinitely.  This is likely running on my laptop.
/BODY
/HTML



index2_html = !DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.0
Transitional//EN
HTML
HEAD
  TITLE/Title
/HEAD
BODY

H1 ALIGN=CENTERCGI scripts/H1
a href=cgi/test.pycgi/test.py/abr
/BODY
/HTML


example_cgi = #!/usr/bin/python

# Required header that tells the browser how to render the text.
print Content-Type: text/html\\n\\n

# Print a simple message to the display window.
print Hello, World!\\n

print pWhat follows are some files in the CGI directory:p
import commands
output = commands.getoutput('ls -1 cgi/').splitlines()
for item in output:
print a href=,
print item,
print 
print item,
print /a
print br




def readip():
returns your external IP address by querying dyndns.org

import re, urllib
f = urllib.urlopen('http://checkip.dyndns.org')
s = f.read()
m = re.search('([\d]*\.[\d]*\.[\d]*\.[\d]*)', s)
return m.group(0)

print http://+readip()+:8000/

import urllib
import os


originaldir = os.getcwd()

# For safety, changing the document root
import tempfile, os
DOCUMENT_ROOT = tempfile.mkdtemp()
print DOCUMENT_ROOT:  + DOCUMENT_ROOT
os.chdir(DOCUMENT_ROOT)
writefile(DOCUMENT_ROOT+/README.html,html_template)

#print readfile(originaldir+'/'+__file__)
writefile(DOCUMENT_ROOT+/+os.path.basename(os.getcwd()+'/'+__file__),readfile(originaldir
+'/'+__file__))  # write a copy of this file


# create a cgi directory
os.mkdir(DOCUMENT_ROOT+'/cgi')
writefile(DOCUMENT_ROOT+/cgi/test.py,example_cgi)
os.chmod(DOCUMENT_ROOT+/cgi/test.py,755)
### not sure why the previous line doesn't work, but this next
(os-dependent) line does work (on some OSes):
os.system('chmod 755 ' + DOCUMENT_ROOT+/cgi/test.py)



### INDEX2.HTML
writefile(DOCUMENT_ROOT+/index2.html,index2_html)
os.system('chmod 755 ' + DOCUMENT_ROOT+/index2.html)



try:
os.remove('/tmp/web')  # this path is OS-dependent
os.symlink(DOCUMENT_ROOT, '/tmp/web')
print Created symlink /tmp/web
except:
pass



import os
os.symlink( /Users/shanegeiger/Desktop, DOCUMENT_ROOT+'/Desktop' )
os.symlink( cgi/test.py, DOCUMENT_ROOT+'/test.py' )


PORT = 8000
#httpd = BaseHTTPServer.HTTPServer((, PORT), Handler)
#httpd = BaseHTTPServer.HTTPServer((10.37.129.2, PORT), Handler)
httpd = BaseHTTPServer.HTTPServer((0.0.0.0, PORT), Handler)

print serving at port, PORT
httpd.serve_forever()


-- 
Shane Geiger
IT Director
National Council on Economic Education
[EMAIL PROTECTED]  |  402-438-8958  |  http://www.ncee.net

Leading the Campaign for Economic and Financial Literacy




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

Re: Timezones in python

2007-12-05 Thread Gabriel Genellina
En Wed, 05 Dec 2007 06:43:49 -0300, [EMAIL PROTECTED] escribió:

 Thanks guys for your answers! I know those library's but I was
 wondering is there something build-in for this simple convert convert.
 I have to do it only from +4 to +0.

Copying the example from the tzinfo docs:

 from datetime import tzinfo, timedelta, datetime

ZERO = timedelta(0)
HOUR = timedelta(hours=1)

# A class building tzinfo objects for fixed-offset time zones.
# Note that FixedOffset(0, UTC) is a different way to build a
# UTC tzinfo object.

class FixedOffset(tzinfo):
 Fixed offset in minutes east from UTC.
 def __init__(self, offset, name):
 self.__offset = timedelta(minutes = offset)
 self.__name = name
 def utcoffset(self, dt):
 return self.__offset
 def tzname(self, dt):
 return self.__name
 def dst(self, dt):
 return ZERO

UTC = FixedOffset(0, 'UTC')
Argentina = FixedOffset(-3*60, 'UTC-3')
UTCPlus4 = FixedOffset(4*60, 'UTC+4')

py now = datetime.now(Argentina)
py print now.strftime('%c %Z')
12/05/07 10:52:28 UTC-3
py print now.astimezone(UTC).strftime('%c %Z')
12/05/07 13:52:28 UTC
py print now.astimezone(Argentina).strftime('%c %Z')
12/05/07 10:52:28 UTC-3
py print now.astimezone(UTCPlus4).strftime('%c %Z')
12/05/07 17:52:28 UTC+4

-- 
Gabriel Genellina

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


Re: reloading modules and isinstance()

2007-12-05 Thread Diez B. Roggisch
Steven D'Aprano wrote:

 On Tue, 04 Dec 2007 15:41:48 +0100, Diez B. Roggisch wrote:
 
 You just discovered one reason why reload() is a bad idea and IMHO
 shouldn't be used at all - as tempting it might be.
 
 
 I disagree -- I find reload() extremely useful for interactively testing
 modules. But I would never dream of using it in production code!

I find short scripts I write  start on the commandline much more helpful -
and if I need interactivity, throwing in a 

import pdb; pdb.set_trace()

or 

python -i script

do what I want. But I certainly don't have time to hunt down bugs introduced
by reloading in the first place...

YMMV - and it seems it does :)

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


Re: Python is not a good name, should rename to Athon

2007-12-05 Thread Boris Borcic
Russ P. wrote:
 If I had invented Python, I would have called it Newton or Euler,
 arguably the greatest scientist and mathematician ever, respectively.

This makes your taste on the matter dubious.

Such choice of a name implies either a claim to the fame of the Person that's 
devoid of substance. Or else a degree of carelessness about name capture that 
casts doubt on the quality of the language design. Or else a claim by the 
language designers/namers to themselves borrow from the Person while destining 
the language to grunt practitioners not expected to have any (further) need to 
refer to said Person.

Not serious - not even serious marketing, IMHO.







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


Re: An Object's Type

2007-12-05 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit :
 Hi,
 
 Is it possible to find out if an object is of a certain type or of a
 type derived from this type?
 
You have the answer, thanks to Diez and Christian. Now unless you have a 
*very* compelling reason to check the type of an object, *just forget 
about it*. 9 times out of 10, this is fighting against the language's 
type system (hint: google for duck typing).

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


Re: Why did no one tell me about import antigravity?

2007-12-05 Thread J. Clifford Dyer

On Wed, 2007-12-05 at 10:08 +, Adrian Cherry wrote:
 Ant [EMAIL PROTECTED] wrote in news:52f0eca3-e807-4890-b21d-
 [EMAIL PROTECTED]:
 
  Python on xkcd:
  
  http://xkcd.com/353/
  
 
 Another good comic from xkcd, I'm surprised by the muted response 
 on here. Don't forget to check out the alt. text on the comic
 
 Alt text: I wrote 20 short programs in Python yesterday. It was 
 wonderful. Perl, I'm leaving you.
 
 
 Regards
 
 Adrian

I did check it out.  Loved it.  I'm about to forward it to my coworkers.
I had previously wondered at his Perl zealousy.  Now we see--he just
didn't know any better.

:)

Cheers,
Cliff

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


RE: Timeout test hangs IDLE

2007-12-05 Thread Andreas Tawn
 On Dec 5, 6:00 am, Andreas Tawn [EMAIL PROTECTED] wrote:
  I'm trying to integrate the timeout function from 
 herehttp://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/47
 3878into a
  long running automation script and the following code 
 causes IDLE after
  20 or 30 iterations in countTest.
 
  This is in 2.5, XP and there's no traceback.
 
  Could someone point me at the user error?
 
  Thanks in advance.
 
  def countTest():
  for i in xrange(1000):
  print i
  return True
 
  def timeout(func, args=(), kwargs={}, timeout_duration=1, 
 default=None):
  import threading
  class InterruptableThread(threading.Thread):
  def __init__(self):
  threading.Thread.__init__(self)
  self.result = None
 
  def run(self):
  try:
  self.result = func(*args, **kwargs)
  except:
  self.result = default
 
  it = InterruptableThread()
  it.start()
  it.join(timeout_duration)
  if it.isAlive():
  return default
  else:
  return it.result
 
  def runTest():
  timeout(countTest, timeout_duration=5)
 
  if __name__ == __main__:
  runTest()
 
 I'm confused. What does it cause IDLE to do? I tried running the
 script and it ran fine. I killed it 17346 since I have no intention of
 letting it tie up my work for your extraordinary large iteration
 number.
 
 I'm using Python 2.4 on Windows XP.
 
 Mike

Sorry, I need a better proof-reader.

When I run that code, the output gets to ~26 and then IDLE (or the
shell, I'm not sure which) hangs and there's  zero CPU activity in the
pythonw.exe process.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why Python 3?

2007-12-05 Thread Christian Heimes
A.T.Hofkamp wrote:
 Well, Python 3 design is from the ground up, and aimed at the future, so they
 are quite a few steps ahead of today's coding practice, let alone today's code
 base (which is still 1.5 compatible as you discovered).

Just a small note from me:

Several people think that we are rewriting Python 3.0 from the scratch.
That is *not* correct. The 3.x series shares lots of code with the 2.x
series. We are still merging changes from the trunk (2.6) into the py3k
branch and we are going to backport several features from 3.0 into 2.6.

Some parts are of Python 3.0 are new and the majority of the rest is
just cleaned up a bit. Some new features like the new immutable bytes
type in 3.0a2 are mostly based on existing code.

At http://www.joelonsoftware.com/articles/fog69.html Joel
explains why rewriting from the scratch is often the worst strategy.

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


Re: Tkinter vs. py2exe problem

2007-12-05 Thread msunderwd
On Dec 5, 9:50 am, [EMAIL PROTECTED] wrote:
 Having a problem with compiling a Tkinter/python program using
 py2exe (and pyinstaller, for that matter)...

 I have several dialogs that are derived from the tkSimpleDialog.Dialog
 class.  These work just fine if run through the interpreter.  When I
 compile this with py2exe, I don't see any errors, and when I execute
 the resulting program, it appears to work fine until I invoke one of
 the derived dialogs.

 Then, I get the body of the dialog, but no OK or Cancel button,
 and I get the following exception:

AttributeError: MyDialog instance has no attribute
 'buttonbox'

 For reference, MyDialog is declared as follows:
 #

 from Tkinter import *
 import tkSimpleDialog
 class MyDialog(tkSimpleDialog.Dialog)

 #

 And my setup.py file looks like this:

 #

 from distutils.core import setup
 import py2exe

 setup(console=['tcgui3.py'])

 #

 I'm invoking py2exe like this:

 C:\python setup.py py2exe -p Tkinter -p tkSimpleDialog

 ??

Oh, and it fails when the setup() line in setup.py says
setup(window=['tcgui3.py']) as well.  Same error.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python is not a good name, should rename to Athon

2007-12-05 Thread Adrian Cherry
Russ P. [EMAIL PROTECTED] wrote in
news:[EMAIL PROTECTED]
ups.com: 

 Speaking of stupid names, what does C++ mean? I think it's
 the grade you get when you just barely missed a B--. But I
 can't deny that it *is* good for searching.
 

For that matter C# is no better, I thought that # was pronounced 
hash, I still refer to C# as C-hash.

Adrian

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


Re: Python is not a good name, should rename to Athon

2007-12-05 Thread Dotan Cohen
On 04/12/2007, Hendrik van Rooyen [EMAIL PROTECTED] wrote:

 Dotan Cohen dotanail.com wrote:

  Newton was the bridge between science and superstition. Without him,
  we would not have science. For that he is notable. He is both magician
  and scientist. It was Newton's belief in the occult that led to his
  discovery of gravity: the fact that distant objects could influence
  one another. Even today, science has a hard time accepting that. And
  gravity _still_ has not been incorporated into a theory of everything
  / grand unified theory.

 You live in exciting times - google for surfer dude and E8 for a paper
 that purports to be a theory of everything.  I stumbled across it last week
 and downloaded a pdf but true to form I have lost the link.

 It was written by A. Garrett Lisi.

 Even if his theory pans out, I would oppose changing the language name
 to Garrett, or Lisi, on the grounds that John Cleese was funnier.

I read the paper a few weeks ago when it appeared on /.. It was quite
a bit over my head, but to tell you the truth, I think that it has a
fighting chance. It explains the family relationship between
particles, and even predicts new particles. So it can be tested. Until
some of those particles are found, however, I'm still in the string
camp.

Maybe we could rename Python to String?

Dotan Cohen

http://what-is-what.com
http://gibberish.co.il
א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ-ל-ם-מ-ן-נ-ס-ע-ף-פ-ץ-צ-ק-ר-ש-ת

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Why Python 3?

2007-12-05 Thread Kay Schluehr
On 5 Dez., 15:32, Christian Heimes [EMAIL PROTECTED] wrote:

 Athttp://www.joelonsoftware.com/articles/fog69.htmlJoel
 explains why rewriting from the scratch is often the worst strategy.

About migration strategies:

I do not exactly recollect whether it was in Eastland or Jugemanland,
but I remember that in the midst of a dreary forest I spied a terrible
wolf making after me, with all the speed of ravenous winter hunger.

He soon overtook me. There was no possibility of escape. Mechanically
I laid myself down flat in the sledge, and let my horse run for our
safety. What I wished, but hardly hoped or expected, happened
immediately after. The wolf did not mind me in the least, but took a
leap over me, and falling furiously on the horse, began instantly to
tear and devour the hind-part of the poor animal, which ran the faster
for his pain and terror.

Thus unnoticed and safe myself, I lifted my head slyly up, and with
horror I beheld that the wolf had ate his way into the horse's body;
it was not long before he had fairly forced himself into it, when I
took my advantage, and fell upon him with the butt-end of my whip.

This unexpected attack in his rear frightened him so much, that he
leaped forward with all his might: the horse's carcase dropped on the
ground, but in his place the wolf was in the harness, and I on my part
whipping him continually: we both arrived in full career safe at St.
Petersburg, contrary to our respective expectations, and very much to
the astonishment of the spectators.

http://bulfinch.englishatheist.org/baron/Baron.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sending commands to parallel printer through python

2007-12-05 Thread Larry Bates
hari wrote:
 Hi all,
  I need to automate printer command testing, prinetr supports
 parallel/
 serial/USB.How can i send the commands from python to printer.
 
 I have got pyparallel, as am new to python,  no idea how to work on
 it.
 Please give some tips,The comamnd to be sent to the printer is hex
 data 1B 40.please give a example,it will be grateful.
 
 
 Thank you. postedthe same in it.comp.lang.python
 
 
 Regards
 -Hari
 
 
If the printer is connected to the computer running the program you can open 
the 
printer in binary mode and write to it directly.  If it is a networked printer 
you will need to write to the spooler.

printer=open(LPT1, wb)
printer.write(int('01b', 16), int('40', 16)

printer.close()

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


Re: How to split string

2007-12-05 Thread Tim Chase
 In other words, the string should be split at every 10th possition but
 if the 10th character is space, then the string must be split at the
 nearest space before the 10th possition.
 
 It could be better explained if the length of split strings will be
 20.
 
 S='this is just a random sequence of letters courtesy of monkeys on
 typewriter.'
 
 Results:
 
 this is just a
 random sequence of
 letters courtesy of
 monkeys on
 typewriter.'
 
 Any idea how to do that?

As mentioned previously, it sounds like you're looking for the 
built-in textwrap module:

  s = this is just a random sequence of letters courtesy of 
monkeys on typewriter.
  import textwrap
  print textwrap.fill(s, 20)
this is just a
random sequence of
letters courtesy of
monkeys on
typewriter.

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

The Python library has already done all the heavy lifting--no 
need to re-invent the wheel.

-tkc





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


Re: Tkinter vs. py2exe problem

2007-12-05 Thread msunderwd
On Dec 5, 9:50 am, [EMAIL PROTECTED] wrote:
 Having a problem with compiling a Tkinter/python program using
 py2exe (and pyinstaller, for that matter)...

 I have several dialogs that are derived from the tkSimpleDialog.Dialog
 class.  These work just fine if run through the interpreter.  When I
 compile this with py2exe, I don't see any errors, and when I execute
 the resulting program, it appears to work fine until I invoke one of
 the derived dialogs.

 Then, I get the body of the dialog, but no OK or Cancel button,
 and I get the following exception:

AttributeError: MyDialog instance has no attribute
 'buttonbox'

 For reference, MyDialog is declared as follows:
 #

 from Tkinter import *
 import tkSimpleDialog
 class MyDialog(tkSimpleDialog.Dialog)

 #

 And my setup.py file looks like this:

 #

 from distutils.core import setup
 import py2exe

 setup(console=['tcgui3.py'])

 #

 I'm invoking py2exe like this:

 C:\python setup.py py2exe -p Tkinter -p tkSimpleDialog

 ??

Nevermind.  I fixed it.  I had a tkSimpleDialog.py in my local
directory that was typed in from an introductory text.

Apparently this was confusing Python.  Removing that file, and letting
it find the tkSimpleDialog from Tk makes it work.

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


Re: [SQL] plpythonu and hello concurrent world

2007-12-05 Thread Tom Lane
Gerardo Herzig [EMAIL PROTECTED] writes:
 Hi all. Im having some problems with a small concurrent plpython function.

Don't even *think* about starting multiple threads inside the Postgres
backend.  It's an excellent way to break things.

regards, tom lane
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why did no one tell me about import antigravity?

2007-12-05 Thread Paul McGuire
On Dec 5, 5:12 am, Richard Jones [EMAIL PROTECTED]
wrote:
 Ant wrote:
 http://xkcd.com/353/

 I laughed :)


... I cried, it's a part of me!

-- Paul


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


sending commands to parallel printer through python

2007-12-05 Thread hari
Hi all,
 I need to automate printer command testing, prinetr supports
parallel/
serial/USB.How can i send the commands from python to printer.

I have got pyparallel, as am new to python,  no idea how to work on
it.
Please give some tips,The comamnd to be sent to the printer is hex
data 1B 40.please give a example,it will be grateful.


Thank you. postedthe same in it.comp.lang.python


Regards
-Hari


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


Re: Python Class Best Practice

2007-12-05 Thread cptnwillard
On Dec 5, 12:18 am, Rod Person [EMAIL PROTECTED] wrote:
 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1

 I've been doing python programming for about 2 years as a hobby and now
 I'm finally able to use it at work in an enterprise environment. Since
 I will be creating the base classes and libraries I wondering which why
 is consider best when creating python classes:

 1:
 class Foo(object):
   member1=''
   member2=0

   def __init__(self,member1='',member2=0):
 self.member1 = member1
 self.member2 = member2

 2:
 class Foo(object):
 def  __init(self,member1='',member2=0):
 self.member1 = member1
 self.member2 = member2



The short answer : if 2 works, then stick with it.
-- 
http://mail.python.org/mailman/listinfo/python-list


find a man at www.SexDatingPoint.com

2007-12-05 Thread itayka3
find a man at www.SexDatingPoint.com
find a man looking for a woman at www.SexDatingPoint.com
meet adult male at www.SexDatingPoint.com
men seeking women at www.SexDatingPoint.com
women seeking men
www.SexDatingPoint.com
woman seeking man
www.SexDatingPoint.com
woman looking for man
www.SexDatingPoint.com
find a male looking for a female
www.SexDatingPoint.com
female seeking male
www.SexDatingPoint.com
female looking for male
www.SexDatingPoint.com
find a partner
www.SexDatingPoint.com
women searching for men
www.SexDatingPoint.com
woman searching for a man
www.SexDatingPoint.com
woman searching for men
www.SexDatingPoint.com
find a single man
www.SexDatingPoint.com
find single men
www.SexDatingPoint.com
search for single men
www.SexDatingPoint.com
find a groom
www.SexDatingPoint.com
search for a groom
www.SexDatingPoint.com
find a sex partner
www.SexDatingPoint.com
seek single male
www.SexDatingPoint.com
seek single men
www.SexDatingPoint.com
seek for men
www.SexDatingPoint.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: reloading modules and isinstance()

2007-12-05 Thread Gabriel Genellina
En Wed, 05 Dec 2007 15:06:43 -0300, Tlis [EMAIL PROTECTED] escribi�:

 With all the problems of the reload() function, I still hope, that
 there should be possible to write a safe module 'reloader', that would
 fix the references, as required (e.g. by changing the
 variable.__class__ references). This should be provided by every
 serious Python development environment.

Unfortunately that's not so simple, given the dynamic nature of Python.  
With some help from the programmer, reload may perform better; by example,  
if you never ever do from module import xxx, and always do import  
module and use module.xxx everywhere. But it gets rather annoying, and  
still has many problems.

-- 
Gabriel Genellina

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

Re: Python is not a good name, should rename to Athon

2007-12-05 Thread Piet van Oostrum
 Adrian Cherry [EMAIL PROTECTED] (AC) wrote:

AC For that matter C# is no better, I thought that # was pronounced 
AC hash, I still refer to C# as C-hash.

Are you musically illiterate?
-- 
Piet van Oostrum [EMAIL PROTECTED]
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python is not a good name, should rename to Athon

2007-12-05 Thread Robert Boyd
On Dec 4, 2007 10:02 AM, George Sakkis [EMAIL PROTECTED] wrote:
 On Dec 3, 12:50 pm, Russ P. [EMAIL PROTECTED] wrote:

  I know this because I've been through it myself. When I tell people
  that I use Python, I often qualify it by pointing out that it is used
  extensively at Google. In other words, I'm banking on the reputation
  of Google to offset the goofiness of the Python name.
 
  Come to think of it, maybe it should be called Googlang or Googon?

 I see, so Python has to somehow offset the goofiness of its name
 while Google can rest on its reputation. Never occured to you that the
 goofiness of the name Google is at least an order of magnitude
 greater than Python.

And it never occurred to him that Guido could have named the
programming language Google, and later, the search-engine guys could
have founded a company named Python. He'd be defending his choice of
programming in the Google language by pointing to the reputation of
the Python company, while complaining to a list that Google was a
goofy name.

I'll bet he uses the word google as a verb yet doesn't realize how
goofy that sounds to someone unfamiliar with Google? Oh well, I
suppose he'll never try programming in Caml, he'd be too embarrassed
to tell anyone.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Timeout test hangs IDLE

2007-12-05 Thread Andreas Tawn
 
  On Dec 5, 6:00 am, Andreas Tawn [EMAIL PROTECTED] wrote:
   I'm trying to integrate the timeout function from 
  herehttp://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/47
  3878into a
   long running automation script and the following code 
  causes IDLE after
   20 or 30 iterations in countTest.
  
   This is in 2.5, XP and there's no traceback.
  
   Could someone point me at the user error?
  
   Thanks in advance.
  
   def countTest():
   for i in xrange(1000):
   print i
   return True
  
   def timeout(func, args=(), kwargs={}, timeout_duration=1, 
  default=None):
   import threading
   class InterruptableThread(threading.Thread):
   def __init__(self):
   threading.Thread.__init__(self)
   self.result = None
  
   def run(self):
   try:
   self.result = func(*args, **kwargs)
   except:
   self.result = default
  
   it = InterruptableThread()
   it.start()
   it.join(timeout_duration)
   if it.isAlive():
   return default
   else:
   return it.result
  
   def runTest():
   timeout(countTest, timeout_duration=5)
  
   if __name__ == __main__:
   runTest()
  
  I'm confused. What does it cause IDLE to do? I tried running the
  script and it ran fine. I killed it 17346 since I have no 
 intention of
  letting it tie up my work for your extraordinary large iteration
  number.
  
  I'm using Python 2.4 on Windows XP.
  
  Mike
 
 Sorry, I need a better proof-reader.
 
 When I run that code, the output gets to ~26 and then IDLE (or the
 shell, I'm not sure which) hangs and there's  zero CPU activity in the
 pythonw.exe process.

Also, I should say that the the idea is that the huge iteration should
timeout after 5 seconds. I only gave it a 1000 range because I
didn't know how fast it would get through the loop. Perhaps you stopped
it before the timeout triggered?

Cheers,

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


Re: sending commands to parallel printer through python

2007-12-05 Thread Gabriel Genellina
En Wed, 05 Dec 2007 10:19:51 -0300, hari [EMAIL PROTECTED] escribi�:

 Hi all,
  I need to automate printer command testing, prinetr supports
 parallel/
 serial/USB.How can i send the commands from python to printer.

 I have got pyparallel, as am new to python,  no idea how to work on
 it.
 Please give some tips,The comamnd to be sent to the printer is hex
 data 1B 40.please give a example,it will be grateful.

a) how to control the printer port:
You should look for some info on the protocol and timings. I vaguely  
remember that you should write the desired data onto the eight data lines,  
then set the STROBE control signal for some time, then reset the signal.  
Something like this:

import parallel

port = parallel.Parallel()

def send_to_printer(bytes):
 for byte in bytes:
 port.setData(ord(byte))
 port.setDataStrobe(1)
 sleep(...)
 port.setDataStrobe(0)
 sleep(...)

send_to_printer(Hello world\r\n)

You'll have to look for the right values to sleep in each case. Those 1/0  
may be reversed too.

b) how to convert hex data:

The easiest way would be: send_to_printer(\x1B\x40)

If you have the string 1B 40 already built:

def hex_to_raw(hex):
 return ''.join([chr(int(num,16)) for num in hex.split()])

data = 1B 40
send_to_printer(hex_to_raw(data))

-- 
Gabriel Genellina

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

Re: Tkinter vs. py2exe problem

2007-12-05 Thread msunderwd
On Dec 5, 10:07 am, [EMAIL PROTECTED] wrote:
 On Dec 5, 9:50 am, [EMAIL PROTECTED] wrote:



  Having a problem with compiling a Tkinter/python program using
  py2exe (and pyinstaller, for that matter)...

  I have several dialogs that are derived from the tkSimpleDialog.Dialog
  class.  These work just fine if run through the interpreter.  When I
  compile this with py2exe, I don't see any errors, and when I execute
  the resulting program, it appears to work fine until I invoke one of
  the derived dialogs.

  Then, I get the body of the dialog, but no OK or Cancel button,
  and I get the following exception:

 AttributeError: MyDialog instance has no attribute
  'buttonbox'

  For reference, MyDialog is declared as follows:
  #

  from Tkinter import *
  import tkSimpleDialog
  class MyDialog(tkSimpleDialog.Dialog)

  #

  And my setup.py file looks like this:

  #

  from distutils.core import setup
  import py2exe

  setup(console=['tcgui3.py'])

  #

  I'm invoking py2exe like this:

  C:\python setup.py py2exe -p Tkinter -p tkSimpleDialog

  ??

 Nevermind.  I fixed it.  I had a tkSimpleDialog.py in my local
 directory that was typed in from an introductory text.

 Apparently this was confusing Python.  Removing that file, and letting
 it find the tkSimpleDialog from Tk makes it work.

 Thanks, anyway.

Ummm... Un-nevermind.  I didn't fix it.  It's still complaining.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to browse a C Library with Python

2007-12-05 Thread Rafael Sachetto
This could be a solution

import commands

callables = commands.getoutput(nm -D /lib/libc.so.6 | egrep ' T '
).split(\n)
callables = [c.split()[2] for c in callables]

print callables

On Dec 5, 2007 5:26 PM, Rafael Sachetto [EMAIL PROTECTED] wrote:
   with Python it is simple to call direct functions from c-librarys.
   Is there a way to browse over a library i.e. '/lib/libc.so' with
   python, to see all possible functions in a library?
 
  You could use the subprocess module to execute 'nm /lib/libc.so' and look
  at lines with type T.

 To do this on a dynamic library you have to use nm -D /lib/libc.so


 --
 Rafael Sachetto Oliveira

 Sir - Simple Image Resizer
 http://rsachetto.googlepages.com




-- 
Rafael Sachetto Oliveira

Sir - Simple Image Resizer
http://rsachetto.googlepages.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting wxPython to work on a Mac

2007-12-05 Thread Chris Mellon
On Dec 4, 2007 8:35 PM, Timothy Smith [EMAIL PROTECTED] wrote:
 Not sure exactly what I need to do to get wxPython to work on either of
 my Macs. (One's a notebook running Tiger (OS X 10.4.11), the other a Mac
 Pro running Leopard (10.5.1.))

 I downloaded what should be the latest binary, and it installed without
 error. So Python comes up as

 $ python -V
 Python 2.5.1
 $ ls -l /usr/bin/python
 lrwxr-xr-x  1 root  wheel  72 Oct 26 17:59 /usr/bin/python@ -
 ../../System/Library/Frameworks/Python.framework/Versions/2.5/bin/python
 $

 I set PYTHONPATH to
 System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5

 The Python interpreter works OK, far as I can tell. wx sort of works,
 but all the functionality is not there. For example, working through the
 exercises in WxPython in Action by Noel Rappin, I find that while I
 can create and display a frame, and create an app, stuff like
 wx.MessageBox() just doesn't work.

 The same exercises work just fine on a Python 2.5.1 installation on my
 wife's Windows XP machine.


There's a note at the top of the downloads page - the current wx
binary is built against MacPython, not the python that ships with 10.5

That said, 10.5 ships with wx 2.8.4, which is reasonably recent and
actually more recent than the book, so you should be pretty much okay
without any downloads.

I'm not sure if 10.5 ships with the scripts and applications for
wxPython - if not, you should download the docs and demos package
for 2.8.4 and test with those, especially PyShell and friends.

Specific details about what doesn't work (including the script you're
running and how you're running it) are welcomed if this doesn't help.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: reloading modules and isinstance()

2007-12-05 Thread Tlis
On 5 Dec, 13:18, Steven D'Aprano [EMAIL PROTECTED]
cybersource.com.au wrote:
 On Tue, 04 Dec 2007 15:41:48 +0100, Diez B. Roggisch wrote:
  You just discovered one reason why reload() is a bad idea and IMHO
  shouldn't be used at all - as tempting it might be.

 I disagree -- I find reload() extremely useful for interactively testing
 modules. But I would never dream of using it in production code!

 --
 Steven.

Please note, that I was using the 'Reload modules' functionality of
the software system in use, rather than the reload() function
directly. I admit, though, that in the background it just may call
reload() ...

With all the problems of the reload() function, I still hope, that
there should be possible to write a safe module 'reloader', that would
fix the references, as required (e.g. by changing the
variable.__class__ references). This should be provided by every
serious Python development environment.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to browse a C Library with Python

2007-12-05 Thread Rafael Sachetto
  with Python it is simple to call direct functions from c-librarys.
  Is there a way to browse over a library i.e. '/lib/libc.so' with
  python, to see all possible functions in a library?

 You could use the subprocess module to execute 'nm /lib/libc.so' and look
 at lines with type T.

To do this on a dynamic library you have to use nm -D /lib/libc.so


-- 
Rafael Sachetto Oliveira

Sir - Simple Image Resizer
http://rsachetto.googlepages.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python is not a good name, should rename to Athon

2007-12-05 Thread Bjoern Schliessmann
Piet van Oostrum wrote:
 Adrian Cherry [EMAIL PROTECTED] (AC) wrote:

 For that matter C# is no better, I thought that # was
 pronounced hash, I still refer to C# as C-hash.
 
 Are you musically illiterate?

I wonder what Cb (C-flat) would be. Ada? :)

Regards,


Björn

-- 
BOFH excuse #351:

PEBKAC (Problem Exists Between Keyboard And Chair)

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


Re: Optimizing memory usage w/ HypterText package

2007-12-05 Thread [EMAIL PROTECTED]
On Dec 5, 1:35 pm, [EMAIL PROTECTED] wrote:
 I've been using the HyperText module for a while now
 (http://dustman.net/andy/python/HyperText/), and I really like it.

 I've run into a situation where I have code to construct a table
 and while it is normally perfect, there are times where the table
 can get quite huge (e.g. 1000 columns, 10 rows  yes, the
 question of how on earth would someone render this table? comes
 up, but that's not the point here :) ), and the code I have generating
 this starts choking and dying from excessive RAM usage.

Duh.


 I'm curious if people see a better way of going about this task and/or
 believe that an alternative method of HTML generation here would be
 better.

Here's a hint: go look at comp.lang.python on Google Groups.
Note that up in the right corner it says Topics 1-30 of 98305.
Why do you suppose there is no option to display ALL the topics,
and that you are limited to 100 at a time?


 A (possibly somewhat pseudocode, as I'm doing this by hand) small example
 of what I'm doing ...

 inputs = [A, List, Of, Values, To, Go, Into, A, Table]
 numcolumns = howManyColumnsIWant

 out = ht.TABLE()
 column = 0
 for input in inputs:
 if (column == 0):
 tr = ht.TR()
 tr.append(ht.TD(input))
 column += 1
 if (column == numcolumns):
 out.append(tr)
 column = 0

 As I said, this works fine for normal cases, but I've run into some situations
 where I need this to scale not just into the hundreds of thousands but also
 well into the millions - and that's just not happening.  Is there a better
 way to do this (which involves direct HTML generation in Python), or am
 I SOL here?

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


How to get the fullname of AcroExch.PDDoc?

2007-12-05 Thread Kelie
Hello group,

I'm trying to perform some simple pdf file processing using PyWin32
package with Adobe's COM support. After searching the whole Acrobat
Interapplication Communication Reference, I didn't find a way to get
the fullname (file path) of
AcroExch.PDDoc which does have a GetFileName method (to return the
filename of the pdf). Does anyone know the answer?

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


Re: reloading modules and isinstance()

2007-12-05 Thread Chris Mellon
On Dec 5, 2007 12:06 PM, Tlis [EMAIL PROTECTED] wrote:
 On 5 Dec, 13:18, Steven D'Aprano [EMAIL PROTECTED]
 cybersource.com.au wrote:
  On Tue, 04 Dec 2007 15:41:48 +0100, Diez B. Roggisch wrote:
   You just discovered one reason why reload() is a bad idea and IMHO
   shouldn't be used at all - as tempting it might be.
 
  I disagree -- I find reload() extremely useful for interactively testing
  modules. But I would never dream of using it in production code!
 
  --
  Steven.

 Please note, that I was using the 'Reload modules' functionality of
 the software system in use, rather than the reload() function
 directly. I admit, though, that in the background it just may call
 reload() ...

 With all the problems of the reload() function, I still hope, that
 there should be possible to write a safe module 'reloader', that would
 fix the references, as required (e.g. by changing the
 variable.__class__ references). This should be provided by every
 serious Python development environment.


It's very nice to say that until you actually think about what it
entails - it's an extraordinarily hard problem. I challenge you to
write one (you don't need to have much more than a beginner knowledge
of Python to start on one) and then come back with your experiences.
-- 
http://mail.python.org/mailman/listinfo/python-list


import antigravity

2007-12-05 Thread dlp
Guess what made xkcd today:

http://xkcd.com/353/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python is not a good name, should rename to Athon

2007-12-05 Thread Bjoern Schliessmann
Dennis Lee Bieber wrote:

 I wouldn't be that harsh... Though I've never heard # as hash...

Python programmer and never heard of the hashbang? :)

Also see: http://en.wikipedia.org/wiki/Number_sign

Regards,


Björn

-- 
BOFH excuse #170:

popper unable to process jumbo kernel

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


Re: An Object's Type

2007-12-05 Thread Neil Cerutti
On 2007-12-05, Bruno Desthuilliers
[EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] a écrit :
 Is it possible to find out if an object is of a certain type
 or of a type derived from this type?

 You have the answer, thanks to Diez and Christian. Now unless
 you have a *very* compelling reason to check the type of an
 object, *just forget about it*. 9 times out of 10, this is
 fighting against the language's type system (hint: google for
 duck typing).

As I understand Python practice (and this is pretty limited, so
corrections or other use cases are welcome), type checking is
useful for overloading functions by argument type, e.g.,
__getitem__, which accepts both integers and slice objects as
keys for sequence types. Although in the case of __getitem__, et
al, it seems like the key type could have been unified to slices
(except I suppose the return type also change, er... except for
strings--oh never mind).

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


Re: How to browse a C Library with Python

2007-12-05 Thread Gabriel Genellina
En Wed, 05 Dec 2007 12:32:31 -0300, georg.heiss [EMAIL PROTECTED]  
escribi�:

 with Python it is simple to call direct functions from c-librarys.
 Is there a way to browse over a library i.e. '/lib/libc.so' with
 python, to see all possible functions in a library?

You could use the subprocess module to execute 'nm /lib/libc.so' and look  
at lines with type T.

-- 
Gabriel Genellina

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

Re: YOU MUST KNOW THIS MAN

2007-12-05 Thread Piet van Oostrum
 Deltantor [EMAIL PROTECTED] (D) wrote:

D Does c.l.python get religious spam that much? Of all of the places to be
D spammed the least likely I expected would be here.

Is that the reason you find it necessary to repeat it?
-- 
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: import antigravity

2007-12-05 Thread Chris
On Dec 5, 10:14 pm, [EMAIL PROTECTED] wrote:
 Guess what made xkcd today:

 http://xkcd.com/353/

rofl, pity it's on page 2 already of the group ;(
-- 
http://mail.python.org/mailman/listinfo/python-list


AIX Subversion Python Swig Bindings fix for core dump

2007-12-05 Thread Reedick, Andrew
If you're on AIX and Python immediately dumps core when trying to import
any SVN module, then adding -Wl,-brtl to LINKFORSHARED in the Makefile
seems to fix the problem.
 
Bad:LINKFORSHARED=-Wl,-bE:Modules/python.exp -lld
Good:   LINKFORSHARED=-Wl,-bE:Modules/python.exp -lld -Wl,-brtl

1.  unset PYTHONPATH
2.  ./configure --without-gcc --disable-ipv6 --with-thread
CC=/usr/vac/bin/xlc_r CXX=/usr/vacpp/bin/xlC_r 
3.  Edit Makefile:  LINKFORSHARED=  -Wl,-bE:Modules/python.exp -lld
-Wl,-brtl 
4.  make CC=/usr/vac/bin/xlc_r CXX=/usr/vacpp/bin/xlC_r OPT=-O2
-qmaxmem=4000
5.  make install

Oddly enough, there was no need to build Python using shared libraries.
(#*shared* in Modules/Setup was left commented out and --enable-shared
was not used.)  The OPT=... is described in
Python-2.5.1/Misc/AIX-NOTES.

This was on AIX 5.3, xlc_r 9.0, Python 5.2.1, Subversion 1.4.5.  It also
appears to work using gcc and Python 2.4.4.

Thanks to Andy Nocera for figuring it out before 'Plan B: Blood
Sacrifice While Doing the Hokey-Pokey' was implemented.




*

The information transmitted is intended only for the person or entity to which 
it is addressed and may contain confidential, proprietary, and/or privileged 
material. Any review, retransmission, dissemination or other use of, or taking 
of any action in reliance upon this information by persons or entities other 
than the intended recipient is prohibited. If you received this in error, 
please contact the sender and delete the material from all computers. GA621


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


SimpleXMLRPCServer interruptable?

2007-12-05 Thread Bret
I'm coming back to Python after an absence and it's surprising how
many things I've forgotten since wandering (against my will) into Java
land.

Anyway, I have a need for a way to make SimpleXMLRPCServer
interruptable.  Basically, I have a main server that, in response to
certain RPC calls, creates additional servers on different ports.  I
then need to be able to shut these additional servers down.

I've got something like this in the __init__ of the class which
contains the spawned servers:

def __init__(self, host, port):
:
:
server = SimpleXMLRPCServer((host, port))
:
: Bunch of server.register_function calls
:
def serverWrapper():
try:
while True:
server.handle_request()
except:
pass

One of the methods that I register is:

def shutdown(self):
raise Quitting time

Through watching logs and such I can see that the shutdown() method is
getting called, but the loop isn't getting broken.  I've done
something like this before in a previous job (so I don't have my
source in front of me, more's the pity) and am hoping someone can
chime in with a good idea.

Thanks in advance!


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


Re: How to split string

2007-12-05 Thread Neil Cerutti
On 2007-12-05, Tim Chase [EMAIL PROTECTED] wrote:
 http://docs.python.org/lib/module-textwrap.html

 The Python library has already done all the heavy lifting--no
 need to re-invent the wheel.

Well no, clearly we need xwrap methods and a ctextwrap module. ;)

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


Re: Tkinter vs. py2exe problem

2007-12-05 Thread msunderwd
On Dec 5, 10:46 am, [EMAIL PROTECTED] wrote:
 On Dec 5, 10:07 am, [EMAIL PROTECTED] wrote:



  On Dec 5, 9:50 am, [EMAIL PROTECTED] wrote:

   Having a problem with compiling a Tkinter/python program using
   py2exe (and pyinstaller, for that matter)...

   I have several dialogs that are derived from the tkSimpleDialog.Dialog
   class.  These work just fine if run through the interpreter.  When I
   compile this with py2exe, I don't see any errors, and when I execute
   the resulting program, it appears to work fine until I invoke one of
   the derived dialogs.

   Then, I get the body of the dialog, but no OK or Cancel button,
   and I get the following exception:

  AttributeError: MyDialog instance has no attribute
   'buttonbox'

   For reference, MyDialog is declared as follows:
   #

   from Tkinter import *
   import tkSimpleDialog
   class MyDialog(tkSimpleDialog.Dialog)

   #

   And my setup.py file looks like this:

   #

   from distutils.core import setup
   import py2exe

   setup(console=['tcgui3.py'])

   #

   I'm invoking py2exe like this:

   C:\python setup.py py2exe -p Tkinter -p tkSimpleDialog

   ??

  Nevermind.  I fixed it.  I had a tkSimpleDialog.py in my local
  directory that was typed in from an introductory text.

  Apparently this was confusing Python.  Removing that file, and letting
  it find the tkSimpleDialog from Tk makes it work.

  Thanks, anyway.

 Ummm... Un-nevermind.  I didn't fix it.  It's still complaining.

Okay, here's a sample program that fails:

#--
#!/usr/bin/python

from Tkinter import *
import tkSimpleDialog

class MyDialog(tkSimpleDialog.Dialog):
def body(self, master):
Label(master, text=Label).grid()

def apply(self):
print OK

if __name__ == __main__:
root = Tk()
md = MyDialog(root)
mainloop()

#

And here's the setup file I'm using with py2exe:

#
from distutils.core import setup
import py2exe

opts = {
py2exe: {
includes:tkSimpleDialog
}
}

setup(windows=['hellogui.py'], options=opts)

#

Can't make it any simpler than that... I'm so confused!
-- 
http://mail.python.org/mailman/listinfo/python-list


Tkinter vs. py2exe problem

2007-12-05 Thread msunderwd
Having a problem with compiling a Tkinter/python program using
py2exe (and pyinstaller, for that matter)...

I have several dialogs that are derived from the tkSimpleDialog.Dialog
class.  These work just fine if run through the interpreter.  When I
compile this with py2exe, I don't see any errors, and when I execute
the resulting program, it appears to work fine until I invoke one of
the derived dialogs.

Then, I get the body of the dialog, but no OK or Cancel button,
and I get the following exception:

   AttributeError: MyDialog instance has no attribute
'buttonbox'

For reference, MyDialog is declared as follows:
#

from Tkinter import *
import tkSimpleDialog
class MyDialog(tkSimpleDialog.Dialog)

#

And my setup.py file looks like this:

#

from distutils.core import setup
import py2exe

setup(console=['tcgui3.py'])

#

I'm invoking py2exe like this:

C:\python setup.py py2exe -p Tkinter -p tkSimpleDialog

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


Re: SimpleXMLRPCServer interruptable?

2007-12-05 Thread Bret
I just tried changing this so that I now have a threading.Event()
called self.done, which is set within the body of the shutdown()
method.  The serverWrapper loop now looks like this:

def serverWrapper():
while True:
server.handle_request()
if self.done.isSet():
break

This works, but only if I follow the shutdown() rpc call a few seconds
later with ... something else to cause handle_request() to complete
again.  Obviously, not quite the right approach


On Dec 5, 2:00 pm, Bret [EMAIL PROTECTED] wrote:
 I'm coming back to Python after an absence and it's surprising how
 many things I've forgotten since wandering (against my will) into Java
 land.

 Anyway, I have a need for a way to make SimpleXMLRPCServer
 interruptable.  Basically, I have a main server that, in response to
 certain RPC calls, creates additional servers on different ports.  I
 then need to be able to shut these additional servers down.

 I've got something like this in the __init__ of the class which
 contains the spawned servers:

 def __init__(self, host, port):
 :
 :
 server = SimpleXMLRPCServer((host, port))
 :
 : Bunch of server.register_function calls
 :
 def serverWrapper():
 try:
 while True:
 server.handle_request()
 except:
 pass

 One of the methods that I register is:

 def shutdown(self):
 raise Quitting time

 Through watching logs and such I can see that the shutdown() method is
 getting called, but the loop isn't getting broken.  I've done
 something like this before in a previous job (so I don't have my
 source in front of me, more's the pity) and am hoping someone can
 chime in with a good idea.

 Thanks in advance!

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


Re: Python surpasses Perl in TIOBE index

2007-12-05 Thread George Sakkis
On Dec 5, 7:34 am, BlueBird [EMAIL PROTECTED] wrote:
 On Dec 4, 4:08 pm, [EMAIL PROTECTED] wrote:

  This is *not* an attempt to start yet another Python-versus-
  AnyOtherProgrammingLanguage flame war, but I thought people might be
  interested in this:

 http://www.tiobe.com/tpci.htm

  Marc

 I find Ohloh comparisons also 
 useful:http://www.ohloh.net/languages/compare?commit=Updatel0=pythonl0_0=-...

 What it highlights is that the number of python programmer is growing
 quicker than the number of perl programmers.

Not necessarily; it shows that the count of monthly commits by open
source developers is growing, which might be mostly thanks to
relatively few dedicated committers rather than an overall increase in
the population.

Another interesing point is that the gap with PHP is narrowing too:
http://www.ohloh.net/languages/compare?measure=commitspercent=l0=perll1=phpl2=pythonl3=-1l4=-1commit=Update

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


Re: Converting LF/FF delimited logs to XML w/ Python?

2007-12-05 Thread kyosohma
On Dec 5, 3:19 pm, Kadin2048 [EMAIL PROTECTED] wrote:
 This is a very noob-ish question so I apologize in advance, but I'm
 hoping to get some input and advice before I get too over my head.

 I'm trying to convert some log files from a formfeed- and
 linefeed-delimited form into XML.  I'd been thinking of using Python to
 do this, but I'll be honest and say that I'm very inexperienced with
 Python, so before I dive in I wanted to see whether some more
 experienced minds thought I was choosing the right tool.

 Basically, what I want to do is convert from instant messaging logs
 produced by CenterIM, which look like this (Where ^L represents ASCII
 12, the formfeed character):

 ^L
 IN
 MSG
 1190126325
 1190126325
 hi
 ^L
 OUT
 MSG
 1190126383
 1190126383
 hello

 To an XML-based format* like this:

 chat account=joeblow service=AIM version=0.4
   message sender=janedoe time=1190126325hi/message
   message sender=joeblow time=1190126383hello/message
 /chat

 Obviously there's information in the bottom example not present in the
 top (account names, protocol), but I'll grab those from the file name or
 prompt the user.

 Given that I'd be learning as I go along, is Python a good tool for
 doing this? (Am I totally insane to be trying this as a beginner?) And
 if so, where should I start?  I'd like to avoid massive
 wheel-reinvention if at all possible.

 I'm not afraid to RTFM but there's a lot of information around on Python
 and I'm not sure what's most relevant.  Suggestions on what to read,
 books to buy, etc., are all welcomed.

 Thanks in advance,
 Kadin.

 * For the curious, this is sort of poor attempt at the Universal Log
 Format as used by Adium on OS X.

 --http://kadin.sdf-us.org/

I've used lxml and DOM/minidom. Both took my a while to figure out and
I still don't always understand them. Anyway, lxml is similar to the
method Chris mentioned.

http://docs.python.org/lib/module-xml.dom.html
http://www.oreilly.com/catalog/pythonxml/chapter/ch01.html
http://pyxml.sourceforge.net/topics/

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


Re: Getting wxPython to work on a Mac

2007-12-05 Thread Timothy Smith
In article [EMAIL PROTECTED],
 Piet van Oostrum [EMAIL PROTECTED] wrote:

 TS I set PYTHONPATH to 
 TS System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5
 
 Why would you do that?

Don't know, as it's not clear (to me) from the documentation whether 
PYTHONPATH has to include a path to the regular Python modules, or only 
to one's own modules. Just fishing here.

 TS The Python interpreter works OK, far as I can tell. wx sort of works, 
 TS but all the functionality is not there. For example, working through the 
 TS exercises in WxPython in Action by Noel Rappin, I find that while I 
 TS can create and display a frame, and create an app, stuff like 
 TS wx.MessageBox() just doesn't work.
 
 TS The same exercises work just fine on a Python 2.5.1 installation on my 
 TS wife's Windows XP machine.
 
 I tried the example (python_compare.py) and it just works, including the
 MessageBox, on Tiger with python 2.5.1. I run the in Terminal (pythonw
 python_compare.py) both with and without your PYTHONPATH.
 
 How did you run the examples?

I tried them using just python and also pythonw. Same (lack of) results.

I will try going back to the OS X 10.5 distribution of Python. Will have 
to do a reinstall, I suppose.
-- 
http://mail.python.org/mailman/listinfo/python-list


Converting LF/FF delimited logs to XML w/ Python?

2007-12-05 Thread Kadin2048
This is a very noob-ish question so I apologize in advance, but I'm 
hoping to get some input and advice before I get too over my head.

I'm trying to convert some log files from a formfeed- and 
linefeed-delimited form into XML.  I'd been thinking of using Python to 
do this, but I'll be honest and say that I'm very inexperienced with 
Python, so before I dive in I wanted to see whether some more 
experienced minds thought I was choosing the right tool.

Basically, what I want to do is convert from instant messaging logs 
produced by CenterIM, which look like this (Where ^L represents ASCII 
12, the formfeed character):

^L
IN
MSG
1190126325
1190126325
hi
^L
OUT
MSG
1190126383
1190126383
hello

To an XML-based format* like this:

chat account=joeblow service=AIM version=0.4
  message sender=janedoe time=1190126325hi/message
  message sender=joeblow time=1190126383hello/message
/chat

Obviously there's information in the bottom example not present in the 
top (account names, protocol), but I'll grab those from the file name or 
prompt the user.

Given that I'd be learning as I go along, is Python a good tool for 
doing this? (Am I totally insane to be trying this as a beginner?) And 
if so, where should I start?  I'd like to avoid massive 
wheel-reinvention if at all possible.

I'm not afraid to RTFM but there's a lot of information around on Python 
and I'm not sure what's most relevant.  Suggestions on what to read, 
books to buy, etc., are all welcomed.

Thanks in advance,
Kadin.

* For the curious, this is sort of poor attempt at the Universal Log 
Format as used by Adium on OS X.

-- 
http://kadin.sdf-us.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Optimizing memory usage w/ HypterText package

2007-12-05 Thread Chris
On Dec 5, 10:17 pm, Chris [EMAIL PROTECTED] wrote:
 On Dec 5, 9:35 pm, [EMAIL PROTECTED] wrote:



  I've been using the HyperText module for a while now
  (http://dustman.net/andy/python/HyperText/), and I really like it.

  I've run into a situation where I have code to construct a table
  and while it is normally perfect, there are times where the table
  can get quite huge (e.g. 1000 columns, 10 rows  yes, the
  question of how on earth would someone render this table? comes
  up, but that's not the point here :) ), and the code I have generating
  this starts choking and dying from excessive RAM usage.

  I'm curious if people see a better way of going about this task and/or
  believe that an alternative method of HTML generation here would be
  better.

  A (possibly somewhat pseudocode, as I'm doing this by hand) small example
  of what I'm doing ...

  inputs = [A, List, Of, Values, To, Go, Into, A, Table]
  numcolumns = howManyColumnsIWant

  out = ht.TABLE()
  column = 0
  for input in inputs:
  if (column == 0):
  tr = ht.TR()
  tr.append(ht.TD(input))
  column += 1
  if (column == numcolumns):
  out.append(tr)
  column = 0

  As I said, this works fine for normal cases, but I've run into some 
  situations
  where I need this to scale not just into the hundreds of thousands but also
  well into the millions - and that's just not happening.  Is there a better
  way to do this (which involves direct HTML generation in Python), or am
  I SOL here?

 for (i, input) in enumerate(inputs):
   Your Code
   
   if not i % 1000:
 # Flush your data.

 It's logical that you will run out of space as the code just appends
 data constantly instead of ever writing it out.  How you flush the
 data out is up to you or if it's as simple as you have there you could
 do something like.

 file_out.write('TABLE\n')
 for x in xrange(0, len(inputs)//numcolumns):
   file_out.write('TR\nTD%s/TD\n/TR' % '/TD
 \nTD'.join(inputs[(x*numcolumns):((x+1)*numcolumns)]) )
   if not x % 500: file_out.flush()
 file_out.write('TR\nTD%s/TD\n/TR\n/TABLE' % '/TD
 \nTD'.join(inputs[x*numcolumns:]) )
 file_out.close()

Sorry, change the second last line from:

 file_out.write('TR\nTD%s/TD\n/TR\n/TABLE' % 
 '/TD\nTD'.join(inputs[x*numcolumns:]) )

to:

if len(inputs) % numcolumns:
  file_out.write('TR\nTD%s/TD\n/TR\n/TABLE' % '/TD
\nTD'.join(inputs[x*numcolumns:]) )
else:
  file_out.write('\n/TABLE')
-- 
http://mail.python.org/mailman/listinfo/python-list


Need Help to start with RTP

2007-12-05 Thread niket mhatre
Hello to every one.
I currently working on project where, I need to handle my audio streaming ,
For that reason
I m looking for some python lib or any python module, which wl help me to
construct RTP packets. Or any one can able to lead me to any resource wl
also help lot..
Thanks in advanced
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Timeout test hangs IDLE

2007-12-05 Thread Sergio Correia
I once made a small app that used threads on IDLE.

There was a strange error when using 'print'  threads. When what I printed
filled the entire screen, instead of moving all the text up, IDLE just
hanged. Try running your code from the shell instead, to see if the problem
is in IDLE.

HTH,
Sergio

On Dec 5, 2007 5:07 PM, [EMAIL PROTECTED] wrote:

 On Dec 5, 10:37 am, Andreas Tawn [EMAIL PROTECTED] wrote:
On Dec 5, 6:00 am, Andreas Tawn [EMAIL PROTECTED] wrote:
 I'm trying to integrate the timeout function from
herehttp://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/47
3878into a
 long running automation script and the following code
causes IDLE after
 20 or 30 iterations in countTest.
 
 This is in 2.5, XP and there's no traceback.
 
 Could someone point me at the user error?
 
 Thanks in advance.
 
 def countTest():
 for i in xrange(1000):
 print i
 return True
 
 def timeout(func, args=(), kwargs={}, timeout_duration=1,
default=None):
 import threading
 class InterruptableThread(threading.Thread):
 def __init__(self):
 threading.Thread.__init__(self)
 self.result = None
 
 def run(self):
 try:
 self.result = func(*args, **kwargs)
 except:
 self.result = default
 
 it = InterruptableThread()
 it.start()
 it.join(timeout_duration)
 if it.isAlive():
 return default
 else:
 return it.result
 
 def runTest():
 timeout(countTest, timeout_duration=5)
 
 if __name__ == __main__:
 runTest()
 
I'm confused. What does it cause IDLE to do? I tried running the
script and it ran fine. I killed it 17346 since I have no
   intention of
letting it tie up my work for your extraordinary large iteration
number.
 
I'm using Python 2.4 on Windows XP.
 
Mike
 
   Sorry, I need a better proof-reader.
 
   When I run that code, the output gets to ~26 and then IDLE (or the
   shell, I'm not sure which) hangs and there's  zero CPU activity in the
   pythonw.exe process.
 
  Also, I should say that the the idea is that the huge iteration should
  timeout after 5 seconds. I only gave it a 1000 range because I
  didn't know how fast it would get through the loop. Perhaps you stopped
  it before the timeout triggered?
 
  Cheers,
 
  Drea

 No...I ran it for at least 30-60 seconds. Making a thread stop on
 command is a pain though.

 This link taught me one way to do it, but I cannot vouch how will it
 works as I've never aborted any of my threads:

 http://wiki.wxpython.org/LongRunningTasks

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

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

Re: An Object's Type

2007-12-05 Thread Bruno Desthuilliers
Neil Cerutti a écrit :
 On 2007-12-05, Bruno Desthuilliers
 [EMAIL PROTECTED] wrote:
 
[EMAIL PROTECTED] a écrit :

Is it possible to find out if an object is of a certain type
or of a type derived from this type?

You have the answer, thanks to Diez and Christian. Now unless
you have a *very* compelling reason to check the type of an
object, *just forget about it*. 9 times out of 10, this is
fighting against the language's type system (hint: google for
duck typing).
 
 
 As I understand Python practice (and this is pretty limited, so
 corrections or other use cases are welcome), type checking is
 useful for overloading functions by argument type, e.g.,
 __getitem__, which accepts both integers and slice objects as
 keys for sequence types.

Yeps, this is one of the couple occasions you might want to know 
something about the object's type. The few other use case I had where 
mostly about the same pattern - low-level and somewhat dirty code.

 Although in the case of __getitem__, et
 al, it seems like the key type could have been unified to slices
 (except I suppose the return type also change, er... except for
 strings--oh never mind).
 

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


Re: Converting LF/FF delimited logs to XML w/ Python?

2007-12-05 Thread Chris Mellon
On Dec 5, 2007 3:19 PM, Kadin2048 [EMAIL PROTECTED] wrote:
 This is a very noob-ish question so I apologize in advance, but I'm
 hoping to get some input and advice before I get too over my head.

 I'm trying to convert some log files from a formfeed- and
 linefeed-delimited form into XML.  I'd been thinking of using Python to
 do this, but I'll be honest and say that I'm very inexperienced with
 Python, so before I dive in I wanted to see whether some more
 experienced minds thought I was choosing the right tool.

 Basically, what I want to do is convert from instant messaging logs
 produced by CenterIM, which look like this (Where ^L represents ASCII
 12, the formfeed character):

 ^L
 IN
 MSG
 1190126325
 1190126325
 hi
 ^L
 OUT
 MSG
 1190126383
 1190126383
 hello

 To an XML-based format* like this:

 chat account=joeblow service=AIM version=0.4
   message sender=janedoe time=1190126325hi/message
   message sender=joeblow time=1190126383hello/message
 /chat

 Obviously there's information in the bottom example not present in the
 top (account names, protocol), but I'll grab those from the file name or
 prompt the user.

 Given that I'd be learning as I go along, is Python a good tool for
 doing this? (Am I totally insane to be trying this as a beginner?) And
 if so, where should I start?  I'd like to avoid massive
 wheel-reinvention if at all possible.

 I'm not afraid to RTFM but there's a lot of information around on Python
 and I'm not sure what's most relevant.  Suggestions on what to read,
 books to buy, etc., are all welcomed.


This is a pretty simple problem and is well suited for a beginner
project. The file() builtin will get you the data in your log file.
Using the split() method of the string object, you can break your
logfile into chunks.

There are a number of XML libraries in the standard lib, but xml.etree
is my preferred one. It is documented in the stdlib docs, and on the
effbot site.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter vs. py2exe problem

2007-12-05 Thread msunderwd
On Dec 5, 9:50 am, [EMAIL PROTECTED] wrote:
 Having a problem with compiling a Tkinter/python program using
 py2exe (and pyinstaller, for that matter)...

 I have several dialogs that are derived from the tkSimpleDialog.Dialog
 class.  These work just fine if run through the interpreter.  When I
 compile this with py2exe, I don't see any errors, and when I execute
 the resulting program, it appears to work fine until I invoke one of
 the derived dialogs.

 Then, I get the body of the dialog, but no OK or Cancel button,
 and I get the following exception:

AttributeError: MyDialog instance has no attribute
 'buttonbox'

 For reference, MyDialog is declared as follows:
 #

 from Tkinter import *
 import tkSimpleDialog
 class MyDialog(tkSimpleDialog.Dialog)

 #

 And my setup.py file looks like this:

 #

 from distutils.core import setup
 import py2exe

 setup(console=['tcgui3.py'])

 #

 I'm invoking py2exe like this:

 C:\python setup.py py2exe -p Tkinter -p tkSimpleDialog

 ??

Oh yeah... if it matters, I'm using Python 2.5.1 on Win XP, and py2exe
v1.4.  I get the same problem using pyinstaller, except it doesn't
show the exception - it just fails to display the buttons.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Omitting results with id3reader [Beginner]

2007-12-05 Thread Ionis
Thank you for your help, it is really appreciated. I'll post back if
there are any more problems.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why Python 3?

2007-12-05 Thread Michael Spencer
Kay Schluehr wrote:
 
 This unexpected attack in his rear frightened him so much, that he
 leaped forward with all his might: the horse's carcase dropped on the
 ground, but in his place the wolf was in the harness, and I on my part
 whipping him continually: we both arrived in full career safe at St.
 Petersburg, contrary to our respective expectations, and very much to
 the astonishment of the spectators.
 
 http://bulfinch.englishatheist.org/baron/Baron.html

in order, I presume, to counterpoint the surrealism of the underlying metaphor

http://flag.blackened.net/dinsdale/dna/book1.html

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


[OT] Guide me on Apache Virtual server+mod_python

2007-12-05 Thread Ravi Kumar
HI,
I am sorry for OT here.  But I search google, could not quench my thrist, so
came here, and for single question, I don't want to subscribe in Apache
Newsgroup.
The problem is :
i wwant to implement a mod_python based Website + Reporting Application on
my system.

In the domain, my system is : mysys.domain.com
Now, I want to implement two subdomains on my apache server:
http://www.site.com
http://report.site.com
Means two or multiple subdomains on same Apache Server.
Only one IP Address and NIC is allocated in System (can't go for two IPs).
Network has CISCO Routers .
So can you please guide me a little, on how to do it. I just need some
pointers and I will start finding them on Google.


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

Re: Omitting results with id3reader [Beginner]

2007-12-05 Thread Bruno Desthuilliers
Ionis a écrit :
 Hey guys, hope you can help me here. I've been playing with python for
 about a week or two and I've been reading A Byte Of Python to get me
 on my feet. I've decided to write a program which will list all ID3
 information in a directory of .mp3 files into a .html file.
 
 The python script I'm using for this, along with album art (Example)
 are in the same directory as the music. The output I am getting when
 it reads these files is None so I tried to set up a way to get rid
 of these results and move onto the next file.
 
 The omitting I'm attempting is within the If statement half way down
 the code, easy to find. Could anyone point me in the right direction
 on how to stop these None results showing in the result .html file.
 
 Thanks in advance.
 
 ==
 import os
 import id3reader
 
 songartist = str()

You're passing a string to the string class constructor... this is a bit 
redondant, isn't it ?-)

songartist = 

 songtrack = str()
 html_bulkadd = str()

idem...

 html_start = str(
 !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://
 www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
 html xmlns=http://www.w3.org/1999/xhtml;
   head
   meta http-equiv=Content-Type content=text/html; 
 charset=utf-8 /
   titleTest Document/title
   /head
   body
 )
 html_end = str(
 /body
 /html
 )


You may want to learn about string formating.

html_template = 
!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://
   www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
html xmlns=http://www.w3.org/1999/xhtml;
   head
 meta http-equiv=Content-Type content=text/html; charset=utf-8 /
 title%(title)s/title
   /head
   body
 %(content)s
   /body
/html

data = {'title':'The title',
 'content':h1The content comes here/h1\n
   + pFine, isn't it?/p\n
 }

print html_template % data


This would let you build the whole page in one pass instead...

 output = file(output.html, w)
 output.write()

??? Why this empty string ?

 output.write(html_start)
 output.close

This *doesn't* call the file.close method, but returns a reference to it 
(reference which is immediatly discarded). In Python, the parens are not 
optional wrt/ function call - in fact, they actually are the 'call' 
operator.

 path = 

Note that you can pass arguments to Python scripts - like, say, a path. 
You retrieve the arg list in sys.argv:

import sys
try:
   # sys.argv[0] is either the script name or nothing,
   # depending on your os. The first arg - if there's one,
   # is sys.argv[1]
   path = sys.argv[1]
except IndexError:
   # no arg passed
   err = usage : python myscript.py path\n(missing argument 'path') \
   sys.exit(err)


then call it:

python myscript.py /path/to/some/mp3/dir

This would let you keep your script out of your music directory...


 dirList = os.listdir(path)

otUsual convention is to use all_lower names for vars. /ot

 for fname in dirList:
 songartist = str()
 songtrack = str()

Why do you rebind these 2 names ? There already defined above - and 
rebound below FWIW.

 id3r = id3reader.Reader(fname)
 if id3r.getValue('performer') == None:

You want to test against the None object, not against the literal string 
None:

  if id3.getValue(performer) is None:
 # etc

FWIW, note that id3.getValue(tag here) returning None doesn't mean the 
file is not a valid mp3 - just that it doesn't hold this information 
(tested here...). Anyway, Chris already told you a way to handle this 
problem...

 break

This get you out of the loop, which may not be what you want. If you 
decide to ignore untagged mp3 files, using 'continue' might be a better 
idea.

 elif id3r.getValue('title') == None:
 break

idem

 else:
 songartist = id3r.getValue('performer')
 songtrack = id3r.getValue('title')

Since you only use these variables here, defining them at the top of 
your script, and rebiding them at the top of the loop is useless.

Also, you're making useless calls to id3r.getValue. A simpler solution 
would be to test the values *after* storing them:

for fname in dirList:
 # note that if your script is not in the same
 # directory as the one you're inspecting,
 # you need to pass absolute path:
 fpath os.path.join(path, fname)
 id3r = id3reader.Reader(fpath)
 songartist = id3r.getValue('performer')
 songtrack = id3r.getValue('title')
 if (songartist is None or songtrack is None):
# if you want to just skip this file:
continue
 # if you're here then songartist and songtrack are not None




 output = file(output.html, a)

Opening and closing files is a costly operation. You should not 
open/close a same file on each iteration - better to either keep it open 
or first store all data and only then open the file, write, and close.

Also and FWIW, you failed to properly close the file before the loop, 

Timeout test hangs IDLE

2007-12-05 Thread Andreas Tawn
I'm trying to integrate the timeout function from here
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/473878 into a
long running automation script and the following code causes IDLE after
20 or 30 iterations in countTest.

This is in 2.5, XP and there's no traceback.

Could someone point me at the user error?

Thanks in advance.


def countTest():
for i in xrange(1000):
print i
return True

def timeout(func, args=(), kwargs={}, timeout_duration=1, default=None):
import threading
class InterruptableThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.result = None

def run(self):
try:
self.result = func(*args, **kwargs)
except:
self.result = default

it = InterruptableThread()
it.start()
it.join(timeout_duration)
if it.isAlive():
return default
else:
return it.result

def runTest():
timeout(countTest, timeout_duration=5)

if __name__ == __main__:
runTest()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Converting LF/FF delimited logs to XML w/ Python?

2007-12-05 Thread Kadin2048
In article [EMAIL PROTECTED],
 Chris Mellon [EMAIL PROTECTED] wrote:

 This is a pretty simple problem and is well suited for a beginner
 project. The file() builtin will get you the data in your log file.
 Using the split() method of the string object, you can break your
 logfile into chunks.

Glad to hear I'm not jumping too far into the deep end, then.  I figured 
this had to be a fairly common/basic task.

 There are a number of XML libraries in the standard lib, but xml.etree
 is my preferred one. It is documented in the stdlib docs, and on the
 effbot site.

Excellent, I'll check it out further.  effbot looks like a good resource.

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


Re: How to split string

2007-12-05 Thread Peter Otten
Johny wrote:

 I have a string of a variable length and I need to split the string
 in strings of 6 characters .
 But if the 6th character is not space then I must split the string
 at possition  before the 6th character.
 
 For example:
 if the main string  S is
 
 S='abcde fghc ijkl mnop'
 
 the result should be
 abcde
 fghc
 ijkl
 mnop
 
 
 Do you have any idea how it can be done?

 print textwrap.fill('abcde fghc ijkl mnop verylongword', width=6)
abcde
fghc
ijkl
mnop v
erylon
gword
 
Peter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to split string

2007-12-05 Thread Johny
On Dec 5, 11:55 am, Chris [EMAIL PROTECTED] wrote:
 On Dec 5, 10:55 am, Johny [EMAIL PROTECTED] wrote:





  I have a string of a variable length and I need to split the string
  in strings of 6 characters .
  But if the 6th character is not space then I must split the string
  at possition  before the 6th character.

  For example:
  if the main string  S is

  S='abcde fghc ijkl mnop'

  the result should be
  abcde
  fghc
  ijkl
  mnop

  Do you have any idea how it can be done?
  Thank you
  L.

 That's not a great example of what you are looking for, because that
 result just looks like:
 '\n'.join(S.split())

 What result would you be looking for with say:
 S='this is just a random sequence of letters courtesy of monkeys on
 typewriter.'

Chris,
Thank you for your reply.
So, let's suppose the  example:
S='this is just a random sequence of letters courtesy of monkeys on
typewriter.'
and the length of split strings is now 10( instead of 6)
The example should be like this
this is
just a
random
sequence
of letters
courtesy
of monkeys
on
typewriter


In other words, the string should be split at every 10th possition but
if the 10th character is space, then the string must be split at the
nearest space before the 10th possition.

It could be better explained if the length of split strings will be
20.

S='this is just a random sequence of letters courtesy of monkeys on
 typewriter.'

Results:

this is just a
random sequence of
letters courtesy of
monkeys on
typewriter.'


Any idea how to do that?
Thank you
L.




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


Re: An Object's Type

2007-12-05 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote:

 Hi,
 
 Is it possible to find out if an object is of a certain type or of a
 type derived from this type?

http://docs.python.org/lib/built-in-funcs.html

Look for isinstance.

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


Re: How to split string

2007-12-05 Thread Chris
On Dec 5, 10:55 am, Johny [EMAIL PROTECTED] wrote:
 I have a string of a variable length and I need to split the string
 in strings of 6 characters .
 But if the 6th character is not space then I must split the string
 at possition  before the 6th character.

 For example:
 if the main string  S is

 S='abcde fghc ijkl mnop'

 the result should be
 abcde
 fghc
 ijkl
 mnop

 Do you have any idea how it can be done?
 Thank you
 L.

That's not a great example of what you are looking for, because that
result just looks like:
'\n'.join(S.split())

What result would you be looking for with say:
S='this is just a random sequence of letters courtesy of monkeys on
typewriters.'
?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.access() under windows

2007-12-05 Thread Martin v. Löwis
 * R_OK: A process with bypass-traversal-check priv. enabled
 doesn't need any access to intervening directories in order
 to get the attributes of a file within them. This means that
 our existing R_OK result is accurate for any file: if we can
 get its attributes then you can open the file for reading.

That cannot be. There is still an ACL on the file itself which
is considered when the file is opened for reading, namely,
the List Folder / Read Data permission. It may be that you need
the Read Attributes permission to have GetFileAttributes
succeed, but that is independent from read data.

 * W_OK: If a user has *only* read permission on a file
 (regardless of the intervening directories), we'll still return
 True for a W_OK check, as long the file doesn't have its read-only
 bit set. This means that it's possible for os.access to return True
 for a W_OK check on a file which can't then be opened for, say,
 appending.

Or any other kind of writing.

 * X_OK: No idea what we should do with this.

Well, there is the Traverse Folder / Execute File permission that
should be checked against (but currently isn't).

Regards,
Martin

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


An Object's Type

2007-12-05 Thread bg_ie
Hi,

Is it possible to find out if an object is of a certain type or of a
type derived from this type?

Thanks,

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


Re: Python is not a good name, should rename to Athon

2007-12-05 Thread Boris Borcic
Russ P. wrote:
 Speaking of stupid names, what does C++ mean?

According to Special Relativity, C++ is a contradiction in terms :)

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


Re: Timezones in python

2007-12-05 Thread lukasz . f24
Thanks guys for your answers! I know those library's but I was
wondering is there something build-in for this simple convert convert.
I have to do it only from +4 to +0.
-- 
http://mail.python.org/mailman/listinfo/python-list


How to split string

2007-12-05 Thread Johny
I have a string of a variable length and I need to split the string
in strings of 6 characters .
But if the 6th character is not space then I must split the string
at possition  before the 6th character.

For example:
if the main string  S is

S='abcde fghc ijkl mnop'

the result should be
abcde
fghc
ijkl
mnop


Do you have any idea how it can be done?
Thank you
L.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: reloading modules and isinstance()

2007-12-05 Thread Steven D'Aprano
On Tue, 04 Dec 2007 15:41:48 +0100, Diez B. Roggisch wrote:

 You just discovered one reason why reload() is a bad idea and IMHO
 shouldn't be used at all - as tempting it might be.


I disagree -- I find reload() extremely useful for interactively testing 
modules. But I would never dream of using it in production code!


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


Re: Timeout test hangs IDLE

2007-12-05 Thread kyosohma
On Dec 5, 6:00 am, Andreas Tawn [EMAIL PROTECTED] wrote:
 I'm trying to integrate the timeout function from 
 herehttp://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/473878into a
 long running automation script and the following code causes IDLE after
 20 or 30 iterations in countTest.

 This is in 2.5, XP and there's no traceback.

 Could someone point me at the user error?

 Thanks in advance.

 def countTest():
 for i in xrange(1000):
 print i
 return True

 def timeout(func, args=(), kwargs={}, timeout_duration=1, default=None):
 import threading
 class InterruptableThread(threading.Thread):
 def __init__(self):
 threading.Thread.__init__(self)
 self.result = None

 def run(self):
 try:
 self.result = func(*args, **kwargs)
 except:
 self.result = default

 it = InterruptableThread()
 it.start()
 it.join(timeout_duration)
 if it.isAlive():
 return default
 else:
 return it.result

 def runTest():
 timeout(countTest, timeout_duration=5)

 if __name__ == __main__:
 runTest()

I'm confused. What does it cause IDLE to do? I tried running the
script and it ran fine. I killed it 17346 since I have no intention of
letting it tie up my work for your extraordinary large iteration
number.

I'm using Python 2.4 on Windows XP.

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


contributing to an open source project

2007-12-05 Thread kdt
Hi,

I am looking for an open source project to contribute to, to enhance
my python skills. I have about 6 months experience in the language. I
have searched freshmeat.net, but as I'm pretty new, I'm not sure which
projects I would be able to contribute to.

If anyone can suggest any open source projects python projects that
would be suitable for a beginner, and where mentoring might be an
option, please let me know.

Thanks

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


Re: Omitting results with id3reader [Beginner]

2007-12-05 Thread Chris
On Dec 5, 2:04 pm, Ionis [EMAIL PROTECTED] wrote:
 On Dec 5, 11:59 am, Chris [EMAIL PROTECTED] wrote:

  Ok, just noticed you linked the id3reader.  I tested my code and it
  worked fine.

 Thanks alot Chris. Could you comment your code so I can see what each
 line is doing? I hope that isn't a problem. Still pretty new to python.

import os, fnmatch
 fnmatch will check your directory listing and compare
it to the pattern, in this case mp3, and will normalize
the case for you as well and only return those matching
the pattern.
Equivalent commands would be: dir *.mp3 or ls *.mp3

# os.listdir() and the fnmatch.filter will return you lists
# to iterate over so no need to store it seperately
for each_file in fnmatch.filter(os.listdir(path), '*.mp3'):
  id3r = id3reader.Reader(each_file) # Read the new file
   A value of None will return false if you test it so
  by just doing 'if value', it will return false if
  there is nothing.
  
  if id3r.getValue('performer') and id3r.getValue('title'):
output = open('output.html','ab')
# using string formatting is neater than string concatenation
output.write('p%s - %s/p\n' % (id3r.getValue('performer'),
id3r.getValue('title')) )
output.close()

HTH,
Chris
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Omitting results with id3reader [Beginner]

2007-12-05 Thread Ionis
On Dec 5, 11:59 am, Chris [EMAIL PROTECTED] wrote:
 Ok, just noticed you linked the id3reader.  I tested my code and it
 worked fine.

Thanks alot Chris. Could you comment your code so I can see what each
line is doing? I hope that isn't a problem. Still pretty new to python.
-- 
http://mail.python.org/mailman/listinfo/python-list


parsing python code

2007-12-05 Thread Ryan Krauss
I need to parse a Python file by breaking it into blocks matching
indentation levels so that function definitions, for loops, and
classes are kept together as blocks.  For example, if I have something
like

from scipy import*
from pylab import*

g = .6
Input_freq = 10.0

def load_data(path):
data = loadtxt(path, skiprows = 1)
t = data[:,0]
Input = data[:,1]
Output = data[:,2]
return t,Input,Output

def time_plot(x,y,n = 1):
figure(n)
clf()
for curx, cury in zip(x,y):
plot(curx,cury)
title('Time Plot')
xlabel('time')
ylabel('f(t)')
legend(['Input','Output'],1)
return figure(n)

t, Input, Output = load_data('system_data.txt')



I would like the blocks to be

block1 = ['from scipy import*', 'from pylab import*', 'g =
.6','Input_freq = 10.0']

block2 = ['def load_data(path):',
'   data = loadtxt(path, skiprows = 1)',
'   t = data[:,0]',
'   Input = data[:,1]',
'   Output = data[:,2]',
'   return t,Input,Output']

and so on.

I think the parser module should enable me to do this, but I can't
seem to figure it out.  Specifically, I think I need to use
parser.sequence2ast, but it doesn't work the way I think it should and
I can't find more documentation on it or an example that uses it.

I tried

f = open('Example.py','r')
mylines = f.readlines()
parser.sequence2ast(mylines)

but got a ParserError.

Is there an easy way to do what I need?

Thanks,

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


Re: Timeout test hangs IDLE

2007-12-05 Thread kyosohma
On Dec 5, 10:37 am, Andreas Tawn [EMAIL PROTECTED] wrote:
   On Dec 5, 6:00 am, Andreas Tawn [EMAIL PROTECTED] wrote:
I'm trying to integrate the timeout function from
   herehttp://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/47
   3878into a
long running automation script and the following code
   causes IDLE after
20 or 30 iterations in countTest.

This is in 2.5, XP and there's no traceback.

Could someone point me at the user error?

Thanks in advance.

def countTest():
for i in xrange(1000):
print i
return True

def timeout(func, args=(), kwargs={}, timeout_duration=1,
   default=None):
import threading
class InterruptableThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.result = None

def run(self):
try:
self.result = func(*args, **kwargs)
except:
self.result = default

it = InterruptableThread()
it.start()
it.join(timeout_duration)
if it.isAlive():
return default
else:
return it.result

def runTest():
timeout(countTest, timeout_duration=5)

if __name__ == __main__:
runTest()

   I'm confused. What does it cause IDLE to do? I tried running the
   script and it ran fine. I killed it 17346 since I have no
  intention of
   letting it tie up my work for your extraordinary large iteration
   number.

   I'm using Python 2.4 on Windows XP.

   Mike

  Sorry, I need a better proof-reader.

  When I run that code, the output gets to ~26 and then IDLE (or the
  shell, I'm not sure which) hangs and there's  zero CPU activity in the
  pythonw.exe process.

 Also, I should say that the the idea is that the huge iteration should
 timeout after 5 seconds. I only gave it a 1000 range because I
 didn't know how fast it would get through the loop. Perhaps you stopped
 it before the timeout triggered?

 Cheers,

 Drea

No...I ran it for at least 30-60 seconds. Making a thread stop on
command is a pain though.

This link taught me one way to do it, but I cannot vouch how will it
works as I've never aborted any of my threads:

http://wiki.wxpython.org/LongRunningTasks

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


Re: PyObjC and Webkits

2007-12-05 Thread kyosohma
On Dec 4, 1:01 pm, Tommy Grav [EMAIL PROTECTED] wrote:
 I am trying to install PyObjC 1.4 on my Mac OS X 10.4.11.

 I run:

 [EMAIL PROTECTED] Temporary/pyobjc-1.4 -- python setup.py bdist_mpkg --
 open
 ** using pyobjc source-deps py2app for building
 running bdist_mpkg
 installing to build/bdist.macosx-10.3-fat/mpkg
 running build
 running build_py
 running build_ext
 Performing task: Generating wrappers  stubs
 /Library/Frameworks/Python.framework/Versions/2.5/Resources/
 Python.app/Contents/MacOS/Python Scripts/CodeGenerators/
 cocoa_generator.py
 building 'WebKit._WebKit' extension
 gcc -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -
 fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd -
 fPIC -fno-common -dynamic -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -
 I/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 -
 c Modules/WebKit/_WebKit.m -o build/temp.macosx-10.3-fat-2.5/Modules/
 WebKit/_WebKit.o -IModules/objc -DMACOSX -DAPPLE_RUNTIME -no-cpp-
 precomp -Wno-long-double -g -Wall -Wstrict-prototypes -Wmissing-
 prototypes -Wformat=2 -W -Wshadow -Wpointer-arith -Wmissing-
 declarations -Wnested-externs -Wno-long-long -Wno-import -Ibuild/
 codegen/
 In file included from Modules/WebKit/_WebKit.m:23:
 build/codegen/_WebKit_Enum.inc:3:35: error: WebKit/DOMAbstractView.h:
 No such file or directory

 Followed by numerous errors.

 The problem seems to be that the WebKit Framework is not found by the
 install
 script. It is present and located in /System/Library/Frameworks/
 WebKit.framework/
 How can I get the code to find this framework?

 Cheers
TG

I've never done this, but I think you need to learn how to create a
custom manifest file:

http://docs.python.org/dist/manifest.html

Hope that helps!

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


Re: Distutils help for sub-packages

2007-12-05 Thread kyosohma
On Dec 3, 9:44 am, Rick Muller [EMAIL PROTECTED] wrote:
 I need some distutils help. I currently run a python library
 (PyQuante) that, until recently, had all of its modules in a single
 directory, called PyQuante. The setup command in my setup.py module
 had a single packages line:

   packages = ['PyQuante'],

 I moved some of the routines into Basis and IO subdirectories of
 PyQuante, and amended the packages line to be:

   packages = ['PyQuante','PyQuante.Basis','PyQuante.IO'],

 Everything works find if I'm installing from SVN. However, when I
 build a tarball via setup.py sdist, the Basis and IO subdirectories
 are not included. How can I get the distutils to include this?

 Thanks in advance,

 Rick

I recommend asking the distutils guys at their list:

http://mail.python.org/mailman/listinfo/distutils-sig

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


  1   2   >