lllllIllIlllI 178 Veteran Poster

Sorry wait, that only solves half of the problem. The thing i only just spotted was that you go Monster.__init__. That then means that all of Monsters methods will now be stored in self. So you can call self.getAttributesInfo But the problem with that is there are two methods called self.getAttibutesInfo One is in the Orc and Troll classes and the other is in the Monster class so then we have to change the name of one of them to make sure that the program does not call the method over and over and over.

I fiddled with the code and here is what i got:

#!/usr/bin/env python

import random

choice = 0

class weapon(object):
    def _init_(self, attack, defense):
        self.attack = self.attack
        defense = self.defense

    def getAttributesInfo(self):
        attributes = ['Attack:' + self.attack,
        'Defense:' + self.defense]
        return ' '.join(attributes)

class sword(weapon):
    def _init_(self):
        wepon._init_(self, random.randrange(1,3), random.randrange(1,3))

    def getAttributesInfo(self):
        weapon.getAttributesInfo()

class axe(weapon):
    def _init_(self):
        weapon._init_(self, random.randrange(1,5), random.randrange(1,5))
        print 'This Axe\'s Attributes are:'
        print 'Attack:' + self.attack
        print 'Defense:' + self.defense

    def getAttributesInfo(self):
        weapon.getAttributesInfo()
        
class player():
    def _init_(self):
        self.health = 10
        self.defense = 4
        self.base_attack = 3
        self.attacking = 1

    def weapon(self):
        self.weapon = random.range(1,2)
        if self.weapon == 1:
            self.weapon = sword()
            print "you got a sword."
        elif self.weapon == 2:
            self.weapon = axe()
            print "you got an axe."

    def attack(Monster):
        if not self.attacking == 1:
            self.attacking = 1
        if self.weapon.attack > monster.defense:
            hit = True
            monster.health = monster.health - self.weapon.damage
            print 'You hit him for ' + self.damage + 'damage!' …
lllllIllIlllI 178 Veteran Poster

In your code you go:

Monster.getAttributesInfo()
#and
weapon.getAttributesInfo()

The problem with this is that you are not instanciating your class. First creat an instance of the class and then you can call methods then. Otherwise you will keep getting this error.

lllllIllIlllI 178 Veteran Poster

Try editing it in IDLE, you are probably getting an Error/Exception. If you double click it to start your python script then if there is an error it will not tell you what it is, the window and program will just close. If you run it from IDLE (F5) then if an error occours it will tell you where and why there is an error.

Hope that helps.

lllllIllIlllI 178 Veteran Poster

Okay, do you have any code so-far or are you starting from scratch?

lllllIllIlllI 178 Veteran Poster

perhaps you could bind it to an event so when you press enter it does something like this:

def enter(self,event):
    text = self.textarea.GetValue()
    self.textarea.SetValue(text+'\n')

But maybe to get it to process the enter button you have to add the style wx.PROCESS_ENTER and then bind it:

self.textarea.Bind(wx.EVT_TEXT_ENTER,self.enter)

Hope that works, tell me how it goes.

lllllIllIlllI 178 Veteran Poster

I mean if you had a square $1 note. I rekon people would think it was so amazing that it must therefore be worth more!

lllllIllIlllI 178 Veteran Poster

Hi guys,
I was just wondering how far peole have ever gotten in the python challenge?
if you havent heard of it, it is a series of python based problems that explore many programming techniques including regex and images. If you havent tried it the link to it is:
http://www.pythonchallenge.com
Tell us all where you get up to. :)

lllllIllIlllI 178 Veteran Poster

Oh my gosh. You are amazing. I have googled for hours. But never thinking along the lines of putting translucent into my search. But it is perfect. It works so amazingly well.

Thankyou so much, that is absolutley perfect. :)

lllllIllIlllI 178 Veteran Poster

Ha ha ha, Perfect! But we arent exactly stretching a buck, it looks more like shrinking it.

Gosh thats the best idea so far :P

lllllIllIlllI 178 Veteran Poster

Yeah i did it a while ago and i remember getting to level 10

lllllIllIlllI 178 Veteran Poster

Oh its good. Actually i was wondering, do you rekon anyone from here has finished it?

lllllIllIlllI 178 Veteran Poster

What is the chance of that happening do you rekon?

lllllIllIlllI 178 Veteran Poster

If you ever need the values of wx ID's as well as any other constants in wxPython here is a way to do it:

import wx

class MainFrame(wx.Frame):
    def __init__ (self):
        wx.Frame.__init__(self,None,title = "ID's and Values", size=(400, 400))
        self.text = wx.TextCtrl(self, wx.ID_ANY, style = wx.TE_MULTILINE)
        
       
        for f in wx.__dict__:
            if f.startswith("ID_"):
                t = f+'  -->  '+str(wx.__dict__[f])+'\n'
                self.text.write(t)
        self.Show()
        

app = wx.App(False)
f = MainFrame()
app.MainLoop()

If you want a full dictionary of values try this:

import wx

class MainFrame(wx.Frame):
    def __init__ (self):
        wx.Frame.__init__(self,None,title = "ID's and Values", size=(400, 400))
        self.text = wx.TextCtrl(self, wx.ID_ANY, style = wx.TE_MULTILINE)
       
        for f in wx.__dict__:
            try:
                t =  f+'  -->  '+str(int(wx.__dict__[f]))+'\n'
                self.text.write(t)
            except:
                pass
        
        self.Show()
        

app = wx.App(False)
f = MainFrame()
app.MainLoop()

Notive that bit where is goes str(int(wx.__dict__[f])) ? Thats to make sure that anything that has a value that isnt an int will not work as there will be an error and the program will skip it.

lllllIllIlllI 178 Veteran Poster

Hi Guys,
I was wondering if there was any way in which you can change the opacity of a window in wxPython. I would like to create a window that is mostly see through but so far i have found no way to do that. My program is a simple frame with a few staticTexts on it so it is pretty standard kind of wxPython program.

Any help on this topic would be greatly appreciated! :)

lllllIllIlllI 178 Veteran Poster

Okay, what it your whole program try and do? I'm not quite sure with the information given.

lllllIllIlllI 178 Veteran Poster

Have you tried the python challenge?
http://www.pythonchallenge.com/
It is a bit obscure sometimes yet a lot of fun and can really test how efficient your code can be.

lllllIllIlllI 178 Veteran Poster

Could you post your code please. I made myself a wx.RichText based frame and it works no problems so maybe we would have more chance solving the problem with a bit of code to work with.

lllllIllIlllI 178 Veteran Poster

Okay, so python 2.4 for that one as well. cool, ill download it to test it out.

Gosh yeah, how much longer heh? If developers arent making things for it any more it is going to quickly fall behind and gradually die i guess. I hope not!

lllllIllIlllI 178 Veteran Poster

Yeah good point. Maybe it could square the value of the currency? Because you think that the $ in Australia (where i live) is a different value to the $ in America. So maybe squaring the dollar would make it... more valuable? Yet there would still be just two dollars, just the two dollars would be worth more.

lllllIllIlllI 178 Veteran Poster

Hi guys,
I was looking at some of the commercial IDE's today. Most notably being wingware's python IDE personal edition. I was wondering wether people thought wether the $30 you need to pay for it is worth it or is it not that great when it comes to it.

Any input would be a great help. Thanks :)

lllllIllIlllI 178 Veteran Poster

Ah bummer. Should i move this project onto another language such as C++ or do you rekon i could still do it in python?

lllllIllIlllI 178 Veteran Poster

So i have to install python 2.4 on my computer still to do that?

lllllIllIlllI 178 Veteran Poster

Is there anywhere to download pysonic for python 2.5? Because i cant find it on the sourceforge page..

lllllIllIlllI 178 Veteran Poster

I was about to choose it when I failed to see debugger. That made me give up!

Yeah that did it for me as well. I really enjoy having a debugger in my IDE. It makes it a lot easier. Though i still hate it how i cant find an IDE that dosent to the whole wx.App has not been created error! That is really annoying yet seemingly unavoidable. IT comes around when using wxPython and you run it a few times and then it sends an error saying that the wx.App has not been created?!

lllllIllIlllI 178 Veteran Poster

What happens now when you hit return?

Oh and for the algin left and right just bind something to this code:

#to align left
self.textarea.ApplyAlignmentToSelection(rt.TEXT_ALIGNMENT_LEFT)
#to align right
self.textarea.ApplyAlignmentToSelection(rt.TEXT_ALIGNMENT_RIGHT)

Hope that helps

lllllIllIlllI 178 Veteran Poster

Yeah you cant assign values to a string. Thats what your program is trying to do. Well i would advise using a dictionary for this one:

d1 = {}
d2 = {}
for swipeload in range (0, 15, 1):
    d1["E"+str(swipeload)+"_Path"] = os.path.join("data","E"+str(swipeload)+".gif")
    d2["E"+str(swipeload)] = pygame.image.load("E"+str(swipeload)+"_Path")

This now has a dictionary where the string values are the keys and the values are what you want. The first dictionary holds the path while the second dictionary holds the image.

Hope that helps

lllllIllIlllI 178 Veteran Poster

Well a percent sign means x/100 dosent it? So that sum would be
1/100 * 2/100 = 2/10000
So pretty much 2%(squared) as well. Well that one is easier then the dollar sign. :)

But with the dollar sign couldn't you do algebra with that? Just pretend that the dollar sign is just a fancy looking x?

lllllIllIlllI 178 Veteran Poster

No not necessarily on a computer. I know a computer wouldn't do it, but what about maths, or just hypothetically. :)

lllllIllIlllI 178 Veteran Poster

So. Today i had this though. What is one dollar times two dollars.
Instantly the thought sprang to mind that it would be two dollars right? Becuase 1 x 2 = 2. But then i though wait. What about the dollar sign?
That means that this has become algebra! So then i thought this:
1x2 = 2 AND $x$ = $Squared
So the answer would be
two dollars squared.
But i was wondering what people think about that. Is i correct? And if so, how would you write two dollars squared because squaring a dollar sign just sounds a tad odd.
Oh well, just thoughts would be fun. What do you rekon it should equal?

lllllIllIlllI 178 Veteran Poster

Okay well got an update for everyone. I am using pyAudio and wave modules to play my .wav file. Now i can set the "Rate" in which the file plays. This i can change at the start of the program and it will change the rate at which the sound is played. This changes the speed and therefore the pitch. My issue is, with using pyAudio i haven't been able to work out how to change the rate while the application is running.

So if anyone knows how to do that. That will be very helpful.

lllllIllIlllI 178 Veteran Poster

Well im on windows if that helps. How would i change the sample rate? Is there an easy way to do that in python?

lllllIllIlllI 178 Veteran Poster

If your using a GUI you may want to take a look at this piece of code:
http://www.daniweb.com/forums/post623822-10.html

lllllIllIlllI 178 Veteran Poster

I really enjoy pyScripter on windows, it lets you debug as well as run the script. Syntax highlighting, automatic indentation. Its a great piece of software.

lllllIllIlllI 178 Veteran Poster

Hi guys,
I have a program that lets the user play a sound but i was wanting to know how i could make it so the user could vary the speed in which the sound plays so the sound can play slowly and quickly and normaly as well. Is this even possible with python? Becuase i was looking and i couldn't find any modules to help me with this problem but if anyone could give me a hand that would be greatly appreciated.
Thanks.

lllllIllIlllI 178 Veteran Poster

I used to do this is i wanted to restart the file:

exec file("File Name Here")

That will re-open your python program again.

lllllIllIlllI 178 Veteran Poster

Okay, here goes:

The program starts off and we have our list called A. This has in it, 65,88,2,9876,33,8. Okay.
the program then uses a range to iterate over. To start off with the program makes J the value of 1.
The key will then equal 88 because thats whats at A[1]. But now i will equal 0. Because of that the loop will not go through and i+1 = key, for this iteration this does nothing because 0+1 = 1 so A[1] = A[1].

Now the next iteration of the range has J as 2. Sorry im going through this slowly, but this is what i find is useful for a full understanding. So the key will equal 2. the vairable i will now equal 1 and the loop will go through because i is more than 0 (or equal to). And also 88 (a) is more than 2. So as we go through the loop we start by moving things. The first thing we move is A[i+1] i+1 = 2 so we are moving our number 2. We replace number 2 with 88 and then subtract 1 from i and keep going. Now i is 0 and the list look like this: 65,88,88,9876,33,8.
This time the program asks, is A > key, A = 65 so thats true and also i is not less than one. This time the loop goes through through things move again, A[i+1] (88) = A (65) so now …

lllllIllIlllI 178 Veteran Poster

This is a sorting function.
It grabs a number from the list, that is now the key.
Then in the while loop it moves the values to the right if they are more then the key, so essentially, it gets a number from a list. It then compares it with the other numbers and if the number they compare it with is bigger the bigger number moves to the end of the list.
Do you need a more detailed explaination?

lllllIllIlllI 178 Veteran Poster

You can also get it by using the class.__dict__ method.

>>> class tester(object):
	def f1(self):
		print '1'
	def f2(self):
		print '2'
	def HELLO(self):
		print 'Hello'

		
>>> print tester.__dict__
{'f1': <function f1 at 0x00BB8AF0>, '__module__': '__main__', 'f2': <function f2 at 0x00BB8B30>, '__doc__': None, '__dict__': <attribute '__dict__' of 'tester' objects>, '__weakref__': <attribute '__weakref__' of 'tester' objects>, 'HELLO': <function HELLO at 0x00BB8B70>}
>>>

Notice you use the __dict__ method on the class not on an instance of the class.

lllllIllIlllI 178 Veteran Poster

Ah! Got it. i have been looking at your code and i notice this:

print p.Hi()

the problem is that you dont need to print it becuase the printing is done INSIDE the method, so for this just delete the print statement and just have:

class add:
    def __init__(self, name):
        self.name = name
    def Hi(self):
        
        print self.name, "just joined"
        
while True:                          
    i = raw_input("command>")
    if i.split()[0] == 'add':
        p = add(i.split()[1])      
                                    
        p.Hi()                    #dont print a function that does not return anything
        
    else:
        print "no"

The only times in which you can PRINT a function is when it returns something, in this case the function p.Hi() didnt return anything so the value None was given.
Hope that helps.

lllllIllIlllI 178 Veteran Poster

So you want the user to be able to specify which class to use?
Well a way to do that would be to split the string and do some if statements such as:

i = raw_input()
if i.split()[0] == 'add':
    p = add(i)
    p.hi

If thats not it could you just maybe clarify it for us.
Thanks

lllllIllIlllI 178 Veteran Poster

yeah sorry its rather stuffed up code. Ill try and fix that, the main thing i want to grab from that is the idea that to position it in the middle all you have to do is get the parents position and add half of its size.

That is just the basic concept im trying to show. Sorry it didnt work.

lllllIllIlllI 178 Veteran Poster

Well there might be a better way but you could go something like:

# lets assubme variable self.frame is your frame
class Frame(wx.Frame)
    def __init__(self)
        wx.Frame.__init__(self,None,pos = (100,100))
        self.Show()
        self.Dialog()
    def Dialog()
        d = wx.Dialo("arguments here")
        d.Position = (self.frame.Position[0]+(self.frame.Size[0]/2,self.frame.Position[1]+(self.frame.Size[1]/2
        d.ShowModal()

I think that should work.
It takes the frames position and adds half of its size to get the position of the dialog.

lllllIllIlllI 178 Veteran Poster

in that case you parse no arguments by giving it an empty tuple.
So it would be

os.execv("path here",())
lllllIllIlllI 178 Veteran Poster

If you want help for syntax. There is an easy way to do it. you go something like this for your example:

# just type each line in the interpreter
>>> import os
>>>help(os.execv)
#displays info

in your case it shows this:

Help on built-in function execv in module nt:

execv(...)
    execv(path, args)
    
    Execute an executable path with arguments, replacing current process.
    
            path: path of executable file
            args: tuple or list of strings

Hope that helps

lllllIllIlllI 178 Veteran Poster

when you go.

if word in tuplelist:
    #do stuff

That is a problem. The reason is your comparing something that looks like this:

"Hello"

To something that looks like this

[("hello","something you say as a greeting")]

Now those dont look quite the same right?
So what you need to do is say,

if True in [word == f[0] for f in tuplelist]:
    #do stuff

That might not be the most efficient way but it will work better.

lllllIllIlllI 178 Veteran Poster

yeah that did the trick. Thanks a lot.

lllllIllIlllI 178 Veteran Poster

Corn chips, mmmm very healthy!

lllllIllIlllI 178 Veteran Poster

Really? This a parody, it sounds exactly like judge judy on a completly normal day! Ha ha ha, very good. :)

lllllIllIlllI 178 Veteran Poster

I cant get the link to work. It says this:

You have attempted to access code for an article that does not exist. Create this article first. If the article used to exist, it may have been deleted.

Am i the only one getting this problem?

lllllIllIlllI 178 Veteran Poster

Thanks alex, thats really helpful. Thats all my problems solved.. for the moment