jlm699 320 Veteran Poster

Please use code tags.
They work like this:

[code=<language>] My Code goes here!

[/code]

Where <language> is any of the languages on DaniWeb (C, Perl, Python, HTML, PHP, etc.)

jlm699 320 Veteran Poster

I understand what you're trying to do but where is your question? Do you need to know what modules can be used for this or do you need help implementing a certain portion of this idea? etc...

jlm699 320 Veteran Poster

It's not exactly clear what this example is doing.. Plus this isn't a stand-alone example of the problem that you are seeing since we don't know what possible and matches are (ie, are they lists, tuples, dictionaries, strings?) ...

If you could provide us with an idea of exactly what you're trying to do with an example of input -> output it would help greatly!

jlm699 320 Veteran Poster

Please read my last post.

jlm699 320 Veteran Poster

First of all, please use Code Tags. They make your post readable, and thus will make forum members more likely to read your problem and help you.

Secondly, you say that only the last field is "changin", but that is the only variable that changes... for emailadd in mailing_list: ... see? You're iterating over mailing_list and the variable that displays the iterated value is emailadd.

jlm699 320 Veteran Poster

You never imported your class... as I'm assuming that 'PathFinder' is not in your Main.py ... let's say it's in PF.py .... from PF import PathFinder That should do it

jlm699 320 Veteran Poster

For the many of you who still want to know the solution, make variable 'a' a global:

That or simply pass a to test:

words = ["aero", "aesthet", "andr", "arch", "arch", "ast", "baro",\
"biblio", "bio", "cardi", "chron", "cosm", "crat", "cycl", "dem", "dont",\
"dogma", "dox", "esth"]

answers = ["air", "sense", "man", "man", "chief", "ancient", "star", "weight",\
"book", "life", "heart", "time", "universe", "rule", "circle", "people",\
"tooth", "opinion", "belief", "feeling"]

a = 0

def test(a):
    a = a + 1
    print "What does", words[a], "mean?"
    ans = raw_input("> ")
    if ans == answers[a]:
        print "Correct!"
        test()
    else:
        print "That is incorrect. Try again."
        a = a - 1
        test()

test(a)
jlm699 320 Veteran Poster
jlm699 320 Veteran Poster

Yes. That would simply be a system call, which can be achieved by any number of Python methods (popen, os.system, subprocess, etc.).

As far as the GUI portion that can also be achieved by any number of Python GUI toolkits (wxPython, Tkinter, EasyGUI, etc.)

I refer you to google for any more information on those topics.

jlm699 320 Veteran Poster

For the "GUI" portion of your program you'll likely want to look into wxPython. There are a number of other toolkits for creating GUIs but wx is by far the most native-looking so it'll get you a very clean looking interface that looks like it was built right into Windows. It'll be impressive for your friend I'm sure.

jlm699 320 Veteran Poster

Yes zachabest is correct. There is nothing special about a csv file. It is literally a text file that uses commas to delimit, or separate, each data cell of a row. Each new line is therefore a new row.

I've found that using the csv modules are overkill and it is much easier to simply read the file as standard text and use common PYthon operations like split(',') and ','.join() to manipulate your data.

jlm699 320 Veteran Poster

From the documentation

parse( source)
Process an input source, producing SAX events. The source object can be a system identifier (a string identifying the input source - typically a file name or an URL), a file-like object, or an InputSource object. When parse() returns, the input is completely processed, and the parser object can be discarded or reset. As a limitation, the current implementation only accepts byte streams; processing of character streams is for further study.

So it looks like you can't simply send text; a quick work-around would be to save that ISBNdb_XML to a temporary file and then use the file path as the parameter to parse()

jlm699 320 Veteran Poster

You can launch threads for each new process. Look into the Python subprocess module

jlm699 320 Veteran Poster

Where does execution stop? Does it give an error? Where is this so-called "file open file print" statement?

jlm699 320 Veteran Poster

Sometimes you can simply do import <module> in the setup.py script as a work around; however this does not work in all cases.

jlm699 320 Veteran Poster

Perhaps because you are appending to p1 instead of p ?

although even after replacing p1 with p the list shows up empty... what exactly are you trying to do here?

I have a feeling it's an indentation error...

jlm699 320 Veteran Poster

I suggest that you modularize your code. Come up with some kind of structure that will detail player positions.

Then come up with a function to print the game board, which takes the player position structure as input. Then you'll need a 'movement' function, which will check two other functions for checking whether a move is valid or not, as well as winning conditions.

jlm699 320 Veteran Poster

What have you tried so far? What errors are you running into? What are the rules of said game?

jlm699 320 Veteran Poster

I would suggest a nested for loop like:

for row in xrange( usr_row ):
    for col in xrange( usr_col ):
        ## Do my division and printing
jlm699 320 Veteran Poster

You're never reading your file... you're literally trying to read from sys.stdin. This is wrong and I think you may have misunderstood your prof.

You need to open the file via open(file_name, mode) ... then read from there....

jlm699 320 Veteran Poster

Hmm... there is no way to simply tell Python to insert a line at a specific "index" of lines (that I know of, although it would be a great way to contribute to the on-going Python development!!)... We could go about this two ways:

Approach 1: keep each line that we want to write to output in a list (this is the format in which using readlines() returns our data). That way, we can make use of the list's insert([index],[value]) function.
When you are done with your calculations, you can iterate over the list and write each line back to an output file.

Approach 2 (much more complicated): Open the output file in append mode, and using a combination of seek() and tell() commands [tell returns an int that represents the position of where the file handler is pointing within the file], [seek moves the file handler to a specific spot within the file (ie, seek(0) returns to the beginning of the file)] we could actively modify the file. Don't forget to flush() !! [flush writes and changes to the file that are currently stored in the buffer]

I would suggest Approach number 1, as number 2 has too much potential for bugs and silly mistakes! I hope it makes sense to you what I've suggested and if not I will clarify and provide an example if you don't know how to work with lists.

jlm699 320 Veteran Poster

I have an inkling that he means reload a module... I too have looked around google and found some sites that insist that it can be done. I just don't know how.

To further clarify when I'm developing a module and I import it into my python shell then realize I need to change the module, instead of closing the shell, modifying the module, then reopening the shell and reimporting and doing all the steps I could just 're'-import it and have it pull in the newer version... if that makes sense.

jlm699 320 Veteran Poster

Paulthom also forgot to mention that the replace function has an optional third parameter that will help you greatly:

>>> t = 'I love cheese;  cheese is my favorite thing to eat besides melted cheese.'
>>> t.replace('cheese', 'Shredded Gorgonzola', 1)
'I love Shredded Gorgonzola;  cheese is my favorite thing to eat besides melted cheese.'

The third parameter is count and I'm sure that you'll be able to deduce how to use it from my example. HTH

jlm699 320 Veteran Poster

Here's a snippet of a setup.py that I've used before to grab things that were not in the same directory...

setup(
  zipfile = None,
    # We use os.path.join for portability
    package_dir = {'': os.path.join('..', 'Common')},
    py_modules = ['mylog', 'IPVerify', 'logfile', 'remoteCmd', 'rd_num_gen', 'crc32'],
	windows = [
		{
			"script": "my_program.py",
			"icon_resources": [(1, "my.ico")],
			"other_resources": [(24,1,manifest)]
		}
	],
)

NOTE: The py_modules were .py scripts that were in the Common directory

I can't guarantee that this will work for images, but it will definitely work for modules.

jlm699 320 Veteran Poster

HEre's a few things to get you on your way... first iterating over a list of files using the os module:

import os

my_dir = '/home/AtomData/'
## path example for Windows:
## my_dir = 'C:\\XXX\\AtomData\\' 

my_files = os.listdir(mydir)

for each_file in my_files:
    ## Here we will do our file actions

Note: The windows path looks funny because in Python '\' is an escape character, so you need to escape the escape character to use it normally in a string (if that makes any sense)

So in the past example we see how to list the contents of directory. Note that this command, much like ls or dir will list all contents including sub-directories, which is why it may be appropriate to check the following condition before opening a file if os.path.isfile(each_file): . This way you don't try to open a directory as a file handle!

Next we'll look at iterating over a file. There are many approaches to doing this, I will show you the one I most often use.

f = open( os.path.join( my_dir, each_file ), 'r' )
lines = f.readlines()
f.close()

for each_line in lines:
   ## Do your data parsing here

So the open() function returns a file handle, which points to the file that you provided, and since we provide 'r' for the Mode, the file will open in 'read' mode. Similarly you could use 'w' for write (this will begin a new file if it does not exist or clear the contents …

jlm699 320 Veteran Poster

Reference this page: Python DeBugger (PDB)

jlm699 320 Veteran Poster

Yes, what vegaseat suggested... either that or use an escape (a la \) before the text as in:

>>> t = '!,.?\'$%'
>>> print t
!,.?'$%
>>>

Same thing goes for double quotes within double-quoted string:

>>> t = "!,.?\"$%"
>>> print t
!,.?"$%
>>>
jlm699 320 Veteran Poster

This is similar to someone who wanted to use py2exe on linux ... both of these packages (py2app and py2exe) are somewhat misleading; as they do not simply build an executable 'version' of your program, they literally package your scripts together with an as-needed version of Python.

jlm699 320 Veteran Poster

...Adding on to the previous posts; another thing to keep in mind is that EVERYTHING in python is an object; meaning that the file handle (object) has methods and members that facilitate line-by-line iteration.

jlm699 320 Veteran Poster

One of the values that you are trying to concatenate is an integer. You need to wrap it with str() in order to convert it and concatenate.

Also, I don't see you performing any commit() operations. If you do not commit your transactions they will never be posted to the database.

jlm699 320 Veteran Poster

For completeness' sake be sure to let us know how you've implemented your changes once you get it working satisfactorily.

jlm699 320 Veteran Poster

Here's the code I alluded to yesterday...

import sys, pygame, math

pygame.init()

xpos = 92
ypos = 0
gravity = 9.8
velocity = 0
# How much of the velocity of the ball is retained on a bounce
bounce = 0.8
win_h = 400

screen = pygame.display.set_mode((200, win_h), 0, 32)
ball = pygame.image.load('box.bmp')
clock = pygame.time.Clock()
size_bott = ball.get_rect().bottom


# The main loop
while True:
    # Test for exit
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            exit()

    # The physics
    # Reverse velocity taking into account bounciness if we hit the ground
    if ypos >= (win_h - size_bott) and velocity > 0:
        # Avoid the ball sinking into the ground
        ypos = (win_h - size_bott)
        velocity = -velocity * bounce

    time_passed = clock.tick(60) / 1000.0
    newvelocity = velocity + (gravity * time_passed)
    # Use the average velocity over the period of the frame to change position
    ypos = ypos + int(((velocity + newvelocity) / 2) * time_passed * 160)
    velocity = newvelocity

    # Update the screen
    screen.fill((0, 0, 0))
    screen.blit(ball, (xpos, ypos))
    pygame.display.update()

The only change I made was to account for the height of the "box.bmp" dynamically since it was hard coded as 16 pixels before...

jlm699 320 Veteran Poster

try this version

After removing the two syntax errors the object simply rests at about 3/4 of the way up the screen.

I found a version online that produces accurate physics with much simpler syntax; however I am hesitant to post the code as you may not take the time to learn why it works as well as it does (The secret is in the phyics calculations).

If you ask, I will post the working version.

jlm699 320 Veteran Poster

Actually, looking into the pygame documentation reveals that the .move() function only accepts integers

jlm699 320 Veteran Poster

I just tested the code from the first page and after creating my own "box.bmp" in MSPaint I was able to observe the box "bounce" from the top of the screen to the bottom and back again before finally coming to a stop at the bottom of the window.

Looks like the "speed" value doesn't like anything below 1.0?

jlm699 320 Veteran Poster

Heh, whoops. Tequila makes you do funny things.

jlm699 320 Veteran Poster

To get a list of the contents of a folder you can use the os module's listdir() function.

Then loop over each item, and use split('.') on the name to add '_output' before opening the output file.

jlm699 320 Veteran Poster

Your choice of words is very unique and I'm not sure that I understand your dilemma; but perhaps you are asking about passing parameters to a function that you've imported from another module?

import os

os.listdir('/mydir/test/python')

Like that.

jlm699 320 Veteran Poster

Ah, so it would seem that data[0] does not contain that final email message... are there other elements to the data object that may contain this last email or is this a limitation of IMAP4?

jlm699 320 Veteran Poster

How about for num in data[0].split() + 1: ?

jlm699 320 Veteran Poster

Looking through the Date Parsing section of the feed parser reference page reveals the following: that the dateHandler functions "return a single value, a 9-tuple Python date in UTC".

Which means that the time that is returned is standardized to GMT (I still don't like the UTC naming convention)... If you would like to display it as a different timezone you will need to get the utc offset value and simply add it to the hours. Otherwise, I would just leave it in UTC so that all posts are standardized.

jlm699 320 Veteran Poster

I think your best bet would be to simply print the value of contents and then ask the user for a new value. Otherwise you will need to figure out how to prompt for input and then subsequently write to the stdin ... you can access stdin/stdout via sys.stdxxx, which will allow you to use write, read, etc. Perhaps you can make use of those to create a custom text input function.

jlm699 320 Veteran Poster

Please use code tags when posting blocks of code, and icode tags when posting small snippets. This will make sure your formatting is not lost to the ether; and will also make your posts easier for us to read; thereby making it easier for us to help you. You can read up on code tags here

jlm699 320 Veteran Poster

I don't really know what you mean by your explanation of what's happening but I presume that you would want to modify your code to use if/else if structures as such:

while mainloop == 0:
       for event in pygame.event.get():
          if event.type == KEYDOWN:
            draw_level()
            if event.key == K_ESCAPE:
                sys.exit()    
            elif event.key == K_RIGHT:
               # perform right action
            elif event.key == K_UP:
               # perform up action
            else:
               #blahblahblah.........

HTH

jlm699 320 Veteran Poster

It depends heavily on the format that you are receiving the time data in. Could you provide us with an example of EXACTLY what you are getting?
If it is coming in as a string with the Time Zone then iyou simply use time.strptime(), which will make it very easy for you.

jlm699 320 Veteran Poster

By getting rid of your infinite loops (ie, while p == 0: . You need to realize that since p is never changed within that loop, it will continuously run. I assume that you really want an if statement. Here is an example of how you would use an if:

>>> a = 0
>>> if a == 1:
...     print 'The value of a is a 1!'
... elif a == 2:    
...     print 'The value of a is a 2!'
... else:    
...     print 'The value of a is neither 1, nor 2.  It is', a
...     
The value of a is neither 1, nor 2.  It is 0
>>>
jlm699 320 Veteran Poster

You have to realize that 9 times out of 10 when you have a syntax error it's actually at the line above. So if you peer at the line above n = raw_input("what is the persons name") you'll notice that you're missing a trailing parenthesis, as I mentioned in my last post.

There are 7 syntax errors that I found in your code. 4 of which are infinite loops.

jlm699 320 Veteran Poster

You're missing a parenthesis at the end of the v = float(raw_input( line.

Also close = print "thank you for using a George Lee program" is incorrect syntax. You can either print that string or save it using close = . Which is it?

jlm699 320 Veteran Poster

You are right as to why this is happening; a variable and a function sharing the same name.

From within the class scope, self.number is the variable and self.number() is the function. When you initialize the class, it goes through and recognizes each function then calls __init__ (at least that's how I understand it). Since init is assigning something to self.number (which is already defined as a function), the reference to this method is over-written by the value of the passed-in parameter. Why not use self._number = number ?

jlm699 320 Veteran Poster

Could you give us the offending code and the Traceback? Your explanation is devoid of any information that could allow us to help you.

Help US help you!