Re: [Tutor] (no subject)

2010-05-11 Thread spir ☣
On Wed, 12 May 2010 00:35:27 -0500
Luke Paireepinart  wrote:

> I'd have rather you top-posted, then I wouldn't have wasted 30 seconds
> scrolling past a bunch of irrelevant crap that I just gloss over
> anyway.
> If I want context I'll read the previous messages in the thread.
> but that's just MHO.
> -Luke

The problem in this case is not bottom posting (or better: interleaved), rather 
the "bunch of irrelevant crap" let by the previous poster. Many use an email 
client feature that quotes all by default, and places the cusor at the end by 
default as well; which is fine in many cases. But then if they don't bother 
reviewing the post before sending, & "pruning" irrelevant parts, we get all 
that stupid stuff (and the new part at the end).
If the software would place the cursor on top...

MHO,
Denis


vit esse estrany ☣

spir.wikidot.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2010-05-11 Thread Luke Paireepinart
I'm just not going to quote previous threads because with my top-posting and
dave's bottom-posting and whatever the heck Siva's posting was... whatever.
 Read previous e-mails if you need context.

Siva is it possible that you accidentally installed the 64-bit version of
python 3.1?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2010-05-11 Thread Luke Paireepinart
I'd have rather you top-posted, then I wouldn't have wasted 30 seconds
scrolling past a bunch of irrelevant crap that I just gloss over
anyway.
If I want context I'll read the previous messages in the thread.
but that's just MHO.
-Luke

On Tue, May 11, 2010 at 9:28 PM, Dave Angel  wrote:
> (1. Please don't top-post.  It gets everything out of sequence, and is the
> wrong convention for this forum
> 2. Be sure and do a reply-all, so that the message goes to the forum.  I'm
> not here to give private advice.
> 3. Use your editor's reply-quoting so that we can tell who wrote which
> parts.  Normally, you'll see that as either a leading ">" character or as a
> "!" character.  And one can tell which parts were written by whom by
> counting the number of those at the beginning of each line)
>
> For my real response, see the end of the message, where it belongs.
>
> Sivapathasuntha Aruliah wrote:
>>
>> Dave
>> Thank you very much for your response. I think I have problem with both
>> Python23 & Python31. Please help.
>>
>> Python23 : The program works but programs written by Mark Summerfield in
>> his book Programming in Python3 does not work.
>> Python 31: When I run this program it says in the pop up window "
>> C:\py3eg\csv2html1_ans.py is not a valid Win32 application" and on the the
>> dos box it says Access is denied.
>> Below is the dos box contents
>>
>>
>> C:\>cd python31
>>
>> C:\Python31>python C:\py3eg\quadratic.py
>> Access is denied.
>>
>> C:\Python31>python C:\py3eg\quadratic.py
>> Access is denied.
>>
>> C:\Python31>python C:\py3eg\hello.py
>> Access is denied.
>>
>> C:\Python31>python.exe C:\py3eg\hello.py
>> Access is denied.
>>
>> C:\Python31>cd..
>>
>> C:\>cd python23
>>
>> C:\Python23>python.exe C:\py3eg\hello.py
>> ('Hello', 'World!')
>>
>> C:\Python23>python.exe C:\py3eg\print_unicode.py
>> Traceback (most recent call last):
>>  File "C:\py3eg\print_unicode.py", line 30, in ?
>>    print_unicode_table(word)
>> NameError: name 'print_unicode_table' is not defined
>>
>> C:\Python23>python.exe C:\py3eg\quadratic.py
>>  File "C:\py3eg\quadratic.py", line 14
>>    except ValueError as err:
>>                       ^
>> SyntaxError: invalid syntax
>>
>>
>>
>>
>> Regards,
>> Siva
>> Test Equipment Engineering
>> Amkor Technology (S) Pte Ltd
>> 1 Kaki Bukit View
>> #03-28 TechView Building
>> Singapore 415941
>> Tel: (65) 6347 1131
>> Fax: (65) 6746 4815
>>
>>
>>
>> Dave Angel 
>>
>>
>> 05/12/2010 09:50 AM
>>
>>
>> To
>> Sivapathasuntha Aruliah/S1/a...@amkor
>> cc
>> tutor@python.org
>> Subject
>> Re: [Tutor] (no subject)
>>
>>
>>
>>
>>
>>
>>
>>
>> Sivapathasuntha Aruliah wrote:
>>
>>>
>>> Hi
>>> I am learning Python. When I tried to run any of the program for example
>>>
>>
>>
>>>
>>> csv2html1_ans.py it displays the following message. This error is coming
>>>
>>
>>
>>>
>>> on both Python24 & Python 31. That is whether i give the any one of the
>>> following command
>>>
>>> COMMAND GIVEN
>>> 1.C:\python24\python.exe C:\py3eg\quadratic.py
>>> 2.C:\python31\python.exe C:\py3eg\quadratic.py
>>>
>>> A message below appears with the program name. Please advice me how to
>>>
>>
>> get
>>>
>>> over from this issue
>>> ERROR MESSAGE
>>> command  C:\py3eg\csv2html1_ans.py is not a valid Win32 application
>>>
>>> Regards,
>>> Siva
>>> Test Equipment Engineering
>>> Amkor Technology (S) Pte Ltd
>>> 1 Kaki Bukit View
>>> #03-28 TechView Building
>>> Singapore 415941
>>> Tel: (65) 6347 1131
>>> Fax: (65) 6746 4815
>>>
>>>
>>
>> Please copy and paste the actual contents of your DOS box, rather than
>> paraphrasing.  COMMAND hasn't been the normal shell name since Win95 days.
>>  You can't use numbers in front of commands in any shell I've used.  The
>> error message refers to a different file than anything you specified in your
>> commands.
>>
>> What OS are you using?
>>
>> DaveA
>>
>>
>>
>>
>
> Again, what OS are you using?
>
> I have no idea what the pop up comes from, but I suspect you have some
> non-trivial code in that python program, perhaps that creates a gui.  Is
> there any tkinter stuff in it?
>
> As for "Access is Denied", it usually means you tried to access a
> non-existent drive, or one which isn't currently mounted.  For example,
> referencing your CD drive with no platter in it.
>
> I don't know why "print_unicode_table" is undefined, but apparently you're
> missing some code.
>
>
> And the except clause changed between 2.x and 3.x, so you need to change the
> syntax to match the particular interpreter you're using.  They're not
> compatible, although there's a utility to convert from 2.x to 3.x, I don't
> think there's anything that reverses it.
>
> I'd suggest picking one version, and using only books and references that
> are compatible with it till you're comfortable with the language.
>
> DaveA
>
> ___
> Tutor maillist  -  tu...@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>

Re: [Tutor] (no subject)

2010-05-11 Thread ramya natarajan
I really thank you all for  the quick response,   It was really helpful!!

On Tue, May 11, 2010 at 7:28 PM, Dave Angel  wrote:

> (1. Please don't top-post.  It gets everything out of sequence, and is the
> wrong convention for this forum
> 2. Be sure and do a reply-all, so that the message goes to the forum.  I'm
> not here to give private advice.
> 3. Use your editor's reply-quoting so that we can tell who wrote which
> parts.  Normally, you'll see that as either a leading ">" character or as a
> "!" character.  And one can tell which parts were written by whom by
> counting the number of those at the beginning of each line)
>
> For my real response, see the end of the message, where it belongs.
>
> Sivapathasuntha Aruliah wrote:
>
>> Dave
>> Thank you very much for your response. I think I have problem with both
>> Python23 & Python31. Please help.
>>
>> Python23 : The program works but programs written by Mark Summerfield in
>> his book Programming in Python3 does not work.
>> Python 31: When I run this program it says in the pop up window "
>> C:\py3eg\csv2html1_ans.py is not a valid Win32 application" and on the the
>> dos box it says Access is denied.
>> Below is the dos box contents
>>
>>
>> C:\>cd python31
>>
>> C:\Python31>python C:\py3eg\quadratic.py
>> Access is denied.
>>
>> C:\Python31>python C:\py3eg\quadratic.py
>> Access is denied.
>>
>> C:\Python31>python C:\py3eg\hello.py
>> Access is denied.
>>
>> C:\Python31>python.exe C:\py3eg\hello.py
>> Access is denied.
>>
>> C:\Python31>cd..
>>
>> C:\>cd python23
>>
>> C:\Python23>python.exe C:\py3eg\hello.py
>> ('Hello', 'World!')
>>
>> C:\Python23>python.exe C:\py3eg\print_unicode.py
>> Traceback (most recent call last):
>>  File "C:\py3eg\print_unicode.py", line 30, in ?
>>print_unicode_table(word)
>> NameError: name 'print_unicode_table' is not defined
>>
>> C:\Python23>python.exe C:\py3eg\quadratic.py
>>  File "C:\py3eg\quadratic.py", line 14
>>except ValueError as err:
>>   ^
>> SyntaxError: invalid syntax
>>
>>
>>
>>
>> Regards,
>> Siva
>> Test Equipment Engineering
>> Amkor Technology (S) Pte Ltd
>> 1 Kaki Bukit View
>> #03-28 TechView Building
>> Singapore 415941
>> Tel: (65) 6347 1131
>> Fax: (65) 6746 4815
>>
>>
>>
>> Dave Angel 
>>
>>
>> 05/12/2010 09:50 AM
>>
>>
>> To
>> Sivapathasuntha Aruliah/S1/a...@amkor
>> cc
>> tutor@python.org
>> Subject
>> Re: [Tutor] (no subject)
>>
>>
>>
>>
>>
>>
>>
>>
>> Sivapathasuntha Aruliah wrote:
>>
>>
>>> Hi
>>> I am learning Python. When I tried to run any of the program for example
>>>
>>>
>>
>>
>>
>>> csv2html1_ans.py it displays the following message. This error is coming
>>>
>>>
>>
>>
>>
>>> on both Python24 & Python 31. That is whether i give the any one of the
>>> following command
>>>
>>> COMMAND GIVEN
>>> 1.C:\python24\python.exe C:\py3eg\quadratic.py
>>> 2.C:\python31\python.exe C:\py3eg\quadratic.py
>>>
>>> A message below appears with the program name. Please advice me how to
>>>
>>>
>> get
>>
>>> over from this issue
>>> ERROR MESSAGE
>>> command  C:\py3eg\csv2html1_ans.py is not a valid Win32 application
>>>
>>> Regards,
>>> Siva
>>> Test Equipment Engineering
>>> Amkor Technology (S) Pte Ltd
>>> 1 Kaki Bukit View
>>> #03-28 TechView Building
>>> Singapore 415941
>>> Tel: (65) 6347 1131
>>> Fax: (65) 6746 4815
>>>
>>>
>>>
>> Please copy and paste the actual contents of your DOS box, rather than
>> paraphrasing.  COMMAND hasn't been the normal shell name since Win95 days.
>>  You can't use numbers in front of commands in any shell I've used.  The
>> error message refers to a different file than anything you specified in your
>> commands.
>>
>> What OS are you using?
>>
>> DaveA
>>
>>
>>
>>
>>
> Again, what OS are you using?
>
> I have no idea what the pop up comes from, but I suspect you have some
> non-trivial code in that python program, perhaps that creates a gui.  Is
> there any tkinter stuff in it?
>
> As for "Access is Denied", it usually means you tried to access a
> non-existent drive, or one which isn't currently mounted.  For example,
> referencing your CD drive with no platter in it.
>
> I don't know why "print_unicode_table" is undefined, but apparently you're
> missing some code.
>
>
> And the except clause changed between 2.x and 3.x, so you need to change
> the syntax to match the particular interpreter you're using.  They're not
> compatible, although there's a utility to convert from 2.x to 3.x, I don't
> think there's anything that reverses it.
>
> I'd suggest picking one version, and using only books and references that
> are compatible with it till you're comfortable with the language.
>
> DaveA
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/l

Re: [Tutor] (no subject)

2010-05-11 Thread Dave Angel
(1. Please don't top-post.  It gets everything out of sequence, and is 
the wrong convention for this forum
2. Be sure and do a reply-all, so that the message goes to the forum.  
I'm not here to give private advice.
3. Use your editor's reply-quoting so that we can tell who wrote which 
parts.  Normally, you'll see that as either a leading ">" character or 
as a "!" character.  And one can tell which parts were written by whom 
by counting the number of those at the beginning of each line)


For my real response, see the end of the message, where it belongs.

Sivapathasuntha Aruliah wrote:

Dave
Thank you very much for your response. I think I have problem with both 
Python23 & Python31. Please help.


Python23 : The program works but programs written by Mark Summerfield in 
his book Programming in Python3 does not work.

Python 31: When I run this program it says in the pop up window "
C:\py3eg\csv2html1_ans.py is not a valid Win32 application" and on the the 
dos box it says Access is denied.

Below is the dos box contents


C:\>cd python31

C:\Python31>python C:\py3eg\quadratic.py
Access is denied.

C:\Python31>python C:\py3eg\quadratic.py
Access is denied.

C:\Python31>python C:\py3eg\hello.py
Access is denied.

C:\Python31>python.exe C:\py3eg\hello.py
Access is denied.

C:\Python31>cd..

C:\>cd python23

C:\Python23>python.exe C:\py3eg\hello.py
('Hello', 'World!')

C:\Python23>python.exe C:\py3eg\print_unicode.py
Traceback (most recent call last):
  File "C:\py3eg\print_unicode.py", line 30, in ?
print_unicode_table(word)
NameError: name 'print_unicode_table' is not defined

C:\Python23>python.exe C:\py3eg\quadratic.py
  File "C:\py3eg\quadratic.py", line 14
except ValueError as err:
   ^
SyntaxError: invalid syntax




Regards,
Siva
Test Equipment Engineering
Amkor Technology (S) Pte Ltd
1 Kaki Bukit View
#03-28 TechView Building
Singapore 415941
Tel: (65) 6347 1131
Fax: (65) 6746 4815



Dave Angel 


05/12/2010 09:50 AM


To
Sivapathasuntha Aruliah/S1/a...@amkor
cc
tutor@python.org
Subject
Re: [Tutor] (no subject)








Sivapathasuntha Aruliah wrote:
  

Hi
I am learning Python. When I tried to run any of the program for example 



  
csv2html1_ans.py it displays the following message. This error is coming 



  
on both Python24 & Python 31. That is whether i give the any one of the 
following command


COMMAND GIVEN
1.C:\python24\python.exe C:\py3eg\quadratic.py
2.C:\python31\python.exe C:\py3eg\quadratic.py

A message below appears with the program name. Please advice me how to 

get 
  

over from this issue
ERROR MESSAGE
command  C:\py3eg\csv2html1_ans.py is not a valid Win32 application

Regards,
Siva
Test Equipment Engineering
Amkor Technology (S) Pte Ltd
1 Kaki Bukit View
#03-28 TechView Building
Singapore 415941
Tel: (65) 6347 1131
Fax: (65) 6746 4815


Please copy and paste the actual contents of your DOS box, rather than 
paraphrasing.  COMMAND hasn't been the normal shell name since Win95 
days.  You can't use numbers in front of commands in any shell I've 
used.  The error message refers to a different file than anything you 
specified in your commands.


What OS are you using?

DaveA



  

Again, what OS are you using?

I have no idea what the pop up comes from, but I suspect you have some 
non-trivial code in that python program, perhaps that creates a gui.  Is 
there any tkinter stuff in it?


As for "Access is Denied", it usually means you tried to access a 
non-existent drive, or one which isn't currently mounted.  For example, 
referencing your CD drive with no platter in it.


I don't know why "print_unicode_table" is undefined, but apparently 
you're missing some code.



And the except clause changed between 2.x and 3.x, so you need to change 
the syntax to match the particular interpreter you're using.  They're 
not compatible, although there's a utility to convert from 2.x to 3.x, I 
don't think there's anything that reverses it.


I'd suggest picking one version, and using only books and references 
that are compatible with it till you're comfortable with the language.


DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help required to count no of lines that are until 1000 characters

2010-05-11 Thread Dave Angel

ramya natarajan wrote:

Hello,

I am very  beginner to programming, I  got task to Write a loop that 
reads
each line of a file and counts the number of lines that are read until 
the

total length of the lines is 1,000 characters. I have to read lines from
files exactly upto 1000 characters.

Here is my code:
 I created file under /tmp/new.txt  which has 100 lines and 2700 
characters
, I wrote code will read exactly 1000 characters and count lines upto 
those

characters.But the problem is its reading entire line and not stopping
excatly in 1000 characters. Can some one help what mistake i am doing 
here?.


   log = open('/tmp/new.txt','r')
   lines,char = 0,0
   for line in log.readlines():
while char < 1000 :
for ch in line :
 char += len(ch)
lines += 1
  print char , lines
  1026 , 38    Its counting entire line  instead of character upto 
1000

-- can some one point out what mistake am i doing here , where its not
stopping at 1000 . I am reading only char by car

My new.txt -- cotains content like
this is my new number\n

Can some one please help. I spent hours and hours to find issue but i 
am not

able to figure out, Any help would be greatly appreciated.
Thank you
Ramya

  
The problem is ill-specified (contradictory).  It'd probably be better 
to give the exact wording of the assignment.


If you read each line of the file, then it would only be a coincidence 
if you read exactly 1000 characters, as most likely one of those lines 
will overlap the 1000 byte boundary.



But you have a serious bug in your code, that nobody in the first five 
responses has addressed.  That while loop will loop over the first line 
repeatedly, till it reaches or exceeds 1000, regardless of the length of 
subsequent lines.  So it really just divides 1000 by the length of that 
first line.  Notice that the lines += 1 will execute multiple times for 
a single iteration of the for loop.


Second, once 1000 is reached, the for loop does not quit.  So it will 
read the rest of the file, regardless of how big the file is.  It just 
stops adding to lines or char, since char reached 1000 on the first line.


The simplest change to your code which might accomplish what you want is 
to put the whole thing inside a function, and return from the function 
when the goal is reached.  So instead of a while loop, you need some 
form of if test.  See if you can run with that.  Remember that return 
can return a tuple (pair of numbers).


There are plenty of other optimizations and approaches, but you'll learn 
best by incrementally fixing what you already have.


DaveA





___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2010-05-11 Thread Dave Angel

Sivapathasuntha Aruliah wrote:

Hi
I am learning Python. When I tried to run any of the program for example 
csv2html1_ans.py it displays the following message. This error is coming 
on both Python24 & Python 31. That is whether i give the any one of the 
following command


COMMAND GIVEN
1.C:\python24\python.exe C:\py3eg\quadratic.py
2.C:\python31\python.exe C:\py3eg\quadratic.py

A message below appears with the program name. Please advice me how to get 
over from this issue

ERROR MESSAGE
command  C:\py3eg\csv2html1_ans.py is not a valid Win32 application

Regards,
Siva
Test Equipment Engineering
Amkor Technology (S) Pte Ltd
1 Kaki Bukit View
#03-28 TechView Building
Singapore 415941
Tel: (65) 6347 1131
Fax: (65) 6746 4815
  
Please copy and paste the actual contents of your DOS box, rather than 
paraphrasing.  COMMAND hasn't been the normal shell name since Win95 
days.  You can't use numbers in front of commands in any shell I've 
used.  The error message refers to a different file than anything you 
specified in your commands.


What OS are you using?

DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help required to count no of lines that are until 1000 characters

2010-05-11 Thread Alan Gauld


"spir ☣"  wrote

Either you read line per line, but then you cannot stop exactly at the 1000th 
character;

or you traverse the text char per char, but this is a bit picky.


Or you could just read 1000 chars from the file then pick out the lines from 
that.

But that requires you to count newlines as characters! :-)

HTH,

Alan G.


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] An interesting situation befalls me

2010-05-11 Thread Eric Dorsey
> On Sat, May 8, 2010 at 5:31 PM, Kirk Z Bailey wrote:
>>
>>> An instructor of mine is about to teach the FIRST EVER class in Python at
>>> Saint Petersburg College; knowing I am a snakecharmer, he asked me for
>>> referrals to online resources.
>>>
>>> Oh my.
>>>
>>
>
> Here is another resource, the Byte of Python book:

http://www.swaroopch.com/notes/Python_en:Table_of_Contents

The online version is free, or you can buy the book.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2010-05-11 Thread Alan Gauld


"Sivapathasuntha Aruliah"  wrote

I am learning Python. When I tried to run any of the program for example 
csv2html1_ans.py it displays the following message. This error is coming 
on both Python24 & Python 31. That is whether i give the any one of the 
following command


COMMAND GIVEN
1.C:\python24\python.exe C:\py3eg\quadratic.py
2.C:\python31\python.exe C:\py3eg\quadratic.py

A message below appears with the program name. Please advice me how to get 
over from this issue

ERROR MESSAGE
command  C:\py3eg\csv2html1_ans.py is not a valid Win32 application


How are you running the commands? In a DOS box?
Which OS version is it? I get a different error message in XP:

C:\Documents and Settings\Alan Gauld>ghfghfghfh
'ghfghfghfh' is not recognized as an internal or external command,
operable program or batch file.

If it is a DOS box then what you are doing should work, but the error suggests 
it is trying to treat the argument as a program which should not happen!


HTH,

--
Alan Gauld
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] Help required to count no of lines that are until 1000characters

2010-05-11 Thread Alan Gauld

"ramya natarajan"  wrote


characters.But the problem is its reading entire line and not stopping
excatly in 1000 characters. 


Do you really need to stop reading the file at 1000 characters rather 
than the line containing the 1000th character? That seems a very 
arbitrary sort of thing to do.



Can some one help what mistake i am doing here?.

  log = open('/tmp/new.txt','r')
  lines,char = 0,0
  for line in log.readlines():
   while char < 1000 :
   for ch in line :
char += len(ch)
   lines += 1


The problem is that the inner for loop will always process every 
character in the line. You want to stop (or break) from the for loop 
when char gets to 1000. So you need to insert a test inside the for 
loop. Or don't use the for loop and use an index to get the characters 
within your while loop.


BTW You don't want to add the length of the characters you just 
want to add 1...



stopping at 1000 . I am reading only char by car


No you are not, you are reading all the chars in every line 
that you read from the file. In fact even if you fix this loop 
error you will still be reading the full line from the file. 
Thats why I asked if you really had to stop reading the 
file at 1000 chars, because if so this design is fundamentally 
wrong.


But I suspect you only need to stop reading at the line 
containing the 1000th char... If that is so there is an easier 
way to do it:


# pseudo code
chars = 0
for count, line in enumerate(file)
if chars + len(line) < 1000
   chars += len(line)
else: break
print "1000 chars read in", count, "lines"

HTH,

--
Alan Gauld
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] Help required to count no of lines that are until 1000 characters

2010-05-11 Thread शंतनू

On 12-May-2010, at 12:32 AM, spir ☣ wrote:

> On Tue, 11 May 2010 11:00:20 -0700
> ramya natarajan  wrote:
> 
>> Hello,
>> 
>> I am very  beginner to programming, I  got task to Write a loop that reads
>> each line of a file and counts the number of lines that are read until the
>> total length of the lines is 1,000 characters. I have to read lines from
>> files exactly upto 1000 characters.
>> 
>> Here is my code:
>> I created file under /tmp/new.txt  which has 100 lines and 2700 characters
>> , I wrote code will read exactly 1000 characters and count lines upto those
>> characters.But the problem is its reading entire line and not stopping
>> excatly in 1000 characters. Can some one help what mistake i am doing here?.
>> 
>>   log = open('/tmp/new.txt','r')
>>   lines,char = 0,0
>>   for line in log.readlines():
>>while char < 1000 :
>>for ch in line :
>> char += len(ch)
>>lines += 1
>>  print char , lines
>>  1026 , 38    Its counting entire line  instead of character upto 1000
>> -- can some one point out what mistake am i doing here , where its not
>> stopping at 1000 . I am reading only char by car
>> 
>> My new.txt -- cotains content like
>> this is my new number\n
>> 
>> Can some one please help. I spent hours and hours to find issue but i am not
>> able to figure out, Any help would be greatly appreciated.
>> Thank you
>> Ramya
> 
> Either you read line per line, but then you cannot stop exactly at the 1000th 
> character; or you traverse the text char per char, but this is a bit picky.
> I would read line per line, and when count >= 1000, read chars inside current 
> line to get to the 1000th, if needed.
> (Your specification does not state this, but your disappointment seems to be 
> about that issue ;-)
> 
> Denis

You can try read instead of readlines.
Something like...
print 'Number of lines till 1000th character:', 
len(open('/tmp/new.txt','r').read(1000).split('\n'))

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help required to count no of lines that are until 1000 characters

2010-05-11 Thread spir ☣
On Tue, 11 May 2010 11:00:20 -0700
ramya natarajan  wrote:

> Hello,
> 
> I am very  beginner to programming, I  got task to Write a loop that reads
> each line of a file and counts the number of lines that are read until the
> total length of the lines is 1,000 characters. I have to read lines from
> files exactly upto 1000 characters.
> 
> Here is my code:
>  I created file under /tmp/new.txt  which has 100 lines and 2700 characters
> , I wrote code will read exactly 1000 characters and count lines upto those
> characters.But the problem is its reading entire line and not stopping
> excatly in 1000 characters. Can some one help what mistake i am doing here?.
> 
>log = open('/tmp/new.txt','r')
>lines,char = 0,0
>for line in log.readlines():
> while char < 1000 :
> for ch in line :
>  char += len(ch)
> lines += 1
>   print char , lines
>   1026 , 38    Its counting entire line  instead of character upto 1000
> -- can some one point out what mistake am i doing here , where its not
> stopping at 1000 . I am reading only char by car
> 
> My new.txt -- cotains content like
> this is my new number\n
> 
> Can some one please help. I spent hours and hours to find issue but i am not
> able to figure out, Any help would be greatly appreciated.
> Thank you
> Ramya

Either you read line per line, but then you cannot stop exactly at the 1000th 
character; or you traverse the text char per char, but this is a bit picky.
I would read line per line, and when count >= 1000, read chars inside current 
line to get to the 1000th, if needed.
(Your specification does not state this, but your disappointment seems to be 
about that issue ;-)

Denis


vit esse estrany ☣

spir.wikidot.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help required to count no of lines that are until 1000 characters

2010-05-11 Thread Luke Paireepinart
On Tue, May 11, 2010 at 1:00 PM, ramya natarajan  wrote:
> Hello, I have to read lines from
> files exactly upto 1000 characters.
>But the problem is its reading entire line and not stopping
> excatly in 1000 characters. Can some one help what mistake i am doing here?.
>
>    log = open('/tmp/new.txt','r')
>    lines,char = 0,0
>    for line in log.readlines():
>     while char < 1000 :
>     for ch in line :
>  char += len(ch)
>     lines += 1
>   print char , lines

here's the pseudocode of what you're doing, it might help you
understand what the problem is:
for every line in the file:
if the character count is less than 1000, add the length of the
current line.

You are missing a condition.

Here is another version of your code that has the same problem, see if
this helps make it clearer:
lines, chars = 0,0
with open('/temp/new.txt') as f:
for line in f:
if chars > 1000: break
chars += len(line)


This sounds a lot like a homework problem so I won't give you the
answer, but I hope that helps.


Also do you realize you are counting newlines as well?  You may not
want to do this, depending on your intended application.

Hope that helps,
-Luke
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Help required to count no of lines that are until 1000 characters

2010-05-11 Thread ramya natarajan
Hello,

I am very  beginner to programming, I  got task to Write a loop that reads
each line of a file and counts the number of lines that are read until the
total length of the lines is 1,000 characters. I have to read lines from
files exactly upto 1000 characters.

Here is my code:
 I created file under /tmp/new.txt  which has 100 lines and 2700 characters
, I wrote code will read exactly 1000 characters and count lines upto those
characters.But the problem is its reading entire line and not stopping
excatly in 1000 characters. Can some one help what mistake i am doing here?.

   log = open('/tmp/new.txt','r')
   lines,char = 0,0
   for line in log.readlines():
while char < 1000 :
for ch in line :
 char += len(ch)
lines += 1
  print char , lines
  1026 , 38    Its counting entire line  instead of character upto 1000
-- can some one point out what mistake am i doing here , where its not
stopping at 1000 . I am reading only char by car

My new.txt -- cotains content like
this is my new number\n

Can some one please help. I spent hours and hours to find issue but i am not
able to figure out, Any help would be greatly appreciated.
Thank you
Ramya
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2010-05-11 Thread Vincent Davis
probably need to do something like
python C:\py3eg\quadratic.py

your cmd prompt/shell should know "python" is a command


On Tue, May 11, 2010 at 2:43 AM, Sivapathasuntha Aruliah <
sivapathasuntha.arul...@amkor.com> wrote:

>
> Hi
> I am learning Python. When I tried to run any of the program for example
> csv2html1_ans.py it displays the following message. This error is coming on
> both Python24 & Python 31. That is whether i give the any one of the
> following command
>
> *COMMAND GIVEN*
> 1.C:\python24\python.exe C:\py3eg\quadratic.py
> 2.C:\python31\python.exe C:\py3eg\quadratic.py
>
> A message below appears with the program name. Please advice me how to get
> over from this issue
> *ERROR MESSAGE*
> command  C:\py3eg\csv2html1_ans.py is not a valid Win32 application
>
> Regards,
> Siva
> Test Equipment Engineering
> Amkor Technology (S) Pte Ltd
> 1 Kaki Bukit View
> #03-28 TechView Building
> Singapore 415941
> Tel: (65) 6347 1131
> Fax: (65) 6746 4815
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
  *Vincent Davis
720-301-3003 *
vinc...@vincentdavis.net
 my blog  |
LinkedIn
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] (no subject)

2010-05-11 Thread Sivapathasuntha Aruliah
Hi
I am learning Python. When I tried to run any of the program for example 
csv2html1_ans.py it displays the following message. This error is coming 
on both Python24 & Python 31. That is whether i give the any one of the 
following command

COMMAND GIVEN
1.C:\python24\python.exe C:\py3eg\quadratic.py
2.C:\python31\python.exe C:\py3eg\quadratic.py

A message below appears with the program name. Please advice me how to get 
over from this issue
ERROR MESSAGE
command  C:\py3eg\csv2html1_ans.py is not a valid Win32 application

Regards,
Siva
Test Equipment Engineering
Amkor Technology (S) Pte Ltd
1 Kaki Bukit View
#03-28 TechView Building
Singapore 415941
Tel: (65) 6347 1131
Fax: (65) 6746 4815___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] displaying clock and/or elapsed time

2010-05-11 Thread Steven D'Aprano
On Tue, 11 May 2010 11:54:13 pm Art Kendall wrote:
> I am learning python and I want to see how long parts of of a process
> take.  Are there system variables that can just be displayed?
> how do I get variables that contain the wall time (x) and the elapsed
> time (y)?

Get the current time in seconds since the start of the universe (10am on 
January 1st 1970 on Linux systems, it may be slightly different on 
Windows or Macintosh):

>>> import time
>>> time.time()
1273588356.8070121


Get the current time in a more human-readable fashion:

>>> time.ctime()
'Wed May 12 00:33:22 2010'


Get the elapsed time:


>>> start = time.time()  # save the current time
>>> for i in range(1000):  # do some work
... pass
...
>>> elapsed = time.time() - start
>>> print "work took %f seconds" % elapsed
work took 0.015870 seconds


See the documentation for the time module:

http://docs.python.org/library/time.html

That's a bit technical and newbie-unfriendly, so you might also like to 
read this:

http://effbot.org/librarybook/time.htm

although it's very old and parts of it are obsolete.



-- 
Steven D'Aprano
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] displaying clock and/or elapsed time

2010-05-11 Thread Art Kendall
I am learning python and I want to see how long parts of of a process 
take.  Are there system variables that can just be displayed?
how do I get variables that contain the wall time (x) and the elapsed 
time (y)?


I would like to put little messages on the screen while I am developing 
a python script so I can see how long things are taking.


Is it something like
print ' starting part1' (x y)
to put the times on the screen?

Is it something like
logfile.write( x,y)
to put the times in the log file.


Art



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor