Re: [Tutor] interface

2015-12-15 Thread Laura Creighton
A question for Alex Kleider:
Do you want this thing to eventually run on mobile? -- android and IOS?

If so, tkinter isn't the place to start, but kivy (which also runs
on desktops) is. http://kivy.org/#home

re: full stack frameworks
The thing about full stack frameworks such as Django is that they
provide their own 'full ecosystem' --  if you are going to use Django,
you are going to have to learn -the Django way to do things-.  Now
Django, in particular, fits many people's brains quite nicely.  So 
they find doing things 'the Django way' fairly natural ... it works
the way they expected.

But there are a whole lot of other people who don't naturally think
in anything approaching -the Django way-.  They end up fighting the
framework every inch of the way, which makes for an extremely unpleasant
experience.  And this goes for every full stack Framework there is --
every one of them has arbitrary decision after arbitrary decision
after arbitrary decision --  we had to pick a way to do things, and
also force everybody to do it this way, and this is what we picked.

This doesn't bother many people at all.  They are very good at
accepting 'this is the way the world is' and it does not stress them
out that this is the case.  In contrast, many people find that this
accepting attitude cuts right across their own creativity -- not
accepting 'the world the way it is' in favour of 'the world, as I
shall make it better' is essential to their own creative process.
Unless the full stack framework happens to make the arbitrary
decisions pretty much the same way that they would, they will find
using such a thing a constant source of frustration.

So, full stack frameworks can save you a lot of work and effort, but
only if you are willing to do things the framework's way.  If, as
you explore using Django (or any other full stack framework) remember
this note -- if you find the whole thing tedious, arbitrary and
frustrating, it may be an indication that you have the wrong
framework, or that Full Stack frameworks are not for you, and you
would be happier with a much lighter one, such as bottle or flask.

Laura
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Batchfile to Python conversion

2015-12-15 Thread Dominique Descamps
Dear,
In my company we are working with Windows-7 batchfiles, but as you know, this 
is very limited, unreadable and time-consuming.
 
I have already some experience with Python and as I'm very satisfied with it, I 
would like to use Python instead of continuing using batchfiles.
Those batchfiles however need to be updated, and therefore I would like to 
convert those into Python scripts.
On the StackOverflow website, I have seen some issues of people who have done 
this manually.
As I'm dealing here with almost hundred batchfiles, some of them containing 
several hundreds of lines of code, I'm more interested in a tool, who can do 
this conversion automatically.
 
Can you confirm me whether or not such a conversion tool already exists?
Thanks
Dominique
  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Batchfile to Python conversion

2015-12-15 Thread Alan Gauld
On 15/12/15 09:14, Dominique Descamps wrote:

> As I'm dealing here with almost hundred batchfiles, some of them 
> containing several hundreds of lines of code, I'm more
> interested in a tool, who can do this conversion automatically.
>  
> Can you confirm me whether or not such a conversion tool already exists?

I certainly have never heard of such a thing.
Even if it did exist it would probably produce terrible Python code.

The reason I say that is that batch files (like Unix shell
scripts but more so) are essentially program launchers. They get the
work done by starting other programs. A Python conversion would
wind up being full of os.system() calls or Popen() calls.

Also the bat file control structures are very limited (much
worse than Unix shell) and a conversion script would be unable
to select more elegant structures. So while you might translate
the batch file code to Python it would probably be nearly as
unreadable and error prone as the original batch file was.

I would suggest your best bet is not to even try converting
all of the scripts but to tackle them one by one as you need
to work on them. This may mean that some of the scripts never
get converted, but those will be the ones that are stable and
working as intended. If they ain't broke, don't fix them...
The ones that need regular maintenance are the ones you most
want in Python.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] functions

2015-12-15 Thread Matthew Lintern
Hello,

I'm new to python and I've been following some youtube videos etc to learn
python. I'm using the spyder IDE.  Im having problems with the following
piece of code:

def myfun(x):
y=x**2
return y

print myfun(5)

the answer I should get is obviously 25, and this is the case in the video
(https://www.youtube.com/v/GT1UfkLIeZ4?version=3&vq=hd1080&autoplay=1)

However, Spyder tells me theres a syntax error with myfun(5).  However, the
videos shows no issue?

Any help is greatly appreciated!

Thanks

Matt
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] functions

2015-12-15 Thread Alan Gauld
On 15/12/15 11:19, Matthew Lintern wrote:

> def myfun(x):
> y=x**2
> return y
> 
> print myfun(5)
> 
> However, Spyder tells me there's a syntax error with myfun(5).

I suspect that the video is for Python v2 and you are using
Python v3. v3 was a major change in the language and on of
the biggest was that print is now a function and therefore
needs parentheses around its arguments.
So your code should look like:

print( myfun(5) )

My recommendation is that you try to find a set of
python v3 videos. Alternatively download Python v2.7
and use that with the v2 videos, then when you are
ready to upgrade to v3 you can look at one of the
many resources on migrating from 2->3.


BTW One alternative source outside Youtube is
Showmedo.com. Some of them are paid for but many
are free.

http://showmedo.com/videotutorials/python

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] functions

2015-12-15 Thread Steven D'Aprano
On Tue, Dec 15, 2015 at 11:19:33AM +, Matthew Lintern wrote:
> Hello,
> 
> I'm new to python and I've been following some youtube videos etc to learn
> python. I'm using the spyder IDE.  Im having problems with the following
> piece of code:
> 
> def myfun(x):
> y=x**2
> return y
> 
> print myfun(5)
> 
> the answer I should get is obviously 25, and this is the case in the video
> (https://www.youtube.com/v/GT1UfkLIeZ4?version=3&vq=hd1080&autoplay=1)
> 
> However, Spyder tells me theres a syntax error with myfun(5).  However, the
> videos shows no issue?

I'm not familiar with Spyder, but I expect it should actually show 
you where the error is, or at least, where it *notices* the error 
for the first time.

For instance, you might see something like this:

py> print func(5}
  File "", line 1
print func(5}
^
SyntaxError: invalid syntax

Look carefully, and you will see I mis-typed the closing bracket ) as } 
instead.

Or you might get something like this:

py>   print func(5)
  File "", line 1
print func(5)
^
IndentationError: unexpected indent

Spyder might treat that as a syntax error.


If you get this:

py> print func(5)
  File "", line 1
print func(5)
 ^
SyntaxError: invalid syntax

Notice the caret ^ pointing just after the first word following "print"? 
In that case, try running these twolines of code instead:

import sys
print(sys.version)


If the version starts with 3, then you have discovered a minor nuisance 
when programming in Python: a slight difference between Python version 3 
and older versions.

In Python 3, "print" is a normal function, and so it must be called with 
parentheses:

print(func(5))

In Python 2, "print" is a special statement, which doesn't require 
parentheses, so you can write this:

print func(5)

Many tutorials are written for Python 2, and so they will show print 
with a space, but that's a syntax error in Python 3. Just remember to 
always use an extra pair of brackets for printing, and you should be 
fine.



-- 
Steve
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Countdown Clock Programming Question

2015-12-15 Thread Evan Sommer
Hey there Alan!

So I tried some of your modifications, and they seem to be doing some
pretty interesting things with the program. For some reason, now the
program runs extremely fast, and doesn't now count down in one second
intervals. I think this is a result of the root.after command. I still
get 3 different windows with 3 different colours as well.

I'm probably just doing something completely wrong, so if you could
show me where to edit the code, I would much appreciate it!

Thanks!

Here is the most recent code:

try:
# Python2
import Tkinter as tk
except ImportError:
# Python3
import tkinter as tk
import time
def count_down(start, end):
root.after (1000, count_down)
root = tk.Tk()
time_str = tk.StringVar()
# create the time display label, give it a large font
# label auto-adjusts to the font
label_font = ('helvetica', 100)
tk.Label(root, textvariable=time_str, font=label_font, bg='forestgreen',
 fg='white', relief='raised', bd=3).pack(fill='x', padx=5, pady=5)
 # start with 2 minutes --> 119 seconds
for t in range(240, 120, -15):
# format as 2 digit integers, fills with zero to the left
# divmod() gives minutes, seconds
sf = "{:01d}:{:02d}".format(*divmod(t, 60))
#print(sf)  # test
time_str.set(sf)
root.update()
# delay one second
root.after (1, count_down)
# create the time display label, give it a large font
# label auto-adjusts to the font
label_font = ('helvetica', 100)
tk.Label(root, textvariable=time_str, font=label_font, bg='gold',
 fg='white', relief='raised', bd=3).pack(fill='x', padx=5, pady=5)
 # start with 1 minutes --> 59 seconds
for t in range(120,60, -15):
# format as 2 digit integers, fills with zero to the left
# divmod() gives minutes, seconds
sf = "{:01d}:{:02d}".format(*divmod(t, 60))
#print(sf)  # test
time_str.set(sf)
root.update()
# delay one second
root.after (1, count_down)
# create the time display label, give it a large font
# label auto-adjusts to the font
label_font = ('helvetica', 100)
tk.Label(root, textvariable=time_str, font=label_font, bg='firebrick',
 fg='white', relief='raised', bd=3).pack(fill='x', padx=5, pady=5)
 # start with 4 minutes --> 240 seconds
for t in range(60,-1, -15):
# format as 2 digit integers, fills with zero to the left
# divmod() gives minutes, seconds
sf = "{:01d}:{:02d}".format(*divmod(t, 60))
#print(sf)  # test
time_str.set(sf)
root.update()
# delay one second
root.after (1, count_down)
# start the GUI event loop
root.mainloop()


On 11/30/15, Evan Sommer  wrote:
> Hello again Alan!
>
>  Do you think you could write a revised code with the modifications that
> you suggested? I tried changing the code with your recommendations and I
> keep getting syntax errors.
>
> If you could do that, I would greatly appreciate it!!
>
> Thank you for all your help!
>
> Evan Sommer
>
> On Tue, Nov 24, 2015 at 9:01 AM, Evan Sommer  wrote:
>
>> Hello there!
>>
>> I am working on a project for an engineering class that I am in at my
>> high
>> school, and our task has been to create a clock that counts down the time
>> between periods, so that the students walking the hallways know how much
>> time they have to get to class. The timer will be displayed on multiple
>> monitors throughout the halls. However, the idea behind the countdown
>> clock
>> is for the background to change colours when it hits a certain time. The
>> goal is for the clock to change from green to yellow at 2 minutes, and
>> yellow to red at 1 minute. However, I have been having a hard time trying
>> to get the color change to display in one window. If you could give me
>> some
>> advice, I'd really appreciate it!
>>
>> Here's the code:
>>
>> try:
>> # Python2
>> import Tkinter as tk
>> except ImportError:
>> # Python3
>> import tkinter as tk
>> import time
>> def count_down():
>> # start with 4 minutes --> 240 seconds
>> for t in range(240, 120, -1):
>> # format as 2 digit integers, fills with zero to the left
>> # divmod() gives minutes, seconds
>> sf = "{:01d}:{:02d}".format(*divmod(t, 60))
>> #print(sf)  # test
>> time_str.set(sf)
>> root.update()
>> # delay one second
>> time.sleep(1)# create root/main window
>> root = tk.Tk()
>> time_str = tk.StringVar()
>> # create the time display label, give it a large font
>> # label auto-adjusts to the font
>> label_font = ('helvetica', 100)
>> tk.Label(root, textvariable=time_str, font=label_font, bg='green',
>>  fg='white', relief='raised', bd=3).pack(fill='x', padx=5,
>> pady=5)
>>  # start with 2 minutes --> 119 seconds
>> for t in range(240, 120, -1):
>> # format as 2 digit integers, fills with zero to the left
>> # divmod() gives minutes, seconds
>> sf = "{:01d}:{:02d}".format(*divmod(t,

Re: [Tutor] Countdown Clock Programming Question

2015-12-15 Thread Alan Gauld
On 15/12/15 14:18, Evan Sommer wrote:
> Hey there Alan!
> 
> So I tried some of your modifications, and they seem to be doing some
> pretty interesting things with the program. For some reason, now the
> program runs extremely fast, and doesn't now count down in one second
> intervals. I think this is a result of the root.after command. 

Yes, you are using it wrongly.
The root.after() function removes the need for your for loops.
You just call root after until the time reaches the point you are
interested in.

> def count_down(start, end):
> root.after (1000, count_down)

You should be updating your display inside the count_down function.
This function, if done right, will get called each second. So every
second it will update your display until it reaches the end. So start
will be the value to display. stop will be the end value. When start==
stop the function will terminate.

It should look something like this:

def count_down(start,end):
update display to show start
if start > end:
   root.after(1000, lambda : count_down(start-1, end))


That pattern will simply count from start to end. If you want to change
colours etc then you need some more worjk.
But for now just try to get the counter working.


> for t in range(240, 120, -15):
> # format as 2 digit integers, fills with zero to the left
> # divmod() gives minutes, seconds
> sf = "{:01d}:{:02d}".format(*divmod(t, 60))
> #print(sf)  # test
> time_str.set(sf)
> root.update()
> # delay one second
> root.after (1, count_down)

Replace the whole loop with a call to

root.after(1, lambda : count_down(240,0))

And put the display code into the count_down method.

Here is a very simple program that just counts down the seconds.
You can build on that to do all the other display tweaks you
want.


import tkinter as tk

def count_down(start,stop):
   display['text'] = str(start)
   if start > stop:
top.after(1000, lambda : count_down(start-1,stop))

top = tk.Tk()
display = tk.Button(top,text="Press",
command = lambda: count_down(10,0))
display.pack()
top.mainloop()


Notice that there are no for loops involved.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Countdown Clock Programming Question

2015-12-15 Thread Alan Gauld
On 15/12/15 17:10, Alan Gauld wrote:

> 
> import tkinter as tk
> 
> def count_down(start,stop):
>display['text'] = str(start)
>if start > stop:
> top.after(1000, lambda : count_down(start-1,stop))
> 
> top = tk.Tk()
> display = tk.Button(top,text="Press",
> command = lambda: count_down(10,0))
> display.pack()
> top.mainloop()
> 

In case lambda confuses things, here is a version
using globals and no lambdas:


import tkinter as tk

start = 10
stop = 0

def count_down():
global start
display['text'] = str(start)
if start > stop:
start -= 1
top.after(1000, count_down)

top = tk.Tk()
display = tk.Button(top,text="Press",command = count_down)
display.pack()
top.mainloop()



-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] interface

2015-12-15 Thread Mark Lawrence

On 15/12/2015 00:52, Alan Gauld wrote:

On 14/12/15 21:48, Alex Kleider wrote:


wxPython is slightly more complex but more powerful and
looks more like the native UI on each platform. (There
is also Dabo which is wxPython based but has an IDE with
GUI builder and is very good for database oriented apps.)



wxPython still does not support Python 3, and it doesn't look as if this 
will happen any time soon.  In fairness this is due to Robin Dunn being 
tied up on paid work.


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] interface

2015-12-15 Thread Alan Gauld
On 15/12/15 22:13, Mark Lawrence wrote:

> wxPython still does not support Python 3, and it doesn't look as if this 
> will happen any time soon.  In fairness this is due to Robin Dunn being 
> tied up on paid work.

That's a pity. Not least because it presumably means Dabo
is stuck on v2 too. Dabo is on my todo list of things to
investigate (aka play with :-).

Mind you I'm busy enough with Javascript/NodeJS and F# at
the moment!


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor