How does one distribute Tkinter or Qt GUI apps Developed in Python

2015-12-16 Thread Bruce Whealton
I watched one training video that discussed Python and Tkinter. Like many 
similar tutorials from online training sites, I was left scratching my head. 

What seems to be blatantly missing is how this would be distributed. In the 
first mentioned tutorial from Lynda.com the Tkinter app was related to a web 
page. However, the browser cannot run Python Bytecode or Python Scripts. 

Surely, one is going to want to create GUI apps for users that are not Python 
Developers. I would not think to ask someone to install Python on their system 
and make sure it is added to the path. Maybe it is not so hard for the 
non-technical, average users. 

I would want to package in some way so that when launched, it installs whatever 
is needed on the end user's computer. How is this done? 
Are there common practices for this? 
Thanks, 
Bruce
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Prob. Code Downloaded for Programming the Semantic Web (python code)

2014-07-28 Thread Bruce Whealton
On Friday, July 25, 2014 9:28:32 PM UTC-4, Steven D'Aprano wrote:
 On Fri, 25 Jul 2014 17:06:17 -0700, Bruce Whealton wrote:
Steven,
See below please.  The explanation did help.   
 
  OK, Eclipse with PyDev doesn't like this first line, with the function:
 
  def add(self, (sub, pred, obj)):
 
 
 
 In Python 2, you could include parenthesised parameters inside function
 declarations as above. That is effectively a short cut for this version,
 where you collect a single argument and then expand it into three
 variables:
 
 
 
 def add(self, sub_pred_obj):
 
 sub, pred, obj = sub_pred_obj
 
I setup Eclipse to use python 2.7.x and tried to run this and it just gave an 
error on line 9 where the def add function is declared.  It just says invalid 
syntax and points at the parentheses that are in the function definition
def add(self, (subj, pred, obj)):
So, from what you said, and others, it seems like this should have worked but 
eclipse would not run it.  I could try to load it into IDLE.
 
 
 
 In Python 3, that functionality was dropped and is no longer allowed. Now
 you have to use the longer form.

I'm not sure I follow what the longer method is.  Can you explain that more, 
please. 
 
 
 [...]
 
  There are other places where I thought that there were too many
 
  parentheses and I tried removing one set of them.  For example this
 
  snippet here:
 
  
 
  def remove(self, (sub, pred, obj)):
 
  
 
  Remove a triple pattern from the graph. 
 
  triples = list(self.triples((sub, pred, obj)))
 
 
 
 Firstly, the remove method expects to take a *single* argument (remember
 
 that self is automatically provided by Python) which is then automatically
 
 expanded into three variables sub, pred, obj. So you have to call it with a
 
 list or tuple of three items (or even a string of length exactly 3).
 

 Then, having split this list or tuple into three items, it then joins them
 
 back again into a tuple:
 
 
 
 (sub, pred, obj)
 
 passes that tuple to the triples method:
 
 self.triples((sub, pred, obj))
 
 
 
 (not shown, but presumably it uses the same parenthesised parameter trick),
 
 and then converts whatever triples returns into a list:
 
The full code listing should be available in the code paste link that I 
included.
 
 
 list(self.triples((sub, pred, obj)))
 
 
 
 that list then being bound to the name triples.
 
 
Thanks, the explanation helped,
Bruce
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Prob. Code Downloaded for Programming the Semantic Web (python code)

2014-07-28 Thread Bruce Whealton
On Friday, July 25, 2014 11:25:15 PM UTC-4, Chris Angelico wrote:
 On Sat, Jul 26, 2014 at 10:06 AM, Bruce Whealton
 
Chris,
In response to your comments below, I'm comfortable changing this to use 
python 3.
 As others have said, this is something that changed in Python 3. So
 you have two parts to the problem: firstly, your code is bound to
 Python 2 by a triviality, and secondly, Eclipse is complaining about
 it.
 
 
 
 But a better solution, IMO, would be to avoid that implicit tuple
 unpacking. It's not a particularly clear feature, and I'm not sorry
 it's gone from Py3. The simplest way to change it is to just move it
 into the body:
 

OK, that makes sense. So, I cut out the Alternatively...  suggestion you made.
 
 
 def add(self, args):
 
 sub, pred, obj = args
 
 # rest of code as before
 
 
 
 Preferably with a better name than 'args'.

Yes, I could call it triples. 
 
  triples = list(self.triples((sub, pred, obj)))
 
 
 
  Are the two sets parentheses needed after self.triples?  That syntax is
 
  confusing to me.  It seems that it should be
 
  triples = list(self.triples(sub, pred, obj))
 
 
 
 No, that's correct. The extra parens force that triple to be a single
 
 tuple of three items, rather than three separate arguments. Here's a
 
 simpler example:
 
  lst = []
 
  lst.append(1,2,3)
 
 Traceback (most recent call last):
 
   File pyshell#25, line 1, in module
 
 lst.append(1,2,3)
 
 TypeError: append() takes exactly one argument (3 given)
 
  lst.append((1,2,3))
 
  addme = 4,5,6
 
  lst.append(addme)
 
  lst
 
 [(1, 2, 3), (4, 5, 6)]
 
 
This is helpful and makes sense... clarifies it for me.
 
 The list append method wants one argument, and appends that argument 
 to the list. Syntactically, the comma has multiple meanings; when I
 assign 4,5,6 to a single name, it makes a tuple, but in a function
 call, it separates args in the list. I don't see why the triples()
 function should be given a single argument, though; all it does is
 immediately unpack it. It'd be better to just remove the parens and 
 have separate args:
 
 
 triples = list(self.triples(sub, pred, obj))

I didn't see the above in the code... Is this something I would need to add and 
if so, where? 
 
 
def triples(self, sub, pred, obj):
 
 
 
 While I'm looking at the code, a few other comments. I don't know how
 much of this is your code and how much came straight from the book,
 but either way, don't take this as criticism, but just as suggestions 
 for ways to get more out of Python.
 
So far it is just from the book, and just serves as an example...  It is also a 
few years old, having been published in 2009.
 
 
 Inside remove(), you call a generator (triples() uses yield to return
 multiple values), then construct a list, and then iterate exactly once
 over that list. Much more efficient and clean to iterate directly over
 what triples() returns, as in save(); that's what generators are good
 for.
 
 
 
 In triples(), the code is deeply nested and repetitive. I don't know
 if there's a way to truly solve that, but I would be inclined to 
 flatten it out a bit; maybe check for just one presence, to pick your
 index, and then merge some of the code that iterates over an index.
 Not sure though.
 
I would have to get a better understanding of this.  
 
 
 (Also: It's conventional to use is not None rather than != None to
 
 test for singletons. It's possible for something to be equal to None
 
 without actually being None.)
 
 
 
 I would recommend moving to Python 3, if you can. Among other
 benefits, the Py3 csv module allows you to open a text file rather
 than opening a binary file and manually encoding/decoding all the
 parts separately. Alternatively, if you don't need this to be saving
 and loading another program's files, you could simply use a different
 file format, which would remove the restrictions (and messes) of the 
 CSV structure.

I was curious about why the binary flag was being used.  It just made no sense 
to me.
 
 
 
 Instead of explicitly putting f.close() at the end of your load and
 save methods, check out the 'with' statement. It'll guarantee that the
 file's closed even if you leave early, get an exception, or anything
 
 like that. Also, I'd tend to use the .decode() and .encode() methods,
 rather than the constructors. So here's how I'd write a Py2 load:

I would like to see this in python 3 format.
 
 def load(self, filename):
 
 with open(filename, rb) as f:
 
 for sub, pred, obj in csv.reader(f):
 
 self.add((sub.decode(UTF-8), pred.decode(UTF-8),
 
 obj.decode(UTF-8)))
 
 
 
 (You might want to break that back out into three more lines, but this
 
 parallels save(). If you break this one, you probably want to break
 
 save() too.)
 
 
 
 Hope that helps!
 
 
 
 ChrisA

Thanks,
Bruce

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


Re: Prob. Code Downloaded for Programming the Semantic Web (python code)

2014-07-28 Thread Bruce Whealton
On Monday, July 28, 2014 11:28:40 AM UTC-4, Steven D'Aprano wrote:
 On Mon, 28 Jul 2014 03:39:48 -0700, Bruce Whealton wrote:
Stephen,
I went to my Ubuntu box inside vmware and added a #!/usr/bin/env python2.7 
to the top.  Then I made the file executable and it ran the code perfectly. 

 
 First step is to confirm that Eclipse actually is using Python 2.7. Can 
 
 you get it to run this code instead? Put this in a module, and then run 
 
 it:
 
 
 
 import sys
 
 print(sys.version)
 
 
I had both python2.7 and python3.4.  I could be less specific with my shebang 
line but what the heck.  
 
 
 
I then installed pydev into my eclipse environment within the Ubuntu virtual 
machine and it ran the program just fine.  So, I suspect the extra character 
was 
only an issue on Windows.  I thought I had it setup to show even hidden 
characters.  
Anyway, thanks so much for all the help...everyone.  It might be interesting 
for me to convert this to a module that runs with python 3.
Bruce 
 
 
  It just
 
  says invalid syntax and points at the parentheses that are in the
 
  function definition def add(self, (subj, pred, obj)):
 
  So, from what you said, and others, it seems like this should have
 
  worked but eclipse would not run it.  I could try to load it into IDLE.
 
 
 
 Whenever you have trouble with one IDE, it's good to get a second opinion 
 
 in another IDE. They might both be buggy, but they're unlikely to both 
 
 have the same bug.
 
 
 
 Also, try to run the file directly from the shell, without an IDE. from 
 
 the system shell (cmd.exe if using Windows, bash or equivalent for 
 
 Linux), run:
 
 
 
 python27 /path/to/yourfile.py
 
 
 
 You'll obviously need to adjust the pathname, possibly even give the full 
 
 path to the Python executable.
 
 
 
 
 
 [...]
 
  In Python 3, that functionality was dropped and is no longer allowed.
 
  Now you have to use the longer form.
 
 
 
  I'm not sure I follow what the longer method is.  Can you explain that
 
  more, please.
 
 
 
 I referred to the parenthesised parameter version as a short cut for a 
 
 method that takes a single argument, then manually expands that argument 
 
 into three items. Let me show them together to make it more obvious:
 
 
 
 # Unparenthesised version, with manual step.
 
 def add(self, sub_pred_obj):
 
 sub, pred, obj = sub_pred_obj
 
 do_stuff_with(sub or pred or obj)
 
 
 
 # Parenthesised shortcut.
 
 def add(self, (sub, pred, obj)):
 
 do_stuff_with(sub or pred or obj)
 
 
 
 Both methods take a single argument, which must be a sequence of exactly 
 
 three values. The second version saves a single line, hence the first 
 
 version is longer :-)
 
 
 
 
 
 -- 
 
 Steven

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


Strange Error with pip install.

2014-07-25 Thread Bruce Whealton
Hello,
  I am using Windows 8.1 (I do have a linux box setup with virtualbox also) 
and I've used python previously but now it is giving me problems whenever I try 
to install anything from PyPI using pip.  The error I get from the command line 
is 
Cannot fetch index base URL http://pypi.python.org/simple/
Could not find any downloads that satisfy the requirement...

I tried within the MinGW environment setup when I installed Git and was given 
Git Bash as a console.  I also installed Bitnami Django stack and even in that 
environment, I get that error.

I did some Google searches but I seem to only happen when people are trying to 
install Django.  For me it is happening with django and any other pypi 
installation with pip.  

Interestingly, as I started trying to get advice with this, in the django chat 
room - at the time I was trying to get django to work in my Windows 
environment, someone suggested Vagrant.  I started creating some boxes with 
Vagrant and Puppet, Chef or bash scripts.  I had problems with this inside a 
Windows command prompt.  So, I tried it under the MinGW environment I mentioned 
above, and half the time, when I run Vagrant up, it starts the environment but 
then it tries to connect using a public key authentication.  Sometimes it will 
just give up and let me run vagrant ssh or use putty.  Other times it just 
times out.  

One idea I have is to import a VirtualBox box from Bitnami into VirtualBox, 
their Django stack.  

Does anyone have any suggestions about this problem I am having using pip 
install somepackage inside Windows (Windows 8, if that matters)?

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


Prob. Code Downloaded for Programming the Semantic Web (python code)

2014-07-25 Thread Bruce Whealton
Hello all,
   I downloaded some code accompanying the book Programming the Semantic 
Web.  This question is not Semantic Web related and I doubt that one needs to 
know anything about the Semantic Web to help  me with this.  It's the first 
code sample in the book, I'm embarrassed to say.  I have the code shared here 
(just one file, not the majority of the book or anything): 
http://pastebin.com/e870vjYK

OK, Eclipse with PyDev doesn't like this first line, with the function:
def add(self, (sub, pred, obj)):

It complains about the parentheses just before sub.  Simply removing them just 
moves me down to another error.  I did try using python 3.x (3.4 to be 
specific), which meant changing print statements to function calls.  Of course, 
that didn't fix the errors I was mentioning.  The text uses python 2.7.x.  

There are other places where I thought that there were too many parentheses and 
I tried removing one set of them.  For example this snippet here:

def remove(self, (sub, pred, obj)):

Remove a triple pattern from the graph.

triples = list(self.triples((sub, pred, obj)))

Are the two sets parentheses needed after self.triples?  That syntax is 
confusing to me.  It seems that it should be
triples = list(self.triples(sub, pred, obj))

The full listing is here: http://pastebin.com/e870vjYK

I agree with the authors that python is a fun and easy language to use, thus it 
is strange that I am getting stuck here.

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


Re: Newbie help - Programming the Semantic Web with Python

2011-07-16 Thread Bruce Whealton

Hello,
  So, regarding the path that python uses to find modules, I read 
the link that you sent.  Suppose, I open IDLE and start an interactive 
session.  That would mean the input script location is wherever python is 
installed, correct?  I did add an environment variable PYTHONPATH which did 
not even exist when I first installed Python.  I figured I would want to 
have a directory where I could store modules that might interest me.  I 
might want to expand that into a package style path later.
Now, if I was going to create an application to run on the web, I 
guess those included modules would have to get compiled with the rest of the 
code for it to work, right?

Bruce

-Original Message- 
From: Chris Angelico

Sent: Saturday, July 09, 2011 10:10 PM
To: python-list@python.org
Subject: Re: Newbie help - Programming the Semantic Web with Python

On Sun, Jul 10, 2011 at 11:32 AM, Bruce Whealton br...@whealton.info 
wrote:

problem with is this line:

def add(self, (sub, pred, obj)):
I think the problem is with the parentheses before the sub.  I removed 
those and that seemed to fix that error or make it go away.  I don’t 
remember how I figured that out,   It should be on the Errata page for 
sure.

Then it has a problem with this line:
print list(g.triples((None, None, None)))
If I was using python 3, it would require () around the thing that is 
going to be printed, right?  Maybe python 2.7 doesn’t like this line for 
the same reason.




The issue there is with tuple unpacking. To match the older syntax,
don't touch the call, but change the definition thus:
def add(self, args):
 (sub, pred, obj)=args

Or, of course, simply list the arguments directly, rather than in a
tuple; but that requires changing every call (if it's a small program
that may not be a problem).

You're right about needing parentheses around the print() call; in
Python 2 it's a statement, but in Python 3, print is a function like
any other.

Regarding the module search path, this may help:
http://docs.python.org/dev/tutorial/modules.html#the-module-search-path

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


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


Re: Newbie help - Programming the Semantic Web with Python

2011-07-11 Thread Bruce Whealton
This didn't seem to work either.  I was getting errors the number of 
arguments expected being two, when I changed to

def add (self, args):
I seem to remember that if I removed the parentheses around sub, pred, obj, 
it worked.  I thought that was how it worked.  What is strange is that this 
is not reported as an error on the books page.  So, it should have worked as 
is with either Python 2.7, which I have installed or Python 3.0 which I also 
have installed.  So, it seems like it would have worked as is for one of the 
versions of Python, but it doesn't seem to work that way.
I'll paste a link to where the code exists.  Could someone help me figure it 
out please.  The code is here on the site:

http://semprog.com/content/the-book/

I wonder if I can also try it out from the IDLE interactive session.
Thanks,
Bruce

On Sun, Jul 10, 2011 at 11:32 AM, Bruce Whealton br...@whealton.info 
wrote:

problem with is this line:

def add(self, (sub, pred, obj)):
I think the problem is with the parentheses before the sub.  I removed 
those and that seemed to fix that error or make it go away.  I don’t 
remember how I figured that out,   It should be on the Errata page for 
sure.

Then it has a problem with this line:
print list(g.triples((None, None, None)))
If I was using python 3, it would require () around the thing that is 
going to be printed, right?  Maybe python 2.7 doesn’t like this line for 
the same reason.




The issue there is with tuple unpacking. To match the older syntax,
don't touch the call, but change the definition thus:
def add(self, args):
 (sub, pred, obj)=args

Or, of course, simply list the arguments directly, rather than in a
tuple; but that requires changing every call (if it's a small program
that may not be a problem).

You're right about needing parentheses around the print() call; in
Python 2 it's a statement, but in Python 3, print is a function like
any other.

Regarding the module search path, this may help:
http://docs.python.org/dev/tutorial/modules.html#the-module-search-path

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


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


Re: Newbie help - Programming the Semantic Web with Python

2011-07-10 Thread Bruce Whealton
Thanks for the tips.  I actually had done some studies with Python, mainly 
Python 3, back about 6 months ago and over a period of a few months.
I didn't write a great deal of programs though, at the time.  I got away 
from it in a while and I didn't want to go back to step one of being like a 
total beginner.  There are so many things I try to keep up with as a Web 
Developer and coder and trying to expand my skills.  Unfortunately, I don't 
do well with picking  a focus.  I remember reading through this long 
reference manual, called Learning Python, while I was on a flight and over 
a trip.  That was without a computer, so I was just reading, which is not 
the way to learn programming, obviously.  I feel the many concepts will come 
back to me fast.  I have another text, called Beginning Python: From Novice 
to Professional which covers Python 3.  This is a bit more practical in 
orientation.  I'm debating whether to jump to the chapters dealing with the 
web and see what I can do or starting from the beginning.  I did look into 
some online training, tutorials, or the like.


The Programming the Semantic Web book uses Python but all the code is 
included.  So, while it won't be a way to learn python, I hope I can get the 
code to run correctly.  In that text, they must be using Python 2.7 because 
I see print statements and not the print function call.
If you know of any good resources for finding python applications on the 
web, this might be a good way to learn.  I don't know if  I should look for 
Python applications, or if I'll have more luck looking for Python Libraries.

Thanks,
Bruce

-Original Message- 
From: Andrew Berg

Sent: Saturday, July 09, 2011 10:44 PM
To: comp.lang.python
Subject: Re: Newbie help - Programming the Semantic Web with Python

On 2011.07.09 08:32 PM, Bruce Whealton wrote:

Hello,
So, I got this book on Programming the Semantic Web about
the same time I started learning Python.  The code seems to be
developed for python 2.7 and not 3, I believe.

If you're going to learn Python 3, I suggest learning from a book that
deals with Python 3 (if there's not an updated text for the area you're
dealing with, go with something that teaches the basics). Once you have
the basics down and you know the common differences, then it will be
much easier to learn from a text that's based on Python 2 (you'll
stumble a whole lot less when trying to learn from such texts). You'll
also find some things in Python 3 that have been added to recent
versions of Python 2 that the text may not cover (e.g., the old % string
formatting syntax vs. the new format() string method).

If I was using python 3, it would require () around the thing that is
going to be printed, right?

That's not really the right way to think of the print() function. The
print statement has some very arbitrary syntax that could cause
unexpected behavior if simply put in the print() function. The print
function has parameters for optional behavior rather than odd syntax. In
the simplest cases, print and print() are extremely similar, but print()
has a bunch of functionality that is either difficult/annoying to
decipher (for humans, not the interpreter) or simply doesn't exist in print.
--
http://mail.python.org/mailman/listinfo/python-list 


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


Newbie help - Programming the Semantic Web with Python

2011-07-09 Thread Bruce Whealton
Hello,
So, I got this book on Programming the Semantic Web about the same 
time I started learning Python.  The code seems to be developed for python 2.7 
and not 3, I believe.  The code is here:
http://semprog.com/content/the-book/
I tried to run simpletriple.py from inside eclipse with PYDEV.  The first thing 
it has a problem with is this line:
def add(self, (sub, pred, obj)):
I think the problem is with the parentheses before the sub.  I removed those 
and that seemed to fix that error or make it go away.  I don’t remember how I 
figured that out,   It should be on the Errata page for sure.  
Then it has a problem with this line:
print list(g.triples((None, None, None)))
If I was using python 3, it would require () around the thing that is going to 
be printed, right?  Maybe python 2.7 doesn’t like this line for the same 
reason.  

The book suggests that from IDLE, I can just use 
from simplegraph import SimpleGraph
That means it is going to look for a file named simplegraph.py
but where will it be looking?  I guess I would have to have it in the same 
folder as the python interpreter or one of the PATH directories, right?
Thanks,
Bruce

++

Bruce Whealton, Owner Future Wave Designs

FOAF: http://whealton.info/BruceWhealtonJr/foaf.rdf

Vcard: http://whealton.info/BruceWhealtonJr/brucewhealtonvcard.html

Web Design and Development http://FutureWaveDesigns.com

http://futurewavedesigns.com/wordpress/

Web Technology wiki: http://futurewavedesigns.com/w/

++

wlEmoticon-smile[1].png-- 
http://mail.python.org/mailman/listinfo/python-list


Clarification of notation

2010-09-29 Thread Bruce Whealton

Hello all,
 I recently started learning python.  I am a bit thrown by a 
certain notation that I see.  I was watching a training course on 
lynda.com and this notation was not presented.  For lists, when would 
you use what appears to be nested lists, like:

[[], [], []]
a list of lists?
Would you, and could you combine a dictionary with a list in this fashion?

Next, from the documentation I see and this is just an example (this 
kind of notation is seen elsewhere in the documentation:


str.count(sub[, start[, end]])
This particular example is from the string methods.
Is this a nesting of two lists inside a a third list?  I know that it 
would suggest that some of the arguments are optional, so perhaps if 
there are 2 items the first is the sub, and the second is start?  Or did 
I read that backwards?

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