Re: [Tutor] classes : post-declaration attributes

2013-02-09 Thread Alan Gauld

On 09/02/13 07:01, neubyr wrote:


I am learning Python 2.7 classes and objects. It seems like attributes
(data attributes and methods) can be added to a class/object  even after
it's first declaration. For example,


You can do that, but mostly you shouldn't.

Usually when classes/objects are used like that its where the object is 
just being used as a data container rather than a true object (with 
behaviour and supporting data). Often a straight dictionary is a better 
option.


Python allows us lots of freedom in how we use it with many unusual 
features. Not all of those things are advisable to use in day to day 
programming. But very occasionally you find a case where they help.

In general, beginners should avoid them.

--
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] Which pip for Ubuntu 12.04

2013-02-09 Thread Albert-Jan Roskam
- Original Message -

> From: Jim Byrnes 
> To: tutor@python.org
> Cc: 
> Sent: Saturday, February 9, 2013 3:02 AM
> Subject: [Tutor] Which pip for Ubuntu 12.04
> 
> How important is it to have the latest pip installed?
> 
> Initially I want to use it to install the latest pymongo driver for mongoDB.  
> The pip version in the Ubuntu 12.04 repositories is 1.0.1. I see on 
> http://www.pip-installer.org/en/latest/ the version is 1.2.1.
> 
> It certainly would be easier to install from the repositories but will that 
> version work to install the latest python packages?
> 
> Thanks,  Jim

You could just try it? And downloading it and then doing sudo tar -xvr 
pip.tar.gz, cd ..., sudo python setup.py isn't that hard, is it?

But you're right, I also nnoticed that the Canonical repositories are a little 
outdated sometimes. Would be nice if it's possible to add pypi.org, so updating 
would be easier.

Albert-Jan

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


Re: [Tutor] Which pip for Ubuntu 12.04

2013-02-09 Thread Albert-Jan Roskam
> How important is it to have the latest pip installed?

> 
> Initially I want to use it to install the latest pymongo driver for mongoDB.  
> The pip version in the Ubuntu 12.04 repositories is 1.0.1. I see on 
> http://www.pip-installer.org/en/latest/ the version is 1.2.1.
> 
> It certainly would be easier to install from the repositories but will that 
> version work to install the latest python packages?
> 
> Thanks,  Jim

(sorry, tar -xvf  me and my big fingers ;-))

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


[Tutor] python help!

2013-02-09 Thread Ghadir Ghasemi
Hi guys can you tell me what is wrong with the second part of this code(elif 
choice == '2'). When I type something other than 0-255, it correctly asks again 
for an input but when I enter a number from 0-255 it does nothing :

def show_menu():
 print("===")
 print("1-binary to denary")
 print("2-denary to binary")
 print("3-exit")
 print("===")


while True:
show_menu()

choice = input("please enter an option: ")

if choice == '1':
binary = input("Please enter a binary number: ")
denary = 0
place_value = 1

for i in binary [::-1]:
denary += place_value * int(i)
place_value *= 2

print("The result is",denary)
   

elif choice == '2':
 denary2 = int(input("Please enter a denary number: "))
 remainder = ''
 while denary2 not in range(0,256):
 denary2 = int(input("Please enter a denary number: "))
 continue
 while denary2 in range(0,256):
 
remainder = str(denary2 % 2) + remainder
denary2 >>= 1
 print("The result is",remainder)

   
 

elif choice == '3':
 break


elif choice not in '1' or '2' or '3':
print("Invalid input-try again!")
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python help!

2013-02-09 Thread Peter Otten
Ghadir Ghasemi wrote:

> Hi guys can you tell me what is wrong with the second part of this
> code(elif choice == '2'). When I type something other than 0-255, it
> correctly asks again for an input but when I enter a number from 0-255 it
> does nothing :

It doesn't do nothing, it keeps running the while loop. Add a print() call

> elif choice == '2':
>  denary2 = int(input("Please enter a denary number: "))
>  remainder = ''
>  while denary2 not in range(0,256):
>  denary2 = int(input("Please enter a denary number: "))
>  continue
>  while denary2 in range(0,256):

  print("XXX denary2 =",  denary2)
  
> remainder = str(denary2 % 2) + remainder
> denary2 >>= 1
>  print("The result is",remainder)

to see what's happening.


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


Re: [Tutor] classes : post-declaration attributes

2013-02-09 Thread neubyr
On Sat, Feb 9, 2013 at 3:24 AM, Alan Gauld wrote:

> On 09/02/13 07:01, neubyr wrote:
>
>>
>> I am learning Python 2.7 classes and objects. It seems like attributes
>> (data attributes and methods) can be added to a class/object  even after
>> it's first declaration. For example,
>>
>
> You can do that, but mostly you shouldn't.
>
> Usually when classes/objects are used like that its where the object is
> just being used as a data container rather than a true object (with
> behaviour and supporting data). Often a straight dictionary is a better
> option.
>
> Python allows us lots of freedom in how we use it with many unusual
> features. Not all of those things are advisable to use in day to day
> programming. But very occasionally you find a case where they help.
> In general, beginners should avoid them.
>
>
>

Thanks for the reply Alan, Steven and Mitya. That's helpful.

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


[Tutor] Code to open a website

2013-02-09 Thread mann kann
Dear Jedi,

I wrote my first program but it doesn't open a website as I intended it to.
Please correct my mistake.

Sincerely,
Mann



def a():
import urllib.request
url = "http://www.google.com";
response = urllib.request.urlopen(url)

g = input("Please enter y or n to go to youtube : ")
if g == "y":
print("Opening the website")
a()
else:
print("kein website")
exit()
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Code to open a website

2013-02-09 Thread Wayne Werner

On Sat, 9 Feb 2013, mann kann wrote:


Dear Jedi, 
I wrote my first program but it doesn't open a website as I intended it to.
Please correct my mistake. 

Sincerely, 
Mann


You'll actually want the webbrowser module, which will open the links in 
your web browser - at least if you want to load sites like YouTube.


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


Re: [Tutor] Code to open a website

2013-02-09 Thread mann kann
I used webbrowser and it worked via terminal, but the same code returns
AttrituteError: 'module' object has no attribute 'open' in komodo edit.
suggestions? here's the code:

import webbrowser
webbrowser.open("http://youtube.com";)



On Sat, Feb 9, 2013 at 8:17 PM, Wayne Werner  wrote:

> On Sat, 9 Feb 2013, mann kann wrote:
>
>  Dear Jedi,
>> I wrote my first program but it doesn't open a website as I intended it
>> to.
>> Please correct my mistake.
>>
>> Sincerely,
>> Mann
>>
>
> You'll actually want the webbrowser module, which will open the links in
> your web browser - at least if you want to load sites like YouTube.
>
> HTH,
> Wayne
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Code to open a website

2013-02-09 Thread Alan Gauld

On 10/02/13 01:00, mann kann wrote:

Dear Jedi,

I wrote my first program but it doesn't open a website as I intended it
to. Please correct my mistake.


Well, how did you intend it to?
It looks like it probably does open the web site, but it will be hard to 
tell since you do nothing with the result.




def a():


Please use meaningful names.
openURL() or similar would be a useful choice here.



 import urllib.request
 url = "http://www.google.com";
 response = urllib.request.urlopen(url)


Here you open the url and store the response. But then the function ends 
and it gets thrown away and the site is closed again.




g = input("Please enter y or n to go to youtube : ")


You aren't going to YouTube yet, only Google but I assume YouTube is the 
intended eventual target?


Again g is not a very meaningful name. 'choice' or similar
would be more helpful.


if g == "y":
 print("Opening the website")
 a()


Here you call you function but again all the action inside is just lost.



else:
 print("kein website")
 exit()


Where does exit() come from? Usually its from sys but you
don't import from sys anywhere...

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


Re: [Tutor] python help!

2013-02-09 Thread D . V . N . Sarma డి . వి . ఎన్ . శర్మ
I have altered the program to run on Python 2.7.3
Perhaps it will run on Python 3 with small/or no alterations.

def show_menu():
 print("===")
 print("1-binary to denary")
 print("2-denary to binary")
 print("3-exit")
 print("===")


while True:
show_menu()

choice = raw_input("please enter an option: ")

if choice == '1':
binary = raw_input("Please enter a binary number: ")
denary = 0
place_value = 1

for i in binary [::-1]:
denary += place_value * int(i)
place_value *= 2

print("The result is",denary)


elif choice == '2':
 denary2 = int(raw_input("Please enter a denary number: "))
 remainder = ''
 if denary2 not in range(0,256):
 denary2 = int(input("Please enter a denary number: "))
 continue
 while denary2 > 0:
remainder = str(denary2 % 2) + remainder
denary2 /= 2
 print("The result is",remainder)




elif choice == '3': break


elif choice == '1' or choice == '2' or choice == '3':
print("Invalid input-try again!")



On Sun, Feb 10, 2013 at 12:50 AM, Peter Otten <__pete...@web.de> wrote:

> Ghadir Ghasemi wrote:
>
> > Hi guys can you tell me what is wrong with the second part of this
> > code(elif choice == '2'). When I type something other than 0-255, it
> > correctly asks again for an input but when I enter a number from 0-255 it
> > does nothing :
>
> It doesn't do nothing, it keeps running the while loop. Add a print() call
>
> > elif choice == '2':
> >  denary2 = int(input("Please enter a denary number: "))
> >  remainder = ''
> >  while denary2 not in range(0,256):
> >  denary2 = int(input("Please enter a denary number: "))
> >  continue
> >  while denary2 in range(0,256):
>
>   print("XXX denary2 =",  denary2)
>
> > remainder = str(denary2 % 2) + remainder
> > denary2 >>= 1
> >  print("The result is",remainder)
>
> to see what's happening.
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>



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


Re: [Tutor] python help!

2013-02-09 Thread D . V . N . Sarma డి . వి . ఎన్ . శర్మ
Remove also 'continue' statement under the 'if denary2 not in
range(0,256)' clause.


On Sun, Feb 10, 2013 at 7:06 AM, D.V.N.Sarma డి.వి.ఎన్.శర్మ <
dvnsa...@gmail.com> wrote:

> I have altered the program to run on Python 2.7.3
> Perhaps it will run on Python 3 with small/or no alterations.
>
> def show_menu():
>  print("===")
>  print("1-binary to denary")
>  print("2-denary to binary")
>  print("3-exit")
>  print("===")
>
>
> while True:
> show_menu()
>
> choice = raw_input("please enter an option: ")
>
> if choice == '1':
> binary = raw_input("Please enter a binary number: ")
> denary = 0
> place_value = 1
>
> for i in binary [::-1]:
> denary += place_value * int(i)
> place_value *= 2
>
> print("The result is",denary)
>
>
> elif choice == '2':
>  denary2 = int(raw_input("Please enter a denary number: "))
>  remainder = ''
>  if denary2 not in range(0,256):
>  denary2 = int(input("Please enter a denary number: "))
>  continue
>  while denary2 > 0:
> remainder = str(denary2 % 2) + remainder
> denary2 /= 2
>  print("The result is",remainder)
>
>
>
>
> elif choice == '3': break
>
>
> elif choice == '1' or choice == '2' or choice == '3':
> print("Invalid input-try again!")
>
>
>
> On Sun, Feb 10, 2013 at 12:50 AM, Peter Otten <__pete...@web.de> wrote:
>
>> Ghadir Ghasemi wrote:
>>
>> > Hi guys can you tell me what is wrong with the second part of this
>> > code(elif choice == '2'). When I type something other than 0-255, it
>> > correctly asks again for an input but when I enter a number from 0-255
>> it
>> > does nothing :
>>
>> It doesn't do nothing, it keeps running the while loop. Add a print() call
>>
>> > elif choice == '2':
>> >  denary2 = int(input("Please enter a denary number: "))
>> >  remainder = ''
>> >  while denary2 not in range(0,256):
>> >  denary2 = int(input("Please enter a denary number: "))
>> >  continue
>> >  while denary2 in range(0,256):
>>
>>   print("XXX denary2 =",  denary2)
>>
>> > remainder = str(denary2 % 2) + remainder
>> > denary2 >>= 1
>> >  print("The result is",remainder)
>>
>> to see what's happening.
>>
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>
>
>
> --
> regards,
> Sarma.
>



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


Re: [Tutor] Code to open a website

2013-02-09 Thread eryksun
On Sat, Feb 9, 2013 at 8:33 PM, Alan Gauld  wrote:
>
> Where does exit() come from? Usually its from sys but you
> don't import from sys anywhere...

site.py adds the exit/quit Quitter instances to builtins (2.x
__builtin__). When called they raise SystemExit, like sys.exit does.
Since you can bypass importing site.py with the -S flag, it's better
to use sys.exit.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Code to open a website

2013-02-09 Thread Danny Yoo
On Sat, Feb 9, 2013 at 6:25 PM, mann kann  wrote:
> I used webbrowser and it worked via terminal, but the same code returns
> AttrituteError: 'module' object has no attribute 'open' in komodo edit.
> suggestions? here's the code:
>
> import webbrowser
> webbrowser.open("http://youtube.com";)


What's the file name of your program, just out of curiosity?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Code to open a website

2013-02-09 Thread mann kann
oh wow, I foolishly named it webbrowser.py earlier.
Thanks for the witty hint, Danny :)


On Sat, Feb 9, 2013 at 11:55 PM, Danny Yoo  wrote:

> On Sat, Feb 9, 2013 at 6:25 PM, mann kann  wrote:
> > I used webbrowser and it worked via terminal, but the same code returns
> > AttrituteError: 'module' object has no attribute 'open' in komodo edit.
> > suggestions? here's the code:
> >
> > import webbrowser
> > webbrowser.open("http://youtube.com";)
>
>
> What's the file name of your program, just out of curiosity?
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor