Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #34660
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!rt.uk.eu.org!nntp-feed.chiark.greenend.org.uk!ewrotcd!news.nosignal.org!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <d@davea.name> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'example:': 0.03; 'skip:" 60': 0.05; 'escape': 0.07; 'sequences.': 0.07; 'trailing': 0.07; 'python': 0.09; 'email addr:example.com': 0.09; 'fix.': 0.09; 'iterate': 0.09; 'cc:addr:python-list': 0.10; 'stored': 0.10; 'assume': 0.11; '(just': 0.16; 'row': 0.16; 'statement)': 0.16; 'subject:Problem': 0.16; 'subject:screen': 0.16; 'wrote:': 0.17; 'fix': 0.17; 'directory.': 0.17; 'import': 0.21; 'assuming': 0.22; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'command': 0.24; 'script': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; 'mike': 0.27; 'skip:# 10': 0.27; 'easiest': 0.27; 'correct': 0.28; 'whitespace': 0.29; 'file': 0.32; "skip:' 20": 0.32; 'print': 0.32; 'problem': 0.33; 'open': 0.35; 'pm,': 0.35; 'next': 0.35; "i'll": 0.36; 'subject:with': 0.36; 'subject:: ': 0.38; 'things': 0.38; 'shows': 0.38; 'received:192': 0.39; 'hello,': 0.39; 'received:192.168': 0.40; 'your': 0.60; 'skip:u 10': 0.60; 'show': 0.63; 'header :Reply-To:1': 0.68; 'received:74.208': 0.71; 'reply-to:no real name:2**0': 0.72; 'yourself,': 0.75; 'divided': 0.93 |
| Date | Tue, 11 Dec 2012 17:48:09 -0500 |
| From | Dave Angel <d@davea.name> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121011 Thunderbird/16.0.1 |
| MIME-Version | 1.0 |
| To | Mike <miguelcoam@gmail.com> |
| Subject | Re: Problem with print and output to screen |
| References | <37e2ba70-a709-4888-9672-be30956d690d@googlegroups.com> |
| In-Reply-To | <37e2ba70-a709-4888-9672-be30956d690d@googlegroups.com> |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | 7bit |
| X-Provags-ID | V02:K0:swmrhfo+6/Ne8RU9Wxl+T+fdODpjP7vU5kKORPWBkNy a4q3A5F51i2doacZE323r9CkF+Gw1F7SHLRUoDb8Znmpwpmvv4 ZPWufwqVHKHfECmHoshdJFXK7QXbQAqgJeX/S3LVa3jx6Or45k YFXe59O4OD4LjB10wzkADtSgZnkx0568EXcKgXsodmbyrm0xJi ESk89aXwqIazZqTaHI+Kgf8P8gb0hepF5fmhVuedLflbx2BLZu CDozaiOtjAP78g+PuthfdKbZn5C+jCMirimVMwPb8O0Ry+0Wpy Vubb1CjzKgtX/1Kk+tmLZdEkWFepk818penx305Ed/aA67WCw= = |
| Cc | python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| Reply-To | d@davea.name |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.753.1355266124.29569.python-list@python.org> (permalink) |
| Lines | 53 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1355266124 news.xs4all.nl 6903 [2001:888:2000:d::a6]:60103 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:34660 |
Show key headers only | View raw
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