change line with columns when print
Hello: I have a text file that looks like: 0 23 1 342 3 31 and I want to read the file and print it out like: 0 1 3 23 342 31 How can I do this? Thnak you in advance, Ionut -- http://mail.python.org/mailman/listinfo/python-list
Re: change line with columns when print
Thank you Almar It worked :), I now have to format it nicely Ionut - Original Message From: Almar Klein <[EMAIL PROTECTED]> To: python-list@python.org Sent: Wednesday, October 1, 2008 2:57:00 PM Subject: Re: change line with columns when print Hi, probably not the best solution, but this should work: L1 = [] L2 = [] for i in file: tmp = i.split(" ") L1.append(tmp[0]) L2.append(tmp[1]) for i in L1: print i, print # new line for i in L2: print i, print # new line Almar 2008/10/1 sandric ionut <[EMAIL PROTECTED]> Hello: I have a text file that looks like: 0 23 1 342 3 31 and I want to read the file and print it out like: 0 1 3 23 342 31 How can I do this? Thnak you in advance, Ionut -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: change line with columns when print
Even better, Thank you all Ionut - Original Message From: D'Arcy J.M. Cain <[EMAIL PROTECTED]> To: sandric ionut <[EMAIL PROTECTED]> Cc: python-list@python.org Sent: Wednesday, October 1, 2008 3:13:55 PM Subject: Re: change line with columns when print On Wed, 1 Oct 2008 04:43:34 -0700 (PDT) sandric ionut <[EMAIL PROTECTED]> wrote: > > > Hello: > I have a text file that looks like: > 0 23 > 1 342 > 3 31 > and I want to read the file and print it out like: > 0 1 3 > 23 342 31 > > How can I do this? Probably tons of ways. Here's one with no input checking. L = [x.strip().split() for x in open("infile") if x] for i in range(2): print ' '.join([x[i] for x in L]) -- D'Arcy J.M. Cain <[EMAIL PROTECTED]> | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. -- http://mail.python.org/mailman/listinfo/python-list
string concatenate
Hi: I have the following situation: nameAll = [] for i in range(1,10,1): n = "name" + str([i]) nameAll += n print nameAll I get: ['n', 'a', 'm', 'e', '[', '1', ']', 'n', 'a', 'm', 'e', '[', '2', ']', 'n', 'a', 'm', 'e', '[', '3', ']', 'n', 'a', 'm', 'e', '[', '4', ']', 'n', 'a', 'm', 'e', '[', '5', ']', 'n', 'a', 'm', 'e', '[', '6', ']', 'n', 'a', 'm', 'e', '[', '7', ']', 'n', 'a', 'm', 'e', '[', '8', ']', 'n', 'a', 'm', 'e', '[', '9', ']'] but I would like to have it as: name1 name2 name3 ...name10 How can I do it? Thank you, Ionut -- http://mail.python.org/mailman/listinfo/python-list
Re: Fwd: string concatenate
Thank you: but I would like to have them not like: ['name1', 'name2', 'name3', 'name4', 'name5', 'name6', 'name7', 'name8', 'name9'] but like name1 name2 name3 name4 name5 name6 name7 name8 name9 Is it possible? Ionut - Original Message From: Tommy Grav <[EMAIL PROTECTED]> To: Python List Sent: Wednesday, October 1, 2008 7:50:25 PM Subject: Fwd: string concatenate On Oct 1, 2008, at 12:41 PM, sandric ionut wrote: > Hi: > > I have the following situation: > nameAll = [] > for i in range(1,10,1): > n = "name" + str([i]) > nameAll += n > print nameAll > > I get: > > ['n', 'a', 'm', 'e', '[', '1', ']', 'n', 'a', 'm', 'e', '[', '2', > ']', 'n', 'a', 'm', 'e', '[', '3', ']', 'n', 'a', 'm', 'e', '[', > '4', ']', 'n', 'a', 'm', 'e', '[', '5', ']', 'n', 'a', 'm', 'e', > '[', '6', ']', 'n', 'a', 'm', 'e', '[', '7', ']', 'n', 'a', 'm', > 'e', '[', '8', ']', 'n', 'a', 'm', 'e', '[', '9', ']'] > > but I would like to have it as: > > name1 name2 name3 ...name10 > > How can I do it? > > Thank you, > > Ionut > nameAll = [] > for i in xrange(1,10,1): > n = "name" + str(i) > nameAll.append(n) > print nameAll ['name1', 'name2', 'name3', 'name4', 'name5', 'name6', 'name7', 'name8', 'name9'] list.append() is the right tool for adding new elements to a list. Cheers Tommy -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
sendmail error
Hello: I have a script for sending email from python (it is attached bellow). When I am launching the script I get the error: TypeError: cannot concatenate 'str' and 'type' objects if I use sys.argv[1], but if I input from the begging an email address like "em...@email.com", the script is working OK What could be the problem? Thank you, Ionut import mesaj = email.MIMEMultipart.MIMEMultipart() fromEmail = sys.argv[ toEmail = os, sys, smtplib, email1]"toEmail"mesaj[ mesaj[ mesaj["From"] = fromEmail"To"] = toEmail"Subject"] = "Teste"mesaj[ atasament = r"Date"] = email.Utils.formatdate(localtime=True)"d:\Doc1.zip"atasamentP = email.MIMEBase.MIMEBase( atasamentP.set_payload(open(atasament, email.Encoders.encode_base64(atasamentP) atasamentP.add_header( mesaj.attach(atasamentP) mesaj.attach(email.MIMEText.MIMEText( smtpObj = smtplib.SMTP('application','zip')"rb").read())'Content-Disposition','attachement; filename="%s"'% os.path.basename(atasament))"Email transmis la data: ", email.Utils.formatdate(localtime=False)))"192.168.1.2")try smtpObj.sendmail(fromEmail, toEmail, mesaj.as_string()) smtpObj.close():exceptsmtplib.SMTPException:print"eroare: "+ smtplib.SMTPException -- http://mail.python.org/mailman/listinfo/python-list
Fw: sendmail error
- Forwarded Message From: sandric ionut To: Dave Angel Sent: Tue, August 31, 2010 3:56:40 PM Subject: Re: sendmail error From: Dave Angel To: sandric ionut Cc: Python List Sent: Tue, August 31, 2010 2:49:29 PM Subject: Re: sendmail error The code was COPY and PASTE -> presume wrong When quoting an error message, get it all. Since you omit the stacktrace part, we can't tell what line might be giving you that error That is all the error code!!! Once you've noticed which line, just examine the types of each of the elements you're combining. If you're using the + operator, and the left operand is a string, then the right one must also be string. Figure out why it's not and you have your own answer Do you really think that I didn't do it? What a... response. This + or , is really USELESS. Please don't bother to send useless replays This is the line where I get the error: smtpObj.sendmail(fromEmail, toEmail, mesaj.as_string()) I.S. DaveA > sandric ionut wrote: > Hello: > > I have a script for sending email from python (it is attached bellow). When I >am launching the script I get the error: > TypeError: cannot concatenate 'str' and 'type' objects if I use sys.argv[1], >but if I input from the begging an email address like "em...@email.com", the >script is working OK > > What could be the problem? > > Thank you, > > Ionut > > import > mesaj = email.MIMEMultipart.MIMEMultipart() > fromEmail = sys.argv[ > toEmail = os, sys, smtplib, email1]"toEmail"mesaj[ > mesaj[ > mesaj["From"] = fromEmail"To"] = toEmail"Subject"] = "Teste"mesaj[ > atasament = r"Date"] = >email.Utils.formatdate(localtime=True)"d:\Doc1.zip"atasamentP = >email.MIMEBase.MIMEBase( > atasamentP.set_payload(open(atasament, > email.Encoders.encode_base64(atasamentP) > atasamentP.add_header( > mesaj.attach(atasamentP) > mesaj.attach(email.MIMEText.MIMEText( > smtpObj = >smtplib.SMTP('application','zip')"rb").read())'Content-Disposition','attachement; > > filename="%s"'% os.path.basename(atasament))"Email transmis la data: ", >email.Utils.formatdate(localtime=False)))"192.168.1.2")try > smtpObj.sendmail(fromEmail, toEmail, mesaj.as_string()) > smtpObj.close():exceptsmtplib.SMTPException:print"eroare: "+ >smtplib.SMTPException > > > Three things: When quoting code, do it exactly, and without wordwrap in your mail program. There are so many typos in that code sample that it's useless, presumably because you didn't use copy/paste -- http://mail.python.org/mailman/listinfo/python-list
Re: sendmail error
This is the only message that I will send to this list regarding my question: 1. I have copied and paste my code from Eclipe PyDev and I have used web interface for yahoo email to send the email. I don't know why the message arrived like that. I consider that the message from Dave was rude and just a replay considering the structure of the script would have been enough 2. Regarding the useless of the question: I consider that you two are also rude! There are some many more "useless" questions than my question on this forum! Do not bother to replay to this email because I would not receive the message. Your replays were enough to make me unsubscribe from the list I.S. From: Thomas Jollans To: python-list@python.org Sent: Tue, August 31, 2010 4:46:58 PM Subject: Re: sendmail error On Tuesday 31 August 2010, it occurred to sandric ionut to exclaim: > Hello: > > I have a script for sending email from python (it is attached bellow). When > I am launching the script I get the error: > TypeError: cannot concatenate 'str' and 'type' objects if I use > sys.argv[1], but if I input from the begging an email address like > "em...@email.com", the script is working OK > > What could be the problem? > > Thank you, > > Ionut > > import > mesaj = email.MIMEMultipart.MIMEMultipart() > fromEmail = sys.argv[ > toEmail = os, sys, smtplib, email1]"toEmail"mesaj[ > mesaj[ > mesaj["From"] = fromEmail"To"] = toEmail"Subject"] = "Teste"mesaj[ > atasament = r"Date"] = > email.Utils.formatdate(localtime=True)"d:\Doc1.zip"atasamentP = > email.MIMEBase.MIMEBase( > atasamentP.set_payload(open(atasament, > email.Encoders.encode_base64(atasamentP) > atasamentP.add_header( > mesaj.attach(atasamentP) > mesaj.attach(email.MIMEText.MIMEText( > smtpObj = > smtplib.SMTP('application','zip')"rb").read())'Content-Disposition','attach > ement; filename="%s"'% os.path.basename(atasament))"Email transmis la data: > ", email.Utils.formatdate(localtime=False)))"192.168.1.2")try > smtpObj.sendmail(fromEmail, toEmail, mesaj.as_string()) > smtpObj.close():exceptsmtplib.SMTPException:print"eroare: "+ > smtplib.SMTPException I struggle to imagine what one might do to a piece of code to garble it this badly. If this was actually the script you're trying to run, then it would have blown up in your face with a angry SyntaxError, not the helpful TypeError you quoted. As far as I can see, you never actually use sys.argv[1], so this can't be the right code. To paraphrase what you failed to spell correctly in your other message, please don't bother sending useless inquiries to this list. If you want to get a useful reply, please: - Quote the code correctly. Before sending, check that it actually makes sense. The above is quite simply nothing like Python. - Quote the entire stack trace and error message. You might have looked at it already, but we haven't. This information is not useless! Also, when replying: - Quote properly. While top posting is discouraged, the most important bit is to clearly distinguish quoted material from new material. Make it possible from the structure of the message you're sending which parts you wrote and which parts you're just quoting. - Keep your reply on-list. - Thomas -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list