Syntax error - what's wrong?

Andre-John Mas ajmas at bigfoot.com
Sun Oct 17 21:15:12 EDT 1999


Hi,

 I have never programmed in Python before and need a quick crash
 course. I am installing Redhat Linux 6.1 and I am getting a Python
 related error. Could someone tell me what it wrong - I hoping this
 will be faster that waiting for a Redhat solution ;-)

 Everything you should need is below:

--- Error start

Traceback (innermost last):
  File "/usr/bin/anaconda", line 13, in ?
    import gettext
  File "/usr/lib/python1.5/site-packages/gettext.py", line 40 in ?
    import os, string
  File "/usr/lib/python1.5/string.py", line 480
    return sign + '0'*(width-n) +
                                      ^
SyntaxError:  invalid syntax

--- Error end

--- Code segment start

# Zero-fill a number, e.g., (12, 3) --> '012' and (-3, 3) --> '-03'
# Decadent feature: the argument may be a string or a number
# (Use of this is deprecated; it should be a string as with ljust c.s.)
def zfill(x, width):
	"""zfill(x, width) -> string

	Pad a numeric string x with zeros on the left, to fill a field
	of the specified width.  The string x is never truncated.

	"""
	if type(x) == type(''): s = x
	else: s = `x`
	n = len(s)
	if n >= width: return s
	sign = ''
	if s[0] in ('-', '+'):
		sign, s = s[0], s[1:]
	return sign + '0'*(width-n) + s

--- Code segment start

A copy of the source file is available at:

ftp://ftp.eecs.umich.edu/pub/linux/redhat/redhat/redhat-6.1/i386/RedHat/
instimage/usr/lib/python1.5/

Andre
--
http://www.bigfoot.com/~ajmas/


Sent via Deja.com http://www.deja.com/
Before you buy.




More information about the Python-list mailing list