Re: [Tutor] creating a mspaint utility

2016-01-14 Thread Alan Gauld
On 14/01/16 10:58, Whom Isac wrote:
> Hi, I was wondering if it is possible to make a similar drawing tool with
> basic functionality to draw lines, circles or square with python canvas.

Yes of course and there are at least a couple of online tutorials
on how to do that. Google is your friend.

> I did not think it would have been a difficult work but I have spent 3-4
> hours and out of luck. I get my functions to give me the mouse position
> while moving, when pressed, original position or current position. But
> don't know how to store them as a value. 

Use variables just like any other value.
GUI work is always harder than you expect and ful;l of
frustrating details. 3-4 hours on a GUI project is not
long at all.

> I am not a genius and is not used to tkinter very well (to use command
> function or anything) to store a value.

Which tkinter tutorial are you reading?

> import tkinter as tk
> from tkinter import *
> import sys

> #app GUI
> app=tk.Tk()
> app.title("MSPAINT By Shams")
> app.geometry('400x450')
> 
> #
> show_event=app.winfo_pointerxy()
> (X,Y)=show_event
> 
> #Mouse events
> def original_mouse_position():
> show_event=app.winfo_pointerxy()
> (X,Y)=show_event
> print("The mouse are on: X:{0} Y:{1}".format(X,Y))
> label0=Label(frame1,text="Original Position",
> relief=RAISED).pack(side=TOP,anchor="ne")

pavck() and grid() both return None so if you want to store a reference
to the widget you MUST split it over two lines

widgetVar = Widget()
widgetVar.pack()   # or grid()

Otherwise your widgetVar will just store None.

> label=Label(frame1,text="XY",relief=GROOVE).pack(side=BOTTOM,
> anchor="ne")
> label1=Label(frame1,text=str(show_event),
> relief=SUNKEN).pack(side=BOTTOM, anchor="ne")
> return

This is confusing because your function is called
original_mouse_position() but it does a lot more than
that - it creates labels and all sorts. You should
either split this into several smaller functions
or change the name to reflect what the function
actually does.


> # Continuous Mouse Movement
> 
> def motion(event):
> x, y = event.x, event.y
> currentMousePosition=(x,y)
> print('MousePos: X:{0} Y:{1}'.format(x, y))
> return currentMousePosition
> ###app.bind('', motion)-->WORKS but disabled from running

You return the x,y coordinates but the values are not
used by Tkinter when it calls the function in
response to a Motion event. You probably want
to store them in global variables - remember
to use the global keyword.

> 
> #Mouse Update And Position
> def mouse_position():
> show_event=app.winfo_pointerxy()
> (X,Y)=show_event

You've used these two lines several times. Probably
better to make them into a function.

> if ''!=show_event :

This will always be true since you are comparing
a literal string ('') with an (x,y) tuple.
They can never be equal.

> show_event=app.winfo_pointerxy()
> (X,Y)=show_event

and yet again you repeat these lines.

> print("Current mouse are on: X:{0} Y:{1}".format(X,Y))
> label2=Label(frame1,text=str(show_event),
> relief=GROOVE).pack(side=RIGHT)
> 
> #app.bind(mouse_position(),'Show')
> 
> #Mouse pressed
> def Mouse_pressed(event):
> print("Right Click has been pressed.")
> initialpos=(X,Y)
> initialpos=app.winfo_pointerxy()
> #finalpos=motion(event)
> """
> while initialpos!=(0,0):
> initialpos=app.winfo_pointerxy()   #Explain me why
> it does not work.Should not it work?it's logical to do/call recursive

There is nothing recursive going on.
You set initialpos to the mouse position in the 3rd line
of this function. You then loop round doing it until the
mouse is on position 0,0 - ie extreme top left.

> finalpos=(0,0)
> if initialpos !=finalpos:
> if Mouse_pressed(event):
> finalpos=app.winfo_pointerxy()

I've no idea what you think this bit is doing.

> print(initialpos)
> """
> print(initialpos)
> return initialpos
> 

That's as far as I went because there are enough big issues
to fix already that finding more would not be useful.

-- 
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] Clickable listbox opening .txt files

2016-01-14 Thread Alan Gauld
On 14/01/16 11:39, Ali Moradi wrote:
> Hi, you said my click event grabs text and doesn't show it. So how do get
> it to show on the Text widget?

Your text widget is calloed text.
So simply insert the text into the widget using

text.insert(END,file)

at the end of your click handler.

> def click(event):
>   index = list.curselection()[0]
>   file = open(r"C:\Users\deadmarshal\PycharmProjects\ali\1.txt").read()

> list = Listbox(frame1)
> list.insert(1, "Konatiĝu kun Kamila") list.insert(2, "Sinjoro Johano")
> list.insert(3, "Onklino Marta")
> scroll = Scrollbar(frame1, orient=VERTICAL, command=list.yview)
> scroll.grid(row=0, column=2, sticky='ns') list.grid(row=0, column=1)
> list.bind("", click)
> text = Text(frame2).grid() root.mainloop()

However one problem is that you are creating your widget and calling
grid() which returns None. You need to split the line into two:

text = Text(frame2)
text.grid()

HTH

-- 
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] me, my arm, my availability ...

2016-01-14 Thread Cem Karan

On Jan 13, 2016, at 3:47 PM, Laura Creighton  wrote:

> 
> I fell recently.  Ought to be nothing, but a small chip of bone, either an
> existing one or one I just made is nicely wedged in the joint taking away
> a whole lot of the ability of my arm to rotate in the elbow joint.  Or
> hold my arm in a position that is usual for typing.  Plus,  now that the
> sprain/swelling is more or less over, the pain, unfortunately is not.
> 
> The real downside is that my typing speed is down from 135-140 wpm
> to 5-10 wmp.  At this rate, just getting my usual work done takes
> overtime.
> 
> Seems like surgery is needed to fix this. 
> 
> So I wanted you all to know, no, I haven't forgotten you and no haven't
> stopped caring.  I have just stopped being as __capable__ if you know
> what I mean.
> 
> Please take care of yourselves and each other.  I will often be reading
> even if typing is more than I can do right now.
> 
> Laura
> 
> ps -- (recent tutor discussion) I am with Alan and not with Mark.  I
> am happy as anything when people post their not-quite-working code for
> homework assignments here to tutor.  They aren't lazy bastards wanting
> somebody to do their assignments for them, they want to learn why what
> they are trying to do isn't working.  Sounds perfect for tutor to me.

Good luck healing!  Hope you get better soon.  Surgery has gotten a WHOLE lot 
better recently, they did wonders for my knee a few years back.  With luck, 
it'll be more or less outpatient surgery.

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


Re: [Tutor] Modularity

2016-01-14 Thread Mark Lawrence

On 14/01/2016 15:27, James Chapman wrote:

I should have re-read that last reply before hitting send. Apologies
for the poor sentence construction!

Something I forgot to highlight before which might be related to your
initial question.

If you have a file called sound.py which contained a class called
WavFile, if you imported just sound like this:

 import sound

Then your class constructor would be called like this:

 wavFile = sound.WavFile()


Importing the module doesn't import the class, for that you'd do

 from sound import WavFile

 wavFile = WavFile()


Without any context this is completely meaningless, so what the hell are 
you talking about?


--
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] Modularity

2016-01-14 Thread James Chapman
I should have re-read that last reply before hitting send. Apologies
for the poor sentence construction!

Something I forgot to highlight before which might be related to your
initial question.

If you have a file called sound.py which contained a class called
WavFile, if you imported just sound like this:

import sound

Then your class constructor would be called like this:

wavFile = sound.WavFile()


Importing the module doesn't import the class, for that you'd do

from sound import WavFile

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


Re: [Tutor] Procedure to install dlib on windows?

2016-01-14 Thread Mark Lawrence

On 14/01/2016 10:09, Rheeya Uppaal wrote:

I'm an absolute beginner at python, but have been asked to download the
dlib library on my windows system. I have followed the instructions given
here: http://dlib.net/compile.html

I have already downloaded cmake and Visual Studio. On the Visual Studio
command prompt, on running "python setup.py install" I get this:

running install
running bdist_egg
running build
Detected Python architecture: 64bit
Removing build directory
C:\Python\PackagesForPython\dlib-18.18\./tools/python/build
Configuring cmake ...
CMake Error in CMakeLists.txt:
error: cmake configuration failed!

Could anyone help me out please? I've tried whatever I can think of.

Thank you! Cheers!


It is available on pypi for 2.7 and 3.4 so from a cmd prompt all you 
need is:-


pip install dlib.

--
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] Procedure to install dlib on windows?

2016-01-14 Thread James Chapman
>From one of the Python examples:

# COMPILING/INSTALLING THE DLIB PYTHON INTERFACE
#   You can install dlib using the command:
#   pip install dlib
#
#   Alternatively, if you want to compile dlib yourself then go into the dlib
#   root folder and run:
#   python setup.py install
#   or
#   python setup.py install --yes USE_AVX_INSTRUCTIONS

It looks like the pip installer will install a pre-compiled lib with
python API bindings for you.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Procedure to install dlib on windows?

2016-01-14 Thread Alan Gauld
On 14/01/16 10:09, Rheeya Uppaal wrote:
> I'm an absolute beginner at python, but have been asked to download the
> dlib library on my windows system. I have followed the instructions given
> here: http://dlib.net/compile.html

Its not clear why you are doing this.
Who asked you to download it? Why do they want you to use it?
Do you have experience in C++ (which seems to be how DLib is
documented)

The reason I ask is that DLib looks like a fairly specialised
tool that overlaps quite a lot of the standard libraries that
come with Python. It's certainly not something a novice Python
user would normally be playing with.

This list is really for teaching people the python language
and standard library. To get support on DLib you are probably
better asking on the DLib forum. Failing that you might try
the main Python list.

But I'd check you really need it first.

-- 
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] idle??

2016-01-14 Thread Chris Warrick
On 13 January 2016 at 21:49, Mark Lawrence  wrote:
> On 09/01/2016 10:38, Chris Warrick wrote:
>>
>> On 8 January 2016 at 20:07, bruce  wrote:
>>>
>>> So, where does IDLE fit into this
>>
>>
>> IDLE is a sad little “IDE”, which is really ugly, because it’s written
>> in Tk. It lacks many IDE features. It comes with a really basic
>> debugger (that doesn’t even highlight the line that is being currently
>> executed…), function signature hinting, and some code completion.
>>
>
> Please ignore this drivel, he's spouted this before without giving any
> justification.  IDLE is perfectly adequate as a starter for Python.

I’m sorry, which part of “ugly” (which you cannot deny, it doesn’t
match the OS most of the time), “no debugger line highlighting”, “no
line numbering” (which is a crucial feature of any code editor!) is
not enough “justification”?

For learning, a text editor (that’s better than notepad.exe) is
enough. However, the OP explicitly asked for an IDE, and as such, they
should get a good one.

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


Re: [Tutor] PLEASE I NEED HELP URGENTLY

2016-01-14 Thread Whom Isac
@precious Akams.
I don't know if you have tried to look for any resources e.g. python
directory to help you with this small syntax error. And I don't see
any relevance information with your callback error message with your
code. How did you able to run it?? I have not been reading my mails in
a while so I just honestly did not wanted upset you with anymore
words.
I felt you should learn to take a little bit precaution while coding.
Here is my Solution which I don't think you are using to pass or to
have cheated your homework:
class BankAccount(object):
def __init__(self, initial_amount):
self.balance=initial_amount
def deposit (self, amount):
self.balance+=amount
def withdraw (self, amount):
if self.balance>=amount:
return ('invalid transaction')
else:
#What are trying to do eg.
self.balance=self.balance-amount
return self.balance
pass

MinimumBalanceAcc=BankAccount #---> This created an instances
#To create a subclass
class MinimumBalanceAccount(BankAccount):
#You don't need to call the init function if you are just trying
to use Bank account functions
# add any other additional methods below:
#eg.
def show_balance(self):
print(str(self.balance))


On Thu, Jan 14, 2016 at 6:52 AM, Tim Golden  wrote:
>
> On 13/01/2016 20:51, Tim Golden wrote:
>>
>> Speaking as the list moderator in question over there: if I might
>> moderate Mark's well-known zeal...
>
>
> (Absolutely no pun intended!)
>
>
> TJG
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Creating a webcrawler

2016-01-14 Thread Whom Isac
Thanks guys for your replies. I actually tried playing with my browser but
getting a web crawler to select a video and fetch the video link was not
helpful or should I say very hard for me as I am just a beginner level
programmer and python was the first language I learnt. I also learnt
javascript, ruby and html, bootstrap, C# recently. I may try this same
project in future with more knowledge.

On Sun, Jan 10, 2016 at 2:33 AM, bruce  wrote:

> Hi Isac.
>
> I'm not going to get into the pythonic stuff.. People on the list are
> way better than I.  I've been doing a chunk of crawling, it's not too
> bad, depending on what you're trying to accomplish and the site you're
> targeting.
>
> So, no offense, but I'm going to treat you like a 6 year old (google
> it - from a movie!)
>
> You need to back up, and analyze the site/pages/structure you're going
> after. Use the tools - firefox - livehttpheaders/nettraffic/etc..
>   -you want to be able to see what the exchange is between the
> client/browser, as well as the server..
>   -often, this gives you the clues/insite to crafting the request from
> your client back to the server for the item/data you're going for...
>
> Once you've gotten that together, setup the basic process with
> wget/curl etc to get a feel for any weird issues - cert issues?
> -security issues - are cookies required - etc.. A good deal of this
> stuff can be resolved/checked out at this level, without jumping into
> coding..
>
> Once you're comfortable at this point, you can crank out some simple
> code to go after the site you're targeting.
>
> In the event you really have a javascript/dynamic site that you can't
> handle in any other manner, you're going to need to go use a 'headless
> browser' process.
>
> There are a number of headless browser projects - I think most run on
> the webit codebase (don't quote me). Casper/phantomjs, there are also
> pythonic implementations as well...
>
> So, there you go, should/hopefully this will get you on your way!
>
>
>
> On Fri, Jan 8, 2016 at 9:01 PM, Whom Isac  wrote:
> > Hi I want to create a web-crawler but dont have any lead to choose any
> > module. I have came across the Jsoup but I am not familiar with how to
> use
> > it in 3.5 as I tried looking at a similar web crawler codes from 3.4 dev
> > version.
> > I just want to build that crawler to crawl through a javascript enable
> site
> > and automatically detect a download link (for video file)
> > .
> > And should I be using pickles to write the data in the text file/ save
> file.
> > Thanks
> > ___
> > Tutor maillist  -  Tutor@python.org
> > To unsubscribe or change subscription options:
> > https://mail.python.org/mailman/listinfo/tutor
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] creating a mspaint utility

2016-01-14 Thread Whom Isac
Hi, I was wondering if it is possible to make a similar drawing tool with
basic functionality to draw lines, circles or square with python canvas.
I know how to draw them with canvas very well but the problem is the way I
am getting my mouse positions (initial& final).
I did not think it would have been a difficult work but I have spent 3-4
hours and out of luck. I get my functions to give me the mouse position
while moving, when pressed, original position or current position. But
don't know how to store them as a value. Should I write a function to store
them inside of it. I don't know because I had tried doing just that
recursively and failed and unfortunately I erased that part in the process.
I am not a genius and is not used to tkinter very well (to use command
function or anything) to store a value.
Here is my code. I kind of left some reduntant codes to show my try and
fail situation. Thus my code is quite long.

__author__ = 'WHOM ISAC'
import tkinter as tk
from tkinter import *
import sys
#import time

#app GUI
app=tk.Tk()
app.title("MSPAINT By Shams")
app.geometry('400x450')

#
show_event=app.winfo_pointerxy()
(X,Y)=show_event

#Mouse events
def original_mouse_position():
show_event=app.winfo_pointerxy()
(X,Y)=show_event
print("The mouse are on: X:{0} Y:{1}".format(X,Y))
label0=Label(frame1,text="Original Position",
relief=RAISED).pack(side=TOP,anchor="ne")
label=Label(frame1,text="XY",relief=GROOVE).pack(side=BOTTOM,
anchor="ne")
label1=Label(frame1,text=str(show_event),
relief=SUNKEN).pack(side=BOTTOM, anchor="ne")
return

# Continuous Mouse Movement

def motion(event):
x, y = event.x, event.y
currentMousePosition=(x,y)
print('MousePos: X:{0} Y:{1}'.format(x, y))
return currentMousePosition
###app.bind('', motion)-->WORKS but disabled from running



#Mouse Update And Position
def mouse_position():
show_event=app.winfo_pointerxy()
(X,Y)=show_event
if ''!=show_event :
show_event=app.winfo_pointerxy()
(X,Y)=show_event
print("Current mouse are on: X:{0} Y:{1}".format(X,Y))
label2=Label(frame1,text=str(show_event),
relief=GROOVE).pack(side=RIGHT)

#app.bind(mouse_position(),'Show')

#Mouse pressed
def Mouse_pressed(event):
print("Right Click has been pressed.")
initialpos=(X,Y)
initialpos=app.winfo_pointerxy()
#finalpos=motion(event)
"""
while initialpos!=(0,0):
initialpos=app.winfo_pointerxy()   #Explain me why
it does not work.Should not it work?it's logical to do/call recursive
finalpos=(0,0)
if initialpos !=finalpos:
if Mouse_pressed(event):
finalpos=app.winfo_pointerxy()
print(initialpos)
"""
print(initialpos)
return initialpos


#Mouse coordination
"""
initial_pos=Mouse_pressed
print(initial_pos)
time.sleep(1)
final_pos=Mouse_pressed
print(final_pos)
"""

#SOME WIDGETS:
lbl0=Label(app, text="This is a program that I have build Using Python.
Please Use it.", fg='blue', font='Times 9 bold').pack(fill=BOTH,anchor='nw')
Frame for Original Mouse Position
frame1=Frame(app, bg='red', width=2).pack(fill=BOTH,anchor='ne')




#Canvas tools
"""CanvasFrame=Frame(app, width=300, height=200)"""
canvas_GUI=Canvas(app, height=300, width=300, bg='white')
   #canvas_draw_tool=canvas_GUI.create_line(20,0,100,200)
canvas_draw_tool=canvas_GUI.create_line(20,0,(X,Y)) #I know it won't work
unless I could get the initial position and final position but I don't have
a clue

##CanvasFrame Binding
canvas_GUI.bind("", Mouse_pressed)
canvas_GUI.bind('', motion)
canvas_GUI.pack()

#QUIT Function
def quit():
print("Quit function has been called. So I am quitting.")
sys.exit()



#CLEAR Function
def clear():
canvas_GUI.delete("all")
print("Everything has been flushed.")



#Buttons
Button(app, text='Quit', command=quit).pack(anchor='sw',side=LEFT)
Button(app, text='Clear', command=clear).pack(anchor='sw',side=LEFT)
Button(app, text='Show', command=mouse_position).pack(anchor='sw',side=LEFT)
"""
initial_pos=Label(app,text="Initial
pos:{}".format(app.winfo_pointerxy())).pack()
final_pos=Label(app,text="Final
pos:{}".format(app.winfo_pointerxy())).pack()
canvas_GUI.bind(Mouse_pressed,initial_pos)
canvas_GUI.bind(Mouse_pressed,final_pos)
"""
#Mainloop running
original_mouse_position()
app.mainloop()
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Procedure to install dlib on windows?

2016-01-14 Thread Rheeya Uppaal
I'm an absolute beginner at python, but have been asked to download the
dlib library on my windows system. I have followed the instructions given
here: http://dlib.net/compile.html

I have already downloaded cmake and Visual Studio. On the Visual Studio
command prompt, on running "python setup.py install" I get this:

running install
running bdist_egg
running build
Detected Python architecture: 64bit
Removing build directory
C:\Python\PackagesForPython\dlib-18.18\./tools/python/build
Configuring cmake ...
CMake Error in CMakeLists.txt:
error: cmake configuration failed!

Could anyone help me out please? I've tried whatever I can think of.

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


[Tutor] Clickable listbox opening .txt files

2016-01-14 Thread Ali Moradi
Hi, you said my click event grabs text and doesn't show it. So how do get
it to show on the Text widget? So that when i clicked on item 1, 1.txt
shows on the Text widget. I can't connect click event to Text widget

from Tkinter import *
root = Tk()
root.title("Renkontoj kun Diferenculoj")
root.iconbitmap(r"C:\python27\DLLs/py.ico")
root.resizable(0, 0)
frame1 = LabelFrame(root, height=300, width=400, text='Lecionoj')
frame2 = LabelFrame(root, height=300, width=400, text='Tekstoj')
frame1.grid(row=0, column=0) frame2.grid(row=0, column=1)
def click(event):
index = list.curselection()[0]
file = open(r"C:\Users\deadmarshal\PycharmProjects\ali\1.txt").read()
list = Listbox(frame1)
list.insert(1, "Konatiĝu kun Kamila") list.insert(2, "Sinjoro Johano")
list.insert(3, "Onklino Marta")
scroll = Scrollbar(frame1, orient=VERTICAL, command=list.yview)
scroll.grid(row=0, column=2, sticky='ns') list.grid(row=0, column=1)
list.bind("", click)
text = Text(frame2).grid() root.mainloop()
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] idle??

2016-01-14 Thread Sydney Shall

On 13/01/2016 23:10, Danny Yoo wrote:

So, where does IDLE fit into this


IDLE is a sad little “IDE”, which is really ugly, because it’s written
in Tk. It lacks many IDE features. It comes with a really basic
debugger (that doesn’t even highlight the line that is being currently
executed…), function signature hinting, and some code completion.

And it doesn’t even do something as basic as line numbering.


Hi Chris,

The quality of a beginner-level IDE might not necessarily be based on
the number of features it has.  For someone who's starting out, IDLE
is probably fine because it gets out of your way.  It lets you type
programs and evaluate them.  For a beginner, that might just be enough
to focus on learning the language.


(Aside: I've had the contrary experience with Eclipse, for example,
which is as full-featured as they come, but makes me feel like I'm
staring at the flight controls of a space shuttle, with all this stuff
about launchers and Luna and such.  I can get productive with it  It
takes my a long time to learn.  I suppose I could say the same thing
about Emacs.)


That is, many features might be a *distraction* from learning to
program.  Tools for beginners should be measured by criteria for
learning, and that might not match with the features we care about as
professional developers.  But maybe that's a controversial opinion.

I think IDLE is ok for what it's designed for: to provide a simple,
textual environment for writing and running simple Python programs.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


I was a beginner who began with >idle< following advice from this list.
I found it invaluable for the reason Danny gives. More complex 
environments befuddled me, and distracted me from learning Python.

I do not use it any longer. I now use IPython which I like a lot.
But for beginners I would recommend it, speaking as a debutante myself.

I hope that Ma Laura gets better soon. But please take care and have it 
seen to or you will have arthritis later. I have never met nor 
corresponded with the fine woman, but I think she is >terrible> [in 
French, otherwise in English wonderful.]


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


Re: [Tutor] me, my arm, my availability ...

2016-01-14 Thread Oscar Benjamin
On 13 January 2016 at 20:47, Laura Creighton  wrote:
>
> Seems like surgery is needed to fix this.
>
> So I wanted you all to know, no, I haven't forgotten you and no haven't
> stopped caring.  I have just stopped being as __capable__ if you know
> what I mean.
>
> Please take care of yourselves and each other.  I will often be reading
> even if typing is more than I can do right now.

I had honestly been wondering where you were. Glad to see that you're
not gone (although obviously not glad that you're injured!).

Wishing a speedy recovery.

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


Re: [Tutor] Question about the memory manager

2016-01-14 Thread eryk sun
On Thu, Jan 14, 2016 at 3:03 AM, Albert-Jan Roskam
 wrote:
>
> These two pages are quite nice. The author says the memory used by small 
> objects is
> never returned to the OS, which may be problematic for long running processes.

The article by Evan Jones discusses a patch to enable releasing unused
arenas (i.e. "how the problem was fixed"). Starting with 2.5, unused
arenas do get released back to the heap. Here's the diff in which Tim
Peters merged in a "heavily altered derivative" of Evan's patch [1].

Also, 2.7 and 3.3 bypass C malloc/free and the process heap to instead
use mmap/munmap on POSIX when available. This avoids the heap
high-water mark problem. Similarly, 3.4 switched to using
VirtualAlloc/VirtualFree on Windows. 3.4 also introduced the
PyObjectArenaAllocator and associated C API functions [2] to allow
modifying the default allocators.

[1]: https://hg.python.org/cpython/diff/685849bd905c/Objects/obmalloc.c
[2]: 
https://docs.python.org/3/c-api/memory.html#customize-pyobject-arena-allocator
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] idle??

2016-01-14 Thread Wolf Halton
Idle is sufficient for a beginner. Better than notepad. It is cross platform so 
your environment looks the same on Linux Mac or What-have-you. Some people 
obsess over ide features to avoid thinking about the more important questions. 
Eclipse never helped me learn to write better py code. I have made several 
attempts to run eclipse, and I keep falling back to geany. Geany needed some 
tweaking at the beginning. Idle never did. 

Wolf Halton
Atlanta Cloud Technology
Cybersecurity & Disaster Recovery Solutions 
Mobile/Text 678-687-6104

--
Sent from my iPhone. Creative word completion courtesy of Apple, Inc. 

On Jan 13, 2016, at 18:10, Danny Yoo  wrote:

>>> So, where does IDLE fit into this
>> 
>> IDLE is a sad little “IDE”, which is really ugly, because it’s written
>> in Tk. It lacks many IDE features. It comes with a really basic
>> debugger (that doesn’t even highlight the line that is being currently
>> executed…), function signature hinting, and some code completion.
>> 
>> And it doesn’t even do something as basic as line numbering.
> 
> Hi Chris,
> 
> The quality of a beginner-level IDE might not necessarily be based on
> the number of features it has.  For someone who's starting out, IDLE
> is probably fine because it gets out of your way.  It lets you type
> programs and evaluate them.  For a beginner, that might just be enough
> to focus on learning the language.
> 
> 
> (Aside: I've had the contrary experience with Eclipse, for example,
> which is as full-featured as they come, but makes me feel like I'm
> staring at the flight controls of a space shuttle, with all this stuff
> about launchers and Luna and such.  I can get productive with it  It
> takes my a long time to learn.  I suppose I could say the same thing
> about Emacs.)
> 
> 
> That is, many features might be a *distraction* from learning to
> program.  Tools for beginners should be measured by criteria for
> learning, and that might not match with the features we care about as
> professional developers.  But maybe that's a controversial opinion.
> 
> I think IDLE is ok for what it's designed for: to provide a simple,
> textual environment for writing and running simple Python programs.
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Modularity

2016-01-14 Thread James Chapman
May I suggest: https://docs.python.org/2/tutorial/modules.html

In particular:
* https://docs.python.org/2/tutorial/modules.html#the-module-search-path
* https://docs.python.org/2/tutorial/modules.html#packages


Now the next bit of advice is likely to be controversial but I have
good reasons for it.

I like to import the top level module and use the full namespace in
the code, that way, when I come back to it in 3 years time I know
where each function call is coming from.

For example, lets say I had the following package (stolen from the
docs page linked above):


sound/  Top-level package
  __init__.py   Initialize the sound package
  formats/  Subpackage for file format conversions
  __init__.py
  wavread.py
  wavwrite.py
  aiffread.py
  aiffwrite.py
  auread.py
  auwrite.py
  ...
  effects/  Subpackage for sound effects
  __init__.py
  echo.py
  surround.py
  reverse.py
  ...
  filters/  Subpackage for filters
  __init__.py
  equalizer.py
  vocoder.py
  karaoke.py


I myself would import as follows

import sound

Then in my code, the calls would look like:

wave = sound.formats.waveread(someFile)
aiffFile = sound.formats.aiffwrite(wave)
auFile = sound.formats.auwrite(wave)


If I did:

from sound import formats.*

Then the code would be

wave = waveread(someFile)
aiffFile = aiffwrite(wave)
auFile = auwrite(wave)


The problem with the latter is, which module supplies waveread?
I have roughly 20 import statements where I'm importing something.*
which one of those modules supplies the function waveread?


A way around the above would be

import sound.formats.waveread
import sound.formats.aiffwrite
import sound.formats.auwrite

Code would then be

wave = waveread(someFile)
aiffFile = aiffwrite(wave)
auFile = auwrite(wave)



But what if we have various modules that implement a waveread function?

Then we'd have to start using

import sound.formats.waveread as sfwaveread
import some.other.waveread


Code is read more than it is written, so don't be lazy! Use the
namespaces in your code. You make it clear what you're doing it you
avoid clashing.


Finally, if you absolutely must be lazy, then import like this:

from sound import formats as sf

wave = sf.waveread(someFile)
aiffFile = sf.aiffwrite(wave)
auFile = sf.auwrite(wave)


There is nothing I hate more than being asked to change or fix someone
elses code when that programmer is lazy and feels he/she can produce a
solution quicker by reducing the amount of typing he/she has to do.
Well, that's a lie, there are things I hate more but this come close!


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


Re: [Tutor] Question about the memory manager

2016-01-14 Thread Albert-Jan Roskam
D

> From: sjeik_ap...@hotmail.com
> To: tim.pet...@gmail.com
> Date: Wed, 13 Jan 2016 08:11:11 +
> Subject: Re: [Tutor] Question about the memory manager
> CC: tutor@python.org
> 
> > From: tim.pet...@gmail.com
> > Date: Sun, 10 Jan 2016 10:54:10 -0600
> > Subject: Re: [Tutor] Question about the memory manager
> > To: sjeik_ap...@hotmail.com
> > CC: tutor@python.org
> > 
> > [Albert-Jan Roskam ]
> > > I just found a neat trick to free up an emergency stash of memory in
> > > a funtion that overrides sys.excepthook. The rationale is that all
> > > exceptions, including MemoryErrors will be logged.
> > > The code is below. My question: is that memory *guaranteed* to be
> > > freed right after the 'del' statement? Or should one call gc.collect to
> > > be really sure?
> > >
> > > rainydayfund = [[] for x in xrange(16*1024)] # or however much you need
> > > def handle_exception(e):
> > > global rainydayfund
> > > del rainydayfund
> > > ... etc, etc ...
> > > http://stackoverflow.com/questions/1235349/python-how-can-i-handle-any-unhandled-exception-in-an-alternative-way
> > 
> > This works fine in all versions of CPython (the C implementation of
> > Python distributed by python.org) to date.  That's because:
> > 
> > 1. All versions of CPython rely primarily on reference counting (`gc`
> > is only needed to reclaim garbage containing reference cycles).  An
> > object is released immediately when its reference count falls to 0.
> > 
> > 2. There is only one reference to the big list there (via the global
> > `raindydayfund`), so the memory becomes garbage immediately upon
> > executing the `del`.
> > 
> > 3. Similarly, that giant list holds the only references to the masses
> > of distinct empty lists it contains, so they also become garbage
> > immediately upon the giant list becoming garbage.
> > 
> > 4. CPython doesn't happen to stick garbage lists in, e.g., some
> > internal free list reusable only for new list objects - it actually
> > releases the memory for garbage lists.  Kinda ;-)
> > 
> > #2 and #3 are necessarily true.  #1 is true in CPython, but not in all
> > implementations of Python.
> > 
> > #4 is where things _might_ change even in CPython, but it's very
> > unlikely to change.  As is, it would take a small book to flesh out
> > what "Kinda ;-)" means, exactly.  Memory management is complex, with
> > many layers, involving many details.
> > 
> > If you can live with all that, I'd suggest a more straightforward way
> > of setting it up, like:
> > 
> > rainydayfund  = b"x" * N
> > 
> > where `N` is the number of bytes you want to reserve.  That is, create
> > a giant bytestring containing the number of "emergency bytes" you
> > need.  If N is large enough, that will avoid CPython's "small object
> > allocator" and CPython's "arena allocator", getting the memory
> > directly from (and returning the memory directly to) the OS.  The
> > fewer layers that get involved, the fewer layers that _may_ surprise
> > you by changing behavior in the future.
> 
> Hi Tim,
> 
> Thank you! Can you recommend a document or website that CPython's memory 
> manager?
> Might be interesting and perhaps useful to know a bit more about the details. 
> Perhaps this knowledge might sometimes help writing faster code?
> 

These two pages are quite nice. The author says the memory used by small 
objects is never returned to the OS, which may be problematic for long running 
processes. It appears that it is better to have a few big objects rather than 
many small ones, because memory is more likely to become fragmented with many 
deleted small objects (and there's no such thing as gc.defrag)
http://www.evanjones.ca/memoryallocator/
http://deeplearning.net/software/theano/tutorial/python-memory-management.html


> Best wishes,
> Albert-Jan
> 
> PS:
> 
> albertjan@debian:~$ python -c "import this" 
> The Zen of Python, by Tim Peters
> 
> ...
> ...
> There should be one-- and preferably only one --obvious way to do it.
> Although that way may not be obvious at first unless you're Dutch.
> 
> --> Nope not even then. Perhaps if my name were Guido? :-)
> 
> 
> 
> 
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Clickable listbox opening specific .txt files

2016-01-14 Thread Alan Gauld
On 14/01/16 08:05, Ali Moradi wrote:
> Hi, i want to open specific .txt files when each item on the listbox was
> clicked! When i click on the first item for example it opens 1.txt and
> shows it on the text widget on the right, and when i select the second item
> on the list first it erases the text on the Text widget and then opens
> 2.txt file and so on till item 17 on the list.

So what does happen?

> Please modify my code i'm still beginner
> Thanks a lot
> 
> paste.pound-python.org/show/uMUswu4YSmMY5XBPPgIy/

We won't write your code for you but we will point out areas
for improvement. But... see below.

For the future:
It's best if you post the actual code in your mail
(using plain text please). We are happy to accept up
to, say, a hundred lines.

Also post full error messages, if any.

Finally tell us the OS and Python version.

Here is a slightly shortened version of your code:


from Tkinter import *

root = Tk()
root.title("Renkontoj kun Diferenculoj")
root.iconbitmap(r"C:\python27\DLLs/py.ico")
root.resizable(0, 0)
frame1 = LabelFrame(root, height=300, width=400, text='Lecionoj')
frame2 = LabelFrame(root, height=300, width=400, text='Tekstoj')
frame1.grid(row=0, column=0)
frame2.grid(row=0, column=1)

def click(event):
index = list.curselection()[0]
file = open(r"C:\Users\deadmarshal\PycharmProjects\ali\1.txt").read()

list = Listbox(frame1)
list.insert(1, "Konatiĝu kun Kamila")
list.insert(2, "Sinjoro Johano")
list.insert(3, "Onklino Marta")
scroll = Scrollbar(frame1, orient=VERTICAL, command=list.yview)
scroll.grid(row=0, column=2, sticky='ns')
list.grid(row=0, column=1)
list.bind("", click)
text = Text(frame2).grid()

root.mainloop()


Notice that your click function does not do anything. It reads
the file then throws it away when the function exits. You need
to insert the file data into your text widget. (And probably
clear the text widget first.)

Finally, note that by using the name liust you are hiding a builtin
Python function, so you will no longer be able to convert things
to a list using list(). This doesn't mattter just now but may be
a problem later. Its best to avoid using names that Python already
uses. One way to do that is to add a descriptive modifier like
name_list, say.

-- 
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] Modularity

2016-01-14 Thread Alan Gauld
On 14/01/16 03:56, kay Cee wrote:

> I'm looking to make individual modules for each class eg. Ball, 
> Paddle,bounds, Game, Physics and Logic.

That's not usually necessary in Python. It's often better
to group several related classes in a single module.
For example your Ball and Paddle and any other display
type things might go together in a module called, say,
pongwidgets.

> Used like this :
> ball = Ball(), paddle = Paddle() and etc...

If you put your Ball class into a module called ball
then you would need to do

import ball

myBall = ball.Ball()

you need to reference the imported module.

Alternatively you could use

from ball import Ball

myBall = Ball()

> Mainly, I get errors that say class is not defined..

It would help if you show us actual code and post
the full error message rather than summarizing things.

> So far I've tried:
> Import class as class,
> From class import*,
> Import class

Note that python is case sensitive so you need lower case.
That may just be your mail tool being too clever though...

The first and third versions are ok, the middle one is frowned on.
It's better to use the

from module import class

style I showed above if you only have (or use) a single
class per module

Post some code and some errors and we will be better
able to help.

-- 
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] Modularity

2016-01-14 Thread kay Cee
Recently I've decided to write a pong style game with pygame; however, I can't 
seem to modularize the game successfully.

I'm looking to make individual modules for each class eg. Ball, Paddle,bounds, 
Game, Physics and Logic.
Used like this :
ball = Ball(), paddle = Paddle() and etc...
In a Game class...
Mainly, I get errors that say class is not defined..

My questions are what is the best way to achieve this and what is the best way 
to import yourClass?

So far I've tried:
Import class as class,
>From class import*,
Import class



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


Re: [Tutor] me, my arm, my availability ...

2016-01-14 Thread CMG Thrissur

take care, get well soon,

regards

CMG

On Thursday 14 January 2016 02:17 AM, Laura Creighton wrote:

I fell recently.  Ought to be nothing, but a small chip of bone, either an
existing one or one I just made is nicely wedged in the joint taking away
a whole lot of the ability of my arm to rotate in the elbow joint.  Or
hold my arm in a position that is usual for typing.  Plus,  now that the
sprain/swelling is more or less over, the pain, unfortunately is not.

The real downside is that my typing speed is down from 135-140 wpm
to 5-10 wmp.  At this rate, just getting my usual work done takes
overtime.

Seems like surgery is needed to fix this.

So I wanted you all to know, no, I haven't forgotten you and no haven't
stopped caring.  I have just stopped being as __capable__ if you know
what I mean.

Please take care of yourselves and each other.  I will often be reading
even if typing is more than I can do right now.

Laura

ps -- (recent tutor discussion) I am with Alan and not with Mark.  I
am happy as anything when people post their not-quite-working code for
homework assignments here to tutor.  They aren't lazy bastards wanting
somebody to do their assignments for them, they want to learn why what
they are trying to do isn't working.  Sounds perfect for tutor to me.

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


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


[Tutor] Clickable listbox opening specific .txt files

2016-01-14 Thread Ali Moradi
Hi, i want to open specific .txt files when each item on the listbox was
clicked! When i click on the first item for example it opens 1.txt and
shows it on the text widget on the right, and when i select the second item
on the list first it erases the text on the Text widget and then opens
2.txt file and so on till item 17 on the list.

Please modify my code i'm still beginner
Thanks a lot

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