Re: [Tutor] change values in an array

2011-11-17 Thread Peter Otten
questions anon wrote: > I am trying to do something really simple. > I have a numpy array and if any values in the array are 255 I want to > change them to 1. > but I can't seem to get anything to work! Note that numpy is a specialist topic, and for everything but the basics the numpy mailing li

[Tutor] how to understand unhashable type: 'list'

2011-11-17 Thread lina
list1 [['61', '34', '61', '34'], ['61', '35', '61', '70', '61'], ['61', '70', '61', '34'], ['34', '58', '34', '58']] >>> weight={} >>> weight{list1[0]}=1 SyntaxError: invalid syntax >>> weight[list1[0]]=1 Traceback (most recent call last): File "", line 1, in weight[list1[0]]=1 TypeError: u

Re: [Tutor] how to understand unhashable type: 'list'

2011-11-17 Thread Christian Witts
On 2011/11/17 11:59 AM, lina wrote: list1 [['61', '34', '61', '34'], ['61', '35', '61', '70', '61'], ['61', '70', '61', '34'], ['34', '58', '34', '58']] weight={} weight{list1[0]}=1 SyntaxError: invalid syntax weight[list1[0]]=1 Traceback (most recent call last): File "", line 1, in w

Re: [Tutor] how to understand unhashable type: 'list'

2011-11-17 Thread lina
On Thu, Nov 17, 2011 at 6:09 PM, Christian Witts wrote: > On 2011/11/17 11:59 AM, lina wrote: > > list1 > [['61', '34', '61', '34'], ['61', '35', '61', '70', '61'], ['61', > '70', '61', '34'], ['34', '58', '34', '58']] > > weight={} > weight{list1[0]}=1 > > SyntaxError: invalid syntax > > weight[l

Re: [Tutor] how to understand unhashable type: 'list'

2011-11-17 Thread Christian Witts
On 2011/11/17 12:26 PM, lina wrote: On Thu, Nov 17, 2011 at 6:09 PM, Christian Witts wrote: On 2011/11/17 11:59 AM, lina wrote: list1 [['61', '34', '61', '34'], ['61', '35', '61', '70', '61'], ['61', '70', '61', '34'], ['34', '58', '34', '58']] weight={} weight{list1[0]}=1 SyntaxError: inval

[Tutor] ProgressBar - Python and Powershell

2011-11-17 Thread Nikunj.Badjatya
Hi All, I am using Python 2.7, windows Env. I have an Installer written in Python(45%) and Powershell(55%) which is used to install Virtual Machines at specific locations. It is single threaded. I am trying to implement a ProgressBar for this installer. So that the user will come to know the p

Re: [Tutor] how to understand unhashable type: 'list'

2011-11-17 Thread Steven D'Aprano
lina wrote: list1 [['61', '34', '61', '34'], ['61', '35', '61', '70', '61'], ['61', '70', '61', '34'], ['34', '58', '34', '58']] You have a list of lists. weight={} weight{list1[0]}=1 SyntaxError: invalid syntax In Python, {} are used for dicts, and in Python 3, sets. They aren't used fo

[Tutor] (no subject)

2011-11-17 Thread Nidian Job-Smith
Hi all, I'm new to programming (thus Python), so after reading the basics, I wanted to practise what I've learnt . I've come across a beginners exercise which is to programme rot13. I've written some code but it doesn't seem to work Here it is: def rot13(s):char_low = ()result = ""

Re: [Tutor] (no subject)

2011-11-17 Thread Andre Engels
On Thu, Nov 17, 2011 at 2:14 PM, Nidian Job-Smith wrote: > Hi all, > > I'm new to programming (thus Python), so after reading the > basics, I wanted to practise what I've learnt . I've come across a > beginners exercise which is to programme rot13. > > I've written some code but it doesn't seem t

Re: [Tutor] how to understand unhashable type: 'list'

2011-11-17 Thread lina
> ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > > sum(1 if type(elem) == list else 0 for elem in list1) not work for you if > all you want to do is count how

Re: [Tutor] how to understand unhashable type: 'list'

2011-11-17 Thread lina
On Thu, Nov 17, 2011 at 8:17 PM, Steven D'Aprano wrote: > lina wrote: >> >> list1 >> [['61', '34', '61', '34'], ['61', '35', '61', '70', '61'], ['61', >> '70', '61', '34'], ['34', '58', '34', '58']] > > You have a list of lists. > > > weight={} > weight{list1[0]}=1 >> >> SyntaxError: inval

Re: [Tutor] how to understand unhashable type: 'list'

2011-11-17 Thread Steven D'Aprano
lina wrote: May I ask which role the __repr__ plays here? ... weight[elem.__repr__()] += 1 ... else: ... weight[elem.__repr__()] = 1 ... You should never call elem.__repr__(), any more than you would call elem.__len__() or elem.__str__(). (Well, technically there *are* rare u

Re: [Tutor] (no subject)

2011-11-17 Thread Steven D'Aprano
Nidian Job-Smith wrote: Hi all, I'm new to programming (thus Python), so after reading the basics, I wanted to practise what I've learnt . I've come across a beginners exercise which is to programme rot13. I've written some code but it doesn't seem to work Here it is: def rot13(s):cha

Re: [Tutor] how to understand unhashable type: 'list'

2011-11-17 Thread Christian Witts
On 2011/11/17 03:56 PM, lina wrote: ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor sum(1 if type(elem) == list else 0 for elem in list1) not work for you if all yo

Re: [Tutor] how to understand unhashable type: 'list'

2011-11-17 Thread Walter Prins
Hi Lina On 17 November 2011 14:04, lina wrote: > >> Traceback (most recent call last): > >> File "", line 1, in > >>weight[list1[0]]=1 > >> TypeError: unhashable type: 'list' > > > > You are trying to store a list as a key inside a dict. This cannot be > done > > because lists (like all mu

Re: [Tutor] how to understand unhashable type: 'list'

2011-11-17 Thread lina
Thanks for all. Everything new to me is so amazing. Well, still a remaining question, how to sort based on the value of the key. Actually I googled hours ago, wanna see more ways of doing it. Best regards, > > On 17 November 2011 14:04, lina wrote: >> >> >> Traceback (most recent call last): >

Re: [Tutor] how to understand unhashable type: 'list'

2011-11-17 Thread Steven D'Aprano
lina wrote: You are trying to store a list as a key inside a dict. This cannot be done because lists (like all mutable types) can't be hashed. I checked online dictionary, still confused about hashed. is it equal to mix together or mess together? Almost. In ordinary English, a hash is a mix

Re: [Tutor] Clock in tkinter?

2011-11-17 Thread Mic
From: Wayne Werner Sent: Wednesday, November 16, 2011 8:38 PM To: Mic Cc: tutor@python.org Subject: Re: [Tutor] Clock in tkinter? On Wed, Nov 16, 2011 at 11:44 AM, Mic wrote: I wonder if you have any suggestions regarding how to place widgets in my window. Even though I try to arran

Re: [Tutor] binary file query

2011-11-17 Thread Prasad, Ramit
-Original Message- From: Shirkhedkar, Dhanashri [mailto:dhanashri.shirkhed...@honeywell.com] Sent: Wednesday, November 16, 2011 10:58 PM To: Prasad, Ramit Subject: RE: binary file query Thanks for replying. It means that no need to use the 'Struct' module for binary file read, right? ===

Re: [Tutor] Clock in tkinter?

2011-11-17 Thread Wayne Werner
On Thu, Nov 17, 2011 at 8:57 AM, Mic wrote: > > > Okay, to begin with, I hope I am replying correctly now. > Better, though there was quite a lot of my email that you could have removed. > > I wonder, how do I add a background picture to my GUI window? > > So far, I thought I could make a l

Re: [Tutor] how to understand unhashable type: 'list'

2011-11-17 Thread lina
On Thu, Nov 17, 2011 at 10:44 PM, Steven D'Aprano wrote: > lina wrote: > >>> You are trying to store a list as a key inside a dict. This cannot be >>> done >>> because lists (like all mutable types) can't be hashed. >> >> I checked online dictionary, still confused about hashed. is it equal >> to

Re: [Tutor] how to understand unhashable type: 'list'

2011-11-17 Thread Steven D'Aprano
lina wrote: Right now I wanna check which are not hash-able, for strings, set, and tuple (which I don't understand). Mutable objects are those that can be changed in place: lists, sets, dicts are all mutable, because you can change them: >>> mylist = [1, 2, 3] >>> mylist[1] = 200 >>> print

[Tutor] Rot13

2011-11-17 Thread Nidian Job-Smith
Hi all, I'm new to programming (thus Python), so after reading the basics, I wanted to practise what I've learnt . I've come across a beginners exercise which is to write the code for rot13.   I've written some code but it doesn't seem to work When I run it I get this error: NameError: glo

Re: [Tutor] Rot13

2011-11-17 Thread Nidian Job-Smith
Sorry about the code format in last E-mail. I'll attach the code in notepad, as my e-mail doesnt seem to like sending plain text.. > From: nidia...@hotmail.com > To: st...@pearwood.info; tutor@python.org > Date: Thu, 17 Nov 2011 17:45:11 + > Subject:

Re: [Tutor] Rot13

2011-11-17 Thread Steven D'Aprano
Nidian Job-Smith wrote: When I run it I get this error: NameError: global name 'rot13_char' is not defined [...] Any ideas where i'm wrong? You have a function called "rot13", and *another* function called "rot13", which will over-write the first one. But you have no function called "rot

[Tutor] python telnet

2011-11-17 Thread Rayon
From: Rayon [mailto:ra...@gtt.co.gy] Sent: 17 November 2011 14:04 To: 'tutor@python.org' Subject: python telnet I am trying to use winpexpect to connect a telnet session. I keep getting this error. raise ExceptionPexpect, 'Command not found: %s' % self.command ExceptionPex

Re: [Tutor] Rot13

2011-11-17 Thread Dave Angel
On 11/17/2011 12:54 PM, Nidian Job-Smith wrote: Sorry about the code format in last E-mail. I'll attach the code in notepad, as my e-mail doesnt seem to like sending plain text.. But attachments aren't visible to everyone on the list, and even when they are, some people are (rightfully) parano

[Tutor] local variable referenced before assignment

2011-11-17 Thread ADRIAN KELLY
hi all,keep getting the above error, can't understand or fix it, can anyone help. def exchange():euro=1dollar=1.35base=50amount = input ('how much do you want to change')if amount>base: totalreturn=amount*dollarelse:print 'not enough'return totalretur

Re: [Tutor] local variable referenced before assignment

2011-11-17 Thread delegbede
Post the error stack. Sent from my BlackBerry wireless device from MTN -Original Message- From: ADRIAN KELLY Sender: tutor-bounces+delegbede=dudupay@python.org Date: Thu, 17 Nov 2011 18:47:07 To: Subject: [Tutor] local variable referenced before assignment

Re: [Tutor] local variable referenced before assignment

2011-11-17 Thread Joel Goldstick
On Thu, Nov 17, 2011 at 1:53 PM, wrote: > Post the error stack. > Sent from my BlackBerry wireless device from MTN > > -Original Message- > From: ADRIAN KELLY > Sender: tutor-bounces+delegbede=dudupay@python.org > Date: Thu, 17 Nov 2011 18:47:07 > To: > Subject: [Tutor] local variab

Re: [Tutor] local variable referenced before assignment

2011-11-17 Thread Dave Angel
On 11/17/2011 01:47 PM, ADRIAN KELLY wrote: hi all,keep getting the above error, can't understand or fix it, can anyone help. def exchange():euro=1dollar=1.35base=50amount = input ('how much do you want to change')if amount>base:totalreturn=amount*dollar else:

Re: [Tutor] how to understand unhashable type: 'list'

2011-11-17 Thread Peter Otten
Steven D'Aprano wrote: > Immutable objects are those that cannot be changed in place: you have to > create a new object. Tuples, frozensets, strings, ints, floats are all > immutable. They are hashable. Tuples are special: there are hashable and unhashable tuples. To be hashable all items in a t

Re: [Tutor] Clock in tkinter?

2011-11-17 Thread Mic
If you're going to put a function inside your class (since you're using self in there, I'm sure that's what you meant to do), you should change it to: def change_value_the_time(self): and call it with self.display_time.after(20, self.change_value_the_time) But your program also has un

Re: [Tutor] local variable referenced before assignment

2011-11-17 Thread ADRIAN KELLY
you are spot on. thanks very much i understand the problem now and its been solved. very clear help thanks, adrian > Date: Thu, 17 Nov 2011 14:01:19 -0500 > From: d...@davea.name > To: kellyadr...@hotmail.com > CC: tutor@python.org > Subject: Re: [Tutor] local variable reference

Re: [Tutor] Clock in tkinter?

2011-11-17 Thread Wayne Werner
On Thu, Nov 17, 2011 at 1:17 PM, Mic wrote: > I have now worked to stop using the global scope and instead put my > prior global variable into > the constructor in the class. I believe that I have managed to do that now. > > Do you believe that this is correctly done? > > > #Trying putting the_

[Tutor] please help - stuck for hours

2011-11-17 Thread ADRIAN KELLY
i have tried everything, i am trying to build in a loop to my 2 functions which worked fine up until my latest sorti. please have a look if you can.. def exchange(cash_in):euro=1dollar=1.35base=50if cash_in>base: totalreturn=cash_in*dollarelse:tota

[Tutor] infinite loop

2011-11-17 Thread ADRIAN KELLY
#i am nearly there guys..please loop at the infinite loop i am getting here..PLEASE!!#ADRIAN def exchange(cash_in):euro=1dollar=float(1.35)base=50if cash_in>base:totalreturn=cash_in*dollarelse:totalreturn=0 return totalreturn amoun

Re: [Tutor] please help - stuck for hours

2011-11-17 Thread Wayne Werner
On Thu, Nov 17, 2011 at 3:19 PM, ADRIAN KELLY wrote: > i have tried everything, i am trying to build in a loop to my 2 functions > which worked fine up until my latest sorti. > > please have a look if you can.. > > def exchange(cash_in): > euro=1 > dollar=1.35 > base=50 >

Re: [Tutor] infinite loop

2011-11-17 Thread Wayne Werner
On Thu, Nov 17, 2011 at 3:29 PM, ADRIAN KELLY wrote: > def main(): > amount = float(raw_input('how much do you want to change:')) > while amount<50: > print 'Sorry, cannot convert an amount under €50 ' > > When do you reassign amount? HTH, Wayne ___

Re: [Tutor] please help - stuck for hours

2011-11-17 Thread delegbede
Where do you intend the variable cash_in to come from? The system doesn't know what cash_in is beyond that you mentioned it and that makes it impossible to multiply it with dollar which is a float type. If cash_in is supposed to be an input from the user, you probably should make it an int typ

Re: [Tutor] please help - stuck for hours

2011-11-17 Thread ADRIAN KELLY
thanks very much, great response really really appreciated it and now i understand. i hate to ask again but can you see why it won't print the 'enter and amount over 50' in the right place?? # -*- coding: cp1252 -*-def exchange(cash_in):euro=1dollar=1.35 base=50if cash_in>b

Re: [Tutor] please help - stuck for hours

2011-11-17 Thread Wayne Werner
On Thu, Nov 17, 2011 at 4:32 PM, ADRIAN KELLY wrote: > > thanks very much, great response really really appreciated it and now i > understand. i hate to ask again but can you see why it won't print the > 'enter and amount over 50' in the right place?? > Computers are unfailingly stupid machines.

Re: [Tutor] please help - stuck for hours

2011-11-17 Thread ADRIAN KELLY
i know i should use input but when i changed to raw_input it wouldn't recognise the word print on the next line. honestly i have tried everything to get this working..i am 6 hrs at one program Adrian Kelly 1 Bramble Close Baylough Athlone County Westmeath 0879495663 From: waynejw

[Tutor] urgent help!!!!!!!!!!!

2011-11-17 Thread ADRIAN KELLY
i know i'm stupid but i have tried everything to get one line of text working, i have written out pseudo and read every website.now i am getting this error Traceback (most recent call last): File "F:\VTOS ATHLONE\PYTHON_VTOS\foreign exchange\f_ex4 - Copy.py", line 24, in ma

Re: [Tutor] binary file query

2011-11-17 Thread Alan Gauld
On 17/11/11 14:55, Prasad, Ramit wrote: It means that no need to use the 'Struct' module for binary file read, right? Its not necessary but if the data does not already have a file handling module then the struct module is a very convenient way of accessing the data. It really depends on

Re: [Tutor] urgent help!!!!!!!!!!!

2011-11-17 Thread Alex Hall
My mail client stripped new lines, at least on this machine, so I will just top-post this. Sorry! Your problem is that you say: amount=0 def main()... You then try to use amount in main, but main has no amount in it. Either move "amount=0" inside main, or put a global reference: amount=0 def main()

Re: [Tutor] python telnet

2011-11-17 Thread Steven D'Aprano
Rayon wrote: I am trying to use winpexpect to connect a telnet session. I keep getting this error. raise ExceptionPexpect, 'Command not found: %s' % self.command ExceptionPexpect: Command not found: telnet Please copy and paste the entire traceback, not just the last couple of lines.

Re: [Tutor] please help - stuck for hours

2011-11-17 Thread Alan Gauld
On 17/11/11 23:12, ADRIAN KELLY wrote: i know i should use input but when i changed to raw_input In Python v3 use input() In python v2 input() is dangerous, use raw_input() instead. > ... it wouldn't recognise the word print on the next line. Show us the exact code and error. You may be miss

Re: [Tutor] infinite loop

2011-11-17 Thread Alan Gauld
On 17/11/11 21:29, ADRIAN KELLY wrote: amount=float() You don;t need this line because you assign a value to amount immediately you run main() def main(): amount = float(raw_input('how much do you want to change:')) while amount<50: print 'Sorry, cannot convert an amount under €50 ' To

Re: [Tutor] urgent help!!!!!!!!!!!

2011-11-17 Thread Prasad, Ramit
def exchange(cash_in):     euro=1     dollar=1.35     base=50     if cash_in>base:         totalreturn=cash_in*dollar     else:         totalreturn=0     return totalreturn amount=0 # this would be better placed inside the main function. def main():     while amount<50:         amount = raw_input(

Re: [Tutor] how to understand unhashable type: 'list'

2011-11-17 Thread Alan Gauld
On 17/11/11 15:30, lina wrote: tuple (which I don't understand). You mean you don't understand the term 'tuple'? Basically its just a collection of data. You can get a triple - 3 items, a quadruple - 4 items, quintiple - 5 items etc The generic term for a collection of N items is a tuple. tri

[Tutor] Encoding

2011-11-17 Thread Nidian Job-Smith
Hi all, In my programme I am encoding what the user has in-putted. What the user inputs will in a string, which might a mixture of letters and numbers. However I only want the letters to be encoded. Does any-one how I can only allow the characters to be encoded ?? Big thanks,

[Tutor] The Perennial 3.2 vs 2.7

2011-11-17 Thread Mark Lybrand
Okay, so I am about to take up the banner of learning Python again. I had started with 3.2 and I have a book that I like. But all of the things that I want to use Python for appear to be 2.x specific. Will I be setting myself up for failure if I continue learning 3 and then try to write programs

Re: [Tutor] The Perennial 3.2 vs 2.7

2011-11-17 Thread Wayne Werner
On Nov 17, 2011 8:28 PM, "Mark Lybrand" wrote: > > Okay, so I am about to take up the banner of learning Python again. I had started with 3.2 and I have a book that I like. But all of the things that I want to use Python for appear to be 2.x specific. Will I be setting myself up for failure if I

Re: [Tutor] Encoding

2011-11-17 Thread bob gailer
On 11/17/2011 8:45 PM, Nidian Job-Smith wrote: Hi all, In my programme I am encoding what the user has in-putted. What the user inputs will in a string, which might a mixture of letters and numbers. However I only want the letters to be encoded. Does any-one how I can only allow the chara

[Tutor] Doctest error!

2011-11-17 Thread John
Hi all, When i run a doctest on this piece of code (shown at bottom) i get this error message [from the doctest]: Trying: rot13('5 The Parade') Expecting: '5 Gur Cnenqr' ** File "F:\Uni\Rot13_1.py", line 12, in Rot13_

Re: [Tutor] Doctest error!

2011-11-17 Thread Dave Angel
On 11/18/2011 10:29 AM, John wrote: Hi all, When i run a doctest on this piece of code (shown at bottom) i get this error message [from the doctest]: Trying: rot13('5 The Parade') Expecting: '5 Gur Cnenqr' ** File "

Re: [Tutor] infinite loop

2011-11-17 Thread Dave Angel
On 11/17/2011 04:29 PM, ADRIAN KELLY wrote: #i am nearly there guys..please loop at the infinite loop i am getting here..PLEASE!!#ADRIAN def exchange(cash_in):euro=1dollar=float(1.35)base=50if cash_in>base:totalreturn=cash_in*dollarelse:

Re: [Tutor] Doctest error!

2011-11-17 Thread Nidian Job-Smith
> Date: Thu, 17 Nov 2011 22:49:33 -0500 > From: d...@davea.name > To: nidia...@hotmail.com > CC: tutor@python.org > Subject: Re: [Tutor] Doctest error! > > On 11/18/2011 10:29 AM, John wrote: > > > > Hi all, > > When i run a doctest on this piece of code

Re: [Tutor] Doctest error!

2011-11-17 Thread Dave Angel
On 11/17/2011 10:56 PM, Nidian Job-Smith wrote: Date: Thu, 17 Nov 2011 22:49:33 -0500 From: d...@davea.name To: nidia...@hotmail.com CC: tutor@python.org Subject: Re: [Tutor] Doctest error! On 11/18/2011 10:29 AM, John wrote: Hi all, When i run a doct

Re: [Tutor] The Perennial 3.2 vs 2.7

2011-11-17 Thread Wayne Werner
Forwarding on to the list... (hit reply to all next time) On Thu, Nov 17, 2011 at 8:45 PM, Mark Lybrand wrote: > so, use my 2.7 and not my 3.2 for my study? Or use my 3.2 for study and > then do what I have to in 2.7 after including those lines? > > Thanks for the quick reply by the way. I am st