Re: What library/package to use for parsing XML?

2017-01-31 Thread Chris Green
Irmen de Jong  wrote:
> On 30-1-2017 18:58, Chris Green wrote:
> > I want to parse some XML data, it's the address book data from the
> > linux program osmo.  The file I want to parse is like this:-
> > 
> 
> [snip]
> 
> > 
> > I basically want to be able to extract the data and output in other
> > formats - e.g. write to a Sqlite3 database and/or CSV.
> > 
> > So what do I need to import (and probably install first) to do this?
> 
> No need to install anything. Python has batteries included.
> 
> Parse your XML with xml.etree.ElementTree
> [https://docs.python.org/3/library/xml.etree.elementtree.html]
> Read/write CSV with csv
> [https://docs.python.org/3/library/csv.html]
> Put stuff in sqlite3 database and query it using sqlite3
> [https://docs.python.org/3/library/sqlite3.html]
> 

Thanks, it was the ElementTree bit I didn't know.  Searching for
'Python XML' produces so many hits it's difficult to see what's
necessary/best.


-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


command line micro wiki written in Python

2017-01-31 Thread Paul Wolf
I've created a command line utility for managing text files. It's written in 
Python: 

https://github.com/paul-wolf/yewdoc-client

It makes heavy use of the fantastic Click module by Armin Ronacher: 
http://click.pocoo.org/5/

This can be thought of in different ways: 

* A micro-wiki

* A note-taking application

* A file manager

The key aspects are 

* Entirely command-line driven

* Text documents only with a slight preference for Markdown

* Make it easy to operate on documents without having to remember where they 
are or the exact names

* Editor agnostic (vim, emacs, Sublime, Atom, etc.)

Here's how to create a document: 

yd edit "shopping list"

After editing, saving, closing, you can find again: 

➜  yd ls -l shop
   15981278  md   61   2017-01-20 12:15:43   shopping list

While some people might gasp at the idea of a command line wiki, I find using 
the command line with a text editor like emacs the best workflow. I also like 
not having to worry about where a file of this kind is located. You can also 
use it to track configuration files: 

yd take ~/.emacs --symlink

Now, I can edit this. Because it's a link to the actual file - having used the 
`--symlink` option, the configuration file will be updated: 

➜  yd ls -l emacs
  1c608cd7  md  113   2016-12-16 10:53:24   emacs
   ln 183a5b80 txt 5608   2017-01-15 12:59:39   
/Users/paul/.emacs

Using the cloud sync options lets me get my current config file wherever I am, 
completely up-to-date. For a more wiki-like experience, I can load all the 
documents with a common tag so:

yd browse wolf

This converts all the documents tagged with 'wolf' and loads them in a browser 
with a simple navigation sidebar.

Convert a Markdown document called "Python3" to .odt: 

➜ yd convert Python3 odt
python3.odt

There is an optional cloud syncronisation feature that connects to a specific 
endpoint, https://doc.yew.io: 

➜ yd sync

This requires registration at https://doc.yew.io, which can also be done via 
command line. But that is entirely optional.

I'd be interested in feedback if there is any interest in using this kind of 
utility. I'll expose a python API so bulk operations can be done easily on the 
command line or via scripts.
-- 
https://mail.python.org/mailman/listinfo/python-list


update a list element using an element in another list

2017-01-31 Thread Daiyue Weng
Hi, I am trying to update a list of dictionaries using another list of
dictionaries correspondingly. In that, for example,

#  the list of dicts that need to be updated
dicts_1 = [{'dict_1': '1'}, {'dict_2': '2'}, {'dict_3': '3'}]

# dict used to update dicts_1
update_dicts = [{'dict_1': '1_1'}, {'dict_2': '1_2'}, {'dict_3': '1_3'}]

so that after updating,

dicts_1 = [{'dict_1': '1_1'}, {'dict_2': '1_2'}, {'dict_3': '1_3'}]

what's the best way to the updates?

This is actually coming from when I tried to create a list of entities
(dictionaries), then updating the entities using another list dictionaries
using google.cloud.datastore.

entities = [Entity(self.client.key(kind, entity_id)) for entity_id in
entity_ids]

# update entities using update_dicts
for j in range(len(entities)):
for i in range(len(update_dicts)):
if j == i:
entities[j].update(update_dicts[i])

I am wondering is there a brief way to do this.

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


Re: update a list element using an element in another list

2017-01-31 Thread Jussi Piitulainen
Daiyue Weng writes:

> Hi, I am trying to update a list of dictionaries using another list of
> dictionaries correspondingly. In that, for example,
>
> #  the list of dicts that need to be updated
> dicts_1 = [{'dict_1': '1'}, {'dict_2': '2'}, {'dict_3': '3'}]
>
> # dict used to update dicts_1
> update_dicts = [{'dict_1': '1_1'}, {'dict_2': '1_2'}, {'dict_3': '1_3'}]
>
> so that after updating,
>
> dicts_1 = [{'dict_1': '1_1'}, {'dict_2': '1_2'}, {'dict_3': '1_3'}]
>
> what's the best way to the updates?
>
> This is actually coming from when I tried to create a list of entities
> (dictionaries), then updating the entities using another list
> dictionaries using google.cloud.datastore.
>
> entities = [Entity(self.client.key(kind, entity_id)) for entity_id in
> entity_ids]
>
> # update entities using update_dicts
> for j in range(len(entities)):
> for i in range(len(update_dicts)):
> if j == i:
>entities[j].update(update_dicts[i])

[I restored the indentation.]

> I am wondering is there a brief way to do this.

A straightforward algorithmic improvement:

for j in range(len(entities)):
entities[j].update(update_dicts[j])

The real thing:

for e, u in zip(entities, update_dicts):
e.update(u)

A thing between those:

for j, e in enumerate(entities):
e.update(update_dicts[j])

(By symmetry, you could enumerate update_dicts instead.)

It pays to learn zip and enumerate.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: update a list element using an element in another list

2017-01-31 Thread Rhodri James

On 31/01/17 11:28, Daiyue Weng wrote:

Hi, I am trying to update a list of dictionaries using another list of
dictionaries correspondingly. In that, for example,

#  the list of dicts that need to be updated
dicts_1 = [{'dict_1': '1'}, {'dict_2': '2'}, {'dict_3': '3'}]

# dict used to update dicts_1
update_dicts = [{'dict_1': '1_1'}, {'dict_2': '1_2'}, {'dict_3': '1_3'}]

so that after updating,

dicts_1 = [{'dict_1': '1_1'}, {'dict_2': '1_2'}, {'dict_3': '1_3'}]

what's the best way to the updates?

This is actually coming from when I tried to create a list of entities
(dictionaries), then updating the entities using another list dictionaries
using google.cloud.datastore.

entities = [Entity(self.client.key(kind, entity_id)) for entity_id in
entity_ids]

# update entities using update_dicts
for j in range(len(entities)):
for i in range(len(update_dicts)):
if j == i:
entities[j].update(update_dicts[i])

I am wondering is there a brief way to do this.


This all relies on the lists being in the same order and the same 
length, which is probably an unwise assumption, but it's what your code 
does:


for entity, update_dict in zip(entities, update_dicts):
entity.update(update_dict)

range(len(something)) is usually a warning sign (code smell, if you 
prefer) that you aren't thinking in Python.  If you really need the list 
index for some nefarious purpose, enumerate(something) is probably still 
a better bet.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: command line micro wiki written in Python

2017-01-31 Thread Ethan Furman

On 01/31/2017 02:33 AM, Paul Wolf wrote:


I've created a command line utility for managing text files. It's written in 
Python...


That sounds really cool!

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


Re: What are your opinions on .NET Core vs Python?

2017-01-31 Thread Michael Torrie
On 01/30/2017 10:31 PM, Gregory Ewing wrote:
> Michael Torrie wrote:
>> He was saying that you can
>> use the explicit self paradigm in C#. Simply prefix each member variable
>> with "this."
> 
> One can do that in one's own code, but it doesn't help
> you to read the code of someone else who hasn't done
> that. Since it's not part of the C# culture, the vast
> majority of other C# code you encounter won't be using
> it.

Agreed, and that's what I said in response to his suggestion about doing
that.

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


PyDev 5.5.0 Released

2017-01-31 Thread Fabio Zadrozny
PyDev 5.5.0 Release Highlights
---

* **Important** PyDev now requires Java 8 and Eclipse 4.6 (Neon) onwards.

* PyDev 5.2.0 is the last release supporting Eclipse 4.5 (Mars).

* If you enjoy PyDev, you can help in keeping it supported through its
Patreon crowdfunding: https://www.patreon.com/fabioz.

* **Refactoring**

* Fixed refactoring error when dealing with imports which have a
continuation char inside the module name part. **#PyDev-712**

* When extracting a method, decorators are properly considered for the
new method position. **#PyDev-321**

* **Code completion**

* When accessing enums, 'value' and 'name' are properly found.
**#PyDev-591**

* Code completion improved on method chaining. **#PyDev-636** and
**#PyDev-583**

* It's now possible to choose whether when a code-completion which adds
a local import should add the import to the beginning of the function or
the line above where it was requested.

* It may be configured in the preferences (Preferences > PyDev >
Editor > Code Completion > Put local imports on top of method?).

* Default was changed to add it to the top of the method.

* **New actions**

* **Ctrl+Shift+Alt+O** can be used to open the last hyperlink in the
console that's currently open (it's now possible to jump directly to the
error in some exception). **#PyDev-755**

* **Ctrl+2,sw** switches the target and value in assign statements (may
not work properly if more than one '=' is found in the line).

* **Debugger**

* Fixed error when hovering over variable when debugging. **#PyDev-580**

* **Others**

* Fixed issue in grammar parsing on nested async calls. **#PyDev-753**

* Fixed issue grouping imports when an import has a continuation char
inside the module part. **#PyDev 712**


What is PyDev?
---

PyDev is an open-source Python IDE on top of Eclipse for Python, Jython and
IronPython development.

It comes with goodies such as code completion, syntax highlighting, syntax
analysis, code analysis, refactor, debug, interactive console, etc.

Details on PyDev: http://pydev.org
Details on its development: http://pydev.blogspot.com


What is LiClipse?
---

LiClipse is a PyDev standalone with goodies such as support for Multiple
cursors, theming, TextMate bundles and a number of other languages such as
Django Templates, Jinja2, Kivy Language, Mako Templates, Html, Javascript,
etc.

It's also a commercial counterpart which helps supporting the development
of PyDev.

Details on LiClipse: http://www.liclipse.com/



Cheers,

--
Fabio Zadrozny
--
Software Developer

LiClipse
http://www.liclipse.com

PyDev - Python Development Environment for Eclipse
http://pydev.org
http://pydev.blogspot.com

PyVmMonitor - Python Profiler
http://www.pyvmmonitor.com/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What are your opinions on .NET Core vs Python?

2017-01-31 Thread Ian Kelly
On Jan 30, 2017 11:32 PM, "Gregory Ewing" 
wrote:
> That's the thing I find most frustrating about both C# and Java,
> the lack of anything like Python's "from ... import ...". You get
> a choice of either effectively doing "import *" on the contents
> of a whole class and polluting your namespace, or Fully.Qualifying.
> Every.Little.Thing.

I'm not sure about C#, but this is certainly not true in Java. Importing a
class adds exactly one name to your namespace, just as in Python, which is
the unqualified name of the class. Java also has "static import" which lets
you individually import specific static methods or fields from a class.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What are your opinions on .NET Core vs Python?

2017-01-31 Thread Ian Kelly
On Jan 30, 2017 8:00 PM, "Michael Torrie"  wrote:
> In any case, partial classes seems like a misfeature of C# to me but
> apparently they are used when making Windows Forms GUI-based apps.
> Apparently VS autogenerates the class that backs the form, and then the
> developer creates a partial class that extends that to flesh out the
> logic and handle the events.

I'm not sure that partial classes were ever really meant as anything other
than a useful feature for code-generating IDEs. But if you think that's
weird, read up on C# extension methods, which are how users of your classes
can add their own methods to them. True, this is also possible in Python
but requires monkey-patching which is rightfully frowned upon.
-- 
https://mail.python.org/mailman/listinfo/python-list


Python3.6 tkinter bug?

2017-01-31 Thread George Trojan - NOAA Federal
The following program behaves differently under Python 3.6:

'''
checkbutton test
'''

import tkinter

class GUI(tkinter.Tk):
def __init__(self):
tkinter.Tk.__init__(self)
frame = tkinter.Frame(self)
for tag in ('A', 'B'):
w = tkinter.Checkbutton(frame, text=tag)
w.pack(side='top', padx=10, pady=10)
print(w)
frame.pack(side='top')
frame = tkinter.Frame(self)
for tag in ('C', 'D'):
w = tkinter.Checkbutton(frame, text=tag)
w.pack(side='top', padx=10, pady=10)
print(w)
frame.pack(side='top')

gui = GUI()
gui.mainloop()

Selection of button 'A' also selects button 'C'. Same goes for 'B' and 'D'.
I noticed that widget names have changed, which likely leads to the cause:

> /usr/local/Python-3.5.1/bin/python3 foo.py
.140182648425776.140182647743208
.140182648425776.140182647841848
.140182648424152.140182648282080
.140182648424152.140182648282136

> /usr/local/Python-3.6.0/bin/python3 foo.py
.!frame.!checkbutton
.!frame.!checkbutton2
.!frame2.!checkbutton
.!frame2.!checkbutton2

Is this a known issue?

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


sorting a list of dicts by a computed field

2017-01-31 Thread Larry Martell
I have a list of dicts and one item of the dict is a date in m/d/Y
format. I want to sort by that. I tried this:

sorted(data['trends'], key=lambda k:
datetime.strptime(k['date_time'],'%m/%d/%Y'))

But that fails with:

Exception Type: AttributeError at /report/CDSEM/WaferAlignment/ajax/waChart.json
Exception Value: 'module' object has no attribute 'strptime'

How can I do this sort?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: sorting a list of dicts by a computed field

2017-01-31 Thread Chris Angelico
On Wed, Feb 1, 2017 at 7:26 AM, Larry Martell  wrote:
> I have a list of dicts and one item of the dict is a date in m/d/Y
> format. I want to sort by that. I tried this:
>
> sorted(data['trends'], key=lambda k:
> datetime.strptime(k['date_time'],'%m/%d/%Y'))
>
> But that fails with:
>
> Exception Type: AttributeError at 
> /report/CDSEM/WaferAlignment/ajax/waChart.json
> Exception Value: 'module' object has no attribute 'strptime'
>
> How can I do this sort?

I think your problem here may be with how you're trying to parse that
datetime. There are two common ways to get access to a thing called
"datetime":

# Option 1:
import datetime
# Option 2:
from datetime import datetime

The first one gives you a module; the second gives you just one class
out of that module (one that happens to have the same name as the
module itself). My guess is that you're using the first form, but you
picked up some example code from somewhere that assumes the second.

Try using "datetime.datetime.strptime" in your key function, and see
if that helps.

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


Re: sorting a list of dicts by a computed field

2017-01-31 Thread Kev Dwyer
Larry Martell wrote:

> I have a list of dicts and one item of the dict is a date in m/d/Y
> format. I want to sort by that. I tried this:
> 
> sorted(data['trends'], key=lambda k:
> datetime.strptime(k['date_time'],'%m/%d/%Y'))
> 
> But that fails with:
> 
> Exception Type: AttributeError at
> /report/CDSEM/WaferAlignment/ajax/waChart.json Exception Value: 'module'
> object has no attribute 'strptime'
> 
> How can I do this sort?

datetime.datetime.strptime?

>>> import datetime
>>> datetime.strptime
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: module 'datetime' has no attribute 'strptime'
>>> datetime.datetime.strptime



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


Re: sorting a list of dicts by a computed field

2017-01-31 Thread MRAB

On 2017-01-31 20:26, Larry Martell wrote:

I have a list of dicts and one item of the dict is a date in m/d/Y
format. I want to sort by that. I tried this:

sorted(data['trends'], key=lambda k:
datetime.strptime(k['date_time'],'%m/%d/%Y'))

But that fails with:

Exception Type: AttributeError at /report/CDSEM/WaferAlignment/ajax/waChart.json
Exception Value: 'module' object has no attribute 'strptime'

How can I do this sort?

The module 'datetime' contains a class called 'datetime'. Judging by 
your exception, 'datetime' is the module.


Try "datetime.datetime.strptime" instead.

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


Re: sorting a list of dicts by a computed field

2017-01-31 Thread Michael Torrie
On 01/31/2017 01:26 PM, Larry Martell wrote:
> I have a list of dicts and one item of the dict is a date in m/d/Y
> format. I want to sort by that. I tried this:
> 
> sorted(data['trends'], key=lambda k:
> datetime.strptime(k['date_time'],'%m/%d/%Y'))
> 
> But that fails with:
> 
> Exception Type: AttributeError at 
> /report/CDSEM/WaferAlignment/ajax/waChart.json
> Exception Value: 'module' object has no attribute 'strptime'
> 
> How can I do this sort?

You're not showing us all your code, so I can only make an assumption
that the "datetime" you are referencing is a module import.  Did you try
your sort function before you stuck it in a lambda?  Here's a attempt:

>>> import datetime
>>> datetime.strptime
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'module' object has no attribute 'strptime'

Looks like the same problem you encountered. So it has nothing to do
with sorting.  Quite literally, your datetime symbol does not contain
the attribute strptime like you thought it did.  I think you meant to
use datetime.datetime.strptime:

>>> import datetime
>>> datetime.datetime.strptime("01/02/2003","%m/%d/%Y")
datetime.datetime(2003, 1, 2, 0, 0)

Use the interactive interpreter to test out little things like this. It
will save you a lot of hassle later on.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python3.6 tkinter bug?

2017-01-31 Thread MRAB

On 2017-01-31 19:18, George Trojan - NOAA Federal wrote:

The following program behaves differently under Python 3.6:

'''
checkbutton test
'''

import tkinter

class GUI(tkinter.Tk):
def __init__(self):
tkinter.Tk.__init__(self)
frame = tkinter.Frame(self)
for tag in ('A', 'B'):
w = tkinter.Checkbutton(frame, text=tag)
w.pack(side='top', padx=10, pady=10)
print(w)
frame.pack(side='top')
frame = tkinter.Frame(self)
for tag in ('C', 'D'):
w = tkinter.Checkbutton(frame, text=tag)
w.pack(side='top', padx=10, pady=10)
print(w)
frame.pack(side='top')

gui = GUI()
gui.mainloop()

Selection of button 'A' also selects button 'C'. Same goes for 'B' and 'D'.
I noticed that widget names have changed, which likely leads to the cause:


/usr/local/Python-3.5.1/bin/python3 foo.py

.140182648425776.140182647743208
.140182648425776.140182647841848
.140182648424152.140182648282080
.140182648424152.140182648282136


/usr/local/Python-3.6.0/bin/python3 foo.py

.!frame.!checkbutton
.!frame.!checkbutton2
.!frame2.!checkbutton
.!frame2.!checkbutton2

Is this a known issue?


I don't believe so; at least, I couldn't see it in the bug tracker.

Presumably you'll want to check the values of the checkboxes, so you'll 
bind them to tkinter variables (IntVar, etc). When you do that, it works 
correctly.


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


Re: sorting a list of dicts by a computed field

2017-01-31 Thread Larry Martell
On Tue, Jan 31, 2017 at 3:30 PM, Chris Angelico  wrote:
> On Wed, Feb 1, 2017 at 7:26 AM, Larry Martell  wrote:
>> I have a list of dicts and one item of the dict is a date in m/d/Y
>> format. I want to sort by that. I tried this:
>>
>> sorted(data['trends'], key=lambda k:
>> datetime.strptime(k['date_time'],'%m/%d/%Y'))
>>
>> But that fails with:
>>
>> Exception Type: AttributeError at 
>> /report/CDSEM/WaferAlignment/ajax/waChart.json
>> Exception Value: 'module' object has no attribute 'strptime'
>>
>> How can I do this sort?
>
> I think your problem here may be with how you're trying to parse that
> datetime. There are two common ways to get access to a thing called
> "datetime":
>
> # Option 1:
> import datetime
> # Option 2:
> from datetime import datetime
>
> The first one gives you a module; the second gives you just one class
> out of that module (one that happens to have the same name as the
> module itself). My guess is that you're using the first form, but you
> picked up some example code from somewhere that assumes the second.
>
> Try using "datetime.datetime.strptime" in your key function, and see
> if that helps.

Thanks. I knew that ;-) I've had a very long day, and I don't use
lambda much so I thought it was an issue with that.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python3.6 tkinter bug?

2017-01-31 Thread Terry Reedy

On 1/31/2017 3:43 PM, MRAB wrote:

On 2017-01-31 19:18, George Trojan - NOAA Federal wrote:

The following program behaves differently under Python 3.6:

'''
checkbutton test
'''

import tkinter

class GUI(tkinter.Tk):
def __init__(self):
tkinter.Tk.__init__(self)
frame = tkinter.Frame(self)
for tag in ('A', 'B'):
w = tkinter.Checkbutton(frame, text=tag)
w.pack(side='top', padx=10, pady=10)
print(w)
frame.pack(side='top')
frame = tkinter.Frame(self)
for tag in ('C', 'D'):
w = tkinter.Checkbutton(frame, text=tag)
w.pack(side='top', padx=10, pady=10)
print(w)
frame.pack(side='top')

gui = GUI()
gui.mainloop()

Selection of button 'A' also selects button 'C'. Same goes for 'B' and
'D'.
I noticed that widget names have changed, which likely leads to the
cause:


/usr/local/Python-3.5.1/bin/python3 foo.py

.140182648425776.140182647743208
.140182648425776.140182647841848
.140182648424152.140182648282080
.140182648424152.140182648282136


/usr/local/Python-3.6.0/bin/python3 foo.py

.!frame.!checkbutton
.!frame.!checkbutton2
.!frame2.!checkbutton
.!frame2.!checkbutton2

Is this a known issue?


I don't believe so; at least, I couldn't see it in the bug tracker.


Me neither.  I will open an issue on the tracker.


Presumably you'll want to check the values of the checkboxes, so you'll
bind them to tkinter variables (IntVar, etc). When you do that, it works
correctly.




--
Terry Jan Reedy

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


Re: sorting a list of dicts by a computed field

2017-01-31 Thread jladasky
On Tuesday, January 31, 2017 at 12:34:38 PM UTC-8, MRAB wrote:
> On 2017-01-31 20:26, Larry Martell wrote:

> The module 'datetime' contains a class called 'datetime'. Judging by 
> your exception, 'datetime' is the module.
> 
> Try "datetime.datetime.strptime" instead.

This re-use of the name "datetime" has tripped me up more than once.  It's one 
of my few grumbles with the Python standard library.
-- 
https://mail.python.org/mailman/listinfo/python-list


DJANGO IMAGES QUESTION

2017-01-31 Thread Xristos Xristoou
who is the better method to take images from uses(visitors) on my web site
and to return the new images(processing) back to users using DJANGO?
i am new i dont know how to connect my python script with the html templetes to 
take the images and how to return?
for example my script take images paths to processing new images with new paths.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Overriding True and False ?

2017-01-31 Thread jladasky
On Sunday, January 29, 2017 at 11:29:29 PM UTC-8, Irv Kalb wrote:

> It seems very odd that Python allows you to override the values of 
> True and False.

Hi Irv,

Let me join the chorus of people who are encouraging you to switch to Python3, 
which corrects this problem.  Overriding builtins has been judged harmful, and 
now it is a lot harder to do.

There are sometimes good reasons for shadowing builtins, but more than a few 
newcomers to Python (once upon a time, myself included) wrote buggy code by 
accident because of this surprising flexibility.

That being said, I can't resist re-posting a story from 14 years ago:

https://groups.google.com/forum/#!original/comp.lang.python/xEtUYsxLnFE/6yYgvhvkggMJ

==

From: lad...@my-deja.com (John Ladasky)
Newsgroups: comp.lang.python
Subject: Re: Python 2.3 True = False
Date: 24 Mar 2003 12:29:04 -0800

an...@calbay.com (Anand) wrote in message 
news:...
> >>> True = False
> >>> True
>  False

Shhh!  Anand!  You're not supposed to show anyone that!  Now every
politician on Earth will want to program in Python!

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


Re: Python3.6 tkinter bug?

2017-01-31 Thread Terry Reedy

On 1/31/2017 4:11 PM, Terry Reedy wrote:

On 1/31/2017 3:43 PM, MRAB wrote:

On 2017-01-31 19:18, George Trojan - NOAA Federal wrote:

The following program behaves differently under Python 3.6:

'''
checkbutton test
'''

import tkinter

class GUI(tkinter.Tk):
def __init__(self):
tkinter.Tk.__init__(self)
frame = tkinter.Frame(self)
for tag in ('A', 'B'):
w = tkinter.Checkbutton(frame, text=tag)
w.pack(side='top', padx=10, pady=10)
print(w)
frame.pack(side='top')
frame = tkinter.Frame(self)
for tag in ('C', 'D'):
w = tkinter.Checkbutton(frame, text=tag)
w.pack(side='top', padx=10, pady=10)
print(w)
frame.pack(side='top')

gui = GUI()
gui.mainloop()

Selection of button 'A' also selects button 'C'. Same goes for 'B' and
'D'.
I noticed that widget names have changed, which likely leads to the
cause:


/usr/local/Python-3.5.1/bin/python3 foo.py

.140182648425776.140182647743208
.140182648425776.140182647841848
.140182648424152.140182648282080
.140182648424152.140182648282136


/usr/local/Python-3.6.0/bin/python3 foo.py

.!frame.!checkbutton
.!frame.!checkbutton2
.!frame2.!checkbutton
.!frame2.!checkbutton2

Is this a known issue?


I don't believe so; at least, I couldn't see it in the bug tracker.


Me neither.  I will open an issue on the tracker.


https://bugs.python.org/issue29402


Presumably you'll want to check the values of the checkboxes, so you'll
bind them to tkinter variables (IntVar, etc). When you do that, it works
correctly.


This still seems like a bug to me.  Similar issue
https://bugs.python.org/issue25684 has the same workaround for ttk 
Option Menu radiobuttons.


--
Terry Jan Reedy

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


Re: What are your opinions on .NET Core vs Python?

2017-01-31 Thread Gregory Ewing

Ian Kelly wrote:

Java also has "static import" which lets
you individually import specific static methods or fields from a class.


Yes, but it's nowhere near as convenient as Python's import.
To import individual names you have to qualify all of them with
the whole package name, and there is no way to give them
different names locally.

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


Embedding python, run a function and get it's result

2017-01-31 Thread Charles Heizer
Hello,
I'm messing around with the embedded python and I can get parts to work. What 
I'm having a hard time is getting my head around calling a function in the 
python string and getting it's result.

Question, how do I load the python script and call runMe() and get it's value?

Thanks!

Example Works

Obj-C Code:

Py_Initialize();
PyObject *py_main, *py_dict;
py_main = PyImport_AddModule("__main__");
py_dict = PyModule_GetDict(py_main);

// Run the python source code
PyRun_String([auditScript UTF8String], Py_file_input, py_dict, py_dict);

PyObject *pythonString = PyDict_GetItemString(py_dict, "x") ;
if (!pythonString) {
NSLog(@"pythonString returned NULL");
return "NO";
}

// Convert the unpickled Python string to a C string
char *cString = PyString_AsString(pythonString);
Py_DECREF(pythonString);
f (!cString) {
NSLog(@"Failed converting pythonString string to C string");
return 1;
}
NSLog(@"answer: %@",[NSString cString]);

Python Code:

x = "NA"
def runMe():
return "YES"

x = runMe()
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python3.6 tkinter bug?

2017-01-31 Thread Christian Gollwitzer

Am 31.01.17 um 20:18 schrieb George Trojan - NOAA Federal:

Selection of button 'A' also selects button 'C'. Same goes for 'B' and 'D'.
I noticed that widget names have changed, which likely leads to the cause:


/usr/local/Python-3.5.1/bin/python3 foo.py

.140182648425776.140182647743208
.140182648425776.140182647841848
.140182648424152.140182648282080
.140182648424152.140182648282136


/usr/local/Python-3.6.0/bin/python3 foo.py

.!frame.!checkbutton
.!frame.!checkbutton2
.!frame2.!checkbutton
.!frame2.!checkbutton2


The widget names look fine to, and the 3.6 naming is way better, because 
it can be used for debugging more easily. The behaviour you describe can 
have two reasons, a) the same widget can be packed twice b) the widgets 
use the same variable. In Tk, a widget does not need an associate 
variable - which can be done by setting the variable to an empty string, 
or by leaving this option off.


Presumably Python 3.6 passes anything else than an empty string to Tk as 
the -variable option, maybe a mistranslated None? Can't test it myself, 
but in your example you could, for instance, check the output of 
self.call(w, 'configure'), which lists you the Tk side configuration, or 
self.call(w, 'configure', '-variable') to get specifically the bound 
variable.


Christian

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


What's the best python projects book

2017-01-31 Thread Marvin Sinclair
Am a newbie to python, just to completed reading and practice a python book, 
but I wanted to know if there is a good python book that is composed of 
different projects on different topics that I can code along, read what is 
happening so i can gain more experience, please suggest me  any, or if you have 
it please email it to me 
kapitiku...@gmail.com  i will so much appreciate
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python3.6 tkinter bug?

2017-01-31 Thread MRAB

On 2017-01-31 22:34, Christian Gollwitzer wrote:

Am 31.01.17 um 20:18 schrieb George Trojan - NOAA Federal:

Selection of button 'A' also selects button 'C'. Same goes for 'B' and 'D'.
I noticed that widget names have changed, which likely leads to the cause:


/usr/local/Python-3.5.1/bin/python3 foo.py

.140182648425776.140182647743208
.140182648425776.140182647841848
.140182648424152.140182648282080
.140182648424152.140182648282136


/usr/local/Python-3.6.0/bin/python3 foo.py

.!frame.!checkbutton
.!frame.!checkbutton2
.!frame2.!checkbutton
.!frame2.!checkbutton2


The widget names look fine to, and the 3.6 naming is way better, because
it can be used for debugging more easily. The behaviour you describe can
have two reasons, a) the same widget can be packed twice b) the widgets
use the same variable. In Tk, a widget does not need an associate
variable - which can be done by setting the variable to an empty string,
or by leaving this option off.

Presumably Python 3.6 passes anything else than an empty string to Tk as
the -variable option, maybe a mistranslated None? Can't test it myself,
but in your example you could, for instance, check the output of
self.call(w, 'configure'), which lists you the Tk side configuration, or
self.call(w, 'configure', '-variable') to get specifically the bound
variable.

Perhaps someone who knows Tcl and tk can tell me, but I notice that in 
the first example, the second part of the widget names are unique, 
whereas in the second example, the second part of the widget names are 
the reused (both "!checkbutton" and "!checkbutton2" occur twice). Is 
that the cause?


Do the names need to be:

.!frame.!checkbutton
.!frame.!checkbutton2
.!frame2.!checkbutton3
.!frame2.!checkbutton4

?

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


Re: command line micro wiki written in Python

2017-01-31 Thread Ben Finney
Paul Wolf  writes:

> I've created a command line utility for managing text files. It's
> written in Python: […]

Thank you.

> The key aspects are 
>
> * Entirely command-line driven
>
> * Text documents only with a slight preference for Markdown

The Python community has a stronger (?) preference for reStructuredText
format. Can that be the default?

That is, I want my text files to be named ‘foo’ (no suffix) or ‘foo.txt’
(because they're primarily text), and have the default be to parse them
as reStructuredText.

> I'd be interested in feedback if there is any interest in using this
> kind of utility. I'll expose a python API so bulk operations can be
> done easily on the command line or via scripts.

This is a great way to start!

-- 
 \   “Science shows that belief in God is not only obsolete. It is |
  `\also incoherent.” —Victor J. Stenger, 2001 |
_o__)  |
Ben Finney

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


Re: Python3.6 tkinter bug

2017-01-31 Thread George Trojan - NOAA Federal
On 2017-01-31 18:02, MRAB wrote:

On 2017-01-31 22:34, Christian Gollwitzer wrote:
> >* Am 31.01.17 um 20:18 schrieb George Trojan - NOAA Federal:
> *>>* Selection of button 'A' also selects button 'C'. Same goes for 'B' and 
> 'D'.
> *>>* I noticed that widget names have changed, which likely leads to the 
> cause:
> *>>
> >>>* /usr/local/Python-3.5.1/bin/python3 foo.py
> *>>* .140182648425776.140182647743208
> *>>* .140182648425776.140182647841848
> *>>* .140182648424152.140182648282080
> *>>* .140182648424152.140182648282136
> *>>
> >>>* /usr/local/Python-3.6.0/bin/python3 foo.py
> *>>* .!frame.!checkbutton
> *>>* .!frame.!checkbutton2
> *>>* .!frame2.!checkbutton
> *>>* .!frame2.!checkbutton2
> *>
> >* The widget names look fine to, and the 3.6 naming is way better, because
> *>* it can be used for debugging more easily. The behaviour you describe can
> *>* have two reasons, a) the same widget can be packed twice b) the widgets
> *>* use the same variable. In Tk, a widget does not need an associate
> *>* variable - which can be done by setting the variable to an empty string,
> *>* or by leaving this option off.
> *>
> >* Presumably Python 3.6 passes anything else than an empty string to Tk as
> *>* the -variable option, maybe a mistranslated None? Can't test it myself,
> *>* but in your example you could, for instance, check the output of
> *>* self.call(w, 'configure'), which lists you the Tk side configuration, or
> *>* self.call(w, 'configure', '-variable') to get specifically the bound
> *>* variable.
> *>
> Perhaps someone who knows Tcl and tk can tell me, but I notice that in
> the first example, the second part of the widget names are unique,
> whereas in the second example, the second part of the widget names are
> the reused (both "!checkbutton" and "!checkbutton2" occur twice). Is
> that the cause?
> Do the names need to be:
> .!frame.!checkbutton
> .!frame.!checkbutton2
> .!frame2.!checkbutton3
> .!frame2.!checkbutton4
> ?


Adding dummy variable solves the issue. Following Christian's
suggestion I added code to print Tk variable:

from functools import partial
import tkinter

class GUI(tkinter.Tk):
def __init__(self):
tkinter.Tk.__init__(self)
frame = tkinter.Frame(self)
for tag in ('A', 'B'):
w = tkinter.Checkbutton(frame, text=tag, #
variable=tkinter.IntVar(),
command=partial(print, tag))
w.pack(side='top', padx=10, pady=10)
print(tag, self.call(w, 'configure', '-variable'))
print(w)
frame.pack(side='top')
frame = tkinter.Frame(self)
for tag in ('C', 'D'):
w = tkinter.Checkbutton(frame, text=tag, #
variable=tkinter.IntVar(),
command=partial(print, tag))
w.pack(side='top', padx=10, pady=10)
print(tag, self.call(w, 'configure', '-variable'))
print(w)
frame.pack(side='top')

gui = GUI()
gui.mainloop()

The output is:

(venv-3.6.0) dilbert@gtrojan> python foo.py
A ('-variable', 'variable', 'Variable', '', )
.!frame.!checkbutton
B ('-variable', 'variable', 'Variable', '', )
.!frame.!checkbutton2
C ('-variable', 'variable', 'Variable', '', )
.!frame2.!checkbutton
D ('-variable', 'variable', 'Variable', '', )
.!frame2.!checkbutton2

It looks like the default name is the last component of widget tree.

When the # sign is removed, the names are unique and the problem disappears:

(venv-3.6.0) dilbert@gtrojan> python foo.py
A ('-variable', 'variable', 'Variable', '', )
.!frame.!checkbutton
B ('-variable', 'variable', 'Variable', '', )
.!frame.!checkbutton2
C ('-variable', 'variable', 'Variable', '', )
.!frame2.!checkbutton
D ('-variable', 'variable', 'Variable', '', )
.!frame2.!checkbutton2
-- 
https://mail.python.org/mailman/listinfo/python-list


SQL CE Database (.sdf) file connection with python

2017-01-31 Thread Jay Desai
Hello,


I came across a post from Nikhil Joshi at 
https://mail.python.org/pipermail/python-list/2014-November/681568.html.

*.sdf database access - 
mail.python.org
mail.python.org
On Saturday, April 21, 2012 6:55:55 AM UTC-4, Alex Willmer wrote: > On Apr 19, 
9:18 pm, Page3D wrote: > > Hi, I am trying to connect and access ...




I am facing the following problem. Can anyone please provide some guideline?

Problem Statement: Extract data stored in the .sdf file to python. System 
config: Win 10 Pro 64-bit, python 3.5.2-64 bit, adodbapi library, SQL CE 3.5

I am fairly new to programming and I have picked up Python as my first language 
to learn. Currently, I have hit a wall in process of connecting a SQL CE 3.5 
.sdf file.

I have used the adodbapi library. I have searched the web extensively over the 
past week to find a solution to this problem and to make sure that my 
connection string is correct. I have tried multiple options/solutions provided 
on stack overflow and 
https://www.connectionstrings.com/microsoft-sqlserver-ce-oledb-3-5/.

Code:

import adodbapi

cons_str = "Provoider=Microsoft.SQLSERVER.MOBILE.OLEDB.3.5;" \
   "Data Source=D:\Work\Programming\Python\SQL_DataTransfer\LF.sdf;"\
   "Persist Security Info=False;" \
   "SSCE:Max Database Size=4091"

connection = adodbapi.connect(cons_str)
print(connection)

Error Message: Traceback (most recent call last): File 
"D:\Work\Programs\Python35.virtualenvs\sql_output\lib\site-packages\adodbapi\adodbapi.py",
 line 93, in make_COM_connecter c = Dispatch('ADODB.Connection') #connect after 
CoIninialize v2.1.1 adamvan NameError: name 'Dispatch' is not defined

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File 
"D:\Work\Programs\Python35.virtualenvs\sql_output\lib\site-packages\adodbapi\adodbapi.py",
 line 112, in connect co.connect(kwargs) File 
"D:\Work\Programs\Python35.virtualenvs\sql_output\lib\site-packages\adodbapi\adodbapi.py",
 line 269, in connect self.connector = connection_maker() File 
"D:\Work\Programs\Python35.virtualenvs\sql_output\lib\site-packages\adodbapi\adodbapi.py",
 line 95, in make_COM_connecter raise api.InterfaceError ("Windows COM Error: 
Dispatch('ADODB.Connection') failed.") adodbapi.apibase.InterfaceError: Windows 
COM Error: Dispatch('ADODB.Connection') failed.

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File 
"D:/Work/Programming/Python/SQL_DataTransfer/SQL_CE_reportDB.py", line 8, in 
connection = adodbapi.connect(cons_str) File 
"D:\Work\Programs\Python35.virtualenvs\sql_output\lib\site-packages\adodbapi\adodbapi.py",
 line 116, in connect raise api.OperationalError(e, message) 
adodbapi.apibase.OperationalError: (InterfaceError("Windows COM Error: 
Dispatch('ADODB.Connection') failed.",), 'Error opening connection to 
"Provoider=Microsoft.SQLSERVER.MOBILE.OLEDB.3.5;Data 
Source=D:\Work\Programming\Python\SQL_DataTransfer\LF.sdf;Persist Security 
Info=False;SSCE:Max Database Size=4091"')

At this point any help is much appreciated.

Thank you, Sincerely, JD.

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


Qtcore error problem

2017-01-31 Thread Xiao Zhang
Dear python users,

I am new to python and now I met a problem. When I try to run a py file, I
got the following error:

from vacumm.misc.grid.regridding import regrid2d
  File
"/home/xzhang3/usr/local/uvcdat/2.4.1/lib/python2.7/site-packages/vacumm/misc/__init__.py",
line 41, in 
import color
  File
"/home/xzhang3/usr/local/uvcdat/2.4.1/lib/python2.7/site-packages/vacumm/misc/color.py",
line 50, in 
import pylab as P

ImportError:
/home/xzhang3/usr/local/uvcdat/2.4.1/lib/python2.7/site-packages/PyQt4/QtCore.so:
undefined symbol: _ZN7QLocale14scriptToStringENS_6ScriptE

I searched the web and it looks like the problem has something to do with
different versions.
Any idea how to fix the problem ?  I am using python 2.7 now.


Really appreciate your ideas and best regards,


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


Re: SQL CE Database (.sdf) file connection with python

2017-01-31 Thread MRAB

On 2017-02-01 00:45, Jay Desai wrote:

Hello,


I came across a post from Nikhil Joshi at 
https://mail.python.org/pipermail/python-list/2014-November/681568.html.

*.sdf database access - 
mail.python.org
mail.python.org
On Saturday, April 21, 2012 6:55:55 AM UTC-4, Alex Willmer wrote: > On Apr 19, 9:18 
pm, Page3D wrote: > > Hi, I am trying to connect and access ...




I am facing the following problem. Can anyone please provide some guideline?

Problem Statement: Extract data stored in the .sdf file to python. System 
config: Win 10 Pro 64-bit, python 3.5.2-64 bit, adodbapi library, SQL CE 3.5

I am fairly new to programming and I have picked up Python as my first language 
to learn. Currently, I have hit a wall in process of connecting a SQL CE 3.5 
.sdf file.

I have used the adodbapi library. I have searched the web extensively over the 
past week to find a solution to this problem and to make sure that my 
connection string is correct. I have tried multiple options/solutions provided 
on stack overflow and 
https://www.connectionstrings.com/microsoft-sqlserver-ce-oledb-3-5/.

Code:

import adodbapi

cons_str = "Provoider=Microsoft.SQLSERVER.MOBILE.OLEDB.3.5;" \
   "Data Source=D:\Work\Programming\Python\SQL_DataTransfer\LF.sdf;"\
   "Persist Security Info=False;" \
   "SSCE:Max Database Size=4091"

I can a problem here. Your string contains "Provoider", which is a 
misspelling. It should be "Provider".


It would also be a good idea to make those 'raw' strings (prefix them 
with 'r') where they contain backslashes.



connection = adodbapi.connect(cons_str)
print(connection)

Error Message: Traceback (most recent call last): File 
"D:\Work\Programs\Python35.virtualenvs\sql_output\lib\site-packages\adodbapi\adodbapi.py",
 line 93, in make_COM_connecter c = Dispatch('ADODB.Connection') #connect after 
CoIninialize v2.1.1 adamvan NameError: name 'Dispatch' is not defined

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File 
"D:\Work\Programs\Python35.virtualenvs\sql_output\lib\site-packages\adodbapi\adodbapi.py", line 112, in 
connect co.connect(kwargs) File 
"D:\Work\Programs\Python35.virtualenvs\sql_output\lib\site-packages\adodbapi\adodbapi.py", line 269, in 
connect self.connector = connection_maker() File 
"D:\Work\Programs\Python35.virtualenvs\sql_output\lib\site-packages\adodbapi\adodbapi.py", line 95, in 
make_COM_connecter raise api.InterfaceError ("Windows COM Error: Dispatch('ADODB.Connection') failed.") 
adodbapi.apibase.InterfaceError: Windows COM Error: Dispatch('ADODB.Connection') failed.

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "D:/Work/Programming/Python/SQL_DataTransfer/SQL_CE_reportDB.py", 
line 8, in connection = adodbapi.connect(cons_str) File 
"D:\Work\Programs\Python35.virtualenvs\sql_output\lib\site-packages\adodbapi\adodbapi.py", line 116, in 
connect raise api.OperationalError(e, message) adodbapi.apibase.OperationalError: (InterfaceError("Windows COM 
Error: Dispatch('ADODB.Connection') failed.",), 'Error opening connection to 
"Provoider=Microsoft.SQLSERVER.MOBILE.OLEDB.3.5;Data 
Source=D:\Work\Programming\Python\SQL_DataTransfer\LF.sdf;Persist Security Info=False;SSCE:Max Database 
Size=4091"')

At this point any help is much appreciated.


I've had a quick look on StackOverflow. I think you have to install pywin32.

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


Re: Python3.6 tkinter bug?

2017-01-31 Thread Christian Gollwitzer

Am 01.02.17 um 00:02 schrieb MRAB:

On 2017-01-31 22:34, Christian Gollwitzer wrote:

.!frame.!checkbutton
.!frame.!checkbutton2
.!frame2.!checkbutton
.!frame2.!checkbutton2




Perhaps someone who knows Tcl and tk can tell me, but I notice that in
the first example, the second part of the widget names are unique,
whereas in the second example, the second part of the widget names are
the reused (both "!checkbutton" and "!checkbutton2" occur twice).


It is indeed the reason, but it has some strange legacy cause: the 
default name for the checkbutton-linked variable is the name of the 
button inside the parent. Therefore creating a checkbutton has the side 
effect of creating a variable with the button's name.


In this case, the first buttons in the frames are linked to a variable 
called "!checkbutton" and the other two are linked to "!checkbutton2". 
(a variable name in Tcl can be anything apart from the empty string). 
This can also be demonstrated by this Tcl script:


package require Tk

pack [frame .f1]
pack [frame .f2]

pack [checkbutton .f1.c1 -text "A" ]
pack [checkbutton .f1.c2 -text "B" ]

pack [checkbutton .f2.c1 -text "C" ]
pack [checkbutton .f2.c2 -text "D" ]

which is equivalent to the Python code above.

Note that this surprising behaviour was corrected for the (modern) ttk 
widgets, so if "checkbutton" is replaced by "ttk::checkbutton", they are 
not any longer linked. In Python, that would be


from tkinter import ttk
...
w = ttk.Checkbutton()

(Personally, I'm not using the legacy widgets any longer)


Do the names need to be:

.!frame.!checkbutton
.!frame.!checkbutton2
.!frame2.!checkbutton3
.!frame2.!checkbutton4


Good question. Maybe there should be unique variable names? I.e., if the 
script is changed into 	package require Tk


pack [frame .f1]
pack [frame .f2]

pack [checkbutton .f1.c1 -text "A" -variable v1]
pack [checkbutton .f1.c2 -text "B" -variable v2]

pack [checkbutton .f2.c1 -text "C" -variable v3]
pack [checkbutton .f2.c2 -text "D" -variable v4]

then they are also not linked.


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