Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #34660
| Date | 2012-12-11 17:48 -0500 |
|---|---|
| From | Dave Angel <d@davea.name> |
| Subject | Re: Problem with print and output to screen |
| References | <37e2ba70-a709-4888-9672-be30956d690d@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.753.1355266124.29569.python-list@python.org> (permalink) |
On 12/11/2012 05:31 PM, Mike wrote:
> Hello, I am learning python and i have the next problem and i not understand how fix.
> The script is very simple, shows in the terminal the command but, the row is divided in two:
> Example:
>
>
> /opt/zimbra/bin/zmprov ga user@example.com
> |egrep "(zimbraPrefMailForwardingAddress:|zimbraPrefMailForwardingAddress:)"
> /opt/zimbra/bin/zmprov ga user2@example.com
> |egrep "(zimbraPrefMailForwardingAddress:|zimbraPrefMailForwardingAddress:)"
>
> And the correct is:
> /opt/zimbra/bin/zmprov ga user@example.com |egrep "(zimbraPrefMailForwardingAddress:|zimbraPrefMailForwardingAddress:)"
>
>
> The script is:
>
> #!/usr/bin/python
> import os
>
> for user in open ("email"):
> print '/opt/zimbra/bin/zmprov ga ' + user + '|egrep "(zimbraPrefMailForwardingAddress:|zimbraPrefMailForwardingAddress:)" '
>
>
>
I'll assume that 'email' is a file in the current working directory. So
when you open it and iterate through it, each line will be stored in
'user', including its trailing newline.
When you print 'user', you're seeing the newline.
To see for yourself, you could/should have used (just before your print
statement)
print repr(user)
which will show such things as escape sequences.
Anyway, the easiest way to fix it would be to use rstrip() on the line.
for user in open("email"):
user = user.rstrip()
print '/opt/...
That's assuming there's no trailing whitespace that you DO want to preserve.
--
DaveA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Problem with print and output to screen Mike <miguelcoam@gmail.com> - 2012-12-11 14:31 -0800
Re: Problem with print and output to screen Dave Angel <d@davea.name> - 2012-12-11 17:48 -0500
Re: Problem with print and output to screen Joel Goldstick <joel.goldstick@gmail.com> - 2012-12-11 17:53 -0500
Re: Problem with print and output to screen Dave Angel <d@davea.name> - 2012-12-11 18:00 -0500
Re: Problem with print and output to screen Joel Goldstick <joel.goldstick@gmail.com> - 2012-12-11 18:07 -0500
Re: Problem with print and output to screen Mike <miguelcoam@gmail.com> - 2012-12-11 16:44 -0800
Re: Problem with print and output to screen Mike <miguelcoam@gmail.com> - 2012-12-11 16:44 -0800
csiph-web