Name: Anonymous 2010-08-12 10:49
I don't know if I fucked up adding python libs or what, but I get NameError's when trying to use python's built in function 'sorted()' in my own function.
#!/usr/bin/python -tt
import sys
def Cat(filename):
f = open(filename, 'rU')
text = f.readlines()
print sorted(text)
print text
f.close()
def main():
Cat(sys.argv[1])
if __name__ == '__main__':
main()
All it should do is read from a text file with every line being an element and sort through them. I simplified my sorted parameters. The error I get is:
Traceback (most recent call last):
File "./test.py", line 17, in ?
main()
File "./test.py", line 12, in main
Cat(sys.argv[1])
File "./test.py", line 8, in Cat
print sorted(text)
NameError: global name 'sorted' is not defined
fkn python
also version is 2.7, and when i "python -c 'print sorted'"
it tells me:
<built-in function sorted>
Am i fucking up on python's scope or smth maybe?
#!/usr/bin/python -tt
import sys
def Cat(filename):
f = open(filename, 'rU')
text = f.readlines()
print sorted(text)
print text
f.close()
def main():
Cat(sys.argv[1])
if __name__ == '__main__':
main()
All it should do is read from a text file with every line being an element and sort through them. I simplified my sorted parameters. The error I get is:
Traceback (most recent call last):
File "./test.py", line 17, in ?
main()
File "./test.py", line 12, in main
Cat(sys.argv[1])
File "./test.py", line 8, in Cat
print sorted(text)
NameError: global name 'sorted' is not defined
fkn python
also version is 2.7, and when i "python -c 'print sorted'"
it tells me:
<built-in function sorted>
Am i fucking up on python's scope or smth maybe?