Python Forum
pass after a loop is a syntax error???
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pass after a loop is a syntax error???
#1
i don't believe this should be an error
Output:
lt1/forums /home/forums 3> py3 Python 3.5.2 (default, Nov 17 2016, 17:05:23) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> for f in os.listdir('.'): ...     print(f) ... pass   File "<stdin>", line 3     pass        ^ SyntaxError: invalid syntax >>> lt1/forums /home/forums 4> py2 Python 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> for f in os.listdir('.'): ...     print f ... pass   File "<stdin>", line 3     pass        ^ SyntaxError: invalid syntax >>>
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
Pass is used when some statement is required syntactically. Out of the loop, a function or condition doesn't do anything.
I don't know how to find the source code of pass to see why exactly it happens
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#3
I'm guessing that pass is a C macro, perhaps defined like
#define pass (void)0
Reply
#4
It has nothing to do with pass, which needn't be used within any block.
>>> for t in 'abc':
...     print t
... print 'xyz'
  File "<stdin>", line 3
    print 'xyz'
        ^
SyntaxError: invalid syntax
Python's REPL, for whatever reason, just doesn't like it when you try to put code after a block before executing that block.
Reply
#5
(Jan-15-2017, 03:30 PM)Larz60+ Wrote: I'm guessing that pass is a C macro, perhaps defined like
#define pass (void)0

there is no such define in C.  i'm not using C.  i was using python and testing some code when i ran into this.  i don't actually need to use pass.  i am just bringing it up as "implementation != documentation",

i just ran across another one in datetime but i have yet to test that one thoroughly before posting it.

if these don't work as documented i consider it to be a bug.  i'll let the developers _decide_ if it is a bug in the implementation or a bug in the documentation.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#6
(Jan-16-2017, 02:58 AM)Skaperen Wrote: i am just bringing it up as "implementation != documentation"
Could you link to that documentation?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Syntax error for "root = Tk()" dlwaddel 15 1,151 Jan-29-2024, 12:07 AM
Last Post: dlwaddel
Photo SYNTAX ERROR Yannko 3 370 Jan-19-2024, 01:20 PM
Last Post: rob101
  How to pass encrypted pass to pyodbc script tester_V 0 849 Jul-27-2023, 12:40 AM
Last Post: tester_V
  Syntax error while executing the Python code in Linux DivAsh 8 1,540 Jul-19-2023, 06:27 PM
Last Post: Lahearle
  Code is returning the incorrect values. syntax error 007sonic 6 1,204 Jun-19-2023, 03:35 AM
Last Post: 007sonic
  syntax error question - string mgallotti 5 1,285 Feb-03-2023, 05:10 PM
Last Post: mgallotti
  Syntax error? I don't see it KenHorse 4 1,237 Jan-15-2023, 07:49 PM
Last Post: Gribouillis
  Syntax error tibbj001 2 881 Dec-05-2022, 06:38 PM
Last Post: deanhystad
  Python-for-Android:p4a: syntax error in main.py while compiling apk jttolleson 2 1,828 Sep-17-2022, 04:09 AM
Last Post: jttolleson
  Mysql Syntax error in pymysql ilknurg 4 2,344 May-18-2022, 06:50 AM
Last Post: ibreeden

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020