timelib 0.2 - parse english textual date descriptions

2009-06-25 Thread Ralf Schmitt
Hi all,

timelib is a short wrapper around php's internal timelib module.

It currently only provides two functions for parsing textual date descriptions:

timelib.strtodatetime:

 timelib.strtodatetime('today')
datetime.datetime(2009, 6, 23, 0, 0)
 timelib.strtodatetime('today')
datetime.datetime(2009, 6, 23, 0, 0)
 timelib.strtodatetime('next friday')
datetime.datetime(2009, 6, 26, 0, 0)
 timelib.strtodatetime('29 feb 2008 -108 years')
datetime.datetime(1900, 3, 1, 0, 0)

timelib.strtotime:

 import time, timelib
 time.ctime(timelib.strtotime(now))
'Tue Jun 23 15:17:32 2009'
 time.ctime(timelib.strtotime(4 hours ago))
'Tue Jun 23 11:17:38 2009'
 time.ctime(timelib.strtotime(20080229 -1 year))
'Thu Mar  1 01:00:00 2007'




timelib is available via PyPI:
http://pypi.python.org/pypi/timelib/

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

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


mailog - a minimalstic blog engine

2009-06-25 Thread simon oberhammer
serving static html (enhanced with ajax) created by a python daemon
fetching markdowned emails via imap.

* post and comment per email
  o youremail+p...@example.com
  o youremail+comm...@example.com
* no database, no dependencies (only python, which you should
already have)
* use markdown to format your posts
* attach images you want to embed in your post
* your emails go through the mail server, therefore:
  o you get free spam protection
  o automatic backups (in imap mailbox)

MIT license. stable.

more infos http://code.google.com/p/mailog/
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


ANN: pycairo release 1.8.6 now available

2009-06-25 Thread Steve
Pycairo is a set of Python bindings for the multi-platform 2D graphics
library cairo.
 http://cairographics.org
 http://cairographics.org/pycairo

A new pycairo release 1.8.6 is now available from:

http://cairographics.org/releases/pycairo-1.8.6.tar.gz
http://cairographics.org/releases/pycairo-1.8.6.tar.gz.md5

d10a68f88da0a6a02864bf8f0c25ee4d  pycairo-1.8.6.tar.gz

Overview of changes from pycairo 1.8.4 to pycairo 1.8.6
===
General Changes:
Pycairo 1.8.6 requires cairo 1.8.6 (or later)

Bug Fixes:
ImageSurface.create_from_png _read_func fix
ToyFontFace type fix
19221: restore cairo.Matrix '*' operator to the way it originally
worked.

Other Changes:
Documentation completed.


Steve

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

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


Re: [SPAM] It's ...

2009-06-25 Thread Angus Rodgers
Someone has gently directed me to the Tutor mailing list:
http://mail.python.org/mailman/listinfo/tutor
which I hadn't known about.  I've joined, and will try to
confine my initial blundering experiments to there.  Sorry
about the spam spam spam spam, lovely spam, wonderful spam!
-- 
Angus Rodgers
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter: get filename of askopenfilename

2009-06-25 Thread Sean McIlroy

i think what he means is to put the global declaration inside the
function that assigns to filename:

def open_file_dialog():
global filename
filename = tkFileDialog.askopenfilename(filetypes=
[(allfiles,*)])

as it was, the function was creating a new variable called filename
and assigning to THAT (and then doing absolutely nothing with it).
with the above modification, the function understands that filename
refers to the global variable of that name, and that variable's value
does indeed get printed, but since the print statement comes before
root.mainloop() -- hence before the button gets pressed -- filename
gets printed before the function has assigned to it. this fact becomes
apparent if you initialize the variable with filename='blank' (for
example). putting the print statement after root.mainloop() doesn't
work either, since root.mainloop() keeps control from getting to the
print statement. the effect i think you want can be gotten from
putting the print statement into the function as well, so what you end
up with is this:

import Tkinter
import tkFileDialog

filename = 'uninitialized'

def open_file_dialog():
global filename
filename = tkFileDialog.askopenfilename(filetypes=
[(allfiles,*)])
print filename

root = Tkinter.Tk()
Tkinter.Button(root, text='Notch genes...',
command=open_file_dialog).pack()
root.mainloop()




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


Fw: Meta question: disappearing posts (was Re: calculating aself.value, self.randomnum = normalvariate(x, y))

2009-06-25 Thread Hendrik van Rooyen

Below is one that just disappeared, without any feedback:
(unless I just missed it)
- Hendrik

- Original Message -
From: Hendrik van Rooyen m...@microcorp.co.za
To: Aahz a...@pythoncraft.com; python-list@python.org
Sent: Wednesday, June 24, 2009 10:08 AM
Subject: Re: Meta question: disappearing posts (was Re: calculating aself.value,
self.randomnum = normalvariate(x, y))


 Aahz aa..craft.com wrote:

  While that's also a bug in Mailman (I have a long-standing to-do item to
  fix that), there are also plenty of posts that simply aren't showing up
  in c.l.py.  As I said, I'm pretty sure (based on what was happening with
  c.l.py.announce) that it's some kind of weird problem with the mail-news
  gateway with MIME posts.

 I have lately had some posts returned with a seems to be forged message.
 Two reasons for that:
 - first is if I use the smtp server from our local telco - saix - then there
is
   no apparent relationship between where the message comes from and
   where it comes from, if you follow my Irish...
 - Second is if the same telco assigns me an IP that has been put on a list
   of bad boy IPs.

 So it is kind of pot luck if you see this message or not.

 - Hendrik



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


Python simple web development

2009-06-25 Thread Private Private
Hi,

I am looking for a python library which will allow me to do a simple
web development. I need to use
some forms (but nice looking :-) ), creating images based on input
from those forms, etc. I have read a bit about Django and TurboGears
but I am afraid that this is too big for my requirements (am I
wrong ?).

Can you suggest anything ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Barbara Liskov wins Turing Award

2009-06-25 Thread Steven D'Aprano
I haven't seen any links to this here: Barbara Liskov has won the Turing 
Award:

http://web.mit.edu/newsoffice/2009/turing-liskov-0310.html/?


[quote]
Institute Professor Barbara Liskov has won the Association for Computing 
Machinery's A.M. Turing Award, one of the highest honors in science and 
engineering, for her pioneering work in the design of computer 
programming languages. Liskov's achievements underpin virtually every 
modern computing-related convenience in people's daily lives.
[end quote]

Liskov is well known for the Liskov substitution principle. She also 
created the language CLU, one of the most important inspirations to 
Python, and coined the term pass by object (also known as pass by 
object reference) to describe CLU's then novel argument passing 
behaviour. Such behaviour has since become a virtual standard for OO 
languages such as Python and Java.



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


Re: Barbara Liskov wins Turing Award

2009-06-25 Thread Chris Rebert
On Thu, Jun 25, 2009 at 12:34 AM, Steven
D'Apranoste...@remove.this.cybersource.com.au wrote:
 I haven't seen any links to this here: Barbara Liskov has won the Turing
 Award:

 http://web.mit.edu/newsoffice/2009/turing-liskov-0310.html/?


 [quote]
 Institute Professor Barbara Liskov has won the Association for Computing
 Machinery's A.M. Turing Award, one of the highest honors in science and
 engineering, for her pioneering work in the design of computer
 programming languages. Liskov's achievements underpin virtually every
 modern computing-related convenience in people's daily lives.
 [end quote]

 Liskov is well known for the Liskov substitution principle. She also
 created the language CLU, one of the most important inspirations to
 Python

Erm, Wikipedia (which is generally excellent on programming topics)
seems to disagree with you.

http://en.wikipedia.org/wiki/Python_(programming_language)
Influenced by  ABC, ALGOL 68,[1] C, Haskell, Icon, Lisp, Modula-3, Perl, Java

Unless you mean it influenced Python indirectly by way of the
aforelisted languages...

Cheers,
Chris
-- 
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter: get filename of askopenfilename

2009-06-25 Thread rom
Thanks again. After your replies, I have understood how to do what I
wanted. What I wanted to do is to get a value after clicking a button
and use it in another part of the program. As you said, after getting
the value, I have to store it in a global variable. However, the
program does not do anything with it until I trigger another event,
e.g. by clicking on another button. Therefore, I have added another
button to my program:
#
import Tkinter
import tkFileDialog

filename = 'uninitialized'

def open_file_dialog():
global filename
filename = tkFileDialog.askopenfilename(filetypes=
[(allfiles,*)])

def print_variable(variable):
print variable

root = Tkinter.Tk()
Tkinter.Button(root, text='Select file...',
command=open_file_dialog).pack()

Tkinter.Button(root, text='Print file', command=lambda: print_variable
(filename)).pack()

root.mainloop()
#

On Jun 25, 4:12 pm, Sean McIlroy sean_mcil...@yahoo.com wrote:
 i think what he means is to put the global declaration inside the
 function that assigns to filename:

 def open_file_dialog():
     global filename
     filename = tkFileDialog.askopenfilename(filetypes=
 [(allfiles,*)])

 as it was, the function was creating a new variable called filename
 and assigning to THAT (and then doing absolutely nothing with it).
 with the above modification, the function understands that filename
 refers to the global variable of that name, and that variable's value
 does indeed get printed, but since the print statement comes before
 root.mainloop() -- hence before the button gets pressed -- filename
 gets printed before the function has assigned to it. this fact becomes
 apparent if you initialize the variable with filename='blank' (for
 example). putting the print statement after root.mainloop() doesn't
 work either, since root.mainloop() keeps control from getting to the
 print statement. the effect i think you want can be gotten from
 putting the print statement into the function as well, so what you end
 up with is this:

 import Tkinter
 import tkFileDialog

 filename = 'uninitialized'

 def open_file_dialog():
     global filename
     filename = tkFileDialog.askopenfilename(filetypes=
 [(allfiles,*)])
     print filename

 root = Tkinter.Tk()
 Tkinter.Button(root, text='Notch genes...',
 command=open_file_dialog).pack()
 root.mainloop()

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


Re: Tutorials on Jinja

2009-06-25 Thread Wayne Brehaut
On Wed, 24 Jun 2009 11:46:55 -0700 (PDT), Saurabh
saurabh.gupt...@gmail.com wrote:

Hi All,

I am trying to move my application on a MVC architecture and plan to
use Jinja for the same. Can anyone provide me with few quick links
that might help me to get started with Jinja?

Perhaps the most useful link is:

http://www.google.com/

from which you can easily find many more with a very basic search,
including:

http://jinja.pocoo.org/

Hope that helps?
wwwayne


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


Recipes for trace statements inside python programs?

2009-06-25 Thread Francesco Bochicchio
Hi all,

as many - I think - python programmers, I find muself debugging my
scripts by placing print statements in strategic places rather than
using the python debugger, and commenting/uncommenting them according
to myy deugging needs.  After a time, these prints staements start to
evolving in some ad-hoc half-baked framework ... so I wonder if there
is somewhere there is a full-baked trace statement support framework
which I can use. I'm aware of the logging module, but for me it its
more geared toward  application logging rather than toward trace for
debugging purpose.

Having googlet and found nothing (or too much but nothing relefìvant),
I'm now asking The List.

Here is what I have in mind:

Each module, function, class and method should have an attribute, say
trace_flag, which can be set to true or false value.

there should be a function TRACE which does something like this:

if __debug__ :
def TRACE(*args):
 if  trace_enabled(): print TRACE(%s) : %s  % ( context(), 
.join( str(x) for x in args ) )

where trace_enabled() should return the value of the innermost
trace_flag (checking current function/method then current class (if
any) then current module) and context() shoud return a string like
module.function or module.class.method ).

At this point I could in my test code enable  the trace in the
function/class that gives me trouble and disable it after I fixed it,
without having to touch the actual code under test.

I guess it should not be too hard do using python introspection
modules, but of couse I first would like to know if something like
this already exists.

I'm  aware that this imposes a performance penalty, but my scripts are
not operformance-critical. And if I put an if __debug__ switch


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


Re: Recipes for trace statements inside python programs?

2009-06-25 Thread Francesco Bochicchio

Sorry, hit the send button by mistake ...
The definition of the trace function should be like:

if __debug__ :
   def TRACE(*args):
 if  trace_enabled(): print TRACE(%s) : %s  % ( context(),
   .join( str(x) for x in args ) )
else : # optimazed code, only a function call performance penalty
   def TRACE(*args): pass


If I don't find anything suitable, maybe I will bake my own again,
this
time aiming to something that I can reuse ...

Ciao and thanks for any tip/suggestion
--
FB
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Barbara Liskov wins Turing Award

2009-06-25 Thread Terry Reedy

Chris Rebert wrote:

On Thu, Jun 25, 2009 at 12:34 AM, Steven
D'Apranoste...@remove.this.cybersource.com.au wrote:

I haven't seen any links to this here: Barbara Liskov has won the Turing
Award:


It was posted about the time of the announcement, but is worth the reminded.


http://web.mit.edu/newsoffice/2009/turing-liskov-0310.html/?


[quote]
Institute Professor Barbara Liskov has won the Association for Computing
Machinery's A.M. Turing Award, one of the highest honors in science and
engineering, for her pioneering work in the design of computer
programming languages. Liskov's achievements underpin virtually every
modern computing-related convenience in people's daily lives.
[end quote]

Liskov is well known for the Liskov substitution principle. She also
created the language CLU, one of the most important inspirations to
Python


This inspired me to to spend a couple of hours finding and reading a CLU 
manual.



Erm, Wikipedia (which is generally excellent on programming topics)
seems to disagree with you.

http://en.wikipedia.org/wiki/Python_(programming_language)
Influenced by ABC, ALGOL 68,[1] C, Haskell, Icon, Lisp, Modula-3, Perl, 
Java

Unless you mean it influenced Python indirectly by way of the
aforelisted languages...


Python's object model, assignment semantics, and call-by-object 
mechanism, and that name, come from CLU.  Whether Guido knew of it 
directly or not, I do not know. To the extent that the above is part of 
the heart of Python, I think Steven's statement stands pretty well.


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


Re: Python simple web development

2009-06-25 Thread Chris Withers

Private Private wrote:

from those forms, etc. I have read a bit about Django and TurboGears
but I am afraid that this is too big for my requirements (am I
wrong ?).


You are wrong :-)


Can you suggest anything ?


http://www.djangoproject.com/

http://bfg.repoze.org/

http://pylonshq.com/

Drink whichever koolaid you like the taste of :-)

Chris

--
Simplistix - Content Management, Zope  Python Consulting
   - http://www.simplistix.co.uk
--
http://mail.python.org/mailman/listinfo/python-list


Re: Measuring Fractal Dimension ?

2009-06-25 Thread Robin Becker

pdpi wrote:
...


But yeah, Log2 and LogE are the only two bases that make natural
sense except in specialized contexts. Base 10 (and, therefore, Log10)
is an artifact of having that 10 fingers (in fact, whatever base you
use, you always refer to it as base 10).


someone once explained to me that the set of systems that are continuous in the 
calculus sense was of measure zero in the set of all systems I think it was a 
fairly formal discussion, but my understanding was of the hand waving sort.


If true that makes calculus (and hence all of our understanding of such 
natural concepts) pretty small and perhaps non-applicable.


On the other hand R Kalman (of Bucy and Kalman filter fame) likened study of 
continuous linear dynamical systems to a man searching for a lost ring under 
the only light in a dark street ie we search where we can see. Because such 
systems are tractable doesn't make them natural or essential or applicable in a 
generic sense.

--
Robin Becker

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


Re: ctypes list library

2009-06-25 Thread luca72
Hello but find_library find only the lib. but if i need to load from a
list of lib how i have to do.
My proble is that i have 5 lib (a,b,c,d,e), if i load the a i get lib
b not found, if for first i load the b and than the a i get the same
error how i have to proceed.

Thanks

Luca

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


Re: Measuring Fractal Dimension ?

2009-06-25 Thread Paul Rubin
Robin Becker ro...@reportlab.com writes:
 someone once explained to me that the set of systems that are
 continuous in the calculus sense was of measure zero in the set of all
 systems I think it was a fairly formal discussion, but my
 understanding was of the hand waving sort.

That is very straightforward if you don't mind a handwave.  Let S be
some arbitrary subset of the reals, and let f(x)=0 if x is in S, and 1
otherwise (this is a discontinuous function if S is nonempty).  How
many different such f's can there be?  Obviously one for every
possible subset of the reals.  The cardinality of such f's is the
power set of the reals, i.e. much larger than the set of reals.

On the other hand, let g be some arbitrary continuous function on the
reals.  Let H be the image of Q (the set of rationals) under g.  That
is, H = {g(x) such that x is rational}.  Since g is continuous, it is
completely determined by H, which is a countable set.  So the
cardinality is RxN which is the same as the cardinality of R.  


 If true that makes calculus (and hence all of our understanding of
 such natural concepts) pretty small and perhaps non-applicable.

No really, it is just set theory, which is a pretty bogus subject in
some sense.  There aren't many discontinuous functions in nature.
There is a philosophy of mathematics (intuitionism) that says
classical set theory is wrong and in fact there are NO discontinuous
functions.  They have their own mathematical axioms which allow
developing calculus in a way that all functions are continuous.

 On the other hand R Kalman (of Bucy and Kalman filter fame) likened
 study of continuous linear dynamical systems to a man searching for
 a lost ring under the only light in a dark street ie we search
 where we can see. Because such systems are tractable doesn't make
 them natural or essential or applicable in a generic sense.

Really, I think the alternative he was thinking of may have been
something like nonlinear PDE's, a horribly messy subject from a
practical point of view, but still basically free of set-theoretic
monstrosities.  The Banach-Tarski paradox has nothing to do with nature.
-- 
http://mail.python.org/mailman/listinfo/python-list


print u'\u2013' error on console/terminal

2009-06-25 Thread robert

 sys.stdout.encoding
'cp850'
 print u'\u2013'
Traceback (most recent call last):
  File stdin, line 1, in module
  File C:\Python25\Lib\encodings\cp850.py, line 12, in encode
return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode character 
u'\u2013' in position

 0: character maps to undefined
 sys.stdout.encoding='xy'
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: readonly attribute



is there a switch to suppress those encoding errors for standard 
print's on the console - e.g. for getting automatic behavior like 
'replace' :


 print u'a \2013 b'.encode('cp850','replace')
a ?3 b



or a new filter file class necessary?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Recipes for trace statements inside python programs?

2009-06-25 Thread koranthala
On Jun 25, 1:40 pm, Francesco Bochicchio bieff...@gmail.com wrote:
 Sorry, hit the send button by mistake ...
 The definition of the trace function should be like:

 if __debug__ :
    def TRACE(*args):
      if  trace_enabled(): print TRACE(%s) : %s  % ( context(),
                                .join( str(x) for x in args ) )
 else : # optimazed code, only a function call performance penalty
    def TRACE(*args): pass

 If I don't find anything suitable, maybe I will bake my own again,
 this
 time aiming to something that I can reuse ...

 Ciao and thanks for any tip/suggestion
 --
 FB

Is assert what you are looking for?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Measuring Fractal Dimension ?

2009-06-25 Thread Robin Becker

Paul Rubin wrote:
.

That is very straightforward if you don't mind a handwave.  Let S be
some arbitrary subset of the reals, and let f(x)=0 if x is in S, and 1
otherwise (this is a discontinuous function if S is nonempty).  How
many different such f's can there be?  Obviously one for every
possible subset of the reals.  The cardinality of such f's is the
power set of the reals, i.e. much larger than the set of reals.

On the other hand, let g be some arbitrary continuous function on the
reals.  Let H be the image of Q (the set of rationals) under g.  That
is, H = {g(x) such that x is rational}.  Since g is continuous, it is
completely determined by H, which is a countable set.  So the
cardinality is RxN which is the same as the cardinality of R.  



ok so probably true then



If true that makes calculus (and hence all of our understanding of
such natural concepts) pretty small and perhaps non-applicable.


No really, it is just set theory, which is a pretty bogus subject in
some sense.  There aren't many discontinuous functions in nature.
There is a philosophy of mathematics (intuitionism) that says
classical set theory is wrong and in fact there are NO discontinuous
functions.  They have their own mathematical axioms which allow
developing calculus in a way that all functions are continuous.



so does this render all the discreteness implied by quantum theory unreliable? 
or is it that we just cannot see(measure) the continuity that really happens? 
Certainly there are people like Wolfram who seem to think we're in some kind of 
giant calculating engine where state transitions are discontinuous.




On the other hand R Kalman (of Bucy and Kalman filter fame) likened
study of continuous linear dynamical systems to a man searching for
a lost ring under the only light in a dark street ie we search
where we can see. Because such systems are tractable doesn't make
them natural or essential or applicable in a generic sense.


Really, I think the alternative he was thinking of may have been
something like nonlinear PDE's, a horribly messy subject from a
practical point of view, but still basically free of set-theoretic
monstrosities.  The Banach-Tarski paradox has nothing to do with nature.


My memory of his seminar was that he was concerned about our failure to model 
even the simplest of systems with non-linearity and/or discreteness. I seem to 
recall that was about the time that chaotic behaviours were starting to appear 
in the control literature and they certainly depend on non-linearity.

--
Robin Becker

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


Re: Recipes for trace statements inside python programs?

2009-06-25 Thread samwyse
I use an @trace decorator.  This (http://wordaligned.org/articles/
echo) will get you started but there are lots of others available.  My
personal preference is a decorator that catches, displays and re-
raises exceptions as well as displaying both calling parameters and
returned values.

btw, here's a cool Python3K (or 2.6 if you turn on print functions)
trick that's sort-of on topic since it relates to log files and such:
import functools, sys
warn = functools.partial(print, file=sys.stderr)
logfile = open(...)
log = functools.partial(print, file=logfile)
# etc.

On Jun 25, 3:33 am, Francesco Bochicchio bieff...@gmail.com wrote:
 Hi all,

 as many - I think - python programmers, I find muself debugging my
 scripts by placing print statements in strategic places rather than
 using the python debugger, and commenting/uncommenting them according
 to myy deugging needs.  After a time, these prints staements start to
 evolving in some ad-hoc half-baked framework ... so I wonder if there
 is somewhere there is a full-baked trace statement support framework
 which I can use. I'm aware of the logging module, but for me it its
 more geared toward  application logging rather than toward trace for
 debugging purpose.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python simple web development

2009-06-25 Thread samwyse
I just started with web2py (http://www.web2py.com/) for an internal-
use-only app that doesn't need to be very pretty.  Been using it for
about a week and after re-watching the tutorial, I've decided that I'm
making things way too complicated.  So today I'm going to replace a
lot of my code with some built-ins.

On Jun 25, 2:29 am, Private Private mail...@gmail.com wrote:
 Hi,

 I am looking for a python library which will allow me to do a simple
 web development. I need to use
 some forms (but nice looking :-) ), creating images based on input
 from those forms, etc. I have read a bit about Django and TurboGears
 but I am afraid that this is too big for my requirements (am I
 wrong ?).

 Can you suggest anything ?

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


How to get filename from a pid?

2009-06-25 Thread Dudeja, Rajat

Hi,

I've a PID of a process (the process is a notepad application), I want to know 
which file is opened by this process.

regards,
Rajat


Notice: This e-mail is intended solely for use of the individual or entity to 
which it is addressed and may contain information that is proprietary, 
privileged, company confidential and/or exempt from disclosure under applicable 
law. If the reader is not the intended recipient or agent responsible for 
delivering the message to the intended recipient, you are hereby notified that 
any dissemination, distribution or copying of this communication is strictly 
prohibited.  If this communication has been transmitted from a U.S. location it 
may also contain data subject to the International Traffic in Arms Regulations 
or U.S. Export Administration Regulations and cannot be disseminated, 
distributed or copied to foreign nationals, residing in the U.S. or abroad, 
without the prior approval of the U.S. Department of State or appropriate 
export licensing authority. If you have received this communication in error, 
please notify the sender by reply e-mail or collect telephone call and delete 
or destroy all copies of this e-mail message, any physical copies made of this 
e-mail message and/or any file attachment(s).

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


Re: Recipes for trace statements inside python programs?

2009-06-25 Thread Francesco Bochicchio
On 25 Giu, 13:15, koranthala koranth...@gmail.com wrote:
 On Jun 25, 1:40 pm, Francesco Bochicchio bieff...@gmail.com wrote:


 Is assert what you are looking for?

No. Assert raises exception if some condition is met. I just want to
be able to enable/disable the
printout of intermediate data, on a per function/method/class/module
basis, without altering the
execution flow.

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


How to convert he boolean values into integers

2009-06-25 Thread krishna
Hi Guys,

I need to convert 1010100110 boolean value to some think like 2345, if
its possible then post me your comment on this

Advanced thanks for all

Narayana perumal.G
-- 
http://mail.python.org/mailman/listinfo/python-list


scipy stats binom_test

2009-06-25 Thread dusans
Amm i using the function wrong or ...? cuz in R i get the right value

 binom_test(3, 5, p=0.8)
0.262

 dbinom(3, 5, 0.8)
[1] 0.205
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to convert he boolean values into integers

2009-06-25 Thread Ulrich Eckhardt
krishna wrote:
 I need to convert 1010100110 boolean value to some think like 2345, if
 its possible then post me your comment on this

Yes, sure. You can simply sum up the digit values and then format them as
decimal number. You can also just look up the number:

  def decode_binary(input):
  for i in range(2**len(input)):
  if bin(i)==input:
  return str(i)

I Hope I was able to help you with your homework! ;^)

Uli

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

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


I need a dict that inherits its mappings

2009-06-25 Thread samwyse
I need a dict-like object that, if it doesn't contain a key, will
return the value from a parent object.  Is there an easy way to do
this so I don't have to define __getitem__ and __contains__ and others
that I haven't even thought of yet?  Here's a use case, if you're
confused:

en_GB=mydict()
en_US=mydict(en_GB)

en_GB['bonnet']='part of your car'
print en_US['bonnet']  # prints 'part of your car'

en_US['bonnet']='a type of hat'
print en_US['bonnet']  # prints 'a type of hat'
print en_GB['bonnet']  # prints 'part of your car'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to convert he boolean values into integers

2009-06-25 Thread samwyse
 int('1010100110', 2)
678

On Jun 25, 7:06 am, krishna gnperu...@gmail.com wrote:
 Hi Guys,

 I need to convert 1010100110 boolean value to some think like 2345, if
 its possible then post me your comment on this

 Advanced thanks for all

 Narayana perumal.G

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


Re: How to get filename from a pid?

2009-06-25 Thread Tim Golden

Dudeja, Rajat wrote:

Hi,

I've a PID of a process (the process is a notepad application), 
I want to know which file is opened by this process.


Is there anything wrong with this answer which I gave you
last week? (Note: there might be, but the fact that you
seem to have ignored it makes me wonder...)

http://groups.google.com/group/comp.lang.python/msg/6a44e15473b08de0?hl=en

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


trace options

2009-06-25 Thread Edward Peschko
All,

I've been looking at the trace module, and although it looks useful, I'm
surprised that there aren't a couple of features that I would have thought
would be fairly basic. So, does trace support (for the --trace option):

   - indentation tracking stacklevel (where each function is prefixed
 by tabs equal to the number of stacklevels deep in the program)

   - output to something other than sys.stdout (eg. output to a file
 specified either by environmental variable or by parameter).

   - mult-threaded programs going to multiple output handles,
 especially in light of the above

   - fully qualified python modules in path: (eg:

 /path/to/module/my_module.py(1): print HERE

 instead of

   my_module.py(1): print HERE.

Ultimately, I'd like to be able to look at two runs of a program
and be able to pinpoint the very first difference
between thembased on the output of their trace runs. As it
stands, I really can't do this.

Of course I could implement the above, but I was
hoping to avoid duplicated effort if someone has
already implemented options like this..I posted the above to
the python-dev list, they suggested I take it here, so any help
would be appreciated.

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


Re: Paramiko help - processing multiple commands

2009-06-25 Thread J. Clifford Dyer
On Wed, 2009-06-24 at 15:22 -0700, Frank Ruiz wrote:
 Greetings,
 
 I am trying to process multiple commands using paramiko. I have
 searched other threads, and I think my use case is a little different.
 I am trying to login to a storage node that has a special shell, and
 as such I cant execute a script on the storage node side.
 
 I am also trying to avoid using pexpect because I hate making system
 calls.. hence my leaning towards paramiko.
 
 Was hoping someone could help me identify a way to process multiple
 commands using paramiko.
 
 I have two commands listed below, however only one is getting processed.
 
 Any help is much appreciated.
 
 Thanks!
 
 Here is my script:
 
 #!/usr/bin/env python
 
 
 #-Modules-
 import optparse
 import sys
 import paramiko
 
 
 #-Variables---
 plog = 'storagessh.log'
 suser = 'root'
 
 
 #-Config--
 
 #-Subs-Defined
 def options():
 global hostname
 global goldenimage
 global lunclone
 global sshport
 
 usage = usage: %prog [options] -n nodename -g goldenimage -l lun
 
 parser = optparse.OptionParser(usage)
 
 parser.add_option(-n, --node,
   dest=hostname,
   help=Name of storage node you are connecting to.)
 parser.add_option(-g, --gold,
   dest=goldenimage,
   help=Name of goldenimage to clone.)
 parser.add_option(-l, --lun,
   dest=lunclone,
   help=Name of lun to create.)
 parser.add_option(-p, --port,
   dest=sshport,
   default=22,
   help=SSH port number.)
 options, args = parser.parse_args()
 
 if not options.hostname:
 parser.error(Missing hostname argument.)
 exit
 elif not options.goldenimage:
 parser.error(Missing goldenimage argument.)
 exit
 elif not options.lunclone:
 parser.error(Missing lun argument.)
 exit
 
 hostname = options.hostname
 goldenimage = options.goldenimage
 lunclone = options.lunclone
 sshport = options.sshport
 

It looks like you are trying to create a configuration class, but going
through extra gyrations to use global variables instead.  Perl's class
system is rather convoluted, but it is straightforward in python, and
will make your code easier to maintain.  I recommend you take a look at
the section on classes in the python tutorial, and play around with it.
Not everything needs to be a class in python, but in certain cases (and
this is one of them) it will make things much cleaner.

 def storagessh():
 paramiko.util.log_to_file(plog)
 client = paramiko.SSHClient()
 client.load_system_host_keys()
 client.connect(hostname, sshport, suser)
 stdin, stdout, stderr = client.exec_command('show')
 stdin, stdout, stderr = client.exec_command('help')
 print stdout.read()
 client.close()
 

You just did it.  You processed two commands.  The only problem is that
you wrote values to stdin, stdout, and stderr with the show command, and
then immediately overwrote them with the help command.  Use different
variable names for each command (like stdout_show and stdout_help), and
you should be fine.

 
 
 
 #--Initialization-
 if __name__ == __main__:
 options()
 storagessh()

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


Re: pyinstaller

2009-06-25 Thread Gabriel Genellina

En Sun, 21 Jun 2009 21:48:29 -0300, Arlie arli...@gmail.com escribió:


Newbie here using Python 2.6.2 on MS WinXP Pro SP3. I'm trying create
an frozen exec and was able to generate and exe file.


Have you tried py2exe?


Imported files in myprog.py:
import MySQLdb


Probably using MySQLdb requires some extra work... Try a more specific
forum, http://www.pyinstaller.org/ menctions a mailing list.

--
Gabriel Genellina

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


Re: Tutorials on Jinja

2009-06-25 Thread Saurabh
On Jun 25, 2:04 am, Wayne Brehaut wbreh...@mcsnet.ca wrote:
 On Wed, 24 Jun 2009 11:46:55 -0700 (PDT), Saurabh

 saurabh.gupt...@gmail.com wrote:
 Hi All,

 I am trying to move my application on a MVC architecture and plan to
 use Jinja for the same. Can anyone provide me with few quick links
 that might help me to get started with Jinja?

 Perhaps the most useful link is:

 http://www.google.com/

 from which you can easily find many more with a very basic search,
 including:

 http://jinja.pocoo.org/

 Hope that helps?
 wwwayne



 Thanks,
 Saby



Thanks (Sir!). I was hoping to get some good tutorial on
implementation (which I wasn't able to find with a basic search -
http://dev.pocoo.org/projects/lodgeit/ is what I was referring to
earlier) as this is my first assignment on any template engine (never
used Cheetah, MakO, Tempita).

I would appreciate people responding with something helpful. If you
find a question pretty naive, kindly ignore the question rather than
passing comments on it. Doesn't helps anyone's time.

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


Re: os.walk and os.listdir problems python 3.0+

2009-06-25 Thread Amos Anderson
Thank you. That works very well when writing to a text file but what is the
equivalent when writing the information to stdout using print?

Sorry when I originally replied I sent it directly and it didn't go to the
list.

On Thu, Jun 25, 2009 at 12:57 AM, Mark Tolonen
metolone+gm...@gmail.commetolone%2bgm...@gmail.com
 wrote:


 Amos Anderson amosander...@gmail.com wrote in message
 news:a073a9cf0906242007k5067314dn8e9d7b1c6da62...@mail.gmail.com...

  I've run into a bit of an issue iterating through files in python 3.0 and
 3.1rc2. When it comes to a files with '\u200b' in the file name it gives
 the
 error...

 Traceback (most recent call last):
  File ListFiles.py, line 19, in module
   f.write(file:{0}\n.format(i))
  File c:\Python31\lib\encodings\cp1252.py, line 19, in encode
   return codecs.charmap_encode(input,self.errors,encoding_table)[0]
 UnicodeEncodeError: 'charmap' codec can't encode character '\u200b' in
 position
 30: character maps to undefined

 Code is as follows...
 import os
 f = open(dirlist.txt, 'w')

 for root, dirs, files in os.walk(C:\\Users\\Filter\\):
   f.write(root:{0}\n.format(root))
   f.write(dirs:\n)
   for i in dirs:
   f.write(dir:{0}\n.format(i))
   f.write(files:\n)
   for i in files:
   f.write(file:{0}\n.format(i))
 f.close()
 input(done)

 The file it's choking on happens to be a link that internet explorer
 created. There are two files that appear in explorer to have the same name
 but one actually has a zero width space ('\u200b') just before the .url
 extension. In playing around with this I've found several files with the
 same character throughout my file system. OS: Vista SP2, Language: US
 English.

 Am I doing something wrong or did I find a bug? It's worth noting that
 Python 2.6 just displays this character as a ? just as it appears if you
 type dir at the windows command prompt.


 In Python 3.x strings default to Unicode.  Unless you choose an encoding,
 Python will use the default system encoding to encode the Unicode strings
 into a file.  On Windows, the filesystem uses Unicode and supports the full
 character set, but cp1252 (on your system) is the default text file
 encoding, which doesn't support zero-width space.  Specify an encoding for
 the output file such as UTF-8:

  f=open('blah.txt','w',encoding='utf8')
 f.write('\u200b')

 1

 f.close()


 -Mark


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

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


Re: IMPORTANT: I NEED TO HELP WITH ONE OF THE CORE DEVELOPERS

2009-06-25 Thread Grant Edwards
On 2009-06-24, Chris Rebert c...@rebertia.com wrote:

 In the future, also NOTE THAT SHOUTING TYPICALLY DOES NOT EARN ONE SYMPATHY.

And to insure that a post is ignored, make sure the subject
contains no meaningful question, only a plea for help:

  http://catb.org/~esr/faqs/smart-questions.html#bespecificurget

done

Also be sure to use urgent, important or high priority in
the subject:

  http://catb.org/~esr/faqs/smart-questions.html#urgent

check
  
However, he did forget to use multiple exclamation points --
the nails in the coffin of a Usenet post.

-- 
Grant Edwards   grante Yow! Kids, don't gross me
  at   off ... Adventures with
   visi.comMENTAL HYGIENE can be
   carried too FAR!
-- 
http://mail.python.org/mailman/listinfo/python-list


compiling python 2.6.2 on uclibc

2009-06-25 Thread Jeseem S
hi,
  am looking for patched to compile python 2.6.2 on uclibc.
any help is greatly appreciated

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


extending method descriptors

2009-06-25 Thread Michael Sliczniak
Suppose I have this:

Python 2.5.1 (r251:54863, Feb  6 2009, 19:02:12)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type help, copyright, credits or license for more information.
 class A(object):
... __slots__ = ('x', 'y')
...
 a = A()
 b = A()

So I am using descriptors (and I want to). I also would like to have
methods A.x.foo(), A.x.bar(), A.y.foo(), and A.y.bar() and my idea was
to extend member_descriptor, but it seems that I cannot:

 type(A.x)
type 'member_descriptor'
 class my_descriptor(type(A.x)):
... def foo():
... return 1
...
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: Error when calling the metaclass bases
type 'member_descriptor' is not an acceptable base type

Is there some way, outside of using C, to be able to do what I want.
Yes I want a.x and b.x to be different, but type(a).x.foo(), type
(b).x.foo(), and A.x.foo() should all be the same. I have tried other
approaches and get exceptions of one flavor or another with everything
I have tried.

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


Re: generator expression works in shell, NameError in script

2009-06-25 Thread Aahz
In article 13e776b0-6ca8-479e-ba82-eb5b7eb8f...@a5g2000pre.googlegroups.com,
ssc  steven.samuel.c...@gmail.com wrote:
On Jun 18, 10:49=A0am, Jon Clements jon...@googlemail.com wrote:

 Why are you doing this? I'm assuming a code to title look up is
 required (don't forget military, royal and honorable titles
 etc... :) )

I'm in New Zealand. Hardly any need for military titles, rarely any
for royal and damn sure none for honorable :-D (scnr)

+1 QOTW
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

as long as we like the same operating system, things are cool. --piranha
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Measuring Fractal Dimension ?

2009-06-25 Thread pdpi
On Jun 25, 12:23 pm, Robin Becker ro...@reportlab.com wrote:
 Paul Rubin wrote:

 so does this render all the discreteness implied by quantum theory unreliable?
 or is it that we just cannot see(measure) the continuity that really happens?
 Certainly there are people like Wolfram who seem to think we're in some kind 
 of
 giant calculating engine where state transitions are discontinuous.

More like that axiomatic system doesn't accurately map to reality as
we currently understand it.

Your posts made me think that I wasn't clear in saying e and 2 are the
only natural bases for logs.

The log function, as the inverse of the exponential, is a pretty
fundamental function.

The base e exponential has a load of very natural properties, f'(x) = f
(x) being an example.

As the smallest admissible integer base, log 2 is also a pretty
natural notion, especially in computer science, or in general all that
follow from binary true/false systems.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: It's ...

2009-06-25 Thread Kirk Strauser
At 2009-06-24T19:53:49Z, Angus Rodgers twir...@bigfoot.com writes:

 stop = 3   # Tab stops every 3 characters
 from types import StringType   # Is this awkwardness necessary?
 detab = lambda s : StringType.expandtabs(s, stop)  # Or use def
 f = open('h071.txt')   # Do some stuff to f, perhaps, and then:
 f.seek(0)
 print ''.join(map(detab, f.xreadlines()))
 f.close()

An equivalent in modern Pythons:

 print ''.join(line.expandtabs(3) for line in file('h071.txt'))

In short: expandtabs is a method on strings, there's no need to seek to the
beginning, and files are closed when they are garbage collected (although I
can't make myself not close output files after years of doing so), and map()
is largely deprecated in favor of list comprehensions and generator
functions.
-- 
Kirk Strauser
The Day Companies
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IMPORTANT: I NEED TO HELP WITH ONE OF THE CORE DEVELOPERS

2009-06-25 Thread Paul Boddie
On 24 Jun, 15:22, Pegasus non...@nowhere.com wrote:
 I need help with an implementation of your
 interpreter under PSPE/PSP.

There doesn't seem to be much of an intersection between the PSP and
mainstream Python communities, so some more context may have been
desirable here.

[...]

 We believe that the trouble is in a routine
 of our Nanodesktop libc that can be
 a bottleneck. But we don't know
 which can be the interested routine
 (string ? memory allocation ?)

It sounds like a job for a profiler. Maybe KCachegrind [1] along with
some other tools might be of assistance.

Paul

[1] http://kcachegrind.sourceforge.net/cgi-bin/show.cgi/KcacheGrindWhat
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Measuring Fractal Dimension ?

2009-06-25 Thread pdpi
On Jun 25, 10:38 am, Paul Rubin http://phr...@nospam.invalid wrote:
 Robin Becker ro...@reportlab.com writes:
  someone once explained to me that the set of systems that are
  continuous in the calculus sense was of measure zero in the set of all
  systems I think it was a fairly formal discussion, but my
  understanding was of the hand waving sort.

 That is very straightforward if you don't mind a handwave.  Let S be
 some arbitrary subset of the reals, and let f(x)=0 if x is in S, and 1
 otherwise (this is a discontinuous function if S is nonempty).  How
 many different such f's can there be?  Obviously one for every
 possible subset of the reals.  The cardinality of such f's is the
 power set of the reals, i.e. much larger than the set of reals.

 On the other hand, let g be some arbitrary continuous function on the
 reals.  Let H be the image of Q (the set of rationals) under g.  That
 is, H = {g(x) such that x is rational}.  Since g is continuous, it is
 completely determined by H, which is a countable set.  So the
 cardinality is RxN which is the same as the cardinality of R.  

  If true that makes calculus (and hence all of our understanding of
  such natural concepts) pretty small and perhaps non-applicable.

 No really, it is just set theory, which is a pretty bogus subject in
 some sense.  There aren't many discontinuous functions in nature.
 There is a philosophy of mathematics (intuitionism) that says
 classical set theory is wrong and in fact there are NO discontinuous
 functions.  They have their own mathematical axioms which allow
 developing calculus in a way that all functions are continuous.

  On the other hand R Kalman (of Bucy and Kalman filter fame) likened
  study of continuous linear dynamical systems to a man searching for
  a lost ring under the only light in a dark street ie we search
  where we can see. Because such systems are tractable doesn't make
  them natural or essential or applicable in a generic sense.

 Really, I think the alternative he was thinking of may have been
 something like nonlinear PDE's, a horribly messy subject from a
 practical point of view, but still basically free of set-theoretic
 monstrosities.  The Banach-Tarski paradox has nothing to do with nature.

I'll take the Banach-Tarski construct (it's not a paradox, damn it!)
over non-linear PDEs any day of the week, thankyouverymuch. :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A superclass using a child classes' methods

2009-06-25 Thread Nick Craig-Wood
Kurt Schwehr schw...@gmail.com wrote:
  Thanks for the excellent response setting me straight.  Now to figure
  out what dumb thing I did to make my code not work...

If you have trouble then post the code (or a cut down version
demonstrating the code) - it always helps to have real code with real
error messages when tracking down problems.  A lot of people (like me)
will enjoy the puzzle of looking through your code and finding out
where it went wrong.

-- 
Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best way to enumerate classes in a module

2009-06-25 Thread Nick Craig-Wood
Carl Banks pavlovevide...@gmail.com wrote:
  On Jun 23, 10:02 pm, Дамјан Георгиевски gdam...@gmail.com wrote:
  I need to programmaticaly enumerate all the classes in a given module.
  Currently I'm using dir(module) but the Notice on the documentation page
  [1]  says dir() is supplied primarily as a convenience for use at an
  interactive prompt so that kind of scares me.
 
  Is there a better approach?
 
  If there is, how do I get all the classes of the current module?
 
  You can use module.__dict__.values() (or .itervalues()) to retrieve
  the contents of the module (and of course .keys() if you want names).
  If you want to check the same module that the code appears in, use
  globals() instead of module.__dict__.
 
  Something makes me think that module.__dict__ was only added to Python
  fairly recently, but I'm not sure.

It exists in python2.1 - I don't have an older python to check at the
moment.

  A word of warning (although I would guess you are already aware of
  these issues, but for other readers): this method can't tell the
  difference between a class defined in the module and a class imported
  into it.
 
  Finally, despite the warning, I think you are ok to use dir() for that
  purpose.  It's not likely to change.

Good advice...

And as a double check

 import sys
 set(sys.__dict__.keys()) == set(dir(sys))
True
 import os
 set(os.__dict__.keys()) == set(dir(os))
True

-- 
Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: extending method descriptors

2009-06-25 Thread Peter Otten
Michael Sliczniak wrote:

 Suppose I have this:
 
 Python 2.5.1 (r251:54863, Feb  6 2009, 19:02:12)
 [GCC 4.0.1 (Apple Inc. build 5465)] on darwin
 Type help, copyright, credits or license for more information.
 class A(object):
 ... __slots__ = ('x', 'y')
 ...
 a = A()
 b = A()
 
 So I am using descriptors (and I want to). I also would like to have
 methods A.x.foo(), A.x.bar(), A.y.foo(), and A.y.bar() and my idea was
 to extend member_descriptor, but it seems that I cannot:
 
 type(A.x)
 type 'member_descriptor'
 class my_descriptor(type(A.x)):
 ... def foo():
 ... return 1
 ...
 Traceback (most recent call last):
   File stdin, line 1, in module
 TypeError: Error when calling the metaclass bases
 type 'member_descriptor' is not an acceptable base type
 
 Is there some way, outside of using C, to be able to do what I want.
 Yes I want a.x and b.x to be different, but type(a).x.foo(), type
 (b).x.foo(), and A.x.foo() should all be the same. I have tried other
 approaches and get exceptions of one flavor or another with everything
 I have tried.

If you define an attribute with the same name in both the class and its 
instances the instance attribute just hides the class attribute:

 class X(object):
... def foo(self): return yadda
...
 class A(object):
... def __init__(self, x):
... self.x = x
... x = X()
...
 a = A(foo)
 b = A(bar)
 a.x, b.x, type(a).x.foo(), type(b).x.foo()
('foo', 'bar', 'yadda', 'yadda')

This is probably not what you expected. So what are you really trying to 
achieve?

Peter

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


Re: It's ...

2009-06-25 Thread Angus Rodgers
On Thu, 25 Jun 2009 17:53:51 +0100, I wrote:

On Thu, 25 Jun 2009 10:31:47 -0500, Kirk Strauser 
k...@daycos.com wrote:

At 2009-06-24T19:53:49Z, Angus Rodgers twir...@bigfoot.com writes:

 print ''.join(map(detab, f.xreadlines()))

An equivalent in modern Pythons:

 print ''.join(line.expandtabs(3) for line in file('h071.txt'))

I guess the code below would also have worked in 2.1?
(It does in 2.5.4.)

 print ''.join(line.expandtabs(3) for line in \
 file('h071.txt').xreadlines())

Possibly silly question (in for a penny ...): does the new feature,
by which a file becomes iterable, operate by some kind of coercion
of a file object to a list object, via something like x.readlines()?
runs for cover
-- 
Angus Rodgers
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: It's ...

2009-06-25 Thread Angus Rodgers
On Thu, 25 Jun 2009 17:56:47 +0100, I burbled incoherently:

[...] does the new feature,
by which a file becomes iterable, operate by some kind of coercion
of a file object to a list object, via something like x.readlines()?

Sorry to follow up my own post yet again (amongst my weapons is
a fanatical attention to detail when it's too late!), but I had 
better rephrase that question:

Scratch list object, and replace it with something like: some
kind of iterator object, that is at least already implicit in 2.1
(although the term 'iterator' isn't mentioned in the index to the
2nd edition of Beazley's book).  Something like that!  8-P

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


Re: It's ...

2009-06-25 Thread Angus Rodgers
On Thu, 25 Jun 2009 10:31:47 -0500, Kirk Strauser 
k...@daycos.com wrote:

At 2009-06-24T19:53:49Z, Angus Rodgers twir...@bigfoot.com writes:

 print ''.join(map(detab, f.xreadlines()))

An equivalent in modern Pythons:

 print ''.join(line.expandtabs(3) for line in file('h071.txt'))

I guess the code below would also have worked in 2.1?
(It does in 2.5.4.)

 print ''.join(line.expandtabs(3) for line in \
 file('h071.txt').xreadlines())

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


Re: IMPORTANT: I NEED TO HELP WITH ONE OF THE CORE DEVELOPERS

2009-06-25 Thread Martin P. Hellwig

Chris Rebert wrote:
cut


In the future, also NOTE THAT SHOUTING TYPICALLY DOES NOT EARN ONE SYMPATHY.

Cheers,
Chris


Let me demonstrate: Chris, I have no sympathy for you :-)

--
MPH
http://blog.dcuktec.com
'If consumed, best digested with added seasoning to own preference.'
--
http://mail.python.org/mailman/listinfo/python-list


Re: It's ...

2009-06-25 Thread Angus Rodgers
On Thu, 25 Jun 2009 17:56:47 +0100, I found a new way to disgrace
myself, thus:

[...] something like x.readlines()?
   ^
I don't know how that full stop got in there.  Please ignore it!
-- 
Angus Rodgers
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: It's ...

2009-06-25 Thread MRAB

Angus Rodgers wrote:
On Thu, 25 Jun 2009 10:31:47 -0500, Kirk Strauser 
k...@daycos.com wrote:



At 2009-06-24T19:53:49Z, Angus Rodgers twir...@bigfoot.com writes:


print ''.join(map(detab, f.xreadlines()))

An equivalent in modern Pythons:


print ''.join(line.expandtabs(3) for line in file('h071.txt'))


I guess the code below would also have worked in 2.1?
(It does in 2.5.4.)

 print ''.join(line.expandtabs(3) for line in \
 file('h071.txt').xreadlines())


That uses a generator expression, which was introduced in 2.4.
--
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter: get filename of askopenfilename

2009-06-25 Thread norseman

rom wrote:

Thanks for your response. I have modified this minimal program as you
suggested but still is not able to print the filename:

##
import Tkinter
import tkFileDialog

global filename  


# NO NO NO!  No global line here


filename=''

root = Tkinter.Tk()

Tkinter.Button(root, text='Notch genes...', command=lambda:
open_file_dialog()).pack()

def open_file_dialog():


# global var  goes here, inside the def so the var filename is not local
#  just like I show below.

filename = tkFileDialog.askopenfilename(filetypes=
[(allfiles,*)])


print filename

root.mainloop()
##

Is this what you mean?


On Jun 25, 1:28 pm, norseman norse...@hughes.net wrote:

OOPS - I left out the global statement

rom wrote:

Hi there,
I am writing an interface with Tkinter. My minimal program looks like
this:
#
import Tkinter
import tkFileDialog

# define globals here
filename= '' # will take care of the problem


root = Tkinter.Tk()
Tkinter.Button(root, text='Notch genes...', command=lambda:
open_file_dialog()).pack()
def open_file_dialog():

   global filename   # need this to assign to it


filename = tkFileDialog.askopenfilename(filetypes=[(all
files,*)])
# print filename
root.mainloop()
#
I would like to recover the filename variable outside the
open_file_dialog function. For instance, to be able to print the
selected file name (uncomment # print filename line).
Is there a way to do that?
Thanks in advance.
R






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


Re: tkinter: get filename of askopenfilename

2009-06-25 Thread norseman

rom wrote:

Ok. I think I got it. I have to do it in this way:
###
import Tkinter
import tkFileDialog


filename=''

root = Tkinter.Tk()

Tkinter.Button(root, text='Notch genes...', command=lambda:
open_file_dialog()).pack()

def open_file_dialog():
global filename
filename = tkFileDialog.askopenfilename(filetypes=
[(allfiles,*)])
print_filename()

def print_filename():
print filename

root.mainloop()
###
Thanks again

On Jun 25, 1:46 pm, rom rompu...@gmail.com wrote:

Thanks for your response. I have modified this minimal program as you
suggested but still is not able to print the filename:

##
import Tkinter
import tkFileDialog

global filename
filename=''

root = Tkinter.Tk()

Tkinter.Button(root, text='Notch genes...', command=lambda:
open_file_dialog()).pack()

def open_file_dialog():
filename = tkFileDialog.askopenfilename(filetypes=
[(allfiles,*)])

print filename

root.mainloop()
##

Is this what you mean?

On Jun 25, 1:28 pm, norseman norse...@hughes.net wrote:


OOPS - I left out the global statement
rom wrote:

Hi there,
I am writing an interface with Tkinter. My minimal program looks like
this:
#
import Tkinter
import tkFileDialog

# define globals here
filename= '' # will take care of the problem

root = Tkinter.Tk()
Tkinter.Button(root, text='Notch genes...', command=lambda:
open_file_dialog()).pack()
def open_file_dialog():

   global filename   # need this to assign to it

filename = tkFileDialog.askopenfilename(filetypes=[(all
files,*)])
# print filename
root.mainloop()
#
I would like to recover the filename variable outside the
open_file_dialog function. For instance, to be able to print the
selected file name (uncomment # print filename line).
Is there a way to do that?
Thanks in advance.
R



===
Now you got it!! So ignore my just previous response. :)

The global statement inside the def keeps the specified variable from 
being local by default.  If the global statement is higher up the food 
chain then it will cause Python to look back for a definition from that 
point. There may not be one or it might be other than expected. Python 
works backward (or up) from global statement through the defs and 
modules enclosing it. Uses first found.


A small suggestion, filename is a word usually used commonly. fname 
would be a better substitute. Or fn or ifil, ofil (in/out files) and so 
forth.  Of course it is perfectly OK for question and answer time.



version: Python
OS : All or Not relevant
date   : June 25, 2009


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


Re: Problem with multithreading

2009-06-25 Thread larudwer

Jeffrey Barish jeff_bar...@earthlink.net schrieb im Newsbeitrag 
news:mailman.2091.1245902997.8015.python-l...@python.org...
 Jeffrey Barish wrote:

 I have a program that uses multithreading to monitor two loops.  When
 something happens in loop1, it sends a message to loop2 to have it 
 execute
 a command.  loop2 might have to return a result.  If it does, it puts the
 result in a queue.  loop1, meanwhile, would have blocked waiting for
 something to appear in the queue.  The program works for a while, but
 eventually freezes.  I know that freezing is a sign of deadlock. 
 However,
 I put in print statements to localize the problem and discovered 
 something
 weird.  The freeze always occurs at a point in the code with the 
 following
 statements:

 print about to try
 try:
 print in try
 do something

 I get about to try, but not in try.  Is this observation consistent
 with
 the deadlock theory?  If not, what could be making the program freeze at
 the try statement?  I wrote a test program using the same techniques to
 illustrate the problem, but the test program works perfectly.  I could
 post it, though, if it would help to understand what I am doing -- and
 what might be wrong in the real program.

 As I ponder this problem, I am beginning to believe that the problem is 
 not
 related to multithreading.  If the problem were due to a collision between
 the two threads then timing would matter, yet I find that the program
 always freezes at exactly the same statement (which executes perfectly
 hundreds of times before the freeze).  Moreover, the test program that I
 wrote to test the multithreading implementation works perfectly. And
 finally, there is nothing going on related to multithreading at this point
 in the code.  Why else might the program freeze at a try statement?
 -- 
 Jeffrey Barish


If you have one thread sleeping you need another running thread to waken up 
the sleeping thread.
If the running thread terminates unexpectedly the other thread will sleep 
forever.

Though. Since there is a try statement in your example code and the failure 
always happens there,
there might be the chance that some unexpected exception was thrown and 
cought somewhere else in your program.
If the Program is terminated, the last print might also have gone lost in 
some I/O buffer.
There is no guarantee that the print statement really wasn't executed.

Think about things like
  exception Queue.Empty
  Exception raised when non-blocking get() (or get_nowait()) is called on a 
Queue object which is empty.
  exception Queue.Full
  Exception raised when non-blocking put() (or put_nowait()) is called on a 
Queue object which is full.




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


Re: tkinter: get filename of askopenfilename

2009-06-25 Thread norseman

rom wrote:

Thanks again. After your replies, I have understood how to do what I
wanted. What I wanted to do is to get a value after clicking a button
and use it in another part of the program. As you said, after getting
the value, I have to store it in a global variable. However, the
program does not do anything with it until I trigger another event,
e.g. by clicking on another button. Therefore, I have added another
button to my program:
#
import Tkinter
import tkFileDialog

filename = 'uninitialized'

def open_file_dialog():
global filename
filename = tkFileDialog.askopenfilename(filetypes=
[(allfiles,*)])

def print_variable(variable):
print variable

root = Tkinter.Tk()
Tkinter.Button(root, text='Select file...',
command=open_file_dialog).pack()

Tkinter.Button(root, text='Print file', command=lambda: print_variable
(filename)).pack()

root.mainloop()
#


Your original, as written, would open and print immediately.  But it 
could be a problem as (or if) more code is added in that area.
This current code allows the user to open, perhaps view via other code 
and print only if wanted.


Either is OK, having both is OK, making it do what Rom wants is best. :)

If open/print was wanted, put the print statement in the open file 
button group right after the open file statement.  Anyone reading the 
code will immediately understand that is the intent. At least for that 
button.


Also it would be best to put the def statements before the button 
statements.  Actually it is best to put all defs BEFORE the GUI (frame, 
buttons, etc...) statements when using Tkinter.


The print filename statement being placed as in the original request may 
attempt to print filename after other code above it is run.  Since 
Tkinter is not a 'closed' package, that is, it's statements can be 
interspersed with program code, it is thus best to make sure what will 
and will not be triggered by other actions.  I've beat my head on that a 
few times. :)



Steve


...(snip)


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


Re: Python simple web development

2009-06-25 Thread Private Private
On Jun 25, 10:59 am, Chris Withers ch...@simplistix.co.uk wrote:
 Private Private wrote:
  from those forms, etc. I have read a bit about Django and TurboGears
  but I am afraid that this is too big for my requirements (am I
  wrong ?).

 You are wrong :-)

Why ?
What I've read about Django, Turbogears is that they are powerful
enough to create big web-based portals, applications, etc.
I need just simple forms without any sophisticated functionality.
So again: why I am wrong ?

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


3.2*2 is 9.6 ... or maybe it isn't?

2009-06-25 Thread Bojan Sudarevic
Hi,

I'm PHP developer and entirely new to Python. I installed it (version 
2.5.2, from Debian repos) today on the persuasion of a friend, who is a 
Python addict.

The first thing I typed into it was 3.2*3 (don't ask why I typed *that*, 
I don*t know, I just did). And the answer wasn't 9.6.

Here it is:

 3.2*3
9.6014

So I became curious...

 3.21*3
9.629
 (3.2*3)*2
19.203
... and so on ...

After that I tried Windows version (3.1rc2), and...

 3.2*3
9.601

I wasn't particularly good in math in school and university, but I'm 
pretty sure that 3.2*3 is 9.6.

Cheers,
Bojan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 3.2*2 is 9.6 ... or maybe it isn't?

2009-06-25 Thread Amos Anderson
I think what your experiencing is addressed on this page...

http://docs.python.org/tutorial/floatingpoint.html

... it has to do with the binary representation of the numbers.

On Thu, Jun 25, 2009 at 1:04 PM, Bojan Sudarevic bo...@sudarevic.comwrote:

 Hi,

 I'm PHP developer and entirely new to Python. I installed it (version
 2.5.2, from Debian repos) today on the persuasion of a friend, who is a
 Python addict.

 The first thing I typed into it was 3.2*3 (don't ask why I typed *that*,
 I don*t know, I just did). And the answer wasn't 9.6.

 Here it is:

  3.2*3
 9.6014

 So I became curious...

  3.21*3
 9.629
  (3.2*3)*2
 19.203
 ... and so on ...

 After that I tried Windows version (3.1rc2), and...

  3.2*3
 9.601

 I wasn't particularly good in math in school and university, but I'm
 pretty sure that 3.2*3 is 9.6.

 Cheers,
 Bojan
 --
 http://mail.python.org/mailman/listinfo/python-list

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


Re: 3.2*2 is 9.6 ... or maybe it isn't?

2009-06-25 Thread Mark Dickinson
On Jun 25, 7:04 pm, Bojan Sudarevic bo...@sudarevic.com wrote:
 Hi,

 I'm PHP developer and entirely new to Python. I installed it (version
 2.5.2, from Debian repos) today on the persuasion of a friend, who is a
 Python addict.

 The first thing I typed into it was 3.2*3 (don't ask why I typed *that*,
 I don*t know, I just did). And the answer wasn't 9.6.

 [examples snipped]

Hi Bojan,

This is a FAQ.  Take a look at:

http://docs.python.org/tutorial/floatingpoint.html

and let us know whether that explains things to your
satisfaction.

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


Re: I need a dict that inherits its mappings

2009-06-25 Thread Terry Reedy

samwyse wrote:

I need a dict-like object that, if it doesn't contain a key, will
return the value from a parent object.  Is there an easy way to do
this so I don't have to define __getitem__ and __contains__ and others
that I haven't even thought of yet?  Here's a use case, if you're
confused:

en_GB=mydict()
en_US=mydict(en_GB)

en_GB['bonnet']='part of your car'
print en_US['bonnet']  # prints 'part of your car'

en_US['bonnet']='a type of hat'
print en_US['bonnet']  # prints 'a type of hat'
print en_GB['bonnet']  # prints 'part of your car'


For that specific case:

def lookup(key):
  try: return en_US[key]
  except KeyError: return en_GB[key]

More generally,

def make_lookup_with_backup(d1, d2):
  def _l(key):
try: return d1[key]
except KeyError: return d2[key]
  return _

Terry Jan Reedy

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


Re: 3.2*2 is 9.6 ... or maybe it isn't?

2009-06-25 Thread Tomasz Zieliński
On 25 Cze, 20:04, Bojan Sudarevic bo...@sudarevic.com wrote:


 I wasn't particularly good in math in school and university, but I'm
 pretty sure that 3.2*3 is 9.6.


It's not math, it's floating point representation of numbers - and its
limited accuracy.
Type 9.6 and you'll get 9.5996

--
Tomasz Zielinski
http://pyconsultant.eu

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


Re: Problem with multithreading

2009-06-25 Thread Lou Pecora
In article h20d7k$nih$0...@news.t-online.com,
 larudwer larud...@freenet.de wrote:

 Jeffrey Barish jeff_bar...@earthlink.net schrieb im Newsbeitrag 
 news:mailman.2091.1245902997.8015.python-l...@python.org...
  Jeffrey Barish wrote:
 
  I have a program that uses multithreading to monitor two loops.  When
  something happens in loop1, it sends a message to loop2 to have it 
  execute
  a command.  loop2 might have to return a result.  If it does, it puts the
  result in a queue.  loop1, meanwhile, would have blocked waiting for
  something to appear in the queue.  The program works for a while, but
  eventually freezes.  I know that freezing is a sign of deadlock. 
  However,
  I put in print statements to localize the problem and discovered 
  something
  weird.  The freeze always occurs at a point in the code with the 
  following
  statements:
 
  print about to try
  try:
  print in try
  do something
 
  I get about to try, but not in try.  Is this observation consistent

Try putting a flush in after the 2nd print statement in case the output 
is left in some I/O buffer when the thing terminates.  e.g.

import sys



try:
   print 'in try
   sys.stdout.flush()
   do something

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


Re: 3.2*2 is 9.6 ... or maybe it isn't?

2009-06-25 Thread Emile van Sebille

On 6/25/2009 11:04 AM Bojan Sudarevic said...

snip


3.2*3

9.601

I wasn't particularly good in math in school and university, but I'm 
pretty sure that 3.2*3 is 9.6.


Yes -- in this world.  But in the inner workings of computers, 3.2 isn't
accurately representable in binary.  This is a faq.

ActivePython 2.6.2.2 (ActiveState Software Inc.) based on
Python 2.6.2 (r262:71600, Apr 21 2009, 15:05:37) [MSC v.1500 32 bit 
(Intel)] on win32

Type help, copyright, credits or license for more information.
 3.2
3.2002



Emile


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


Re: 3.2*2 is 9.6 ... or maybe it isn't?

2009-06-25 Thread Paul Rudin
Bojan Sudarevic bo...@sudarevic.com writes:

 Hi,

 I'm PHP developer and entirely new to Python. I installed it (version 
 2.5.2, from Debian repos) today on the persuasion of a friend, who is a 
 Python addict.

 The first thing I typed into it was 3.2*3 (don't ask why I typed *that*, 
 I don*t know, I just did). And the answer wasn't 9.6.

 Here it is:

 3.2*3
 9.6014

 So I became curious...

 3.21*3
 9.629
 (3.2*3)*2
 19.203
 ... and so on ...

 After that I tried Windows version (3.1rc2), and...

 3.2*3
 9.601

 I wasn't particularly good in math in school and university, but I'm 
 pretty sure that 3.2*3 is 9.6.

This is almost certainly nothing to do with python per se, but the
floating point implementation of your hardware.  Floating point
arithmetic on computers is not accurate to arbitrary precision. If you
want such precision use a library that supports it or make you own
translations to and from appropriate integer sums (but it's going to be
slower).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python simple web development

2009-06-25 Thread Chris Withers

Private Private wrote:

What I've read about Django, Turbogears is that they are powerful
enough to create big web-based portals, applications, etc.
I need just simple forms without any sophisticated functionality.
So again: why I am wrong ?


Just because something is powerful doesn't mean you can't do simple 
things with it.


Have a read of the first few chapters of the Django book...

http://www.djangobook.com/

Chris

--
Simplistix - Content Management, Zope  Python Consulting
   - http://www.simplistix.co.uk
--
http://mail.python.org/mailman/listinfo/python-list


Re: 3.2*2 is 9.6 ... or maybe it isn't?

2009-06-25 Thread Mark Dickinson
On Jun 25, 7:04 pm, Bojan Sudarevic bo...@sudarevic.com wrote:
 The first thing I typed into it was 3.2*3 (don't ask why I typed *that*,
 I don*t know, I just did). And the answer wasn't 9.6.

It looks like it's false in PHP too, by the way (not
that I know any PHP, so I could well be missing
something...)


bernoulli:py3k dickinsm$ php -a
Interactive mode enabled

?
$a = 3.2*3;
$b = 9.6;
var_dump($a);
float(9.6)
var_dump($b);
float(9.6)
var_dump($a == $b);
bool(false)


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


Re: 3.2*2 is 9.6 ... or maybe it isn't?

2009-06-25 Thread Bojan Sudarevic
In article 26be756e-5a0a-40cd-b9a2-133ce14ac7d7
@n30g2000vba.googlegroups.com, dicki...@gmail.com says...
 This is a FAQ.  Take a look at:
 
 http://docs.python.org/tutorial/floatingpoint.html
 
 and let us know whether that explains things to your
 satisfaction.
 

Hi Mark,

Yes, that explains things to my satisfation. Now I'm embarrassed that I 
didn't know that before.

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


Re: 3.2*2 is 9.6 ... or maybe it isn't?

2009-06-25 Thread Michael Torrie
Bojan Sudarevic wrote:
 The first thing I typed into it was 3.2*3 (don't ask why I typed *that*, 
 I don*t know, I just did). And the answer wasn't 9.6.
 
 Here it is:
 
 3.2*3
 9.6014

I'm surprised how often people encounter this and wonder about it.  As I
began programming back in the day using C, this is just something I grew
up with (grudging acceptance).

I guess PHP artificially rounds the results or something to make it seem
like it's doing accurate calculations, which is a bit surprising to me.
We all know that IEEE floating point is a horribly inaccurate
representation, but I guess I'd rather have my language not hide that
fact from me.  Maybe PHP is using BCD or something under the hood (slow
but accurate).

If you want accurate math, check out other types like what is in the
decimal module:

 import decimal
 a=decimal.Decimal('3.2')
 print a * 3
9.6

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


Re: scipy stats binom_test

2009-06-25 Thread Robert Kern

On 2009-06-25 07:14, dusans wrote:

Amm i using the function wrong or ...? cuz in R i get the right value


binom_test(3, 5, p=0.8)

0.262


dbinom(3, 5, 0.8)

[1] 0.205


The R equivalent of scipy.stats.binom_test() is binom.test(), not dbinom(). If 
you want the equivalent of dbinom(), use scipy.stats.binom.pmf(3,5,0.8).


If you have more scipy questions, you should ask them on the scipy mailing list:

  http://www.scipy.org/Mailing_Lists

--
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth.
  -- Umberto Eco

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


Re: 3.2*2 is 9.6 ... or maybe it isn't?

2009-06-25 Thread Robert Kern

On 2009-06-25 13:41, Michael Torrie wrote:


If you want accurate math, check out other types like what is in the
decimal module:


import decimal
a=decimal.Decimal('3.2')
print a * 3

9.6


I wish people would stop representing decimal floating point arithmetic as more 
accurate than binary floating point arithmetic. It isn't. Decimal floating 
point arithmetic does have an extremely useful niche: where the inputs have 
finite decimal representations and either the only operations are addition, 
subtraction and multiplication (e.g. many accounting problems) OR there are 
conventional rounding modes to follow (e.g. most of the other accounting problems).


In the former case, you can claim that decimal floating point is more accurate 
*for those problems*. But as soon as you have a division operation, decimal 
floating point has the same accuracy problems as binary floating point.


--
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth.
  -- Umberto Eco

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


Tkinter - non-ASCII characters in text widgets problem

2009-06-25 Thread Sebastian Pająk
Hello

I'm writing an application in Python 2.5.4 under Windows (xp sp3 en).
I use Tkinter as the main GUI toolkit. The app is intended to be
portable (not fully but win  mac os x is a must). It works as it
should on my system, but when I've sent the program to my friend who
has a mac computer, he told me accented characters are turned into
weird symbols. It is another must, the GUI consists of widgets with
polish characters. I always use UTF-8 encoding in Python and I save my
scripts in Notepad++ as UTF-8 without BOM. I've never experienced
similar problems under Windows with Tkinter before

I've created a simple test script:

CODE_START 
# -*- coding: utf-8 -*-

import sys
from Tkinter import *

root = Tk()

Label(root, text='ęóąśłżźćń').pack()
Button(root, text='ęóąśłżźćń').pack()
Entry(root).pack()

root.mainloop()
CODE_END 

No problem on Windows, but on mac Button widget has correct text.
Label and Entry has garbage instead of accented characters. (Mac OS X
10.5.6 and 10.4.11 both armed with Python 2.5.4)

I've tried various UTF file encoding (also with BOM mark), use of
utext or unicode() function - non of this worked. Googling shows not
much:

  reload(sys)
  sys.setdefaultencoding(utf-8)

or:

  root = Tk()
  root.tk.call('encoding', 'system', 'utf-8')

After applying this, the effect remains the same - one big garbage.
I'm out of ideas: my script is UTF-8 in 101%; Mac and Windows both
support UTF-8, Python also supports it - so where is the problem? How
can I show mac-users polish signs?

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


Re: Barbara Liskov wins Turing Award

2009-06-25 Thread Martin v. Löwis
 Python's object model, assignment semantics, and call-by-object
 mechanism, and that name, come from CLU.  Whether Guido knew of it
 directly or not, I do not know. To the extent that the above is part of
 the heart of Python, I think Steven's statement stands pretty well.

Why do you say that? ISTM that Python is much closer to Smalltalk than
to CLU in its object model. CLU is statically typed (and it is important
to its notion of program correctness that it is statically typed);
Smalltalk and Python aren't. In addition, Smalltalk and Python have
inheritance; CLU (deliberately) doesn't. Liskov reported that she didn't
know about Smalltalk until 1976.

I believe that Python's, CLU's, and Smalltalk's assignment semantics
actually all come from Simula. I would claim the same for the
call-by-object mechanism - except that this is probably best described
as coming from LISP (in the sense of caller and callee sharing
references).

FWIW, Simula has also inheritance, but that specific notion of
inheritance did not transfer to any other language, except for Beta.

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


Re: extending method descriptors

2009-06-25 Thread Carl Banks
On Jun 25, 8:10 am, Michael Sliczniak msliczn...@gmail.com wrote:
 Suppose I have this:

 Python 2.5.1 (r251:54863, Feb  6 2009, 19:02:12)
 [GCC 4.0.1 (Apple Inc. build 5465)] on darwin
 Type help, copyright, credits or license for more information. 
 class A(object):

 ...     __slots__ = ('x', 'y')
 ...

  a = A()
  b = A()

 So I am using descriptors (and I want to). I also would like to have
 methods A.x.foo(), A.x.bar(), A.y.foo(), and A.y.bar() and my idea was
 to extend member_descriptor, but it seems that I cannot:

  type(A.x)

 type 'member_descriptor' class my_descriptor(type(A.x)):

 ...     def foo():
 ...             return 1
 ...
 Traceback (most recent call last):
   File stdin, line 1, in module
 TypeError: Error when calling the metaclass bases
     type 'member_descriptor' is not an acceptable base type


The question isn't too clear, but I can explain this error message.

A Python type defined in C must have Py_TP_BASETYPE set in its
tp_flags field, otherwise subclassing it isn't happening.

If you want such functionality, I believe it would be easiest have to
implement a MemberDescriptorWrapper class in Python that delegates to
the actual member_descriptor.  You would use it something like this:

class A(object):
__slots__ = ['_x_internal','_y_internal']
x = MemberDescriptorWrapper('_x_internal')
y = MemberDescriptorWrapper('_y_internal')

MemberDescriptorWrapper class would have to implement __get__,
__set__, and __del__ methods and have them call the corresponding
methods on the slot; details are left as an exercise.


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


Re: 3.2*2 is 9.6 ... or maybe it isn't?

2009-06-25 Thread Mark Dickinson
On Jun 25, 7:41 pm, Michael Torrie torr...@gmail.com wrote:
 I guess PHP artificially rounds the results or something to make it seem
 like it's doing accurate calculations, which is a bit surprising to me.

After a bit of experimentation on my machine, it *looks* as though PHP
is using the usual hardware floats internally (no big surprise there),
but implicit conversions to string use 14 significant digits.  If
Python's repr used '%.14g' internally instead of '%.17g' then we'd see
pretty much the same thing in Python.

 We all know that IEEE floating point is a horribly inaccurate
 representation [...]

That's a bit extreme!  Care to elaborate?

, but I guess I'd rather have my language not hide that
 fact from me.  Maybe PHP is using BCD or something under the hood (slow
 but accurate).

 If you want accurate math, check out other types like what is in the
 decimal module:

As Robert Kern already said, there really isn't any sense in which
decimal
floating-point is any more accurate than binary floating-point, except
that---somewhat tautologically---it's better at representing decimal
values exactly.

The converse isn't true, though, from a numerical perspective: there
are some interesting examples of bad things that can happen with
decimal floating-point but not with binary.  For example, given any
two Python floats a and b, and assuming IEEE 754 arithmetic with
default rounding, it's always true that a = (a+b)/2 = b, provided
that a+b doesn't overflow.  Not so for decimal floating-point:

 import decimal
 decimal.getcontext().prec = 6 # set working precision to 6 sig figs
 (decimal.Decimal('7.12346') + decimal.Decimal('7.12348'))/2
Decimal('7.12345')

Similarly, sqrt(x*x) == x is always true for a positive IEEE 754
double x (again
assuming the default roundTiesToEven rounding mode, and assuming that
x*x neither overflows nor underflows).  But this property fails for
IEEE 754-compliant decimal floating-point.

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


Re: Slow wxPyhon on Vista?

2009-06-25 Thread Martin Schöön
David Lyon david.l...@preisshare.net writes:

 On Fri, 19 Jun 2009 10:16:39 +0200, martin.sch...@gmail.com (Martin
 Schöön) wrote:
 Here is my problem. When I use it on a Vista box its
 user interface is very, very slow when it comes to
 some but not all operations. On any other Windows
 version it reacts instantaneously. I have not tried
 Task Coach on Linux or Solaris (yet).
 
 Is this how wxPython or Python works on Vista in
 general or is this the result of some local oddity on my
 employer's Vista configuration?

 I have encountered the same thing on XP in one instance
 on a development box. For some reason, wxpython just
 grinds to a halt.

 I couldn't solve it and reimaged the O/S... that
 fixed it...

Reimaged?

Since my first post on this I have installed the very latest
version of Task Coach and Vista has been through an SP1 install.

The GUI speed issue remains despite this.

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


py2exe: some problems

2009-06-25 Thread gianbrix

Hi,
I am trying to get an exe file using py2exe with one my application.
If I let all in the same main folder it works fine.
If I set zipfile=bin\\myapp.zip I get some errors like this:
unable to load dlls: relating to win32gui or win32print etc.
What is wrong?
There is a way to have zipfile set to None and move the pyds and dlls in 
the bin folder?

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


Re: Problem with multithreading

2009-06-25 Thread Jeffrey Barish
Lou Pecora wrote:

 In article h20d7k$nih$0...@news.t-online.com,
  larudwer larud...@freenet.de wrote:
 
 Jeffrey Barish jeff_bar...@earthlink.net schrieb im Newsbeitrag
 news:mailman.2091.1245902997.8015.python-l...@python.org...
  Jeffrey Barish wrote:
 
  I have a program that uses multithreading to monitor two loops.  When
  something happens in loop1, it sends a message to loop2 to have it
  execute
  a command.  loop2 might have to return a result.  If it does, it puts
  the
  result in a queue.  loop1, meanwhile, would have blocked waiting for
  something to appear in the queue.  The program works for a while, but
  eventually freezes.  I know that freezing is a sign of deadlock.
  However,
  I put in print statements to localize the problem and discovered
  something
  weird.  The freeze always occurs at a point in the code with the
  following
  statements:
 
  print about to try
  try:
  print in try
  do something
 
  I get about to try, but not in try.  Is this observation
  consistent
 
 Try putting a flush in after the 2nd print statement in case the output
 is left in some I/O buffer when the thing terminates.  e.g.
 
 import sys
 
 
 
 try:
print 'in try
sys.stdout.flush()
do something
 

I was hoping for some suggestions of things to think about, so thanks
especially to those who had such suggestions.  Believe it or not (and I'm
having trouble believing it myself), I didn't think to use flush.  When I
did, I found that, indeed, the program did progress past the try statement. 
It made it to a call to GStreamer (playbin2), which has been proving itself
intractable in my experience.  Note that my test program (which works)
excised GStreamer.  The next step will be to try again to compile the
latest version of PyGST as the version in Ubuntu 9.04 is one generation
old.  The last time I tried, the compile failed.  This is the first time in
days that I have had any hope.
-- 
Jeffrey Barish

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


Re: trace options

2009-06-25 Thread Terry Reedy

Edward Peschko wrote:

All,

I've been looking at the trace module, and although it looks useful, I'm
surprised that there aren't a couple of features that I would have thought
would be fairly basic. So, does trace support (for the --trace option):


I have never used the trace module but decided to try it out, following 
the simple example in the docs with a simple function. It seems a bit 
underdocumented, so I presume help with that would be welcome. I also 
found deficiencies in the operation, though different from you.



   - indentation tracking stacklevel (where each function is prefixed
 by tabs equal to the number of stacklevels deep in the program)


Trace already does one space indents for modules after the first

 --- modulename: threading, funcname: settrace
  --- modulename: compare, funcname: lt_iw

and lines after the first

compare.py(47): while m != 0 and n != 0:
 compare.py(48): m, n = m-1, n-1

That would have to be eliminated, at least when stack indents were on.
Tabs are nasty when interpreted as 8 chars. If added, the user should 
specify the indent: indent = '  ', for instance, for 2 space indents.



   - output to something other than sys.stdout (eg. output to a file
 specified either by environmental variable or by parameter).


That seems reasonable.  It also seems reasonable that I be able to write 
counts *to* stdout (the screen) when running interactive. But

when I changed
  r.write_results(show_missing=True, coverdir=/tmp)
in the doc example to just
  r.write_results()
I got nothing, rather than the line-by-line count I expected.  A bug?

On the other hand,
  r.write_results(summary=True)
did give output - the coverage for the module, which was not helpful.
This was so with both run('func(args)') and runfunc(func, args)
Coverage should be by function, I think, especially with runfunc.


   - mult-threaded programs going to multiple output handles,
 especially in light of the above

   - fully qualified python modules in path: (eg:

 /path/to/module/my_module.py(1): print HERE

 instead of

   my_module.py(1): print HERE.


I think a full name in the modulename line would be good, but full names 
in the trace lines would be awful.  In fact, I would prefer no name, 
and, especially when using runfunc, line numbers relative to the 
function rather than the module. Also remove the silly indent. So I 
would like


 --- modulename: compare, funcname: lt_iw
compare.py(47): while m != 0 and n != 0:
 compare.py(48): m, n = m-1, n-1

changed to

Modulename: path/compare, funcname: lt_iw
  1: while m != 0 and n != 0:
  2: m, n = m-1, n-1


Ultimately, I'd like to be able to look at two runs of a program
and be able to pinpoint the very first difference
between thembased on the output of their trace runs. As it
stands, I really can't do this.


When I trace a function mentally, to write or debug, I keep track of the 
values of the local names.  Perhaps trace was not meant for this. 
However, if I were modifying trace, the first thing I would add would be 
the ability to print variable values with each line executed.



Of course I could implement the above, but I was
hoping to avoid duplicated effort if someone has
already implemented options like this..I posted the above to
the python-dev list, they suggested I take it here, so any help
would be appreciated.


I searched http://pypi.python.org/pypi for 'trace' and did not see 
anything obvious.  If you do modify trace and your changes are not 
immediately accepted, you could list your version on PyPI.  In fact, 
that might be the best way to get them in.  Of course, one problem you 
can see from the above is that different people will have different 
ideas on what constitutes 'better' ;-).


Terry Jan Reedy

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


Re: Tkinter - non-ASCII characters in text widgets problem

2009-06-25 Thread Martin v. Löwis
 I've tried various UTF file encoding (also with BOM mark), use of
 utext

Always use utext. This should work. Everything else might not work.

 After applying this, the effect remains the same - one big garbage.

Can you please be more specific? What is one big garbage?

 I'm out of ideas: my script is UTF-8 in 101%; Mac and Windows both
 support UTF-8, Python also supports it - so where is the problem? 

Most likely, Tk does not work correctly on your system. See whether
you can get correct results with wish.

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


Re: print u'\u2013' error on console/terminal

2009-06-25 Thread Martin v. Löwis
 is there a switch to suppress those encoding errors for standard print's
 on the console

No, there is no such switch.

 or a new filter file class necessary?

You can wrap sys.stdout with a codecs.StreamWriter, passing replace
as the error handler.

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


Re: Tkinter - non-ASCII characters in text widgets problem

2009-06-25 Thread Sebastian Pająk
2009/6/25 Martin v. Löwis mar...@v.loewis.de:
 I've tried various UTF file encoding (also with BOM mark), use of
 utext

 Always use utext. This should work. Everything else might not work.

But I tried this here without success

 After applying this, the effect remains the same - one big garbage.

 Can you please be more specific? What is one big garbage?


There is a square (or some other weird sign) in place where polish
accented character should be (like ęłąśł etc)
This problem is only on mac os x and it doesn't apply to button widget
(where characters are correct)

 I'm out of ideas: my script is UTF-8 in 101%; Mac and Windows both
 support UTF-8, Python also supports it - so where is the problem?

 Most likely, Tk does not work correctly on your system. See whether
 you can get correct results with wish.


There is no wish. I'm talking about build-in Tkinter (isn't Tk
build-in Python?).

btw. I'm workin on Windows, my friend on Mac - he points me the
problem he has with my script. He is not a computer geek nor a
programmer - he even doesn't know what wish/Tk or Python is


Does different endianness can have something to do here?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Gimp-user] Color change a whole range based on a break point

2009-06-25 Thread norseman
I know I'm not the only one that does archival scanning and 
georefferencing of old maps.


What follows is the combined conversations between myself 
(norse...@hughes.net and saulgo...@flashingtwelve.brickfilms.com) that 
lead to getting what is needed for the above process when working with 
sources that are copies made with the Sepia process of old (before 
Xerox copiers). Namely; a clean raster.  For non-sepia source I use 
GIMP-Colors-Levels and get excellent results with minor effort.



1)  original request and reply
  Wanted:
   In Gimp, to add (SUM) the RGB values for a pixel and then
  change all pixels who's RGB SUM is greater than a user stated value
  to WHITE.
  Second side of that is to change all RGB SUMs less than value given 
to Black. BUT not doing both at same time, thus allowing user to step

  in and see what got lost.

* Duplicate the layer.
* Desaturate the duplicate using the Average method.
* Add layermask to the duplicate using the
   Initialize to: Grayscale Copy of Layer option.
* Bucket fill the duplicate layer with white.
* Run Colors-Threshold on the layermask, setting
   the value appropriately.
* Bucket fill your original layer with black.

2) starting round 2
Quoting norseman norse...@hughes.net:

 I understand the idea. I am not getting any usable results.

 If I cut out a small piece of a project raster and send it to you
 would you have the time to try your idea(s) on it?

That would be fine. Perhaps I misinterpreted what you are trying to 
accomplish.


3) closing results
As often happens, just as one is ready to quit, the unexpected happens.

I went back to your idea of Desaturate and Threshold and tried them 
without doing the layer/fill parts. (keep original, save as newname the 
modified)  Success!


What I have is 45 year old sepias of USGS 7.5 minute Topo Quads with 
inked lines drawn on the sepia.  They have 'faded' and the surface has 
corroded and some has rubbed off onto the inked lines originally drawn 
on them. Thus the black lines are tainted with color. The rest of the 
sepia is like any other old sepia. It is trying to become all one color 
- very dark sepia. :)


What I did was try your idea of Desaturate (I settled on the Lightness 
setting) and then used Threshold (left or 'black' side set to 50 +/- and 
right or white side set to 200 to 220) and BINGO! -- I get what I want! 
The sepia (very nearly 100%) turns white and the inked lines are dark 
enough for further processing. Final manual touch-up prior to 
vectorizing will be very minor. Manually doing the major cleanup is less 
than 60 seconds per sheet. Majority of sheets take less than 30 seconds. 
Anticipate individual settings and times to vary with source conditions. :)


Final product is to be inked lines converted to georefferenced vectors.


side note:  the 'small sample' I had clipped out was small compared to 
the original sheet but it was still 25 megabytes AFTER LZW compression!
The original sheets are 200 megabytes each in uncompressed RGB Tiff. A 
totally manual cleanup of originals is definitely an unwanted task.



GIMP: 2.6.6
OS  : Window$ XP PRO
As of writing, I have not tested on Linux but I do expect same results.

Sincerely - I do appreciate your help.


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


Re: Python simple web development

2009-06-25 Thread Gabriel Genellina

En Thu, 25 Jun 2009 04:29:28 -0300, Private Private mail...@gmail.com
escribió:


I am looking for a python library which will allow me to do a simple
web development. I need to use
some forms (but nice looking :-) ), creating images based on input
from those forms, etc. I have read a bit about Django and TurboGears
but I am afraid that this is too big for my requirements (am I
wrong ?).
Can you suggest anything ?


You may try pesto: http://pesto.redgecko.org/

pesto is a very small framework (45k to download!), WSGI compliant,
includes session management, mapping URL-function, caching, templates
(optional, whichever you like). Minimalist but flexible.

Anyway, learning to use Django isn't a bad idea.

--
Gabriel Genellina

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


Re: C-extension 2 times slower than exe

2009-06-25 Thread Nick Craig-Wood
Rolf Wester rolf.wes...@ilt.fraunhofer.de wrote:
  Hello,
 
  thank you all very much for your replies.
 
  I tried to simplify things and make the two versions as comparable as
  possible. I put the C++ part of the program into a shared object
  libff.so. For the exe the main function is linked against this shared
  object. For the python stuff I made an interface consiting of only one
  function call_solver with the same code that has the main function used
  for the exe. Then I created a wrapper for this interface using swig and
  linked interface.o, ff_warp.o and libff.so into _ff.so. The Python code
  just imports _ff and calls call_solver wich creates an object of the
  class Solver and calls its member solve (the main function of the exe
  does the same).
 
  I included some code for timing into the C++-code.
 
  #include time.h
 
  //beginning of solve
  clock_t t0 = clock();
  ...
  clock_t t1 = clock();
  //end of solve
  cout  time used =   (t1-t0)/CLOCKS_PER_SEC  endl;
 
  I'm using gcc4.5 (latest snapshot) and Python2.6 under Suse 10.3. The
  sources are compiled using the flags -fPIC -O3.
 
  Timing:
 
  1) time python ff.py
  time used = 3.74
  real0m3.234s
  user0m3.712s
  sys 0m0.192s

Those times look odd because the user time is  than the real time.

User time is number of CPU seconds used.  Real time is wallclock time.

That must mean
a) your program is threading
b) there is something up with timing on your computer

Looks odd but exactly what it means I don't know!

  2) time ff
  time used = 2.19
  real0m3.170s
  user0m2.088s
  sys 0m0.168s

-- 
Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter - non-ASCII characters in text widgets problem

2009-06-25 Thread MRAB

Sebastian Pająk wrote:

2009/6/25 Martin v. Löwis mar...@v.loewis.de:

I've tried various UTF file encoding (also with BOM mark), use of
utext

Always use utext. This should work. Everything else might not work.


But I tried this here without success


After applying this, the effect remains the same - one big garbage.

Can you please be more specific? What is one big garbage?



There is a square (or some other weird sign) in place where polish
accented character should be (like ęłąśł etc)
This problem is only on mac os x and it doesn't apply to button widget
(where characters are correct)


I'm out of ideas: my script is UTF-8 in 101%; Mac and Windows both
support UTF-8, Python also supports it - so where is the problem?

Most likely, Tk does not work correctly on your system. See whether
you can get correct results with wish.



There is no wish. I'm talking about build-in Tkinter (isn't Tk
build-in Python?).

btw. I'm workin on Windows, my friend on Mac - he points me the
problem he has with my script. He is not a computer geek nor a
programmer - he even doesn't know what wish/Tk or Python is


Does different endianness can have something to do here?


In summary:

You're providing the same text for a Button and a Label. On Mac OSX the
Button shows the text correctly, but the Label doesn't.

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


Re: Tkinter - non-ASCII characters in text widgets problem

2009-06-25 Thread norseman

Sebastian Pająk wrote:

2009/6/25 Martin v. Löwis mar...@v.loewis.de:

I've tried various UTF file encoding (also with BOM mark), use of
utext

Always use utext. This should work. Everything else might not work.


But I tried this here without success


After applying this, the effect remains the same - one big garbage.

Can you please be more specific? What is one big garbage?



There is a square (or some other weird sign) in place where polish
accented character should be (like ęłąśł etc)
This problem is only on mac os x and it doesn't apply to button widget
(where characters are correct)


I'm out of ideas: my script is UTF-8 in 101%; Mac and Windows both
support UTF-8, Python also supports it - so where is the problem?

Most likely, Tk does not work correctly on your system. See whether
you can get correct results with wish.



There is no wish. I'm talking about build-in Tkinter (isn't Tk
build-in Python?).

btw. I'm workin on Windows, my friend on Mac - he points me the
problem he has with my script. He is not a computer geek nor a
programmer - he even doesn't know what wish/Tk or Python is


Does different endianness can have something to do here?


Can, but should not.
I read that the problem is when using the Polish language only. 
Otherwise things work normally. Is that correct?
If so then byte swap may be a problem.  Using the u'string' should solve 
that. I am assuming you have the Polish alphabet working correctly on 
your machine. I think I read that was so in an earlier posting.


Are there any problems with his alphabet scrambling on your machine?
If so that needs investigating.  Here I assume you are reading Polish 
from him on your machine and not a network translator version.



No - Tkinter is not built in. tkinter is a module shipped with Python 
for people to use. (Tk interface)  use:  import tkinter


From Google:
Tkinter Life Preserver
Tkinter is a Python interface to the Tk GUI toolkit.
This document is not designed to be an exhaustive tutorial on either Tk 
or Tkinter. ...www.python.org/doc/life-preserver/


more properly   Tcl/Tk
see alsowww.tcl.tk



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


Re: Problem with multithreading

2009-06-25 Thread MRAB

Jeffrey Barish wrote:
[snip]


Lou Pecora wrote:


Try putting a flush in after the 2nd print statement in case the output
is left in some I/O buffer when the thing terminates.  e.g.

import sys



try:
   print 'in try
   sys.stdout.flush()
   do something



I was hoping for some suggestions of things to think about, so thanks
especially to those who had such suggestions.  Believe it or not (and I'm
having trouble believing it myself), I didn't think to use flush.  When I
did, I found that, indeed, the program did progress past the try statement. 
It made it to a call to GStreamer (playbin2), which has been proving itself

intractable in my experience.  Note that my test program (which works)
excised GStreamer.  The next step will be to try again to compile the
latest version of PyGST as the version in Ubuntu 9.04 is one generation
old.  The last time I tried, the compile failed.  This is the first time in
days that I have had any hope.


On occasion I've needed to debug a program that's crashing, and I've
found it best to open the log file unbuffered, otherwise I lose the
final log messages. It saves me from having to flush each message
explicitly.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter - non-ASCII characters in text widgets problem

2009-06-25 Thread Sebastian Pająk
 Can, but should not.
 I read that the problem is when using the Polish language only. Otherwise
 things work normally. Is that correct?

Yes, correct

 If so then byte swap may be a problem.  Using the u'string' should solve
 that. I am assuming you have the Polish alphabet working correctly on your
 machine. I think I read that was so in an earlier posting.

 Are there any problems with his alphabet scrambling on your machine?
 If so that needs investigating.  Here I assume you are reading Polish from
 him on your machine and not a network translator version.


The original thread is here:
http://mail.python.org/pipermail/python-list/2009-June/717666.html
I've explained the problem there
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C-extension 2 times slower than exe

2009-06-25 Thread MRAB

Nick Craig-Wood wrote:

Rolf Wester rolf.wes...@ilt.fraunhofer.de wrote:

 Hello,

 thank you all very much for your replies.

 I tried to simplify things and make the two versions as comparable as
 possible. I put the C++ part of the program into a shared object
 libff.so. For the exe the main function is linked against this shared
 object. For the python stuff I made an interface consiting of only one
 function call_solver with the same code that has the main function used
 for the exe. Then I created a wrapper for this interface using swig and
 linked interface.o, ff_warp.o and libff.so into _ff.so. The Python code
 just imports _ff and calls call_solver wich creates an object of the
 class Solver and calls its member solve (the main function of the exe
 does the same).

 I included some code for timing into the C++-code.

 #include time.h

 //beginning of solve
 clock_t t0 = clock();
 ...
 clock_t t1 = clock();
 //end of solve
 cout  time used =   (t1-t0)/CLOCKS_PER_SEC  endl;

 I'm using gcc4.5 (latest snapshot) and Python2.6 under Suse 10.3. The
 sources are compiled using the flags -fPIC -O3.

 Timing:

 1) time python ff.py
 time used = 3.74
 real0m3.234s
 user0m3.712s
 sys 0m0.192s


Those times look odd because the user time is  than the real time.

User time is number of CPU seconds used.  Real time is wallclock time.

That must mean
a) your program is threading
b) there is something up with timing on your computer

Looks odd but exactly what it means I don't know!


 2) time ff
 time used = 2.19
 real0m3.170s
 user0m2.088s
 sys 0m0.168s



Perhaps multithreading on dual cores?
--
http://mail.python.org/mailman/listinfo/python-list


Re: 3.2*2 is 9.6 ... or maybe it isn't?

2009-06-25 Thread Scott David Daniels

Robert Kern wrote:
... I wish people would stop representing decimal floating point arithmetic 
as more accurate than binary floating point arithmetic. It isn't. 
Decimal floating point arithmetic does have an extremely useful niche: 
...

Well, we don't actually have an arbitrary-precision, huge exponent
version of binary floating point.  In that sense the Decimal floating
point beats it.  Not that it would be too hard to have such a floating
point in Python (long for mantissa, int for exponent, ...), but we don't
in fact have such a module in place.

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: 3.2*2 is 9.6 ... or maybe it isn't?

2009-06-25 Thread Robert Kern

On 2009-06-25 18:43, Scott David Daniels wrote:

Robert Kern wrote:

... I wish people would stop representing decimal floating point
arithmetic as more accurate than binary floating point arithmetic.
It isn't. Decimal floating point arithmetic does have an extremely
useful niche: ...

Well, we don't actually have an arbitrary-precision, huge exponent
version of binary floating point.


You may not. I do.

  http://code.google.com/p/mpmath/

--
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth.
  -- Umberto Eco

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


Re: Meta question: disappearing posts (was Re: calculating aself.value, self.randomnum = normalvariate(x, y))

2009-06-25 Thread Aahz
In article mailman.2045.1245831161.8015.python-l...@python.org,
Hendrik van Rooyen m...@microcorp.co.za wrote:

I have lately had some posts returned with a seems to be forged message.
Two reasons for that:
- first is if I use the smtp server from our local telco - saix - then there is
  no apparent relationship between where the message comes from and
  where it comes from, if you follow my Irish...
- Second is if the same telco assigns me an IP that has been put on a list
  of bad boy IPs.

So it is kind of pot luck if you see this message or not.

Sorry, didn't see it.  ;-)
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

as long as we like the same operating system, things are cool. --piranha
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 3.2*2 is 9.6 ... or maybe it isn't?

2009-06-25 Thread Mensanator
On Jun 25, 6:43 pm, Scott David Daniels scott.dani...@acm.org wrote:
 Robert Kern wrote:
  ... I wish people would stop representing decimal floating point arithmetic
  as more accurate than binary floating point arithmetic. It isn't.
  Decimal floating point arithmetic does have an extremely useful niche:
  ...

 Well, we don't actually have an arbitrary-precision, huge exponent
 version of binary floating point.  In that sense the Decimal floating
 point beats it.  Not that it would be too hard to have such a floating
 point in Python (long for mantissa, int for exponent, ...), but we don't
 in fact have such a module in place.

We have the gmpy module which can do arbitray precision floats.

 gmpy.pi(600)
mpf
('3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446e0',
600)


 --Scott David Daniels
 scott.dani...@acm.org

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


Re: 3.2*2 is 9.6 ... or maybe it isn't?

2009-06-25 Thread Aahz
In article q_2dnqkbe7ywl9nxnz2dnuvz_iydn...@pdx.net,
Scott David Daniels  scott.dani...@acm.org wrote:

Well, we don't actually have an arbitrary-precision, huge exponent
version of binary floating point.  

gmpy?
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

as long as we like the same operating system, things are cool. --piranha
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 3.2*2 is 9.6 ... or maybe it isn't?

2009-06-25 Thread Robert Kern

On 2009-06-25 18:43, Scott David Daniels wrote:

Robert Kern wrote:

... I wish people would stop representing decimal floating point
arithmetic as more accurate than binary floating point arithmetic.
It isn't. Decimal floating point arithmetic does have an extremely
useful niche: ...

Well, we don't actually have an arbitrary-precision, huge exponent
version of binary floating point. In that sense the Decimal floating
point beats it.


And while that's true, to a point, that isn't what Michael or the many others 
are referring to when they claim that decimal is more accurate (without any 
qualifiers). They are misunderstanding the causes and limitations of the example 
3.2 * 3 == 9.6. You can see a great example of this in the comparison between 
new Cobra language and Python:


  http://cobra-language.com/docs/python/

In that case, they have a fixed-precision decimal float from the underlying .NET 
runtime but still making the claim that it is more accurate arithmetic. While 
you may make (completely correct) claims that decimal.Decimal can be more 
accurate because of its arbitrary precision capabilities, this is not the claim 
others are making or the one I am arguing against.


--
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth.
  -- Umberto Eco

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


Re: Tkinter - non-ASCII characters in text widgets problem

2009-06-25 Thread norseman

Sebastian Pająk wrote:

Can, but should not.
I read that the problem is when using the Polish language only. Otherwise
things work normally. Is that correct?


Yes, correct


If so then byte swap may be a problem.  Using the u'string' should solve
that. I am assuming you have the Polish alphabet working correctly on your
machine. I think I read that was so in an earlier posting.

Are there any problems with his alphabet scrambling on your machine?
If so that needs investigating.  Here I assume you are reading Polish from
him on your machine and not a network translator version.



The original thread is here:
http://mail.python.org/pipermail/python-list/2009-June/717666.html
I've explained the problem there


I re-read the posting. (Thanks for the link)

You do not mention if he has sent you any Polish words and if they
appear OK on your machine.

A note here:  In reading the original posting I get symbols that are not
familiar to me as alphabet.
From the line in your original:
 Label(root, text='ęóąśłżźćń').pack()
I see text='
   then an e with a goatee
a  capitol O with an accent symbol on top (')
an a with a tail on the right
a  s with an accent on top
an I do no not know what - maybe some sort of l with a
   slash through the middle
a  couple of z with accents on top
a  capitol C with an accent on top
a  n with a short bar on top

I put the code into python and took a look.



I get:
cat xx

# -*- coding: utf-8 -*-

import sys
from Tkinter import *

root = Tk()

Label(root, text='\u0119ó\u0105\u015b\u0142\u017c\u017a\u0107\u0144').pack()
Button(root,
text='\u0119ó\u0105\u015b\u0142\u017c\u017a\u0107\u0144').pack()
Entry(root).pack()

root.mainloop()

Then:
python xx
  File xx, line 10
SyntaxError: Non-ASCII character '\xf3' in file xx on line 10, but no
encoding declared; see http://www.python.org/peps/pep-0263.html for details

So I did.
It notes Window$ puts things into those lines. Namely:
To aid with platforms such as Windows, which add Unicode BOM marks
to the beginning of Unicode files, the UTF-8 signature
'\xef\xbb\xbf' will be interpreted as 'utf-8' encoding as well
(even if no magic encoding comment is given).


Then I took out the o with the accent and re-ran the file.

Everything works except the text is exactly as shown above. That is:
\u0119ó\u0105\u015b\u0142\u017c\u017a\u0107\u0144
(shows twice as directed, one for label, one for button, no apostrophes)

OK - now I take a look at what in actually in the file.
in MC on Linux Slackware 10.2 I read, in the mail folder,
0119 capitol A with a tilde on top.
HEX readings beginning at the 0119\...
30 31 31 39 C3 B3 5C

but in the python file xx, I read:
30 31 31 39 5C
0119\...

I would have to say the mail system is screwing you up.  Might try 
zipping the file and sending it that way and see if problem changes.



Steve

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


Re: Tkinter - non-ASCII characters in text widgets problem

2009-06-25 Thread Martin v. Löwis
 After applying this, the effect remains the same - one big garbage.
 Can you please be more specific? What is one big garbage?

 
 There is a square (or some other weird sign)

***PLEASE*** be specific. A square box is something *completely*
different than any other weird sign. It is impossible to understand
the problem if you don't know *exactly* what happens.

 in place where polish
 accented character should be (like ęłąśł etc)
 This problem is only on mac os x and it doesn't apply to button widget
 (where characters are correct)

I see. So it is a font problem: if the square box is displayed, it means
that the font just doesn't have a glyph for the character you want to
display. Try using a different font in the label widget.

 There is no wish. I'm talking about build-in Tkinter

So try installing Tk separately.

 (isn't Tk build-in Python?).

Depends on where exactly you got your Python from, and what exactly
is your OSX version. Recent releases of OSX include a copy of Tcl/Tk,
and some sets of Python binaries link against the Apple Tk.

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


ElementTree.XML(string XML) and ElementTree.fromstring(string XML) not working

2009-06-25 Thread Kee Nethery
Summary: I have XML as string and I want to pull it into ElementTree  
so that I can play with it but it is not working for me. XML and  
fromstring when used with a string do not do the same thing as parse  
does with a file. How do I get this to work?


Details:
I have a CGI that receives XML via an HTTP POST as a POST variable  
named 'theXml'. The POST data is a string that the CGI receives, it is  
not a file on a hard disk.


The POSTed string looks like this when viewed in pretty format:

xml
purchase id=1 lang=en
item id=1 productId=369369
nameAutumn/name
quantity1/quantity
price8.46/price
/item
javascriptYES/javascript
/purchase
customer id=123456 time=1227449322
shipping
street19 Any Street/street
cityBerkeley/city
stateCalifornia/state
zip12345/zip
countryPeople's Republic of Berkeley/country
nameJon Roberts/name
/shipping
emailju...@shrimp.edu/email
/customer
/xml


The pseudocode in Python 2.6.2 looks like:

import xml.etree.ElementTree as et

formPostData = cgi.FieldStorage()
theXmlData = formPostData['theXml'].value
theXmlDataTree = et.XML(theXmlData)

and when this runs, theXmlDataTree is set to:

theXmlDataTree  instanceElement xml at 7167b0
attrib  dict{}
tag str xml
tailNoneTypeNone
textNoneTypeNone

I get the same result with fromstring:

formPostData = cgi.FieldStorage()
theXmlData = formPostData['theXml'].value
theXmlDataTree = et.fromstring(theXmlData)

I can put the xml in a file and reference the file by it's URL and use:

et.parse(urllib.urlopen(theUrl))

and that will set theXmlDataTree to:

theXmlDataTree	instance	xml.etree.ElementTree.ElementTree instance at  
0x67cb48


This result I can play with. It contains all the XML.

et.parse seems to pull in the entire XML document and give me  
something to play with whereas et.XML and et.fromstring do not.


Questions:
How do I get this to work?
Where in the docs did it give me an example of how to make this work  
(what did I miss from reading the docs)?


... and for bonus points ...

Why isn't et.parse the only way to do this? Why have XML or fromstring  
at all? Why not enhance parse and deprecate XML and fromstring with  
something like:


formPostData = cgi.FieldStorage()
theXmlData = formPostData['theXml'].value
theXmlDataTree =  
et 
.parse 
(makeThisUnicodeStringLookLikeAFileSoParseWillDealWithIt(theXmlData))


Thanks in advance,
Kee Nethery
--
http://mail.python.org/mailman/listinfo/python-list


  1   2   >