Re: Logging module stopped working

2017-10-18 Thread llanitedave
On Monday, October 16, 2017 at 11:58:12 PM UTC-7, Steve D'Aprano wrote:
> On Tue, 17 Oct 2017 03:06 pm, llanitedave wrote:
> 
> [...]
> > I set up the logging code at the very beginning of the app, before any other
> > work is done.  Here's the relevant code:
> > 
> > #!/usr/bin/env python3
> [... snip imports ...]
> > class MainWindow(QMainWindow):
> > def __init__(self):
> > super().__init__()
> > # set up logging
> > logging.basicConfig(format='%(levelname)s:%(message)s',
> >   filename="sample.log", level=logging.DEBUG)  
> > logging.info("Starting system, MainWindow.__init__,  %s",
> >   str(datetime.datetime.today()))
> > self.createUI() 
> 
> According to this code, no logging will occur because no MainWindow is
> created. Nor is there any sort of main event loop.
> 
> I'm sure that you're not actually so silly that you forgot to create a window
> at all, but the point is, this example is *not* "the relevant code". It is
> only *part* of the relevant code. Who knows what else is happening that might
> be preventing logging from working? We don't know because we can't see the
> rest of the relevant code. Perhaps you need to focus on that.
> 
> 
> [...]
> > Between the time that the logging was working and the time it quit, the only
> >  changes I made were to add a couple of logging.info() statements into a
> >  downstream module.  But that seems irrelevant here, as those modules aren't
> >  included in the above test.
> 
> I doubt that. I expect there must be some other change you have forgotten, and
> it is *that* which has disabled logging. Maybe you call something which sets
> the logging level above INFO?
> 
> I would start with this:
> 
> import sys
> import os
> import logging
> logging.basicConfig(format='%(levelname)s:%(message)s', 
> filename="sample.log", level=logging.DEBUG)
> logging.info("Starting module,  %s", str(datetime.datetime.today()))
> 
> # import everything else
> ...
> logging.info("Importing complete %s", str(datetime.datetime.today()))
> 
> class MainWindow(QMainWindow):
> def __init__(self):
> super().__init__()
> logging.info("Creating window,  %s", str(datetime.datetime.today()))
> self.createUI() 
> 
> logging.info("Class created %s", str(datetime.datetime.today()))
> window = MainWindow()
> logging.info("Window created %s", str(datetime.datetime.today()))
> logging.critical("Can you see this? %s", str(datetime.datetime.today()))
> 
> # plus whatever else is needed to make the application run
> ...
> 
> That will show precisely where and when logging stops:
> 
> 1. Does it work at all, straight out of the logging module? If not, then
> something broke it before your module even gets loaded.
> 
> 2. Does it still work after all the other imports? If not, then bisect the
> imports until you locate which module breaks logging.
> 
> 3. Do you get the "Class created" and "Window created" messages? If no, then
> that helps narrow down where the fault may lie.
> 
> E.g. if you see the first, but not the second, then something in
> super().__init__ may be disabling logging; if you don't see the first, then
> look at QMainWindow's metaclass, if it has one. If it doesn't have a
> metaclass, then that's a mystery -- maybe something in some other thread is
> messing you about?
> 
> 4. If you see the CRITICAL message, but not the INFO ones, then something has
> reset the logging level.
> 
> 5. What happens if you delete sample.log? Does it get re-created? If not,
> maybe there's a permissions error.
> 
> 6. If you're not seeing *any* logging at all, perhaps you need to fall back on
> calling print() directly. Run your application from a terminal, and see what
> it prints.
> 
> If even print isn't working, then follow the three Rs: Reboot, Reinstall, and
> Resign :-)
> 
> 7. Perhaps a bit less drastic, you can insert a debugging checkpoint in the
> code, run the application from a terminal, and when it halts at the debugger,
> have a look at the state of the logging module.
> 
> 8. Just to be absolutely sure, check logging.__file__ to ensure you haven't
> shadowed the real logging module with some sort of mock. But now I'm really
> clutching at straws, because if that were the case, I'd expect there to be an
> exception, not just logging failing to work.
> 
> 
> 
> I'm intrigued by this error, and would love to hear what caused it when you
> find out. Please respond back on the list with your diagnos

Re: Logging module stopped working

2017-10-17 Thread llanitedave
Those are some good suggestions, I've found that I won't be able to work on it 
today, but I'll definitely follow up tomorrow.  As for not showing all the 
code, the main window and its associated code are definitely there and working. 
 I didn't post it because of all the setup code for fields and buttons and 
menus that I'd have to filter out.  The main point was that I had two files 
containing identical code (all the differences between the two drafts were in 
other modules) yet one activated the logging properly and one didn't.  It's the 
silent failure that bothers me, I would have hoped that if I'd done something 
really boneheaded it would have made some noise.

I'll try those suggestions and post back.  Thanks for the thoughtful help.
-- 
https://mail.python.org/mailman/listinfo/python-list


Logging module stopped working

2017-10-16 Thread llanitedave
I'm building an application that contains some long-running operations in a 
separate thread from the user interface.  I've been using the logging module 
writing logging.info() statements to a .log file to keep track of the data 
interactions while it runs.

In the midst of a recent run, the logging simply stopped working.  The rest of 
the application continued on as if nothing had happened, but without the log 
I'm pretty much blind.

I set up the logging code at the very beginning of the app, before any other 
work is done.  Here's the relevant code:

#!/usr/bin/env python3

import sys
import os
#import functions_classes
from PyQt5 import QtGui, QtCore, QtWidgets
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
import sqlite3
import logging
import inspect
import threading
import datetime

#import local modules
import qt_EnvTabs
import globalnames
import evocontrol
import inputoutput

class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
# set up logging
logging.basicConfig(format='%(levelname)s:%(message)s', 
filename="sample.log", level=logging.DEBUG)
logging.info("Starting system, MainWindow.__init__,  %s", 
str(datetime.datetime.today()))
self.createUI()

I also have an earlier draft of the application that I saved into another 
directory.  Its initial code is identical to what I posted here.  I opened it, 
saw the first window activate, and then closed it.  I checked for the 
sample.log file, it existed, and contained the proper message:
"INFO:Starting system, MainWindow.__init__,  2017-10-16 20:58:40.988035"

I did the same to the current file, and no log file was created at all!

Between the time that the logging was working and the time it quit, the only 
 changes I made were to add a couple of logging.info() statements into a 
downstream module.  But that seems irrelevant here, as those modules aren't 
included in the above test.

Is there any behind-the-scenes behavior that I'm missing?  I'm stumped.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: asyncio Behaviour Difference 3.6 vs 3.5 (Posting On Python-List Prohibited)

2017-06-11 Thread llanitedave
On Sunday, June 11, 2017 at 2:42:41 AM UTC-7, Lawrence D’Oliveiro wrote:
> I tried the following very simple script under both versions 3.5.3 and 3.6.1 
> of Python:
> 
> import sys
> import asyncio
> 
> loop = asyncio.get_event_loop()
> 
> async def idle() :
> while True :
> await asyncio.sleep(1)
> #end while
> #end idle
> 
> loop.create_task(idle())
> loop.run_forever()
> 
> After it starts running, I hit CTRL/C. Under both versions, I get the usual 
> KeyboardInterrupt exception and traceback. However, under 3.5, I also get 
> this:
> 
> Task was destroyed but it is pending!
> task:  
> wait_for=>
> 
> OK, as near as I can tell from the asyncio docs 
> , it makes sense for this 
> message to appear. Yet it does not come up with 3.6. Was it deemed to be too 
> noisy, and too much trouble to silence, so it was quietly dropped?
> 
> Yet according to the 3.6 release notes 
> , the changes to asyncio 
> have been backported to 3.5. So should there be a difference in behaviour 
> between the two?
> 
> I’m running Debian Unstable, so feel free to tell me 3.5.3 is obsolete and 
> there is some later 3.5.x version. ;)


My message in 3.5.3 is somewhat different, running Kubuntu 17.04:

>>> import sys
>>> import asyncio
>>> loop = asyncio.get_event_loop()

>>> async def idle():
... while True:
... await asyncio.sleep(1)
... #end while
... #end idle
... 
>>> loop.create_task(idle())
:1>>
>>> loop.run_forever()
^CTraceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python3.5/asyncio/base_events.py", line 421, in run_forever
self._run_once()
  File "/usr/lib/python3.5/asyncio/base_events.py", line 1388, in _run_once
event_list = self._selector.select(timeout)
  File "/usr/lib/python3.5/selectors.py", line 445, in select
fd_event_list = self._epoll.poll(timeout, max_ev)
KeyboardInterrupt
As yu can see, I get the  "Task pending coro=

Re: Getting back into PyQt and not loving it.

2016-06-27 Thread llanitedave
On Sunday, June 26, 2016 at 11:16:01 PM UTC-7, John Ladasky wrote:
> On Sunday, June 26, 2016 at 7:41:17 PM UTC-7, Michael Torrie wrote:
> > If GTK+ had first-class support on Windows and Mac, including native
> > themes and seamless UI integration (file and print dialogs), I'd say
> > GTK+ would be the only game in town for Python programmers.
> > Unfortunately, unless you're only concerned with Linux, GTK+ is probably
> > not going to be your choice.
> 
> Although I work almost exclusively in Linux, I've been teaching Python for 
> several years as a sideline, and my students usually do not use Linux.  I 
> insist on teaching my students Python 3.  Unless they're professionals who 
> must work with legacy code (and, so far, none of them have been), I think I 
> would be doing them a disservice to teach them Python 2.
> 
> I started with WxPython, but WxPython/Phoenix has been very slow to migrate 
> to Python 3.  
> 
> Between the Py3 requirement and the need to work with all major OS's, I 
> decided to learn PyQt and not GTK+.  
> 
> In my current day job, I'm developing an application on a Linux box, but I'll 
> be handing it off to Windows users.  My choice of PyQt turned out to be the 
> right one in that situation as well.

I produced a couple of applications using wxPython 2.8 and Python 2.7, and I 
was happy with how they turned out, but since I moved to Python 3 I got tired 
of waiting for a Phoenix release that I felt comfortable with, so I've been 
learning PyQT lately. I do find that PyQt is more straightforward in many 
respects than wxPython, but the difference for me has always been how well 
organized and understandable the documentation is.  The PyQt examples seem very 
comprehensive, but the code is poorly commented and there are some quirks that 
are confusing me.   The original wxPython book was quite well put together and 
extremely helpful, and I miss having something like that for Qt.  I'm going 
through the eBook on PyQt4, but I'm not yet sure how well it will translate to 
PyQt5, which I'm trying to develop with.  I do think I'll stick with it, 
though.  Once I learn it I think it will serve me well.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Getting back into PyQt and not loving it.

2016-06-26 Thread llanitedave
On Sunday, June 26, 2016 at 2:45:18 PM UTC-7, Michael Torrie wrote:
> I'm starting to question the advice I gave not long ago to for new users
> to consider the Qt toolkit with Python.
> 
> I just did a little project porting a simple graphical user interface
> from GTK+ to Qt (PyQt4 for now as that's what I have installed).  For
> the most part it worked out pretty well.  It's been a while since I used
> PyQt or PySide, and I had forgotten what a horrid Python experience Qt
> really is, at least in PyQt4.  Maybe the bindings for Qt5 are better...
> I'll be working with them next as I convert my working code.
> 
> Qt's a fantastic toolkit, and the most mature of any of them, and the
> most portable, but man the bindings are not Pythonic at all. PyQt does
> not seem to hide the C++-isms at all from the programmer.  I am
> constantly wrapping things up in Qt classes like QRect, QPoint, QSize,
> etc, when really a python Tuple would have sufficed.  All the data
> structures are wrapped in Qt C++ classes, so you end up writing what is
> really idiomatic C++ code using Python syntax. Not the best way to code
> Python!  Implementing signals in a class, too, reminds you strongly that
> you're working with C++ as you have to construct their method signatures
> using types that map back into C++.

Not sure that wxPython is really any different in that respect, and Tkinter 
doesn't feel Pythonic to me, either -- considering how it's Tk at heart.  So 
what's the alternative?  There really is no good Python-based GUI tool, and 
that's a shame.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Which GUI?

2015-07-25 Thread llanitedave
On Friday, July 24, 2015 at 4:16:19 PM UTC-7, Mark Lawrence wrote:
 On 24/07/2015 23:20, Frank Miles wrote:
  On Fri, 24 Jul 2015 19:31:36 +0100, Paulo da Silva wrote:
 
  [snip]
 
 
  Which technology is better?
  matplotlib?
  tkinter?
  wxwidgets?
  qt?
 
  Sadly - I don't think wxpython has been ported to python3 yet.
 
 
 http://wxpython.org/Phoenix/docs/html/main.html
 
 -- 
 My fellow Pythonistas, ask not what our language can do for you, ask
 what you can do for our language.
 
 Mark Lawrence

Matplotlib apparently still has some issues with wxPhoenix. Not that Matplotlib 
is a necessity for the OP's application, but it could address some of the speed 
issues he was concerned about.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: New to Python - block grouping (spaces)

2015-04-21 Thread llanitedave
On Sunday, April 19, 2015 at 7:09:02 PM UTC-7, Rustom Mody wrote:

 
 let me spell it out:
 Prestige of Aristotle stymies progress of physics of 2 millennia 
 likewise
 Prestige of Unix development environment keeps us stuck with text files when
 the world has moved on

Difference is, Aristotle was flat-out, objectively wrong.

Unix with text files, not so much.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: New to Python - block grouping (spaces)

2015-04-21 Thread llanitedave
On Tuesday, April 21, 2015 at 8:12:07 PM UTC-7, Rustom Mody wrote:
 On Wednesday, April 22, 2015 at 3:05:57 AM UTC+5:30, llanitedave wrote:
  On Tuesday, April 21, 2015 at 10:49:34 AM UTC-7, Rustom Mody wrote:
   If only Galileo had had you as lawyer...
  
  Well, I'd asked Giordano Bruno for a positive recommendation.  For some
  inexplicable reason, he declined.
 
 Maybe got too steamed-up pursuing high philosophy??

I think it had something to do with multiple inheritance.  Anyway, back in 
those days using indentation rather than braces was definitely considered 
heresy.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: New to Python - block grouping (spaces)

2015-04-21 Thread llanitedave
On Tuesday, April 21, 2015 at 10:49:34 AM UTC-7, Rustom Mody wrote:
 On Tuesday, April 21, 2015 at 9:01:08 PM UTC+5:30, llanitedave wrote:
  On Sunday, April 19, 2015 at 7:09:02 PM UTC-7, Rustom Mody wrote:
  
   
   let me spell it out:
   Prestige of Aristotle stymies progress of physics of 2 millennia 
   likewise
   Prestige of Unix development environment keeps us stuck with text files 
   when
   the world has moved on
  
  Difference is, Aristotle was flat-out, objectively wrong.
  
  Unix with text files, not so much.
 
 If only Galileo had had you as lawyer...

Well, I'd asked Giordano Bruno for a positive recommendation.  For some 
inexplicable reason, he declined.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices]

2015-03-06 Thread llanitedave
On Friday, March 6, 2015 at 2:03:42 AM UTC-8, Marko Rauhamaa wrote:
 Rustom Mody rustompm...@gmail.com:
 
  I really dont understand what we are communicating (or not) about...
 
  Can you hear my accent?
 
 If we met at a Python conference, I would hear it and hopefully even
 understand it.
 
  But more to the point its still not clear (to me) whether you are objecting 
  to
  - to Mark
  - to British accent
  - to British spellings in software
  - to anyone/anywhere international, using non-international format
 
 I'm objecting (mildly) to British spellings in source code and technical
 documentation.
 
 I'm objecting (more strongly) to local English accents in settings
 including but not limited to:
 
  - conference speeches with international audiences
 
  - group discussions with international participants
 
  - teleconferences with international participants
 
 In my experience, it is harder to understand most British English
 accents than, say, a run-of-the-mill Chinese engineer trying to speak
 English. It has to do with pronunciation, speed and eloquence (too much
 of it with native speakers).
 
 
 Marko

It's obvious that's what's needed here is a PEP requiring that the 
International Phonetic Alphabet be used for all Python identifiers and keywords.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: HELP!! How to ask a girl out with a simple witty Python code??

2015-03-06 Thread llanitedave
On Wednesday, March 4, 2015 at 6:50:32 PM UTC-8, sohca...@gmail.com wrote:
 On Wednesday, March 4, 2015 at 5:34:16 PM UTC-8, Xrrific wrote:
  Guys, please Help!!!
  
  I am trying to impress a girl who is learning python and want ask her out 
  at the same time.
  
  Could you please come up with something witty incorporating a simple python 
  line like If...then... but..etc.
  
  You will make me a very happy man!!!
  
  Thank you very much!!!
 
 You're asking a bunch of nerds for dating advice?

Girls can be nerds too, ya know...
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices]

2015-03-03 Thread llanitedave
Seems the ultimate in irony when a language invented by a Dutchman and named 
after a British comedy troupe gets bogged down in an argument about whether its 
users are sufficiently American.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: SQLite3 in Python 2.7 Rejecting Foreign Key Insert

2014-11-23 Thread llanitedave
On Sunday, November 23, 2014 12:22:30 AM UTC-8, Frank Millman wrote:
 Chris Angelico ros...@gmail.com wrote in message 
 news:captjjmp4y5zowwn5yftjutko4h5jvtqlantwqepa6b35xnd...@mail.gmail.com...
 
  Entirely possible. I never did track down the actual cause of the
  SQLite3 issues my students were having; though I suspect it's not
  purely a Python API issue. I tried to demonstrate the concept of
  foreign keys using the sqlite3 command line tool, and did a sequence
  of commands which ought to have failed, but didn't.
 
 The default is for sqlite3 to ignore foreign key contraints.
 
 To enable them, add the following -
 
 pragma foreign_keys = on;
 
 It works for me.
 
 Unfortunately it has a limitation, which they acknowledge but they say is 
 unlikely to be addressed. You can access more than one database concurrently 
 by using the 'attach' command, and qualifying a remote tablename as 
 {database} dot {tablename}. You can then include the remote table in any sql 
 command. However, it will not enforce foreign key constraints across 
 databases.
 
 Frank Millman

Well in this case the foreign keys ARE on, otherwise it wouldn't be throwing up 
a foreign key  conflict.  I've got one more thing to try, but so far I still 
haven't figured out why it's not accepting the foreign key data.  The only 
thing I can conclude so far is that it chokes if the fields are TEXT.  I've got 
other foreign keys in the database that are more traditional integer fields, 
and they seem to be working fine.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: SQLite3 in Python 2.7 Rejecting Foreign Key Insert

2014-11-23 Thread llanitedave
On Saturday, November 22, 2014 6:11:22 PM UTC-8, llanitedave wrote:
 I've built a database in SQLite3 to be embedded into a python application 
 using wxPython 2.8.12 and Python 2.7.6.  I'm using Sqliteman to manage the 
 database directly and make changes to the structure when necessary.
 
 One item that's been bugging me is when I'm inserting records into one 
 particular table:
 
 The parent table is called borehole, and the 'borehole_id' field is TEXT.  
 It's essentially a name field, because every borehole name is naturally 
 unique, therefore I thought an autoincrementing integer would be superfluous.
 
 A related field is called core_run, and its foreign key field is named 
 of_borehole -- of course its type is TEXT NOT NULL as well.  It's described 
 in the DESCRIBE TABLE feature of Sqliteman as FOREIGN KEY(of_borehole) 
 REFERENCES borehole(borehole_id)
 
 When I use Sqliteman to manually create a record using INSERT INTO core_run 
 VALUES..., it works properly.  However, when I do the same thing, using the 
 same test data, from inside Python, I get the following SQLite error
 
 'foreign key mismatch - core_run referencing borehole'
 
 To make sure the core_run.of_borehole and borehole.borehole_id fields are 
 equivalent, I inserted a logging statement just prior to the database cursor.
 
 [code]
 # retrieve the borehole id field, check it matches with of_borehole field
 db_cursor.execute(select borehole_id from borehole where borehole_id = ?, 
 (runfields[1],))
 relatedbh = db_cursor.fetchone()[0]
 logging.info(Related borehole_id is %s, of_borehole is %s, relatedbh, 
 runfields[1])
 [/code]
 
 runfields[1] here is the of_borehole field taken from the applications GUI 
 field.
 
 In this case, the displayed data from both is identical -- the logging line 
 comes back as:
 INFO:Related borehole_id is testbh3, of_borehole is testbh3
 
 So the data type is the same, and the content appears to be the same.  So why 
 would there be a foreign key mismatch?  Is it possible that there is some 
 invisible code in the string which isn't being detected by the logging 
 command?  Is this just a quirk of the Sqlite3 implementation in Python that 
 demands foreign keys be integers?
 
 I feel like I've hit a brick wall here.
 
 Thanks!

OK, I got it working.  VICTORY!

Here's what I did.

The original CREATE TABLE command for the core_run table defined all the fields 
and then added the foreign key at the bottom of the definition like so:

FOREIGN KEY(of_borehole) REFERENCES borehole(borehole_id)

I recreated the table and put the foreign key reference directly into the field 
definition:

of_borehole TEXT NOT NULL REFERENCES borehole,

This is a valid alternative according to the SQLite3 docs, if you don't 
explicitly define the field name then it references to the primary key that 
already exists in the referenced table.

And that's all I had to do.  Strange, but it did the trick.

For the enhanced version of this application I will DEFINITELY use an integer 
primary key for the boreholes table!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ** in python

2014-11-23 Thread llanitedave
On Sunday, November 23, 2014 5:49:05 PM UTC-8, Skip Montanaro wrote:
 I want to add one more thing to the other responses. People new to Python 
 often seem unaware that being an interpreted language, often the best way to 
 figure something out is to simply try it at the interpreter prompt. The OP 
 saw var ** 2 in done code. The most obvious thing to me would have been to 
 type
 
 var = 42
 
 var ** 2
 
 and see what happened. It's unlikely to trigger a nuclear meltdown, or even 
 crash the interpreter.
 
 Skip


I dunno, if it took 7.5 million years to come up with the answer in the first 
place, imagine how long it might take to square it!
-- 
https://mail.python.org/mailman/listinfo/python-list


SQLite3 in Python 2.7 Rejecting Foreign Key Insert

2014-11-22 Thread llanitedave
I've built a database in SQLite3 to be embedded into a python application using 
wxPython 2.8.12 and Python 2.7.6.  I'm using Sqliteman to manage the database 
directly and make changes to the structure when necessary.

One item that's been bugging me is when I'm inserting records into one 
particular table:

The parent table is called borehole, and the 'borehole_id' field is TEXT.  
It's essentially a name field, because every borehole name is naturally unique, 
therefore I thought an autoincrementing integer would be superfluous.

A related field is called core_run, and its foreign key field is named 
of_borehole -- of course its type is TEXT NOT NULL as well.  It's described 
in the DESCRIBE TABLE feature of Sqliteman as FOREIGN KEY(of_borehole) 
REFERENCES borehole(borehole_id)

When I use Sqliteman to manually create a record using INSERT INTO core_run 
VALUES..., it works properly.  However, when I do the same thing, using the 
same test data, from inside Python, I get the following SQLite error

'foreign key mismatch - core_run referencing borehole'

To make sure the core_run.of_borehole and borehole.borehole_id fields are 
equivalent, I inserted a logging statement just prior to the database cursor.

[code]
# retrieve the borehole id field, check it matches with of_borehole field
db_cursor.execute(select borehole_id from borehole where borehole_id = ?, 
(runfields[1],))
relatedbh = db_cursor.fetchone()[0]
logging.info(Related borehole_id is %s, of_borehole is %s, relatedbh, 
runfields[1])
[/code]

runfields[1] here is the of_borehole field taken from the applications GUI 
field.

In this case, the displayed data from both is identical -- the logging line 
comes back as:
INFO:Related borehole_id is testbh3, of_borehole is testbh3

So the data type is the same, and the content appears to be the same.  So why 
would there be a foreign key mismatch?  Is it possible that there is some 
invisible code in the string which isn't being detected by the logging command? 
 Is this just a quirk of the Sqlite3 implementation in Python that demands 
foreign keys be integers?

I feel like I've hit a brick wall here.

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


Re: SQLite3 in Python 2.7 Rejecting Foreign Key Insert

2014-11-22 Thread llanitedave
On Saturday, November 22, 2014 6:22:32 PM UTC-8, Chris Angelico wrote:
 On Sun, Nov 23, 2014 at 1:11 PM, llanitedave wrote:
  logging.info(Related borehole_id is %s, of_borehole is %s, relatedbh, 
  runfields[1])
 
  In this case, the displayed data from both is identical -- the logging line 
  comes back as:
  INFO:Related borehole_id is testbh3, of_borehole is testbh3
 
  So the data type is the same, and the content appears to be the same.  So 
  why would there be a foreign key mismatch?  Is it possible that there is 
  some invisible code in the string which isn't being detected by the logging 
  command?  Is this just a quirk of the Sqlite3 implementation in Python that 
  demands foreign keys be integers?
 
 
 First thing I'd do, if I'm suspicious of invisible stuff in a string,
 is to change those %s markers to %r. You'll get a quoted string (so
 you can see if there's leading/trailing whitespace), any non-ASCII
 characters will be escaped (assuming this is a byte string in Python
 2, which seems to be the case), and control characters like newlines
 will become escapes too.
 
 But I've seen a number of very strange and annoying behaviours out of
 SQLite as regards foreign keys. It seems that sometimes integrity
 checks just aren't being done, and I don't know why. Can you switch to
 a PostgreSQL back-end to see if the problem (a) suddenly disappears,
 (b) suddenly appears at a completely different point, or (c) now has a
 more informative error message? Chances are all you need to do is
 change your import and connection setup, and all the rest will work
 just the same.
 
 By the way, naming convention: I prefer to use id only when it's
 actually a numeric ID. For something like this, I'd call it name,
 since that's what it is. But that won't be affecting your foreign key.
 
 ChrisA

Well that DID make a difference!  I used the %r marker, and the logger line 
gave me back:
INFO:Related borehole_id is u'testbh3', of_borehole is 'testbh3'

So it looks like I need to change my foreign key string to a unicode string.  
I'll be working on that...
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: SQLite3 in Python 2.7 Rejecting Foreign Key Insert

2014-11-22 Thread llanitedave
On Saturday, November 22, 2014 9:41:55 PM UTC-8, Chris Angelico wrote:
 On Sun, Nov 23, 2014 at 3:58 PM, Michael Torrie wrote:
  On 11/22/2014 08:54 PM, llanitedave wrote:
  Well that DID make a difference!  I used the %r marker, and the logger
  line gave me back:
  INFO:Related borehole_id is u'testbh3', of_borehole is 'testbh3'
 
  So it looks like I need to change my foreign key string to a unicode
  string.  I'll be working on that...
 
  Or manually encode it to a UTF-8 byte string (just call .encode() on
  it).  Sqlite probably only knows about UTF-8 when it comes to unicode.
 
 Since it was a byte string sent to the database and a Unicode string
 coming back, the solution would be to .decode() the byte string.
 However, I doubt that's the issue; that's being done for you
 implicitly by the lower-level connections. Also, in Python 2:
 
  u'testbh3' ==  'testbh3'
 True
 
 So that's not your primary problem. You could try that, but I doubt
 it'll solve anything for you.
 
 Are you able to switch to Python 3, though? If you are, Unicode issues
 tend to be a lot easier to resolve there.
 
 ChrisA

You're right.  It ultimately didn't make a difference.  And it makes sense that 
it wouldn't have, because when I did a query using the same field that got 
rejected by the foreign key, the query was successful.

The application was working correctly earlier (meaning that I could enter and 
retrieve data with it; being a strictly user application it didn't allow 
deletes from the GUI), and then I discovered (while cleaning up the user 
documentation) that I'd neglected to include a couple of relatively important 
database fields.  Because of SQLite's limited ALTER TABLE capabilities, that 
mean I had to recreate the tables to add the fields, and in doing so noticed 
that the table in question didn't even have the foreign key constraint defined. 
 So ever since I defined that constraint, it hasn't let me save any records on 
that table from Python.  Although, as I said, when entering the same data 
through the Sqliteman application, it works fine. That's why I suspected that 
the problem might be in the Python API for SQLite3.

As for Python3, that's a future possibility.  My next step was to expand the 
functionality of this particular app, which is intended for use in the field on 
a tablet or laptop, to a web-app using Django 1.7. WxPython was really a way to 
get my feet wet on it.  The Django version is using Python 3.4 and Postgresql 
9.3.4, and it's still in the early stages -- I broke off of it to correct this 
mess.

It's in the back of my head to go back to the field version at some point with 
Python3 and PyQt, but it is not this day.

Anyway, if I can't get this thing straightened out, I may have to just remove 
the foreign key constraint and rely on application logic to ensure my data 
integrity.  :(

I do appreciate the help, though Chris.  If nothing else, you've showed me some 
directions that I needed some extra learning in.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: SQLite3 in Python 2.7 Rejecting Foreign Key Insert

2014-11-22 Thread llanitedave
On Saturday, November 22, 2014 10:32:30 PM UTC-8, Chris Angelico wrote:
 On Sun, Nov 23, 2014 at 5:08 PM, llanitedave wrote:
  The application was working correctly earlier (meaning that I could enter 
  and retrieve data with it; being a strictly user application it didn't 
  allow deletes from the GUI), and then I discovered (while cleaning up the 
  user documentation) that I'd neglected to include a couple of relatively 
  important database fields.  Because of SQLite's limited ALTER TABLE 
  capabilities, that mean I had to recreate the tables to add the fields, and 
  in doing so noticed that the table in question didn't even have the foreign 
  key constraint defined.  So ever since I defined that constraint, it hasn't 
  let me save any records on that table from Python.  Although, as I said, 
  when entering the same data through the Sqliteman application, it works 
  fine. That's why I suspected that the problem might be in the Python API 
  for SQLite3.
 
 
 Entirely possible. I never did track down the actual cause of the
 SQLite3 issues my students were having; though I suspect it's not
 purely a Python API issue. I tried to demonstrate the concept of
 foreign keys using the sqlite3 command line tool, and did a sequence
 of commands which ought to have failed, but didn't. Let's see if I can
 recreate this:
 
 rosuav@sikorsky:~$ sqlite3
 SQLite version 3.7.13 2012-06-11 02:05:22
 Enter .help for instructions
 Enter SQL statements terminated with a ;
 sqlite create table foo (val text primary key);
 sqlite create table bar (val text references foo on delete set null);
 sqlite insert into foo values ('asdf');
 sqlite insert into bar values ('asdf');
 sqlite insert into bar values ('qwer');
 sqlite select * from foo;
 asdf
 sqlite select * from bar;
 asdf
 qwer
 sqlite delete from foo;
 sqlite select * from foo;
 sqlite select * from bar;
 asdf
 qwer
 
 So the foreign key is being completely ignored. If I do the same
 commands in PostgreSQL, I get errors at appropriate places:
 
 rosuav@sikorsky:~$ psql
 psql (9.3.5)
 Type help for help.
 
 rosuav= create table foo (val text primary key);
 CREATE TABLE
 rosuav= create table bar (val text references foo on delete set null);
 CREATE TABLE
 rosuav= insert into foo values ('asdf');
 INSERT 0 1
 rosuav= insert into bar values ('asdf');
 INSERT 0 1
 rosuav= insert into bar values ('qwer');
 ERROR:  insert or update on table bar violates foreign key
 constraint bar_val_fkey
 DETAIL:  Key (val)=(qwer) is not present in table foo.
 rosuav= select * from foo;
  val
 --
  asdf
 (1 row)
 
 rosuav= select * from bar;
  val
 --
  asdf
 (1 row)
 
 rosuav= delete from foo;
 DELETE 1
 rosuav= select * from foo;
  val
 -
 (0 rows)
 
 rosuav= select * from bar;
  val
 -
 
 (1 row)
 
 
 PostgreSQL is a lot more chatty, but what's significant here is that
 it won't let me insert into the referring table when there's no row in
 the referent. Also, when I delete the referred-to row, the referring
 row's key gets correctly set to NULL (like I specified in the
 constraint definition).
 
 I don't know if there's a way to tell SQLite hey, I want you to
 actually take notice of foreign keys, tyvm, as there's nothing
 obvious in the .help command output; but even if there is, I don't
 know why that isn't the default. Maybe there can be a way to say
 ignore foreign key constraints for efficiency, but frankly, I'd
 rather have constraints actually checked - if you want to cheat them
 away, actually drop the constraints, don't have the database silently
 ignore them.
 
  As for Python3, that's a future possibility.  My next step was to expand 
  the functionality of this particular app, which is intended for use in the 
  field on a tablet or laptop, to a web-app using Django 1.7. WxPython was 
  really a way to get my feet wet on it.  The Django version is using Python 
  3.4 and Postgresql 9.3.4, and it's still in the early stages -- I broke off 
  of it to correct this mess.
 
  It's in the back of my head to go back to the field version at some point 
  with Python3 and PyQt, but it is not this day.
 
 Cool. There are several GUI toolkits for Python, and I know multiple
 of them do support Py3; I can't say which is the best, as I don't do
 my GUI programming in Python generally. But definitely try to use
 Python 3 if you can; and try to use PostgreSQL if you can, too.
 SQLite3 may be the light-weight option, but as you're seeing, it does
 sometimes take shortcuts; switching to a more full-featured database
 may be worth doing permanently, or at least for development (think of
 it like turning on a bunch of assertions).
 
  Anyway, if I can't get this thing straightened out, I may have to just 
  remove the foreign key constraint and rely on application logic to ensure 
  my data integrity.  :(
 
  I do appreciate the help, though Chris.  If nothing else, you've showed me 
  some directions that I needed some extra learning in.
 
 My pleasure! Databasing

Re: Python GUI?

2013-09-18 Thread llanitedave
On Friday, September 13, 2013 10:31:17 AM UTC-7, Eamonn Rea wrote:
 I don't like the idea of being able to drag and drop anything in the 
 programming world. Outside of that, I use DD programs a lot. I got into GUI 
 programming because I thought that I could get away from them, but I guess 
 not.
 
 
 
 Maybe I'm against them because if I can't code, I don't have anything else to 
 do with my time. If I don't program, the only other thing I have to do is... 
 well... nothing. So, because of this, they're making programming easier... by 
 not coding as much. Oh well, guess coding is dead :(

Why do you feel the need to project your personal issues onto the whole world?  
Nobody is forcing you to use Drag and Drop -- you simply have the option to do 
so, or not.  I don't use it either, but I sure don't fill up with angst just 
because someone else might actually enjoy using it.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can I trust downloading Python?

2013-09-08 Thread llanitedave
I capitalize Free to avoid confusing it with free as in beer.

On Sunday, September 8, 2013 3:01:58 AM UTC, Ben Finney wrote:
 Aaron Martin aaronspencermar...@gmail.com writes:
 
 
 
  Hi, I am thinking about getting a software but it requires python, so
 
  that brought up a few questions. Is it safe do download python, and
 
  does it come with spam or advertisements?
 
 
 
 Python is free software, meaning that every recipient is free to improve
 
 it and redistribute the result.
 
 
 
 URL:https://en.wikipedia.org/wiki/Free_software
 
 
 
 Free software rarely has the problems you describe – spam and
 
 advertisements – and never has them for long, because those problems are
 
 quickly improved (by eradicating the annoying problem), and the improved
 
 version becomes what people share.
 
 
 
  If it doesn't then should I get the latest version?
 
 
 
 The latest stable version is Python 3.3, and this version is strongly
 
 recommended for people who will be developing with Python.
 
 
 
 But you say that you are getting Python because you have some other
 
 program that requires Python. Which version of Python does it require?
 
 Download and install the latest version that is supported for the
 
 program you are wanting to use.
 
 
 
  I mostly want to know if it is safe to download, because most of the
 
  time downloading free stuff off the internet comes with spam and all
 
  that, so I want to know if I can trust downloading it.
 
 
 
 Ah, your experience is with zero-cost non-free software. Non-free
 
 software is prone to have spam and advertisements, and many other
 
 problems that arise from disrespect for the recipient's freedom. So your
 
 caution is well advised.
 
 
 
 Know that free software respects your freedom, and Python is free
 
 software.
 
 
 
 URL:https://www.fsf.org/about/what-is-free-software
 
 
 
 Welcome, and good fortune to you in using Python!
 
 
 
 -- 
 
  \ “I was trying to daydream, but my mind kept wandering.” —Steven |
 
   `\Wright |
 
 _o__)  |
 
 Ben Finney

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


Re: PEP8 79 char max

2013-07-31 Thread llanitedave
It's not just the number of characters, it's the size and the font.  Even 
fixed-width fonts differ greatly in their readability.  

I can handle different line widths just fine up til about 120 or so without 
losing the flow of the program, but some fonts simply make it more difficult at 
any width.

I've tried many, but for some reason I keep coming back to Courier10 at 10 
points.  I'm almost embarrassed that my choice is such an old and primitive 
font, but that's how my brain works.

In my experience, if code is well-spaced, well-commented, and broken up into 
logical groups with appropriate blank spaces, line length can be about 3/4 the 
width of whatever editor is being used.  And most editors are wide enough to 
easily accommodate over 100 characters.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: looking for a new router

2013-07-09 Thread llanitedave
On Tuesday, July 9, 2013 2:14:36 PM UTC-7, Dave Angel wrote:
 On 07/09/2013 01:29 AM, Kumita Bruce wrote:
 
  Agree.
 
 
 
  Sir, this mailing list is for Python discussion. :)
 
 
 
 
 
 Save your breath.  saadharana and saishreemathi are spambots, and are 
 
 undoubtedly not listening.
 
 
 
 
 
 
 
 
 
 -- 
 
 DaveA

But hey, the plunge router recommendations are great!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A small question about PEP 8

2013-07-09 Thread llanitedave
I definitely prefer the 'fool' style.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Re-using copyrighted code

2013-06-10 Thread llanitedave
On Sunday, June 9, 2013 2:08:54 PM UTC-7, zipher wrote:
 
 
  Fair use has nothing to do with money. It depends on how the work is
 
  used and how you've changed it. Weird Al's song parodies are fair use,
 
  even though he sells them.
 
 
 
 That can't really be claimed without a case being brought against him.
 
  Michael Jackson, for example, probably could have made a case against
 
 WierdAl, but did not -- that does not automatically mean that
 
 WierdAl's use was fair-use in the slightest.  In fact, it probably was
 
 not, but MJ made enough money that he probably also didn't want to the
 
 PR loss.
 
 
 

Weird Al can be a complex case, because sometimes his songs are true parodies, 
and sometimes they're more satires.  Parody has a pretty firm history of being 
protected under fair use, and Weird Al's MJ-inspired songs (Fat and Eat It) 
are clearly parodies.  (As is his more recent Lady Gaga sendup Perform This 
Way, while his Star wars saga The Story Begins and Coolio-esque Amish 
Paradise are more like satires).

So in the case of Weird Al's Michael Jackson parodies, he would be protected 
under law if MJ had decided to sue.

However, there's another reason that Weird Al's victims never file a suit.  
First, he always gets permission from them BEFORE publishing a song.  Second, 
the objects of his skewering usually like the fact that they've been noticed by 
him.  Madonna actually suggested the idea of Like a Surgeon, and when he did 
Smells Like Nirvana, the group felt like they'd finally made it.

This is all kind of OT, of course, except to point out that fair use is not as 
straightforward as it might seem, but neither is prohibition of reuse.

However, I have yet to see an example of source code that qualifies as either 
parody or satire under any standard.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Re-using copyrighted code

2013-06-10 Thread llanitedave
On Monday, June 10, 2013 12:40:57 PM UTC-7, zipher wrote:
  Weird Al can be a complex case, because sometimes his songs are true 
  parodies, and sometimes they're more satires.  Parody has a pretty firm 
  history of being protected under fair use, and Weird Al's MJ-inspired songs 
  (Fat and Eat It) are clearly parodies.  (As is his more recent Lady 
  Gaga sendup Perform This Way, while his Star wars saga The Story Begins 
  and Coolio-esque Amish Paradise are more like satires).
 
 
 
  So in the case of Weird Al's Michael Jackson parodies, he would be 
  protected under law if MJ had decided to sue.
 
 
 
 Not entirely.  The use of the musical tune is not a parody, only the
 
 lyrics.  But if, like you say, he did get permission, then he is safe.
 
 
 
 But you bring up a point of *criticism* which is distinct from re-use.
 
 -- 
 
 MarkJ
 
 Tacoma, Washington


In this case, the tune and the lyrics really aren't separable.  What's being 
parodied is the entire work, including the music video, down to the costumes, 
the dance moves, and the guitar solo.  It's the work, taken as a whole.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Future standard GUI library

2013-05-22 Thread llanitedave
On Wednesday, May 22, 2013 7:24:15 AM UTC-7, Chris Angelico wrote:
 On Wed, May 22, 2013 at 11:42 PM, Wolfgang Keller felip...@gmx.net wrote:
 
  What other open-source cross-platform programming language choices do yo
 
  have.
 
 
 
  Java? For GUIs? Excuse me while I vomit.
 
 
 
  C++? As a language for human beings? Oops, I have to throw up again.
 
 
 
 I personally like using Pike and GTK, so if I were to try a
 
 cross-platform Python GUI project, I'd probably give PyGTK a shot. But
 
 there's another option that is available to every platform and
 
 (practially) every high level language: the web browser. Make your app
 
 serve HTTP and do up your UI in HTML5/CSS3 - your facilities are
 
 pretty extensive. Plus you get networking support for free! Obviously
 
 this option isn't for everyone, but don't discount it out of hand.
 
 
 
 ChrisA

I've been thinking about that myself for some future app ideas.  If you have a 
stand-alone app working from your web browser, don't you need an embedded web 
server to utilize the file system?  Is a system like Django for an app 
overkill?  Or is its embedded development server underkill for a single-user 
browser-based application?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Future standard GUI library

2013-05-18 Thread llanitedave
I'm curious about how commonly tkinter is actually used among Python app 
developers as compared to wx, Pyside, or PyQT.  I get the impression that more 
distributed apps are built with wxPython, at least, than tkinter.  My 
impression is far from actual knowledge, of course.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fwd: Fwd: Python for philosophers

2013-05-16 Thread llanitedave
On Thursday, May 16, 2013 5:28:11 AM UTC-7, Citizen Kant wrote:
 On May 16, 5:55 am, Citizen Kant citizenk...@gmail.com wrote:
 
If someone's interested on thinking outside the box with me for the sake of 
helping me, that would be great and highly appreciated. 

Sorry, but you're asking for more than just thinking outside the box.  What you 
want would seem to require thinking from within the bottle.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python for philosophers

2013-05-13 Thread llanitedave
On Monday, May 13, 2013 4:32:43 PM UTC-7, Citizen Kant wrote:

An entity named Python must be 
 somehow as a serpent. 


Moe like a dead parrot, actually.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python for philosophers

2013-05-12 Thread llanitedave
On Sunday, May 12, 2013 7:51:28 AM UTC-7, Chris Angelico wrote:
 On Mon, May 13, 2013 at 12:17 AM, Citizen Kant citizenk...@gmail.com wrote:
 
  Maybe It'd be good if I explain myself a bit more. What I'm trying here is
 
  to grasp Python from the game's abstraction point of view, as if it were,
 
  for example, chess.
 
 
 
 Maybe you're going for something a little too complicated. Let's boil
 
 the question down to a much MUCH simpler subset: expression
 
 evaluation. And let's take Python itself right out of the picture, and
 
 work with only the following elements:
 
 
 
 * Parentheses ( )
 
 * Multiplication and division * /
 
 * Addition and subtraction + -
 
 * Decimal integer constants 0123456789
 
 
 
 This will give the basics of algebraic evaluation. It's quite fun to
 
 build a simple little expression evaluator that just does these few
 
 operations, and it's surprisingly useful (embed it within a command
 
 interpreter, for instance). Some time ago I wrote one into a Windows
 
 app (written in C++), and when I pulled it out just now and made it a
 
 stand-alone tool, the whole thing was only ~60 lines of code. Nice and
 
 easy to work with.
 
 
 
 So, let's take an expression and see what it really means.
 
 
 
 2*(3+4)+6
 
 
 
 One way to interpret this is with a stack. Here's how Python evaluates
 
 that expression:
 
 
 
  def foo():
 
   return 2*(three+4)+6
 
 
 
  dis.dis(foo)
 
   2   0 LOAD_CONST   1 (2)
 
   3 LOAD_GLOBAL  0 (three)
 
   6 LOAD_CONST   2 (4)
 
   9 BINARY_ADD
 
  10 BINARY_MULTIPLY
 
  11 LOAD_CONST   3 (6)
 
  14 BINARY_ADD
 
  15 RETURN_VALUE
 
 
 
 (I had to replace one of the constants with a global, to foil the optimizer)
 
 
 
 The LOAD statements add to an internal stack, the BINARY operations
 
 pop two operands and push the result. This is more-or-less the same
 
 technique as I used in my evaluator, except that instead of compiling
 
 it to code, I just march straight through, left to right, and so I had
 
 to maintain two stacks (one of operands, one of operators).
 
 
 
 Is this what you had in mind when you wanted to grasp Python's
 
 internals? Because it's pretty easy to explore, thanks to the dis
 
 module. There's a huge amount that can be learned about the
 
 interpreter, its optimizers, and so on, just by disassembling
 
 functions. Alternatively, if you're thinking on a more abstract level,
 
 leave Python aside altogether and pick up a book on language design.
 
 Also can be awesome fun, but completely different.
 
 
 
 ChrisA

No, that won't help.  You're trying to give him knowledge; he wants 
understanding.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why do Perl programmers make more money than Python programmers

2013-05-06 Thread llanitedave
On Sunday, May 5, 2013 12:10:47 PM UTC-7, Steven D'Aprano wrote:

 
 
 Also, Perl programmers are an unprincipled, devious bunch, always looking 
 
 for an opportunity to blackmail their employers into paying them extra. 
 
 Python programmers are a decent, law-abiding people with a strong moral 
 
 code who would never stoop to the sort of things that Perl coders are 
 
 proud of doing.
 

 
 -- 
 
 Steven

And of course, the Python Programmer's moral code is only 80 characters wide.

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


Re: Comparison Style

2013-04-25 Thread llanitedave
On Wednesday, April 24, 2013 10:57:49 PM UTC-7, Chris Angelico wrote:
 On Thu, Apr 25, 2013 at 3:49 PM, llanitedave llanited...@veawb.coop wrote:
 
  Given that
 
 
 
  s = some static value
 
  i = a value incremented during a loop
 
 
 
  I'm used to comparing them as
 
 
 
  if i == s:
 
  # some code
 
 
 
  But for some unknown reason I did a switch
 
 
 
  if s == i:
 
  # same code
 
 
 
  It didn't seem to make any difference at first glance, so I just got to 
  wondering --
 
 
 
 It won't make any difference in any sort of sane code. If there's any
 
 situation in which == is not reflexive, something seriously nasty is
 
 going on.
 
 
 
  Is there a standard for comparison order?  Is there any kind of performance 
  difference?  Is there even a tradition for one or the other?  Are there any 
  gotchas?
 
 
 
 It's conventional to compare variables to constants, not constants to
 
 variables (even in C where there's the possibility of mucking up the
 
 operator, most people still compare variables to constants). I'd
 
 normally use i == s there, treating s as a constant for the purpose
 
 of the loop. Unless you're deliberately being poetical, language such
 
 as Three is the number thou shalt count is distinctly abnormal, so
 
 saying if (5 == i) is equally awkward. It's nothing major; mostly
 
 it's like the algebraic convention of putting the more-known elements
 
 earlier in a term (eg 2πix - 2 is known, 3.14159 is mostly known,
 
 i is imaginary but at least it's constant, and x is unknown).
 
 



Thanks, Chris.  That's kind of along the lines of what I was thinking.  
Visually, the code just looked wrong, and I figure if for no other reasons than 
readability it's preferable in the traditional way.

It's nice to know, though, that the next time dyslexia strikes it's not 
necessarily a horrible thing.

 
  Do I need to get a hobby?
 
 
 
 I thought programming WAS a hobby?
 

I meant a safer, easier, and more mainstream hobby, like base jumping or 
motorcycle aerobatics or something.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Comparison Style

2013-04-25 Thread llanitedave
On Thursday, April 25, 2013 11:31:04 AM UTC-7, Steve Simmons wrote:
 Chris Angelico ros...@gmail.com wrote:
 
 
 
 With the sort of thinking you're demonstrating here, you
 
 should consider a job working with Spike Milligna (the well known typing 
 error).
 
 
 
 Errr ,  I think you'll find that he's joined the choir invisibule. Mind you,  
 he did say he was ill! 
 
 
 
 Sent from a Galaxy far far away


Did you ever hear him sing?  He's better off in the choir inaudible.

As am I...
-- 
http://mail.python.org/mailman/listinfo/python-list


Comparison Style

2013-04-24 Thread llanitedave
Given that 

s = some static value
i = a value incremented during a loop

I'm used to comparing them as

if i == s:
# some code

But for some unknown reason I did a switch

if s == i:
# same code

It didn't seem to make any difference at first glance, so I just got to 
wondering --

Is there a standard for comparison order?  Is there any kind of performance 
difference?  Is there even a tradition for one or the other?  Are there any 
gotchas?

Do I need to get a hobby?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: In defence of 80-char lines

2013-04-04 Thread llanitedave
On Thursday, April 4, 2013 4:52:38 AM UTC-7, Roy Smith wrote:
 In article c338b844-e9ce-46a7-9daf-203743723...@googlegroups.com,
 
  llanitedave llanited...@veawb.coop wrote:
 
  
 
  I would hate to have to break up this line, for instance:
 
  
 
  self.mainLabel.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName 
  = 
 
  FreeSans))
 
 
 
 I would write that as some variation on
 
 
 
 self.mainLabel.SetFont(wx.Font(12,
 
wx.DEFAULT,
 
wx.NORMAL,
 
wx.BOLD, 
 
faceName=FreeSans))
 
 
 
 This lets the reader see at a glance that all the arguments go with 
 
 wx.Font(), not with SetFont(), without having to visually parse and 
 
 match parenthesis levels.
 
 
 
 Actually, I would probably break it up further as:
 
 
 
 my_font = wx.Font(12,
 
   wx.DEFAULT,
 
   wx.NORMAL,
 
   wx.BOLD,
 
   faceName=FreeSans)
 
 self.mainLabel.SetFont(my_font)
 
 
 
 The last thing on my mind when deciding how to format this is whether I 
 
 would be able to punch it onto a single card.

To each their own, definitely.  For myself, I don't see the utility in adding a 
bunch of what appears to be superfluous horizontal white space at the expense 
of extra lines to scroll down.  I like to limit my scrolling needs in *both* 
directions.
(Although I do tend to be fairly generous with blank lines to break up code 
paragraphs)

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


Re: In defence of 80-char lines

2013-04-03 Thread llanitedave
I also tend to prefer a maximum between 110 and 120 characters.  I find 
continuation lines confusing, and when you use some third-party tools, such as 
wxPython, for example, the boilerplate code leads to some long lines.

I would hate to have to break up this line, for instance:

self.mainLabel.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = 
FreeSans))

Especially if it's already indented a few levels to begin with.

With most of your code in classes, you already got most of it indented two 
levels right off the bat.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PSF News: Guido van Rossum quitting Python to develop new, more difficult to learn, language.

2013-04-01 Thread llanitedave
Another detail about the new language: the Btrees used in Python's persistent 
object data structures have been replaced by...

A SHRUBBERY! 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PSF News: Guido van Rossum quitting Python to develop new, more difficult to learn, language.

2013-04-01 Thread llanitedave
On Monday, April 1, 2013 12:59:04 PM UTC-7, Tim Daneliuk wrote:
 On 04/01/2013 01:32 PM, llanitedave wrote:
 
  Another detail about the new language: the Btrees used in Python's 
  persistent object data structures have been replaced by...
 
 
 
  A SHRUBBERY!
 
 
 
 
 
 I believe you mean A 'oly shrubbery, do you not?
 
 
 
 -- 
 
 ---
 
 Tim Daneliuk

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


Re: How can i create a random array of floats from 0 to 5 in python

2013-03-12 Thread llanitedave
On Tuesday, March 12, 2013 10:47:25 AM UTC-7, Maarten wrote:
 On Tuesday, March 12, 2013 6:11:10 PM UTC+1, Norah Jones wrote:
 
  I want to create a random float array of size 100, with the values in the 
  array ranging from 0 to 5. I have tried random.sample(range(5),100) but 
  that does not work. How can i get what i want to achieve?
 
 
 
 Use numpy
 
 
 
 import numpy as np
 
 np.random.uniform(0, 5, 100)
 
 
 
 # note that the values are from the interval [0, 5)
 
 
 
 Maarten

While numpy would work, I fail to see how encouraging the op to download and 
install a separate library and learn a whole new set of tools would be 
beneficial by default, without knowing the purpose of the need.  This is like 
recommending an RPG to fix a sticky door hinge.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can i create a random array of floats from 0 to 5 in python

2013-03-12 Thread llanitedave
On Tuesday, March 12, 2013 2:59:29 PM UTC-7, Oscar Benjamin wrote:
 On 12 March 2013 20:21, llanitedave llanited...@veawb.coop wrote:
 
  On Tuesday, March 12, 2013 10:47:25 AM UTC-7, Maarten wrote:
 
  On Tuesday, March 12, 2013 6:11:10 PM UTC+1, Norah Jones wrote:
 
 
 
   I want to create a random float array of size 100, with the values in 
   the array ranging from 0 to 5. I have tried random.sample(range(5),100) 
   but that does not work. How can i get what i want to achieve?
 
 
 
  Use numpy
 
 [SNIP]
 
 
 
  While numpy would work, I fail to see how encouraging the op to download 
  and install a separate library and learn a whole new set of tools would be 
  beneficial by default, without knowing the purpose of the need.  This is 
  like recommending an RPG to fix a sticky door hinge.
 
 
 
 This suggestion comes after others that show how to use the stdlib's
 
 random module. I don't think it's unreasonable to recommend numpy for
 
 this. If you want to create *arrays* of random numbers then why not
 
 use a library that provides an API specifically for that? You can test
 
 yourself to see that numpy is 10x faster for large arrays:
 
 
 
 Python 2.7 on Linux:
 
 $ python -m timeit -s 'import random' -- '[random.uniform(0, 5) for x
 
 in range(1000)]'
 
 1000 loops, best of 3: 729 usec per loop
 
 $ python -m timeit -s 'import random' -- '[random.random() * 5 for x
 
 in range(1000)]'
 
 1000 loops, best of 3: 296 usec per loop
 
 $ python -m timeit -s 'import numpy' -- 'numpy.random.uniform(0, 5, 1000)'
 
 1 loops, best of 3: 32.2 usec per loop
 
 
 
 I would use numpy for this mainly because if I'm creating arrays of
 
 random numbers I probably want to use them in ways that are easier
 
 with numpy arrays. There's also a chance the OP might benefit more
 
 generally from using numpy depending on what they're working on.
 
 
 
 
 
 Oscar

I don't think numpy is unreasonable for you or me.  I just started learning it 
recently, and I'm pretty jazzed about its possibilities.  I obtained an app for 
work that uses it, and now it's up to me to maintain it, so learning it is a 
good idea for me regardless.  Now I'm starting to fantasize about other things 
I could do with it.

But the OP appears like a pretty basic beginner, and I really think that for 
such a entry-level knowledge scale, we should stick to the standard library 
until they're ready to take on more sophisticated tasks.  Premature 
Optimization is the analogy that comes to mind.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Do you feel bad because of the Python docs?

2013-02-27 Thread llanitedave
I just completed my first Python app for public consumption, and I was learning 
as I was coding.  I've played on the outskirts of the language for a few years, 
but until this project I'd never really immersed myself in it.  I ended up 
being confused a lot.  So, I DO have some relevant thoughts:

1.  The Python official documentation is not great, but it's not bad either.  
Some of it seems outdated, some of it is a bit hard to parse, some of it 
assumes more background knowledge on the part of the reader than is justified.

Somebody mentioned the Django documentation.  I've looked at it a bit, and it's 
*very* nice.  I do think that the PSF could take some clues from its style and 
approach. 
But those are pretty minor gripes.  I've learned a lot from referencing the 
documentation, and its still my first go-to source when I'm stuck.

2.  The Python Community:  Jopie91 wrote I will no doubt piss off quite a few 
people with this statement, but the community around Python is one of the most 
hostile and unhelpful communities around any programming-related topic that I 
have ever seen – and with that I am not just referring to #python on Freenode, 
but to communities with a dense population of Python developers in general. 
This point actually consists of several separate attitudes and issues.

There, I'd have to say he's very, very wrong.  When I have on occasion asked 
questions on this group I've never been flamed, and I've always had people give 
me thoughtful answers that obviously took some effort to compose.

My most recent question here concerned something that was thought to be a bug, 
but was due more to my own unfamiliarity with the material combined with what 
I'd suggest really was some ambiguity on the part of the documentation.  
Nevertheless, even with the misunderstandings, my questions were treated 
respectfully, and that's all I ask.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Project Based python tutorials

2013-02-27 Thread llanitedave
On Wednesday, February 27, 2013 12:31:11 AM UTC-8, Alvin Ghouas wrote:
 Hi everyone!
 
 
 
 First of all: Im new to this group and i dont know if there are any rules 
 or jargon around her. If so; pleas fill me in.
 
 
 
 So, I desided to start learning programming a few months ago and by now i 
 feel pretty confident about the basics of the python language, and 
 programming in general. 
 
 Variables,loops, conditionals, data structures, methods and even some object 
 oriented programming, are all familiar consepts.
 
 
 
 As i want to become a better programmer, i figured the next step would be to 
 start working on some bigger and more complex projects.Yet despite my 
 numerouse web searchs for project based tutorials,i cant seem to find any 
 good ones.   
 
 I have no trouble with understanding the concepts of programming, however I 
 find it quite difficult to take it to the next level.
 
 
 
 So, is there anyone out there willing to share some experience? I would be 
 really grateful!
 
 
 
 Greetings from Norway!

There's no teacher like trial and error.  My main advice, as one who's not far 
beyond raw beginner myself, is to build your complex project in small 
increments.  Think of the functionality you want to implement, and break it up 
into individual modules that focus on one aspect of it.

Functions can be simple and short, and always remember that the output of one 
function can be passed as input into another.

Global variables should be minimized as much as possible, but there are most 
likely going to be a few that you'll need anyway.  So don't completely prohibit 
them from your thinking.  Make sure you label them clearly.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Project Based python tutorials

2013-02-27 Thread llanitedave
On Wednesday, February 27, 2013 4:40:41 PM UTC-8, Rick Johnson wrote:
 
 Before you decide to start participating in outside projects may we have a 
 list of some of the software you've written for yourself? (With all due 
 respect) I very seriously doubt that someone with only a few months of 
 programming experience is ready for the real world.


Nobody is ready for the real world when they start working on their first 
real-world application.  If they develop their skills while developing their 
program, then with luck they'll be ready for the real world when they finish.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Do you feel bad because of the Python docs?

2013-02-27 Thread llanitedave
On Wednesday, February 27, 2013 7:43:58 PM UTC-8, Rick Johnson wrote:
 
 Python is a great language, but we need diverse ideas to keep the cogs of 
 evolution turning. Guido can start the ball rolling 10 minutes from now, all 
 it will take is for him to make a public announcement...

Geez, dude, let the man get some sleep!
-- 
http://mail.python.org/mailman/listinfo/python-list


webbrowser.open(./documentation/help.html)-- No Go in Windows

2013-02-24 Thread llanitedave
I created an html help page for my Python 2.7.3 application and put it in a 
documentation folder.  I used webbrowser.open() to fetch the page.

On linux -- KDE specifically, the command opens the local file on my default 
browser with no issues.  However, on Windows 7, it opens Internet Explorer, 
which doesn't even search the local folder, but goes straight to the web and 
does a Google search, returning nothing but useless noise.

My default browser on Windows is Chrome, so my intention is getting undermined 
right from the start.

How do I get a local html file to open properly from Python in Windows?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: webbrowser.open(./documentation/help.html)-- No Go in Windows

2013-02-24 Thread llanitedave
On Sunday, February 24, 2013 1:35:31 AM UTC-8, Chris Rebert wrote:
 On Feb 24, 2013 1:21 AM, llanitedave llani...@veawb.coop wrote:
 
 
 
  I created an html help page for my Python 2.7.3 application and put it in a 
  documentation folder.  I used webbrowser.open() to fetch the page.
 
 
 
  On linux -- KDE specifically, the command opens the local file on my 
  default browser with no issues.  However, on Windows 7, it opens Internet 
  Explorer, which doesn't even search the local folder, but goes straight to 
  the web and does a Google search, returning nothing but useless noise.
 
 
 
 
  My default browser on Windows is Chrome, so my intention is getting 
  undermined right from the start.
 
 
 
  How do I get a local html file to open properly from Python in Windows?
 
 Sounds like this might be your problem:
 
 http://bugs.python.org/issue8936
 
 The fix would seem to be ensuring that the URL you pass includes the scheme 
 (in your case, file:).
 
 Cheers,
 
 Chris

Holy Toledo!  That's a two-year-old bug spanning two versions of the language!

BTW, Chris, the snippet I showed in the title essentially WAS the exact code.  
It's a method with that single line called from a wxPython Help menu.  I can't 
really put an absolute pathname into the argument, because the application is 
going to be distributed to a variety of computers at my workplace, and there's 
no assurance that it will go into (or remain in)a particular folder.

I was trying to avoid using the wx.html.HtmlWindow feature of wxPython, because 
it doesn't handle CSS and styles.  My help page is the portal to a multi-page 
users guide with a style sheet to render all the content consistently.

Plus, I couldn't get the wx.html.HtmlWindow to open relative paths either -- it 
gave me URL Malformed messages even in KDE, when webbrowser.open(filepath) 
was working for the exact same path.  But that's something to take up on the 
wxPython list, I guess.

This to me illustrates the downside of the Python philosophy of There should 
be only one obvious way to do things.  If that one obvious way has a fatal 
bug, you're pretty much SOL.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: webbrowser.open(./documentation/help.html)-- No Go in Windows

2013-02-24 Thread llanitedave
On Sunday, February 24, 2013 12:48:40 PM UTC-8, Chris Rebert wrote:
 On Sun, Feb 24, 2013 at 12:28 PM, llanitedave llanited...@veawb.coop wrote:
 
  On Sunday, February 24, 2013 1:35:31 AM UTC-8, Chris Rebert wrote:
 
  On Feb 24, 2013 1:21 AM, llanitedave llani...@veawb.coop wrote:
 
   I created an html help page for my Python 2.7.3 application and put it 
   in a documentation folder.  I used webbrowser.open() to fetch the page.
 
   On linux -- KDE specifically, the command opens the local file on my 
   default browser with no issues.  However, on Windows 7, it opens 
   Internet Explorer, which doesn't even search the local folder, but goes 
   straight to the web and does a Google search, returning nothing but 
   useless noise.
 
   My default browser on Windows is Chrome, so my intention is getting 
   undermined right from the start.
 
   How do I get a local html file to open properly from Python in Windows?
 
 
 
  Sounds like this might be your problem:
 
  http://bugs.python.org/issue8936
 
 
 
  The fix would seem to be ensuring that the URL you pass includes the 
  scheme (in your case, file:).
 
 
 
  Holy Toledo!  That's a two-year-old bug spanning two versions of the 
  language!
 
 
 
  BTW, Chris, the snippet I showed in the title essentially WAS the exact 
  code.
 
 
 
 Sorry, my bad. This is why I dislike messages that put critical info
 
 *only* in the subject line; I tend not to reread the subject line once
 
 I've opened the message.
 

Nah, my bad.  I didn't realize that the title was the only place I'd put the 
actual command.  I don't like it when other people do that either.

 
 
   It's a method with that single line called from a wxPython Help menu.  I 
  can't really put an absolute pathname into the argument, because the 
  application is going to be distributed to a variety of computers at my 
  workplace, and there's no assurance that it will go into (or remain in)a 
  particular folder.
 
 
 
 As Demian demonstrated, you can simply compute the absolute path from
 
 the relative path at runtime; although I would probably toss an
 
 abspath() call in for good measure
 
 (http://docs.python.org/2/library/os.path.html#os.path.abspath ).
 
 

OK, I'm going to have to study that one a bit.  It looks like a new concept for 
my feeble brain.

 
  This to me illustrates the downside of the Python philosophy of There 
  should be only one obvious way to do things.  If that one obvious way has 
  a fatal bug, you're pretty much SOL.
 
 
 
 On the other hand, you don't have to investigate which of N APIs is
 
 the fixed/correct one (Which PHP MySQL function is safe from SQL
 
 injection again?), and you only have wait for 1 fix instead of N. But
 
 yes, some of Python's included batteries are due for some recharging.
 
 
 
 Cheers,
 
 Chris

You're right.  It's one thing to have a persistent bug, it's another thing to 
offer the function in the documentation as if the bug doesn't exist.

The bug report from October 2010 indicated that someone was working on a fix at 
that time.  The fact that it's still not fixed implies that it might be 
something that's really hard to pin down.  In a case like that, it's probably 
better to simply withdraw the feature, or tag it as Non-windows only
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: webbrowser.open(./documentation/help.html)-- No Go in Windows

2013-02-24 Thread llanitedave
On Sunday, February 24, 2013 12:50:02 PM UTC-8, Mark Lawrence wrote:
 On 24/02/2013 20:28, llanitedave wrote:
 
  On Sunday, February 24, 2013 1:35:31 AM UTC-8, Chris Rebert wrote:
 
  On Feb 24, 2013 1:21 AM, llanitedave llani...@veawb.coop wrote:
 
 
 
 
 
 
 
  I created an html help page for my Python 2.7.3 application and put it in 
  a documentation folder.  I used webbrowser.open() to fetch the page.
 
 
 
 
 
 
 
  On linux -- KDE specifically, the command opens the local file on my 
  default browser with no issues.  However, on Windows 7, it opens Internet 
  Explorer, which doesn't even search the local folder, but goes straight 
  to the web and does a Google search, returning nothing but useless noise.
 
 
 
 
 
 
 
 
 
  My default browser on Windows is Chrome, so my intention is getting 
  undermined right from the start.
 
 
 
 
 
 
 
  How do I get a local html file to open properly from Python in Windows?
 
 
 
  Sounds like this might be your problem:
 
 
 
  http://bugs.python.org/issue8936
 
 
 
  The fix would seem to be ensuring that the URL you pass includes the 
  scheme (in your case, file:).
 
 
 
  Cheers,
 
 
 
  Chris
 
 
 
  Holy Toledo!  That's a two-year-old bug spanning two versions of the 
  language!
 
 
 
 Only two years is nothing.  Pay your money, take your choice :)
 
 
 
  This to me illustrates the downside of the Python philosophy of There 
  should be only one obvious way to do things.  If that one obvious way has 
  a fatal bug, you're pretty much SOL.
 
 
 
 Misquoted as always.  I guess that some day someone will quote it correctly.
 
 
 
 -- 
 
 Cheers.
 
 
 
 Mark Lawrence

I think the correct quote is You pays your money, and you takes your chances. 
 ;)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: webbrowser.open(./documentation/help.html)-- No Go in Windows

2013-02-24 Thread llanitedave
On Sunday, February 24, 2013 2:15:10 PM UTC-8, MRAB wrote:
 On 2013-02-24 20:28, llanitedave wrote:
 
  On Sunday, February 24, 2013 1:35:31 AM UTC-8, Chris Rebert wrote:
 
 [snip]
 
  Sounds like this might be your problem:
 
 
 
  http://bugs.python.org/issue8936
 
 
 
  The fix would seem to be ensuring that the URL you pass includes
 
  the scheme (in your case, file:).
 
 
 
  Holy Toledo!  That's a two-year-old bug spanning two versions of the
 
  language!
 
 
 
  BTW, Chris, the snippet I showed in the title essentially WAS the
 
  exact code.  It's a method with that single line called from a
 
  wxPython Help menu.  I can't really put an absolute pathname into the
 
  argument, because the application is going to be distributed to a
 
  variety of computers at my workplace, and there's no assurance that
 
  it will go into (or remain in)a particular folder.
 
 
 
  I was trying to avoid using the wx.html.HtmlWindow feature of
 
  wxPython, because it doesn't handle CSS and styles.  My help page is
 
  the portal to a multi-page users guide with a style sheet to render
 
  all the content consistently.
 
 
 
  Plus, I couldn't get the wx.html.HtmlWindow to open relative paths
 
  either -- it gave me URL Malformed messages even in KDE, when
 
  webbrowser.open(filepath) was working for the exact same path.  But
 
  that's something to take up on the wxPython list, I guess.
 
 
 
  This to me illustrates the downside of the Python philosophy of
 
  There should be only one obvious way to do things.  If that one
 
  obvious way has a fatal bug, you're pretty much SOL.
 
 
 
 I've had a brief look at webbrowser.py. It's looking for the browsers in 
 
 the paths listed in the PATH environment variable.
 
 
 
 On my PC at least, the paths to the other browsers, such as C:\Program
 
 Files\Mozilla Firefox for Firefox, aren't listed there, hence the only
 
 one it can find is Internet Explorer.

Well, it's still very odd, because when I use wxPython's wx.html.HtmlWindow to 
click a web link, it DOES use the default browser, which is Chrome on my PC.  
It's just using the webbrowser.open() function that goes to IE.  Until then, 
I'd been suspecting that wx.html.HtmlWindow was using webbrowser.open() under 
the hood.  I guess not.

But wx.html.HtmlWindow doesn't work on relative paths, it seems (in neither 
Linux NOR Windows), so I'm not able to find a substitute as of yet.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: webbrowser.open(./documentation/help.html)-- No Go in Windows

2013-02-24 Thread llanitedave
On Sunday, February 24, 2013 3:51:09 PM UTC-8, Demian Brecht wrote:
 For the record, I completely misread and misunderstood the question. I
 
 should stop posting that late at night :P
 
 
 
 On Sun, Feb 24, 2013 at 1:25 AM, Demian Brecht demianbre...@gmail.com wrote:
 
  Rather than using a relative path, try using
 
  webbrowser.open('{}/documentation/help.html'.format(os.path.dirname(__file__))).
 
 
 
  On Sun, Feb 24, 2013 at 1:17 AM, llanitedave llanited...@veawb.coop wrote:
 
  I created an html help page for my Python 2.7.3 application and put it in 
  a documentation folder.  I used webbrowser.open() to fetch the page.
 
 
 
  On linux -- KDE specifically, the command opens the local file on my 
  default browser with no issues.  However, on Windows 7, it opens Internet 
  Explorer, which doesn't even search the local folder, but goes straight to 
  the web and does a Google search, returning nothing but useless noise.
 
 
 
  My default browser on Windows is Chrome, so my intention is getting 
  undermined right from the start.
 
 
 
  How do I get a local html file to open properly from Python in Windows?
 
  --
 
  http://mail.python.org/mailman/listinfo/python-list
 
 
 
 
 
 
 
  --
 
  Demian Brecht
 
  http://demianbrecht.github.com
 
 
 
 
 
 
 
 --
 
 Demian Brecht
 
 http://demianbrecht.github.com

Well, between you and Chris, I think you've got me on the right track.  If 
things keep going like they are now, I should have it back under control in an 
hour or two.

So, thanks in advance for all of you!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: webbrowser.open(./documentation/help.html)-- No Go in Windows

2013-02-24 Thread llanitedave
Well, we can mark this one as solved.

Simple enough, actually -- thanks to Chris and Demian for leading me to water.

The following code works on both Linux and Windows 7:

def OnDocs(self, event):
Opens the User's Guide in the default web browser
fullpath = os.path.abspath('documentation/HTMLDocs/index.html')
url_link = file:/// + fullpath
webbrowser.open(url_link)

This allows both platforms to have their own idiosyncratic path structures 
without having to create separate code for each.  It even chooses the correct 
browser!

I learned some more about Python today, too. I'd never explored the 'os.' 
library before, and now I see things a little more clearly.

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


Re: webbrowser.open(./documentation/help.html)-- No Go in Windows

2013-02-24 Thread llanitedave
On Sunday, February 24, 2013 9:35:17 PM UTC-8, Terry Reedy wrote:
 On 2/24/2013 4:35 AM, Chris Rebert wrote:
 
 
 
  Sounds like this might be your problem:
 
  http://bugs.python.org/issue8936
 
 
 
 I just closed that issue an invalid. Here is most of what I wrote.
 
 '''
 
 After reading the doc and the code, I am convinced that current behavior 
 
 is close to the implied wanted behavior, and that it is not a bug.
 
 
 
 The doc says
 
   webbrowser.open(url, new=0, autoraise=True)
 
  Display url using the default browser.
 
 
 
 What does 'default browswer' mean? Near the top, the doc says If the 
 
 environment variable BROWSER exists, it is interpreted to override the 
 
 platform default list of browsers,. So the 'default browser' is 
 
 actually the 'default browser list'. What open() does is to try each in 
 
 turn and stop when one says it succeeded. So the doc should say 'using 
 
 the first default browser that claims to succeed.'
 
 
 
 What does 'default browser list' mean? It depends on the platform *and* 
 
 the software loaded on the particular machine when webbrowser is first 
 
 imported in a particular instance of the interpreter. The 'platform' 
 
 part is in the quote above, the rest is not. I will open a separate doc 
 
 issue.
 
 
 
 On Windows, the list starts with 'default Windows browser', which calls 
 
 os.startfile(), which, I believe, does call the user default browser. 
 
 Next is Internet Explorer -- if available at that time on the particular 
 
 machine! If the user-default browser rejects the url, then IE is tried.
 
 
 
 On my win7 machine today, I have Firefox the default and IE available. 
 
 Firefox rejects 127.0.0.1:8080 with an 'Unable to connect' error box. IE 
 
 'accepts' it in the sense that it displays an information starting 'The 
 
 webpage cannot be displayed'.
 
 '''
 
 
 
 For *this* issue, I strongly suspect that Chrome is rejecting the 
 
 invalid URL and telling Python so. So IE is tried next (but not first).
 
 
 
  The fix would seem to be ensuring that the URL you pass includes the
 
  scheme (in your case, file:).
 
 
 
 so that Chrome does not return an error code, in which case IE should 
 
 *not* be tried as a backup.
 
 
 
 -- 
 
 Terry Jan Reedy


Terry, after what I've learned today I'm tempted to agree that it's not 
necessarily a bug, and that maybe all that's needed is a bit more clarity in 
the documentation.

On the other hand, it *is* a bit frustrating that Linux recognizes an 
html-style relative path, while Windows insists on the entire absolute path.  
Maybe we can call it a Windows bug, but a workaround would be nice to have.

However, combined with os.path.abspath(), it's not a huge issue -- once we 
understand the approach. 

I certainly appreciate your taking the time to make an analysis of it, and 
someday I hope to have the time and skills to help out in some small way.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python trademark under attack -- the PSF needs your help

2013-02-15 Thread llanitedave
The news is featured as an article on Groklaw now.

Those folks are on it...

http://www.groklaw.net/article.php?story=20130215074839583
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The best, friendly and easy use Python Editor.

2013-01-24 Thread llanitedave
On Thursday, January 24, 2013 7:54:55 AM UTC-8, rusi wrote:

 
 [I personally use emacs. It would be sadistic to make that into a
 
 recommendation]

Lol!  That's just too true.  It's also true for Eclipse, which I use very 
comfortably on Windows 7, but has proven to be a nightmare to set up on Ubuntu.

On Linux, I've tried several, but always keep coming back to Geany.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sqlite3 puzzle

2013-01-15 Thread llanitedave
On Tuesday, January 15, 2013 6:36:51 AM UTC-8, Rob Day wrote:
 On 15 January 2013 07:09, llanitedave llanited...@veawb.coop wrote:
 
 
 
  So I put the following test code in my initialization method:
 
 
 
  # open database file
 
  self.geologger_db = sqlite3.connect('geologger.mgc')
 
  self.db_cursor = self.geologger_db.cursor()
 
  self.foreign_key_status = self.db_cursor.execute(PRAGMA foreign_keys = 
  ON)
 
  self.foreign_key_status = self.foreign_key_status.fetchone()
 
 
 
  print self.foreign_key_status
 
 
 
  I ran this several times while I was arranging the downstream queries, and 
  each time it returned '(1,)', which means foreign keys is enabled.
 
 
 
  But I was using a variable named 'cmd1' as a placeholder until I changed 
  the name to
 
  the more descriptive 'self.foreign_key_status'.  Since I made the name 
  change, however,
 
  the code only returns 'None'.  Reverting to the previous variable name has 
  no effect.
 
 
 
 Hmm - your code doesn't quite match up with the docs at
 
 http://docs.python.org/2/library/sqlite3.html. That seems to suggest
 
 that you should call fetchone() on the cursor, not on the result of
 
 execute().
 
 
 
 Does the following work?
 
 
 
 # open database file
 
 self.geologger_db = sqlite3.connect('geologger.mgc')
 
 self.db_cursor = self.geologger_db.cursor()
 
 self.db_cursor.execute(PRAGMA foreign_keys = ON)
 
 print self.db_cursor.fetchone()
 
 
 
 
 
 --
 
 Robert K. Day
 
 robert@merton.oxon.org

Thanks for the suggestion, Rob, but that didn't make any difference.  I've 
never had an issue with putting the execute object into a variable and calling 
fetch on that variable.  

I can accept reality if it turns out that foreign keys simply isn't enabled on 
the Python distribution of sqlite, although I don't know why that should be the 
case.  I'm just curious as to why it worked at first and then stopped working.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sqlite3 puzzle

2013-01-15 Thread llanitedave
On Tuesday, January 15, 2013 9:13:13 AM UTC-8, Rob Day wrote:
 On 15 January 2013 15:51, llanitedave llanited...@veawb.coop wrote:
 
  Thanks for the suggestion, Rob, but that didn't make any difference.  I've 
  never had an issue with putting the execute object into a variable and 
  calling fetch on that variable.
 
 
 
  I can accept reality if it turns out that foreign keys simply isn't enabled 
  on the Python distribution of sqlite, although I don't know why that should 
  be the case.  I'm just curious as to why it worked at first and then 
  stopped working.
 
 
 
 Well - you might be able to accept that, but I'm not sure I can! If it
 
 was working before, it must be compiled in, and so it must be possible
 
 to make it work again.
 
 
 
 http://www.sqlite.org/foreignkeys.html#fk_enable seems to suggest that
 
 PRAGMA foreign_keys = ON never returns anything, and it's only
 
 PRAGMA foreign_keys which returns 0, 1 or None (when unsupported).
 
 With that in mind, does the following code work?
 
 
 
 # open database file
 
 
 
 self.geologger_db = sqlite3.connect('geologger.mgc')
 
 self.db_cursor = self.geologger_db.cursor()
 
 self.db_cursor.execute(PRAGMA foreign_keys = ON)
 
 self.db_cursor.execute(PRAGMA foreign_keys)
 
 print self.db_cursor.fetchone()

http://www.sqlite.org/foreignkeys.html#fk_enable seems to suggest that PRAGMA 
foreign_keys = ON never returns anything, and it's only PRAGMA foreign_keys 
which returns 0, 1 or None (when unsupported).

That was it, exactly, Rob.  I don't know where I got the idea that I was 
getting  a '1' from the 'ON' command, although I was sure that I'd seen it.  
But once I just called foreign_key it returned just fine.

Ummm...  Obviously I was up fiddling around too late.  Yeah, that's it.


Thanks!  It's solved now.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sqlite3 puzzle

2013-01-15 Thread llanitedave
Yabut I'm talking about changes I'd made 30 seconds before to code I'd written 
5 minutes before.  My short-term memory is nothing to write home about, even if 
I could remember my mailing address!


On Tuesday, January 15, 2013 2:27:28 PM UTC-8, Rob Day wrote:
 Glad I could help!
 
 
 
 evangelism
 
 Using a local source control system like git, bzr or hg is really
 
 useful in situations like these - it's far, far easier to debug issues
 
 of the form I made changes and now it's broken when you can do `git
 
 diff yesterday's-version today's-version` and see exactly what the
 
 changes were.
 
 /evangelism
 
 
 
 On 15 January 2013 20:29, llanitedave llanited...@veawb.coop wrote:
 
  On Tuesday, January 15, 2013 9:13:13 AM UTC-8, Rob Day wrote:
 
  On 15 January 2013 15:51, llanitedave llanited...@veawb.coop wrote:
 
 
 
   Thanks for the suggestion, Rob, but that didn't make any difference.  
   I've never had an issue with putting the execute object into a variable 
   and calling fetch on that variable.
 
 
 
  
 
 
 
   I can accept reality if it turns out that foreign keys simply isn't 
   enabled on the Python distribution of sqlite, although I don't know why 
   that should be the case.  I'm just curious as to why it worked at first 
   and then stopped working.
 
 
 
 
 
 
 
  Well - you might be able to accept that, but I'm not sure I can! If it
 
 
 
  was working before, it must be compiled in, and so it must be possible
 
 
 
  to make it work again.
 
 
 
 
 
 
 
  http://www.sqlite.org/foreignkeys.html#fk_enable seems to suggest that
 
 
 
  PRAGMA foreign_keys = ON never returns anything, and it's only
 
 
 
  PRAGMA foreign_keys which returns 0, 1 or None (when unsupported).
 
 
 
  With that in mind, does the following code work?
 
 
 
 
 
 
 
  # open database file
 
 
 
 
 
 
 
  self.geologger_db = sqlite3.connect('geologger.mgc')
 
 
 
  self.db_cursor = self.geologger_db.cursor()
 
 
 
  self.db_cursor.execute(PRAGMA foreign_keys = ON)
 
 
 
  self.db_cursor.execute(PRAGMA foreign_keys)
 
 
 
  print self.db_cursor.fetchone()
 
 
 
  http://www.sqlite.org/foreignkeys.html#fk_enable seems to suggest that 
  PRAGMA foreign_keys = ON never returns anything, and it's only PRAGMA 
  foreign_keys which returns 0, 1 or None (when unsupported).
 
 
 
  That was it, exactly, Rob.  I don't know where I got the idea that I was 
  getting  a '1' from the 'ON' command, although I was sure that I'd seen it. 
   But once I just called foreign_key it returned just fine.
 
 
 
  Ummm...  Obviously I was up fiddling around too late.  Yeah, that's it.
 
 
 
 
 
  Thanks!  It's solved now.
 
  --
 
  http://mail.python.org/mailman/listinfo/python-list
 
 
 
 
 
 
 
 -- 
 
 Robert K. Day
 
 robert@merton.oxon.org

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


sqlite3 puzzle

2013-01-14 Thread llanitedave
I'm trying to get an application working in Python 2.7 and wx.Python which 
contains an embedded sqlite3 file.  There are a few tables with foreign keys 
defined.  In looking at the sqlite3 documentation, it says 

Assuming the library is compiled with foreign key constraints enabled, it must 
still be enabled by the application at runtime, using the PRAGMA foreign_keys 
command. 
It goes on to say that foreign keys must be enabled separately for each 
connection, which is fine as my app has only one.

So I put the following test code in my initialization method:

# open database file
self.geologger_db = sqlite3.connect('geologger.mgc')
self.db_cursor = self.geologger_db.cursor()
self.foreign_key_status = self.db_cursor.execute(PRAGMA foreign_keys = ON)
self.foreign_key_status = self.foreign_key_status.fetchone()

print self.foreign_key_status

I ran this several times while I was arranging the downstream queries, and each 
time it returned '(1,)', which means foreign keys is enabled.

But I was using a variable named 'cmd1' as a placeholder until I changed the 
name to the more descriptive 'self.foreign_key_status'.  Since I made the name 
change, however, the code only returns 'None'.  Reverting to the previous 
variable name has no effect.

Yes, I'm closing the connection with self.db_cursor.close() at the end of each 
run.

According to the sqlite3 website, getting no return value, not even a '0', 
means that the version of SQLite you are using does not support foreign keys 
(either because it is older than 3.6.19 or because it was compiled with 
SQLITE_OMIT_FOREIGN_KEY or SQLITE_OMIT_TRIGGER defined).

How can that be a compilation issue when it worked previously?  Does this 
somehow relate to it being a Python plugin instance?

I'm very confused.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: HTML - WEB FORM running PYTHON SCRIPT

2012-12-23 Thread llanitedave
I'll second this.  Javascript is pretty comparable to Python in ease of 
learning, so that should be no obstacle.  As for keeping the code from being 
accessible, you can put the javascript in a separate file that's called from 
the guest's web page, but that's far from a foolproof method.  If you want the 
guest browser to do the calculation, there's no realistic way to keep the 
calculation code off of it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Pragmas, foreign keys in sqlite3?

2012-03-15 Thread llanitedave
Several questions here, but they're related.

I'm trying to incorporate an sqlite3 database that was created using
Sqliteman1.2.2.  I don't know what version of sqlite3 that one uses,
but it seems to have ignored any attempts to create foreign keys for
its tables.

I'm using Python 2.7.2, and I know that the sqlite3 version that it
contains is 3.7.7.  Therefore, it should be able to handle foreign
keys.  Where I'm clueless is about how to get that information out of
it, and how to implement or add foreign keys to existing tables.

Is there some way to use the sqlite PRAGMA command from within python?

I tried connecting to the database and got

 cr.execute('''PRAGMA foreign_keys;''')
sqlite3.Cursor object at 0xb7335720

 using inspect.getmembers() I got a huge list of everything; it lets
me see that there's no foreign key created, but I can't get that
particular tuple separated out, and I have no idea how to add them.

Do I need to recreate the entire database structure from scratch?
-- 
http://mail.python.org/mailman/listinfo/python-list