[ANN] PyScript 0.5 released

2005-01-10 Thread Paul Cochrane
PyScript is a python module for producing high quality postscript 
graphics. Rather than use a GUI to draw a picture, the picture is 
programmed using python and the PyScript objects.

Some of the key features are:
* All scripting is done in python, which is a high level, easy to 
  learn, well developed scripting language.
* All the objects can be translated, scaled, rotated, ... in fact
  any affine transformation.
* Plain text is automatically kerned.
* You can place abritrary LaTeX expressions on your figures.
* You can create your own figure objects, and develop a library of 
  figure primitives.
* Output is publication quality.

LICENSE: Released under the GPL

The major change in this release is a complete rewrite of the Path 
object. The internals have completely changed and there have been 
some incompatible changes with previous versions but it's now much 
closer to what was envisaged for the object.  There have also been 
many bug fixes and minor other improvements.  For details see the 
PyScript web page: 
a href=http://pyscript.sourceforge.net;pyscript.sourceforge.net/a.

PA HREF=http://pyscript.sourceforge.net;PyScript 0.5/A - a 
python module for producing high quality postscript graphics; rather 
than use a GUI to draw a picture, the picture is programmed using 
python and the pyscript objects.  (10-Jan-05)

--
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


Python unicode

2005-01-10 Thread Michel Claveau - abstraction mta-galactique non triviale en fuite perptuelle.



Hi !If Python is Ok with Unicode, 
why the next script not run ?
# -*- 
coding: utf-8 -*-

def (toto): 
return(toto*3)

aret = (4)

@-salutations-- Michel 
Claveau
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: C structure in the Python extension

2005-01-10 Thread Craig Ringer
Dave win wrote:

Howdy:
   When I was writting interface functions of the extending python,  I
meet a question. As I using the  PyArg_ParseTuple(args,arg_type,...)
function call, if I wanna use the personal defined argument, such as the
C structure which I made. How to make it?

static PyObject* Call_V_ABSUB(PyObject *self, PyObject* args){
  myStruct FU;
  myStruct result;
  if(!PyArg_ParseTuple(args,O,FU)) return NULL;
^^^
How to modify here???
  V_ABSUB(FU);

  return Py_BuildValue(i,result);
}
  

You can't, really. Python code can't work with C structs directly, so it
can't pass you one. I have used one utterly hideous hack to do this when
prototyping code in the past, but that was before I knew about
PyCObject. PyCObject is also pretty evil if abused, but nowhere NEAR on
the scale of what I was doing. Can you say passing pointers around as
Python longs? Can't bring yourself to say it? Don't blame you. My only
defense was that it was quick hack prototype code, and that the Python/C
API for making classes is too painful to use when quickly prototyping
things.

To do what you want, you could encapsulate a pointer to the struct in a
PyCObject, then pass that around. Your Python code will just see a
PyCObject with no attributes or methods; it can't do anything to it
except pass it to other Python code (and delete it, but that'll result
in a memory leak if the PyCObject holds the only pointer to the struct).
Your C code can extract the pointer to the struct and work with that. DO
NOT do this if the Python code just deleting the PyCObject could ever
discard the last pointer to the struct, as you'll leak the struct.

A much BETTER option is probably to rewrite myStruct to be a Python type
(class) implemented in C, and provide it with both a C and Python API.
This isn't too hard, though the Python/C API does make creating types a
bit cumbersome. (Most of this seems to be because you're playing
pretend-we-have-objects in C, rather than issues specific to the
Python/C API).

--
Craig Ringer


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


Re: Writing huve ge Sets() to disk

2005-01-10 Thread Tim Peters
[Tim Peters]
 As I mentioned before, if you store keys in sorted text files,
 you can do intersection and difference very efficiently just by using
 the Unix `comm` utiltity.

[Martin MOKREJ]
 Now I got your point. I understand the comm(1) is written in C, but it still
 has to scan file1 once and file2 n-times, where n is a number of lines
 in file1, right? Without any index ... I'll consider it, actually will test,
 thanks!

`comm` is much more efficient than that.  Note that the input files
have to be sorted.  Then, in a single pass over both files (not 2
passes, not 3, not n, just 1), it can compute any subset of these
three (do `man comm`):

1. The words common to both files.
2. The words unique to the first file.
3. The words unique to the second file.

It's essentially just doing a merge on two sorted lists, and how it
works should be obvious if you give it some thought.  It takes time
proportional to the sum of the lengths of the input files, and nothing
*can* be faster than that.

 I was really hoping I'll get an answer how to alter the indexes for 
 dictionaries
 in python.

Sorry, I don't have a guess for what that might mean.

 You convinced me not to even try to construct to theoretical dictionary,
 as it will take ages just to create. Even if I'd manage, I couldn't
 save it (the theoretical and possibly not even the dict(theoret) - dict(real)
 result).

Worse, it didn't sound like a good approach even if you could save it.

 Still, before I give the whole project, once more:
 
 I'll parse some text files, isolates separate words and add them to
 either Set(), list, dict, flatfile line by line.

 Depending on the above, I'll compare them and look for those unique
 to some language. I need to keep track of frequencies used
 in every such language,

Frequencies of what?  A language here can contain some words
multiple times each?

 so the dict approach would be the best.  The number stored as a value vould
 be a float ^H^H^H^H^H^H Decimal() type - very small number.

Integers are the natural type for counting, and require less memory
than floats or decimals.

 Once more, I expect to have between E4 or E5 to E8??? words
 stored in 20 dictionaries (remember words of sizes in range 1-20?
 Every of those 20 dictionaries should be, I believe, indexed just once.
 The indexing method should know all entries in a given file are of same
 size, i.e. 5 chars, 15 chars, 20 chars etc.

I think you're making this more complicated than it needs to be.

 I already did implement the logic to walk through those 20 different
 dictionaries from language a and from language b and find uout those
 unique to a or common to both of them. Why I went to ask on this list
 was to make sure I took right approach. Sets seemed to be better solution
 for the simple comparison (common, unique). To keep track of those
 very small frequencies, I anyway have to have dictionaries. I say
 that again, how can I improve speed of dictionary indexing?
 It doesn't matter here if I have 10E4 keys in dictionary or
 10E8 keys in a dictionary.

What reason do you have for believing that the speed of dictionary
indexing is worth any bother at all to speed up?  Dict lookup is
generally considered to be extremely fast already.  If you're just
*guessing* that indexing is the bottleneck, you're probably guessing
wrong -- run a profiler to find out where the real bottleneck is.
--
http://mail.python.org/mailman/listinfo/python-list


Re: static compiled python modules

2005-01-10 Thread Thomas Linden
Nick Coghlan wrote:
 http://www.python.org/dev/doc/devel/api/importing.html
 Take a look at the last three entries about registering builtin modules.

Thanks a lot, it works!


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


Re: Old Paranoia Game in Python

2005-01-10 Thread McBooCzech
Newbie in Python.
I did copy the whole script form the web and save it as para1.py. I did
download pyparsing module and save it to
C:\\Python23\\Lib\\pyparsing122.
I did run following script:

import sys
sys.path.append('C:\\Python23\\Lib\\pyparsing122')

from pyparsing import *
extraLineBreak = White( ,exact=1) + LineEnd().suppress()
text = file(Para1.py).read()
newtext = extraLineBreak.transformString(text)
file(para2.py,w).write(newtext)

I did try to run para2.py script, but following message

File para2.py, line 169
choose(4,You give your correct clearance,5,You lie and claim
^
SyntaxError: EOL while scanning single-quoted string

So my questions are:
Why pyparser didn't correct the script?
What I am doing wrong?
Is it necessary to correct the script by hand anyway?

Petr

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


Re: complex numbers

2005-01-10 Thread It's me
For those of us that works with complex numbers, having complex number as a
natively supported data type is a big advantage.  Non-native add-ons are not
sufficient and lead to very awkward program code.


Jürgen Exner [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 [EMAIL PROTECTED] wrote:
  #python supports complex numbers.
 [...]

 So?


The world would come to a halt if all of a sudden nobody understands complex
numbers anymore.  :-)

  # Perl doesn't support complex numbers. But there are packages that
  supports it.

 The Math::Complex module is part of the standard installation already, no
 need for any packages (whatever that might be).
 Did you check perldoc Math::Complex

 NAME
 Math::Complex - complex numbers and associated mathematical functions
 [...]

 jue




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


Re: Writing huge Sets() to disk

2005-01-10 Thread Scott David Daniels
Martin MOKREJ wrote:
 But I don't think I can use one-way hashes, as I need to reconstruct
the string later. I have to study hard to get an idea what the proposed 
 code really does.
Scott David Daniels wrote:
Tim Peters wrote:
 Call the set of all English words E; G, C, and P similarly.
This Python expression then gives the set of words common to all 4:
E  G  C  P
and for those unique to Polish.
P -  E - G  - C
One attack is to define a hash to get sizes smaller.  Suppose you find
your word sets are 10**8 large, and you find you need to deal with sets
of size 10**6.  Then if you define a hash that produces an integer below
100, you'll find:
E  G  C  P == Union(E_k  G_k  C_k  P_k) for k in range(100)
P -  E - G  - C == Union(P_k - E_k - G_k - C_k) for k in range(100)
where X_k = [v for v in X if somehash(v) == k]
I don't understand here what would be the result from the hashing 
function. :(  ... Can you clarify this please in more detail?
The trick is to build the X_k values into files.
For example:
for base in range(0, 100, 10):
# work in blocks of 10 (or whatever)
for language in ('English', 'German', 'Czech', 'Polish'):
source = open(language)
dests = [open('%s_%s.txt' % (language.lower(), base + n), 'w')
 for n in range(10)]
for word in source:  # Actually this is probably more involved
code = somehash(word) - base
if 0 = code  base:
dests[code].write(word + '\n')
for dest in dests:
dest.close()
source.close()
After running the above code, you get 400 files with names like, for
example, 'english_33.txt'.  'english_33.txt' contains only words in
English which hash to 33.  Then you need to sort the different files
(like 'english_33.txt') before using them in the next phase.  If you
can sort and dupe-elim in the same step, do that and get rid of the
calls to dupelim below.  Otherwise use dupelim below when reading the
sorted files.  If you must, you might want to do the sort and
dupe-elim in Python:
for language in ('english', 'german', 'czech', 'polish'):
for hashcode in range(100):
filename = '%s_%s.txt' % (language, hashcode)
source = open(filename)
lines = sorted(source)
source.close()
dest = open(filename, 'w')
for line in dupelim(lines):
dest.write(line)
dest.close()
 def inboth(left, right): 
 def leftonly(left, right): 
Aaaah, so the functions just walk one line in left, one line in right, 
if values don't match the value in left is unique, it walks again one
line in left and checks if it already matches the value in right file
in the last position, and so on until it find same value in the right file?
Exactly, you must make sure you deal with cases where you pass values,
match values, and run out of source -- that keeps these from being four-
liners.
 For example:

 Ponly = open('polishonly.txt', 'w')
 every = open('every.txt', 'w')
 for hashcode in range(100):
English = open('english_%s.txt' % hashcode)
 ^^ this is some kind of eval?
If  hashcode == 33  then 'english_%s.txt' % hashcode == 'english_33.txt'
So we are just finding the language-specific for-this-hash source.
... for unmatched in leftonly(leftonly(leftonly(dupelim(Polish),
 dupelim(English)), dupelim(German)), dupelim(Czech)):
Ponly.write(unmatched)
 for source in (Polish, English, German, Czech):#(paraphrased)
 source.seek(0)
 for match in inboth(inboth(dupelim(Polish), upelim(English)),
   inboth(dupelim(German), dupelim(Czech))):
 every.write(match)
 for source in (Polish, English, German, Czech):#(paraphrased)
 source.close()
 Ponly.close()
 every.close()
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: time module precision

2005-01-10 Thread Peter Hansen
[EMAIL PROTECTED] wrote:
Peter Hansen wrote:
_Why_ do you want to wait such brief amounts of time?
What I am trying to do is sending binary data to a serial port. Since
the device attached to the port cannot handle a continous in-flow of
data, I need to make an artificial tiny delay in-between data chunks(a
few hundreds of KBs). The delay might be a few tens to hundreds of us.
I guess you've checked that your situation can't take advantage
of either hardware handshaking (e.g. RTS/CTS) or software handshaking
(Xon/Xoff) to do flow control.
Something doesn't quite feel right in your description, however,
but it could simply be because the sorts of devices we work with
are quite different.  I'm very surprised to hear about a device
that can manage to absorb *hundreds of KBs* of data without any
handshaking, and yet after that much data suddenly manages to
have a hiccup on the order of mere microseconds before it can
take more data.
Also, is your data rate so high that a few hundred microseconds
represents a noticeable delay?  I'm rarely dealing with data
rates higher than, say, 38400bps, where hundreds of KBs would take
on the order of minutes, so 100us is effectively instantaneous
in my world.
I calculate that your data rate would have to be higher than
307Mbps (a third of a gigabit per second) before 100us would
represent a large enough delay (measured in bits rather than
time) that you would be bothered by it... (defined somewhat
arbitrarily as more than 2% of the time required to send
100KB of data at your data rate).
I'd like to make the transmission as fast as possible, uh.. well..
reasonably fast.
I suspect it will be, if you simply do a time.sleep(0.001) and
pretend that's shorter than it really is...  since WinXP
is not a realtime OS, sometimes that could take as long as
hundreds of milliseconds, but it's very unlikely that anyone
will ever notice.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Operating System???

2005-01-10 Thread Paul Rubin
Roose [EMAIL PROTECTED] writes:
 Well, then of course you know I have to say:  An OS does not run inside a
 browser.  There's a sentence I never thought I'd utter in my lifetime.
 
 So that is an irrelevant example, since it obviously isn't a task scheduler
 in the context of this thread.

Huh?  I'm just baffled why you think writing a scheduler in an OS is
harder than writing one in an application.  You have some means of
doing a coroutine switch in one situation, and some means of doing a
hardware context switch in the other.  Aside from that the methods are
about the same.

Why do you think there's anything difficult about doing this stuff in
Python, given the ability to call low level routines for some hardware
operations as needed?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Writing huge Sets() to disk

2005-01-10 Thread John Lenton
On Tue, Jan 11, 2005 at 12:33:42AM +0200, Simo Melenius wrote:
 John Lenton [EMAIL PROTECTED] writes:
 
  you probably want to look into building set-like objects ontop of
  tries, given the homogeneity of your language. You should see
  imrpovements both in size and speed.
 
 Ternary search trees give _much_ better space-efficiency compared to
 tries, at the expense of only slightly slower build and search time.
 This is especially essential as the OP mentioned he could have huge
 sets of data.

hmm! sounds like *some*body needs to go read up on ternary trees,
then.

Ok, ok, I'm going...

-- 
John Lenton ([EMAIL PROTECTED]) -- Random fortune:
Fortune finishes the great quotations, #6

But, soft!  What light through yonder window breaks?
It's nothing, honey.  Go back to sleep.


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

Re: Writing huge Sets() to disk

2005-01-10 Thread Paul Rubin
Martin MOKREJ¦ [EMAIL PROTECTED] writes:
   I have sets.Set() objects having up to 20E20 items,
   just imagine, you want to compare how many words are in English, German,
 Czech, Polish disctionary. You collect words from every language and record
 them in dict or Set, as you wish.
 
   Once you have those Set's or dict's for those 4 languages, you ask
 for common words and for those unique to Polish. I have no estimates
 of real-world numbers, but we might be in range of 1E6 or 1E8?
 I believe in any case, huge.

They'll be less than 1e6 and so not huge by the standards of today's
computers.  You could use ordinary dicts or sets.

1e20 is another matter.  I doubt that there are any computers in the
world with that much storage.  How big is your dataset REALLY?

   I wanted to be able to get a list of words NOT found in say Polish,
 and therefore wanted to have a list of all, theoretically existing words.
 In principle, I can drop this idea of having ideal, theoretical lexicon.
 But have to store those real-world dictionaries anyway to hard drive.

One way you could do it is by dumping all the words sequentially to
disk, then sorting the resulting disk file using an O(n log n) offline
algorithm.

Basically data sets of this size are outside of what you can easily
handle with builtin Python operations without putting some thought
into algorithms and data structures.  From ribosome I'm guessing
you're doing computational biology.  If you're going to be writing
code for these kinds of problems on a regular basis, you probably
ought to read a book or two on the topic.  CLRS is a good choice:

  http://theory.lcs.mit.edu/~clr/
  http://mitpress.mit.edu/algorithms/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: exceptions and items in a list

2005-01-10 Thread Peter Hansen
rbt wrote:
Andrey Tatarinov wrote:
# skip bad object and continue with others
for object in objects:
try:
#do something to object
except Exception:
pass
Thanks Andrey. That's a great example of how to do it.
Actually, it's not really a great example, since it catches
_all_ exceptions that might happen, and quietly ignores
them.  For example, in the following code, you might not
realize that you've made a typo and none of the items in
the list are actually being checked, even though there is
obviously no problem with any of these simple items
(integers from 0 to 9).
def fornat_value(val):
return '-- %5d --' % val
L = range(10)
for val in L:
try:
print format_value(val)
except Exception:
pass
It's almost always better to identify the *specific*
exceptions which you are expecting and to catch those,
or not do a simple pass.  See Vincent's response,
for example, where he explicitly asks only for ValueErrors
and lets others propagate upwards, to be reported.
(I realize these were contrived examples, but examples
that don't mention this important issue risk the propagation
of buggy code...)
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Port blocking

2005-01-10 Thread Steve Holden
Mark Carter wrote:
Paul Rubin wrote:
Mark Carter [EMAIL PROTECTED] writes:
Supposing I decide to write a server-side application using something
like corba or pyro.

Usually you wouldn't run a public corba or pyro service over the
internet.  You'd use something like XMLRPC over HTTP port 80 partly
for the precise purpose of not getting blocked by firewalls.

Although, when you think about it, it kinda defeats the purposes of 
firewalls. Not that I'm criticising you personally, you understand.

Yet another brilliant Microsoft marketing concept: Shit, these bloody 
firewalls are getting in the way of our new half-baked ideas for 
application architectures to replace all that funky not-invented-here 
open source stuff we can't charge money for. Let's design something that 
completely screws up existing firewall strategies, then we can charge 
people extra to firewall the new stuff after we've hooked them all on 
yet another inferior execution of existing ideas.

Also, is there a good tool for writing database UIs?

Yes, quite a few.

Ah yes, but is there really? For example, I did a search of the TOC of 
GTK+ Reference Manual:
http://developer.gnome.org/doc/API/2.0/gtk/index.html
for the word data, and there's apparently no widget which is 
explicitly tied to databases. So in GTKs case, for instance, it looks 
like one has to roll one's own solution, rather than just using one out 
of the box.
There isn't, IMHO, anything with the polish of (say) Microsoft Access, 
or even Microsoft SQL Server's less brilliant interfaces. Some things 
Microsoft *can* do well, it's a shame they didn't just stick to the 
knitting.

regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: Port blocking

2005-01-10 Thread Paul Rubin
Mark Carter [EMAIL PROTECTED] writes:
 Also, is there a good tool for writing database UIs?
  Yes, quite a few.
 
 Ah yes, but is there really? For example, I did a search of the TOC of
 GTK+ Reference Manual:

Try looking on freshmeat or sourceforge instead.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Writing huge Sets() to disk

2005-01-10 Thread Paul Rubin
=?windows-1252?Q?Martin_MOKREJ=8A?= [EMAIL PROTECTED] writes:
 Yes, I'm. I still don't get what that acronym CLRS stands for ... :(

CLRS = the names of the authors, Cormen, Leiserson, Rivest, and Stein,
if I spelled those correctly.  :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Port blocking

2005-01-10 Thread Ed Leafe
On Jan 10, 2005, at 8:00 PM, Steve Holden wrote:
Ah yes, but is there really? For example, I did a search of the TOC 
of GTK+ Reference Manual:
http://developer.gnome.org/doc/API/2.0/gtk/index.html
for the word data, and there's apparently no widget which is 
explicitly tied to databases. So in GTKs case, for instance, it looks 
like one has to roll one's own solution, rather than just using one 
out of the box.
There isn't, IMHO, anything with the polish of (say) Microsoft Access, 
or even Microsoft SQL Server's less brilliant interfaces. Some things 
Microsoft *can* do well, it's a shame they didn't just stick to the 
knitting.
	shameless plugThough it's certainly not anywhere near the polish of 
Access, you should check out Dabo. It's designed from the ground up to 
be a database application framework, and is on its way to achieving 
that goal. Right now you still have to do all the UI stuff in code, but 
we're just starting to develop the visual UI Designer. Stay 
tuned!/shameless plug

 ___/
/
   __/
  /
 /
 Ed Leafe
 http://leafe.com/
 http://dabodev.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Chicago Python Users Group: Thu 13 Jan Meeting

2005-01-10 Thread Steve Holden
Ian Bicking wrote:
The Chicago Python User Group, ChiPy, will have its next meeting on
Thursday, 13 January 2005, starting at 7pm.  For more information on
ChiPy see http://chipy.org
[...]
About ChiPy
---
We meet once a month, on the second Thursday of the month.  If you
can't come this month, please join our mailing list:
http://lonelylion.com/mailman/listinfo/chipy
Ian:
I am teaching class in Chicago the week of February 22 (I'll be in 
Schaumberg and available any evening from 21-24). Since that doesn't 
coincide woth your regular schedule, I wonder if you'd like to mention 
that I'd be up for a beer and/or meal and a natter with any Chicago 
Pythonistas who happen to fancy it.

Anyone who so wishes can then email me.
regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: Writing huve ge Sets() to disk

2005-01-10 Thread Martin MOKREJ
Tim Peters wrote:
[Tim Peters]
As I mentioned before, if you store keys in sorted text files,
you can do intersection and difference very efficiently just by using
the Unix `comm` utiltity.

[Martin MOKREJ]
Now I got your point. I understand the comm(1) is written in C, but it still
has to scan file1 once and file2 n-times, where n is a number of lines
in file1, right? Without any index ... I'll consider it, actually will test,
thanks!

`comm` is much more efficient than that.  Note that the input files
have to be sorted.  Then, in a single pass over both files (not 2
passes, not 3, not n, just 1), it can compute any subset of these
three (do `man comm`):
1. The words common to both files.
2. The words unique to the first file.
3. The words unique to the second file.
I read the manpage actually before answering to the list.
It's essentially just doing a merge on two sorted lists, and how it
works should be obvious if you give it some thought.  It takes time
proportional to the sum of the lengths of the input files, and nothing
*can* be faster than that.
Well, I think I understand now because Scott David Daniels wrote
probably the very same logic in python code in this thread.
I was really hoping I'll get an answer how to alter the indexes for dictionaries
in python.

Sorry, I don't have a guess for what that might mean.
I'm not an expert, mysql for example givs you ability to index say
first 10 characters of a text column, which are typically varchar.
Just for curiosity I'd like to know how do it in python.
When importing data from a flatfile into mysql table, there's an
option to delay indexing to the very last moment, when all keys are
loaded (it doesn't make sense to re-create index after each new
row into table is added). I believe it's exactly same waste of cpu/io
in this case - when I create a dictionary and fill it with data,
I want to create index afterward, not after every key/value pair
is recorded.
You convinced me not to even try to construct to theoretical dictionary,
as it will take ages just to create. Even if I'd manage, I couldn't
save it (the theoretical and possibly not even the dict(theoret) - dict(real)
result).

Worse, it didn't sound like a good approach even if you could save it.

Still, before I give the whole project, once more:
I'll parse some text files, isolates separate words and add them to
either Set(), list, dict, flatfile line by line.
Depending on the above, I'll compare them and look for those unique
to some language. I need to keep track of frequencies used
in every such language,

Frequencies of what?  A language here can contain some words
multiple times each?
Yes, to compute the frequency of each word used in say language A,
I'll count number of occurencies and them compute frequency of it.
Frequency number should be recorded as a value in the dictionary,
where the keys are unique and represent the word itself (or it's hash
as recommended already).
Once more, the dictionary will contain every word only once, it will be really
a unique key.
so the dict approach would be the best.  The number stored as a value vould
be a float ^H^H^H^H^H^H Decimal() type - very small number.

Integers are the natural type for counting, and require less memory
than floats or decimals.
I hoped I was clear ... when I said I'll compute frequency of those words.
The algorithm to compute it will be subject to change during developemnt. ;)

Once more, I expect to have between E4 or E5 to E8??? words
stored in 20 dictionaries (remember words of sizes in range 1-20?
Every of those 20 dictionaries should be, I believe, indexed just once.
The indexing method should know all entries in a given file are of same
size, i.e. 5 chars, 15 chars, 20 chars etc.

I think you're making this more complicated than it needs to be.
I hope the algoritm can save some logic. For example, can turn off locking 
support,
index only part of the key etc.

I already did implement the logic to walk through those 20 different
dictionaries from language a and from language b and find uout those
unique to a or common to both of them. Why I went to ask on this list
was to make sure I took right approach. Sets seemed to be better solution
for the simple comparison (common, unique). To keep track of those
very small frequencies, I anyway have to have dictionaries. I say
that again, how can I improve speed of dictionary indexing?
It doesn't matter here if I have 10E4 keys in dictionary or
10E8 keys in a dictionary.

What reason do you have for believing that the speed of dictionary
indexing is worth any bother at all to speed up?  Dict lookup is
generally considered to be extremely fast already.  If you're just
*guessing* that indexing is the bottleneck, you're probably guessing
wrong -- run a profiler to find out where the real bottleneck is.
For example, looking up a key with it's value only once in the whole for 
loop tells me
I don't need an index. Yes, I'll do this 4 times for those 4 languages, but
still I think it's 

Re: Port blocking

2005-01-10 Thread Aldo Cortesi
Thus spake Steve Holden ([EMAIL PROTECTED]):

 I teach the odd security class, and what you say is far
 from true. As long as the service is located behind a
 firewall which opens up the correct holes for it, it's
 most unlikely that corporate firewalls would disallow
 client connections to such a remote port.

Don't be too sure about that - most of the well-run
corporate networks I have been involved with block outbound
traffic by default. It is certainly sound security policy to
shunt outbound traffic through intermediary servers (e.g.
SMTP) and proxies (e.g. HTTP and FTP) so that it can be
logged, monitored, tracked, and controlled.

This is the strategy I recommend to my clients - the only
sensible one in a world of spyware, worms, insecure web
browsers and corporate espionage...




Cheers,


Aldo



--
Aldo Cortesi
[EMAIL PROTECTED]
http://www.nullcube.com
Off: (02) 9283 1131
Mob: 0419 492 863
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why not datetime.strptime() ?

2005-01-10 Thread Joshua Spoerri
Skip Montanaro skip at pobox.com writes:
 josh Shouldn't datetime have strptime?
 If someone wants to get their feet wet with extension module
 programming
 this might be a good place to start.  Mostly, I think nobody who has
 needed/wanted it so far has the round tuits available to spend on the
 task.

OK, it was pretty straightforward. Thanks for the direction.

To whom should I send the patch (attached)?
--- Modules/datetimemodule.c.orig   2003-10-20 10:34:46.0 -0400
+++ Modules/datetimemodule.c2005-01-10 20:58:38.884823296 -0500
@@ -3774,6 +3774,32 @@
return result;
 }
 
+/* Return new datetime from time.strptime(). */
+static PyObject *
+datetime_strptime(PyObject *cls, PyObject *args)
+{
+   PyObject *result = NULL, *obj, *module;
+   const char *string, *format;
+
+   if (!PyArg_ParseTuple(args, ss:strptime, string, format))
+   return NULL;
+   if ((module = PyImport_ImportModule(time)) == NULL)
+   return NULL;
+   obj = PyObject_CallMethod(module, strptime, ss, string, format);
+   Py_DECREF(module);
+
+   result = PyObject_CallFunction(cls, iii,
+   PyInt_AsLong(PySequence_GetItem(obj, 0)),
+   PyInt_AsLong(PySequence_GetItem(obj, 1)),
+   PyInt_AsLong(PySequence_GetItem(obj, 2)),
+   PyInt_AsLong(PySequence_GetItem(obj, 3)),
+   PyInt_AsLong(PySequence_GetItem(obj, 4)),
+   PyInt_AsLong(PySequence_GetItem(obj, 5)),
+   PyInt_AsLong(PySequence_GetItem(obj, 6)));
+   Py_DECREF(obj);
+   return result;
+}
+
 /* Return new datetime from date/datetime and time arguments. */
 static PyObject *
 datetime_combine(PyObject *cls, PyObject *args, PyObject *kw)
@@ -4385,6 +4411,11 @@
 PyDoc_STR(timestamp - UTC datetime from a POSIX timestamp 
   (like time.time()).)},
 
+   {strptime, (PyCFunction)datetime_strptime,
+METH_VARARGS | METH_CLASS,
+PyDoc_STR(strptime - new datetime parsed from a string
+  (like time.strptime()).)},
+
{combine, (PyCFunction)datetime_combine,
 METH_VARARGS | METH_KEYWORDS | METH_CLASS,
 PyDoc_STR(date, time - datetime with same date and time fields)},
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Securing a future for anonymous functions in Python

2005-01-10 Thread Tim Peters
...

[Anna]
 BTW - I am *quite* happy with the proposal for where: syntax - I
 think it handles the problems I have with lambda quite handily.

[Steve Holden]
 Whereas I find it to be an excrescence, proving (I suppose) that one
 man's meat is another person's poison, or something.

I've been waiting for someone to mention this, but looks like nobody
will, so I'm elected.  Modern functional languages generally have two
forms of local-name definition, following common mathematical
conventions.  where was discussed here.  The other is let/in, and
seems a more natural fit to Python's spelling of block structure:

let:
suite
in:
suite

There's no restriction to expressions here.  I suppose that, like the
body of a class, the `let` suite is executed starting with a
conceptually empty local namespace, and whatever the suite binds to a
local name becomes a temporary binding in the `in` suite (like
whatever a class body binds to local names becomes the initial value
of the class __dict__).  So, e.g.,

i = i1 = 3
let:
i1 = i+1
from math import sqrt
in:
print i1, sqrt(i1)
print i1,
print sqrt(i1)

would print

4 2
3

and then blow up with a NameError.

LIke it or not, it doesn't seem as strained as trying to pile more
gimmicks on Python expressions.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Writing huge Sets() to disk

2005-01-10 Thread Tim Peters
[Istvan Albert] 
 #- I think that you need to first understand how dictionaries work. 
 #- The time needed to insert a key is independent of 
 #- the number of values in the dictionary. 

[Batista, Facundo]
 Are you sure? 
 
 I think that is true while the hashes don't collide. If you have collisions,
 time starts to depend of element quantity. But I'm not sure

 Tim sure can enlighten us. 

I can only point the way to enlightenment -- you have to contemplate
your own navel (or Guido's, but he's kind of shy that way).

What Istvan Albert said is close enough in context.  The *expected*
(mean) number of collisions in a Python dict probe is less than 1,
regardless of dict size.  That assumes the collision distribution is
no worse than random.  It's possible that all dict keys hash to the
same table slot, and then each insertion is O(len(dict)).  It's
possible to contrive such cases even if the hash function is a good
one.  But it's not going to happen by accident (and, when it does
wink, open a bug report -- we'll improve the key type's hash
function then).
-- 
http://mail.python.org/mailman/listinfo/python-list


fetching method names from a class, and the parameter list from a method

2005-01-10 Thread Philippe C. Martin
Is this possible ?

I am trying to have auto-completion working in a shell I wrote but I
currently have the method lists done by hand (ie; if I add/subtract a
method from that class, then my auto-completion is out of date).

Same issue with method parameters.

I have parsed through many of the attributes (ex: I use method.__doc__)
but have not yet found a way to achieve the above goal.

Is there a way? something like the following would be great:
1) list = Class.__methods__
2) dict (because of default values: param = None) =
Class.__method__[0].__params__



Regards,


Philippe



-- 
***
Philippe C. Martin
SnakeCard LLC
www.snakecard.com
***

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


OT: MoinMoin and Mediawiki?

2005-01-10 Thread Paul Rubin
I need to set up a wiki for a small group.  I've played with MoinMoin
a little bit and it's reasonably straightforward to set up, but
limited in capabilities and uses BogusMarkupConventions.  I want to
use it anyway because I need something running right away and I don't
want to spend a whole lot of time messing with it.

In the larger world, though, there's currently One True wiki package,
namely Mediawiki (used by Wikipedia).  Mediawiki is written in PHP and
is far more complex than MoinMoin, plus it's database backed, meaning
you have to run an SQL server as well as the wiki software itself
(MoinMoin just uses the file system).  Plus, I'll guess that it really
needs mod_php, while MoinMoin runs tolerably as a set of cgi's, at
least when traffic is low.  I'll say that I haven't actually looked at
the Mediawiki code, though I guess I should do so.

What I'm getting at is I might like to install MoinMoin now and
migrate to Mediawiki sometime later.  Anyone have any thoughts about
whether that's a crazy plan?  Should I just bite the bullet and run
Mediawiki from the beginning?  Is anyone here actually running
Mediawiki who can say just how big a hassle it is?

There are actually two wikis I want to run, one of which I need
immediately, but which will be private, low traffic and stay that way.
The other one will be public and is planned grow to medium size (a few
thousand active users), but which I don't need immediately.  I
definitely want the second one to eventually run Mediawiki.  I can
probably keep the first one on MoinMoin indefinitely, but that would
mean I'm eventually running two separate wiki packages, which gets
confusing.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Old Paranoia Game in Python

2005-01-10 Thread SPK
You can download the code from the web directly now at:
http://homepage.mac.com/spkane/python/
Thanks for all the code suggestions. This is what I was hoping for, but 
was honestly suprised to actually get it all, although I did get at 
least one emotional blast, so I don't feel like Usenet has completely 
changed from it's old self...grin

I already made a change to the this_page() method based on a 
suggestion, and will happily pursue many of the other sugestions here. 
I'm only about 100 pages into Mark Lutz's Learning Python book, so 
I'm sure there is a lot more learning to do.

Thanks for all your input!
Sean

On 2005-01-10 15:44:33 -0800, McBooCzech [EMAIL PROTECTED] said:
Newbie in Python.
I did copy the whole script form the web and save it as para1.py. I did
download pyparsing module and save it to
C:\\Python23\\Lib\\pyparsing122.
I did run following script:
import sys
sys.path.append('C:\\Python23\\Lib\\pyparsing122')
from pyparsing import *
extraLineBreak = White( ,exact=1) + LineEnd().suppress()
text = file(Para1.py).read()
newtext = extraLineBreak.transformString(text)
file(para2.py,w).write(newtext)
I did try to run para2.py script, but following message
File para2.py, line 169
choose(4,You give your correct clearance,5,You lie and claim
^
SyntaxError: EOL while scanning single-quoted string
So my questions are:
Why pyparser didn't correct the script?
What I am doing wrong?
Is it necessary to correct the script by hand anyway?
Petr

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


Re: Writing huve ge Sets() to disk

2005-01-10 Thread Mike C. Fletcher
Martin MOKREJ wrote:
Tim Peters wrote:
...
I was really hoping I'll get an answer how to alter the indexes for 
dictionaries
in python.

Sorry, I don't have a guess for what that might mean.

I'm not an expert, mysql for example givs you ability to index say
first 10 characters of a text column, which are typically varchar.
Just for curiosity I'd like to know how do it in python.
When importing data from a flatfile into mysql table, there's an
option to delay indexing to the very last moment, when all keys are
loaded (it doesn't make sense to re-create index after each new
row into table is added). I believe it's exactly same waste of cpu/io
in this case - when I create a dictionary and fill it with data,
I want to create index afterward, not after every key/value pair
is recorded.
Okay, you seem to be missing this key idea:
   A hash-table (dict) is approximately the same level of abstraction
   as a btree index.
Your MySQL index is likely implemented as a btree.  A hash-table could 
just as readily be used to implement the index.  When you insert into 
either of these structures (btree or hash), you are not creating an 
index separate from the structure, the structure *is* an index of 
the type you are thinking about.  These structures are both efficient 
representations that map from a data-value to some other data-value.  
Hashes with a good hash function (such as Python's dicts) are basically 
O(1) (worst case O(n), as Tim notes), while Btrees (such as common 
database indices) are O(log(n)) (or something of that type, basically it 
grows much more slowly than n).

Once more, I expect to have between E4 or E5 to E8??? words
stored in 20 dictionaries (remember words of sizes in range 1-20?
Every of those 20 dictionaries should be, I believe, indexed just once.
The indexing method should know all entries in a given file are of same
size, i.e. 5 chars, 15 chars, 20 chars etc.

I think you're making this more complicated than it needs to be.

I hope the algoritm can save some logic. For example, can turn off 
locking support,
index only part of the key etc.
I'd tend to agree with Tim.  You're making this all far too complex in 
what appears to be the absence of any real need.  There's a maxim in 
computer programming that you avoid, wherever possible, what is called 
premature optimisation.  You are here trying to optimise away a 
bottleneck that doesn't exist (indexing overhead, and locking support 
are basically nil for a dictionary).  It is almost a certainty that 
these are not *real* bottlenecks in your code (what with not existing), 
so your time would be better spent writing a dumb working version of 
the code and profiling it to see where the *real* bottlenecks are.

For example, looking up a key with it's value only once in the whole 
for loop tells me
I don't need an index. Yes, I'll do this 4 times for those 4 
languages, but
still I think it's faster to live without an index, when I can sort
records. I think I like the sorted text file approach, and the dictionary
approach without an index would be almost the same, especially if I 
manage
to tell the db layout not to move the cursor randomly but just to walk 
down the
pre-sorted data.
Again, you don't really have a cursor with a dictionary (and since it's 
randomly ordered, a cursor wouldn't mean anything).  A *btree* has an 
order, but not a dictionary.  You could construct a sorted list in 
memory that would approximate what I *think* you're thinking of as a 
dictionary-without-an-index.

Good luck,
Mike

 Mike C. Fletcher
 Designer, VR Plumber, Coder
 http://www.vrplumber.com
 http://blog.vrplumber.com
--
http://mail.python.org/mailman/listinfo/python-list


unicode mystery

2005-01-10 Thread Sean McIlroy
I recently found out that unicode(\347, iso-8859-1) is the
lowercase c-with-cedilla, so I set out to round up the unicode numbers
of the extra characters you need for French, and I found them all just
fine EXCEPT for the o-e ligature (oeuvre, etc). I examined the unicode
characters from 0 to 900 without finding it; then I looked at
www.unicode.org but the numbers I got there (0152 and 0153) didn't
work. Can anybody put a help on me wrt this? (Do I need to give a
different value for the second parameter, maybe?)

Peace,
STM

PS: I'm considering looking into pyscript as a means of making
diagrams for inclusion in LaTeX documents. If anyone can share an
opinion about pyscript, I'm interested to hear it.

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


Re: why not datetime.strptime() ?

2005-01-10 Thread David M. Cooke
Joshua Spoerri [EMAIL PROTECTED] writes:

 Skip Montanaro skip at pobox.com writes:
 josh Shouldn't datetime have strptime?
 If someone wants to get their feet wet with extension module
 programming
 this might be a good place to start.  Mostly, I think nobody who has
 needed/wanted it so far has the round tuits available to spend on the
 task.

 OK, it was pretty straightforward. Thanks for the direction.

 To whom should I send the patch (attached)?

Submit it to the patch tracker on sourceforge.

But first, some constructive criticism:

 --- Modules/datetimemodule.c.orig 2003-10-20 10:34:46.0 -0400
 +++ Modules/datetimemodule.c  2005-01-10 20:58:38.884823296 -0500
 @@ -3774,6 +3774,32 @@
   return result;
  }
  
 +/* Return new datetime from time.strptime(). */
 +static PyObject *
 +datetime_strptime(PyObject *cls, PyObject *args)
 +{
 + PyObject *result = NULL, *obj, *module;
 + const char *string, *format;
 +
 + if (!PyArg_ParseTuple(args, ss:strptime, string, format))
 + return NULL;
 + if ((module = PyImport_ImportModule(time)) == NULL)
 + return NULL;
 + obj = PyObject_CallMethod(module, strptime, ss, string, format);
 + Py_DECREF(module);

You don't check for errors: an exception being thrown by
PyObject_CallMethod will return obj == NULL.

If there's a module in sys.path called time that overrides the stdlib
time, things will fail, and you should be able to catch that.

 + result = PyObject_CallFunction(cls, iii,
 + PyInt_AsLong(PySequence_GetItem(obj, 0)),
 + PyInt_AsLong(PySequence_GetItem(obj, 1)),
 + PyInt_AsLong(PySequence_GetItem(obj, 2)),
 + PyInt_AsLong(PySequence_GetItem(obj, 3)),
 + PyInt_AsLong(PySequence_GetItem(obj, 4)),
 + PyInt_AsLong(PySequence_GetItem(obj, 5)),
 + PyInt_AsLong(PySequence_GetItem(obj, 6)));

Are you positive those PySequence_GetItem calls will succeed? That
they will return Python integers?

 + Py_DECREF(obj);
 + return result;
 +}
 +
  /* Return new datetime from date/datetime and time arguments. */
  static PyObject *
  datetime_combine(PyObject *cls, PyObject *args, PyObject *kw)
 @@ -4385,6 +4411,11 @@
PyDoc_STR(timestamp - UTC datetime from a POSIX timestamp 
  (like time.time()).)},
  
 + {strptime, (PyCFunction)datetime_strptime,
 +  METH_VARARGS | METH_CLASS,
 +  PyDoc_STR(strptime - new datetime parsed from a string
 +(like time.strptime()).)},
 +
   {combine, (PyCFunction)datetime_combine,
METH_VARARGS | METH_KEYWORDS | METH_CLASS,
PyDoc_STR(date, time - datetime with same date and time fields)},

It probably would help to add some documentation to add to the
datetime module documentation.

-- 
||\/|
/--\
|David M. Cooke
|cookedm(at)physics(dot)mcmaster(dot)ca
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python3: on removing map, reduce, filter

2005-01-10 Thread David M. Cooke
Steven Bethard [EMAIL PROTECTED] writes:
 Some timings to verify this:

 $ python -m timeit -s def square(x): return x*x map(square, range(1000))
 1000 loops, best of 3: 693 usec per loop

 $ python -m timeit -s [x*x for x in range(1000)]
 1000 loops, best of 3: 0.0505 usec per loop

Maybe you should compare apples with apples, instead of oranges :-)
You're only running the list comprehension in the setup code...

$ python2.4 -m timeit -s def square(x): return x*x map(square, range(1000))
1000 loops, best of 3: 464 usec per loop
$ python2.4 -m timeit [x*x for x in range(1000)]
1000 loops, best of 3: 216 usec per loop

So factor of 2, instead of 13700 ...

-- 
||\/|
/--\
|David M. Cooke
|cookedm(at)physics(dot)mcmaster(dot)ca
-- 
http://mail.python.org/mailman/listinfo/python-list


shutil.move has a mind of its own

2005-01-10 Thread Daniel Bickett
Hello,

I'm writing an application in my pastime that moves files around to
achieve various ends -- the specifics aren't particularly important.
The shutil module was chosen as the means simply because that is what
google and chm searches returned most often.

My problem has to do with shutil.move actually putting the files where
I ask it to. Citing code wouldn't serve any purpose, because I am
using the function in the most straight forward manner, ex:

shutil.move( C:\omg.txt , C:\folder\subdir )

In my script, rather than a file being moved to the desired location,
it is, rather, moved to the current working directory (in this case,
my desktop -- without any exceptions, mind you). As it happens, the
desired locations are system folders (running windows xp, the folders
are as follows: C:\WINDOWS, C:\WINDOWS\SYSTEM, C:\WINDOWS\SYSTEM32).
To see if this factor was causing the problem, I tried it using the
interpreter, and found it to be flawless.

My question boils down to this: What factors could possibly cause
shutil.move to fail to move a file to the desired location, choosing
instead to place it in the cwd (without raising any exceptions)?

Thank you for your time,

Daniel Bickett

P.S. I know I said I didn't need to post code, but I will anyway. You
never know :)

http://rafb.net/paste/results/FcwlEw86.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: fetching method names from a class, and the parameter list from a method

2005-01-10 Thread John Lenton
On Mon, Jan 10, 2005 at 08:29:40PM +0100, Philippe C. Martin wrote:
 Is this possible ?
 
 I am trying to have auto-completion working in a shell I wrote but I
 currently have the method lists done by hand (ie; if I add/subtract a
 method from that class, then my auto-completion is out of date).
 
 Same issue with method parameters.
 
 I have parsed through many of the attributes (ex: I use method.__doc__)
 but have not yet found a way to achieve the above goal.
 
 Is there a way? something like the following would be great:
 1) list = Class.__methods__
 2) dict (because of default values: param = None) =
 Class.__method__[0].__params__

 import inspect
 help(inspect)

HTH

-- 
John Lenton ([EMAIL PROTECTED]) -- Random fortune:
In Greene, New York, it is illegal to eat peanuts and walk backwards on
the sidewalks when a concert is on.


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

Re: OT: MoinMoin and Mediawiki?

2005-01-10 Thread Eric Pederson
Paul Rubin wrote:

 What I'm getting at is I might like to install MoinMoin now and
 migrate to Mediawiki sometime later.  Anyone have any thoughts about
 whether that's a crazy plan?  


Disclaimer, I am neither using Moinmoin nor Mediawiki, and don't really have 
your answer.

From what I read, Mediawiki stores each page as wikitext in a MySQL 
database; wikitext is a mixture of content, markup, and metadata.

It seems essentially what you'd need for migration is a mapping function and I 
do not know how complex the mapping between the systems would be.  I could 
imagine migrating from Moinmoin to Mediawiki via a script looping through the 
Moinmoin files in a directory, modifying a copy of each, and storing them in 
MySQL.

I suspect it's less painful to just start with the wiki you want to end up 
with, but if you're going to migrate between the two, won't Python come in 
handy!  ;-)



Eric Pederson
http://www.songzilla.blogspot.com
:::
domainNot=@something.com
domainIs=domainNot.replace(s,z)
ePrefix=.join([chr(ord(x)+1) for x in do])
mailMeAt=ePrefix+domainIs
:::

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


Re: OT: MoinMoin and Mediawiki?

2005-01-10 Thread Paul Rubin
Brion Vibber [EMAIL PROTECTED] writes:
 MediaWiki should run with PHP configured in CGI handler mode, but
 these days mod_php has got its claws just about everywhere anyway. If
 you control your own server and don't have multi-user security
 worries, mod_php is simple enough to install and will probably perform
 better.

Thanks, yes, I could run a special apache instance with mod_php
installed.  I'm pretty good with apache.  I have no MySQL admin
experience but I suppose enough people are using MySQL that the
installation procedures and docs are pretty well developed and I can
follow the instructions.

What I'm wondering is just how big an adventure I'd be setting off on,
simply to get MediaWiki itself installed, configured, and running.
Any thoughts about that?

 For performance I also highly recommend using Turck MMCache or
 equivalent PHP bytecode cache extension. Unlike Python, saving
 compiled bytecode is not the default behavior of PHP, and for
 non-trivial scripts compilation eats up a lot of runtime.

Hmm, that's something I could deal with later, I guess.  Is that
similar to what Zend does?

   I'll say that I haven't actually looked at
  the Mediawiki code, though I guess I should do so.
 
 Cover your eyes...! it _is_ PHP after all. ;)

Heehee.  I like PHP just fine for small projects.  I just cringe at
the notion of something as complex as MediaWiki being written in PHP
and am constantly, involuntarily thinking about how I would do it in
Python.  I can't help myself.  Without looking at even a line of
WikiMedia's code, I already want to do a total rewrite ;-).

 I would generally recommend you just start with MediaWiki if you
 intend to use it. To migrate a non-tiny site later you'll need to work
 out a migration script to import your data in some way (some people
 have asked about this in the past, I don't know if anyone's ever
 completed one or made it public).

You're probably right, I'll download Wikimedia and see about
installing it.  I have tons of server disk space, though the CPU has
been getting a bit overloaded lately.  

 On the other hand if you _do_ write a MoinMoin-to-MediaWiki
 conversion script (or vice-versa!) we'd love to include it in the
 MediaWiki distribution.

I think a rough approximation would be pretty easy to do.  Trying to
get every detail right would be very difficult.  If I do something like
that, I'll likely go for the rough approximation.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: shutil.move has a mind of its own

2005-01-10 Thread Delaney, Timothy C (Timothy)
Daniel Bickett wrote:

 shutil.move( C:\omg.txt , C:\folder\subdir )
  ^  ^^ ^
The problem is that backslash is the escape character. In particular,
'\f' is a form feed.

 '\o'
'\\o'
 '\f'
'\x0c'
 '\s'
'\\s'

Notice how for '\o' and '\s' it doubles-up the backslash - this is
because '\o' and '\s' are not valid escapes, and so it treats the
backslash as just a backslash. But '\f' is a valid escape.

You have a couple of options:

1. Use double-backslashes (to escape the backslash):
   shutil.move(C:\\omg.txt, C:\\folder\\subdir)

2. Use forward slashes (they work on Windows for the most part):
   shutil.move(C:/omg.txt, C:/folder/subdir)

3. Build your paths using os.path.join (untested):
   shutil.move(os.path.join(C:, omg.txt), os.path.join(C:,
folder, subdir))

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


Re: unicode mystery

2005-01-10 Thread John Lenton
On Mon, Jan 10, 2005 at 07:48:44PM -0800, Sean McIlroy wrote:
 I recently found out that unicode(\347, iso-8859-1) is the
 lowercase c-with-cedilla, so I set out to round up the unicode numbers
 of the extra characters you need for French, and I found them all just
 fine EXCEPT for the o-e ligature (oeuvre, etc). I examined the unicode
 characters from 0 to 900 without finding it; then I looked at
 www.unicode.org but the numbers I got there (0152 and 0153) didn't
 work. Can anybody put a help on me wrt this? (Do I need to give a
 different value for the second parameter, maybe?)

 isn't part of ISO 8859-1, so you can't get it that way. You can do
one of

   u'\u0153'

or, if you must,

   unicode(\305\223, utf-8)

-- 
John Lenton ([EMAIL PROTECTED]) -- Random fortune:
Lisp, Lisp, Lisp Machine,
Lisp Machine is Fun.
Lisp, Lisp, Lisp Machine,
Fun for everyone.


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

PyChecker messages

2005-01-10 Thread Frans Englich

Hello,

I take PyChecker partly as an recommender of good coding practice, but I 
cannot make sense of some of the messages. For example:

runner.py:878: Function (main) has too many lines (201)

What does this mean? Cannot functions be large? Or is it simply an advice that 
functions should be small and simple?


runner.py:200: Function (detectMimeType) has too many returns (11)

The function is simply a long else-if clause, branching out to different 
return statements. What's wrong? It's simply a probably ugly code advice?


A common message is these:

runner.py:41: Parameter (frame) not used

But I'm wondering if there's cases where this cannot be avoided. For example, 
this signal handler:

#---
def signalSilencer( signal, frame ):

Dummy signal handler for avoiding ugly
tracebacks when the user presses CTRL+C.

print Received signal, str(signal) + , exiting.
sys.exit(1)
#---

_must_ take two arguments; is there any way that I can make 'frame' go away?


Also, another newbie question: How does one make a string stretch over several 
lines in the source code? Is this the proper way?

print asda asda asda asda asda asda  \
asda asda asda asda asda asda  \
asda asda asda asda asda asda


Thanks in advance,

Frans

PS. Any idea how to convert any common time type to W3C XML Schema datatype 
duration?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: exceptions and items in a list

2005-01-10 Thread vincent wehren
Steve Holden wrote:
vincent wehren wrote:
rbt wrote:
If I have a Python list that I'm iterating over and one of the 
objects in the list raises an exception and I have code like this:

try:
do something to object in list
except Exception:
pass
Does the code just skip the bad object and continue with the other 
objects in the list, or does it stop?

Thanks

Fire up a shell and try:
  seq = [1, 2, a, 4, 5, 6.0]
  for elem in seq:
 try:
print int(elem)
 except ValueError:
pass
and see what happens...
--
Vincent Wehren

I suspect the more recent versions of Python allow a much more elegant 
solution. I can't remember precisely when we were allowed to use 
continue in an except suite, but I know we couldn't in Python 2.1.

Nowadays you can write:
Python 2.4 (#1, Dec  4 2004, 20:10:33)
[GCC 3.3.3 (cygwin special)] on cygwin
Type help, copyright, credits or license for more information.
  for i in [1, 2, 3]:
 ...   try:
 ... print i
 ... if i == 2: raise AttributeError, Bugger!
 ...   except AttributeError:
 ... print Caught exception
 ... continue
 ...
1
2
Caught exception
3
 
To terminate the loop on the exception you would use break instead of 
continue.
What do you mean by a more elegant solution to the problem? I thought 
the question was if a well-handled exception would allow the iteration 
to continue with the next object or that it would stop. Why would you 
want to use the continue statement when in the above case that is 
obviously unnecessary?:

$ python
Python 2.4 (#1, Dec  4 2004, 20:10:33)
[GCC 3.3.3 (cygwin special)] on cygwin
Type help, copyright, credits or license for more information.
 for i in [1,2,3]:
... try:
... if i == 2: raise AttributeError, Darn!
... except AttributeError:
... print Caught Exception
...
1
2
Caught Exception
3

Or do you mean that using continue is more elegant than using pass 
if there are no other statements in the except block?

Regards,
--
Vincent Wehren
regards
 Steve
--
http://mail.python.org/mailman/listinfo/python-list


Re: shutil.move has a mind of its own

2005-01-10 Thread drs
Delaney, Timothy C (Timothy) [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Daniel Bickett wrote:

  shutil.move( C:\omg.txt , C:\folder\subdir )
  ^  ^^ ^
 The problem is that backslash is the escape character. In particular,
 '\f' is a form feed.

 You have a couple of options:

You can also include an r to make it a raw string if extra or reversed
slashes look odd

shutil.move( rC:\omg.txt , rC:\folder\subdir )


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


reference or pointer to some object?

2005-01-10 Thread Torsten Mohr
Hi,

i'd like to pass a reference or a pointer to an object
to a function.  The function should then change the
object and the changes should be visible in the calling
function.

In perl this would be something like:

sub func {
  $ref = shift;

  $$ref += 123; # change
}

$a = 1;
func(\$a);

is something like this possible in python?

The keyword global does NOT fit this purpose to
my understanding as it only makes the variables of
the UPPERMOST level visible, not the ones of ONE
calling level above.

Is this somehow possible with weakref?

I don't want to pass the parameter to a function and
then return a changed value.

Is there some other mechanism in python available to
achieve a behaviour like this?


Thanks for any hints,
Torsten.

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


Re: reference or pointer to some object?

2005-01-10 Thread Paul Rubin
Torsten Mohr [EMAIL PROTECTED] writes:
 i'd like to pass a reference or a pointer to an object
 to a function.  The function should then change the
 object and the changes should be visible in the calling
 function.

Normally you would pass a class instance or boxed object, and let the
function change the instance or object:

def bump(b):
   b[0] += 123  # change

x = [5]
bump(x)
print x   # prints [128]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python3: on removing map, reduce, filter

2005-01-10 Thread Steven Bethard
David M. Cooke wrote:
Steven Bethard [EMAIL PROTECTED] writes:
Some timings to verify this:
$ python -m timeit -s def square(x): return x*x map(square, range(1000))
1000 loops, best of 3: 693 usec per loop
$ python -m timeit -s [x*x for x in range(1000)]
1000 loops, best of 3: 0.0505 usec per loop

Maybe you should compare apples with apples, instead of oranges :-)
You're only running the list comprehension in the setup code...
$ python2.4 -m timeit -s def square(x): return x*x map(square, range(1000))
1000 loops, best of 3: 464 usec per loop
$ python2.4 -m timeit [x*x for x in range(1000)]
1000 loops, best of 3: 216 usec per loop
So factor of 2, instead of 13700 ...
Heh heh.  Yeah, that'd be better.  Sorry about that!
Steve
--
http://mail.python.org/mailman/listinfo/python-list


Re: Dr. Dobb's Python-URL! - weekly Python news and links (Jan 9)

2005-01-10 Thread Bengt Richter
On Tue, 11 Jan 2005 07:27:42 +1100, Tim Churches [EMAIL PROTECTED] wrote:

Josiah Carlson wrote:
 QOTW:  Jim Fulton: [What's] duck typing?
 Andrew Koenig: That's the Australian pronunciation of 'duct taping'.

I must protest.
1) No (true-blue) Australian has every uttered the words 'duct taping', 
because Aussies (and Pommies) know that the universe is held together 
with gaffer tape, not duct tape. See http://www.exposure.co.uk/eejit/gaffer/
b) If an Australian were ever induced to utter the words 'duct typing', 
the typical Strine (see 
http://www.geocities.com/jendi2_2000/strine1.html ) pronunciation would 
be more like 'duh toypn' - the underlying principle being one of 
elimination of all unnecessary syllables, vowels and consonants, thus 
eliminating the need to move the lips (which reduces effort and stops 
flies getting in).

Tim C
Sydney, Australia
LOL. Thanks, needed that ;-)

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


stretching a string over several lines (Re: PyChecker messages)

2005-01-10 Thread Steven Bethard
Frans Englich wrote:
Also, another newbie question: How does one make a string stretch over several 
lines in the source code? Is this the proper way?
(1)
print asda asda asda asda asda asda  \
asda asda asda asda asda asda  \
asda asda asda asda asda asda
A couple of other options here:
(2)
print asda asda asda asda asda asda
asda asda asda asda asda asda
asda asda asda asda asda asda
(3)
print \
asda asda asda asda asda asda
asda asda asda asda asda asda
asda asda asda asda asda asda
(4)
print (asda asda asda asda asda asda 
   asda asda asda asda asda asda 
   asda asda asda asda asda asda)
Note that backslash continuations (1) are on Guido's list of Python 
Regrets, so it's likely they'll disappear with Python 3.0 (Of course 
this is 3-5 years off.)

I typically use either (3) or (4), but of course the final choice is up 
to you.

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


readline, rlcompleter

2005-01-10 Thread michele . simionato
This a case where the documentation is lacking. The standard library
documentation
(http://www.python.org/dev/doc/devel/lib/module-rlcompleter.html) gives
this example
try:
import readline
except ImportError:
print Module readline not available.
else:
import rlcompleter
readline.parse_and_bind(tab: complete)

but I don't find a list of recognized key bindings. For instance, can I
would
like to bind shift-tab to rlcompleter, is that possible? Can I use
function
keys? I did various attempt, but I did not succed :-(
Is there any readline-guru here with some good pointers?
Michele Simionato

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


Re: time module precision

2005-01-10 Thread janeaustine50
Peter Hansen wrote:
 [EMAIL PROTECTED] wrote:
  So the problem (waiting tens to hundreds of us without busy
looping)
  still remains...

 That's actually not a problem, it's your solution
 to a problem.  Can you describe the _real_ problem, what
 you are trying to do?  _Why_ do you want to wait such
 brief amounts of time?

 I ask as someone with fairly extensive background in
 realtime software (which is basically what it sounds like
 you are trying to write here), and I suspect that you are
 either trying to achieve something that's not really possible
 on Windows XP, or that you are simply doing something that
 is entirely unnecessary, probably for good reasons but
 with too little experience of the issues involved.  Can
 you expand on your situation?

 -Peter

What I am trying to do is sending binary data to a serial port. Since
the device attached to the port cannot handle a continous in-flow of
data, I need to make an artificial tiny delay in-between data chunks(a
few hundreds of KBs). The delay might be a few tens to hundreds of us.

I'd like to make the transmission as fast as possible, uh.. well..
reasonably fast.

[I sort of posted this already but hasn't got it through so am
reposting it now]

Thanks

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


Re: Python3: on removing map, reduce, filter

2005-01-10 Thread Terry Reedy

Andrey Tatarinov [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 How does GvR suggestions on removing map(), reduce(), filter()

While GvR *might* prefer removing them completely on any given day, I think 
moving them to a functional module, as others have suggested and requested, 
is currently more likely.  I believe that GvR has indicated at times that 
this would be an acceptible compromise.

I am one of those who think the list of builtins is currently too long to 
be easily grasped and should be shrunk.

Terry J. Reedy



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


Re: Long strings as function parameters

2005-01-10 Thread Terry Reedy

Dan Bishop [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 In Python, *every* expression is a pointer.

Minor but to me important nit: this should start In the CPython 
implementation of Python ...

Humans can understand and execute Python code without knowing about 
computer memory addresses (pointers).  Other computer languages can also do 
something slightly different from CPython, as I believe is the case with 
Jython.

The Python language is defined by sematics, not by mechanisms, especially 
low-level interpreter-specific mechanisms.  This is a large part of what 
makes it readable.

To the OP: a Python function call binds argument objects to either local 
parameter names or slots within a named catchall list or dict.  Like other 
binding (assignment) operations, there is no copying.

Terry J. Reedy



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


Re: SuSE 9.1: updating to python-2.4

2005-01-10 Thread David Fraser
Torsten Mohr wrote:
Hi,
along with my distribution SuSE 9.1 came python 2.3.3.
I'd like to update to 2.4 now, is this an easy thing to do
or will lots of installed modules refuse to work then?
Is there an easy way to find out what i need to update?
Thanks for any hints,
Torsten.
What you probably want to do is install python2.4 alongside python2.3.3 
as an alternate installation, since a lot of other programs in SuSE 
probably depend on having python2.3.3 and won't work with the upgrade.

Have a look at the RPMs on the python 2.4 downloads page and see if you 
can install them OK (I just did this fine for python 2.3 on whitebox linux).

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


Re: raw sockets ? i need a python sniffer

2005-01-10 Thread lbolognini
Would this suit you?
http://www.nullcube.com/software/pyopenbsd.html

Lorenzo

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


Re: Securing a future for anonymous functions in Python

2005-01-10 Thread Jacek Generowicz
Nick Coghlan [EMAIL PROTECTED] writes:

  Usually one or two have trouble grasping that int would be perfectly
  adequate in this situation.
 
 The ability to pass around functions at run-time was probably the
 hardest thing to get my head around when I started with Python,

And I suspect that this particular case is further complicated by the
fact that int is not a function ... it's a type!

I can imagine it might make a newbie's brain melt. Still, most of them
survive and thoroughly enjoy the course :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SuSE 9.1: updating to python-2.4

2005-01-10 Thread Wolfram Kraus
Heyho!
Torsten Mohr wrote:
Hi,
along with my distribution SuSE 9.1 came python 2.3.3.
I'd like to update to 2.4 now, is this an easy thing to do or will
lots of installed modules refuse to work then?
I installed Python 2.4 under SuSE 9.1 and had no problems so far. If you
install it via ./configure;make;make install, python 2.4 will be
installed in /usr/local/lib/python2.4 parallel to your existing 2.3
installation under /usr/lib/python2.3.
Is there an easy way to find out what i need to update?
Just check out, which version comes up when you call python from the 
shell. If this is version 2.3 you can start 2.4 with python2.4
All the installed packages for python2.3 (e.g. PIL, MySQLdb, wxPython,
...) need to be installed for the new version, too.
Thanks for any hints, Torsten.
HTH,
Wolfram
--
http://mail.python.org/mailman/listinfo/python-list


Old Paranoia Game in Python

2005-01-10 Thread Sean P.Kane
I ported the old (and long since removed) game from the bsd-game 
pacakge called, Paranoia, based on the old Paranoia role playing game 
from C to Python as a simple exercise in learning the language and pure 
late night boredom. Anyways, here it is for anyone looking for a few 
minutes of nostalgia. I may get around to posting this at 
http://homepage.mac.com/spkane/ or http://www.spkane.org/, but for now 
here it is. Improvements or corrections, welcome.

Thanks,
Sean
-Cut Here-
#!/usr/bin/env python
#
#
# -*- encoding = 'utf-8' -*-
#
#
# Command Line GCS Upgrade Application
# 
# This is a port of paranoia from the old bsd-games package.
#
#
# HISTORY
# ===
#
# 1.2 - 03 Jan 2005
# + Initially started porting application
#
# Requires
# 
# 1) Python 2.3
'''\
usage: paranoia
'''
__author__ = 'Sean P. Kane [EMAIL PROTECTED]'
__copyright__  = '''This is a solo paranoia game taken from the Jan/Feb 
issue (No 77) of SpaceGamer/FantasyGamer magazine.

Article by Sam Shirley.
Originally implemented in C on Vax 11/780 under UNIX by Tim Lister
Ported to Python on an Apple Powerbook G4 by Sean P. Kane
This is a public domain adventure and may not be sold for profit'''
__date__  = '01/03/2005'
#Also change version at top of main()
__version__= '1.2'
#the basics
import sys
#For Dice Rolling
import random
#new argument parsing library
from optparse import OptionParser
moxie = 13
agility = 15
maxkill = 7 # The maximum number of UV's you can kill
clone = 1
page = 1
computer_request = 0
ultra_violet = 0
action_doll = 0
hit_points = 10
read_letter = 0
plato_clone = 3
blast_door = 0
killer_count = 0
def instructions():
   print Welcome to Paranoia!
HOW TO PLAY:
   Just press Enter until you are asked to make a choice.
   Select 'a' or 'b' or whatever for your choice, then press Enter.
   You may select 'p' at any time to get a display of your statistics.
   Always choose the least dangerous option.  Continue doing this until
   you win. At times you will use a skill or engage in combat and will
   be informed of the outcome.  These sections will be self explanatory.
   HOW TO DIE:
   As Philo-R-DMD you will die at times during the adventure.
   When this happens you will be given an new clone at a particular
   location. The new Philo-R will usually have to retrace some of
   the old Philo-R\'s path hopefully he won\'t make the same mistake
   as his predecessor.
   HOW TO WIN:
   Simply complete the mission before you expend all six clones.
   If you make it, congratulations.
   If not, you can try again later.

def character():
   print 
===
The 

The Character : Philo-R-DMD %s
Primary Attributes  Secondary Attributes
===
Strength . 13   Carrying Capacity . 30
Endurance  13   Damage Bonus ... 0
Agility .. 15   Macho Bonus ... -1
Manual Dexterity . 15   Melee Bonus .. +5%%
Moxie  13   Aimed Weapon Bonus .. +10%%
Chutzpah .. 8   Comprehension Bonus .. +4%%
Mechanical Aptitude .. 14   Believability Bonus .. +5%%
Power Index .. 10   Repair Bonus . +5%%
===
Credits: 160Secret Society: IlluminatiSecret Society Rank: 1
Service Group: Power Services   Mutant Power: Precognition
Weapon: laser pistol to hit, 40%% type, L Range, 50m Reload, 6r Malfnt, 00
Skills: Basics 1(20%%), Aimed Weapon Combat 2(35%%), Laser 3(40%%),
   Personal Development 1(20%%), Communications 2(29%%), 
Intimidation 3(34%%)
Equipment: Red Reflec Armour, Laser Pistol, Laser Barrel (red),
  Notebook  Stylus, Knife, Com Unit 1, Jump suit,
  Secret Illuminati Eye-In-The-Pyramid(tm) Decoder ring,
  Utility Belt  Pouches
===
 % clone

def page1():
  global page
  print You wake up face down on the red and pink checked E-Z-Kleen 
linoleum floor.
You recognise the pattern, it's the type preferred in the internal security
briefing cells.  When you finally look around you, you see that you are alone
in a large mission briefing room.

  page = 57
  more()

def page2():
  global page
  global computer_request
  print \Greetings,\ says the kindly Internal Security self 
incrimination expert who
meets you at the door, \How are we doing today?\  He offers you a doughnut
and coffee and asks what brings you here.  This doesn\'t seem so bad, so you
tell him that you have come to 

BayPIGgies: January 13, 7:30pm

2005-01-10 Thread aahzpy
WARNING: the last meeting of BayPIGgies at Stanford is currently
scheduled for March.  Our host, Danny Yoo, is leaving Stanford, and we
need to find a new location.  If you wish to assist with the search,
please join the BayPIGgies mailing list.

Meanwhile, let's all give hearty thanks to Danny for helping us find a
stable meeting location for so long!


The next meeting of BayPIGgies will be Thurs, January 13 at 7:30pm.  

Danny Yoo leads a discussion of Python coding tricks and techniques.
Please join the BayPIGgies mailing list to discuss which sample code
will be demonstrated.  The web site will contain more details.

BayPIGgies meetings are in Stanford, California.  For more information
and directions, see http://www.baypiggies.net/


Before the meeting, we may meet at 6pm for dinner in downtown Palo Alto.
Discussion of dinner plans is handled on the BayPIGgies mailing list.


Advance notice: The February 10 meeting agenda has not been set.  Please
send e-mail to [EMAIL PROTECTED] if you want to make a
presentation.
-- 
Aahz ([EMAIL PROTECTED])   * http://www.pythoncraft.com/

19. A language that doesn't affect the way you think about programming,
is not worth knowing.  --Alan Perlis
-- 
http://mail.python.org/mailman/listinfo/python-list


Bug in Python 2.4 raw_input(u'xyz') Win/command line?

2005-01-10 Thread Petr Prikryl
Hi,

Could you test the following example for your
non-English language with accented characters?

I have observed a problem when running 
Python 2.4, Windows version (python-2.4.msi)
and using raw_input() with unicode prompt
string in a console program (ran in the DOS window).

I do use the following sitecustomize file to set
the default encoding:

sitecustomize.py
=
import sys
sys.setdefaultencoding('cp1250')
=


test.py
=
# -*- coding: cp1250 -*-
s = u'string with accented letters'
print s # OK
val = raw_input(s)# s displayed differently (wrong)
=

... when run in a DOS window. See the attached
test.png. The type test.py displays the string
definition also wrong, because the DOS window
uses different encoding than cp1250. The print
command prints the string correctly, converting
the internal unicode string to the encoding that
the is defined by the output environment. However,
the raw_input() probably does convert the unicode
string to the cp1250 and does not do the same
(more clever) thing that the print does.

Could you confirm the bug? Is it known?
Should this be posted into some bug-report list?

Petr


python test.py

I have observed t

-- 
Petr Prikryl (prikrylp at skil dot cz) 


test.py
Description: test.py
attachment: test.png-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Getting rid of self.

2005-01-10 Thread Alex Martelli
BJörn Lindqvist [EMAIL PROTECTED] wrote:
   ...
  http://starship.python.net/crew/mwh/hacks/selfless.py
 
 That's excellent! There is one small problem with the code though:

It shows the fundamentals of how to rewrite the bytecode, yes.

 .class Hi(Selfless):
 .__attrs__ = [x]
 .def __init__(x):
 .self.x = x
 
 In this case, I think the Python interpreter should realise that the
 parameter x shadows the attribute x. But the selfless code has
 problems with that. I want it to work exactly like how the situation
 is handled in Java and C++.

I believe you're referring to the test in rewrite_method:

if op.arg  code.co_argcount:
raise ValueError, parameter also instance member!

If you think that parameters that are also instance members should
shadow instance members, just skip the op.arg cases which are less
than code.co_argcount -- those are the parameters.

  Alex Martelli:
  A decorator can entirely rewrite the bytecode (and more) of the method
  it's munging, so it can do essentially anything that is doable on the
  basis of information available at the time the decorator executes.
 
 Which I believe means that the instance variables have to be declared
 in the class? I am content with declaring them like the selfless
 approach does:

It means the information about which names are names of instance
attributes must be available somewhere, be that declared, inferred,
or whatever.  For example, many C++ shops have an ironclad rule that
instance attributes, and ONLY instance attributes, are always and
invariably named m_something.  If that's the rule you want to enforce,
then you don't necessarily need other declarations or inferences, but
rather can choose to infer the status of a name from looking at the name
itself, if you wish.  Declarations or other complications yet such as:

 alternative would be not to declare the variables in an __attr__ list,
 and instead let them be declared by having them initialised in the
 __init__. I.e:
 
 .def __init__(hi, foo):
 .self.hi = hi
 .self.foo = foo
 
 When the metaclass then does it magic, it would go through the code of
 the __init__ method, see the assignments to self.hi and self.foo,
 decide that hi and foo are attributes of the object and replace
 hi and foo in all other methods with self.hi and self.foo. The

OK, but this approach is not compatible with your stated desire, which I
re-quote...:

 I want it to work exactly like how the situation
 is handled in Java and C++.

...because for example it does not deal with any attributes which may be
initialized in a *superclass*'s __init__.  However, I guess it could be
extended at the cost of some further lack of transparency, to obtain
just as horrid a mess as you require, where it's impossible for any
human reader to guess whether, say,
hi = 33
is setting a local variable, or an instance variable, without chasing
down and studying the sources of an unbounded number of superclasses.

I do not think there is any _good_ solution (which is why many C++ shops
have that rule about spelling this m_hi if it's an instance variable,
keeping the spelling 'hi' for non-instance variables -- an attempt to
get SOME human readability back; a smaller but non-null number of such
shops even achieve the same purpose by mandating the use of 'this-hi'
-- just the Python rule you want to work around, essentially).  The
least bad might be to rely on __attrs__, enriching whatever is in the
current class's __attr__ with any __attrs__ that may be found in base
classes PLUS any member variables specifically set in __init__ -- if you
focus on convenience in writing the code, to the detriment of ability to
read and understand it; or else, for more readability, demand that
__attrs__ list everything (including explicitly attributes coming from
subclasses and ones set in any method by explicit self.whatever = ...)
and diagnose the problem, with at least a warning, if it doesn't.

Yes, there's redundancy in the second choice, but that's what
declarations are all about: if you want to introduce the equivalent of
declarations, don't be surprised if redundancy comes with them.

 downside is that it probably could never be foolproof against code
 like this:
 
 .def __init__(hi, foo):
 .if hi:
 .self.hi = hi
 .else:
 .self.foo = foo
 
 But AFAIK, that example is a corner case and you shouldn't write such
 code anyway. :)

I don't see any problem with this code.  A static analysis will show
that both hi and foo are local variables.  Either may be not
initialized, of course, but having to deal with variables which are not
initialized IS a common problem of C++: you said you want to do things
like in C++, so you should be happy to have this problem, too.


  Alex Martelli:
  You do, however, need to nail down the specs.  What your 'magic' does
  is roughly the equivalent of a from ... import * (except it
  ...
  Then, you must decide whether this applies to all names the method
  accesses 

Re: Long strings as function parameters

2005-01-10 Thread Nick Coghlan
Jeremy Bowers wrote:
I had thought there was an obvious class in the standard library to assist
with this, but I must have been wrong.
buffer is the closest current contender, but I believe it's on the outer due to 
some problems with its implementation.

I think the intention is to eventually have a 'bytes' type, but I don't recall 
if that was going to be mutable or immutable.

Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


RE: interpreter Py_Initialize/Py_Finalize mem leak?

2005-01-10 Thread Roman Suzi
On Mon, 10 Jan 2005, Delaney, Timothy C (Timothy) wrote:

Roman Suzi wrote:

 In pure curiosity I tried to compile loop.c from Demo/embed
 and started it with 'print 2+2'. It seems, that both 2.3 and 2.4
 pythons have memory leaks in Py_Initialize/Py_Finalize calls.
 (That is, interpreter doesn't clean up well after itself).

What's your evidence for this (i.e. what are the symptoms)?

- memory usage grows over time.

If you have a repeatable test case, please raise a bug report on
SourceForge.

I tested only under Linux. And it is 100% repeatable.

Tim Delaney


Sincerely yours, Roman Suzi
-- 
[EMAIL PROTECTED] =\= My AI powered by GNU/Linux RedHat 7.3
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: static compiled python modules

2005-01-10 Thread Nick Coghlan
Thomas Linden wrote:
How can I tell python to use the compiled in modules and not try to
load them from outside?
http://www.python.org/dev/doc/devel/api/importing.html
Take a look at the last three entries about registering builtin modules.
Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: python3: accessing the result of 'if'

2005-01-10 Thread Nick Coghlan
Steve Holden wrote:
Excuse me, these are supposed to be IMPROVEMENTS to Python?
I think it's more messing around before coming to the conclusion that, of the 
many things that 'where' helps with, this sure as hell ain't one of them :)

Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Operating System???

2005-01-10 Thread Michael Sparks
Roose wrote:
...
  I was thinking that there would be a Lisp interpreter in a kernel,
 which afaik doesn't exist.

There's an implementation of scheme that runs as a kernel module in
Linux - it's designed to allow people to experiment with exploring
kernel data structures at run time, and other fun things.

It's a case in point for avoiding saying that something that doesn't
necessarily sound sensible doesn't exist - there's a good chance it
does :)


Michael
-- 
[EMAIL PROTECTED]
British Broadcasting Corporation, Research and Development
Kingswood Warren, Surrey KT20 6NP

This message (and any attachments) may contain personal views
which are not the views of the BBC unless specifically stated.


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


Re: windows mem leak

2005-01-10 Thread Nick Craig-Wood
Bob Smith [EMAIL PROTECTED] wrote:
  Attached is the code. Run it yourself and see.

This seems to run nmap over series of consecutive IP addresses.  nmap
can do that all by itself.  From its man page::

   Nmap also has a more powerful notation which lets  you  specify  an  IP
   address  using  lists/ranges  for  each element.  Thus you can scan the
   whole class 'B' network  128.210.*.*  by  specifying  '128.210.*.*'  or
   '128.210.0-255.0-255' or even '128.210.1-50,51-255.1,2,3,4,5-255'.  And
   of course you can use the mask notation: '128.210.0.0/16'.   These  are
   all  equivalent.  If you use astericts ('*'), remember that most shells
   require you to escape them with  back  slashes  or  protect  them  with
   quotes.

This setting might be useful too::

   --max_parallelism number
  Specifies the maximum number of scans Nmap is allowed to perform
  in parallel.  Setting this to one means Nmap will never  try  to
  scan more than 1 port at a time.  It also effects other parallel
  scans such as ping sweep, RPC scan, etc.

[sorry not Python related but may solve your problem!]
-- 
Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python serial data aquisition

2005-01-10 Thread Steve Holden
Flavio codeco coelho wrote:
[EMAIL PROTECTED] (Michael Fuhr) wrote in message news:[EMAIL PROTECTED]...
If the actual byte and/or bit order is different then you'll have
to modify the expression, but this should at least give you ideas.

Thanks Michael and Steve,
I'll put your Ideas to the test ASAP, meanwhile, could you point me to
references to these bit operations in Python? I am new to this stuff,
and might need to do more of this to support other hardware...
I havent been able to find anything about this on the python
documentation..
Thanks a lot!!
Flavio
ord() is documented in section 2.1 of the library reference manual 
(Built-in Functions) - see 
http://docs.python.org/lib/built-in-funcs.html#l2h-53 for further 
information.

Bitstring operations are at 
http://docs.python.org/lib/bitstring-ops.html#l2h-150

Hope this helps.
regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: 20050119: quoting strings

2005-01-10 Thread Steve Holden
Xah Lee wrote:
#strings are enclosed in double quotes quotes. e.g.
a=this and that
print a
#multiple lines must have an escape backslash at the end:
b=this\n\
and that
print b
#One can use r for raw string.
c=rthis\n\
and that
print c
#To avoid the backslash escape, one can use triple double quotes to
print as it is:
d=this
and
that
print d
---
# in Perl, strings in double quotes acts as Python's triple .
# String is single quote is like Python's raw r.
# Alternatively, they can be done as qq() or q() respectively,
#and the bracket can be just about any character,
# matching or not. (so that escapes can be easy avoided)
$a=q(here, everthing is literal, $what or \n or what not.);
$b=qq[this is
what ever including variables $a that will be
evaluated, and quotes needn't be quoted.];
print $a\n$b;
#to see more about perl strings, do on shell prompt
#perldoc -tf qq
Xah
 [EMAIL PROTECTED]
 http://xahlee.org/PageTwo_dir/more.html
Well, that gets that sorted out, then.
Tomorrow: using single quotes. Using single quotes. The larch.
regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: tuples vs lists

2005-01-10 Thread Gerrit
Steve Holden wrote:
 worzel wrote:
 'Two-Pull' it is then, thanks.
 
 Well, it might be Two-Pull in American, but in English it's tyoopl 
 -- NOT choopl (blearch!). I've also heard people say tuppl.
 
 So, basically, say whatever you want. Language is about communication :-)

Or just write it down and don't say the word at all (-:

regards,
Gerrit, who actually says tpel.

-- 
Weather in Lulea / Kallax, Sweden 10/01 10:20:
-12.0C   wind 0.0 m/s None (34 m above NAP)
-- 
In the councils of government, we must guard against the acquisition of
unwarranted influence, whether sought or unsought, by the
military-industrial complex. The potential for the disastrous rise of
misplaced power exists and will persist.
-Dwight David Eisenhower, January 17, 1961
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python3: 'where' keyword

2005-01-10 Thread Nick Coghlan
Andrey Tatarinov wrote:
And about examples for usage where keyword
reading http://manatee.mojam.com/~skip/python/fastpython.html I 
understand that almost every example should use that keyword =)
I suspect polluting the outer namespace would still be faster, since Python 
wouldn't have to create the extra level of scoping all the time.

Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: python3: 'where' keyword

2005-01-10 Thread Carl Banks

Paul Rubin wrote:
 Carl Banks [EMAIL PROTECTED] writes:
  And a suite, be it a def statement, a where block, or whatever,
belongs
  in a statement, not an expression.

 So do you approve of the movement to get rid of the print statement?

Any little incremental change in Python you could make by having or not
having a print statement would be minor compared to the H-Bomb of
ugliness we'd get if suites of statements were to be allowed inside
Python expressions.  Having or not having a print statement might
violate some small aspect of the Zen, but it won't rape the whole list.

So I don't know what point you're trying to make.

But to answer your question, I would prefer a Python without a print
statement, since a print method could do anything the print statement
could.


-- 
CARL BANKS

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


Re: python3: 'where' keyword

2005-01-10 Thread Paul Rubin
Carl Banks [EMAIL PROTECTED] writes:
  So do you approve of the movement to get rid of the print statement?
 
 Any little incremental change in Python you could make by having or not
 having a print statement would be minor compared to the H-Bomb of
 ugliness we'd get if suites of statements were to be allowed inside
 Python expressions.  Having or not having a print statement might
 violate some small aspect of the Zen, but it won't rape the whole list.

How about macros?  Some pretty horrible things have been done in C
programs with the C preprocessor.  But there's a movememnt afloat to
add hygienic macros to Python.  Got any thoughts about that?

 So I don't know what point you're trying to make.

Why should you care whether the output of a macro is ugly or not,
if no human is ever going to look at it?  

 But to answer your question, I would prefer a Python without a print
 statement, since a print method could do anything the print statement
 could.

A print -method-?!!  You /really/ want to say

  your_name  = Carl
  your_favorite_cereal = cornflakes
  (Hi, your_name, how about a nice bowl of, your_favorite_cereal).print()

instead of 

  your_name  = Carl
  your_favorite_cereal = cornflakes
  print Hi, your_name, how about a nice bowl of, your_favorite_cereal



I've heard of people wanting to replace print with a function, but
hadn't heard of replacing it with a method.  Are you trying to turn
Python into Ruby?
-- 
http://mail.python.org/mailman/listinfo/python-list


Port blocking

2005-01-10 Thread Mark Carter
Supposing I decide to write a server-side application using something 
like corba or pyro.

What's the chance that in big corporations, the client's ports (in both 
 senses of the word: fee-paying, and application) will be blocked, 
thereby immediately scuppering whatever I have written? Has this problem 
ever arisen for anyone?

Also, is there a good tool for writing database UIs?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Port blocking

2005-01-10 Thread Paul Rubin
Mark Carter [EMAIL PROTECTED] writes:
 Supposing I decide to write a server-side application using something
 like corba or pyro.
 
 What's the chance that in big corporations, the client's ports (in
 both senses of the word: fee-paying, and application) will be blocked,
 thereby immediately scuppering whatever I have written? Has this
 problem ever arisen for anyone?

Usually you wouldn't run a public corba or pyro service over the
internet.  You'd use something like XMLRPC over HTTP port 80 partly
for the precise purpose of not getting blocked by firewalls.

 Also, is there a good tool for writing database UIs?

Yes, quite a few.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Statement local namespaces summary (was Re: python3: 'where' keyword)

2005-01-10 Thread Nick Coghlan
Duncan Booth wrote:
Nick Coghlan wrote:

Grammar Change
--
Current::
  statement ::=stmt_list NEWLINE | compound_stmt
New::
  statement ::=(stmt_list NEWLINE | compound_stmt) [local_namespace]
  local_namespace ::= with : suite
Semantics
-
The code::
statement with:
   suite
translates to::
def unique_name():
suite
statement
unique_name()

Your proposed grammar change says that you need a newline after the 
statement:
True, and not really what I intended. However, it does highlight the fact that 
statement lists haven't been considered in the discussion so far.

If statement lists are permitted, getting the right targets bound in the 
containing scope is going to be fun for things like this:

a = b = 2; c = 3; print a + b with:
  pass
(Probably not impossible though - e.g. it may be feasible to figure out all the 
bindings that have to happen and return an appropriate tuple from the inner 
scope for binding in the outer scope)

It might also be somewhat confusing as to exactly which statements are covered 
by the local scoping. (All of them would be, but you could be forgiven for 
assuming it was just the last one)

I think the following would work as a version of the grammar which permits local 
namespaces for statement lists:

  statement ::= (stmt_list (NEWLINE | local_namespace)) |
(compound_stmt [local_namespace])
  local_namespace ::= with : suite
Disallowing local namespaces for statement lists would suggest something like 
this:
  statement ::= (simple_stmt
  (NEWLINE | ; stmt_list NEWLINE | local_namespace)
 ) |
(compound_stmt [local_namespace])
  local_namespace ::= with : suite
I'm pretty sure the permissive version is legal for the CPython parser, and I 
think the somewhat baroque structure I've used for the restrictive version makes 
it legal, too.

Disallowing local namespaces for statement lists might be a good place to start, 
since it gives an easier target for a first implementation.

Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: python3: 'where' keyword

2005-01-10 Thread Carl Banks

Paul Rubin wrote:
 Carl Banks [EMAIL PROTECTED] writes:
   So do you approve of the movement to get rid of the print
statement?
 
  Any little incremental change in Python you could make by having or
not
  having a print statement would be minor compared to the H-Bomb of
  ugliness we'd get if suites of statements were to be allowed inside
  Python expressions.  Having or not having a print statement might
  violate some small aspect of the Zen, but it won't rape the whole
list.

 How about macros?  Some pretty horrible things have been done in C
 programs with the C preprocessor.  But there's a movememnt afloat to
 add hygienic macros to Python.  Got any thoughts about that?

How about this: Why don't you go to a Python prompt, type import
this, and read the Zen of Python.  Consider each line, and whether
adding macros to the language would be going against that line or for
it.  After you've done that, make an educated guess of what you think
I'd think about macros, citing various Zens to support your guess.

Then I'll tell you what my my thoughts about it are.


  So I don't know what point you're trying to make.

 Why should you care whether the output of a macro is ugly or not,
 if no human is ever going to look at it?

I don't.


  But to answer your question, I would prefer a Python without a
print
  statement, since a print method could do anything the print
statement
  could.

 A print -method-?!!
[snip example]

 I've heard of people wanting to replace print with a function, but
 hadn't heard of replacing it with a method.  Are you trying to turn
 Python into Ruby?

I'll give you the benefit of the doubt that you just didn't think it
over thoroughly.  I was thinkging would be a method of file like
objects.

stdout.print(hello)


-- 
CARL BANKS

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


Re: Port blocking

2005-01-10 Thread Mark Carter
Paul Rubin wrote:
Mark Carter [EMAIL PROTECTED] writes:
Supposing I decide to write a server-side application using something
like corba or pyro.

Usually you wouldn't run a public corba or pyro service over the
internet.  You'd use something like XMLRPC over HTTP port 80 partly
for the precise purpose of not getting blocked by firewalls.
Although, when you think about it, it kinda defeats the purposes of 
firewalls. Not that I'm criticising you personally, you understand.

Also, is there a good tool for writing database UIs?

Yes, quite a few.
Ah yes, but is there really? For example, I did a search of the TOC of 
GTK+ Reference Manual:
http://developer.gnome.org/doc/API/2.0/gtk/index.html
for the word data, and there's apparently no widget which is 
explicitly tied to databases. So in GTKs case, for instance, it looks 
like one has to roll one's own solution, rather than just using one out 
of the box.
--
http://mail.python.org/mailman/listinfo/python-list


Command line and GUI tools : need a single threading solution

2005-01-10 Thread Adrian Casey
I have a collection of multi-threaded command line tools which I want wrap a
PyQt gui around.  I'm using queues to route messages from the command line
tools to the PyQt gui. The command line tools use python threads to do
their work.  The gui uses a QThread object to read incoming messages.

This does not work consistently - and I've since read that mixing python
threads and QThreads is a bad idea.  The command line tools work well using
python threads.

I don't want to maintain two copies of the tools - one for command line and
another for the PyQt version.

I'm thinking it may be possible to modify the command line tools to use qt
threads instead of native python threads.  Is this the way to go?  Are
there other options?

Adrian.


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


Re: Command line and GUI tools : need a single threading solution

2005-01-10 Thread Diez B. Roggisch
 I'm thinking it may be possible to modify the command line tools to use qt
 threads instead of native python threads.  Is this the way to go?  Are
 there other options?

Why don't you use python threads in qt - I do so and so far it didn't make
any troubles for me. And I would strongly advise against using qthreads
with your commandline-tools, as these then would only run on machines where
pyqt is installed - which opens a small part of dependency hell for your
users.

-- 
Regards,

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


Re: Port blocking

2005-01-10 Thread Diez B. Roggisch
 Usually you wouldn't run a public corba or pyro service over the
 internet.  You'd use something like XMLRPC over HTTP port 80 partly
 for the precise purpose of not getting blocked by firewalls.

What exactly makes sending bytes over port 80 more secure than over any
other port? It has always been my impression that this was to create less
administrative troubles for firewall admins.  But its not inherently more
secure. That's a property of the application running.

-- 
Regards,

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


Re: Command line and GUI tools : need a single threading solution

2005-01-10 Thread Phil Thompson
 I have a collection of multi-threaded command line tools which I want wrap
 a
 PyQt gui around.  I'm using queues to route messages from the command line
 tools to the PyQt gui. The command line tools use python threads to do
 their work.  The gui uses a QThread object to read incoming messages.

 This does not work consistently - and I've since read that mixing python
 threads and QThreads is a bad idea.  The command line tools work well
 using
 python threads.

How well mixing the two threading APIs works depends on version numbers. A
PyQt generated with SIP v4.x (rather than SIP v3.x) with Python v2.4
should be Ok.

 I don't want to maintain two copies of the tools - one for command line
 and
 another for the PyQt version.

 I'm thinking it may be possible to modify the command line tools to use qt
 threads instead of native python threads.  Is this the way to go?  Are
 there other options?

Using QThreads only should work - just tell the QApplication ctor that you
have a console application.

Phil

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


Re: Datetime module

2005-01-10 Thread Mark McEahern
[EMAIL PROTECTED] wrote:
I am writing a script that acts as an AIM bot [using twisted.IM's base
scripts] and I want to add a logging feature. I got it to log who sends
what to whom, but what I want to add is the date and time that the
message was sent (or recieved by the bot), I tried to look at datetime
on my own, and I couldn't get anything to work.
Anyone know a simple way to get the current date and/or time?
 import datetime
 datetime.datetime.now()
datetime.datetime(2005, 1, 10, 6, 39, 56, 64000)
 print datetime.datetime.now()
2005-01-10 06:40:03.705000

You may also want to consider using the logging module.
// m
--
http://mail.python.org/mailman/listinfo/python-list


Re: python3: 'where' keyword

2005-01-10 Thread Paul Rubin
Carl Banks [EMAIL PROTECTED] writes:

 Paul Rubin wrote:
  Carl Banks [EMAIL PROTECTED] writes:
So do you approve of the movement to get rid of the print
 statement?
  
   Any little incremental change in Python you could make by having or
 not
   having a print statement would be minor compared to the H-Bomb of
   ugliness we'd get if suites of statements were to be allowed inside
   Python expressions.  Having or not having a print statement might
   violate some small aspect of the Zen, but it won't rape the whole
 list.
 
  How about macros?  Some pretty horrible things have been done in C
  programs with the C preprocessor.  But there's a movememnt afloat to
  add hygienic macros to Python.  Got any thoughts about that?
 
 How about this: Why don't you go to a Python prompt, type import
 this, and read the Zen of Python.  Consider each line, and whether
 adding macros to the language would be going against that line or for
 it.  After you've done that, make an educated guess of what you think
 I'd think about macros, citing various Zens to support your guess.
 
 Then I'll tell you what my my thoughts about it are.


The Zen of Python, by Tim Peters

Beautiful is better than ugly.   = +1 macros 
Explicit is better than implicit. = +1 macros
Simple is better than complex.  = +1 macros
Complex is better than complicated.  = I don't understand this, +0
Flat is better than nested.  = not sure, +0
Sparse is better than dense. = +1 macros
Readability counts. = +1 macros
Special cases aren't special enough to break the rules. = +1 macros
Although practicality beats purity. = +1 macros
Errors should never pass silently. = +1 macros
Unless explicitly silenced. = +1 macros
In the face of ambiguity, refuse the temptation to guess. = +1 macros
There should be one-- and preferably only one --obvious way to do it. = -1
Although that way may not be obvious at first unless you're Dutch. = ???
Now is better than never. = +1 macros, let's do it
Although never is often better than *right* now. = +1 
If the implementation is hard to explain, it's a bad idea. = unknown, +0
If the implementation is easy to explain, it may be a good idea. = +0
Namespaces are one honking great idea -- let's do more of those! = +1

I'm -1 on doing stuff by received dogma, but in this particular case
it looks to me like the dogma is +12 for macros.  What are your thoughts?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Securing a future for anonymous functions in Python

2005-01-10 Thread Anna

Jacek Generowicz wrote:
 Anna [EMAIL PROTECTED] writes:

  With class and def, I at least have a *name* to start with - class
  Square pretty obviously is going to have something to do with
  geometric shapes, I would hope (or maybe with boring people...).

 Or maybe with multiplying something by itself. Or maybe the author
 made some changes in his program, and forgot to rename the class
 sensibly, and the class' functionality has nothing to do with squares
 of any sort any more. Or maybe he felt the name Square was very
 appropriate for something else in his program and inadvertently gave
 the same name to two different entities thereby clobbering the one
 whose use was intended at this point.

Idjits abound. ;-)

Can't make anything foolproof because fools are so ingenious.

  Whereas, with lambda - I have *nothing* to go on.

 Aaah. OK, you object to lambda because it gives you no clue as to
what
 the function does, rather than with the word lambda itself? Is that
 it?

 So, IIUC, you consider

def add_one(x):
return x+1

map(add_one, seq)

 to be clearer than

map(lambda x:x+1, seq)

Completely, totally, and unambiguously: the version with the defined
function is immediately clear to me; the version with the lambda is
decipherable, but requires deciphering (even at 2nd and 3rd glance).
But first, wouldn't something like:

[x+1 for x in seq]

be even clearer?

Given an example more complex (which you must admit, lambdas usually
are) - the name of the function is something my brain can hold on to to
represent the group of operations; where with the lambda, I need to
mentally go through each operation each time I try to read it. And the
more complex f is, the harder time I have holding it all in my head
while I figure out how to get from the beginning value x to the ending
value f(x). lambda is an O(N*N) problem for my brain.

I could see someone more mathematically-minded being happier with
lambda. It's not, after all, the word lambda itself; I would still
have some issues with using, say function, instead of lambda, but
at least then I would immediately know what I was looking at...

Anna

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


Re: Statement local namespaces summary (was Re: python3: 'where' keyword)

2005-01-10 Thread Nick Coghlan
Nick Coghlan wrote:
Disallowing local namespaces for statement lists would suggest something 
like this:

  statement ::= (simple_stmt
  (NEWLINE | ; stmt_list NEWLINE | local_namespace)
 ) |
(compound_stmt [local_namespace])
  local_namespace ::= with : suite
Corrected version of the above to avoid an unintended syntax change:
  statement ::= (simple_stmt
  (NEWLINE | ; [stmt_list] NEWLINE | local_namespace)
 ) |
(compound_stmt [local_namespace])
  local_namespace ::= with : suite
(The original version incorrectly prohibited a trailing semi-colon for a single 
statement)

Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: Old Paranoia Game in Python

2005-01-10 Thread Lucas Raab
[EMAIL PROTECTED] wrote:
Aahz wrote:
Trust the computer, the computer is your friend.

However, the computer isn't a fuckin' mind reader.
If you're going to post source code on the usenet, don't
have lines longer than 72 characters. Otherwise you'll
find your code has wrapped lines. This not only causes
syntax errors in your choose and print statements but
also fucks up the formatting of of printed paragraphs.
Stupid human.
Temper, temper...
--
http://mail.python.org/mailman/listinfo/python-list


Re: Port blocking

2005-01-10 Thread Mark Carter
Mark Carter wrote:
Paul Rubin wrote:

Usually you wouldn't run a public corba or pyro service over the
internet.  You'd use something like XMLRPC over HTTP port 80 partly
for the precise purpose of not getting blocked by firewalls.
I'm not sure if we're talking at cross-purposes here, but the 
application isn't intended for public consumption, but for fee-paying 
clients.
--
http://mail.python.org/mailman/listinfo/python-list


Re: tuples vs lists

2005-01-10 Thread Antoon Pardon
Op 2005-01-08, Bruno Desthuilliers schreef [EMAIL PROTECTED]:
 worzel a écrit :
 I get what the difference is between a tuple and a list, but why would I 
 ever care about the tuple's immuutability?

 Because, from a purely pratical POV, only an immutable object can be 
 used as kay in a dict.

This is not true.

 So you can use tuples for 'composed key'.

lists can be so used too. Just provide a hash.

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


Re: Powerful CGI libraries for Python?

2005-01-10 Thread Thomas Guettler
Am Mon, 10 Jan 2005 10:11:16 +0800 schrieb sam:

 Hi,
 
 I m looking for a CGI libraries just  like perl's CGI.pm for Python.
  From google, I found quite a few of CGI libraries already written for 
 python. But I haven't had experience to try any of them in Python.
 
 Can anyone share your Python CGI experience with me? Which library is 
 better in terms of functionality and stability?

Hi,

in the standard library there is cgi and cgitb. If you just want to
write a small cgi script, both modules should be all you need.

I found quixote simple and easy to learn. Quixote 1.x is quite stable.
The version I use is more then six months old, and there is no need to
update.

Take a look at:
http://www.python.org/cgi-bin/moinmoin/WebProgramming

 Thomas

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


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


Re: Python3: on removing map, reduce, filter

2005-01-10 Thread Nick Coghlan
Terry Reedy wrote:
Andrey Tatarinov [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]

How does GvR suggestions on removing map(), reduce(), filter()

While GvR *might* prefer removing them completely on any given day, I think 
moving them to a functional module, as others have suggested and requested, 
is currently more likely.  I believe that GvR has indicated at times that 
this would be an acceptible compromise.

I am one of those who think the list of builtins is currently too long to 
be easily grasped and should be shrunk.
Heh. When PEP 309 hits CVS (with functional.partial), maybe it can grow aliases 
for the three of them so people can get used to the idea.

It might keep partial from getting too lonely. . . :)
Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


C structure in the Python extension

2005-01-10 Thread Dave win
Howdy:
When I was writting interface functions of the extending python,  I
meet a question. As I using the  PyArg_ParseTuple(args,arg_type,...)
function call, if I wanna use the personal defined argument, such as the
C structure which I made. How to make it?

static PyObject* Call_V_ABSUB(PyObject *self, PyObject* args){
  myStruct FU;
  myStruct result;
  if(!PyArg_ParseTuple(args,O,FU)) return NULL;
 ^^^
 How to modify here???
  V_ABSUB(FU);

  return Py_BuildValue(i,result);
}




Thx.

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


Re: Speed revisited

2005-01-10 Thread Nick Coghlan
John Machin wrote:
My wild guess: Not a common use case. Double-ended queue is a special
purpose structure.
As Kent said, the suggestion of making index 0 insertions and deletions on lists 
more efficent was made, and the decision was to leave list alone and provide 
collections.deque instead. This let deque sacrifice some of list's flexibility 
in favour of increased speed.

Appropriate parts of the core which needed a FIFO were then updated to use the 
new data type, while everything else continues to use lists.

Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: python3: 'where' keyword

2005-01-10 Thread Jonas Galvez
Andrey Tatarinov wrote:
 It would be great to be able to reverse usage/definition parts 
 in haskell-way with where keyword.

Hi folks, I really like this idea. But I couldn't help but think 
of a few alternative ways. I'm no language design expert by any 
means, but I'm a little concerned with the idea of an 'expression' 
preceding a 'block'. Maybe I'm naive (actually, I'm pretty sure I 
am), but I think a decorator-like syntax would be a little more 
Pythonic. Here's a small example:

def where(closure=None, *v):
if not False in v:
closure(*v)

def foo(a, b):
@where(a: int, b: int):
return str(a) + str(b)
raise TypeMismatch

The (variable : type) could be turned into a syntact sugar for 
(type(variable) is type). Basically, this would be a simple 
implementation of the so called closures, where a decorator is 
able to 'receive' a code block, which would be passed as a 
function as the first argument of the decorator. (Is this clear?)

As I said, I'm no language design expert and I'm sure I'm breaking 
a few important rules here heh. But I find it cool. This is not a 
proposal. I'm just thinking out loud :)


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


Re: Port blocking

2005-01-10 Thread Grant Edwards
On 2005-01-10, Diez B. Roggisch [EMAIL PROTECTED] wrote:

 Usually you wouldn't run a public corba or pyro service over
 the internet.  You'd use something like XMLRPC over HTTP port
 80 partly for the precise purpose of not getting blocked by
 firewalls.

 What exactly makes sending bytes over port 80 more secure than
 over any other port?

Nothing.

When has reality had anything to do with the way corporate IT
types configure firewalls?  ;)

 It has always been my impression that this was to create less
 administrative troubles for firewall admins.

It's to give corporate IT types the _illusion_ of security and
relieve them of the need to learn how to configure firewalls.

 But its not inherently more secure. That's a property of the
 application running.

-- 
Grant Edwards   grante Yow!  HAIR TONICS, please!!
  at   
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Securing a future for anonymous functions in Python

2005-01-10 Thread Ville Vainio
 James == James Stroud [EMAIL PROTECTED] writes:

James I think we should not try too hard to make everything
James English like. Its a crappy language anyway (though its
James the only one I speak good). Matt Neuberg,

QOTW material, unless you stole this from someone else :-).

-- 
Ville Vainio   http://tinyurl.com/2prnb
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT: google groups bug, or worse?

2005-01-10 Thread Tomi Häsä
[EMAIL PROTECTED] wrote:
 I'm concerned that google groups is not correctly reflecting
 the python lists.
 [...]
 Is it a google bug?

Yes, Google Groups Beta is missing messages:

http://groups-beta.google.com/group/google-labs-groups2/browse_thread/thread/c4108ad41c189d34?tvc=2
http://tinyurl.com/6vybw
http://groups-beta.google.com/group/google-labs-groups2/msg/dc745c7784c81890
http://tinyurl.com/4keqh
http://groups-beta.google.com/group/google-labs-groups2/msg/b54c12517c75eb24

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


Re: python3: 'where' keyword

2005-01-10 Thread Carl Banks
Paul Rubin wrote:

 The Zen of Python, by Tim Peters

 Beautiful is better than ugly.   = +1 macros
 Explicit is better than implicit. = +1 macros
 Simple is better than complex.  = +1 macros
 Complex is better than complicated.  = I don't understand this,
+0
 Flat is better than nested.  = not sure, +0
 Sparse is better than dense. = +1 macros
 Readability counts. = +1 macros
 Special cases aren't special enough to break the rules. = +1
macros
 Although practicality beats purity. = +1 macros
 Errors should never pass silently. = +1 macros
 Unless explicitly silenced. = +1 macros
 In the face of ambiguity, refuse the temptation to guess. = +1
macros
 There should be one-- and preferably only one --obvious way to do
it. = -1
 Although that way may not be obvious at first unless you're
Dutch. = ???
 Now is better than never. = +1 macros, let's do it
 Although never is often better than *right* now. = +1
 If the implementation is hard to explain, it's a bad idea. =
unknown, +0
 If the implementation is easy to explain, it may be a good idea.
= +0
 Namespaces are one honking great idea -- let's do more of those!
= +1

 I'm -1 on doing stuff by received dogma, but in this particular case
 it looks to me like the dogma is +12 for macros.  What are your
thoughts?

Paul,

When I asked you to do this, it was just a rhetorical way to tell you
that I didn't intend to play this game.  It's plain as day you're
trying to get me to admit something.  I'm not falling for it.

If you have a point to make, why don't you just make it?
-- 
CARL BANKS

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


Re: Port blocking

2005-01-10 Thread Ville Vainio
 Mark == Mark Carter [EMAIL PROTECTED] writes:

Mark Mark Carter wrote:
 Paul Rubin wrote:

 Usually you wouldn't run a public corba or pyro service over
 the internet.  You'd use something like XMLRPC over HTTP port
 80 partly for the precise purpose of not getting blocked by
 firewalls.

Mark I'm not sure if we're talking at cross-purposes here, but
Mark the application isn't intended for public consumption, but
Mark for fee-paying clients.

Still, if the consumption happens over the internet there is almost
100% chance of the communication being prevented by firewalls.

This is exactly what web services are for.

-- 
Ville Vainio   http://tinyurl.com/2prnb
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT: spacing of code in Google Groups

2005-01-10 Thread Tomi Häsä
Dan Bishop wrote:

 And for a long time, Google groups postings *were* whitespace
 significant.  But the new interface broke it.

  I made a complaint several weeks ago to Google support,
  asking them too quit stripping leading whitespace,
  and the sent me a reply saying they appreciated my feedback.
  Maybe they  just need more feedback :)

 I send them some earlier today.  So far, I've only received
 their auto-reply.

Removing and adding spaces discussed in the Google Groups Beta group
also:

http://groups-beta.google.com/group/google-labs-groups2/browse_thread/thread/9bc4328fd27d3ad4/80ad25b58d5dbb49?_done=%2Fgroup%2Fgoogle-labs-groups2%2Fthreads%3Fstart%3D60%26order%3Drecent%26_doneTitle=Backd#80ad25b58d5dbb49
http://tinyurl.com/6oe6v
http://groups-beta.google.com/group/google-labs-groups2/browse_thread/thread/73b712c45c9d89d2/bdc0544e3b08a1cd?_done=%2Fgroup%2Fgoogle-labs-groups2%2Fthreads%3Fstart%3D120%26order%3Drecent%26_doneTitle=Backd#bdc0544e3b08a1cd
http://tinyurl.com/5nz5u

Demonstration of the problem:

http://groups-beta.google.com/group/Groups-2-Test-Group/browse_thread/thread/cc5a64d2e18f0594/945fa09eea37e41c?_done=%2Fgroup%2FGroups-2-Test-Group%3F_doneTitle=Back+to+topics_doneTitle=Backd#945fa09eea37e41c
http://tinyurl.com/4wem9

More problems listed here:

http://groups-beta.google.com/group/google-labs-groups2/msg/b54c12517c75eb24
http://tinyurl.com/3khmj

More info in the FAQ:
http://www.geocities.com/googlepubsupgenfaq/#groupsproblems

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


Re: python3: 'where' keyword

2005-01-10 Thread Paul Rubin
Carl Banks [EMAIL PROTECTED] writes:
 When I asked you to do this, it was just a rhetorical way to tell you
 that I didn't intend to play this game.  It's plain as day you're
 trying to get me to admit something.  I'm not falling for it.
 
 If you have a point to make, why don't you just make it?

You asked me to compare the notion of macros with the Zen list.  I did
so.  I didn't see any serious conflict, and reported that finding.
Now you've changed your mind and you say you didn't really want me to
make that comparison after all.

An amazing amount of the headaches that both newbies and experienced
users have with Python, could be solved by macros.  That's why there's
been an active interest in macros for quite a while.  It's not clear
what the best way to do design them is, but their existence can have a
profound effect on how best to do these ad-hoc syntax extensions like
where.  Arbitrary limitations that are fairly harmless without
macros become a more serious pain in the neck if we have macros.

So, we shouldn't consider these topics separately from each other.
They are likely to end up being deeply related.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a new Perl/Python a day

2005-01-10 Thread François Pinard
[Andy Gross]

 On Jan 10, 2005, at 12:11 AM, Scott Bryce wrote:

 No. Perl may have some interesting idiosyncrasies

 I [...] still have to look at the documentation to remember that I
 need to type '$|' to turn buffering off.  Ditto for the rest of the
 perl line-noise syntax.

Behind each language, there is a culture.  The Perl man pages give many
mnemonic tricks to remember special variable names like the above, and
if you are willing to play the game the way it was written, you might
even have some fun at it, and easily be proficient at this line-noise.

I did a lot of Perl for many years, and still appreciate what Perl is
(or at least was).  Python does not change Perl in my eyes.  However,
Python is significantly more legible and maintainable, the comparison
merely stresses the unreadability of Perl.  No doubt that I prefer
Python, but Python not being there, Perl would be quite useful to me.

-- 
François Pinard   http://pinard.progiciels-bpi.ca
-- 
http://mail.python.org/mailman/listinfo/python-list


Dr. Dobb's Python-URL! - weekly Python news and links (Jan 9)

2005-01-10 Thread Josiah Carlson
QOTW:  Jim Fulton: [What's] duck typing?
Andrew Koenig: That's the Australian pronunciation of 'duct taping'.

I'm thinking that the I-Ching is a vast untapped resource for programming
wisdom, plus it makes it funny. -- Mark Carter


Nick Coghlan brings up the 'lambdas are going away in 3.0' topic, which
has been discussed before:

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

A user asks about a non-generator-based method for iteration using class
__iter__ and next() methods:

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

Daniel Bickett asks about getting Twisted and wxPython working together,
and receives both a threaded and non-threaded version:

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

A question about iterating over floats...be careful!

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

A Boogieman asks whether Python is easily learned and what can be done
with it.  Quick answer: yes, and anything you are capable of doing:
This Boogieman later asks about GUI toolkits:

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

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

Erik Bethke writes Majong game after using Python for a month.  Ahh, will
the wonders of Python never cease?

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

Kamilche asks about getting warnings when not calling a function, and gets
pointed to pychecker, something more of us should be using:

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

Are people allowed to build commercial applications in Python?  YES!

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

Questions about asyncore brings up a web server in asyncore from _Python
Web Programming_, and a pointer to Twisted.  Alternatively, one could look
at the asynchat or smtpd modules in the standard library as sources of
inspiration:

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


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=djqas_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.
 

Re: Using ICL to compile C extensions

2005-01-10 Thread John Carter
On 3 Jan 2005 21:18:13 -0800, [EMAIL PROTECTED] wrote:

Hi,

Does anyone know how I can use icl (Intel C++) to compile C
extensions? I'm on Windows, and my Python is compiled using VS7.1
(binary distribution). Right now, when I run setup.py install, it uses
cl.exe (MSVC++ Toolkit 2003), and I would like to use icl because
MSVC++ 2003 does not support C99.
Any help will be much appreciated.

Cheers,
Michael

I've not tried to do it using distutils yet, but when I was building
extension modules with my own make files and nmake all I had to do was
chance cl to icl and use the correct linker. You can tune the
performance playing with switches, but I got a factor 3 improvement on
a DCT type algorithm with out of the box settings.

I can send you an example makefile if you want

John Carter

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


Re: Developing Commercial Applications in Python

2005-01-10 Thread bit_bucket5
See http://www.journynx.com/
Commercial timesheet app written in Python.

[EMAIL PROTECTED] wrote:
 Hello All,
 I am trying to convince my client to use Python in his new product.
He
 is worried about the license issues. Can somebody there to point me
any
 good commercial applications developed using python ?. The licence
 clearly says Python can be used for commercial applications. Is there
 any other implications like that of GPL to make the source open ?
 Thanks for any help.
 eeykay

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


  1   2   >