Re: Relative-importing *

2007-07-28 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes:
> I read "from module import *" as explicitly saying "clobber the current
> namespace with whatever names module exports". That's what from does: it
> imports names into the current namespace. It isn't some sort of easy to
> miss side-effect. If a name already existed, it gets clobbered, just like
> any other import:

Seems to me that there should be a compiler warning when this happens.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 128 or 96 bit integer types?

2007-07-28 Thread [EMAIL PROTECTED]
On Jul 28, 12:30 am, Tim Roberts <[EMAIL PROTECTED]> wrote:
> "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>
> >On Jul 27, 1:27 pm, Peter Otten <[EMAIL PROTECTED]> wrote:
> >> Robert Dailey wrote:
> >> > Is there build-in or third party support for large integer types, such
> >> > as 96 or 128 bits in size? I require such large sizes for precision
> >> > issues (nanoseconds). Thanks.
> >> >>> SECOND = 10**9
> >> >>> YEAR = 365*24*60*60
> >> >>> 2**128/SECOND/YEAR
>
> >> 10790283070806014188970L
>
> >> What are you measuring? The age of the universe? In nanoseconds?
>
> >> :-)
>
> >Well, 2**96 would only be 2512308552583 years.
>
> Yes, but that's still roughly 100 times the estimated age of the universe.

Yeah, I know. I thought it was so obvious I didn't need a :-).

But _I_ won't question the need for numbers that large.
That's how I got into Python in the first place,
looking for Big Arithmetic. And I've been very happy
with it. Especially compared to the competition.
Would you believe that new F# language from Microsoft
doesn't even have an exponentiation operator? It has
a power function for floats, but not for Big Integers.
Completely worthless.

Some very simple questions can have very big answers.

For example, how many ways can you put 492 marbles into
264 ordered bins such that each bin has at least 1 marble?

The answer

66189415264331559482776409694993032407028709677550
59629130019289014193777349831417543311612293951363
4124491233746912456893016976209252459301489030

has 146 digits. And that's just the begining. The above
actually represents a polynomial with 264 terms, the
exponents of which range from 0 to 492. One of those
polynomials can have over 5 decimal digits when
solved.

So I never let the age of the universe intimidate me.

Of course, I can't solve ALL the polynomials.
Gotta be a bit selective. :-)


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


Re: 128 or 96 bit integer types?

2007-07-28 Thread Paul Rubin
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:
> has 146 digits. And that's just the begining. The above
> actually represents a polynomial with 264 terms, the
> exponents of which range from 0 to 492. One of those
> polynomials can have over 5 decimal digits when
> solved.

You should use gmpy rather than python longs if you're dealing with
numbers of that size.  Python multiplication uses a straightforward
O(n**2) algorithm where n is the number of digits.  This is the best
way for up to a few hundred or maybe a few thousand digits.  After
that, it's better to use more complicated FFT-based algorithms which
are O(n log n) despite their increased constant overhead.  Gmpy does this.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: removing items from a dictionary ?

2007-07-28 Thread Paddy
On Jul 28, 1:43 am, Steven D'Aprano
<[EMAIL PROTECTED]> wrote:
> On Thu, 26 Jul 2007 21:38:31 +0200, martyw wrote:
> > Remoing elements from a dict is done with del, try this;
> >  >>> d = {'a' : 1,'b' : 2}
> >  >>> del d['a']
> >  >>> print d
> > {'b': 2}
>
> > maybe you can post a working snippet to demonstrate your problem
>
> Wow. This wins my award for the least helpful, while still being
> technically correct, reply ever. Did you even read the Original Poster's
> post? He already knows that you delete items from a dictionary with del,
> and he posted code and the traceback he gets when he runs it.
>
> --
> Steven.

... But lets also applaud the fact that MartyW wants to help.

- Paddy.

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


Re: Comparing Dictionaries

2007-07-28 Thread Paddy
Hi Kenneth,  being new to Python i wondered if you at least considered
Doctests as part of your testing solution.
Other languages don't have Doctest.

- Paddy.

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


Re: Compile python with Mingw

2007-07-28 Thread Brian Elmegaard
iwinux <[EMAIL PROTECTED]> writes:

> To build python with mingw, there is a common way.
> First you should install msys, which can be downloaded from mingw's website.
> Run msys and type 'cd /path/to/source'.
> Then type "./configure & make & make install".
> And you will get a python built with mingw.

It would be nice if this was the situation. I just tested without
success. Do you say that the instructions in e.g. the first three hits
on http://www.google.com/search?q=python+mingw are no longer relevant?



-- 
Brian (remove the sport for mail)
http://www.et.web.mek.dtu.dk/Staff/be/be.html
http://www.rugbyklubben-speed.dk
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 128 or 96 bit integer types?

2007-07-28 Thread David H Wild
In article <[EMAIL PROTECTED]>,
   [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> For example, how many ways can you put 492 marbles into
> 264 ordered bins such that each bin has at least 1 marble?

> The answer

> 66189415264331559482776409694993032407028709677550
> 59629130019289014193777349831417543311612293951363
> 4124491233746912456893016976209252459301489030

> has 146 digits.

What on  earth made you think of that question?

-- 
David Wild using RISC OS on broadband
www.davidhwild.me.uk
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Compiling python2.5.1 results in 3.5MB python lib?

2007-07-28 Thread Martin v. Löwis
> I'm compiling 2.5.1 and end up with a 3.5MB libpython2.5.so file. I
> seem to remember it should be somewhere around the 1MB mark. What
> could be causing this?

Try stripping it.

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


Re: a simple string question

2007-07-28 Thread vedrandekovic
On 28 srp, 07:05, Zentrader <[EMAIL PROTECTED]> wrote:
> > > [EMAIL PROTECTED] wrote:
> > > > NEW TEXT :  "Hello world;\nHello:\n\t\t\n\n\n\n\n\nHello2"
>
> If you are doing all of this to format the output into columns,
> Python's print() or write() will do this, and is easier as well.  Some
> more info on what you want to do will clear things up.

Hi,

That is confusing me too, so now I will try explain it more.This is
text before "translation":
Let me explain you with python code. I want to this "function" act
code indentation

>>> Short_Text="n=90; if n==90:print 'ok'"
Then now I must  write that function for detect ";" and ":", and if
that function detect ";" then it appends "\n" before ";" but
if detect ":" then it appends "\n\t\t\t\t\t\t\t\t"
>>> Short_text_after_translation="n=90;\nif n==90:\n\t\t\t\t\t\t\t\tprint 'ok"
...And now when we run this code with exec this must look like:

n=90;
if n==90:
   print 'ok'

I think this will be enough for help.

Regards,
Vedran

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


Re: wxGlade: Who knows how to drive this application?

2007-07-28 Thread Roel Schroeven
Alberto Griggio schreef:
> Hello,
> 
>> I've been trying to use wxGlade recently and I am finding it something
>> of a challenge. Is there any user who finds the user interface
>> satisfactory and the operation of the program predictable?
>>
>> If so I would love to hear from you.
> 
> Do you have some specific example of what you mean? 
> Sure, wxGlade has bugs and isn't always in sync with the latest wxPython
> changes (usually the CVS version is better in this respect), but
> suggestions on how to improve it are always welcome...

Here are some things I can think of, in no particular order:

- I have to find and select the frame I'm working on in the tree to
   display the preview of that frame. That's especially cumbersome if
   I'm playing with the properties of a widget to see their effect;
   then I find myself constantly switching between the frame and the
   widget. Solutions I can think of:
   - maybe a "Refresh"-functionality in the preview-window (via a
 right-click, F5, ctrl-R, window system menu?).
   - possibility to have multiple Properties window open.
   - a "Preview" in each Properties window; when used with a widget
 that doesn't support it, work up the tree until a widget is
 encountered that does support a preview.
   - Put a Preview-item in the right-click menu for the frame widget in
 the tree window.
- Changes in preferences don't take effect until wxGlade is restarted.
   It's workable, but it would be nice if e.g. a change in "Default
   border width for widgets" would take effect immediately.
- It's cumbersome to change the order of widgets in a sizer. Ideally I
   should be able to drag and drop the widgets into place in the tree
   window and/or the design window.
- I think drag and drop should also work to move widgets from one
   sizer to another in the tree window. If the target sizer doesn't
   have a free slot, one should be added automatically.
- Suppose I have a frame; the frame contains a sizer with a number
   slots containing widgets and/or other sizers. Now I realize I need a
   panel in the frame as a container for all sizers and widgets. I
   should have thought of that earlier of course, but I still feel
   there should be an easy way to insert it in the right place in the
   tree.
- Often the keyboard shortcuts (del, ctrl-x, ctrl-v) don't seem to
   work in the design window.
- If I select a widget in the tree, it is visually marked in the
   design window.  I think that should happen for sizers too.
- Often when you add an empty slot, you have to make the designer
   window larger, to show the new slot. I think that should happen
   automatically.
- In general, I find myself switching between the properties window,
   the tree window and the design window an awful lot of times. I'm not
   sure how to improve that.
- Spacers have the same color as panels, making them invisible in the
   design window when places on them.


-- 
If I have been able to see further, it was only because I stood
on the shoulders of giants.  -- Isaac Newton

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


Re: Wikicodia - The code snippets wiki

2007-07-28 Thread Tina I
Wikicodia Admin wrote:
> Dears,
> 
> Wikicodia is a wiki based project for sharing code snippets. We're
> collecting large number of code snippets for all code-based
> programming languages, scripts, shells and consoles. We wish you could
> help us. We're still BETA. Your suggestions, ideas and criticisms are
> very welcomed. We're waiting for you contributions. You can easily
> share and search our snippet using our Google Desktop Gadget. Share
> your Python snippets to help the world :)
> 
> http://www.wikicodia.com
> 
> Thanks
> Wikicodia Admin
> 
Just in case you are not aware of it; there already exists a fairly 
identical service called "The Rosetta Code" at http://www.rosettacode.org/

Maybe you could join forces instead? ;-)

Tina
PS: I'm not affiliated with Rosetta in any way...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: slow emails

2007-07-28 Thread John J. Lee
Gabriel Dragffy <[EMAIL PROTECTED]> writes:

> Whenever I post to this list my email invariably takes ages to show
> up - perhaps two days or so. Often times not at all. Why is this?
>
> I am subscribed to Ubuntu mail list which is also high traffic, and
> my posts show  up there within minutes.

No idea, but you could try posting through Google Groups or gmane.org
instead.  The latter is a newsfeed, so you need a newsreader program
to post using that (to find the gmane newsgroup for python-list, click
on "Lists" on the gmane.org front page, and type python-list in the
search box).


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


Re: Pythonic way for missing dict keys

2007-07-28 Thread John J. Lee
Alex Popescu <[EMAIL PROTECTED]> writes:

> Zentrader <[EMAIL PROTECTED]> wrote in news:1185041243.323915.161230
> @x40g2000prg.googlegroups.com:
>
>> On Jul 21, 7:48 am, Duncan Booth <[EMAIL PROTECTED]> wrote:
>>
>> [snip...]
>>
>> 
>>>From the 2.6 PEP #361 (looks like dict.has_key is deprecated)
>> Python 3.0 compatability: ['compatibility'-->someone should use a
>> spell-checker for 'official' releases]
>> - warnings were added for the following builtins which no
>> longer exist in 3.0:
>>  apply, callable, coerce, dict.has_key, execfile, reduce,
>> reload
>> 
>
> I see... what that document doesn't describe is the alternatives to be 
> used. And I see in that list a couple of functions that are probably used a 
> lot nowadays (callable, reduce, etc.).

callable and reduce are rarely used, at least in code I've seen.  I
would agree there will be a large number of programs that contain one
or two calls to these functions, though.  Certainly has_key will be
the most common of those listed above (but trivial to fix).  apply
will be common in old code from the time of Python 1.5.2.  execfile is
perhaps more common that callable (?) but again is really a "maybe 1
call in a big program" sort of thing.  Anybody using coerce or reload
deserves to lose ;-)


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


Re: Pythonic way for missing dict keys

2007-07-28 Thread Alex Popescu
[EMAIL PROTECTED] (John J. Lee) wrote in news:[EMAIL PROTECTED]:

> Alex Popescu <[EMAIL PROTECTED]> writes:
> 
>> Zentrader <[EMAIL PROTECTED]> wrote in
>> news:1185041243.323915.161230 @x40g2000prg.googlegroups.com:
>>
>>> On Jul 21, 7:48 am, Duncan Booth <[EMAIL PROTECTED]>
>>> wrote: 
>>>
>>> [snip...]
>>>
>>> 
From the 2.6 PEP #361 (looks like dict.has_key is deprecated)
>>> Python 3.0 compatability: ['compatibility'-->someone should use a
>>> spell-checker for 'official' releases]
>>> - warnings were added for the following builtins which no
>>> longer exist in 3.0:
>>>  apply, callable, coerce, dict.has_key, execfile,
>>>  reduce, 
>>> reload
>>> 
>>
>> I see... what that document doesn't describe is the alternatives to
>> be used. And I see in that list a couple of functions that are
>> probably used a lot nowadays (callable, reduce, etc.).
> 
> callable and reduce are rarely used, at least in code I've seen.  

I thought G would be using that function a lot. Also, what is the 
replacement of reduce? I think I remember seeing somewhere that lists 
comprehension would be (but also remember the advise that reduce will be 
quicker).

> Certainly has_key will be
> the most common of those listed above (but trivial to fix).  

dict.has_key(key) becomes key in dict (correct?)

> apply
> will be common in old code from the time of Python 1.5.2.  

I think there were some advises to not use apply.

> execfile is
> perhaps more common that callable (?) but again is really a "maybe 1
> call in a big program" sort of thing.  

What is the replacement for this one? 

tia,
./alex
--
.w( the_mindstorm )p.


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


Re: Where do they tech Python officialy ?

2007-07-28 Thread Omari Norman
On Mon, Jul 23, 2007 at 10:48:10PM -0700, Paul Rubin wrote:
 
> If you're having trouble with Python because you're new at
> programming, I can sympathize--I don't think it's the most
> beginner-friendly of languages despite the efforts in that direction
> by the designers.  

Just curious--what language would you recommend as most
beginner-friendly?

My previous programming experience was with BASIC--and I think it is
true that BASIC will, in many ways, rot your brain. I had used QBasic
and, later, a little VBA and some PHP. It took some time to unlearn some
bad things (object orientation in VBA seems to be mostly a hack, for
example, while PHP seems to be a big hack generally) but it seems to me
that Python helped me learn my first modern programming language.

> I think Python is not used in university programs very much.  Look for
> one that uses SICP (Scheme) or CTM (Mozart/Oz) or a functional
> language like Haskell, in preference to the ones that use Java (the
> Cobol of the 1990's).  With some reasonable experience in Scheme or
> Mozart or Haskell, plus a Python manual, you'll be well on your way.

I had heard of these languages, but learning them is a bit discouraging
because (Java excepted) they don't seem to get much practical use.

In college I had a programming course that used C++. Big mistake in my
view, and we didn't learn much in the way of true principles (in
retrospect it would have been nice if they had us use GCC rather than
Borland on Windows.)

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


Re: Relative-importing *

2007-07-28 Thread Ben Finney
Paul Rubin  writes:

> Steven D'Aprano <[EMAIL PROTECTED]> writes:
> > I read "from module import *" as explicitly saying "clobber the
> > current namespace with whatever names module exports". That's what
> > from does: it imports names into the current namespace. It isn't
> > some sort of easy to miss side-effect. If a name already existed,
> > it gets clobbered, just like any other import:
> 
> Seems to me that there should be a compiler warning when this
> happens.

The import happens at run-time. The compiler can't catch it.

-- 
 \  "I stayed up all night playing poker with tarot cards. I got a |
  `\   full house and four people died."  -- Steven Wright |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter -- Show Data in an Excel like Read-Only Grid

2007-07-28 Thread beginner
On Jul 27, 11:08 pm, Zentrader <[EMAIL PROTECTED]> wrote:
> On Jul 27, 2:56 pm, beginner <[EMAIL PROTECTED]> wrote:
>
> > Hi All,
>
> > I am really new to Tk and Tkinter. I googled the web but it was not
> > mentioned how to build a data grid with Tkinter.
>
> > Basically, I want to show an excel like data grid with fixed column
> > and row headers and sortable columns. But the grids can be read-only.
>
> > Can anyone give some hint on implementing this?
>
> > Thanks,
> > beginner
>
> See if tkTable will helphttp://tkinter.unpythonic.net/wiki/TkTable

Thanks for your help.

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


Re: Process Control Help

2007-07-28 Thread Hendrik van Rooyen
 <[EMAIL PROTECTED]> wrote:

> 
> 
> I'm attempting to start some process control using Python.  I've have
> quite a bit of literature on networking, and have made some tinkering
> servers and clients for different protocols HTTP, FTP, etc... But now
> it's time for the murky web of industrial protocol.  I'm looking to
> start with IO and servo controls via  Ethernet.
> 
> Questions:
> 
> Is there an existing forum on this already?
> What protocols are the most python friendly? i.e. are transparent
> enough that i can create my own python driver. (or do these drivers
> exist?)
> What ethernet accesible servo and IO industrial devices have people
> had success with?

What is it that you are trying to do? 
Some of the commercial devices come with their own software, and
you may not need python or anything else.
A lot of the industrial connectivity is still RS-485 or RS-422 and not
Ethernet based - although some of the protocols, have, I think, been ported.

If you say more, then someone can maybe help you, as there are quite a few
people on this group who seem to dabble in process control.

- Hendrik


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


Re: a simple string question

2007-07-28 Thread Steve Holden
[EMAIL PROTECTED] wrote:
> On 28 srp, 07:05, Zentrader <[EMAIL PROTECTED]> wrote:
 [EMAIL PROTECTED] wrote:
> NEW TEXT :  "Hello world;\nHello:\n\t\t\n\n\n\n\n\nHello2"
>> If you are doing all of this to format the output into columns,
>> Python's print() or write() will do this, and is easier as well.  Some
>> more info on what you want to do will clear things up.
> 
> Hi,
> 
> That is confusing me too, so now I will try explain it more.This is
> text before "translation":
> Let me explain you with python code. I want to this "function" act
> code indentation
> 
 Short_Text="n=90; if n==90:print 'ok'"
> Then now I must  write that function for detect ";" and ":", and if
> that function detect ";" then it appends "\n" before ";" but
> if detect ":" then it appends "\n\t\t\t\t\t\t\t\t"
 Short_text_after_translation="n=90;\nif n==90:\n\t\t\t\t\t\t\t\tprint 'ok"
> ...And now when we run this code with exec this must look like:
> 
> n=90;
> if n==90:
>print 'ok'
> 
> I think this will be enough for help.
> 
OK, but you don't want that many tab characters if you can the code to 
look like you show it. It's not, anyway, a good idea to use tabs to 
indent code.

I suspect what you need is to split the code on semicolons first, then 
re-form lines with colons in them. Some simple code to do this would 
look *something* like what follows. This will handle a little more than 
you wanted.

 >>> Short_Text="n=90; if n==90:print 'ok'"
 >>> compound_lines = Short_Text.split(";")
 >>> for line in compound_lines:
...   line = line.replace(":", ":\n")
...   print line
...
n=90
  if n==90:
 print 'ok'
 >>>

Note there are issues here that I haven't addressed. The first is that 
leading spaces on the second statement need to be removed, and the 
second is that this only works at the outermost level of indentation. 
For example, if you want to end up translating function definitions with 
if statements inside them correctly you will need to handle multiple 
levels of indentation. There are other problems, like semicolons and 
colons inside string constants should be ignored, but the only way to 
get over those will be to parse the program text according to some 
grammar rather than using ad-hoc methods such as the above.

I hope I have finally been of some assistance ... please reply via the 
newsgroup, not in personal email.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


interpreter in the background

2007-07-28 Thread Andrea Tomadin

Hi,
I need to use the Python interpreter as if it were a Matlab or  
Mathematica "kernel", i.e. running in the background while I use an  
interface program to send commands and get output.


Ideally, I would pipe some text "to" the interpreter (through a fifo,  
a socket...?) and got all the output back to the calling program, or  
appended to a text file, etc. Say:


# cat pythonInput.txt
1 + 1
# cat pythonInput.txt | myInterface > pythonOutput.txt
# cat pythonOutput.txt
2

or similar. Note that I need the *same* interpreter to run between  
consecutive calls of myInterface, to preserve the memory stack.  
Moreover, if I run a python script in the background, and not the  
bare interpreter, an input error could force the termination of the  
program, while I want the background "kernel" to keep up running.


At first I thought it was a trivial task, just change default input  
and output instead of tty, but I could not find out a solution!


Any help or hint is greatly appreciated!

Best,
Andrea



smime.p7s
Description: S/MIME cryptographic signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Tkinter program with a usable interpreter console

2007-07-28 Thread beginner
On Jul 27, 6:17 pm, Ivan Johansen <[EMAIL PROTECTED]> wrote:
> beginner wrote:
> > The problem is that the Tkinter program ends with a .mainloop() call
> > and it is not going to give back control to the command prompt. I feel
> > it is almost like I need to implement the python shell myself. Is
> > there any better way of doing this?
>
> Take a look at this:http://lfw.org/python/Console.py
>
> I haven't really used it myself yet, but it looks really great.
>
> Ivan Johansen

It looks interesting. Let me take a close look.

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


Re: Pythonic way for missing dict keys

2007-07-28 Thread Steve Holden
Alex Popescu wrote:
> [EMAIL PROTECTED] (John J. Lee) wrote in news:[EMAIL PROTECTED]:
> 
>> Alex Popescu <[EMAIL PROTECTED]> writes:
>>
>>> Zentrader <[EMAIL PROTECTED]> wrote in
>>> news:1185041243.323915.161230 @x40g2000prg.googlegroups.com:
>>>
 On Jul 21, 7:48 am, Duncan Booth <[EMAIL PROTECTED]>
 wrote: 

 [snip...]


 >From the 2.6 PEP #361 (looks like dict.has_key is deprecated)
 Python 3.0 compatability: ['compatibility'-->someone should use a
 spell-checker for 'official' releases]
 - warnings were added for the following builtins which no
 longer exist in 3.0:
  apply, callable, coerce, dict.has_key, execfile,
  reduce, 
 reload

>>> I see... what that document doesn't describe is the alternatives to
>>> be used. And I see in that list a couple of functions that are
>>> probably used a lot nowadays (callable, reduce, etc.).
>> callable and reduce are rarely used, at least in code I've seen.  
> 
> I thought G would be using that function a lot. Also, what is the 
> replacement of reduce? I think I remember seeing somewhere that lists 
> comprehension would be (but also remember the advise that reduce will be 
> quicker).
> 
See his latest blog entry on artima.com, where he has started a Py3k 
FAQ. He suggests that uses if reduce are almost always more readable 
when written using a for loop and an accumulator variable.

   http://www.artima.com/weblogs/viewpost.jsp?thread=211200

>> Certainly has_key will be
>> the most common of those listed above (but trivial to fix).  
> 
> dict.has_key(key) becomes key in dict (correct?)
> 
>> apply
>> will be common in old code from the time of Python 1.5.2.  
> 
> I think there were some advises to not use apply.
> 
Yup. Anyway there's a trivial translation for uses of apply.

 apply(f, *args, **kw) =>  f(*args, **kw)

The converter will almost certainly do this for you.

>> execfile is
>> perhaps more common that callable (?) but again is really a "maybe 1
>> call in a big program" sort of thing.  
> 
I don't ever remember using execfile. It has always been a blot on the 
landscape.

> What is the replacement for this one? 
> 
I'd have to guess, and will refrain from doing so.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


Re: How to programmatically insert pages into MDI.

2007-07-28 Thread fynali iladijas
On Jul 24, 4:36 pm, fynali iladijas <[EMAIL PROTECTED]> wrote:
> Hi, this query is regarding automating page insertions in Microsoft
> Document Imaging.
>
> I have two sets of MDIs generated fortnightly: Invoices and their
> corresponding Broadcast Certificates; about 150 of each.
>
> My billing application can generate one big MDI with all 150 invoices
> and another with all the Broadcast Certificates.  At the moment I take
> the pages of, say invoice #1 and insert them into a new MDI (calling
> it in001.mdi).  Then I grab the corresponding Broadcast-Certificate-
> pages of invoice #1 and insert them into in001.mdi.  I proceed to
> complete the rest the same way (quite a pain).
>
> Once done, I print each inx.mdi, setting various printer options
> such as binding direction, staple & hole-punch etc.
>
> What I would like to automate is the coupling of an Invoice & its
> corresponding Broadcast-Certificate-pages into a new appropriately
> named MDI & then printing it into one step; iterating over all the
> x until done.
>
> My billing app can be set to generate each invoice & broadcast
> certificate separately with a convenient naming convention to aid in
> program logic (for eg. inx.mdi & bcx.mdi) where x
> indicates corresponding invoice & respective broadcast certificates.
>
> All help and advice will be most appreciated.
>
> Thank you.
>
> s|a fynali

)-:

--
s|a fynali

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


Re: Where do they tech Python officialy ?

2007-07-28 Thread Neil Cerutti
On 2007-07-28, Omari Norman <[EMAIL PROTECTED]> wrote:
> On Mon, Jul 23, 2007 at 10:48:10PM -0700, Paul Rubin wrote:
>  
>> If you're having trouble with Python because you're new at
>> programming, I can sympathize--I don't think it's the most
>> beginner-friendly of languages despite the efforts in that direction
>> by the designers.  
>
> Just curious--what language would you recommend as most
> beginner-friendly?

I recommend the symbolic logo-like Scheme used in _Simply
Scheme_. It works with sentences and words polymorphically.

(first smith)
s

(first '(smith jones cooper))
smith

The books exercises revolve around writing functions like
pig-latin, reverse, palindrom?, and other word and sentence
manipulations. Real Scheme primitives are not introduced until
lots of programming ideas have been conveyed.

http://www.amazon.com/Simply-Scheme-Introducing-Computer-Science/dp/0262082810

> In college I had a programming course that used C++. Big
> mistake in my view, and we didn't learn much in the way of true
> principles (in retrospect it would have been nice if they had
> us use GCC rather than Borland on Windows.)

I can imagine a course using C++ that taught basic programming
concepts; it would teach the rudiments of using the STL to start,
and work with vectors, lists and maps. See _Accelerated C++_ for
a great example.

But most C++ courses start with the lowest level functionality of
C++, soon embroiling inexperienced programmers with the
difficulties of manual dynamic memory management. That's a big
side-show.

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


Python 2.5.1 can't find win32file?

2007-07-28 Thread samwyse
I just upgraded from 2.4.something to 2.5.1.  I get the stuff below.
I tried easy-installing pywin32; same results.  Anyone know what's
going on?

Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
(Intel)] on win32
Type "copyright", "credits" or "license()" for more information.


Personal firewall software may warn about the connection IDLE
makes to its subprocess using this computer's internal loopback
interface.  This connection is not visible on any external
interface and no data is sent to or received from the Internet.


IDLE 1.2.1   No Subprocess 
>>> import win32file
Traceback (most recent call last):
  File "", line 1, in 
import win32file
ImportError: DLL load failed: The specified module could not be found.
>>> import sys
>>> sys.path
['C:\\Documents and Settings\\dentos\\Desktop\\scripting', 'C:\
\Python25\\Lib\\idlelib', 'C:\\Python25\\lib\\site-packages\
\setuptools-0.6c6-py2.5.egg', 'C:\\Python25\\lib\\site-packages\
\sqlalchemy-0.3.10-py2.5.egg', 'C:\\Python25\\lib\\site-packages\
\pil-1.1.6-py2.5-win32.egg', 'C:\\Python25\\lib\\site-packages\
\epydoc-3.0beta1-py2.5-win32.egg', 'C:\\Python25\\lib\\site-packages\
\pywin32-210-py2.5-win32.egg', 'C:\\WINNT\\system32\\python25.zip', 'C:
\\Python25\\DLLs', 'C:\\Python25\\lib', 'C:\\Python25\\lib\\plat-win',
'C:\\Python25\\lib\\lib-tk', 'C:\\Python25', 'C:\\Python25\\lib\\site-
packages']

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


Re: Comparing Dictionaries

2007-07-28 Thread Martin P. Hellwig
Kenneth Love wrote:

> That should teach me not to change working code at the same time I am
> writing unit tests.  Even so, I realize it won't be the last time I
> do something so silly.  Yes, I know about TDD's "write the test first",
> but I'm not comfortable with the philosophy of these new fangled unit
> tests yet.
> 

I've been using python for about 3 years now, it was the first 
programming language I learned and I haven't done any other since (well 
that is if you dismiss sql and shell scripting on various platforms).

Though in my daily job I have some coding tasks, I do not see my self as 
a programmer since in my perspective a programmer is someone who can 
write good code regardless of the language. My code isn't any good, it 
is barely functional (so I really needed unit-test way of coding, for my 
own protection and not even because it gives more maintenance security 
for the project).

But the funny thing that I have seen in the development scene is that 
writing tests first and code later is a lot easier when you have a 
technical specification to base it on. A technical specification is of 
course based on a functional design. A functional design is written on 
the base of the assignment and the scope definition.

The scope and design can change in the course of the project but good 
practice is usually to do changes in another release. And that is what 
software change management and release management is for.

Still there are tons of reasons why you shouldn't follow blindly the 
best practice, since best practice is founded on theory molded around 
the most occurring reality. And the only thing that I am absolutely sure 
of is that reality differs enough from person to person and situation to 
situation, that forcing the same practice to every person/situation is a 
guarantee for wasting time and energy.

IMHO there are two extreme basic types of programmers, on the left are 
the ones that have a problem them self, solve it while happily hacking 
along the way, leaving the design part for a later stage, on the right 
are people that know beforehand on an almost bit level what a program is 
supposed to do, already have a design and aren't really that interested 
in the problem that their code should solve in the first place.

Me I am a bit schizophrenic, I move in between of them, on a hourly 
base. So for me the reality is that I have a certain 'problem' I write 
some code with the built-in IDLE mostly following functional coding 
practice (since I still have to figure out how some stuff works in 
python).

Then when I have a an idea what I am doing, I create a new project tree 
in subversion and write my technical specification (still having IDLE 
open to test some of the wild ideas that pop-up along the way).

After that I open Eclipse/PyDEV and start working on the unit-test and 
follow from there, when the code is finished I check it in and branch it 
as 0.0.1. Sleep over it and probably refactor it later on because I 
didn't like some variables names and want to add some comments in the 
code or move out some code to other classes, etc. etc.

The only problem is that I wish I was a bit more stable, because several 
times it has happend that I thought that the problem is a one-liner, so 
skipped the whole part after the figure-out-the-problem-code and used 
that what I have already written. Sometimes that works out well, but if 
it doesn't it always bites me hard.

But all these are just experiences from my side, I have no idea whether 
I am right or not, but for me it seems to work, so don't take it as 
advice (I am not really the person to take advice from) but as a little 
'story' along the way :-)

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


Re: Tkinter -- Show Data in an Excel like Read-Only Grid

2007-07-28 Thread Benjamin
On Jul 27, 4:56 pm, beginner <[EMAIL PROTECTED]> wrote:
> Hi All,
>
> I am really new to Tk and Tkinter. I googled the web but it was not
> mentioned how to build a data grid with Tkinter.
>
> Basically, I want to show an excel like data grid with fixed column
> and row headers and sortable columns. But the grids can be read-only.
>
> Can anyone give some hint on implementing this?
If tkTable isn't what you're looking for, take a look at wxPython
(http://www.wxpython.org). It's a different widget set and bit of a
higher learning curve than Tkinter, but it has hundreds of widgets for
things like this (wx.Grid).
>
> Thanks,
> beginner


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


Re: How to programmatically insert pages into MDI.

2007-07-28 Thread samwyse
On Jul 28, 7:46 am, fynali iladijas <[EMAIL PROTECTED]> wrote:
> On Jul 24, 4:36 pm, fynali iladijas <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hi, this query is regarding automating page insertions in Microsoft
> > Document Imaging.
>
[...]
>
> > All help and advice will be most appreciated.
>
> > Thank you.
>
> > s|a fynali
>
> )-:
>
> --
> s|a fynali

Perhaps you should post to a Microsoft-related newsgroup.  This is the
place for questions about the Python programming language, and the
word "Python" didn't appear anywhere in your initial question.

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


Re: 128 or 96 bit integer types?

2007-07-28 Thread [EMAIL PROTECTED]
On Jul 28, 2:28?am, Paul Rubin  wrote:
> "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:
> > has 146 digits. And that's just the begining. The above
> > actually represents a polynomial with 264 terms, the
> > exponents of which range from 0 to 492. One of those
> > polynomials can have over 5 decimal digits when
> > solved.
>
> You should use gmpy rather than python longs if you're dealing with
> numbers of that size.  Python multiplication uses a straightforward
> O(n**2) algorithm where n is the number of digits.  This is the best
> way for up to a few hundred or maybe a few thousand digits.  After
> that, it's better to use more complicated FFT-based algorithms which
> are O(n log n) despite their increased constant overhead.  Gmpy does this.

I actually do use gmpy. Great stuff. But one thing I
learned about gmpy is to never use literals inside
a loop. Otherwise the mpz coercion has to be done
every time and that kills performance.

So you would do something like

import gmpy
ONE = gmpy.mpz(1)
TWO = gmpy.mpz(2)
TWE = gmpy.mpz(3)

n = gmpy.mpz(2**177149-1)

while n > ONE:
  if n % TWO == 1
n = TWE*n + ONE
  else:
n = n/TWO

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


Re: Python 2.5.1 can't find win32file?

2007-07-28 Thread samwyse
On Jul 28, 8:16 am, samwyse <[EMAIL PROTECTED]> wrote:
> I just upgraded from 2.4.something to 2.5.1.  I get the stuff below.
> I tried easy-installing pywin32; same results.  Anyone know what's
> going on?
>

Interestingly enough, this works:

C:\Python25>path=%path%;C:\Python25\Lib\site-packages\pywin32-210-
py2.5-win32.eg
g\pywin32_system32

C:\Python25>python
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import win32file
>>>

It looks like the system search path isn't getting updated so that
PYWINTYPES25.DLL can be found when win32file.pyd is loaded.

Anyone have any ideas?

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


replacement for execfile

2007-07-28 Thread Alex Popescu
Hi all!

>From another thread (and the pointed PEP) I have found that execfile will 
not be present in Py3k. So, I am wondering what will be its replacement? 
Considering that most probably Py3k will keep eval and exec, this will 
still be possible (indeed requiring manual loading of the file string), so 
I would really appreciate some enlightning comments on this.

Background:
Basically this question is related to my learning process/working project. 
In this, I have the need to allow the final user to provide a configuration 
like script, but built using my API (and whatever other normal Python code 
they want). For this, having execfile was a nice surprise as I was able to 
automatically expose the API (so the end user doesn't need to bother about 
imports) and also easily execute it in the context I wanted.

many thanks in advance,
./alex
--
.w( the_mindstorm )p.

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


Why no maintained wrapper to Win32?

2007-07-28 Thread Gilles Ganault
Hello

It looks like the development of the PyWin32 wrapper to the
Win32 API stopped years ago, which is too bad because it means that
writing GUI apps in Python even just for Windows means adding
megabytes when using eg. wxWidgets.

How come no one too over this project, or offered another wrapper? Or
even better, why no company offered a RAD IDE so that we could write
GUI apps in Python for Windows? It's such a waste not being apple to
just send someone a small EXE.

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


Re: 128 or 96 bit integer types?

2007-07-28 Thread John DeRosa
On Sat, 28 Jul 2007 00:19:02 -0700, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:

>For example, how many ways can you put 492 marbles into
>264 ordered bins such that each bin has at least 1 marble?
>
>The answer
>
>66189415264331559482776409694993032407028709677550
>59629130019289014193777349831417543311612293951363
>4124491233746912456893016976209252459301489030

You missed that blue one in the corner...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why no maintained wrapper to Win32?

2007-07-28 Thread Martin v. Löwis
>   It looks like the development of the PyWin32 wrapper to the
> Win32 API stopped years ago, which is too bad because it means that
> writing GUI apps in Python even just for Windows means adding
> megabytes when using eg. wxWidgets.

Why does it mean that? The Win32 APIs for GUI are up-to-date; they
don't need further development. Win32 itself stopped years ago.
You can write GUI applications with PyWin32 just fine.

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


Re: Any reason why cStringIO in 2.5 behaves different from 2.4?

2007-07-28 Thread Stefan Scholl
Chris Mellon <[EMAIL PROTECTED]> wrote:
> On 7/26/07, Stefan Scholl <[EMAIL PROTECTED]> wrote:
>> Chris Mellon <[EMAIL PROTECTED]> wrote:
>> > XML is not a string. It's a specific type of bytestream. If you want
>> > to work with XML, then generate well-formed XML in the correct
>> > encoding. There's no reason you should have an XML document (as
>> > opposed to values extracted from that document) in unicode objects at
>> > all.
>>
>> The affected method in xml.sax is called parseString()
> 
> The imprecision of the english language has caused greater problems
> than this. Since you've now had everything clarified for you, and the
> imprecision is resolved, I'm sure that this won't be a problem again.


Right. I now know that xml.sax's parseString() has undocumented
implementation dependent behavior. That there are libraries (not
included with Python) which can parse Unicode strings. And that
the reason to change cStringIO's behavior is acceptable.

But the style of the answers makes me wonder if I should report
the bug in xml.sax (or its documentation) or just ignore it.


-- 
Web (en): http://www.no-spoon.de/ -*- Web (de): http://www.frell.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a simple string question

2007-07-28 Thread Zentrader
>  >>> Short_Text="n=90; if n==90:print 'ok'"
>  >>> compound_lines = Short_Text.split(";")
>  >>> for line in compound_lines:
> ...   line = line.replace(":", ":\n")
> ...   print line
> ...
> n=90
>   if n==90:
>  print 'ok'

A variation of this will work if the input file isn't too
complicated.  I found this link with a Google of "c to python".  This
will give you an idea of how difficult it can be if you take into
account every possibility when converting.  You might check the web
first, since someone has probably already done what you want.  Good
luck.
http://www.catb.org/~esr/ctopy/

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


Re: Python 2.5.1 can't find win32file?

2007-07-28 Thread Jay Loden
samwyse wrote:
> Interestingly enough, this works:
> 
> C:\Python25>path=%path%;C:\Python25\Lib\site-packages\pywin32-210-
> py2.5-win32.eg
> g\pywin32_system32
> 
> C:\Python25>python
> Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
> (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
 import win32file

> 
> It looks like the system search path isn't getting updated so that
> PYWINTYPES25.DLL can be found when win32file.pyd is loaded.
> 
> Anyone have any ideas?

If you just want to update your PATH, you can do that from My Computer -> 
Properties -> Advanced -> Environment Variables and just update PATH for your 
user (or all users if you prefer).

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


How to write a warning to my log file?

2007-07-28 Thread MarkyMarc
Hi All,

A small newbie Q.

I have made a nice log function in me program. The program writes some
data to me mysql database.
When I write to the database I get som warnings back.

Have do I write these to me log file?
I know I have to use the the warnings api. But I can not figure out
how to use it.
Is there anyone take might give me a small example.

THX all :-)

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


Re: Any reason why cStringIO in 2.5 behaves different from 2.4?

2007-07-28 Thread Stefan Behnel
Stefan Scholl wrote:
> Chris Mellon <[EMAIL PROTECTED]> wrote:
>> On 7/26/07, Stefan Scholl <[EMAIL PROTECTED]> wrote:
>>> Chris Mellon <[EMAIL PROTECTED]> wrote:
 XML is not a string. It's a specific type of bytestream. If you want
 to work with XML, then generate well-formed XML in the correct
 encoding. There's no reason you should have an XML document (as
 opposed to values extracted from that document) in unicode objects at
 all.
>>> The affected method in xml.sax is called parseString()
>> The imprecision of the english language has caused greater problems
>> than this. Since you've now had everything clarified for you, and the
>> imprecision is resolved, I'm sure that this won't be a problem again.
> 
> 
> Right. I now know that xml.sax's parseString() has undocumented
> implementation dependent behavior. That there are libraries (not
> included with Python) which can parse Unicode strings. And that
> the reason to change cStringIO's behavior is acceptable.
> 
> But the style of the answers makes me wonder if I should report
> the bug in xml.sax (or its documentation) or just ignore it.

Note that PyXML is no longer actively maintained, so it's unlikely that
reporting the bug would get you a version that raises an exception when
passing a unicode string *independent of the Python version*.

Besides, the bug has been fixed in Python 2.5 already.

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


Re: Any reason why cStringIO in 2.5 behaves different from 2.4?

2007-07-28 Thread Stefan Scholl
Stefan Behnel <[EMAIL PROTECTED]> wrote:
> Stefan Scholl wrote:
>> But the style of the answers makes me wonder if I should report
>> the bug in xml.sax (or its documentation) or just ignore it.
> 
> Note that PyXML is no longer actively maintained, so it's unlikely that

Too bad it can still be found in at least 80 % of all XML
examples. I should burn the XML chapter of the cookbook.

By the way: Thanks for the tip regarding LXML. I'll try to
remember it for the next project.


> reporting the bug would get you a version that raises an exception when
> passing a unicode string *independent of the Python version*.
> 
> Besides, the bug has been fixed in Python 2.5 already.

Just checked on a system without PyXML: xml/sax/__init__.py
defines parseString() and uses cStringIO (when available).

Python 2.5.1


-- 
Web (en): http://www.no-spoon.de/ -*- Web (de): http://www.frell.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to write a warning to my log file?

2007-07-28 Thread Jay Loden
MarkyMarc wrote:
> Hi All,
> 
> A small newbie Q.
> 
> I have made a nice log function in me program. The program writes some
> data to me mysql database.
> When I write to the database I get som warnings back.
> 
> Have do I write these to me log file?
> I know I have to use the the warnings api. But I can not figure out
> how to use it.
> Is there anyone take might give me a small example.
> 
> THX all :-)

It looks like what you need to do is override the warnings module's showwarning 
function:

showwarning(message, category, filename, lineno[, file])
Write a warning to a file. The default implementation calls 
formatwarning(message, category, filename, lineno) and writes 
the resulting string to file, which defaults to sys.stderr. 
You may replace this function with an alternative implementation 
by assigning to warnings.showwarning.


Example:

#!/usr/bin/python

import warnings

def mywarn(message, category, filename, lineno, file="warnings.log"):
handle = open(file, 'a')
handle.write(warnings.formatwarning(message, category, filename, lineno))
handle.close()

warnings.showwarning = mywarn

#now test it
warnings.warn('test warn message')

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


Re: Any reason why cStringIO in 2.5 behaves different from 2.4?

2007-07-28 Thread Chris Mellon
On 7/28/07, Stefan Scholl <[EMAIL PROTECTED]> wrote:
> Stefan Behnel <[EMAIL PROTECTED]> wrote:
> > Stefan Scholl wrote:
> >> But the style of the answers makes me wonder if I should report
> >> the bug in xml.sax (or its documentation) or just ignore it.
> >
> > Note that PyXML is no longer actively maintained, so it's unlikely that
>
> Too bad it can still be found in at least 80 % of all XML
> examples. I should burn the XML chapter of the cookbook.
>
> By the way: Thanks for the tip regarding LXML. I'll try to
> remember it for the next project.
>
>
> > reporting the bug would get you a version that raises an exception when
> > passing a unicode string *independent of the Python version*.
> >
> > Besides, the bug has been fixed in Python 2.5 already.
>
> Just checked on a system without PyXML: xml/sax/__init__.py
> defines parseString() and uses cStringIO (when available).
>
> Python 2.5.1
>

Yes, thats the fixed bug. After all this you still do not seem to be
clear on what the bug is. The bug is not that your code fails in 2.5,
it's that it worked at all in 2.4.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Where do they tech Python officialy ?

2007-07-28 Thread Paul Rubin
Omari Norman <[EMAIL PROTECTED]> writes:
> Just curious--what language would you recommend as most
> beginner-friendly?

I'm not sure what to suggest, I don't pay much attention to this
area.  Maybe Logo?

> > With some reasonable experience in Scheme or
> > Mozart or Haskell, plus a Python manual, you'll be well on your way.
> I had heard of these languages, but learning them is a bit discouraging
> because (Java excepted) they don't seem to get much practical use.

I wouldn't worry about that.  It's like saying it's discouraging to
learn in engineering class how to solve problems involving frictionless
pulleys because you can't buy those in practice.  The idea in each of
the above cases is to strip the problem to its bare essentials for
study.  Dealing with real-world complications can come later.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a simple string question

2007-07-28 Thread vedrandekovic
On 28 srp, 14:15, Steve Holden <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > On 28 srp, 07:05, Zentrader <[EMAIL PROTECTED]> wrote:
>  [EMAIL PROTECTED] wrote:
> > NEW TEXT :  "Hello world;\nHello:\n\t\t\n\n\n\n\n\nHello2"
> >> If you are doing all of this to format the output into columns,
> >> Python's print() or write() will do this, and is easier as well.  Some
> >> more info on what you want to do will clear things up.
>
> > Hi,
>
> > That is confusing me too, so now I will try explain it more.This is
> > text before "translation":
> > Let me explain you with python code. I want to this "function" act
> > code indentation
>
>  Short_Text="n=90; if n==90:print 'ok'"
> > Then now I must  write that function for detect ";" and ":", and if
> > that function detect ";" then it appends "\n" before ";" but
> > if detect ":" then it appends "\n\t\t\t\t\t\t\t\t"
>  Short_text_after_translation="n=90;\nif n==90:\n\t\t\t\t\t\t\t\tprint 
>  'ok"
> > ...And now when we run this code with exec this must look like:
>
> > n=90;
> > if n==90:
> >print 'ok'
>
> > I think this will be enough for help.
>
> OK, but you don't want that many tab characters if you can the code to
> look like you show it. It's not, anyway, a good idea to use tabs to
> indent code.
>
> I suspect what you need is to split the code on semicolons first, then
> re-form lines with colons in them. Some simple code to do this would
> look *something* like what follows. This will handle a little more than
> you wanted.
>
>  >>> Short_Text="n=90; if n==90:print 'ok'"
>  >>> compound_lines = Short_Text.split(";")
>  >>> for line in compound_lines:
> ...   line = line.replace(":", ":\n")
> ...   print line
> ...
> n=90
>   if n==90:
>  print 'ok'
>  >>>
>
> Note there are issues here that I haven't addressed. The first is that
> leading spaces on the second statement need to be removed, and the
> second is that this only works at the outermost level of indentation.
> For example, if you want to end up translating function definitions with
> if statements inside them correctly you will need to handle multiple
> levels of indentation. There are other problems, like semicolons and
> colons inside string constants should be ignored, but the only way to
> get over those will be to parse the program text according to some
> grammar rather than using ad-hoc methods such as the above.
>
> I hope I have finally been of some assistance ... please reply via the
> newsgroup, not in personal email.
>
> regards
>   Steve
> --
> Steve Holden+1 571 484 6266   +1 800 494 3119
> Holden Web LLC/Ltd  http://www.holdenweb.com
> Skype: holdenweb  http://del.icio.us/steve.holden
> --- Asciimercial --
> Get on the web: Blog, lens and tag the Internet
> Many services currently offer free registration
> --- Thank You for Reading -

Thanks Steve!
When first version of this software emerge (after competition)  you
will get your full version for free.

Once again thanks!

Regards,
Vedran


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


Re: Tkinter -- Show Data in an Excel like Read-Only Grid

2007-07-28 Thread Zentrader
If you want to only display data in a table format, try
MultiListBox.py. Just download and run for a demo.
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52266

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


Re: Any reason why cStringIO in 2.5 behaves different from 2.4?

2007-07-28 Thread Stefan Scholl
Chris Mellon <[EMAIL PROTECTED]> wrote:
> On 7/28/07, Stefan Scholl <[EMAIL PROTECTED]> wrote:
>> Just checked on a system without PyXML: xml/sax/__init__.py
>> defines parseString() and uses cStringIO (when available).
>>
>> Python 2.5.1
>>
> 
> Yes, thats the fixed bug. After all this you still do not seem to be
> clear on what the bug is. The bug is not that your code fails in 2.5,
> it's that it worked at all in 2.4.

Don't let the subject line fool you. I'm OK with cStringIO. The
thread is now about xml.sax's parseString().


-- 
Web (en): http://www.no-spoon.de/ -*- Web (de): http://www.frell.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


great new site for IT GURUS - www.itkong.com

2007-07-28 Thread itkong


Check out this site  -   WWW.ITKONG.COM.

Focused solely on the community of IT specialists, web developers,
technological experts, companies and individuals alike.

Currently we are up and running in our beta phase, taking care of
final minor bugs tightening loose screws and slowly getting the word
out about our existence.

I hope it is of some help and we welcome your feedback.

Team ITkong

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


◘►FREE Satellite TV on your PC◄◘

2007-07-28 Thread Ana James
Watch all your favorite shows on your Computer from anywhere in the
World!

Save 1000's of $$$ over many years on cable and satellite bills.

INSTANT DOWNLOAD

For More Details: http://tvonpc.cq.bz

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


this must be a stupid question ...

2007-07-28 Thread Stef Mientki
but I can;t find the answer ;-)

As searching for the '$' sign doesn't work well in the help files,
I can not find out, where is the '$' sign used for.

If I try to use it in names,
I get a compiler error,
so it probably has some special meaning.

thanks,
Stef Mientki
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Installing mod_python on mac os 10.4.7

2007-07-28 Thread 7stud
On Jul 14, 8:34 pm, Graham Dumpleton <[EMAIL PROTECTED]>
wrote:
> On Jul 15, 10:06 am, Graham Dumpleton <[EMAIL PROTECTED]>
> wrote:
>
>
>
> > On Jul 15, 2:47 am, 7stud <[EMAIL PROTECTED]> wrote:
>
> > > Themod_pythonmanual says this under section 2.1 Prerequisites:
>
> > > --
> > > In order to compilemod_pythonyou will need to have the include files
> > > for both Apache and Python, as well as the Python library installed on
> > > your system. If you installed Python and Apache from source, then you
> > > already have everything needed. However, if you are using prepackaged
> > > software (e.g. Red Hat Linux RPM, Debian, or Solaris packages from
> > > sunsite, etc) then chances are, you have just the binaries and not the
> > > sources on your system. Often, the Apache and Python include files and
> > > libraries necessary to compilemod_pythonare part of separate
> > > ``development'' package. If you are not sure whether you have all the
> > > necessary files, either compile and install Python and Apache from
> > > source, or refer to the documentation for your system on how to get
> > > the development packages.
> > > -
>
> > > I installed Apache from source using these instructions:
>
> > >http://switch.richard5.net/isp-in-a-box-v2/installing-apache-on-mac-o...
>
> > > but I used a package to install python 2.4.  The package was from
> > > here:
>
> > >http://www.pythonmac.org/packages/
>
> > > and it's a "Universal binary version of Python that runs natively on
> > > PPC and Intel systems."
>
> > > But my mac came with Python 2.3.5 pre-installed, so I wonder if I
> > > already have the necessary "include files for both Apache and Python,
> > > as well as the Python library" already installed.
>
> > Have you actually tried to installmod_python? That would be the
> > quickest way of finding out.
>
> > Because you are using an alternate Apache than the OS supplied one,
> > you will need to use the --with-apxs option to configure when building
> > Python.
>
> Whoops, --with-apxs option is to configure formod_python, not Python.
>
> > Unless you really need Python 2.4, it is easier to use the OS
> > supplied version of Python. If you must use an alternate version, use
> > the --with-python option to configure formod_pythonto tell it which
> > version. Depending on where that Python version is installed, you may
> > also have to fiddle the Apache 'envvars' file as well to get it to
> > work.
>
> > Graham

Hi,

Thanks for the response.  Sorry, I didn't respond in a timely manner.

I thought I would give your suggestion a shot and just try installing
mod_python and see what happens, so I installed mod_python 3.3.1 with
this command:

$ ./configure --with-apxs=/Library/Apache2/bin/apxs

Here is the output:


checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking for ar... ar
checking for a BSD-compatible install... /usr/bin/install -c
checking whether make sets $(MAKE)... yes
checking for main in -lm... yes
checking for an ANSI C-conforming const... yes
checking your blood pressure... a bit high, but we can proceed
configure: checking whether apxs is available...
checking for --with-apxs... /Library/Apache2/bin/apxs executable, good
checking Apache version... 2.2.4
checking for Apache libexec directory... /Library/Apache2/modules
checking for Apache include directory... -I/Library/Apache2/include
checking for --with-python... no
checking for python... /Library/Frameworks/Python.framework/Versions/
Current/bin/python
checking Python version... 2.4
checking Python install prefix... /Library/Frameworks/Python.framework/
Versions/2.4
checking checking where python libraries are installed... /Library/
Frameworks/Python.framework/Versions/2.4/lib/python2.4
checking what libraries Python was linked with... -framework
Python-ldl
checking linker flags used to link Python...
checking where Python include files are... -I/Library/Frameworks/
Python.framework/Versions/2.4/include/python2.4
checking for --with-python-src... no
checking for --with-mutex-dir... no
Using MUTEX_DIR /tmp
checking for --with-max-locks... no
Using 8 MAX_LOCKS.
checking for --with-flex... no
checking for flex... /usr/bin/flex
found /usr/bin/flex, we'll use this. Use --with-flex to specify
another.
checking flex version... configure: WARNING: Flex version 2.5.4 found.
Version 2.5.31 or greater is required.  You can generally ignore
this
warning unless you need to regenerate psp_parser.c from
psp_parse.l.
If you do need regenerate psp_parser.c, use --with-flex to specify
the
location of the correct flex version. See the README for more
information.
configure: creatin

http://MoneyCertain.com

2007-07-28 Thread qyetime
http://MoneyCertain.com

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


Re: this must be a stupid question ...

2007-07-28 Thread Neil Cerutti
On 2007-07-28, Stef Mientki <[EMAIL PROTECTED]> wrote:
> but I can;t find the answer ;-)
>
> As searching for the '$' sign doesn't work well in the help
> files, I can not find out, where is the '$' sign used for.
>
> If I try to use it in names, I get a compiler error, so it
> probably has some special meaning.

It means something in regular expressions, namely, the end of the
string/line.

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


How to stop print printing spaces?

2007-07-28 Thread CC
Hi:

I've conjured up the idea of building a hex line editor as a first real 
Python programming exercise.

To begin figuring out how to display a line of data as two-digit hex 
bytes, I created a hunk of data then printed it:

ln = '\x00\x01\xFF 456789abcdef'
for i in range(0,15):
 print '%.2X ' % ord(ln[i]),

This prints:
00  01  FF  20  34  35  36  37  38  39  61  62  63  64  65

because print adds a space after each invocation.

I only want one space, which I get if I omit the space in the format 
string above.  But this is annoying, since print is doing more than what 
I tell it to do.

What if I wanted no spaces at all?  Then I'd have to do something 
obnoxious like:

for i in range(0,15):
 print '\x08%.2X' % ord(ln[i]),

This works:

import sys
for i in range(0,15):
 sys.stdout.write( '%.2X' % ord(ln[i]) )

print


Is that the best way, to work directly on the stdout stream?


Thanks for input.




-- 
_
Christopher R. Carlen
[EMAIL PROTECTED]
SuSE 9.1 Linux 2.6.5
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Installing mod_python on mac os 10.4.7

2007-07-28 Thread 7stud
I also get this:

>>> import mod_python.psp
Traceback (most recent call last):
  File "", line 1, in ?
ImportError: No module named mod_python.psp
>>>

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


Re: Any reason why cStringIO in 2.5 behaves different from 2.4?

2007-07-28 Thread Stefan Behnel
Stefan Scholl wrote:
> Chris Mellon <[EMAIL PROTECTED]> wrote:
>> On 7/28/07, Stefan Scholl <[EMAIL PROTECTED]> wrote:
>>> Just checked on a system without PyXML: xml/sax/__init__.py
>>> defines parseString() and uses cStringIO (when available).
>>>
>>> Python 2.5.1
>>>
>> Yes, thats the fixed bug. After all this you still do not seem to be
>> clear on what the bug is. The bug is not that your code fails in 2.5,
>> it's that it worked at all in 2.4.
> 
> Don't let the subject line fool you. I'm OK with cStringIO. The
> thread is now about xml.sax's parseString().

... which works correctly with Python 2.5 and was broken before.

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


Re: Installing mod_python on mac os 10.4.7

2007-07-28 Thread 7stud
I'm using Apache 2.2.4 whose root is /Library/Apache2. My installation
of python 2.4 is here:

/Library/Frameworks/Python.framework/Versions/2.4/
/Library/Frameworks/Python.framework/Versions/Current/

"Current" is a link to the 2.4 directory:


$ ls -al /Library/Frameworks/Python.framework/Versions/
total 8
drwxr-xr-x4 root  admin  136 Mar 22 14:22 .
drwxr-xr-x6 root  admin  204 Mar 22 14:22 ..
drwxrwxr-x   12 root  admin  408 May  2 22:59 2.4
lrwxr-xr-x1 root  admin3 Apr  8 01:45 Current -> 2.4


And /usr/local/bin looks like this:


$ ls -al /usr/local/bin

lrwxr-xr-x1 root   wheel 68 Apr  8 01:45
python -> ../../../Library/Frameworks/Python.framework/Versions/2.4/
bin/python

lrwxr-xr-x1 root   wheel 71 Apr  8 01:45
python2.4 -> ../../../Library/Frameworks/Python.framework/Versions/2.4/
bin/python2.4

lrwxr-xr-x1 root   wheel 69 Apr  8 01:45
pythonw -> ../../../Library/Frameworks/Python.framework/Versions/2.4/
bin/pythonw

lrwxr-xr-x1 root   wheel 72 Apr  8 01:45
pythonw2.4 -> ../../../Library/Frameworks/Python.framework/Versions/
2.4/bin/pythonw2.4

---

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


Re: Installing mod_python on mac os 10.4.7

2007-07-28 Thread 7stud
My PATH environment variable looks like this:

PATH=/Library/Frameworks/Python.framework/Versions/Current/bin:/bin:/
sbin:/usr/bin:/usr/sbin:/usr/local/mysql/bin

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


Re: this must be a stupid question ...

2007-07-28 Thread David Wilson
On 28/07/07, Stef Mientki <[EMAIL PROTECTED]> wrote:
> but I can;t find the answer ;-)
>
> As searching for the '$' sign doesn't work well in the help files,
> I can not find out, where is the '$' sign used for.
>
> If I try to use it in names,
> I get a compiler error,
> so it probably has some special meaning.

Hi Stef,

It has no special meaning in the Python language, beyond being invalid
for use in identifiers. I believe there is a new string formatting
module which interprets it when it is part of a format string, but
nothing in the core language.

If you look at the language grammar, you can see why this is an error

http://docs.python.org/ref/identifiers.html


David.


>
> thanks,
> Stef Mientki
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to stop print printing spaces?

2007-07-28 Thread Roel Schroeven
CC schreef:
> Hi:
> 
> I've conjured up the idea of building a hex line editor as a first real 
> Python programming exercise.
> 
> To begin figuring out how to display a line of data as two-digit hex 
> bytes, I created a hunk of data then printed it:
> 
> ln = '\x00\x01\xFF 456789abcdef'
> for i in range(0,15):
>  print '%.2X ' % ord(ln[i]),
> 
> This prints:
> 00  01  FF  20  34  35  36  37  38  39  61  62  63  64  65
> 
> because print adds a space after each invocation.
> 
> I only want one space, which I get if I omit the space in the format 
> string above.  But this is annoying, since print is doing more than what 
> I tell it to do.
> 
> What if I wanted no spaces at all?  Then I'd have to do something 
> obnoxious like:
> 
> for i in range(0,15):
>  print '\x08%.2X' % ord(ln[i]),
> 
> This works:
> 
> import sys
> for i in range(0,15):
>  sys.stdout.write( '%.2X' % ord(ln[i]) )
> 
> print
> 
> 
> Is that the best way, to work directly on the stdout stream?

It's not a bad idea: print is mostly designed to be used in interactive 
mode and for quick and dirty logging; not really for normal program 
output (though I often use it for that purpose).

There is another way: construct the full output string before printing 
it. You can do that efficiently using a list comprehension and the 
string method join():

 >>> print ''.join(['%.2X' % ord(c) for c in ln])
0001FF20343536373839616263646566

In Python 2.4 and higher, you can use a generator expression instead of 
a list comprehension:

 >>> print ''.join('%.2X' % ord(c) for c in ln)
0001FF20343536373839616263646566

BTW, in your examples it's more pythonic not to use range with an index 
variable in the for-loop; you can loop directly over the contents of ln 
like this:

import sys
for c in ln:
 sys.stdout.write('%.2X' % ord(c))
print



-- 
If I have been able to see further, it was only because I stood
on the shoulders of giants.  -- Isaac Newton

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


Re: this must be a stupid question ...

2007-07-28 Thread Gary Herron
Stef Mientki wrote:
> but I can;t find the answer ;-)
>
> As searching for the '$' sign doesn't work well in the help files,
> I can not find out, where is the '$' sign used for.
>
> If I try to use it in names,
> I get a compiler error,
> so it probably has some special meaning.
>
> thanks,
> Stef Mientki
>   
The $ is not used in any Python syntax.  Neither in  variable names nor 
any syntactical construct.

Of course, like any character, it can be used in strings.  (And some 
packages, like re, will make special use of a $ in a string.)

Gary Herron

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


Events: The Python Way

2007-07-28 Thread Gianmaria
Hi,
i'm a .net programmer and i'm learnig python, so this question can be very
stupid or easy for python programmers. I've a doubt about events here is
what:

in c# for example i can write a delegate and an event in this way...

public delegate SomethingChangedHandler(string message);
public event SomethingChangedHandler SomethingChanged;

and later in the code fire this event in this way...

if(SomethingChanged != null)
{
SomethingChanged("Nothing important");
}

and the subscription of this event of other objects can be easy as

eventGeneratorObject.SomethingChanged += new
SomethingChangedHandler(aFunctionto_takecareof_it);

and even the handlig of the event is aesy...

void aFunctionto_takecareof_it(string msg)
{

}


now the question is.. how can i do the same using Python? Every help is
appreciated





Regards,
Gianmaria

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


Crunchy security advisory

2007-07-28 Thread André
A security hole has been uncovered in Crunchy (version 0.9.1.1 and
earlier).

Anyone using Crunchy to browse web tutorials should only visit sites
that are trustworthy.

We are working hard at fixing the hole; a new release addressing the
problems that have
been found should be forthcoming shortly.

André


-

The security problem is as follows:

In theory, a web page could contain some javascript code (or link to
such code) that would bypass Crunchy's filter to be executed by the
browser.  If that is the case, the javascript code could be designed
to send some
Python code directly to the Python backend (i.e. without the Crunchy
user pressing a button, or having the chance to view the code to be
executed) so that it is executed.   Such code could result in deleting
the entire files or installing some virus on the user's machine.

At the moment, the risk is pretty low.  Crunchy already removes all
obvious (and most non-obvious) javascript code, links to such code,
etc.  The holes found require the use of some uncommon combination of
html and css code, with a particular knowledge of Firefox.

(Note that browsers other than Firefox are likely to be even more
vulnerable).

Furthermore, Crunchy is not that well known that it is likely to
be a target by a cracker that would 1) write a "tutorial" interesting
enough to lure current Crunchy users (who, at this point, are
likely to include only advanced Python users) and 2) write some fairly
involved
javascript code to bypass the second security layer (where the
commands enabling communication between the browser and crunchy are
made up of random string generated uniquely at each new Crunchy
session).

If anyone is interested in security issues related to Crunchy, feel
free to
contact me directly.

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


Re: Why no maintained wrapper to Win32?

2007-07-28 Thread Gilles Ganault
On Sat, 28 Jul 2007 18:05:34 +0200, "Martin v. Löwis"
<[EMAIL PROTECTED]> wrote:
>Why does it mean that? The Win32 APIs for GUI are up-to-date; they
>don't need further development. Win32 itself stopped years ago.
>You can write GUI applications with PyWin32 just fine.

Besides the total lack of documentation, you mean that nothing was
added to the Win32 API since PyWin32 was last updated?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Events: The Python Way

2007-07-28 Thread David Wilson
Hi there,

Python has no built-in way of doing this. You may consider writing
your own class if you like this pattern (I personally do):

class Event(object):
def __init__(self):
self.subscribers = set()

def __iadd__(self, subscriber):
self.subscribers.add(subscriber)
return self

def __isub__(self, subscriber):
self.subscribers.pop(subscriber)
return self

def __call__(self, *args, **kwargs):
for subscriber in self.subscribers:
subscriber(*args, **kwargs)


def HandleFoo(strng):
print "HandleFoo:", strng

OnFoo = Event()
OnFoo += HandleFoo

OnFoo("Test.")


On 29/07/07, Gianmaria <[EMAIL PROTECTED]> wrote:
> Hi,
> i'm a .net programmer and i'm learnig python, so this question can be very
> stupid or easy for python programmers. I've a doubt about events here is
> what:
>
> in c# for example i can write a delegate and an event in this way...
>
> public delegate SomethingChangedHandler(string message);
> public event SomethingChangedHandler SomethingChanged;
>
> and later in the code fire this event in this way...
>
> if(SomethingChanged != null)
> {
> SomethingChanged("Nothing important");
> }
>
> and the subscription of this event of other objects can be easy as
>
> eventGeneratorObject.SomethingChanged += new
> SomethingChangedHandler(aFunctionto_takecareof_it);
>
> and even the handlig of the event is aesy...
>
> void aFunctionto_takecareof_it(string msg)
> {
>
> }
>
>
> now the question is.. how can i do the same using Python? Every help is
> appreciated
>
>
>
>
>
> Regards,
> Gianmaria
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Any reason why cStringIO in 2.5 behaves different from 2.4?

2007-07-28 Thread Michael L Torrie
Stefan Scholl wrote:
> Don't let the subject line fool you. I'm OK with cStringIO. The
> thread is now about xml.sax's parseString().

Giving you the benefit of the doubt here, despite the fact that Stefan
Behnel has state this over and over again and you just haven't listened.

xml.sax's use of parseString() is exactly correct.  xml.sax should
*never* parse python unicode strings as by definition XML must be
encoded as a *byte stream*, which is what a python string is.

A python /unicode/ string could be held internally in any number of
ways, 2, 3, 4, or even 8 bytes per character if the implementation
demanded it (a bit contrived, I admit).  Since the xml parser is only
ever intended to parse *XML*, why should it ever know what to do with
python unicode strings, which could be stored any number of ways, making
byte-parsing impossible.

So your code is faulty in its assumptions, not xml.sax.

> 
> 

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


Test-driven design (was: Comparing Dictionaries)

2007-07-28 Thread Ben Finney
"Martin P. Hellwig" <[EMAIL PROTECTED]> writes:

> But the funny thing that I have seen in the development scene is
> that writing tests first and code later is a lot easier when you
> have a technical specification to base it on. A technical
> specification is of course based on a functional design. A
> functional design is written on the base of the assignment and the
> scope definition.

This is, to my mind, one of the greatest advantages of test-driven
development: if you're not clear on how the code will be used, you
can't write the test, and (by the discipline of TDD) you can't write
the code either.

Therefore, you're forced to confront the fuzziness of your design
*before* it causes you to write meaningless code – but only to the
extent necessary to write the code at hand. If understanding the code
you're about to write requires some more extensive design thinking,
that's all to the good; but if you have enough understanding to write
a test for the small area you're on, you don't need to do a huge
amount of design. The stark confrontation of needing to write the unit
test up front shows you the difference, at exactly the time it's most
useful.

There are many who call TDD "test-driven design" for this same reason.

-- 
 \ "A child of five could understand this. Fetch me a child of |
  `\   five."  -- Groucho Marx |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Any reason why cStringIO in 2.5 behaves different from 2.4?

2007-07-28 Thread Stefan Scholl
Michael L Torrie <[EMAIL PROTECTED]> wrote:
> Stefan Scholl wrote:
>> Don't let the subject line fool you. I'm OK with cStringIO. The
>> thread is now about xml.sax's parseString().
> 
> Giving you the benefit of the doubt here, despite the fact that Stefan
> Behnel has state this over and over again and you just haven't listened.

Speaking of over and over again ...


> xml.sax's use of parseString() is exactly correct.  xml.sax should
> *never* parse python unicode strings as by definition XML must be
> encoded as a *byte stream*, which is what a python string is.

I don't care about the definition of XML at this point of the
program. http://docs.python.org/lib/module-xml.sax.html calls
parseString() a convenience function.

This is Python. Python has a class named unicode. Its literals
look like strings. The base class is basestring.

xml.sax belongs to Python. Batteries included. parseString() is
in Python.

It's not parseString() that tells me something is wrong with the
parameter. It's cStringIO, which is used on platforms where it is
available. On other platforms no exceptions are thrown, because
then StringIO is used, which behaves in Python 2.4 and Python 2.5
the same, regarding unicode strings.

Other libraries like LXML (not included) parse unicode strings.


And these are two additional lines in my code now:

if isinstance(string, unicode):
string = string.encode("utf-8")


> A python /unicode/ string could be held internally in any number of
> ways, 2, 3, 4, or even 8 bytes per character if the implementation
> demanded it (a bit contrived, I admit).  Since the xml parser is only
> ever intended to parse *XML*, why should it ever know what to do with
> python unicode strings, which could be stored any number of ways, making
> byte-parsing impossible.

xml.sax is no external parser. The program doesn't have to
communicate with the outside world at this point of execution.
The Python programm calls a Python function of a Python class and
passes a Python unicode string as parameter.

XML parsers only have to support few encodings. But nobody has
something against it when they support more than that.

A Python convenience function isn't broken when it allows Python
unicode strings.


The behavior of cStringIO (the original topic of this thread) is
correct and documented. parseString() uses the old idiom where
cStringIO is imported as StringIO, when available. Despite the
fact that they behave differently.

In my personal opinion: If parseString() shouldn't support
unicode strings, then it should check for it and throw a
meaningful exception.

At the moment the code just looks as if someone has overlooked
the fact that unicode strings (with non-ascii characters in it)
cause a problem. Missing test?


> So your code is faulty in its assumptions, not xml.sax.

As I said in the conclusion, a few messages before: Undocumented,
implementation dependent behavior.

Or maybe just a bug, considering the following on
http://docs.python.org/lib/module-xml.sax.html

A typical SAX application uses three kinds of objects:
readers, handlers and input sources. ``Reader'' in this
context is another term for parser, i.e. some piece of
code that reads the bytes or characters from the input
source, and produces a sequence of events.


Bytes _or_ characters.


-- 
Web (en): http://www.no-spoon.de/ -*- Web (de): http://www.frell.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Memory utilization (linux v. openbsd)

2007-07-28 Thread nazgul
Hi all,

I have an app that runs on multiple boxes.  On my slackware box, running 
Python 2.5.1, top shows this:

Mem:   1002736k total,   453268k used,   549468k free,31392k buffers
Swap:  2097136k total,0k used,  2097136k free,   136876k cached

  PID USER  PR  NI  VIRT  RES  SHR S %CPU %MEMTIME+  COMMAND
 2741 dnm   16   0  267m 261m 2676 S 99.3 26.7  14:54.62 python

The same app running on OpenBSD 4.1 (but on Python 2.5P3 from ports) 
yields this (actually, I have 2 copies running on a dualcore box):

Memory: Real: 1130M/1989M act/tot  Free: 792K  Swap: 337M/2048M used/tot

  PID USERNAME PRI NICE  SIZE   RES STATEWAIT TIMECPU 
COMMAND
12380 dnm   640  926M  436M run/0-   22:22 73.58% 
python2.5
22956 dnm   640  933M  695M onproc/0 -   22:46 68.55% 
python2.5

RES was has over 800M earlier in the job.

My problem is that the two process under OpenBSD are going to fail with 
a MemoryError becaause the size just keeps getting larger and larger.  
ulimit -d is 1G for each process.

Any idea why the memory utilization is so much higher under OpenBSD?

What I also find interesting is that the OpenBSD box seems to grind to a 
halt (that's probably due to swapping since there's 500M of swap space 
in use).  Those processes should both be over 90% since they are CPU 
bound, and they are that way at the start of the run.  Gradually, the 
system % creeps up as does idle, but there's no reason for them to be 
idle.  It's a CPU bound process.  (While I'm typing this top is showing 
cpu rats of 63% and 41% for the two jobs).

TIA,
nazgul
-- 
http://mail.python.org/mailman/listinfo/python-list


Compiling 2.5.1 on OpenBSD 4.1

2007-07-28 Thread nazgul
Hi all,

In my prev post, I indicated I was using 2.5.1 on one box and 2.5p3 on the 
OpenBSD box.  I'm trying to build 2.5.1 on OpenBSD and I get this:

Modules/posixmodule.c:5701: error: `lstat' undeclared (first use in this 
function)

I browsed the source and don't understand why I'm getting it. I'm not a 
configure expert, but I did figure out that pyconfig.h has these set:

#define HAVE_LSTAT 1
#define HAVE_SYS_STAT_H 1
#define HAVE_SYS_TYPES_H 1

and that posixmodule.c includes sys/stat.h, sys/types.h (per the lstat 
manpage) as well as declaring lstat outright.

I'm stumped.  Any suggestions?  ./configure was run with no options.

TIA,
nazgul
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Memory utilization (linux v. openbsd)

2007-07-28 Thread Michael Torrie
[EMAIL PROTECTED] wrote:
> My problem is that the two process under OpenBSD are going to fail with 
> a MemoryError becaause the size just keeps getting larger and larger.  
> ulimit -d is 1G for each process.

The problem is that you can't get accurate memory use readings from top.

The reality is that your python program is probably using the same 
amount of memory on both platforms (in and of itself), but due to the 
way the memory management OS system works, the usage is being reported 
differently on BSD.  Basically you're seeing the memory footprint of the 
python executable, it's data (your program) and also all of the shared 
libraries that python is linked to.  Of course the shared libraries are 
shared, so it's not like python's using all this memory just itself.

> 
> Any idea why the memory utilization is so much higher under OpenBSD?
> 
> What I also find interesting is that the OpenBSD box seems to grind to a 
> halt (that's probably due to swapping since there's 500M of swap space 
> in use).  Those processes should both be over 90% since they are CPU 
> bound, and they are that way at the start of the run.  Gradually, the 
> system % creeps up as does idle, but there's no reason for them to be 
> idle.  It's a CPU bound process.  (While I'm typing this top is showing 
> cpu rats of 63% and 41% for the two jobs).

I can't answer your questions or solve your problem.  But I just wanted 
to point out that the problem is likely somewhere besides python itself. 
  Maybe there are settings in the OS.  Who knows.  My guess is the 
difference in overall memory footprint is due to differences in the C 
library and its dependencies.  You probably would want to bring this 
issue up on the OpenBSD lists as it's clear that your BSD machine is 
having problems generally (trashing to death).  This doesn't appear to 
be a python problem.

> 
> TIA,
> nazgul

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


Re: this must be a stupid question ...

2007-07-28 Thread Ben Finney
Stef Mientki <[EMAIL PROTECTED]> writes:

> but I can;t find the answer ;-)

It's not a stupid question, but it is a stupid Subject field. That's
easy to fix though: in future, please write a Subject field that
actually tells us what the message is about.

> If I try to use [the $ symbol] in names, I get a compiler error,

Yes, because names have a specific set of characters that must be
used: A-Z, a-z, 0-9, and the underscore.

> so it probably has some special meaning.

That doesn't follow; it just means that character isn't allowed for
names. This does have the advantage that, if necessary, it can be used
in future (the '@' symbol was recently added to the language, though
it didn't have a meaning before).

-- 
 \  "The future always arrives too fast, and in the wrong order."  |
  `\  -- Alvin Toffler |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to stop print printing spaces?

2007-07-28 Thread CC
Roel Schroeven wrote:
> CC schreef:
>> ln = '\x00\x01\xFF 456789abcdef'
>> # This works:
>> import sys
>> for i in range(0,15):
>>  sys.stdout.write( '%.2X' % ord(ln[i]) )
>> print
>> Is that the best way, to work directly on the stdout stream?
> 
> It's not a bad idea: print is mostly designed to be used in interactive 
> mode and for quick and dirty logging; not really for normal program 
> output (though I often use it for that purpose).
> 
> There is another way: construct the full output string before printing 
> it. You can do that efficiently using a list comprehension and the 
> string method join():
> 
>  >>> print ''.join(['%.2X' % ord(c) for c in ln])
> 0001FF20343536373839616263646566

Oh yeah, that's right!

> In Python 2.4 and higher, you can use a generator expression instead of 
> a list comprehension:
> 
>  >>> print ''.join('%.2X' % ord(c) for c in ln)
> 0001FF20343536373839616263646566

Hmm.  I'm at 2.3 :-(

> BTW, in your examples it's more pythonic not to use range with an index 
> variable in the for-loop; you can loop directly over the contents of ln 
> like this:
> 
> import sys
> for c in ln:
> sys.stdout.write('%.2X' % ord(c))
> print


Ah yes, duh!  I played with this means of iterating over items in a 
sequence the other day while studying the tutorial, but it sinks in 
slowly for a C programmer.

That's why I posted my silly code.  I'll probably do that a lot until I 
get used to this pythonic business.

Thanks for the input!




-- 
_
Christopher R. Carlen
[EMAIL PROTECTED]
SuSE 9.1 Linux 2.6.5
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OOP in Python book?

2007-07-28 Thread Dick Moores
At 01:27 PM 7/28/2007, Dennis Lee Bieber wrote:
>On Fri, 27 Jul 2007 16:27:57 -0700, Dick Moores <[EMAIL PROTECTED]>
>declaimed the following in comp.lang.python:
>
>
> > Well, the publisher is Prentice Hall, "The world's leading
> > educational publisher". Textbooks are typically expensive.
> >
>
> Yeah... But at that price it should have hard-covers!

Should have, but look at this popular Cultural Anthropology text 
(paperback): . List price is $120.95 USD. 
(BTW I just bought the 6th edition online for about $10.)

Then there's Calculus: Single Variable (Paperback) 
 List price $123.95 USD.

And so it goes.

Dick


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


Re: replacement for execfile

2007-07-28 Thread Steven D'Aprano
On Sat, 28 Jul 2007 15:17:56 +, Alex Popescu wrote:

> Hi all!
> 
> From another thread (and the pointed PEP) I have found that execfile
> will not be present in Py3k. So, I am wondering what will be its
> replacement? Considering that most probably Py3k will keep eval and
> exec, this will still be possible (indeed requiring manual loading of
> the file string), so I would really appreciate some enlightning comments
> on this.

(1) Don't use eval, exec or execfile.

(2) If you're an expert, don't use eval, exec or execfile.

(3) If you're an expert, and are fully aware of the security risks, don't
use eval, exec or execfile.

(4) If you're an expert, and are fully aware of the security risks, and
have a task that can only be solved by using eval, exec or execfile, find
another solution.

(5) If there really is no other solution, you haven't looked hard enough.

(6) If you've looked REALLY hard, and can't find another solution, AND
you're an expert and are fully aware of the security risks, THEN you can
think about using eval, exec or execfile.


> Background:
> Basically this question is related to my learning process/working
> project. In this, I have the need to allow the final user to provide a
> configuration like script, but built using my API (and whatever other
> normal Python code they want). 

I hope this is running on their own computer, not yours.

If they're running it on a multi-user system, I hope they don't care about
security, because they probably don't have any now.

> For this, having execfile was a nice surprise 

Oh yes, I bet it was, in more ways than one.

> as I was able to automatically expose the API (so the end user
> doesn't need to bother about imports) and also easily execute it in the
> context I wanted.

Let's see that I understand you... you're expecting the users to write
working Python code, but you think "import module" is too hard for them?

Anyway, with all the disclaimers above, execfile is trivial:


def execfile_(filename, globals_=None, locals_=None):
if globals_ is None:
globals_ = globals()
if locals_ is None:
locals_ = globals_
text = file(filename, 'r').read()
exec text in globals_, locals_




-- 
Steven.

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


Re: Pythonic way for missing dict keys

2007-07-28 Thread Steven D'Aprano
On Sat, 28 Jul 2007 11:52:48 +, Alex Popescu wrote:

> [EMAIL PROTECTED] (John J. Lee) wrote in news:[EMAIL PROTECTED]:
> 
>> Alex Popescu <[EMAIL PROTECTED]> writes:
>> 
>>> Zentrader <[EMAIL PROTECTED]> wrote in
>>> news:1185041243.323915.161230 @x40g2000prg.googlegroups.com:
>>>
 On Jul 21, 7:48 am, Duncan Booth <[EMAIL PROTECTED]>
 wrote: 

 [snip...]

 
>From the 2.6 PEP #361 (looks like dict.has_key is deprecated)
 Python 3.0 compatability: ['compatibility'-->someone should use a
 spell-checker for 'official' releases]
 - warnings were added for the following builtins which no
 longer exist in 3.0:
  apply, callable, coerce, dict.has_key, execfile,
  reduce, 
 reload
 
>>>
>>> I see... what that document doesn't describe is the alternatives to
>>> be used. And I see in that list a couple of functions that are
>>> probably used a lot nowadays (callable, reduce, etc.).
>> 
>> callable and reduce are rarely used, at least in code I've seen.  
> 
> I thought G would be using that function a lot. 

Who or what is G? Guido?

And which of the two functions mentioned is "that function"? callable()?


Instead of doing:


if callable(function): function()

you should do:

try:
function()
except TypeError:
pass


That should work for most uses of callable(), but isn't quite the same.
(What if function() has side-effects, or is expensive, and you want to
determine if it is callable, but not actually call it _now_?)


> Also, what is the replacement of reduce? I think I remember seeing
> somewhere that lists comprehension would be (but also remember the
> advise that reduce will be quicker).

No, a list comprehension isn't equivalent to reduce(). There is no
replacement for reduce().

Guido has essentially done the functional equivalent of deciding that
because he personally doesn't like for loops, they can and should be
written out as:

counter = 0
while counter < len(sequence):
item = sequence[counter]
do_something_with_item
counter += 1

because it is "easier to read" than a for loop.

And yes, if you think my example is extreme because nobody would be that
stupid, that's the point: removing reduce() _is_ that stupid (and it is
not often I say that about a language design decision by Guido!). Python
can, and probably will, get away with it only because reducing an iterable
to a single value is an uncommon operation, and the most common uses of it
(summing a sequence, finding the minimum and maximum) already have
workable replacements.

It's especially stupid because map() and filter(), both of which do have
simple, easy to understand, completely functional replacements, are going
to stay. reduce() doesn't, and it is going. That's nuts.

It's a shame really. Oh well, maybe it will sneak back in via a functional
module, or itertools, or something. What a waste, what a waste.


>> Certainly has_key will be
>> the most common of those listed above (but trivial to fix).
> 
> dict.has_key(key) becomes key in dict (correct?)

Yes.



>> apply
>> will be common in old code from the time of Python 1.5.2.
> 
> I think there were some advises to not use apply.


help(apply) already tells you how to replace apply():

Deprecated since release 2.3. Instead, use the extended call syntax:
function(*args, **keywords).



>> execfile is
>> perhaps more common that callable (?) but again is really a "maybe 1
>> call in a big program" sort of thing.
> 
> What is the replacement for this one?


Slurp the file into a string, execute the string.


But the thing that makes my brain melt is reload(). No, reload() probably
isn't good enough to use in production code, but for interactive use it is
Good Enough. I'm boggled that it is going away!



-- 
Steven.

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


Split a string based on change of character

2007-07-28 Thread Andrew Savige
Python beginner here.

For a string 'ABBBCC', I want to produce a list ['A', 'BBB', 'CC'].
That is, break the string into pieces based on change of character.
What's the best way to do this in Python?

Using Python 2.5.1, I tried:

import re
s = re.split(r'(?<=(.))(?!\1)', 'ABBBCC')
for e in s: print e

but was surprised when it printed:

ABBBCC

I expected something like:

A
A
BBB
B
CC
C

(the extra fields because of the capturing parens).

Thanks,
/-\



  

Yahoo!7 Mail has just got even bigger and better with unlimited storage on all 
webmail accounts. 
http://au.docs.yahoo.com/mail/unlimitedstorage.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Compiling 2.5.1 on OpenBSD 4.1

2007-07-28 Thread Martin v. Löwis
> I'm stumped.  Any suggestions?

You will have to find the true declaration of lstat - reading
man pages or checking that everything "looks right" won't help.

So where is lstat declared? Is it declared at all, and if so,
is that declaration conditional perhaps?

Produce a preprocessor output (posixmodule.i), by adding
-fsave-temps to the compiler line compiling posixmodule.c
(copy the line from the make output into a shell, and add
this command line); then inspect that output to see whether
lstat has been declared.

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


Re: Why no maintained wrapper to Win32?

2007-07-28 Thread Martin v. Löwis
>> Why does it mean that? The Win32 APIs for GUI are up-to-date; they
>> don't need further development. Win32 itself stopped years ago.
>> You can write GUI applications with PyWin32 just fine.
> 
> Besides the total lack of documentation, you mean that nothing was
> added to the Win32 API since PyWin32 was last updated?

Why do you say that the Win32 API lacks documentation? I find the
documentation at msdn.microsoft.com to be quite useful.

Yes, there haven't been many changes to Win32 in recent years (there
haven't been many system releases in the first place). Most additions
did not concern GUI programming, which is what you were after, and
even those that are recent additions are rather rarely needed, so
you likely won't miss them. If you do, ask Mark Hammond to add them.

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


Re: Split a string based on change of character

2007-07-28 Thread [EMAIL PROTECTED]
On Jul 28, 9:46 pm, Andrew Savige <[EMAIL PROTECTED]> wrote:
> Python beginner here.
>
> For a string 'ABBBCC', I want to produce a list ['A', 'BBB', 'CC'].
> That is, break the string into pieces based on change of character.
> What's the best way to do this in Python?
>
> Using Python 2.5.1, I tried:
>
> import re
> s = re.split(r'(?<=(.))(?!\1)', 'ABBBCC')
> for e in s: print e
>
> but was surprised when it printed:
>
> ABBBCC
>
> I expected something like:
>
> A
> A
> BBB
> B
> CC
> C
>
> (the extra fields because of the capturing parens).


Using itertools:

import itertools

s = 'ABBBCC'
print [''.join(grp) for key, grp in itertools.groupby(s)]


Using re:

import re

pat = re.compile(r'((\w)\2*)')
print [t[0] for t in re.findall(pat, s)]


By the way, your pattern seems to work in perl:

$ perl -le '$, = " "; print split(/(?<=(.))(?!\1)/, "ABBBCC");'
A A BBB B CC C

Was that the type of regular expressions you were expecting?

--
Hope this helps,
Steven


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


Re: Events: The Python Way

2007-07-28 Thread Antti Rasinen

On 2007-07-29, at 02:34, David Wilson wrote:

> Hi there,
>
> Python has no built-in way of doing this. You may consider writing
> your own class if you like this pattern (I personally do):
>
> class Event(object):
> def __init__(self):
> self.subscribers = set()

...

> def __isub__(self, subscriber):
> self.subscribers.pop(subscriber)
> return self

A slight typo there. For sets s.pop() returns an arbitrary element  
and s.remove(x) or s.discard(x) removes the element x from the set s.  
For the OP: remove raises an exception if x is not in the set,  
discard does not.

-- 
[ [EMAIL PROTECTED] <*> Antti Rasinen ]

"The music of rebellion makes you wanna rage
But it's made by millionaires who are nearly twice your age"


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


Re: Split a string based on change of character

2007-07-28 Thread Andrew Savige
--- "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> Using itertools:
> 
> import itertools
> 
> s = 'ABBBCC'
> print [''.join(grp) for key, grp in itertools.groupby(s)]

Nice.

> Using re:
> 
> import re
> 
> pat = re.compile(r'((\w)\2*)')
> print [t[0] for t in re.findall(pat, s)]

Also nice. Especially nice that it only returns the outer parens. :-)

> By the way, your pattern seems to work in perl:
> 
> $ perl -le '$, = " "; print split(/(?<=(.))(?!\1)/, "ABBBCC");'
> A A BBB B CC C
> 
> Was that the type of regular expressions you were expecting?

Yes. Here's a simpler example without any backreferences:

s = re.split(r'(?<=\d)(?=\D)', '1B2D3')

That works in Perl but not in Python.
Is it that "chaining" assertions together like this is not supported in Python
re?
Or is that the case only in the split function?

Thanks,
/-\



  

Yahoo!7 Mail has just got even bigger and better with unlimited storage on all 
webmail accounts. 
http://au.docs.yahoo.com/mail/unlimitedstorage.html
-- 
http://mail.python.org/mailman/listinfo/python-list