Re: Problem with the for loop syntax

2013-06-21 Thread Neil Cerutti
On 2013-06-20, Cameron Simpson c...@zip.com.au wrote:
 On 20Jun2013 13:55, Neil Cerutti ne...@norwich.edu wrote:
| On 2013-06-20, Joshua Landau joshua.landau...@gmail.com wrote:
|  On 20 June 2013 04:11, Cameron Simpson c...@zip.com.au wrote:
|  Also, opening-and-not-closing a set of brackets is almost the
|  only way in Python to make this kind of error (syntax at one
|  line, actual mistake far before).
| 
|  See if your editor has a show-the-matching-bracket mode.
|  If you suspect you failed to close a bracket, one approach is
|  to go _below_ the syntax error (or right on it) and type a
|  closing bracket. Then see where the editor thinks the opening
|  one is.
| 
|  Thanks for that, that's quite an ingenious technique.
| 
| The auto-indent feature of Vim catches this type of syntax error,
| and I imagine other good autoindent support will do the same.

 Interesting. I use autoindent but grew up with it for prose. I
 hadn't realised vim's support inderstaood python indentation.
 I'll have to pay more attention...

A standard Vim install autoindents Python tolerably well if
you've set filetype=python. If you've got a baked-in Python
interpreter you can get even more bells and whistles. The
standard executable installs I could find don't support Python 3,
so I haven't seen all the great stuff I'm missing.

-- 
Neil Cerutti
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with the for loop syntax

2013-06-20 Thread Joshua Landau
On 20 June 2013 04:11, Cameron Simpson c...@zip.com.au wrote:
 Also, opening-and-not-closing a set of brackets is almost the only
 way in Python to make this kind of error (syntax at one line, actual
 mistake far before).

 See if your editor has a show-the-matching-bracket mode.
snip
 If you suspect you failed to close a bracket, one approach is to
 go _below_ the syntax error (or right on it) and type a closing
 bracket. Then see where the editor thinks the opening one is.

Thanks for that, that's quite an ingenious technique.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with the for loop syntax

2013-06-20 Thread Neil Cerutti
On 2013-06-20, Joshua Landau joshua.landau...@gmail.com wrote:
 On 20 June 2013 04:11, Cameron Simpson c...@zip.com.au wrote:
 Also, opening-and-not-closing a set of brackets is almost the
 only way in Python to make this kind of error (syntax at one
 line, actual mistake far before).

 See if your editor has a show-the-matching-bracket mode.
 If you suspect you failed to close a bracket, one approach is
 to go _below_ the syntax error (or right on it) and type a
 closing bracket. Then see where the editor thinks the opening
 one is.

 Thanks for that, that's quite an ingenious technique.

The auto-indent feature of Vim catches this type of syntax error,
and I imagine other good autoindent support will do the same.
After I press enter and the following line's indent isn't what I
expect, it is nearly always due to a missing bracket, quote or
colon.

So if you press enter and the autoindent is unexpected, don't
just press space or backspace to fix it. It's usually a sign of
an earlier syntax error, so look for that first.

-- 
Neil Cerutti
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with the for loop syntax

2013-06-20 Thread Oscar Benjamin
On 20 June 2013 04:11, Cameron Simpson c...@zip.com.au wrote:
 I use vi/vim and it both shows the matching bracket when the cursor
 is on one and also have a keystroke to bounce the curser between
 this bracket and the matching one.

 If you suspect you failed to close a bracket, one approach is to
 go _below_ the syntax error (or right on it) and type a closing
 bracket. Then see where the editor thinks the opening one is.

I use this technique sometimes and it works if the unclosed bracket is
still in view.

If you use vim then you can do [( i.e. type  '[' followed by '(' in
normal mode. It will jump backwards to the first unmatched opening
bracket. Use ]) to find the next unmatched closing bracket. You can
also do [{ and ]} for curly brackets. I'm not sure how to do square
brackets - [[ and ]] are used for navigating between functions.


Oscar
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with the for loop syntax

2013-06-20 Thread Chris Angelico
On Thu, Jun 20, 2013 at 11:55 PM, Neil Cerutti ne...@norwich.edu wrote:
 On 2013-06-20, Joshua Landau joshua.landau...@gmail.com wrote:
 On 20 June 2013 04:11, Cameron Simpson c...@zip.com.au wrote:
 Also, opening-and-not-closing a set of brackets is almost the
 only way in Python to make this kind of error (syntax at one
 line, actual mistake far before).

 See if your editor has a show-the-matching-bracket mode.
 If you suspect you failed to close a bracket, one approach is
 to go _below_ the syntax error (or right on it) and type a
 closing bracket. Then see where the editor thinks the opening
 one is.

 Thanks for that, that's quite an ingenious technique.

 The auto-indent feature of Vim catches this type of syntax error,
 and I imagine other good autoindent support will do the same.
 After I press enter and the following line's indent isn't what I
 expect, it is nearly always due to a missing bracket, quote or
 colon.

 So if you press enter and the autoindent is unexpected, don't
 just press space or backspace to fix it. It's usually a sign of
 an earlier syntax error, so look for that first.

Yes, though editors (like everything else!) can be buggy - SciTE, for
instance, has a bug with handling two adjacent braces in C code:

void dummy_function() {}
//SciTE will indent after that line

But autoindentation is a *hugely* valuable feature, because it gives
INSTANT feedback. You hit enter, the line is indented, you expected no
indent, problem found. And I've even used it as a means of probing -
if there's a problem in this area somewhere, I just go to the middle
of the area, hit enter to insert a blank line, and see if the
indentation is wrong. If it is, the problem's in the top half, else
the problem's in the bottom half. That is: The problem is in the
top-if-indentation-wrong-else-bottom half, using Python's ternary
syntax. Or the (indentation-wrong? top: bottom) half, in C notation.
Or... okay, I'll stop now.

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with the for loop syntax

2013-06-20 Thread Cameron Simpson
On 20Jun2013 15:33, Oscar Benjamin oscar.j.benja...@gmail.com wrote:
| On 20 June 2013 04:11, Cameron Simpson c...@zip.com.au wrote:
|  I use vi/vim and it both shows the matching bracket when the cursor
|  is on one and also have a keystroke to bounce the curser between
|  this bracket and the matching one.
| 
|  If you suspect you failed to close a bracket, one approach is to
|  go _below_ the syntax error (or right on it) and type a closing
|  bracket. Then see where the editor thinks the opening one is.
| 
| I use this technique sometimes and it works if the unclosed bracket is
| still in view.

Standing on a bracket, the '%' key jumps to the matching bracket.
No need for it to be in view.

Cheers,
-- 
Cameron Simpson c...@zip.com.au

Vy can't ve chust climb?  - John Salathe
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with the for loop syntax

2013-06-20 Thread Cameron Simpson
On 20Jun2013 13:55, Neil Cerutti ne...@norwich.edu wrote:
| On 2013-06-20, Joshua Landau joshua.landau...@gmail.com wrote:
|  On 20 June 2013 04:11, Cameron Simpson c...@zip.com.au wrote:
|  Also, opening-and-not-closing a set of brackets is almost the
|  only way in Python to make this kind of error (syntax at one
|  line, actual mistake far before).
| 
|  See if your editor has a show-the-matching-bracket mode.
|  If you suspect you failed to close a bracket, one approach is
|  to go _below_ the syntax error (or right on it) and type a
|  closing bracket. Then see where the editor thinks the opening
|  one is.
| 
|  Thanks for that, that's quite an ingenious technique.
| 
| The auto-indent feature of Vim catches this type of syntax error,
| and I imagine other good autoindent support will do the same.

Interesting. I use autoindent but grew up with it for prose.
I hadn't realised vim's support inderstaood python indentation.
I'll have to pay more attention...
-- 
Cameron Simpson c...@zip.com.au

Do I have it all?  Yes.
Do I want more?  Yeah, sure.- Demi Moore
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with the for loop syntax

2013-06-19 Thread Dave Angel

On 06/19/2013 05:14 PM, arturo balbuena wrote:

Hello guys...
I´m a begginer in Python, I'm doing a Hangman game, but I'm having trouble with 
this blank space. I would be greatful if you help me. :)

Here's my code:

http://snipplr.com/view/71581/hangman/

When I run the code it says: Invalid Syntax and this is the error:

http://i.imgur.com/jKYOPMY.png

http://i.imgur.com/ySoOZFR.png




If you want us to read it, put it in your message.  Show at least a few 
lines before and after the syntax error, and show the error itself, as 
text of course.  Use copy/paste.


Of course that assumes you're using a proper console/shell, and know how 
to use it.  So if you have to ask about that, start there.


In addition, specify the python version, and if appropriate, the OS and 
its version.


Generally, you can find your own problem.  Syntax errors that seem 
confusing are frequently really on the line before the line in which 
they're discovered.



--
DaveA
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with the for loop syntax

2013-06-19 Thread John Gordon
In 18f427ef-7a9a-413d-a824-65c9df430...@googlegroups.com arturo balbuena 
a7xrturo...@gmail.com writes:

 Hello guys...
 I=B4m a begginer in Python, I'm doing a Hangman game, but I'm having troubl=
 e with this blank space. I would be greatful if you help me. :)

 Here's my code:

 http://snipplr.com/view/71581/hangman/

Snipplr says that link doesn't exist.

 When I run the code it says: Invalid Syntax and this is the error:

 http://i.imgur.com/jKYOPMY.png

 http://i.imgur.com/ySoOZFR.png

I don't see anything obviously wrong with that code.  Are you sure that's
a real blank space, and not some weird character that *looks* like a space?

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, The Gashlycrumb Tinies

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with the for loop syntax

2013-06-19 Thread Ian Kelly
On Wed, Jun 19, 2013 at 3:14 PM, arturo balbuena a7xrturo...@gmail.com wrote:
 Hello guys...
 I´m a begginer in Python, I'm doing a Hangman game, but I'm having trouble 
 with this blank space. I would be greatful if you help me. :)

 Here's my code:

 http://snipplr.com/view/71581/hangman/

 When I run the code it says: Invalid Syntax and this is the error:

 http://i.imgur.com/jKYOPMY.png

 http://i.imgur.com/ySoOZFR.png

Are you running this in Python 2 or Python 3?  In Python 2, print is a
statement, not a function, and the end='' arguments would cause a
SyntaxError if you're not using the necessary __future__ import.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with the for loop syntax

2013-06-19 Thread Arturo B
Mmmm

Ok guys, thank you

I'm really sure that isn't a weird character, it is a space.

My Python version is 3.3.2, I've runed this code in Python 2.7.5, but it stills 
the same.

I've done what you said but it doesn't work.

Please Check it again here is better explained:

http://snipplr.com/view/71581/hangman/

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with the for loop syntax

2013-06-19 Thread Joshua Landau
On 19 June 2013 23:53, Arturo B a7xrturo...@gmail.com wrote:
 Mmmm

 Ok guys, thank you

 I'm really sure that isn't a weird character, it is a space.

 My Python version is 3.3.2, I've runed this code in Python 2.7.5, but it 
 stills the same.

 I've done what you said but it doesn't work.

 Please Check it again here is better explained:

 http://snipplr.com/view/71581/hangman/

Listen;

1) Post the code in the EMail, not an external link.

2) Don't Top Post.

3) That link doesn't exist. There are so many good hosting sites; why
use one that doesn't work?

4) Give us a minimal example. This should be easy; just remove the
code above and the code below. This is also a valid debugging
technique.

5) Images? Really?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with the for loop syntax

2013-06-19 Thread Arturo B
Sorry, I'm new in here

So, if you want to see the complete code I've fixed it:
http://www.smipple.net/snippet/a7xrturo/Hangman%21%20%3A%29

And here is the part of code that doesn't work:


#The error is marked in the whitespace between letter and in
 
def displayBoard(HANGMANPICS, missedLetters, correctLetters, secretWord):
print (HANGMANPICS[len(missedLetters)])
print()
   
print('Missed letters: ', end='')

#Starts problem

 for letter in missedLetters:

#Finishes problem

print(letter, end=' ')
print()

blanks = '_' * len(secretWord)
 
for i in range(len(secretWord)):
  if secretWord[i] in correctLetters:
  blanks = blanks[:i] + secretWord[i] + blanks[i+1:]
  
for letter in blanks:
print(letter, end=' ')
print()
   


When I press F5 (Run) I get a window that says: 'Invalid Syntax' and the 
whitespace between letter and in is in color red 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with the for loop syntax

2013-06-19 Thread Arturo B
Fixed, the problem was in 
HANGMANPICS 

I didn't open the brackets.

Thank you guys :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with the for loop syntax

2013-06-19 Thread Chris Angelico
On Thu, Jun 20, 2013 at 11:02 AM, Arturo B a7xrturo...@gmail.com wrote:
 Fixed, the problem was in
 HANGMANPICS

 I didn't open the brackets.

 Thank you guys :)

General debugging tip: Syntax errors are sometimes discovered quite
some way below the actual cause. The easiest way to figure out what's
the real cause is to start cutting away unnecessary code until all
that's left is the tiniest part that still has the error. This is also
very helpful as a prerequisite to posting on a list like this, so even
if you can't find the problem yourself by this method (you often will,
though), it's well worth doing.

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with the for loop syntax

2013-06-19 Thread Cameron Simpson
On 20Jun2013 11:09, Chris Angelico ros...@gmail.com wrote:
| On Thu, Jun 20, 2013 at 11:02 AM, Arturo B a7xrturo...@gmail.com wrote:
|  Fixed, the problem was in
|  HANGMANPICS
| 
|  I didn't open the brackets.
|  Thank you guys :)
| 
| General debugging tip: Syntax errors are sometimes discovered quite
| some way below the actual cause. The easiest way to figure out what's
| the real cause is to start cutting away unnecessary code until all
| that's left is the tiniest part that still has the error. This is also
| very helpful as a prerequisite to posting on a list like this, so even
| if you can't find the problem yourself by this method (you often will,
| though), it's well worth doing.

Also, opening-and-not-closing a set of brackets is almost the only
way in Python to make this kind of error (syntax at one line, actual
mistake far before).

See if your editor has a show-the-matching-bracket mode.

I use vi/vim and it both shows the matching bracket when the cursor
is on one and also have a keystroke to bounce the curser between
this bracket and the matching one.

If you suspect you failed to close a bracket, one approach is to
go _below_ the syntax error (or right on it) and type a closing
bracket. Then see where the editor thinks the opening one is.

If you have a syntax highlighting editor (highlights keywords,
colours quoted text differently, etc) it can also be useful for
finding errors; the text will be the wrong colour at some point.

Just a few suggestions to aid finding this kind of thing without
outside help.

Cheers,
-- 
Cameron Simpson c...@zip.com.au

Are you experiencing more Windows95 crashes than the norm? How on earth
would you _know_?   - John Brook jo...@research.canon.com.au
  reporting about a new virus
-- 
http://mail.python.org/mailman/listinfo/python-list