[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


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


[newbie] starting geany from within idle does not work

2014-01-12 Thread Jean Dupont
I'm using the latest Raspbian on a Raspberry Pi and I'd like to start IDLE so 
that it uses Geany instead of Leafpad. This seems at first sight a trivial task:
Perform a rightmouse click on the IDLE-icon-->Open with: Geany (in stead of the 
default Leafpad)-->OK
LXTerminal-->lxpanelctl restart

However if I then click on IDLE followed by File-->New Window a Leafpad-session 
is opened and not a Geany-session
Is there a workaround for it?

thanks in advance
jean
p.s. I posted this question before in the Raspberry Pi forum but nobody seems
to know the answer
-- 
https://mail.python.org/mailman/listinfo/python-list


[newbie] advice and comment wanted on first tkinter program

2014-01-17 Thread Jean Dupont
Dear all,
I made a simple gui with tkinter. I can imagine there are things which I
did which are "not optimal". So what I ask is to comment on my code
preferable with snippets of code which show how to do improve my code.
#!/usr/bin/env python
import Tkinter
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(26,GPIO.OUT)
GPIO.setup(24,GPIO.OUT)
#hardware : connect 2 leds:
#board-pin 26 on/off led; control with buttons
#board-pin 24 led with pwm dimming and frequency; control via sliders
top = Tkinter.Tk()
top.geometry("600x400+310+290")
var1 = DoubleVar()
var2 = DoubleVar()
i=0
p=GPIO.PWM(24,1)
p.start(50)
def btn_on_cmd():
text3.configure(bg = "#00FF00")
text3.delete(0.1,END)
text3.insert("0.1","ON ")
GPIO.output(26,True)
def btn_off_cmd():
text3.configure(bg = "#FF4000")
text3.delete(0.1,END)
text3.insert("0.1","OFF")   
GPIO.output(26, False)
def timer0():
global i
i=i+1
text1.delete(0.1,END)
text1.insert(4.2,"Timer: " + str(i))
label1.configure(text=time.strftime("%H:%M:%S"))
top.after(1000, timer0)
def Set_PWM(var1):
DC = float(var1)
p.ChangeDutyCycle(DC)
def Set_FREQ(var2):
FR = float(var2)
p.ChangeFrequency(FR)   
btn_on = Button(top, text ="On", command = btn_on_cmd)
btn_on.place(x=10,y=100)
btn_off = Button(top, text ="Off", command = btn_off_cmd)
btn_off.place(x=100,y=100)
text1 =Text(top, bg = "#009BFF", font=("Helvetica",14), height = 1, width
= 15)
text1.place(x=5,y=5)
text3=Text(top, bg = "red", font=("Helvetica",12),height = 1, width = 4) 
text3.place(x=60,y=60)
label1 = Label(top,relief=RAISED,bg =
"#EFF980",font=("Helvetica",14),height = 1, width = 15)
label1.place(x=5,y=350)
label2= Label(top,relief=RAISED,bg =
"#BFBFBF",font=("Helvetica",10),height = 1, text= "Freq (Hz)")
label2.place(x=420,y=320)
label3= Label(top,relief=RAISED,bg =
"#BFBFBF",font=("Helvetica",10),height = 1, text= "DC %")
label3.place(x=520,y=320)
slider1 = Scale(top,variable = var1,length = 300,resolution = 1,command  =
Set_PWM)
slider1 = Scale(top,variable = var1,length = 300,resolution = 1,command  = 
Set_PWM)
slider1.place(x=500,y=5)
slider1.set(50)
slider2 = Scale(top,variable = var2,length = 300,from_= 0.1, to = 50,resolution 
= 0.1,command  = Set_FREQ)
slider2.place(x=400,y=5)
slider2.set(2)
timer0()
top.mainloop()
GPIO.cleanup()


thanks in advance 
jean

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


Re: [newbie] advice and comment wanted on first tkinter program

2014-01-18 Thread Jean Dupont
Op vrijdag 17 januari 2014 22:40:42 UTC+1 schreef Terry Reedy:
> On 1/17/2014 8:20 AM, Jean Dupont wrote:
> 
> > Dear all,
> 
> > I made a simple gui with tkinter. I can imagine there are things which I
> 
> > did which are "not optimal". So what I ask is to comment on my code
> 
> > preferable with snippets of code which show how to do improve my code.
> 
> > #!/usr/bin/env python
> 
> > import Tkinter
> 
> 
> 
> 1. import Tkinter as tk
> 
> 
> 
> Besides saving a bit of writing and reading time later, this makes any 
> 
> future conversion to 3.x easier.
> 
> 
> 
> import tkinter as tk
> 
> 
> 
> 2. add a few spaces to demarcate blocks of code.
> 
> 
> 
> > import time
> 
> > import RPi.GPIO as GPIO
> 
> 
> 
> 2. add a few spaces to demarcate blocks of code, such as here
> 
> 
> 
> > GPIO.setmode(GPIO.BOARD)
> 
> > GPIO.setup(26,GPIO.OUT)
> 
> > GPIO.setup(24,GPIO.OUT)
> 
> > #hardware : connect 2 leds:
> 
> > #board-pin 26 on/off led; control with buttons
> 
> > #board-pin 24 led with pwm dimming and frequency; control via sliders
> 
> 
> 
> and here
> 
> 
> 
> > top = Tkinter.Tk()
> 
> > top.geometry("600x400+310+290")
> 
> 
> 
> This looks strange somehow, but if it works...
> 
> 
> 
> 
> 
> > label1 = Label(top,relief=RAISED,bg =
> 
> > "#EFF980",font=("Helvetica",14),height = 1, width = 15)
> 
> 
> 
> In calls, put spaces after , but not before and after =.
> 
> For other suggestions, see
> 
> http://www.python.org/dev/peps/pep-0008/
> 
> 
> 
> I suspect that the above is one line in your code and the bad wrapping a 
> 
> result of mis-spacing. The following is also one line, but easer to read 
> 
> as spaces separate argument chunks
> 
> 
> 
> label1 = Label(top, relief=RAISED, bg="#EFF980", font=("Helvetica",14), 
> 
> height=1, width=15)
> 
> 
> 
> and the wrapping, if any, does not break up an arg chunk.
> 
> 
> 
> Some people advocate defining an App class, but Tk and tkinter, even 
> 
> though object method based, allow the straightforward imperative style 
> 
> you have used.
> 
> 
> 
> I agree with Peter: "First and foremost a program has to do what the 
> 
> author wants it to do. Everything else is secondary." But a bit of 
> 
> styling will make reading and changing easier.
> 
> 
> 
> -- 
> 
> Terry Jan Reedy

Thanks Peter and Terry Jan for the useful suggestions. One thing which I find a 
bit weird: when asking for Python-help concerning raspberry pi code or 
problems, a lot of people don't seem to be interested in helping out, that's of 
course their choice, but maybe they don't seem to be aware the raspberry pi is 
often the motivation for starting to learn to program in Python. And as such 
such a reaction is a bit disappointing.

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


Re: [newbie] advice and comment wanted on first tkinter program

2014-01-19 Thread Jean Dupont
Op zaterdag 18 januari 2014 16:12:41 UTC+1 schreef Oscar Benjamin:
> On 18 January 2014 14:52, Jean Dupont  wrote:
> >
> > Thanks Peter and Terry Jan for the useful suggestions. One thing which I 
> >find a bit weird: when asking for Python-help concerning raspberry pi code 
> > or problems, a lot of people don't seem to be interested in helping out, 
> > that's of course their choice, but maybe they don't seem to be aware the 
> > raspberry pi is often the motivation for starting to learn to program in 
> >Python. And as such such a reaction is a bit disappointing.
> Hi Jean,
> What makes you say that? Did you previously ask questions about
> Rasberry Pi code on this list?
It was not about code but about python-coding in IDLE (that's the default
on raspbian):
I started a thread "[newbie] starting geany from within idle does not
work" both here and in the raspberry pi forum. I just wondered why I never
got an answer concerning that topic.

> If you did I wouldn't have answered those questions because I've never
> used a Raspberry Pi and know nothing about them (except that they
> encourage using Python somehow). I think that there's actually a list
> that is specifically for Raspberry Pi Python questions that might be
> more helpful although I don't know what it is...
Here is the url to that forum

http://www.raspberrypi.org/forum/

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


Re: [newbie] advice and comment wanted on first tkinter program

2014-01-21 Thread Jean Dupont
Op maandag 20 januari 2014 07:24:31 UTC+1 schreef Chris Angelico:
> On Mon, Jan 20, 2014 at 3:04 PM, Jean Dupont  wrote:
> > I started a thread "[newbie] starting geany from within idle does not
> > work" both here and in the raspberry pi forum. I just wondered why I never
> > got an answer concerning that topic.
> I saw that thread. It looked like a R-Pi problem, not a Python one, so
> I didn't respond because I don't have an R-Pi. If you get no response
> on the R-Pi forum, you might want to see if you can duplicate the
> issue on a desktop computer - preferably on Win/Mac/Lin, as those are
> the platforms most people use. That, with exact steps to repro (which
> it looks like you gave for the R-Pi, though again I can't verify),
> would get some interest.
I did try to do the same on my linux desktop computer, but the problem is,
it has another desktop environment (KDE4). In the rpi-environment it is
possible
(but it doesn't work) to change the default IDLE-editor by right-clicking
the idle-icon and choosing geany in stead of leafpad, however the same
can't be done
in KDE4, I hoped to find a similar setting once running IDLE in
Options-->Configure IDLE, but nothing there neither. I also looked
unsuccessfuly in the .idlerc-directory for a config-file. Hence my initial
question.

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


Re: [newbie] advice and comment wanted on first tkinter program

2014-01-22 Thread Jean Dupont
Op maandag 20 januari 2014 10:17:15 UTC+1 schreef Alister:
> On Sun, 19 Jan 2014 20:04:05 -0800, Jean Dupont wrote:
>
> > Op zaterdag 18 januari 2014 16:12:41 UTC+1 schreef Oscar Benjamin:
> >> On 18 January 2014 14:52, Jean Dupont  wrote:
> >> >
> >> > Thanks Peter and Terry Jan for the useful suggestions. One thing
> >> > which I
> >> >find a bit weird: when asking for Python-help concerning raspberry pi
> >> >code
> >> > or problems, a lot of people don't seem to be interested in helping
> >> > out,
> >> > that's of course their choice, but maybe they don't seem to be aware
> >> > the raspberry pi is often the motivation for starting to learn to
> >> > program in
> >> >Python. And as such such a reaction is a bit disappointing.
> >> Hi Jean,
> >> What makes you say that? Did you previously ask questions about
> >> Rasberry Pi code on this list?
> > It was not about code but about python-coding in IDLE (that's the
> > default on raspbian):
> > I started a thread "[newbie] starting geany from within idle does not
> > work" both here and in the raspberry pi forum. I just wondered why I
> > never got an answer concerning that topic.
> > 
> >> If you did I wouldn't have answered those questions because I've never
> >> used a Raspberry Pi and know nothing about them (except that they
> >> encourage using Python somehow). I think that there's actually a list
> >> that is specifically for Raspberry Pi Python questions that might be
> >> more helpful although I don't know what it is...
> > Here is the url to that forum
> > 
> > http://www.raspberrypi.org/forum/
> > 
> > kind regards,
> > jean
>
> Personally  use Geany  stand alone and not under idle, pressing F5 should 
> save & run the code you are currently editing. Would running under idle 
> give any other benefits? 
I don't know yet, but I just wanted to try out which of the following three I'd 
like best:
1. idle+leafpad
2. idle+geany
3. plain geany

It's normal for a newbie to start with (1) as that is the default on raspbian,
however I still don't understand why (2) does not work...

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


Re: [newbie] advice and comment wanted on first tkinter program

2014-01-27 Thread Jean Dupont
Op woensdag 22 januari 2014 16:43:21 UTC+1 schreef Alister:
> On Wed, 22 Jan 2014 06:45:53 -0800, Jean Dupont wrote:
>
> > Op maandag 20 januari 2014 10:17:15 UTC+1 schreef Alister:
> >> On Sun, 19 Jan 2014 20:04:05 -0800, Jean Dupont wrote:
> >>
> >> > Op zaterdag 18 januari 2014 16:12:41 UTC+1 schreef Oscar Benjamin:
> >> >> On 18 January 2014 14:52, Jean Dupont 
> >> >> wrote:
> >> >> >
> >> >> > Thanks Peter and Terry Jan for the useful suggestions. One thing
> >> >> > which I
> >> >> >find a bit weird: when asking for Python-help concerning raspberry
> >> Personally  use Geany  stand alone and not under idle, pressing F5
> >> should save & run the code you are currently editing. Would running
> >> under idle give any other benefits?
> > I don't know yet, but I just wanted to try out which of the following
> > three I'd like best:
> > 1. idle+leafpad 2. idle+geany 3. plain geany
> > 
> > It's normal for a newbie to start with (1) as that is the default on
> > raspbian,
> > however I still don't understand why (2) does not work...
> > 
> When I play with my Pi I tend to use another computer for all my editing
> (sshfs is a quick & easy way for me to mount the necessary parts of the 
> PI file system so I don't have to keep transferring files)
Thanks for the suggestion, I'm going to try it out

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


Re: [newbie] advice and comment wanted on first tkinter program

2014-01-27 Thread Jean Dupont
Op woensdag 22 januari 2014 15:45:53 UTC+1 schreef Jean Dupont:
> Op maandag 20 januari 2014 10:17:15 UTC+1 schreef Alister:
> > On Sun, 19 Jan 2014 20:04:05 -0800, Jean Dupont wrote:
> >
> > > Op zaterdag 18 januari 2014 16:12:41 UTC+1 schreef Oscar Benjamin:
> > >> On 18 January 2014 14:52, Jean Dupont  wrote:
> > >> >
> > >> > Thanks Peter and Terry Jan for the useful suggestions. One thing
> > >> > which I
> > >> >find a bit weird: when asking for Python-help concerning raspberry pi
> > >> >code
> > >> > or problems, a lot of people don't seem to be interested in helping
> > >> > out,
> > >> > that's of course their choice, but maybe they don't seem to be aware
> > >> > the raspberry pi is often the motivation for starting to learn to
> > >> > program in
> > >> >Python. And as such such a reaction is a bit disappointing.
> > >> Hi Jean,
> > >> What makes you say that? Did you previously ask questions about
> > >> Rasberry Pi code on this list?
> > > It was not about code but about python-coding in IDLE (that's the
> > > default on raspbian):
> > > I started a thread "[newbie] starting geany from within idle does not
> > > work" both here and in the raspberry pi forum. I just wondered why I
> > > never got an answer concerning that topic.
> > > 
> > >> If you did I wouldn't have answered those questions because I've never
> > >> used a Raspberry Pi and know nothing about them (except that they
> > >> encourage using Python somehow). I think that there's actually a list
> > >> that is specifically for Raspberry Pi Python questions that might be
> > >> more helpful although I don't know what it is...
> > > Here is the url to that forum
> > > 
> > > http://www.raspberrypi.org/forum/
> > > 
> > > kind regards,
> > > jean
> >
> > Personally  use Geany  stand alone and not under idle, pressing F5 should 
> > save & run the code you are currently editing. Would running under idle 
> > give any other benefits? 
> I don't know yet, but I just wanted to try out which of the following three 
> I'd like best:
> 1. idle+leafpad
> 2. idle+geany
> 3. plain geany
>
> It's normal for a newbie to start with (1) as that is the default on raspbian,
> however I still don't understand why (2) does not work...
I finally found out where I was wrong: leafpad is _not_ the default choice
in IDLE, IDLE has its own built in editor and IDLE does not allow to use
another editor. The confusion stemmed from the properties I got when right
clicking on the IDLE-icon on the raspbian desktop, which shows "Open with"
and then suggests the default choice is Leafpad and Geany as a second
choice, it has however nothin to do with IDLE as such.

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


[newbie] making rows of table with discrete values for different number systems

2014-02-02 Thread Jean Dupont
I'm looking for an efficient method to produce rows of tables like this:

for base 2
0 0 0 0
0 0 0 1
0 0 1 0
0 0 1 1
0 1 0 0
.
.
.
1 1 1 1

for base 3
0 0 0 0 0 0
0 0 0 0 0 1
0 0 0 0 0 2
0 0 0 0 1 0
0 0 0 0 1 1
0 0 0 0 1 2
.
.
2 2 2 2 2 2

As you can see the rows are always twice the size of the base
I _don't_ need to have all rows available together in one array which would 
become too large for higher value number bases. It's sufficient to produce
one row after the other, as I will do further data manipulation on such a row
immediately.

If someone here could suggest best practices to perform this kind of 
operations,I'd really appreciate it very much

kind regards and thanks in advance
jean

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


Re: [newbie] making rows of table with discrete values for different number systems

2014-02-02 Thread Jean Dupont
Op zondag 2 februari 2014 19:10:32 UTC+1 schreef Peter Otten:
> Jean Dupont wrote:
>
> > I'm looking for an efficient method to produce rows of tables like this:
> > 
> > for base 2
> > 0 0 0 0
> > 0 0 0 1
> > 0 0 1 0
> > 0 0 1 1
> > 0 1 0 0
> > .
> > .
> > .
> > 1 1 1 1
> > 
> > for base 3
> > 0 0 0 0 0 0
> > 0 0 0 0 0 1
> > 0 0 0 0 0 2
> > 0 0 0 0 1 0
> > 0 0 0 0 1 1
> > 0 0 0 0 1 2
> > .
> > .
> > 2 2 2 2 2 2
> > 
> > As you can see the rows are always twice the size of the base
> > I _don't_ need to have all rows available together in one array which
> > would become too large for higher value number bases. It's sufficient to
> > produce one row after the other, as I will do further data manipulation on
> > such a row immediately.
> > 
> > If someone here could suggest best practices to perform this kind of
> > operations,I'd really appreciate it very much
>
> Have a look at itertools.product(): 
>
> >>> import itertools
> >>> for row in itertools.product(range(2), repeat=4):
> ... print(*row)
> ... 
> 0 0 0 0
> 0 0 0 1
> 0 0 1 0
> 0 0 1 1
> 0 1 0 0
> 0 1 0 1
> 0 1 1 0
> 0 1 1 1
> 1 0 0 0
> 1 0 0 1
> 1 0 1 0
> 1 0 1 1
> 1 1 0 0
> 1 1 0 1
> 1 1 1 0
> 1 1 1 1

Thanks for the suggestion I'm going to look into it further

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


Re: [newbie] making rows of table with discrete values for different number systems

2014-02-03 Thread Jean Dupont
Op maandag 3 februari 2014 02:56:43 UTC+1 schreef Asaf Las:
> On Sunday, February 2, 2014 10:51:15 PM UTC+2, Jean Dupont wrote:
> > Op zondag 2 februari 2014 19:10:32 UTC+1 schreef Peter Otten:
> > 
> > I'm looking for an efficient method to produce rows of tables like this: 
> > jean
> you can also try to make below universal for all needed bases: 
> m = lambda m, n: 1 if m & n else 0
> k = [[ m(x,8) , m(x, 4), m(x, 2), m(x, 1)] for x in range(10)]
> print (k)
Dear Asaf,
I'm not at ease with lamba-notation, could you show me how to modify your
example for the base 3 case? I guess then it will be much clearer to me

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


Re: [newbie] making rows of table with discrete values for different number systems

2014-02-03 Thread Jean Dupont
Op zondag 2 februari 2014 19:07:38 UTC+1 schreef Roy Smith:
> In article <515e582f-ed17-4d4e-9872-f07f1fda6...@googlegroups.com>,
>  Jean Dupont  wrote:
>
> > I'm looking for an efficient method to produce rows of tables like this:
> > 
> > for base 2
> > 0 0 0 0
> > 0 0 0 1
> > 0 0 1 0
> > 0 0 1 1
> > 0 1 0 0
> > .
> > .
> > .
> > 1 1 1 1
> > 
> > for base 3
> > 0 0 0 0 0 0
> > 0 0 0 0 0 1
> > 0 0 0 0 0 2
> > 0 0 0 0 1 0
> > 0 0 0 0 1 1
> > 0 0 0 0 1 2
> > .
> > .
> > 2 2 2 2 2 2
>
> This sounds like a homework problem :-)
>
> > As you can see the rows are always twice the size of the base
>
> Why?
>
> > I _don't_ need to have all rows available together in one array which would 
> > become too large for higher value number bases. It's sufficient to produce
> > one row after the other, as I will do further data manipulation on such a 
> > row
> > immediately.
>
> What I get out of that is that you don't want to just print them, you 
> want to have some function which returns all the generated rows in 
> order.  The way to do that is with the yield statement.  Take a look at 
> https://wiki.python.org/moin/Generators for some discussion on how that 
> works.  Actually, http://stackoverflow.com/questions/231767/
> looks like an even better discussion.
>
> Does that help you any?

Thanks, I'll try to figure out what yield does

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


[newbie] troubles with tuples

2014-02-03 Thread Jean Dupont
I'm looking at the way to address tuples
e.g.
tup2 = (1, 2, 3, 4, 5, 6, 7 );

As I found out indices start with 0 in Python, so 
tup2[0] gives me 1, the first element in the tuple as expected
tup2[1] gives me 2, the second element in the tuple as expected
now here comes what surprises me:
tup2[0:1] does not give me the expected (1,2) but (2,)

what is the reason for this and how then should one get the first and the 
second element of a tuple? Or the 3rd until the 5th?

thanks in advance and kind regards,

jean

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


Re: [newbie] troubles with tuples

2014-02-03 Thread Jean Dupont
Op maandag 3 februari 2014 18:06:46 UTC+1 schreef Rustom Mody:
> On Monday, February 3, 2014 10:20:31 PM UTC+5:30, Jean Dupont wrote:
> > I'm looking at the way to address tuples
> > e.g.
> > tup2 = (1, 2, 3, 4, 5, 6, 7 );
> > As I found out indices start with 0 in Python, so 
> > tup2[0] gives me 1, the first element in the tuple as expected
> > tup2[1] gives me 2, the second element in the tuple as expected
> > now here comes what surprises me:
> > tup2[0:1] does not give me the expected (1,2) but (2,)
>
> Python 2.7.6 (default, Jan 11 2014, 17:06:02) 
> [GCC 4.8.2] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> tup2=(1,2,3,4,5,6,7)
> >>> tup2[0:1]
> (1,)
> >>> 
> So assuming you meant (1,) and wrote (2,) :-)
> > what is the reason for this and how then should one get the first and the 
> > second element of a tuple? Or the 3rd until the 5th?
> Generally ranges in python are lower-inclusive upper-exclusive
> What some math texts write as [lo, hi)
> So if you want from index 1 to 2-inclusive it is 1 to 3 exclusive
> tup2[0:2]
>
> See for motivations
> http://www.cs.utexas.edu/~EWD/transcriptions/EWD08xx/EWD831.html
> And one more surprising thing to note is that negatives count from the end
Thank you (and the others) for making this "logical"

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


Re: [newbie] making rows of table with discrete values for different number systems

2014-02-03 Thread Jean Dupont
Op maandag 3 februari 2014 16:34:18 UTC+1 schreef Asaf Las:
> On Monday, February 3, 2014 5:05:40 PM UTC+2, Jean Dupont wrote:
> > Op maandag 3 februari 2014 02:56:43 UTC+1 schreef Asaf Las:
> > 
> > > On Sunday, February 2, 2014 10:51:15 PM UTC+2, Jean Dupont wrote:
> > > > Op zondag 2 februari 2014 19:10:32 UTC+1 schreef Peter Otten:
> > > > I'm looking for an efficient method to produce rows of tables like 
> > > > this: 
> > > > jean
> > 
> > > you can also try to make below universal for all needed bases: 
> > > m = lambda m, n: 1 if m & n else 0
> > > k = [[ m(x,8) , m(x, 4), m(x, 2), m(x, 1)] for x in range(10)]
> > 
> > > print (k)
> > 
> > Dear Asaf,
> > I'm not at ease with lamba-notation, could you show me how to modify your
> > example for the base 3 case? I guess then it will be much clearer to me
> > thanks in advance
> > 
> > jean
>
> I don't have to - use normal functions instead :-)
Of course you don't have to, but I'm curious and learn well by examples

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


[newbie] copying identical list for a function argument

2014-02-03 Thread Jean Dupont
I have a list like this:
[1,2,3]

The argument of my function should be a repeated version e.g.
[1,2,3],[1,2,3],[1,2,3],[1,2,3] (could be a different number of times repeated 
also)

what is the prefered method to realize this in Python?

any help would be really appreciated

kind regards,
jean

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


Re: [newbie] copying identical list for a function argument

2014-02-04 Thread Jean Dupont
Op maandag 3 februari 2014 23:19:39 UTC+1 schreef Steven D'Aprano:
> On Mon, 03 Feb 2014 13:36:24 -0800, Jean Dupont wrote:
> > I have a list like this:
> > [1,2,3]
> > 
> > The argument of my function should be a repeated version e.g.
> > [1,2,3],[1,2,3],[1,2,3],[1,2,3] (could be a different number of times
> > repeated also)
> > 
> > what is the prefered method to realize this in Python?
>
> I don't really understand your question. It could mean any of various 
> things, so I'm going to try to guess what you mean. If my guesses are 
> wrong, please ask again, giving more detail, and possibly an example of 
> what you want to do and the result you expect.
> I think you mean that you have some function that needs to take (say) 
> five arguments, and you want to avoid writing:
> result = function([1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 23], [1, 2, 3])
> because it's too easy to make a mistake (as I did, deliberately, above -- 
> can you see it?).
> If my guess is correct, try this:
> mylist = [1, 2, 3]
> result = function(mylist, mylist, mylist, mylist, mylist)
>
> That's perfectly reasonable for two or three arguments, but not so much 
> for five. Instead, here's a trick: first we make five identical 
> references to the same list:
> [mylist]*5  # same as [mylist, mylist, mylist, mylist, mylist]
> then expand them as arguments to the function:
> mylist = [1, 2, 3]
> list_of_lists = [mylist]*5
> result = function(*list_of_lists)
> (The * operator means multiplication when used between two arguments, and 
> inside a function call a leading * also does argument expansion.)
>
> But wait... there's something slightly weird here. Even though there are 
> five distinct references to mylist, they're all the same list! Change 
> one, change all. This may be what you want, or it may be a problem. Hard 
> to tell from your question.
> Think about references as being a little bit like names. A *single* 
> person could be known as "son", "Dad", "Mr Obama", "Barack", "Mr 
> President", "POTUS", and more. In this case, we have a single list, [1, 
> 2, 3], which is known by six references: the name "mylist", and five 
> additional references list_of_lists index 0, list_of_lists index 1, and 
> so on up to list_of_lists index 4.
> We can prove that they all refer to the same list by running a bit of 
> code in the interactive interpreter:
>
> py> mylist = [1, 2, 3]
> py> list_of_lists = [mylist]*5
> py> list_of_lists
> [[1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3]]
> py> mylist.append(99)
> py> list_of_lists
> [[1, 2, 3, 99], [1, 2, 3, 99], [1, 2, 3, 99], [1, 2, 3, 99], [1, 2, 3, 
> 99]]
>
> So rather than having five references to the same, identical, list, you 
> might want five *copies*. You can copy a list using slicing:
> mylist = [1, 2, 3]
> copy = mylist[:]
> Instead of using list multiplication to repeat five identical lists, we 
> make five copies using a list comprehension:
> list_of_lists = [mylist[:] for i in range(5)]
> then expand it in the function call as before:
> result = function(*list_of_lists)
>
> Hope this helps,
Yes it does, thanks a lot to you and all the others who responded, "the
missing link" which until now I wasn't aware of but which was essential
for the solution was the "*" in
result = function(*list_of_lists)

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


Re: [newbie] making rows of table with discrete values for different number systems

2014-02-04 Thread Jean Dupont
Op maandag 3 februari 2014 20:50:04 UTC+1 schreef Asaf Las:
> On Monday, February 3, 2014 9:37:36 PM UTC+2, Jean Dupont wrote:
> > Op maandag 3 februari 2014 16:34:18 UTC+1 schreef Asaf Las:
> > 
> > Of course you don't have to, but I'm curious and learn well by examples
> > :-(
>
> Hi Jean 
>
> Don't get me wrong i did not mean to be rude (was joking) - i 
> think if you will do it yourself that will be very good for 
> you - you can learn a lot from that as i did not very long time ago. 
> My apologies for inconvenience.
no hard feelings, anyway I am programming it myself using normal functions, 
when I have finished it I'll post it, then maybe you can do it with 
lamba-notation, it could be interesting to compare execution times for the two 
approaches

kind regards,
jean

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