Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed print to print() to be compatible with Python 3.0 + #6

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
6 changes: 3 additions & 3 deletions Advanced/CoRoutine/CoRoutine.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def keep_sorted():
# Start the generator
g.next()
# Send stuff
print g.send('zzz')
print g.send('Hi there')
print 'Sorted list is {0:s}'.format(g.next())
print(g.send('zzz'))
print(g.send('Hi there'))
print('Sorted list is {0:s}'.format(g.next()))
g.close()
13 changes: 6 additions & 7 deletions Advanced/RomeoAndJuliet/util/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,14 @@ def get_acts_scenes_actors():
s.add_actor('c')
s.add_actor('d')
g = s.gen_actors()
g
print next(g)
print next(g)
print next(g)
print next(g)
print next(g)
print(next(g))
print(next(g))
print(next(g))
print(next(g))
print(next(g))
# print next(s)
# print next(s)
# print next(s)
# print next(s)
# print next(s)


6 changes: 3 additions & 3 deletions Beginners/ExampleFunctions/A_functions_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
###################
def noArgs():
"""Function that takes no arguments."""
print ' noArgs(): No arguments'
print(' noArgs(): No arguments')

def twoArgs(a, b):
"""Function that takes two arguments."""
print ' twoArgs(): a=%s, b=%s' % (a, b)
print (' twoArgs(): a=%s, b=%s' % (a, b))

def main():
print 'callSimple():'
print('callSimple():')
noArgs()
twoArgs(12, 34)
twoArgs(b='b_given', a='a_given')
Expand Down
4 changes: 2 additions & 2 deletions Beginners/ExampleFunctions/B_functions_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
# Simple functions, with defaults.
##################################
def twoArgsOneDefault(a, b='default_value'):
print ' a=%s, b=%s' % (a, b)
print(' a=%s, b=%s' % (a, b))

def main():
print 'callTwoArgsOneDefault():'
print ('callTwoArgsOneDefault():')
twoArgsOneDefault('a_only')
twoArgsOneDefault('a_value', b='b_given')

Expand Down
12 changes: 6 additions & 6 deletions Beginners/ExampleFunctions/C_functions_default_mutable.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ def defaultMutableFix(a=x):

def main():
# defaultMutableCatch()
print 'defaultMutableCatch():', defaultMutableCatch()
print 'defaultMutableCatch():', defaultMutableCatch([])
print 'defaultMutableCatch():', defaultMutableCatch()
print('defaultMutableCatch():', defaultMutableCatch())
print('defaultMutableCatch():', defaultMutableCatch([]))
print('defaultMutableCatch():', defaultMutableCatch())
# defaultMutableFix()
print 'defaultMutableFix():', defaultMutableFix()
print 'defaultMutableFix():', defaultMutableFix()
print 'defaultMutableFix():', defaultMutableFix()
print('defaultMutableFix():', defaultMutableFix())
print('defaultMutableFix():', defaultMutableFix())
print('defaultMutableFix():', defaultMutableFix())

if __name__ == '__main__':
main()
Expand Down
16 changes: 8 additions & 8 deletions Beginners/ExampleFunctions/D_functions_parrot.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ def parrot(voltage,
state='a stiff',
action='voom',
type='Norwegian Blue'):
print "-- This parrot wouldn't", action,
print "if you put", voltage, "volts through it."
print "-- Lovely plumage, the", type
print "-- It's", state, "!"
print("-- This parrot wouldn't", action)
print("if you put", voltage, "volts through it.")
print("-- Lovely plumage, the", type)
print("-- It's", state, "!")

def main():
parrot(1000)
print
print("\n")
parrot(action='VOOOOOM', voltage=1000000)
print
print("\n")
parrot('a thousand', state='pushing up the daisies')
print
print("\n")
parrot('a million', 'bereft of life', 'jump')
print
print("\n")
# These will raise a SyntaxError
# parrot() # required argument missing
# parrot(voltage=5.0, 'dead') # non-keyword argument following keyword
Expand Down
10 changes: 5 additions & 5 deletions Beginners/ExampleFunctions/E_functions_cheeseshop.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
# With keyword arguments.
#########################
def cheeseshop(kind, *args, **kwargs):
print "-- Do you have any", kind, "?"
print " *args ".center(40, '-')
print("-- Do you have any", kind, "?")
print(" *args ".center(40, '-'))
pprint.pprint(args)
print " *args ".center(40, '-')
print " *kwargs ".center(40, '-')
print(" *args ".center(40, '-'))
print(" *kwargs ".center(40, '-'))
pprint.pprint(kwargs)
print " *kwargs ".center(40, '-')
print(" *kwargs ".center(40, '-'))

def main():
cheeseshop(
Expand Down
14 changes: 7 additions & 7 deletions Beginners/ExampleFunctions/F_functions_unpack_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@

def unpackArgs(*args):
for arg in args:
print type(arg), arg
print
print(type(arg), arg)
print("\n")

def main():
print 'callUnpackArgs():'
print 'Specific arguments:'
print('callUnpackArgs():')
print('Specific arguments:')
unpackArgs(0,1,2,3)
l = ['a', 'b', 'c', 'd']
print 'Single list argument:'
print('Single list argument:')
unpackArgs(l)
print 'Unpacked list argument:'
print('Unpacked list argument:')
unpackArgs(*l)
print 'Single value unpacked'
print('Single value unpacked')
unpackArgs(*'hello')

if __name__ == '__main__':
Expand Down
10 changes: 5 additions & 5 deletions Beginners/ExampleFunctions/G_functions_unpack_kwargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ def unpackKwargs(**kwargs):
keys = kwargs.keys()
keys.sort()
for kw in keys:
print kw, ":", kwargs[kw]
print(kw, ":", kwargs[kw])

def main():
print 'callUnpackKwargs():'
print 'Specific arguments:'
print('callUnpackKwargs():')
print('Specific arguments:')
unpackKwargs(name='python', version=2.6)
d = {
'name' : 'python',
'version' : 2.6,
}
print
print 'Unpacked arguments:'
print("\n")
print('Unpacked arguments:')
unpackKwargs(**d)

if __name__ == '__main__':
Expand Down
18 changes: 9 additions & 9 deletions Beginners/Functions/ArgsKwargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ def f(x, y, z):
# print "x=%s y=%s, z=%s" % (x, y, z)
return (x + y) / float(z)

print f(10, 5, 3)
print(f(10, 5, 3))

x = 20
y = 10
z = 3

# using kwargs
print f(x=x, y=y, z=z)
print(f(x=x, y=y, z=z))

# using args and kwargs
print f(y, x, z=2)
print(f(y, x, z=2))

# using args and kwargs out of order
print f(z=3, y=x, x=y)
print(f(z=3, y=x, x=y))

# all x
print f(z=x, y=x, x=x)
print(f(z=x, y=x, x=x))

"""
With defaults
Expand All @@ -36,15 +36,15 @@ def ff(x=20, y=10, z=3):
# print "x=%s y=%s, z=%s" % (x, y, z)
return (x + y) / float(z)

print ff(10, 5, 3)
print(ff(10, 5, 3))

# using args
print ff(10)
print(ff(10))

# using kwargs
print ff(z=10)
print(ff(z=10))

x = 20
print ff(z=x, y=x)
print(ff(z=x, y=x))


8 changes: 4 additions & 4 deletions Beginners/basics.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Given
x = 10000.0
y = 3.0
print x / y
print 10000 / 3
print(x / y)
print(10000 / 3)
# What is happening?

# Given
print x - 1 / y
print (x - 1) / y
print(x - 1 / y)
print((x - 1) / y)
# What is happening?

# Given
Expand Down
2 changes: 1 addition & 1 deletion First.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""

def main():
print 'Hi there'
print('Hi there')

if __name__ == '__main__':
main()
2 changes: 1 addition & 1 deletion Intermediate/Histogram/DictHistogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def pprint_histogram(d, bucket_size, char='+', width=80, key_format='%6.3f'):
char is the character to use for the histogram bars.
width is the total width to use.
key_format is used to turn the keys into strings."""
print pformat_histogram(d, bucket_size, char, width, key_format)
print(pformat_histogram(d, bucket_size, char, width, key_format))


def pformat_histogram(d, bucket_size, char='+', width=80, key_format='%6.3f'):
Expand Down
4 changes: 2 additions & 2 deletions Intermediate/RandomWords/RandomWords.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def main():
break
max_len = max([len(w) for w in words])
for n in range(max_len):
print '%4d: %s' % (n, ' '.join(randomWords(words, n)))
print('%4d: %s' % (n, ' '.join(randomWords(words, n))))

if __name__ == '__main__':
main()
print 'Bye, bye.'
print('Bye, bye.')
2 changes: 1 addition & 1 deletion Intermediate/RegexMapping/RegexMap.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def main():
Hello world
42"""
result = matchLines(text.split('\n'))
print result
print(result)

if __name__ == '__main__':
main()