lllllIllIlllI 178 Veteran Poster

Here!

s = '/home/dir1/dir2/folder1/file' 
list_s = s.split('/')
print '/'.join(list_s[1:]
lllllIllIlllI 178 Veteran Poster

Well i think your first problem is here:

w = input(random.randrange(100)+)

input is a built in function that only needs a string and gets input from the user. There are a few other things that dont work in your program, like print w*random will just times w by random and give back one number, here is a sample of what i think you mean to do

import random

exit = False
while not exit:
    nums = input("how many numbers?")
    for f in range(nums):
        print random.randrange(0,100),

That will give you the amount of numbers you want, ill leave the exiting for you to figure out.

But do you see how this works?
I get the user input of how many random numbers and then i loop through that many times and print out a random number between zero and one hundred. Then that gets printed out.

lllllIllIlllI 178 Veteran Poster

Well on the forums remember to use code tags

[code]

code here

[/code]
But here is the code you have

def count(sub, s):
    """
    >>> count('is', 'Mississippi')
    3
    >>> count('an', 'banana')
    3
    >>> count('ana', 'banana')
    3
    >>> count('nana', 'banana')
    3
    >>> count('nanan', 'banana')
    3
    """
    count = 0
    if sub in s:
        count += 1
    print count


if __name__ == '__main__':
    import doctest
    doctest.testmod()

There are a few problem is see with your doc. Firstly this one:
>>> count('ana', 'banana')
2
there is only ONE ana in banana, the other one is a cross over of it, so in that case you should have
>>> count('ana', 'banana')
1
as your docstring.


Also your function is wrong, it will only ever get one as a return value at max, that is because an if statement executes and then goes on.
This seems like a more relevant function.

def count(string, sub):
    return string.count(sub)

See how that goes, and ill help out if there is something still wrong with it.

lllllIllIlllI 178 Veteran Poster

But if you do really want to keep it in the procedure you have now, then os.startfile is what you need to look at.

#at the end of your code you put something like this
os.starfile(os.getcwd()+"\\Name of Python File.py")
#that will re-start your python file.
lllllIllIlllI 178 Veteran Poster

Just a thought, i cant see how it breaks out of the loop, so maybe move the other raw_input() in a bit:

# -*- coding: iso-8859-15 -*-
# check encoding in http://www.python.org/dev/peps/pep-0263/

def function1():
    print "Bonjour, comment allez-vous ?"

def function2():
    print "Hola, cómo esta usted?"

def function3():
    print "Hello, hoe zijn u?"

def function4():
    print "Hallo, wie geht es Ihnen?"

#main

print "Hello, how are you?"

while True:
    choice = raw_input("Enter a language (french, spanish, greek, german): ")
    if choice == "french":
         function1()
    elif choice == "spanish":
         function2()
    elif choice == "greek":
         function3()
    elif choice == "german":
         function4()
    else:
         print "You have to choose from french, spanish, greek or german!"

    if raw_input("\n\nPress the enter key to exit.") == '':
        break
lllllIllIlllI 178 Veteran Poster

Just a thought, i cant see how it breaks out of the loop, so maybe move the other raw_input() in a bit:

# -*- coding: iso-8859-15 -*-
# check encoding in http://www.python.org/dev/peps/pep-0263/

def function1():
    print "Bonjour, comment allez-vous ?"

def function2():
    print "Hola, cómo esta usted?"

def function3():
    print "Hello, hoe zijn u?"

def function4():
    print "Hallo, wie geht es Ihnen?"

#main

print "Hello, how are you?"

while True:
    choice = raw_input("Enter a language (french, spanish, greek, german): ")
    if choice == "french":
         function1()
    elif choice == "spanish":
         function2()
    elif choice == "greek":
         function3()
    elif choice == "german":
         function4()
    else:
         print "You have to choose from french, spanish, greek or german!"

    if raw_input("\n\nPress the enter key to exit.") == '':
        break
lllllIllIlllI 178 Veteran Poster

Python 2.6 has known issues with wxPython, i would reccomend that you download 2.5

lllllIllIlllI 178 Veteran Poster

heres a bit more:

running = True
sent = raw_input("Enter a sentence")

while running:

    for word in sent.split():
        if word[0] in "aeiou":
            print word + "way"

        else:
            print word[1:] + word[0] + "ay"

What i did was ask for a sentence at the start and then i split it into words using the sent.split() function, then i could do the whole sentence at once rather then one word at a time.

lllllIllIlllI 178 Veteran Poster

there is a really quick way to get a list of even numbers:

list_of_evens= [f for f in range(1,500) if f%2==0]

that should give all the even numbers from 1 to 500 in a list

scru commented: Actually it's one to 499, but I agree that a list omprehension is the easiest route. +5
lllllIllIlllI 178 Veteran Poster

just mark it as solved.

lllllIllIlllI 178 Veteran Poster

This will do the adding of the default value:

self.inputTxtThree = self.textbox('Starting at what hour? 6? 24 hr clock-\n or immediate start just accept 99.','99', bmp)



def textbox(self, label_str, default_value= "99", bmp = None):
		if bmp:
			bitmap = wx.StaticBitmap(self.panel, wx.ID_ANY, bmp)
			
		#label = wx.StaticText(self.panel,wx.ID_ANY, label_str,style=wx.TE_MULTILINE)
		label = wx.StaticText(self.panel,wx.ID_ANY, label_str)
		tbox = wx.TextCtrl(self.panel, wx.ID_ANY,size=(55, -1))
                tbox.SetValue(default_value)
		input_sizer   = wx.BoxSizer(wx.HORIZONTAL)
		input_sizer.Add((20,20), proportion=-1)  # this is a spacer
		if bmp:
			input_sizer.Add(bitmap, 0, wx.ALL, 5)
		input_sizer.Add(label, 0, wx.ALL|wx.ALIGN_RIGHT, 0,wx.TE_DONTWRAP)
		#self.gridSizer.Add(input_sizer, 1, wx.ALIGN_RIGHT, wx.TE_DONTWRAP)
		self.gridSizer.Add(input_sizer, 1, wx.ALIGN_RIGHT, wx.TE_DONTWRAP)

		self.gridSizer.Add(tbox, 0)
		return tbox
lllllIllIlllI 178 Veteran Poster

Here is an example of how one works:

import  wx
import  wx.lib.scrolledpanel as scrolled

class TestPanel(scrolled.ScrolledPanel):
    def __init__(self, parent):
        scrolled.ScrolledPanel.__init__(self, parent, -1)

        vbox = wx.BoxSizer(wx.VERTICAL)
        desc = wx.StaticText(self, -1,
                            "ScrolledPanel extends wx.ScrolledWindow, adding all "
                            "the necessary bits to set up scroll handling for you.\n\n"
                            "Here are three fixed size examples of its use. The "
                            "demo panel for this sample is also using it -- the \nwxStaticLine "
                            "below is intentionally made too long so a scrollbar will be "
                            "activated."
                            )
        desc.SetForegroundColour("Blue")
        vbox.Add(desc, 0, wx.ALIGN_LEFT|wx.ALL, 5)

      

        self.SetSizer(vbox)
        self.SetAutoLayout(1)
        self.SetupScrolling()


app = wx.App(0)
frame = wx.Frame(None, wx.ID_ANY)
fa = TestPanel(frame)
frame.Show()
app.MainLoop()

Hope that helps you out!:)

lllllIllIlllI 178 Veteran Poster

Yeah thats not too hard:

def printfunc(star=star, *printers):
    for item in printers:
        print star[item]
        #if you want it all on one line then use pring star[item],
lllllIllIlllI 178 Veteran Poster

if you are using wx then just go:

text.SetValue("Default Value Here")

Where text is your wx.TextCtrl

lllllIllIlllI 178 Veteran Poster

Dont worry, this can be lots easier. First we can find the minimun of a list by using the min function, the max by using the max function!

So :

li = [1,2,3,4,5,6,7,8,9,1,11,5,0,64]
print min(li) #0
print max(li) #64
print li.index(max(li))  #position 13
print li.index(min(li))   #position 12

To get the numbers you can use a loop like this:

li = []
value = '-1'
while value != '':
    li.append(int(raw_input("Enter a number please, just press enter to stop")))

Then for the average you just need another loop, this time a for loop:

sum = 0
for item in list:
    sum += item
print "average is:", (sum*1.0)/;en(li)

That should help you out, just try piece it together for what you need to do.

lllllIllIlllI 178 Veteran Poster

I see a problem here. Firstly have a look at the start, there is an ' mark, this makes the value of resource a string forever and no dictionary. So resource equals all this:

}, "uri": "https://myserver.com//users/userkey/values/home"}', '{"metadata": {"type": "directory", "size": "2"}, "name": "estolume", "links": {"link": ["{\\"href\\": \\"https://myserver.com//users/userkey/values/estolume\\", \\"rel\\": \\"self\\"}", "{\\"href\\": \\"https://myserver.com//users/userkey/values/estolume\\", \\"rel\\": \\"edit\\"}", "{\\"href\\": \\"https://myserver.com/userkey/estolume\\", \\"rel\\": \\"webdav\\"}"]}, "uri": "https://myserver.com//users/userkey/values/estolume"}', '{"metadata": {"type": "directory", "size": "2"}, "name": "creatingnew", "links": {"link": ["{\\"href\\": \\"https://myserver.com//users/userkey/values/creatingnew\\", \\"rel\\": \\"self\\"}", "{\\"href\\": \\"https://myserver.com//users/userkey/values/creatingnew\\", \\"rel\\": \\"edit\\"}", "{\\"href\\": \\"https://myserver.com/userkey/creatingnew\\", \\"rel\\": \\"webdav\\"}"]}, "uri": "https://myserver.com//users/userkey/values/creatingnew"}', '{"metadata": {"type": "directory", "size": "2"}, "name": "test", "links": {"link": ["{\\"href\\": \\"https://myserver.com//users/userkey/values/test\\", \\"rel\\": \\"self\\"}", "{\\"href\\": \\"https://myserver.com//users/userkey/values/test\\", \\"rel\\": \\"edit\\"}", "{\\"href\\": \\"https://myserver.com/userkey/test\\", \\"rel\\": \\"webdav\\"}"]}, "uri": "https://myserver.com//users/userkey/values/test"}', '{"metadata": {"type": "directory", "size": "2"}, "name": "NewFolder", "links": {"link": ["{\\"href\\": \\"https://myserver.com//users/userkey/values/NewFolder\\", \\"rel\\": \\"self\\"}", "{\\"href\\": \\"https://myserver.com//users/userkey/values/NewFolder\\", \\"rel\\": \\"edit\\"}", "{\\"href\\": \\"https://myserver.com/userkey/NewFolder\\", \\"rel\\": \\"webdav\\"}"]}, "uri": "https://myserver.com//users/userkey/values/NewFolder"}', '{"metadata": {"type": "directory", "size": "2"}, "name": "NewTest", "links": {"link": ["{\\"href\\": \\"https://myserver.com//users/userkey/values/NewTest\\", \\"rel\\": \\"self\\"}", "{\\"href\\": \\"https://myserver.com//users/userkey/values/NewTest\\", \\"rel\\": \\"edit\\"}", "{\\"href\\": \\"https://myserver.com/userkey/NewTest\\", \\"rel\\": \\"webdav\\"}"]}, "uri": "https://myserver.com//users/userkey/values/NewTest"}', '{"metadata": {"type": "directory", "size": "2"}, "name": "newTestVolume", "links": {"link": ["{\\"href\\": \\"https://myserver.com//users/userkey/values/newTestVolume\\", \\"rel\\": \\"self\\"}", "{\\"href\\": \\"https://myserver.com//users/userkey/values/newTestVolume\\", \\"rel\\": \\"edit\\"}", "{\\"href\\": \\"https://myserver.com/userkey/newTestVolume\\", \\"rel\\": \\"webdav\\"}"]}, "uri": "https://myserver.com//users/userkey/values/newTestVolume"}']

And thats not what we want to try taking the ' key out of the second character in the last bit and that …

lllllIllIlllI 178 Veteran Poster

Yeah it would be nice to have the dictionary Exactly as it is in your program.. and also for readability just wrap it in

Your code here

but only have one forward slash

lllllIllIlllI 178 Veteran Poster

There certainly is a way!

import os

path = "path here"
seconds = os.path.getmtime(path)
print time.strftime('%Y-%m-%d %H:%M', time.localtime(seconds)
#it will output the time last modified!
lllllIllIlllI 178 Veteran Poster

something is wrong with the actual dictionary, when i put it into python i get errors along the lines of
SyntaxError: EOL while scanning single-quoted string

and i tried for a few minutes but i couldnt get it to work, the "" marks were all out of place.

lllllIllIlllI 178 Veteran Poster

If you post the actual error message it will make it a lot easier. I tells us the line in which the error happened

lllllIllIlllI 178 Veteran Poster

have you tried os.walk. That is a function that will iterate throught the files and sub directories of the folder you are talking about.

lllllIllIlllI 178 Veteran Poster

This loop will increment by 2!

for f in range(start=0, end=10, step=2):
    print f

Just replace 2 with anything you need

lllllIllIlllI 178 Veteran Poster

Well my next and last step would be to go to the wxpython mailing list and see if anyone there can help, i find if there is ever a problem in wx that cannot be fixed, that the mailing list really does the trick.

lllllIllIlllI 178 Veteran Poster

Whats the problem there? You could just set it to 1 or something like that.

lllllIllIlllI 178 Veteran Poster

Yeah i got the same issue when i did a program using a richtextctrl.
I fixed it by binding the delete key to an event where i called something along the lines of

self.text.SetSelection(self.text.GetCursor()[0],self.text.GetCursor()[1]+1)
self.text.DeleteSelection()

I remember having to bind it to a wx.EVT_KEY_DOWN event because i could not find one for DELETE specifically so then i just checked in the method to see if it was the delete key and then if it was the method continued to run.

lllllIllIlllI 178 Veteran Poster

Couldnt you just bind it to an event that called SetSelection before doing anything kinda like:

def method(self,event):
    self.richtext.SetSelection()
    #and then do all of your usual stuff here
lllllIllIlllI 178 Veteran Poster

And you can add to things as well and change things around. So you can have a class of Line, that has:

Attributes
start
end

And if you wanted to make box, well a box is just a complicated set of lines, so if you inherit from lines then you already have some stuff sorted out, though you can overwrite anything in lines by redefining it in box.

So box could have

Attributes
list_of_lines
area
curcumference

And then you can have a cube, which is just a number of boxes joined together, i guess i should have called box square huh? BUt it means that when making the cube you do not have to worry about lines, they are already dealt with, you do not worry about the squares being put together, they are already working, so all you have to do is work out the arrangement of the squares.

Classes generally are there and tend to (if used well) make your job a lot easier.

lllllIllIlllI 178 Veteran Poster

Just press space 4 times, then you have it indented the right amount. Do this for all of them, not the actual if statement but the stuff afterwards.
So

>>>if stuff == True:
...     print "stuff" #i pressed space 4 times
... else:
...     print 'no'
lllllIllIlllI 178 Veteran Poster

you did it already:

word = "Hello"
for letter in word:
    #this iterates through every letter in the variable word
#and to check if A in B then 
a = "1"
b = "123"
if a in b:
    #this will be tru, a is in b
lllllIllIlllI 178 Veteran Poster

Yep, save or not works well. Well done so far scu

lllllIllIlllI 178 Veteran Poster

Oh and the comctrl32.manifest is there. Is that a problem? Should i delete it or something?

lllllIllIlllI 178 Veteran Poster

Ah the value is False. Does that mean that curtains will not work unless you are using something like Vista? Or is there some way that i can make it work on XP?

lllllIllIlllI 178 Veteran Poster

So at the end of my loop i gave you you need to reconstruct the sentence so find a way to peice it back together. Here is a code snippet which might help:

first = "hello"
second = ""
for letter in first:
    second += letter

print second
#prints "Hello"

And what you need to do, is if that for every time through the loop you check to see if the letter is a vowel, if it is then the if statement will be true and run, so then you would have to use that letter= letter.upper() code and that would capitalize your letter ready to be added onto the second string.

lllllIllIlllI 178 Veteran Poster

Woops silly me, i didnt download the .exe installer. Okay well its installed now.. But im at a loose end.. Can you tell us how we would be able to test the taskdialog. Because my current code:

#testing Curtains

import curtains

def tester(event):
    print "hello"

f = curtains.TaskDialog("Hello",'World',"Please do smething", "retry")
f.bind(curtains.BUTTON_CLICKED,tester)
f.show()

This raises an error:
NameError:global name 'indirect' is not defined
Line 8 in module: f.show()
Line 307 in show: indirect(byref(conf), byref(button), byref(radio), byref(checkbox)

So if there is something i am doing majorly wrong just post it. It would be lovely to just post a simple example of a working taskdialog.

lllllIllIlllI 178 Veteran Poster

We need more infomation, are you making a webpage using python? What is it you really need solved, where are you redirecting from.

If you take a minute or two more writing down your problem people will find it a lot easier to answer any questions that arise.

lllllIllIlllI 178 Veteran Poster

Okay, well not to fully solve the problem for you i would do something like this:

S = raw_input("Enter a sentence:")

vowels = 'aeiou'

for letter in S:
    if letter in vowels:
        #letter is a vowel
        letter.upper()

Now that does nothing at all, just shows you an idea, what you need to do is have another variable and add the letter to it each iteration of the loop.. see if you can do that yourself.

If you have any questions about how this works just post!

lllllIllIlllI 178 Veteran Poster

Okay, i dont know if this is a bit of a dump question but how do i install it? I keep getting a system exit when i try.

Oh and by the way, i read it was not based on anything, so wow. Does it work using ctypes or something like that?

Well done, it looks really nice so far though. The website and the API.

lllllIllIlllI 178 Veteran Poster

Okay, i see you are using wing IDE, well in that case go to stack and go to the Call Stack, Click on them one by one and at one of them you will get something do with the actual problem, not just the function that called the problem.

So tht way you will be able to give greater detail as to whats going on.

lllllIllIlllI 178 Veteran Poster

504

lllllIllIlllI 178 Veteran Poster

I would say to replace this:

if delete=="yes":
                del records[entry]["Title"]
                del records[entry]["Director"]
                del records[entry]["Year"]
                del entry

With this

if delete=="yes":
                del records[entry]
                del entry

That will remove it from the records *completley* so you shouldnt have it still looking for it when it comes to re-print all the records.

Hope that helps.

lllllIllIlllI 178 Veteran Poster

Well can you post the whole error because that usually also shows what line it is on, it makes it easy to debug. But ill give you an example of something that would get that error:

f = open("infile.txt")
f()            #here i would get my error. The file variable is not callable
f.close()
lllllIllIlllI 178 Veteran Poster

What you are doing is trying to delete a string. that is impossible, you can delete a variable, here is an example:

del "hello" #will not work
h = "hello"
del h   #works
h = [1,2,3,4,5]
del h  #works

h = {"1":1,"2":2}
del h #also works

del 1   #will not work

So for your code:

if delete=="yes":
    
    del records[entry]["Title"]
    del records[entry]["Director"]
    del entry

That will now delete those records from the dictionary records and also the variable entry.

Hope that works better

lllllIllIlllI 178 Veteran Poster

I think i solved this problem once by just going str(stringvar) . Im not quite sure if it definitley works.. it might have been something else.

lllllIllIlllI 178 Veteran Poster

Yeah i can help a bit as well... maybe a bit slow.. i have a broken computer and i am left with using an old decrepit computer from years and years ago

lllllIllIlllI 178 Veteran Poster

Well if you want the python.exe you find it in
C:\Pythonxx\python.exe

If you want it to be opened by IDLE then you find that in:
C:\Pythonxx\Lib\IdleLib\idle.bat

If you then check "open with this every time" box then it will do that.

Oh and xx is the version of python, so 2.5 is 25 and 2.3 is 23

lllllIllIlllI 178 Veteran Poster

Personally i never use GUI builders, i just code from scratch, it leaves you learning a lot more about the code and how it works and stuff like that, so in my opinion its best to just learn how to write the code

lllllIllIlllI 178 Veteran Poster

500

lllllIllIlllI 178 Veteran Poster

Okay, so a vector is basically a direction of where to go with a velocity. I think... Okay, well i don't think there is more to be learnt so i will mark this as solved. Thanks for the help guys.

lllllIllIlllI 178 Veteran Poster

Hmmm... i sortove get it, what is the point of having whole classes devoted to vectors though, it seems a bit over the top if its just the position and velocity of something, is there something deeper i do not understand here?

lllllIllIlllI 178 Veteran Poster

A statement in python is something that is already set as what is does, if is a statement, break is another, print is a statement.

An expression is something that evaluates to something. Such as adding numbers or strings together evaluates to something.