Namibnat 10 Junior Poster in Training

Maybe something like this:

option_input = raw_input(">>> ").upper()
if option_input == "V":
    print "High Scores:\n"
    saveFile = open("scores.txt", "r")
    scores = saveFile.readlines()
    for line in scores:
        if "," in line:
            userScore, userName = line.split(',')
            print "%2s, %s" % (userScore, userName.strip())

At the end of the program you're assigning the variables wrong and end up creating tuples. You need to have your print statement in the loop to cycle through the lines.

Namibnat 10 Junior Poster in Training

I only use Linux. My main work station runs Ubuntu 10.04 (although I'll move up soon - 10.10). I have some old computers around just for playing with and for my kids. On those I play around with other Linux distros - just to learn or see how they work and for fun.

Since I was a tour guide working at a lodge I had almost no interaction with computers for many years. When I did buy a laptop I ran Windows XP but still didn't use it to much. When I started trying to learn to program, the computer was always slow - you'd have to go away to make a cup of coffee each time you would boot up. I tried everything and then one day decided to try Ubuntu, which I had got in a book, and suddenly the laptop booted up really quickly. Compared with the initiations I was having trying to run Windows, Linux just seemed like a breath of fresh air.

So I never developed much of an attachment to anything on Windows - if anything I developed a dislike. My wife has her work stuff on a shiny new laptop with Windows 7 - which I guess seems okay - otherwise my household is all Linux. My seven year old son will already ask "Daddy, can I change my o-per-at-ing sys-tem today" and already knows the answer - "Sure, Mark, just remember you are going to loose all the games we …

Namibnat 10 Junior Poster in Training

Thanks tsmets,

I posted many questions since then all over the place and have already revived all the help I needed. I have also read a great deal of Django's documentation, and have developed a number of websites using Django.

Namibnat 10 Junior Poster in Training

I am new to working with Django, and have found it really fun and interesting to develop with. But I have been trying to upload it to a hosted server and just not getting it to work. I have followed the instructions they give, but just not getting it to work. There seem to be different instructions, and I am just not clued up enough to understand what applies me.

I have contacted the admins and have spent some time with the online help technicians, but they don't always know exactly what to do. The site is hosted with hostgator, through an company in Africa. I seem to have a delay in getting answer (probably because the technical guys are sitting on the exact opposite side of the world from me.)

Let me run you through what I have done (if I can now remember it all...I may well have messed everything up while trying):

1. Requested MySQLdb and Flup to be installed on the server for my site. Ran Python through SSH and tried import ... for both, and they both return without error.
2. Followed the instructions on this page:
http://support.hostgator.com/articles/getting-started/general-help/django-with-fastcgi
starting with the mkdir ~/django I follow along with the instructions: svn for the django trunk, make a directory for project, edit the bash_profile file in my /home/username directory.

Then I get to the start project part and start having trouble. They say that I have to go into …

Namibnat 10 Junior Poster in Training

If someone could recommend where (more appropriate forum) I should ask this question, I would appreciate that.

Namibnat 10 Junior Poster in Training

There are a couple things to set right with your code first.

n = random.randint(0, 99)
for i in range(1):

First, don't indent the for i in .... part. It is a code block itself.

Second, why have a code block that loops once. Just drop it.

The only loop you have left then is the while loop, now, not being in the for loop anymore (which it would have been), the while can also go right back to the line. The only indented stuff will be what follows it.

Okay, now to your question

How do i make this code to store data in a global variable, it create random number of elements.

Well, everything within this script is within the global namespace, so no worries there.

All you need to do is to save it in a list. In your example, your data_list is actually not a list at all, it's an int. Why not change that to data_element, and use data_list for the whole list.

import random, time

n = random.randint(0, 99)
data_list = []

print "-"*60
print "Here is some new elements! "

while n >= 0:   
    data_elements = random.randint(0,99)    
    print data_elements,    
    time.sleep(.10)
    data_list.append(data_elements)
    n= n-1

print "\ndata_list has %d elements" % len(data_list)
Namibnat 10 Junior Poster in Training

Hello, if I start to distribute some software I have written under a copyright, using a free software license, I would like to know what do the dates of the copyright stand for.

If I say (c) 2009-2010 Vernon Swanepoel, what does it mean that I did on those dates. The reason I am asking is can I do something like this (written in Python)

def copyrightText():
    from time import localtime
    if localtime()[0] == 2009:
        crD = "2009"
    else:
        crD = "2009 - %d" % localtime()[0]
    return crD

So that each year, the material's copyright simply updates itself. Is there a legal issue to doing that. I am not just asking Python specifically, if I do the same on a website, is there an problem with that.

Basically, if I am lazy, will I get burned :S One of the main reasons I would like to do this is for websites I build for clients, so that years from now they don't have to worry that the website's copyright thingi (heavy legal terminology, I know) is updated.

Namibnat 10 Junior Poster in Training

time.sleep()

import time
x = 1

for it in range(5):
    x = x*2
    time.sleep(x)
    print "Dude!...."
Namibnat 10 Junior Poster in Training

thx for the help but how could i print the length of whatever the parameters are?.. like length("tree", "computer") and it prints out the string the with length?... this is what i dnt get

how could i print the length of whatever the parameters are

Well, if you tried the example given by vegaseat, it gave you the length of parameters passed to the function 'length'. If that isn't what you are looking for, perhaps just re-phrase your question a little.

If all you are looking for is to get the length of a string the len('your string') will do the trick.

prints out the string the with length

Just take a closer look at the example given by Vegaseat. That is exactly what his function did. You give it a string, it prints the string and the length of the string.

Namibnat 10 Junior Poster in Training

Okay, like that it works. Now, I really believe that you are going to struggle to build all the functionality with bound events for this in a forum. You are talking about hundreds of lines of code for this file you have produced.

Why not scale it down. Deal with one concept at a time. One of the main ways that you are going to deal with these events is with wxdialogs, where, on pressing something, a dialog will pop up with some options to do stuff. It is best to put these in their own module and just import them into the methods. Otherwise your code will become unmanageable.

i don't have senior or any other person to guide me about that

And as for learning yourself, well, that is the long tradition of hacking. I work in Namibia as a tour guide part of the time and thought myself html/web scripting in order to spend more time at home with my kids. If I am on tour, I carry notes on regular expression or oop or whatever I am working on, with me and learn while I am far from a computer. If I have a 15 hour day...I still take time to flip through some tutorials at night before I sleep. -- If you are learning by yourself it is more important than anything to learn one concept at a time. Be patient. I really believe that it is pointless to learn all the gui …

vegaseat commented: Very nice advise! +10
Namibnat 10 Junior Poster in Training

A port is just an extra number tacked onto your IP address. Basically, they exist so multiple applications can use the same IP address simultaneously when they use different ports.

I recommend Beej's Guide to Network Programming for increased understanding. The section on port numbers has a bit more explanation.

Thanks, I'll be reading Beej's Guide to Network Programming over the weekend.


It says:

It is probably at its best when read by individuals who are just starting out with socket programming and are looking for a foothold.

That's me

Namibnat 10 Junior Poster in Training

A single computer may run a bunch of network applications simultaneously. Each incoming network packet must be routed to a particular one. Since the network layer has no idea of applications, the routing is done by means of ports. An applications (say, a server) binds its socket to a specific port, and a peer uses that port number as a part of destination address, so that the full address is ip:port, where ip identifies a computer, and port identifies an application (a socket, in fact) within that computer.

Ports are numbered from 0 to 65535. Some of them are assigned to specific servers. Everybody knows that port 80 is assigned to http server, port 22 to SSH etc. For a complete list of port assignments look at the IANA page.

Hope it helps.

Thanks...it helps.

Namibnat 10 Junior Poster in Training

i have changed the capitals to same character format but even than its giving me following errors...

Traceback (most recent call last):
  File "C:/Documents and Settings/bilal.nawaz/Desktop/kika.py", line 1, in <module>
    import wx
  File "C:\Python26\lib\site-packages\wx-2.8-msw-ansi\wx\__init__.py", line 45, in <module>
    from wx._core import *
  File "C:\Python26\lib\site-packages\wx-2.8-msw-ansi\wx\_core.py", line 5, in <module>
    import new
  File "C:\Documents and Settings\bilal.nawaz\Desktop\new.py", line 3, in <module>
  File "C:\Python26\lib\site-packages\wx-2.8-msw-ansi\wx\aui.py", line 106, in <module>
    new_instancemethod = new.instancemethod
AttributeError: 'module' object has no attribute 'instancemethod'

Did you make the other changes that I mentioned? You had:

#
self.Centre()
#
self.Show(True)

within a method, which wouldn't work That is the stuff that makes the gui display itself.

You do have wxPython? Just checking.

Why don't you go through and clean it up and then post your code with the correct indentation. Looking at the way you set it up, I wonder if you have learned the basics of dealing with classes/objects in Python? Maybe you need to have a look at a good tutorial covering those subjects. My personal favorite was 'dive into Python' which covers it really nicely.

You know, working with a gui is a lot of complicated bits. If you do not have the background of knowing Python very well to begin with, you will struggle with the gui stuff...you know, you need to think frame on panel on sizer...with this event, that event. It doesn't take very long at all to get very complicated and if you are struggling with Python itself, this isn't …

Namibnat 10 Junior Poster in Training

I have a follow up question, i cant get a grip of this random stuff..:)
How do i change this code line
del data_list[3:5+1]

so instead of removing specifik elements i want to remove random ones, amount of elements to be removed as well.

very thankful for this forum and i start to like python more and more.

I am not sure that this question has anything to do with your above question. You can use import random and then random.randint(0, 10) to generate a random number in the range (and including) 0 to 10.

Check it out and if you still have questions, perhaps ask it in a new thread.

Namibnat 10 Junior Poster in Training

All the port numbers, and what they're used for.
http://www.iana.org/assignments/port-numbers

Thanks so much.

Namibnat 10 Junior Poster in Training

One aspect of computers that I just don't find clear learning material on is networking. There seems to be loads of information on 'how to' but I still don't understand the underlying basics.

What is meant by a Port? Why are ports numbered so strange (as in, not 1,2,3).

I am using Ubuntu Linux. I can see what ports I have open (or something like that) and I have successfully connected up a nice home network. But I don't actually understand the what a port is and how it differed from directories.

If it is something that can be easily summed up, that would be great. If not, is there any clear, beginner intro to understanding linux (or any other) ports.

Namibnat 10 Junior Poster in Training

I assume that you indented correctly when you tried the code on your own?

View = wx.Menu()
###the python gives on this line and held my system### 
self.shtl = view.Append(1, 'Show toolbar', 'Show Toolbar', kind=wx.ITEM_CHECK)
view.Check(1, True)

'The Python' gives on this line due to the fact that you have 'View' View = wx.Menu and then just below it you want to append to 'view'. You need to make them the same. Capitalization matters in Python variables, as it does in most programming language.

Another problem, you assign to 'save' twice'

save = wx.MenuItem(file, 3, '&Save\tCtrl+S', 'Save')
        file.AppendItem(save)


        save = wx.MenuItem(file, 4, '&Save As...', 'Save As...')
        file.AppendItem(save)
        file.AppendSeparator()

I also assume that you know that your whole gui is just the menu? You don't have anything to print, save and so on. You need to call self.Show(True) in the __init__ method. You call it within an event method. It means your gui will not be shown if that even isn't triggered, which it can't be because your gui isn't showing - chicken/egg.

Namibnat 10 Junior Poster in Training

Put your code in code tags, and try to boil it down to what is going wrong a little.

Your 'View' and 'view' should be the same caps.

Namibnat 10 Junior Poster in Training

It might be a lot simpler to use the Python module enchant, see:
http://www.rfk.id.au/software/pyenchant/

I had actually found it while searching around, and I have been trying to install it (which is turning out tricker than is should be for linux, it certainly doesn't work with a simple get-apt)

If I get it all working nicely, I'll post an example.

Namibnat 10 Junior Poster in Training

Thanks jcao219,

I was assuming that there would be some easier way, but I guess not. I'll have to see if I can get stuck into getting something like that working.

Namibnat 10 Junior Poster in Training

Here is how you can approach it:

create an empty list:

newVals = []

First of all deal with the file. Open the file, read it to a variable (The hint vegaseat gave you - in the file.readlines()) and then close the file, you have the contents already in 'line'

input_file = open('xxx_extract.txt', 'rb')
line = input_file.readlines()
input_file.close()

Now you do your searching through the file for the content you are looking for. That can usually be the headache, but in your case it's simple.

for l in line:
    if len(l.strip()) == 10 or len(l.strip()) == 7:
        if l[0] == '0':
            newVals.append(l.strip())

You can print to the console first until you are sure you have it working:

for i in newVals:
    print i

And then you can write to a new file with the same for loop as you used to print above. Just open the file with 'w' for right or 'a' for append.

Namibnat 10 Junior Poster in Training

Could be as simple as using

"     OK      "  that has the size of 
"Edit Birdlist"

Well, that's kind of what I have done. It just would be 'nice' to have the "OK" button smaller most of the time, but no biggie. I think coming more from web stuff I just assume that these things are as easy to in wxPython as they are in JavaScript or CSS.

Namibnat 10 Junior Poster in Training

I didn't really get it right to change or dynamically resize the buttons. So I just compormized - set the value of the 'OK' button to just the right size to fit the full text. It's a pitty. Perhaps some other time I will play with it again until I get it right. But I wasn't getting it right with Show() and Hide(), and when I started with more sizers inside the existing sizers it starts to just get to be a lot of code that I would rather do without at this point.

For the second part it was rather easy. I set a counter, and instead of setting an if/else to choose the event within the sizer's code, I set a standard method call from the even to a small method where I then select which method to call from there, using the counter.

The second part was easy and I am happy with my solution, but the first part, I am sure that there must be something that I am missing. If anyone has an answer at a later stage, or a suggestion as to how I should ask the question to make it more clear, please let me know. I will keep this post unsolved for the time being, despite going on with my project.

Namibnat 10 Junior Poster in Training

Hi there,

I would like to be able to change a button during the runtime of a gui. I can change the value no problem (set Label) but I need to change the size of the button as well. I have managed to change it with SetSize((120, 30)) but then the button scoots under the next button along.

I would like to change the self.okay_button's value from "OK" to "Edit Birdlist" and it will need to be much wider.

I have tried to use Show/Hide, but then the new button gets put right up at the top of the gui.

Do I need to put my buttons inside another sizer? What is the best way to do this.

I also need to be able to change the even, but I think that should be rather easy? But I would appreciate comments on that.

#Buttons
        hbox_buttons = wx.BoxSizer(wx.HORIZONTAL)
        #### Here is the part I want to be able to change
        self.okay_button = wx.Button(self.panel, -1, "OK", size=(70, 30))
        hbox_buttons.Add(self.okay_button, 0)
        ####
        html_button = wx.Button(self.panel, -1, "Build HTML", size=(120, 30))
        hbox_buttons.Add(html_button, 0)
        exit_button = wx.Button(self.panel, -1, "Close", size=(70, 30))
        hbox_buttons.Add(exit_button, 0)
        vbox.Add(hbox_buttons, 0, wx.ALIGN_RIGHT | wx.RIGHT, 10)
        self.Bind(wx.EVT_BUTTON, self.getData, id=self.okay_button.GetId())
        #I will need a button event: self.ChangeBirdlist
        #when this usually  hidden button is there.
        self.Bind(wx.EVT_BUTTON, self.getHtml, id=html_button.GetId())
        self.Bind(wx.EVT_BUTTON, self.OnQuit, id=exit_button.GetId())
Namibnat 10 Junior Poster in Training

You had a few issues. Most significant, if you used raw_input instead of input you were getting strings instead of ints. You complicate things with the different functions. I would even take out the get_length() function and just pass that as a parameter to make_pass() and deal with it there.

Here is the code after I played around with it a bit.

#! /usr/bin/python
# psword.py

"""Password Generator"""
__version__ = "Version 1.0"
__date__ = "Created 1/3/09"

import random

def get_length():
    l = input("How long do you want your password?  ")
    d = input("How many digits do you want?  ")
    make_pass(l, d)

def make_pass(length=8, digit=2):
    letters = "abcdefghijklmnopqrstuvwxyz"
    password = []
    word = []
    for i in range(length):
        if digit:
            next_ch = str(random.randint(0,9))
            digit -= 1
        else:
            next_ch = letters[random.randint(0, len(letters))-1]
            # Just a small bonus - make some of the letters upper case randomly
            if random.randint(0, 1) == 0: next_ch = next_ch.upper()
        password.append(next_ch)
    while password:
        choose = password[random.randint(0, len(password)-1)]
        word.append(choose)
        del password[password.index(choose)]
    print "Here is your new password: %s" % "".join(word)

if __name__ == "__main__":
    r = raw_input("Do you want a custom password or a quick generated password?  ").lower()
    if r[:2] in "custom":
        get_length()
    else:
        make_pass()

Also, if you wanted to be able to use this for various things, like call it from another program, it would be a good idea to return the value and print it outside the function, rather than print it within the function. That's easy, of course, just a thought.

Namibnat 10 Junior Poster in Training

If you just want to find the file with the highest value, that should be simple if the files all have the same format. Something like this:

high = 0
for i in files:
    if i[2] > high:
        high = i[2]
        change_file = i

Then you can just append the content to the change_file:

try:
         f = open(file, "r")
         to_file = f.read()
         f.close()
         f = open(change_file, "a") #Use append instead of 'w' to append the content
         f.write(to_file)
etc
Namibnat 10 Junior Poster in Training

Is there a way to incorporate a spell checker within a wxPython gui? I would like to be able to check the spelling of wx.TextCtrl values before they get posted to a sqlite3 database.

I would imagine that the spell checker would be very os specific, but for me it would be really important that it worked on Linux, Ubuntu (9.4 and 9.10) and that it works on various flavors of Windows.

I most certainly wouldn't want to build a spell checker, only if I can connect to a spell checker already on my machine.

Just to show some code, below are a couple sections, of which there are a number in this gui. First, the initialization of the class:

class BirdUpload(wx.Frame, EachBird):
    """Bird Upload extends my EachBird class (bird.py module)
    
    The class provides a gui framework for working with bird list uploading.
    """
    def __init__(self, parent, id, title='Blu - Bird List Uploader', dbase='', table='', presetCountry='', presetYear=''):
        wx.Frame.__init__(self, parent, id, title, size=(700, 720))
        EachBird.__init__(self, dbase, table)

And some of the fields boxsizers containing the textctrls:

# Country_
        hbox10 = wx.BoxSizer(wx.HORIZONTAL)
        self.country = wx.StaticText(self.panel, -1, "Country", size=(180, 30))
        self.country.SetFont(self.font)
        hbox10.Add(self.country, 0, wx.RIGHT | wx.TOP, 8)
        if self.prStCntry == '':
            self.country_input = wx.TextCtrl(self.panel, -1, size=(400, 30))
        else:
            self.country_input = wx.TextCtrl(self.panel, -1, value=self.prStCntry, size=(400, 30))            
        hbox10.Add(self.country_input, 1)        
        vbox.Add(hbox10, 0, wx.LEFT | wx.TOP, 10)        
        
        # Notes_
        hbox11 = wx.BoxSizer(wx.HORIZONTAL)
        self.Notes = wx.StaticText(self.panel, -1, "Notes", size=(180, 30))
        self.Notes.SetFont(self.font)
        hbox11.Add(self.Notes, 0, wx.RIGHT | wx.TOP, 8)
        self.notes_input = wx.TextCtrl(self.panel, -1, size=(400, 120), …
Namibnat 10 Junior Poster in Training

I think it would be more useful to specify where this text is. If you are working with HTML it would be very different, say, from text in a gui app.

Namibnat 10 Junior Poster in Training

To give you a more simple answer, your problem with the player's score is that you keep resetting it. Why not just pass it in as a function argument.

Your coding is a little strange...did you work with C before? I have just cleaned up what you have done a little.

#! /usr/bin/python
# dice.py

import random

def gameIntro():
    print('''This is a dice roll game. Dice are rolled, and you recieve money
if you are equal to the total. Are you ready?''')
    
    if raw_input("Yes or no?")[0].lower() == "y":
        gamePlay(PLAYER_TOTAL=0)
    else:
        print "\nCheers\n"
        exit()

def gamePlay(PLAYER_TOTAL=0):
    
    dieRoll = random.randint(1, 6)
    dieRoll1 = random.randint(1, 6)
    print
    print 'Guess a number from 1 to 12'
    playerGuess = input()
    diceTotal = dieRoll + dieRoll1
    if playerGuess == diceTotal:
        print 'Woo! You got it! Plus $5 for you!' 
        PLAYER_TOTAL += 5
        print
        print 'You have ' + str(PLAYER_TOTAL)
    else:
        if raw_input('Sorry you didn\'t match the dice roll. Try again?')[0].lower() == "y":
            return True
        else:
            print "Goodbey!"
            exit()

gameIntro()
while True:
    gamePlay()

It's still a little messy. You could make it a bit more simple, I think.

Namibnat 10 Junior Poster in Training

why and where are we usıng None.whats the aım to use that

Using None as a default value to a function is often useful to give different options. Here is a small example:

def zed(a, b=None):
    name = a.capitalize()
    if b: name = name + " " + str(b).capitalize()
    print name

With this example, you could pass just a first name, or both a first and a last name as two separate values. The more you code for end users the more you will understand this. When you don't know what kind of values you are going to get, it is useful to have a way to give optional values.

and my other questıon ıs when do we need to make list of lists

Easy. Write some bigger projects and you will soon find an example. More likely you will use dicts with lists as the values, or, if it all gets to much, use a database. But lists in Python are just such useful tools and easy to do thing with that you will find you keep coming back to them. More than lists of lists you will more likely find that you use lists that map through lists:

print "\n".join([a**2 for a in [4, 5, 30, 14]])

for example

Namibnat 10 Junior Poster in Training

Here is how it searches the description:

des = re.split("'''", fileCont)
description = "<description>%s</description>" % des[1]

This assumes that you only use the ''' around the description, and it splits the whole file into three and puts it in a list. the first bit is the part before the first encounter of '''. the second is the description, and the third is the parts after the second '''

Then I just called the second part des[1] You know that lists start with 0 as the index for the first bit, so the [1] refers to the second item in the list des...your description. Of course if there are other occurrences of ''' in your file, it will not work. It doesn't use regular expression.

Namibnat 10 Junior Poster in Training

Wildplace, your code is rather strange. I think that you are trying to do something well above your level of knowledge at the moment. Perhaps the best thing you can do is get a good Python tutorial and work through the chapters on functions and object orientation.

Anyway, lets look at your code a little.

First off, how do you call the function. If it is a calculator, I am not clear on where you think the two numbers or the operator comes from?

Basically I guess that you want to call the function with one value, and it should be a text value for a number between one and ten? So what do you do with values higher than 9. Why no zeros?

Okay, then you want to instantiate the class.

calculator = calculatorClass.calculator(self.__num1, self.__sign)

Okay, I am going to put the class and the function in the same file, so loose the calculatorClass (I assume that that was an import?)

You don't instantiate a class with the 'self' reverence...Python puts the self in for you. Self, itself, is not a reserved word in Python, it is just a convention. So if you use 'self' outside of your class, it doesn't mean anything. (note: if you meant click to be a method of calculator then I am wrong, but since you gave the two blocks of code apart, I assume not.)

calculator = calculator(__num1, __sign)

From that, it should also be clear that this line …

Namibnat 10 Junior Poster in Training

Okay, I am on a linux system and so I haven't worried to much about the escape characters, but I think that what you were after is getting the prompt to change from C:\\ to D:\\

What you need to do is take the initial_drive = r"C:\\" out of the while loop, because otherwise you are changing the 'initial_drive' value, but the changing it back again when the loop goes round again.

Here is the code I used to get it to work right on my system:

#!/usr/bin/python3
import os
import sys

whileloop = True
initial_drive = r"C:\\"

while(whileloop):
    inputline = raw_input(initial_drive)
    print("inputline = %s" % (inputline))
    if inputline == "exit":
        whileloop = False
    elif inputline == "about":
        print("no input")
    elif inputline == "":
        print("write a command and press enter.")
    elif inputline[0] == 'd':
        initial_drive = r"D:\\"
        print("initial_drive is now %s" % (initial_drive))
    else:
        print("bad command")
Namibnat 10 Junior Poster in Training

I have been playing with it and didn't get index() to work, mainly because index always returns the first instance of the string if it occurs multiple times. I assume that normally it would be different values and then it wouldn't matter. But just in case the email is repeated somewhere in your lists, the only way I could get it to work was like this:

for a in range(len(list)):
     if '@' in list[a]: print list[a],
     else:
         if a < (len(list)-1):
             if '@' in list[a + 1]:
                 print list[a]
             else:
                 print list[a],
         else:
             print list[a]
Namibnat 10 Junior Poster in Training

Thanks

Namibnat 10 Junior Poster in Training

Okay, you will just need to refine how it searches for files and how it actually finds the bits you are looking for. It worked with the example file you gave, but if you had interfering text in the files, there could be issues with the simple search stuff I did.

Namibnat 10 Junior Poster in Training

No, I can't?? It must have come from trying things and just not cleaning it all up enough? Perhaps I wanted to check for something in there? I don't know. Certainly looking at it now, the self.plus = "".join(v) would be better.

Namibnat 10 Junior Poster in Training

Namibnat, imagine that your function doStuff has to be executed more than once, actually many times. The 1st time it went through the try/except part and stored the variable. But next time is called the user didn't enter a language code, he started typing, how can I get the value I stored via the first call (try except).

Just for this part, you should create a class, so that each instance of the class stores its own data.

Namibnat 10 Junior Poster in Training

I have been playing with your code for the hangman game and made a complete working program. It has gone a long way from what you started out with, but maybe you want to have a look at it. It may give you ideas for what you need to change in your own code.

I did the graphics just with ascii in the terminal window running it.

Namibnat 10 Junior Poster in Training
Namibnat 10 Junior Poster in Training

make

#
for i in range(len(word)):
#
test="*"*(i+1)

into this test = "*"*(len(word)) In your example you are doing the assignment over and over. The for i in range(len(word)): is a loop, so you loop through the assignment over and over for no reason.

Namibnat 10 Junior Poster in Training

For a start, put wordBank in a list

Namibnat 10 Junior Poster in Training

Just one thing, it is not intuitive about the spacing - important for Python. You still need to sort that out manually. I am not really sure why, and I will try to fix that later.

Namibnat 10 Junior Poster in Training

Note two things: First off, I don't guarantee that it works well. Writing to files, if done wrong can always break things. Be careful. I mostly participate in this forum (the Python part) for fun, and my code is written like that.
Second: this script is about copying things. I mean it to be of use where you can work with code you find to help or be helped. Copying stuff always means copyright issues can come into play.

Okay...I am sure that there must be something like this around already, but I couldn't find it and it was quicker (and kind of fun) to write than to read/search endless sticky notes/code snippets and forum-clever-stuff.

Just in case someone else is lazy like me, I thought I would stick this little script up here.

I would have thought that something like this would have been on a page like http://www.daniweb.com/forums/misc-explaincode.html, but I didn't find it. If it is there, I am sorry, I'm on holiday :)

The problem:
If you are trying to help someone, or getting help from someone and you copy the code posted in the thread and then paste it in your text editor, it puts the line numbers on one line and the code unchanged, with the right indentation on the next line.

The solution:
A really simple script that opens your file, reads it, deletes each line with the line numbers and finally writes over …

Namibnat 10 Junior Poster in Training

I am sorry that it is not working for you. I have just been testing it again, running the tests further down the file path (I had only let it search a small directory) and created more control.ini files, and it worked each time.

Yes, i correct the path.

Okay, try the test

#
test = CntIniFileDetails('/path/to/try/')

changing line 66 (or whatever it turns into on your text editor) to just one directory down from one control.ini file and see if it finds just that one.

I don't know if you are familiar with the __name__ == "__main__" trick, but it means you can run the thing from command line:

vernon@sandcurve3:~/Python/trying$ python playonlcd.py
One file written to:
/home/vernon/Python/trying/controlDetails.xml
vernon@sandcurve3:~/Python/trying$

Here is an example running it from the command line.

The code seems far to different form C but is intuitive.
I understand it but because i don't have any experience with object oriented i don't have much ideas to write it and the lack of experience with python.

If you have done C++ you are going to find pythons object orientation really easy to get the hang of. Read 'dive into python' and just ignore the fact that some of the stuff is out of data - you can figure all that out later.

Basically with the test:

#
if __name__ == "__main__":
#
test = CntIniFileDetails('/file/path/to/test/')
#
test.buildXml()

the "test = CntIniFileDetails('...." intanciates and 'test.buildXml()' calls …

Namibnat 10 Junior Poster in Training

I need your help with a simple program I'm trying to make

It doesn't sound simple. It would be a fun problem to try to work on. Could you post the gist of your code.

Namibnat 10 Junior Poster in Training

Did you correct all the file paths throughout the program? It is going to search a directory and all the files within it. I guess that you need to build a thing in it that stops it building the xml file when it didn't find a control.ini file.

Just put a series of prints it is to see what each variable is doing.

Does the code make sense? Is there anything that you don't understand?

I see that I left line 62 in there from when I was testing it. Just delete that, but if you create a series of print and try catch tests, you should have it all working soon.

I basically built it all up one step at a time in the python ide. You can de-construct it in the same manner.

Are you on Linux. If not, there may be a few things that work different for you?

Namibnat 10 Junior Poster in Training

Don't let the object paradigm confuse you. It is actually rather easy to understand...maybe tricky to code at first, but it is not a confusing concept.

'object' means different things in different programming languages, and as mentioned before, in python almost everything is an object.

An object basically is something (in the scene that it is a 'thing') that has methods and attributes. So, it is like this or like that and it can do this or that.

A class is really just a blueprint for a 'thing' (lets rather say 'type'...you will probably read stuff like Bruce Eckel's books at some point.) Forget about dogs, with four legs and barking (when I first started to try to get my head around it, all these dogs and tables just made it seem more mysterious and confusing.)

Anyway, stick to this idea of a blueprint. Basically it says 'let the programmer think about his problem' not 'let the programmer think about bits and loops and the structure of the machine.'

A blueprint basically means that you want to look at your problem and create bits that fix it.

So, in your problem, your class would need to create methods or variables for each thing you need from students.

Here is a start:

#! /usr/bin/python
#  jlm699.py

class StudentDataEngine:
    def __init__(self, name, gender, ID, moreStuff):
        namelist = name.split()
        for a in range(len(namelist)):
            namelist[a] = namelist[a].capitalize()
        self.name = " ".join(namelist)
        self.gender = gender
        self.ID = …
Namibnat 10 Junior Poster in Training

Take a look in the final method in the class - it creates an xml file with each of the details you wanted.

Namibnat 10 Junior Poster in Training

In my example the cases are the same. The newlang is an instance object, the Newlang is a variable build from the class method.

In my example everything works. I have tested the class, each method and checked all the variables. Now it is just a matter of El Duke building in the other stuff around it.