I've installed a copy of Tcl/Tk and Python 2.6 in the
~cs5350 directory (yes, 5350, not 5300: this is because I
have a much larger quota in 5350 than 5300 and this stuff wouldn't fit
in 5300).
First, you need to set your library path so that it looks in
the ~cs5350/lib directory for dynamic libraries. If
you're running a csh-style shell, you'll need to say
setenv LD_LIBRARY_PATH /home/cs5350/lib:$LD_LIBRARY_PATH; if
you're using a bash-style shell, you'll need to say
export LD_LIBRARY_PATH=/home/cs5350/lib:$LD_LIBRARY_PATH.
(You can check which shell you're running by saying echo
$SHELL.) Note, if you don't currently have a
LD_LIBRARY_PATH defined, remove the
":$LD_LIBRARY_PATH" from these expressions (the shell
will complain about an undefined variable in this case).
Next, when you invoke python, you'll need to run the version in
~cs5350/bin/python. This is version 2.6. So, for
instance, you can run pacman with: ~cs5350/bin/python
pacman.py if you're in the search directory.
csh
shell, then you'll want to add the following two lines to your
.cshrc file that's in your home directory:
setenv LD_LIBRARY_PATH /home/cs5350/lib:$LD_LIBRARY_PATH alias python /home/cs5350/bin/pythonOn the other hand, if you're running a
bash shell, you'll
want to add the following lines to your .bashrc file
that's in your home directory:
export LD_LIBRARY_PATH=/home/cs5350/lib:$LD_LIBRARY_PATH alias python='/home/cs5350/bin/python'Again, if you don't currently have a
LD_LIBRARY_PATH
defined, remove the ":$LD_LIBRARY_PATH" from these
expressions (the shell will complain about an undefined variable in
this case when you log back in).Now, you should just be able to log out from CADE, log back in, and run pacman via:
python pacman.pywithout any extra magic.
filename.py. How do I execute it from the Python interpreter?filename.py is in (or if it's in the Python path...), then you can import the contents of filename.py as a module:
>>> import filename
>>> filename.function(arguments)
With this kind of import statement, you must reference the module name followed by the function name. Alternatively, you can import the contents of filename.py into the local namespace:
>>> from filename import *
>>> function(arguments)
With this kind of import statement, you no longer need to reference the module name.
Solution:
When using import, do not include the ".py" from the filename.
For example, you should say: import shop
NOT: import shop.py
Solution:
To access a member of a module, you have to type MODULE NAME.MEMBER NAME, where MODULE NAME is the name of the .py file, and MEMBER NAME is the name of the variable (or function) you are trying to access.
Solution:
Dictionary looks up are done using square brackets: [ and ]. NOT parenthesis: ( and ).
Solution:
Make sure the number of variables you are assigning in a for loop matches the number of elements in each item of the list.
Similarly for working with tuples.
For example, if pair is a tuple of two elements (e.g. pair =('apple', 2.0)) then the following code would cause the "too many values to unpack error":
(a,b,c) = pair
Here is a problematic scenario involving a for loop:
pairList = [('apples', 2.00), ('oranges', 1.50), ('pears', 1.75)]
for fruit, price, color in pairList:
print '%s fruit costs %f and is the color %s' % (fruit, price, color)
Solution:
Finding length of lists is done using len(NAME OF LIST).
Solution:
reload(YOUR_MODULE) to guarantee your changes are being reflected.
reload works similar to import.