Re: [Tutor] PYTHONPATH (Mac OS X)

2011-12-30 Thread Stayvoid
>You don't have any option.
>You either type in the full path or you get the user to tell you
>in some way - either with a prompt or via an input argument.

OK, now I get it.

How can I tell this to the end-user?
Should I write a README file or what?

I've tried to run lengthcounter_lutz from the file's folder and this worked out.
cd /Users/Username/Python_modules/
python /Users/Username/Python_modules/lengthcounter_lutz.py
('Lines:', 12, 'Chars:', 285)


But I can't understand what's wrong with the second one:
def countLines(name):
file = open(name.__file__)
return len(file.readlines())

def countChars(name):
return len(open(name.__file__).read())

def test(name):
return "Lines:", countLines(name), "Chars:", countChars(name)

if __name__ == '__main__':
import lengthcounter
print test(lengthcounter)

>>> import lengthcounter
>>> lengthcounter.test(lengthcounter)
('Lines:', 5, 'Chars:', 885)


That PYTHONPATH variable has no connection with the mess above. When
should I use it?


Thanks for your help.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] PYTHONPATH (Mac OS X)

2011-12-30 Thread Alan Gauld

On 30/12/11 13:11, Stayvoid wrote:


I've tried to run lengthcounter_lutz from the file's folder and this worked out.
cd /Users/Username/Python_modules/
python /Users/Username/Python_modules/lengthcounter_lutz.py



You should only have needed:

> python ./lengthcounter_lutz.py

the ./ tells Linux to use the current folder as startuing point.


('Lines:', 12, 'Chars:', 285)


But I can't understand what's wrong with the second one:
def countLines(name):
 file = open(name.__file__)
 return len(file.readlines())

def countChars(name):
 return len(open(name.__file__).read())

def test(name):
 return "Lines:", countLines(name), "Chars:", countChars(name)

if __name__ == '__main__':
 import lengthcounter
 print test(lengthcounter)


import lengthcounter
lengthcounter.test(lengthcounter)

('Lines:', 5, 'Chars:', 885)


Neither do I but you can debug it easily from the >>> prompt by calling 
the individual lines/functions. Try:


>>> import lengthcounter as lc
>>> print lc.__file__   # to check it's using the expected file
>>> # assuming it is...
>>> print (open(lc.__name__),read())   # check the contents is what we 
expect

>>> print ( len(open(lc.__name__),read()) )   # check the length result
>>> print ( len(open(lc.__name__),readlines()) )   # check the lines


That PYTHONPATH variable has no connection with the mess above. When
should I use it?


Python uses PYTHONPATH to find modules when you import them.

So when we do import lengthcounter above we dont need to be in the same 
folder as lengthcounter.py to be able to import it.


HTH
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

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


[Tutor] Drawing a figure

2011-12-30 Thread Stayvoid
Hey there!

I want to write a program that can draw a figure using the coordinates
specified by the user and calculate its area. An output should be
saved in tiff or png.
What should I use for this?


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


Re: [Tutor] Drawing a figure

2011-12-30 Thread Alan Gauld

On 30/12/11 14:12, Stayvoid wrote:

I want to write a program that can draw a figure using the coordinates
specified by the user and calculate its area. An output should be
saved in tiff or png.
What should I use for this?


You have lots of options.

Since you are on a Mac you might want to try using the Mac native 
libraries or OpenGL. Both are available via the MacPython downloads.


Or more generically you can use one of the several cross-platform GUI 
toolkits (GTk, Qt, wxPython, Tkinter) - they all have a Canvas widget 
that allows you to draw figures.


But the easiest option is probably to use the turtle module which
lets you draw graphics using turtle commands (like forward, rioght, 
left, pen up,down, etc. The documentation has several examples and you 
can find lots of web pages discussing turtle graphics in general terms.


Calculating the area is probablybest done indepenmdantly of drawing the 
figure., Store the coordinates, calculate the shape and hyence its area 
and display the result. You can buuld this as a  text based app first or 
get the turtle stuff working first, it really doesn;t matter which, then 
stitch the two elements together in a single UI.


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

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


Re: [Tutor] Drawing a figure

2011-12-30 Thread Stayvoid
I think I'll stick with PyGTK.

How to install it?

This FAQ looks outdated:
http://faq.pygtk.org/index.py?req=show&file=faq01.019.htp

I've also tried to compile it from source:
PyGTK asked for pkg-config and pygobject.
Pygobject asked for pkg-config.
Pkg-config asked for pkg-config and glib:
configure: error: pkg-config and glib-2.0 not found, please set
GLIB_CFLAGS and GLIB_LIBS to the correct values

I know that there is no glib on Mac by default. Where can I get it?


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


Re: [Tutor] Drawing a figure

2011-12-30 Thread Alan Gauld

On 30/12/11 18:49, Stayvoid wrote:

I think I'll stick with PyGTK.


I assume "stick with" implies you have previous experience with GTk?


How to install it?


Sorry, can't help there, but there are some other GTk users
on the list, maybe some of them use Mac and can help?


I know that there is no glib on Mac by default. Where can I get it?


You could try some of the open source repositories for the Mac. The one 
I've used has been Fink, but there are at least 2 others. I don't know 
if fink has GTk though...


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

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