Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Strange problem when running python code

Reply
Thread Tools

Strange problem when running python code

 
 
ishtar2020
Guest
Posts: n/a
 
      04-04-2006
Hi everybody

I've been writing my very first application in Python and everything is
running smoothly, except for a strange problem that pops up every once
in a while. I'm sure is the kind
of newbie thing every seasoned programmer knows.

Sometimes a receive strange Syntax Errors from parts of code that
worked perfectly minutes ago. What's even more puzzling is that those
errors are pointed to another part of the module when I do some random,
innofensive changes in the code (like inserting a line or deleting some
comments). Sometimes those changes are enough to make the error
dissapear.

Could it be that python has found a real error but is failing to tell
me where it is?

 
Reply With Quote
 
 
 
 
Brian Beck
Guest
Posts: n/a
 
      04-04-2006
For certain errors like Syntax Errors, you'll get a much more helpful
response if you post some actual code. Strip it down if you have to,
but make sure we can reproduce the errors.

--
Brian Beck
Adventurer of the First Order

 
Reply With Quote
 
 
 
 
John Salerno
Guest
Posts: n/a
 
      04-04-2006
ishtar2020 wrote:
> Hi everybody
>
> I've been writing my very first application in Python and everything is
> running smoothly, except for a strange problem that pops up every once
> in a while. I'm sure is the kind
> of newbie thing every seasoned programmer knows.
>
> Sometimes a receive strange Syntax Errors from parts of code that
> worked perfectly minutes ago. What's even more puzzling is that those
> errors are pointed to another part of the module when I do some random,
> innofensive changes in the code (like inserting a line or deleting some
> comments). Sometimes those changes are enough to make the error
> dissapear.
>
> Could it be that python has found a real error but is failing to tell
> me where it is?
>


I recently had quite a hassle with an indentation problem, so you might
want to check on your whitespace.

 
Reply With Quote
 
Fredrik Lundh
Guest
Posts: n/a
 
      04-04-2006
"ishtar2020" wrote:

> Sometimes a receive strange Syntax Errors from parts of code that
> worked perfectly minutes ago. What's even more puzzling is that those
> errors are pointed to another part of the module when I do some random,
> innofensive changes in the code (like inserting a line or deleting some
> comments). Sometimes those changes are enough to make the error
> dissapear.


Python 2.4.1 has a bug where this can happen if you're 1) using coding
directives, and 2) your module is relatively large.

I suggest upgrading to 2.4.3.

</F>



 
Reply With Quote
 
Roy Smith
Guest
Posts: n/a
 
      04-04-2006
ishtar2020 <(E-Mail Removed)> wrote:
>I've been writing my very first application in Python and everything is
>running smoothly, except for a strange problem that pops up every once
>in a while. I'm sure is the kind
>of newbie thing every seasoned programmer knows.


Nobody here has a crystal ball. Please post your code, tell us what
changes you made, and cut-and-paste the entire error message and the
associated stack trace.


 
Reply With Quote
 
ishtar2020
Guest
Posts: n/a
 
      04-04-2006
I must add, when the python interpreter displays the traceback, with
the line that is producing the error, it doesn't look like the one I
got in the code.

This is the line where the interpreter finds the error

if text.list[i].toString() in limits:list)): <- Here is where
the error is found, but this line is not on my file

SyntaxError: invalid syntax

And this is the line I got on the file, looks like the interpreter is
mixing the second sentence with the end of the first one:

for i in range(self.initialPositionl+1,len(text.list)):
if text.list[i].toString() in limits:
self.finalPosition=i
break

It's quite puzzling. And if I change some lousy thing, like inserting a
newline between the sentences, the interpreter will find another error
somewhere else, even when that
part of the code was working flawlessly in previous runs

 
Reply With Quote
 
Steve Juranich
Guest
Posts: n/a
 
      04-04-2006
Roy Smith wrote:

> ishtar2020 <(E-Mail Removed)> wrote:
>>I've been writing my very first application in Python and everything is
>>running smoothly, except for a strange problem that pops up every once
>>in a while. I'm sure is the kind
>>of newbie thing every seasoned programmer knows.

>
> Nobody here has a crystal ball. Please post your code, tell us what
> changes you made, and cut-and-paste the entire error message and the
> associated stack trace.


Speak for yourself, Mr. I-Have-No-Crystal-Ball. Besides, any lummox knows
that crystal balls are for seeing the future, not for mind-reading. No, to
do proper mind reading you need youself a pointy hat and (preferably) a
deck of cards.

Sorry, weird day at work. Had to vent.
--
Steve Juranich
Tucson, AZ
USA

 
Reply With Quote
 
James Stroud
Guest
Posts: n/a
 
      04-04-2006
ishtar2020 wrote:
> Hi everybody
>
> I've been writing my very first application in Python and everything is
> running smoothly, except for a strange problem that pops up every once
> in a while. I'm sure is the kind
> of newbie thing every seasoned programmer knows.
>
> Sometimes a receive strange Syntax Errors from parts of code that
> worked perfectly minutes ago. What's even more puzzling is that those
> errors are pointed to another part of the module when I do some random,
> innofensive changes in the code (like inserting a line or deleting some
> comments). Sometimes those changes are enough to make the error
> dissapear.
>
> Could it be that python has found a real error but is failing to tell
> me where it is?
>


I don't mean to accuse you or to start a tab v. non-tab war (is tab v.
non-tab a holy war?, it should be because tabs are so damn useful for
formatting and getting everything just-right), but don't use tabs if you
are using them. Here are the reasons: 1. they personally annoy me. 2.
you can't see the damn things (hence the basis for why they are so
annoying). "Tab" comes from the root for the Greek for "table" (or is it
the other way around?, or is it Latin? or Arabic? or Hebrew?). Thus,
tabs should be reserved for thier god-given intended purpose, which is
tab-delimited tables, where a parser can easily separate by them.
Internal, and hence annoying, tabs should not be used elsewhere because
it screws everything up. For example, here is a tab-delimited parser
written in python


table = []
for line in tab_delimited_table:
table.append(line.split('\t'))


Man that was easy! Now, when people put annoying tabs everywhere, to get
their indent just-so, then it totally screws everything up, including
this parser, which was designed for tables delimited by tabs--because
that is the tab's special purpose.

There is one exception however. Its called the tab-space-tab approach.
If you are using tabs to indent your code, then always put at least one
space between tabs. Never put two tabs together. This helps the editor
to display your code correctly.

James

--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
 
Reply With Quote
 
Christopher Weimann
Guest
Posts: n/a
 
      04-04-2006
On 04/04/2006-12:01PM, ishtar2020 wrote:
> This is the line where the interpreter finds the error
>
> if text.list[i].toString() in limits:list)): <- Here is where


That line has two extra close parens before the :

Can you show the traceback?

 
Reply With Quote
 
sushant.sirsikar@gmail.com
Guest
Posts: n/a
 
      04-05-2006
Are U Using any IDE for Python?
If yes then check out the setting and make sure that u are running same
code.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in running a basic code in python 3.3.0 that includes HTML file Satabdi Mukherjee Python 1 04-04-2013 07:48 PM
C Python: Running Python code within function scope channel727272@gmail.com Python 1 09-04-2012 10:18 PM
modify a long-running python script while it is running? Benjamin Rutt Python 2 12-20-2005 01:42 PM
RE: Strange problem running app remotely Jim Cheshire [MSFT] ASP .Net 6 07-22-2004 02:14 AM
Question About Strange 'C' Code Syntax ( Well strange to me anyway ) Harvey Twyman C Programming 8 10-25-2003 05:54 AM



Advertisments