Re: Tkinter spacing

2016-01-26 Thread Peter Otten
KP wrote:

> If I want to have some space between, say, btn_last & btn_new, will I have
> to use a dummy label in between these two or is there a better way?
> 
> Thanks for any help, as always!

You could use nested frames with nonzero padding, e. g:

nav_bar = ttk.Frame(root, borderwidth=2, relief='ridge', padding=(0, 3))

nav_bar1 = ttk.Frame(nav_bar, padding=(5, 0))
nav_bar1.pack(side=LEFT)

btn_first  = ttk.Button(nav_bar1, text='|<', width=4)  
btn_first.grid(column=0, row=0)
...

nav_bar2 = ttk.Frame(nav_bar, padding=(5, 0))
nav_bar2.pack(side=LEFT)

btn_new= ttk.Button(nav_bar2, text='New')
btn_new.grid(column=0, row=0)
...

> from tkinter import *
> from tkinter import ttk
> 
> root = Tk()
> root.geometry("822x600+100+100")
> nav_bar = ttk.Frame(root, borderwidth=2, relief='ridge', padding=(10, 3,
> 10, 3))
> 
> btn_first  = ttk.Button(nav_bar, text='|<', width=4)  # for buttons
> showing text only, this will be text units (= average characters?)
> btn_prev   = ttk.Button(nav_bar, text='<',  width=4)  # for image buttons,
> it will be in pixels
> btn_next   = ttk.Button(nav_bar, text='>',  width=4)
> btn_last   = ttk.Button(nav_bar, text='>|', width=4)
> btn_new= ttk.Button(nav_bar, text='New')
> btn_edit   = ttk.Button(nav_bar, text='Edit')
> btn_delete = ttk.Button(nav_bar, text='Delete')
> btn_cancel = ttk.Button(nav_bar, text='Cancel')
> btn_print  = ttk.Button(nav_bar, text='Print')
> btn_help   = ttk.Button(nav_bar, text='Help')
> btn_save   = ttk.Button(nav_bar, text='Save')
> lbl_Recs   = ttk.Label(nav_bar,  text='Records')
> lbl_RCount = ttk.Label(nav_bar,  text='0 ', width=10, borderwidth=2,
> relief='sunken', anchor='e')  # fake entry look
> 
> nav_bar.grid(column=0, row=0, columnspan=13)
> 
> btn_first.grid(column=0, row=0)
> btn_prev.grid(column=1,  row=0)
> btn_next.grid(column=2,  row=0)
> btn_last.grid(column=3,  row=0)
> 
> btn_new.grid(column=4,row=0)
> btn_edit.grid(column=5,   row=0)
> btn_delete.grid(column=6, row=0)
> btn_cancel.grid(column=7, row=0)
> 
> lbl_Recs.grid(column=8,   row=0, padx=5)
> lbl_RCount.grid(column=9, row=0, padx=5)
> btn_print.grid(column=10, row=0)
> btn_help.grid(column=11,  row=0)
> btn_save.grid(column=12,  row=0)
> 
> root.mainloop()


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


Python Unit test

2016-01-26 Thread toluagboola
I'm a University student of IT with majors in Embedded Systems. I have this 
assignment where I have to write Unittest for a simple Python Code without 
having prior knowledge of Python. I really need some help.
Thanks
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Unit test

2016-01-26 Thread David Palao
Hello,
It would be good to provide more details on what you need help for.
For instance, have you read the manual
https://docs.python.org/3/library/unittest.html
?
It even contains a couple of examples.

Best

2016-01-26 12:09 GMT+01:00  :
> I'm a University student of IT with majors in Embedded Systems. I have this 
> assignment where I have to write Unittest for a simple Python Code without 
> having prior knowledge of Python. I really need some help.
> Thanks
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Unit test

2016-01-26 Thread toluagboola
Yes I have studied the page but it's quite vague to me. So we have this project 
- Development of a touch screen controllable IEC61850 standard protocol 
analyzer. With this analyzer user can monitor and analyze network traffic in 
substation network.
-- 
https://mail.python.org/mailman/listinfo/python-list


python-2.7.3 vs python-3.2.3

2016-01-26 Thread Gene Heskett
Greetings;

I have need of using a script written for python3, but the default python 
on wheezy is 2.7.3.

I see in the wheezy repos that 3.2.3-6 is available.

Can/will they co-exist peacefully?

Thank you.

Cheers, Gene Heskett
-- 
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
Genes Web page 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Unit test

2016-01-26 Thread David Palao
Well, there is a very specific example in there.
But you still don't give us much information about *concrete* troubles you have.
I *guess* that one of the following is true:
1) You have problems to understand some part of the example in the
unittest module documentation.
2) You don't know how to apply those ideas to some specific code you have.
3) something else.
Could you please be more specific?

Best

2016-01-26 13:26 GMT+01:00  :
> Yes I have studied the page but it's quite vague to me. So we have this 
> project - Development of a touch screen controllable IEC61850 standard 
> protocol analyzer. With this analyzer user can monitor and analyze network 
> traffic in substation network.
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python-2.7.3 vs python-3.2.3

2016-01-26 Thread Wolfgang Maier

I have used 2.7 and 3.2 side-by-side for two years or so on Ubuntu 12.04.
Never encountered any problem except for a few times that I accidentally 
tried to run something with python when I should have used python3.


Cheers,
Wolfgang


On 26.01.2016 13:26, Gene Heskett wrote:

Greetings;

I have need of using a script written for python3, but the default python
on wheezy is 2.7.3.

I see in the wheezy repos that 3.2.3-6 is available.

Can/will they co-exist peacefully?

Thank you.

Cheers, Gene Heskett



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


Re: python-2.7.3 vs python-3.2.3

2016-01-26 Thread David Palao
Hello,
On my system I have 2.7.10 and 3.4.3 system wide, but it is not
debian. Of course, the "python" executable can be only one of them at
a given time.
Another option is tu use a virtual environment or something (pyvenv or
virtualenv).


Best

2016-01-26 13:26 GMT+01:00 Gene Heskett :
> Greetings;
>
> I have need of using a script written for python3, but the default python
> on wheezy is 2.7.3.
>
> I see in the wheezy repos that 3.2.3-6 is available.
>
> Can/will they co-exist peacefully?
>
> Thank you.
>
> Cheers, Gene Heskett
> --
> "There are four boxes to be used in defense of liberty:
>  soap, ballot, jury, and ammo. Please use in that order."
> -Ed Howdershelt (Author)
> Genes Web page 
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Unit test

2016-01-26 Thread Bernardo Sulzbach
Or maybe he doesn't know enough about unit testing. If that is the
case, Wikipedia and SO should have you covered. Amazon has a few books
on the subject, too.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python-2.7.3 vs python-3.2.3

2016-01-26 Thread Grobu

On 26/01/16 13:26, Gene Heskett wrote:

Greetings;

I have need of using a script written for python3, but the default python
on wheezy is 2.7.3.

I see in the wheezy repos that 3.2.3-6 is available.

Can/will they co-exist peacefully?

Thank you.

Cheers, Gene Heskett



On Debian Jessie :

$ ls -F /usr/bin/pyth*
/usr/bin/python@ /usr/bin/python3@ /usr/bin/python3m@
/usr/bin/python2@/usr/bin/python3.4*
/usr/bin/python2.7*  /usr/bin/python3.4m*

... so it seems they can co-exist peacefully.

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


Re: python-2.7.3 vs python-3.2.3

2016-01-26 Thread Matt Wheeler
On 26 January 2016 at 12:26, Gene Heskett  wrote:
> Greetings;
>
> I have need of using a script written for python3, but the default python
> on wheezy is 2.7.3.
>
> I see in the wheezy repos that 3.2.3-6 is available.
>
> Can/will they co-exist peacefully?

Yes, python packages for different minor versions do not clash with
one another on Debian (or any other system I am aware of).

The `python` executable is provided by a version of Python 2 (decided
by the "alternatives" system on Debian if there is more than one).

Python 3 packages will only provide a `python3` executable, not
`python`, so everything will continue to work as it currently does.


The only slight issue you might encounter is that Python 3.2 is quite
old now and actually not as well supported as Python 2.7 (many
projects support Python 2.7 or 3.3+ only). Best to just try out your
script and find out though.


-- 
Matt Wheeler
http://funkyh.at
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python-2.7.3 vs python-3.2.3

2016-01-26 Thread Nick Sarbicki
On Tue, Jan 26, 2016 at 2:22 PM David Palao  wrote:

> Hello,
> On my system I have 2.7.10 and 3.4.3 system wide, but it is not
> debian. Of course, the "python" executable can be only one of them at
> a given time.
> Another option is tu use a virtual environment or something (pyvenv or
> virtualenv).
>
>
Worth noting that it is best to leave the default, python, as pointing to
2.7.

I believe Ubuntu has removed all dependencies on 2.x now (from memory,
can't remember source so correct me if I'm wrong), which would suggest to
me that Debian has done the same. But some systems will still be reliant on
it.

Then there is also this PEP:

https://www.python.org/dev/peps/pep-0394/

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


Re: Question about asyncio and blocking operations

2016-01-26 Thread Frank Millman

"Frank Millman"  wrote in message news:[email protected]...


I am developing a typical accounting/business application which involves a 
front-end allowing clients to access the system, a back-end connecting to 
a database, and a middle layer that glues it all together.



[...]


There was one aspect that I deliberately ignored at that stage. I did not 
change the database access to an asyncio approach, so all reading 
from/writing to the database involved a blocking operation. I am now ready 
to tackle that.


I am making some progress, but I have found a snag - possibly unavoidable, 
but worth a mention.


Usually when I retrieve rows from a database I iterate over the cursor -

   def get_rows(sql, params):
   cur.execute(sql, params)
   for row in cur:
   yield row

If I create a Future to run get_rows(), I have to 'return' the result so 
that the caller can access it by calling future.result().


If I return the cursor, I can iterate over it, but isn't this a blocking 
operation? As far as I know, the DB adaptor will only actually retrieve the 
row when requested.


If I am right, I should call fetchall() while inside get_rows(), and return 
all the rows as a list.


This seems to be swapping one bit of asynchronicity for another.

Does this sound right?

Frank


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


Re: python-2.7.3 vs python-3.2.3

2016-01-26 Thread Wolfgang Maier

On 26.01.2016 15:34, Matt Wheeler wrote:


The only slight issue you might encounter is that Python 3.2 is quite
old now and actually not as well supported as Python 2.7 (many
projects support Python 2.7 or 3.3+ only). Best to just try out your
script and find out though.



Right. For example, pip dropped support for Python 3.2 last week. So if 
you need to install it make sure you do it via:


curl https://bootstrap.pypa.io/3.2/get-pip.py | python3.2

see: https://github.com/pypa/get-pip

then ignore the upgrade advice because pip versions 8.0.0 and above will 
not work for you.


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


Re: python-2.7.3 vs python-3.2.3

2016-01-26 Thread Gene Heskett
On Tuesday 26 January 2016 09:20:16 Wolfgang Maier wrote:

> I have used 2.7 and 3.2 side-by-side for two years or so on Ubuntu
> 12.04. Never encountered any problem except for a few times that I
> accidentally tried to run something with python when I should have
> used python3.

I think thats unavoidable. ;-)

I'm not sure what I'll need to go with it, but we'll find out today.

Thanks Wolfgang

Cheers, Gene Heskett
-- 
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
Genes Web page 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python-2.7.3 vs python-3.2.3

2016-01-26 Thread Chris Angelico
On Wed, Jan 27, 2016 at 2:11 AM, Gene Heskett  wrote:
> On Tuesday 26 January 2016 09:20:16 Wolfgang Maier wrote:
>
>> I have used 2.7 and 3.2 side-by-side for two years or so on Ubuntu
>> 12.04. Never encountered any problem except for a few times that I
>> accidentally tried to run something with python when I should have
>> used python3.
>
> I think thats unavoidable. ;-)
>
> I'm not sure what I'll need to go with it, but we'll find out today.
>
> Thanks Wolfgang

Here's what I'd recommend :)

$ sudo apt-get build-dep python3
$ sudo apt-get install mercurial
$ hg clone https://hg.python.org/cpython
$ cd cpython
$ ./configure
$ make
$ sudo make install

That should get you Python 3.6 with a whole lot of new features above
3.2. (And yes, 3.6 and 3.2 can happily coexist too.) After that,
you'll want to use pip exclusively for installing Python modules (you
can use apt-get to grab packages for your 3.2 install, but it won't do
anything for your 3.6), but other than that, you should have a
perfectly working system that runs the very latest in Pythons.

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


thanks

2016-01-26 Thread Kawuma Julius
Thank you for developing us.We love you God bless you the more. I am Julius
in Uganda learning computer.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question about asyncio and blocking operations

2016-01-26 Thread Ian Kelly
On Tue, Jan 26, 2016 at 7:15 AM, Frank Millman  wrote:
> I am making some progress, but I have found a snag - possibly unavoidable,
> but worth a mention.
>
> Usually when I retrieve rows from a database I iterate over the cursor -
>
>def get_rows(sql, params):
>cur.execute(sql, params)
>for row in cur:
>yield row
>
> If I create a Future to run get_rows(), I have to 'return' the result so
> that the caller can access it by calling future.result().
>
> If I return the cursor, I can iterate over it, but isn't this a blocking
> operation? As far as I know, the DB adaptor will only actually retrieve the
> row when requested.
>
> If I am right, I should call fetchall() while inside get_rows(), and return
> all the rows as a list.
>
> This seems to be swapping one bit of asynchronicity for another.
>
> Does this sound right?

You probably want an asynchronous iterator here. If the cursor doesn't
provide that, then you can wrap it in one. In fact, this is basically
one of the examples in the PEP:
https://www.python.org/dev/peps/pep-0492/#example-1
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Unit test

2016-01-26 Thread Tolu Agboola
I'll go with number 2. I don't know how to apply the ideas to the code I have. 

Sent from my iPhone

> On 26 Jan 2016, at 15:48, David Palao  wrote:
> 
> Well, there is a very specific example in there.
> But you still don't give us much information about *concrete* troubles you 
> have.
> I *guess* that one of the following is true:
> 1) You have problems to understand some part of the example in the
> unittest module documentation.
> 2) You don't know how to apply those ideas to some specific code you have.
> 3) something else.
> Could you please be more specific?
> 
> Best
> 
> 2016-01-26 13:26 GMT+01:00  :
>> Yes I have studied the page but it's quite vague to me. So we have this 
>> project - Development of a touch screen controllable IEC61850 standard 
>> protocol analyzer. With this analyzer user can monitor and analyze network 
>> traffic in substation network.
>> --
>> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Unit test

2016-01-26 Thread Joel Goldstick
On Tue, Jan 26, 2016 at 10:48 AM, Tolu Agboola 
wrote:

> I'll go with number 2. I don't know how to apply the ideas to the code I
> have.
>
> Sent from my iPhone
>
> > On 26 Jan 2016, at 15:48, David Palao  wrote:
> >
> > Well, there is a very specific example in there.
> > But you still don't give us much information about *concrete* troubles
> you have.
> > I *guess* that one of the following is true:
> > 1) You have problems to understand some part of the example in the
> > unittest module documentation.
> > 2) You don't know how to apply those ideas to some specific code you
> have.
> > 3) something else.
> > Could you please be more specific?
> >
> > Best
> >
> > 2016-01-26 13:26 GMT+01:00  :
> >> Yes I have studied the page but it's quite vague to me. So we have this
> project - Development of a touch screen controllable IEC61850 standard
> protocol analyzer. With this analyzer user can monitor and analyze network
> traffic in substation network.
> >> --
> >> https://mail.python.org/mailman/listinfo/python-list
> --
> https://mail.python.org/mailman/listinfo/python-list
>

Test driven development with python and django.  The complete text is
online here:
http://chimera.labs.oreilly.com/books/123400754/pr02.html#_python_3_and_programming


-- 
Joel Goldstick
http://joelgoldstick.com/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tkinter spacing

2016-01-26 Thread high5storage
On Monday, January 25, 2016 at 7:41:57 PM UTC-8, KP wrote:
> If I want to have some space between, say, btn_last & btn_new, will I have to 
> use a dummy label in between these two or is there a better way?
> 
> Thanks for any help, as always!
> 
> 
> 
> 
> from tkinter import *
> from tkinter import ttk
> 
> root = Tk()
> root.geometry("822x600+100+100")
> nav_bar = ttk.Frame(root, borderwidth=2, relief='ridge', padding=(10, 3, 10, 
> 3))
> 
> btn_first  = ttk.Button(nav_bar, text='|<', width=4)  # for buttons showing 
> text only, this will be text units (= average characters?)
> btn_prev   = ttk.Button(nav_bar, text='<',  width=4)  # for image buttons, it 
> will be in pixels 
> btn_next   = ttk.Button(nav_bar, text='>',  width=4)
> btn_last   = ttk.Button(nav_bar, text='>|', width=4)
> btn_new= ttk.Button(nav_bar, text='New')
> btn_edit   = ttk.Button(nav_bar, text='Edit')
> btn_delete = ttk.Button(nav_bar, text='Delete')
> btn_cancel = ttk.Button(nav_bar, text='Cancel')
> btn_print  = ttk.Button(nav_bar, text='Print')
> btn_help   = ttk.Button(nav_bar, text='Help')
> btn_save   = ttk.Button(nav_bar, text='Save')
> lbl_Recs   = ttk.Label(nav_bar,  text='Records')
> lbl_RCount = ttk.Label(nav_bar,  text='0 ', width=10, borderwidth=2, 
> relief='sunken', anchor='e')  # fake entry look
> 
> nav_bar.grid(column=0, row=0, columnspan=13)
> 
> btn_first.grid(column=0, row=0)
> btn_prev.grid(column=1,  row=0)
> btn_next.grid(column=2,  row=0)
> btn_last.grid(column=3,  row=0)
> 
> btn_new.grid(column=4,row=0)
> btn_edit.grid(column=5,   row=0)
> btn_delete.grid(column=6, row=0)
> btn_cancel.grid(column=7, row=0)
> 
> lbl_Recs.grid(column=8,   row=0, padx=5)
> lbl_RCount.grid(column=9, row=0, padx=5)
> btn_print.grid(column=10, row=0)
> btn_help.grid(column=11,  row=0)
> btn_save.grid(column=12,  row=0)
> 
> root.mainloop()

Hmm - this only gives me an empty window (no errors). 
What puzzles me that every book/site on tkinter strongly warns of mixing pack 
and grid managers...

Any ideas?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Unit test

2016-01-26 Thread David Palao
2016-01-26 16:56 GMT+01:00 Joel Goldstick :
> On Tue, Jan 26, 2016 at 10:48 AM, Tolu Agboola 
> wrote:
>
>> I'll go with number 2. I don't know how to apply the ideas to the code I
>> have.
>>
>> Sent from my iPhone
>>
>> > On 26 Jan 2016, at 15:48, David Palao  wrote:
>> >
>> > Well, there is a very specific example in there.
>> > But you still don't give us much information about *concrete* troubles
>> you have.
>> > I *guess* that one of the following is true:
>> > 1) You have problems to understand some part of the example in the
>> > unittest module documentation.
>> > 2) You don't know how to apply those ideas to some specific code you
>> have.
>> > 3) something else.
>> > Could you please be more specific?
>> >
>> > Best
>> >
>> > 2016-01-26 13:26 GMT+01:00  :
>> >> Yes I have studied the page but it's quite vague to me. So we have this
>> project - Development of a touch screen controllable IEC61850 standard
>> protocol analyzer. With this analyzer user can monitor and analyze network
>> traffic in substation network.
>> >> --
>> >> https://mail.python.org/mailman/listinfo/python-list
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>>
>
> Test driven development with python and django.  The complete text is
> online here:
> http://chimera.labs.oreilly.com/books/123400754/pr02.html#_python_3_and_programming
>
>
> --
> Joel Goldstick
> http://joelgoldstick.com/stats/birthdays
> --
> https://mail.python.org/mailman/listinfo/python-list

Good reference.
I like also this one:
http://code.tutsplus.com/tutorials/test-driven-development-in-python--net-30137
which is shorter.

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


show instant data on webpage

2016-01-26 Thread mustang

I've built a sensor to measure some values.
I would like to show it on a web page with python.


This is an extract of the code:

file  = open("myData.dat", "w")

while True:
temp = sensor.readTempC()
riga = "%f\n" % temp
file.write(riga)
time.sleep(1.0)

file.close()

Until this all ok.
Then in PHP I read the file and show it on internet. It works ok but...
First problem. I've to stop the streaming with CTRl-C to load the PHP 
file because if I try to read during measurement I cannot show anything 
(I think because the file is in using).

How can I show time by time in a webpage the output?

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


Re: show instant data on webpage

2016-01-26 Thread David Palao
2016-01-26 17:10 GMT+01:00 mustang :
> I've built a sensor to measure some values.
> I would like to show it on a web page with python.
>
>
> This is an extract of the code:
>
> file  = open("myData.dat", "w")
>
> while True:
> temp = sensor.readTempC()
> riga = "%f\n" % temp
> file.write(riga)
> time.sleep(1.0)
>
> file.close()
>
> Until this all ok.
> Then in PHP I read the file and show it on internet. It works ok but...
> First problem. I've to stop the streaming with CTRl-C to load the PHP file
> because if I try to read during measurement I cannot show anything (I think
> because the file is in using).
> How can I show time by time in a webpage the output?
>
> --
> https://mail.python.org/mailman/listinfo/python-list

Is this an option?

open("myData.dat", "w").close()

while True:
temp = sensor.readTempC()
riga = "%f\n" % temp
with open("myData.dat", "a") as f:
f.write(riga)
time.sleep(1)

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


Re: Tkinter spacing

2016-01-26 Thread Peter Otten
[email protected] wrote:

>> from tkinter import *
>> from tkinter import ttk
>> 
>> root = Tk()
>> root.geometry("822x600+100+100")
>> nav_bar = ttk.Frame(root, borderwidth=2, relief='ridge', padding=(10, 3,
>> 10, 3))
>> 
>> btn_first  = ttk.Button(nav_bar, text='|<', width=4)  # for buttons
>> root.mainloop()
> 
> Hmm - this only gives me an empty window (no errors).

That's strange. 

If you ran the script in Idle, try again from the commandline.

> What puzzles me that every book/site on tkinter strongly warns of mixing
> pack and grid managers...

You can mix pack and grid for one window, but you have to pick one layout 
manager per parent widget:

top = Toplevel(root)

panel = Frame(top)
panel.pack(...) 
# we picked pack() and now have to use it for all
# children of top
canvas = Canvas(top, ...)
canvas.pack(...) # must use pack() again

# we are free to pick a layout for panel
ok = Button(panel)
ok.grid(...)
# we picked grid() and now have to use it for all 
# children of panel
cancel = Button(panel)
cancel.grid(...) # must use grid()


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


Re: show instant data on webpage

2016-01-26 Thread mustang



open("myData.dat", "w").close()

while True:
 temp = sensor.readTempC()
 riga = "%f\n" % temp
 with open("myData.dat", "a") as f:
 f.write(riga)
 time.sleep(1)

yes great it works!thanks a lot!
Anyway to refresh temperature I've to recall anytime the php page.
My idea is to read for example the first line every x seconds...it 
should work.

Is it possible to use python and not php to plot data?


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


Re: python-2.7.3 vs python-3.2.3

2016-01-26 Thread Gene Heskett
On Tuesday 26 January 2016 10:21:07 Chris Angelico wrote:

> On Wed, Jan 27, 2016 at 2:11 AM, Gene Heskett  
wrote:
> > On Tuesday 26 January 2016 09:20:16 Wolfgang Maier wrote:
> >> I have used 2.7 and 3.2 side-by-side for two years or so on Ubuntu
> >> 12.04. Never encountered any problem except for a few times that I
> >> accidentally tried to run something with python when I should have
> >> used python3.
> >
> > I think thats unavoidable. ;-)
> >
> > I'm not sure what I'll need to go with it, but we'll find out today.
> >
> > Thanks Wolfgang
>
> Here's what I'd recommend :)
>
> $ sudo apt-get build-dep python3
> $ sudo apt-get install mercurial
> $ hg clone https://hg.python.org/cpython
> $ cd cpython
> $ ./configure
> $ make
> $ sudo make install

Message marked as important, should I need to. It turns out the script 
actually works fine on 2.7.3.

Thanks for the advice Chris, it will be helpfull in that event.

> That should get you Python 3.6 with a whole lot of new features above
> 3.2. (And yes, 3.6 and 3.2 can happily coexist too.) After that,
> you'll want to use pip exclusively for installing Python modules (you
> can use apt-get to grab packages for your 3.2 install, but it won't do
> anything for your 3.6), but other than that, you should have a
> perfectly working system that runs the very latest in Pythons.
>
> ChrisA


Cheers, Gene Heskett
-- 
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
Genes Web page 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Which Python editor has this feature?

2016-01-26 Thread Fabio Zadrozny
On Sun, Jan 10, 2016 at 11:59 PM,  wrote:

> It lets you jump between the current cursor position and the line the
> upper level indentation start, something like the bracket matching in C
> editor. Because of Python use indentation as its code block mark, It might
> be helpful if we can jump between different level of it:-)
>

​You can do this in Eclipse/PyDev by using the scope selector (​Shift + Alt
+ Up multiple times to select outer scopes and Shift + Alt + Down to
deselect) and then use left arrow to go to the start or right arrow to go
to the end (although if you're just navigating methods, you can do
Ctrl+Shift+Up / Down to select the previous/next method, which may be a bit
faster).

Best Regards,

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


Re: Which Python editor has this feature?

2016-01-26 Thread Fabio Zadrozny
On Mon, Jan 11, 2016 at 6:40 AM, Gordon Levi  wrote:

> [email protected] wrote:
>
> >It lets you jump between the current cursor position and the line the
> upper level indentation start, something like the bracket matching in C
> editor. Because of Python use indentation as its code block mark, It might
> be helpful if we can jump between different level of it:-)
>
> Jetbrains Pycharm has "go to start of block" and "go to end of block"
> commands .
>
> Unfortunately the free version of Pycharm does not support remote
> debugging and my main use for Python is for programming a Raspberry
> Pi. I use Visual Studio instead and its "go to end of block" does not
> work in the Python editor
> .
> --


​Note that you can use Eclipse/ PyDev for remote debugging.​
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Unit test

2016-01-26 Thread 4ndre4

On 26/01/2016 11:09, [email protected] wrote:

[...]

I'm a University student of IT with majors in Embedded Systems.
> I have this assignment where I have to write Unittest for a simple 
Python Code

> without having prior knowledge of Python. I really need some help.

www.python.org to get a basic grasp on Python. There is a very good 
tutorial there.


As for unit testing, you need to know a bit of the the theory behind it, 
and how to use it in Python.


The following are four very good books about unit testing, in general:

Effective Unit Testing: A guide for Java developers - Lasse Koskela
Test Driven: TDD and Acceptance TDD for Java Developers - Lasse Koskela
Test-Driven Development: By Example - Kent Beck

This is a good book but with examples in C# (you might just get the 
logic behind them):

The Art of Unit Testing: with examples in C# - Roy Osherove

I am pretty sure that on Amazon you can find many others about specific 
unit testing in Python.


On YouTube, there's a good number of videos about unit testing.
This one, for example: https://www.youtube.com/watch?v=TWBDa5dqrl8

--
4ndre4
"The use of COBOL cripples the mind; its teaching should, therefore, be 
regarded as a criminal offense." (E. Dijkstra)


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


Re: pip install mitmproxy - fails on watchdog-0.8.3.tar.gz with "Permission denied" error (Python 2.7.11 on Win XP SP3);

2016-01-26 Thread eryk sun
 On Sun, Jan 24, 2016 at 7:27 PM, Terry Reedy  wrote:
>
> More specifically, / is not accepted in paths to be executed. It seems to be
> generally accepted in path arguments, as in cd path, or
>
> C:\Users\Terry>C:\programs\python35\python.exe C:/programs/python34/tem.py

An exception that comes to mind is takeown.exe, which fails to parse
paths that use slash as the value for /F.

A couple of exceptional cases in the Windows API come to mind. The
"\\?\" extended path syntax requires backslash. Also referencing named
kernel objects requires a backslash after either the "Global" prefix
or a private namespace prefix. For example, in "Global/ObjectName" the
slash is just another character in the name, so the object manager
doesn't follow the "Global" symbolic link to \BaseNamedObjects but
instead creates"Global/ObjectName" in the session's named objects
directory.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tkinter spacing

2016-01-26 Thread high5storage
On Monday, January 25, 2016 at 7:41:57 PM UTC-8, KP wrote:
> If I want to have some space between, say, btn_last & btn_new, will I have to 
> use a dummy label in between these two or is there a better way?
> 
> Thanks for any help, as always!
> 
> 
> 
> 
> from tkinter import *
> from tkinter import ttk
> 
> root = Tk()
> root.geometry("822x600+100+100")
> nav_bar = ttk.Frame(root, borderwidth=2, relief='ridge', padding=(10, 3, 10, 
> 3))
> 
> btn_first  = ttk.Button(nav_bar, text='|<', width=4)  # for buttons showing 
> text only, this will be text units (= average characters?)
> btn_prev   = ttk.Button(nav_bar, text='<',  width=4)  # for image buttons, it 
> will be in pixels 
> btn_next   = ttk.Button(nav_bar, text='>',  width=4)
> btn_last   = ttk.Button(nav_bar, text='>|', width=4)
> btn_new= ttk.Button(nav_bar, text='New')
> btn_edit   = ttk.Button(nav_bar, text='Edit')
> btn_delete = ttk.Button(nav_bar, text='Delete')
> btn_cancel = ttk.Button(nav_bar, text='Cancel')
> btn_print  = ttk.Button(nav_bar, text='Print')
> btn_help   = ttk.Button(nav_bar, text='Help')
> btn_save   = ttk.Button(nav_bar, text='Save')
> lbl_Recs   = ttk.Label(nav_bar,  text='Records')
> lbl_RCount = ttk.Label(nav_bar,  text='0 ', width=10, borderwidth=2, 
> relief='sunken', anchor='e')  # fake entry look
> 
> nav_bar.grid(column=0, row=0, columnspan=13)
> 
> btn_first.grid(column=0, row=0)
> btn_prev.grid(column=1,  row=0)
> btn_next.grid(column=2,  row=0)
> btn_last.grid(column=3,  row=0)
> 
> btn_new.grid(column=4,row=0)
> btn_edit.grid(column=5,   row=0)
> btn_delete.grid(column=6, row=0)
> btn_cancel.grid(column=7, row=0)
> 
> lbl_Recs.grid(column=8,   row=0, padx=5)
> lbl_RCount.grid(column=9, row=0, padx=5)
> btn_print.grid(column=10, row=0)
> btn_help.grid(column=11,  row=0)
> btn_save.grid(column=12,  row=0)
> 
> root.mainloop()

Ah - that clears it up. Thanks for your help!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question about asyncio and blocking operations

2016-01-26 Thread Alberto Berti
> "Frank" == Frank Millman  writes:

Frank> Now I have another problem. I have some classes which retrieve some
Frank> data from the database during their __init__() method. I find that it
Frank> is not allowed to call a coroutine from __init__(), and it is not
Frank> allowed to turn __init__() into a coroutine.

IMHO this is semantically correct for a method tha should really
initialize that instance an await in the __init__ means having a
suspension point that makes the initialization
somewhat... unpredictable :-).

To cover the cases when you need to call a coroutine from a non
coroutine function like __init__ I have developed a small package that
helps maintaining your code almost clean, where you can be sure that
after some point in your code flow, the coroutines scheduled by the
normal function have been executed. With that you can write code like
this:

from metapensiero.asyncio import transaction

class MyObject():

def __init__(self):
tran = transaction.get()
tran.add(get_db_object('company'), cback=self._init) # 
get_db_object is a coroutine

def _init(self, fut):
self.company = fut.result()

async external_coro(): # this is the calling context, which is a coro
async with transction.begin():
o = MyObject
# maybe other stuff

# start using your db object
o.company...

This way the management of the "inner" coroutine is simpler, and from
your code it's clear it suspends to wait and after that all the
"stashed" coroutines are guaranteed to be executed.

Hope it helps,

Alberto

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


Re: python-2.7.3 vs python-3.2.3

2016-01-26 Thread Ben Finney
Gene Heskett  writes:

> I have need of using a script written for python3, but the default
> python on wheezy is 2.7.3.

Correction: the default Python 2 is 2.7.3. The default Python 3 is
3.2.3.

Since Python 2 and Python 3 are distinct run-time systems, there's no
single “default Python” in Debian Wheezy.

> I see in the wheezy repos that 3.2.3-6 is available.

Correct. If you have a program needing Python 3, you should ignore the
Python 2 system and only look at Python 3.

> Can/will they co-exist peacefully?

Yes.

-- 
 \ “Broken promises don't upset me. I just think, why did they |
  `\ believe me?” —Jack Handey |
_o__)  |
Ben Finney

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


Re: Question about asyncio and blocking operations

2016-01-26 Thread Alberto Berti

> "Alberto" == Alberto Berti  writes:

Alberto> async external_coro(): # this is the calling context, which is 
a coro
Alberto> async with transction.begin():
Alberto> o = MyObject
Alberto> # maybe other stuff

ops... here it is "o = MyObject()" ;-)

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


Re: Python Unit test

2016-01-26 Thread toluagboola
On Tuesday, January 26, 2016 at 10:57:51 PM UTC+2, 4ndre4 wrote:
> On 26/01/2016 11:09, [email protected] wrote:
> 
> [...]
> > I'm a University student of IT with majors in Embedded Systems.
>  > I have this assignment where I have to write Unittest for a simple 
> Python Code
>  > without having prior knowledge of Python. I really need some help.
> 
> www.python.org to get a basic grasp on Python. There is a very good 
> tutorial there.
> 
> As for unit testing, you need to know a bit of the the theory behind it, 
> and how to use it in Python.
> 
> The following are four very good books about unit testing, in general:
> 
> Effective Unit Testing: A guide for Java developers - Lasse Koskela
> Test Driven: TDD and Acceptance TDD for Java Developers - Lasse Koskela
> Test-Driven Development: By Example - Kent Beck
> 
> This is a good book but with examples in C# (you might just get the 
> logic behind them):
> The Art of Unit Testing: with examples in C# - Roy Osherove
> 
> I am pretty sure that on Amazon you can find many others about specific 
> unit testing in Python.
> 
> On YouTube, there's a good number of videos about unit testing.
> This one, for example: https://www.youtube.com/watch?v=TWBDa5dqrl8
> 
> -- 
> 4ndre4
> "The use of COBOL cripples the mind; its teaching should, therefore, be 
> regarded as a criminal offense." (E. Dijkstra)

import getopt, sys
import dpkt, pcap

def usage():
print >>sys.stderr, 'usage: %s [-i device] [pattern]' % sys.argv[0]
sys.exit(1)

def main():
opts, args = getopt.getopt(sys.argv[1:], 'i:h')
name = None
for o, a in opts:
if o == '-i': name = a
else: usage()

pc = pcap.pcap(name)
pc.setfilter(' '.join(args))
decode = { pcap.DLT_LOOP:dpkt.loopback.Loopback,
   pcap.DLT_NULL:dpkt.loopback.Loopback,
   pcap.DLT_EN10MB:dpkt.ethernet.Ethernet }[pc.datalink()]
try:
print 'listening on %s: %s' % (pc.name, pc.filter)
for ts, pkt in pc:
print ts, `decode(pkt)`
except KeyboardInterrupt:
nrecv, ndrop, nifdrop = pc.stats()
print '\n%d packets received by filter' % nrecv
print '%d packets dropped by kernel' % ndrop

if __name__ == '__main__':
main()


Here is what the python code looks like and I am to make a Unittest for it
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tkinter spacing

2016-01-26 Thread Christian Gollwitzer

Am 26.01.16 um 04:41 schrieb KP:

If I want to have some space between, say, btn_last & btn_new, will
I  have to use a dummy label in between these two or is there a better way?


If you just want to put space there, you can use the pad options of 
grid, just like you do for lbl_Recs. Specifically, if you want to put it 
on one side only, you'd do:


btn_new.grid(column=4, row=0, padx="20 0")

which does 20px of space to the left of btn_new. Besides that, I have a 
few comments (I assume you are new to Tkinter and/or GUI programming in 
general)



from tkinter import *
from tkinter import ttk

root = Tk()



root.geometry("822x600+100+100")


This is very bad. The grid geometry manager calculates the needed space 
automatically. Your code fails, if you use a different ttk theme, or a 
different font size. For instance, on my OSX computer, the window is cut 
off at the right side at the Print button. Delete this line. As soon as 
you fill the bottom with content, the window will look reasonanble.



nav_bar = ttk.Frame(root, borderwidth=2, relief='ridge', padding=(10, 3, 10, 3))

btn_first  = ttk.Button(nav_bar, text='|<', width=4)  # for buttons showing 
text only, this will be text units (= average characters?)
btn_prev   = ttk.Button(nav_bar, text='<',  width=4)  # for image buttons, it 
will be in pixels
btn_next   = ttk.Button(nav_bar, text='>',  width=4)
btn_last   = ttk.Button(nav_bar, text='>|', width=4)


If you want these buttons to look like a real Toolbur, there is a ttk 
widget class for that. Try:



btn_first  = ttk.Button(nav_bar, text='|<', style="Toolbutton")
btn_prev   = ttk.Button(nav_bar, text='<',  style="Toolbutton")
btn_next   = ttk.Button(nav_bar, text='>',  style="Toolbutton")
btn_last   = ttk.Button(nav_bar, text='>|', style="Toolbutton")


Also note that I left off the manual width. Probably you wwant to use 
images in the end, and if these all have the same size, which is usual 
for an icon set (32x32 or 48x48, e.g.) then the size of all the buttons 
will look good. You shouldn't have to set size values manually.



btn_new= ttk.Button(nav_bar, text='New')
btn_edit   = ttk.Button(nav_bar, text='Edit')
btn_delete = ttk.Button(nav_bar, text='Delete')
btn_cancel = ttk.Button(nav_bar, text='Cancel')
btn_print  = ttk.Button(nav_bar, text='Print')
btn_help   = ttk.Button(nav_bar, text='Help')
btn_save   = ttk.Button(nav_bar, text='Save')
lbl_Recs   = ttk.Label(nav_bar,  text='Records')




lbl_RCount = ttk.Label(nav_bar,  text='0 ', width=10, borderwidth=2, 
relief='sunken', anchor='e')  # fake entry look


This will also look correct only with some themes. Maybe you want a 
readonly or disabled entry? You can do this like


sometkvar=Tk.StringVar()
lbl_RCount = ttk.Entry(nav_bar,  textvariable=sometkvar, width=10, 
state='readonly')

sometkvar.set('0 ')




nav_bar.grid(column=0, row=0, columnspan=13)


There is no need to give the nav_bar a columnspan. So far you have no 
elements in the main frame besides the nav_bar. Columnspan=13 would mean 
that the navbar should be the same size as 13 columns below it. You 
don't tell it the number of children (your buttons) here. So for the 
moment just


nav_bar.grid(column=0, row=0)

HTH,

Christian


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


Re: Tkinter spacing

2016-01-26 Thread Christian Gollwitzer

Am 26.01.16 um 23:48 schrieb [email protected]:

On Monday, January 25, 2016 at 7:41:57 PM UTC-8, KP wrote:
> [fullquote snipped]
Ah - that clears it up. Thanks for your help!


It is totally unclear what you reply to. PLease cite what you refer to, 
and shorten your citation for clarity.


Christian

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