shadwickman 159 Posting Pro in Training

Hello. I haven't ever needed to bother trying to do things to the console such as clearing one line, changing colours, etc. But now I was wondering if there is a (preferably built-in) cross-platform way of clearing just the current line in the console.

I have a program which does a lot of calculations and I thought it would be nice to have one line clear and update with the percentage of the iterations done. I guess I'm looking for something similar to, say aptitude in GNOME (from the terminal); when it's downloading packages, it updates the one line with the current percentage downloaded.

I've looked at curses, but I honestly don't want to have to resort to that. If there isn't a simpler way of doing this sort of thing, I guess what I wanted it for isn't really required... it would just be handy to have.

Thank you!

shadwickman 159 Posting Pro in Training

You're not understanding: the else with the break is attached to the try/except block. That is inside the while loop. Then, outside the loop, on the starting on the same indentation level as your loop, goes all the stuff that happens after the input segment.

No offense, but please, please, please read some books on basic Python or programming in general and do some simple exercises pertaining to that. You need to understand how the code I gave in my previous post actually works.

It's simple: the while loop begins, and asks the user for input. If it's bad (i.e. a non-number), then it goes to the except block, and because of that, it does not execute that else: break section. This means that it asks for input again, and so forth. If it gets good input, then it won't cause an error, so it will go to the else: break part. This break ends the while loop, this allowing the script to continue execution downwards where it encounters the stuff you have dealing with handling the choice the user gave.

I honestly cannot get any more simplistic than that...

shadwickman 159 Posting Pro in Training

I meant something like this:

I changed the car_list file to make each Car instance's image attribute as a string of the image filename. Like so:

# ...
title = "Golf Mk1 (A1/Typ 17, 1974-1984)"
info = """\
In May, 1974 Volkswagen presented the first-generation
Golf as a modern front wheel drive long-range replacement
of the Beetle.
"""
image = 'Golf_Mk1.jpg'  # just the image filename
# create the class instance and append to the list
car_list.append(Car(title, info, image))
# ...

This means that you can remove all the imports for tk and PIL at the top of your car_list script, and also delete the root = tk.Tk() part.

Then, in the main file, I changed the show function so that it creates a Tk image of the filename upon showing it. Like this:

def show(car_num):
    global car_list
    global screen
    global info    
    
    # delete any previous picture, title and info
    screen.delete(0.0, 'end')
    info.delete(0.0, 'end')
    # create picture heading
    s = car_list[car_num].title + '\n\n'
    screen.insert('1.0', s)

    # insert picture
    img = ImageTk.PhotoImage(file=car_list[car_num].image)  # make image upon showing
    screen.image_create('2.0', image=img)  # changed to use the newly created image

    # insert information about the picture
    info.insert('1.0', car_list[car_num].info)
# ...

I'm also re-attaching this modified version so that you can see the changes better.

shadwickman 159 Posting Pro in Training

Well if the try ... except block isn't in a while loop, with that else: break segment I posted for you before, then there's your problem.

If you give bad input, it will error and go to the "Invalid Input!..." line, and then continue on down the script to the if choice in [1,2,3,4] statement.
But if it threw an error, choice is still undefined, yet it tries to compare it in that if statement. The reason it is still undefined is because it caused an error when trying to assign a value to it, so it stayed undefined.

I showed you a solution before, which was the while loop to get input until it gets good input, in which case it breaks out and continues down the script:

while True:
    try:
        choice = int(raw_input('Enter Number: '))
    except ValueError:
        print 'Invalid Input! Please input only numbers.\n'
    else:  # if the input doesn't cause an error
        break

# that 'break' will make it continue along to here... (outside of the loop)
if choice in [1, 2, 3, 4]:
    # etc.
shadwickman 159 Posting Pro in Training

I can tell you've come from C++. You're making things much harder than they need be. Python has such a simple syntax, yet you're clogging it up by doing things similar to how you would in C++.

For #1, in C++ you couldn't just write Candidate[20] anyways because that doesn't store the names for each instance like you're trying to here by reading it from a file. However, you can simplify that whole process considerably:

# read the whole file as a list of lines
# we use this list comprehension to trim leading and trailing whitespace
everything = [line.strip() for line in f.readlines()]

# everything up to the no_of_candidates index, again,
# using a list comprehension to make the instances
candidates = [Candidate(name) for name in everything[:no_of_candidates]]

# and the same for the voters
voters = [Voter(name) for name in everything[no_of_candidates:]]

#2
I don't get your question. I see no lower function in your code. If you're referring to the lowest function, then I'd say it's best how it is. It shouldn't be a method of the Candidate class as it needs to handle count values from all the other Candidate instances too. Best to keep it the way it is. If it was something that performed operations on only that specific instance's values, then I'd make it a method, but that's not the case.

#3
Of course you must initialize the lists. You're appending stuff to them, and you can't do so if …

shadwickman 159 Posting Pro in Training

That is due to line 24:

if choice in [1, 2, 3, 4, 5]:

You allow 5 to execute the 'buying-a-ship' if statement instead of the break one. It should just be:

if choice in [1, 2, 3, 4]:  # no 5!
shadwickman 159 Posting Pro in Training

Or mildly more elegant ...

In that case, you could just use filter with a lambda expression :P

mylist = ['apple','orange','mango','pear','strawberry']
target = 'pear'
newlist = filter(lambda x: x == target, mylist)

# or ... multiple targets
mylist = ['apple','orange','mango','pear','strawberry']
targets = ['pear', 'apple']
newlist = filter(lambda x: x in targets, mylist)

As for the problem regarding modifying the list while using a for loop, you could just use a while one instead. Just increment the loop index as needed.

mylist = ['apple','orange','mango','pear','strawberry']

i = 0
while i < len(mylist):
    item = mylist[i]
    if item == 'pear':
        # if you delete one index, the ones after will now be located
        # at one index lower, so you don't need to increment i.
        del mylist[i]
    else:
        # go to the next index...
        i += 1
shadwickman 159 Posting Pro in Training

Oh... this code looks fairly um, interesting. There are a number of things that should be changed.

It would be best to indent the lines 2- 57 in one level so that they're under the if that triggers if the input is 1 - 4.

The problem that this should also solve is the "elif choice == 5: break". The issue is that because you put lines 46-56 in that same level as those "choice" ifs, the breaking conditional is now linked as an elif for the "if gold >= price" statement.

Your code should be something like:

# ...
        try:
            choice = int(raw_input('Enter Number: '))
        except ValueError:
            print 'Invalid Input! Please input only numbers.\n'

        if choice in [1, 2, 3, 4]:
            global price
            global ship
            # I indented this below
            if choice == 1:
                ship = 'Sloop'
                price = 1500

            elif choice == 2:
                ship = 'Schooner'
                price = 3500

            elif choice == 3:
                ship = 'Brigantine'
                price = 6500

            elif choice == 4:
                ship = 'Galley'
                price = 9500
                
            if gold >= price:
                print 'You bought a new ship!'
                gold -= price
                print 'You now have:',
                print gold,
                print 'Gold\n'
                    
            elif gold < price:
                print 'You do not have enough Gold!'
                print 'Try again later!\n'
            # ...all the way to here.

        elif choice == 5:
            break

elif links the statement to the most recent if statement on the same level of indentation as it. All that part that I indented only happens if the …

shadwickman 159 Posting Pro in Training

@Aia

You just strike me as an extremist for your beliefs (Conservative right?). And I hate extremists because they only lead to problems, such as the ones caused by religious fanatics, or by those who are too damn bull-headed to try to even consider a different viewpoint. You fall into this latter category. Can I also presume that you liked G. W. Bush (*shudder*)?

And regarding Obama - I don't live in the US (thank God for that), but to be honest he is quite different in office than he was during election-time. Of course, this is the case with any politician, and people will never be satisfied with whoever is in office. That being said, you blame the deficit on Obama... whose fault was it for letting it start? Oh! The Republicans! Them with their darn effective capitalist system. Those sub-prime mortgages sure were a great idea!

Now I know you're going to criticize me for my anti-conservative post, but I had to say it anyways.

shadwickman 159 Posting Pro in Training

If you want to use Blender for your 3D stuff, that's an option as it's open-source, very advanced, supports Python integration, and has a game-engine built-in. This means that you can control your models and such if you integrate in Python scripts for it, or you could go with the interface for using logic in the game engine that Blender has integrated into it. Then you can export that as an exe and all that jazz.

http://www.blender.org/features-gallery/features/

shadwickman 159 Posting Pro in Training

i make a game with the use of flash but i want ti make more interactive what will i do,can you offer me or send codes to make the game more interactive

Ahaha! It's called reading up on the subject and understanding what it is you're actually doing. I can't just "send you codes" to make your game better. That, and your post was so incredibly vague. Nice try :P

As for developing games in Flash MX, does that version use Actionscript 2.0? Or does it still use 1.x? AS 2.0 is good enough for making games, and 3.0 is great too, but version 1 (if MX uses it) is definitely not so great.

shadwickman 159 Posting Pro in Training

I'm up for contributing. My experience is mainly Python, but also PHP (+ HTML/CSS/Javascript; you said it was for browsers?) and also Actionscript 2.0 and 3.0, and a tad of C++, but that last one doesn't matter for web stuff. Also, money doesn't bother me - I program for fun

shadwickman 159 Posting Pro in Training

Well if you wanted it to re-print your menu every time, you'd just need to stick all those print statements from above that while loop to inside it, right on top of that choice = raw_input... part.

As for "messing up the functions above", what exactly do you mean? I can only really answer your questions when you be specific with them, and if there are errors, also show the traceback it gives.

If you wanted Tav to loop the entirety of itself, you can contain its contents within a large while loop, or you could place the call to it from the other part of code within a while loop.

shadwickman 159 Posting Pro in Training

I can only assume that you put the indentation level of the if statements so that they were inside the loop. They should be outside of that while loop, like I had in my above code.

shadwickman 159 Posting Pro in Training

I hate to spam this thread more than it already has had, but people: PLEASE stop posting when you can still edit your last post. It just clutters things and makes this thread annoyingly unmanageable. This last page of posts was useless stuff that didn't deserve new posts for anyways.

shadwickman 159 Posting Pro in Training

This doesn't even incorporate the suggestion I gave, but still contains the unwanted recursion (see lines 12 to 16, along with 27, 30, 38, 41).

You would have to change the Tav function to:

def Tav():
    global gold
    print 'Hello There! Welcome to the Tavern!\n'
    print 'Here you can purchase some beer or liquor!\n'
    print 'You currently have',gold,'Gold\n'

    print '1)Beer 10$'
    print '2)Liquor 20$'
    print '3)Exit\n'
    print 'Enter 1, 2, 3\n'

    while True:
        try:
            choice = int(raw_input('What will it be? '))
        except ValueError:
            print 'Invalid Input! Please input only numbers.\n'
        else:
            break

    # this now gets executed after "break" is made.
    if choice in [1, 2]:
        # etc...

And even then, you make a couple more calls to the Tav function further down, leading to that recursion thing I told you about. You should be able to figure out a way of changing that :P

shadwickman 159 Posting Pro in Training

Huh? Can you post some context (code)? This is it within IDLE for me:

>>> while True:
    try:
        choice = int(raw_input('Enter Number: '))
    except ValueError:
        print 'Invalid Input! Please input only numbers.'
    else:
        break

Enter Number: asahrotry
Invalid Input! Please input only numbers.
Enter Number: 1
>>> # it broke out of the while loop fine...

This must just be an error in how you're implementing the code I gave you.

shadwickman 159 Posting Pro in Training

So did you try what it was that I was suggesting then? It seemed logical and I think it would work.

shadwickman 159 Posting Pro in Training

Well I'd structure it like this:

# within the function wanting to gather input...
while True:
    try:
        choice = int(raw_input('Enter Number: '))
    except ValueError:
        print 'Invalid Input! Please input only numbers.'
    else:
        break

That loops the whole segment over and over. If there is an error (i.e. a non-numerical input), then it doesn't break out of the loop, leading it to keep asking. If it does get a number as input, it doesn't cause an error so it goes to the else statement, in which I called break. This breaks out of the while loop, and then continues down the script instead of asking again.

shadwickman 159 Posting Pro in Training

I can't help with GUI stuff as I can't use Tkinter, only wxPython. However, if you decided to use os system calls, you can always use threading to run the os calls in one thread, and use a second to update your GUI.

Or like Bumsfeld said, you could go with the subprocess module. That is probably a better bet though as os system calls are never ideal.

As for your message window thing, in wxPython there is a wx.Dialog derivative called wx.MessageDialog which keeps focus until it is done. I'm sure Tkinter has a similar thing.

shadwickman 159 Posting Pro in Training
try:
        choice = int(raw_input('Enter Number: '))
    except ValueError:
        print 'Invalid Input! Please input only numbers.'
        S()
    else:
        if choice in [1, 2, 3, 4]:

This is just a small snip of it.

This will lead to strange behaviour and such things due to one problem: the S() function you call to on bad input (adds unwanted recursion). If S is the name of the function that this snippet of code is from, then this may cause odd errors for you in the future.

What's happening is that say you have one call to the S function. In it, someone gives bad input. Upon this, your code makes another call to the S function to get input again. But when this second call is made, your first S call won't be terminated or anything. It pauses until this new S call it makes ends. I.e. each time the user makes bad input, it calls S again, but when that new call is done, it will continue down the script within the original call of S.

This is hard to wrap your head around, so think about it like this:

def S():
    try:
        choice = int(raw_input('Enter Number: '))
    except ValueError:
        print 'Invalid Input! Please input only numbers.'
        # I'M INSERTING THE S FUNCTION CODE WHERE YOU CALLED S() #
        # that new call to S happens here, and this is what S does:
        try:
            choice = int(raw_input('Enter Number: '))
        except ValueError:
            print 'Invalid Input! Please input only numbers.'
            # …
shadwickman 159 Posting Pro in Training

Not quite Clueless :P

Haha I just meant this:
You currently (for each car) make the image variable for the Car instance a Tk image thing. Then you append this Car instance onto the car_list variable within the car_list module.

What I suggested is:
Make the image variable for each Car instance in that list just the filename to that car's image (a string). Then, in your page-displaying function within the main script, have it create a Tk image of that filename for that image variable before displaying it. That way all the Tk instances are created from within the main script and your car_list module doesn't need to use the Tk stuff in it.

shadwickman 159 Posting Pro in Training

Instead of appending Tk image instances to the list, try passing the image filenames in the car_list module to the list. Then when you use them in the main script, just create the Tk image instance then. Maybe that's a better solution...

shadwickman 159 Posting Pro in Training

Yeah, that's definitely a problem. I hope the developers for pyHook release a 2.6 version soon... in the meantime, you can just download the 2.5 source and try re-compiling it yourself for 2.6. You'll probably do a better job than me as, like Bumsfeld said, I probably screwed it up :P It doesn't take very long to remake it yourself, and it may solve the issue that my version has :S

shadwickman 159 Posting Pro in Training

Oh sorry! I didn't see your previous post metioning that :D Does anyone know if this has to do with Python 3.x? Changing the value of sys.sydout always worked for me...

shadwickman 159 Posting Pro in Training

Well I can see that the line you have redirecting the standard output (stdout) is commented out. So it won't be changing the output to that window you wanted. Or is there something I'm missing...? :P

shadwickman 159 Posting Pro in Training

You can try substituting your current thread with this custom Thread class which allows only itself to be killed.

import threading, sys, trace


class KThread( threading.Thread ):
    def __init__( self, category, desc, func, params=() ):
        threading.Thread.__init__( self )
        
        self.category = category
        self.desc = desc
        self.function = func
        self.params = params
        self.killed = False
        
    
    def start( self ):
        self.__run_backup = self.run
        self.run = self.__run
        threading.Thread.start( self )
        
    
    def __run( self ):
        sys.settrace( self.globaltrace )        
        self.__run_backup()
        self.run = self.__run_backup
        
    
    def globaltrace( self, frame, why, arg ):
        if why == 'call': return self.localtrace
        else: return None
        
    
    def localtrace( self, frame, why, arg ):
        if self.killed:
            if why == 'line':
                raise SystemExit()
        return self.localtrace
        
    
    def run( self ):
        self.function( self.params )
        
    
    def kill( self ):
        self.killed = True

This is wirrten by Connelly Barnes.

shadwickman 159 Posting Pro in Training

You should add an else statement at the end of the checking, so that if I enter anything other than 1 to 4, it'll tell me I gave bad input and then it'll let me re-enter until it's correct.

Also, you can rewrite your if statements because they use a lot of the same code, so you can put it all into one place. Here's just an example:

# beginning of your code snipped here...

    choice = input('Enter Number: ')

    if choice in [1, 2, 3]:
        global gold
        
        if choice == 1:
            ship = 'Sloop'
            price = 1500
        elif choice == 2:
            ship = 'Schooner'
            price = 3500
        elif choice == 3:
            ship = 'Brigantine'
            price = 6500
        
        if gold >= price:
            print 'You bought a ' + ship + '!\n'
            gold -= price
            print'You now have:',
            print gold,
            print 'Gold'
        elif gold < price:
            print 'You do not have enough Gold!'
        
    elif choice == 4:
        print 'Exit'
        
    else:
        print 'Invalid input!'

If you wanted to keep the dictionary you use for listing the ship name and price, there's also an easier way for getting the ship name and price without using so many manual if statements, but may prove a bit complicated for you...

# beginning of your code snipped here...

    choice = input('Enter Number: ')

    if choice in [1, 2, 3]:
        global gold
        
        # get the names of the ships as a list
        shipnames = Shiplist.keys()

        # sort it (each name starts with "#)" so …
shadwickman 159 Posting Pro in Training

And by the way, you can copy from the Ubuntu terminal via Ctrl+Shift+C, and past into it with Ctrl+Shift+V. Now you can give us a full traceback, plus you should also provide the code segment which the error is in, and any other info we need to know pertaining to that code.

shadwickman 159 Posting Pro in Training

I just thought about it... is it giving strange errors because you initialize a Tk thing in both the main script and the module you're importing? Shouldn't you only have the root = tk.Tk() present in the main script? The module shouldn't have it because you're importing it into the main one, which already has a Tk() class instance...

At least, this is how it works with wxPython, so maybe it's the deal here. (In wxPython, you only make the wx.App() instance in the main file; in the modules you import wx so that you can subclass it and do stuff like you do in your car_list module, but you don't make a new wx.App() in each subsequent module.)

Sorry if the above was confusing :P

shadwickman 159 Posting Pro in Training

The rent here in BC can be bad depending on the city too. Where I live, a one bedroom apartment with a tiny kitchen and living room/den can easily be $800/month without utilities and such. And the houses.... sheesh. The one next to us is trying to sell for 2.4 million dollars Canadian. And don't get me wrong, this isn't the top-class neighbor hood at all - the average neighborhood houses can also quite easily read a $1.7 mil. asking price (and the lots are usually tiny and crammed).

shadwickman 159 Posting Pro in Training

I don't use Tkinter as I personally hate it :P But I'm going to assume that the Text control has a write function of some kind, just like the wxPython TextCtrls. If that's the case, then you redirect the standard output stream so that it uses your Text control as the object it writes to:

import sys

# your code
outputWindow = Text(root)
outputWindow.config(relief=SUNKEN, bg='beige', width=51, height=17)
outputWindow.place(x=350, y=130)

# redirect stdout
sys.stdout = outputWindow

# and if you want to reset the stdout
# sys.stdout = sys.__stdout__

This is the sort of method I always use for wxPython GUIs. Note that this is a flexible thing though - files are objects with a write command, so they can be used to redirect output too, like if you wanted all the output logged to a file:

import sys

fh = open('log.file', 'w')
sys.stdout = fh
# program here...
fh.close()
sys.stdout = sys.__stdout__

Hope that helps :)

shadwickman 159 Posting Pro in Training

Hello, I look forward to seeing you around :)

And as a side note, I'd personally suggest sticking with Python 2.5 or 2.6 for another little while, just because so many third-party modules and such aren't supporting 3.x yet. (Among those important to me is wxPython, an excellent GUI toolkit which I use a lot.) Although if you're not heavily using such modules, then Python 3.1 should be fine :)

shadwickman 159 Posting Pro in Training

I was reacting to this:

"That is why i respect a blonde cute female c++ developer too much.
She could have taken advantage of her beauty instead of coding all her life..
She just likes to produce something with her brain, she likes contemplating and observing."

Nav33n is correct. Say hello to Serkan Sendur... if you search around for his posts you'll probably find most non-programming related threads seem to have been polluted with some (at times) disturbing material about a certain other member on this site :P
Welcome to DaniWeb hahaha :)

nav33n commented: :D heh.. +11
shadwickman 159 Posting Pro in Training

did you try dos2unix on the file first?

Oh damn, good point. I forgot about the new line thing being different on UNIX from Windows... UNIX is just \n and Windows is \r\n
I think?....

shadwickman 159 Posting Pro in Training

Yeah, the "\x##" is the format for encoding non-ansi (is that correct?...) characters. As far as I can tell, these are useless characters anyway, because if you pick through the segment: '\x00A\x00D\x00A\x00M\x00S\x00 \x00C\x00O\x00U\x00N\x00T\x00Y\x00' You can see that there are the regular letters "ADAMS COUNTY" in it. So are all these null characters useless? If so you can just remove them from every index in your script so that you'd only get those regular letters left...

EDIT:
Here's a way to remove those control characters and keep each value in the list:

# in that for loop of the lines...
s = ''.join(out)
final = []
for segment in s.split('\x00\x00'):
    temp = ''
    for char in segment:
        if ord(char) > 31:
            temp += char
    final.append(temp)

# or, for ugly but compressed code (not really recommended though...):
s = ''.join(out)
final = []
for segment in s.split('\x00\x00'):
    final.append(''.join(filter(lambda x: ord(x) > 31, [char for char in segment])))

s is the joined string of the out variable you had in your loop. I discovered that each index was separated by a \x00\x00, so I split the string at that. Then, within each of the resulting segments, I weeded out any characters whose ASCII value was less than 32 (the null/control characters). Then it appends those resulting characters to the new final list.
This is messy solution, but it left me with the output: ['001', 'ADAMS COUNTY', '99344', '46.824922', '-119.173798', 'COM', '1320'] for one of the lines. There's most likely …

shadwickman 159 Posting Pro in Training

I think over-population and limited resources make Indian students work twice as hard as anybody else.

Very true, which is sad because their population expansion was so rapid that their infrastructure and social services are very lacking for such a large amount of people.

shadwickman 159 Posting Pro in Training

Why is a good-looking coder better than not-so-good-looking/ugly coder?

Since when did anyone mention beauty or looks in this thread?...

shadwickman 159 Posting Pro in Training

Is that because you forgot to delete the lines I added in that changed the "image" variable to strings like "Golf1", "Golf2", etc.? I put those in right under the image lines that I had commented out.

If that's the case, then it's still assigning strings to the image variable of the Car class instances...

shadwickman 159 Posting Pro in Training

Ok, I'm attaching it, but it'll perform your Tk thing but without the photos - I just commented out the lines in car_list which made the ImageTk.PhotoImage instances as I didn't have the JPGs it was trying to load. I just had it pass stuff like "Golf1" and "Golf2" to the Car class as the image variable instead. Try this code and I hope it works...

shadwickman 159 Posting Pro in Training

I assume you know at least the very basic styling available with CSS. You'll want to make something basic, for a red and a green class in CSS like this:

<style type='text/css'>
    .red { color: #f00; }
    .green { color: #0f0; }
</style>

Then you'll want to take each line of the output and search it. If it finds "FAILED" in the string, wrap the red-colour style tag around that line; if it finds "PASSED", wrap the green-coloured tag around it. Something like:

# assuming 'output' is a list of the output lines
for index, value in enumerate(output):
    if "PASSED" is in value:
        output[index] = "<span class='green'>" + value + "</span>"
    else:
        output[index] = "<span class='red'>" + value + "</span>"

Finally, save it to a file opened so that its saved with a .html extension. You'll need to include the HTML structure (<html><head><body>, etc.) into the string you save though:

toSave = """
<html>
<head>
    # insert your CSS styling write-up here
</head>
<body>
""" + my_output_as_a_string + """
</body>
</html>"""

fh = open("file.html", "w")
fh.write(toSave)
fh.close()

This is very basic of course, and if you're wanting to update the records by just appending new ones, I assume you'll need to open up the HTML, remove the ending body and html tags, add the records, and then reattach those tags.

shadwickman 159 Posting Pro in Training

What Python installation are you using? I'm running 2.5.4 and after I moved the Car class into the car_list module, your code ran for me without an error... does Python 2.6 disallow the use of main-scope variables sharing the same name as the module or something?

EDIT:
Tested that name-thing on my 2.6 installation and that's not the case. I really have no clue now what is going wrong for you...

shadwickman 159 Posting Pro in Training

but they have something in common...

Possibly some deeply-rooted Celtic hatred of the Saxons :P

And moving out isn't just that easy. I work two jobs but still live at home...

shadwickman 159 Posting Pro in Training

I had no issues running your code... all I did was move the segment:

class Car(object):
    """this class creates a record structure"""
    def __init__(self, title, info, image):
        self.title = title
        self.info = info
        self.image = image

which was in the main file, INTO the module car_list that you had created. This is because you were doing things like car_list.append(Car(title, info, image)) inside the car_list module, yet you had defined the Car class in the main file. I.e. calling an instance of Car in the car_list module was throwing me a "class Car is undefined" error.

shadwickman 159 Posting Pro in Training

Do you mean you want to format your output automatically in Python, i.e. wrapping it in appropriate HTML tags?
Or just do you mean save whatever comes out of your program into a file with a .html extension?

For appending to a file, just open it with append mode, i.e. filehandle = open("myfile.html", "a") Your question was way too vague. I can't read your mind, nor magically know what the output coming out of your program is like. You need to provide details.

shadwickman 159 Posting Pro in Training

This makes no sense to me though... even having the module name car_list the same as a variable name within it didn't cause errors when I ran a quick test on importing that.

However, one issue is that your Car class is located in your main file, yet you make calls to it from within your car_list module. That throws me an error. Try re-locating the Car class declaration to the car_list script, and then see if this other weird error is still occurring for you.

EDIT:
And yes, he was a very interesting guy :P

EDIT2:
Moving the Car class to the right module fixed it for me and the script ran the Tk window without an error.

shadwickman 159 Posting Pro in Training

From what I can tell, you don't have a main-scope variable named car_list within the car_list module. You sure it isn't a simple mistake like that?

shadwickman 159 Posting Pro in Training

Ewwww. Half your variables aren't even defined dude. You can't say:

def SplashScreen(self):
          root.title("My Title")

What is root? When do you define root?

If you scrolled to the bottom of the code, after the class definition, you'd see that he defined root as Tk() :P

shadwickman 159 Posting Pro in Training

You're going to want to read up on what objects are; the whole OOP thing. You'd be doing something like:

class Room(object):
    def __init__(self, description):
        self.desc = description
    def showDesc(self):
        print self.desc

myroom = Room('You are standing in a restroom...')
otherroom = Room("You are out in a dark hallway...')

# myroom.showDesc()
# etc.

You're definitely going to need to read up on all this, along with inheritance, and so forth. You can start here with Dive Into Python's "Object" section. And here's the Python documentation on classes. This is definitely an essential thing to know about.

shadwickman 159 Posting Pro in Training

Wow, I can't believe my previous code had such a bad mistake... start = filename.rfind('_', filename[:end]) + 1 SHOULD have been: start = filename[:end].rfind('_') + 1 Sorry for any confusion!