Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #63927 > unrolled thread
| Started by | Mike <miguelcoam@gmail.com> |
|---|---|
| First post | 2014-01-14 11:24 -0800 |
| Last post | 2014-01-14 13:38 -0600 |
| Articles | 5 — 4 participants |
Back to article view | Back to comp.lang.python
Printer list value problem Mike <miguelcoam@gmail.com> - 2014-01-14 11:24 -0800
Re: Printer list value problem MRAB <python@mrabarnett.plus.com> - 2014-01-14 19:32 +0000
Re: Printer list value problem Mike <miguelcoam@gmail.com> - 2014-01-14 11:54 -0800
Re: Printer list value problem Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-01-14 20:03 +0000
Re: Printer list value problem Tim Chase <python.list@tim.thechases.com> - 2014-01-14 13:38 -0600
| From | Mike <miguelcoam@gmail.com> |
|---|---|
| Date | 2014-01-14 11:24 -0800 |
| Subject | Printer list value problem |
| Message-ID | <6139406d-9ccc-41b2-8aa8-7f6fd2431366@googlegroups.com> |
Hello,
I confudsed,need printer the value of list (this is reaer from csv) . The reader is ok, but my problem is in the print moment because printer only the last value. For example my csv is:
[........]
user1@example.com;user1;lastName;Name
user2@example.com;user2;lastName;Name
[........]
But when execute the script I view the print is only the last user
[........]
ca user2@example.com displayName 'user2' sn 'lastName' cn 'Name'
[........]
And I need the next printer
[........]
ca user1@example.com displayName 'User1' sn ''lastName" cn 'Name'
ca user1@example.com displayName 'User2' sn ''lastName" cn 'Name'
[........]
My script is
[........]
#!/usr/bin/python
import csv
with open ('users.csv', 'rb') as f:
reader = csv.reader (f, delimiter=';' ) #delimiter tabulador
for row in reader:
mail = row [0]
name = row [3]
lastname = row [2]
print "ma {} displayName '{}' sn '{}'".format(mail,name,lastname)
f.close()
[........]
Thanks.
[toc] | [next] | [standalone]
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2014-01-14 19:32 +0000 |
| Message-ID | <mailman.5470.1389727971.18130.python-list@python.org> |
| In reply to | #63927 |
On 2014-01-14 19:24, Mike wrote:
> Hello,
> I confudsed,need printer the value of list (this is reaer from csv) . The reader is ok, but my problem is in the print moment because printer only the last value. For example my csv is:
>
> [........]
> user1@example.com;user1;lastName;Name
> user2@example.com;user2;lastName;Name
> [........]
>
> But when execute the script I view the print is only the last user
>
> [........]
> ca user2@example.com displayName 'user2' sn 'lastName' cn 'Name'
> [........]
>
> And I need the next printer
>
> [........]
> ca user1@example.com displayName 'User1' sn ''lastName" cn 'Name'
> ca user1@example.com displayName 'User2' sn ''lastName" cn 'Name'
> [........]
>
> My script is
>
> [........]
> #!/usr/bin/python
> import csv
> with open ('users.csv', 'rb') as f:
>
> reader = csv.reader (f, delimiter=';' ) #delimiter tabulador
> for row in reader:
>
> mail = row [0]
> name = row [3]
> lastname = row [2]
>
This line is indented the same amount as the 'for' loop, which means
that it will be executed after the loop has finished.
> print "ma {} displayName '{}' sn '{}'".format(mail,name,lastname)
>
You don't need to close the file here because the 'with' statement will
do that for you.
> f.close()
> [........]
>
>
> Thanks.
>
[toc] | [prev] | [next] | [standalone]
| From | Mike <miguelcoam@gmail.com> |
|---|---|
| Date | 2014-01-14 11:54 -0800 |
| Message-ID | <75028f66-b36c-4b1d-b055-3beb05b66f8c@googlegroups.com> |
| In reply to | #63929 |
El martes, 14 de enero de 2014 16:32:49 UTC-3, MRAB escribió:
> On 2014-01-14 19:24, Mike wrote:
>
> > Hello,
>
> > I confudsed,need printer the value of list (this is reaer from csv) . The reader is ok, but my problem is in the print moment because printer only the last value. For example my csv is:
>
> >
>
> > [........]
>
> > user1@example.com;user1;lastName;Name
>
> > user2@example.com;user2;lastName;Name
>
> > [........]
>
> >
>
> > But when execute the script I view the print is only the last user
>
> >
>
> > [........]
>
> > ca user2@example.com displayName 'user2' sn 'lastName' cn 'Name'
>
> > [........]
>
> >
>
> > And I need the next printer
>
> >
>
> > [........]
>
> > ca user1@example.com displayName 'User1' sn ''lastName" cn 'Name'
>
> > ca user1@example.com displayName 'User2' sn ''lastName" cn 'Name'
>
> > [........]
>
> >
>
> > My script is
>
> >
>
> > [........]
>
> > #!/usr/bin/python
>
> > import csv
>
> > with open ('users.csv', 'rb') as f:
>
> >
>
> > reader = csv.reader (f, delimiter=';' ) #delimiter tabulador
>
> > for row in reader:
>
> >
>
> > mail = row [0]
>
> > name = row [3]
>
> > lastname = row [2]
>
> >
>
>
>
> This line is indented the same amount as the 'for' loop, which means
>
> that it will be executed after the loop has finished.
>
>
>
> > print "ma {} displayName '{}' sn '{}'".format(mail,name,lastname)
>
> >
>
> You don't need to close the file here because the 'with' statement will
>
> do that for you.
>
>
>
> > f.close()
>
> > [........]
>
> >
>
> >
>
> > Thanks.
>
> >
Hello MRAB,
I remove the "f.close" and after execute the script but still i have the same result (print the last row)
Thanks
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2014-01-14 20:03 +0000 |
| Message-ID | <mailman.5474.1389729800.18130.python-list@python.org> |
| In reply to | #63933 |
On 14/01/2014 19:54, Mike wrote:
> El martes, 14 de enero de 2014 16:32:49 UTC-3, MRAB escribió:
>> On 2014-01-14 19:24, Mike wrote:
>>
>>> Hello,
>>
>>> I confudsed,need printer the value of list (this is reaer from csv) . The reader is ok, but my problem is in the print moment because printer only the last value. For example my csv is:
>>
>>>
>>
>>> [........]
>>
>>> user1@example.com;user1;lastName;Name
>>
>>> user2@example.com;user2;lastName;Name
>>
>>> [........]
>>
>>>
>>
>>> But when execute the script I view the print is only the last user
>>
>>>
>>
>>> [........]
>>
>>> ca user2@example.com displayName 'user2' sn 'lastName' cn 'Name'
>>
>>> [........]
>>
>>>
>>
>>> And I need the next printer
>>
>>>
>>
>>> [........]
>>
>>> ca user1@example.com displayName 'User1' sn ''lastName" cn 'Name'
>>
>>> ca user1@example.com displayName 'User2' sn ''lastName" cn 'Name'
>>
>>> [........]
>>
>>>
>>
>>> My script is
>>
>>>
>>
>>> [........]
>>
>>> #!/usr/bin/python
>>
>>> import csv
>>
>>> with open ('users.csv', 'rb') as f:
>>
>>>
>>
>>> reader = csv.reader (f, delimiter=';' ) #delimiter tabulador
>>
>>> for row in reader:
>>
>>>
>>
>>> mail = row [0]
>>
>>> name = row [3]
>>
>>> lastname = row [2]
>>
>>>
>>
>>
>>
>> This line is indented the same amount as the 'for' loop, which means
>>
>> that it will be executed after the loop has finished.
>>
>>
>>
>>> print "ma {} displayName '{}' sn '{}'".format(mail,name,lastname)
>>
>>>
>>
>> You don't need to close the file here because the 'with' statement will
>>
>> do that for you.
>>
>>
>>
>>> f.close()
>>
>>> [........]
>>
>>>
>>
>>>
>>
>>> Thanks.
>>
>>>
>
> Hello MRAB,
> I remove the "f.close" and after execute the script but still i have the same result (print the last row)
>
> Thanks
>
Your print statement needs to be inside the for loop, you currently have
it after the loop has finished.
Would you also please read and action this
https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the
double line spacing above, thanks.
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
[toc] | [prev] | [next] | [standalone]
| From | Tim Chase <python.list@tim.thechases.com> |
|---|---|
| Date | 2014-01-14 13:38 -0600 |
| Message-ID | <mailman.5471.1389728238.18130.python-list@python.org> |
| In reply to | #63927 |
On 2014-01-14 11:24, Mike wrote:
> Hello,
> I confudsed,need printer the value of list (this is reaer from
> csv) . The reader is ok, but my problem is in the print moment
> because printer only the last value. For example my csv is:
>
> [........]
> user1@example.com;user1;lastName;Name
> user2@example.com;user2;lastName;Name
> [........]
>
> But when execute the script I view the print is only the last user
> with open ('users.csv', 'rb') as f:
>
> reader = csv.reader (f, delimiter=';' ) #delimiter tabulador
> for row in reader:
>
> mail = row [0]
> name = row [3]
> lastname = row [2]
>
> print "ma {} displayName '{}' sn '{}'".format(mail,name,lastname)
This print needs to be at the same indentation as the previous bit.
> f.close()
This .close() is superfluous--the "with" takes care of that for you.
I'd also unpack the row as I iterate to make it easier to read. That
would make the final look something like
with open("users.csv", "rb") as f:
reader = csv.reader(f, delimiter=';')
for mail, _, lastname, name in reader:
print "ca {} displayName '{}' sn '{}'".format(
mail, name, lastname)
-tkc
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web