Shift Confusion

2005-02-23 Thread Kamilche
I'm trying to pack two characters into a single byte, and the shifting
in Python has me confused.

Essentially, it should be possible to use a 'packed string' format in
Python, where as long as the characters you're sending are in the ASCII
range 0 to 127, two will fit in a byte.

Here's the code. Can you tell what I'm doing wrong?

|import types
|
|def PackString(s):
|if type(s) != types.StringType:
|raise Exception("This routine only packs strings!")
|l = len(s)
|if l % 2 != 0:
|s = s + '\0'
|l += 1
|chars = []
|for i in range(0, l, 2):
|x = ord(s[i])
|y = ord(s[i+1])
|chars.append(chr((y << 1) | x))
|return ''.join(chars)
|
|def UnpackString(s):
|if type(s) != types.StringType:
|raise Exception("This routine only unpacks strings!")
|l = len(s)
|chars = []
|for i in range(l):
|temp = ord(s[i])
|c = 0xf0 & temp
|chars.append(chr(c))
|c = 0x0f & temp
|chars.append(chr(c))
|return ''.join(chars)
|
|
|def main():
|s = "Test string"
|print s
|packed = PackString(s)
|print "This is the string packed:"
|print packed
|print "This is the string unpacked:"
|print UnpackString(packed)
|
|main()

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


Re: Like overloading __init__(), but how?

2005-02-23 Thread John M. Gabriele
On Wed, 23 Feb 2005 21:32:52 -0700, Steven Bethard wrote:

> [snip]
> Another possibility is to play around with *args:
> 
> class Vector3d(object):
>  def __init__(self, *args):
>  if not args:
>  # constructor with no arguments
>  elif len(args) == 6:
>  # constructor with xyz coords
>  elif len(args) == 2:
>  # constructor with points
>  elif len(args) == 1:
>  # copy constructor
>  else:
>  raise TypeError('expected 0, 1, 2 or 6 args, got %i' %
>  len(args))
> 
> But this can get really ugly really quick.
> 
> HTH,
> 
> STeVe

Thanks STeVe. I think, for now, I'll probably stick with
the easier but less elegant way of checking *args. I guess
I could compare args[0].__class__.__name__  against 'Point3d',
'Vector3d', or just 'float'.

Didn't realize this topic came up recently. Sorry for the
duplication.

---J

-- 
--- if replying via email, remove zees ---


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


Re: Pythoncard - Mistake in walkthrough?

2005-02-23 Thread Deltones
> As stated in the on-line WalkThrough, the information there was written for
> an older version of the program.
> 


Hi,

I understand, but the walkthrough I'm doing comes from the doc folder
of the latest windows package. I thought that the walkthrough were
updated to fit the newest version. Thanks though.

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


Dr. Dobb's Python-URL! - weekly Python news and links (Feb 24)

2005-02-23 Thread Cameron Laird
QOTW:  "Who's 'Guido'?" -- Ilias Lazaridis

"I know this document.  It has no relevance to me." -- Ilias
Lazaridis, on http://www.catb.org/~esr/faqs/smart-questions.html >

"Nobody asked them to do this (AFAIK), it's more that nobody could
_stop_ them from doing it." -- timbot, on the work of Jason Tishler
and Andrew MacIntyre with Cygwin and OS/2 EMX, respectively


Hot off the virtual press:  Py2.4 Quick Reference:

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/5be203da13eafdd2/

For a decade now, confident people have declaimed in 
managers' meetings and conferences that {local,Web}
applications are {dead,utterly triumphant}, in all
combinations (and sometimes at the same venues) (and
sometimes by the same people!) (although not by the
same people at the same time).  Real Programmers know
they need judgment and expertise on both sides.  The
principal implications for Python:  client-side Web
scripting is one of the few domains where Python is
*not* nearly ideal (although not for technical reasons);
but the best "Weblications" still can result from co-
operation between Python and other languages:

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/b0085890efa29780/

Kartic and Tony Meyer provide nice two-minute tutorials
on imaplib, and, more generally, network programming:

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/c8f87f28f00a9c93/

Tkinter has modal dialogues:

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/8fce072f149f13c0/

Ron Stephens entertainingly advertises pyGoogle:

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/e28557ad49b4619a/

Peaceful coexistence:

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/3adfa3b1148aaa8e/

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/3775e1b575d8fb67/



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

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

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

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

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

Brett Cannon continues the marvelous tradition established by 
Andrew Kuchling and Michael Hudson of intelligently summarizing
action on the python-dev mailing list once every other week.
http://www.python.org/dev/summary/

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

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

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

The Python Business Forum "further[s] the interests of companies
that base their business on ... Python."
http://www.python-in-business.org

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

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

Kurt B. Kaiser publishes a weekly report on faults and patches.
http://www.google.com/groups?as_usubject=weekly%20python%20patch
   
Cetus collects Python hyperlinks.
http://www.cetus-links.org/oo_python.html

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

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

Among several Python-oriented RSS/RDF feeds available are
http://www.python.org/channews.rdf
http://bootleg-rss.g-blog.net/pythonware_com_daily.pcgi
   

Re: rounding problem

2005-02-23 Thread Dan Bishop
tom wrote:
> On Wed, 23 Feb 2005 19:04:47 -0600, Andy Leszczynski wrote:
>
> > It is on Windows, Linux, Python 2.3:
> >
> > [GCC 3.3.2 (Mandrake Linux 10.0 3.3.2-6mdk)] on linux2 Type "help",
> > "copyright", "credits" or "license" for more information.
> >  >>> a=1.1
> >  >>> a
> > 1.1001
...
> > Is it normal?
>
> Yes. Quite normal.
...
> The print statement ,by itself, adds the most minimial formatting,
which
> amounts to dropping the last significant digit your math processor
holds.
> That last digit will *always* contain some arithmetic slop.

Your statement is misleading, because it suggests that your processor
stores digits.  It doesn't; it stores *bits*.

The distinction is important because 1.1 does not have a finite
representation in binary.  Instead, it's the repeating bit sequence 1.0
0011 0011 0011...
This is analogous to 1/3 = 0.333... in base ten.

IEEE 754 requires that all normalized numbers be rounded to 53
significant bits, so "1.1" is actually stored as 0x1.1999A,
which is equivalent to the decimal number
1.100088817841970012523233890533447265625.  Python's repr
function rounds this to 17 significant digits, or "1.1001".

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


Re: Source Encoding GBK/GB2312

2005-02-23 Thread Kent Johnson
[EMAIL PROTECTED] wrote:
When I specify an source encoding such as:
# -*- coding: GBK -*-
or
# -*- coding: GB2312 -*-
as the first line of source, I got the following error:
SyntaxError: 'unknown encoding: GBK'
Does this mean Python does not support GBK/GB2312?  What do I do?
GB2312 is supported in Python 2.4.
GB2312 support can be added to Python 2.3 with the CJKCodecs package:
http://cjkpython.i18n.org/
Kent
-
narke
--
http://mail.python.org/mailman/listinfo/python-list


Re: Source Encoding GBK/GB2312

2005-02-23 Thread limodou
2.4 support gb2312, gbk, gb18030 and cjk codec.
you can also move these things to 2.3.


On Wed, 23 Feb 2005 22:34:02 -0600, Steve Holden <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> 
> > When I specify an source encoding such as:
> >
> > # -*- coding: GBK -*-
> > or
> > # -*- coding: GB2312 -*-
> >
> > as the first line of source, I got the following error:
> >
> > SyntaxError: 'unknown encoding: GBK'
> >
> >
> > Does this mean Python does not support GBK/GB2312?  What do I do?
> >
> 
> Well, *your* Python might not support GTK:
> 
> [EMAIL PROTECTED] ~
> $ cat test90.py
> # -*- coding: GBK -*-
> 
> print "Hello!"
> 
> [EMAIL PROTECTED] ~
> $ python test90.py
> Hello!
> 
> but Python generally appears to. Do you have encodings/gbk.py in your
> library?
> 
> regards
>   Steve
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
> 


-- 
I like python! 
My Blog: http://www.donews.net/limodou
New Maillist: http://groups-beta.google.com/group/python-cn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Like overloading __init__(), but how?

2005-02-23 Thread Kent Johnson
John M. Gabriele wrote:
I know that Python doesn't do method overloading like
C++ and Java do, but how am I supposed to do something
like this:
This was just discussed. See
http://tinyurl.com/6zo3g
Kent
- incorrect 
#!/usr/bin/python
class Point3d:
  pass
class Vector3d:
  """A vector in three-dimensional cartesian space."""
  def __init__( self ):
"""Create a Vector3d with some reasonable default value."""
x, y, z = 0.0, 0.0, 0.0
  def __init__( self, x_from, y_from, z_from,
  x_to,   y_to,   z_to ):
"""Create a Vector3d from x-y-z coords."""
# ...
pass
  def __init__( self, point_from, point_to ):
"""Create a Vector3d from two Point3d objects."""
# ...
pass
  

  def __init__( self, same_as_this_vec ):
"""Create a Vector3d from a copy of another one."""
# ...
pass
p = Point3d()
p2 = Point3d()
# v = Vector3d( p2, p ) -- Nope. Only the last __init__() counts.
 
-- /incorrect ---

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


Re: Like overloading __init__(), but how?

2005-02-23 Thread djw
This was discussed only days ago:
http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/41a6c0e1e260cd72/fc1c924746532316?q=multiple+constructors+python&_done=%2Fgroups%3Fq%3Dmultiple+constructors+python%26&_doneTitle=Back+to+Search&&d#fc1c924746532316
-Don
John M. Gabriele wrote:
I know that Python doesn't do method overloading like
C++ and Java do, but how am I supposed to do something
like this:
- incorrect 
#!/usr/bin/python
class Point3d:
  pass
class Vector3d:
  """A vector in three-dimensional cartesian space."""
  def __init__( self ):
"""Create a Vector3d with some reasonable default value."""
x, y, z = 0.0, 0.0, 0.0
  def __init__( self, x_from, y_from, z_from,
  x_to,   y_to,   z_to ):
"""Create a Vector3d from x-y-z coords."""
# ...
pass
  def __init__( self, point_from, point_to ):
"""Create a Vector3d from two Point3d objects."""
# ...
pass
  

  def __init__( self, same_as_this_vec ):
"""Create a Vector3d from a copy of another one."""
# ...
pass
p = Point3d()
p2 = Point3d()
# v = Vector3d( p2, p ) -- Nope. Only the last __init__() counts.
 
-- /incorrect ---

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


Re: Like overloading __init__(), but how?

2005-02-23 Thread Steven Bethard
John M. Gabriele wrote:
class Vector3d:
  def __init__(self):
...
  def __init__(self, x_from, y_from, z_from, x_to, y_to, z_to):
...
  def __init__(self, point_from, point_to):
...
  def __init__(self, same_as_this_vec):
...
My preferred option is to break these into different methods.  I pick 
the xyz-coords (and the empty coords) __init__ as the most basic cases, 
but if you find one of the other cases to be more basic, the 
modification should be pretty simple.

class Vector3d(object):
# define init to take only xyz coords (missing coords default to 0)
# this covers your first two cases, I think
def __init__(self, x_from=0.0, y_from=0.0, z_from=0.0,
   x_to=0.0,   y_to=0.0,   z_to=0.0):
...
# define a classmethod that creates a Vector3d from points
# this covers your third case
@classmethod
def from_points(cls, point_from, point_to):
...
return cls(x_from=..., y_from=..., ...)
# define copy as an instance method, not a constructor
# this covers your fourth case
def copy(self):
...
return type(self)(x_from=..., y_from=..., ...)
Another possibility is to play around with *args:
class Vector3d(object):
def __init__(self, *args):
if not args:
# constructor with no arguments
elif len(args) == 6:
# constructor with xyz coords
elif len(args) == 2:
# constructor with points
elif len(args) == 1:
# copy constructor
else:
raise TypeError('expected 0, 1, 2 or 6 args, got %i' %
len(args))
But this can get really ugly really quick.
HTH,
STeVe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Source Encoding GBK/GB2312

2005-02-23 Thread Steve Holden
[EMAIL PROTECTED] wrote:
When I specify an source encoding such as:
# -*- coding: GBK -*-
or
# -*- coding: GB2312 -*-
as the first line of source, I got the following error:
SyntaxError: 'unknown encoding: GBK'
Does this mean Python does not support GBK/GB2312?  What do I do?
Well, *your* Python might not support GTK:
[EMAIL PROTECTED] ~
$ cat test90.py
# -*- coding: GBK -*-
print "Hello!"
[EMAIL PROTECTED] ~
$ python test90.py
Hello!
but Python generally appears to. Do you have encodings/gbk.py in your 
library?

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


Re: On eval and its substitution of globals

2005-02-23 Thread Kent Johnson
Paddy wrote:
I do in fact have the case you mention. I am writing a module that will
manipulate functions of global variables where the functions are
defined in another module.
Would it be possible to have your functions take arguments instead of globals? That would seem to be 
a better design.

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


Re: How Do I get Know What Attributes/Functions In A Class?

2005-02-23 Thread Dan Eloff
Use the dir() function
dir(myClass)
returns a list of strings
-Dan
--
http://mail.python.org/mailman/listinfo/python-list


Source Encoding GBK/GB2312

2005-02-23 Thread steven
When I specify an source encoding such as:

# -*- coding: GBK -*-
or
# -*- coding: GB2312 -*-

as the first line of source, I got the following error:

SyntaxError: 'unknown encoding: GBK'


Does this mean Python does not support GBK/GB2312?  What do I do?

-
narke

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


Re: Dynamically pass a function arguments from a dict

2005-02-23 Thread Dan Eloff
Awesome, wrapping that into a function:
def getargs(func):
numArgs = func.func_code.co_argcount
names = func.func_code.co_varnames
return names[:numArgs]
short, concise, and it works :)
variables declared inside the function body are also in co_varnames
but after the arguments only it seems
A good module (huge, very comprehensive)
for this kinda thing can be found at:
http://lfw.org/python/inspect.py
Thanks very much!
-Dan
--
http://mail.python.org/mailman/listinfo/python-list


Re: How Do I get Know What Attributes/Functions In A Class?

2005-02-23 Thread steven
Thank you All !

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


Canonical way of dealing with null-separated lines?

2005-02-23 Thread Douglas Alan
Is there a canonical way of iterating over the lines of a file that
are null-separated rather than newline-separated?  Sure, I can
implement my own iterator using read() and split(), etc., but
considering that using "find -print0" is so common, it seems like
there should be a more cannonical way.

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


Re: rounding problem

2005-02-23 Thread tom
On Wed, 23 Feb 2005 19:04:47 -0600, Andy Leszczynski wrote:

> It is on Windows, Linux, Python 2.3:
> 
> [GCC 3.3.2 (Mandrake Linux 10.0 3.3.2-6mdk)] on linux2 Type "help",
> "copyright", "credits" or "license" for more information.
>  >>> a=1.1
>  >>> a
> 1.1001
>  >>>
>  >>>
>  >>>
> Is it normal?

Yes. Quite normal.

Floating point numbers are by nature approximations. When you enter your
variable "a" at the prompt, you are asking for a very raw (i.e totally
unformatted!) dump of what your variable "a" contains. It is the
most precise representation of the float 1.1 that your computer can store.
 It is probably the best precision your hardware math processor subsystem
has to offer. And, incidentally, that ain't too shabby since a 1 in the
16th decimal place ain't worth spit!

Try putting a print statement in front of your variable.
>>> print a
>>> 1.1

The print statement ,by itself, adds the most minimial formatting, which
amounts to dropping the last significant digit your math processor holds.
That last digit will *always* contain some arithmetic slop.

If you do any serious work with floats, you will want to learn about
significant figures and the use of the very essential round() function in
whatever language you are using. If you do, you will find that this
situation is really a math thing and has little to do with computers or
any particular language. It's the exact same problem one runs into when
using a slide rule.

If anyone remembers those things :-)
Thomas Bartkus

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


Re: rounding problem

2005-02-23 Thread Michael Hartl
> Is it normal?

Yes.  The interpreter prints back the repr of a, which reflects the
imprecision inherent in floats.  If you want '1.1', use the string
returned by the str function.

>>> a = 1.1
>>> a
1.1001
>>> repr(a)
'1.1001'
>>> str(a)
'1.1'

Michael

--
Michael D. Hartl, Ph.D.
CTO, Quark Sports LLC
http://quarksports.com/

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


Like overloading __init__(), but how?

2005-02-23 Thread John M. Gabriele
I know that Python doesn't do method overloading like
C++ and Java do, but how am I supposed to do something
like this:

- incorrect 
#!/usr/bin/python

class Point3d:
  pass

class Vector3d:
  """A vector in three-dimensional cartesian space."""

  def __init__( self ):
"""Create a Vector3d with some reasonable default value."""
x, y, z = 0.0, 0.0, 0.0


  def __init__( self, x_from, y_from, z_from,
  x_to,   y_to,   z_to ):
"""Create a Vector3d from x-y-z coords."""
# ...
pass


  def __init__( self, point_from, point_to ):
"""Create a Vector3d from two Point3d objects."""
# ...
pass
  

  def __init__( self, same_as_this_vec ):
"""Create a Vector3d from a copy of another one."""
# ...
pass

p = Point3d()
p2 = Point3d()
# v = Vector3d( p2, p ) -- Nope. Only the last __init__() counts.
 
-- /incorrect ---

Thanks.

-- 
--- if replying via email, remove zees ---


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


Re: python tutorial/projects

2005-02-23 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Leif B. Kristensen <[EMAIL PROTECTED]> wrote:
>Danny skrev:
>
>> Does anyone know of a good python tutorial?
>> I was also looking for some non-trivial projects to do in python.
> 
>There's a lot of projects on Sourceforge that are written in Python,
>where you're free to study the code and maybe participate, if you've
>got what it takes.
> 
>> Basically I would like to claim on my resume, that I know python, with
>> out bad karma.
>
>Your stance is a difficult one, and one that is hard to conciliate with
>the Zen of Hacking. Search for enlightenment first, my son, and the
>rest will be given to you freely.
>-- 
>Leif Biberg Kristensen

Should we just tell Danny to come to a PyCon?  'Bet we could put
him to use in a Sprint.  There's work that fits even the rawest
beginners, if they have the right attitude.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: reading only new messages in imaplib

2005-02-23 Thread Raghul
Thanks ya.It helped me a lot 

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


Re: Question about logfiles in Python

2005-02-23 Thread Harlin Seritt
I'm not familiar with Exchange log files but this can be done rather
easily assuming the log file is a flat text file (which usually these
are not-- like NT event logs).

search_str = "words and phrases"
data = open(LogFile, 'r').read()

if search_str in data:
   flag = 1

If they are binary files, you may have to use a special module (or
write one yourself if it doesn't exist). A good place to look is in
Mark Hammond's Win32 modules. You'll find some stuff here:
http://starship.python.net/crew/mhammond/

Hope this sends you in the right direction.

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


Re: How to write a ping client

2005-02-23 Thread Harlin Seritt
?

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


Re: rounding problem

2005-02-23 Thread Kristian M Zoerhoff
In article <[EMAIL PROTECTED]>, Andy Leszczynski wrote:
> >>> a=1.1
> >>> a
> 1.1001
> >>>
> 
> 
> Is it normal?

Yes, for floating-point numbers. This is due to inherent imprecision
in how floats are represented in hardware. If you can live with being
a touch off that many decimal places out, you can just clean up upon
printing with something like:

>>>print "%0.1f" % (a)
1.1

for your value of a above. If you don't want to deal with this cruft,
you may want to give the Decimal class a gander:

>>>from Decimal import *
>>>setcontext(ExtendedContext)
>>>a = Decimal('1.1')
>>>a
'Decimal("1.1")'
>>> print a
1.1


-- 
zoerhoff(AT)sdf.lonestar.org 
kristian.zoerhoff(AT)gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [EVALUATION] - E02 - Support for MinGW Open Source Compiler

2005-02-23 Thread Markus Wankus
Nick Vargish wrote:
Ilias Lazaridis <[EMAIL PROTECTED]> writes:

Guido is the one, who should care by time about the status of the
python-community.

That one crashed my parser.
Sounds like a new Ministry song - "Guido Crashed my Parser".  Could be 
the sequel to "Jesus Built My Hot Rod".
--
http://mail.python.org/mailman/listinfo/python-list


Re: Attaching to a Python Interpreter a la Tcl

2005-02-23 Thread Stephen Thorne
On 23 Feb 2005 02:37:48 -0800, DE <[EMAIL PROTECTED]> wrote:
> Hello,
> 
> Some long time ago, I used to use Tcl/Tk. I had an tcl embedded into my
> app.
> 
> The coolest thing was however, I was able to attach to the interpreter
> (built in to my app) via a tcl shell in which I could type in regular
> tcl code which would be interpreted by the interpreter of my
> application. Naturally, it was possible to call tcl functions of my
> applications.
> 
> Some kind of rapid RPC.
> 
> Is this also possible with python ?

Yes, using something like twisted's 'Manhole', which allows you to
execute code in the server process.

It may require twisted-ising your application however.

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


Re: Style guide for subclassing built-in types?

2005-02-23 Thread janeaustine50
Michael Spencer wrote:
> [EMAIL PROTECTED] wrote:
> > Kent Johnson wrote:
> >
> >>[EMAIL PROTECTED] wrote:
> >>
> >>>p.s. the reason I'm not sticking to reversed or even reverse :
> >
> > suppose
> >
> >>>the size of the list is huge.
> >>
> >>reversed() returns an iterator so list size shouldn't be an issue.
> >>
> >>What problem are you actually trying to solve?
> >>
> >>Kent
> >>
> >
> >
> > Oh, you are right.
> >
> > Actually, it's more complicated than simple reversion. The list
order
> > should be somewhat "twisted" and the list is big.
> >
> > For example,
> >
> > [1,2,3,4,5,6,7,8,9,10]
> >
> > --> [10,9,8,7,6,1,2,3,4,5]
> >
> > so __getitem__(self,i) => __getitem__(self,-i-1) if i > otherwise __getitem__(self,i-len(size)/2)
> >
> > I'd like to have TwistedList class that takes in an original list
and
> > pretends as if it is twisted actually. However, I have to have
> > duplicate codes here and there to make it act like a "list", say
assert
> > twisted_list == [10,9,...] and for each in twisted_list and etc.
> >
> If you want a twisted 'view' of an existing list, then a wrapper
makes most sense.
>
> If, however, you only need the twisted version, why not simply
override
> list.__init__ (and extend, append etc... as required):
>
>   >>> class rev_list(list):
>   ... def __init__(self, iterable):
>   ... list.__init__(self, iterable[::-1])
>   ...
>   >>> l = rev_list([1,2,3])
>   >>> l
>   [3, 2, 1]
>
> Michael

Thank you but your advice doesn't fit in my case since I want to keep
the memory usage and the initial time minimum. iterable[::-1] would
build another list and it would take big memory and time during
reversing if iterable were huge. (and the "iterable" wouldn't be
garbage-collected because I want to keep a reference to it)

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


Re: Dynamically pass a function arguments from a dict

2005-02-23 Thread Mark McEahern
Dan Eloff wrote:
How can you determine that func2 will only accept
bar and zoo, but not foo and call the function with
bar as an argument? 
Let Python answer the question for you:
>>> def func2(bar='a', zoo='b'):
... pass
...
>>> for name in dir(func2):
... print '%s: %s' % (name, getattr(func2, name))
...
__call__: 
__class__: 
__delattr__: 
__dict__: {}
__doc__: None
__get__: 
__getattribute__: 
__hash__: 
__init__: 
__module__: __main__
__name__: func2
__new__: 
__reduce__: 
__reduce_ex__: 
__repr__: 
__setattr__: 
__str__: 
func_closure: None
func_code: ", line 1>
func_defaults: ('a', 'b')
func_dict: {}
func_doc: None
func_globals: {'func2': , 'name': 
'func_globals',
'__builtins__': , '__name__': 
'__main__', 'foo
: , '__doc__': None}
func_name: func2
>>> for name in dir(func2.func_code):
... print '%s: %s' % (name, getattr(func2.func_code, name))
...
__class__: 
__cmp__: 
__delattr__: 
__doc__: code(argcount, nlocals, stacksize, flags, codestring, 
constants, names,

varnames, filename, name, firstlineno, lnotab[, freevars[, cellvars]])
Create a code object. Not for the faint of heart.
__getattribute__: 
__hash__: 
__init__: 
__new__: 
__reduce__: 
__reduce_ex__: 
__repr__: 
__setattr__: 
__str__: 
co_argcount: 2
co_cellvars: ()
co_code: d S
co_consts: (None,)
co_filename: 
co_firstlineno: 1
co_flags: 67
co_freevars: ()
co_lnotab: â
co_name: func2
co_names: ()
co_nlocals: 2
co_stacksize: 1
co_varnames: ('bar', 'zoo')
>>>
Hmm, func2.func_code.co_varnames seems to have the answer.
Cheers,
// m
--
http://mail.python.org/mailman/listinfo/python-list


Re: Communication between JAVA and python

2005-02-23 Thread Steve Menard
Jacques Daussy wrote:
Hello
How can I transfert information between a JAVA application and a python 
script application. I can't use jython because, I must use python 
interpreter.I think to socket or semaphore, but can I use it on Windows 
plateform ?

thanks a lot
jack 


Well, it all depends on the exact deployment scenario you;re facing.
If you're java program can be embedded dinside hte python scripts, then 
JPype (see my sig at the bottom of this post) can certainly help you.

Otherwise ... Is there a java way to "access" you java program from 
outside it's process? I mean things like RMI servers, or EJBs. If so, 
again JPype can take the place of a "java" client.

If not, there is no magic. You must first find a way to contact you Java 
process. If that remote-call technology is "standard", i.e. Something 
like SOAP or XML-RPC, then you can find a python technology to access 
it. If its not standard, but tehre is a Java way to use it, Again jpype 
can be your friend.

If you can tell us more about the nature of each program (Python and 
Java) we may be better able to help you.

--
Steve Menard

Maintainer of http://jpype.sourceforge.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: rounding problem

2005-02-23 Thread Aahz
In article <[EMAIL PROTECTED]>,
Andy Leszczynski  <[EMAIL PROTECTED]> wrote:
>It is on Windows, Linux, Python 2.3:
>
>[GCC 3.3.2 (Mandrake Linux 10.0 3.3.2-6mdk)] on linux2
>Type "help", "copyright", "credits" or "license" for more information.
> >>> a=1.1
> >>> a
>1.1001
> >>>
>
>
>Is it normal?

http://www.python.org/doc/current/tut/node16.html
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"The joy of coding Python should be in seeing short, concise, readable
classes that express a lot of action in a small amount of clear code -- 
not in reams of trivial code that bores the reader to death."  --GvR
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Attaching to a Python Interpreter a la Tcl

2005-02-23 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Robin Becker  <[EMAIL PROTECTED]> wrote:
>DE wrote:
>> Hello,
>> 
>> Some long time ago, I used to use Tcl/Tk. I had an tcl embedded into my
>> app.
>> 
>> The coolest thing was however, I was able to attach to the interpreter
>> (built in to my app) via a tcl shell in which I could type in regular
>> tcl code which would be interpreted by the interpreter of my
>> application. Naturally, it was possible to call tcl functions of my
>> applications.
>> 
>> Some kind of rapid RPC.
>> 
>> Is this also possible with python ?
>> 
>> Thanks,
>> 
>I think you are talking about the tk send command which allows for 
>communicating with a known app.
>
>I don't believe python comes with such a facility without some coding, 
>but it has been implemented in various ways using sockets etc etc.
>
>I seem to remember that modern idle uses an rpc technique for debugging.
>
>There are several python projects which address interprocess 
>communication pyro http://pyro.sourceforge.net/ is a good example.
.
.
.
Agreed:  Python makes it easy to do this.  Tk *does* this,
out-of-the-box.

But note!  Tkinter can access Tk's [send], so, if the appli-
cation happened to be built with Tkinter, and one were fluent
enough at translating between Tcl and Python to reach the
latter by way of the former, then, yes, you would find that
your Python application already has this.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: kill a process in XP

2005-02-23 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Dave Brueck  <[EMAIL PROTECTED]> wrote:
>Tor Erik Sønvisen wrote:
>>>From my Python-program I spawn a new process. When using P_NOWAIT spawnl 
>> returns the pid but in windows it returns a process handle.
>> Later I want to kill this process. How can I do this when I only have the 
>> process handle?
>
>Try ctypes - if it's really a Windows handle, then this should work:
>
>from ctypes import *
>windll.kernel32.TerminateProcess(h, 0) # or whatever return code you want
>
>-Dave

I sometimes am so irritated with attendant portability issues
that I open a channel between parent and child, which I use to
send an exit-now message.
-- 
http://mail.python.org/mailman/listinfo/python-list


rounding problem

2005-02-23 Thread Andy Leszczynski
It is on Windows, Linux, Python 2.3:
[GCC 3.3.2 (Mandrake Linux 10.0 3.3.2-6mdk)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a=1.1
>>> a
1.1001
>>>
Is it normal?
Andy
--
http://mail.python.org/mailman/listinfo/python-list


Re: On eval and its substitution of globals

2005-02-23 Thread Paddy
Leif wrote:
" If globals were deeply substituted when using eval, the program would
presumably print "42\n24", which would be far from intuitive. If you
limit the deep substitution to functions in the same module, you're
creating a confusing special case.  "

I guess I need outside opinions on what should be normal. The
documentation does not mention the case of 'nested' function calls and
so the present action could be documented but  there is still the issue
of "should there be a 'deep'  globals substitution". I have such a
need, but this is the first time I have had to consider this whole
topic.
I do in fact have the case you mention. I am writing a module that will
manipulate functions of global variables where the functions are
defined in another module.
My module will evaluate those 'other module' functions supplying the
globals itself - which works fine, the problem comes when I create
derivative functions in my module that call the original 'other module'
functions, and then try and evaluate these derivatives supplying the
globals as before. The 'correct' action that I want is for the globals
I supply to eval to be used for all functions called by the code block
as well as for the code block itself.

- Pad.

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


Question about logfiles in Python

2005-02-23 Thread Courtis Joannis
Hello readers,

my name is Joannis Courtis and I study computer science in
Frankfurt/Germany. I hope you can help me, because I try to find a script
that helps me to filter logfiles which I received from the Microsoft
Exchange Server.
Can you help me, where I can find a script in Python.

Regards Joannis Courtis

-- 
Lassen Sie Ihren Gedanken freien Lauf... z.B. per FreeSMS
GMX bietet bis zu 100 FreeSMS/Monat: http://www.gmx.net/de/go/mail
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unicode(obj, errors='foo') raises TypeError - bug?

2005-02-23 Thread "Martin v. LÃwis"
Kent Johnson wrote:
Could this be handled with a try / except in unicode()? Something like 
this:
Perhaps. However, this would cause a significant performance hit, and
possbibly undesired side effects. So due process would require that the
interface of __unicode__ first, and then change the actual calls to it.
One thing that hasn't been pointed out in this thread yet is that the OP 
could just define __unicode__() on his class to do what he wants...
Actually, Steven Bethard wrote "You should either define __unicode__ or
call str() manually on the object."
Regards,
Martin
--
http://mail.python.org/mailman/listinfo/python-list


Dynamically pass a function arguments from a dict

2005-02-23 Thread Dan Eloff
You can take a dictionary of key/value pairs and pass it to a function as  
keyword arguments:

def func(foo,bar):
print foo, bar
args = {'foo':1, 'bar':2}
func(**args)
will print "1 2"
But what if you try passing those arguments to a function
def func2(bar,zoo=''):
print bar, zoo
How can you determine that func2 will only accept
bar and zoo, but not foo and call the function with
bar as an argument?
I know CherryPy does this, but it's not obvious from the source
how they pulled it off.
-Dan
--
http://mail.python.org/mailman/listinfo/python-list


Re: Communication between JAVA and python

2005-02-23 Thread Kent Johnson
Jacques Daussy wrote:
Hello
How can I transfert information between a JAVA application and a python 
script application. I can't use jython because, I must use python 
interpreter.I think to socket or semaphore, but can I use it on Windows 
plateform ?
Jython has an interpreter and Windows has sockets.
Kent
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with the sort() function

2005-02-23 Thread clementine
Thanks everyone!!:-) Nicks solution coupled with John's modifications
worked great for 2.2!! Yipeee...!!:):)


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


RE: reading only new messages in imaplib

2005-02-23 Thread Tony Meyer
[Raghul]
>>> Is it posssible to read only the new messages or unread
>>> messages using imaplib in python? If it is possible pls 
>>> specify the module or give a sample code.

[Tony Meyer]
>> This will print out the first 20 chars of each undeleted message. 
>> You should be able to figure out how to do what you want from it.
[...]

[Raghul]
> Received: by twmail.
> Received: from mail.
[...]
> it prints something like this. what it actually display.

Did you read what I wrote, or just run the code?  As I said, it displays the
first 20 characters of each undeleted message.  If you can't see where the
'first 20 characters' bit is in the code, then you really need to forget
about IMAP for the moment and start with the Python tutorial.

> And pls tell me what it actually does? I can't understand

>>> import imaplib

Imports the imaplib module.

>>> i = imaplib.IMAP4("mail.example.com")

Creates an imaplib.IMAP4 instance to be connected to the mail.example.com
server.

>>> i.login("username", "password")

Logs into the server with the username "username" and the password
"password".

>>> i.select()

Selects the inbox.

>>> for msg_num in i.search(None, "UNDELETED")[1][0].split():

Does an IMAP search for UNDELETED messages.  Assumes that [0] of the
response is "OK" and that [1] of the response is a tuple of the string of
the ids.  Splits the string on whitespace and iterates through it.

... msg = i.fetch(str(msg_num), "RFC822")

Fetches the message (header and body in RFC822 format) for the given message
number.

... print msg[1][0][1][:20]

Digs down through the response (use imaplib.debug = 4 to see it) to get the
message as a string.  Prints out 20 characters of it.

As basically everyone has said, you must read the IMAP RFC and understand it
in order to use imaplib.  Please do so.

=Tony.Meyer

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


Re: LC_ALL and os.listdir()

2005-02-23 Thread Kenneth Pronovici
On Wed, Feb 23, 2005 at 10:07:19PM +0100, "Martin v. Löwis" wrote:
> So we have three options:
> 1. skip this string, only return the ones that can be
>converted to Unicode. Give the user the impression
>the file does not exist.
> 2. return the string as a byte string
> 3. refuse to listdir altogether, raising an exception
>(i.e. return nothing)
> 
> Python has chosen alternative 2, allowing the application
> to implement 1 or 3 on top of that if it wants to (or
> come up with other strategies, such as user feedback).

Understood.  This appears to be the most flexible solution among the
three.

> >3) The proper "general" way to deal with this situation?
> 
> You can chose option 1 or 3; you could tell the user
> about it, and then ignore the file, you could try to
> guess the encoding (UTF-8 would be a reasonable guess).

Ok.

> >My goal is to build generalized code that consistently works with all
> >kinds of filenames.
> 
> Then it is best to drop the notion that file names are
> character strings (because some file names aren't). You
> do so by converting your path variable into a byte
> string. To do that, you could try
[snip]
> So your code would read
> 
> try:
>   path = path.encode(sys.getfilesystemencoding() or
>  sys.getdefaultencoding())
> except UnicodeError:
>   print >>sys.stderr, "Invalid path name", repr(path)
>   sys.exit(1)

This makes sense to me.  I'll work on implementing it that way.

Thanks for the in-depth explanation!

KEN

-- 
Kenneth J. Pronovici <[EMAIL PROTECTED]>
Personal Homepage: http://www.skyjammer.com/~pronovic/
"They that can give up essential liberty to obtain a little 
 temporary safety deserve neither liberty nor safety." 
  - Benjamin Franklin, Historical Review of Pennsylvania, 1759 
--
http://mail.python.org/mailman/listinfo/python-list


Re: Dealing with config files what's the options

2005-02-23 Thread Tom Willis
On Wed, 23 Feb 2005 20:15:47 +, Phil Jackson
<[EMAIL PROTECTED]> wrote:
> Tom Willis <[EMAIL PROTECTED]> writes:
> 
> > How are the expert pythoneers dealing with config files?
> 
> You could use the cPickle module if you don't mind your config files
> being unreadable by humans. There is also the shlex module for more
> powerful config file needs:
> 
> http://docs.python.org/lib/module-shlex.html
> 
> While I'm replying to you, would you mind if I take the opportunity to
> ask you to stop top-posting?
> 
> Thanks,
> 
> Phil
> --
> http://mail.python.org/mailman/listinfo/python-list
> 




I guess. 

It's just so inconvenient in gmail. 

But anything for you. I'll try to try. :)


Thanks for the info.

-- 
Thomas G. Willis
http://paperbackmusic.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: select + ssl

2005-02-23 Thread Donn Cave
In article <[EMAIL PROTECTED]>,
 Ktm <[EMAIL PROTECTED]> wrote:

> I don't have the same behaviour with two codes who are quite the same,
> one using SSL, the other not. I tested the programs with stunnel and
> telnet , respectively.

[... program source ...]

> The server blocks on recv here.

SSL is a layer on top of the socket.  It reads and writes
SSL protocol data on the socket connection, while its
recv() and send() methods return and accept the unencrypted
protocol payload (you already knew this.)

The select() function does not however deal with this layer,
it looks directly at the socket.  It's telling you that recv()
won't block -- but it means the recv(2) that SSL uses, not
the SSL.Connection.recv() that you have to use.

> In both case I don't send anything with the client. (Perhaps stunnel
> send something that I don't see ?)
> 
> Why does the server block ?

Probably you're seeing the initial exchange of data during
the SSL connection - certificates and so forth.  You may
find that after this is done, further exchanges will work
OK with select().  Or maybe not -- I really don't know enough
about SSL to predict this.

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


Re: Python and "Ajax technology collaboration"

2005-02-23 Thread Valentino Volonghi aka Dialtone
aurora <[EMAIL PROTECTED]> wrote:

> It was discussed in the last Bay Area Python Interest Group meeting.
> 
> Thursday, February 10, 2005
> Agenda: Developing Responsive GUI Applications Using HTML and HTTP
> Speakers: Donovan Preston
> http://www.baypiggies.net/
> 
> The author has a component LivePage for this. You may find it from  
> http://nevow.com/. Similar idea from the Javascript stuff but very Python
> centric.

As an example for that technology (LivePage) I have this:

http://vercingetorix.dyndns.org:20080/

Which is an online forum where the "Quote & Reply" function is done with
XMLHttpRequest and Python.

Implementing this stuff in the forum with Nevow ( the framework created
by Donovan who I help to develop ) was almost effortless. 

-- 
Valentino Volonghi aka Dialtone
Now Running MacOSX 10.3.8
Blog: http://vvolonghi.blogspot.com
http://weever.berlios.de
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unicode(obj, errors='foo') raises TypeError - bug?

2005-02-23 Thread Kent Johnson
Martin v. LÃwis wrote:
Steven Bethard wrote:
Yeah, I agree it's weird.  I suspect if someone supplied a patch for 
this behavior it would be accepted -- I don't think this should break 
backwards compatibility (much).

Notice that the "right" thing to do would be to pass encoding and errors
to __unicode__. If the string object needs to be told what encoding it
is in, why not any other other object as well?
Unfortunately, this apparently was overlooked, and now it is too late
to change it (or else the existing __unicode__ methods would all break
if they suddenly get an encoding argument).
Could this be handled with a try / except in unicode()? Something like this:
 >>> class A:
 ...   def u(self):  # __unicode__ with no args
 ... print 'A.u()'
 ...
 >>> class B:
 ...   def u(self, enc, err):  # __unicode__ with two args
 ... print 'B.u()', enc, err
 ...
 >>> def convert(obj, enc='ascii', err='strict'): # unicode() function 
delegates to u()
 ...   try:
 ... obj.u(enc, err)
 ...   except TypeError:
 ... obj.u()
 ...
 >>> convert(a)
A.u()
 >>> convert(a, 'utf-8', 'replace')
A.u()
 >>> convert(b)
B.u() ascii strict
 >>> convert(b, 'utf-8', 'replace')
B.u() utf-8 replace
As for using encoding and errors on the result of str() conversion
of the object: how can the caller know what encoding the result of
str() is in, reasonably? 
The same way that the caller will know the encoding of a byte string, or of the result of 
str(some_object) - in my experience, usually by careful detective work on the source of the string 
or object followed by attempts to better understand and control the encoding used throughout the 
application.

It seems more correct to assume that the
str() result in in the system default encoding.
To assume that in absence of any guidance, sure, that is consistent. But to ignore the guidance the 
programmer attempts to provide?

One thing that hasn't been pointed out in this thread yet is that the OP could just define 
__unicode__() on his class to do what he wants...

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


Re: Python and "Ajax technology collaboration"

2005-02-23 Thread Dave Brueck
John Willems wrote:
Interesting GUI developments, it seems. Anyone developed a "Ajax"
application using Python? Very curious
thx
(Ajax stands for:
XHTML and CSS;
dynamic display and interaction using the Document Object Model;
data interchange and manipulation using XML and XSLT;
asynchronous data retrieval using XMLHttpRequest;
and JavaScript binding everything together
We're using it in a couple of projects with Zope as the backend and it works 
really well - the web applications are way more responsive now (I'm hoping 
someone with lots of Zope knowledge will redo the ZMI itself using this approach).

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


Re: [EVALUATION] - E02 - Support for MinGW Open Source Compiler

2005-02-23 Thread Stephen Kellett
In message <[EMAIL PROTECTED]>, Ilias Lazaridis 
<[EMAIL PROTECTED]> writes
Stephen Kellett wrote:
[...]
Who's Guido?
Guido is the one, who should care by time about the status of the 
python-community.
Who is care by time?
--
Stephen Kellett
Object Media Limitedhttp://www.objmedia.demon.co.uk
RSI Information:http://www.objmedia.demon.co.uk/rsi.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python and "Ajax technology collaboration"

2005-02-23 Thread aurora
It was discussed in the last Bay Area Python Interest Group meeting.
Thursday, February 10, 2005
Agenda: Developing Responsive GUI Applications Using HTML and HTTP
Speakers: Donovan Preston
http://www.baypiggies.net/
The author has a component LivePage for this. You may find it from  
http://nevow.com/. Similar idea from the Javascript stuff but very Python  
centric.


Interesting GUI developments, it seems. Anyone developed a "Ajax"
application using Python? Very curious
thx
(Ajax stands for:
XHTML and CSS;
dynamic display and interaction using the Document Object Model;
data interchange and manipulation using XML and XSLT;
asynchronous data retrieval using XMLHttpRequest;
and JavaScript binding everything together
ie Google has used these technologies to build Gmail, Google Maps etc.
more info:
http://www.adaptivepath.com/publications/essays/archives/000385.php)
--
http://mail.python.org/mailman/listinfo/python-list


Re: LC_ALL and os.listdir()

2005-02-23 Thread "Martin v. Löwis"
Serge Orlov wrote:
Shouldn't os.path.join do that? If you pass a unicode string
and a byte string it currently tries to convert bytes to characters
but it makes more sense to convert the unicode string to bytes
and return two byte strings concatenated.
Sounds reasonable. OTOH, this would be the only (one of a very
few?) occasion where Python combines byte+unicode => byte.
Furthermore, it might be that the conversion of the Unicode
string to a file name fails as well.
That said, I still think it is a good idea, so contributions
are welcome.
Regards,
Martin
--
http://mail.python.org/mailman/listinfo/python-list


msnp group chats

2005-02-23 Thread sparda713
I'm currently using the msnp.py module in a project.  We are trying to
implement a group chats feature.  Has anyone had any success in doing
this or know how to do this?  We have it doing single chats, but we
can't figure out how MSN is adding the multiple invites.  Any help
would be greatly appreciated!

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


Re: LC_ALL and os.listdir()

2005-02-23 Thread Serge Orlov
"Martin v. Löwis" wrote:
>> My goal is to build generalized code that consistently works with all
>> kinds of filenames.
>
> Then it is best to drop the notion that file names are
> character strings (because some file names aren't). You
> do so by converting your path variable into a byte
> string. To do that, you could try
>
> path = path.encode(sys.getfilesystemencoding())

Shouldn't os.path.join do that? If you pass a unicode string
and a byte string it currently tries to convert bytes to characters
but it makes more sense to convert the unicode string to bytes
and return two byte strings concatenated.

  Serge.


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


Python and "Ajax technology collaboration"

2005-02-23 Thread John Willems

Interesting GUI developments, it seems. Anyone developed a "Ajax"
application using Python? Very curious

thx

(Ajax stands for:
XHTML and CSS;
dynamic display and interaction using the Document Object Model;
data interchange and manipulation using XML and XSLT;
asynchronous data retrieval using XMLHttpRequest;
and JavaScript binding everything together

ie Google has used these technologies to build Gmail, Google Maps etc.

more info:
http://www.adaptivepath.com/publications/essays/archives/000385.php)

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


Re: LC_ALL and os.listdir()

2005-02-23 Thread "Martin v. Löwis"
Kenneth Pronovici wrote:
   1) Why LC_ALL has any effect on the os.listdir() result? 
The operating system (POSIX) does not have the inherent notion
that file names are character strings. Instead, in POSIX, file
names are primarily byte strings. There are some bytes which
are interpreted as characters (e.g. '\x2e', which is '.',
or '\x2f', which is '/'), but apart from that, most OS layers
think these are just bytes.
Now, most *people* think that file names are character strings.
To interpret a file name as a character string, you need to know
what the encoding is to interpret the file names (which are byte
strings) as character strings.
There is, unfortunately, no operating system API to carry
the notion of a file system encoding. By convention, the locale
settings should be used to establish this encoding, in particular
the LC_CTYPE facet of the locale. This is defined in the
environment variables LC_CTYPE, LC_ALL, and LANG (searched
in this order).
   2) Why only 3 of the 4 files come back as unicode strings?
If LANG is not set, the "C" locale is assumed, which uses
ASCII as its file system encoding. In this locale,
'\xe2\x99\xaa\xe2\x99\xac' is not a valid file name (atleast
it cannot be interpreted as characters, and hence not
be converted to Unicode).
Now, your Python script has requested that all file names
*should* be returned as character (ie. Unicode) strings, but
Python cannot comply, since there is no way to find out what
this byte string means, in terms of characters.
So we have three options:
1. skip this string, only return the ones that can be
   converted to Unicode. Give the user the impression
   the file does not exist.
2. return the string as a byte string
3. refuse to listdir altogether, raising an exception
   (i.e. return nothing)
Python has chosen alternative 2, allowing the application
to implement 1 or 3 on top of that if it wants to (or
come up with other strategies, such as user feedback).
3) The proper "general" way to deal with this situation?
You can chose option 1 or 3; you could tell the user
about it, and then ignore the file, you could try to
guess the encoding (UTF-8 would be a reasonable guess).
My goal is to build generalized code that consistently works with all
kinds of filenames.
Then it is best to drop the notion that file names are
character strings (because some file names aren't). You
do so by converting your path variable into a byte
string. To do that, you could try
path = path.encode(sys.getfilesystemencoding())
This should work in most cases; Python will try to
determine the file system encoding from the environment,
and try to encode the file. Notice, however:
- on some systems, getfilesystemencoding may return None,
  if the encoding could not be determined. Fall back
  to sys.getdefaultencoding in this case.
- depending on where you got path from, this may
  raise a UnicodeError, if the user has entered a
  path name which cannot be encoding in the file system
  encoding (the user may well believe that she has
  such a file on disk).
So your code would read
try:
  path = path.encode(sys.getfilesystemencoding() or
 sys.getdefaultencoding())
except UnicodeError:
  print >>sys.stderr, "Invalid path name", repr(path)
  sys.exit(1)
Ultimately, all I'm trying to do is copy some files
around.  I'd really prefer to find a programmatic way to make this work
that was independent of the user's configured locale, if possible.
As long as you manage to get a byte string from the path
entered, all should be fine.
Regards,
Martin
--
http://mail.python.org/mailman/listinfo/python-list


Re: LC_ALL and os.listdir()

2005-02-23 Thread "Martin v. Löwis"
Kenneth Pronovici wrote:
I think that I can solve my problem by just converting any unicode
strings from configuration into utf-8 simple strings using encode().
Using this solution, all of my existing regression tests still pass, and
my code seems to make it past the unusual directory.
See my other post. UTF-8 might be the wrong choice: the path might be
encoded as, say, ISO-8859-1 on disk, in which case an UTF-8-encoded
path would not be found.
Regards,
Martin
--
http://mail.python.org/mailman/listinfo/python-list


Re: unicode(obj, errors='foo') raises TypeError - bug?

2005-02-23 Thread "Martin v. LÃwis"
Steven Bethard wrote:
Yeah, I agree it's weird.  I suspect if someone supplied a patch for 
this behavior it would be accepted -- I don't think this should break 
backwards compatibility (much).
Notice that the "right" thing to do would be to pass encoding and errors
to __unicode__. If the string object needs to be told what encoding it
is in, why not any other other object as well?
Unfortunately, this apparently was overlooked, and now it is too late
to change it (or else the existing __unicode__ methods would all break
if they suddenly get an encoding argument).
As for using encoding and errors on the result of str() conversion
of the object: how can the caller know what encoding the result of
str() is in, reasonably? It seems more correct to assume that the
str() result in in the system default encoding.
If you can follow so far(*): if it is the right thing to ignore the
encoding argument for the case that the object was str() converted,
why should the errors argument not be ignored? It is inconsistent
to ignore one parameter to the decoding but not the other.
Regards,
Martin
(*) I admit that the reasoning for ignoring the encoding is
somewhat flawed. There are some types (e.g. numbers) where
str() always uses the system encoding (i.e. ASCII - actually,
it always uses ASCII, no matter what the system encoding is).
There may be types where the encoding of the str() result
is not ASCII, and the caller happens to know what it is,
but I'm not aware of any such type.
--
http://mail.python.org/mailman/listinfo/python-list


Re: On eval and its substitution of globals

2005-02-23 Thread Leif K-Brooks
Paddy wrote:
I had to do as you suggest but I was thinking either it was a kludge,
 and there should be a 'deep' substitution of globals, or that there
was a good reason for it to work as it does and some magician would
tell me.
If there was deep substitution of globals, how would functions imported 
from different modules behave? Consider this:

--- foo.py ---
from bar import func
data = 24
print func()
print eval('func()', globals(), locals())
--- bar.py ---
data = 42
def func():
return data

If globals were deeply substituted when using eval, the program would 
presumably print "42\n24", which would be far from intuitive. If you 
limit the deep substitution to functions in the same module, you're 
creating a confusing special case.
--
http://mail.python.org/mailman/listinfo/python-list


Yahoo! Auto Response

2005-02-23 Thread ben-fuzzybear
Hi -

This is the "vacation" program; I'm working for my owner, Ben. The account to 
which you have sent your mail is going to be discontinued at at the end of July 
(Yahoo's mail service has deteriorated well past "abysmal" into "nightmarishly 
bad", and the trend shows no sign of stopping). Please update your information 
for Ben; his new email address is at the "callahans.org" domain under the 
username of "ben" (it is not shown as a complete address in order to foil 
stupid spambots; use it as "[EMAIL PROTECTED]".)

Sorry about any inconvenience, and have a nice day.






Original Message:


X-YahooFilteredBulk: 61.1.74.98
Authentication-Results: mta106.mail.mud.yahoo.com
  from=python.org; domainkeys=neutral (no sig)
X-Originating-IP: [61.1.74.98]
Return-Path: 
Received: from 61.1.74.98  (EHLO yahoo.com) (61.1.74.98)
  by mta106.mail.mud.yahoo.com with SMTP; Wed, 23 Feb 2005 12:25:29 -0800
From: python-list@python.org
To: [EMAIL PROTECTED]
Subject: Re: Message Error
Date: Thu, 24 Feb 2005 01:55:13 +0530
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="=_NextPart_000_0016=_NextPart_000_0016"
X-Priority: 3
X-MSMail-Priority: Normal

This is a multi-part message in MIME format.

--=_NextPart_000_0016=_NextPart_000_0016
Content-Type: text/plain;
charset="Windows-1252"
Content-Transfer-Encoding: 7bit


For further details see the attachment.


+++ Attachment: No Virus found
+++ Kaspersky AntiVi
_
DO YOU YAHOO!?
Get your free @yahoo.com address at http://mail.yahoo.com

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


Re: Pythoncard - Mistake in walkthrough?

2005-02-23 Thread It's me
As stated in the on-line WalkThrough, the information there was written for
an older version of the program.


"Deltones" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hi all,
>
> I'm just getting into Python/wxPython/Pythoncard and I'm trying the
> tutorial from this page:
> http://pythoncard.sourceforge.net/walkthrough1.html
>
> Is it me who's totally dense or there's some sort of confusion with
> this tutorial?
>
> Here's what is said in the tutorial:
>
> Open the file starter1.py in your Python-aware editor of choice. The
> Python script is, as you'd expect, brief and to the point. Here's the
> important part to focus on:
>
> def on_menuFileExit_select(self, event):
> pass
>
>
> But here's the starter1.py code:
>
> #!/usr/bin/python
>
> from PythonCard import model
>
> class Minimal(model.Background):
> pass
>
> if __name__ == '__main__':
> app = model.Application(Minimal)
> app.MainLoop()
>
>
> As you can see, the on_menu line is not in the starter1.py original
> script, so I guessed that it should be a part of the Minimal class.
>
> Then the tutorial ask me to replace the on_menu "pass" line with:
>
> result = dialog.alertDialog(self, 'It works!', 'Showing Off')
>
> but when you run the script, it runs, but clicking on Exit does not
> display any dialog box. I did change the import line to include
> dialog.
>
> Is there something I'm not seeing here or there is really a mistake
> with the walkthrough?
>
> Thanks
>
> Denis


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


Re: Problem with minidom and special chars in HTML

2005-02-23 Thread Jarek Zgoda
Horst Gutmann napisał(a):
Don't use minidom or convert HTML4 to XHTML and change declaration of 
doctype.

This was just a bad example :-) I get the same problem with XHTML in the 
doctype. The funny thing here IMO is, that the special chars are simply 
removed. No warning, no nothing :-(
As Fredrik pointed out, it's minidom that cann't fetch DTD from remote 
location. Download this DTD file to your local machine (it lies at 
exactly this URI), try changing PUBLIC identifier to SYSTEM and give 
local path to this file.

--
Jarek Zgoda
http://jpa.berlios.de/ | http://www.zgodowie.org/
--
http://mail.python.org/mailman/listinfo/python-list


Communication between JAVA and python

2005-02-23 Thread Jacques Daussy
Hello
How can I transfert information between a JAVA application and a python 
script application. I can't use jython because, I must use python 
interpreter.I think to socket or semaphore, but can I use it on Windows 
plateform ?

thanks a lot

jack 


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


Re: Dealing with config files what's the options

2005-02-23 Thread Phil Jackson
Tom Willis <[EMAIL PROTECTED]> writes:

> How are the expert pythoneers dealing with config files?

You could use the cPickle module if you don't mind your config files
being unreadable by humans. There is also the shlex module for more
powerful config file needs:

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

While I'm replying to you, would you mind if I take the opportunity to
ask you to stop top-posting?

Thanks,

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


Re: assert 0, "foo" vs. assert(0, "foo")

2005-02-23 Thread Carl Banks

Thomas Guettler wrote:
> Is it possible to change future python versions, that
> assert accept parenthesis?


It's possible, but extremely unlikely that it will ever happen.  assert
is not a function, but a statement (like print).  Statements don't use
parentheses; when you use parentheses, it considers that a tuple.

For example, if you try this with print:

print ("hello","world")

you see that in prints out a tuple value, rather than treating "hello"
and "world" as arguments.  Same thing with assert.


-- 
CARL BANKS

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


Re: [EVALUATION] - E02 - Support for MinGW Open Source Compiler

2005-02-23 Thread Nick Vargish
Ilias Lazaridis <[EMAIL PROTECTED]> writes:

> Guido is the one, who should care by time about the status of the
> python-community.

That one crashed my parser.

> Thank's for every bit of contribution, which has made this thread an
> worthfull insight into the python-community.

To really get a sense of the Python "community" (at least the Usenet
branch), you should see how it responds to typical questions and
requests for help. The response you received is not really typical,
because your attitude has been atypical.

Just sayin',

Nick

-- 
#  sigmask  ||  0.2  ||  20030107  ||  public domain  ||  feed this to a python
print reduce(lambda x,y:x+chr(ord(y)-1),' Ojdl!Wbshjti!=obwAcboefstobudi/psh?')
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: On eval and its substitution of globals

2005-02-23 Thread Paddy
Thanks Kent for your reply.
I had to do as you suggest but I was thinking either it was a kludge,
and there should be a 'deep' substitution of globals, or that there was
a good reason for it to work as it does and some magician would tell
me.
Oh, the third reason could be that it was first implimented that way
and no-one has submitted a patch of course.

Could someone clue me in?

Ta,  Paddy.

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


select + ssl

2005-02-23 Thread Ktm
Hello,
I don't have the same behaviour with two codes who are quite the same,
one using SSL, the other not. I tested the programs with stunnel and
telnet , respectively.
Here are the first code :

#!/usr/bin/python
from select import select
import socket
if __name__ == '__main__':
   s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
   s.bind(('', 6001))
   s.listen(5)
   ready_read = {}
   ready_send = {}
   ready_read[s] = s
   while True:
   rs, ws, _ = select(ready_read.keys(), ready_send.keys(), [], 2)
   print '.'
   for r in rs:
   if r == s:
   (cli, addr) = s.accept()
   ready_send[cli] = cli
   ready_read[cli] = cli
   else:
   ret = r.recv(1000)
   print 'ret =', ret
   for w in ws:
   w.send('you have to give up')
 

 The client receive the 'you have to give up' sentence every two seconds.
The second code is :
 

#!/usr/bin/python
from select import select
import socket
from   OpenSSL import SSL
import os
def verify_cb():
   return ok
if __name__ == '__main__':
   dir = ''
   ctx = SSL.Context(SSL.SSLv23_METHOD)
   ctx.set_options(SSL.OP_NO_SSLv2)
   ctx.set_verify(SSL.VERIFY_NONE, verify_cb)
   ctx.use_privatekey_file (os.path.join(dir, 'server.pkey'))
   ctx.use_certificate_file(os.path.join(dir, 'server.cert'))
   ctx.load_verify_locations(os.path.join(dir, 'CA.cert'))
   s = SSL.Connection(ctx, socket.socket(socket.AF_INET,
socket.SOCK_STREAM))
   #s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
   s.bind(('', 6000))
   s.listen(5)
   s.setblocking(0)
   ready_read = {}
   ready_send = {}
   ready_read[s] = s
   while True:
   rs, ws, _ = select(ready_read.keys(), ready_send.keys(), [], 2)
   print '.'
   for r in rs:
   if r == s:
   (cli, addr) = s.accept()
   ready_send[cli] = cli
   ready_read[cli] = cli
   else:
   ret = r.recv(1000)
   print 'ret =', ret
   for w in ws:
   w.send('you have to give up')
 


The server blocks on recv here.
In both case I don't send anything with the client. (Perhaps stunnel
send something that I don't see ?)
Why does the server block ?
Kototama
--
http://mail.python.org/mailman/listinfo/python-list


Re: user interface for python

2005-02-23 Thread Mike Meyer
Scott David Daniels <[EMAIL PROTECTED]> writes:

> Thomas Guettler wrote:
> You can write portable programs (if you test across platforms).   The
> only truly portable programs in any language are abstract.  Once you
> start dealing with I/O and the real world, you inevitably have to face
> issues one circumstance at a time.  Both Tkinter and wxPython spend a
> lot of effort in reducing the work you have to do.  Don't fool
> yourself with a manager-friendly slogan; programs must be tested to
> work.  Any I/O heavy (or threaded, or ) application running on two
> platforms will take more work than on a single platform.  Python and
> wxPython or Tkinter, for example, _allow_ you to write portable
> programs, but they don't _guarantee_ it.


"There are no portable programs, only ported programs."

   -- John Gilmore (?)
   
  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Don't understand global variables between modules

2005-02-23 Thread Bart van Deenen
Hi

thanks for the answer. Coming from C and C++ this behaviour wasn't
really obvious to me. I still love Python though :-) Most elegant
language I've ever seen.

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


Re: Don't understand global variables between modules

2005-02-23 Thread Bart van Deenen
Fredrik Lundh <[EMAIL PROTECTED]> wrote:

> because running a script isn't the same thing as importing it.  try adding
> "print __name__" lines before your other print statements so you can see
> who's printing what.
> 
> > Is there more than one global space?
> 
> in this case, there are more module namespaces than you think.
> this page might help (especially the "Using Modules as Scripts" section):
> http://effbot.org/zone/import-confusion.htm

Thanks for your answer, and also thanks for effbot. Lots of good tips. 

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


Re: PyEphem on Win32 -- 2nd try

2005-02-23 Thread John Roth
A quick look at the site, and following the link to
the XEphem site reveals that the Windows port
of XEphem uses Cygwin. AFAIK, that's not
compatible with the usual CPython implementation.
Again, AFAIK, you'll either have to use a Python
port compiled under Cygwin, or you'll have to
find a Windows port compiled with VS 6 or
higher.
Someone who knows more about those
issues will have to take it from here.
John Roth
<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
A second request for help...
Has anyone run the PyEphem ephemeris application under WinXP?
http://rhodesmill.org/brandon/projects/pyephem.html
I have compiled it with Visual Studio 6 and it crashes Python with a
simple
import ephem
ephem.date('1994/7/16')
Identical code works fine under Linux. I suspect that the problem has
to do with a parser built into the c shell for the c code that the
app wraps around.  However, I am not good enough at c to spot the
error.
I am running ActivePython 2.3.5 Build 236 on a WinXP SP2 system with
Visual Studio 6 patched to sp6.
I would appreciate either help from a c guru who knows how to wrap
python around c or a pointer to another list where experts might
reside.
- ---
Cheers, David Flory
-BEGIN PGP SIGNATURE-
Version: PGP 8.1
iQA/AwUBQhy551e2/rcN3lp8EQIu2gCfRyDmSCtiP4uB2qKMtIvjcOOsNUkAn1FD
rir+BKqfDqZ0P+lKcwfgdQPu
=5+at
-END PGP SIGNATURE-
--
http://mail.python.org/mailman/listinfo/python-list


Re: reading only new messages in imaplib

2005-02-23 Thread Kartic
Raghul said the following on 2/22/2005 11:24 PM:
Is it posssible to read only the new messages or unread messages using
imaplib in python? If it is possible pls specify the module or give a
sample code.
Thanks in advance

import imaplib, sys
conn = imaplib.IMAP4_SSL(host='mail.example.com')
# or conn =imaplib.IMAP4(host='mail.example.com') for no SSL
try:
	(retcode, capabilities) = conn.login('user', 'pass')
except:
	print sys.exc_info()[1]
	sys.exit(1)
conn.select(readonly=1) # Select inbox or default namespace
(retcode, messages) = conn.search(None, '(UNSEEN)')
if retcode == 'OK':
	for message in messages[0].split(' '):
		print 'Processing :', message
		(ret, mesginfo) = conn.fetch(message, '(BODY[HEADER.FIELDS (SUBJECT 
FROM)])')
		if ret == 'OK':
			print mesginfo,'\n',30*'-'
conn.close()

Please also go thru the IMAP RFC to learn more about the flags field and 
the IMAP protocol in general. If you're developing something serious 
using IMAP, it will be very beneficial to you to understand the protocol.

http://www.imap.org/papers/biblio.html
Thanks,
-Kartic
--
http://mail.python.org/mailman/listinfo/python-list


Re: running a shell command from a python program

2005-02-23 Thread aurora
In Python 2.4, use the new subprocess module for this. It subsume the  
popen* methods.

Hi,
   I'm a newbie, so please be gentle :-)
How would I run a shell command in Python?
Here is what I want to do:
I want to run a shell command that outputs some stuff, save it into a
list and do stuff with the contents of that list.
I started with a BASH script actually, until I realized I really needed
better data structures :-)
Is popen the answer? Also, where online would I get access to good
sample code that I could peruse?
I'm running 2.2.3 on Linux, and going strictly by online doc so far.
Thanks!
S C
--
http://mail.python.org/mailman/listinfo/python-list


Re: PyQt and Python 2.4 - also WinXP LnF?

2005-02-23 Thread Eric Jardim
Simon John - Feb 13, 4:24 pm:
> After building with MSVC6 (Python 2.3.5 and 2.4  versions) I've
noticed
> that the ToolTips don't seem to work in the GPL version.

Free (GPL) Qt3 port to Windows is not complete. They indeed need help
to conclude their job.  And as Trolltech is not going to release Qt3
under GPL, to "encorage" people using Qt4, this work of porting is not
useless.


> MSVC6 is about twice as fast to build as MinGW

I think it is because they use precompiled headers. But I prefer to
wait rather than using MSVC.

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


Re: Style guide for subclassing built-in types?

2005-02-23 Thread Michael Spencer
[EMAIL PROTECTED] wrote:
Kent Johnson wrote:
[EMAIL PROTECTED] wrote:
p.s. the reason I'm not sticking to reversed or even reverse :
suppose
the size of the list is huge.
reversed() returns an iterator so list size shouldn't be an issue.
What problem are you actually trying to solve?
Kent

Oh, you are right.
Actually, it's more complicated than simple reversion. The list order
should be somewhat "twisted" and the list is big.
For example,
[1,2,3,4,5,6,7,8,9,10]
--> [10,9,8,7,6,1,2,3,4,5]
so __getitem__(self,i) => __getitem__(self,-i-1) if i
I'd like to have TwistedList class that takes in an original list and
pretends as if it is twisted actually. However, I have to have
duplicate codes here and there to make it act like a "list", say assert
twisted_list == [10,9,...] and for each in twisted_list and etc.
If you want a twisted 'view' of an existing list, then a wrapper makes most 
sense.
If, however, you only need the twisted version, why not simply override 
list.__init__ (and extend, append etc... as required):

 >>> class rev_list(list):
 ...def __init__(self, iterable):
 ...list.__init__(self, iterable[::-1])
 ...
 >>> l = rev_list([1,2,3])
 >>> l
 [3, 2, 1]
Michael
--
http://mail.python.org/mailman/listinfo/python-list


Re: PyQt and Python 2.4 - also WinXP LnF?

2005-02-23 Thread Eric Jardim
Simon John - Feb 10, 11:51 am:
> I've just read the Qt4 GPL for Windows will only support gcc (and
maybe
> MinGW) anyway, not BCC or VisualC++ (or it's free equivalents), so it
> looks like it would be a daunting task to actually build PyQt

Why? I think that it is fair. Why a Free Software developer should buy
VC++ licenses to build free Qt? It is nonsense. "gcc" works under
Windows, and that is enough.


> I guess a lot of this licensing crap will change when Qt4 GPL is
> actually released, but it's still looking like commercial Qt is the
> only "easy" way to go, and the Trolls are just making a "difficult"
GPL
> version to shut people up!

What is the matter with you? When Qt is released GPL for Windows, with
the support from Trolltech, if they do not  give you a ".exe" version
of Qt, then someone should compile it. There is no need to compile it
every time.

I think Trolltech is right. If can afford Windows and VisualStudio, you
can also afford Qt. Or maybe you are a "pirate".

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


Re: Selective HTML doc generation

2005-02-23 Thread Brian van den Broek
Graham said unto the world upon 2005-02-23 09:42:
Hi. I'm looking for a documentation generation tool (such as pydoc,
epydoc, happydoc, etc.) that will allow me to filter what it includes
in
it's output.
I only want the reader to know about classes and methods in my package
if if the classes have docstrings. I've got a large package that is
used
by relatively non-technical users (and yet they write Python!) that
documents the public API with docstrings. I don't want to clutter their
view of the world with links to the package's internal classes and
documentation that covers things like __special__ methods.
Anybody know of anything that let's you do it? I realise I may end up
doing some hacking here but don't want to repeat work unnecessarily.
Cheers,
Graham
Hi Graham,
 I'm not at all an expert 
OK, that out of the way:
I recently wanted pydoc to display information about my methods whose 
names started with one or more underscores, so that I could see in the 
docs for the objects in my first bigger than small project.

I managed with a small change to the visiblename function of pydoc.py.
It looks to me that this is also the place where you'd want to put in 
code to filter for only treating objects with docstrings. *How* to do 
that is something I've not read enough of pydoc.py to speak to.

Omitting special methods is easy, though. The code says:
# Private names are hidden, but special names are displayed.
if name.startswith('__') and name.endswith('__'): return 1
So, just change the 1 to a 0. (The `private' logic is a few lines 
down.) Easy :-)

Hope that is at least of some help. Best,
Brian vdB
--
http://mail.python.org/mailman/listinfo/python-list


Re: LC_ALL and os.listdir()

2005-02-23 Thread Kenneth Pronovici
On Wed, Feb 23, 2005 at 01:03:56AM -0600, Kenneth Pronovici wrote:
[snip]
> Today, I accidentally ran across a directory containing three "normal"
> files (with ASCII filenames) and one file with a two-character unicode
> filename.  My code, which was doing something like this:
>
>for entry in os.listdir(path):   # path is 
>   entrypath = os.path.join(path, entry)
> 
> suddenly started blowing up with the dreaded unicode error:
> 
>UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in 
>position 1: ordinal not in range(128)

Sorry to reply to my own note, but after sleeping on it, I think I've
come up with a reasonable solution.  Now that I've dug further and my
eyes are less bleery, everything seems to work as long as I only pass in
simple strings to the filesystem functions.  

I think that I can solve my problem by just converting any unicode
strings from configuration into utf-8 simple strings using encode().
Using this solution, all of my existing regression tests still pass, and
my code seems to make it past the unusual directory.

>[u'README.strange-name', '\xe2\x99\xaa\xe2\x99\xac', 
> u'utflist.long.gz', u'utflist.cp437.gz', u'utflist.short.gz']
> 
> Note that in this second result, element [1] is not a unicode string
> while the other three elements are.

I'm still confused as to why this happens, but since I work around it, I
guess I don't care so much.

Thanks,

KEN

-- 
Kenneth J. Pronovici <[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Comm. between Python and PHP

2005-02-23 Thread Nils Emil P.Larsen
Hello

Sorry for not being too exact in my request!

>If the data you want to pass is structured then you might consider
>XML-RPC which is a cross platform way of passing structured data

XML-RPC looks like something very suitable for my needs. It seems
Python handles the remote procedure calls very easily (almost like
local functions).
It also works quite well in PHP. I didn't recompile anything but
downloaded Keith Devens XML-RPC Library (500 lines code). With this I
can call RPC-functions almost as easily as with Python. It took me
just about an hour to get it working...

Thanks everybody!

Nils Emil P. Larsen


--
My reply-address is valid.   www.bios-flash.dk
Min svar-adresse er gyldig.  Redning af døde BIOS'er
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Comm. between Python and PHP

2005-02-23 Thread Nils Emil P.Larsen
Hello

>Python is perfectly capable of generating HTML.  You don't have to demean
>yourself by working in PHP.

Thanks for the tip about using Python instead of PHP to generate web
pages. I may follow it.

Nils Emil
--
My reply-address is valid.   www.bios-flash.dk
Min svar-adresse er gyldig.  Redning af døde BIOS'er
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [EVALUATION] - E02 - Support for MinGW Open Source Compiler

2005-02-23 Thread Ilias Lazaridis
Stephen Kellett wrote:
[...]
Who's Guido?
Guido is the one, who should care by time about the status of the 
python-community.

-
I've send an addition CC of this message to the python-foundation, which 
 will hopefully take some steps to improve the build-system.

[EVALUATION] - E02 - Support for MinGW Open Source Compiler
Essence:
http://groups-beta.google.com/group/comp.lang.python/msg/5ba2a0ba55d4c102
-
Thank's for every bit of contribution, which has made this thread an 
worthfull insight into the python-community.

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


Arrow-keys bug.

2005-02-23 Thread Daniel Alexandre
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Hi there.
I'm making a talker's base in python and i'm with a serious bug in it.
Everytime a client connects to the talker and presses for ex. the arrow 
key lets say twice, the following characters appears in it's screen: 
Ë[[AË[[A, if he presses enter to send that characters to all the users 
in the talker, the user's screen will go up two lines, and the input 
line will be there, replacing older text, instead of being where it 
should, in the bottom of the screen; this also works for the down key 
and for home, end, etc. Does anyone here knows how I can strip those 
keys? Thanks in advance.
- -- 
Cumprimentos,
Daniel Alexandre ( [EMAIL PROTECTED] )
Chave pÃblica PGP: http://student.dei.uc.pt/~dfcruz/pubring.html
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.4 (Darwin)

iD8DBQFCHMAEL3+DjgQV3LgRApyBAJ9iPL428OkF1vHwTu61F6zQIz0SeQCg03D+
NAp+hY/10+IPUQa0T1fGjGY=
=ooz8
-END PGP SIGNATURE-
--
http://mail.python.org/mailman/listinfo/python-list


Re: [EVALUATION] - E02 - Support for MinGW Open Source Compiler

2005-02-23 Thread Stephen Kellett
In message <[EMAIL PROTECTED]>, George Sakkis 
<[EMAIL PROTECTED]> writes
"Ilias Lazaridis" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
Grant Edwards wrote:
[...]
> Um, you realize that nobody in this thread takes you the least
> bit seriously and people are just poking you with a stick to
> watch you jump?
jump:
[EVALUATION] - E02 - Support for MinGW Open Source Compiler
Essence:
http://groups-beta.google.com/group/comp.lang.python/msg/5ba2a0ba55d4c102

Lol, this guy is hopeless :-)
Who's Guido?
--
Stephen Kellett
Object Media Limitedhttp://www.objmedia.demon.co.uk
RSI Information:http://www.objmedia.demon.co.uk/rsi.html
--
http://mail.python.org/mailman/listinfo/python-list


PyEphem on Win32 -- 2nd try

2005-02-23 Thread Flory
 
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

A second request for help... 

Has anyone run the PyEphem ephemeris application under WinXP?
http://rhodesmill.org/brandon/projects/pyephem.html 
I have compiled it with Visual Studio 6 and it crashes Python with a
simple

>>> import ephem
>>> ephem.date('1994/7/16')

Identical code works fine under Linux. I suspect that the problem has
to do with a parser built into the c shell for the c code that the
app wraps around.  However, I am not good enough at c to spot the
error.

I am running ActivePython 2.3.5 Build 236 on a WinXP SP2 system with
Visual Studio 6 patched to sp6.

I would appreciate either help from a c guru who knows how to wrap
python around c or a pointer to another list where experts might
reside.
- ---
Cheers, David Flory

-BEGIN PGP SIGNATURE-
Version: PGP 8.1

iQA/AwUBQhy551e2/rcN3lp8EQIu2gCfRyDmSCtiP4uB2qKMtIvjcOOsNUkAn1FD
rir+BKqfDqZ0P+lKcwfgdQPu
=5+at
-END PGP SIGNATURE-

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


Re: kill a process in XP

2005-02-23 Thread Dave Brueck
Tor Erik Sønvisen wrote:
From my Python-program I spawn a new process. When using P_NOWAIT spawnl 
returns the pid but in windows it returns a process handle.
Later I want to kill this process. How can I do this when I only have the 
process handle?
Try ctypes - if it's really a Windows handle, then this should work:
from ctypes import *
windll.kernel32.TerminateProcess(h, 0) # or whatever return code you want
-Dave
--
http://mail.python.org/mailman/listinfo/python-list


Re: [EVALUATION] - E02 - Support for MinGW Open Source Compiler

2005-02-23 Thread George Sakkis
"Ilias Lazaridis" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
> Grant Edwards wrote:
> [...]
> > Um, you realize that nobody in this thread takes you the least
> > bit seriously and people are just poking you with a stick to
> > watch you jump?
>
> jump:
>
> [EVALUATION] - E02 - Support for MinGW Open Source Compiler
> Essence:
> http://groups-beta.google.com/group/comp.lang.python/msg/5ba2a0ba55d4c102


Lol, this guy is hopeless :-)

George


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


Pythoncard - Mistake in walkthrough?

2005-02-23 Thread Deltones
Hi all,

I'm just getting into Python/wxPython/Pythoncard and I'm trying the
tutorial from this page:
http://pythoncard.sourceforge.net/walkthrough1.html

Is it me who's totally dense or there's some sort of confusion with
this tutorial?

Here's what is said in the tutorial:

Open the file starter1.py in your Python-aware editor of choice. The
Python script is, as you'd expect, brief and to the point. Here's the
important part to focus on:

def on_menuFileExit_select(self, event):
pass


But here's the starter1.py code:

#!/usr/bin/python

from PythonCard import model

class Minimal(model.Background):
pass

if __name__ == '__main__':
app = model.Application(Minimal)
app.MainLoop()


As you can see, the on_menu line is not in the starter1.py original
script, so I guessed that it should be a part of the Minimal class.

Then the tutorial ask me to replace the on_menu "pass" line with:

result = dialog.alertDialog(self, 'It works!', 'Showing Off')

but when you run the script, it runs, but clicking on Exit does not
display any dialog box. I did change the import line to include
dialog.

Is there something I'm not seeing here or there is really a mistake
with the walkthrough?

Thanks

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


Re: [perl-python] exercise: partition a list by equivalence

2005-02-23 Thread Paul McGuire
Please consider my submission also (Python 2.3-compatible).

-- Paul McGuire

.import sets
.
.input = [[1, 2], [3, 4], [2, 3], [4, 5]]
.input = [[1, 2], [3, 4], [4, 5]]
.input = [[1, 2],[2,1], [3, 4], [4, 5],[2,2],[2,3],[6,6]]
.
.def merge(pairings):
.ret = []
.for a,b in pairings:
.s1 = None
.s2 = None
.for s in ret:
.if a in s or b in s:
.if s1 is None:
.s1 = s
.else:
.s2 = s
.break
.else:
.for s in ret:
.if a in s:
.s.add(b)
.break
.elif b in s:
.s.add(a)
.break
.else:
.ret.append(sets.Set([a,b]))
.continue
.ret.remove(s1)
.ret.remove(s2)
.ret.append(s1.union(s2))
.
.return [list(s) for s in ret]
.
.print merge(input)

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


Re: MatPlotLib.MatLab troubles (how to install/run matplotlib.PyLab?)

2005-02-23 Thread John Hunter
> "Colombes" == Colombes  <[EMAIL PROTECTED]> writes:

Colombes>Now I only need to figure out how to install the
Colombes> correct "Numeric" module(s).  I'm making progress,
Colombes> almost have my home laptop fully capable with the
Colombes> MatLab-like (PyLab) graphs, plots.

You can get either Numeric or numarray from
http://sourceforge.net/projects/numpy.  matplotlib works transparently
with either (and provides a unified interface to both), but if you
choose numarray you need to change the "numerix" variable to numarray
in your matplotlib configuration file, which is described at
http://matplotlib.sf.net/.matplotlibrc

Good luck!
JDH

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


Vexira ALERT [your mail: "Hi"]

2005-02-23 Thread VaMailArmor
* * * * * * * * * * * * * * * Vexira ALERT * * * * * * * * * * * * * * *
This version of Vexira MailArmor is licensed and full featured.

Vexira has detected the following in a mail from your address:

Worm/NetSky.Z worm  

The mail was not delivered.

Your computer may be infected with a virus! Please visit
Central Command at http://www.centralcommand.com and obtain a copy
of Vexira AntiVirus now.

Mail-Info:
--8<--
 From: python-list@python.org
 To: [EMAIL PROTECTED]
 Date: Wed, 23 Feb 2005 17:32:58 +0100
 Subject: Hi
--8<--


-- 
Vexira AntiVirus for Linux, OpenBSD, FreeBSD
Virus Protection for the Real World (TM).
Central Command http://www.centralcommand.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unicode(obj, errors='foo') raises TypeError - bug?

2005-02-23 Thread Steven Bethard
Kent Johnson wrote:
Steven Bethard wrote:
No, this is documented behavior[1]:
"""
unicode([object[, encoding [, errors]]])
...
For objects which provide a __unicode__() method, it will call 
this method without arguments to create a Unicode string. For all 
other objects, the 8-bit string version or representation is requested 
and then converted to a Unicode string using the codec for the default 
encoding in 'strict' mode.
"""

Note that the documentation basically says that it will call str() on 
your object, and then convert it in 'strict' mode.  You should either 
define __unicode__ or call str() manually on the object.
Not a bug, I guess, since it is documented, but it seems a bit bizarre 
that the encoding and errors parameters are ignored when object does not 
have a __unicode__ method.
Yeah, I agree it's weird.  I suspect if someone supplied a patch for 
this behavior it would be accepted -- I don't think this should break 
backwards compatibility (much).

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


Re: Fonts and PIL

2005-02-23 Thread Ulf Göransson
Greg Lindstrom wrote:
I'm running Python 2.3 on a windows box and would like to use PIL to 
superimpose text over an existing pgn image.  I have no problem getting 
the text on the image but can not figure out how to manage fonts.  How 
to set the font style and size.  From reading the archives I surmise 
that I want to work with *.pil files.  I've searched my box for the font 
files but did not find them.  I've googled for information on pil font 
files and it appears to be involved with Zope.  So, can any of you 
honcho-level types help me out?  How can I set font size and style in my 
PIL application?
Pick a nice .ttf file and load it with ImageFont.truetype().
/ug
--
http://mail.python.org/mailman/listinfo/python-list


Can somebody help compiling 'mssqldb.pyd' for Python24 [win]?

2005-02-23 Thread Martin Bless
I need to access a MSSQL database (MS-Sql, not MySQL!)and would very
much like to use mssql-0.09.tar.gz which is available from 

http://www.object-craft.com.au/projects/mssql/download.html

Unfortunately the binary for Python-2.4 isn't available yet and I'd
hate to step back to a previous version.

I'm glad I managed to set up my XP machine to being able to compile
extensions using the VC++ toolkit which freely availbale from MS. See
my posting "Step by step: Compiling extensions with MS Visual C++
Toolkit 2003" in this group.

The problem is that compiling stops with an error in this case.

Two additional header files are needed: sqlfront.h and sqldb.h. They
can be downloaded as file 'Ptk_I386.exe' here:



The problem I have in compiling is:

[...]
c:\Python24-extra-modules\MSSQL-0.09\sqlfront.h(312) : error C2373:
'LPCBYTE' : redefinition; different type modifiers

c:\Programme\Microsoft Platform SDK for Windows XP
SP2\Include\WinSCard.h(43) : see declaration of 'LPCBYTE'

error: command '"c:\programme\Microsoft Visual C++ Toolkit
2003\bin\cl.exe"' failed with exit status 2

Currently I'm not C-Guru enough to find out what's wrong. I'm hoping
somebody else succeeds in compiling and can provide compiled module.

I think the object-craft.com.au staff would gladly accept the binary
as well, as they don't have the appropriate environment right now.

Thanks in advance

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


Re: user interface for python

2005-02-23 Thread Fuzzyman
Yeah.. Tkinter is nice. Wzx is just as easy though, but scales better
because it's built on wx.

Regards,

Fuzzy
http://www.voidsapce.org.uk/python/index.shtml

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


print and str subclass with tab in value

2005-02-23 Thread David Bolen
I ran into this strange behavior when noticing some missing spaces in
some debugging output.  It seems that somewhere in the print
processing, there is special handling for string contents that isn't
affected by changing how a string is represented when printed
(overriding __str__).

For example, given a class like:

class mystr(str):

def __new__(cls, value):
return str.__new__(cls, value)

def __str__(self):
return 'Test'

you get the following behavior

>>> x = strtest.mystr('foo')
>>> print x,1
Test 1
>>> print repr(x),1
'foo' 1
>>> x = strtest.mystr('foo\t')
>>> print x,1
Test1
>>> print repr(x),1
'foo\t' 1

Note the lack of a space if the string value ends in a tab, even if
that tab has nothing to do with the printed representation of a
string.

It looks like it's part of basic string output since with a plain old
string literal the tab gets output (I've replaced the literal tab with
[TAB] in the output below) but no following string.

>>> x = 'testing\t'
>>> print x,1
testing[TAB]1
>>> x = str('testing\t')
>>> print x,1
testing[TAB]1

so I'm guessing it's part of some optimization of tab handling in
print output, although a quick perusal of the Python source didn't
have anything jump out at me.

It seems to me that this is probably a buglet since I would expect
print and its softspace handling to depend on what was actually
written and not internal values - has anyone else ever run into this.

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


Re: running a shell command from a python program

2005-02-23 Thread Leif B. Kristensen
Sandman wrote:

> How would I run a shell command in Python?
> 
> Here is what I want to do:
> I want to run a shell command that outputs some stuff, save it into a
> list and do stuff with the contents of that list.

There's a Python Cookbook example that should fit nicely with what
you're trying to do here:


-- 
Leif Biberg Kristensen
-- 
http://mail.python.org/mailman/listinfo/python-list


[OT] [Job] Open Python/Zope/Plone Positions in Ireland

2005-02-23 Thread Darragh Sherwin
Propylon is looking to recruit people with Python or Zope experience
for several projects that we are involved in.

We are seeking candidates with varying amount of experience in Python
and all who are interested in learning in Python are encouraged to apply
for the positions.

Experience with Zope or Plone is an advantage but not necessary.

For more information on Propylon, please visit http://www.propylon.com .

All positions would be in our Irish office in Dublin.

All candidates would have to be eligible to work in the EU and have the 
appropriate visas, etc.

If you or anyone you know is interested, please forward a CV,
preferably in the OpenOffice.org or RTF format to both
[EMAIL PROTECTED] and [EMAIL PROTECTED]

Regards,
--
Darragh Sherwin
PWB Implementations Manager
http://www.propylon.com/ solutions/parliament/index.html
+353-1-4927456
+353-87-1204654
-- 
http://mail.python.org/mailman/listinfo/python-list


Socks-4 Client Example in Twisted

2005-02-23 Thread Daniel Chandran
I am looking for examples on how to write a Socks-4 client example
using the Twisted framework.  Has anybody attempted this or aware of
examples?

Thanks,
Daniel

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


Re: running a shell command from a python program

2005-02-23 Thread Sandman
Doh, use the search Luke:

http://www.wellho.net/forum/Programming-in-Python-and-Ruby/Running-shell-commands-from-Python.html

Seems like popen is the way to go.

S

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


Re: running a shell command from a python program

2005-02-23 Thread Thomas Guettler
Am Wed, 23 Feb 2005 07:00:31 -0800 schrieb Sandman:

> Hi,
>I'm a newbie, so please be gentle :-)
> 
> How would I run a shell command in Python?
[cut]
> Is popen the answer? Also, where online would I get access to good
> sample code that I could peruse?

Yes, popen is the answer. I recommend popen4 because it avoids
deadlocks if there is output on stdout and stderr.

Example:
stdout, stdin = popen2.popen4("tidy -q -errors '%s'" % htmlfile)

HTH,
 Thomas

-- 
Thomas Güttler, http://www.thomas-guettler.de/


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


Re: [EVALUATION] - E02 - Support for MinGW Open Source Compiler

2005-02-23 Thread Ilias Lazaridis
Grant Edwards wrote:
[...]
Um, you realize that nobody in this thread takes you the least
bit seriously and people are just poking you with a stick to
watch you jump?
jump:
[EVALUATION] - E02 - Support for MinGW Open Source Compiler
Essence:
http://groups-beta.google.com/group/comp.lang.python/msg/5ba2a0ba55d4c102
.
--
http://lazaridis.com
--
http://mail.python.org/mailman/listinfo/python-list


  1   2   >