Re: [Tutor] What is this an example of (and how can i use it?)

2009-09-22 Thread kevin parks


On Sep 21, 2009, at 9:52 AM, Kent Johnson wrote:




Calling a generator function gives you something that can be iterated.
You can create a list out of it (by passing it to the list() function)
or you can iterate the items in it directly with a for loop. Using the
example above, you could say
for item in roundrobin('abc', [], range(4),  (True,False)):
 print item

I kinda understand conceptually what iterators and generators do  
and why
they are "a honking good idea" (why create 100 of x when we just  
want the
100th, etc.) what i don't get is the syntax and how they are used  
in real

life. How generator and iterators behave in the wild.


It's really not that bad. They are just a generalization of what you
have already been doing with lists.


Even the Lutz is too
terse and generally poor on these two complex and relatively new  
constructs.

They are a dark and obscure magic.


No, really they are not difficult. Read my essay and ask questions if
you don't understand.



Thanks. I have some time today and will read up on what you sent me  
and revisit
the lutz and other docs. It appears it is not so impenetrable as i  
initially though. Well iterators
aren't maybe, but generator do look tricky. So interators iterate over  
lists, tuples, strings, dictionaries
and any data type that is iterable, and generators are ways to make  
new iterables? Anyway, i will

brew some coffee and hit those links. Thanks,

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


Re: [Tutor] Challenge

2009-09-22 Thread Tim Bowden
On Tue, 2009-09-22 at 05:13 -0700, Ali Sina wrote:
> Hello tutor
> 
> I downloaded a guide about learning Python by Michael Dawson which has
> challenges at the end of each chapter. I'm a novice so I encountered a
> problem with this challenge:
> 
> 
> 
> "Write a program that flips a coin 100 times and then tells you the
> number of heads and tails."

The heads and tails bit is a red herring.  Don't try and model it in
your code.  It does nothing more than signal a binary condition, and
provide a tag to hang the result on (at least in this context).

#!/usr/bin/python
import random

i=0
for flip in range(100):
  i += random.choice((0,1))

print "Heads: %d, Tails: %d" % (i, 100-i)
#

Tim bowden


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


Re: [Tutor] How to get homework help (was need to hire a tutor... )

2009-09-22 Thread Tim Bowden
On Tue, 2009-09-22 at 09:20 +0100, Alan Gauld wrote:
> > I'm new on this list <*waves hello to everyone*>, 
> 
> welcome to the tutor list  <*waves back*> :-)
> 
> > trick to getting help here with homework is pretty much the same as
> > most > other tech lists.
> 
> Absolutely so, and well summarised.
> 
> Alan G.
> http://www.alan-g.me.uk/


And the off list reply was pretty much what you'd expect.  Funny old
thing life.

Tim Bowden
-- 
Mapforge Geospatial
Open Source Spatial Consulting
http://www.mapforge.com.au

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


Re: [Tutor] how to define a function with multple parameters

2009-09-22 Thread David

shellc...@juno.com wrote:

I want to know how to use multiple parameters for 1 function


def display(message):
print message

def rate_score():
score = rate_score


if rate_score <= 999:

print "that's nothing."
elif rate_score <= 1:
print "ok."
elif rate_score >= 1:   
print "great." 
 
		

#main   

display("Get  the meaning !")

raw_input("Please type in your score")
print "here's your score", rate_score
rate_score()
This is the outcome:

great.
Get the meaning
Please type in your score50
here's your score 


Here is something that you can try;

#!/usr/bin/python

def display(message):
print message

def rate_score(selection):
if selection <= 99:
print 'Thats nothing !'
else:
print 'Thats something !'

def main():
display('Get the meaning !')
while True:
try:
selection = int(raw_input('Please enter your score: '))
break
except ValueError:
print 'Oops! Did you forget to enter a number !'
print 'You entered %s as your score' % selection
rate_score(selection)

main()


--
Powered by Gentoo GNU/Linux
http://linuxcrazy.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] calling a superclass method after overriding it

2009-09-22 Thread Dave Angel

Serdar Tumgoren wrote:

  def add_name(self):
  try:
  self.name = SPECIALIZED_SQLcall_for_child()
  except SpecialSQLError:
  #default to the superclass's add_name method
  super(Child, self).add_name()



That certainly is a lot easier to read. So if I were to go that route,
would my "SPECIALIZED_SQLCall_for_child()"  function (I've slightly
renamed it) have to resemble something like below?:

def SpecialSQLcall_for_child():
   result = execute some sql_for_special_case()
if type(result) != str:
raise SpecialSQLError
else:
return result

  
Exactly.  The whole point of forgiveness/permission is to be able to 
propagate the error without having other code in the path affected by 
it.  So if you return at all, return a real value.  (Raise isn't exactly 
returning, the way I see it, since the flow of control goes elsewhere)


BTW, it's possible that "execute_some_sql...()" might itself be raising 
the exception.  In this case, we might make this call even simpler;  it 
needn't even know anything about the exception.


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


Re: [Tutor] urllib2, read data with specific encoding

2009-09-22 Thread Kent Johnson
On Tue, Sep 22, 2009 at 7:56 PM, Sander Sweers  wrote:
> On Tue, 2009-09-22 at 18:04 -0400, Kent Johnson wrote:
>> > def reader(fobject, encoding='UTF-8'):
>> >    '''Read a fileobject with specified encoding, defaults UTF-8.'''
>> >    r = codecs.getreader(encoding)
>> >    data = r(fobject)
>> >    return data
>> >
>> > I would call it like reader(urllib2.urlopen(someurl), 'somencoding').
>> > Now I am looking for advice if this is the proper way of dealing with
>> > these type of issues? Is there better practice maybe?
>>
>> That seems ok if you want a file-like object.
>
> Ok good, I was worried I was doing something stupid :-)
>
>> If you just want a string it would be simpler to use
>> urllib2.urlopen(someurl).read().decode('someencoding')
>
> Wouldn't this have an extra conversion from str to unicode which my
> function skips?

No, IIUC your version is returning unicode strings, the decoding is
just hidden inside the codecs reader object.

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


Re: [Tutor] calling a superclass method after overriding it

2009-09-22 Thread Serdar Tumgoren
>   def add_name(self):
>       try:
>           self.name = SPECIALIZED_SQLcall_for_child()
>       except SpecialSQLError:
>           #default to the superclass's add_name method
>           super(Child, self).add_name()
>
That certainly is a lot easier to read. So if I were to go that route,
would my "SPECIALIZED_SQLCall_for_child()"  function (I've slightly
renamed it) have to resemble something like below?:

def SpecialSQLcall_for_child():
   result = execute some sql_for_special_case()
if type(result) != str:
raise SpecialSQLError
else:
return result
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] calling a superclass method after overriding it

2009-09-22 Thread ALAN GAULD


> In this case, is there any argument against checking for None? Or is
> it better to do a type check for a string?
> 
> if name is None:
> super()
> else:
> # do stuff


That might be ok if string or None are the only types you could get.
Checking for not string will catch any numbers, booleans or anything 
else that might slip through...

Basically check for what id most accurately representing what 
you want. If you want to catch anything other than a string use
an explicit string test, if you only want to catch None then check 
for None.

Alan G.

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


Re: [Tutor] calling a superclass method after overriding it

2009-09-22 Thread Serdar Tumgoren
>>>            self.name =ame
>
> I assume this is a typo? And it never gets executed because the error is
> always raised.

yep. that was a typo that should be "name"

> I don't mind using exceptions for a simple test but not where the test is
> being forced by a piece of code that does nothing. In this case I agree it
> would be better to check explicitly for a string if a string is required.

I am indeed trying to check if it's a string.
>
>  if type(name) != str:
>       super()
>  else:
>       # other stuff here
>
> is clearer still
>

In this case, is there any argument against checking for None? Or is
it better to do a type check for a string?

if name is None:
super()
else:
# do stuff
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to define a function with multple parameters

2009-09-22 Thread Alan Gauld

 wrote


I want to know how to use multiple parameters for 1 function


Do you by any chance come from a Visual Basic background?


def display(message):
print message

def rate_score():
   score = rate_score


This does nothing. It assigns the function rate_score to a local 
variable which is immediately thrown away.


I suspect you wanted to "return" the score? Except you 
don't assign a value to score, you assign the same function. 
So I'm a bit confused over what you are trying to do.



if rate_score <= 999:


This compares a function object, rate_score, to a number
which does not make sense. Even if rate_score returned 
a value you need to provide parentheses to call the function.

Like this:

if rate_score() <= 99:


elif rate_score <= 1:


Same again

elif rate_score >= 1:   


and again


raw_input("Please type in your score")


And here you are again not storing the value anywhere.
I suspect you also want to convert it to a number so you 
probably want:


score = int( raw_input("Please type your score ") )


print "here's your score", rate_score


Again you are using the function object not a value. 
You want to use whatever variable you choose to store the score in.



rate_score()


Despite the subject of your email I think you need to go 
back to the fundamentals of writing and using Python functions. 
You obviously missed something fundamental first time around.


Try the Functions and Modules topic in my tutorial as an 
alternative source of info...


--
Alan Gauld
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] calling a superclass method after overriding it

2009-09-22 Thread Dave Angel

Serdar Tumgoren wrote:

An "if" test would be more readable, I agree.  But I was trying to
apply the "Easier to Ask Permission Forgiveness" style, discussed in
the Python Cookbook: ,



Err..."Easier to Ask Forgiveness than Permission" approach is what I
meant (perhaps proving my point about not fully understanding the
technique!)

  
I certainly understand the concept and use it often.  But the main time 
to use it is when it can avoid interrupting the normal flow for normal 
operation.  For example, if you define a function that doesn't return 
unless it has a valid result (for invalid, it raises an exception), then 
the calling function doesn't need to explicitly check the result.  That 
might permit one to embed the first function call into a more complex 
expression without having to decompose it to test for errors at various 
points.


If the first function were written that way (raise, rather than 
returning None), then we could change from:


   def add_name(self):
   name = result_of_SPECIALIZED_SQLcall_for_child()
   try:
   name + ''
   self.name =ame
   except TypeError:
   #default to the superclass's add_name method
   super(Child, self).add_name()

to:

   def add_name(self):
   try:
   self.name = result_of_SPECIALIZED_SQLcall_for_child()
   except SpecialSQLError:
   #default to the superclass's add_name method
   super(Child, self).add_name()


still not really worth it, but it's getting there.  And notice it's 
shorter, and especially so in the normal path.


DaveA

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


Re: [Tutor] how to define a function with multple parameters

2009-09-22 Thread Dave Angel

shellc...@juno.com wrote:

I want to know how to use multiple parameters for 1 function


def display(message):
print message

def rate_score():
score =ate_score


if rate_score <=99:

print "that's nothing."
elif rate_score <=:
print "ok."
elif rate_score >=:   
print "great." 
 
		

#main   

display("Get  the meaning !")

raw_input("Please type in your score")
print "here's your score", rate_score
rate_score()
This is the outcome:

great.
Get the meaning
Please type in your score50
here's your score 


  
I have no idea what the subject line is supposed to mean, but that 
program is in sad shape.  It won't compile and run as it stands, so I 
suspect you didn't transcribe it correctly.  Please use cut and paste to 
show us what you really have, and what it really produces.  Then maybe 
we can comment on improvements.


Also, please delineate which parts of the message are from a python 
script, and which parts are the echoes from an interactive run.  And if 
you're running from a command line, show the command used to launch the 
script, all the way through to the end.


One thing that probably isn't a transcribing error is your total 
confusion between a variable called rate_score and a function by the 
same name.  A given name can only have one meaning in one scope, so plan 
carefully.  And even if you can reassign a function name inside that 
function to have a new value, it's almost never a good idea.  For one 
thing, it makes it hard to call the function a second time.


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


Re: [Tutor] calling a superclass method after overriding it

2009-09-22 Thread Alan Gauld


"Dave Angel"  wrote


def result_of_SPECIALIZED_SQLcall_for_child():
name =None
return name


I assume this is a placeholder for more complex code to follow?


class Child(Parent):
def add_name(self):
name = result_of_SPECIALIZED_SQLcall_for_child()
try:
name + ''


This does nothing except raise a type error. But that's 
a very contrived way of checking the type.



self.name =ame


I assume this is a typo? And it never gets executed because 
the error is always raised.



except TypeError:
super(Child, self).add_name()


I know this is a simplified example, but I'd still like to point out 
that using exceptions when there's a simple test is not reasonable.   
You can just check for None with a simple if test.


I don't mind using exceptions for a simple test but not where the 
test is being forced by a piece of code that does nothing. In this 
case I agree it would be better to check explicitly for a string if 
a string is required.


Even using exceptions it would be better to do someting like:

try:
  if type(name) != str:
 raise TypeError
  # other stuff here
except TypeError:
   super()

It makes the purpose of the code obvious.

But

  if type(name) != str:
   super()
  else:
   # other stuff here

is clearer still


--
Alan Gauld
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] urllib2, read data with specific encoding

2009-09-22 Thread Sander Sweers
On Tue, 2009-09-22 at 18:04 -0400, Kent Johnson wrote:
> > def reader(fobject, encoding='UTF-8'):
> >'''Read a fileobject with specified encoding, defaults UTF-8.'''
> >r = codecs.getreader(encoding)
> >data = r(fobject)
> >return data
> >
> > I would call it like reader(urllib2.urlopen(someurl), 'somencoding').
> > Now I am looking for advice if this is the proper way of dealing with
> > these type of issues? Is there better practice maybe?
> 
> That seems ok if you want a file-like object.

Ok good, I was worried I was doing something stupid :-)

> If you just want a string it would be simpler to use
> urllib2.urlopen(someurl).read().decode('someencoding')

Wouldn't this have an extra conversion from str to unicode which my
function skips?

Thanks
Sander

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


Re: [Tutor] ex-ftp

2009-09-22 Thread Kent Johnson
On Tue, Sep 22, 2009 at 12:39 AM, prasad rao  wrote:
> hello  friends
>   I am trying to write a class to save a url.page.
> But it is not working.It is saving the html.page.But not getting
> images.I am unable to show the list (object.links).
> Please take a look at it and show me how to rectify it.

There is a websucker tool supplied with python that will do this.
http://effbot.org/zone/websucker.htm

There's a gui version too, called wsgui.

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


Re: [Tutor] urllib2, read data with specific encoding

2009-09-22 Thread Kent Johnson
On Tue, Sep 22, 2009 at 5:04 PM, Sander Sweers  wrote:
> Hello Tutors, Because a website was giving me issues with unicode
> character I created a function to force the encoding. I am not sure it
> is the correct way to handle these things.
>
> def reader(fobject, encoding='UTF-8'):
>    '''Read a fileobject with specified encoding, defaults UTF-8.'''
>    r = codecs.getreader(encoding)
>    data = r(fobject)
>    return data
>
> I would call it like reader(urllib2.urlopen(someurl), 'somencoding').
> Now I am looking for advice if this is the proper way of dealing with
> these type of issues? Is there better practice maybe?

That seems ok if you want a file-like object. If you just want a
string it would be simpler to use
urllib2.urlopen(someurl).read().decode('someencoding')

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


Re: [Tutor] calling a superclass method after overriding it

2009-09-22 Thread Serdar Tumgoren
> An "if" test would be more readable, I agree.  But I was trying to
> apply the "Easier to Ask Permission Forgiveness" style, discussed in
> the Python Cookbook: ,
>
Err..."Easier to Ask Forgiveness than Permission" approach is what I
meant (perhaps proving my point about not fully understanding the
technique!)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] calling a superclass method after overriding it

2009-09-22 Thread Serdar Tumgoren
> I know this is a simplified example, but I'd still like to point out that
> using exceptions when there's a simple test is not reasonable.   You can
> just check for None with a simple if test.

An "if" test would be more readable, I agree.  But I was trying to
apply the "Easier to Ask Permission Forgiveness" style, discussed in
the Python Cookbook: ,

http://tinyurl.com/lfp35q

And in this recipe from the book:

http://code.activestate.com/recipes/52291/

The example Martelli uses is far more complicated than my simple use
case of checking for None, so perhaps I've engaged in a bit of
overkill? Or perhaps I'm not fully understanding the lesson. I'll
admit, the latter is very possible since I'm still on the front end of
the learning curve...
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] calling a superclass method after overriding it

2009-09-22 Thread Dave Angel



Serdar Tumgoren wrote:




def result_of_SPECIALIZED_SQLcall_for_child():
name =None
return name



class Child(Parent):
def __init__(self):
super(Child, self).__init__()

def add_name(self):
name = result_of_SPECIALIZED_SQLcall_for_child()
try:
name + ''
self.name =ame
except TypeError:
#default to the superclass's add_name method
super(Child, self).add_name()

Meantime, many thanks!!

  
I know this is a simplified example, but I'd still like to point out 
that using exceptions when there's a simple test is not reasonable.   
You can just check for None with a simple if test.


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


[Tutor] how to define a function with multple parameters

2009-09-22 Thread shellc...@juno.com
I want to know how to use multiple parameters for 1 function


def display(message):
print message

def rate_score():
score = rate_score


if rate_score <= 999:
print "that's nothing."
elif rate_score <= 1:
print "ok."
elif rate_score >= 1:   
print "great." 
 

#main   

display("Get  the meaning !")

raw_input("Please type in your score")
print "here's your score", rate_score
rate_score()
This is the outcome:

great.
Get the meaning
Please type in your score50
here's your score 



Life Insurance Quotes
30 Seconds can save a lifetime. Get it done. Its never been easier.
http://thirdpartyoffers.juno.com/TGL2141/c?cp=mP3QZBgr1A9eUSmX6ls13gAAJ1CmHaRKpeX3s0f3JfT8odq8AAQFAK1A2j4ACEcEAA==
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] urllib2, read data with specific encoding

2009-09-22 Thread Sander Sweers
Hello Tutors, Because a website was giving me issues with unicode
character I created a function to force the encoding. I am not sure it
is the correct way to handle these things.

def reader(fobject, encoding='UTF-8'):
'''Read a fileobject with specified encoding, defaults UTF-8.'''
r = codecs.getreader(encoding)
data = r(fobject)
return data

I would call it like reader(urllib2.urlopen(someurl), 'somencoding').
Now I am looking for advice if this is the proper way of dealing with
these type of issues? Is there better practice maybe?

Many thanks
Sander

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


Re: [Tutor] calling a superclass method after overriding it

2009-09-22 Thread Serdar Tumgoren
> I know that when you need super(), you have to use it everywhere. So I
> would stick with what you have.
>
> Kent
>

Okay. Thanks as always to all.
Best,
Serdar
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] module not found problem

2009-09-22 Thread Parag Shah
Hi Luke, Kent,

Thanks the solution worked.

-- 
Thanks & Regards
Parag Shah
http://blog.adaptivesoftware.biz


On 9/23/09, Luke Paireepinart  wrote:
> Yeah looks like Kent had the same recommendation.I would suggest you don't
> import from draft, because they will probably change the version number of
> pape at some point.
> That's why they aliased it as openid.extensions.pape, so they can update it
> without breaking your code.  Seems odd that they would do it that way
> though.
>
> On Tue, Sep 22, 2009 at 8:27 PM, Parag Shah  wrote:
>
>> Hi Luke,
>>
>> If I get into the Python prompt, the following line does succeed (so
>> it seems like __init__.py is being processed):
>>
>> >>> from openid.extensions import pape
>>
>> But this one fails because pape is not found... this is very strange:
>> >>> from openid.extensions.pape import Request as PapeRequest
>>
>> As you suggested I tried this, but it too fails:
>> >>> from openid.extensions.pape5 import Request as PapeRequest
>>
>> However, doing this succeeds:
>> >>> from openid.extensions.draft.pape5 import Request as PapeRequest
>>
>>
>> --
>> Thanks & Regards
>> Parag Shah
>> http://blog.adaptivesoftware.biz
>>
>> On 9/22/09, Luke Paireepinart  wrote:
>> > It looks to me like your __init__.py is transparently
>> > mapping openid.extensions.pape to openid.extensions.pape5 but when you
>> try
>> > to do a direct import from openid.extensions.pape it doesn't process
>> > the
>> > __init__.py.  I've never seen something like this but from your example
>> > that's my first guess.Try doing
>> > from openid.extensions.pape5 import PageRequest
>> >
>> > I would guess the way you're expected to do it is just
>> > from openid.extensions import pape
>> >
>> > and if you don't want to refer to PageRequest as pape.PageRequest
>> > just do
>> > PageRequest = pape.PageRequest
>> >
>> > That doesn't sound quite right though
>> >
>> > On Tue, Sep 22, 2009 at 7:56 PM, Parag Shah 
>> > wrote:
>> >
>> >> Hi,
>> >>
>> >> I am using django-openid-consumer, which has a line in it's views.py
>> >> which results in an error due to module not found -
>> >>
>> >> from openid.extensions.pape import Request as PapeRequest
>> >>
>> >> where 'openid.extensions' comes from python-openid-2.2.4 (installed
>> >> using 'python setup.py install'), which has an 'extensions' directory,
>> >> but no 'pape' directory. However, 'extensions' has an __init__.py
>> >> which seems to be importing 'pape', like this:
>> >>
>> >> __all__ = ['ax', 'pape', 'sreg']
>> >> from openid.extensions.draft import pape5 as pape
>> >>
>> >>
>> >> However, the Django app still gives me an error when the line which
>> >> required pape is executed. I started the Python prompt and tried the
>> >> following:
>> >>
>> >> >>> from openid.extensions import pape
>> >> >>> from openid.extensions.pape import PageRequest
>> >> Traceback (most recent call last):
>> >>  File "", line 1, in 
>> >> ImportError: No module named pape
>> >>
>> >>
>> >> So Python is able to execute the first import which just imports
>> >> 'pape', but fails on the second import which imports 'PageRequest'
>> >> from 'pape'.
>> >>
>> >> Can someone point out what the problem may be.
>> >>
>> >> --
>> >> Thanks & Regards
>> >> Parag Shah
>> >> http://blog.adaptivesoftware.biz
>> >> ___
>> >> Tutor maillist  -  Tutor@python.org
>> >> To unsubscribe or change subscription options:
>> >> http://mail.python.org/mailman/listinfo/tutor
>> >>
>> >
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] module not found problem

2009-09-22 Thread Luke Paireepinart
Yeah looks like Kent had the same recommendation.I would suggest you don't
import from draft, because they will probably change the version number of
pape at some point.
That's why they aliased it as openid.extensions.pape, so they can update it
without breaking your code.  Seems odd that they would do it that way
though.

On Tue, Sep 22, 2009 at 8:27 PM, Parag Shah  wrote:

> Hi Luke,
>
> If I get into the Python prompt, the following line does succeed (so
> it seems like __init__.py is being processed):
>
> >>> from openid.extensions import pape
>
> But this one fails because pape is not found... this is very strange:
> >>> from openid.extensions.pape import Request as PapeRequest
>
> As you suggested I tried this, but it too fails:
> >>> from openid.extensions.pape5 import Request as PapeRequest
>
> However, doing this succeeds:
> >>> from openid.extensions.draft.pape5 import Request as PapeRequest
>
>
> --
> Thanks & Regards
> Parag Shah
> http://blog.adaptivesoftware.biz
>
> On 9/22/09, Luke Paireepinart  wrote:
> > It looks to me like your __init__.py is transparently
> > mapping openid.extensions.pape to openid.extensions.pape5 but when you
> try
> > to do a direct import from openid.extensions.pape it doesn't process the
> > __init__.py.  I've never seen something like this but from your example
> > that's my first guess.Try doing
> > from openid.extensions.pape5 import PageRequest
> >
> > I would guess the way you're expected to do it is just
> > from openid.extensions import pape
> >
> > and if you don't want to refer to PageRequest as pape.PageRequest
> > just do
> > PageRequest = pape.PageRequest
> >
> > That doesn't sound quite right though
> >
> > On Tue, Sep 22, 2009 at 7:56 PM, Parag Shah  wrote:
> >
> >> Hi,
> >>
> >> I am using django-openid-consumer, which has a line in it's views.py
> >> which results in an error due to module not found -
> >>
> >> from openid.extensions.pape import Request as PapeRequest
> >>
> >> where 'openid.extensions' comes from python-openid-2.2.4 (installed
> >> using 'python setup.py install'), which has an 'extensions' directory,
> >> but no 'pape' directory. However, 'extensions' has an __init__.py
> >> which seems to be importing 'pape', like this:
> >>
> >> __all__ = ['ax', 'pape', 'sreg']
> >> from openid.extensions.draft import pape5 as pape
> >>
> >>
> >> However, the Django app still gives me an error when the line which
> >> required pape is executed. I started the Python prompt and tried the
> >> following:
> >>
> >> >>> from openid.extensions import pape
> >> >>> from openid.extensions.pape import PageRequest
> >> Traceback (most recent call last):
> >>  File "", line 1, in 
> >> ImportError: No module named pape
> >>
> >>
> >> So Python is able to execute the first import which just imports
> >> 'pape', but fails on the second import which imports 'PageRequest'
> >> from 'pape'.
> >>
> >> Can someone point out what the problem may be.
> >>
> >> --
> >> Thanks & Regards
> >> Parag Shah
> >> http://blog.adaptivesoftware.biz
> >> ___
> >> Tutor maillist  -  Tutor@python.org
> >> To unsubscribe or change subscription options:
> >> http://mail.python.org/mailman/listinfo/tutor
> >>
> >
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] module not found problem

2009-09-22 Thread Parag Shah
Hi Luke,

If I get into the Python prompt, the following line does succeed (so
it seems like __init__.py is being processed):

>>> from openid.extensions import pape

But this one fails because pape is not found... this is very strange:
>>> from openid.extensions.pape import Request as PapeRequest

As you suggested I tried this, but it too fails:
>>> from openid.extensions.pape5 import Request as PapeRequest

However, doing this succeeds:
>>> from openid.extensions.draft.pape5 import Request as PapeRequest


-- 
Thanks & Regards
Parag Shah
http://blog.adaptivesoftware.biz

On 9/22/09, Luke Paireepinart  wrote:
> It looks to me like your __init__.py is transparently
> mapping openid.extensions.pape to openid.extensions.pape5 but when you try
> to do a direct import from openid.extensions.pape it doesn't process the
> __init__.py.  I've never seen something like this but from your example
> that's my first guess.Try doing
> from openid.extensions.pape5 import PageRequest
>
> I would guess the way you're expected to do it is just
> from openid.extensions import pape
>
> and if you don't want to refer to PageRequest as pape.PageRequest
> just do
> PageRequest = pape.PageRequest
>
> That doesn't sound quite right though
>
> On Tue, Sep 22, 2009 at 7:56 PM, Parag Shah  wrote:
>
>> Hi,
>>
>> I am using django-openid-consumer, which has a line in it's views.py
>> which results in an error due to module not found -
>>
>> from openid.extensions.pape import Request as PapeRequest
>>
>> where 'openid.extensions' comes from python-openid-2.2.4 (installed
>> using 'python setup.py install'), which has an 'extensions' directory,
>> but no 'pape' directory. However, 'extensions' has an __init__.py
>> which seems to be importing 'pape', like this:
>>
>> __all__ = ['ax', 'pape', 'sreg']
>> from openid.extensions.draft import pape5 as pape
>>
>>
>> However, the Django app still gives me an error when the line which
>> required pape is executed. I started the Python prompt and tried the
>> following:
>>
>> >>> from openid.extensions import pape
>> >>> from openid.extensions.pape import PageRequest
>> Traceback (most recent call last):
>>  File "", line 1, in 
>> ImportError: No module named pape
>>
>>
>> So Python is able to execute the first import which just imports
>> 'pape', but fails on the second import which imports 'PageRequest'
>> from 'pape'.
>>
>> Can someone point out what the problem may be.
>>
>> --
>> Thanks & Regards
>> Parag Shah
>> http://blog.adaptivesoftware.biz
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] calling a superclass method after overriding it

2009-09-22 Thread Kent Johnson
On Tue, Sep 22, 2009 at 2:20 PM, Serdar Tumgoren  wrote:

> Is my case isolated enough here that I could use the old syntax, but
> leave my remain usages of super in tact? My worry is that I'd have to
> convert all of my subclasses (quite a few at this point) to the
> old-style...

I know that when you need super(), you have to use it everywhere. So I
would stick with what you have.

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


Re: [Tutor] module not found problem

2009-09-22 Thread Kent Johnson
On Tue, Sep 22, 2009 at 1:56 PM, Parag Shah  wrote:
> Hi,
>
> I am using django-openid-consumer, which has a line in it's views.py
> which results in an error due to module not found -
>
> from openid.extensions.pape import Request as PapeRequest
>
> where 'openid.extensions' comes from python-openid-2.2.4 (installed
> using 'python setup.py install'), which has an 'extensions' directory,
> but no 'pape' directory. However, 'extensions' has an __init__.py
> which seems to be importing 'pape', like this:
>
> __all__ = ['ax', 'pape', 'sreg']
> from openid.extensions.draft import pape5 as pape
>
>
> However, the Django app still gives me an error when the line which
> required pape is executed. I started the Python prompt and tried the
> following:
>
 from openid.extensions import pape
 from openid.extensions.pape import PageRequest
> Traceback (most recent call last):
>  File "", line 1, in 
> ImportError: No module named pape

The __init__.py creates the name openid.extensions.pape by importing
from the draft. So there is no openid.extensions.pape module in the
import path. I would try
from openid.extensions import pape
PageRequest = pape.PageRequest

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


Re: [Tutor] calling a superclass method after overriding it

2009-09-22 Thread Serdar Tumgoren
> I prefer the older approach too, it is simple and explicit. super()
> comes with a raft of complications (google "super considered harmful")
> and AFAIK it is only really needed in the case of "diamond"
> inheritance.
>
The explicit method does indeed seem...well...more explicit and easier
to understand. But I thought I'd also read someplace that you
shouldn't combine old and new methods. That you should pick one and
stick with it, because otherwise you could run into MRO problems.

Is my case isolated enough here that I could use the old syntax, but
leave my remain usages of super in tact? My worry is that I'd have to
convert all of my subclasses (quite a few at this point) to the
old-style...
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] calling a superclass method after overriding it

2009-09-22 Thread Kent Johnson
On Tue, Sep 22, 2009 at 1:27 PM, Alan Gauld  wrote:

> I tend to prefer the explicit approach since it is explicit which
> class/method is getting called, but I suspect the preferred mechanism
> nowadays is to use super()

I prefer the older approach too, it is simple and explicit. super()
comes with a raft of complications (google "super considered harmful")
and AFAIK it is only really needed in the case of "diamond"
inheritance.

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


Re: [Tutor] module not found problem

2009-09-22 Thread Luke Paireepinart
It looks to me like your __init__.py is transparently
mapping openid.extensions.pape to openid.extensions.pape5 but when you try
to do a direct import from openid.extensions.pape it doesn't process the
__init__.py.  I've never seen something like this but from your example
that's my first guess.Try doing
from openid.extensions.pape5 import PageRequest

I would guess the way you're expected to do it is just
from openid.extensions import pape

and if you don't want to refer to PageRequest as pape.PageRequest
just do
PageRequest = pape.PageRequest

That doesn't sound quite right though

On Tue, Sep 22, 2009 at 7:56 PM, Parag Shah  wrote:

> Hi,
>
> I am using django-openid-consumer, which has a line in it's views.py
> which results in an error due to module not found -
>
> from openid.extensions.pape import Request as PapeRequest
>
> where 'openid.extensions' comes from python-openid-2.2.4 (installed
> using 'python setup.py install'), which has an 'extensions' directory,
> but no 'pape' directory. However, 'extensions' has an __init__.py
> which seems to be importing 'pape', like this:
>
> __all__ = ['ax', 'pape', 'sreg']
> from openid.extensions.draft import pape5 as pape
>
>
> However, the Django app still gives me an error when the line which
> required pape is executed. I started the Python prompt and tried the
> following:
>
> >>> from openid.extensions import pape
> >>> from openid.extensions.pape import PageRequest
> Traceback (most recent call last):
>  File "", line 1, in 
> ImportError: No module named pape
>
>
> So Python is able to execute the first import which just imports
> 'pape', but fails on the second import which imports 'PageRequest'
> from 'pape'.
>
> Can someone point out what the problem may be.
>
> --
> Thanks & Regards
> Parag Shah
> http://blog.adaptivesoftware.biz
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] module not found problem

2009-09-22 Thread Parag Shah
Hi,

I am using django-openid-consumer, which has a line in it's views.py
which results in an error due to module not found -

from openid.extensions.pape import Request as PapeRequest

where 'openid.extensions' comes from python-openid-2.2.4 (installed
using 'python setup.py install'), which has an 'extensions' directory,
but no 'pape' directory. However, 'extensions' has an __init__.py
which seems to be importing 'pape', like this:

__all__ = ['ax', 'pape', 'sreg']
from openid.extensions.draft import pape5 as pape


However, the Django app still gives me an error when the line which
required pape is executed. I started the Python prompt and tried the
following:

>>> from openid.extensions import pape
>>> from openid.extensions.pape import PageRequest
Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named pape


So Python is able to execute the first import which just imports
'pape', but fails on the second import which imports 'PageRequest'
from 'pape'.

Can someone point out what the problem may be.

-- 
Thanks & Regards
Parag Shah
http://blog.adaptivesoftware.biz
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python win32 drive mapping help

2009-09-22 Thread Alan Gauld


"Dave Angel"  wrote


Traceback (most recent call last):
  File "test.py", line 31, in 
import win32wnet
ImportError: No module named win32net


But I'd point out an essential problem in your message:  your error 
message isn't self-consistent,


What Dave is getting at is that the import uses a different name
for the module than the one in the ImportError line. So if the import
is correct you simply used the wrong module name!

You can do copy/paste from a console window, for example by enabling 
quick-edit mode.  You turn that on by doing right click on the title bar 
and choosing properties.  Once quick-edit is on, you can select any 
rectangle from a console window, and copy it to clipboard with 
right-click.


Or even just hit return after selecting the area to copy...

HTH,

--
Alan Gauld
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] calling a superclass method after overriding it

2009-09-22 Thread Alan Gauld


"Serdar Tumgoren"  wrote


Is there a way to call a superclass method after I've overridden it in
a subclass?


Yes, you can do it as you have iin __init__ using super() 


class Child(Parent):
   def __init__(self):
   super(Child, self).__init__()


Or you can do it explicitly:

Parent.__init__(self)

and:


   def add_name(self):

   except TypeError:
   #default to the superclass's add_name method

  super(Child,self).add_name()
or
  Parent.add_name(self)

I tend to prefer the explicit approach since it is explicit which 
class/method is getting called, but I suspect the preferred 
mechanism nowadays is to use super()



My key point of confusion is in the except clause: I'm not sure of the
syntax for calling the original superclass method 


The except clause is no different to any other bit of code inside 
a method. You use exactly the same mechanisms.


HTH,


--
Alan Gauld
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] calling a superclass method after overriding it

2009-09-22 Thread Serdar Tumgoren
> You're actually already doing it:  look at __init__.
>
> __init__ is overridden in your subclass, so you call super(Child,
> self).__init__() to initialise the class using the parent
> (superclass)'s __init__ method.

Yes indeed. Thanks for pointing it out. In case it helps anyone else
out down the road, below is a bit of test code that appears to work
(of course, please let me know if the way I've done the call has some
unexpected (at least by me) side effects):

def result_of_GENERIC_SQLcall():
name = "This name came from the Parent class"
return name

def result_of_SPECIALIZED_SQLcall_for_child():
name = None
return name

class Parent(object):
def __init__(self):
self.add_name()
print self.name, self.__class__

def add_name(self):
self.name = result_of_GENERIC_SQLcall()

class Child(Parent):
def __init__(self):
super(Child, self).__init__()

def add_name(self):
name = result_of_SPECIALIZED_SQLcall_for_child()
try:
name + ''
self.name = name
except TypeError:
#default to the superclass's add_name method
super(Child, self).add_name()

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


[Tutor] calling a superclass method after overriding it

2009-09-22 Thread Serdar Tumgoren
Hi everyone,
Is there a way to call a superclass method after I've overridden it in
a subclass?

Specifically, what I'm trying to is something like the following:

class Parent(object):
def add_name(self):
self.name = result_of_GENERIC_SQLcall()

class Child(Parent):
def __init__(self):
super(Child, self).__init__()

def add_name(self):
name = result_of_SPECIALIZED_SQLcall_for_child()
try:
name + ''
self.name = name
except TypeError:
#default to the superclass's add_name method
Base.add_name()

My key point of confusion is in the except clause: I'm not sure of the
syntax for calling the original superclass method (or if it's even
possible). Can anyone point me in the right direction?

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


Re: [Tutor] python win32 drive mapping help

2009-09-22 Thread Dave Angel

Vineet Kothari wrote:

Hi Everyone

I saw alot of responses for python on this  mailing list.
I thought any python guru might wish to help me with little code to map two
network drives on windows systems


I have 3computers at different locations in a network A,B,C

I want to map c:/temp folder of A to C & c:/temp folder of B to C as well do
some copying of data and then delete the mapping.

I tried using the code given for mapping:

import win32net
  

win32net.NetUseAdd(None,1,{'remote':r'\\server\share','local':'K:','password':'XXX'
})




but I get this error:

C:\Users\Administrator\Desktop>python test.py
  

Traceback (most recent call last):
  File "test.py", line 31, in 
import win32wnet
ImportError: No module named win32net




I just need help in setting up the mapping. I know how to do the copying
using shutil please if you can help me with the mapping code. I am very new
to python and I need this help for my project at school.

I am using python 2.6

I'll be eagerly waiting for your response.
Thanks

  
As someone else pointed out, you need to make sure you have the win32 
extensions installed.  A quick manual check would be to look in the 
install directory for the win32 files, something like:


python26\lib\site-packages\win32\win32net.pyd

But I'd point out an essential problem in your message:  your error 
message isn't self-consistent, indicating to me that perhaps you retyped 
it in the message.  It's important to use copy/paste to get the program 
samples and error messages precise;  tiny typos can sometimes change the 
diagnosis significantly.


You can do copy/paste from a console window, for example by enabling 
quick-edit mode.  You turn that on by doing right click on the title bar 
and choosing properties.  Once quick-edit is on, you can select any 
rectangle from a console window, and copy it to clipboard with right-click.


DaveA


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


Re: [Tutor] Challenge

2009-09-22 Thread Daniel Sarmiento



Date: Tue, 22 Sep 2009 05:13:32 -0700 (PDT)
From: Ali Sina 
To: tutor@python.org
Subject: [Tutor] Challenge
Message-ID: <826729.63168...@web45911.mail.sp1.yahoo.com>
Content-Type: text/plain; charset="iso-8859-1"

Hello tutor

I downloaded a guide about learning Python by Michael Dawson which has 
challenges at the end of each chapter. I'm a novice so I encountered a problem 
with this challenge:

"Write a program that flips a coin 100 times and then tells
you the number of heads and tails."
I wrote this code but I know its wrong. Although it works properly:

flips=0
h='heads'
t='tails'
while True:
??? flips+=1
??? if flips>100:
??? break
??? if True:
??? print(flips,'=',h or t)

But it prints every number with the string 'heads'. I'm really blank at this. 
It may have something to do with the 'random' module.

Regards



You could use a dictionary to store the outcome and a list with the 
possible outcomes, then use random.choice to pick an outcome.


Here is my try at it:

In [18]: from random import choice

In [19]: pos = ('head', 'tail')

In [20]: outcomes = {'head':0, 'tail':0}

In [21]: for i in range(100):
   : outcomes[choice(pos)] += 1
   :
   :

In [22]: print outcomes
---> print(outcomes)
{'head': 46, 'tail': 54}

HTH

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


Re: [Tutor] Challenge

2009-09-22 Thread Che M


> I wrote this code but I know its wrong. Although it works properly:

> flips=0
> h='heads'
> t='tails'
> while True:
>flips+=1
>if flips>100:
>break
>if True:
>print(flips,'=',h or t)

> But
it prints every number with the string 'heads'. I'm really blank at
this. It may have 
> something to do with the 'random' module.

Keep in mind, you never import the random module in this code,
so the problem could have nothing to do with that module.  When
you use a module in Python, you import it, and there will be a line
at the top like this:

import random

Read up on importing modules; they are very important (pardon the
pun) in Python.  The random module, like most of the modules, has
lots of functions in it for cases where randomization is needed.  You
can read up on it:  http://docs.python.org/library/random.html

I also really like Effbot's guide to the modules; for example, for random:
http://effbot.org/librarybook/random.htm

Che


_
Hotmail: Powerful Free email with security by Microsoft.
http://clk.atdmt.com/GBL/go/171222986/direct/01/___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Challenge

2009-09-22 Thread Alan Gauld

Ali Sina wrote:

I wrote this code but I know its wrong. Although it works properly:


Thereis adfference between "works properly" (ie does what it should) and 
"runs without errors" :-)


You need to read up a bit more on boolean expressions


flips=0
h='heads'
t='tails'
while True:
flips+=1
if flips>100:
break


So far so good, this will loop 100 times.
You could have done the same with a for loop:

for flips in range(100):


if True:


if true is meaningless, it is always true so
the next line will always be executed so you can
just miss it out.



print(flips,'=',h or t)


h or t is a boolean expression which expands out to

'heads' or 'tails'

Since Python considers a non null string to be True
this is equivalent to True or True which is always
True.

In addition Python knows that for an 'or' test if the first value is 
true then the whole expression is true(this iscalle short circuit 
evaluation) and so it only evaluates h as 'heads' to realize the whole 
is true and it returns the first value h (or 'heads')


But it prints every number with the string 'heads'. I'm really blank at 
this. It may have something to do with the 'random' module.


The reason it prints heads is that you have basically written the 
following code:


for flips in range(100):
print 'heads'

What you are not doing is replicating the flip of the coin
(thats where random comes in) and you are not testing
the result of that flip to determine whether to print
heads/tails.

You will find more examples of boolean expressions in
the Functional Programming topic of my tutor under
the heading "Other Constructs" about  60% of the way
down the page.

HTH,

Alan G.
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] Challenge

2009-09-22 Thread Eric Walker
Ali,
I am new at this but here is my interpretation.
1) flip coin 100 times, and print out the number of heads and number of tails.

from random import Random
score = [0,0]# first position will be heads and second position will be tails
count=0#counter to find out how many times we have flipped.
a = Random()#creates random object
while count < 100:
  answer = a.choice((1,2))
  if answer == 1:
   score[0]+=answer
  else:
   score[1]+=1
  count +=1

print("Heads:%s\nTails:%s" % (score[0], score[1]))



>
>From: Ali Sina 
>To: tutor@python.org
>Sent: Tuesday, September 22, 2009 5:13:32 AM
>Subject: [Tutor] Challenge
>
>
>Hello tutor
>
>I downloaded a guide about learning Python by Michael Dawson which has 
>challenges at the end of each chapter. I'm a novice so I encountered a problem 
>with this challenge:
>
>
>"Write a program that flips a coin 100 times and then tells 
>you the number of heads and tails."
>I wrote this code but I know its wrong. Although it works properly:
>
>flips=0
>h='heads'
>t='tails'
>while True:
>flips+=1
>if flips>100:
>break
>if True:
>print(flips,'=',h or t)
>
>But it prints every number with the string 'heads'. I'm really blank at this. 
>It may have something to do with the 'random' module.
>
>Regards
>
> 
>


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


Re: [Tutor] Challenge

2009-09-22 Thread Lucas Prado Melo
On Tue, Sep 22, 2009 at 9:13 AM, Ali Sina  wrote:

>  But it prints every number with the string 'heads'. I'm really blank at
> this. It may have something to do with the 'random' module.
>
> You could use the choice function on random.
Given a list, the choice function returns a random element of that list.

from random import choice

print choice([1,2,3,4])
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Challenge

2009-09-22 Thread Ali Sina
Hello tutor

I downloaded a guide about learning Python by Michael Dawson which has 
challenges at the end of each chapter. I'm a novice so I encountered a problem 
with this challenge:

"Write a program that flips a coin 100 times and then tells 
you the number of heads and tails."
I wrote this code but I know its wrong. Although it works properly:

flips=0
h='heads'
t='tails'
while True:
    flips+=1
    if flips>100:
    break
    if True:
    print(flips,'=',h or t)

But it prints every number with the string 'heads'. I'm really blank at this. 
It may have something to do with the 'random' module.

Regards




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


Re: [Tutor] python win32 drive mapping help

2009-09-22 Thread vishwajeet singh
On Tue, Sep 22, 2009 at 5:38 AM, Vineet Kothari wrote:

>
> Hi Everyone
>
> I saw alot of responses for python on this  mailing
> list. I thought any python guru might wish to help me with little code to
> map two network drives on windows systems
>
>
> I have 3computers at different locations in a network A,B,C
>
> I want to map c:/temp folder of A to C & c:/temp folder of B to C as well
> do some copying of data and then delete the mapping.
>
> I tried using the code given for mapping:
>
> import win32net
>> win32net.NetUseAdd(None,1,{'remote':r'\\server\share','local':'K:','password':'XXX'
>> })
>>
>
> but I get this error:
>
> C:\Users\Administrator\Desktop>python test.py
>> Traceback (most recent call last):
>>   File "test.py", line 31, in 
>> import win32wnet
>> ImportError: No module named win32net
>>
>
> I just need help in setting up the mapping. I know how to do the copying
> using shutil please if you can help me with the mapping code. I am very new
> to python and I need this help for my project at school.
>
> I am using python 2.6
>
> I'll be eagerly waiting for your response.
> Thanks
>
> --
> Regards,
> Vineet Kothari
> http://www.vineetkothari.in
>
> -
> Its NICE 2 be IMPORTANT, but whats more IMPORTANT is 2 be NICE.
>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
You need python extension installed on your machine to be able to execute
the above code; you can get same from
http://sourceforge.net/projects/pywin32/

-- 
Vishwajeet Singh
+91-9657702154 | dextrou...@gmail.com | http://singhvishwajeet.com
Twitter: http://twitter.com/vishwajeets | LinkedIn:
http://www.linkedin.com/in/singhvishwajeet
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] python win32 drive mapping help

2009-09-22 Thread Vineet Kothari
Hi Everyone

I saw alot of responses for python on this  mailing list.
I thought any python guru might wish to help me with little code to map two
network drives on windows systems


I have 3computers at different locations in a network A,B,C

I want to map c:/temp folder of A to C & c:/temp folder of B to C as well do
some copying of data and then delete the mapping.

I tried using the code given for mapping:

import win32net
> win32net.NetUseAdd(None,1,{'remote':r'\\server\share','local':'K:','password':'XXX'
> })
>

but I get this error:

C:\Users\Administrator\Desktop>python test.py
> Traceback (most recent call last):
>   File "test.py", line 31, in 
> import win32wnet
> ImportError: No module named win32net
>

I just need help in setting up the mapping. I know how to do the copying
using shutil please if you can help me with the mapping code. I am very new
to python and I need this help for my project at school.

I am using python 2.6

I'll be eagerly waiting for your response.
Thanks

-- 
Regards,
Vineet Kothari
http://www.vineetkothari.in

-
Its NICE 2 be IMPORTANT, but whats more IMPORTANT is 2 be NICE.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to get homework help (was need to hire a tutor... )

2009-09-22 Thread Alan Gauld


I'm new on this list <*waves hello to everyone*>, 


welcome to the tutor list  <*waves back*> :-)


trick to getting help here with homework is pretty much the same as most
other tech lists.


Absolutely so, and well summarised.

Alan G.
http://www.alan-g.me.uk/

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