Re: [Tutor] Simple Question On A Method (in subclass)

2011-10-24 Thread Marc Tompkins
On Mon, Oct 24, 2011 at 3:44 PM, bob gailer wrote: > On 10/24/2011 7:45 AM, Wayne Werner wrote: > > On Sun, Oct 23, 2011 at 11:06 PM, Marc Tompkins > wrote: > >> Things to remember: >> -you can get a value from a method, but you can't assign to it: >> variable = object.method() >> but NOT

Re: [Tutor] Simple Question On A Method (in subclass)

2011-10-24 Thread Marc Tompkins
On Mon, Oct 24, 2011 at 9:20 PM, Chris Kavanagh wrote: > Makes perfect sense now. . .Thanks again Marc (and Alan, Dave) > BTW, do you guys luv Python the way I do!?? I just luv the way everything > works together so explicitly. I LUV learning this stuff!! > Oh yeah, baby. Python makes programmi

Re: [Tutor] Simple Question On A Method (in subclass)

2011-10-24 Thread Chris Kavanagh
On 10/24/2011 12:06 AM, Marc Tompkins wrote: On Sun, Oct 23, 2011 at 8:08 PM, Chris Kavanagh mailto:cka...@msn.com>> wrote: So we have {member.tell} as the last line of code. So trying to understand this piece of code, {member} the variable is considered an object? Therefore we can

Re: [Tutor] Quacks like an object

2011-10-24 Thread Alan Gauld
On 25/10/11 00:02, Christopher King wrote: Dear Tutors, I am trying to make an object, which will appear exactly like an object of my choice. It will should be impossible to tell it is not the object. We can get pretty close but I suspect its impossible to make it 100% reliable - otherwis

Re: [Tutor] string immutability

2011-10-24 Thread Alan Gauld
On 24/10/11 20:52, Johan Martinez wrote: Also, is there any doc link where I can find all the information about String object - class and instance methods. >>> help(str) or even >>> help("") For a quick list try dir() >>> dir ("") Finally I figured it out ( __length__() ) thanks to ipy

Re: [Tutor] How to print corresponding keys in Dictionary

2011-10-24 Thread Alan Gauld
On 24/10/11 19:00, Alan Gauld wrote: For fun: def getKeys(aDict, aValue): return [key for key,val in aDict if val == aValue] Oops, that should have been return [key for key,val in aDict.items() if val == aValue] -- Alan G Author of the Learn to Program web site http://www.alan-g.me

[Tutor] Quacks like an object

2011-10-24 Thread Christopher King
Dear Tutors, I am trying to make an object, which will appear exactly like an object of my choice. It will should be impossible to tell it is not the object. This is because I am making an object that modifies it methods so that if the methods make a change to the object, it will sync those cha

Re: [Tutor] How to print corresponding keys in Dictionary

2011-10-24 Thread bob gailer
Another approach is to subclass dict such that each time you add a key:value pair you also create an entry in a reverse dictionary. Then all you need do is lookup in the reverse dictionary. If there are several keys with the same value, then create and extend a list of values in the reverse di

Re: [Tutor] Simple Question On A Method (in subclass)

2011-10-24 Thread bob gailer
On 10/24/2011 7:45 AM, Wayne Werner wrote: On Sun, Oct 23, 2011 at 11:06 PM, Marc Tompkins mailto:marc.tompk...@gmail.com>> wrote: Things to remember: -you can get a value from a method, but you can't assign to it: variable = object.method() but NOT object.method() =

Re: [Tutor] regex and parsing through a semi-csv file

2011-10-24 Thread Mina Nozar
Hi Marc, Thank you. Following some of your suggestion, the rewrite below worked. I agree with your point on readability over complexity. By grace I meant not convoluted or simpler. That's all. As a beginner, I find not knowing all the existing functions, I end up re-inventing the wheel som

Re: [Tutor] reg current work in pycrypto

2011-10-24 Thread Steven D'Aprano
nivedita datta wrote: Hi all, Can anyone tell me about some projects or applications which has been built using pycrypto. Also I would like to know about any ongoing/past project or application development in pycrypto. This is a mailing list for beginners learning the basics of Python program

Re: [Tutor] string immutability

2011-10-24 Thread Joel Goldstick
the len() function works on lots of objects: >>> a = "this is a string" >>> len(a) 16 On Mon, Oct 24, 2011 at 3:52 PM, Johan Martinez wrote: > > > On Mon, Oct 24, 2011 at 2:32 PM, Steve Willoughby wrote: > >> On 24-Oct-11 12:17, Johan Martinez wrote: >> >>> Thanks for the replies everyone - St

Re: [Tutor] string immutability

2011-10-24 Thread Johan Martinez
On Mon, Oct 24, 2011 at 2:32 PM, Steve Willoughby wrote: > On 24-Oct-11 12:17, Johan Martinez wrote: > >> Thanks for the replies everyone - Steve, Dave, Sander and Wayne. I >> realized my wrong understanding/interpretation after posting the message >> to the list, which usually happens most of t

Re: [Tutor] string immutability

2011-10-24 Thread Dave Angel
On 10/24/2011 03:21 PM, Johan Martinez wrote: On Mon, Oct 24, 2011 at 2:07 PM, Andreas Perstinger< andreas.perstin...@gmx.net> wrote: On 2011-10-24 20:04, Johan Martinez wrote: Hi, I am struggling to understand Python string immutability. I am able to modify Python string object after initi

Re: [Tutor] string immutability

2011-10-24 Thread Steve Willoughby
On 24-Oct-11 12:17, Johan Martinez wrote: Thanks for the replies everyone - Steve, Dave, Sander and Wayne. I realized my wrong understanding/interpretation after posting the message to the list, which usually happens most of the time with me! That happens to most of us all the time too :) Unf

Re: [Tutor] string immutability

2011-10-24 Thread Dipo Elegbede
What you did here is just re-assigning s. Try slicing s and then assign a new value to the slice. s[2] would return 'r' now try to to set s[2] to another value to understand immutability. Hope it helps. On 24 Oct 2011 19:06, "Johan Martinez" wrote: > Hi, > > I am struggling to understand Python

Re: [Tutor] string immutability

2011-10-24 Thread Johan Martinez
On Mon, Oct 24, 2011 at 2:07 PM, Andreas Perstinger < andreas.perstin...@gmx.net> wrote: > On 2011-10-24 20:04, Johan Martinez wrote: > >> Hi, >> >> I am struggling to understand Python string immutability. I am able to >> modify Python string object after initializing/assigning it a value. >> >>

Re: [Tutor] string immutability

2011-10-24 Thread Johan Martinez
On Mon, Oct 24, 2011 at 1:52 PM, Wayne Werner wrote: > On Mon, Oct 24, 2011 at 1:04 PM, Johan Martinez wrote: > >> Hi, >> >> I am struggling to understand Python string immutability. I am able to >> modify Python string object after initializing/assigning it a value. So how >> does immutability wo

Re: [Tutor] string immutability

2011-10-24 Thread Andreas Perstinger
On 2011-10-24 20:04, Johan Martinez wrote: Hi, I am struggling to understand Python string immutability. I am able to modify Python string object after initializing/assigning it a value. s = "First" print s.__class__ print s First s = "Second" print s Second Dave, Sander and Wayne

Re: [Tutor] string immutability

2011-10-24 Thread Steve Willoughby
On Mon, Oct 24, 2011 at 01:04:20PM -0500, Johan Martinez wrote: > Hi, > > I am struggling to understand Python string immutability. I am able to > modify Python string object after initializing/assigning it a value. So how > does immutability work? I am not following it. Sorry for really stupid >

Re: [Tutor] string immutability

2011-10-24 Thread Wayne Werner
On Mon, Oct 24, 2011 at 1:04 PM, Johan Martinez wrote: > Hi, > > I am struggling to understand Python string immutability. I am able to > modify Python string object after initializing/assigning it a value. So how > does immutability work? I am not following it. Sorry for really stupid > question

Re: [Tutor] string immutability

2011-10-24 Thread Sander Sweers
On Mon, 24 Oct 2011, 20:04:20 CEST, Johan Martinez wrote: > I am struggling to understand Python string immutability. I am able to > modify Python string object after initializing/assigning it a value. So > how does immutability work? I am not following it. Sorry for really > stupid question. Any

Re: [Tutor] string immutability

2011-10-24 Thread Dave Angel
On 10/24/2011 02:04 PM, Johan Martinez wrote: Hi, I am struggling to understand Python string immutability. I am able to modify Python string object after initializing/assigning it a value. So how does immutability work? I am not following it. Sorry for really stupid question. Any help? You're c

Re: [Tutor] How to print corresponding keys in Dictionary

2011-10-24 Thread Alan Gauld
On 24/10/11 14:18, Dave Angel wrote: def getkey(dictionary, value): for key, val in dictionary.items(): if val == value: return key Note that if there are multiple keys with the same value, my function would get only the first. It wouldn't be hard to modify the function to re

[Tutor] string immutability

2011-10-24 Thread Johan Martinez
Hi, I am struggling to understand Python string immutability. I am able to modify Python string object after initializing/assigning it a value. So how does immutability work? I am not following it. Sorry for really stupid question. Any help? >>> s = "First" >>> print s.__class__ >>> print s Fi

Re: [Tutor] Simple Question On A Method (in subclass)

2011-10-24 Thread Alan Gauld
On 24/10/11 11:17, lina wrote: a quick Q: Every time call the method, need go through the __initi__( ) part? No. __init__() is only called when an instance is first created. Here is an example in the IDLE: >>> class C: def __init__(self): print("I'm in init")

Re: [Tutor] How to print corresponding keys in Dictionary

2011-10-24 Thread Dave Angel
(You forgot to include the list on your reply. Easiest way is to do a reply-all when you're replying) On 10/24/2011 12:21 PM, Praveen Singh wrote: On Mon, Oct 24, 2011 at 9:18 AM, Dave Angel wrote: def getkey(dictionary, value): for key, val in dictionary.items(): if va

Re: [Tutor] How to print corresponding keys in Dictionary

2011-10-24 Thread Dave Angel
On 10/24/2011 09:10 AM, Praveen Singh wrote: In Dictionary- How to print corresponding keys if the values of dictionary is given?? -d={'a':1,'b':2,'c':3} -i can print the corresponding values by using get() method- - d.get('a') -1 What if i have to print reverse??? A dictionary can be viewed

Re: [Tutor] How to print corresponding keys in Dictionary

2011-10-24 Thread Raúl Cumplido
Hi, Keys are unique in a dictionaire but values aren't. What do you want to print if you have the next dictionaire: dict = {'a' : 1, 'b' : 1} If you are using python 2.7 you can use dictionary comprehensions to swap keys for values: >>> d={'a':1,'b':2,'c':3} >>> new_dict = {v : k for k,v in d.i

[Tutor] How to print corresponding keys in Dictionary

2011-10-24 Thread Praveen Singh
In Dictionary- How to print corresponding keys if the values of dictionary is given?? -d={'a':1,'b':2,'c':3} -i can print the corresponding values by using get() method- - d.get('a') -1 What if i have to print reverse??? ___ Tutor maillist - Tutor@pyt

Re: [Tutor] Simple Question On A Method (in subclass)

2011-10-24 Thread Wayne Werner
On Sun, Oct 23, 2011 at 11:06 PM, Marc Tompkins wrote: > Things to remember: > -you can get a value from a method, but you can't assign to it: > variable = object.method() > but NOT > object.method() = variable > As a slight aside, you _can_ assign to the method name: object.method = var

Re: [Tutor] Simple Question On A Method (in subclass)

2011-10-24 Thread Chris Kavanagh
On 10/24/2011 4:40 AM, Alan Gauld wrote: On 24/10/11 04:08, Chris Kavanagh wrote: Thanks so much for the help Alan. . .I'm not trying to beat this question into the ground, LOL, but let me see if I can ask it a better way. Marc has already given a good answer, but I'll try a slightly differ

Re: [Tutor] Simple Question On A Method (in subclass)

2011-10-24 Thread lina
a quick Q: Every time call the method, need go through the __initi__( ) part? Thanks, I attached the one I used to practice fast-typing: #!/usr/bin/python3 class SchoolMember: '''Represents any school members.''' def __init__(self,name,age): self.name = name self.age

Re: [Tutor] Simple Question On A Method (in subclass)

2011-10-24 Thread Alan Gauld
On 24/10/11 04:08, Chris Kavanagh wrote: Thanks so much for the help Alan. . .I'm not trying to beat this question into the ground, LOL, but let me see if I can ask it a better way. Marc has already given a good answer, but I'll try a slightly different approach to the same thing The diff

Re: [Tutor] how to unique the string

2011-10-24 Thread lina
On Mon, Oct 24, 2011 at 3:24 PM, Peter Otten <__pete...@web.de> wrote: > lina wrote: > >> But I am getting confused later: >> >> def translate_process(dictionary,tobetranslatedfile): >>     results=[] >>     unique={} >>     for line in open(tobetranslatedfile,"r"): >>         tobetranslatedparts=l

Re: [Tutor] how to unique the string

2011-10-24 Thread lina
>> >> def translate_process(dictionary,tobetranslatedfile): >>     results=[] >>     unique={} >>     for line in open(tobetranslatedfile,"r"): >>         tobetranslatedparts=line.strip().split() >>         results.append(dictionary[tobetranslatedparts[2]]) >>         unique=Counter(results) >>  

Re: [Tutor] how to unique the string

2011-10-24 Thread lina
On Mon, Oct 24, 2011 at 3:24 PM, Peter Otten <__pete...@web.de> wrote: > lina wrote: > >> But I am getting confused later: >> >> def translate_process(dictionary,tobetranslatedfile): >>     results=[] >>     unique={} >>     for line in open(tobetranslatedfile,"r"): >>         tobetranslatedparts=l

Re: [Tutor] how to unique the string

2011-10-24 Thread Peter Otten
lina wrote: > But I am getting confused later: > > def translate_process(dictionary,tobetranslatedfile): > results=[] > unique={} > for line in open(tobetranslatedfile,"r"): > tobetranslatedparts=line.strip().split() > results.append(dictionary[tobetranslatedparts[2]])