Re: pynguin-0.13 python turtle graphics application now uses python 3

2013-03-17 Thread rusi
On Mar 17, 5:12 am, Lee Harr  wrote:
> Pynguin is a python-based turtle graphics application.
>     It combines an editor, interactive interpreter, and
>     graphics display area.


What does pynguin have that the builting python turtle does not?
http://docs.python.org/2/library/turtle.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What's the easiest Python datagrid GUI (preferably with easy database hooks as well)?

2013-03-17 Thread Sibylle Koczian

Am 16.03.2013 21:30, schrieb Wolfgang Keller:

Will look at Pypapi and SQLkit.


Did look: SQLkit needs Python 2. Pypapi, from the link you gave: "The 
new release of PyPaPi is written in Java. You can find more info in the 
official site." On this official site - http://www.pypapi.org/ - I can't 
find anything at all about using PyPaPi with Python.



Frustrated with Dabo? Why?

First and main reason: just because for my needs it's the _only_ package 
that still forces me to keep a Python 2 installation.


Second reason: too often things suddenly break that worked before. 
Writing to the Dabo list always helps, usually quite quickly, and that 
list really is one of the friendliest and most helpful I know, but still 
it's tiresome. Possibly I wouldn't care if English were my native 
language, but it isn't and so writing to the list is work and no fun.


Sincerely
Sibylle


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


Top 10 python features

2013-03-17 Thread Albert Vonpupp
Hello pythonistas,

I'm new to python and so far I'm really enjoying learning it.

I would like to know what are the top 10 most important features (on your 
opinion) in python.

I have to prepare a presentation on that and this is a very good chance to 
learn something new to me as well.

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


Re: Top 10 python features

2013-03-17 Thread Miki Tebeka
> I would like to know what are the top 10 most important features (on your 
> opinion) in python.
You're in luck :) Raymond Hettinger just gave "Python is Awesome" keynote at 
PyCon. You can view the slides at 
https://speakerdeck.com/pyconslides/pycon-keynote-python-is-awesome, video will 
follow - not sure when.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Top 10 python features

2013-03-17 Thread Peter Otten
Albert Vonpupp wrote:

> Hello pythonistas,
> 
> I'm new to python and so far I'm really enjoying learning it.
> 
> I would like to know what are the top 10 most important features (on your
> opinion) in python.
> 
> I have to prepare a presentation on that and this is a very good chance to
> learn something new to me as well.

Amongst our weapons are

- Generators
- Duck-Typing
- The Interactive Interpreter

and an almost fanatical devotion to the Zen.

Wait, I forgot dictionaries; it's dictionaries all the way down...

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


How to make a Python script to audio read a text file on phone ?

2013-03-17 Thread Nic
I've installed Python on my Nokia E71 (Symbian S60 3rd FP1) and found a script 
example which can read out text, see example below.
 I want to make the script to asks me for a text file instead and then reads 
out the content. I guess it works with a .txt file, dont know if other formats 
work.  Regards!


[Quote]

# Copyright (c) 2006 Jurgen Scheible
# This script performs a query with a single-field dialog (text input field)
# and lets the phone speak out the text (text to speech) that the users have 
typed in
# NOTE: this script runs only with Python S60 version 3.1.14 or above
# NOTE: this script doesn't work on all S60 phones neccessarily. Check your 
phone model if it has text to speech capability at all

import appuifw
import audio

text = appuifw.query(u"Type a word:", "text")
audio.say(text)

[End Quote]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Top 10 python features

2013-03-17 Thread Chris Angelico
On Mon, Mar 18, 2013 at 1:09 AM, Peter Otten <__pete...@web.de> wrote:
> Albert Vonpupp wrote:
>
>> I would like to know what are the top 10 most important features (on your
>> opinion) in python.
>
> Amongst our weapons are
>
> - Generators
> - Duck-Typing
> - The Interactive Interpreter
>
> and an almost fanatical devotion to the Zen.
>
> Wait, I forgot dictionaries; it's dictionaries all the way down...

That's five. Here's five more:

* No variable declarations - keep your code simple
* An *extensive* standard library
* comp.lang.python / python-list, Python help 24/7!
* Active development and constant improvements
* Strong OS/platform support (many Linuxes have at least some version
of Python either already installed or in the standard repository;
Windows and Mac OS have ready-to-go binaries available on python.org;
there are Pythons for various mobile platforms; even relative
obscurities like OS/2 have their ports)

Hmm. Side point regarding OS/2: I notice that
http://www.python.org/getit/other/ points to a port of 2.4.4, but Paul
Smedley has a port of 2.7.2:
http://smedley.id.au/os2ports_new/index.php?page=python - what's the
appropriate way to get that mentioned?

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


Re: What's the easiest Python datagrid GUI (preferably with easy database hooks as well)?

2013-03-17 Thread rusi
On Mar 17, 4:06 pm, Sibylle Koczian  wrote:
> Am 16.03.2013 21:30, schrieb Wolfgang Keller:>> Will look at Pypapi and 
> SQLkit.
>
> Did look: SQLkit needs Python 2. Pypapi, from the link you gave: "The
> new release of PyPaPi is written in Java. You can find more info in the
> official site." On this official site -http://www.pypapi.org/- I can't
> find anything at all about using PyPaPi with Python.
>
> > Frustrated with Dabo? Why?
>
> First and main reason: just because for my needs it's the _only_ package
> that still forces me to keep a Python 2 installation.
>
> Second reason: too often things suddenly break that worked before.
> Writing to the Dabo list always helps, usually quite quickly, and that
> list really is one of the friendliest and most helpful I know, but still
> it's tiresome. Possibly I wouldn't care if English were my native
> language, but it isn't and so writing to the list is work and no fun.

About your python I cant say, but your English looks/sounds as good as
a native's.
So dont waste your time getting that right; its good enough!
-- 
http://mail.python.org/mailman/listinfo/python-list


Error about " module object has no attribute 'QStringList' "

2013-03-17 Thread ofenerci
Dear List,

I have been working on restructured text(rest) documents and found a nice 
application which makes viewing the rest documents easy. It is a  web browser 
especially suited for Sphinx documents. 

When I run the code, I get error which says that :

->---
Traceback (most recent call last):
  File "/usr/local/bin/doc-watch", line 73, in 
self.wb.urlChanged.connect(lambda: 
self.url.setCompleter(QtGui.QCompleter(QtCore.QStringList([QtCore.QString(i.url().toString())
 for i in self.wb.history().items()]), caseSensitivity = 
QtCore.Qt.CaseInsensitive)))
AttributeError: 'module' object has no attribute 'QStringList'
<

I am running python2.7 on Debian Testing. I appreciate any help to shed any 
light on this error. The code is following:

Best Regards,
Ozhan Fenerci



#!/usr/bin/env python
#
# Copyright (C) 2012 Vinay Sajip. Licensed under the MIT license.
#
# Based on Roberto Alsina's 128-line web browser, see
#
# http://lateral.netmanagers.com.ar/weblog/posts/BB948.html
#
import json
import os
import subprocess
import sys
import tempfile
from urllib import pathname2url

import sip
sip.setapi("QString", 2)
sip.setapi("QVariant", 2)

from PyQt4 import QtGui, QtCore, QtWebKit, QtNetwork


settings = QtCore.QSettings("Vinay Sajip", "DocWatch")

class Watcher(QtCore.QThread):
"""
A watcher which looks for source file changes, builds the documentation,
and notifies the browser to refresh its contents
"""
def run(self):
self._stop = False
watch_command = 'inotifywait -rq -e close_write --exclude \'"*.html"\' 
.'.split()
make_command = 'make html'.split()
while not self._stop:
# Perhaps should put notifier access in a mutex - not bothering yet
self.notifier = subprocess.Popen(watch_command)
self.notifier.wait()
if self._stop:
break
subprocess.call(make_command)
# Refresh the UI ...
self.parent().changed.emit()

def stop(self):
self._stop = True
# Perhaps should put notifier access in a mutex - not bothering for now
if self.notifier.poll() is None:# not yet terminated ...
self.notifier.terminate()

class MainWindow(QtGui.QMainWindow):
"""
A browser intended for viewing HTML documentation generated by Sphinx.
"""
changed = QtCore.pyqtSignal()

def __init__(self, url):
QtGui.QMainWindow.__init__(self)
self.sb=self.statusBar()

self.pbar = QtGui.QProgressBar()
self.pbar.setMaximumWidth(120)
self.wb=QtWebKit.QWebView(loadProgress = self.pbar.setValue, 
loadFinished = self.pbar.hide, loadStarted = self.pbar.show, titleChanged = 
self.setWindowTitle)
self.setCentralWidget(self.wb)

self.tb=self.addToolBar("Main Toolbar")
for a in (QtWebKit.QWebPage.Back, QtWebKit.QWebPage.Forward, 
QtWebKit.QWebPage.Reload):
self.tb.addAction(self.wb.pageAction(a))

self.url = QtGui.QLineEdit(returnPressed = 
lambda:self.wb.setUrl(QtCore.QUrl.fromUserInput(self.url.text(
self.tb.addWidget(self.url)

self.wb.urlChanged.connect(lambda u: self.url.setText(u.toString()))
self.wb.urlChanged.connect(lambda: 
self.url.setCompleter(QtGui.QCompleter(QtCore.QStringList([QtCore.QString(i.url().toString())
 for i in self.wb.history().items()]), caseSensitivity = 
QtCore.Qt.CaseInsensitive)))

self.wb.statusBarMessage.connect(self.sb.showMessage)
self.wb.page().linkHovered.connect(lambda l: self.sb.showMessage(l, 
3000))

self.search = QtGui.QLineEdit(returnPressed = lambda: 
self.wb.findText(self.search.text()))
self.search.hide()
self.showSearch = QtGui.QShortcut("Ctrl+F", self, activated = lambda: 
(self.search.show() , self.search.setFocus()))
self.hideSearch = QtGui.QShortcut("Esc", self, activated = lambda: 
(self.search.hide(), self.wb.setFocus()))

self.quit = QtGui.QShortcut("Ctrl+Q", self, activated = self.close)
self.zoomIn = QtGui.QShortcut("Ctrl++", self, activated = lambda: 
self.wb.setZoomFactor(self.wb.zoomFactor()+.2))
self.zoomOut = QtGui.QShortcut("Ctrl+-", self, activated = lambda: 
self.wb.setZoomFactor(self.wb.zoomFactor()-.2))
self.zoomOne = QtGui.QShortcut("Ctrl+=", self, activated = lambda: 
self.wb.setZoomFactor(1))
self.wb.settings().setAttribute(QtWebKit.QWebSettings.PluginsEnabled, 
True)

self.sb.addPermanentWidget(self.search)
self.sb.addPermanentWidget(self.pbar)

self.load_settings()

self.wb.load(url)
self.watcher = Watcher(self)

self.changed.connect(self.wb.reload)

self.watcher.start()

def load_settings(self):
settings.beginGroup('mainwindow')
pos = settings.value('pos')
size = settings.value('size')
if isinstanc

Re: Error about " module object has no attribute 'QStringList' "

2013-03-17 Thread Vincent Vande Vyvre
Le 17/03/13 17:15, ofene...@hotmail.com a écrit :
> Dear List,
>
> I have been working on restructured text(rest) documents and found a nice 
> application which makes viewing the rest documents easy. It is a  web browser 
> especially suited for Sphinx documents. 
>
>
.

Forget the reference:
http://pyqt.sourceforge.net/Docs/PyQt4/incompatible_apis.html
-- 
Vincent V.V.
Oqapy  . Qarte
 . PaQager 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Error about " module object has no attribute 'QStringList' "

2013-03-17 Thread Vincent Vande Vyvre
Le 17/03/13 17:15, ofene...@hotmail.com a écrit :
> sip.setapi("QString", 2)

Remove the line:

sip.setapi("QString", 2)

and try it.


-- 
Vincent V.V.
Oqapy  . Qarte
 . PaQager 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Error about " module object has no attribute 'QStringList' "

2013-03-17 Thread Vincent Vande Vyvre
Le 17/03/13 17:53, Vincent Vande Vyvre a écrit :
> Le 17/03/13 17:15, ofene...@hotmail.com a écrit :
>> Dear List,
>>
>> I have been working on restructured text(rest) documents and found a nice 
>> application which makes viewing the rest documents easy. It is a  web 
>> browser especially suited for Sphinx documents. 
>>
>>
> .
>
> Forget the reference:
> http://pyqt.sourceforge.net/Docs/PyQt4/incompatible_apis.html

It seems my first mail was lost.

Remove the line:

sip.setapi("QString", 2)

See here:

http://pyqt.sourceforge.net/Docs/PyQt4/incompatible_apis.html


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


Re: Error about " module object has no attribute 'QStringList' "

2013-03-17 Thread ofenerci
Thank you Vincent and to All,


It has worked like a charm. 
-- 
http://mail.python.org/mailman/listinfo/python-list


pprint defaultdict one record per line

2013-03-17 Thread Peng Yu
Hi,

pprint can not print defaultdict one record per line. Is there some
other convenient way in python to print one record per line?

~/linux/test/python/man/library/pprint/function/pprint$ ./main.py
{'two': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], 'one': [0,
1, 2, 3, 4, 5, 6, 7, 8, 9]}
{'one': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
 'two': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]}
defaultdict(, {'two': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14], 'one': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]})
~/linux/test/python/man/library/pprint/function/pprint$ cat main.py
#!/usr/bin/env python

import pprint

d=dict(one=range(10), two=range(15))
print d
pprint.pprint(d)

from collections import defaultdict
d=defaultdict(list)
d['one']=range(10)
d['two']=range(15)
pprint.pprint(d)

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


RE: Top 10 python features

2013-03-17 Thread Joseph Clark
I'm a Python newbie and already found a few things that I love about the 
language.
Among them:

- list/set comprehensions
- dictionaries and sets
- pickle/shelve

// joseph w. clark , phd , visiting research associate
\\ university of nebraska at omaha - college of IS&T

> Date: Mon, 18 Mar 2013 01:21:45 +1100
> Subject: Re: Top 10 python features
> From: ros...@gmail.com
> To: python-list@python.org
>
> On Mon, Mar 18, 2013 at 1:09 AM, Peter Otten <__pete...@web.de> wrote:
> > Albert Vonpupp wrote:
> >
> >> I would like to know what are the top 10 most important features (on your
> >> opinion) in python.
> >
> > Amongst our weapons are
> >
> > - Generators
> > - Duck-Typing
> > - The Interactive Interpreter
> >
> > and an almost fanatical devotion to the Zen.
> >
> > Wait, I forgot dictionaries; it's dictionaries all the way down...
>
> That's five. Here's five more:
>
> * No variable declarations - keep your code simple
> * An *extensive* standard library
> * comp.lang.python / python-list, Python help 24/7!
> * Active development and constant improvements
> * Strong OS/platform support (many Linuxes have at least some version
> of Python either already installed or in the standard repository;
> Windows and Mac OS have ready-to-go binaries available on python.org;
> there are Pythons for various mobile platforms; even relative
> obscurities like OS/2 have their ports)
>
> Hmm. Side point regarding OS/2: I notice that
> http://www.python.org/getit/other/ points to a port of 2.4.4, but Paul
> Smedley has a port of 2.7.2:
> http://smedley.id.au/os2ports_new/index.php?page=python - what's the
> appropriate way to get that mentioned?
>
> ChrisA
> --
> http://mail.python.org/mailman/listinfo/python-list   
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pprint defaultdict one record per line

2013-03-17 Thread Mark Lawrence

On 17/03/2013 17:45, Peng Yu wrote:

Hi,

pprint can not print defaultdict one record per line. Is there some
other convenient way in python to print one record per line?

~/linux/test/python/man/library/pprint/function/pprint$ ./main.py
{'two': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], 'one': [0,
1, 2, 3, 4, 5, 6, 7, 8, 9]}
{'one': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
  'two': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]}
defaultdict(, {'two': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14], 'one': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]})
~/linux/test/python/man/library/pprint/function/pprint$ cat main.py
#!/usr/bin/env python

import pprint

d=dict(one=range(10), two=range(15))
print d
pprint.pprint(d)

from collections import defaultdict
d=defaultdict(list)
d['one']=range(10)
d['two']=range(15)
pprint.pprint(d)



Try writing a for loop that prints one record per line.

--
Cheers.

Mark Lawrence

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


Help me with Event handlers please

2013-03-17 Thread Dreamer
Hi can anybody share some expertise on event handlers...i need to use em to 
update user activity in my web appthanks in advance
Cheers
-- 
http://mail.python.org/mailman/listinfo/python-list


tuple of ids of integers or lists

2013-03-17 Thread bartolome . sintes
In Python 3.3 for Windows, every list gets a different id when it is created:

>>> id([3])
46555784
>>> id([3])
47920192
>>> id([4])
46532048

But if I write a tuple asking for the ids of two lists, each list seems to get 
the same id:

>>> id([3]), id([4])
(43079000, 43079000)

I was expecting a tuple with two different ids. What is the reason for this 
behaviour?

Thanking you in advance,
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tuple of ids of integers or lists

2013-03-17 Thread Roy Smith
In article <8e66719c-5e90-4776-bba9-a11c29fba...@googlegroups.com>,
 bartolome.sin...@gmail.com wrote:

> In Python 3.3 for Windows, every list gets a different id when it is created:
> 
> >>> id([3])
> 46555784
> >>> id([3])
> 47920192
> >>> id([4])
> 46532048
> 
> But if I write a tuple asking for the ids of two lists, each list seems to 
> get the same id:
> 
> >>> id([3]), id([4])
> (43079000, 43079000)
> 
> I was expecting a tuple with two different ids. What is the reason for this 
> behaviour?

This is a classic little gotcha.

Object ids are guaranteed to be unique, but only for the lifetime of an 
object.  Or, to put it another way, it is guaranteed that no two objects 
that exist at the same time can have the same id.

What's happening when you do:

>>> id([3]), id([4])

Is that a list, [3], is created, its id is taken, and then the list is 
destroyed.  In this particular implementation, object ids happen to be 
the address of the object in memory.  Then, a new list, [4], is created.  
It just so happens that it gets created using the same memory block that 
was just freed by the destruction of the other list, so it ends up in 
the same place in memory.  So it gets the same id!

Kind of neat, huh?

PS -- this makes a nice interview question to see if somebody really 
understands what's happening beneath the surface.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help me with Event handlers please

2013-03-17 Thread mar...@python.net


On Sun, Mar 17, 2013, at 03:30 PM, Dreamer wrote:
> Hi can anybody share some expertise on event handlers...i need to use em
> to update user activity in my web appthanks in advance
> Cheers

You're proably going to need to be more specific about what help you
need.  Just a generic "give me a hand with X" is probably not going to
get you very far.

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


Re: tuple of ids of integers or lists

2013-03-17 Thread bartolome . sintes
OK. Now I understand it. 

I was confused because when two list are created in two different lines, Python 
gives them different ids, but when the two lists are created in the same line 
(in a tuple) Python gives them the same id. It doesn't really matter as these 
lists are just created and destroyed, as you have said.

Thank you very much for your fast answer.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tuple of ids of integers or lists

2013-03-17 Thread Chris Angelico
On Mon, Mar 18, 2013 at 7:23 AM,   wrote:
> OK. Now I understand it.
>
> I was confused because when two list are created in two different lines, 
> Python gives them different ids, but when the two lists are created in the 
> same line (in a tuple) Python gives them the same id. It doesn't really 
> matter as these lists are just created and destroyed, as you have said.
>
> Thank you very much for your fast answer.

Here's something that'll either help you understand another aspect of
Python, or totally do your head in.

>>> print(id([3]))
14485504
>>> print(id([3]))
14485504

If you print it to stdout, the id can be reused! How is this?

Here's what's going on. In interactive mode, the result of the last
expression is made available under the name _ (a single underscore):

>>> id([3])
15597160
>>> _
15597160

Integers are objects, like everything else. (Some of them are
pre-made, but big numbers like this aren't - at least, not in this
Python. But that's implementation-dependent too.) The retention of
this integer object can in some circumstances change where the next
object is stored. So you may find that some things behave differently
in interactive mode than in a script; or perhaps printing something
out instead of letting the interpreter display it will change what
happens.

You're looking into some extremely unspecified behaviour, here, so
anything is allowed to affect it. Which means you might be able to
learn all sorts of things about Python's internals! :)

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


Re: PyWart: NameError trackbacks are superfluous

2013-03-17 Thread Jason Swails
On Sat, Mar 16, 2013 at 2:27 PM, Rick Johnson
wrote:

>
> [snip junk]
> We don't need multiple layers of traces for NameErrors. Python does not
> have *real* global variables; and thank Guido for that! All we need to know
> is which module the error occurred in AND which line of that module
> contains the offensive lookup of a name that does not exist.
> [snip more junk]


2 comments here.

1) Where's the consistency??  NameError is an exception.  All other
exceptions get full tracebacks.  A NameError is not special enough to
deserve special treatment (zen of Python? PEP 8?  I don't remember).  If
you like the full traceback (like I do), it's there. If you just want the
error, look at the last frame only.

 Example where you want a full traceback 

Pyflakes doesn't catch all NameErrors.  If you don't set all of an object's
possible attributes inside its constructor, but some are applied later-on
(i.e., when they are needed, like in some sort of specialized setup routine
that you only call in certain circumstances), then you can benefit from a
full traceback even for a NameError. Consider the DataSet class below:

import numpy as np
from scipy.stats.kde import gaussian_kde as kde
class DataSet(object):

   def __init__(self, data):
  self._dataset = np.asarray(data)
   def setup_kde(self):
  "Set up KDE. Do not do by default since it is expensive for large
data sets"
  self.kde = kde(self._dataset)
   def resampled(self):
  return DataSet(self.kde.resample())

In this case generating the KDE can become time- and RAM-consuming for
large data sets, so it's worthwhile to only generate the KDE if you
actually plan on doing something with that requires it.  If you call
resampled before setup_kde, you get a NameError, and it would be helpful to
have the full traceback when debugging.  Yes, you can get around having the
'non-trivial' NameError, but having the full traceback if someone _did_
write code like this makes your job a hell of a lot easier to debug if you
don't have to go stack tracing yourself. And for a large project with
multiple coders that is built in stages and has functionality added as it's
needed, this type of situation is not at all unusual.  While one approach
is to take to the (email) streets and proclaim how incompetent all coders
that came before you truly were and that such a project is not worth
modifying in view of their ineptitude, the approach that does _not_ lead to
your firing would benefit from a full NameError traceback. Go ahead and
fire away about how stupid I am for the suggestion anyway, though.

2) Fine.  You don't like long tracebacks for NameErrors, write a 8-line
module that you import at the top of every program (like division from
__future__ if you work with Python 2 like I have to):

--- file ricksstupididea.py ---
import sys, traceback
def excepthook(exctype, value, tb):
   if exctype is NameError:
  print 'Traceback (only printing last frame):'
  print '  File "%s", line %d, in %s\n%s' %
traceback.extract_tb(tb).pop()
  print 'NameError: %s' % value
   else:
  sys.__excepthook__(exctype, value, tb)
sys.excepthook = excepthook
--- end ricksstupididea.py ---

Once you do this, you get your special behavior for NameErrors like you
want.  Observe, padawan:

-- begin nameerror.py --
import ricksstupididea
def func1(x):
   return func2(x)

def func2(x):
   return func3(x)

def func3(x):
   return func4(x)

def func4(x):
   return noname

func1(1)

$ python noname.py
Traceback (only printing last frame):
  File "noname.py", line 12, in func4
return noname
NameError: global name 'noname' is not defined

-- begin divzero.py --
import ricksstupididea
def func1(x):
   return func2(x)

def func2(x):
   return func3(x)

def func3(x):
   return func4(x)

def func4(x):
   return x / 0

func1(1)

$ python divzero.py
Traceback (most recent call last):
  File "divzero.py", line 14, in 
func1(1)
  File "divzero.py", line 3, in func1
return func2(x)
  File "divzero.py", line 6, in func2
return func3(x)
  File "divzero.py", line 9, in func3
return func4(x)
  File "divzero.py", line 12, in func4
return x / 0
ZeroDivisionError: integer division or modulo by zero

GvR's time machine strikes again.  The only bad thing about this approach
is that you have to actually write that extra 8 lines of code, and I get to
keep the behavior I like rather than being forced into the (inconsistent)
behavior you would prefer I use instead.  But since the 8 lines has been
provided to you here free of charge, the only real cost for you is how I
like my NameErrors given to me.

I hereby leave you enlightened.


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


Re: How to make a Python script to audio read a text file on phone ?

2013-03-17 Thread dey . sumit . kr
On Sunday, March 17, 2013 7:34:18 PM UTC+5:30, Nic wrote:
> I've installed Python on my Nokia E71 (Symbian S60 3rd FP1) and found a 
> script example which can read out text, see example below.
> 
>  I want to make the script to asks me for a text file instead and then reads 
> out the content. I guess it works with a .txt file, dont know if other 
> formats work.  Regards!
> 
> 
> 
> 
> 
> [Quote]
> 
> 
> 
> # Copyright (c) 2006 Jurgen Scheible
> 
> # This script performs a query with a single-field dialog (text input field)
> 
> # and lets the phone speak out the text (text to speech) that the users have 
> typed in
> 
> # NOTE: this script runs only with Python S60 version 3.1.14 or above
> 
> # NOTE: this script doesn't work on all S60 phones neccessarily. Check your 
> phone model if it has text to speech capability at all
> 
> 
> 
> import appuifw
> 
> import audio
> 
> 
> 
> text = appuifw.query(u"Type a word:", "text")
> 
> audio.say(text)
> 
> 
> 
> [End Quote]

Here is a code that works fine for PC. Hope it'll work for you..

def op():
global TXT, L
filepath = tkFileDialog.askopenfilename(filetypes=[("Text Files","*.txt")])
if(len(filepath) == 0):
return 0
F = open(filepath,'r')
TXT = F.read()
F.close()
filename = filepath.split("/")
filename = filename[-1]
L.config(text=filename+": "+filepath)

def play():
global TXT
audio.say(TXT) ##Used as mentioned
print "said"


from Tkinter import *
import Tkconstants, tkFileDialog

import audio ##used as mentioned

TXT = ""

root = Tk()
root.title("Read that Out!!")

L = Label(text="No File Selected!",width="35",fg="black",bg="white")
L.grid(row=1,column=1)

F = Frame(root)
F.grid(row=2,column=1)

Button(F,text="Open File",command=op).grid(row=1,column=1)
Button(F,text="Read File",command=play).grid(row=1,column=2)

root.mainloop()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pynguin-0.13 python turtle graphics application now uses python 3

2013-03-17 Thread Lee Harr

>> Pynguin is a python-based turtle graphics application.
>>     It combines an editor, interactive interpreter, and
>>     graphics display area.
>
>
> What does pynguin have that the builtin python turtle does not?

It is meant to be easier to get started with.

You start the application and it is all ready to go with the basic
turtle-style commands pulled in to the local namespace.

It also has some nice added features:

Many commands are available from menus. The equivalent
    python is copied to the interpreter to help students discover
    and learn how to write the code.
The canvas can be panned and zoomed with the mouse.
I just posted a quick hack on edu-sig for exporting the canvas as svg.
All colors (except the background) can have alpha channels.


If you are a fan of turtle.py please give pynguin a try and let me
know what you think!

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


Escaping a Python sandbox

2013-03-17 Thread Steven D'Aprano
An example of how to hack your way out of a Python sandbox:

[quote]
Now that we can build any function we want, what can we do? We can’t 
directly access the non restricted builtins: the functions we craft are 
still executed in the restricted environment. We can get a non sandboxed 
function to call us: the auth function call the __len__ method of the 
object that we pass as a parameter. This is however not enough to get 
out of the sandbox: our globals are still the same and we can’t for 
example import a module. I tried to look at all the classes we could 
access via the __subclasses__ trick to see if we could get a reference 
to a useful module through there, but no dice. Even getting Twisted to 
call one of our crafted functions via the reactor was not enough. We 
could try to get a traceback object and use it to browse the stack 
frames of our callers, but the only trivial ways to get a traceback 
object are via the inspect or the sys modules which we can’t import. 
After being blocked on that problem, I went to work on other problems, 
slept a lot, and woke up to the solution I needed!




http://blog.delroth.net/2013/03/escaping-a-python-sandbox-ndh-2013-quals-writeup/


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


Re: Top 10 python features

2013-03-17 Thread Terry Reedy

On 3/17/2013 10:00 AM, Miki Tebeka wrote:

I would like to know what are the top 10 most important features
(on your opinion) in python.

You're in luck :) Raymond Hettinger just gave "Python is Awesome"
keynote at PyCon. You can view the slides at
https://speakerdeck.com/pyconslides/pycon-keynote-python-is-awesome,
video will follow - not sure when.


The full url works better ;-).
https://speakerdeck.com/pyconslides/pycon-keynote-python-is-awesome-by-raymond-hettinger

I am part way through and recommend it.

--
Terry Jan Reedy

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


[Python 2.7.3] What's the difference between these two uses of "for"?

2013-03-17 Thread Yves S. Garret
N00b question.  But here is the code:

http://bin.cakephp.org/view/709201806

In the first example, the first for-loop is run and then the list is assigned 
to the tricky variable.  But, what 
happens in the second example?  Does the loop after "in" get run only once or 
multiple number of times?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Python 2.7.3] What's the difference between these two uses of "for"?

2013-03-17 Thread Andrew Berg
On 2013.03.17 19:58, Yves S. Garret wrote:
> N00b question.  But here is the code:
> 
> http://bin.cakephp.org/view/709201806
> 
> In the first example, the first for-loop is run and then the list is assigned 
> to the tricky variable.  But, what 
> happens in the second example?  Does the loop after "in" get run only once or 
> multiple number of times?
> 
In the first example, sorted() returns a list, which is assigned to the
name tricky (Python doesn't have variables - names simply point to
objects in memory), and then the for loop iterates over tricky, which
points to a list. In the second example, the for loop iterates over the
list that sorted() returns. The only difference between the two is that
the list that sorted() returns is assigned to a name in the first example.

-- 
CPython 3.3.0 | Windows NT 6.2.9200 / FreeBSD 9.1
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Python 2.7.3] What's the difference between these two uses of "for"?

2013-03-17 Thread Gary Herron

On 03/17/2013 05:58 PM, Yves S. Garret wrote:

N00b question.  But here is the code:

http://bin.cakephp.org/view/709201806

In the first example, the first for-loop is run and then the list is assigned 
to the tricky variable.  But, what
happens in the second example?  Does the loop after "in" get run only once or 
multiple number of times?


Just once.  The sorted fn is called just once, and the resulting list is 
iterated through.  In your first case, the list is bound to (assigned 
to) a name so it is accessible afterwards.  In the second case, it is 
available for garbage collection immediately after the loop finishes.


Gary Herron

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


Re: [Python 2.7.3] What's the difference between these two uses of "for"?

2013-03-17 Thread Roy Smith
In article <485a3093-8c07-4d1a-b49e-af32f84f8...@googlegroups.com>,
 "Yves S. Garret"  wrote:

> N00b question.  But here is the code:
> 
> http://bin.cakephp.org/view/709201806
> 
> In the first example, the first for-loop is run and then the list is assigned 
> to the tricky variable.  But, what 
> happens in the second example?  Does the loop after "in" get run only once or 
> multiple number of times?

It's a little hard to answer your question because you're not using the 
right terminology.  When you say, 'the loop after "in"', I assume you 
mean:

[w for w in set(text2) if 'cie' in w or 'cei' in w]

yes?  That's not what most people would call "a loop".  It's a list 
comprehension.  For sure, there's an implied looping over the elements 
of set(text2) in there, but that's not the way people refer to it.

Anyway, here's what happens.  Working from the inside out...

First, set(text2) is evaluated.  I assume text2 is something like a list 
of strings, or at least iterable which yields strings.  This results in 
a set object being created.  Let's call that set S.

Next, the list comprehension gets evaluated:

[w for w in s if 'cie' in w or 'cei' in w]

This iterates over the the elements of s and forms a list out of those 
elements which pass the condition in the 'if' clause.  This results in a 
list object being created. Let's call that L1

Next, sorted(L1) is evaluated.  This returns another list (call it L2).

Finally, we get to:

for word in L2:
   print word,

This iterates over all the elements in L2, assigning each one, in turn 
to word, and executing the body of the for statement.

Does that answer your question?  I'm sure other people will point out 
that this is not the most efficient way to do this (your way is not 
wrong, it's just not the most efficient way).  There's a way to write 
this which avoids creating L1.  That could be important if there's a 
large amount of data involved.

But, make sure you fully understand what's happing in the example you 
gave before you move on to the next step.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Python 2.7.3] What's the difference between these two uses of "for"?

2013-03-17 Thread Yves S. Garret
On Sunday, March 17, 2013 9:18:12 PM UTC-4, Gary Herron wrote:
> On 03/17/2013 05:58 PM, Yves S. Garret wrote:
> 
> > N00b question.  But here is the code:
> 
> >
> 
> > http://bin.cakephp.org/view/709201806
> 
> >
> 
> > In the first example, the first for-loop is run and then the list is 
> > assigned to the tricky variable.  But, what
> 
> > happens in the second example?  Does the loop after "in" get run only once 
> > or multiple number of times?
> 
> 
> 
> Just once.  The sorted fn is called just once, and the resulting list is 
> 
> iterated through.  In your first case, the list is bound to (assigned 
> 
> to) a name so it is accessible afterwards.  In the second case, it is 
> 
> available for garbage collection immediately after the loop finishes.
> 
> 
> 
> Gary Herron

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


Re: [Python 2.7.3] What's the difference between these two uses of "for"?

2013-03-17 Thread Yves S. Garret
On Sunday, March 17, 2013 9:28:56 PM UTC-4, Roy Smith wrote:
> In article <485a3093...@googlegroups.com>,
> 
>  "Yves S. Garret"  wrote:
> 
> 
> 
> > N00b question.  But here is the code:
> 
> > 
> 
> > http://bin.cakephp.org/view/709201806
> 
> > 
> 
> > In the first example, the first for-loop is run and then the list is 
> > assigned 
> 
> > to the tricky variable.  But, what 
> 
> > happens in the second example?  Does the loop after "in" get run only once 
> > or 
> 
> > multiple number of times?
> 
> 
> 
> It's a little hard to answer your question because you're not using the 
> 
> right terminology.  When you say, 'the loop after "in"', I assume you 
> 
> mean:
> 
> 
> 
> [w for w in set(text2) if 'cie' in w or 'cei' in w]
> 
> 
> 
> yes?  That's not what most people would call "a loop".  It's a list 
> 
> comprehension.  For sure, there's an implied looping over the elements 
> 
> of set(text2) in there, but that's not the way people refer to it.
> 
> 
> 
> Anyway, here's what happens.  Working from the inside out...
> 
> 
> 
> First, set(text2) is evaluated.  I assume text2 is something like a list 
> 
> of strings, or at least iterable which yields strings.  This results in 
> 
> a set object being created.  Let's call that set S.
> 
> 
> 
> Next, the list comprehension gets evaluated:
> 
> 
> 
> [w for w in s if 'cie' in w or 'cei' in w]
> 
> 
> 
> This iterates over the the elements of s and forms a list out of those 
> 
> elements which pass the condition in the 'if' clause.  This results in a 
> 
> list object being created. Let's call that L1
> 
> 
> 
> Next, sorted(L1) is evaluated.  This returns another list (call it L2).
> 
> 
> 
> Finally, we get to:
> 
> 
> 
> for word in L2:
> 
>print word,
> 
> 
> 
> This iterates over all the elements in L2, assigning each one, in turn 
> 
> to word, and executing the body of the for statement.
> 
> 
> 
> Does that answer your question?  I'm sure other people will point out 
> 
> that this is not the most efficient way to do this (your way is not 
> 
> wrong, it's just not the most efficient way).  There's a way to write 
> 
> this which avoids creating L1.  That could be important if there's a 
> 
> large amount of data involved.
> 
> 
> 
> But, make sure you fully understand what's happing in the example you 
> 
> gave before you move on to the next step.

Hi, thanks for the detailed explanation.  And yes, you've answered my question.

I'm trying to better understand what's going on behind the scenes and I
appreciate your thorough input.  What I don't understand is, how would you
avoid creating L1?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Python 2.7.3] What's the difference between these two uses of "for"?

2013-03-17 Thread Yves S. Garret
I don't get why it's posting what I said twice...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Python 2.7.3] What's the difference between these two uses of "for"?

2013-03-17 Thread Roy Smith
In article <7f3b4dde-fbd7-44ca-96bc-31a6b2894...@googlegroups.com>,
 "Yves S. Garret"  wrote:

> I'm trying to better understand what's going on behind the scenes and I
> appreciate your thorough input.  What I don't understand is, how would you
> avoid creating L1?

Leave out the square brackets in:

sorted([w for w in set(text2) if 'cie' in w or 'cei' in w])

If you re-write that as:

sorted(w for w in set(text2) if 'cie' in w or 'cei' in w)

Now you've got what's called a generator expression.  This iterates over 
the same values as the list comprehension would, but it generates them 
one at a time, so it doesn't have to store them all somewhere.  It 
essentially a really neat syntax for writing coroutines.

As usual, Stack Overflow does a pretty good job explaining this:

http://stackoverflow.com/questions/47789/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Python 2.7.3] What's the difference between these two uses of "for"?

2013-03-17 Thread Roy Smith
In article ,
 "Yves S. Garret"  wrote:

> I don't get why it's posting what I said twice...

Because you're posting using the Google Groups web interface, right?  
Google Groups is just plain busted and double-posts everything (at least 
to this group).  Not your fault, but something to be aware of.  You'd do 
better to subscribe to the real email list, or use a traditional NNTP 
newsreader.

Google's motto may be "don't be evil", but they get to define what evil 
is.  Apparently working and playing well with mailing list technology 
which has worked just fine for literally decades isn't part of the 
definition.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Python 2.7.3] What's the difference between these two uses of "for"?

2013-03-17 Thread Steven D'Aprano
On Sun, 17 Mar 2013 19:14:49 -0700, Yves S. Garret wrote:

> I don't get why it's posting what I said twice...

Because you are emailing to the list, and CCing the list.

In your email, you have:

To: comp.lang.pyt...@googlegroups.com
Cc: python-list@python.org


Unfortunately, they are the same thing. Or rather, when Google Groups 
receives its copy of the email, it then "helpfully" sends another copy to 
python-list@python.org even though you have already CCed it.

In defence of Google Groups, it's not *quite* as stupid as it appears, 
because it's not actually forwarding directly to the same email address. 
It is actually forwarding to the newsgroup comp.lang.python, which is an 
alias to python-list@python.org.

Confused? Don't be. It is very simple: there are at least three ways to 
post to this group:

1) Email to python-list@python.org

2) Post to the news group comp.lang.python on Usenet

3) Email to comp.lang.pyt...@googlegroups.com

There are others as well. Think of them as all aliases to the same 
discussion forum. Whichever you choose, choose ONE ONLY. You are using 
two, hence there are two copies of your message.

I recommend that you choose 1) or 2) rather than Google Groups, if 
possible. There are two problems with Google Groups: 

- it is not very smart, and often mangles messages so that every line is 
separated by a blank line (although I see you have avoided that, at least 
so far!); 

- also, we get a lot of spam and junk advertising coming from Google 
Groups, and so in self-defence many people here have an automatic filter 
that junks anything from Google Groups unread.

If you are unable or unwilling to avoid Google Groups, we will still 
answer your questions, but keep in mind that many of the regulars here 
will not directly see your posts, but only replies to them.


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


Re: [Python 2.7.3] What's the difference between these two uses of "for"?

2013-03-17 Thread Roy Smith
In article <51467f6f$0$6599$c3e8da3$54964...@news.astraweb.com>,
 Steven D'Aprano  wrote:

> there are at least three ways to 
> post to this group:
> 
> 1) Email to python-list@python.org
> 
> 2) Post to the news group comp.lang.python on Usenet
> 
> 3) Email to comp.lang.pyt...@googlegroups.com

Amongst the ways, there are
-- 
http://mail.python.org/mailman/listinfo/python-list


How to add the current dir to sys.path when calling a python file?

2013-03-17 Thread Peng Yu
Hi,

man python says "If a script  argument  is  given,  the directory
containing the script is inserted in the path in front of $PYTHONPATH.
The search path can be manipulated from  within a Python program as
the variable sys.path." Instead I want to have the current directory
inserted to the front of $PYTHONPATH without changing anything the
script. Is there a way to do so?

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


Re: pprint defaultdict one record per line

2013-03-17 Thread Terry Reedy

On 3/17/2013 1:45 PM, Peng Yu wrote:


pprint can not print defaultdict one record per line


Known issue, no progress for 2+ years. Patch not updated for default 
branch (3.4). Not clear what best way forward is.


--
Terry Jan Reedy

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


Re: pynguin-0.13 python turtle graphics application now uses python 3

2013-03-17 Thread rusi
On Mar 18, 3:28 am, Lee Harr  wrote:

> If you are a fan of turtle.py please give pynguin a try and let me
> know what you think!

Not a 'fan' per se -- just a teacher who has occasionally tried turtle
to introduce programming.
(which was not completely smooth; Ive forgotten all the hiccups)

http://mail.python.org/pipermail/python-list/2011-May/604698.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Message passing syntax for objects

2013-03-17 Thread Mark Janssen
Continuing on this thread, there would be a new bunch of behaviors to
be defined.  Since "everything is an object", there can now be a
standard way to define the *next* common abstraction of "every object
interacts with other objects".  And going with my suggestion of
defining >> and << operators, I'm going to explore the concept
further

>>> 42 >> MyNumberType #would add the integer to your integer type
>>> 42 >> MyCollectionType  #would add the object into your collection:  
>>> *poof*: no more random syntaxiis for putting things in collections.\
>>> MyObject >> # queries the object to output its state.
>>> "http://www.cnn.com"; >> MyInternetObject  #outputs the HTML text from CNN's 
>>> home page.

Each object has to figure out how it will receive things from outside
of it.  Things it can't handle (a string sent to an int) just have to
be dropped to some other space, much like stderr does within the O.S.

There are probably many other very interesting examples, but the key
idea I'm working on (as noted in other messages), is a sort-of
universal language for the internet, a WebOS to be applied to a
universal data model.

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


Re: [Python 2.7.3] What's the difference between these two uses of "for"?

2013-03-17 Thread Terry Reedy

On 3/17/2013 8:58 PM, Yves S. Garret wrote:

N00b question.  But here is the code:

http://bin.cakephp.org/view/709201806


Short code like this should be included in your message.

tricky = sorted([w for w in set(text2) if 'cie' in w or 'cei' in w])
for word in tricky:
  print word,

for word in sorted([w for w in set(text2) if 'cie' in w or 'cei' in w]):
  print word,

--
Terry Jan Reedy

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


Re: Message passing syntax for objects

2013-03-17 Thread Mark Janssen
On Sun, Mar 17, 2013 at 9:26 PM, Mark Janssen  wrote:
> Continuing on this thread, there would be a new bunch of behaviors to
> be defined.  Since "everything is an object", there can now be a
> standard way to define the *next* common abstraction of "every object
> interacts with other objects".  And going with my suggestion of
> defining >> and << operators, I'm going to explore the concept
> further
> Each object has to figure out how it will receive things from outside
> of it.  Things it can't handle (a string sent to an int) just have to
> be dropped to some other space, much like stderr does within the O.S.

I guess here's the idea I'm getting at.  As a programming language
paradigm, OOP has to evolve -- it still has too much dependency on
number-crunching and the mathematical operators still dominate.

But a better abstraction to wrap the OOP paradigm around is
*message-passing* rather than *arithmetic*.  And having in/out
operators on objects is just *way cool*.

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


decode php base64

2013-03-17 Thread Peter juliano
 Not long ago, my friend resignation of the company. He left a few app's in
php, some of those files are hashed with base64 code, he told me that those
files handle http request on the server and some security rules. Because
i'm migrating all these applications on django. I do not really care about
those files, but today just for playing around, i try to see the code, and
in a less of an hour can see all the code. I want to share the solution
with this mail list

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


Re: How to add the current dir to sys.path when calling a python file?

2013-03-17 Thread Steven D'Aprano
On Sun, 17 Mar 2013 22:56:07 -0500, Peng Yu wrote:

> Hi,
> 
> man python says "If a script  argument  is  given,  the directory
> containing the script is inserted in the path in front of $PYTHONPATH.
> The search path can be manipulated from  within a Python program as the
> variable sys.path." Instead I want to have the current directory
> inserted to the front of $PYTHONPATH without changing anything the
> script. Is there a way to do so?

No. If you want to manipulate the path, you have to write code to do so, 
and put it in your script. That's very simple:

import os, sys
sys.path.insert(0, os.getcwd())



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