[Tutor] String formating

2011-12-15 Thread Stayvoid
Hey folks!

What's the difference between these commands?

print "%02d" % (12)

print "%d" % (12)

I know that "d" stands for decimal. What does "02" mean?


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


[Tutor] PYTHONPATH (Mac OS X)

2011-12-18 Thread Stayvoid
Hey there!

How to set it right?


Cheers!
___
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-19 Thread Stayvoid
> Please clarify, or expand, or tell us what problem you are having or
> trying to solve.

Hi!

I want to have a possibility to import modules from the folder, which
is not included in the load path.

Example:

module.py
-
def testfunc(name):
  file = open(name)
  return len(file.readlines())

if __name__ == "__main__":
  print testfunc(module.py)

Code listing (shell):
python /Users/Username/pythonmodules/module.py

NameError: name 'module.py' is not defined

Kind regards.
___
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-25 Thread Stayvoid
Hey there!

I'm reading Lutz's Learning Python.

Here is some code from the book.

There is a module called lcclient_lutz.py:

from lengthcounter_lutz import countLines, countChars
print countLines('lengthcounter_lutz.py'), countChars('lengthcounter_lutz.py')

And there is another one called lengthcounter_lutz.py:

def countLines(name):
file = open(name)
return len(file.readlines())

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

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

if __name__ == '__main__':
print test('lengthcounter_lutz.py')

I've got an error while trying to load lcclient_lutz module:
python /Users/Username/Python_modules/lcclient_lutz.py
Traceback (most recent call last):
  File "/Users/Username/Python_modules/lcclient_lutz.py", line 2, in 
print countLines('lengthcounter_lutz.py'),
countChars('lengthcounter_lutz.py')
  File "/Users/Username/Python_modules/lengthcounter_lutz.py", line 2,
in countLines
file = open(name)
IOError: [Errno 2] No such file or directory: 'lengthcounter_lutz.py'

How to fix it? Is it connected with the PYTHONPATH variable?

P.S. There might be an error in the lengthcounter_lutz module, because
it makes mistakes while counting.


Kind regards.
___
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-26 Thread Stayvoid
>Simply that python is saying it cannot find the file.
>So it is probably in a different folder to the one in which the program is 
>running. You need to provide a valid path to the file,

Those files are in the same folder:
/Users/Username/Python_modules/

I don't want to write a full path here:
if __name__ == '__main__':
   print test('lengthcounter_lutz.py')

How to add this directory to the search path?

>So what is it doing exactly that seems wrong?
>What input? What output? What did you expect?

I have a slightly different copy of this file:

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)

I've tried to run it in the interactive shell:

import lengthcounter as lc
lc.test(lengthcounter)

And here is the output:

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

But that code has 13 lines and 317 characters according to the Emacs' counter.
Where is an error?

Cheers.
___
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 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


[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 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


[Tutor] Class vs. instance

2012-01-01 Thread Stayvoid
Hi there!

>>> class Sample:
>>> def method(self): pass

>>> Sample().method()

What's the difference between class __main__.Sample and
__main__.Sample instance?
Why should I write "Sample().method" instead of "Sample.method"?


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


Re: [Tutor] Class vs. instance

2012-01-01 Thread Stayvoid
Thanks.

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


Re: [Tutor] Class vs. instance

2012-01-17 Thread Stayvoid
Hello!

Here is another one.

class A:
def __init__(self, data):
self.data = data
print self.data

I'm trying to understand this function-like syntax:
A('foo').__init__(42)
A(12).data

What are we actually calling this way?
Are there any other ways to get the same result?


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


[Tutor] __getattribute__

2012-02-03 Thread Stayvoid
Hi!

Could you provide some examples (easy and hard ones) and comments on the topic?
I'm trying to understand how this thing works.


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