Re: pre-PEP: Simple Thunks

2005-04-20 Thread Steven Bethard
Greg Ewing wrote:
Brian Sabbey wrote:
do f in with_file('file.txt'):
print f.read()

I don't like this syntax. Try to read it as an English sentence:
Do f in with file 'file.txt'. Say what???
To sound right it would have to be something like
  with_file('file.txt') as f do:
print f.read()
This is still strange since f is the arguments the thunk was called 
with, e.g. the current syntax is basically:

do unpack_list in returnval = callable(params):
code
I don't really know a more readable sequence of keywords, though someone 
suggested 'with' and 'from', which might read something like:

with unpack_list from callable(params):
code
which looks okay to me, though I'm not sure that 'with' makes it clear 
that this is not a normal block...  I also find readability problems 
when I try to stick returnval back in.

One of the other issues is that, with the current proposal, the thunk 
can be called multiple times within a function, so the keywords have to 
make sense both with a single iteration interpretation and a multiple 
iteration interpretation...  Makes it even harder...

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


Why Python does *SLICING* the way it does??

2005-04-20 Thread [EMAIL PROTECTED]
Many people I know ask why Python does slicing the way it does.

Can anyone /please/ give me a good defense/justification???

I'm referring to why mystring[:4] gives me
elements 0, 1, 2 and 3 but *NOT* mystring[4] (5th element).

Many people don't like idea that 5th element is not invited.

(BTW, yes I'm aware of the explanation where slicing
is shown to involve slices _between_ elements.  This
doesn't explain why this is *best* way to do it.)

Chris

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


Re: Enumerating formatting strings

2005-04-20 Thread Greg Ewing
Steve Holden wrote:
I've been wondering whether it's possible to perform a similar analysis 
on non-mapping-type format strings, so as to know how long a tuple to 
provide,
I just tried an experiment, and it doesn't seem to be possible.
The problem seems to be that it expects the arguments to be
in the form of a tuple, and if you give it something else,
it wraps it up in a 1-element tuple and uses that instead.
This seems to happen even with a custom subclass of tuple,
so it must be doing an exact type check.
So it looks like you'll have to parse the format string.
--
Greg Ewing, Computer Science Dept,
University of Canterbury,   
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg
--
http://mail.python.org/mailman/listinfo/python-list


Re: New to Tkinter...

2005-04-20 Thread hue
Hello

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


Re: Why Python does *SLICING* the way it does??

2005-04-20 Thread Raymond Hettinger
[EMAIL PROTECTED]
 Many people I know ask why Python does slicing the way it does.

Half open intervals are just one way of doing things.  Each approach has its own
merits and issues.

Python's way has some useful properties:

* s == s[:i] + s[i:]

* len(s[i:j]) == j-i # if s is long enough


OTOH, it has some aspects that bite:

* It is awkward with negative strides such as with s[4:2:-1].  This was the
principal reason for introducing the reversed() function.

* It makes some people cringe when they first see it (you're obviously in that
group).


I suspect that whether it feels natural depends on your previous background and
whether you're working in an environment with arrays indexed from one or from
zero.  For instance, C programmers are used to seeing code like:   for(i=0 ;
in; i++) a[i]=f(i);   In contrast, a BASIC programmer may be used to FOR I = 1
to N:  a[I]=f(I); NEXT.Hence, the C coders may find Python's a[:n] to be
more natural than BASIC programmers.

As long as a language is consistent about its approach, you just get used to it
and it stops being an issue after a few days.


Raymond Hettinger


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


Re: How to run Python in Windows w/o popping a DOS box?

2005-04-20 Thread Paul Rubin
[EMAIL PROTECTED] (Bengt Richter) writes:
 I would try right-clicking the shortcut icon and selecting
 properties, then select the shortcut tab and edit the target string
 with s/python/pythonw/ and then click ok.

Thanks!  I'll try that tomorrow.  I never would have figured that out.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to Convert a makefile to Python Script

2005-04-20 Thread rkoida
Thanks For Your Help

Regards
rkoida

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


Re: Array of Chars to String

2005-04-20 Thread Peter Otten
Michael Spencer wrote:

  def func_join(s, letters):
 ... return .join(letter for letter in s if letter in set(letters))

Make that

def func_join(s, letters):
letter_set = set(letters) 
return .join(letter for letter in s if letter in letter_set)

for a fair timing of a set lookup as opposed to set creation.

Peter

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


Re: Writing to stdout and a log file

2005-04-20 Thread Wolfram Kraus
Mike wrote:
I would like my 'print' statements to send its output to the user's
screen and a log file.
This is my initial attempt:
class StdoutLog(file):
def __init__(self, stdout, name='/tmp/stdout.log',
mode='w',bufsize=-1):
super(StdoutLog, self).__init__(name,mode,bufsize)
self.stdout = stdout
def write(self, data):
self.stdout.write(data)
What happens when you do a self.stdout.flush() here?
self.write(data)
import sys
sys.stdout = StdoutLog(sys.stdout)
print 'STDOUT', sys.stdout
When the program is run the string is written to the log file but
nothing appears on my screen. Where's the screen output?
It looks like the superclass's write() method is getting called instead
of the StdoutLog instance's write() method.
The python documentation says 'print' should write to
sys.stdout.write() but that doesn't seem to be happening.
Any idea what's going one? 
Or ideas on how to debug this?

Thanks, Mike
I had the same problem (writing to file and stdout with print) and my 
solution was *not* to subclass file and instead add a 
self.outfile=file(...) to the constructor.

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


Re: pre-PEP: Simple Thunks

2005-04-20 Thread Mike Meyer
Ron_Adam [EMAIL PROTECTED] writes:
 Here's yet another way to do it, but it has some limitations as well.

 import pickle
 def pickle_it(filename, obj, commands):
 try:
 f = open(filename, 'r')
 obj = pickle.load(f)
 f.close()
 except IOError:
 pass  
 for i in commands:
 i[0](i[1])
 f = open(filename, 'w')
 pickle.dump(obj, f)
 f.close()
  
 file = 'filename'
 L = []

 opps = [ (L.append,'more data'),
  (L.append,'even more data') ]
 pickle_it(file, L, opps)

Um - it doesn't look like this will work. You pass L in as the obj
paremeter, and then it gets changed to the results of a
pickle.load. However, you call L.append in the for loop, so the data
will be appended to L, not obj. You'll lose an list elements that were
in the pickle.

   mike
-- 
Mike Meyer [EMAIL PROTECTED]  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: Enumerating formatting strings

2005-04-20 Thread Peter Otten
Greg Ewing wrote:

 Steve Holden wrote:
 
 I've been wondering whether it's possible to perform a similar analysis
 on non-mapping-type format strings, so as to know how long a tuple to
 provide,
 
 I just tried an experiment, and it doesn't seem to be possible.
 
 The problem seems to be that it expects the arguments to be
 in the form of a tuple, and if you give it something else,
 it wraps it up in a 1-element tuple and uses that instead.
 
 This seems to happen even with a custom subclass of tuple,
 so it must be doing an exact type check.

No, it doesn't do an exact type check, but always calls the tuple method:

 class Tuple(tuple):
... def __getitem__(self, index):
... return 42
...
 %r %r % Tuple(ab) # would raise an exception if wrapped
'a' 'b'

 So it looks like you'll have to parse the format string.
 
Indeed.

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


To decode the Subject =?iso-8859-2?Q?=... in email in python

2005-04-20 Thread Dan Polansky
When parsing messages using python's libraries email and mailbox, the
subject is often encoded using some kind of = notation. Apparently, the
encoding used in this notation is specified like =?iso-8859-2?Q?=... or
=?iso-8859-2?B?=. Is there a python library function to decode such a
subject, returning a unicode string? The use would be like

  human_readable = cool_library.decode_equals(message['Subject'])

Thank you, Dan

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


Python instances

2005-04-20 Thread henrikpierrou
Hi,

How do python instances work?
Why does the code at the end of my posting produce this output:

list in a:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
list in b:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

instead of

list in a:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
list in b:
[]



class MyClass:
list = []

def add(self, x):
self.list.append(x)

def printer(self):
print self.list

a = MyClass()
b = MyClass()

for n in range(10):
a.add(n)

print list in a:
a.printer()
print list in b:
b.printer()

/H

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


Re: Python instances

2005-04-20 Thread Roland Heiber
Hi,
class MyClass:
list = []
you have list defined as a classmember, not an instancemember. So 
list ist defined ONCE for all instances.

Try this instead:
class MyClass:
def __init__(self):
self.list = []
[...]
and use self.list ...
HtH, Roland
--
http://mail.python.org/mailman/listinfo/python-list


long time we haven't spoken ;)

2005-04-20 Thread Elbert Delaney
Daayuum bro

You'll never guess what happened to me last week.

Basically found a 18 + date site that doesn't charge anything.

So many couples, guys and girls are there messaging and meeting eachother.

And I'm certain there is someone (or more than one) for you.

Although most of them want one-nighters, there are also those who like it 
serious.

Whatever you feel like pretty much ;-)


http://www.fernirr.com/a5/




PS:no.more?
http://www.fernirr.com/rmv/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: To decode the Subject =?iso-8859-2?Q?=... in email in python

2005-04-20 Thread Max M
Dan Polansky wrote:
When parsing messages using python's libraries email and mailbox, the
subject is often encoded using some kind of = notation. Apparently, the
encoding used in this notation is specified like =?iso-8859-2?Q?=... or
=?iso-8859-2?B?=. Is there a python library function to decode such a
subject, returning a unicode string? The use would be like
  human_readable = cool_library.decode_equals(message['Subject'])

parts = email.Header.decode_header(header)
new_header = email.Header.make_header(parts)
human_readable = unicode(new_header)

--
hilsen/regards Max M, Denmark
http://www.mxm.dk/
IT's Mad Science
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python instances

2005-04-20 Thread henrikpierrou
Guess i shouldn't think of the __init__(self) function as a constructor
then.
Thanks.

/H

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


Fwd: Memory leak in python

2005-04-20 Thread Abhishek S
Hi Nick,

Thanks for reply... Please include me in reply.
Currently i am not in the list (i will subscribe soon)

I upgarded to 2.4.1 - still the same issue.

Nick
Thats not a lot of leak - have you done that over a
longer time period?

Abhi
I have tried for 4 days. It has reached 150MB.

Nick
Are there any objects in gc.garbage?
 gc.set_debug(gc.DEBUG_LEAK)
 gc.get_debug( )
62
 gc.collect()
0
 gc.garbage
[]


Abhi
There is none.

Nick
Are you writing objects with __del__ methods?  If so
then that is your problem probably.

Abhi 
I have not written any __del__ methods.

Nick
Have you written any C extension modules in C?

Yes. Many - All of them are called only 
when the app starts. And never called again.
Till then it is stable only - 16MB used.

I have tried following - let me know if you need any
more details.. and want me to try something.

1)
I found a sizer python program. Which gives me the
module which is growing. It indicates that __main__ is
growing.

__main__': 4000774

2) I tried following.. (not smart but..)

def f():
 c = gc.get_objects()
 j = 0
 for i in c:
   j = j + 1
   try:
 tmp = len(i)
 if tmp  1000:
  print (c[%d]) (%d), % (j-1, tmp)
   except:
 pass

it prints me as folows:

l(c[175]) (7336),
l(c[12475]) (1260),
l(c[12477]) (1260),
l(c[12479]) (1381),
l(c[12481]) (1381),
l(c[34159]) (1200),
l(c[37144]) (28234),
l(c[37191]) (28286),
 type(c[37191])
type 'dict'
 for k,v in c[37164].items():
...print k, v
...b = b + 1
...if b  30:
...   break
...
1085115764 620
1080048556 2
1085045932 4
1085146316 1
1085246700 2
1090615060 9
1089571940 2
1090519084 2
1090876932 234
1093456364 48
1085168140 2
1089964748 6
1089994828 0
1090095684 69
1076932268 2
1085014108 6
1080092204 10
108412 1
1118543628 48
1089994860 6
1076731524 6
1079640188 3
1084883076 15
1079712492 1
1118459244 64
1080295564 1
1076522028 4
1085211788 2
1076887700 20
1076729756 70
1091012236 2

This two dict in the last is growing slowly..
I am not maintaing any dict with such indices and
value.

Any clue? 
Please let me know what else to check and how!

At the time i am ending this.. module size..
'__main__': 7926830,

Thanks,
Abhishek

Note: forwarded message attached.


__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com ---BeginMessage---
Hi,

using python2.2.2

I am seeing that the python application is very slowly
eating up the memory. i need help to indentify it.

It start with 11MB and keeps growing by 1 MB around
every 30mins.

#top | grep python
10351 root  15   0 26584  25M  3896 S 0.5  0.8
 46:05   1 python2
10351 root  15   0 26592  25M  3896 S 3.5  0.8
 46:06   1 python2
10351 root  15   0 26596  25M  3896 S30.9  0.8
 46:07   0 python2
10351 root  15   0 26608  25M  3896 S73.0  0.8
 46:11   0 python2
10351 root  15   0 26612  25M  3896 S73.2  0.8
 46:15   0 python2
10351 root  15   0 26616  25M  3896 S78.6  0.8
 46:18   1 python2
10351 root  15   0 26620  25M  3896 S78.4  0.8
 46:22   1 python2
10351 root  15   0 26620  25M  3896 S77.4  0.8
 46:26   1 python2
10351 root  15   0 26620  25M  3896 S73.2  0.8
 46:30   1 python2
10351 root  15   0 26620  25M  3896 S65.8  0.8
 46:33   1 python2
10351 root  15   0 26620  25M  3896 S43.3  0.8
 46:35   1 python2
10351 root  15   0 26620  25M  3896 S53.8  0.8
 46:38   1 python2
10351 root  15   0 26620  25M  3896 S26.3  0.8
 46:39   1 python2
10351 root  15   0 26636  26M  3896 S33.5  0.8
 46:41   1 python2
10351 root  15   0 26640  26M  3896 S25.7  0.8
 46:42   1 python2
10351 root  15   0 26656  26M  3896 S23.9  0.8
 46:44   1 python2
10351 root  15   0 26656  26M  3896 S11.7  0.8
 46:44   1 python2
10351 root  15   0 26660  26M  3896 S10.7  0.8
 46:45   1 python2
10351 root  15   0 26668  26M  3896 S 3.7  0.8
 46:45   1 python2
10351 root  15   0 26668  26M  3896 S 1.7  0.8
 46:45   1 python2
10351 root  15   0 26668  26M  3896 S 0.7  0.8
 46:45   1 python2
10351 root  15   0 26668  26M  3896 S 0.3  0.8
 46:45   1 python2
10351 root  15   0 26684  26M  3896 S 4.5  0.8
 46:45   1 python2
10351 root  15   0 26688  26M  3896 S 2.1  0.8
 46:45   1 python2

let me know how to approch this.
gc.collect - does not collect anything.


Thanks,
Abhishek

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
---End Message---
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python instances

2005-04-20 Thread Laszlo Zsolt Nagy

Guess i shouldn't think of the __init__(self) function as a constructor
then.
 

__init__ is THE constructor in Python
--
_
 Laszlo Nagy  web: http://designasign.biz
 IT Consultantmail: [EMAIL PROTECTED]
Python forever!
--
http://mail.python.org/mailman/listinfo/python-list


Re: To decode the Subject =?iso-8859-2?Q?=... in email in python

2005-04-20 Thread Roman Neuhauser
# [EMAIL PROTECTED] / 2005-04-20 00:30:35 -0700:
 When parsing messages using python's libraries email and mailbox, the
 subject is often encoded using some kind of = notation. Apparently, the
 encoding used in this notation is specified like =?iso-8859-2?Q?=... or
 =?iso-8859-2?B?=.

That's RFC 2047 encoding, both examples introduce an ISO8859-2
string, the first variant says it's ascii-ized using
Quoted-Printable, the other says the string is Base64-encoded.

 Is there a python library function to decode such a
 subject, returning a unicode string? The use would be like
 
   human_readable = cool_library.decode_equals(message['Subject'])

quoting from http://docs.python.org/lib/module-email.Header.html

 from email.Header import decode_header
 decode_header('=?iso-8859-1?q?p=F6stal?=')
[('p\xf6stal', 'iso-8859-1')]

-- 
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Enumerating formatting strings

2005-04-20 Thread Bengt Richter
On Wed, 20 Apr 2005 09:14:40 +0200, Peter Otten [EMAIL PROTECTED] wrote:

Greg Ewing wrote:

 Steve Holden wrote:
 
 I've been wondering whether it's possible to perform a similar analysis
 on non-mapping-type format strings, so as to know how long a tuple to
 provide,
 
 I just tried an experiment, and it doesn't seem to be possible.
 
 The problem seems to be that it expects the arguments to be
 in the form of a tuple, and if you give it something else,
 it wraps it up in a 1-element tuple and uses that instead.
 
 This seems to happen even with a custom subclass of tuple,
 so it must be doing an exact type check.

No, it doesn't do an exact type check, but always calls the tuple method:

 class Tuple(tuple):
... def __getitem__(self, index):
... return 42
...
 %r %r % Tuple(ab) # would raise an exception if wrapped
'a' 'b'

 So it looks like you'll have to parse the format string.
 
Indeed.

Parse might be a big word for

  def tupreq(fmt): return sum(map(lambda s:list(s).count('%'), 
  fmt.split('%%')))
 ..
  tupreq('%s this %(x)s not %% but %s')

(if it works in general ;-)

Or maybe clearer and faster:

  def tupreq(fmt): return sum(1 for c in fmt.replace('%%','') if c=='%')
 ...
  tupreq('%s this %(x)s not %% but %s')
 3

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


Re: Python Google Server

2005-04-20 Thread Fuzzyman
Thanks Benji,

It returns the results using an ip address - not the google domain.
This means IPCop bans it :-(

Thanks for the suggestion though. In actual fact the googleCacheServer
works quite well.

Best Regards,

Fuzzy
http://www.voidspace.org.uk/python/weblog

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


Re: Proposal: an unchanging URL for Python documentation

2005-04-20 Thread Simon Brunning
On 4/19/05, Skip Montanaro [EMAIL PROTECTED] wrote:
 ... the documentation for the os
 steve module would also be available at
 steve http://python.org/doc/current/lib/module-os.html.
 
 Time machine at work?  The above URL works for me now.

Yup, but it's not all unchanging. Take, for example,
http://www.python.org/doc/current/tut/node16.html. I have wanted to
steer people towards that page a number of times, and that node number
keeps changing.

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


Re: Python instances

2005-04-20 Thread Bengt Richter
On 20 Apr 2005 00:44:53 -0700, [EMAIL PROTECTED] wrote:

Guess i shouldn't think of the __init__(self) function as a constructor
then.
Thanks.
Depends on what you think when you think constructor ;-)
Read about both __new__ and __init__. The former is always
necessary to create an object, and __init__ may take parameters to
define intial state from its parameters, but __new__ does the whole
job for immutables. I.e., constructor translates to combination of
both if both are present, but __new__ must be always be there and
come first. In general there are default methods inherited from
object and/or type, the most primitive classes, so you don't have
to define them except to customize for your purposes.
At least, that's the way I think of it ;-)

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


Re: Behaviour of str.split

2005-04-20 Thread David Fraser
Greg Ewing wrote:
Will McGugan wrote:
Hi,
I'm curious about the behaviour of the str.split() when applied to 
empty strings.

.split() returns an empty list, however..
.split(*) returns a list containing one empty string.

Both of these make sense as limiting cases.
Consider
  a b c.split()
['a', 'b', 'c']
  a b.split()
['a', 'b']
  a.split()
['a']
  .split()
[]
and
  **.split(*)
['', '', '']
  *.split(*)
['', '']
  .split(*)
['']
The split() method is really doing two somewhat different things
depending on whether it is given an argument, and the end-cases
come out differently.
You don't really explain *why* they make sense as limiting cases, as 
your examples are quite different.

Consider
 a*b*c.split(*)
['a', 'b', 'c']
 a*b.split(*)
['a', 'b']
 a.split(*)
['a']
 .split(*)
['']
Now how is this logical when compared with split() above?
David
--
http://mail.python.org/mailman/listinfo/python-list


Re: Enumerating formatting strings

2005-04-20 Thread Peter Otten
Bengt Richter wrote:

 Parse might be a big word for
 
   def tupreq(fmt): return sum(map(lambda s:list(s).count('%'),
   fmt.split('%%')))
  ..
   tupreq('%s this %(x)s not %% but %s')
 
 (if it works in general ;-)

Which it doesn't:

 def tupreq(fmt): return sum(map(lambda s:list(s).count('%'),
fmt.split('%%')))
...
 fmt = %*d
 fmt % ((1,) * tupreq(fmt))
Traceback (most recent call last):
  File stdin, line 1, in ?
TypeError: not enough arguments for format string

 Or maybe clearer and faster:
 
   def tupreq(fmt): return sum(1 for c in fmt.replace('%%','') if
   c=='%')
  ...
   tupreq('%s this %(x)s not %% but %s')
  3

Mixed formats show some interesting behaviour:

 %s %(x)s % (1,2)
Traceback (most recent call last):
  File stdin, line 1, in ?
TypeError: format requires a mapping
 class D:
... def __getitem__(self, key):
... return D[%s] % key
...
 %s %(x)s % D()
'__main__.D instance at 0x402aaf2c D[x]'
 %s %(x)s %s % D()
Traceback (most recent call last):
  File stdin, line 1, in ?
TypeError: not enough arguments for format string
 %s %(x)s %(y)s % D()
'__main__.D instance at 0x402aad8c D[x] D[y]'

That is as far as I got. So under what circumstances is 
'%s this %(x)s not %% but %s' a valid format string?

Peter

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


Re: xmlrpclib and binary data as normal parameter strings

2005-04-20 Thread Rune Froysa
Richard Brodie [EMAIL PROTECTED] writes:

 Rune Froysa [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]

 From http://www.xmlrpc.com/spec ::
   Any characters are allowed in a string except  and , which are
   encoded as lt; and amp;. A string can be used to encode binary
   data.

 the XMLRPC specification is worded pretty loosely. Obviously characters
 forbidden in XML will be problematic.

IMHO that is not obvious.  The API-user wants to call a function on a
remote server with an arbitrary argument.  What the transport-layer
does to achieve this should be completly transparent to the user.

We already have code that takes care of .  Ideally we should do
that for other data as well.  Unfortunately the XML-spec doesn't allow
us to use character references %#x1b;.

With the patch below, setting BINARY_AS_STRING=True will cause all
strings to be transparently base64-encoded during transport.
Unfortunately it will do this for all incoming binary data, thus
breaking aplications that explicitly uses the Binary class for this
purpose.

IMHO the xmlrpc spec should be updated to allow something like this.

--- /local/lib/python2.3/xmlrpclib.py  2005-01-10 10:30:43.0 +0100
+++ xmlrpclib.py2005-04-20 09:56:11.0 +0200
@@ -177,6 +177,8 @@
 
 __version__ = 1.0.1
 
+BINARY_AS_STRING = False
+
 # xmlrpc integer limits
 MAXINT =  2L**31-1
 MININT = -2L**31
@@ -652,6 +654,11 @@
 dispatch[FloatType] = dump_double
 
 def dump_string(self, value, write, escape=escape):
+if BINARY_AS_STRING:
+self.write = write
+Binary(value).encode(self)
+del self.write
+return
 write(valuestring)
 write(escape(value))
 write(/string/value\n)
@@ -843,7 +850,10 @@
 def end_base64(self, data):
 value = Binary()
 value.decode(data)
-self.append(value)
+if BINARY_AS_STRING:
+self.append(value.data)
+else:
+self.append(value)
 self._value = 0
 dispatch[base64] = end_base64
 
-- 
Rune Frøysa
-- 
http://mail.python.org/mailman/listinfo/python-list


goto statement

2005-04-20 Thread praba kar
Dear All,

   In Python what is equivalent to goto statement

regards,
praba 

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: goto statement

2005-04-20 Thread Mage
praba kar wrote:

Dear All,

   In Python what is equivalent to goto statement

  

You shouldn't use goto in high-level languages.

   Mage


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


Re: Writing to stdout and a log file

2005-04-20 Thread Mike
flushing stdout has no effect.

I've got an implementation that does not subclass file. It's not as
nice but it works.

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


Re: Refactoring in Python.

2005-04-20 Thread Peter Dembinski
[EMAIL PROTECTED] writes:

 Investigate the CVS histories of the few 1000s python projects
 available at www.sourceforge.net

I don't work with these guys :

-- 
http://www.pdemb.prv.pl 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: XML parsing per record

2005-04-20 Thread Willem Ligtenberg
On Sun, 17 Apr 2005 02:16:04 +, William Park wrote:

 Willem Ligtenberg [EMAIL PROTECTED] wrote:
 I want to parse a very large (2.4 gig) XML file (bioinformatics
 ofcourse :)) But I have no clue how to do that. Most things I see read
 the entire xml file at once. That isn't going to work here ofcourse.
 
 So I would like to parse a XML file one record at a time and then be
 able to store the information in another object.  How should I do
 that?
 
 Thanks in advance,
 
 Willem Ligtenberg A total newbie to python by the way.
 
 You may want to try Expat (www.libexpat.org) or Python wrapper to it.
 You can feed small piece at a time, say by lines or whatever.  Of
 course, it all depends on what kind of parsing you have in mind. :-)
 
 Care to post more details?

The XML file I need to parse contains information about genes.
So the first element is a gene and then there are a lot sub-elements with
sub-elements. I only need some of the informtion and want to store it in
my an object called gene. Lateron this information will be printed into a
file, which in it's turn will be fed into some other program.
This is an example of the XML
?xml version=1.0?
!DOCTYPE Entrezgene-Set PUBLIC -//NCBI//NCBI Entrezgene/EN 
NCBI_Entrezgene.dtd
Entrezgene-Set
  Entrezgene
Entrezgene_track-info
  Gene-track
Gene-track_geneid9996/Gene-track_geneid
Gene-track_status value=secondary1/Gene-track_status
Gene-track_current-id
  Dbtag
Dbtag_dbLocusID/Dbtag_db
Dbtag_tag
  Object-id
Object-id_id320632/Object-id_id
  /Object-id
/Dbtag_tag
  /Dbtag
  Dbtag
Dbtag_dbGeneID/Dbtag_db
Dbtag_tag
  Object-id
Object-id_id320632/Object-id_id
  /Object-id
/Dbtag_tag
  /Dbtag
/Gene-track_current-id
Gene-track_create-date
  Date
Date_std
  Date-std
Date-std_year2003/Date-std_year
Date-std_month8/Date-std_month
Date-std_day28/Date-std_day
Date-std_hour21/Date-std_hour
Date-std_minute39/Date-std_minute
Date-std_second0/Date-std_second
  /Date-std
/Date_std
  /Date
/Gene-track_create-date
Gene-track_update-date
  Date
Date_std
  Date-std
Date-std_year2005/Date-std_year
Date-std_month2/Date-std_month
Date-std_day17/Date-std_day
Date-std_hour12/Date-std_hour
Date-std_minute54/Date-std_minute
Date-std_second0/Date-std_second
  /Date-std
/Date_std
  /Date
/Gene-track_update-date
  /Gene-track
/Entrezgene_track-info
Entrezgene_type value=protein-coding6/Entrezgene_type
Entrezgene_source
  BioSource
BioSource_genome value=genomic1/BioSource_genome
BioSource_origin value=natural1/BioSource_origin
BioSource_org
  Org-ref
Org-ref_taxnameMus musculus/Org-ref_taxname
Org-ref_commonhouse mouse/Org-ref_common
Org-ref_db
  Dbtag
Dbtag_dbtaxon/Dbtag_db
Dbtag_tag
  Object-id
Object-id_id10090/Object-id_id
  /Object-id
/Dbtag_tag
  /Dbtag
/Org-ref_db
Org-ref_syn
  Org-ref_syn_Emouse/Org-ref_syn_E
/Org-ref_syn
Org-ref_orgname
  OrgName
OrgName_name
  OrgName_name_binomial
BinomialOrgName
  BinomialOrgName_genusMus/BinomialOrgName_genus
  
BinomialOrgName_speciesmusculus/BinomialOrgName_species
/BinomialOrgName
  /OrgName_name_binomial
/OrgName_name
OrgName_lineageEukaryota; Metazoa; Chordata; Craniata; 
Vertebrata; Euteleostomi; Mammalia; Eutheria; Euarchontoglires; Glires; 
Rodentia; Sciurognathi; Muridae; Murinae; Mus/OrgName_lineage
OrgName_gcode1/OrgName_gcode
OrgName_mgcode2/OrgName_mgcode
OrgName_divROD/OrgName_div
  /OrgName
/Org-ref_orgname
  /Org-ref
/BioSource_org
  /BioSource
/Entrezgene_source
Entrezgene_gene
  Gene-ref
  /Gene-ref
/Entrezgene_gene
Entrezgene_gene-source
  Gene-source
Gene-source_srcLocusLink/Gene-source_src
Gene-source_src-int9996/Gene-source_src-int
Gene-source_src-str29996/Gene-source_src-str2
Gene-source_gene-display value=false/
Gene-source_locus-display value=false/
Gene-source_extra-terms value=false/
  /Gene-source
/Entrezgene_gene-source

Re: Behaviour of str.split

2005-04-20 Thread Bengt Richter
On Wed, 20 Apr 2005 10:55:18 +0200, David Fraser [EMAIL PROTECTED] wrote:

Greg Ewing wrote:
 Will McGugan wrote:
 
 Hi,

 I'm curious about the behaviour of the str.split() when applied to 
 empty strings.

 .split() returns an empty list, however..

 .split(*) returns a list containing one empty string.
 
 
 Both of these make sense as limiting cases.
 
 Consider
 
   a b c.split()
 ['a', 'b', 'c']
   a b.split()
 ['a', 'b']
   a.split()
 ['a']
   .split()
 []
 
 and
 
   **.split(*)
 ['', '', '']
   *.split(*)
 ['', '']
   .split(*)
 ['']
 
 The split() method is really doing two somewhat different things
 depending on whether it is given an argument, and the end-cases
 come out differently.
 
You don't really explain *why* they make sense as limiting cases, as 
your examples are quite different.

Consider
  a*b*c.split(*)
['a', 'b', 'c']
  a*b.split(*)
['a', 'b']
  a.split(*)
['a']
  .split(*)
['']

Now how is this logical when compared with split() above?

The trouble is that s.split(arg) and s.split() are two different functions.

The first is 1:1 and reversible like arg.join(s.split(arg))==s
The second is not 1:1 nor reversible: 'various whitespace'.join(s.split()) 
== s ?? Not usually.

I think you can do it with the equivalent whitespace regex, preserving the 
splitout whitespace
substrings and ''.joining those back with the others, but not with split(). 
I.e.,

  def splitjoin(s, splitter=None):
 ... return (splitter is None and 'whitespace' or 
splitter).join(s.split(splitter))
 ...
  splitjoin('a*b*c', '*')
 'a*b*c'
  splitjoin('a*b', '*')
 'a*b'
  splitjoin('a', '*')
 'a'
  splitjoin('', '*')
 ''
  splitjoin('a bc')
 'awhitespacebwhitespacec'
  splitjoin('a b')
 'awhitespaceb'
  splitjoin('  b')
 'b'
  splitjoin('')
 ''

  splitjoin('*','*')
 '*'
Note why that works:

  '*'.split('*')
 ['', '', '', '', '', '']
  '*a'.split('*')
 ['', 'a']
  'a*'.split('*')
 ['a', '']

  splitjoin('*a','*')
 '*a'
  splitjoin('a*','*')
 'a*'

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


Re: goto statement

2005-04-20 Thread Simon Brunning
On 4/20/05, praba kar [EMAIL PROTECTED] wrote:
In Python what is equivalent to goto statement

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

See, it's those dratted node numbers again. ;-)

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


Lex

2005-04-20 Thread jozo
I have to work on python lexical definition in Lex. I spent lots of my
time to find regular expresions written for Lex of Python language but
nothing.
Can somebody help me?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: goto statement

2005-04-20 Thread Maurice Caret
Simon Brunning a écrit :
On 4/20/05, praba kar [EMAIL PROTECTED] wrote:
  In Python what is equivalent to goto statement

http://docs.python.org/tut/node6.html
See, it's those dratted node numbers again. ;-)
other equivalents are in
http://docs.python.org/tut/node10.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: Enumerating formatting strings

2005-04-20 Thread Bengt Richter
On Wed, 20 Apr 2005 11:01:28 +0200, Peter Otten [EMAIL PROTECTED] wrote:

Bengt Richter wrote:

 Parse might be a big word for
 
   def tupreq(fmt): return sum(map(lambda s:list(s).count('%'),
   fmt.split('%%')))
  ..
   tupreq('%s this %(x)s not %% but %s')
 
 (if it works in general ;-)

Which it doesn't:
   D'oh. (My subconscious knew that one, and prompted the if ;-)

 def tupreq(fmt): return sum(map(lambda s:list(s).count('%'),
fmt.split('%%')))
...
 fmt = %*d
 fmt % ((1,) * tupreq(fmt))
Traceback (most recent call last):
  File stdin, line 1, in ?
TypeError: not enough arguments for format string

But that one it totally spaced on ;-/

 Or maybe clearer and faster:
 
   def tupreq(fmt): return sum(1 for c in fmt.replace('%%','') if
   c=='%')
  ...
   tupreq('%s this %(x)s not %% but %s')
  3


Mixed formats show some interesting behaviour:

 %s %(x)s % (1,2)
Traceback (most recent call last):
  File stdin, line 1, in ?
TypeError: format requires a mapping
 class D:
... def __getitem__(self, key):
... return D[%s] % key
...
 %s %(x)s % D()
'__main__.D instance at 0x402aaf2c D[x]'
 %s %(x)s %s % D()
Traceback (most recent call last):
  File stdin, line 1, in ?
TypeError: not enough arguments for format string
 %s %(x)s %(y)s % D()
'__main__.D instance at 0x402aad8c D[x] D[y]'

That is as far as I got. So under what circumstances is 
'%s this %(x)s not %% but %s' a valid format string?

Yeah, I got that far too, some time ago playing % mapping, and
I thought they just didn't allow for mixed formats. My thought then
was that they could pass integer positional keys to another method
(say __format__) on a mapping object that wants to handle mixed formats.
If you wanted the normal str or repr resprensentation of a mapping
object that had a __format__ method, you'd have to do it on the args
side with str(theobject), but you'd have a way. And normal mapping objects
would need no special handling for %s' in a mixed format context.

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


Re: goto statement

2005-04-20 Thread Simon Brunning
On 4/20/05, Maurice Caret [EMAIL PROTECTED] wrote:
 
 other equivalents are in
 
 http://docs.python.org/tut/node10.html

I also missed 
http://docs.python.org/tut/node5.html#SECTION00520,
for the while statement.

Those URLs just keeg getting better...

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


trying to understand unicode

2005-04-20 Thread F. Petitjean
Python has a very good support of unicode, utf8, encodings ... But I
have some difficulties with the concepts and the vocabulary. The
documentation is not bad, but for example in reading
http://docs.python.org/lib/module-unicodedata.html
I had a long time to figure out what unicodedata.digit(unichr) would
mean, a simple example is badly lacking.

So I wrote the following script :

#!/usr/bin/env python

Example of use of the unicodedata module
http://docs.python.org/lib/module-unicodedata.html


import unicodedata
import sys

# outcodec = 'latin_1'
outcodec = 'iso8859_15'
if len(sys.argv)  1:
outcodec = sys.argv[1]

for c in range(256):
uc = unichr(c)
uname = unicodedata.name(uc, None)
if uname:
unfd = unicodedata.normalize('NFD', uc).encode(outcodec,
'replace')
unfc = unicodedata.normalize('NFC', uc).encode(outcodec,
'replace')
print str(c).ljust(3), uname.ljust(42), unfd.ljust(2),
unfc.ljust(2), \
unicodedata.category(uc), unicodedata.numeric(uc, None)


and here are some samples of output
44  COMMA  ,  ,  Po None
45  HYPHEN-MINUS   -  -  Pd None
46  FULL STOP  .  .  Po None
47  SOLIDUS/  /  Po None
48  DIGIT ZERO 0  0  Nd 0.0
49  DIGIT ONE  1  1  Nd 1.0
50  DIGIT TWO  2  2  Nd 2.0

It seems that 'Nd' category means Numerical digit  doh!

64  COMMERCIAL AT  @  @  Po None
65  LATIN CAPITAL LETTER A A  A  Lu None
66  LATIN CAPITAL LETTER B B  B  Lu None

'Lu' should read 'Letter upper' ?

94  CIRCUMFLEX ACCENT  ^  ^  Sk None
95  LOW LINE   _  _  Pc None
96  GRAVE ACCENT   `  `  Sk None
97  LATIN SMALL LETTER A   a  a  Ll None
98  LATIN SMALL LETTER B   b  b  Ll None
'Ll' == Letter lower

124 VERTICAL LINE  |  |  Sm None
125 RIGHT CURLY BRACKET}  }  Pe None
126 TILDE  ~  ~  Sm None
160 NO-BREAK SPACE       Zs None
161 INVERTED EXCLAMATION MARK  ¡  ¡  Po None

What a gap !

245 LATIN SMALL LETTER O WITH TILDEo? õ  Ll None
246 LATIN SMALL LETTER O WITH DIAERESISo? ö  Ll None
247 DIVISION SIGN  ÷  ÷  Sm None
248 LATIN SMALL LETTER O WITH STROKE   ø  ø  Ll None

'Sm' should read 'sign mathematics' ?

I think that such code snippets should be included in the documentation
or in a Wiki.

Regards

Sorry for bad english, I'm not a native speaker.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: goto statement

2005-04-20 Thread Maxim Kasimov
Mage wrote:
praba kar wrote:

Dear All,
 In Python what is equivalent to goto statement

You shouldn't use goto in high-level languages.
it would be quite useful for debuging porposes
--
Best regards,
Maxim Kasimov
mailto: [EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: (Python newbie) Using XP-SP2/MSVC6: No Python24_d.lib, winzip barfs on Python-2.4.1.tar, cannot download bzip2

2005-04-20 Thread Bill Davy
Thank you Khalid,



OK.  (4) (compile using MSVC6) worked.



Now working through various issues to do with paths and naming (_d suffix to 
root for DEBUG, _ prefix to root for SWIG, and I had not spotted that SWIG 
makes Module.py that imports _Module.pyd but not _Module_d.pyd for DEBUG 
builds).



I'd like to persuade IDLE to use my locally compiled version of Python 
rather than the one I downloaded, and will find out how eventually. 
Necessary to keep to a VC6 build of 2.4.1 throughout.



Rgds,

Bill (an inveterate top poster, I'm afraid).


A.B., Khalid [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Okay, let me have another stap at this.

 As you have probably noticed MSVC6 is no longer actively supported as
 far as Python 2.4 goes. The official distribution of Python 2.4 for
 Windows is built using MSVC7.1 (or whatever you wish to call it).

 We are told that building C extensions with MSVC6 for use in the
 official Python 2.4 (which uses the MSVCR71) is not safe, and mixing
 the different runtime libraries that your extension (or my extension)
 with that which official Python 2.4 uses will/might cause crashes.
 Google around for details on this.

 So, what to do? You seem to have four options.

 1. Get and use the MSVC7.1 compiler.
 2. Get and use the freely distributed MS compiler.
 3. Download the Python source[1] and compile it yourself in MSVC6
 (there are project files in the source to enable you to do that). Then
 use your MSVC6 to create the extension.
 4. Get and use MinGW and pyMinGW[2]




 Regards,
 Khalid




 [1] Check to see if your archiever tool is working, or get the source
 from CVS.

 [2] pyMinGW:
 http://jove.prohosting.com/iwave/ipython/pyMinGW.html
 


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


Re: goto statement

2005-04-20 Thread Simon Brunning
On 4/20/05, Maxim Kasimov [EMAIL PROTECTED] wrote:
 it would be quite useful for debuging porposes

How does goto help you to remove bugs?

I can certainly see how it helps you put them in in the first place...

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


Re: (Python newbie) Using XP-SP2/MSVC6: No Python24_d.lib, winzip barfs on Python-2.4.1.tar, cannot download bzip2

2005-04-20 Thread Bill Davy
Thanks Jaime,

I'm making gradual progress and am finding it quite satisfying.  Resorted to 
tracing Python in MSVC6 to see what it was trying to IMPORT, which is a bit 
heavy but thank heavens for the sources.

Had not thouight of adapting SWIG, and will think about it when I have a 
clearer view of what I am doing (rather deeply embedded at present, trying 
to get one success).  I had not spotted SWIG's wrapper round a wrapper 
(Module.py imports _Module.pyd) but it's reasonable except they go into 
different directories.  And there's the _d too, of course :-(

Many thanks for your help,

Bill

Jaime Wyant [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
I fight the python24_d.lib problem with swig daily.  The way I got
around it was to modify swig's python configuration module.  Mine was
located at

/lib/swig1.3/python/python.swg

(I'm using cygwin)

At the top, I changed

#include python.h

to

#ifdef _DEBUG
  #undef _DEBUG
  #include python.h
  #define _DEBUG
#else
  #include python.h
#endif

Somewhere in the includes, python uses a pragma telling the MSVC
compiler which library to link the object files against.  Because
you're building a _DEBUG build, you magically get the python24_d.lib
library.

hth,
jw

On 4/18/05, Bill Davy [EMAIL PROTECTED] wrote:
 I downlaoded and installed
 http://www.python.org/ftp/python/2.4.1/python-2.4.1.msi

 I'm trying to build an extension using SWIG 1.3.24 and the linker needs
 python24_d.lib (I do not have the DLL either).  I've not found it in any 
 of
 the
 downloads.

 So I tried to download the source to build it myself.  Of
 http://www.python.org/ftp/python/2.4.1/Python-2.4.1.tar.bz2 and
 http://www.python.org/ftp/python/2.4.1/Python-2.4.1.tgz, WinZip (9.0 SR1)
 just says Error reading header after processing 0 entries.

 Additionally, I've had no joy downloading the unzipper
 (ftp://sources.redhat.com/pub/bzip2/v102/bzip2-102-x86-win32.exe) from the
 site cited for the unzipper (http://sources.redhat.com/bzip2/).  It 
 flashed
 up a
 black console window momentarily.

 Oh, this is so frustrating! :-(

 Can anyone point me in the right direction?

 And then I can get to grips with my work.

 tia
 Bill

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


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


Re: Why Python does *SLICING* the way it does??

2005-04-20 Thread John Bokma
Raymond Hettinger wrote:

 to seeing code like:   for(i=0 ; in; i++) a[i]=f(i);   In contrast, a
 BASIC programmer may be used to FOR I = 1 to N:  a[I]=f(I); NEXT.   

Afaik, at least BBC BASIC uses zero based arrays :-) Maybe ZX Spectrum 
Basic too (too long ago to remember).

-- 
John   MexIT: http://johnbokma.com/mexit/
   personal page:   http://johnbokma.com/
Experienced programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: goto statement

2005-04-20 Thread John Bokma
Mage wrote:

 praba kar wrote:
 
Dear All,

   In Python what is equivalent to goto statement

  

 You shouldn't use goto in high-level languages.

Nonsense

-- 
John   MexIT: http://johnbokma.com/mexit/
   personal page:   http://johnbokma.com/
Experienced programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: goto statement

2005-04-20 Thread Reinhold Birkenfeld
John Bokma wrote:
 Mage wrote:
 
 praba kar wrote:
 
Dear All,

   In Python what is equivalent to goto statement

  

 You shouldn't use goto in high-level languages.
 
 Nonsense

Thank you!

Above all your claim is well justified. These brilliant arguments
you have put forth really explain in a magnificent way why goto is a
sane addition to any HLL.

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


Re: goto statement

2005-04-20 Thread Maxim Kasimov
Simon Brunning wrote:
On 4/20/05, Maxim Kasimov [EMAIL PROTECTED] wrote:
it would be quite useful for debuging porposes

How does goto help you to remove bugs?
I can certainly see how it helps you put them in in the first place...
if you need to comment a couple of code (and then uncomment ), what are you 
doing then?
--
Best regards,
Maxim Kasimov
mailto: [EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why Python does *SLICING* the way it does??

2005-04-20 Thread Nick Efford
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 Many people I know ask why Python does slicing the way it does.

 Can anyone /please/ give me a good defense/justification???

 I'm referring to why mystring[:4] gives me
 elements 0, 1, 2 and 3 but *NOT* mystring[4] (5th element).

mystring[:4] can be read as the first four characters of mystring.
If it included mystring[4], you'd have to read it as the first
five characters of mystring, which wouldn't match the appearance
of '4' in the slice.

Given another slice like mystring[2:4], you know instantly by
looking at the slice indices that this contains 4-2 = 2 characters
from the original string.  If the last index were included in the
slice, you'd have to remember to add 1 to get the number of
characters in the sliced string.

It all makes perfect sense when you look at it this way!


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


Re: goto statement

2005-04-20 Thread Robert Kern
Maxim Kasimov wrote:
Simon Brunning wrote:
On 4/20/05, Maxim Kasimov [EMAIL PROTECTED] wrote:
it would be quite useful for debuging porposes

How does goto help you to remove bugs?
I can certainly see how it helps you put them in in the first place...
if you need to comment a couple of code (and then uncomment ), what are 
you doing then?
Use comments?
--
Robert Kern
[EMAIL PROTECTED]
In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die.
  -- Richard Harter
--
http://mail.python.org/mailman/listinfo/python-list


Re: goto statement

2005-04-20 Thread Maxim Kasimov
Robert Kern wrote:
Maxim Kasimov wrote:
Simon Brunning wrote:
On 4/20/05, Maxim Kasimov [EMAIL PROTECTED] wrote:
it would be quite useful for debuging porposes


How does goto help you to remove bugs?
I can certainly see how it helps you put them in in the first place...
if you need to comment a couple of code (and then uncomment ), what 
are you doing then?

Use comments?
WOW, just greate! ... but i'd like to relax at some more interesting way 
than to comment each of rows
--
Best regards,
Maxim Kasimov
mailto: [EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: trying to understand unicode

2005-04-20 Thread John Machin
On 20 Apr 2005 10:58:35 GMT, F. Petitjean
[EMAIL PROTECTED] wrote:

Python has a very good support of unicode, utf8, encodings ... But I
have some difficulties with the concepts and the vocabulary.

You're not alone there. But I don't expect the docs for the Python
implementation of Unicode to explain the concepts and vocabulary of
Unicode. That's the job of the Unicode consortium, and they do a
not-unreasonable job of it; see www.unicode.org and in particular 

http://www.unicode.org/Public/UNIDATA/UCD.html

explains all the things that the Python unicodedata module is
implementing.


 The
documentation is not bad, but for example in reading
http://docs.python.org/lib/module-unicodedata.html
I had a long time to figure out what unicodedata.digit(unichr) would
mean, a simple example is badly lacking.

So I wrote the following script :

[snip]


I think that such code snippets should be included in the documentation
or in a Wiki.


Any effort should be directed (IMESHO) towards (a) keeping the URL in
the Python documentation up-to-date [it's not] (b) using the *LATEST*
version of the ucd file when each version of Python is released [still
stuck on 3.2.0 when the current version available from Unicode.org is
4.1.0]

[Exit, pursued by a bear.]
[Noises off.]

OK OK don't hit me, Martin, how about instructions on how to DIY,
then?

Cheers,
John

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


Re: XML parsing per record

2005-04-20 Thread Kent Johnson
Willem Ligtenberg wrote:
Willem Ligtenberg [EMAIL PROTECTED] wrote:
I want to parse a very large (2.4 gig) XML file (bioinformatics
ofcourse :)) But I have no clue how to do that. Most things I see read
the entire xml file at once. That isn't going to work here ofcourse.
So I would like to parse a XML file one record at a time and then be
able to store the information in another object.  How should I do
that?
The XML file I need to parse contains information about genes.
So the first element is a gene and then there are a lot sub-elements with
sub-elements. I only need some of the informtion and want to store it in
my an object called gene. Lateron this information will be printed into a
file, which in it's turn will be fed into some other program.
This is an example of the XML
?xml version=1.0?
!DOCTYPE Entrezgene-Set PUBLIC -//NCBI//NCBI Entrezgene/EN 
NCBI_Entrezgene.dtd
Entrezgene-Set
  Entrezgene
snip
  /Entrezgene
/Entrezgene-Set
This should get you started with cElementTree:
import cElementTree as ElementTree
source = 'Entrezgene.xml'
for event, elem in ElementTree.iterparse(source):
if elem.tag == 'Entrezgene':
# Process the Entrezgene element
geneid = 
elem.findtext('Entrezgene_track-info/Gene-track/Gene-track_geneid')
print 'Gene id', geneid
# Throw away the element, we're done with it
elem.clear()
Kent
--
http://mail.python.org/mailman/listinfo/python-list


Re: goto statement

2005-04-20 Thread Reinhold Birkenfeld
Maxim Kasimov wrote:
 Robert Kern wrote:
 Maxim Kasimov wrote:
 
 Simon Brunning wrote:

 On 4/20/05, Maxim Kasimov [EMAIL PROTECTED] wrote:

 it would be quite useful for debuging porposes




 How does goto help you to remove bugs?

 I can certainly see how it helps you put them in in the first place...


 if you need to comment a couple of code (and then uncomment ), what 
 are you doing then?
 
 
 Use comments?
 
 
 WOW, just greate! ... but i'd like to relax at some more interesting way than 
 to comment each of rows

Use multi-line string literals.

'''

This whole 'code' is commented out, and you can
use every type of quote except three singles.

'''

Or, if you really like the spirit of goto,
use if 0:.

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


Re: goto statement

2005-04-20 Thread Mage
Maxim Kasimov wrote:

 WOW, just greate! ... but i'd like to relax at some more interesting
 way than to comment each of rows

There are editors that can comment and uncomment blocks.

In worst case you can use  to comment blocks (not elegant but works).

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


RE: goto statement

2005-04-20 Thread Sander Steffann
On 4/20/05, praba kar [EMAIL PROTECTED] wrote:
In Python what is equivalent to goto statement

An old user-friendly cartoon that might be relevant:
http://ars.userfriendly.org/cartoons/?id=2506

Have fun :-)
Sander

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


Re: goto statement

2005-04-20 Thread Simon Brunning
On 4/20/05, Maxim Kasimov [EMAIL PROTECTED] wrote:
 WOW, just greate! ... but i'd like to relax at some more interesting way than 
 to comment each of rows

Get a decent text editor.

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


Re: goto statement

2005-04-20 Thread Do Re Mi chel La Si Do
+1



Michel Claveau



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


Re: goto statement

2005-04-20 Thread Torsten Bronger
Hallchen!

Maxim Kasimov [EMAIL PROTECTED] writes:

 [...]

 WOW, just greate! ... but i'd like to relax at some more
 interesting way than to comment each of rows

Then just use a good editor.

Tsch,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why Python does *SLICING* the way it does??

2005-04-20 Thread Torsten Bronger
Hallchen!

[EMAIL PROTECTED] (Nick Efford) writes:

 [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 Many people I know ask why Python does slicing the way it does.

 Can anyone /please/ give me a good defense/justification???

 I'm referring to why mystring[:4] gives me elements 0, 1, 2 and 3
 but *NOT* mystring[4] (5th element).

 mystring[:4] can be read as the first four characters of
 mystring.  If it included mystring[4], you'd have to read it as
 the first five characters of mystring, which wouldn't match the
 appearance of '4' in the slice.

 [...]

 It all makes perfect sense when you look at it this way!

Well, also in my experience every variant has its warts.  You'll
never avoid the i+1 or i-1 expressions in your indices or loops
(or your mind ;).

It's interesting to muse about a language that starts at 1 for all
arrays and strings, as some more or less obsolete languages do.  I
think this is more intuitive, since most people (including
mathematicians) start counting at 1.  The reason for starting at
0 is easier memory address calculation, so nothing for really high
level languages.

But most programmers are used to do it the Python (and most other
languages) way, so this opportunity has been missed for good.

Tsch,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Debugger with source code tracking ability

2005-04-20 Thread Jaime Wyant
I haven't tried the customizations listed at the site below.  If it
works, let me know.

http://page.sourceforge.net/tricks.html

jw

On 19 Apr 2005 19:45:05 -0700, Tran Tuan Anh [EMAIL PROTECTED] wrote:
 Hi all,
 
 I am new to Python and desperated to look for a good Python debugger.
 I mean a debugger with source coding tracking. For C/C++, emacs and
 gud offers execellent development env. The source code tracking is
 extremely useful for recursive functions.
 
 I have spent time Googling but not found anything near.
 
 Thanks!
 Tuan-Anh
 --
 http://mail.python.org/mailman/listinfo/python-list

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


exception handling

2005-04-20 Thread Mage
   Hello,


def error_msg(msg):
sys.exit(msg)

try:
do_something()
if value != my_wish:
   error_msg('Invalid input')
except:
print Fatal IO or Network error

This doesn't work because sys.exit raises an exception.

I know that I can define exception types after except, but there might
be many. Also I know I can write:
except:
if str(sys.exc_info()[0]) == 'exceptions.SystemExit':
raise

But honestly I would like simething like that:

except (!SystemExit):

Is this possible somehow?

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


Re: building a small calculator

2005-04-20 Thread aleksander . helgaker
I get the following error message when using the command sys.exit().

name 'sys' is not defined.

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


Re: Python instances

2005-04-20 Thread Kent Johnson
[EMAIL PROTECTED] wrote:
Guess i shouldn't think of the __init__(self) function as a constructor
then.
No, that's not it. You shouldn't think of variables defined outside of a 
method as instance variables.
In Java for example you can write something like
public class MyClass {
private List list = new ArrayList();
public void add(Object x) {
list.add(x);
}
}
In this case list is a member variable of MyClass instances; 'this' is implicit 
in Java.
In Python, if you write something that looks similar, the meaning is different:
class MyClass:
list = []
def add(self, x):
self.list.append(x)
In this case, list is an attribute of the class. The Java equivalent is a static attribute. In 
Python, instance attributes have to be explicitly specified using 'self'. So instance attributes 
have to be bound in an instance method (where 'self' is available):

class MyClass:
def __init__(self):
self.list = []
def add(self, x):
self.list.append(x)
Kent
--
http://mail.python.org/mailman/listinfo/python-list


Re: building a small calculator

2005-04-20 Thread Simon Brunning
On 20 Apr 2005 05:31:15 -0700, [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
 I get the following error message when using the command sys.exit().
 
 name 'sys' is not defined.

You really are new at this, aren't you? ;-) You need to import the sys
module before you use it. Put this at the top of your script:

import sys

I'd also suggest that you have a run through the tutorial -
http://docs.python.org/tut/. It's time well spent. If you don't get
on with that, there's another couple of tutorials available aimed
directly at those new to programming -
http://www.livewires.org.uk/python/ and
http://www.ibiblio.org/obp/thinkCSpy/.

Lastly, although neophytes are more than welcome here, you might find
the tutor mailing list a good place to ask questions in the early days
of your Python experience. You'll find it here -
http://mail.python.org/mailman/listinfo/tutor.

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


Re: building a small calculator

2005-04-20 Thread aleksander . helgaker
Sorry. This is my first day using Python.

Is there an equivelent to the goto command? I want to find some way to
take the user back to the main menu.

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


Redhat 9, Python 2.4.1, CGIHTTPServer problem

2005-04-20 Thread Bill Oldroyd
I cannot get a simple CGI-script to work with this combination :

Redhat 9 Linux
Both Python 2.41. and ActiveState Python 2.4.1

either as an Apache 2 cgi-script or using CGIHTTPServer.

The same script works fine on Redhat 7.3.

The script fails at 230 in CGIHTTPServer :

 osexecve(scriptfile,args.os.environ)

the error message being 
OSError: [Errno 2] No such file or directory

Can anyone through any light on this problem ?. 

I have seen a few references to problems in this area, but nothing
that is helpful in solving the problem.

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


Re: building a small calculator

2005-04-20 Thread Simon Brunning
On 20 Apr 2005 05:41:37 -0700, [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
 Sorry. This is my first day using Python.

Nothing to apologise for. We were all new to Python once.

 Is there an equivelent to the goto command? I want to find some way to
 take the user back to the main menu.

Funny you should mention that...

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/832906c6122dc137/f4cca2f994881220#f4cca2f994881220

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


Re: Writing to stdout and a log file

2005-04-20 Thread Michael Hoffman
Mike wrote:
I should've mentioned I want StdoutLog to subclass the 'file' type
because I need all the file attributes available.
You might use a surrogate pattern. Here's one I use for this kind of 
situation, where I want to subclass but that can't be done for some reason.

class SurrogateNotInitedError(exceptions.AttributeError):
pass
class Surrogate(object):
def __init__(self, data):
self._data = data
def __getattr__(self, name):
if name == _data:
raise SurrogateNotInitedError, name
else:
try:
return getattr(self._data, name)
except SurrogateNotInitedError:
raise SurrogateNotInitedError, name
I'll leave it as an exercise to the reader to make this work when 
self._data is actually a list of objects instead of a single object. 
You'll obviously need special logic for different methods, like write(), 
since for some of them you will want to call every object in self._data, 
and others only a single object.
--
Michael Hoffman
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why Python does *SLICING* the way it does??

2005-04-20 Thread Terry Hancock
On Wednesday 20 April 2005 01:36 am, Raymond Hettinger wrote:
 [EMAIL PROTECTED]
  Many people I know ask why Python does slicing the way it does.
 [...] 
 Python's way has some useful properties:
 [...]
 OTOH, it has some aspects that bite:
 [...]
 I suspect that whether it feels natural depends on your previous background 
 and
 whether you're working in an environment with arrays indexed from one or from
 zero.  For instance, C programmers are used to seeing code like:   for(i=0 ;
 in; i++) a[i]=f(i);   In contrast, a BASIC programmer may be used to FOR I = 
 1
 to N:  a[I]=f(I); NEXT.Hence, the C coders may find Python's a[:n] to be
 more natural than BASIC programmers.

Well, I learned Basic, Fortran, C, Python --- more or less.  And I first found
Python's syntax confusing as it didn't follow the same rules as any of the
previous ones.

However, I used to make off by one errors all the time in both C and Fortran,
whereas I hardly ever make them in Python.

So I like Python's slicing because it bites *less* than intervals in C or 
Fortran.

Cheers,
Terry


--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com

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


Re: Why Python does *SLICING* the way it does??

2005-04-20 Thread Antoon Pardon
Op 2005-04-20, Torsten Bronger schreef [EMAIL PROTECTED]:
 Hallöchen!

 [EMAIL PROTECTED] (Nick Efford) writes:

 [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 Many people I know ask why Python does slicing the way it does.

 Can anyone /please/ give me a good defense/justification???

 I'm referring to why mystring[:4] gives me elements 0, 1, 2 and 3
 but *NOT* mystring[4] (5th element).

 mystring[:4] can be read as the first four characters of
 mystring.  If it included mystring[4], you'd have to read it as
 the first five characters of mystring, which wouldn't match the
 appearance of '4' in the slice.

 [...]

 It all makes perfect sense when you look at it this way!

 Well, also in my experience every variant has its warts.  You'll
 never avoid the i+1 or i-1 expressions in your indices or loops
 (or your mind ;).

 It's interesting to muse about a language that starts at 1 for all
 arrays and strings, as some more or less obsolete languages do.  I
 think this is more intuitive, since most people (including
 mathematicians) start counting at 1.  The reason for starting at
 0 is easier memory address calculation, so nothing for really high
 level languages.

Personnaly I would like to have the choice. Sometimes I prefer to
start at 0, sometimes at 1 and other times at -13 or +7.

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


Re: goto statement

2005-04-20 Thread Michael Hoffman
praba kar wrote:
   In Python what is equivalent to goto statement
http://groups-beta.google.com/group/comp.lang.python/msg/98264a0daa007c46
--
Michael Hoffman
--
http://mail.python.org/mailman/listinfo/python-list


Re: Behaviour of str.split

2005-04-20 Thread David Fraser
Bengt Richter wrote:
On Wed, 20 Apr 2005 10:55:18 +0200, David Fraser [EMAIL PROTECTED] wrote:

Greg Ewing wrote:
Will McGugan wrote:

Hi,
I'm curious about the behaviour of the str.split() when applied to 
empty strings.

.split() returns an empty list, however..
.split(*) returns a list containing one empty string.

Both of these make sense as limiting cases.
Consider
 a b c.split()
['a', 'b', 'c']
 a b.split()
['a', 'b']
 a.split()
['a']
 .split()
[]
and
 **.split(*)
['', '', '']
 *.split(*)
['', '']
 .split(*)
['']
The split() method is really doing two somewhat different things
depending on whether it is given an argument, and the end-cases
come out differently.
You don't really explain *why* they make sense as limiting cases, as 
your examples are quite different.

Consider
a*b*c.split(*)
['a', 'b', 'c']
a*b.split(*)
['a', 'b']
a.split(*)
['a']
.split(*)
['']
Now how is this logical when compared with split() above?

The trouble is that s.split(arg) and s.split() are two different functions.
The first is 1:1 and reversible like arg.join(s.split(arg))==s
The second is not 1:1 nor reversible: 'various whitespace'.join(s.split()) 
== s ?? Not usually.
I think you can do it with the equivalent whitespace regex, preserving the 
splitout whitespace
substrings and ''.joining those back with the others, but not with split(). 
I.e.,
  def splitjoin(s, splitter=None):
 ... return (splitter is None and 'whitespace' or 
splitter).join(s.split(splitter))
 ...
  splitjoin('a*b*c', '*')
 'a*b*c'
  splitjoin('a*b', '*')
 'a*b'
  splitjoin('a', '*')
 'a'
  splitjoin('', '*')
 ''
  splitjoin('a bc')
 'awhitespacebwhitespacec'
  splitjoin('a b')
 'awhitespaceb'
  splitjoin('  b')
 'b'
  splitjoin('')
 ''
  splitjoin('*','*')
 '*'
Note why that works:
  '*'.split('*')
 ['', '', '', '', '', '']
  '*a'.split('*')
 ['', 'a']
  'a*'.split('*')
 ['a', '']
  splitjoin('*a','*')
 '*a'
  splitjoin('a*','*')
 'a*'
Thanks, this makes sense.
So ideally if we weren't dealing with backward compatibility these 
functions might have different names... split (with arg) and 
spacesplit (without arg)
In fact it would be nice to allow an argument to spacesplit specifying 
the characters regarded as 'space'
But all not worth breaking current code :-)

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


Re: exception handling

2005-04-20 Thread Peter Otten
Mage wrote:

 def error_msg(msg):
 sys.exit(msg)
 
 try:
 do_something()
 if value != my_wish:
error_msg('Invalid input')
 except:
 print Fatal IO or Network error
 
 This doesn't work because sys.exit raises an exception.
 
 I know that I can define exception types after except, but there might
 be many. Also I know I can write:
 except:
 if str(sys.exc_info()[0]) == 'exceptions.SystemExit':
 raise
 
 But honestly I would like simething like that:
 
 except (!SystemExit):
 
 Is this possible somehow?

try:
# may raise any exception
except SystemExit:
raise # propagate SystemExit (and subclasses)
except:
# handle everything else

Peter

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


Re: goto statement

2005-04-20 Thread Maxim Kasimov
Use multi-line string literals.
'''
it will not help if there is another ''' or/and  inside of code block
This whole 'code' is commented out, and you can
use every type of quote except three singles.
'''
Or, if you really like the spirit of goto,
use if 0:.
... and add tabs to each string
Reinhold

--
Best regards,
Maxim Kasimov
mailto: [EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why Python does *SLICING* the way it does??

2005-04-20 Thread Sion Arrowsmith
Raymond Hettinger [EMAIL PROTECTED] wrote:
[EMAIL PROTECTED]
 Many people I know ask why Python does slicing the way it does.
Python's way has some useful properties:

* s == s[:i] + s[i:]

* len(s[i:j]) == j-i # if s is long enough

The latter being particularly helpful when i = 0 -- the first n
elements are s[:n] . (Similarly elegantly, although of no
practical significance, s == s[0:len(s)] .)

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


Re: Why Python does *SLICING* the way it does??

2005-04-20 Thread Bill Mill
On 20 Apr 2005 12:52:19 GMT, Antoon Pardon [EMAIL PROTECTED] wrote:
 Op 2005-04-20, Torsten Bronger schreef [EMAIL PROTECTED]:
  Hallöchen!
 
  [EMAIL PROTECTED] (Nick Efford) writes:
 
  [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
  Many people I know ask why Python does slicing the way it does.
 
  Can anyone /please/ give me a good defense/justification???
 
  I'm referring to why mystring[:4] gives me elements 0, 1, 2 and 3
  but *NOT* mystring[4] (5th element).
 
  mystring[:4] can be read as the first four characters of
  mystring.  If it included mystring[4], you'd have to read it as
  the first five characters of mystring, which wouldn't match the
  appearance of '4' in the slice.
 
  [...]
 
  It all makes perfect sense when you look at it this way!
 
  Well, also in my experience every variant has its warts.  You'll
  never avoid the i+1 or i-1 expressions in your indices or loops
  (or your mind ;).
 
  It's interesting to muse about a language that starts at 1 for all
  arrays and strings, as some more or less obsolete languages do.  I
  think this is more intuitive, since most people (including
  mathematicians) start counting at 1.  The reason for starting at
  0 is easier memory address calculation, so nothing for really high
  level languages.
 
 Personnaly I would like to have the choice. Sometimes I prefer to
 start at 0, sometimes at 1 and other times at -13 or +7.
 

-1. You can start arrays at 0 or 1 (and arbitrary bases? I don't
recall) in VB, and it's an unmitigated disaster. It adds needless
complexity. What our slicing system loses in elegance in a few cases,
it more than makes up for in consistency throughout all programs.

Peace
Bill Mill
bill.mill at gmail.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: goto statement

2005-04-20 Thread Maxim Kasimov
Torsten Bronger wrote:
Hallchen!
Maxim Kasimov [EMAIL PROTECTED] writes:

[...]
WOW, just greate! ... but i'd like to relax at some more
interesting way than to comment each of rows

but what if i just can't to do this becouse i'm working thrue ssh, and have 
to use only installed editors (such as vi)
--
Best regards,
Maxim Kasimov
mailto: [EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why Python does *SLICING* the way it does??

2005-04-20 Thread Torsten Bronger
Hallchen!

Antoon Pardon [EMAIL PROTECTED] writes:

 Op 2005-04-20, Torsten Bronger schreef [EMAIL PROTECTED]:

 [...]

 It's interesting to muse about a language that starts at 1 for
 all arrays and strings, as some more or less obsolete languages
 do.  I think this is more intuitive, since most people (including
 mathematicians) start counting at 1.  The reason for starting
 at 0 is easier memory address calculation, so nothing for
 really high level languages.

 Personnaly I would like to have the choice. Sometimes I prefer to
 start at 0, sometimes at 1 and other times at -13 or +7.

In HTBasic you have the choice between 0 and 1; there is a global
source code directive for it.  However, hardly anybody really wants
to use HTBasic.

Tsch,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: goto statement

2005-04-20 Thread Simon Brunning
On 4/20/05, Maxim Kasimov [EMAIL PROTECTED] wrote:
  Or, if you really like the spirit of goto,
  use if 0:.
 
 ... and add tabs to each string

Get a decent text editor.

What are you using? Notepad?

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


Re: To decode the Subject =?iso-8859-2?Q?=... in email in python

2005-04-20 Thread Neil Hodgson
Dan Polansky:

 When parsing messages using python's libraries email and mailbox, the
 subject is often encoded using some kind of = notation. Apparently, the
 encoding used in this notation is specified like =?iso-8859-2?Q?=... or
 =?iso-8859-2?B?=. Is there a python library function to decode such a
 subject, returning a unicode string? The use would be like
 
   human_readable = cool_library.decode_equals(message['Subject'])

   Here is some code from a front end to Mailman moderation pages:

import email.Header
hdr = email.Header.make_header(email.Header.decode_header(sub))

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


Re: Python Debugger with source code tracking ability

2005-04-20 Thread Richard Eibrand
On 4/20/05, Jaime Wyant [EMAIL PROTECTED] wrote:
 I haven't tried the customizations listed at the site below.  If it
 works, let me know.
 
 http://page.sourceforge.net/tricks.html
 
 jw
 
 On 19 Apr 2005 19:45:05 -0700, Tran Tuan Anh [EMAIL PROTECTED] wrote:
  Hi all,
 
  I am new to Python and desperated to look for a good Python debugger.
  I mean a debugger with source coding tracking. For C/C++, emacs and
  gud offers execellent development env. The source code tracking is
  extremely useful for recursive functions.

You could take a look at Eclipse (http://eclipse.org/) in conjunction
with pydev (http://pydev.sourceforge.net/). Or you could take a look
at Komodo (http://www.activestate.com/Products/Komodo/) which is a
commercial product with a trial version.

Regards, 

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


Re: exception handling

2005-04-20 Thread Roy Smith
Mage [EMAIL PROTECTED] wrote:

Hello,
 
 
 def error_msg(msg):
 sys.exit(msg)
 
 try:
 do_something()
 if value != my_wish:
error_msg('Invalid input')
 except:
 print Fatal IO or Network error
 
 This doesn't work because sys.exit raises an exception.

Peter Otten posted a good way to do what you want, but I'm not convinced 
that it's a good idea.

You're assuming that any exception you get will be a Fatal IO or Network 
error.  What if it's not?  What if do_something() raises FutureWarning, or 
KeyboardInterrupt, or AssertionError, or DeprecationWarning, or anything 
else which has nothing to do with IO or networks?  You would just end up 
producing a misleading error message.

If you expect do_something() will throw certain exceptions, catch them 
specifically.  It's usually a mistake to catch everything.  It's certainly 
a mistake to catch everything and assume you know what it must be.

Try running the following code and see what happens:

import traceback

def do_something():
pass

try:
do_something()
if value != my_wish:
error_msg('Invalid input')
except:
print Fatal IO or Network error
print traceback.print_exc()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why Python does *SLICING* the way it does??

2005-04-20 Thread beliavsky
Terry Hancock wrote:

snip

 So I like Python's slicing because it bites *less* than intervals
in C or Fortran.

I disagree. Programming languages should not needlessly surprise
people, and a newbie to Python probably expects that x[1:3] =
[x[1],x[2],x[3]] . Array-oriented languages, such as Fortran 90/95,
Matlab/Octave/Scilab, and S-Plus/R do not follow the Python convention,
and I don't know of Fortran or R programmers who complain (don't follow
Matlab enough to say). There are Python programmers, such as the OP and
me, who don't like the Python convention. What languages besides Python
use the Python slicing convention?

Along the same lines, I think the REQUIREMENT that x[0] rather than
x[1] be the first element of list x is a mistake. At least the
programmer should have a choice, as in Fortran or VBA. In C starting at
0 may be justified because of the connection between array subscripting
and pointer arithmetic, but Python is a higher-level language where
such considerations are less relevant.

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


Re: Why Python does *SLICING* the way it does??

2005-04-20 Thread Roy Smith
Antoon Pardon [EMAIL PROTECTED] wrote:

 Personnaly I would like to have the choice. Sometimes I prefer to
 start at 0, sometimes at 1 and other times at -13 or +7.

Argggh.  Having two (or more!) ways to do it, would mean that every time I 
read somebody else's code, I would have to figure out which flavor they are 
using before I could understand what their code meant.  That would be evil.

What would actually be cool is if Python were to support the normal math 
notation for open or closed intervals.  Any of the following would make 
sense:

foo = bar (1, 2)
foo = bar (1, 2]
foo = bar [1, 2)
foo = bar [1, 2]

That would certainly solve this particular problem, but the cost to the 
rest of the language syntax would be rather high :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why Python does *SLICING* the way it does??

2005-04-20 Thread Antoon Pardon
Op 2005-04-20, Bill Mill schreef [EMAIL PROTECTED]:
 On 20 Apr 2005 12:52:19 GMT, Antoon Pardon [EMAIL PROTECTED] wrote:
 Op 2005-04-20, Torsten Bronger schreef [EMAIL PROTECTED]:
  Hallöchen!
 
  [EMAIL PROTECTED] (Nick Efford) writes:
 
  [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
  Many people I know ask why Python does slicing the way it does.
 
  Can anyone /please/ give me a good defense/justification???
 
  I'm referring to why mystring[:4] gives me elements 0, 1, 2 and 3
  but *NOT* mystring[4] (5th element).
 
  mystring[:4] can be read as the first four characters of
  mystring.  If it included mystring[4], you'd have to read it as
  the first five characters of mystring, which wouldn't match the
  appearance of '4' in the slice.
 
  [...]
 
  It all makes perfect sense when you look at it this way!
 
  Well, also in my experience every variant has its warts.  You'll
  never avoid the i+1 or i-1 expressions in your indices or loops
  (or your mind ;).
 
  It's interesting to muse about a language that starts at 1 for all
  arrays and strings, as some more or less obsolete languages do.  I
  think this is more intuitive, since most people (including
  mathematicians) start counting at 1.  The reason for starting at
  0 is easier memory address calculation, so nothing for really high
  level languages.
 
 Personnaly I would like to have the choice. Sometimes I prefer to
 start at 0, sometimes at 1 and other times at -13 or +7.
 

 -1. You can start arrays at 0 or 1 (and arbitrary bases? I don't
 recall) in VB, and it's an unmitigated disaster. It adds needless
 complexity.

Complexity that is now put on the programmers shoulders.

If I have a table with indexes going from -13 to +7, I have to
add the offset myself if I want to use a list for that.

 What our slicing system loses in elegance in a few cases,
 it more than makes up for in consistency throughout all programs.

You write this af if other solutions can't be consistent.

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


Re: goto statement

2005-04-20 Thread Peter Hansen
Maxim Kasimov wrote:
Torsten Bronger wrote:
Hallchen!
Maxim Kasimov [EMAIL PROTECTED] writes:
WOW, just greate! ... but i'd like to relax at some more
interesting way than to comment each of rows
but what if i just can't to do this becouse i'm working thrue ssh, and 
have to use only installed editors (such as vi)
Surely you use more than one-character indents?  If
that's so, you can just insert the if 0: using, say,
two characters indentation instead of the usual four.
Then the following four-character-indented code is
removed.
Alternatively, use ''' and ''' surrounding the code
block and it will be ignored.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: XML-RPC -- send file

2005-04-20 Thread Skip Montanaro

codecraig stefan:  i added, return 1 to my sendFile method on the 
server...took
codecraig care of the error, thanks.

Yes, by default XML-RPC doesn't support objects like Python's None.  As the
error message indicated you have to enable allow_none to permit transmission
of None.

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


Re: Why Python does *SLICING* the way it does??

2005-04-20 Thread Antoon Pardon
Op 2005-04-20, Roy Smith schreef [EMAIL PROTECTED]:
 Antoon Pardon [EMAIL PROTECTED] wrote:

 Personnaly I would like to have the choice. Sometimes I prefer to
 start at 0, sometimes at 1 and other times at -13 or +7.

 Argggh.  Having two (or more!) ways to do it, would mean that every time I 
 read somebody else's code, I would have to figure out which flavor they are 
 using before I could understand what their code meant.  That would be evil.

This is nonsens. table[i] = j, just associates value j with key i.
That is the same independend from whether the keys can start from
0 or some other value. Do you also consider it more ways because
the keys can end in different values?

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


Re: goto statement

2005-04-20 Thread Maxim Kasimov
Peter Hansen wrote:
Maxim Kasimov wrote:
Torsten Bronger wrote:
Hallchen!
Maxim Kasimov [EMAIL PROTECTED] writes:
WOW, just greate! ... but i'd like to relax at some more
interesting way than to comment each of rows

but what if i just can't to do this becouse i'm working thrue ssh, and 
have to use only installed editors (such as vi)

Surely you use more than one-character indents?  If
that's so, you can just insert the if 0: using, say,
two characters indentation instead of the usual four.
Then the following four-character-indented code is
removed.
Alternatively, use ''' and ''' surrounding the code
block and it will be ignored.
 f..., i don't requesting that goto was available in next versions of 
python,
 but i'm saying if it will be so, it will be easy and quickly _debug_ some 
skripts,
 _not only_ for commenting
--
Best regards,
Maxim Kasimov
mailto: [EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to run Python in Windows w/o popping a DOS box?

2005-04-20 Thread pyguy2
Python.exe starts up a windows console which gives you things stdin,
stderr, and stdout  from the C runtime.

Be warned that you do not have those things with the consoleless(?)
pythonw.exe, stuff which MS intends for gui applications.

It reminds me of select() on windows only working halfway (just
w/sockets) because of the history of how all this got added to windows.
A lot of half-way stuff.

john

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


Re: Why Python does *SLICING* the way it does??

2005-04-20 Thread Bill Mill
On 20 Apr 2005 13:39:42 GMT, Antoon Pardon [EMAIL PROTECTED] wrote:
 Op 2005-04-20, Bill Mill schreef [EMAIL PROTECTED]:
  On 20 Apr 2005 12:52:19 GMT, Antoon Pardon [EMAIL PROTECTED] wrote:
  Op 2005-04-20, Torsten Bronger schreef [EMAIL PROTECTED]:
   Hallöchen!
  
   [EMAIL PROTECTED] (Nick Efford) writes:
  
   [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
   Many people I know ask why Python does slicing the way it does.
  
   Can anyone /please/ give me a good defense/justification???
  
   I'm referring to why mystring[:4] gives me elements 0, 1, 2 and 3
   but *NOT* mystring[4] (5th element).
  
   mystring[:4] can be read as the first four characters of
   mystring.  If it included mystring[4], you'd have to read it as
   the first five characters of mystring, which wouldn't match the
   appearance of '4' in the slice.
  
   [...]
  
   It all makes perfect sense when you look at it this way!
  
   Well, also in my experience every variant has its warts.  You'll
   never avoid the i+1 or i-1 expressions in your indices or loops
   (or your mind ;).
  
   It's interesting to muse about a language that starts at 1 for all
   arrays and strings, as some more or less obsolete languages do.  I
   think this is more intuitive, since most people (including
   mathematicians) start counting at 1.  The reason for starting at
   0 is easier memory address calculation, so nothing for really high
   level languages.
 
  Personnaly I would like to have the choice. Sometimes I prefer to
  start at 0, sometimes at 1 and other times at -13 or +7.
 
 
  -1. You can start arrays at 0 or 1 (and arbitrary bases? I don't
  recall) in VB, and it's an unmitigated disaster. It adds needless
  complexity.
 
 Complexity that is now put on the programmers shoulders.
 
 If I have a table with indexes going from -13 to +7, I have to
 add the offset myself if I want to use a list for that.
 
  What our slicing system loses in elegance in a few cases,
  it more than makes up for in consistency throughout all programs.
 
 You write this af if other solutions can't be consistent.

Propose one, and I won't write it off without thinking, but my bias is
way against it from experience. Knowledge gets scattered across the
program, unless you're defining the start index every time you use the
list, which seems no better than adding an offset to me.

Peace
Bill Mill
bill.mill at gmail.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why Python does *SLICING* the way it does??

2005-04-20 Thread Diez B. Roggisch
 Personnaly I would like to have the choice. Sometimes I prefer to
 start at 0, sometimes at 1 and other times at -13 or +7.


Subclass from builtin list - and make the necessary adjustmenst yourself in
an overloaded __getitem__.

-- 
Regards,

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


Re: Why Python does *SLICING* the way it does??

2005-04-20 Thread Roy Smith
Antoon Pardon  [EMAIL PROTECTED] wrote:
Op 2005-04-20, Roy Smith schreef [EMAIL PROTECTED]:
 Antoon Pardon [EMAIL PROTECTED] wrote:

 Personnaly I would like to have the choice. Sometimes I prefer to
 start at 0, sometimes at 1 and other times at -13 or +7.

 Argggh.  Having two (or more!) ways to do it, would mean that every time I 
 read somebody else's code, I would have to figure out which flavor they are 
 using before I could understand what their code meant.  That would be evil.

This is nonsens. table[i] = j, just associates value j with key i.
That is the same independend from whether the keys can start from
0 or some other value. Do you also consider it more ways because
the keys can end in different values?

There are certainly many examples where the specific value of the
first key makes no difference.  A good example would be

for element in myList:
print element

On the other hand, what output does

   myList = [spam, eggs, bacon]
   print myList[1]

produce?  In a language where some lists start with 0 and some start
with 1, I don't have enough information just by looking at the above
code.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: goto statement

2005-04-20 Thread Reinhold Birkenfeld
Maxim Kasimov wrote:
 
 Use multi-line string literals.
 
 '''
 
 it will not help if there is another ''' or/and  inside of code block

Yes, but how often do you use them? And aren't you consistent in the choice
of your quotes?

 This whole 'code' is commented out, and you can
 use every type of quote except three singles.
 
 '''
 
 Or, if you really like the spirit of goto,
 use if 0:.
 
 ... and add tabs to each string

Yes. Where's the problem?

M-x indent-region-ly yours,
Reinhold
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: goto statement

2005-04-20 Thread Reinhold Birkenfeld
Maxim Kasimov wrote:

   f..., i don't requesting that goto was available in next versions of 
 python,
   but i'm saying if it will be so, it will be easy and quickly _debug_ some 
 skripts,
   _not only_ for commenting

If you want, you can always use the goto module.

Reinhold, no, I will not tell you where to find it
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python SSL Socket issue

2005-04-20 Thread adam
Try

con.connect()

before the first putrequest

-adam

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


Re: Redhat 9, Python 2.4.1, CGIHTTPServer problem

2005-04-20 Thread adam
It might not be the script, but might be the environment. I've been
burned by something similar in the past when I had my CGI script in my
home dir (default +r) and didnt have the permissions correct on the
dir. Not only does the script have to be +r +x, but the dir it is in
has to be as well for the apache user.

-adam

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


Re: goto statement

2005-04-20 Thread TZOTZIOY
On Wed, 20 Apr 2005 14:58:35 +0300, rumours say that Maxim Kasimov
[EMAIL PROTECTED] might have written:

 if you need to comment a couple of code (and then uncomment ), what 
 are you doing then?
 
 Use comments?
 
WOW, just greate! ... but i'd like to relax at some more interesting way than 
to comment each of rows

What editor exactly are you using that can't un/indent and un/comment a
block of lines?  Obviously, neither vi, nor emacs, nor idle.
-- 
TZOTZIOY, I speak England very best.
Be strict when sending and tolerant when receiving. (from RFC1958)
I really should keep that in mind when talking with people, actually...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: newbie question

2005-04-20 Thread Cameron Laird
In article [EMAIL PROTECTED],
Tiziano Bettio  [EMAIL PROTECTED] wrote:
.
.
.
If u want to achieve high performance you'd rather use c++ and directly 
access libs like nvidias cg, ms directx or opengl...
.
.
.
Yes.  Well, maybe.  Python-coded programs, even graphically-intense
games, *can* exhibit good performance, and there are numerous 
anecdotes about applications LOSING speed on conversion to C++ from
Python.  Moreover, there's no inherent conflict between C++ and
Python; some successful applications use both.

My summary:  it's a subtler matter than, for performance, abandon
Python on favor of C++.  I think you know that, but I want to make
it explicit for less-experienced readers.
-- 
http://mail.python.org/mailman/listinfo/python-list


random number between 0 and 20

2005-04-20 Thread aleksander . helgaker
How can I generate a random number between 0 - 20 and store the number
in nrrandom?

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


  1   2   3   >