[Tutor] Confusion regarding the 'from' statement

2012-08-14 Thread Mazhar Hussain
Im new to python and theres something thats bothering me for quite a
time. I read in 'Learning Python' by Mark Lutz that when we use a
'from' statement to import a name present in a module, it first
imports the module then assigns a new name to it(i.e. the name of the
function,class, etc present in the imported module) and then deletes
the module object with the del statement. However what happens if I
try to import a name using 'from' that references a name in the
imported module that itself is not imported. Consider the following
example,here there are two modules mod1.py and mod2.py,

#mod1.py
from mod2 import test
test('mod1.py')

#mod2.py
def countLines(name):
print len(open(name).readlines())

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

def test(name):
print 'loading...'
countLines(name)
countChars(name)
print '-'*10

Now see what happens when I run or import mod1

>>>import mod1

loading...
3
44
--

Here when I imported and ran the 'test' function, it ran successfully
although I didn't even import countChars or countLines, and the 'from'
statement had already deleted the mod2 module object.

SO I basically need to know why does this code work although
considering the problems I mentioned it shouldn't.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Thanks!

2009-07-20 Thread Mazhar Hussain
Thanks for all your help guys! I will try to buy all those books so that if
I find something in one book not understandable, I will look for it in
another book. Again Thanks. This list really is Helpful!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Pygame

2009-07-20 Thread Mazhar Hussain
 Hello All! My name is Mazhar Hussain, and I am new to python, in fact, I am
new to programming as a whole. I dont know if its the right list to talk
about this.
 I am really interested in 2d games, especially 2d games. I am also
interested in making games. I searched for a lot of programming languages
but I didnt like anyone of them, either they were too hard to learn or not
suitable to make games. But then I found Python. I had heard that it was
very easy to learn and great for making games, it also had a binding for SDL
called pygame. But the main games I want to create are: a pokemon clone, a
megaman battle network clone and a world of goo like game. I just want to
know if I can make these type of games with pygame(before learning python).
If it can then I'll start learning python right away but if it cant then I
think I may better find another language.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor