Re: [Tutor] where does the ViewerFrameWorkGUI come from

2011-12-18 Thread Steven D'Aprano

lina wrote:

Hi,

I met below issue:

File /usr/lib/python2.7/dist-packages/ViewerFramework/VF.py, line
369, in __init__
self.GUI = ViewerFrameworkGUI(self, title=title,
NameError: global name 'ViewerFrameworkGUI' is not defined


Is VF.py your code?

If so, you have a bug in the code.

If not, then *possibly* there is a bug in the ViewerFramework package. Or more 
likely you are aren't using it correctly. My guess is that you haven't 
initialised the framework correctly. Read the documentation for it.




can someone tell me how to examine,

I mean, how to examine, what would you do when you face the problem?


Read the documentation.
Check your code.
Google for the error message and see if other people are having it.
What are you doing that leads to the error? Do something different.
If there is a forum specifically for the ViewerFramework package, ask there.
If not, write to the author.



--
Steven

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Memory and functions

2011-12-18 Thread Charles Becker
I have a rather obscure question, and not sure where in the docs to find an 
answer like this.

For functions that return values (ie the list method pop): If you don't assign 
the returned value to anything does it still end up residing in memory?  Just 
seems like this could be a potential problem to watch out for when memory usage 
is an issue (probably not most of the time).

Also, where can I begin to find these 'lower level' answers in the docs?

Thanks!
Charles
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Memory and functions

2011-12-18 Thread Steven D'Aprano

Charles Becker wrote:

I have a rather obscure question, and not sure where in the docs to find an 
answer like this.

For functions that return values (ie the list method pop): If you don't assign 
the returned value to anything does it still end up residing in memory?  Just 
seems like this could be a potential problem to watch out for when memory usage 
is an issue (probably not most of the time).


Python is a modern language with a garbage collector. That means that behind 
the scenes Python deletes objects which are no longer in use. So the short 
answer is, yes, if you don't assign the returned value, it will be deleted by 
the garbage collector and you don't normally have to worry about it.




Also, where can I begin to find these 'lower level' answers in the docs?


Mostly in the source code. Otherwise, scattered all over the documentation: it 
depends on what you consider lower level.


If you're familiar with C, or just curious, you might read this part:

http://docs.python.org/extending/extending.html#reference-counts


--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Memory and functions

2011-12-18 Thread Peter Otten
Charles Becker wrote:

 For functions that return values (ie the list method pop): If you don't
 assign the returned value to anything does it still end up residing in
 memory?  Just seems like this could be a potential problem to watch out
 for when memory usage is an issue (probably not most of the time).

Every object in CPython has a counter to keep track how many times it is 
referenced. When this counter drops to zero the object is destroyed and the 
memory is available for reuse. This is simple and works most of the time 
except when there are reference cycles. Consider:

class A: 
pass
a = A()
b = A()
a.other = b
b.other = a
del a
del b

There is now no way for your program to reach a or b, but the reference 
counter of a is still one because it is referenced by b as b.other, and the 
reference counter of b is still one because it's referenced by a. 
Therefore CPython has another mechanism called garbage collection as a 
backup that periodically searches for reference cycles.

While the specific mechanism described above is only implemented in CPython 
all variants (pypy, jython, ironpython) guarantee that you don't have to 
bother about object lifetime.


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] where does the ViewerFrameWorkGUI come from

2011-12-18 Thread Walter Prins
Lina,

On 18 December 2011 05:08, lina lina.lastn...@gmail.com wrote:
 Hi,

 I met below issue:

 File /usr/lib/python2.7/dist-packages/ViewerFramework/VF.py, line
 369, in __init__
    self.GUI = ViewerFrameworkGUI(self, title=title,
 NameError: global name 'ViewerFrameworkGUI' is not defined


 can someone tell me how to examine,

 I mean, how to examine, what would you do when you face the problem?

You should be telling us what you're doing, what platform you're
using, what packages you've installed and so on, and not be leaving us
to guess these things.  It makes our job harder than it would
otherwise be.  That said, I've spent only a few minutes to
troubleshoot this and will outline what I did so you can see what I
did when faced with this problem:

1.) Some googling reveals to me that ViewerFramework/VF.py apparently
forms part of a molecular visualization package called
mgltools-viewerframework.
2.) OK so Installing this package yields the same files in the same
location on my Ubuntu 11.10 box.
3.) Trying to see what was going on, I then when on to inspect the
referenced source file at line 369, where it becomes apparent that the
code is trying instantiate a class ViewerFrameworkGUI.
4.) The question then occurs: Where does this class come from?  How is
it that it's not defined?  Consequently I started searching for this
class, firstly in the same file, so see where it may be defined or
where it might be imported from.
5.) Doing so I found the following code at line 221 in VF.py:
try:
from ViewerFramework.VFGUI import ViewerFrameworkGUI
except:
pass

Curious, I thought, how is it that this module can fail to import
this class?  And why is it squashing the exception?  Generally I would
consider this type of behaviour very undersireable.  Far better would
be to stub or mock out the class with a fake that gives some useful
behaviour if it's instantiated (e.g. even if just to give some
sensible error message to the end user...) but perhaps this is a
semi-standard way of stubbing out optional extensions to packages in
Python.

6.) So next I decided to manually replicate the aboev import in the
Python interpreter to see what would happen:
walterp@s1:/usr/lib/python2.7/dist-packages/ViewerFramework$ python
Python 2.7.2+ (default, Oct  4 2011, 20:06:09)
[GCC 4.6.1] on linux2
Type help, copyright, credits or license for more information.
 from ViewerFramework.VFGUI import ViewerFrameworkGUI
Traceback (most recent call last):
  File stdin, line 1, in module
  File /usr/lib/python2.7/dist-packages/ViewerFramework/VFGUI.py,
line 21, in module
import Tkinter, thread, string, Pmw, types
ImportError: No module named Pmw


Well then, what's this 'Pmw' that's missing? I thought to myself.  A
quick google later and I found it: http://pmw.sourceforge.net/

7.) OK, so that import will fail with an exception due to Pmw being
missing (if it's not installed), but it'll go unnoticed due to the
exception handler squashing it.  This however means that the
ViewerFrameworkGUI class is not always defined, which will cause other
stuff depending on it to fail mysteriously (as you've found.)  At this
point, not knowing anything about the packages involved, I'd
tentatively suggest that perhaps the Pmw package should be a
dependency of the mgltools-viewerframework, and it not being might be
an omission/bug in the package.  Then again maybe they deliberately
don't want the mgltools-viewerframework package to be neccesarily
dependant on the Pmw package but keep it optional.  Whatever the case
is, the bottom line is that you need it in order to solve this
issue...

8.) Knowing that oftentimes python modules are packaged on Debian
based systems (like Ubuntu) as python-xxx I then tried:
sudo apt-get install python-pmw
... and voila, the Pmw module should now be there.

9.) Thus I retried my experiment to manually import ViewerFrameworkGUI
as before:
walterp@s1:/usr/lib/python2.7/dist-packages/ViewerFramework$ python
Python 2.7.2+ (default, Oct  4 2011, 20:06:09)
[GCC 4.6.1] on linux2
Type help, copyright, credits or license for more information.
 from ViewerFramework.VFGUI import ViewerFrameworkGUI
Traceback (most recent call last):
  File stdin, line 1, in module
  File /usr/lib/python2.7/dist-packages/ViewerFramework/VFGUI.py,
line 22, in module
from PIL import Image, ImageTk
ImportError: cannot import name ImageTk

Hmmm, so now it's not finding the ImageTk class from the PIL library
for some reason I thought.  Why might that be...?  I checked and I
did in fact have the PIL library already installed, so it wasn't that
PIL wasn't there at all.  (This should've been expected since if PIL
wasn't there at all, then presulably importing Image would've also
failed...)

A little bit of further googling and I find some evidence that ImageTk
was (for whatever reason) seperated into its own package with the
advent of Python 2.6 (See
http://www.python-forum.org/pythonforum/viewtopic.php?f=4p=65248 and

[Tutor] 'str' object has no attribute 'description'

2011-12-18 Thread Russell Shackleton
I am learning Python classes by writing an adventure game. I have extracted 
just the relevant code. The player can look, go, drop, take, inventory but not 
examine.

Python produces the error message in the Player class, examine function, in the 
first print statement. 

How do I fix this code, please?

class Player(object):
The player in the game.
def __init__(self, name, currentRoom=None):
self.name = name
self.currentRoom = currentRoom
self.items = [] # items taken by Player

def look(self):
Prints the room description, exits and items in the current room.
print self.currentRoom

def go(self, direction):
Go to another room through an exit.

def drop(self, item):
Drop an item you are carrying in the current room.

def take(self, item):
Take (pick up) an item from the current room.
if item == self.currentRoom.item:
self.items.append(item)
print self.currentRoom.item +  added to player's inventory..\n
# remove item from currentRoom
self.currentRoom.item = ''
else:
print There is no  + item +  here to take!\n

def inventory(self):
Prints list of items the player is carrying.

def examine(self, item):
Prints description of item.
if item in self.items:
# Error: 'str' object has no attribute 'description'
print Item Description:  + item.description + .\n
else:
print You are not holding the  + item +  to examine!\n

class Item(object):
A useful item in the game.
def __init__(self, name, description, location):
self.name = name
self.description = description
self.location = location

def __str__(self):
Description of item.
return self.description

class Game(object):
The adventure game.
def __init__(self, name, player):
self.name = name
self.player = player
print Welcome to  + self..name + \n
print player.currentRoom

def play(self, character):
Command loop for game.
while True: # loop forever
commands = raw_input(- ).lower()
if not commands:
print Huh?
else:
try:
cmdlist = commands.split()  # separate commands
action = cmdlist[0]
if action == quit:
print See you later!
break
elif action == look:
elif action == go:
elif action == take:
elif action == drop:
elif action == examine:
if len(cmdlist) != 2:
print An examine command must be followed by an 
item name.
continue
else:
character.examine(cmdlist[1])
elif action == inventory:
except AttributeError, msg:
print Error - undefined method:  + str(msg)

def main():
# Room descriptions
room5 = Room(name=hallway, description=You are in a dark hallway., 
item=diary)

# Item descriptions
diary = Item(name=diary, description=grey-covered Croxley diary, 
location=room5)

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] 'str' object has no attribute 'description'

2011-12-18 Thread Wayne Werner
On Sun, Dec 18, 2011 at 4:06 PM, Russell Shackleton rsh...@xtra.co.nzwrote:

 I am learning Python classes by writing an adventure game. I have
 extracted just the relevant code. The player can look, go, drop, take,
 inventory but not examine.

 Python produces the error message in the Player class, examine function,
 in the first print statement.


It's best to give the full traceback, because it provides an awful lot of
information.

-Wayne
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] unsupported operand

2011-12-18 Thread stm atoc
Well, I tried to  check and I do not have that problem any more..but i
have the clear script as follows and a couple of question regarding to
this:

# coding: utf-8
from pylab import *
import numpy
import matplotlib.pyplot as pyplot
import matplotlib.mlab as mlab
#tmax=360

with open(ourtest_out.list, r) as f:
   t = numpy.array([float(v) for v in f.readline().split()[1:]])

for t, filename in enumerate(ourtest_out.list):

a = numpy.loadtxt(ourtest_out.list, skiprows=3)
Conc=[]
#Conc = a[:, 200]
Conc.append(a[:,200])
#Conc = a[0:, tmax+1:]
plot(Conc,t)
show()

My main problem is, i do try to see the plot of Conc according to
time. I have a graph without any data!
Basically, I have a program written in FORTRAN including conc, time,
etc. calculation. The out put data shows that I do have concentration.
However, i am not able to have a plot based on time.
I should mention that I did have run the model (fortran) for
concentration according to the number of layer (N=200) and defined the
concentration like this Conc(0:N). Perhaps the reason that I am not
able to see the concentration with time is because of this definition.
BUT, still if I do plot based on pyplot.pcolor, I have a nice and
seems correct graph.

So, actually, I am not sure what is the problem for showing the
regular/linear plot. I hope I made it clear now..

Would it be possible to give me some hint please?

Thank you in advance,
Sue

On Sun, Dec 18, 2011 at 2:07 AM, Steven D'Aprano st...@pearwood.info wrote:
 stm atoc wrote:

 and this is the error that I got:


 Would you like us to guess which line causes the error?

 Please show the ENTIRE traceback. Do not retype it from memory, paraphrase
 or simplify it, or otherwise change it in any way. Copy and paste it.


 TypeError: unsupported operand type(s) for -: 'list' and 'int'

 What would you suggest?


 The code sample you showed did not include any subtractions. This hints that
 perhaps you are not showing us all of the code you are actually running. The
 full traceback will answer that one way or the other.

 Otherwise, I suggest you look at the line which the traceback prints. It
 probably has something like result = a - b (or some other subtraction).
 Look for the two variables: one of them is set to a list.


 --
 Steven


 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] 'str' object has no attribute 'description'

2011-12-18 Thread Hugo Arts
On Sun, Dec 18, 2011 at 11:23 PM, Wayne Werner waynejwer...@gmail.com wrote:
 On Sun, Dec 18, 2011 at 4:06 PM, Russell Shackleton rsh...@xtra.co.nz
 wrote:

 I am learning Python classes by writing an adventure game. I have
 extracted just the relevant code. The player can look, go, drop, take,
 inventory but not examine.

 Python produces the error message in the Player class, examine function,
 in the first print statement.


 It's best to give the full traceback, because it provides an awful lot of
 information.

 -Wayne


Wayne's right. Always give us a full traceback. Where the error
finally shows itself is rarely the same as where it's first started,
and a traceback can tell us that.

That said, you did a pretty good job of removing irrelevant code
(thank you!! it helps us a lot! :), and I was able to find your
particular error. It starts in this snippet:

elif action == examine:
   if len(cmdlist) != 2:
   print An examine command must be followed
by an item name.
   continue
   else:
   character.examine(cmdlist[1]) # --- right here

the problem is that cmdlist is just a list of strings. Hence
cmdlist[1] is a string as well. And strings don't have the description
attribute, hence python is complaining. What you likely meant is not
to examine not the string, but the item object with a name that equals
that string.

HTH,
Hugo
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] PYTHONPATH (Mac OS X)

2011-12-18 Thread Stayvoid
Hey there!

How to set it right?


Cheers!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor



[Tutor] 'str' object has no attribute 'description'

2011-12-18 Thread Russell Shackleton
I am learning Python classes by writing an adventure game. I have extracted 
just the relevant code. The player can look, go, drop, take, inventory but not 
examine.

Python produces the error message in the Player class, examine function, in the 
first print statement.

I have added the traceback following a suggestion from Wayne Werner.

Traceback (most recent call last):
  File adv03.py, line 205, in module
main()
  File adv03.py, line 202, in main
game.play(adventurer)
  File adv03.py, line 147, in play
character.examine(cmdlist[1])
  File adv03.py, line 86, in examine
print Item Description:  + item.description + .\n
AttributeError: 'str' object has no attribute 'description'
[Note: actual line numbers appended in comments in this listing]

How do I fix this code, please?

class Player(object):
The player in the game.
def __init__(self, name, currentRoom=None):
self.name = name
self.currentRoom = currentRoom
self.items = [] # items taken by Player

def look(self):
Prints the room description, exits and items in the current room.
print self.currentRoom

def go(self, direction):
Go to another room through an exit.

def drop(self, item):
Drop an item you are carrying in the current room.

def take(self, item):
Take (pick up) an item from the current room.
if item == self.currentRoom.item:
self.items.append(item)
print self.currentRoom.item +  added to player's inventory.\n
# remove item from currentRoom
self.currentRoom.item = ''
else:
print There is no  + item +  here to take!\n

def inventory(self):
Prints list of items the player is carrying.

def examine(self, item):
Prints description of item.
if item in self.items:
# Error: 'str' object has no attribute 'description'
print Item Description:  + item.description + .\n # line 86
else:
print You are not holding the  + item +  to examine!\n

class Item(object):
A useful item in the game.
def __init__(self, name, description, location):
self.name = name
self.description = description
self.location = location

def __str__(self):
Description of item.
return self.description

class Game(object):
The adventure game.
def __init__(self, name, player):
self.name = name
self.player = player
print Welcome to  + self.name + \n
print player.currentRoom

def play(self, character):
Command loop for game.
while True: # loop forever
commands = raw_input(- ).lower()
if not commands:
print Huh?
else:
try:
cmdlist = commands.split()  # separate commands
action = cmdlist[0]
if action == quit:
print See you later!
break
elif action == look:
elif action == go:
elif action == take:
elif action == drop:
elif action == examine:
if len(cmdlist) != 2:
print An examine command must be followed by an 
item name.
continue
else:
character.examine(cmdlist[1]) # line 147
elif action == inventory:
except AttributeError, msg:
print Error - undefined method:  + str(msg)

def main():
# Room descriptions
room5 = Room(name=hallway, description=You are in a dark hallway., 
item=diary)

# Item descriptions
diary = Item(name=diary, description=grey-covered Croxley diary, 
location=room5)

game.play(adventurer)   # line 202
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] sqlite3: turning on foreign key support thru python

2011-12-18 Thread Wayne Werner
On Fri, Dec 16, 2011 at 1:43 PM, Modulok modu...@gmail.com wrote:

  How do I tell if it succeeded (short of trying an operation that should
 be
  blocked by foreign keys)?  How do I use that cursor object returned by
 the
  pragma query to tell if its a '1' (on) or a '0' (off) and verify the
 state?


 The cursor object contains the result set. It's a python generator object.
 (Or
 at least a generator interface.) You have to iterate over it in order to
 see
 the resulting rows which are stored as a tuple. Not all operations return a
 result row. (For example, conn.execute('pragma foreign_keys=ON' will
 return a
 cursor object, but it won't generate any result rows, as there were
 none returned by the database.)

 To see the result of your second command, do something like this::

rows = conn.execute('pragma foreign_keys')
for r in rows:
print r


If you're mucking about in the interactive prompt, and you just want to see
the results quickly you can just turn it into a tuple or a list (list would
be less typing):

print(list(rows))

or just

list(rows)

HTH,
Wayne
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] reset password program

2011-12-18 Thread Wayne Werner
On Fri, Dec 16, 2011 at 7:17 PM, Robert Sjoblom robert.sjob...@gmail.comwrote:

  Some improvements to think about, in order of least secure (easiest) to
 most
  secure (hardest).
 
  (1) my secret password.txt is a crappy name. Is there a better name?

 I'm going to go with EULA.txt; the reasons should be obvious.


+1, because I laughed.

-Wayne
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] 'str' object has no attribute 'description'

2011-12-18 Thread Wayne Werner
On Sun, Dec 18, 2011 at 4:49 PM, Russell Shackleton rsh...@xtra.co.nzwrote:

 I am learning Python classes by writing an adventure game. I have
 extracted just the relevant code. The player can look, go, drop, take,
 inventory but not examine.

 Python produces the error message in the Player class, examine function,
 in the first print statement.

 I have added the traceback following a suggestion from Wayne Werner.


That's much more useful. As a slight aside, it probably would have been
better to just reply-all to the original thread with the traceback.



 Traceback (most recent call last):
  File adv03.py, line 205, in module
main()
  File adv03.py, line 202, in main
game.play(adventurer)
  File adv03.py, line 147, in play
character.examine(cmdlist[1])
  File adv03.py, line 86, in examine
print Item Description:  + item.description + .\n
 AttributeError: 'str' object has no attribute 'description'
 [Note: actual line numbers appended in comments in this listing]


This is *much* more helpful - I don't even need to see your code to tell
you what went wrong. I don't know if you've worked with other programming
languages with nearly useless stack traces, but in Python you'll find that
they're (usually) very high quality. In this case it tells you a few
things. First, it tells you where it happened with this line:

  File adv03.py, line 86, in examine

It happened in the file adv03.py, on line 86, in a function (or method)
called examine.

The next two lines tell you what blew up, and why it did:

   print Item Description:  + item.description + .\n
 AttributeError: 'str' object has no attribute 'description'


'str' object has no attribute 'description'. Well if you look on the line
before that the only description attribute you try to look up is
item.description. So if 'str' doesn't have that attribute then item must be
a string.

With that in mind, let's take a look at that function:

   def examine(self, item):
Prints description of item.
if item in self.items:
# Error: 'str' object has no attribute 'description'
print Item Description:  + item.description + .\n # line 86
else:
print You are not holding the  + item +  to examine!\n


This looks pretty straightforward. You pass something in as item, and check
to see if it's contained in your list of items. If it is, then you print
out the description, otherwise you print out whatever you passed in.

And so if we rewind back to where you call the function:

  character.examine(cmdlist[1]) # line 147


What is cmdlist? A list of strings. What is contained in cmdlist[1]?

If you still have issues fixing this, please let us know.

HTH,
Wayne

How do I fix this code, please?

 class Player(object):
The player in the game.
def __init__(self, name, currentRoom=None):
self.name = name
self.currentRoom = currentRoom
self.items = [] # items taken by Player

def look(self):
Prints the room description, exits and items in the current
 room.
print self.currentRoom

def go(self, direction):
Go to another room through an exit.

def drop(self, item):
Drop an item you are carrying in the current room.

def take(self, item):
Take (pick up) an item from the current room.
if item == self.currentRoom.item:
self.items.append(item)
print self.currentRoom.item +  added to player's inventory.\n
# remove item from currentRoom
self.currentRoom.item = ''
else:
print There is no  + item +  here to take!\n

def inventory(self):
Prints list of items the player is carrying.

def examine(self, item):
Prints description of item.
if item in self.items:
# Error: 'str' object has no attribute 'description'
print Item Description:  + item.description + .\n # line 86
else:
print You are not holding the  + item +  to examine!\n

 class Item(object):
A useful item in the game.
def __init__(self, name, description, location):
self.name = name
self.description = description
self.location = location

def __str__(self):
Description of item.
return self.description

 class Game(object):
The adventure game.
def __init__(self, name, player):
self.name = name
self.player = player
print Welcome to  + self.name + \n
print player.currentRoom

def play(self, character):
Command loop for game.
while True: # loop forever
commands = raw_input(- ).lower()
if not commands:
print Huh?
else:
try:
cmdlist = commands.split()  # separate commands
action = cmdlist[0]
if action == quit:
print See you later!
break
  

Re: [Tutor] unsupported operand

2011-12-18 Thread Alan Gauld

On 18/12/11 22:35, stm atoc wrote:

Well, I tried to  check and I do not have that problem any more..but i
have the clear script as follows and a couple of question regarding to
this:

# coding: utf-8
from pylab import *
import numpy
import matplotlib.pyplot as pyplot
import matplotlib.mlab as mlab
#tmax=360

with open(ourtest_out.list, r) as f:
t = numpy.array([float(v) for v in f.readline().split()[1:]])

for t, filename in enumerate(ourtest_out.list):
a = numpy.loadtxt(ourtest_out.list, skiprows=3)


You do realize that you are throwing away the t that you created above?
And I'm pretty sure this loop is not doing what you think it is...
Lets try an experiment at the ? prompt:

 for t,f in enumerate('testing'):
...print t,f
...
0 t
1 e
2 s
3 t
4 i
5 n
6 g


Is that what you would have expected?



Conc=[]
Conc.append(a[:,200])


What is a?


plot(Conc,t)
show()


HTH

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] 'str' object has no attribute 'description'

2011-12-18 Thread Alan Gauld

On 18/12/11 22:06, Russell Shackleton wrote:

I have extracted just the relevant code.


Its possible you extracted too much but


class Player(object):
 The player in the game.
 def __init__(self, name, currentRoom=None):
 def take(self, item):
 Take (pick up) an item from the current room.
 if item == self.currentRoom.item:
 self.items.append(item)
 print self.currentRoom.item +  added to player's inventory..\n
 # remove item from currentRoom
 self.currentRoom.item = ''


Here at least you are making item a string rather than an Item()


 def examine(self, item):
 Prints description of item.
 if item in self.items:
 # Error: 'str' object has no attribute 'description'
 print Item Description:  + item.description + .\n


And here you access the item.description which doesn';t exist for strings.
But you could get rounfd that by converting item to a str(). Then if it 
is an Item instance your __str__ method gets called - thats why you 
defined it right? - and if its already a string the same string gets 
returned...



 print You are not holding the  + item +  to examine!\n



class Item(object):
 A useful item in the game.
 def __init__(self, name, description, location):
 self.name = name
 self.description = description
 self.location = location

 def __str__(self):
 Description of item.
 return self.description

class Game(object):
 def play(self, character):

def main():
 # Room descriptions
 room5 = Room(name=hallway, description=You are in a dark hallway., 
item=diary)



Notice that  the item is just a strinng, not the diary object. Which 
doesn't actually exist yet anyhow!



 # Item descriptions
 diary = Item(name=diary, description=grey-covered Croxley diary, 
location=room5)


This appears to be the only place you ever instantiate an Item? But this 
is not what you assigned to room5...


So you are not assigning Items to the rooms. Unless its in the code you 
deleted?


HTH,

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] PYTHONPATH (Mac OS X)

2011-12-18 Thread bob gailer

On 12/18/2011 5:45 PM, Stayvoid wrote:

Hey there!

How to set it right?

You may not get an answer as your question is pretty vague.

Please clarify, or expand, or tell us what problem you are having or 
trying to solve.


--
Bob Gailer
919-636-4239
Chapel Hill NC

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] where does the ViewerFrameWorkGUI come from

2011-12-18 Thread lina
On Mon, Dec 19, 2011 at 4:28 AM, Walter Prins wpr...@gmail.com wrote:
 Lina,

Hi Walter,

I am sorry, before I posted I did not realize people would get much
attention to do all following as you did.

Thanks,

Well, yesterday I posted a bug report and later during my waiting,
based on it's also python related, so I was interested in digging
further, googled showed me uninstall python 2.6 and re-install
autodocktools will solve this problem (but later checked, it's not a
sound/logical way of solving this problem, might with my
luck/careless, during this process, something was fixed)

before uninstall python2.6,
the VF.py, well, when I tried to grep ViewerFrameworkGUI, it shows no
results, but used ViewerFramework,

after I removal of python2.6, during re-installation of autodocktools,
the relevant depedence package (), in the situation without 2.6,

I checked the VF.py, now it has the ViewerFrameworkGUI, not ViewerFramework.
and then I installed 2.6,

as you can see in my box, both
/usr/lib/python2.7/dist-packages/ViewerFramework/VF.py
/usr/lib/python2.6/dist-packages/ViewerFramework/VF.py

all symbolic links to
/usr/share/pyshared/ViewerFramework/VF.py

I still don't understand what's going on.

and it's pretty weird, before I cat VF.py | grep  ViewerFrameworkGUI,
it showed no result, but now it has.

and most weird is that I noticed the
-rw-r--r-- 1 root root  62177 Aug 18 06:38 VF.py

it's been month ago, seems nothing changed.

even yesterday I also remove and re-install the mgltools-viewerframework.
2011-12-18 13:15:06 remove mgltools-viewerframework
1.5.6~rc2+cvs.20110926-1 none
2011-12-18 13:56:00 install mgltools-viewerframework none
1.5.6~rc2+cvs.20110926-1

Thanks with best regards,




 On 18 December 2011 05:08, lina lina.lastn...@gmail.com wrote:
 Hi,

 I met below issue:

 File /usr/lib/python2.7/dist-packages/ViewerFramework/VF.py, line
 369, in __init__
    self.GUI = ViewerFrameworkGUI(self, title=title,
 NameError: global name 'ViewerFrameworkGUI' is not defined


 can someone tell me how to examine,

 I mean, how to examine, what would you do when you face the problem?

 You should be telling us what you're doing, what platform you're
 using, what packages you've installed and so on, and not be leaving us
 to guess these things.  It makes our job harder than it would
 otherwise be.  That said, I've spent only a few minutes to
 troubleshoot this and will outline what I did so you can see what I
 did when faced with this problem:

 1.) Some googling reveals to me that ViewerFramework/VF.py apparently
 forms part of a molecular visualization package called
 mgltools-viewerframework.
 2.) OK so Installing this package yields the same files in the same
 location on my Ubuntu 11.10 box.
 3.) Trying to see what was going on, I then when on to inspect the
 referenced source file at line 369, where it becomes apparent that the
 code is trying instantiate a class ViewerFrameworkGUI.
 4.) The question then occurs: Where does this class come from?  How is
 it that it's not defined?  Consequently I started searching for this
 class, firstly in the same file, so see where it may be defined or
 where it might be imported from.
 5.) Doing so I found the following code at line 221 in VF.py:
 try:
    from ViewerFramework.VFGUI import ViewerFrameworkGUI
 except:
    pass

 Curious, I thought, how is it that this module can fail to import
 this class?  And why is it squashing the exception?  Generally I would
 consider this type of behaviour very undersireable.  Far better would
 be to stub or mock out the class with a fake that gives some useful
 behaviour if it's instantiated (e.g. even if just to give some
 sensible error message to the end user...) but perhaps this is a
 semi-standard way of stubbing out optional extensions to packages in
 Python.

 6.) So next I decided to manually replicate the aboev import in the
 Python interpreter to see what would happen:
 walterp@s1:/usr/lib/python2.7/dist-packages/ViewerFramework$ python
 Python 2.7.2+ (default, Oct  4 2011, 20:06:09)
 [GCC 4.6.1] on linux2
 Type help, copyright, credits or license for more information.
 from ViewerFramework.VFGUI import ViewerFrameworkGUI
 Traceback (most recent call last):
  File stdin, line 1, in module
  File /usr/lib/python2.7/dist-packages/ViewerFramework/VFGUI.py,
 line 21, in module
    import Tkinter, thread, string, Pmw, types
 ImportError: No module named Pmw


 Well then, what's this 'Pmw' that's missing? I thought to myself.  A
 quick google later and I found it: http://pmw.sourceforge.net/

 7.) OK, so that import will fail with an exception due to Pmw being
 missing (if it's not installed), but it'll go unnoticed due to the
 exception handler squashing it.  This however means that the
 ViewerFrameworkGUI class is not always defined, which will cause other
 stuff depending on it to fail mysteriously (as you've found.)  At this
 point, not knowing anything about the packages involved, I'd
 tentatively suggest that