[Tutor] Error Using A List And SMTP
Hey guys, I was just trying out SMTP and I keep getting a attribute error, *AttributeError: 'list' object has no attribute 'lstrip''*, when I use a list to store the send address. Code - http://pastebin.com/9NmCNdRb Traceback - http://pastebin.com/m1cgKDnn I'm not sure I understand why this is happening. -- Sarma Tangirala, Class of 2012, Department of Information Science and Technology, College of Engineering Guindy - Anna University ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Error Using A List And SMTP
Hi Sarma On 16 May 2012 11:13, Sarma Tangirala tvssarma.ome...@gmail.com wrote: Hey guys, I was just trying out SMTP and I keep getting a attribute error, *AttributeError: 'list' object has no attribute 'lstrip''*, when I use a list to store the send address. Code - http://pastebin.com/9NmCNdRb Traceback - http://pastebin.com/m1cgKDnn I'm not sure I understand why this is happening. All the headers in the MimeText object needs to be strings. You can't directly pass a list object containing multiple recipients to the To header of your MimeText object on line 31 in your code, and expect it to work. You've got to instead first convert the list to valid string and assign that instead, as that's what the MimeText object expects. You can infer this from your error messages since lstrip() is a string method, and the code is (rightly) complaining that a list doesn't have an lstrip() method, which is understandable becuase you're getting the error when you pass a list as parameter. A quick google yields this question/answer on stackoverflow which is relevant to your question. (See the cc: bits): http://stackoverflow.com/questions/5304835/how-to-send-gmail-email-with-multiple-ccs Walter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] table to dictionary and then analysis
On Tue, 2012-05-15 at 19:14 +0100, Alan Gauld wrote: On 15/05/12 10:36, Russel Winder wrote: ...queries passed over it then year a database it the right thing -- though I would probably choose a non-SQL database. As a matter of interest why? Because there are alternatives that need to be investigated on a per problem basis for the best database. SQL MongoDB CouchDB Cassandra Neo etc. Python only has SQLite3 as standard but there are alternatives. I have been using PyMongo quite successfully. And what kind of alternative would you use? See above ;-) It seems to me that SQL is ideally suited(*) to this type of role. I'm curious what the alternatives might be and why they would be preferred? (*)Because: Flexible query language, wide set of tools including GUI query builders, reporting tools etc. Plus easy integration with programming environments, scaleability (less an issue here), security(usually) etc. It is not clear that the original table works better with the relational model compared to one of the key-value stores or document stores. It might. But I no longer always go to SQL for persistence as I used to a few years ago. There are various articles around the Web comparing and contrasting these various models. Some of the articles are even reasonable :-) -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Error Using A List And SMTP
Hi Walter, All the headers in the MimeText object needs to be strings. You can't directly pass a list object containing multiple recipients to the To header of your MimeText object on line 31 in your code, and expect it to work. You've got to instead first convert the list to valid string and assign that instead, as that's what the MimeText object expects. You can infer this from your error messages since lstrip() is a string method, and the code is (rightly) complaining that a list doesn't have an lstrip() method, which is understandable becuase you're getting the error when you pass a list as parameter. Thank you for clearing that. Stupid mistake here. I forgot to change the variable names. But I do have another question. Maybe this is a misunderstanding about the MimeText type, but why does MimeText care about the To field when the actually sending is being done by SMTP? -- Sarma Tangirala, Class of 2012, Department of Information Science and Technology, College of Engineering Guindy - Anna University ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Error Using A List And SMTP
On 16 May 2012 17:04, Sarma Tangirala tvssarma.ome...@gmail.com wrote: Hi Walter, All the headers in the MimeText object needs to be strings. You can't directly pass a list object containing multiple recipients to the To header of your MimeText object on line 31 in your code, and expect it to work. You've got to instead first convert the list to valid string and assign that instead, as that's what the MimeText object expects. You can infer this from your error messages since lstrip() is a string method, and the code is (rightly) complaining that a list doesn't have an lstrip() method, which is understandable becuase you're getting the error when you pass a list as parameter. Thank you for clearing that. Stupid mistake here. I forgot to change the variable names. But I do have another question. Maybe this is a misunderstanding about the MimeText type, but why does MimeText care about the To field when the actually sending is being done by SMTP? OK. That was a stupid question. Sorry for the noise. Please ignore. -- Sarma Tangirala, Class of 2012, Department of Information Science and Technology, College of Engineering Guindy - Anna University -- Sarma Tangirala, Class of 2012, Department of Information Science and Technology, College of Engineering Guindy - Anna University ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] table to dictionary and then analysis
On 16/05/12 12:27, Russel Winder wrote: As a matter of interest why? Because there are alternatives that need to be investigated on a per problem basis for the best database. I agree, but in this case SQL seemed like the most likely fit of the ones I knew. however: SQL MongoDB I know about these CouchDB Cassandra Neo These are new to me. etc. Python only has SQLite3 as standard but there are alternatives. I have been using PyMongo quite successfully. Python comes with several storage/access options including shelve, gdbm, ldap, cobfig files, XML, in addition to SQL. It is not clear that the original table works better with the relational model compared to one of the key-value stores or document stores. Most key-value stores are optimised for fast queries of a single type and generally not great at grouping or ordering. They also tend to major on flexiblity of data format. The OPs requirements suggested intelligent filtering of a fixed record format which is one of the areas where SQL works well. The other side of the coin is that the data is essentially single table so the relationship management aspects of SQL would not be needed. So I agree we don't have enough detail to be 100% sure that another option would not work as well or better. But most other options require learning new (often bespoke) query languages and have limited user tools. All of these factors need to be included too. Mongo et al tend to be better suited, in my experience, to machine access applications rather than end user access. There are various articles around the Web comparing and contrasting these various models. Some of the articles are even reasonable :-) Wikipedia is my friend :-) -- 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] Error Using A List And SMTP
On 16/05/12 12:37, Sarma Tangirala wrote: But I do have another question. Maybe this is a misunderstanding about the MimeText type, but why does MimeText care about the To field when the actually sending is being done by SMTP? OK. That was a stupid question. Sorry for the noise. Please ignore. Actually for a beginners list I thought it was a perfectly reasonable question! :-) But I assume you figured out the answer for yourself so that's fine. -- 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] Error Using A List And SMTP
On 16 May 2012 20:37, Alan Gauld alan.ga...@btinternet.com wrote: On 16/05/12 12:37, Sarma Tangirala wrote: But I do have another question. Maybe this is a misunderstanding about the MimeText type, but why does MimeText care about the To field when the actually sending is being done by SMTP? OK. That was a stupid question. Sorry for the noise. Please ignore. Actually for a beginners list I thought it was a perfectly reasonable question! :-) But I assume you figured out the answer for yourself so that's fine. Not exactly. I did not read the immediate reply properly and got stupid. :P -- 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/tutorhttp://mail.python.org/mailman/listinfo/tutor -- An monkey typed up this email. Please excuse him if he made a stupid error! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] table to dictionary and then analysis
On Wed, May 16, 2012 at 11:03 AM, Alan Gauld alan.ga...@btinternet.com wrote: On 16/05/12 12:27, Russel Winder wrote: As a matter of interest why? Because there are alternatives that need to be investigated on a per problem basis for the best database. I agree, but in this case SQL seemed like the most likely fit of the ones I knew. however: SQL MongoDB I know about these CouchDB Cassandra Neo These are new to me. etc. Python only has SQLite3 as standard but there are alternatives. I have been using PyMongo quite successfully. Python comes with several storage/access options including shelve, gdbm, ldap, cobfig files, XML, in addition to SQL. It is not clear that the original table works better with the relational model compared to one of the key-value stores or document stores. Most key-value stores are optimised for fast queries of a single type and generally not great at grouping or ordering. They also tend to major on flexiblity of data format. The OPs requirements suggested intelligent filtering of a fixed record format which is one of the areas where SQL works well. The other side of the coin is that the data is essentially single table so the relationship management aspects of SQL would not be needed. So I agree we don't have enough detail to be 100% sure that another option would not work as well or better. But most other options require learning new (often bespoke) query languages and have limited user tools. All of these factors need to be included too. Mongo et al tend to be better suited, in my experience, to machine access applications rather than end user access. There are various articles around the Web comparing and contrasting these various models. Some of the articles are even reasonable :-) Wikipedia is my friend :-) -- 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 I think the OP is just learning and this thread may have gotten of track. Here is some code to get started. I decided to use sqlite3 since its easy to use with python -- no finding and learning to load packages. #!/usr/bin/env python import sqlite3 as db # Ideally this shouldn't be global, but in this short code snippet it gets the job done # here we create a database and get a cursor conn = db.connect('climate.db') cursor = conn.cursor() print cursor # this will create a table for our data sql_create = CREATE TABLE if not exists rain ( id INTEGER PRIMARY KEY, year INTEGER, month TEXT(3), rainfall FLOAT, fire_area FLOAT ) # this will read the data file and put it in our database def populate_climate_table(file_name): reads the file_name and insert data into sqlite table sql_insert_string = insert into rain (year, month, rainfall, fire_area) values (%d, '%s', %f, %f) f = open(file_name) f.readline() # get rid of column headers for l in f.readlines(): data_list = l.split() print data_list sql_insert = sql_insert_string % (int(data_list[0]), data_list[1], float(data_list[2]), float(data_list[3])) print sql_insert cursor.execute(sql_insert) conn.commit() if __name__ == '__main__': print sql_create cursor.execute(sql_create) populate_climate_table('data.txt') So, I haven't solved all of the questions with this code. The next thing to do is to read a little about sqlite select statements. for example: sqlite select sum(rainfall)/count(*) from rain; 3.97352768125 This statement will give the average rainfall over the complete dataset. To get the ave rainfall for a given year do this: sqlite select sum(rainfall)/count(*) from rain where year = 1983; Come back with more questions -- Joel Goldstick ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] ssh socks proxy
I'm trying to write a 'simple' script that will set up a socks proxy over ssh and maintain the connection until manually terminated. It's not possible to use key-based authentication so a password will need to be supplied. Also, note, the user is presented with a list of servers to choose from at the beginning. The actual ssh command is: 'ssh -vNCD 2 user@host'. I've been tinkering with both pexpect and paramiko but fear I'm making a mountain out of a mole hill. I'm aware both have example scripts for ssh forwarding but, to be honest, they are both too complicated (aka I don't know how to customise them). Here is one script I've attempted to get working and the associated error listing: http://pastebin.com/jj8Fgvwm - script http://pastebin.com/jRA8zpzi - error Could anyone help me either correct the script I've started or suggest an ockham's-razor-adherent alternative! Many thanks. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] TypeError: 'int' object is not callable
Can anyone tell me what I am doing wrong here. When trying to call the factors function from main with x = factors(Tn), getting the error message: “TypeError: 'int' object is not callable”? Any help would be appreciated. Thanks. def factors(n): L = [] for i in range(1, int(n ** 0.5) + 1): if (n % i == 0): L.append(i) return L def main(): factors = 0 counter = 0 L = [] while len(L) 50: counter += 1 L.append(counter) Tn = sum(L) x = factors(Tn) #print x print(sum(L)) if __name__ == '__main__': main()___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] TypeError: 'int' object is not callable
On 5/16/12, Greg Christian glchrist...@comcast.net wrote: Can anyone tell me what I am doing wrong here. When trying to call the factors function from main with x = factors(Tn), getting the error message: “TypeError: 'int' object is not callable”? Any help would be appreciated. Thanks. def factors(n): L = [] for i in range(1, int(n ** 0.5) + 1): if (n % i == 0): L.append(i) return L def main(): factors = 0 counter = 0 L = [] while len(L) 50: counter += 1 L.append(counter) Tn = sum(L) x = factors(Tn) #print x print(sum(L)) if __name__ == '__main__': main() You declared 'factors' as a variable on line 1 in main:: factors = 0 This masks the call to the function 'factors'. You get the error because you assigned factors an integer and you cannot 'call' an integer. The easiest solution is to use another name for the variable 'factors' instead. -Modulok- ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] TypeError: 'int' object is not callable
On 5/16/2012 1:17 PM Greg Christian said... def factors(n): L = [] for i in range(1, int(n ** 0.5) + 1): if (n % i == 0): L.append(i) return L ... now you've completed defining the function factors... def main(): factors = 0 ... and here you create an integer of the same name... counter = 0 L = [] while len(L) 50: counter += 1 L.append(counter) Tn = sum(L) x = factors(Tn) ... and here you attempt to call the interger factors passing it the argument Tn #print x print(sum(L)) Also, in the future please post the complete traceback -- it relly helps. Emile ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] TypeError: 'int' object is not callable
Le Wed, 16 May 2012 14:37:53 -0600, Modulok modu...@gmail.com a écrit : On 5/16/12, Greg Christian glchrist...@comcast.net wrote: Can anyone tell me what I am doing wrong here. When trying to call the factors function from main with x = factors(Tn), getting the error message: “TypeError: 'int' object is not callable”? Any help would be appreciated. Thanks. def factors(n): L = [] for i in range(1, int(n ** 0.5) + 1): if (n % i == 0): L.append(i) return L def main(): factors = 0 counter = 0 L = [] while len(L) 50: counter += 1 L.append(counter) Tn = sum(L) x = factors(Tn) #print x print(sum(L)) if __name__ == '__main__': main() You declared 'factors' as a variable on line 1 in main:: factors = 0 This masks the call to the function 'factors'. You get the error because you assigned factors an integer and you cannot 'call' an integer. The easiest solution is to use another name for the variable 'factors' instead. -Modulok- If you use 'pylint', a syntax checker, you get this: C: 1,0: Missing docstring C: 1,0:factors: Missing docstring W: 9,4:main: Redefining name 'factors' from outer scope (line 1) C: 8,0:main: Missing docstring E: 16,12:main: factors is not callable W: 16,8:main: Unused variable 'x' ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor -- René Bastian www.pythoneon.org ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] ssh socks proxy
Adam Gold adamg...@lavabit.com wrote: I'm trying to write a 'simple' script that will set up a socks proxy over ssh and maintain the connection until manually terminated. It's not possible to use key-based authentication so a password will need to be supplied. Also, note, the user is presented with a list of servers to choose from at the beginning. The actual ssh command is: 'ssh -vNCD 2 user@host'. I've been tinkering with both pexpect and paramiko but fear I'm making a mountain out of a mole hill. I'm aware both have example scripts for ssh forwarding but, to be honest, they are both too complicated (aka I don't know how to customise them). Here is one script I've attempted to get working and the associated error listing: http://pastebin.com/jj8Fgvwm - script http://pastebin.com/jRA8zpzi - error Could anyone help me either correct the script I've started or suggest an ockham's-razor-adherent alternative! Many thanks. The error message indicates that there hostname HOST could not be resolved. You need to replace that with the value of the variable HOST. COMMAND = ssh -vNDR 2 {}@{}.format(USER, HOST) I'm curious to know why you can't use keys. They make things much simpler. -- regards, kushal ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] ssh socks proxy
kushal.kumaran+pyt...@gmail.com wrote: Adam Gold adamg...@lavabit.com wrote: I'm trying to write a 'simple' script that will set up a socks proxy over ssh and maintain the connection until manually terminated. It's not possible to use key-based authentication so a password will need to be supplied. Also, note, the user is presented with a list of servers to choose from at the beginning. The actual ssh command is: 'ssh -vNCD 2 user@host'. I've been tinkering with both pexpect and paramiko but fear I'm making a mountain out of a mole hill. I'm aware both have example scripts for ssh forwarding but, to be honest, they are both too complicated (aka I don't know how to customise them). Here is one script I've attempted to get working and the associated error listing: http://pastebin.com/jj8Fgvwm - script http://pastebin.com/jRA8zpzi - error Could anyone help me either correct the script I've started or suggest an ockham's-razor-adherent alternative! Many thanks. The error message indicates that there hostname HOST could not be resolved. You need to replace that with the value of the variable HOST. COMMAND = ssh -vNDR 2 {}@{}.format(USER, HOST) I'm curious to know why you can't use keys. They make things much simpler. Excuse the incorrect ssh command. New mail client tripped me up. -- regards, kushal ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor