Re: How to measure the memory cost in Python?

2009-05-01 Thread Jean
On May 1, 7:54 am, CTO  wrote:
> Not OP, but I'd actually like to know if there's an answer to this one
> that doesn't involve platform-specific tools.

Depending on what you need and the O/S you are using, this recipe may
help

  <http://code.activestate.com/recipes/286222/>

That recipe also appeared in the 2nd edition of the Python Cookbook,
see

  <http://books.google.com/books?
id=Q0s6Vgb98CQC&printsec=frontcover&dq=editions:ISBN0596001673#PPA334,M1>

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


Re: How to measure the memory cost in Python?

2009-05-01 Thread Jean
On May 1, 10:56 am, CTO  wrote:
> > sys.getsizeof() [a suggested solution] isn't platform-specific.
>
> So, to answer the OP's question, you'd just do something like
>
> def get_totalsize(obj):
>         total_size = sys.getsizeof(obj)
>         for value in vars(obj).values():
>                 try: total_size += get_total_size(value)
>                 except: total_size += sys.getsizeof(value)
>         return totalSize
>
> def get_current_size(env):
>         size = 0
>         for value in env.values():
>                 try: size += get_total_size(value)
>                 except: pass
>         return size
>
> get_current_size(vars())
>
> and discount the weight of the interpreter?

Keep in mind, sys.getsizeof(obj) returns only the size of the given
object.  Any referenced objects are not included.  You can get the
latter from gc.get_referents(obj).

/Jean Brouwers

PS) The asizeof(obj) function from this recipe  does size the object plus its
references, recursively.

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


Re: How to measure the memory cost in Python?

2009-05-01 Thread Jean
On May 1, 12:50 pm, Jean  wrote:
> On May 1, 10:56 am, CTO  wrote:
>
>
>
> > > sys.getsizeof() [a suggested solution] isn't platform-specific.
>
> > So, to answer the OP's question, you'd just do something like
>
> > def get_totalsize(obj):
> >         total_size = sys.getsizeof(obj)
> >         for value in vars(obj).values():
> >                 try: total_size += get_total_size(value)
> >                 except: total_size += sys.getsizeof(value)
> >         return totalSize
>
> > def get_current_size(env):
> >         size = 0
> >         for value in env.values():
> >                 try: size += get_total_size(value)
> >                 except: pass
> >         return size
>
> > get_current_size(vars())
>
> > and discount the weight of the interpreter?
>
> Keep in mind, sys.getsizeof(obj) returns only the size of the given
> object.  Any referenced objects are not included.  You can get the
> latter from gc.get_referents(obj).
>
> /Jean Brouwers
>
> PS) The asizeof(obj) function from this recipe  code.activestate.com/recipes/546530> does size the object plus its
> references, recursively.

Correction, the last sentence should be: The asizeof(obj) ... plus its
referents, recursively.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Can I run a python program from within emacs?

2009-11-03 Thread Jean
On Nov 1, 10:15 am, rustom  wrote:
> On Nov 1, 7:20 pm, Robinson  wrote:
>
> > I have also just started with both Aquamacs and Python so I ask for  
> > your patience as well.
> > When I evaluate the buffer (C-c C-C) I don't see any response or  
> > output from my python program. Should another buffer open  
> > automatically? Should a terminal window open?
> > thanks for your patience.
> > Rugbeia Floreat Ubique
>
> > > On Mar 20, 3:09 pm, jmDesktop  wrote:
> > > > Hi, I'm trying to learn Python.  I usingAquamacan emac
> > > > implementation with mac os x.  I have a program.  If I go to the
> > > > command prompt and type pythong myprog.py, it works.  Can the  
> > > program
> > > > be run from within the editor or is that not how development is  
> > > done?
>
> There are two python modes -- python.el and python-mode.el
> Default with emacs is python.el, what comes from/with python is python-
> mode.el (needs a download and a couple of lines of setup 
> seehttp://www.emacswiki.org/emacs/PythonMode). I recommend python-mode.
>
> The key-bindings are different --C-c ! to start interpreter followed
> by C-c C-c to exec a file.

Perfect! Many thanks...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best Way to Handle All Exceptions

2009-07-15 Thread Jean
On Jul 13, 6:26 am, seldan24  wrote:
> Hello,
>
> I'm fairly new at Python so hopefully this question won't be too
> awful.  I am writing some code that will FTP to a host, and want to
> catch any exception that may occur, take that and print it out
> (eventually put it into a log file and perform some alerting action).
> I've figured out two different ways to do this, and am wondering which
> is the best (i.e. cleanest, 'right' way to proceed).  I'm also trying
> to understand exactly what occurs for each one.
>
> The first example:
>
> from ftplib import FTP
> try:
>     ftp = FTP(ftp_host)
>     ftp.login(ftp_user, ftp_pass)
> except Exception, err:
>     print err
>
> This works fine.  I read through the documentation, and my
> understanding is that there is a built-in exceptions module in python,
> that is automatically available in a built-in namespace.  Within that
> module is an 'Exception' class which would contain whatever exception
> is thrown.  So, I'm passing that to the except, along with err to hold
> the value and then print it out.
>
> The second example:
>
> from ftplib import FTP
> import sys
> try:
>     ftp = FTP(ftp_host)
>     ftp.login(ftp_user, ftp_pass)
> except:
>     print sys.exc_info()
>
> Here I, for the most part, get the same thing.  I'm not passing
> anything to except and just printing out the exception using a method
> defined in the sys module.
>
> So, I'm new to Python... I've made it this far and am happy, but want
> to make sure I'm coding correctly from the start.  Which method is the
> better/cleaner/more standard way to continue?  Thanks for any help.



The second example is "better" if you need your code to work in Python
3.0 *and* in 2.X.

For Python 3.0, the first example has to be written as:


except Exception as err:



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


[newbie] problem with if then

2013-06-09 Thread Jean Dubois
I'm writing some code to check whether an url is available or not,
therefore I make use of a wget-command in Linux and then check whether
this is successful (returning a 0) or not returning an 8
However the if then statement seems to give the same result in both
cases:
Here is my code:

#!/usr/bin/env python
import sys
import os
from datetime import datetime, timedelta
today=datetime.now()
yesterday= datetime.now() - timedelta(days=1)
daybeforeyesterday= datetime.now() - timedelta(days=2)
collection = [daybeforeyesterday,yesterday,today]
for thisday in collection:
 checkavailablestring='wget -q -O -
http://www.deredactie.be/cm/vrtnieuws/videozone/programmas/journaal/EP_'+thisday.strftime("%y%m%d")+'_JO7
>/dev/null ; echo $?'
 if os.system(checkavailablestring)==0:
  print thisday, 'stream is available'
 else:
  print thisday, 'stream is not available'

Can anyone here tell me what I'm doing wrong.
Thanks in advance
jean
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem with if then

2013-06-09 Thread Jean Dubois
On 9 jun, 22:00, Fábio Santos  wrote:
> On 9 Jun 2013 20:49, "Jean Dubois"  wrote:
>
>
>
> > I'm writing some code to check whether an url is available or not,
> > therefore I make use of a wget-command in Linux and then check whether
> > this is successful (returning a 0) or not returning an 8
> > However the if then statement seems to give the same result in both
> > cases:
>
> Which result? Failure, or success?
In case of failure I expect it to answer: stream not available
In case of success I expect it to answer: stream is available
But I get a "stream is available" in both cases even though the
command os.system(checkavailablestring) does give different answers: 0
and 8
>Have you tried printing the
> checkavailablestring string and running that command exactly?
yes I did, no problem there
>There may be something wrong with the command or URL in some way, and calling 
>os.system
I have added a line to the script and the results below so you can see
better what's going wrong:

Here's the script once again, this time with an extra line:

#!/usr/bin/env python
import sys
import os
from datetime import datetime, timedelta
today=datetime.now()
yesterday= datetime.now() - timedelta(days=1)
daybeforeyesterday= datetime.now() - timedelta(days=2)
collection = [daybeforeyesterday,yesterday,today]
for thisday in collection:
 checkavailablestring='wget -q -O -
http://www.deredactie.be/cm/vrtnieuws/videozone/programmas/journaal/EP_'+thisday.strftime("%y%m%d")+'_JO7
>/dev/null ; echo $?'
 print checkavailablestring
 if os.system(checkavailablestring)==0:
      print thisday, 'stream is available'
 else:
  print thisday, 'stream is not available'

And here is the result:

jean@antec4:~$ ./try.py
wget -q -O - 
http://www.deredactie.be/cm/vrtnieuws/videozone/programmas/journaal/EP_130607_JO7
>/dev/null ; echo $?
8
2013-06-07 22:07:00.016807 stream is available
wget -q -O - 
http://www.deredactie.be/cm/vrtnieuws/videozone/programmas/journaal/EP_130608_JO7
>/dev/null ; echo $?
8
2013-06-08 22:07:00.016795 stream is available
wget -q -O - 
http://www.deredactie.be/cm/vrtnieuws/videozone/programmas/journaal/EP_130609_JO7
>/dev/null ; echo $?
0
2013-06-09 22:07:00.016763 stream is available
















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


Re: problem with if then

2013-06-09 Thread Jean Dubois
On 9 jun, 22:29, Fábio Santos  wrote:
> On 9 Jun 2013 21:24, "Jean Dubois"
> ...> And here is the result:
>
> > jean@antec4:~$ ./try.py
> > wget -q -O -
>
> http://www.deredactie.be/cm/vrtnieuws/videozone/programmas/journaal/E...> 
> >/dev/null ; echo $?
> > 8
> > 2013-06-07 22:07:00.016807 stream is available
> > wget -q -O -
>
> http://www.deredactie.be/cm/vrtnieuws/videozone/programmas/journaal/E...> 
> >/dev/null ; echo $?
> > 8
> > 2013-06-08 22:07:00.016795 stream is available
> > wget -q -O -
>
> http://www.deredactie.be/cm/vrtnieuws/videozone/programmas/journaal/E...
>
> > >/dev/null ; echo $?
> > 0
> > 2013-06-09 22:07:00.016763 stream is available
>
> You don't need to echo the return code. os.system should return that as an
> int.
>
> The problem might be that os.system is returning the result from the echo
> command instead.

I removed the 'echo $?' and now the thing runs like expected, thanks a
lot

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


Re: problem with if then

2013-06-09 Thread Jean Dubois
On 9 jun, 22:23, Roy Smith  wrote:
> In article
> ,
>  Jean Dubois  wrote:
>
> > I'm writing some code to check whether an url is available or not,
> > therefore I make use of a wget-command in Linux and then check whether
> > this is successful
>
> In general, "shelling out" to run a command-line utility should be the
> last resort.  It's slower, and more complicated, than doing it in pure
> python.  You would only call a shell command if there was no other way.
>
> Fortunately, in Python, there is another way.  Several, in fact.
>
> The most straight-forward is to use the built-in urllib2 module
> (http://docs.python.org/2/library/urllib2.html).
>
> If you're going to be doing anything complicated (i.e. setting optional
> headers, managing cookies, etc), you probably want to be looking at the
> excellent third-party module, requests (http://python-requests.org).
>
> In any case, given your code:
>
>
>
>
>
>
>
>
>
> > #!/usr/bin/env python
> > import sys
> > import os
> > from datetime import datetime, timedelta
> > today=datetime.now()
> > yesterday= datetime.now() - timedelta(days=1)
> > daybeforeyesterday= datetime.now() - timedelta(days=2)
> > collection = [daybeforeyesterday,yesterday,today]
> > for thisday in collection:
> >      checkavailablestring='wget -q -O -
> >http://www.deredactie.be/cm/vrtnieuws/videozone/programmas/journaal/E...
> > ay.strftime("%y%m%d")+'_JO7
> > >/dev/null ; echo $?'
> >      if os.system(checkavailablestring)==0:
> >           print thisday, 'stream is available'
> >      else:
> >           print thisday, 'stream is not available'
>
> I would break the debugging down into several parts.  First, are you
> generating the command string properly?  Try printing out
> checkavailablestring before you call os.system() to make sure it's what
> you think it is.
>
> Next, once you're sure you've got the correct string, run it manually in
> the shell and see what it does.
>
> Next, are you sure you're using os.system() correctly?  Try running:
>
> os.system("/bin/true")
>
> and
>
> os.system("/bin/false")
>
> and make sure you get the results you think you should.  But, really,
> once you've done all that (and it's worth doing as an exercise), rewrite
> your code to use urllib2 or requests.  It'll be a lot easier.

Could you show me how to code the  example in metacode below wuth the
use of urllib2?
#!/usr/bin/env python
import urllib2
if check whether url exists succeed:
print 'url exists'
else:
print 'url does not exist'

thanks in advance
jean
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem with if then

2013-06-10 Thread Jean Dubois
On 9 jun, 23:35, Roy Smith  wrote:
> In article
> <20165c85-4cc3-4b79-943b-82443e4a9...@w7g2000vbw.googlegroups.com>,
>  Jean Dubois  wrote:
>
> > But, really,
> > > once you've done all that (and it's worth doing as an exercise), rewrite
> > > your code to use urllib2 or requests.  It'll be a lot easier.
>
> > Could you show me how to code the  example in metacode below wuth the
> > use of urllib2?
> > #!/usr/bin/env python
> > import urllib2
> > if check whether url exists succeed:
> >     print 'url exists'
> > else:
> >     print 'url does not exist'
>
> There are two basic ways Python function return status information.
> Either they return something which indicates failure (such as None), or
> they raise an exception.
>
> In this case, what you want is urlopen(), which is documented 
> athttp://docs.python.org/2/library/urllib2.html.  The key piece of
> information is a couple of paragraphs down, where it says, "Raises
> URLError on errors".
>
> It's not obvious from reading that whether URLError is a built-in or
> not, but that's easy enough to figure out:
>
> >>> URLError
>
> Traceback (most recent call last):
>   File "", line 1, in 
> NameError: name 'URLError' is not defined>>> import urllib2
> >>> urllib2.URLError
>
> 
>
> So, that means you want something like:
>
> #!/usr/bin/env python
>
> import urllib2
>
> url = "http://whatever";
> try:
>    urllib2.urlopen(url)
>    print "url exists"
> except urllib2.URLError:
>    print "url does not exist"

thanks a lot, this works like a charm

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


[newbie] problem with data (different behaviour between batch and interactive use)

2012-06-27 Thread Jean Dupont
I have some data which is presented in the following format to me:
+3.874693E-01,+9.999889E-03,+9.91E+37,+1.876595E+04,+3.994000E+04
I'm only interested in the first two fields i.e.
+3.874693E-01,+9.999889E-03
If I start python interactively I can separate the fields as follows:
>measurement=+3.874693E01,+9.999889E03,+9.91E+37,+1.876595E+04,+3.994000E+04
>print measurement[0]
0.3874693
>print measurement[1]
0.00889
If however I run a script with the same commands I get something different:
The script does this:
measurement=serkeith.readline().replace('\x11','').replace('\x13','').replace('\x0d','\n')
print measurement[0]
+
print measurement[1]
3

can anyone here tell me what I'm doing wrong and how to do it correctly

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


[newbie] Python and Qt4 Designer

2012-07-11 Thread Jean Dubois
I'm trying to combine python-code made with QT4 designer with plain
python statements like
file = open("test","w")
Can anyone tell me what I have to  add to the following code just to
open a file when clicking on the load-button and closing it by
clicking on the save button.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'test.ui'
#
# Created: Wed Jul 11 17:21:35 2012
#  by: PyQt4 UI code generator 4.8.3
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui

try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s

class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName(_fromUtf8("Form"))
Form.resize(400, 300)
self.widget = QtGui.QWidget(Form)
self.widget.setGeometry(QtCore.QRect(10, 20, 146, 25))
self.widget.setObjectName(_fromUtf8("widget"))
self.horizontalLayout = QtGui.QHBoxLayout(self.widget)
self.horizontalLayout.setMargin(0)
 
self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
self.pushButton_2 = QtGui.QPushButton(self.widget)
self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
self.horizontalLayout.addWidget(self.pushButton_2)
self.pushButton = QtGui.QPushButton(self.widget)
self.pushButton.setObjectName(_fromUtf8("pushButton"))
self.horizontalLayout.addWidget(self.pushButton)

self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)

def retranslateUi(self, Form):
Form.setWindowTitle(QtGui.QApplication.translate("Form",
"Form", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton_2.setText(QtGui.QApplication.translate("Form",
"Save file", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton.setText(QtGui.QApplication.translate("Form",
"Load file", None, QtGui.QApplication.UnicodeUTF8))


if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
Form = QtGui.QWidget()
ui = Ui_Form()
ui.setupUi(Form)
Form.show()
sys.exit(app.exec_())


thanks in advance
jean
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python and Qt4 Designer

2012-07-11 Thread Jean Dubois
On 12 jul, 02:59, Vincent Vande Vyvre 
wrote:
> On 11/07/12 17:37, Jean Dubois wrote:
>
>
>
>
>
>
>
> > I'm trying to combine python-code made with QT4 designer with plain
> > python statements like
> > file = open("test","w")
> > Can anyone tell me what I have to  add to the following code just to
> > open a file when clicking on the load-button and closing it by
> > clicking on the save button.
>
> > #!/usr/bin/env python
> > # -*- coding: utf-8 -*-
>
> > # Form implementation generated from reading ui file 'test.ui'
> > #
> > # Created: Wed Jul 11 17:21:35 2012
> > #      by: PyQt4 UI code generator 4.8.3
> > #
> > # WARNING! All changes made in this file will be lost!
>
> > from PyQt4 import QtCore, QtGui
>
> > try:
> >     _fromUtf8 = QtCore.QString.fromUtf8
> > except AttributeError:
> >     _fromUtf8 = lambda s: s
>
> > class Ui_Form(object):
> >     def setupUi(self, Form):
> >         Form.setObjectName(_fromUtf8("Form"))
> >         Form.resize(400, 300)
> >         self.widget = QtGui.QWidget(Form)
> >         self.widget.setGeometry(QtCore.QRect(10, 20, 146, 25))
> >         self.widget.setObjectName(_fromUtf8("widget"))
> >         self.horizontalLayout = QtGui.QHBoxLayout(self.widget)
> >         self.horizontalLayout.setMargin(0)
>
> > self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
> >         self.pushButton_2 = QtGui.QPushButton(self.widget)
> >         self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
> >         self.horizontalLayout.addWidget(self.pushButton_2)
> >         self.pushButton = QtGui.QPushButton(self.widget)
> >         self.pushButton.setObjectName(_fromUtf8("pushButton"))
> >         self.horizontalLayout.addWidget(self.pushButton)
>
> >         self.retranslateUi(Form)
> >         QtCore.QMetaObject.connectSlotsByName(Form)
>
> >     def retranslateUi(self, Form):
> >         Form.setWindowTitle(QtGui.QApplication.translate("Form",
> > "Form", None, QtGui.QApplication.UnicodeUTF8))
> >         self.pushButton_2.setText(QtGui.QApplication.translate("Form",
> > "Save file", None, QtGui.QApplication.UnicodeUTF8))
> >         self.pushButton.setText(QtGui.QApplication.translate("Form",
> > "Load file", None, QtGui.QApplication.UnicodeUTF8))
>
> > if __name__ == "__main__":
> >     import sys
> >     app = QtGui.QApplication(sys.argv)
> >     Form = QtGui.QWidget()
> >     ui = Ui_Form()
> >     ui.setupUi(Form)
> >     Form.show()
> >     sys.exit(app.exec_())
>
> > thanks in advance
> > jean
>
> Connect the signal clicked of your's buttons to your's functions.
>
>     self.pushButton.clicked.connect(self.my_func)
>
> Here's all the truth:
>
> http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/new_style_...
>
> --
> Vincent V.V.
> Oqapy <https://launchpad.net/oqapy> . Qarte+7
> <https://launchpad.net/qarte+7> . PaQager <https://launchpad.net/paqager>

thanks for the reference, could you just supply a small example for
the code above to get me started?

thanks in advance
jean
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python and Qt4 Designer

2012-07-13 Thread Jean Dubois
Op vrijdag 13 juli 2012 03:52:51 UTC+2 schreef Vincent Vande Vyvre het volgende:
> On 12/07/12 08:42, Jean Dubois wrote:
> > On 12 jul, 02:59, Vincent Vande Vyvre <vincent.vandevy...@swing.be>
> > wrote:
> >> On 11/07/12 17:37, Jean Dubois wrote:
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>> I'm trying to combine python-code made with QT4 designer 
> with plain
> >>> python statements like
> >>> file = open("test","w")
> >>> Can anyone tell me what I have to  add to the following code 
> just to
> >>> open a file when clicking on the load-button and closing it by
> >>> clicking on the save button.
> >>> #!/usr/bin/env python
> >>> # -*- coding: utf-8 -*-
> >>> # Form implementation generated from reading ui file 
> 'test.ui'
> >>> #
> >>> # Created: Wed Jul 11 17:21:35 2012
> >>> #  by: PyQt4 UI code generator 4.8.3
> >>> #
> >>> # WARNING! All changes made in this file will be lost!
> >>> from PyQt4 import QtCore, QtGui
> >>> try:
> >>> _fromUtf8 = QtCore.QString.fromUtf8
> >>> except AttributeError:
> >>> _fromUtf8 = lambda s: s
> >>> class Ui_Form(object):
> >>> def setupUi(self, Form):
> >>> Form.setObjectName(_fromUtf8("Form"))
> >>> Form.resize(400, 300)
> >>> self.widget = QtGui.QWidget(Form)
> >>> self.widget.setGeometry(QtCore.QRect(10, 20, 146, 25))
> >>> self.widget.setObjectName(_fromUtf8("widget"))
> >>> self.horizontalLayout = QtGui.QHBoxLayout(self.widget)
> >>> self.horizontalLayout.setMargin(0)
> >>> 
> self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
> >>> self.pushButton_2 = QtGui.QPushButton(self.widget)
> >>> 
> self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
> >>> self.horizontalLayout.addWidget(self.pushButton_2)
> >>> self.pushButton = QtGui.QPushButton(self.widget)
> >>> 
> self.pushButton.setObjectName(_fromUtf8("pushButton"))
> >>> self.horizontalLayout.addWidget(self.pushButton)
> >>> self.retranslateUi(Form)
> >>> QtCore.QMetaObject.connectSlotsByName(Form)
> >>> def retranslateUi(self, Form):
> >>> 
> Form.setWindowTitle(QtGui.QApplication.translate("Form",
> >>> "Form", None, QtGui.QApplication.UnicodeUTF8))
> >>> 
> self.pushButton_2.setText(QtGui.QApplication.translate("Form",
> >>> "Save file", None, QtGui.QApplication.UnicodeUTF8))
> >>> 
> self.pushButton.setText(QtGui.QApplication.translate("Form",
> >>> "Load file", None, QtGui.QApplication.UnicodeUTF8))
> >>> if __name__ == "__main__":
> >>> import sys
> >>> app = QtGui.QApplication(sys.argv)
> >>> Form = QtGui.QWidget()
> >>> ui = Ui_Form()
> >>> ui.setupUi(Form)
> >>> Form.show()
> >>> sys.exit(app.exec_())
> >>> thanks in advance
> >>> jean
> >> Connect the signal clicked of your's buttons to your's 
> functions.
> >>
> >> self.pushButton.clicked.connect(self.my_func)
> >>
> >> Here's all the truth:
> >>
> >> 
> http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/new_style_...
> >>
> >> --
> >> Vincent V.V.
> >> Oqapy <https://launchpad.net/oqapy>; . Qarte+7
> >> <https://launchpad.net/qarte+7>; . PaQager 
> <https://launchpad.net/paqager>;
> > thanks for the reference, could you just supply a small example for
> > the code above to get me started?
> >
> > thanks in advance
> > jean
> Just add the connection at the end of the Ui_Form class and, of course,
> your function.
> 
> You can find numbers of examples in your PyQt4 install folder.
> On my machine is located at /usr/share/doc/python-qt4-doc/examples
> 
> And, for more inspiration, have a look at this site:
>http://diotavelli.net/PyQtWiki/
> 
> -- 
> Vincent V.V.
> Oqapy <https://launchpad.net/oqapy>; . Qarte
> <https://launchpad.net/qarte>; . PaQager 
> <https://launchpad.net/paqager>;

Thanks for the extra docu references

regards,

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


[newbie] Looking for a good introduction to object oriented programming with Python

2012-08-04 Thread Jean Dubois
I'm looking for a good introduction to object oriented programming
with Python. I am looking for an introduction which only refers to
Python. I have seen introductions where the authors make comparisons
to other languages such as C++ and Java, but as I don't know these
languages that doesn't help me further much, it rather confuses me. I
also found an introduction in which the author started by telling that
"object oriented programming is weird", such a statement did stop me
reading further as I think an author should at least believe in the
topic he is going to present as being logical.
If someone here has a link or title to such an intro, I'd appreciate
that very much

regards,
Jean
p.s. People who don't like my style of asking questions, please
neglect this message
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for a good introduction to object oriented programming with Python

2012-08-05 Thread Jean Dubois
On 5 aug, 02:11, shearich...@gmail.com wrote:
> One reason you may be having difficulty is that unlike some languages 
> (C++/Java) object-orientation is not a be all and end all in Python, in fact 
> you could work with Python for a long time without really 'doing it' at all 
> (well other than calling methods/properties on existing API's). Having said 
> that here's what I would suggest ...
>
> Could do worse than this :
>
> http://www.diveintopython.net/object_oriented_framework/index.html
>
> and this
>
> http://docs.python.org/tutorial/classes.html
>
> read together.
>
> Judging by your question this is a probably a little advanced for now but you 
> could bookmark it for the future:
>
> http://www.catonmat.net/blog/learning-python-design-patterns-through-...
>
> Here's the corresponding PDF to go with the video:
>
> http://assets.en.oreilly.com/1/event/45/Practical%20Python%20Patterns...

Thanks a lot for this information, I'll check it out the following
days

best regards,
Jean
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for a good introduction to object oriented programming with Python

2012-08-05 Thread Jean Dubois
On 5 aug, 02:11, shearich...@gmail.com wrote:
> One reason you may be having difficulty is that unlike some languages 
> (C++/Java) object-orientation is not a be all and end all in Python, in fact 
> you could work with Python for a long time without really 'doing it' at all 
> (well other than calling methods/properties on existing API's). Having said 
> that here's what I would suggest ...
>
> Could do worse than this :
>
> http://www.diveintopython.net/object_oriented_framework/index.html
>
This example seems to tell you need the concept of dictionaries to
explain object oriented programming, is this really necessary?
> and this
>
> http://docs.python.org/tutorial/classes.html
Unfortunately, the trouble with this explanation is exactly what made
me ask the original question: it starts from concepts in c++ making it
very hard to understand for someone who does not know that language
already.
>
> read together.
>
> Judging by your question this is a probably a little advanced for now but you 
> could bookmark it for the future:
>
> http://www.catonmat.net/blog/learning-python-design-patterns-through-...
>
> Here's the corresponding PDF to go with the video:
>
> http://assets.en.oreilly.com/1/event/45/Practical%20Python%20Patterns...
Can someone here on this list give a trivial example of what object
oriented programming is, using only Python?

thanks in advance
Jean
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for a good introduction to object oriented programming with Python

2012-08-06 Thread Jean Dubois
On 5 aug, 20:28, Mark Lawrence  wrote:
> On 05/08/2012 19:04, Jean Dubois wrote:
>
>
>
>
>
>
>
>
>
> > On 5 aug, 02:11, shearich...@gmail.com wrote:
> >> One reason you may be having difficulty is that unlike some languages 
> >> (C++/Java) object-orientation is not a be all and end all in Python, in 
> >> fact you could work with Python for a long time without really 'doing it' 
> >> at all (well other than calling methods/properties on existing API's). 
> >> Having said that here's what I would suggest ...
>
> >> Could do worse than this :
>
> >>http://www.diveintopython.net/object_oriented_framework/index.html
>
> > This example seems to tell you need the concept of dictionaries to
> > explain object oriented programming, is this really necessary?
> >> and this
>
> >>http://docs.python.org/tutorial/classes.html
> > Unfortunately, the trouble with this explanation is exactly what made
> > me ask the original question: it starts from concepts in c++ making it
> > very hard to understand for someone who does not know that language
> > already.
>
> >> read together.
>
> >> Judging by your question this is a probably a little advanced for now but 
> >> you could bookmark it for the future:
>
> >>http://www.catonmat.net/blog/learning-python-design-patterns-through-...
>
> >> Here's the corresponding PDF to go with the video:
>
> >>http://assets.en.oreilly.com/1/event/45/Practical%20Python%20Patterns...
> > Can someone here on this list give a trivial example of what object
> > oriented programming is, using only Python?
>
> > thanks in advance
> > Jean
>
> Try thishttp://www.voidspace.org.uk/python/articles/OOP.shtml???
>
> --
> Cheers.
>
> Mark Lawrence.
Thanks, this one is a lot better. Could you just tell me what the use
is of the following lines:
"""Class docstring."""
"""Method docstring."""
"""Method docstring."""
Taken from the following code fragment (I really want to understand
every bit of code, and the author doesn't mention this)


class OurClass(object):
"""Class docstring."""

def __init__(self, arg1, arg2):
"""Method docstring."""
self.arg1 = arg1
self.arg2 = arg2

def printargs(self):
"""Method docstring."""
print self.arg1
print self.arg2



thanks in advance
jean
-- 
http://mail.python.org/mailman/listinfo/python-list


[newbie] problem with module PyVisa

2012-11-09 Thread Jean Dubois
I'm trying to control a programmable power supply via USB using
python.
After doing some googling I thought I should use PyVisa for this
purpose, so I installed it as follows:
tar xvfz PyVISA-1.4.tar.gz
cd PyVISA-1.4
python setup.py install

Installation seems to finish without errors.

When I start a python session things go wrong as you can see in the
output below,
can anyone here tell me how to proceed correctly? thanks in advance.

>>> import visa
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/local/lib/python2.6/dist-packages/PyVISA-1.4-py2.6.egg/
visa.py", line 1, in 
from pyvisa.visa import *
  File "/usr/local/lib/python2.6/dist-packages/PyVISA-1.4-py2.6.egg/
pyvisa/visa.py", line 231, in 
resource_manager = ResourceManager()
  File "/usr/local/lib/python2.6/dist-packages/PyVISA-1.4-py2.6.egg/
pyvisa/vpp43.py", line 105, in __new__
it.init(*args, **kwds)
  File "/usr/local/lib/python2.6/dist-packages/PyVISA-1.4-py2.6.egg/
pyvisa/visa.py", line 227, in init
self.session = self.vi = vpp43.open_default_resource_manager()
  File "/usr/local/lib/python2.6/dist-packages/PyVISA-1.4-py2.6.egg/
pyvisa/vpp43.py", line 758, in open_default_resource_manager
visa_library().viOpenDefaultRM(byref(session))
  File "/usr/local/lib/python2.6/dist-packages/PyVISA-1.4-py2.6.egg/
pyvisa/vpp43.py", line 175, in __call__
self.load_library()
  File "/usr/local/lib/python2.6/dist-packages/PyVISA-1.4-py2.6.egg/
pyvisa/vpp43.py", line 146, in load_library
self.__lib = self.__cdecl_lib = cdll.LoadLibrary(path)
  File "/usr/lib/python2.6/ctypes/__init__.py", line 431, in
LoadLibrary
return self._dlltype(name)
  File "/usr/lib/python2.6/ctypes/__init__.py", line 353, in __init__
self._handle = _dlopen(self._name, mode)
OSError: /usr/local/vxipnp/linux/bin/libvisa.so.7: cannot open shared
object file: No such file or directory
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem with module PyVisa

2012-11-09 Thread Jean Dubois
On 9 nov, 17:40, Rodrick Brown  wrote:
> It seems pretty obvious from the error. Try installing the missing lib 
> packages.
>
> OSError: /usr/local/vxipnp/linux/bin/libvisa.so.7: cannot open shared
> object file: No such file or directory
>
> Sent from my iPhone
>
> On Nov 9, 2012, at 11:22 AM, Jean Dubois  wrote:
>
>
>
>
>
>
>
> > OSError: /usr/local/vxipnp/linux/bin/libvisa.so.7: cannot open shared
> > object file: No such file or directory

The error may be obvious but finding this file and how to install it
is not unfortunately.
It seems I have to install it from the National Instruments site but
Debian Linux doesn't seem to be supported...
and I doubt whether just copying this file will be sufficient to make
PyVisa work.
I wonder whether there might be another way to communicate via USB
with a Keithley programmable power supply using Python.

best regards,
Jean



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


Re: problem with module PyVisa

2012-11-11 Thread Jean Dubois
On 9 nov, 22:14, w...@mac.com wrote:
> On Nov 9, 2012, at 3:43 PM, Jean Dubois  wrote:
>
>
>
>
>
>
>
>
>
>
>
> > The error may be obvious but finding this file and how to install it
> > is not unfortunately.
> > It seems I have to install it from the National Instruments site but
> > Debian Linux doesn't seem to be supported...
> > and I doubt whether just copying this file will be sufficient to make
> > PyVisa work.
> > I wonder whether there might be another way to communicate via USB
> > with a Keithley programmable power supply using Python.
>
> > best regards,
> > Jean
>
> > --
> >http://mail.python.org/mailman/listinfo/python-list
>
> I've been using pyserial quite successfully to control a USB-to-serial 
> converter.
>
> That is, controlling a couple of RS232 serial devices via the USB port 
> through a KeySpan USB-to-Serial converter.
>
> Pyserial seems to make communication through the USB port quite transparent, 
> at least on my OS-X system.
>
> -Bill

Well, in fact I do have some working scripts using pyserial to control
an older (and more expensive) Keithley sourcemeter in combination with
a USB-to-serial converter.
But the trouble started when buying a cheaper and newer Keithley model
which does not have rs232 but only USB. I noticed they have put an
extra layer above USB called USBTMC
which complicates things further. I followed the instructions at
http://www.home.agilent.com/upload/cmc_upload/All/usbtmc.htm?&cc=BE&lc=dut#3.Copyright%20Notice|outline
and compiled and loaded the usbtmc-driver but I still can't
communicate with the Keithley, hence I started looking for an
alternative using PyVisa...and now I'm stuck

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


Re: problem with module PyVisa

2012-11-20 Thread Jean Dubois
On 11 nov, 20:30, Jean Dubois  wrote:
> On 9 nov, 22:14, w...@mac.com wrote:
>
>
>
> > On Nov 9, 2012, at 3:43 PM, Jean Dubois  wrote:
>
> > > The error may be obvious but finding this file and how to install it
> > > is not unfortunately.
> > > It seems I have to install it from the National Instruments site but
> > > Debian Linux doesn't seem to be supported...
> > > and I doubt whether just copying this file will be sufficient to make
> > > PyVisa work.
> > > I wonder whether there might be another way to communicate via USB
> > > with a Keithley programmable power supply using Python.
>
> > > best regards,
> > > Jean
>
> > > --
> > >http://mail.python.org/mailman/listinfo/python-list
>
> > I've been using pyserial quite successfully to control a USB-to-serial 
> > converter.
>
> > That is, controlling a couple of RS232 serial devices via the USB port 
> > through a KeySpan USB-to-Serial converter.
>
> > Pyserial seems to make communication through the USB port quite 
> > transparent, at least on my OS-X system.
>
> > -Bill
>
> Well, in fact I do have some working scripts using pyserial to control
> an older (and more expensive) Keithley sourcemeter in combination with
> a USB-to-serial converter.
> But the trouble started when buying a cheaper and newer Keithley model
> which does not have rs232 but only USB. I noticed they have put an
> extra layer above USB called USBTMC
> which complicates things further. I followed the instructions 
> athttp://www.home.agilent.com/upload/cmc_upload/All/usbtmc.htm?&cc=BE&l...outline
> and compiled and loaded the usbtmc-driver but I still can't
> communicate with the Keithley, hence I started looking for an
> alternative using PyVisa...and now I'm stuck
>
> jean

I finally got it working without PyVisa as follows:
#!/usr/bin/python
#sample program for Keithley 2200 USB
#first compile and load module usbtmc
import os
usbkeith = open('/dev/usbtmc1','r+')
#next commando is very important
#without it you can fetch data but not SET data
usbkeith.write("SYST:REM" + "\n")
usbkeith.write("*IDN?\n")
identification=usbkeith.readline()
print 'Found: ',identification
usbkeith.write("SOUR:CURR 0.2A\n")
usbkeith.write("SOUR:OUTP:STAT ON\n")
usbkeith.write("MEAS:VOLT?\n")
measurement=usbkeith.readline()
print 'Measured voltage: ',measurement

regards,
jean
-- 
http://mail.python.org/mailman/listinfo/python-list


[newbie] problem with usbtmc-communication

2012-12-04 Thread Jean Dubois
The following test program which tries to communicate with a Keithley
2200 programmable power supply using usbtmc in Python does not work as
expected. I have connected a 10 ohm resistor to its terminals and I
apply 0.025A, 0.050A, 0.075A en 0.1A,
I then measure the current and the voltage en write them in a file
De data produced looks like this:
0.00544643 0.254061; first current value is wrong, voltage value is
correct
0.0250807 0.509289; second current value is wrong, but it corresponds
to the first, second voltage is correct
0.0501099 0.763945; 3rd current value is wrong, but it corresponds to
the second, 3rd voltage is right
0.075099 1.01792; 4th current value is wrong,  it corresponds to the
3rd, 4th voltage is right
4th correct current value is missing

But is should be (numerical inaccuracy taking into account)(these data
were produced by a similar octave-program):
0.0248947 0.254047
0.0499105 0.509258
0.0749044 0.764001
0.0998926 1.01828

Here is the python-program:
#!/usr/bin/python
import time
import os
import sys
measurementcurr=''
measurementvolt=''
timesleepdefault=1
filename ='mydata.txt'
usbkeith = open('/dev/usbtmc1','r+')
usbkeith.flush()
usbkeith.write("*IDN?\n")
#strip blank line:
identification=usbkeith.readline().strip()
print 'Found device: ',identification
usbkeith.write("SYST:REM" + "\n")
usbkeith.write(":SENS:VOLT:PROT 1.5\n")
keithdata = open(filename,'w')
#start first measurement
usbkeith.write(":SOUR:CURR 0.025\n")
usbkeith.write(":OUTP:STAT ON\n")
time.sleep(timesleepdefault)
usbkeith.write(":MEAS:CURR?\n")
time.sleep(timesleepdefault)
measurementcurr=usbkeith.readline()
print 'Measured current 1: ',measurementcurr
usbkeith.write("MEAS:VOLT?\n")
time.sleep(timesleepdefault)
measurementvolt=usbkeith.readline()
print 'Measured voltage 1: ',measurementvolt
keithdata.write(measurementcurr.strip()+' '+measurementvolt)
#start second measurement
usbkeith.write("SOUR:CURR 0.050\n")
time.sleep(timesleepdefault)
usbkeith.write("MEAS:CURR?\n")
time.sleep(timesleepdefault)
measurementcurr=usbkeith.readline()
print 'Measured current 2: ',measurementcurr
usbkeith.write("MEAS:VOLT?\n")
time.sleep(timesleepdefault)
measurementvolt=usbkeith.readline()
print 'Measured voltage 2: ',measurementvolt
keithdata.write(measurementcurr.strip()+' '+measurementvolt)
#start 3rd measurement
time.sleep(timesleepdefault)
usbkeith.write("SOUR:CURR 0.075\n")
time.sleep(timesleepdefault)
usbkeith.write("MEAS:CURR?\n")
time.sleep(timesleepdefault)
measurementcurr=usbkeith.readline()
print 'Measured current 3: ',measurementcurr
usbkeith.write("MEAS:VOLT?\n")
time.sleep(timesleepdefault)
measurementvolt=usbkeith.readline()
print 'Measured voltage 3: ',measurementvolt
keithdata.write(measurementcurr.strip()+' '+measurementvolt)
#start 4th measurement
time.sleep(timesleepdefault)
usbkeith.write("SOUR:CURR 0.1\n")
time.sleep(timesleepdefault)
usbkeith.write("MEAS:CURR?\n")
time.sleep(timesleepdefault)
measurementcurr=usbkeith.readline()
print 'Measured current 4: ',measurementcurr
usbkeith.write("MEAS:VOLT?\n")
time.sleep(timesleepdefault)
measurementvolt=usbkeith.readline()
print 'Measured voltage 4: ',measurementvolt
keithdata.write(measurementcurr.strip()+' '+measurementvolt)
usbkeith.write(":OUTP:STAT OFF\n")
print "Goodbye, data logged in file:"
print filename
usbkeith.close()
keithdata.close()

can anyone here what is going wrong and how to get it right?

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


Re: problem with usbtmc-communication

2012-12-04 Thread Jean Dubois
On 4 dec, 15:33, w...@mac.com wrote:
> On Dec 4, 2012, at 7:14 AM, Jean Dubois  wrote:
>
>
>
> > The following test program which tries to communicate with a Keithley
> > 2200 programmable power supply using usbtmc in Python does not work as
> > expected. I have connected a 10 ohm resistor to its terminals and I
> > apply 0.025A, 0.050A, 0.075A en 0.1A,
> > I then measure the current and the voltage en write them in a file
> > De data produced looks like this:
> > 0.00544643 0.254061; first current value is wrong, voltage value is
> > correct
> > 0.0250807 0.509289; second current value is wrong, but it corresponds
> > to the first, second voltage is correct
> > 0.0501099 0.763945; 3rd current value is wrong, but it corresponds to
> > the second, 3rd voltage is right
> > 0.075099 1.01792; 4th current value is wrong,  it corresponds to the
> > 3rd, 4th voltage is right
> >                            4th correct current value is missing
>
> > But is should be (numerical inaccuracy taking into account)(these data
> > were produced by a similar octave-program):
> > 0.0248947 0.254047
> > 0.0499105 0.509258
> > 0.0749044 0.764001
> > 0.0998926 1.01828
>
> > Here is the python-program:
> > #!/usr/bin/python
> > import time
> > import os
> > import sys
> > measurementcurr=''
> > measurementvolt=''
> > timesleepdefault=1
> > filename ='mydata.txt'
> > usbkeith = open('/dev/usbtmc1','r+')
> > usbkeith.flush()
> > usbkeith.write("*IDN?\n")
> > #strip blank line:
> > identification=usbkeith.readline().strip()
> > print 'Found device: ',identification
> > usbkeith.write("SYST:REM" + "\n")
> > usbkeith.write(":SENS:VOLT:PROT 1.5\n")
> > keithdata = open(filename,'w')
> > #start first measurement
> > usbkeith.write(":SOUR:CURR 0.025\n")
> > usbkeith.write(":OUTP:STAT ON\n")
> > time.sleep(timesleepdefault)
> > usbkeith.write(":MEAS:CURR?\n")
> > time.sleep(timesleepdefault)
> > measurementcurr=usbkeith.readline()
> > print 'Measured current 1: ',measurementcurr
> > usbkeith.write("MEAS:VOLT?\n")
> > time.sleep(timesleepdefault)
> > measurementvolt=usbkeith.readline()
> > print 'Measured voltage 1: ',measurementvolt
> > keithdata.write(measurementcurr.strip()+' '+measurementvolt)
> > #start second measurement
> > usbkeith.write("SOUR:CURR 0.050\n")
> > time.sleep(timesleepdefault)
> > usbkeith.write("MEAS:CURR?\n")
> > time.sleep(timesleepdefault)
> > measurementcurr=usbkeith.readline()
> > print 'Measured current 2: ',measurementcurr
> > usbkeith.write("MEAS:VOLT?\n")
> > time.sleep(timesleepdefault)
> > measurementvolt=usbkeith.readline()
> > print 'Measured voltage 2: ',measurementvolt
> > keithdata.write(measurementcurr.strip()+' '+measurementvolt)
> > #start 3rd measurement
> > time.sleep(timesleepdefault)
> > usbkeith.write("SOUR:CURR 0.075\n")
> > time.sleep(timesleepdefault)
> > usbkeith.write("MEAS:CURR?\n")
> > time.sleep(timesleepdefault)
> > measurementcurr=usbkeith.readline()
> > print 'Measured current 3: ',measurementcurr
> > usbkeith.write("MEAS:VOLT?\n")
> > time.sleep(timesleepdefault)
> > measurementvolt=usbkeith.readline()
> > print 'Measured voltage 3: ',measurementvolt
> > keithdata.write(measurementcurr.strip()+' '+measurementvolt)
> > #start 4th measurement
> > time.sleep(timesleepdefault)
> > usbkeith.write("SOUR:CURR 0.1\n")
> > time.sleep(timesleepdefault)
> > usbkeith.write("MEAS:CURR?\n")
> > time.sleep(timesleepdefault)
> > measurementcurr=usbkeith.readline()
> > print 'Measured current 4: ',measurementcurr
> > usbkeith.write("MEAS:VOLT?\n")
> > time.sleep(timesleepdefault)
> > measurementvolt=usbkeith.readline()
> > print 'Measured voltage 4: ',measurementvolt
> > keithdata.write(measurementcurr.strip()+' '+measurementvolt)
> > usbkeith.write(":OUTP:STAT OFF\n")
> > print "Goodbye, data logged in file:"
> > print filename
> > usbkeith.close()
> > keithdata.close()
>
> > can anyone here what is going wrong and how to get it right?
>
> > thanks
> > jean
> > --
> >http://mail.python.org/mailman/listinfo/py

Re: problem with usbtmc-communication

2012-12-05 Thread Jean Dubois
On 5 dec, 16:26, w...@mac.com wrote:
> On Dec 4, 2012, at 11:12 AM, Jean Dubois  wrote:
>
> > On 4 dec, 15:33, w...@mac.com wrote:
> >> On Dec 4, 2012, at 7:14 AM, Jean Dubois  wrote:
>
> >>> The following test program which tries to communicate with a Keithley
> >>> 2200 programmable power supply using usbtmc in Python does not work as
>
> Is usbtmc a software layer (library of some sort) or some sort of hardware 
> adapter?
This is the information concerning usbtmc from the National
Instruments site:
USBTMC stands for USB Test & Measurement Class. USBTMC is a protocol
built on top of USB that allows GPIB-like communication with USB
devices. From the user's point of view, the USB device behaves just
like a GPIB device. For example, you can use VISA Write to send the
*IDN? query and use VISA Read to get the response. The USBTMC protocol
supports service request, triggers and other GPIB specific operations.

>
>
>
>
>
>
>
>
> >>> expected. I have connected a 10 ohm resistor to its terminals and I
> >>> apply 0.025A, 0.050A, 0.075A en 0.1A,
> >>> I then measure the current and the voltage en write them in a file
> >>> De data produced looks like this:
> >>> 0.00544643 0.254061; first current value is wrong, voltage value is
> >>> correct
> >>> 0.0250807 0.509289; second current value is wrong, but it corresponds
> >>> to the first, second voltage is correct
> >>> 0.0501099 0.763945; 3rd current value is wrong, but it corresponds to
> >>> the second, 3rd voltage is right
> >>> 0.075099 1.01792; 4th current value is wrong,  it corresponds to the
> >>> 3rd, 4th voltage is right
> >>>                            4th correct current value is missing
>
> >>> But is should be (numerical inaccuracy taking into account)(these data
> >>> were produced by a similar octave-program):
> >>> 0.0248947 0.254047
> >>> 0.0499105 0.509258
> >>> 0.0749044 0.764001
> >>> 0.0998926 1.01828
>
> >>> Here is the python-program:
> >>> #!/usr/bin/python
> >>> import time
> >>> import os
> >>> import sys
> >>> measurementcurr=''
> >>> measurementvolt=''
> >>> timesleepdefault=1
> >>> filename ='mydata.txt'
> >>> usbkeith = open('/dev/usbtmc1','r+')
> >>> usbkeith.flush()
> >>> usbkeith.write("*IDN?\n")
> >>> #strip blank line:
> >>> identification=usbkeith.readline().strip()
> >>> print 'Found device: ',identification
> >>> usbkeith.write("SYST:REM" + "\n")
> >>> usbkeith.write(":SENS:VOLT:PROT 1.5\n")
> >>> keithdata = open(filename,'w')
> >>> #start first measurement
> >>> usbkeith.write(":SOUR:CURR 0.025\n")
> >>> usbkeith.write(":OUTP:STAT ON\n")
> >>> time.sleep(timesleepdefault)
> >>> usbkeith.write(":MEAS:CURR?\n")
> >>> time.sleep(timesleepdefault)
> >>> measurementcurr=usbkeith.readline()
> >>> print 'Measured current 1: ',measurementcurr
> >>> usbkeith.write("MEAS:VOLT?\n")
> >>> time.sleep(timesleepdefault)
> >>> measurementvolt=usbkeith.readline()
>
> Without knowing anything about the usbtmc hardware/software it is hard to 
> make real recommendations, but it seems pretty clear that you are being 
> stepped on by a buffer problem of some sort.  I'm VERY suspicious of using of 
> readline() as a way of getting the data out of the usbtmc thingy.  That makes 
> python treat the Keithley as a file-like object and there are way too many 
> ways the file pointer may not be where you think it is.
>
> I note that in your Octave example you are reading characters rather than 
> lines.  It seems to me that you have two choices here, either do the 
> equivalent in python or dig through the Keithley documentation to find the 
> hex codes that usbtmc is presumably translating your commands into.  If you 
> can find those, and if you are interested, I can send you off-line the 
> handler I wrote a couple of years ago that used a dictionary to translate 
> English commands into hex, then assembled those with a checksum and sent the 
> string out to a Keyspan usb to serial converter.

If you could show me how to "do the equivalent in Python" I'd
appreciate that very much

best regards,
jean
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem with usbtmc-communication

2012-12-06 Thread Jean Dubois
On 5 dec, 23:21, w...@mac.com wrote:
> On Dec 5, 2012, at 3:38 PM, Jean Dubois  wrote:
>
> [byte]
>
>
>
> >> I note that in your Octave example you are reading characters rather than 
> >> lines.  It seems to me that you have two choices here, either do the 
> >> equivalent in python or dig through the Keithley documentation to find the 
> >> hex codes thatusbtmcis presumably translating your commands into.  If you 
> >> can find those, and if you are interested, I can send you off-line the 
> >> handler I wrote a couple of years ago that used a dictionary to translate 
> >> English commands into hex, then assembled those with a checksum and sent 
> >> the string out to a Keyspan usb to serial converter.
>
> > If you could show me how to "do the equivalent in Python" I'd
> > appreciate that very much
>
> > best regards,
> > jean
> > --
> >http://mail.python.org/mailman/listinfo/python-list
>
> OK - I've excerpted some of the relevant code (the original was much longer 
> and included a lot of error checking).  Please understand that the comments 
> were for my own use, this was never intended to see the light of day (as it 
> were).  Also, the structure grew from a situation where I only had to worry 
> about a single controller model - single relay model to one where I had to be 
> able to deal with two controllers and two relay models.  This was all python 
> 2.7 of course.
>
> cut on dotted line..
> """
>  serial_port = /dev/tty.KeySerial1, 2, 3, etc.
>  X10_controller = 1132B  or TI103
>  Relay_model = UM506  or RBn04
>  Relay_address = B2
>
> """
> import serial, string
>
> def checksum256(st):
>     temp = reduce(lambda x,y:x+y, map(ord,st)) % 256
>     if temp < 9:
>         hex_temp = '0'+str(temp)
>         return hex_temp
>     hex_temp = hex(temp).upper()[2:]
>     return hex_temp
>
> letr_address_dict = {'A':'\x46', 'B':'\x4E', 'C':'\x42', 'D':'\x4A', 
> 'E':'\x41', 'F':'\x49', 'G':'\x45', 'H':'\x4D', 'I':'\x47',  'J':'\x4F',  
> 'K':'\x43',  'L':'\x4B',  'M':'\x40',  'N':'\x48',  'O':'\x44',  'P':'\x4C' }
> numb_address_dict = {'1':'\x4C', '2':'\x5C', '3':'\x44', '4':'\x54', 
> '5':'\x42', '6':'\x52', '7':'\x4A', '8':'\x5A', '9':'\x4E', '10':'\x5E', 
> '11':'\x46', '12':'\x56', '13':'\x40', '14':'\x50', '15':'\x48', '16':'\x58' }
> cmd_dict     =      {'SoC':'\x63', 'All_Units_Off':'\x41', 
> 'All_Lights_On':'\x43', 'ON':'\x45', 'OFF':'\x47', 'Dim':'\x49', 
> 'Bright':'\x4B', 'All_Lights_Off':'\x4D', 'Rep_Cnt1':'\x41', 
> 'Rep_Cnt2':'\x42'}
>
> def relay(port, controller_model, relay_model, relay_address, command):
>     if controller_model == '1132B':
>         if relay_model == 'UM506' or relay_model == 'UM7206':
>             letr = letr_address_dict[relay_address[0]]
>             numb = numb_address_dict[relay_address[1]]
>             cmd = cmd_dict[command]
>             cmd_string = '\x63'+letr+numb+cmd+'\x42'     # Start-of-Command + 
> address_letter + address_number + command + Rep-count
>             ser = serial.Serial(port, 9600, timeout=1)   # Set up handle to 
> serial port
>             stat1 = ser.write('\x02')                    # Write attention to 
> PowerLink, stat = number of bytes written, not really an error return.
>             ack1 = ser.read(2)                           # Check to see if 
> PowerLink is ready
>             if ack1 == '\x06\r':                         # It returns ACK 
> (\x06\r) if it is
>                 stat2 = ser.write(cmd_string)
>                 ack2 = ser.read(19)
>                 if command == 'ON' and ack2 == 'XN\\1\rXNE1\rXNE1\r' : status 
> = 0
>                 if command == 'OFF' and ack2 

Re: problem with usbtmc-communication

2012-12-06 Thread Jean Dubois
On 4 dec, 20:55, Terry Reedy  wrote:
> On 12/4/2012 7:14 AM, Jean Dubois wrote:
>
>
>
>
>
>
>
>
>
> > The following test program which tries to communicate with a Keithley
> > 2200 programmable power supply usingusbtmcin Python does not work as
> > expected. I have connected a 10 ohm resistor to its terminals and I
> > apply 0.025A, 0.050A, 0.075A en 0.1A,
> > I then measure the current and the voltage en write them in a file
> > De data produced looks like this:
> > 0.00544643 0.254061; first current value is wrong, voltage value is
> > correct
> > 0.0250807 0.509289; second current value is wrong, but it corresponds
> > to the first, second voltage is correct
> > 0.0501099 0.763945; 3rd current value is wrong, but it corresponds to
> > the second, 3rd voltage is right
> > 0.075099 1.01792; 4th current value is wrong,  it corresponds to the
> > 3rd, 4th voltage is right
> >                              4th correct current value is missing
>
> > But is should be (numerical inaccuracy taking into account)  (these data
> > were produced by a similar octave-program):
> > 0.0248947 0.254047
> > 0.0499105 0.509258
> > 0.0749044 0.764001
> > 0.0998926 1.01828
>
> > Here is the python-program:
> > #!/usr/bin/python
> > import time
> > import os
> > import sys
> > measurementcurr=''
> > measurementvolt=''
> > timesleepdefault=1
> > filename ='mydata.txt'
> > usbkeith = open('/dev/usbtmc1','r+')
> > usbkeith.flush()
> > usbkeith.write("*IDN?\n")
> > #strip blank line:
> > identification=usbkeith.readline().strip()
> > print 'Found device: ',identification
> > usbkeith.write("SYST:REM" + "\n")
> > usbkeith.write(":SENS:VOLT:PROT 1.5\n")
> > keithdata = open(filename,'w')
> > #start first measurement
> > usbkeith.write(":SOUR:CURR 0.025\n")
> > usbkeith.write(":OUTP:STAT ON\n")
> > time.sleep(timesleepdefault)
> > usbkeith.write(":MEAS:CURR?\n")
> > time.sleep(timesleepdefault)
> > measurementcurr=usbkeith.readline()
> > print 'Measured current 1: ',measurementcurr
> > usbkeith.write("MEAS:VOLT?\n")
> > time.sleep(timesleepdefault)
> > measurementvolt=usbkeith.readline()
> > print 'Measured voltage 1: ',measurementvolt
> > keithdata.write(measurementcurr.strip()+' '+measurementvolt)
>
> [3 near repetitions snipped]
>
> This sort of repetitious code without even line breaks is painful for me
> to read. Python has looping statements for a reason. Replace all four
> nearly identical blocks with the following. (If you are not familiar
> with built-in enumerate, you should be. Read its entry in the library
> manual.)
>
> for number, current_in in enumerate(
>      ('0.025', '0.050'. '0.075', '0.100'), 1)
>    usbkeith.write(":SOUR:CURR %s\n" % current_in)
>    ...
>    print 'Measured current %d: ' % number, measurementcurr
>    ...
>    print 'Measured voltage %d: ' % number, measurementvolt
>
> Now you can make changes in only one place and easily add more test values.
>
> > print "Goodbye, data logged in file:"
> > print filename
> > usbkeith.close()
> > keithdata.close()
>
> > can anyone here what is going wrong and how to get it right?
>
> No, but if both the python and octave programs used loops, it would be
> easier to see if both are doing the same things before, within, and
> after the loop.
>
> --
> Terry Jan Reedy

Thank you for you reply. Of course you are right this kind of code is
not the normal way to program but as I mentioned in my initial post
this is merely a test program, I did avoid using a loop on purpose
because timing can be critical in this kind of application and I
didn't want to add unnecessary uncertainty in the timing which could
be caused by using a loop.
The final version will be more like you suggested here above.
As Bill stated in another e-mail the real trouble here is some kind of
"buffer-problem",  according to him it could be caused by the use of
the readline()-statements. So if anyone could tell me how to
substitute those by some Python commands which read characters instead
does the Octave-code I'd appreciate that very much.

regards,
Jean
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem with usbtmc-communication

2012-12-06 Thread Jean Dubois
On 4 dec, 20:55, Terry Reedy  wrote:
> On 12/4/2012 7:14 AM, Jean Dubois wrote:
>
>
>
>
>
>
>
>
>
> > The following test program which tries to communicate with a Keithley
> > 2200 programmable power supply using usbtmc in Python does not work as
> > expected. I have connected a 10 ohm resistor to its terminals and I
> > apply 0.025A, 0.050A, 0.075A en 0.1A,
> > I then measure the current and the voltage en write them in a file
> > De data produced looks like this:
> > 0.00544643 0.254061; first current value is wrong, voltage value is
> > correct
> > 0.0250807 0.509289; second current value is wrong, but it corresponds
> > to the first, second voltage is correct
> > 0.0501099 0.763945; 3rd current value is wrong, but it corresponds to
> > the second, 3rd voltage is right
> > 0.075099 1.01792; 4th current value is wrong,  it corresponds to the
> > 3rd, 4th voltage is right
> >                              4th correct current value is missing
>
> > But is should be (numerical inaccuracy taking into account)  (these data
> > were produced by a similar octave-program):
> > 0.0248947 0.254047
> > 0.0499105 0.509258
> > 0.0749044 0.764001
> > 0.0998926 1.01828
>
> > Here is the python-program:
> > #!/usr/bin/python
> > import time
> > import os
> > import sys
> > measurementcurr=''
> > measurementvolt=''
> > timesleepdefault=1
> > filename ='mydata.txt'
> > usbkeith = open('/dev/usbtmc1','r+')
> > usbkeith.flush()
> > usbkeith.write("*IDN?\n")
> > #strip blank line:
> > identification=usbkeith.readline().strip()
> > print 'Found device: ',identification
> > usbkeith.write("SYST:REM" + "\n")
> > usbkeith.write(":SENS:VOLT:PROT 1.5\n")
> > keithdata = open(filename,'w')
> > #start first measurement
> > usbkeith.write(":SOUR:CURR 0.025\n")
> > usbkeith.write(":OUTP:STAT ON\n")
> > time.sleep(timesleepdefault)
> > usbkeith.write(":MEAS:CURR?\n")
> > time.sleep(timesleepdefault)
> > measurementcurr=usbkeith.readline()
> > print 'Measured current 1: ',measurementcurr
> > usbkeith.write("MEAS:VOLT?\n")
> > time.sleep(timesleepdefault)
> > measurementvolt=usbkeith.readline()
> > print 'Measured voltage 1: ',measurementvolt
> > keithdata.write(measurementcurr.strip()+' '+measurementvolt)
>
> [3 near repetitions snipped]
>
> This sort of repetitious code without even line breaks is painful for me
> to read. Python has looping statements for a reason. Replace all four
> nearly identical blocks with the following. (If you are not familiar
> with built-in enumerate, you should be. Read its entry in the library
> manual.)
>
> for number, current_in in enumerate(
>      ('0.025', '0.050'. '0.075', '0.100'), 1)
>    usbkeith.write(":SOUR:CURR %s\n" % current_in)
>    ...
>    print 'Measured current %d: ' % number, measurementcurr
>    ...
>    print 'Measured voltage %d: ' % number, measurementvolt
>
> Now you can make changes in only one place and easily add more test values.
>
> > print "Goodbye, data logged in file:"
> > print filename
> > usbkeith.close()
> > keithdata.close()
>
> > can anyone here what is going wrong and how to get it right?
>
> No, but if both the python and octave programs used loops, it would be
> easier to see if both are doing the same things before, within, and
> after the loop.
>
> --
> Terry Jan Reedy
I followed your suggestion an now the code looks like this:
#!/usr/bin/python
import time
import os
import sys
measurementcurr=''
measurementvolt=''
timesleepdefault=2
filename ='mydata.txt'
usbkeith = open('/dev/usbtmc1','r+')
usbkeith.flush()
usbkeith.write("*IDN?\n")
#strip blank line:
identification=usbkeith.readline().strip()
print 'Found device: ',identification
usbkeith.write("SYST:REM" + "\n")
usbkeith.write(":SENS:VOLT:PROT 1.5\n")
keithdata = open(filename,'w')
usbkeith.write(":OUTP:STAT ON\n")
for number, current_in in enumerate(('0.025', '0.050', '0.075',
'0.100'), 1):
   usbkeith.write(":SOUR:CURR %s\n" % current_in)
   time.sleep(timesleepdefault)
   usbkeith.write(":MEAS:CURR?\n")
   measurementcurr=usbkeith.readline()
   print 'Measured current %d: ' % number, measurementcurr
   usbkeith.write(":MEAS:VOLT?\n")
   measurementvolt=usbkeith.readline()
   print 'Measured voltage %d: ' % number, measurementvolt
   keithdata.write(measurementcurr.strip()+' '+measurementvolt)
usbkeith.write(":OUTP:STAT OFF\n")
print "Goodbye, data logged in file:"
print filename
usbkeith.close()
keithdata.close()

Still there is a "buffer-problem" as you can see in the output below:
0.00639725 0.0104065; these values are completely wrong
0.0248976 0.262959; these should have been be the first values
0.0500431 0.516602: these should been the second values
0.0749168 0.772616; these are the 3rd values
 4th values are missing

any idea why this does what it does in Python?

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


Re: problem with usbtmc-communication

2012-12-06 Thread Jean Dubois
On 6 dec, 15:50, w...@mac.com wrote:
> On Dec 6, 2012, at 8:50 AM, Jean Dubois  wrote:
>
> [byte]
>
>
>
>
>
>
>
>
>
>
>
> > It seems there is some misunderstanding here. What I meant with  how
> > to "do the equivalent in Python" refered to  "reading characters
> > rather than lines".
> > I have written working code myself for another Keithleu which does use
> > RS232 for communication. The problem now is specifically for the new
> > Keithley which doesn't allow RS232 but only USB-communication over
> > usbtmc. So if the "buffer-problem" could be changed by reading
> > characters that would be great.
>
> > regards,
> > Jean
>
> > --
> >http://mail.python.org/mailman/listinfo/python-list
>
> Sorry about the misunderstanding (and subsequent waste of bandwidth).  
> However, if you will look at the serial reads and writes in that handler, you 
> will see that it does things like "serial.read(n)" where "n" is an explicit 
> number, the number of bytes to be read from the serial buffer.
>
> -Bill
I tried changing measurementcurr=usbkeith.readline() to
measurementcurr=usbkeith.read(1)
but this leads to trouble with the usbtmc-thing:

Measured current 1:
Traceback (most recent call last):
  File "./keith2200rev2.py", line 26, in 
measurementvolt=usbkeith.read(1)
IOError: [Errno 110] Connection timed out

and hereafter I need to restart the Keithley...:-(

regards,
Jean
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem with usbtmc-communication

2012-12-07 Thread Jean Dubois
On 6 dec, 21:15, w...@mac.com wrote:
> On Dec 6, 2012, at 2:41 PM, Jean Dubois  wrote:
>
>
>
>
>
>
>
>
>
> > On 6 dec, 15:50, w...@mac.com wrote:
> >> On Dec 6, 2012, at 8:50 AM, Jean Dubois  wrote:
>
> >> [byte]
>
> >>> It seems there is some misunderstanding here. What I meant with  how
> >>> to "do the equivalent in Python" refered to  "reading characters
> >>> rather than lines".
> >>> I have written working code myself for another Keithleu which does use
> >>> RS232 for communication. The problem now is specifically for the new
> >>> Keithley which doesn't allow RS232 but only USB-communication over
> >>> usbtmc. So if the "buffer-problem" could be changed by reading
> >>> characters that would be great.
>
> >>> regards,
> >>> Jean
>
> >>> --
> >>>http://mail.python.org/mailman/listinfo/python-list
>
> >> Sorry about the misunderstanding (and subsequent waste of bandwidth).  
> >> However, if you will look at the serial reads and writes in that handler, 
> >> you will see that it does things like "serial.read(n)" where "n" is an 
> >> explicit number, the number of bytes to be read from the serial buffer.
>
> >> -Bill
> > I tried changing measurementcurr=usbkeith.readline() to
> > measurementcurr=usbkeith.read(1)
> > but this leads to trouble with the usbtmc-thing:
>
> > Measured current 1:
> > Traceback (most recent call last):
> >  File "./keith2200rev2.py", line 26, in 
> >    measurementvolt=usbkeith.read(1)
> > IOError: [Errno 110] Connection timed out
>
> > and hereafter I need to restart the Keithley...:-(
>
> > regards,
> > Jean
> > --
> >http://mail.python.org/mailman/listinfo/python-list
>
> Several comments:
>
> 1)  I can't be sure, but that would seem to be asking the Keithley to be 
> providing 10,000 readings.  I don't know about the GPIB bus (which this 
> USBTMC library seems to be trying >to emulate), but most serial devices 
> expect to provide one answer per read-write handshake.  That is, you send one 
> read command and get one answer back.  That answer may contain >several 
> bytes, but I'd be surprised it it contained 10,000.  The typical cycle is 
> something like send-an-initialize, read-status, send-mode-set-up, 
> read-status, send trigger >command, read-answer…  lather and repeat.   (Or 
> some logical equivalent of all that).  On the assumption that the USBTMC API 
> handles most of that, I'd try usbkeith.read(n) where >"n" is the number of 
> decimal digits you expect to get back plus sign.
1 wasn't a good guess indeed
> -
>
> 2) I took a quick look at the Keithley and National Instruments web sites 
> (where the documentation is at best, VERY poorly indexed and hard to search 
> for).  USBTMC *appears* to be a software layer designed to allow newer 
> Tektronix and Keithley instruments to be driven using older software that 
> drove GPIB equipment.  To make matters worse, if I'm reading it right (I 
> didn't study in detail) it appears to ALSO be providing a GPIB-like API to 
> Windows versions of National Instruments LabView.
>
> 3)  If I understand what you are trying to do, you want to go straight from 
> python to the Keithley USB port, without detouring (USB-to-GPIB and GPIB back 
> to USB).
>
Yes indeed, that's exactly what I want

> 4)  I did find (but did not try to read in detail) the following link:  
> http://www.ni.com/white-paper/4478/en which documents direct USB control of 
> instruments.  The python serial >library provides quite transparent control 
> of reading and writing to the USB interface.  Maybe following this link will 
> get you going.
Thanks for the link, but as you can see there they want to push NI-
VISA forward as the solution, which under Linux means more complexity
and surely isn't as simple to install as they claim, so if possible
I'd avoid ni-visa.

I'll experiment further Monday with read() and keep you informed

regards,
Jean


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


Re: problem with usbtmc-communication

2012-12-07 Thread Jean Dubois
On 6 dec, 21:28, Terry Reedy  wrote:
> On 12/6/2012 10:44 AM, Jean Dubois wrote:
>
>
>
>
>
>
>
>
>
> > I followed your suggestion an now the code looks like this:
> > #!/usr/bin/python
> > import time
> > import os
> > import sys
> > measurementcurr=''
> > measurementvolt=''
> > timesleepdefault=2
> > filename ='mydata.txt'
> > usbkeith = open('/dev/usbtmc1','r+')
> > usbkeith.flush()
> > usbkeith.write("*IDN?\n")
> > #strip blank line:
> > identification=usbkeith.readline().strip()
> > print 'Found device: ',identification
> > usbkeith.write("SYST:REM" + "\n")
> > usbkeith.write(":SENS:VOLT:PROT 1.5\n")
> > keithdata = open(filename,'w')
> > usbkeith.write(":OUTP:STAT ON\n")
> > for number, current_in in enumerate(('0.025', '0.050', '0.075',
> > '0.100'), 1):
> >     usbkeith.write(":SOUR:CURR %s\n" % current_in)
> >     time.sleep(timesleepdefault)
> >     usbkeith.write(":MEAS:CURR?\n")
> >     measurementcurr=usbkeith.readline()
> >     print 'Measured current %d: ' % number, measurementcurr
> >     usbkeith.write(":MEAS:VOLT?\n")
> >     measurementvolt=usbkeith.readline()
> >     print 'Measured voltage %d: ' % number, measurementvolt
> >     keithdata.write(measurementcurr.strip()+' '+measurementvolt)
> > usbkeith.write(":OUTP:STAT OFF\n")
> > print "Goodbye, data logged in file:"
> > print filename
> > usbkeith.close()
> > keithdata.close()
>
> > Still there is a "buffer-problem" as you can see in the output below:
> > 0.00639725 0.0104065; these values are completely wrong
> > 0.0248976 0.262959; these should have been be the first values
> > 0.0500431 0.516602: these should been the second values
> > 0.0749168 0.772616; these are the 3rd values
> >                       4th values are missing
>
> > any idea why this does what it does in Python?
>
> I am not familiar with the protocol at all, but my guess (without
> looking at the octave code) is that two of these three commands
>
>  > usbkeith.write("SYST:REM" + "\n")
>  > usbkeith.write(":SENS:VOLT:PROT 1.5\n")
>  > usbkeith.write(":OUTP:STAT ON\n")
>
> before the loop have responses that you need to read (and toss?)
No they don't need to have there responses be red,
first command sets remote mode
second command sets limit on voltage across output terminals
3rd command connects terminals with DUT


> usbkeith.readline(); usbkeith.readline()
This doesn't work because nothing is sent back
> so that the first values you read in the loop are the one that should be
> first. In other words, make sure the read buffer is clear before the loop.
>
> --
> Terry Jan Reedy

I'll look at it further monday

regards,
jean
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem with usbtmc-communication

2012-12-10 Thread Jean Dubois
On 7 dec, 14:46, Jean Dubois  wrote:
> On 6 dec, 21:15, w...@mac.com wrote:
>
> > On Dec 6, 2012, at 2:41 PM, Jean Dubois  wrote:
>
> > > On 6 dec, 15:50, w...@mac.com wrote:
> > >> On Dec 6, 2012, at 8:50 AM, Jean Dubois  wrote:
>
> > >> [byte]
>
> > >>> It seems there is some misunderstanding here. What I meant with  how
> > >>> to "do the equivalent in Python" refered to  "reading characters
> > >>> rather than lines".
> > >>> I have written working code myself for another Keithleu which does use
> > >>> RS232 for communication. The problem now is specifically for the new
> > >>> Keithley which doesn't allow RS232 but only USB-communication over
> > >>>usbtmc. So if the "buffer-problem" could be changed by reading
> > >>> characters that would be great.
>
> > >>> regards,
> > >>> Jean
>
> > >>> --
> > >>>http://mail.python.org/mailman/listinfo/python-list
>
> > >> Sorry about the misunderstanding (and subsequent waste of bandwidth).  
> > >> However, if you will look at the serial reads and writes in that 
> > >> handler, you will see that it does things like "serial.read(n)" where 
> > >> "n" is an explicit number, the number of bytes to be read from the 
> > >> serial buffer.
>
> > >> -Bill
> > > I tried changing measurementcurr=usbkeith.readline() to
> > > measurementcurr=usbkeith.read(1)
> > > but this leads to trouble with theusbtmc-thing:
>
> > > Measured current 1:
> > > Traceback (most recent call last):
> > >  File "./keith2200rev2.py", line 26, in 
> > >    measurementvolt=usbkeith.read(1)
> > > IOError: [Errno 110] Connection timed out
>
> > > and hereafter I need to restart the Keithley...:-(
>
> > > regards,
> > > Jean
> > > --
> > >http://mail.python.org/mailman/listinfo/python-list
>
> > Several comments:
>
> > 1)  I can't be sure, but that would seem to be asking the Keithley to be 
> > providing 10,000 readings.  I don't know about the GPIB bus (which 
> > thisUSBTMClibrary seems to be trying >to emulate), but most serial devices 
> > expect to provide one answer per read-write handshake.  That is, you send 
> > one read command and get one answer back.  That answer may contain >several 
> > bytes, but I'd be surprised it it contained 10,000.  The typical cycle is 
> > something like send-an-initialize, read-status, send-mode-set-up, 
> > read-status, send trigger >command, read-answer…  lather and repeat.   (Or 
> > some logical equivalent of all that).  On the assumption that theUSBTMCAPI 
> > handles most of that, I'd try usbkeith.read(n) where >"n" is the number of 
> > decimal digits you expect to get back plus sign.
>
> 1 wasn't a good guess indeed> -
>
> > 2) I took a quick look at the Keithley and National Instruments web sites 
> > (where the documentation is at best, VERY poorly indexed and hard to search 
> > for).  USBTMC*appears* to be a software layer designed to allow newer 
> > Tektronix and Keithley instruments to be driven using older software that 
> > drove GPIB equipment.  To make matters worse, if I'm reading it right (I 
> > didn't study in detail) it appears to ALSO be providing a GPIB-like API to 
> > Windows versions of National Instruments LabView.
>
> > 3)  If I understand what you are trying to do, you want to go straight from 
> > python to the Keithley USB port, without detouring (USB-to-GPIB and GPIB 
> > back to USB).
>
> Yes indeed, that's exactly what I want
>
> > 4)  I did find (but did not try to read in detail) the following link:  
> > http://www.ni.com/white-paper/4478/en which documents direct USB control of 
> > instruments.  The python serial >library provides quite transparent control 
> > of reading and writing to the USB interface.  Maybe following this link 
> > will get you going.
>
> Thanks for the link, but as you can see there they want to push NI-
> VISA forward as the solution, which under Linux means more complexity
> and surely isn't as simple to install as they claim, so if possible
> I'd avoid ni-visa.
>
> I'll experiment further Monday with read() and keep you informed
>
> regards,
> Jean
I changed the program as below an experimentally found out I have to
use an number of characters between 11 and 4095
I do

Re: problem with usbtmc-communication

2012-12-10 Thread Jean Dubois
On 10 dec, 16:34, w...@mac.com wrote:
> On Dec 10, 2012, at 8:31 AM, Jean Dubois  wrote:
>
> [byte]
>
>
>
>
>
>
>
>
>
> > As you can see this approach suffers from the same "buffer problem" as
> > the approach with readline did. One now good argue as a workaround:
> > get rid of the first data pair and add an extra measure command for
> > the missing data pair, however this still does not explain why this
> > problem is there in Python and not in Octave and I also fear I'll get
> > more trouble when sending combined commands e.g. such as that to
> > create a staircase current
> > So my question is, how to modify the Python-code such that the first
> > data pair is indeed the first data pair
>
> > thanks,
> > jean
>
> > Here follows the new code:
> > #!/usr/bin/python
> > import time
> > import os
> > import sys
> > measurementcurr=''
> > measurementvolt=''
> > timesleepdefault=5
> > print "Enter a numofchar (11 = > numofchar = int(raw_input())
> > filename ='mydata.txt'
> > usbkeith = open('/dev/usbtmc1','r+')
> > usbkeith.flush()
> > usbkeith.write("*IDN?\n")
>
> It seems like a real leap of faith to be opening /dev/usbtmc1 as though it 
> were a file-oriented device.  I've never heard of ANY instrument interface 
> implemented this way.
> Where did you see example code that did that.
I found examples in the usbtmc kernel driver documentation (the
examples there are given in C):
http://www.home.agilent.com/upload/cmc_upload/All/usbtmc.htm?&cc=BE&lc=dut


>  Have you tried to access /dev/usbtmc1 as though it were a serial device?
Yes, I did, as I used to do when communicating with rs232 devices. I
first tried to communicate to with the Keithley using cutecom but I
soon discovered you can't work that way because as soon as you open
the device it closes immediately thereafter. You really have to use
usbtmc (unfortunately) I'm missing the correct "flushing commands" to
do it correctly in Python...Maybe I should try to call the octave code
from within Python?


thanks
jean
>
>
>
>
>
>
>
> > #strip blank line:
> > identification=usbkeith.readline().strip()
> > print 'Found device: ',identification
> > usbkeith.write("SYST:REM" + "\n")
> > usbkeith.write(":SENS:VOLT:PROT 1.5\n")
> > keithdata = open(filename,'w')
> > usbkeith.write(":OUTP:STAT ON\n")
> > for number, current_in in enumerate(('0.025', '0.050', '0.075',
> > '0.100'), 1):
> >   usbkeith.write(":SOUR:CURR %s\n" % current_in)
> >   time.sleep(timesleepdefault)
> >   usbkeith.write(":MEAS:CURR?\n")
> >   measurementcurr=usbkeith.read(numofchar)
> >   print 'Measured current %d: ' % number, measurementcurr
> >   usbkeith.write(":MEAS:VOLT?\n")
> >   measurementvolt=usbkeith.read(numofchar)
> >   print 'Measured voltage %d: ' % number, measurementvolt
> >   keithdata.write(measurementcurr.strip()+' '+measurementvolt)
> > usbkeith.write(":OUTP:STAT OFF\n")
> > print "Goodbye, data logged in file:"
> > print filename
> > usbkeith.close()
> > keithdata.close()
> > --
> >http://mail.python.org/mailman/listinfo/python-list

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


Re: problem with usbtmc-communication

2012-12-11 Thread Jean Dubois
On 11 dec, 15:34, w...@mac.com wrote:
> On Dec 11, 2012, at 1:58 AM, Jean Dubois  wrote:
>
>
>
>
>
>
>
>
>
> > On 10 dec, 16:34, w...@mac.com wrote:
> >> On Dec 10, 2012, at 8:31 AM, Jean Dubois  wrote:
>
> >> [byte]
> >>> As you can see this approach suffers from the same "buffer problem" as
> >>> the approach with readline did. One now good argue as a workaround:
> >>> get rid of the first data pair and add an extra measure command for
> >>> the missing data pair, however this still does not explain why this
> >>> problem is there in Python and not in Octave and I also fear I'll get
> >>> more trouble when sending combined commands e.g. such as that to
> >>> create a staircase current
> >>> So my question is, how to modify the Python-code such that the first
> >>> data pair is indeed the first data pair
>
> >>> thanks,
> >>> jean
>
> >>> Here follows the new code:
> >>> #!/usr/bin/python
> >>> import time
> >>> import os
> >>> import sys
> >>> measurementcurr=''
> >>> measurementvolt=''
> >>> timesleepdefault=5
> >>> print "Enter a numofchar (11 = >>> numofchar = int(raw_input())
> >>> filename ='mydata.txt'
> >>> usbkeith = open('/dev/usbtmc1','r+')
> >>> usbkeith.flush()
> >>> usbkeith.write("*IDN?\n")
>
> >> It seems like a real leap of faith to be opening /dev/usbtmc1 as though it 
> >> were a file-oriented device.  I've never heard of ANY instrument interface 
> >> implemented this way.
> >> Where did you see example code that did that.
> > I found examples in theusbtmckernel driver documentation (the
> > examples there are given in C):
> >http://www.home.agilent.com/upload/cmc_upload/All/usbtmc.htm?&cc=BE&l...
>
> OK - I see where the examples came from, and I notice -
>
>         int my_inst;
>         my_inst=open(“/dev/usbtmc1”,O_RDWR);
>         write(my_inst,”*RST\n”,5);
>         close(my_inst);
>
> and similarly in another place -
>
>         retval=write(myfile,"*IDN?\n",6);
>
> Note that both write commands contain a byte count of the number of 
> characters to be written (\n counts as one character).
> Again, the read commands contain byte counts.  I'm very suspicious that a 
> write command with no byte count writes nothing, but does move a buffer 
> pointer.
>
> -Bill

Does Python support/implement simular commands? Can I use
usbkeith.write("*IDN?\n",6) and  something simular for the reading
commands?

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


Re: problem with usbtmc-communication

2012-12-12 Thread Jean Dubois
On 12 dec, 01:49, Jerry Hill  wrote:
> On Tue, Dec 11, 2012 at 1:58 AM, Jean Dubois  wrote:
>
> > I found examples in theusbtmckernel driver documentation (the
> > examples there are given in C):
> >http://www.home.agilent.com/upload/cmc_upload/All/usbtmc.htm?&cc=BE&l...
>
> Thanks for that link.  I think it explains how the driver works pretty
> well.  I haven't done any work with devices like this, but I see a few
> things in those docs that might help.
>
> In their example code, they open the device with: open(“/dev/usbtmc1”,O_RDWR);
>
> That's not exactly the same as what you've been doing.  I would try
> opening the file this way in python:
> usb_device = open('/dev/usbtmc1', 'w+', buffering=0)
>
> That truncates the file after it opening it, and disables any
> buffering that might be going on.
>
> Then, I would try writing to the device with usb_device.write() and
> usb_device.read().  read() attempts to read to end-of-file, and based
> on the docs, the driver will work okay that way.  Doing that, along
> with turning off buffering when you open the file, should eliminate
> any issues with the driver failing to emit newlines someplace.
>
> Personally, I would probably try playing with the device from python's
> interactive interpreter.  I think that could shed a lot of light on
> the behavior you're seeing.
>
> --
> Jerry

Thanks a thousand times Jerry!!!, the buffering issue has disappeared
after following your recommendations. The test program now looks like
below and performs as expected.

#!/usr/bin/python
import time
import os
import sys
timesleepdefault=5
print "Enter name of data file",
filename = raw_input()
#the following line is very important, especially the buffering=0
usbkeith = open('/dev/usbtmc1','w+', buffering=0)
usbkeith.write("*IDN?\n")
identification=usbkeith.read().strip()
print 'Found device: ',identification
usbkeith.write("SYST:REM" + "\n")
usbkeith.write(":SENS:VOLT:PROT 1.5\n")
keithdata = open(filename,'w')
usbkeith.write(":OUTP:STAT ON\n")
for number, current_in in enumerate(('0.025', '0.050', '0.075',
'0.100'), 1):
   usbkeith.write(":SOUR:CURR %s\n" % current_in)
   time.sleep(timesleepdefault)
   usbkeith.write(":MEAS:CURR?\n")
   measurementcurr=usbkeith.read()
   print 'Measured current %d: ' % number, measurementcurr
   usbkeith.write(":MEAS:VOLT?\n")
   measurementvolt=usbkeith.read()
   print 'Measured voltage %d: ' % number, measurementvolt
   keithdata.write(measurementcurr.strip()+' '+measurementvolt)
usbkeith.write(":OUTP:STAT OFF\n")
print "Goodbye, data logged in file:"
print filename
usbkeith.close()
keithdata.close()

regards,
Jean
-- 
http://mail.python.org/mailman/listinfo/python-list


[newbie] problem making equally spaced value array with linspace

2012-12-18 Thread Jean Dubois
I have trouble with the code beneath to make an array with equally
spaced values
When I enter 100e-6 as start value, 700e-6 as end value and 100e-6 I
get the following result:
[ 0.0001   0.00022  0.00034  0.00046  0.00058  0.0007 ]
But I was hoping for:
[ 0.0001   0.0002  0.0003  0.0004  0.0005  0.0006 0.0007]
It works correctly for other values like 1,7,1 but not for 0.1,0.7,0.1
then again for 0.01,0.07,0.01

What I find strange is that for the 1st example "1+abs(float(endvalue)-
float(startvalue))/float(incr)" gives 7.0 but int() of this value
gives 6
can someone provide help with this issue?
thanks
jean

#!/usr/bin/python
import math
import numpy as np
print "Enter start value as a float (e.g. 0.001) or in scientific
notation (e.g. 1e-3): ",
startvalue = raw_input()
print "Enter end value: ",
endvalue = raw_input()
print "Enter step: ",
incr = raw_input()
#nom = number of measurements
nom=int(1+abs(float(endvalue)-float(startvalue))/float(incr))
array=np.linspace(float(startvalue), float(endvalue), float(nom))
print "Array with current values: ",array
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem making equally spaced value array with linspace

2012-12-18 Thread Jean Dubois
On 18 dec, 14:09, Peter Otten <__pete...@web.de> wrote:
> Jean Dubois wrote:
> > I have trouble with the code beneath to make an array with equally
> > spaced values
> > When I enter 100e-6 as start value, 700e-6 as end value and 100e-6 I
> > get the following result:
> > [ 0.0001   0.00022  0.00034  0.00046  0.00058  0.0007 ]
> > But I was hoping for:
> > [ 0.0001   0.0002  0.0003  0.0004  0.0005  0.0006 0.0007]
> > It works correctly for other values like 1,7,1 but not for 0.1,0.7,0.1
> > then again for 0.01,0.07,0.01
>
> > What I find strange is that for the 1st example "1+abs(float(endvalue)-
> > float(startvalue))/float(incr)" gives 7.0 but int() of this value
> > gives 6
> > can someone provide help with this issue?
> > thanks
> > jean
>
> > #!/usr/bin/python
> > import math
> > import numpy as np
> > print "Enter start value as a float (e.g. 0.001) or in scientific
> > notation (e.g. 1e-3): ",
> > startvalue = raw_input()
> > print "Enter end value: ",
> > endvalue = raw_input()
> > print "Enter step: ",
> > incr = raw_input()
> > #nom = number of measurements
> > nom=int(1+abs(float(endvalue)-float(startvalue))/float(incr))
> > array=np.linspace(float(startvalue), float(endvalue), float(nom))
> > print "Array with current values: ",array
>
> If you repeat the calculation of the number of intervals in the interpreter
> you get
>
> >>> 1 + abs(0.0007-0.0001)/0.0001
>
> 6.999
>
> Many numbers cannot be represented exactly as float (that's the price you
> have to pay for covering a wide range with just a few (8) bytes), and you
> have introduced such a small error. The subsequent int() call will round
> that float to the integer below it:
>
> >>> int(_)
>
> 6
>
> While applying round() would work here
>
> >>> int(round(1 + abs(0.0007-0.0001)/0.0001))
>
> 7
>
> there is no once-and-for-all solution to the underlying problem. E. g.
>
> >>> x = 2.**53
> >>> x == x + 1
>
> True

thanks

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


convert perl-script for voltcraft voltmeter to python [newbie]

2012-02-06 Thread Jean Dupont
I'd like to read in the output of a voltcraft vc960 voltmeter
connected to a usb-port.
I found the perl-script below but I'd like to accomplish the same with
python:
I guess I have to use the module serial but I don't know how I should
set the serial parameters so they are the same as in the perl-script.
Could someone supply me the command for setting the serial-parameters
correctly
in Python?

thanks
Jean

#!/usr/bin/perl

use strict;
use warnings;

use Device::SerialPort;

die("Usage: $0 /dev/ttyS0\n") unless $#ARGV == 0;

my ($devicepath) = @ARGV;

my $port = new Device::SerialPort($devicepath);
die "Couldn't open serial port" if ! defined $port;

$port->baudrate(2400);
$port->databits(8);
$port->parity("none");
$port->stopbits(1);
$port->handshake("none");
$port->rts_active(0);
$port->dtr_active(1);

#$port->read_char_time(5); # wait 5ms per character
$port->read_const_time(200);   # 0.2 second per unfulfilled "read"
call
$| = 1; # autoflush STDOUT
while(1) {
my ($nin, $in) = $port->read(255);
print $in;
}

$port->close;
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: convert perl-script for voltcraft voltmeter to python [newbie]

2012-02-06 Thread Jean Dupont
As my request might have been too much asked, I have started doing
some coding myself.
I'm in doubt about the readline statement -which doesn't show anything
received- as the meter sends continuously streams of 11 bytes
Is there a way to just monitor with python what is arriving at a
serial port?

#!/usr/bin/python
#version 1-2-2012, script to read data from voltcraft vc940-meter
import serial, time, os
voltport='/dev/ttyUSB2'
print "Be sure the Voltcraft is connected to ttyUSB2"
print "Enter a filename:",
filename = raw_input()
voltdata = open(filename,'w')
ser2 = serial.Serial(voltport, 2400, 8, serial.PARITY_NONE, 1,
timeout=15)
print "rs-232 parameters of Voltcraft: ", ser2
print "Opening " + ser2.portstr
received=ser2.readline()
print received
print "Goodbye, data logged in file:"
print filename
ser2.close()
# Close file
voltdata.close()




On 2 feb, 21:57, Jean Dupont  wrote:
> I'd like to read in the output of a voltcraft vc960 voltmeter
> connected to a usb-port.
> I found the perl-script below but I'd like to accomplish the same with
> python:
> I guess I have to use the module serial but I don't know how I should
> set the serial parameters so they are the same as in the perl-script.
> Could someone supply me the command for setting the serial-parameters
> correctly
> in Python?
>
> thanks
> Jean
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> use Device::SerialPort;
>
> die("Usage: $0 /dev/ttyS0\n") unless $#ARGV == 0;
>
> my ($devicepath) = @ARGV;
>
> my $port = new Device::SerialPort($devicepath);
> die "Couldn't open serial port" if ! defined $port;
>
> $port->baudrate(2400);
> $port->databits(8);
> $port->parity("none");
> $port->stopbits(1);
> $port->handshake("none");
> $port->rts_active(0);
> $port->dtr_active(1);
>
> #$port->read_char_time(5);     # wait 5ms per character
> $port->read_const_time(200);   # 0.2 second per unfulfilled "read"
> call
> $| = 1; # autoflush STDOUT
> while(1) {
>         my ($nin, $in) = $port->read(255);
>         print $in;
>
> }
>
> $port->close;

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


pySerial question, setting certain serial parameters [newbie]

2012-02-06 Thread Jean Dupont
I need to set the following options I found in a Perl-script in Python for 
serial communication with a device (a voltmeter):

$port->handshake("none");
$port->rts_active(0);
$port->dtr_active(1); 

I have thus far the following  statements but I think it does not set the above 
parameters correctly:
import serial
voltport='/dev/ttyUSB2'
ser2 = serial.Serial(voltport, 2400, 8, serial.PARITY_NONE, 1,timeout=15) 

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


how to read serial stream of data [newbie]

2012-02-06 Thread Jean Dupont
I'd like to read in a stream of data which looks like this:
the device sends out a byte-string of 11 bytes roughly every second:

B0B0B0B0B03131B0B50D8A
B0B0B0B0B03131B0B50D8A
B0B0B031B63131B0310D8A
B0B034B3323432B3310D8A
B0B03237B53432B3310D8A
.
.
.

As you see every string is ended by 0D8A
How can this be accomplished in Python?


thanks

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


Re: how to read serial stream of data [newbie]

2012-02-07 Thread Jean Dupont
On 7 feb, 06:07, Roy Smith  wrote:
> In article
> ,
>  Jean Dupont  wrote:
>
> > I'd like to read in a stream of data which looks like this:
> > the device sends out a byte-string of 11 bytes roughly every second:
>
> >     B0B0B0B0B03131B0B50D8A
> >     B0B0B0B0B03131B0B50D8A
> >     B0B0B031B63131B0310D8A
> >     B0B034B3323432B3310D8A
> >     B0B03237B53432B3310D8A
> > .
> > .
> > .
>
> > As you see every string is ended by 0D8A
> > How can this be accomplished in Python?
>
> The basic idea would be to open your datastream in binary mode
> (http://docs.python.org/library/functions.html#open), then use read(11)
> to read exactly 11 bytes into a string.
>
> Depending on what the 11 bytes are, you might want to use the struct
> module (http://docs.python.org/library/struct.html) to extract the data
> in a more useful form.

Thank you very much for taking the time to reply. I'm really
completely new to python and all help is really very welcome.
In the documentation I read that to open the datastream binary I need
to add the option b
this is how far I got until now:
#!/usr/bin/python
import serial, time, os
voltport='/dev/ttyUSB2'
print "Enter a filename:",
filename = raw_input()
voltdata = open(filename,'wb')
ser2 = serial.Serial(voltport, 2400, 8, serial.PARITY_NONE, 1,
rtscts=0, dsrdtr=0, timeout=15)
ser2.setDTR(level=True)
print "State of DSR-line: ", ser2.getDSR()
#the following line was added because I want to be sure that all
parameters are set the same as under a working application for the
same device
os.system("stty -F31:0:bbb:
0:0:0:0:0:0:0:1:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0")
print "Opening " + ser2.portstr
s =ser2.read(11) #read up to 11bytes
voltdata.write(s)
ser2.close()
voltdata.close()

However the above code doesn't fill my file with data, I guess the
data should also be flushed somewhere in the code but I'm unsure where
to do that.
A futher consideration: because the device sends its data continuously
I guess I'd have to use the byte sequence 0D8A of the previously sent
data string as an indicator that the next 9 bytes are those I really
want and put those in a string which than coudl be written to the file

all help welcome
Jean
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to read serial stream of data [newbie]

2012-02-07 Thread Jean Dupont
On 7 feb, 15:04, Heiko Wundram  wrote:
> Am 07.02.2012 14:48, schrieb Antti J Ylikoski:
>
> > On 7.2.2012 14:13, Jean Dupont wrote:
> >> ser2 = serial.Serial(voltport, 2400, 8, serial.PARITY_NONE, 1,
> >> rtscts=0, dsrdtr=0, timeout=15)
>
> > In Python, if you want to continue the source line into the next text
> > line, you must end the line to be continued with a backslash '\'.
>
> Absolutely not true, and this is bad advice (stylistically).
>
> When (any form of) brackets are open at the end of a line, Python does
> not start a new command on the next line but rather continues the
> backeted content.
>
> So:
>
> ser2 = serial.Serial(voltport, 2400, 8, serial.PARITY_NONE, 1,
>                       rtscts=0, dsrdtr=0, timeout=15)
>
> is perfectly fine and certainly the recommended way of putting this.
>
> Adding the backslash-continuation is always _possible_, but only
> _required_ when there are no open brackets.
>
> So:
>
> x = "hello" \
>      " test"
>
> is equivalent to:
>
> x = ("hello"
>       " test")
>
> in assigning:
>
> x = "hello test"
>
> --
> --- Heiko.

Hello to all who gave advice concerning the line continuation, in fact
this was not a real problem but happened by accident
copying and pasting my program lines. Advice concerning the empty file
would of course also be very much appreciated.

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


Re: convert perl-script for voltcraft voltmeter to python [newbie]

2012-02-07 Thread Jean Dupont
On 7 feb, 05:21, Terry Reedy  wrote:
> On 2/2/2012 3:57 PM, Jean Dupont wrote:
>
> > I'd like to read in the output of a voltcraft vc960 voltmeter
> > connected to a usb-port.
> > I found the perl-script below but I'd like to accomplish the same with
> > python:
>
> The script below is for an old-fashioned, slow, multiple-pin serial
> port, not usb. I don't know anything about interfacing through usb.
> Recheck what the voltmeter actually connects to.
The voltmeter uses an optical rs232-connection, that is "good enough
technology" for this purpose. But as I don't have a computer with real
rs232 ports I use a rs232toUSB adapter which presents itself to the
linux-computer as /dev/ttyUSBx.
>
> > I guess I have to use the module serial but I don't know how I should
> > set the serial parameters so they are the same as in the perl-script.
> > Could someone supply me the command for setting the serial-parameters
> > correctly in Python?
>
> Last I know, pyserial is also for old serial ports. Setting the
> properties should be pretty obvious from the manual or code.
>
It is not so obvious as you might think, one reason being the
handshake line(s?) are used in an unconvential way to supply power to
the rs232-optical interface
> There are also python usb 
> modules.http://sourceforge.net/projects/mysql-python/?source=directory
I followed this link but all I found was something concerning
mysql...???
>
anyway, thanks for trying to help

Jean
>
>
>
>
>
>
> > #!/usr/bin/perl
>
> > use strict;
> > use warnings;
>
> > use Device::SerialPort;
>
> > die("Usage: $0 /dev/ttyS0\n") unless $#ARGV == 0;
>
> > my ($devicepath) = @ARGV;
>
> > my $port = new Device::SerialPort($devicepath);
> > die "Couldn't open serial port" if ! defined $port;
>
> > $port->baudrate(2400);
> > $port->databits(8);
> > $port->parity("none");
> > $port->stopbits(1);
> > $port->handshake("none");
> > $port->rts_active(0);
> > $port->dtr_active(1);
>
> > #$port->read_char_time(5);     # wait 5ms per character
> > $port->read_const_time(200);   # 0.2 second per unfulfilled "read"
> > call
> > $| = 1; # autoflush STDOUT
> > while(1) {
> >          my ($nin, $in) = $port->read(255);
> >          print $in;
> > }
>
> > $port->close;
>
> --
> Terry Jan Reedy

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


Re: convert perl-script for voltcraft voltmeter to python [newbie]

2012-02-08 Thread Jean Dupont
On 8 feb, 01:26, Dietmar Schwertberger  wrote:
> Am 03.02.2012 14:11, schrieb Jean Dupont:> As my request might have been too 
> much asked, I have started doing
> > some coding myself.
> > I'm in doubt about the readline statement -which doesn't show anything
> > received- as the meter sends continuously streams of 11 bytes
> > Is there a way to just monitor with python what is arriving at a
> > serial port?
>
> Some time ago I started working on reading data from a VC940.
> I would assume that the protocol is the same.
>
> Please find below the code that will return the raw values from
> a VC940 (tested on a classical RS232 port, but probably
> will work on USB-RS232 converters as well).
>
> If you don't get anything, then you should check whether your
> USB converter is supplying voltage on the DTR pin once you have called
> self.serial.setDTR(1).
>
> You have the description how to decode the values?
> E.g. the string "0003:1401" translates to 0.3 Ohms.
>
> I did not implement anything else, as I just wanted to be sure
> that I could read the values, but I never needed to...
>
> Regards,
>
> Dietmar
>
> import serial
> import time
>
> class VC940(object):
>      def __init__(self, port="COM3"):
>          self.port = port
>          self.serial=serial.Serial(port,2400, bytesize=7, parity="N",
> stopbits=1, timeout=1.5, xonxoff=0, rtscts=0, dsrdtr=None)
>          self.serial.setRTS(0)
>          self.serial.setDTR(0)
>      def _read_raw_value(self):
>          timeout = True
>          for n in range(5):
>              self.serial.flushInput()
>              self.serial.setDTR(1)
>              data = self.serial.read(11)
>              self.serial.setDTR(0)
>              if data.endswith("\r\n") and len(data)==11:
>                  return data
>              if not data:
>                  raise ValueError, "communication timeout"
>          raise ValueError, "could not read data from port"
>
> if __name__=="__main__":
>      vc = VC940()
>      while True:
>          print vc._read_raw_value()

Wow, this is great, it works like a charm. Thanks a lot!

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


Good data structure for finding date intervals including a given date

2012-05-12 Thread Jean-Daniel
Hello,

I have a long list of n date intervals that gets added or suppressed
intervals regularly. I am looking for a fast way to find the intervals
containing a given date, without having to check all intervals (less
than O(n)).

Do you know the best way to do this in Python with the stdlib?

A variant of the red black trees can do the job quickly [1], is this a
good enough use case to discuss the inclusion of a red black tree
implementation in the stdlib?

This has been discussed here: http://bugs.python.org/issue1324770 ,
and lack of good use case was the reason the bug was closed. A dict
implemented with red black trees is slower (but not too slow) at
inserting, searching and deleting but the dict is always kept ordered.
Bigger projects have their own implementation of ordered dict so such
datastructures in the standard library would help the porting of the
project to other platforms. Take the example of the zodb and the
C-only implementation of the btree: btree in the stdlib in Python
would help the porting to GAE or pypy [2].

Cheers,

[1] in the "Cormen" book:
http://en.wikipedia.org/wiki/Introduction_to_Algorithms
[2] https://blueprints.launchpad.net/zodb/+spec/remove-btree-dependency
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Good data structure for finding date intervals including a given date

2012-05-12 Thread Jean-Daniel
> Since you say "intervals" in plural here, I assume that they can overlap?

Yes,

For instance, there are the following intervals :
[[1, 10],
[4, 7],
[6, 15],
[11, 17]]

asking for the intervals including  5, the returned value should be

[[1, 10],
[4, 7]]

The idea here to make it fast is to have done some preprocessing at
insertion time, so that not all intervals are processed at query time.



On Sat, May 12, 2012 at 2:30 PM, Karl Knechtel  wrote:
> On Sat, May 12, 2012 at 8:17 AM, Jean-Daniel
>  wrote:
>> I am looking for a fast way to find the intervals
>> containing a given date, without having to check all intervals (less
>> than O(n)).
>
> Since you say "intervals" in plural here, I assume that they can overlap?
>
> --
> ~Zahlman {:>
> --
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Good data structure for finding date intervals including a given date

2012-05-16 Thread Jean-Daniel
On Sun, May 13, 2012 at 2:29 PM, Alec Taylor  wrote:
> There is an ordered dict type since Python 3.1[1] and Python 2.7.3[2].

Ordered dict are useful, but they only remember the ordered in which
they were added, you can not order them a on key.

Thanks for the links.

>
> If you are looking for the best possible self-sorting structure for
> searching, then perhaps you are looking for what's outlined in the
> 2002 article by Han & Thorup: Integer Sorting in O(n sqrt(log log n))
> Expected Time and Linear Space[3].
>
> [1] http://www.python.org/getit/releases/3.1/
> [2] http://www.python.org/getit/releases/2.7.3/
> [3] http://dl.acm.org/citation.cfm?id=645413.652131
>
> On Sat, May 12, 2012 at 10:17 PM, Jean-Daniel
>  wrote:
>>
>> Hello,
>>
>> I have a long list of n date intervals that gets added or suppressed
>> intervals regularly. I am looking for a fast way to find the intervals
>> containing a given date, without having to check all intervals (less
>> than O(n)).
>>
>> Do you know the best way to do this in Python with the stdlib?
>>
>> A variant of the red black trees can do the job quickly [1], is this a
>> good enough use case to discuss the inclusion of a red black tree
>> implementation in the stdlib?
>>
>> This has been discussed here: http://bugs.python.org/issue1324770 ,
>> and lack of good use case was the reason the bug was closed. A dict
>> implemented with red black trees is slower (but not too slow) at
>> inserting, searching and deleting but the dict is always kept ordered.
>> Bigger projects have their own implementation of ordered dict so such
>> datastructures in the standard library would help the porting of the
>> project to other platforms. Take the example of the zodb and the
>> C-only implementation of the btree: btree in the stdlib in Python
>> would help the porting to GAE or pypy [2].
>>
>> Cheers,
>>
>> [1] in the "Cormen" book:
>> http://en.wikipedia.org/wiki/Introduction_to_Algorithms
>> [2] https://blueprints.launchpad.net/zodb/+spec/remove-btree-dependency
>> --
>> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python vs Ruby

2005-10-19 Thread jean-marc
I'd believe that would be Lua, but then again what is common to one
might not be to another ;-)

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


Re: Python vs Ruby

2005-10-19 Thread jean-marc
As you see, pythonistas are a nice humourous bunch...
But to help a bit more in your balancing act you might take a look at:

http://blog.ianbicking.org/ruby-python-power.html

It's rather nice, and commented.

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


Re: textwidget.tag_bind("name", "", self.donothing) not working

2005-10-26 Thread jean-marc
but you don't want to use the state=DISABLED  option because it gray's
out the field showing people that it is not available for editing,
right?

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


Re: textwidget.tag_bind("name", "", self.donothing) not working

2005-10-26 Thread jean-marc
Sorry, kinda wrote over your intentions...

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


Re: textwidget.tag_bind("name", "", self.donothing) not working

2005-10-26 Thread jean-marc
To make amends, I tried my own search and came up with this (that you
might already have...):
http://groups.google.com/group/comp.lang.python/browse_thread/thread/1384f49c35ffba9b/5928092247429e9a%235928092247429e9a?sa=X&oi=groupsr&start=1&num=3

Maybe you'll understand it better than me  :-)

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


Calculating Elapsed Time

2005-12-06 Thread Jean Johnson
Hello - 

I have a start and end time that is written using the
following:

time.strftime("%b %d %Y  %H:%M:%S")

How do I calculate the elapsed time?

JJ



__ 
Yahoo! DSL – Something to write home about. 
Just $16.99/mo. or less. 
dsl.yahoo.com 

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


Re: Calculating Elapsed Time

2005-12-06 Thread Jean Johnson
I'm using an old version of python (2.1) and datetime
isn't available until Python 2.3.  I can't upgrade my
python.

--- [EMAIL PROTECTED] wrote:

> 
> Jean> How do I calculate the elapsed time?
> 
> Where t1_s and t2_s reference time strings in the
> format you describe:
> 
> import datetime
> import time
> 
> fmt = "%b %d %Y  %H:%M:%S"
> 
> t1 = datetime.datetime(*time.strftime(t1_s,
> fmt)[:6])
> t2 = datetime.datetime(*time.strftime(t2_s,
> fmt)[:6])
> dt = t2 - t1
> 
> should do the trick.
> 
> Skip
> 
> 




__ 
Yahoo! DSL – Something to write home about. 
Just $16.99/mo. or less. 
dsl.yahoo.com 

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


Re: Calculating Elapsed Time

2005-12-07 Thread Jean Johnson
Thanks to everyone for their e-mails.  I am using
Fredrik's strptime/mktime solution to calculate my
elapsed time.



__ 
Yahoo! DSL – Something to write home about. 
Just $16.99/mo. or less. 
dsl.yahoo.com 

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


Re: Excel module for Python

2005-01-18 Thread jean-paul
I generate a lot pseudo excel file. Just write row by row on file and
separate every cell of a row by a tab and put an .xls extension on the
file name. When you double click. It opens directly EXCEL and you have
directly the column and the row. It is easier than the CSV or SYLK
files. If you want to format it automatically you can either define a
VBA macro or use python com. 

Cheers,

Jean-Paul

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


problem with import pylab from a website

2005-01-19 Thread jean . rossier

Hello All,
I am facing a problem while importing pylab library(in a .py program file) via
web browser however the same program works when I execute it from the command
prompt.


my configuration :

Fedora Core 3
Apache 2.0
python 2.3.4
postgresql 7.3.4
mod_python-3.1.3-5

Error message we get:

[Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] Traceback (most
recent call last):, referer: http://128.178.156.101/sensor_data/readings.php
[Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101]   File
"/var/www/html/sensor_data/get_graph.py", line 15, in ?, referer:
http://128.178.156.101/sensor_data/readings.php
[Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] , referer:
http://128.178.156.101/sensor_data/readings.php
[Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] import pylab,
referer: http://128.178.156.101/sensor_data/readings.php
[Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101]   File
"/usr/lib/python2.3/site-packages/pylab.py", line 1, in ?, referer:
http://128.178.156.101/sensor_data/readings.php
[Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] , referer:
http://128.178.156.101/sensor_data/readings.php
[Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] from
matplotlib.pylab import *, referer:
http://128.178.156.101/sensor_data/readings.php
[Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101]   File
"/usr/lib/python2.3/site-packages/matplotlib/pylab.py", line 184, in ?, referer:
http://128.178.156.101/sensor_data/readings.php
[Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] , referer:
http://128.178.156.101/sensor_data/readings.php
[Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] from axes import
Axes, PolarAxes, referer: http://128.178.156.101/sensor_data/readings.php
[Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101]   File
"/usr/lib/python2.3/site-packages/matplotlib/axes.py", line 14, in ?, referer:
http://128.178.156.101/sensor_data/readings.php
[Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] , referer:
http://128.178.156.101/sensor_data/readings.php
[Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] from axis import
XAxis, YAxis, referer: http://128.178.156.101/sensor_data/readings.php
[Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101]   File
"/usr/lib/python2.3/site-packages/matplotlib/axis.py", line 20, in ?, referer:
http://128.178.156.101/sensor_data/readings.php
[Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] , referer:
http://128.178.156.101/sensor_data/readings.php
[Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] from font_manager
import FontProperties, referer: http://128.178.156.101/sensor_data/readings.php
[Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101]   File
"/usr/lib/python2.3/site-packages/matplotlib/font_manager.py", line 942, in ?,
referer: http://128.178.156.101/sensor_data/readings.php
[Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] , referer:
http://128.178.156.101/sensor_data/readings.php
[Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] fontManager =
FontManager(), referer: http://128.178.156.101/sensor_data/readings.php
[Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101]   File
"/usr/lib/python2.3/site-packages/matplotlib/font_manager.py", line 786, in
__init__, referer: http://128.178.156.101/sensor_data/readings.php
[Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] , referer:
http://128.178.156.101/sensor_data/readings.php
[Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] rebuild(), referer:
http://128.178.156.101/sensor_data/readings.php
[Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101]   File
"/usr/lib/python2.3/site-packages/matplotlib/font_manager.py", line 780, in
rebuild, referer: http://128.178.156.101/sensor_data/readings.php
[Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] , referer:
http://128.178.156.101/sensor_data/readings.php
[Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101]
pickle.dump(self.ttfdict, file(ttfcache, 'w')), referer:
http://128.178.156.101/sensor_data/readings.php
[Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] IOError, referer:
http://128.178.156.101/sensor_data/readings.php
[Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] : , referer:
http://128.178.156.101/sensor_data/readings.php
[Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] [Errno 13]
Permission denied: '/usr/share/matplotlib/.ttffont.cache', referer:
http://128.178.156.101/sensor_data/readings.php
[Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] , referer:
http://128.178.156.101/sensor_data/readings.php
[Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] Premature end of
script headers: get_graph.py, referer:
http://128.178.156.101/sensor_data/readings.php



Thanks in advance.

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


Re: how to use more than 1 __init__ constructor in a class ?

2005-06-23 Thread jean-marc


Singletoned wrote:
> Rocco Moretti wrote:
> > Steven D'Aprano wrote:
> 
> > > That's the joys of a mostly self-taught programming knowledge: you miss
> > > out on all the buzzwords.
> >
> > Being mostly self taught myself, I have a tendancy to use infrequently
> > encountered terms in related but technically inappropriate contexts,
> > confusing the better informed people I deal with. ;-)
>
> Indeed.  I find I use even more buzzwords because I can just make up as
> many as I want.
This thread 'branch' (humm, is this an appropriate term for the last
few quotes, going to Steven's?) is soothing in reminding us we are not
alone. That there is a sort of distributed 'Alma Mater' of the
'Teach-It-Yourself School of Computing', producing a virtual FOAF group
(Is FOAF, Friend Of A Friend or Flock Of A Feather?)

jm

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


Thanks for PIL (and other stuff)

2005-06-23 Thread jean-marc
I was just reading on daily-python that PIL is 10 years old...

So I wish it and its author(s) a good day, week, month, year and more!
Really!

Jean-Marc
PS If I knew that Python had a anniversary date, I'd also write to
thanks our BDFL (and authors)! But no such luck, so I'm restaining
myself!
;-))

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


Re: SOAP and XMLRPC

2005-08-15 Thread jean-marc
why isn't this good?
http://www.enappsys.com/backend.jsp
Seems to be what you're looking for...

(second entry of a googled 'xml-rpc visual basic' search!)

JM
PS Tell us why the refered *.dll don't do, so I won't refer to it again
if it's of no value.

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


Re: seeking Python developers

2005-08-15 Thread jean-marc
What level? and is geography important?

JM

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


Re: python classes taught

2005-08-20 Thread jean-marc
Cegep du Vieux Montreal (technical college level),  uses Python for CGI
in web developement class.

...At least when I give this course ;-)

Jean-Marc

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


Re: wxgrid multiline cell editor

2005-02-10 Thread jean-michel
"James" <[EMAIL PROTECTED]> a écrit dans le message de
news:[EMAIL PROTECTED]
> wxpython 2.5.3
> anyone know how to make a multiline cell editor for wxgrid?

Hello,

You can do that by a "wxGridCellAutoWrapStringEditor".
You can test it by modifying GridSimple.py in the demo by adding (at line 24
in my version):
self.SetRowSize(1, 45)
self.SetCellEditor(1, 1, wxGridCellAutoWrapStringEditor())
Save it and now, when you launch the gridsimple in the demo (it's in core
windows control), you can enter multiple lines in the cell containing
"Another cell". It works in 2.4.2.4. I think it should also in 2.5.

I join the whole program.
Have fun.
++jm

#---
from wxPython.wx import *
from wxPython.grid import *
from wxPython.lib.mixins.grid import wxGridAutoEditMixin

#---

class SimpleGrid(wxGrid): ##, wxGridAutoEditMixin):
def __init__(self, parent, log):
wxGrid.__init__(self, parent, -1)
##wxGridAutoEditMixin.__init__(self)
self.log = log
self.moveTo = None

EVT_IDLE(self, self.OnIdle)

self.CreateGrid(25, 25) #, wxGrid.wxGridSelectRows)
##self.EnableEditing(False)

# simple cell formatting
self.SetColSize(3, 200)
self.SetRowSize(4, 45)
self.SetCellValue(0, 0, "First cell")
self.SetCellValue(1, 1, "Another cell")
self.SetRowSize(1, 45)
self.SetCellEditor(1, 1, wxGridCellAutoWrapStringEditor())
self.SetCellValue(2, 2, "Yet another cell")
self.SetCellValue(3, 3, "This cell is read-only")
self.SetCellFont(0, 0, wxFont(12, wxROMAN, wxITALIC, wxNORMAL))
self.SetCellTextColour(1, 1, wxRED)
self.SetCellBackgroundColour(2, 2, wxCYAN)
self.SetReadOnly(3, 3, True)

self.SetCellEditor(5, 0, wxGridCellNumberEditor(1,1000))
self.SetCellValue(5, 0, "123")
self.SetCellEditor(6, 0, wxGridCellFloatEditor())
self.SetCellValue(6, 0, "123.34")
self.SetCellEditor(7, 0, wxGridCellNumberEditor())

self.SetCellValue(6, 3, "You can veto editing this cell")


# attribute objects let you keep a set of formatting values
# in one spot, and reuse them if needed
attr = wxGridCellAttr()
attr.SetTextColour(wxBLACK)
attr.SetBackgroundColour(wxRED)
attr.SetFont(wxFont(10, wxSWISS, wxNORMAL, wxBOLD))

# you can set cell attributes for the whole row (or column)
self.SetRowAttr(5, attr)

self.SetColLabelValue(0, "Custom")
self.SetColLabelValue(1, "column")
self.SetColLabelValue(2, "labels")

self.SetColLabelAlignment(wxALIGN_LEFT, wxALIGN_BOTTOM)

#self.SetDefaultCellOverflow(False)
#r = wxGridCellAutoWrapStringRenderer()
#self.SetCellRenderer(9, 1, r)

# overflow cells
self.SetCellValue( 9, 1, "This default cell will overflow into
neighboring cells, but not if you turn overflow off.");
self.SetCellSize(11, 1, 3, 3);
self.SetCellAlignment(11, 1, wxALIGN_CENTRE, wxALIGN_CENTRE);
self.SetCellValue(11, 1, "This cell is set to span 3 rows and 3
columns");


editor = wxGridCellTextEditor()
editor.SetParameters('10')
self.SetCellEditor(0, 4, editor)
self.SetCellValue(0, 4, "Limited text")


# test all the events
EVT_GRID_CELL_LEFT_CLICK(self, self.OnCellLeftClick)
EVT_GRID_CELL_RIGHT_CLICK(self, self.OnCellRightClick)
EVT_GRID_CELL_LEFT_DCLICK(self, self.OnCellLeftDClick)
EVT_GRID_CELL_RIGHT_DCLICK(self, self.OnCellRightDClick)

EVT_GRID_LABEL_LEFT_CLICK(self, self.OnLabelLeftClick)
EVT_GRID_LABEL_RIGHT_CLICK(self, self.OnLabelRightClick)
EVT_GRID_LABEL_LEFT_DCLICK(self, self.OnLabelLeftDClick)
EVT_GRID_LABEL_RIGHT_DCLICK(self, self.OnLabelRightDClick)

EVT_GRID_ROW_SIZE(self, self.OnRowSize)
EVT_GRID_COL_SIZE(self, self.OnColSize)

EVT_GRID_RANGE_SELECT(self, self.OnRangeSelect)
EVT_GRID_CELL_CHANGE(self, self.OnCellChange)
EVT_GRID_SELECT_CELL(self, self.OnSelectCell)

EVT_GRID_EDITOR_SHOWN(self, self.OnEditorShown)
EVT_GRID_EDITOR_HIDDEN(self, self.OnEditorHidden)
EVT_GRID_EDITOR_CREATED(self, self.OnEditorCreated)



def OnCellLeftClick(self, evt):
self.log.write("OnCellLeftClick: (%d,%d) %s\n" %
   (evt.GetRow(), evt.GetCol(), evt.GetPosition()))
evt.Skip()

def OnCellRightClick(self, evt):
self.log.write("OnCellRightClick: (%d,%d) %s\n" %
   (evt.GetRow(), evt.GetCol(), evt.GetPosition()))
evt.Skip()

def OnCellLeftDClick(self, evt):
self.log.write("OnCellLeftDClick: (%d,%d) %s\n" %
   (evt.GetRow(), evt.GetCol(), evt.GetPosition()))
evt.Skip()

def OnCel

Re: python equivalent to access reports

2005-02-11 Thread jean-michel
"flupke" <[EMAIL PROTECTED]> a écrit dans le message de
news:[EMAIL PROTECTED]
> a lot of applications here a made with access. Tables, forms, reports
> and the like. Now i rather use Python to do this but i'm not sure how to
> proceed. I can use wxPython for a gui via wxGlade for rapid testing and
> design (forms), MySQL as db (tables) but the report part is what's
> bothering me.
>
> Any other ideas?

Hello,
You can use wxwindows (http://www.wxpython.org/) which have some very nice
report classes.
If you want to know more, you just have to download and try the demo.
++jm


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


Re: goto, cls, wait commands

2005-02-11 Thread jean-michel
"BOOGIEMAN" <[EMAIL PROTECTED]> a écrit dans le message de
news:[EMAIL PROTECTED]
> I've just finished reading Python turtorial for non-programmers
> and I haven't found there anything about some usefull commands I used in
> QBasic. First of all, what's Python command equivalent to QBasic's "goto"
?
> Secondly, how do I clear screen (cls) from text and other content ?
> And last, how do I put program to wait certain amount of seconds ?
> If I remeber correctly I used to type "Wait 10" and QBasic waits
> 10 seconds before proceeding to next command.

Hi all,
I saw a lot of comments saying GOTO is not usefull, very bad, and we
should'nt use it because we don't need it.
I think that's true, but only if you *create* programs.
But if the goal is to provide some kind of converter to automatically take
an old application written with an old language (using GOTO), and generating
python code, it would certainly a great help to have this (unclean) feature
in native python.
Best regards
jm


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


Re: goto, cls, wait commands

2005-02-11 Thread jean-michel

"Jeff Shannon" <[EMAIL PROTECTED]> a écrit dans le message de
news:[EMAIL PROTECTED]
> jean-michel wrote:
>
> > Hi all,
> > I saw a lot of comments saying GOTO is not usefull, very bad, and we
> > should'nt use it because we don't need it.
> > I think that's true, but only if you *create* programs.
> > But if the goal is to provide some kind of converter to automatically
take
> > an old application written with an old language (using GOTO), and
generating
> > python code, it would certainly a great help to have this (unclean)
feature
> > in native python.
>
> But an automatic translator is certain to be imperfect.  One can no
> more translate mechanically between computer languages than one can
> translate mechanically between human languages -- and we've all seen
> the fun that can be had by machine-translating from language A ->
> language B -> language A, right?  What do you think the effect of that
> sort of meaning-drift would be on application code?
>
> In other words, any translation from one language to another will
> require significant human attention, by someone familiar with both
> languages, to ensure that the original meaning is preserved as close
> as possible.  You're going to have to rewrite chunks of code by hand
> no matter what you do; it'd be silly to *not* take that opportunity to
> purge things like GOTO.
>
> Jeff Shannon
> Technician/Programmer
> Credit International
>

The automated translations are very commonly used actually in computing
industry. If you want an overview, you can try "legacy migration" in google
for instance (or "as400 automated migration" or anything of that kind).
Translate a computer's language is not the same at all than to translate a
human language. In the first case, you have a good chance to know all the
rules. Even if the work is not perfect, it can offer you a chance to
continue to use a 1 programs application without having to rewrite all
(several years of work indeed).
The last time I did that, I converted arround 6000 cobol programs in a
couple of months, which is obviously not possible by hand (thanks to python
;-). And it was not possible to remove GOTO, because that would really need
to rewrite manually the programs, that means to entirely redo the
application (probably a 20 human years work !).

Regards,
jm


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


Re: which parser to use

2005-02-22 Thread Jean Brouwers

Check out SimpleParse/mxTextTools.  Just an outstanding E/BNF driven
parser, very highly recommended.

 <http://simpleparse.sourceforge.net/>

/Jean Brouwers

PS) See also

<http://www-128.ibm.com/developerworks/linux/library/l-simple.html>

<http://gnosis.cx/publish/programming/charming_python_b4.html>

There are descriptions of other Python-based parsers on this site
<http://gnosis.cx/TPiP/>



In article <[EMAIL PROTECTED]>, <[EMAIL PROTECTED]> wrote:

> I'm building something that requires parsing a rather complex
> language. I'd like to do the whole application, including the
> lex/parse phase, in Python (for development/debug speed), and only
> move parts of it to a compiled language if execution speed absolutely
> dictates. So, what i'm looking for in a Python parser is:
> 
> 1) reliability (don't want to debug a parser)
> 1) flexibility (i do a lot of refactoring)
> 2) E/BNF friendliness (working from a spec)
> 3) speed (moderate speed will do; glacial won't)
> 
> Does anyone have any familiarity with some of the several Python
> parsers out there? Any pointers to comparisons (as opposed to surveys)
> of _several_ of the Python parsers would be much appereciated. (I've
> seen the YAPPS/Spark comparison.) If none of the Python parsers really
> fit the bill, any thoughts on ANTLR, Spirit, etc?
> 
> Thanks in advance,
> E
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxStyledTextCtrl problem ?

2004-11-29 Thread Jean Brouwers


If you are running GTK+ try using

self.Editor.SetSTCFocus(True)

in addition to or instead of SetFocus().  Plus maybe

wx.CallAfter(self.Editor.EnsureCaretVisible)

It solved the 'dissapearing caret' problem for our application.


/Jean Brouwers



In article
<[EMAIL PROTECTED]>,
Paul Robson <[EMAIL PROTECTED]> wrote:

> I have a wierd thing with a little editor app I'm writing.
> 
> I'm using wxStyledTextCtrl ; the wrapper for Scintilla. When I create the
> frame in wxPython, I use self.Editor.SetFocus() to put the focus initially
> on the editor.
> 
> This works fine.
> 
> Odd thing is though, switching back and forwards between applications
> alternately hides and reappears the caret.
> 
> Hit Alt-Tab twice and it disappears
> Hit Alt-Tab twice and it comes back.
> 
> It still works fine - there's just no caret. I've tried various things in
> EVT_ACTIVATE including Moving the Caret on screen, and forcing it to be
> visible - they are being called but it makes no difference.
> 
> Any ideas ?
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxStyledTextCtrl problem ?

2004-11-29 Thread Jean Brouwers

Here is the recent thread about this particular problem:

<http://lists.wxwidgets.org/cgi-bin/ezmlm-cgi?11:mss:33225:200410:lfppnf
okhnlgfialpfdh>

/Jean Brouwers


In article <[EMAIL PROTECTED]>,
Jean Brouwers <[EMAIL PROTECTED]> wrote:

> If you are running GTK+ try using
> 
> self.Editor.SetSTCFocus(True)
> 
> in addition to or instead of SetFocus().  Plus maybe
> 
> wx.CallAfter(self.Editor.EnsureCaretVisible)
> 
> It solved the 'dissapearing caret' problem for our application.
> 
> 
> /Jean Brouwers
> 
> 
> 
> In article
> <[EMAIL PROTECTED]>,
> Paul Robson <[EMAIL PROTECTED]> wrote:
> 
> > I have a wierd thing with a little editor app I'm writing.
> > 
> > I'm using wxStyledTextCtrl ; the wrapper for Scintilla. When I create the
> > frame in wxPython, I use self.Editor.SetFocus() to put the focus initially
> > on the editor.
> > 
> > This works fine.
> > 
> > Odd thing is though, switching back and forwards between applications
> > alternately hides and reappears the caret.
> > 
> > Hit Alt-Tab twice and it disappears
> > Hit Alt-Tab twice and it comes back.
> > 
> > It still works fine - there's just no caret. I've tried various things in
> > EVT_ACTIVATE including Moving the Caret on screen, and forcing it to be
> > visible - they are being called but it makes no difference.
> > 
> > Any ideas ?
> >
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: using os

2004-11-29 Thread Jean Brouwers

Check the os.walk() and os.path.walk() functions.  More details and
some examples are at

  <http://docs.python.org/lib/os-file-dir.html>

resp.

  <http://docs.python.org/lib/module-os.path.html>


/Jean Brouwers



In article <[EMAIL PROTECTED]>,
Juliano Freitas <[EMAIL PROTECTED]> wrote:

> how can i get just the directories in other directorie without a files
> using the os module in Python??
> 
> 
> Juliano
> 
> 
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Syntax for extracting multiple items from a dictionary

2004-12-01 Thread Jean Brouwers

The correct syntax is:

dict([(key, row[key]) for key in cols])

i.e. the list must be enclosed in [...].

/Jean Brouwers



In article <[EMAIL PROTECTED]>, Dave Merrill
<[EMAIL PROTECTED]> wrote:

> "anton muhin" wrote:
> > Stefan Behnel wrote:
> > >
> > >
> > > shark schrieb:
> > >
> > >> row = {"fname" : "Frank", "lname" : "Jones", "city" : "Hoboken",
> > >> "state" :
> > >> "Alaska"}
> > >> cols = ("city", "state")
> > >>
> > >> Is there a best-practices way to ask for an object containing only the
> > >> keys
> > >> named in cols out of row? In other words, to get this:
> > >> {"city" : "Hoboken", "state" : "Alaska"}
> > >
> > >
> > > Untested:
> > >
> > > dict( (key,value) for (key,value) in row.iteritems() if key in cols )
> > >
> > > Works in Py2.4
> > >
> > > Stefan
> >
> > Or dict((key, row[key]) for key in cols).
> >
> > regards,
> > anton.
> 
> I'm on Py 2.3.3, and neither of these appear to work. Can someone confirm? I
> can't see anything in the 2.4 release notes that point to where this would
> have changed.
> 
> Thanks,
> 
> shark
> 
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.4 and Tkinter

2004-12-01 Thread Jean Brouwers

FWIW, we just installed Python 2.4 (on RH Linx 8), rebuilt it from
scratch and everything is fine.  Tkinter is there, _tkinter as well and
idle comes up as expected.

/Jean Brouwers



In article <[EMAIL PROTECTED]>,
Jeffrey Barish <[EMAIL PROTECTED]> wrote:

> http://www.python.org/moin/TkInter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.4 and Tkinter

2004-12-01 Thread Jean Brouwers

Here is how we understand this (which may be incomplete and/or
incorrect).

The _tkinter module is a shared library _tkinter.o and that is built
from C source file _tkinter.c.  That C file and a few other tk related
C files are included in the Python distribution.

But the Tcl/Tk libraries to build the _tkinter module are coming from
/usr/local/lib in our case.  And those happens to be tcl83 and tk83 in
our case.

If the Tcl/Tk libraries (and include files) are missing, you will have
to get and install those.  But they are not part of the Python
distribution, as far as we know.

/Jean Brouwers



In article <[EMAIL PROTECTED]>,
Jeffrey Barish <[EMAIL PROTECTED]> wrote:

> Jean Brouwers wrote:
> 
> > 
> > FWIW, we just installed Python 2.4 (on RH Linx 8), rebuilt it from
> > scratch and everything is fine.  Tkinter is there, _tkinter as well
> > and idle comes up as expected.
> > 
> > /Jean Brouwers
> > 
> > 
> > 
> > In article <[EMAIL PROTECTED]>,
> > Jeffrey Barish <[EMAIL PROTECTED]> wrote:
> > 
> >> http://www.python.org/moin/TkInter
> 
> Here's what I get when I import Tkinter at a python prompt:
> 
> [EMAIL PROTECTED]:~$ python
> Python 2.4 (#1, Nov 30 2004, 08:58:13)
> [GCC 3.2.3 20030316 (Debian prerelease)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import Tkinter
> Traceback (most recent call last):
>   File "", line 1, in ?
>   File "/usr/local/lib/python2.4/lib-tk/Tkinter.py", line 38, in ?
> import _tkinter # If this fails your Python may not be configured
> for Tk
> ImportError: No module named _tkinter
> 
> I tried make clean and make.  Same result.  Ah, now I see that the
> output from make includes:
> 
> INFO: Can't locate Tcl/Tk libs and/or headers
> 
> Aren't the libs and headers included in Python-2.4.tgz?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.4 and Tkinter

2004-12-02 Thread Jean Brouwers

It is hard to tell what is wrong, exactly.  Two suggestions:

If this is a 32-bit build, why is there a  "-L/usr/X11R6/lib64" and
*before*  the regular "-L/usr/X11R6/lib"?  Try to rerun just that line
"gcc -pthread  _tkinter.so" but without the "-L/usr/X11R6/lib64"
option.

If that still fails, try a fresh reconfigure and rebuild from scratch,
now that the Tcl/Tk libs are there.  Start with "./configure " per
the instructions in the README file, run "make clean" etc..

/Jean Brouwers



In article <[EMAIL PROTECTED]>,
Jeffrey Barish <[EMAIL PROTECTED]> wrote:

> Jean Brouwers wrote:
> 
> > 
> > Here is how we understand this (which may be incomplete and/or
> > incorrect).
> > 
> > The _tkinter module is a shared library _tkinter.o and that is built
> > from C source file _tkinter.c.  That C file and a few other tk related
> > C files are included in the Python distribution.
> > 
> > But the Tcl/Tk libraries to build the _tkinter module are coming from
> > /usr/local/lib in our case.  And those happens to be tcl83 and tk83 in
> > our case.
> > 
> > If the Tcl/Tk libraries (and include files) are missing, you will have
> > to get and install those.  But they are not part of the Python
> > distribution, as far as we know.
> > 
> > /Jean Brouwers
> > 
> > 
> > 
> > In article <[EMAIL PROTECTED]>,
> > Jeffrey Barish <[EMAIL PROTECTED]> wrote:
> > 
> >> Jean Brouwers wrote:
> >> 
> >> > 
> >> > FWIW, we just installed Python 2.4 (on RH Linx 8), rebuilt it from
> >> > scratch and everything is fine.  Tkinter is there, _tkinter as well
> >> > and idle comes up as expected.
> >> > 
> >> > /Jean Brouwers
> >> > 
> >> > 
> >> > 
> >> > In article <[EMAIL PROTECTED]>,
> >> > Jeffrey Barish <[EMAIL PROTECTED]> wrote:
> >> > 
> >> >> http://www.python.org/moin/TkInter
> >> 
> >> Here's what I get when I import Tkinter at a python prompt:
> >> 
> >> [EMAIL PROTECTED]:~$ python
> >> Python 2.4 (#1, Nov 30 2004, 08:58:13)
> >> [GCC 3.2.3 20030316 (Debian prerelease)] on linux2
> >> Type "help", "copyright", "credits" or "license" for more
> >> information.
> >> >>> import Tkinter
> >> Traceback (most recent call last):
> >>   File "", line 1, in ?
> >>   File "/usr/local/lib/python2.4/lib-tk/Tkinter.py", line 38, in ?
> >> import _tkinter # If this fails your Python may not be configured
> >> for Tk
> >> ImportError: No module named _tkinter
> >> 
> >> I tried make clean and make.  Same result.  Ah, now I see that the
> >> output from make includes:
> >> 
> >> INFO: Can't locate Tcl/Tk libs and/or headers
> >> 
> >> Aren't the libs and headers included in Python-2.4.tgz?
> 
> OK, I downloaded tcl8.4.8 and tk8.4.8.  They are now installed.  Back to
> python2.4 make.  It now bombs at:
> 
> gcc -pthread -shared build/temp.linux-i686-2.4/_tkinter.o
> build/temp.linux-i686-2.4/tkappinit.o -L/usr/X11R6/lib64
> -L/usr/X11R6/lib -L/usr/local/lib -ltk8.4 -ltcl8.4 -lX11 -o
> build/lib.linux-i686-2.4/_tkinter.so
> *** WARNING: renaming "_tkinter" since importing it failed: libtk8.4.so:
> cannot open shared object file: No such file or directory
> running build_scripts
> 
> Here's what I don't get:
> 
> [EMAIL PROTECTED]:/tmp/Python-2.4# ls -l /usr/local/lib/libtk8.4.so
> -rwxr-xr-x1 root staff  893866 2004-12-02
> 15:28 /usr/local/lib/libtk8.4.so
> 
> The library is there but gcc claims that it isn't.  Any suggestions?
-- 
http://mail.python.org/mailman/listinfo/python-list


Newbie alert !

2004-12-03 Thread Jean Montambeault
I am not only learning Python but programming itself ; reading your 
posts makes me believe that nobody is that much of a beginner here. Is 
there a newgroup or list for my type somewhere I can't find it ?

To illustrate my case this script :

# function to draw rings for an Olympic flag
def rings(size,offsetX,offsetY,coul):
x1,y1,x2,y2 = 170, 103, 170, 103,
can1.create_oval(x1-size-offsetX,y1+size+offsetY,\
 x2+size-offsetX,y2-size+offsetY,\
 width=8, outline=coul)
# **mainmainmainmainmainmain**
fen1=Tk()
can1=Canvas(fen1, bg='white', height=206, width=340)
can1.pack(side=LEFT)
bou_europe=Button(fen1, text='Europe',\
  command=rings(41, 100, -22, 'blue'))
bou_europe.pack( )
bou_asia=Button(fen1, text='Asia',\
  command=rings(size=41, offsetX=50,offsetY=22, 
coul='yellow'))
bou_asia.pack( )

bou_africa=Button(fen1, text='Africa',\
  command=rings(size=41, offsetX=0,offsetY=-22, 
coul='black'))
bou_africa.pack( )

bou_australia=Button(fen1, text='Australia',\
  command=rings(size=41, offsetX=-50,offsetY=22, 
coul='dark green'))
bou_australia.pack( )

bou_america=Button(fen1, text='America',\
  command=rings(size=41, offsetX=-100,offsetY=-22, 
coul='Red'))
bou_america.pack( )

bou_quit=Button(fen1, text='Quit', command=fen1.quit)
bou_quit.pack(side=BOTTOM)
fen1.mainloop()
fen1.destroy()

I just cannot figure out why the rings are draw right from the start and 
 don't wait for their buttons to be pressed before being drawn :  I've 
written similar functions before to draw lines, rectangles and whatever 
else with success.

Using Python 2.3, IDLE and Win2k.
Thanks for your time
Jean Montambeault
--
http://mail.python.org/mailman/listinfo/python-list


Re:Of course I have 'from Tkinter import *'...

2004-12-03 Thread Jean Montambeault
... at the start of the file.
I just thought it to be too obvious to be included : my mistake.
Thanks
Jean
--
http://mail.python.org/mailman/listinfo/python-list


Re: Help with use of code.InteractiveInterpreter for multiline code

2004-12-03 Thread Jean Brouwers

Take a look at the source code of the code module (file code.py in the
lib directory).  The push() method of the InteractiveConsole class
shows how to handle multi-line statements.

Basically, keep collecting lines as long as the result returned by the
runsource() call is true.  Maybe instead of calling the runsource()
method, just call the push() method.

/Jean Brouwers


In article <[EMAIL PROTECTED]>,
<"[EMAIL PROTECTED]"> wrote:

> I'm trying to embed a Python interpreter in a GUI I'm developing, and
> I'm having trouble understanding the proper use of
> code.InteractiveInterpreter.
> 
> Here's what I'm trying:
> 
> % python
> Python 2.3 (#1, Sep 13 2003, 00:49:11)
> [GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
> >>> from code import InteractiveInterpreter
> >>> a = InteractiveInterpreter()
> >>> a.runsource('a = 0')
> False
> >>> a.runsource('b = 0')
> False
> >>> a.runsource('print a,b')
> 0 0
> False
> >>> a.runsource('def q():')
> True
> >>> a.runsource('print "hi"')
> File "", line 1
> print "hi"
> ^
> SyntaxError: invalid syntax
> False
> 
> 
> What's the proper way to call the interpreter instance for a multiline
> example like this?
> 
> Thanks in advance,
> 
> Rick
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pythonwin broke

2004-12-03 Thread Jean Brouwers

We just went through a similar install-uninstall-reinstall cycle with
Python 2.4 and 2.3 on Windows XP SP2.  Just uninstalling 2.4 and
reinstalling 2.3 was not sufficient.

It took several attempts to get things back to the original 2.3
configuration.  After unininstalling both, we deleted all Python
related entries in the Registry and in the StartUp folder.  Only after
that did the reinstalled 2.3 plus extensions work fine again.

/Jean Brouwers

PS) We backed out of using Python 2.4 since two of the extensions we
need did not work with 2.4 on Windows XP.

PPS) It looks like Python 2.4 and Python 2.3 can not co-exist (in
different folders under Program Files) but we did not investigate that
any further.



In article <[EMAIL PROTECTED]>, Jive
<[EMAIL PROTECTED]> wrote:

> I've un-installed Python 2.4, re-installed Python 2.3 and PythonWin for 2.3,
> but it's still broke.
> 
> When I start PythonWin, sometimes it looks like it is going to be okay.  But
> as soon as I open a .py file, the interactive window grabs the focus and
> will not let go.  I am stumped.
> 
> Is there something PythonWin uses that I could try re-installing?  WxPython
> maybe?
> 
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie alert !

2004-12-03 Thread Jean Montambeault
Jean Montambeault wrote:
I am not only learning Python but programming itself ; reading your 
posts makes me believe that nobody is that much of a beginner here. Is 
there a newgroup or list for my type somewhere I can't find it ?

To illustrate my case this script :

# function to draw rings for an Olympic flag
def rings(size,offsetX,offsetY,coul):
x1,y1,x2,y2 = 170, 103, 170, 103,
can1.create_oval(x1-size-offsetX,y1+size+offsetY,\
 x2+size-offsetX,y2-size+offsetY,\
 width=8, outline=coul)
# **mainmainmainmainmainmain**
fen1=Tk()
can1=Canvas(fen1, bg='white', height=206, width=340)
can1.pack(side=LEFT)
bou_europe=Button(fen1, text='Europe',\
  command=rings(41, 100, -22, 'blue'))
bou_europe.pack( )
bou_asia=Button(fen1, text='Asia',\
  command=rings(size=41, offsetX=50,offsetY=22, 
coul='yellow'))
bou_asia.pack( )

bou_africa=Button(fen1, text='Africa',\
  command=rings(size=41, offsetX=0,offsetY=-22, 
coul='black'))
bou_africa.pack( )

bou_australia=Button(fen1, text='Australia',\
  command=rings(size=41, offsetX=-50,offsetY=22, 
coul='dark green'))
bou_australia.pack( )

bou_america=Button(fen1, text='America',\
  command=rings(size=41, offsetX=-100,offsetY=-22, 
coul='Red'))
bou_america.pack( )

bou_quit=Button(fen1, text='Quit', command=fen1.quit)
bou_quit.pack(side=BOTTOM)
fen1.mainloop()
fen1.destroy()

I just cannot figure out why the rings are draw right from the start and 
 don't wait for their buttons to be pressed before being drawn :  I've 
written similar functions before to draw lines, rectangles and whatever 
else with success.

Using Python 2.3, IDLE and Win2k.
Thanks for your time
Jean Montambeault
Thank you everybody !
If Tkinter hadn't been so polite... but without any error message I 
didn't know where to start to search. It is a shame that one can't pass 
parameters through 'command' in a simple manner. My intent was to make a 
function that could be of use in as many cases as possible. I was 
experimenting way off the intented target of the exercise. Nevertheless 
it was an occasion to learn a whole lot.

Thanks to Simon and Eric the adresses too.
Jean
--
http://mail.python.org/mailman/listinfo/python-list


Re: pythonwin broke

2004-12-03 Thread Jean Brouwers

Well, we made several attempts to install Python 2.4 with a number of
extension packages on Windows XP and used the binaries from the Python
site, not ActivePython.

Previous to 2.4,  we did have several versions of Python installed on
Windows XP without any problem.  We installed 2.4 as usual in a
separate directory under Program Files.  But there were several
problems getting the 2.4 exe and IDLE started, in addition to issues
with some extensions.  Plus 2.3.4 could not be started any longer.

Uninstalling 2.4 did not quite work and *may* have broken the existing
2.3.4 installation.  Uninstalling and reinstalling that failed also,
until we manually cleaned up the Registry and StartUp folder.

As I mentioned, we did not investigate the 2.4 problem any further
since getting 2.3.4 back up and running was more critical than 2.4 due
to other problems with the extensions on 2.4.

Once all extensions exist for 2.4 we will try again.  And maybe, we
should use the ActivePython builds then ;-)

/Jean Brouwers
 
PS) We had no problem with Python 2.4 or any extensions on Lunix. 
Everything works fine there and all our Python code runs unmodified on
both 2.3 and 2.4 with extensions, without any failure or glitch.  The
difference *may* be that we rebuild the distribution on Linux but not
on Windows.



In article <[EMAIL PROTECTED]>, Trent
Mick <[EMAIL PROTECTED]> wrote:

> Jean Brouwers wrote:
> > PPS) It looks like Python 2.4 and Python 2.3 can not co-exist (in
> > different folders under Program Files) but we did not investigate that
> > any further.
> 
> That's not true. I have every version of Python back to 2.0 installed 
> and all running fine on my system. Obviously you can only have one of 
> your Python installations first on your PATH (and hence the one that 
> gets run by simply typing "python"). Also, you can only have one of you 
> Python installations registered as the default handler for .py files 
> (and hence the one that gets run by simple double-clicking on a .py file 
> in explorer or running a Python script without the extension from the 
> command line).
> 
> It is also possible that there is some little installer bug or detail on 
>   your environment that is causing the problem. You could try 
> ActivePython. I regularly install and uninstall ActivePython 2.3 and 2.4 
> installers and both installs are still working fine.
> 
> Cheers,
> Trent
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pythonwin broke

2004-12-04 Thread Jean Brouwers


I'm not sure what Pythonwin is.  The Python start menu shows "Python
(command line)" and "IDLE (Python GUI)" plus docs, etc.

Your experiment with IDLE works just fine.  Both windows closed on
clickin X.  This is Windows XP SP2 with Python 2.3.4 from the
Python.org site.

/Jean Brouwers



In article <[EMAIL PROTECTED]>, Jive
<[EMAIL PROTECTED]> wrote:

> Do an experiment for me.  Open Pythonwin from the start menu.  Use the FILE
> menu to open a .py file.  Now try to close the window you just opened using
> the X button in the upper right.  Did it close?  Try closing Pythonwin using
> its X button.
> 
> 
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pythonwin broke

2004-12-04 Thread Jean Brouwers

One more test, but after selecting "Modules Doc" from the start menu.  

The small pydoc window shows up, "Python documentation server ..." etc. 
Clicking the X button results in a "pythonw.exe Application Error" with
the message:

   The instruction at "0x..." referenced memory at "0x0..014".  The
memory could not be "read".  Click on OK to terminate the program.

Same Window XP SP2 machine running Python 2.3.4 downloaded from the
Python website (with just one extension, wxPython 2.4.2.4).

/Jean Brouwers



In article <[EMAIL PROTECTED]>,
Jean Brouwers <[EMAIL PROTECTED]> wrote:

> I'm not sure what Pythonwin is.  The Python start menu shows "Python
> (command line)" and "IDLE (Python GUI)" plus docs, etc.
> 
> Your experiment with IDLE works just fine.  Both windows closed on
> clickin X.  This is Windows XP SP2 with Python 2.3.4 from the
> Python.org site.
> 
> /Jean Brouwers
> 
> 
> 
> In article <[EMAIL PROTECTED]>, Jive
> <[EMAIL PROTECTED]> wrote:
> 
> > Do an experiment for me.  Open Pythonwin from the start menu.  Use the FILE
> > menu to open a .py file.  Now try to close the window you just opened using
> > the X button in the upper right.  Did it close?  Try closing Pythonwin using
> > its X button.
> > 
> > 
> >
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The python2.4 IDLE can't be lanuched.

2004-12-06 Thread Jean Brouwers

This is a known problem.  More details at

<http://sourceforge.net/tracker/index.php?func=detail&aid=1076861&group_
id=5470&atid=105470>


/Jean Brouwers


In article <[EMAIL PROTECTED]>,
AnkyHe <[EMAIL PROTECTED]> wrote:

>   I downloaded the python 2.4 final from the offical website and installed it
> on the WindowsXP+SP2 (Chinese version).
> There was not any problem in this process, but the IDLE can't be lanuched
> without any warnning.  Is there anybody else 
> encount this problem and how to resolve it?  Thanks!  
> 
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why I can't launch python 2.4 final IDLE?

2004-12-07 Thread Jean Brouwers

This is the second time you ask the same question.  Did you miss the
answer to the first one?  This is a known problem. More details at

<http://sourceforge.net/tracker/index.php?func=detail&aid=1076861&group_
id=5470&atid=105470>

/Jean Brouwers


In article <[EMAIL PROTECTED]>,
AnkyHe <[EMAIL PROTECTED]> wrote:

>  I downloaded the python 2.4 final from the offical website and installed it
> on WindowsXP+SP2 (Chinese version).
> There was not any problem in this process, but the IDLE can't be launched
> without any warnning.  Is there anybody else 
> encount this problem and how to resolve it?  Thanks!
-- 
http://mail.python.org/mailman/listinfo/python-list


Connecting to numarray. Problem with the setup program

2004-12-08 Thread Jean Moser
I tried many times to connect to numarray without success.
I choosed the release: numarray-1.1.1.win32py2.2.exe then I went to
the setup program made by Greenfield and I tried to follow the
commands.The mentioned Python directory is C:\PROGRA~2 which is not
covenient. I tried to change it but without success. From now on I
could not go further. What shall I do ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: system requirements for python 2.4

2004-12-13 Thread Jean Brouwers

FWIIW, we use Python 2.4 on RH8 and FC2 systems.  In both cases, built
from scratch, following the build instructions.

/Jean Brouwers


In article <[EMAIL PROTECTED]>, ben
<[EMAIL PROTECTED]> wrote:

> I'm trying to upgrade python from 2.2 to 2.4 on a RH9 system, and can't
> find any rpm that will let me install it.
> Is FC3 required for python 2.4?
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: flex/bison like module in Python?

2004-12-15 Thread Jean Brouwers

For command line parsing, take a look at the shlex module, also in the
standard distro.  It may fit your requirements for additional
functionality beyond cmd.

/Jean Brouwers

PS) We use SimpleParse/mxTextTools for parsing large log files, both
are listed on the web page mentioned below.  In addition, check out
David Mertz' web pages 'Text Processing in Python' at

<http://gnosis.cx/TPiP/>



In article <[EMAIL PROTECTED]>,
Fredrik Lundh <[EMAIL PROTECTED]> wrote:

> Jerry Sievers wrote:
> 
> > Curious if there exists in Python package(s) for use as lexer/parser
> > for implementation of language grammars?
> 
> (s) indeed:
> 
> http://www.nedbatchelder.com/text/python-parsers.html
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Accessing DB2 with Python

2004-12-16 Thread Jean Brouwers


Try <ftp://people.linuxkorea.co.kr/pub/DB2> with capital DB.

/Jean Brouwers


In article <[EMAIL PROTECTED]>, Shawn
Milo <[EMAIL PROTECTED]> wrote:

> ftp://people.linuxkorea.co.kr/pub/db2,
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Adding paths to sys.path permanently, and another problem...

2004-12-16 Thread Jean Brouwers

Maybe, set environment variable PYTHONPATH.  More details at

<http://www.python.org/doc/current/tut/node8.html>

/Jean Brouwers



In article <[EMAIL PROTECTED]>, Lenard Lindstrom <[EMAIL PROTECTED]>
wrote:

> Amir Dekel <[EMAIL PROTECTED]> writes:
> 
> > Hi everyone,
> > 
> > I have two problems:
> > 
> > 1. How can I keep my changes in sys.path after closing the interpreter?
> > 
> Just how flexible does this need to be? sys.path can easily be altered
> at startup from within a sitecustomize module (section 3.28 -- site --
> Python Runtime Services -- Python Library Reference) or a module specified
> by the PYTHONSTARTUP environment variable (section 3.29 -- user -- Python
> Runtime Services). Just have one of these modules append to sys.path any
> additional paths you need.
> 
> Saving sys.path changes between interpreter runs would be more involved.
> On Windows Python loads the initial module search path from the registry.
> Python's registry entries are made during installation and are left alone
> afterwards. Changing these entries is probably not a good idea. But
> if you need sys.path persistence I can try writing an example that does
> it automatically using the atexit module and a history file.
> 
> Lenard Lindstrom
> <[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best book on Python?

2004-12-16 Thread Jean Brouwers

The text of David Mertz' book is available on line at

<http://gnosis.cx/TPiP/>

/jean Brouwers


In article <[EMAIL PROTECTED]>, Mirko Zeibig
<[EMAIL PROTECTED]> wrote:

> Maurice LING said the following on 12/12/2004 11:13 PM:
> >>Google for Dive Into Python. Its a free online publication, see if is 
> >>any good for you.
> >>
> >>Cheers,
> > 
> > 
> > I like "Dive into Python" for the fact that it tends to explain examples 
> > line by line in an annotated form but it may just be my personal 
> > preference.
> I second this. Another one I like is "Textprocessing  in Python" by 
> "David Mertz".
> 
> > If the focus is only on printed books and there is some experience with 
> > programming, "programming python" by Lutz from O'Reilly might be a good 
> > one.
> So what, "Dive into Python" is available in a printed version as well 
> ;-) (e.g. 
> http://www.amazon.com/exec/obidos/tg/detail/-/1590593561/103-2217423-3565410).
> 
> Regards
> Mirko
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: extending python with a C-written dll

2004-12-20 Thread Jean Brouwers

First, you might check the calldll module available here

  <http://www.nightmare.com/software.html>

Take a look at Pyrex, it may fit your requirements to access C from
Python.

  <http://nz.cosc.canterbury.ac.nz/~greg/python/Pyrex/>

If you do not have these already, you may need the Win32 API extension

  <http://www.python.org/windows/win32/>


/Jean Brouwers



In article <[EMAIL PROTECTED]>, Jean-Baptiste PERIN
<[EMAIL PROTECTED]> wrote:

> Grant Edwards a écrit :
> > On 2004-12-20, Jean-Baptiste PERIN <[EMAIL PROTECTED]> wrote:
> > 
> > 
> >>I'm trying to make a windows dll reachable from a python script..
> > 
> > 
> > FWIW, you can call dll's using the ctypes modules without
> > mucking around in C.  There may be performance reasons to build
> > a "real" python module, but I haven't run across them yet.
> > 
> 
> Not really a performance reason .. but mainly because I have a huge code 
> produced in C and no time to port it in python ..
> Moreover .. I need the python program to interact with the C code 
> ..(perfom calls to dll-defined functions)
> 
> I don't know ctypes module .. do you really think it can help ?
> Do you have a link to quickly learn about it ?
> 
> The only thing I found is :
> http://www.python.org/workshops/1994-11/BuiltInClasses/BuiltInClasses_5.html
> 
> 
> 
> 
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: memory leak

2004-12-21 Thread Jean Brouwers

Since you are on Linux, one thing which could be helpful is to lower
the virtual memory limit.  Before running your program, use the Csh
limit command to set the upper limit for vmemory.

If there is a leak in your program or in any of the extensions, it will
run out of memory earlier.  But setting the limit does not help finding
the root cause of a leak.  That requires additional effort and/or
dignostic tools.

/Jean Brouwers


In article <[EMAIL PROTECTED]>,
Daniel Wheeler <[EMAIL PROTECTED]> wrote:

> I'm on a linux platform and looking in proc/pid/status. Using top shows 
> the same problem.
> 
> I've actually just found the c routine where the memory is leaking by 
> the painstaking process of
> taking the difference between memory consumption before and after each 
> python routine. I guess
> that memory leaks that are not associated with python dangling 
> references are nearly always in the
> underlying c code.
> 
> Also, does anyone know of some good memory diagnostic tools for python, 
> maybe even a GUI.
> I am currently using some pulled from various webpages:
> 
>  http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/286222
>  http://www.nightmare.com/medusa/memory-leaks.html
> 
> 
> On Dec 21, 2004, at 12:18 PM, Stephen Kellett wrote:
> 
> > In message <[EMAIL PROTECTED]>, 
> > Daniel Wheeler <[EMAIL PROTECTED]> writes
> >> However, I would like to understand first if pure python can leak 
> >> without the reference count increasing?
> >
> > How are you determining that used memory is increasing?
> >
> > Stephen
> > -- 
> > Stephen Kellett
> > Object Media Limitedhttp://www.objmedia.demon.co.uk
> > RSI Information:http://www.objmedia.demon.co.uk/rsi.html
> > -- 
> > http://mail.python.org/mailman/listinfo/python-list
> >
> >
> >
> -
> Daniel Wheeler
> Telephone: (301) 975-8358
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to start a new process while the other ist running on

2004-12-21 Thread Jean Brouwers


See the os. spawn* functions.  For example

  os.spawnv(os.P_NOWAIT, /path/to/script, args)

/Jean Brouwers



In article <[EMAIL PROTECTED]>, Erik Geiger <[EMAIL PROTECTED]>
wrote:

> Hi,
> 
> sorry, my english ist not that got but I'll try.
> 
> I have a running python script (capisuit incoming.py). This script shall
> start a linux shell script. If I start this script like os.system(/paht/to
> shellscipt.sh) the python scipt waits for the exit of the shell script and
> then goes on with the rest of the python script.
> 
> How to start a shell script without waiting for the exit of that shell
> script? It shall start the shell script and immediately execute the next
> python command.
> 
> Thanks for any hints
> 
> Erik
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: popen2, 3, 4 -- will closing all returned streams result in process termination?

2004-12-28 Thread Jean Brouwers

It depends mostly on how the spawned process handles conditions like
closed pipes, EOF, etc.

In general and on *nix, any spawned and terminated process will become
and remain a zombie until "reaped", i.e. until the final status is
collected by a calling os.waitpid().

To avoid zombies, you should call the poll() or wait() method of the
Popen3 object created for each spawned process or call os.waitpid().
The problem is that the popen* functions only return the pipe objects
and not the Popen3 instance nor the process id.   

Take a look at the source code of the popen2 module which is the file
.../Lib/popen2.py in your python installation.  It is straightforward
to create your own popen* functions and keep the Popen3 instance.

/Jean Brouwers



In article <[EMAIL PROTECTED]>, Evgeni
Sergeev <[EMAIL PROTECTED]> wrote:

> After I opened streams to a process using popen2, popen3 or popen4,
> will closing every one of the streams terminate the process?
> 
> Is there assurance that the process will terminate and not sit
> in memory orphaned, waiting on its stdin, for example?
> 
> Evgeni Sergeev
-- 
http://mail.python.org/mailman/listinfo/python-list


[newbie] problem trying out simple non object oriented use of Tkinter

2013-12-06 Thread Jean Dubois
I'm trying out Tkinter with the (non object oriented) code fragment below:
It works partially as I expected, but I thought that pressing "1" would
cause the program to quit, however I get this message:
TypeError: quit() takes no arguments (1 given), I tried changing quit to quit()
but that makes things even worse. So my question: can anyone here help me
debug this?

#!/usr/bin/env python
import Tkinter as tk
def quit():
sys.exit()
root = tk.Tk()
label = tk.Label(root, text="Hello, world")
label.pack()
label.bind("<1>", quit)
root.mainloop()

p.s. I like the code not object orientated
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [newbie] problem trying out simple non object oriented use of Tkinter

2013-12-06 Thread Jean Dubois
Op vrijdag 6 december 2013 13:30:53 UTC+1 schreef Daniel Watkins:
> Hi Jean,
> 
> 
> 
> On Fri, Dec 06, 2013 at 04:24:59AM -0800, Jean Dubois wrote:
> 
> > I'm trying out Tkinter with the (non object oriented) code fragment below:
> 
> > It works partially as I expected, but I thought that pressing "1" would
> 
> > cause the program to quit, however I get this message:
> 
> > TypeError: quit() takes no arguments (1 given), I tried changing quit to 
> > quit()
> 
> > but that makes things even worse. So my question: can anyone here help me
> 
> > debug this?
> 
> 
> 
> I don't know the details of the Tkinter library, but you could find out
> 
> what quit is being passed by modifying it to take a single parameter and
> 
> printing it out (or using pdb):
> 
> 
> 
> def quit(param):
> 
> print(param)
> 
> sys.exit()
> 
> 
> 
> Having taken a quick look at the documentation, it looks like event
> 
> handlers (like your quit function) are passed the event that triggered
> 
> them.  So you can probably just ignore the parameter:
> 
> 
> 
> def quit(_):
> 
> sys.exit()
> 
> 
> 
> 
> 
> Cheers,
> 
> 
> 
> Dan

I tried out your suggestions and discovered that I had the line
import sys to the program. So you can see below what I came up with.
It works but it's not all clear to me. Can you tell me what "label.bind("<1>", 
quit)" is standing for? What's the <1> meaning?



#!/usr/bin/env python
import Tkinter as tk
import sys
#underscore is necessary in the following line
def quit(_):
sys.exit()
root = tk.Tk()
label = tk.Label(root, text="Click mouse here to quit")
label.pack()
label.bind("<1>", quit)
root.mainloop()

thanks
jean


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


[newbie] struggling wth tkinter

2013-12-07 Thread Jean Dubois
I'm trying to go through a tutorial on tkinter which has the code below as an 
example. The only thing I see when running it is a little popup with "Click 
mouse here to quit" which works as expected but always shows the following 
error-message.
However the "main" window which should let you enter the numbers is not shown.

This is the quit error message:
Traceback (most recent call last):
  File "./feet2meters.py", line 3, in 
from tkinter import ttk
ImportError: cannot import name ttk

This is the code:
#!/usr/bin/env python
from tkinter import *
from tkinter import ttk

def calculate(*args):
try:
value = float(feet.get())
meters.set((0.3048 * value * 1.0 + 0.5)/1.0)
except ValueError:
pass

root = Tk()
root.title("Feet to Meters")

mainframe = ttk.Frame(root, padding="3 3 12 12")
mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
mainframe.columnconfigure(0, weight=1)
mainframe.rowconfigure(0, weight=1)

feet = StringVar()
meters = StringVar()

feet_entry = ttk.Entry(mainframe, width=7, textvariable=feet)
feet_entry.grid(column=2, row=1, sticky=(W, E))

ttk.Label(mainframe, textvariable=meters).grid(column=2, row=2, sticky=(W, E))
ttk.Button(mainframe, text="Calculate", command=calculate).grid(column=3, 
row=3, sticky=W)

ttk.Label(mainframe, text="feet").grid(column=3, row=1, sticky=W)
ttk.Label(mainframe, text="is equivalent to").grid(column=1, row=2, sticky=E)
ttk.Label(mainframe, text="meters").grid(column=3, row=2, sticky=W)

for child in mainframe.winfo_children(): child.grid_configure(padx=5, pady=5)

feet_entry.focus()
root.bind('', calculate)

root.mainloop()

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


Re: [newbie] struggling wth tkinter

2013-12-07 Thread Jean Dubois
Op zaterdag 7 december 2013 19:12:50 UTC+1 schreef Dave Angel:
> On Sat, 7 Dec 2013 08:52:08 -0800 (PST), Jean Dubois 
> 
>  wrote:
> 
> > I'm trying to go through a tutorial on tkinter which has the code 
> 
> below as an example. The only thing I see when running it is a little 
> 
> popup with "Click mouse here to quit" which works as expected but 
> 
> always shows the following error-message.
> 
> > However the "main" window which should let you enter the numbers is 
> 
> not shown.
> 
> > This is the quit error message:
> 
> > Traceback (most recent call last):
> 
> >   File "./feet2meters.py", line 3, in 
> 
> > from tkinter import ttk
> 
> > ImportError: cannot import name ttk
> 
> 
> 
> > This is the code:
> 
> > #!/usr/bin/env python
> 
> > from tkinter import *
> 
> > from tkinter import ttk
> 
> 
> 
> Thanks for supplying the complete traceback.  But you should also 
> 
> tell the python version and what OS.  I'll guess python 3.3 on Linux. 
> 
> 
> 
> 
> 
> Finally,  what version tk are you running?  These widgets were 
> 
> introduced in tk 8.5
> 
> 
> 
> Since it failed on the second import, none of the rest of the code 
> 
> matters. However, since you're not running it from a terminal window, 
> 
> it's conceivable that your ide is affecting the result.
> 
> 
> 
> -- 
> 
> DaveA

I have two pythons installed on my system:
Python 2.7.3 and Python 3.2.3
When using python2 I get the errors mentioned above
When using python3 (I removed the shebang and started as python3 
feettometers.py) then I get these errors:

coolens@antec2:~$ python3 feet2meters.py 
Traceback (most recent call last):
  File "feet2meters.py", line 1, in 
from tkinter import *
  File "/home/coolens/tkinter.py", line 2, in 
import Tkinter as tk
ImportError: No module named Tkinter

I tried to fix this by installing
apt-get install python3-tk (python3-tk_3.2.3-1_amd64.deb)

but the error remains

What should I do now?

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


Re: [newbie] struggling wth tkinter

2013-12-07 Thread Jean Dubois
Op zaterdag 7 december 2013 19:23:30 UTC+1 schreef Cousin Stanley:
> >  
> 
> > The only thing I see when running it is a little popup 
> 
> > with "Click mouse here to quit" which works as expected 
> 
> > but always shows the following error-message. 
> 
> 
> 
>   This seems to be left over from an earlier post
> 
>   where you were binding a mouse event to a tk label
> 
> 
> 
>   Did you create a  new  file ?
> 
> 
> 
> 
> 
> > However the "main" window which should let you enter the
> 
> > numbers is not shown.
> 
> > 
> 
> > This is the quit error message:
> 
> > Traceback (most recent call last):
> 
> > File "./feet2meters.py", line 3, in 
> 
> > from tkinter import ttk
> 
> > ImportError: cannot import name ttk
> 
> > 
> 
> > This is the code:
> 
> >  
> 
> 
> 
>   If I copy/paste your code as posted
> 
>   into a new file named ftom.py
> 
>   and change the she-bang line
> 
>   as follows 
> 
> 
> 
> #!/usr/bin/env python3
> 
> 
> 
>   Then from the command line 
> 
> 
> 
> python3 ftom.py
> 
> 
> 
>   Your code runs as expected
> 
>   using python 3.2.3 
I tried you suggestion above:

This is what I get:
Traceback (most recent call last):
  File "./feet2meters.py", line 2, in 
from tkinter import *
  File "/home/jean/tkinter.py", line 2, in 
import Tkinter as tk
ImportError: No module named Tkinter

and this is my python3-version:
Python 3.2.3 (default, Sep 25 2013, 18:22:43) 
[GCC 4.6.3] on linux2

any idea what is going wrong?

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


  1   2   3   4   5   6   7   8   9   10   >