blob: ef7c09b9a57fe8ace098772bd4a1b89a3353a10c [file] [log] [blame]
Guido van Rossum3bead091992-01-27 17:00:37 +00001# Python test set -- part 1, grammar.
2# This just tests whether the parser accepts them all.
3
4from test_support import *
5
6print '1. Parser'
7
8print '1.1 Tokens'
9
10print '1.1.1 Backslashes'
11
12# Backslash means line continuation:
13x = 1 \
14+ 1
15if x <> 2: raise TestFailed, 'backslash for line continuation'
16
17# Backslash does not means continuation in comments :\
18x = 0
19if x <> 0: raise TestFailed, 'backslash ending comment'
20
21print '1.1.2 Numeric literals'
22
23print '1.1.2.1 Plain integers'
24if 0xff <> 255: raise TestFailed, 'hex int'
25if 0377 <> 255: raise TestFailed, 'octal int'
Guido van Rossumdd8cb441993-12-29 15:33:08 +000026if 2147483647 != 017777777777: raise TestFailed, 'large positive int'
27try:
28 from sys import maxint
29except ImportError:
30 maxint = 2147483647
31if maxint == 2147483647:
Guido van Rossume65cce51993-11-08 15:05:21 +000032 if -2147483647-1 != 020000000000: raise TestFailed, 'max negative int'
33 # XXX -2147483648
34 if 037777777777 != -1: raise TestFailed, 'oct -1'
35 if 0xffffffff != -1: raise TestFailed, 'hex -1'
36 for s in '2147483648', '040000000000', '0x100000000':
37 try:
38 x = eval(s)
39 except OverflowError:
40 continue
Guido van Rossum51b1c1c1995-03-04 22:30:54 +000041## raise TestFailed, \
42 print \
Guido van Rossume65cce51993-11-08 15:05:21 +000043 'No OverflowError on huge integer literal ' + `s`
Guido van Rossumdd8cb441993-12-29 15:33:08 +000044elif eval('maxint == 9223372036854775807'):
Guido van Rossumb6775db1994-08-01 11:34:53 +000045 if eval('-9223372036854775807-1 != 01000000000000000000000'):
Guido van Rossumdd8cb441993-12-29 15:33:08 +000046 raise TestFailed, 'max negative int'
47 if eval('01777777777777777777777') != -1: raise TestFailed, 'oct -1'
48 if eval('0xffffffffffffffff') != -1: raise TestFailed, 'hex -1'
49 for s in '9223372036854775808', '02000000000000000000000', \
50 '0x10000000000000000':
51 try:
52 x = eval(s)
53 except OverflowError:
54 continue
55 raise TestFailed, \
56 'No OverflowError on huge integer literal ' + `s`
57else:
58 print 'Weird maxint value', maxint
Guido van Rossum3bead091992-01-27 17:00:37 +000059
60print '1.1.2.2 Long integers'
61x = 0L
62x = 0l
63x = 0xffffffffffffffffL
64x = 0xffffffffffffffffl
65x = 077777777777777777L
66x = 077777777777777777l
67x = 123456789012345678901234567890L
68x = 123456789012345678901234567890l
69
70print '1.1.2.3 Floating point'
71x = 3.14
72x = 314.
73x = 0.314
74# XXX x = 000.314
75x = .314
76x = 3e14
77x = 3E14
78x = 3e-14
79x = 3e+14
80x = 3.e14
81x = .3e14
82x = 3.1e4
83
Guido van Rossumb31c7f71993-11-11 10:31:23 +000084print '1.1.3 String literals'
85
Guido van Rossum505043f1997-04-16 00:27:45 +000086##def assert(s):
87## if not s: raise TestFailed, 'see traceback'
Guido van Rossumb31c7f71993-11-11 10:31:23 +000088
89x = ''; y = ""; assert(len(x) == 0 and x == y)
90x = '\''; y = "'"; assert(len(x) == 1 and x == y and ord(x) == 39)
91x = '"'; y = "\""; assert(len(x) == 1 and x == y and ord(x) == 34)
92x = "doesn't \"shrink\" does it"
93y = 'doesn\'t "shrink" does it'
94assert(len(x) == 24 and x == y)
Guido van Rossumb6775db1994-08-01 11:34:53 +000095x = "does \"shrink\" doesn't it"
96y = 'does "shrink" doesn\'t it'
97assert(len(x) == 24 and x == y)
98x = """
99The "quick"
100brown fox
101jumps over
102the 'lazy' dog.
103"""
104y = '\nThe "quick"\nbrown fox\njumps over\nthe \'lazy\' dog.\n'
105assert(x == y)
106y = '''
107The "quick"
108brown fox
109jumps over
110the 'lazy' dog.
111'''; assert(x == y)
112y = "\n\
113The \"quick\"\n\
114brown fox\n\
115jumps over\n\
116the 'lazy' dog.\n\
117"; assert(x == y)
118y = '\n\
119The \"quick\"\n\
120brown fox\n\
121jumps over\n\
122the \'lazy\' dog.\n\
123'; assert(x == y)
Guido van Rossumb31c7f71993-11-11 10:31:23 +0000124
125
Guido van Rossum3bead091992-01-27 17:00:37 +0000126print '1.2 Grammar'
127
128print 'single_input' # NEWLINE | simple_stmt | compound_stmt NEWLINE
129# XXX can't test in a script -- this rule is only used when interactive
130
131print 'file_input' # (NEWLINE | stmt)* ENDMARKER
132# Being tested as this very moment this very module
133
134print 'expr_input' # testlist NEWLINE
135# XXX Hard to test -- used only in calls to input()
136
137print 'eval_input' # testlist ENDMARKER
138x = eval('1, 0 or 1')
139
140print 'funcdef'
141### 'def' NAME parameters ':' suite
142### parameters: '(' [varargslist] ')'
Jeremy Hyltonaed0d8d2000-03-28 23:51:17 +0000143### varargslist: (fpdef ['=' test] ',')* ('*' NAME [',' ('**'|'*' '*') NAME]
144### | ('**'|'*' '*') NAME)
145### | fpdef ['=' test] (',' fpdef ['=' test])* [',']
Guido van Rossum3bead091992-01-27 17:00:37 +0000146### fpdef: NAME | '(' fplist ')'
147### fplist: fpdef (',' fpdef)* [',']
Jeremy Hyltonaed0d8d2000-03-28 23:51:17 +0000148### arglist: (argument ',')* (argument | *' test [',' '**' test] | '**' test)
149### argument: [test '='] test # Really [keyword '='] test
Guido van Rossum3bead091992-01-27 17:00:37 +0000150def f1(): pass
Jeremy Hyltonaed0d8d2000-03-28 23:51:17 +0000151f1()
152f1(*())
153f1(*(), **{})
Guido van Rossum3bead091992-01-27 17:00:37 +0000154def f2(one_argument): pass
155def f3(two, arguments): pass
156def f4(two, (compound, (argument, list))): pass
157def a1(one_arg,): pass
158def a2(two, args,): pass
159def v0(*rest): pass
160def v1(a, *rest): pass
161def v2(a, b, *rest): pass
162def v3(a, (b, c), *rest): pass
Guido van Rossumb6775db1994-08-01 11:34:53 +0000163def d01(a=1): pass
164d01()
165d01(1)
Jeremy Hyltonaed0d8d2000-03-28 23:51:17 +0000166d01(*(1,))
167d01(**{'a':2})
Guido van Rossumb6775db1994-08-01 11:34:53 +0000168def d11(a, b=1): pass
169d11(1)
170d11(1, 2)
Jeremy Hyltonaed0d8d2000-03-28 23:51:17 +0000171d11(1, **{'b':2})
Guido van Rossumb6775db1994-08-01 11:34:53 +0000172def d21(a, b, c=1): pass
173d21(1, 2)
174d21(1, 2, 3)
Jeremy Hyltonaed0d8d2000-03-28 23:51:17 +0000175d21(*(1, 2, 3))
176d21(1, *(2, 3))
177d21(1, 2, *(3,))
178d21(1, 2, **{'c':3})
Guido van Rossumb6775db1994-08-01 11:34:53 +0000179def d02(a=1, b=2): pass
180d02()
181d02(1)
182d02(1, 2)
Jeremy Hyltonaed0d8d2000-03-28 23:51:17 +0000183d02(*(1, 2))
184d02(1, *(2,))
185d02(1, **{'b':2})
186d02(**{'a': 1, 'b': 2})
Guido van Rossumb6775db1994-08-01 11:34:53 +0000187def d12(a, b=1, c=2): pass
188d12(1)
189d12(1, 2)
190d12(1, 2, 3)
191def d22(a, b, c=1, d=2): pass
192d22(1, 2)
193d22(1, 2, 3)
194d22(1, 2, 3, 4)
195def d01v(a=1, *rest): pass
196d01v()
197d01v(1)
198d01v(1, 2)
Jeremy Hyltonaed0d8d2000-03-28 23:51:17 +0000199d01v(*(1, 2, 3, 4))
200d01v(*(1,))
201d01v(**{'a':2})
Guido van Rossumb6775db1994-08-01 11:34:53 +0000202def d11v(a, b=1, *rest): pass
203d11v(1)
204d11v(1, 2)
205d11v(1, 2, 3)
206def d21v(a, b, c=1, *rest): pass
207d21v(1, 2)
208d21v(1, 2, 3)
209d21v(1, 2, 3, 4)
Jeremy Hyltonaed0d8d2000-03-28 23:51:17 +0000210d21v(*(1, 2, 3, 4))
211d21v(1, 2, **{'c': 3})
Guido van Rossumb6775db1994-08-01 11:34:53 +0000212def d02v(a=1, b=2, *rest): pass
213d02v()
214d02v(1)
215d02v(1, 2)
216d02v(1, 2, 3)
Jeremy Hyltonaed0d8d2000-03-28 23:51:17 +0000217d02v(1, *(2, 3, 4))
218d02v(**{'a': 1, 'b': 2})
Guido van Rossumb6775db1994-08-01 11:34:53 +0000219def d12v(a, b=1, c=2, *rest): pass
220d12v(1)
221d12v(1, 2)
222d12v(1, 2, 3)
223d12v(1, 2, 3, 4)
Jeremy Hyltonaed0d8d2000-03-28 23:51:17 +0000224d12v(*(1, 2, 3, 4))
225d12v(1, 2, *(3, 4, 5))
226d12v(1, *(2,), **{'c': 3})
Guido van Rossumb6775db1994-08-01 11:34:53 +0000227def d22v(a, b, c=1, d=2, *rest): pass
228d22v(1, 2)
229d22v(1, 2, 3)
230d22v(1, 2, 3, 4)
231d22v(1, 2, 3, 4, 5)
Jeremy Hyltonaed0d8d2000-03-28 23:51:17 +0000232d22v(*(1, 2, 3, 4))
233d22v(1, 2, *(3, 4, 5))
234d22v(1, *(2, 3), **{'d': 4})
Guido van Rossum3bead091992-01-27 17:00:37 +0000235
236### stmt: simple_stmt | compound_stmt
237# Tested below
238
239### simple_stmt: small_stmt (';' small_stmt)* [';']
240print 'simple_stmt'
241x = 1; pass; del x
242
Guido van Rossumb3b09c91993-10-22 14:24:22 +0000243### small_stmt: expr_stmt | print_stmt | pass_stmt | del_stmt | flow_stmt | import_stmt | global_stmt | access_stmt | exec_stmt
Guido van Rossum3bead091992-01-27 17:00:37 +0000244# Tested below
245
246print 'expr_stmt' # (exprlist '=')* exprlist
2471
2481, 2, 3
249x = 1
250x = 1, 2, 3
251x = y = z = 1, 2, 3
252x, y, z = 1, 2, 3
253abc = a, b, c = x, y, z = xyz = 1, 2, (3, 4)
254# NB these variables are deleted below
255
256print 'print_stmt' # 'print' (test ',')* [test]
257print 1, 2, 3
258print 1, 2, 3,
259print
260print 0 or 1, 0 or 1,
261print 0 or 1
262
Barry Warsawefc92ee2000-08-21 15:46:50 +0000263print 'extended print_stmt' # 'print' '>>' test ','
264import sys
265print >> sys.stdout, 1, 2, 3
266print >> sys.stdout, 1, 2, 3,
267print >> sys.stdout
268print >> sys.stdout, 0 or 1, 0 or 1,
269print >> sys.stdout, 0 or 1
270
Barry Warsaw9182b452000-08-29 04:57:10 +0000271# test print >> None
272class Gulp:
273 def write(self, msg): pass
274
275def driver():
276 oldstdout = sys.stdout
277 sys.stdout = Gulp()
278 try:
279 tellme(Gulp())
280 tellme()
281 finally:
282 sys.stdout = oldstdout
283
284# we should see this once
285def tellme(file=sys.stdout):
286 print >> file, 'hello world'
287
288driver()
289
290# we should not see this at all
291def tellme(file=None):
292 print >> file, 'goodbye universe'
293
294driver()
295
Barry Warsawefc92ee2000-08-21 15:46:50 +0000296# syntax errors
297def check_syntax(statement):
298 try:
299 compile(statement, '<string>', 'exec')
300 except SyntaxError:
301 pass
302 else:
303 print 'Missing SyntaxError: "%s"' % statement
304check_syntax('print ,')
305check_syntax('print >> x,')
306
Guido van Rossum3bead091992-01-27 17:00:37 +0000307print 'del_stmt' # 'del' exprlist
308del abc
309del x, y, (z, xyz)
310
311print 'pass_stmt' # 'pass'
312pass
313
314print 'flow_stmt' # break_stmt | continue_stmt | return_stmt | raise_stmt
315# Tested below
316
317print 'break_stmt' # 'break'
318while 1: break
319
320print 'continue_stmt' # 'continue'
321i = 1
322while i: i = 0; continue
323
324print 'return_stmt' # 'return' [testlist]
325def g1(): return
326def g2(): return 1
327g1()
328x = g2()
329
330print 'raise_stmt' # 'raise' test [',' test]
331try: raise RuntimeError, 'just testing'
332except RuntimeError: pass
333try: raise KeyboardInterrupt
334except KeyboardInterrupt: pass
335
336print 'import_stmt' # 'import' NAME (',' NAME)* | 'from' NAME 'import' ('*' | NAME (',' NAME)*)
Guido van Rossum3bead091992-01-27 17:00:37 +0000337import sys
Guido van Rossum51b1c1c1995-03-04 22:30:54 +0000338import time, sys
Guido van Rossumb6775db1994-08-01 11:34:53 +0000339from time import time
Guido van Rossum3bead091992-01-27 17:00:37 +0000340from sys import *
Guido van Rossum51b1c1c1995-03-04 22:30:54 +0000341from sys import path, argv
Guido van Rossum3bead091992-01-27 17:00:37 +0000342
343print 'global_stmt' # 'global' NAME (',' NAME)*
344def f():
345 global a
346 global a, b
347 global one, two, three, four, five, six, seven, eight, nine, ten
348
Guido van Rossumb3b09c91993-10-22 14:24:22 +0000349print 'exec_stmt' # 'exec' expr ['in' expr [',' expr]]
350def f():
351 z = None
352 del z
353 exec 'z=1+1\n'
354 if z <> 2: raise TestFailed, 'exec \'z=1+1\'\\n'
355 del z
356 exec 'z=1+1'
357 if z <> 2: raise TestFailed, 'exec \'z=1+1\''
358f()
359g = {}
360exec 'z = 1' in g
Guido van Rossum1f976121995-01-10 10:34:21 +0000361if g.has_key('__builtins__'): del g['__builtins__']
Guido van Rossumb3b09c91993-10-22 14:24:22 +0000362if g <> {'z': 1}: raise TestFailed, 'exec \'z = 1\' in g'
363g = {}
364l = {}
365exec 'global a; a = 1; b = 2' in g, l
Guido van Rossum1f976121995-01-10 10:34:21 +0000366if g.has_key('__builtins__'): del g['__builtins__']
367if l.has_key('__builtins__'): del l['__builtins__']
Guido van Rossumb3b09c91993-10-22 14:24:22 +0000368if (g, l) <> ({'a':1}, {'b':2}): raise TestFailed, 'exec ... in g, l'
369
370
Guido van Rossum3bead091992-01-27 17:00:37 +0000371### compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | funcdef | classdef
372# Tested below
373
374print 'if_stmt' # 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite]
375if 1: pass
376if 1: pass
377else: pass
378if 0: pass
379elif 0: pass
380if 0: pass
381elif 0: pass
382elif 0: pass
383elif 0: pass
384else: pass
385
386print 'while_stmt' # 'while' test ':' suite ['else' ':' suite]
387while 0: pass
388while 0: pass
389else: pass
390
391print 'for_stmt' # 'for' exprlist 'in' exprlist ':' suite ['else' ':' suite]
Guido van Rossum3bead091992-01-27 17:00:37 +0000392for i in 1, 2, 3: pass
Guido van Rossum3bead091992-01-27 17:00:37 +0000393for i, j, k in (): pass
394else: pass
Guido van Rossumb6775db1994-08-01 11:34:53 +0000395class Squares:
396 def __init__(self, max):
397 self.max = max
398 self.sofar = []
399 def __len__(self): return len(self.sofar)
400 def __getitem__(self, i):
401 if not 0 <= i < self.max: raise IndexError
402 n = len(self.sofar)
403 while n <= i:
404 self.sofar.append(n*n)
405 n = n+1
406 return self.sofar[i]
407n = 0
408for x in Squares(10): n = n+x
409if n != 285: raise TestFailed, 'for over growing sequence'
Guido van Rossum3bead091992-01-27 17:00:37 +0000410
Guido van Rossumb6775db1994-08-01 11:34:53 +0000411print 'try_stmt'
412### try_stmt: 'try' ':' suite (except_clause ':' suite)+ ['else' ':' suite]
413### | 'try' ':' suite 'finally' ':' suite
Guido van Rossum3bead091992-01-27 17:00:37 +0000414### except_clause: 'except' [expr [',' expr]]
Guido van Rossum85f18201992-11-27 22:53:50 +0000415try:
416 1/0
417except ZeroDivisionError:
418 pass
Guido van Rossumb6775db1994-08-01 11:34:53 +0000419else:
420 pass
Guido van Rossum3bead091992-01-27 17:00:37 +0000421try: 1/0
422except EOFError: pass
423except TypeError, msg: pass
424except RuntimeError, msg: pass
425except: pass
Guido van Rossumb6775db1994-08-01 11:34:53 +0000426else: pass
Guido van Rossum85f18201992-11-27 22:53:50 +0000427try: 1/0
428except (EOFError, TypeError, ZeroDivisionError): pass
429try: 1/0
430except (EOFError, TypeError, ZeroDivisionError), msg: pass
Guido van Rossum3bead091992-01-27 17:00:37 +0000431try: pass
432finally: pass
Guido van Rossum3bead091992-01-27 17:00:37 +0000433
434print 'suite' # simple_stmt | NEWLINE INDENT NEWLINE* (stmt NEWLINE*)+ DEDENT
435if 1: pass
436if 1:
437 pass
438if 1:
439 #
440 #
441 #
442 pass
443 pass
444 #
445 pass
446 #
447
448print 'test'
449### and_test ('or' and_test)*
450### and_test: not_test ('and' not_test)*
451### not_test: 'not' not_test | comparison
452if not 1: pass
453if 1 and 1: pass
454if 1 or 1: pass
455if not not not 1: pass
456if not 1 and 1 and 1: pass
457if 1 and 1 or 1 and 1 and 1 or not 1 and 1: pass
458
459print 'comparison'
460### comparison: expr (comp_op expr)*
461### comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not'
462if 1: pass
463x = (1 == 1)
464if 1 == 1: pass
465if 1 != 1: pass
466if 1 <> 1: pass
467if 1 < 1: pass
468if 1 > 1: pass
469if 1 <= 1: pass
470if 1 >= 1: pass
471if 1 is 1: pass
472if 1 is not 1: pass
473if 1 in (): pass
474if 1 not in (): pass
Guido van Rossum85f18201992-11-27 22:53:50 +0000475if 1 < 1 > 1 == 1 >= 1 <= 1 <> 1 != 1 in 1 not in 1 is 1 is not 1: pass
Guido van Rossum3bead091992-01-27 17:00:37 +0000476
477print 'binary mask ops'
478x = 1 & 1
479x = 1 ^ 1
480x = 1 | 1
481
482print 'shift ops'
483x = 1 << 1
484x = 1 >> 1
485x = 1 << 1 >> 1
486
487print 'additive ops'
488x = 1
489x = 1 + 1
490x = 1 - 1 - 1
491x = 1 - 1 + 1 - 1 + 1
492
493print 'multiplicative ops'
494x = 1 * 1
495x = 1 / 1
496x = 1 % 1
497x = 1 / 1 * 1 % 1
498
499print 'unary ops'
500x = +1
501x = -1
502x = ~1
503x = ~1 ^ 1 & 1 | 1 & 1 ^ -1
504x = -1*1/1 + 1*1 - ---1*1
505
506print 'selectors'
507### trailer: '(' [testlist] ')' | '[' subscript ']' | '.' NAME
508### subscript: expr | [expr] ':' [expr]
Guido van Rossum85f18201992-11-27 22:53:50 +0000509f1()
510f2(1)
511f2(1,)
512f3(1, 2)
513f3(1, 2,)
514f4(1, (2, (3, 4)))
515v0()
516v0(1)
517v0(1,)
518v0(1,2)
519v0(1,2,3,4,5,6,7,8,9,0)
520v1(1)
521v1(1,)
522v1(1,2)
523v1(1,2,3)
524v1(1,2,3,4,5,6,7,8,9,0)
525v2(1,2)
526v2(1,2,3)
527v2(1,2,3,4)
528v2(1,2,3,4,5,6,7,8,9,0)
529v3(1,(2,3))
530v3(1,(2,3),4)
531v3(1,(2,3),4,5,6,7,8,9,0)
Jeremy Hyltonaed0d8d2000-03-28 23:51:17 +0000532print
Guido van Rossum3bead091992-01-27 17:00:37 +0000533import sys, time
534c = sys.path[0]
535x = time.time()
536x = sys.modules['time'].time()
537a = '01234'
538c = a[0]
539c = a[-1]
540s = a[0:5]
541s = a[:5]
542s = a[0:]
543s = a[:]
544s = a[-5:]
545s = a[:-1]
546s = a[-4:-3]
547
548print 'atoms'
549### atom: '(' [testlist] ')' | '[' [testlist] ']' | '{' [dictmaker] '}' | '`' testlist '`' | NAME | NUMBER | STRING
550### dictmaker: test ':' test (',' test ':' test)* [',']
551
552x = (1)
553x = (1 or 2 or 3)
554x = (1 or 2 or 3, 2, 3)
555
556x = []
557x = [1]
558x = [1 or 2 or 3]
559x = [1 or 2 or 3, 2, 3]
560x = []
561
562x = {}
563x = {'one': 1}
564x = {'one': 1,}
565x = {'one' or 'two': 1 or 2}
566x = {'one': 1, 'two': 2}
567x = {'one': 1, 'two': 2,}
568x = {'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5, 'six': 6}
569
570x = `x`
571x = `1 or 2 or 3`
572x = x
573x = 'x'
574x = 123
575
576### exprlist: expr (',' expr)* [',']
577### testlist: test (',' test)* [',']
578# These have been exercised enough above
579
Guido van Rossum85f18201992-11-27 22:53:50 +0000580print 'classdef' # 'class' NAME ['(' testlist ')'] ':' suite
Guido van Rossum3bead091992-01-27 17:00:37 +0000581class B: pass
582class C1(B): pass
583class C2(B): pass
584class D(C1, C2, B): pass
585class C:
586 def meth1(self): pass
587 def meth2(self, arg): pass
588 def meth3(self, a1, a2): pass
Skip Montanaro803d6e52000-08-12 18:09:51 +0000589
590# list comprehension tests
591nums = [1, 2, 3, 4, 5]
592strs = ["Apple", "Banana", "Coconut"]
593spcs = [" Apple", " Banana ", "Coco nut "]
594
595print [s.strip() for s in spcs]
596print [3 * x for x in nums]
597print [x for x in nums if x > 2]
598print [(i, s) for i in nums for s in strs]
599print [(i, s) for i in nums for s in [f for f in strs if "n" in f]]
600try:
601 eval("[i, s for i in nums for s in strs]")
602 print "FAIL: should have raised a SyntaxError!"
603except SyntaxError:
604 print "good: got a SyntaxError as expected"
605
Skip Montanaro46dfa5f2000-08-22 02:43:07 +0000606try:
607 eval("[x if y]")
608 print "FAIL: should have raised a SyntaxError!"
609except SyntaxError:
610 print "good: got a SyntaxError as expected"
611
Skip Montanaro803d6e52000-08-12 18:09:51 +0000612suppliers = [
613 (1, "Boeing"),
614 (2, "Ford"),
615 (3, "Macdonalds")
616]
617
618parts = [
619 (10, "Airliner"),
620 (20, "Engine"),
621 (30, "Cheeseburger")
622]
623
624suppart = [
625 (1, 10), (1, 20), (2, 20), (3, 30)
626]
627
628print [
629 (sname, pname)
630 for (sno, sname) in suppliers
631 for (pno, pname) in parts
632 for (sp_sno, sp_pno) in suppart
633 if sno == sp_sno and pno == sp_pno
634]