Re: Python 3.4.1 installer on Mac links Python to old Tcl/Tk

2014-06-25 Thread Christian Gollwitzer

Hi Peter,

Am 24.06.14 20:11, schrieb Peter Tomcsanyi:

I use the Python 3.4.1 installer from
https://www.python.org/downloads/release/python-341/

The Windows installation comes with Tcl/Tk version 8.6 which has some
new features (compared to 8.5) that are very important to me.


may I ask which features of 8.6 you need in particular? I'm just 
curious, because I thought that Python mainly uses the Tk part, and 
there has not been much of a difference in Tk between 8.5 and 8.6. In 
contrast, the Tcl language itself got massively enhanced (stackless 
execution engine, coroutines, core OO system, ...)


Christian
--
https://mail.python.org/mailman/listinfo/python-list


Re: Off-Topic: The Machine

2014-06-25 Thread Gregory Ewing

Steven D'Aprano wrote:

Heh, yes, it's a puff-piece, based on HP's publicity, not an in-depth 
review. Considering that The Machine isn't publicly available yet, that's 
hardly surprising.


There's a talk here that goes into a bit more detail,
although still not much:

https://www.youtube.com/watch?v=JzbMSR9vA-c

The basic ideas seem to be:

1) An extremely large number of CPU cores, many of them
specialised for particular tasks.

2) A single form of high speed, non-volatile memory, of very
large capacity, replacing cache, RAM, disk, flash, etc.

3) A high-speed optical connection between the CPUs and
the memory.

They claim to be able to retrieve any desired byte out
of a petabyte of storage in 250ns.

That's nice, but the question that comes to my mind is:
What happens when a zillion cores are all competing for
high-speed access to that memory?

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Re: Off-Topic: The Machine

2014-06-25 Thread Chris Angelico
On Wed, Jun 25, 2014 at 5:31 PM, Gregory Ewing
 wrote:
> That's nice, but the question that comes to my mind is:
> What happens when a zillion cores are all competing for
> high-speed access to that memory?

And what happens if some of those cores are corrupt? Can you initiate
a core transfer? Will there be a stalemate? Are there any trained
Stalemate Resolution Associates around? What if there's a fire in the
Stalemate Resolution Annex?

Seriously, though, how would you go about debugging a system so
massively parallel? If most of the CPU cores are special-purpose, it's
going to require a whole new method of testing. I can just imagine
configure scripts having to be taught to cope with a new form of CPU
bug (in the same way that some still test for the Pentium division
bug).

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


Re: Python 3.4.1 installer on Mac links Python to old Tcl/Tk

2014-06-25 Thread Ned Deily
In article ,
 "Peter Tomcsanyi"  wrote:
> Many thanks for the quick reply.
> I will try the MacPorts version, but I am quite Windows-based (I do the Mac 
> installation for somebody else), so I am not sure how to install all the 
> other packages that we use (NumPy, MatPlotLib, Pillow and maybe something 
> else that I do not recall at this moment...). Last time (for the python.org 
> version of Python) I needed to try out several approached from several sites 
> to succeed finally...

MacPorts provides ports for all of those, generally under names like 
py34-matplotlib, py34-Pillow, etc.

http://www.macports.org/ports.php

> So I will impatiently expect the changes "on that front" and I will hope 
> that they will come till August 2014.

Keep your fingers crossed.

-- 
 Ned Deily,
 n...@acm.org

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


How to connect Python3.4.1 to Mysql 5.1 ?

2014-06-25 Thread Raja Sekhar
Can any body tell how to access data from mysql using python. I am using python 
version 3.4.1 and Mysql version 5.1
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: DHCP query script not work.

2014-06-25 Thread 不坏阿峰
anyone can help ?

在 2014年6月19日星期四UTC+7下午8时56分06秒,不坏阿峰写道:
> On Thursday, June 19, 2014 8:49:21 PM UTC+7, Anssi Saari wrote:
> 
> > 不坏阿峰  writes:
> 
> > 
> 
> > 
> 
> > 
> 
> > > Dear all
> 
> > 
> 
> > >
> 
> > 
> 
> > > i got code recipes from here. and i want to run it on win 7. 
> 
> > 
> 
> > > http://code.activestate.com/recipes/577649-dhcp-query/
> 
> > 
> 
> > 
> 
> > 
> 
> > It works for me as is in Windows 7. It's a Python 3 script though which
> 
> > 
> 
> > might be your problem.
> 
> 
> 
> 
> 
> i got that my issue is the Python version , my is 2.7. i am not familiar with 
> 3.and my tools coded by 2.7.   
> 
> 
> 
> i am stucked on this script.  tks for ur reply.  hope have someone change 
> this script work on 2.7
-- 
https://mail.python.org/mailman/listinfo/python-list


subprocess can not kill when app exit()

2014-06-25 Thread 不坏阿峰
Dear all

code in below,  when close the app window.  the two ping process can not kill 
auto and keep in the windows 7 task list.

During running, ping process under Python.exe as two thread. When app exit,  
this two process move the system process and keep running there.

could someone help to correct it.?
Many thanks.


# -*- coding: utf-8 -*-
 
import sys
import time
import subprocess
from threading import Thread
import re
from PyQt4.QtGui import QMainWindow, QApplication, QStandardItemModel, 
QStandardItem, QWidget, QVBoxLayout, QTableView
from PyQt4.QtCore import pyqtSignature, Qt, QTimer, SIGNAL, QString, QMetaObject
from Queue import Queue

try:
_fromUtf8 = QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s
 
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(500, 435)
self.centralWidget = QWidget(MainWindow)
self.centralWidget.setObjectName(_fromUtf8("centralWidget"))
self.verticalLayout = QVBoxLayout(self.centralWidget)
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.tableView = QTableView(self.centralWidget)
self.tableView.setObjectName(_fromUtf8("tableView"))
self.verticalLayout.addWidget(self.tableView)
MainWindow.setCentralWidget(self.centralWidget)
 
self.retranslateUi(MainWindow)
QMetaObject.connectSlotsByName(MainWindow)
 
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(QApplication.translate("MainWindow", "Ping 
Tester", None, QApplication.UnicodeUTF8))
 
if sys.platform.startswith('linux'):
getdata = re.compile(r"icmp_req=(\d+) ttl=(\d+) time=([\d\.]+)\sms")
pingstr = ["ping", "-n", "-i 0.2"]
filtered = "Packet filtered"
delaytime = 200
else:
getdata = re.compile(r"=([\d\.]+)ms TTL=(\d+)")
pingstr = ["ping.exe", "-t"]
timeout = "Request timed out."
delaytime = 500
 
try:
with open("ips.conf", "r") as f:
t_node = f.read().decode('utf-8')
if not t_node:
raise IOError
except IOError:
with open("ips.conf", "w") as f:
t_node = u"""
8.8.8.8-Google
184.22.112.34-USAHE
"""
f.write(t_node.encode('utf-8'))
 
node = []
for line in t_node.split('\n'):
try:
ip, desc = line.strip().split("-")
node.append((ip, desc))
except ValueError:
pass
nodecount = len(node)
 
class MainWindow(QMainWindow, Ui_MainWindow):
"""
Class documentation goes here.
"""
def __init__(self, parent = None):
"""
Constructor
"""
QMainWindow.__init__(self, parent)
self.setupUi(self)
self.model = QStandardItemModel()
self.model.setColumnCount(6)
self.model.setRowCount(nodecount)
self.model.setHorizontalHeaderLabels(["IP", "Description", "Loss%", 
"CurPing", "AvgPing", "TTL"])
for i, (ip, desc) in enumerate(node):
self.setitem(i, 0, ip)
self.setitem(i, 1, desc)
self.setitem(i, 2, "")
self.setitem(i, 3, "")
self.setitem(i, 4, "")
self.setitem(i, 5, "")
self.tableView.setModel(self.model)
for i in range(len(node)):
self.tableView.setRowHeight(i, 18)
self.resizetable()
self.timer = QTimer(self)
self.connect(self.timer,
 SIGNAL("timeout()"),
 self.checkitems)
self.timer.start(delaytime)
 
def checkitems(self):
while not q.empty():
item = q.get()
self.chgtxt(*item)
q.task_done()
self.resizetable()
 
def resizetable(self):
self.tableView.resizeColumnsToContents()
 
def chgtxt(self, x, y, value):
self.model.item(x, y).setText(value)
 
def setitem(self, x, y, value):
self.model.setItem(x, y, QStandardItem(value))
 
app = QApplication(sys.argv)
ui = MainWindow()
ui.show()
q = Queue()
 
def pinger(i, ip, desc):
s = ""
avgping = 0
count = 0
timeoutcount = 0
ret = subprocess.Popen(pingstr + [ip],
stdout=subprocess.PIPE)
while True:
try:
s += ret.stdout.read(1)
 
tryfind = getdata.findall(s)
if sys.platform.startswith('linux'):
if len(tryfind) > 0:
req, ttl, crtping = tryfind[-1]
avgping += float(crtping)
count += 1
q.put((i, 3, crtping + "ms"))
q.put((i, 4, "%.2f" % (avgping * 1.0 / count) + "ms"))
q.put((i, 5, ttl))
q.put((i, 2, "%.2f" % ((int(req) - count) * 100.0 / 
int(req
s = ""
elif filtered in s:
q.put((i, 2, "Failed"))
q.put((i, 3, "Failed"))
 

Re: Qt and progressBar - how to update

2014-06-25 Thread 不坏阿峰
在 2010年5月17日星期一UTC+7上午2时38分04秒,OMS写道:
> On 16 Maj, 20:52, Robert Kern  wrote:
> > On 2010-05-16 13:28 , OMS wrote:
> >
> >
> >
> > > I am quite new to Python and Qt and need very urgently advice on how
> > > to update Qt progressBar while executing a process. I have went thrugh
> > > number of 'google' stuff and saw different solution, hence none worked
> > > for me. The best idea I have seen is the usage of QThread and emiting
> > > signal from thread to MainWindow. I do not know however why the code I
> > > have written is not working. Most likely a stupid 'beginner related'
> > > error but as far as I am beginner I can't get it. There is a code
> > > below:
> >
> > > #!/opt/local/bin/python2.6
> >
> > > import os
> > > import sys
> > > import time
> > > from PyQt4 import QtCore
> > > from PyQt4 import QtGui
> >
> > > from uiTest import Ui_MainWindow
> >
> > > class MainWindow(QtGui.QMainWindow):
> > >  def __init__(self):
> > >  QtGui.QMainWindow.__init__(self)
> > >  self.ui=Ui_MainWindow()
> > >  self.ui.setupUi(self)
> > >  self.connect(self.ui.pushButton, QtCore.SIGNAL("clicked()"),
> > > self.runWorker)
> >
> > >  def runWorker(self):
> > >  self.worker = Worker()
> > >  self.connect(self.worker, QtCore.SIGNAL("progressUpdated"),
> > > self.updateWorkerProgress)
> > >  self.worker.start()
> >
> > >  def updateWorkerProgress(self, min, max, progress):
> > >  self.ui.progressBar.setMinimum = min
> > >  self.ui.progressBar.setMaximum = max
> > >  self.ui.progressBar.setValue = progress
> >
> > These should be
> >
> > self.ui.progressBar.setMinimum(min)
> > self.ui.progressBar.setMaximum(max)
> > self.ui.progressBar.setValue(progress)
> >
> > --
> > Robert Kern
> 
> Thanks. You have saved the day. I knew it must be something only
> greenhorn could do.
> 
> Once again thanks!

in ur code, u use self.progress in range(self.min, self.max) to define the 
progress bar time.

if want update prograss bar, base on how long dose the Qthread running take?  
how to do ?
-- 
https://mail.python.org/mailman/listinfo/python-list


How to get Timezone from latitude/longitude ?

2014-06-25 Thread codetarsier
Hi,

I'm looking for a python-library which can help me to get Timezone and 
Timezone-offset(UTC) from latitude/longitude. 

I'm not able to find an easy way to do it.

Thanks in advance. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to get Timezone from latitude/longitude ?

2014-06-25 Thread Larry Martell
On Wed, Jun 25, 2014 at 8:53 AM,   wrote:
> Hi,
>
> I'm looking for a python-library which can help me to get Timezone and 
> Timezone-offset(UTC) from latitude/longitude.
>
> I'm not able to find an easy way to do it.
>
> Thanks in advance.

It took me 30 seconds on google to find this:

https://github.com/pegler/pytzwhere
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to get Timezone from latitude/longitude ?

2014-06-25 Thread Bernd Nawothnig
On 2014-06-25, codetars...@gmail.com wrote:
> I'm looking for a python-library which can help me to get Timezone and
> Timezone-offset(UTC) from latitude/longitude. 
>
> I'm not able to find an easy way to do it.

You can find the data as a zipped shapefile here:

http://efele.net/maps/tz/world/

Download the data and use pyshp and/or gdal/ogr for the lookup.

It may not be as simple as you wanted it to be, but it is possible.




Bernd

-- 
no time toulouse
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to get Timezone from latitude/longitude ?

2014-06-25 Thread Chris Angelico
On Wed, Jun 25, 2014 at 10:53 PM,   wrote:
> I'm looking for a python-library which can help me to get Timezone and 
> Timezone-offset(UTC) from latitude/longitude.
>
> I'm not able to find an easy way to do it.

There isn't an easy way to do it.

At best, you would have to do a two-step lookup: first, figure out
what country and city you're in, based on lat/long; and then, look up
the appropriate timezone from the city. Unfortunately that won't
actually be perfect, because there are points on this planet's surface
that cannot be unambiguously assigned timezones... because timezones
are really messy.

Normally, the way to define timezones would be with the Olsen database
(tzdata), which defines "Australia/Melbourne" (where I live),
"America/Merida" (which is not a reimagining of "Brave" on a different
continent), "Africa/Libreville" (which presumably is where a popular
office suite came from), and so on. If you can get your users to pick
based on those, your work will be easy and unambiguous. Otherwise,
you're going to have a lot of work trying to recreate that...

Why do you need to work this out? Are you trying to use a user's IP
geolocation data to pick a timezone? Because that's doomed to failure.
Even if you have something like a phone's GPS fix, trying to guess the
timezone based on that is a bad idea. In fact, guessing is almost
always a bad idea.

On the other hand, if all you need is a rough approximation, just take
the longitude (positive if you're east of Greenwich, negative if
west), and multiply it by 24 hours/360° to get a theoretical timezone.
That's good enough for planting on a map, or for getting a rough idea
of whether it's morning, noon, evening, or night; most actual civil
timezones will be broadly near to that figure. (Some are a long way
away from it, though. New Zealand's Chatham Islands are at around
176.5°W, for a theoretical timezone of roughly UTC-11:45, but the
actual timezone is UTC+12:45, almost but not exactly an entire day
ahead of where you might think.) Of course, that ignores every civil
invention, including the abomination of DST, but that might be
considered an advantage rather than a flaw...

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


Re: How to get Timezone from latitude/longitude ?

2014-06-25 Thread Marko Rauhamaa
Chris Angelico :

> Are you trying to use a user's IP geolocation data to pick a timezone?
> Because that's doomed to failure.

Some years back my employer switched ISPs in Southern California. The
following morning Google displayed everything in Hebrew. It took a week
or two to be corrected.


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to get Timezone from latitude/longitude ?

2014-06-25 Thread Grant Edwards
On 2014-06-25, Marko Rauhamaa  wrote:
> Chris Angelico :
>
>> Are you trying to use a user's IP geolocation data to pick a timezone?
>> Because that's doomed to failure.
>
> Some years back my employer switched ISPs in Southern California. The
> following morning Google displayed everything in Hebrew. It took a week
> or two to be corrected.

Learning Hebrew in a week or two is a pretty impressive feat.

-- 
Grant Edwards   grant.b.edwardsYow! ... I want to perform
  at   cranial activities with
  gmail.comTuesday Weld!!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3.4.1 installer on Mac links Python to old Tcl/Tk

2014-06-25 Thread Kevin Walzer

On 6/25/14, 1:49 AM, wxjmfa...@gmail.com wrote:

I can also add, tcl or tk or tkinter (8.6) is on Windows
quite buggy. In fact, simply*unusable*.


How so?

Please report bugs at http://core.tcl.tk/tcl/reportlist or 
http://core.tcl.tk/tk/reportlist, as needed.


--Kevin

--
Kevin Walzer
Code by Kevin/Mobile Code by Kevin
http://www.codebykevin.com
http://www.wtmobilesoftware.com
--
https://mail.python.org/mailman/listinfo/python-list


Re: How to get Timezone from latitude/longitude ?

2014-06-25 Thread Ethan Furman

On 06/25/2014 07:24 AM, Grant Edwards wrote:

On 2014-06-25, Marko Rauhamaa wrote:


Some years back my employer switched ISPs in Southern California. The
following morning Google displayed everything in Hebrew. It took a week
or two to be corrected.


Learning Hebrew in a week or two is a pretty impressive feat.


Maybe he learned using one of those language classes I keep hearing about in my 
email...

--
~Ethan~
--
https://mail.python.org/mailman/listinfo/python-list


Single underscore in interactive mode

2014-06-25 Thread candide
According to the official documentation (The Python Language Reference, Release 
3.2):


---
The special identifier _ is used in the interactive interpreter to
store the result of the last evaluation;
---


This description is not very specific. Which evaluation is it about ? Consider 
the following interactive mode session:

>>> z = 42 + 1
>>> _
Traceback (most recent call last):
  File "", line 1, in 
_
NameError: name '_' is not defined
>>> 

As explained by the docs, an assignment statement _evaluates_ the expression on 
the right hand side. So we can deduce that at the very beginning of the 2nd 
prompt, "the result of the last evaluation" is 43. Nevertheless, calling _ 
raises a NameError exception!



In fact it seems that underscore returns the value of the last expression 
statement which is different from None :


>>> 4*10+2
42
>>> _
42
>>> "hello"
'hello'
>>> _
'hello'
>>> print(42)
42
>>> _
'hello'
>>> None
>>> _
'hello'
>>>


Can somebody provide a correct specification of the _ identifier in interactive 
mode ?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Single underscore in interactive mode

2014-06-25 Thread Robert Kern

On 2014-06-25 16:20, candide wrote:

According to the official documentation (The Python Language Reference, Release 
3.2):


---
The special identifier _ is used in the interactive interpreter to
store the result of the last evaluation;
---


This description is not very specific. Which evaluation is it about ? Consider 
the following interactive mode session:


z = 42 + 1
_

Traceback (most recent call last):
   File "", line 1, in 
 _
NameError: name '_' is not defined




As explained by the docs, an assignment statement _evaluates_ the expression on the right 
hand side. So we can deduce that at the very beginning of the 2nd prompt, "the 
result of the last evaluation" is 43. Nevertheless, calling _ raises a NameError 
exception!



In fact it seems that underscore returns the value of the last expression 
statement which is different from None :



4*10+2

42

_

42

"hello"

'hello'

_

'hello'

print(42)

42

_

'hello'

None
_

'hello'





Can somebody provide a correct specification of the _ identifier in interactive 
mode ?


See the documentation on `sys.displayhook()`, which is the function that makes 
the assignment:


https://docs.python.org/3/library/sys.html#sys.displayhook

--
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

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


[RELEASE] fastcache

2014-06-25 Thread ptb
Hello all,

I am pleased to announce the release of fastcache v0.1.  It is intended to be a 
drop in replacement for functools.lru_cache but it's written in C so it's 5-10x 
faster.  Currently Python >= 3.3 is supported.

It is available on pip via:

pip install fastcache

Or on github:

https://github.com/pbrady/fastcache.git

More details related to benchmarking and testing can also be found on the 
github page.  

Feel free to direct any issues or requests to the github page.

I look forward to your feedback!

Thanks,
Peter.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Single underscore in interactive mode

2014-06-25 Thread Terry Reedy

On 6/25/2014 11:20 AM, candide wrote:

According to the official documentation (The Python Language Reference, Release 
3.2):


---
The special identifier _ is used in the interactive interpreter to
store the result of the last evaluation;
---


This description is not very specific.


Please say either in a tracker issue or here where you found this 
statement. I think 'evaluation' should be changed to 'non-None 
expression statement' and 'see sys.displayhook' added, linked to the 
entry in the sys doc.



--
Terry Jan Reedy

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


asyncio: wrapping a subprocess in a server

2014-06-25 Thread David Farler
Hi all,

I'm trying to vend some kind of server that spawns a client-unique subprocess 
when a client connects. The server acts as a middleman, receiving structure 
messages from the client, sending input to the subprocess, and packaging up 
subprocess data before sending back to the client. The connection is long-lived 
and the client can continue to send "requests". If the subprocess crashes or 
dies, the server should be able to revive it transparently.

I know how to separately create server and subprocess protocols and having the 
event loop run either until completion, but what is the best way to chain two 
protocols together?

|| Client || <~~ TCP ~~> || Server <--> Subprocess ||

Regards,
David

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


Re: Single underscore in interactive mode

2014-06-25 Thread Lie Ryan

On 25/06/14 16:20, candide wrote:


As explained by the docs, an assignment statement_evaluates_  the expression on the right 
hand side. So we can deduce that at the very beginning of the 2nd prompt, "the 
result of the last evaluation" is 43. Nevertheless, calling _ raises a NameError 
exception!


Only expression can be evaluated, statements are executed. The shell 
cannot see beyond the immediate statement.


The documentation for sys.displayhook() describes that None as a special 
case is neither printed nor stored in `__builtins__._`.


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


Re: Python 3.4.1 installer on Mac links Python to old Tcl/Tk

2014-06-25 Thread Peter Tomcsanyi
"Christian Gollwitzer"  wrote in message 
news:lodruv$k45$1...@dont-email.me...

Hi Peter,
may I ask which features of 8.6 you need in particular?


Hi Christian,

I need two of them:
- Angled text
- PNG image support with alpha channel (even if it seems a bit limited, 
particularly I still did not find the way to programmatically set/read the 
alpha channel of one individual pixel of the image, but maybe it is just my 
inability and a question to another newsgroup).


Peter


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


Re: Single underscore in interactive mode

2014-06-25 Thread candide

> 
> Please say either in a tracker issue or here where you found this 
> 
> statement. 



https://docs.python.org/3.4/reference/lexical_analysis.html#reserved-classes-of-identifiers
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: asyncio: wrapping a subprocess in a server

2014-06-25 Thread Akira Li
David Farler  writes:

> Hi all,
>
> I'm trying to vend some kind of server that spawns a client-unique
> subprocess when a client connects. The server acts as a middleman,
> receiving structure messages from the client, sending input to the
> subprocess, and packaging up subprocess data before sending back to
> the client. The connection is long-lived and the client can continue
> to send "requests". If the subprocess crashes or dies, the server
> should be able to revive it transparently.
>
> I know how to separately create server and subprocess protocols and
> having the event loop run either until completion, but what is the
> best way to chain two protocols together?
>
> || Client || <~~ TCP ~~> || Server <--> Subprocess ||

Here's an example that uses Twisted http://stackoverflow.com/a/11729467

  javascript client <--> websocket <--> twisted server <--> subprocess

Do you want the same but using asyncio module?


--
Akira



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


Re: How to get Timezone from latitude/longitude ?

2014-06-25 Thread Akira Li
Larry Martell  writes:

> On Wed, Jun 25, 2014 at 8:53 AM,   wrote:
>> Hi,
>>
>> I'm looking for a python-library which can help me to get Timezone
>> and Timezone-offset(UTC) from latitude/longitude.
>>
>> I'm not able to find an easy way to do it.
>>
>> Thanks in advance.
>
> It took me 30 seconds on google to find this:
>
> https://github.com/pegler/pytzwhere

Note: tzwhere may consume 750GB memory doing nothing
https://github.com/pegler/pytzwhere/pull/10

You could generate a postgis timezone database from efele.net/tz map or
use an online service instead http://stackoverflow.com/a/16519004


--
akira

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


Re: Python 3.4.1 installer on Mac links Python to old Tcl/Tk

2014-06-25 Thread Christian Gollwitzer

Am 25.06.14 21:26, schrieb Peter Tomcsanyi:

"Christian Gollwitzer"  wrote in message
news:lodruv$k45$1...@dont-email.me...

may I ask which features of 8.6 you need in particular?


I need two of them:
- Angled text
- PNG image support with alpha channel (even if it seems a bit limited,
particularly I still did not find the way to programmatically set/read
the alpha channel of one individual pixel of the image, but maybe it is
just my inability and a question to another newsgroup).


For PNG image support you can load either the Img package which gives 
support for a large variety of images, or the smaller tkpng package. 
After loading these, Tk 8.5 will accept PNG as in 8.6. For angled text 
it's right, I don't know, there used to be some hacks before, it's 
probably not possible in a clean way. Glad to see, that you are pushing 
the adoption of 8.6 ;) (I'm a Tcl-guy)


Christian
--
https://mail.python.org/mailman/listinfo/python-list


Re: Passing a frame to pdb.Pdb.set_trace

2014-06-25 Thread Rotwang

On 24/06/2014 20:10, Rotwang wrote:

Hi all, I've found something weird with pdb and I don't understand it. I
want to define a function mydebugger() which starts the debugger in the
caller's frame. The following is copied from IDLE with Python 2.7.3
(I've since tried it with 3.3.0 and the same thing happens):

[...]


Never mind, I figured out what's going on thanks to an excellent article 
by Ned Batchelder explaining the internals of pdb:


http://nedbatchelder.com/text/trace-function.html
--
https://mail.python.org/mailman/listinfo/python-list


Re: python 3.44 float addition bug?

2014-06-25 Thread Maciej Dziardziel
On Saturday, June 21, 2014 1:57:19 AM UTC+1, FraserL wrote:
> I'm not hugely accustomed to Python, but this seems crazy to me.

Floating points values use finite amount of memory, and  cannot accurately 
represent infinite amount of numbers, they are only approximations. This is 
limitation of float type and applies to any languages that uses types supported 
directly by cpu.
To deal with it you can either use decimal.Decimal type that operates using 
decimal system and saves you from such surprises (but it will be much slower 
and incompatible with c code that doesn't handle decimals or converts them to 
floats) or use epsilon for every comparison and rounding/formatting with 
limited   precision for displaying.

Few more details are here: http://floating-point-gui.de/errors/comparison/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Single underscore in interactive mode

2014-06-25 Thread Dave Angel
Terry Reedy  Wrote in message:
> On 6/25/2014 11:20 AM, candide wrote:
>> According to the official documentation (The Python Language Reference, 
>> Release 3.2):
>>
>>
>> ---
>> The special identifier _ is used in the interactive interpreter to
>> store the result of the last evaluation;
>> ---
>>
>>
>> This description is not very specific.
> 
> Please say either in a tracker issue or here where you found this 
> statement. I think 'evaluation' should be changed to 'non-None 
> expression statement' and 'see sys.displayhook' added, linked to the 
> entry in the sys doc.
> 
> 
https://pydocs2cn.readthedocs.org/en/latest/reference/lexical_anal
ysis.html

https://docs.python.org/2/reference/lexical_analysis.html


-- 
DaveA

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


protect psycopg script from sql injection?

2014-06-25 Thread celati Laurent
Hello,

I coded this following python script via psycopg;

web_service_test.py


1/ When i execute it, the result is 'bad resquest'. Could you tell me why?

2/ Could you tell me how to protect this script from SQL injections please?

Thank you.


web_service_test.py
Description: Binary data
-- 
https://mail.python.org/mailman/listinfo/python-list


protect psycopg script from sql injection?

2014-06-25 Thread dandrigo
Hello,

I coded this following python script via psycopg;

web_service_test.py
  

1/ When i execute it, the result is 'bad resquest'. Could you tell me why? 

2/ Could you tell me how to protect this script from SQL injections please? 

Thank you. 





--
View this message in context: 
http://python.6.x6.nabble.com/protect-psycopg-script-from-sql-injection-tp5062113.html
Sent from the Python - python-list mailing list archive at Nabble.com.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: protect psycopg script from sql injection?

2014-06-25 Thread MRAB

On 2014-06-25 22:58, celati Laurent wrote:

Hello,

I coded this following python script via psycopg;

web_service_test.py


1/ When i execute it, the result is 'bad resquest'. Could you tell me why?

2/ Could you tell me how to protect this script from SQL injections please?


In answer to question 2, don't insert the values into the query string
as you're doing here:

selectString = "SELECT ST_AsText(geom), cult_lib FROM rpg WHERE 
ST_Intersects(SELECT ST_GeomFromText('POINT(%s %s)',2154), rpg)" % (x, y)


Instead, use the placeholder %s in the query string to indicate where a
values should go and then pass that query string and a tuple of the
values to the .execute method:

selectString = "SELECT ST_AsText(geom), cult_lib FROM rpg WHERE 
ST_Intersects(SELECT ST_GeomFromText('POINT(%s %s)',2154), rpg)"


cur.execute(selectString, (x, y))

The database engine will insert the values itself, safely.
--
https://mail.python.org/mailman/listinfo/python-list


Re: How to get Timezone from latitude/longitude ?

2014-06-25 Thread Gregory Ewing

Ethan Furman wrote:

On 06/25/2014 07:24 AM, Grant Edwards wrote:


On 2014-06-25, Marko Rauhamaa wrote:


Some years back my employer switched ISPs in Southern California. The
following morning Google displayed everything in Hebrew. It took a week
or two to be corrected.


Learning Hebrew in a week or two is a pretty impressive feat.


Maybe he learned using one of those language classes I keep hearing 
about in my email...


Nah, the solution's obvious -- just use Google Translate
to turn it back into English.

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Re: subprocess can not kill when app exit()

2014-06-25 Thread Jason Friedman
> code in below,  when close the app window.  the two ping process can not kill 
> auto and keep in the windows 7 task list.
>
> During running, ping process under Python.exe as two thread. When app exit,  
> this two process move the system process and keep running there.
>
> could someone help to correct it.?
> Many thanks.

Hello,
That's a lot of code to read through.
I recommend you read
http://www.catb.org/~esr/faqs/smart-questions.html and then re-submit.
Good luck.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: subprocess can not kill when app exit()

2014-06-25 Thread Michael Torrie
On 06/25/2014 06:07 PM, Jason Friedman wrote:
>> code in below,  when close the app window.  the two ping process can not 
>> kill auto and keep in the windows 7 task list.
>>
>> During running, ping process under Python.exe as two thread. When app exit,  
>> this two process move the system process and keep running there.
>>
>> could someone help to correct it.?
>> Many thanks.
> 
> Hello,
> That's a lot of code to read through.
> I recommend you read
> http://www.catb.org/~esr/faqs/smart-questions.html and then re-submit.
> Good luck.

Indeed. Post the shortest possible code that illustrates your problem,
then ask some specific, clear questions and I'm sure we can help you
out.  With the complete, minimal example (a dozen lines of code
perhaps), state what you want to happen, what does happen, and any
output including full traces.

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


Re: py2app dependency determination?

2014-06-25 Thread john
Steven D'Aprano wrote:

> On Sat, 21 Jun 2014 16:50:22 -0800, john wrote:
> 
>> Hi, trying to get py2app to work. It keeps saying that we need
>> Pillow-PIL, which is wrong. And, anyways, Pillow-PIL fails to install.
>> 
>> The program works fine as a normal python script, and it doesn't use
>> Pillow- PIL. Any ideas?
> 
> Yes.
> 
> (1) Since this is specifically a py2app issue, you may have better
> results from asking on a dedicated py2app mailing list.
> 
> (2) Is it possible that Pillow or PIL is a dependency of py2app, and the
> error has nothing to do with your script at all? What happens if you run
> py2app on a minimal script like this?
> 
> # hello.py
> print("hello world")
> 
> (3) If not, please post a minimal set of steps that demonstrates the
> problem, and the *exact* error message generated (if possible). For
> example:
> 
> Download py2app version 1.3 from http://some.place.com
> 
> Run the py2app installer.
> 
> Create a minimal script hello.py (as above)
> 
> Run py2app hello.py
> 
> The result is ... [whatever actually happens]
> 
> 
> 

We will try that, thank you
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python 3.44 float addition bug?

2014-06-25 Thread Steven D'Aprano
On Wed, 25 Jun 2014 14:12:31 -0700, Maciej Dziardziel wrote:

> Floating points values use finite amount of memory, and  cannot
> accurately represent infinite amount of numbers, they are only
> approximations. This is limitation of float type and applies to any
> languages that uses types supported directly by cpu. To deal with it you
> can either use decimal.Decimal type that operates using decimal system
> and saves you from such surprises

That's a myth. decimal.Decimal *is* a floating point value, and is 
subject to *exactly* the same surprises as binary floats, except for one: 
which Decimal, you can guarantee that any decimal string you enter will 
appear exactly the same (up to the limit of the current precision).

For example:

py> x = Decimal(1)/Decimal(23)
py> x
Decimal('0.04347826086956521739130434783')
py> x*23 == 1
True
py> sum( [x]*23 ) == 1  # Surprise!
False

py> (Decimal(19)/Decimal(17))*Decimal(17) == 19  # Surprise!
False



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


Re: python 3.44 float addition bug?

2014-06-25 Thread Chris Angelico
On Thu, Jun 26, 2014 at 12:56 PM, Steven D'Aprano  wrote:
> That's a myth. decimal.Decimal *is* a floating point value, and is
> subject to *exactly* the same surprises as binary floats, except for one:
> which Decimal, you can guarantee that any decimal string you enter will
> appear exactly the same (up to the limit of the current precision).

The important difference is that the issues with decimal floats come
where humans are comfortable seeing them. If you divide 1 by 3, you
get 0.3 and can understand that adding three of those together
won't quite make 1.0, because you can see that you shortened it. If
you divide 11 by 10, it's not obvious that that repeats.

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


Re: python 3.44 float addition bug?

2014-06-25 Thread Ben Finney
Steven D'Aprano  writes:

> On Wed, 25 Jun 2014 14:12:31 -0700, Maciej Dziardziel wrote:
>
> > Floating points values use finite amount of memory, and cannot
> > accurately represent infinite amount of numbers, they are only
> > approximations. This is limitation of float type and applies to any
> > languages that uses types supported directly by cpu. To deal with it
> > you can either use decimal.Decimal type that operates using decimal
> > system and saves you from such surprises
>
> That's a myth. decimal.Decimal *is* a floating point value

That's misleading: Decimal uses *a* floating-point representation, but
not the one commonly referred to. That is, Decimal does not use IEEE-754
floating point.

> and is subject to *exactly* the same surprises as binary floats,

Since those “surprises” are the ones inherent to *decimal*, not binary,
floating point, I'd say it's also misleading to refer to them as
“exactly the same surprises”. They're barely surprises at all, to
someone raised on decimal notation.

This makes the Decimal functionality starkly different from the built-in
‘float’ type, and it *does* save you from the rather-more-surprising
behaviour of the ‘float’ type. This is not mythical.

-- 
 \ “Guaranteed to work throughout its useful life.” —packaging for |
  `\  clockwork toy, Hong Kong |
_o__)  |
Ben Finney

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


State of speeding up Python for full applications

2014-06-25 Thread CM
I occasionally hear about performance improvements for Python by various 
projects like psyco (now old), ShedSkin, Cython, PyPy, Nuitka, Numba, and 
probably many others.  The benchmarks are out there, and they do make a 
difference, and sometimes a difference on par with C, from what I've heard.

What I have never quite been able to get is the degree to which one can 
currently use these approaches to speed up a Python application that uses 3rd 
party libraries...and that the approaches will "just work" without the 
developer having to know C or really do a lot of difficult under-the-hood sort 
of work.

For examples, and considering an application written for Python 2.7, say, and 
using a GUI toolkit, and a handful of 3rd party libraries:

- Can you realistically package up the PyPy interpreter and have the app run 
faster with PyPy?  And can the application be released as a single file 
executable if you use PyPy?

- Can you compile it with Nuitka to C?

I've had the (perhaps overly pessimistic) sense that you still *can't* do these 
things, because these projects only work on pure Python, or if they do work 
with other libraries, it's always described with major caveats that "I wouldn't 
try this in production" or "this is just a test" sort of thing, such as PyPy 
and wxPython.

I'd love to know what's possible, since getting some even modest performance 
gains would probably make apps feels snappier in some cases, and yet I am not 
up for the job of the traditional advice about "re-writing those parts in C".

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


Re: python 3.44 float addition bug?

2014-06-25 Thread Steven D'Aprano
On Thu, 26 Jun 2014 13:13:45 +1000, Chris Angelico wrote:

> On Thu, Jun 26, 2014 at 12:56 PM, Steven D'Aprano 
> wrote:
>> That's a myth. decimal.Decimal *is* a floating point value, and is
>> subject to *exactly* the same surprises as binary floats, except for
>> one: which Decimal, you can guarantee that any decimal string you enter
>> will appear exactly the same (up to the limit of the current
>> precision).
> 
> The important difference is that the issues with decimal floats come
> where humans are comfortable seeing them. If you divide 1 by 3, you get
> 0.3 and can understand that adding three of those together won't
> quite make 1.0, because you can see that you shortened it. If you divide
> 11 by 10, it's not obvious that that repeats.

I'm not sure if you're agreeing with me or disagreeing with me.

"Repeats" is a property of a number *in a specific base*, not of the 
number itself. So 1/3 does not repeat in base 3, where it would be 
written as the terminating trinary number 0.1. Likewise, 11/10 repeats in 
base 2, but not in base 10.

What I am I saying is that regardless of whether you use binary floats or 
base-10 Decimals, not all rational numbers x/y can be represented 
exactly. I certainly wasn't saying that the same rationals are inexact in 
both bases, just that the surprise "x/y is not exact" occurs whether you 
have binary or decimal floating point numbers.

Likewise for all other floating point issues, except the surprise "this 
base-2 float is not exactly equal to the base-10 number I typed". Because 
Decimal is base-10, what you type is what you get.


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


Re: python 3.44 float addition bug?

2014-06-25 Thread Chris Angelico
On Thu, Jun 26, 2014 at 2:17 PM, Steven D'Aprano  wrote:
> I'm not sure if you're agreeing with me or disagreeing with me.
>
> "Repeats" is a property of a number *in a specific base*, not of the
> number itself. So 1/3 does not repeat in base 3, where it would be
> written as the terminating trinary number 0.1. Likewise, 11/10 repeats in
> base 2, but not in base 10.
>
> What I am I saying is that regardless of whether you use binary floats or
> base-10 Decimals, not all rational numbers x/y can be represented
> exactly. I certainly wasn't saying that the same rationals are inexact in
> both bases, just that the surprise "x/y is not exact" occurs whether you
> have binary or decimal floating point numbers.
>
> Likewise for all other floating point issues, except the surprise "this
> base-2 float is not exactly equal to the base-10 number I typed". Because
> Decimal is base-10, what you type is what you get.

Broadly agreeing, but with the caveat that, as you say, "repeats"
depends on the base - and there's one base that most humans use, and
it's not the base that IEEE floats use. So when I said that 11/10
repeats, I mean that it repeats in binary, which causes precision
problems with binary floats; but everyone who's done basic work with
vulgar and decimal fractions understands that 1/3 can't be perfectly
represented in decimal.

So the problems with floating point representations are indeed common
to float and decimal.Decimal, but they're more surprising with float
because humans aren't used to tenths repeating.

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


Re: python 3.44 float addition bug?

2014-06-25 Thread Stefan Behnel
Steven D'Aprano, 26.06.2014 04:56:
> On Wed, 25 Jun 2014 14:12:31 -0700, Maciej Dziardziel wrote:
> 
>> Floating points values use finite amount of memory, and  cannot
>> accurately represent infinite amount of numbers, they are only
>> approximations. This is limitation of float type and applies to any
>> languages that uses types supported directly by cpu. To deal with it you
>> can either use decimal.Decimal type that operates using decimal system
>> and saves you from such surprises
> 
> That's a myth. decimal.Decimal *is* a floating point value, and is 
> subject to *exactly* the same surprises as binary floats, except for one: 
> which Decimal, you can guarantee that any decimal string you enter will 
> appear exactly the same (up to the limit of the current precision).
> 
> For example:
> 
> py> x = Decimal(1)/Decimal(23)
> py> x
> Decimal('0.04347826086956521739130434783')
> py> x*23 == 1
> True
> py> sum( [x]*23 ) == 1  # Surprise!
> False
> 
> py> (Decimal(19)/Decimal(17))*Decimal(17) == 19  # Surprise!
> False

It seems that no-one has mentioned the "fractions" module in this thread
yet. It gives you rational numbers (enumerator/denominator), as supposed to
the limited real numbers that floating point numbers represent.

https://docs.python.org/3/library/fractions.html

There are quite a number of use cases for exact calculations where rational
numbers beat any other solution. For the cases above, for example, you'd
get exact results by design. Or in currency calculations, where you want to
move the rounding to the very end and prevent any loss of precision along
the way (unless you're trying to tweak your account in the right direction,
that is).

Stefan


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


Re: Python 3 on Mac OS X 10.8.4

2014-06-25 Thread Une Bévue

Le 19/06/2014 12:43, Andrew Jaffe a écrit :

The python.org packages are explicitly created in order to have no
conflict with the system installed python. There is no problem with
using them.


OK, fine thanks.
--
https://mail.python.org/mailman/listinfo/python-list