jlm699 320 Veteran Poster

Here's some documentation on the file object and associated methods.

jlm699 320 Veteran Poster

Karen,

Please use code tags when posting code, or else it will become unreadable as it has above.

To use the code tags, wrap your code like this:
[code=python] # Code inside here

[/code]

This will turn on syntax highlighting and preserve your indentation. Also, forum members are much more inclined to help you if your post isn't a huge mess of plain text.

jlm699 320 Veteran Poster

What exactly do you need explained? Also, in stead of [python] you should be using code tags. To get language-specific syntax highlighting use it like this:
[code=python] # Code in here

[/code]

jlm699 320 Veteran Poster

Another great little trick for classes is providing a __repr__ method, so that when you print the object of a set, instead of displaying a message like this:

>>> class my_class(object):
...     def __init__(self):
...         self.A = '1'
...     
>>> mc = my_class()
>>> mc
<__main__.my_class object at 0x01D24BF0>
>>>

You get this:

>>> class my_class(object):
...     def __init__(self):
...         self.A = '1'
...     def __repr__(self):
...         return 'Hi, my A value is currently %s' % self.A
...     
>>> mc = my_class()
>>> mc
Hi, my A value is currently 1
>>>

Keep in mind that you can make the return value of your repr() function literally anything. It's completely up to you how you want your class object represented.

sneekula commented: good explanation +6
jlm699 320 Veteran Poster

So your add function would need to check if the element was already in the set and if not, add it. Seems pretty straight forward. Maybe you're thinking too hard about it.

jlm699 320 Veteran Poster

What do you need help with? Do you know how to define a class yet? Here's some documentation.

jlm699 320 Veteran Poster

Let's say you have a list of your 8-bit binary elements called new_bytes , if you already have them back into '\x00' form, you could simply write to file like this:

fh = open( 'my_new_file.jpg', 'wb' )
for new_byte in new_bytes:
    fh.write(new_byte)
fh.close()

However if you still need to convert the binary string into hex then you can do either use something like hex('0b10011010') (NOTE: the notation 0b denotes Binary, just as 0x denotes hex-refer here for more details).

jlm699 320 Veteran Poster

I've never set up a mail server. I suggest google.com

jlm699 320 Veteran Poster

Does your laptop also have an open mail server listening on the default port? smptlib provides methods to connect to an smtp mail server, but if your laptop is not currently running one, then you cannot send mail to it.

jlm699 320 Veteran Poster

that works great, thank you! Only thing is, when I print out the 'encrypted' list, it's full of characters like '\x0e', '\xc4' etc etc... not the 1s and 0s I want, how do I get it to do this?

Sorry for all the questions, very limited knowledge I have, you've been very helpful though.

Yes, unfortunately Python's file handling wasn't intended for bit-by-bit reading of a file; the read function takes an optional parameter for the number of bytes to read. Since we used '1', that told Python to read the file byte-by-byte. Each of the characters that you see is a single byte of the image data.

Equipped with the knowledge that a byte consists of 8 bits, you could consider it a personal challenge to come up with a way to take each of those bytes and translate it into the corresponding bits.

\xc4 means hexadecimal C4, a.k.a. 0xC4

>>> int('c4',16)
196
>>> int('0xc4',16)
196
>>>

In fact, I believe that Python 3.0 (and therefore 2.6) has a built-in method bin() that would translate directly to binary.

jlm699 320 Veteran Poster

rc = re.compile( '^THERE WERE ([0-9]*) DIFFERENCES$' )
1. What do the symbols ^,* and $ stand for?

This standard regular expression stuff (refer here for more)...
^ - Indicates match the beginning of the line of text (ie, won't match something in the middle of a line.. the line must start with the text immediately after this symbol)
* - Match as many repetitions of the preceding character as possible (ie, match as many numerals as possible, in this example)
$ - Indicates the end of the line of text. In our case, the line MUST end with 'DIFFERENCES'.

2. The text file is a diff file from a comparer program ... So the number expected could be even double/triple digits... Should I change accordingly ? say [0-999] ???

No, [0-9] is shorthand for writing [0123456789], meaning match anything within this group (brackets indicate a group). Since the following character is *, that means that the regular expression will match any numeral as many times as possible... here's an example to illustrate:

>>> import re
>>> rc = re.compile( '^THERE WERE ([0-9]*) DIFFERENCES$' )
>>> rc.match('THERE WERE 19384856 DIFFERENCES')
<_sre.SRE_Match object at 0x01D11F60>
>>> rc.match('THERE WERE 19384856 DIFFERENCES').group(1)
'19384856'
>>> rc.match('THERE WERE NO DIFFERENCES')
>>> # Since the match() function returned nothing, it means no match
>>> rc.match('THERE WERE 0 DIFFERENCES')
<_sre.SRE_Match object at 0x01D11F60>
>>> rc.match('THERE WERE 0 DIFFERENCES').group(1)
'0'
>>>

Hope that helps

jlm699 320 Veteran Poster

Yes well, I forgot that read() does not raise a stop iteration when used in the manner that it is being used here... so the try-except case never gets thrown and we're stuck in an infinite loop.

You can do something like, if bit == '': break

jlm699 320 Veteran Poster

Please use code tags when posting any type of code
[code=syntax] # Code goes here

[/code]
syntax can be replaced with any code that is supported by DaniWeb like: python, php, etc.

jlm699 320 Veteran Poster

Here's how to add items to a list:

>>> bits_list = []
>>> bits_list.append('0')
>>> bits_list.append('1')
>>> bits_list.append('1')
>>> bits_list
['0', '1', '1']
>>>
jlm699 320 Veteran Poster

You can use a regular expression to grab the number of differences... please ask if there's anything you don't understand.

>>> import re
>>> # my_file_handler = open( 'myfile.txt' )
>>> # my_file_lines = my_file_handler.readlines()
>>> # Here's the contents of my_file_lines after a readlines()
>>> # my_file_lines = [ 'FILE A HAS 2266 LINES OF WHICH 951 WERE IGNORED', 'FILE B HAS 2193 LINES OF WHICH 878 WERE IGNORED', 'THERE WERE 2 DIFFERENCES']
>>> rc = re.compile( '^THERE WERE ([0-9]*) DIFFERENCES$' )
>>> for line in my_file_lines:
...     if rc.match(line):
...         num_diffs = rc.match(line).group(1)
...         print num_diffs
...     
2
>>>

HTH

jlm699 320 Veteran Poster

Thank you, however I'm using Python 2.6.1... is there a different way to do it using that?

Maybe try this.. pretty much same principal as 3.0 :

fh = open('myfile.txt', 'rb')
while True:
    try:
        fh.read(1)
    except:
        pass
jlm699 320 Veteran Poster

Well, Then how do you guys write proprietor(non-free) software with python?

Open-Source software is the way to go.

jlm699 320 Veteran Poster

Did you download and install mpgedit? The link is provided above...

jlm699 320 Veteran Poster

I don't believe that there is a way to ensure Python is un-reverse engineer-able... Meaning that even Python byte code programs can be translated back to source code if someone were dedicated enough to do it.

That being said, I used to be a C++ programmer until I discovered Python. I have not touched C++ since I learned Python and have never looked back. I hope that I can continue to use Python for the rest of my professional career as it is by far the best language that I've ever used. It makes programming actually enjoyable and stress free.

The resource I used to learn Python was Dive Into Python, which is a book that is geared towards programmers and not beginners, as it assumes you already know much about control structure, data types, etc.

I hope that you enjoy learning Python and I think that you'll find that it is nothing short of a pleasure to use.

jlm699 320 Veteran Poster

I would highly suggest reinstalling and making sure you install under admin for everything.

jlm699 320 Veteran Poster

EDIT: I see what you're doing now... in your code above, you have a mistake... it should be for x in A instead of for x in B , right?

jlm699 320 Veteran Poster

does anyone know if it's possible to make this using Tkinter?

Yes, it is. Coming up with a design for the game board (colors, sizes, etc.) might be the hardest part. We can help you once you get started if you get stuck on anything, just don't forget to post the troublesome code and the related error/problem

jlm699 320 Veteran Poster

Remove an item from a list:

>>> B = [12,24,36,48,60,72]
>>> B.remove(24)
>>> B.remove(48)
>>> B.remove(72)
>>> B
[12, 36, 60]
>>>
jlm699 320 Veteran Poster

I find that best practice is to always use strip() on lines that I read in from files. This gets rid of all leading and trailing white-space (tabs, spaces, newlines, etc.)

Also, here's a rewrite of your code... I removed the tabs and replaced them with spaces and also stripped out the unnecessary work that you were doing... Please look it over and if there's anything you don't understand, ask and we shall explain.

def rec_paths(file_name):
    f = open(file_name)
    g = f.readlines()	

    for each_line in g:
        if 'path' in each_line.strip():
            return( each_line.strip() )

print(rec_paths('C:\\Documents and Settings\\folderX\\Desktop\\t.txt'))
jlm699 320 Veteran Poster

f.seek(0) will always return to the beginning of a file as well. If you print out the value of beginning in the code snippet above, you'll likely find that it is an integer == 0.

jlm699 320 Veteran Poster
import os, glob
path = 'd:\del'

for my_file in glob.glob( os.path.join(path, '*.jpg') ):
  (dirName, fileName) = os.path.split(my_file)
  (fileBaseName, fileExtension) = os.path.splitext(fileName)
  print fileBaseName

Are you getting errors? You don't need to import os.path, as you can simply use os.path after importing os...

Also, you aren't using the array module so I removed that as well.

Another thing: file is a reserved word in Python so I would suggest that you avoid using it as a variable name.

Finally: Paths in Windows are tricky because '\' is an escape character in Python... so a path such as 'C:\My Documents\Music' should be written as either 'C:\\My Documents\\Music' or r'C:\My Documents\Music' (which is raw string format)

jlm699 320 Veteran Poster

I don't really understand what you're asking... Can you clarify what you need help with?

jlm699 320 Veteran Poster

Keep getting an error about the tnls:

Your indentation is off... starting with tnls on line 114 and again at 133 going down.

jlm699 320 Veteran Poster

Not sure exactly what you're asking... but you could make a list of tuples list:

my_list = [ (0,0),
            (0,1),
            (1,1),
            (1,2) ]

? Is that what you're asking?

jlm699 320 Veteran Poster

os.popen allows you to execute a system call from within Python, as if you were in the command line. Note that this method would only work on Windows platforms...

jlm699 320 Veteran Poster

Until py2exe works with Python 3 you're out of luck... if you can get your users to install Python 3 then all they have to do is double click on the script to run it...

jlm699 320 Veteran Poster

First of all, you should use code tags like such:
[code=python] # Code goes in here

[/code]
Which would've given you the following:

if param[0:4]<>'ini=':
    print ' %s ini='%sys.argv[0]
    sys.exit(1)
inifile=param[4:]

Now, to answer your question:
First we check that the first 4 characters of param are "not equal" to ini= ... <> is the obsoleted form of != So, as long as the first four characters of param are not 'ini=' then we execute the code block within the if statement, which is printing the name of our program ( sys.argv[0] is always the name of the running program), and then we exit with a return of 1...

If the first four characters of param WERE 'ini=', then we would execute the line of code immediately after the if block, which declares the variable inifile to be equal to the remainder of param.. here's an example of that slicing:

>>> param = 'ini=myinifile.txt'
>>> param[0:4]
'ini='
>>> param[:4]
'ini='
>>> param[4:]
'myinifile.txt'
>>>
vegaseat commented: very nice +11
jlm699 320 Veteran Poster

What's an append?

Append is a way to "add on" to the "end" of the list... Here's a visual example:

>>> my_list = [1,2,3]
>>> my_list
[1, 2, 3]
>>> my_list.append(4)
>>> my_list
[1, 2, 3, 4]
>>> my_list.append([9,8,7])
>>> my_list
[1, 2, 3, 4, [9, 8, 7]]
>>> my_list.append(-1)
>>> my_list
[1, 2, 3, 4, [9, 8, 7], -1]
>>>

HTH

jlm699 320 Veteran Poster

I have put # -*- coding: utf-8 -*- on the top of the script

If you remove that line from the top of your script does it change the result?

Also, have you tried utf-16 ?

jlm699 320 Veteran Poster

I need help with my homework :( but no one's replying. [note: this comment was just to move this thread back to the top of the list]

This isn't a place to come and have your homework done for you. Forum-goers here typically don't just give out solutions to homework, as that would be immoral and you'd never learn anything.

When it comes to homework or projects the best bet for getting help is to give us the code that you've tried and the errors or incorrect results that it has produced. We can then give you tips and help you tweak the code, but we do not provide e2e solutions. Not for homework, anyway... I suggest reading this announcement

Oh and we know what a *bump* is; no need to explain.

jlm699 320 Veteran Poster

Why reinvent the wheel? Python has a text wrapping module built right in

jlm699 320 Veteran Poster

file_list ends up with the final value from data, rather than a string of all values in the file

On every iteration you're simply over-writing the value of file_list. The proper way to use a list is:

my_list = []
for line in my_file:
    my_list.append( line )

Now on ever iteration of the for loop, we'll *append* each line to the list...

When you say "Just kill the readline() and print the results of the slice in line 3" do you mean to simply end the for loop with file_list = line?

Yes he is saying to remove the line of code containing readline(); however file_list = line is not going to give you the results that you want (refer to my first section of comments)

Somehow I'm not getting the full concept here. Sorry. The bit about "print the results" is throwing me off since I really want to load all the data in to file_list, not "print" it.

He was only suggesting that you print the results for your own debug purposes. Using print statements periodically throughout your code helps when you don't know what's happening... it helps to show you what each step is doing to your data.

HTH

jlm699 320 Veteran Poster

Oh yes, and also don't forget to commit your transactions (a requirement for psycopg2). So if you do something like:

# Connect to our database
my_db = psycopg2.connect( my_db_info_string )
# Create a cursor for our transactions
my_cur = my_db.cursor( ... )
# Perform our transaction (query)
my_cur.execute( my_query )
# Commit this transaction to the database
my_db.commit()
jlm699 320 Veteran Poster

Here's a class example...

>>> class car(object):
...     def __init__(self, make='Any', model='Something', year='Unknown'):
...         self.make = make
...         self.model = model
...         self.year = year
...     def __repr__(self):
...         return 'Hello, I am a %s %s %s' % (self.year, self.make, self.model)
...     
>>> my_car = car('Ford', 'Focus', '2008')
>>> your_car = car('Pontiac', 'Grand Prix', '1998')
>>> my_car
Hello, I am a 2008 Ford Focus
>>> your_car
Hello, I am a 1998 Pontiac Grand Prix
>>> your_car.year = 2008
>>> your_car.model = 'Montana'
>>> your_car
Hello, I am a 2008 Pontiac Montana
>>> unknown_car = car()
>>> unknown_car
Hello, I am a Unknown Any Something
>>>
jlm699 320 Veteran Poster

What do you mean by "play" ? Are you wanting to have an image pop up in a window or are you talking about playing a video file?

jlm699 320 Veteran Poster

I am using psycopg2 to read from one database table and insert these into another table. I get a format error when the value I am trying to insert has a space in it. The condensed code looks like:
cursor.execute("""INSERT INTO table (column1, column2)
VALUES ('start finish','now later')""")

I'm a newbie to psycopg2 but this seems like a silly limitation. Any ideas for a work-around?

The syntax of most database languages requires quotes around string values with spaces so the proper way of doing the above is:

cursor.execute('INSERT INTO table (column1, column2)
                      VALUES ("start finish","now later")')
jlm699 320 Veteran Poster

Oh well actually I had to use functions to do this lesson, otherwise I would fail.

Could you have done it this way??

def my_function( language ):
    if "french" in language:
        return "Bonjour, comment allez-vous?"
    elif "german" in language:
        return "Hallo, wie geht es Ihnen?"
    elif "hungarian" in language:
        return "Szia, hogy vagy?"
    elif "dutch" in language:
        return "Hello, hoe zijn u?"
    else:
        return "Invalid language entered"

    # main
while True:
    print"Hello, how are you?"
    language=raw_input("Pick a language: french, german, hungarian, dutch: ")
    print my_function( language.lower() )
jlm699 320 Veteran Poster

Any corrections and explanations to my code?

Your return statement is inside your for loop so it's exiting on the first iteration.... if you knock it back an indentation level it'll work:

>>> def int2roman(number):
...     numerals={1:"I", 4:"IV", 5:"V", 9: "IX", 10:"X", 40:"XL", 50:"L",
...               90:"XC", 100:"C", 400:"CD", 500:"D", 900:"CM", 1000:"M"}
...     result=""
...     for value, numeral in sorted(numerals.items(), reverse=True):
...         while number >= value:
...             result += numeral
...             number -= value
...     return result
...     
>>> print int2roman(input("Enter a number (1 to 4999) in decimal form: "))
Enter a number (1 to 4999) in decimal form: 1942
MCMXLII
>>> print int2roman(input("Enter a number (1 to 4999) in decimal form: "))
Enter a number (1 to 4999) in decimal form: 1994
MCMXCIV
jlm699 320 Veteran Poster

I too have found shutil copies to be very time consuming, especially when copying between a hard-drive and a thumb-drive.

If you are writing a MAC-only utility you could simply use a system call to the recursive copy function, ie (in Linux):

import os
#
src_dir = '/home/usr/test_source'
dst_dir = '/home/usr/test_dest'
#
r = os.system( 'cp -fr %s %s' % (src_dir, dst_dir) )
if r != 0:
    print 'An error occurred!'

In the past I've replaced shutil with my own file copy method:

def CopyFile(self, old, new):
    """ This function is a blind and fast copy operation.
          old and new are absolute file paths. """
    fsrc = None
    fdst = None
    keepGoing = False
    max = os.stat(old).st_size
    try:
        fsrc = open(old, 'rb')
        fdst = open(new, 'wb')
        dlg = wx.ProgressDialog("File Copy Progress",
                "Copied 0 bytes of " + str(max) + " bytes.",
                maximum = max, parent=self, style = wx.PD_CAN_ABORT
                | wx.PD_APP_MODAL | wx.PD_ELAPSED_TIME | wx.PD_REMAINING_TIME
        )
        keepGoing = True
        count = 0
        #
        while keepGoing:
            # Read blocks of size 2**20 = 1048576
            # Depending on system may require smaller
            #  or could go larger... 
            #  check your fs's max buffer size
            buf = fsrc.read(2**20)
            if not buf:
                break
            fdst.write(buf)
            count += len(buf)
            (keepGoing, skip) = dlg.Update(count, "Copied " + \
                str(count) + " bytes of " + str(max) + " bytes.")
        dlg.Destroy()
    finally:
        if fdst:
            fdst.close()
        if fsrc:
            fsrc.close()
    #
    return keepGoing

Note that the above function was developed under wxPython and used a progress dialog box …

jlm699 320 Veteran Poster

I wasn't sure of what type of averaging you were looking to do so I assumed something that sounds nothing like what you want. Basically here's the template version:

# Initialize your variables here for avg, sum, count, etc..
    # You may also declare what directory you're working with
    # Example my_dir = '/home/usr/data_collection'
    file_list = os.listdir(my_dir)
    #
    for file_name in file_list:
        # os.path.join will be needed for open() if we're not
        #   currently within my_dir as a working directory
        # To remove the need for os.path.join we could also do
        #   os.chdir( my_dir )
        file_path = os.path.join(my_dir,file_name)
        # example file_path = '/home/usr/data_collection/test1.txt'
        # To protect us from sub directories we'll check if file_path points to a regular file or a directory
        if os.path.isfile(file_path):
        # Open the file, read it's contents into a list, and close it
            fh = open(file_path)
            lines = fh.readlines()
            fh.close()
            #
            # Iterate line-by-line
            for line in lines:
                # Split each line up by white space and strip off line separators (\n or \r\n)
                line_data = line.strip().split()
                # Check that we have two values per line to avoid error
                if len(line_data) == 2:
                    Assign each segment of the line to a variable
                    element = line_data[0]
                    value = line_data[1]
                    # This is where you update your average, sum, count, etc...
                    # Again, this all depends on what you're looking to average
            #
    # Print the results here at the end

Please, try to understand each and every step of this. Don't be afraid to ask questions …

jlm699 320 Veteran Poster

I assume that re-ordering is due to the way that dictionaries are stored in memory... in order to provide faster searching and indexing dictionaries are stored in a special way... much unlike lists and tuples, which retain their order.... Example:

>>> d = {'cat':'purr', 'dog':'woof', 'aardvark':'?', 'chocolate rain':'feel the pain'}
>>> print d
{'aardvark': '?', 'chocolate rain': 'feel the pain', 'dog': 'woof', 'cat': 'purr'}
>>> l = ['cat:purr', 'dog:woof', 'aardvark:?', 'chocolate rain:feel the pain']
>>> print l
['cat:purr', 'dog:woof', 'aardvark:?', 'chocolate rain:feel the pain']
>>>
jlm699 320 Veteran Poster

My thoughts:

Traverse the grid from top-to-bottom, and left-to-right (ie, just like reading a book).
On each character, make a list of *this letter concatenated with every surrounding letter (for this example we'll start at the left or due west position and progress counter-clockwise, ie:

grid = """
ashfghj      0,0 1,0 2,0 3,0 4,0 5,0 6,0
weatyuu      0,1 1,1 2,1 3,1 4,1 5,1 6,1
xctbnmz      0,2 1,2 2,2 3,2 4,2 5,2 6,2
"""

Assume we're looking for hat... we start at position 0,0 and make the list ['as', 'ae', 'aw'] , none of which match 'ha' (from 'hat'). Although since the letter a doesn't match the first character of 'hat', we can move on...

We repeat for s and then h. The character 'h' matches the input_word[0] so we construct the list as above, which reads ['hs', 'he', 'ha', 'ht', 'hf'] and we have a match with 'ha', so we take the indices of the two positions and extrapolate the direction for the length of the desired word (3)...
So 'ha' corresponds to 2,0 and 2,1 ... implying that the final character is at 2,2. After a simple check of 2,0+2,1+2,2 , we have a match and we win.

As such I guess instead of a list of we could use a dictionary keeping track of indices as well... however that wouldn't be necessary since if we know the starting index, along with the position (index) of the two-letter combo in our list, we …

jlm699 320 Veteran Poster

Alright, well here's the code's merged together....

import os

def main():
    """ Example file contents from the /home/usr/data_collection directory:
        2.825       1.00697992588
        2.875       0.952989176901
        2.925       0.91428970229
        2.975       0.890110513425
        3.025       0.879731596138
        3.075       0.959217137445
        3.125       1.07391392796
        3.175       1.04874407027
        3.225       0.857693793906
    """
    # We can keep track of our data in this structure;
    #  however you may make use of any data structure 
    running_avgs = {}
    my_dir = '/home/usr/data_collection/'
    file_list = os.listdir(my_dir)
    #
    for file_name in file_list:
        # Protect us from sub directories
        # os.path.join will also be needed for open() if we're not
        #   currently within my_dir as a working directory
        # To remove the need for os.path.join we could also do
        #   os.chdir( my_dir )
        file_path = os.path.join(my_dir,file_name)
        if os.path.isfile(file_path):
        # Perform the above code on the file as long as it's valid.
            fh = open(file_path)
            lines = fh.readlines()
            fh.close()
            #
            for line in lines:
                line_data = line.strip().split()
                if len(line_data) == 2:
                    element = line_data[0]
                    value = line_data[1]
                    if running_avgs.get(element):
                        # IF it's in our dictionary we can calculate the new avg here
                        pass # This section depends on how you want to handle your avgs
                    else:
                        # The first element can be the running sum of values
                        # The second element will be the count of elements
                        running_avgs[element] = [value,1]
            #
    print running_avgs

if __name__ == '__main__':
    main()
    raw_input('Press enter to exit...')

Again, I haven't tested this so it could contain a syntax error or two... but I hope it helps get you on your way.

jlm699 320 Veteran Poster

Here's how to open a file and parse the contents as per your example:

def main():
    """ test_data.txt contents (minus leading tabs):
        2.825       1.00697992588
        2.875       0.952989176901
        2.925       0.91428970229
        2.975       0.890110513425
        3.025       0.879731596138
        3.075       0.959217137445
        3.125       1.07391392796
        3.175       1.04874407027
        3.225       0.857693793906
    """
    # We can keep track of our data in this structure;
    #  however you may make use of any data structure that suits you (classes, list, etc)
    running_avgs = {}
    #
    fh = open('test_data.txt')
    lines = fh.readlines()
    fh.close()
    #
    for line in lines:
        line_data = line.strip().split()
        if len(line_data) == 2:
            element = line_data[0]
            value = line_data[1]
            if running_avgs.get(element):
                # IF it's in our dictionary we can calculate the new avg here
                pass # This section depends on how you want to handle your avgs
            else:
                # The first element can be the running sum of values
                # The second element will be the count of elements
                running_avgs[element] = [value,1]
    #
    print running_avgs

if __name__ == '__main__':
    main()
    raw_input('Press enter to exit...')

I haven't tested that so it could contain a syntax error or two... but I hope it helps get you on your way.

EDIT: Also keep in mind that you'll want to loop this whole operation for all your files... So if the files are all under a directory you could simply do this:

import os

my_dir = '/home/usr/data_collection/'
file_list = os.listdir(my_dir)
#
for file_name in file_list:
    # Protect us from sub directories
    # os.path.join will also be needed for open() if we're not
    # …
jlm699 320 Veteran Poster
import wx
import os


class MainWindow(wx.Frame):
     def __init__(self):
        wx.Frame.__init__(self,None,-1,"Agent-Based Model of Residential Development", size = (640, 480))
        self.panel = wx.Panel(self,-1)
        self.imageFile = "C:/Documents and Settings/12345/My Documents/Files/Misc/everythingisshit.jpg"  # provide a diff file name in same directory/path
        self.bmp = wx.Image(self.imageFile,wx.BITMAP_TYPE_JPEG).ConvertToBitmap()
        self.bmp.bitmap = wx.StaticBitmap(self.panel, -1, self.bmp)
        #self.bmp.bitmap.GetSize()
        #self.SetSize(self.bmp.bitmap.GetSize())
        #self.Center()

        button42 = wx.Button(self.panel, -1, "Read", pos=(540,50))
        self.Bind(wx.EVT_BUTTON, self.OnRead ,button42)

     def OnRead(self,event):
         self.imageFile1="D:/Say cheese!/vanity/iuhf.jpg" # you have to provide a diff image file name
         self.bmp = wx.Image(self.imageFile1,wx.BITMAP_TYPE_JPEG).ConvertToBitmap()

         self.obj = wx.StaticBitmap(self.panel, -1, self.bmp)
         #self.obj.GetSize()
         #self.SetSize(self.obj.GetSize())
         #self.Center()
         self.obj.Refresh()

if __name__ == "__main__":
    app = wx.PySimpleApp()
    MainWindow().Show()
    app.MainLoop()

Re-posted with code tags.

Here's the code:

Karen,

Please make use of code tags when posting in this forum. In order to use them, you must simply wrap your code as such:
[code=python] # Your code goes in here

[/code]

Oh also, try not to use curse words (as per forum rules), even if they are inadvertently placed in your code ;)