lllllIllIlllI 178 Veteran Poster

I used a function and that cut down on code needed:

# Character Development Dungeons and Dragons
# pool are the total points that I can use.
pool = 30
strength = 0
health = 0
wisdom = 0
dexterity = 0
choice = None

def getInt(prompt, maximum, cur):
    
    i = 0

    print prompt
    i = int(raw_input())
    
    while (cur+i) > maximum:
        print prompt
        i = int(raw_input())
        
    return i
    

    
while choice !="0":
    current = 0
    print \
    """

    Character Development

    0 - Exit
    1 - attributes
    """
    
    choice = raw_input("Choice: ")
    print
    # exit
    if choice == "0":
      print "Good-bye."
   
    # Strength points
    elif choice == "1":
      strength = getInt("How much strength points do you want?: ", pool,current)
      current +=strength
      print "Your Strength points are", strength
      health = getInt("How much health points do you want?: ", pool,current)
      current +=health
      print "Your health points are", health
      wisdom = getInt("How much wisdom points do you want?: ", pool,current)
      current +=wisdom
      print "Your wisdom points are", wisdom
      dexterity = getInt("How much dexterity points do you want?: ", pool,current)
      current +=dexterity
      print "Your dexterity points are", dexterity
      balance = int(pool-strength-health-wisdom-dexterity)
      print "After deducting all your attribute points you have", balance , "total points left",

    # some unknown choice
    else:
      print "Sorry, but", choice, "isn't a valid choice."

raw_input("\n\nPress the enter key to exit.")
lllllIllIlllI 178 Veteran Poster

Hi,
Im making a program that is sortove like a media player... well, it is a media player. Its quite basic at the moment but i have been working on a few features. One of the things it can do is that it can play a video full screen. I did it using

self.ShowFullScreen(True, style=wx.FULLSCREEN_ALL)

But... i have two windows in my program, one is the player, the thing that the video displays on, and one is the play, pause, stop windows. The control panel if you will. My problem is that when i go full screen i want the control panel to jump IN front of the full-screened window. I using wx.STAY_ON_TOP. But that got annoying because every time i got in and out of fullscreen i would need to change it. So i was wondering, is there a simple way to send a window to the front of a screen.

Thanks

lllllIllIlllI 178 Veteran Poster

Urllib i think gets the source code for a webpage and not what is actually on it. So maybe hunt around for another module that will help you. Or perhaps you actually need the 12th line of the source code of a webpage which you would get like:

>>> import urllib2
>>> data = urllib2.urlopen('http://www.google.com')
>>>

The variable data is now a file like object with all of the data that makes up www.google.com.

Hope that helps

lllllIllIlllI 178 Veteran Poster

Normally when you open a file though it will re-write the file, that is if you open it in write mode. So make sure, if you dont want anything wiped that you can either load the file into a string or something, change what you want and then re-write it to a file. Or you can have a look at append write mode.

lllllIllIlllI 178 Veteran Poster

You could also go:

import random
w1 = ["abacus", "biology", "chemistry", "dog",  "elf", "ghost"]
for f in range(len(w1)):
    w = random.choice(w1)
    w1.remove(w)
    print w
lllllIllIlllI 178 Veteran Poster

There are lots of python HTML modules out there and places that teach you loads about HTML with python:
http://www.boddie.org.uk/python/HTML.html
http://www.hoboes.com/Mimsy/?ART=128
wiki.python.org/moin/WebProgramming

lllllIllIlllI 178 Veteran Poster

Ah, your problem is the following.
You have put in your raw_input() to open the file e:. The problem with that is that you are asking it to open a full directory, not just a file. I had this same problem instead with writing files. You need to specify an actual FILE to open, not a folder or anything else.
So if you put in e:\test_file.txt into the raw_input() and there was a text file called text_file then your program would work.

lllllIllIlllI 178 Veteran Poster

Just wonding, i know a lot of people here will probably not have heard of Panda3D. Me included. Personally i would reccommend talking to the people at the site. Here is a place that has forums that deal with Panda3D, they may be able to offer more help:
http://panda3d.org/phpbb2/index.php

lllllIllIlllI 178 Veteran Poster

What GUI tookit are you using?

lllllIllIlllI 178 Veteran Poster

Just in case you dont usually run it from the command line (maybe you just double click). Here is how you would do it on windows:

First go to the start menu and choose run
type 'cmd'
press enter
using the 'cd' (change directory) function navigate to the place that your python program is in
then write in the following: python name_of_script.py

lllllIllIlllI 178 Veteran Poster

Okay, firstly, what are you talking about? Are you using Notepad to save your python files and that is stuffing up?
Are you using IDLE and that wont save?
Have you got a save box in your program that stuffs it up?

Please provide more information, otherwise its hard to help

lllllIllIlllI 178 Veteran Poster

I got this problem once. I fixed it my (in windows XP) by opening the task manager and ending any processes of python. I found that some of my previous programs, usually the wxPython ones, were excellent at leaving behind processes especially if they didnt end properly. I find that fixes most of my problems with things not connecting.

Hope that helps.

lllllIllIlllI 178 Veteran Poster

Just a word of advice about your if in your code. That is statement will almost always execute unless start is equal to zero. The reason is, even though saying OR something else. You cant apply the same operator to each. So you would have to go:

if start >0 or end > 0:
    #do stuff
lllllIllIlllI 178 Veteran Poster

We wont be able to help you unless you also provide the code for theGraph. Otherwise we are just guessing.

lllllIllIlllI 178 Veteran Poster

Chris the first one worked a charm. Thanks!

lllllIllIlllI 178 Veteran Poster

Well there are a few ways to do it. Preferably i would use a dictionary but as we cant here is another way:

import string
number = raw_input("Please enter the number:").lower()
n_list = list(number)

for enu,f in enumerate(number):
    if f in string.ascii_lowercase:
        i = string.ascii_lowercase.index(f)+2
        i /= 3
        if i == 0:
            i +=1
       
        
        n_list[enu] = '123456789'[i]
        
print ''.join(n_list)

an example output:

Please enter the number:1800-testing
1800-8378463

Wow.. that worked better then i thought it would.
Enjoy!

lllllIllIlllI 178 Veteran Poster

I have noticed that whenever i run it onSetPath() never seems to ever get run. Would this be a problem, or is it just me that this is happening to?

lllllIllIlllI 178 Veteran Poster

Where can we download all of the bitmaps for the buttons for it?

lllllIllIlllI 178 Veteran Poster

Yeah, the problem seems to be that the email module is not being packed with the .exe file and i couldn't find a way to get it to be. Does anyone know how i can package all of the stuff i import?

lllllIllIlllI 178 Veteran Poster

Hi guys,
I was making a program yesterday that would send an email using the email modules of python as well as the smtp module.
My problem is when i put it into an exe using py2exe and vega's code snippet setup i get some problems. This is the error message i get when i try and run the .exe file:

Traceback (most recent call last):
File "email_program.py", line 2, in <module>
File "email\__init__.pyc", line 79, in __getattr__
ImportError: No module named multipart

The thing is that is works fine when i run it when it is not compiled into an exe. Im not that crash hot with py2exe so i was wondering is someone with a bit more idea with me could point me in the right direction. Here is my code for any reference.

import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email import Encoders
import pythoncom, pyHook
import os
global s
s = ""
gmail_user = "*************"
gmail_pwd = "************"

def mail(to, subject, text):
   msg = MIMEMultipart()

   msg['From'] = gmail_user
   msg['To'] = to
   msg['Subject'] = subject

   msg.attach(MIMEText(text))


   mailServer = smtplib.SMTP("smtp.gmail.com", 587)
   mailServer.ehlo()
   mailServer.starttls()
   mailServer.ehlo()
   mailServer.login(gmail_user, gmail_pwd)
   mailServer.sendmail(gmail_user, to, msg.as_string())
   # Should be mailServer.quit(), but that crashes...
   mailServer.close()

mail('paulthom12345@gmail.com',
     'subject',
     'Hello from python')

Cheers!

lllllIllIlllI 178 Veteran Poster

Thanks a lot for that!

lllllIllIlllI 178 Veteran Poster

Could you test how many pixels are red? Because a circle will require many more pixels to draw then a line.
I know when getting colours i used something like:

import Image
im = image.open("myPic.jpg")
for pixel in im.getdata():
    #check if it is red
lllllIllIlllI 178 Veteran Poster

Hi Guys,
My setup is as follows, i have a D-Link DI-524 router and four computers. Three of them have windows XP Professional while the other computer has windows XP Home edition.

They are all connected to the router. The ones with winows Professional are all wireless while the one with winows home edition is wired.

The wireless cards that two of the computers use are D-Link DWL-G122. The other wireless computer uses an inbuilt one.

The problem with the network is that the computers have stopped sharing files between them and even have stopped being able to detect each other in the workgroup. This is strange because it all used to work and i can't think of anything that has changed.

I was wondering if anyone knew how i could fix this problem. It is really annoying, i have tried re-doing all the network setup wizard and all but it still dosent work.

Any help or guidance would be greatly appreciated

lllllIllIlllI 178 Veteran Poster

Yep, that works a charm. I tried something simillar before but it didnt work. Oh well, that all works now, thanks Chris!

lllllIllIlllI 178 Veteran Poster

Okay both of those did not actually do anything different from my first idea. So i went with the SendKeys module and sent the backpace key once so that the cursor would be taken back to the start again.

I do have one last issue though, that is, this text that gets entered in this textCtrl gets pasted up into another, this slowly accumulates. Soon though the text starts to need a scroll bar. My problem is that the text dissapears at the end of the TextCtrl. I want to be able to auto-scroll or something like that but i cant find out how to make it automatically always scroll down to the end.

lllllIllIlllI 178 Veteran Poster

Just make sure that both things you want are methods. I think you will want to do something like:

import wx #if using wxPython
import thread

class Frame(wx.Frame):
    #all the code stuff

def image(path):
    #image stuff

# then you go:
app = wx.App(0)
f = Frame()
thread.start_new_thread(app.MainLoop,())
thread.start_new_thread(image,(path))
shadwickman commented: Threading idea/example was a HUGE help! +2
lllllIllIlllI 178 Veteran Poster

Well python only does one thing at a time so perhaps while the images are being done it dosent do the GUI. A way around this is to use the thread module.

Threading is useful if you want two things to be able to happen at once.

lllllIllIlllI 178 Veteran Poster

No i dont think so.

Emulate key press required an event. I think that means somethign like wx.EVT_TEXT or something. Am i wrong? Can you use the backspace character or some kind of ascii key code?

lllllIllIlllI 178 Veteran Poster

Hi guys
I am making a program that uses a text control to move messages from one place to another. My program needs to be able to, once the message has been moved, delete what is in the textCtrl. I can go:

self.textCtrl.SetValue('')

but that leaves me with a problem as the next time i put my cursor in the text control it is one line down. It added a whole line! So i was wondering how i would combat this so that the textctrl would be reset to have nothing in it?

lllllIllIlllI 178 Veteran Poster

Woops, should have called them paramaters. If you have any that are needed then you put them as the second paramater but if there are no paramaters needed for the MeWin method then you dont need to have a second paramater.
Note that you dont put parentheses after the self.MeWin the the wx.CallAfter.

Stefano Mtangoo commented: Brilliant Boy! +2
lllllIllIlllI 178 Veteran Poster

you would call wx.CallAfter(self.MeWin,ARGUMENTS) and then that will call the function after the YouWin function is done.

lllllIllIlllI 178 Veteran Poster

It is used with events in wxPython. If you have a button lets say that when you press it pops up a dialog box. But there is also something else going on and you want the method that makes that dialog box to be called After the event function is done.

So here is the example from http://wiki.wxpython.org/CallAfter

import threading,wx

ID_RUN=101
ID_RUN2=102

class MyFrame(wx.Frame):
    def __init__(self, parent, ID, title):
        wx.Frame.__init__(self, parent, ID, title)
        panel = wx.Panel(self, -1)
        mainSizer=wx.BoxSizer(wx.HORIZONTAL)
        mainSizer.Add(wx.Button(panel, ID_RUN, "Click me"))
        mainSizer.Add(wx.Button(panel, ID_RUN2, "Click me too"))
        panel.SetSizer(mainSizer)
        mainSizer.Fit(self)
        wx.EVT_BUTTON(self, ID_RUN, self.onRun)
        wx.EVT_BUTTON(self, ID_RUN2, self.onRun2)

    def onRun(self,event):
        print "Clicky!"
        wx.CallAfter(self.AfterRun, "I don't appear until after OnRun exits")
        s=raw_input("Enter something:")
        print s

    def onRun2(self,event):
        t=threading.Thread(target=self.__run)
        t.start()

    def __run(self):
        wx.CallAfter(self.AfterRun, "I appear immediately (event handler\n"+ \
                        "exited when OnRun2 finished)")
        s=raw_input("Enter something in this thread:")
        print s

    def AfterRun(self,msg):
        dlg=wx.MessageDialog(self, msg, "Called after", wx.OK|wx.ICON_INFORMATION)
        dlg.ShowModal()
        dlg.Destroy()


class MyApp(wx.App):
    def OnInit(self):
        frame = MyFrame(None, -1, "CallAfter demo")
        frame.Show(True)
        frame.Centre()
        return True

app = MyApp(0)
app.MainLoop()
lllllIllIlllI 178 Veteran Poster

what does "DictionaryE.txt" look like? I would like to try and run it but i get an error because i have no "DictionaryE.txt" file.

lllllIllIlllI 178 Veteran Poster

you might have an issue with variables not being global. Try putting this at the start of your program.

global file_in
global file_size
lllllIllIlllI 178 Veteran Poster

see the indentation of line 14 and line 13 and line 12 and line 11 do not match the indentation needed to set them all inside the function. You just need to re-write this in a python editor and it should auto-indent it for you.

it should be

def random_word ():
    while True:
        offset =randint (0 ,file_size )
        file_in .seek (offset)
        L=file_in .read (25 ).split ("\r\n")
        if len (L)>2 :
            return L [1]
lllllIllIlllI 178 Veteran Poster

That will mean that the return is not being properly recognised as inside of the function. This could be an indenting problem or just accidentally having a return statement somewhere else in your program that isnt a function.

here is something that will raise that error

def add(x,y):
    z = x+y
return z

this will work though

def add(x,y):
    z = x+y
    return z
lllllIllIlllI 178 Veteran Poster

you use a range.

for variable in range(n/2):
    #do stuff
lllllIllIlllI 178 Veteran Poster

pickle! *slaps head* gosh, i never knew! I always thought it was just a way to store strings in a file that meant you could take it across any platform no worries. Thanks, thats amazing, it will revolutionalise my programming!

lllllIllIlllI 178 Veteran Poster

Could we have an example of what stock.txt has in it please?

lllllIllIlllI 178 Veteran Poster

This is not very hard if you use the random module.

import random

words = ['hello','python','monday','tuesday','friday','ice']
choice = random.choice(words)

print "Guess the word!"
guess = raw_input()
while guess.lower() != choice:
    print "sorry, not correct"
    guess = raw_input()
print "well dont that was it!"
lllllIllIlllI 178 Veteran Poster

Yesterday, i was programming a program in Java when i came accross something i though was just amazing. I could read and write complete Obects with just one line of code! They would go to a file and when i loaded then they would be straight back, without me having to do anything that difficult. The thing i was using was java.io.ObjectInputStream/ObjectOutputStream.

My question is: is there anything that does that in python, that lets you load and save objects so easily?

lllllIllIlllI 178 Veteran Poster

I think you could also use XML to save it. If you are using wxPython then there is an XML module you can load that makes it nice and easy to load.

The module is wx.xrc, it can load a panel, a frame or any other kind of object. Its great to have a fiddle with.

lllllIllIlllI 178 Veteran Poster

If you want to do that to an int and you just want to add it on the end then you could go:

>>> adam = 123
>>> john = 456
>>> #if you just add them together they don't add on to the end, 
>>> print adam+john
579
>>> print str(adam)+str(john)
123456
>>> # and then you can turn that back into an int using the int() function
lllllIllIlllI 178 Veteran Poster

I would also reccomend that when you write to the file you have a new line after each item. To do this then just go:

datalog.write(data+'\n')

Hope that helps

lllllIllIlllI 178 Veteran Poster

Just take the comma off the end of line 20. Adding the comma makes it a tuple.

lllllIllIlllI 178 Veteran Poster

Python would be easy to do this in. You could use a mixture of the random module as well as the String module and combining them together to get something that does it for you. In fact i will show you how i would do it if i was making a program that made a random string.

import random
import string

r = input("How long should the string be?")
s = ""
for number in range(r):
    s += string.lowercase[random.randint(0,26)]
print s
lllllIllIlllI 178 Veteran Poster

Your problem is that sys.argv is what you supply on the command line after starting the script. So you would go

python mycode.py arg1 arg2

For yours to work you need at least 2 arguments for there to be sys.argv[1]

lllllIllIlllI 178 Veteran Poster

I find functions still a great thing to have if you want to have something unrelated to either class. Personally i like to only have related functions in a class and if i want a function and there is no specific class that it fits into then i do not put it in a class and leave it out.

lllllIllIlllI 178 Veteran Poster

You could use list comprehension as well

binary = raw_input()
if False in [f == '0' or f == '1' for f in binary]:
	print "Not Binary"
else:
	print "Is Binary"
lllllIllIlllI 178 Veteran Poster

For starters you shouldnt use the word "file" as a variable. That is a keyword in python.