jlm699 320 Veteran Poster

I don't know; as I've never used it. If that does not suit your needs you'll possibly need to look into the Excel API; which can be access via win32com (you'll need to learn how to use COM objects).

tzushky commented: Thanks +1
jlm699 320 Veteran Poster

Would it be possible for you to simply use a read() to bring in all the information that you can and then worry about parsing it once that operation has completed?

After storing what you've read you can perform a split('\n') and then iterate on the return to perform almost exactly like readline().

Alternately you could perform readlines(), which is basically exactly like doing a read and then splitting it up by line (returns a list).

jlm699 320 Veteran Poster

(Note that semicolons are not used in Python.)

When I was writing a data collecting application that interfaced with pgSQL via psycopg2 I tried out both ways (a query with and without a semicolon), neither of which threw any errors.

And that line ...SELECT etc, is what he typed into his Postgres GUI, not python.

jlm699 320 Veteran Poster

In my experience with regex you can combine two different regexes with an '|' (or operator). So within the quotes just place a '|' between each regex (without single quotes)'
Like so:

tennis_players = re.compile("<div class=\"entrylisttext\">([\d+]*)</div>|playernumber=[A-Z][0-9]+\" id=\"blacklink\">([a-zA-Z]+, [a-zA-Z]+)|pointsbreakdown.asp\?player=[A-Z][0-9]+&ss=y\" id=\"blacklink\">([0-9]+)|playeractivity.asp\?player=[A-Z][0-9]+\" id=\"blacklink\">([0-9]+)", re.I | re.S | re.M)
jlm699 320 Veteran Poster

When using psycopg2 your operations are only transactions. In order to get your transaction to commit to the database you'll need to issue a conn.commit() command.

PoovenM commented: AWw man you're brilliant :D +2
jlm699 320 Veteran Poster

Have you looked into pyExcelerator at all? I'd say it's worth a shot.
link

jlm699 320 Veteran Poster
import random
def getRandomFiveLetterWord(e):
    file = open(e, "r")

That format of opening a file is not wrong its the fact that you're using 'file' as your variable name. Just change the name to something like fh (file handler) or similar. That is completely arbitrary.

t = file.read()
    for line in file:
        randomWord = random.choice(t[0], t[-1])

Here you are reading the entire file into 't', yet in your for loop you're iterating over the file object, which makes no sense, and is also the cause of your problem. Since you are reading the entire contents of the file, the file pointer traverses all the way through the file until it hits the EOF (end of file marker), which is where it sits until told otherwise.
When you try to perform for line in file the pointer is already at EOF so the for loop never runs, which is why randomWord is never declared and why you are receiving your error.
Furthermore, you still missed my point about what you pass to random.choice(). It's supposed to be a list. Whereas you are passing it the first and last character of the file contents. Why don't you try feeding some of this code into your interpreter (and here you will learn the strength of Python, being able to interact with your code to find problems); for your sake just try the following lines:

fh = open('fiveLetterWords.txt', "r")  # Open the file for reading
t = fh.read()    # Read …
jlm699 320 Veteran Poster

You can set up a timer no problem and use that as your event-driving mechanism. Say a repeating five minute timer, which goes off and runs your autobackup script, dumping the results to the TextCtrl

jlm699 320 Veteran Poster

There are a number of problems here. First of all, that text file contains five letter words that are all appended together without any whitespace whatsoever.

Secondly, do not use file as one of your variable names. As you can see above, file is highlighted in purple meaning that it is a reserved word in Python.

Third, as the error is telling you, you cannot use subscript notation on a file object (file). You read the contents of the file into the variable t. At the very least you should be trying to use subscripts on t (even though that would still be wrong).

randint returns a random integer, not a word. What you want is random.choice, which you would pass a *LIST* of words to. Not a gigantic single word that you're expecting the program to magically understand to be a listing of five letter words.

So first either break up your text file into words or write a small function to read in the file contents and return a list of words.
Then implement the proper random function.

jlm699 320 Veteran Poster

[] designates a group of characters to match.. you had [d+] in there, meaning that you wanted to match any of the digits 0-9 as well as the plus symbol. An equivalent statement would be [0-9+], or typing the entire set of digits out would be [0123456789+]. By placing an * after your group of matchable characters that means match this as many times as possible. So the * solves the "only matches single digit" problem. The () are what gave the ability to extract a specific part of the text out of the matched text. Anything that is enclosed in parenthesis is able to be extracted after the pattern is matched.

P.S. if you meant to use '+' as match 1 or more times then it would have to be outside of the square brackets. Read up on regular expression syntax for more info.
HTH

jlm699 320 Veteran Poster

wxPython, like most other GUI modules is event driven. This means that until something triggers an event, processing is more or less waiting for something to happen.

I'm not sure what you mean by appending text afterwards? Do you mean literally after the mainloop() statement? Because the program stays in the mainloop() until the application is closed.

What you'll need to do is create an event that will allow you to input text and then use your appendText method to append it to the textCtrl.

I would suggest binding an event within Frame1's __init__ method that captures a key press, pops up a TextInputDialog, and then captures the input from the Text dialog and appends it to the textCtrl

jlm699 320 Veteran Poster
>>> md = {}
>>> md['a'] = [1,2,3,4]
>>> md['h'] = (1,2)
>>> md['t'] = {'first':[9,8,7], 'sec':(1,2,3,4), 'h':'foobar'}
>>> md
{'a': [1, 2, 3, 4], 'h': (1, 2), 't': {'h': 'foobar', 'sec': (1, 2, 3, 4), 'first': [9, 8, 7]}}
>>>

Is that what you mean by multiple values from a dictionary?

jlm699 320 Veteran Poster

You bind an event to intercept the maximize event and call an event.veto()

jlm699 320 Veteran Poster

i want it to be able to load the program up and then be able to choose from addition as well as substraction like a button for each on start up or something.

What if you had a radio button choice. So that addition and subtraction could be chosen dynamically. The user could try a few additions, and then go to subtraction if they wanted.
If you want to force them to perform the same ops for the entirety of the game, then another option would be to have a message box pop up when the program starts with two buttons, addition or subtraction.

jlm699 320 Veteran Poster

First, you need to use code tags on your code to make it readable and not lose your inentation.

Your line for (first, second) in pairs: is along with your error suggesting that pairs is being passed in as an integer.

When you provide an example code it would help if it is an actual example that can be run to demonstrate your dilemma. Otherwise we are left to guess at best, which is all we can do here since we can't see what you're passing to this function or what the context of your program is like.

jlm699 320 Veteran Poster

When you are calling wx.DirPickerCtrl( ) simply place the size that you want in the initialization like so: wx.DirPickerCtrl( self, -1, '', 'My Dir Picker', size = (a, b) ) where a and b are the desired dimensions.

You could also set the size after the fact with my_picker.SetSize( (a, b) ) where once again a and b are the desired dimensions.

jlm699 320 Veteran Poster
>>> usr_inp = eval( raw_input ('Enter a number: ') )
Enter a number: 5.78
>>> usr_inp
5.7800000000000002
>>> usr_inp = eval( raw_input ('Enter a number: ') )
Enter a number: 14e-5
>>> usr_inp
0.00013999999999999999
>>>

You can use the eval() method to convert your raw_input (saved as a string) to int or float. You should also work into your code a check after that input to make sure that the user did not enter a string, as that will mess up your "maths" as you put it.
A simple try: except: clause wrapping your maths should do it.

jlm699 320 Veteran Poster

I am getting errors such as False is not defined.
When I made it try returning a counter in the modules that called it I get the error that the counter is not defined.

False is a reserved keyword in Python. Make sure you are capitalizing the F in False however.
If you are using a variable inside the function, make sure you return it and capture it outside the function as following:

>>> bool_list = [True, True, 1, 'Hi', False, 0, '']
>>> len( bool_list )
7
>>> def retFalseIndx( list ):
...     my_counter = 0
...     for item in list:
...         if not item:
...             return my_counter
...         else:
...             my_counter += 1
...     
>>> retFalseIndx( bool_list )
4
>>> ret = retFalseIndx( bool_list )
>>> ret
4
>>>
jlm699 320 Veteran Poster

yep exactly, if they input a negative number it will return differentiate that form a positive number.
Also thanks alot for what you have given me.

>>> li = [ 1, -2, 2.3, 't', -5.3e5, -0.1, 4e-5, 'hey!' ]
>>> for item in li:
...     test = str(item)
...     if test == item:
...         print item, 'String!'
...     else:
...         if item < 0:
...             print item, 'Not string... negative!'
...         else:
...             print item, 'Not string... positive!'
...     
1 Not string... positive!
-2 Not string... negative!
2.3 Not string... positive!
t String!
-530000.0 Not string... negative!
-0.1 Not string... negative!
4e-005 Not string... positive!
hey! String!
>>>

Simply check if the number is less than zero to determine if it is negative.
Just remember to do this only after you've verified that the item is not a string or else you will run into some strange results.

jlm699 320 Veteran Poster
fin = open ('input.bin')
fout = open ('output.bin')
fin.readline()

x = fin.readlines (1)
str (x)

open( file_name ) defaults to read mode. You want open( file_name, 'w' ) for your output file so that you may write to it.
This first part is moving the file cursor. Are you sure you want to do this?
The first fin.readline() does not store the line anywhere.
The x = fin.readlines(1) already reads in a string, so saying str(x) isn't doing anything... (especially since you're not storing the result of str(x) ).

for row in fin:
    print open ("input.bin", "r")

What? You are iterating over each line of your input file here. But on each iteration you are reopening "input.bin" for reading?

for line in open ("input.bin", "r"):
    print output.txt,

fout = open ("output.txt", "w")

Now you are opening your input file once more, not storing the file handler but still iterating over it. On each iteration you're trying to print output.txt .... this should be throwing an error since you never created any thing called output, especially an output with an attribute txt.
Then at the end you're simply opening the file "output.txt" for writing and not writing anything to it.
I don't believe that your program will even run.
File reading and writing should be done something like this:

fh = open('input.bin', 'r')
fo = open('output.txt', 'w')

for line in fh:
    # do something to line here, storing to another variable …
jlm699 320 Veteran Poster

There are a few possibilities I can think of, but probably the most straight forward:

>>> li = [ 1, 2.3, 4e-5, 'hey!' ]
>>> for item in li:
...     test = str(item)
...     if test == item:
...         print item, 'String!'
...     else:
...         print item, 'Not String!'
...     
1 Not String!
2.3 Not String!
4e-005 Not String!
hey! String!
>>>

Now when you say restrict this to positive numbers, do you mean:
If Input is not <a positive number>:
perform action

vegaseat commented: Good example +8
jlm699 320 Veteran Poster

Building off of paulthom12345's code...

import random, sys

words = ['sprinkles', 'computer', 'mouse', 'shooter', 'edge', 'guard', 'python']
myword = random.choice(words)
guesses = "aeiou"
turns = 10

print "Do you want to play a game of hangman?"
play = raw_input('Answer (y) yes or (n) no:')
if play == 'y':
    print 'Let\'s begin'
    while turns:
        blank_flag = False
        turns-=1
        print ""
        for letter in myword:
            if letter in guesses:
                sys.stdout.write( letter )
            else:
                blank_flag = True
                sys.stdout.write( '_' )
        sys.stdout.write('\n')
        sys.stdout.flush()
        if not blank_flag:
            print "You've won!!!  AMAZING!"
            break
        usr_inp = raw_input( "Enter your guess (only one letter): " )
        if len(usr_inp) > 1:
            print "You've forfeited a turn by entering more than one letter."
        else:
            guesses += usr_inp
    if not turns:
        print "GAME OVER!"
else:
    print 'Good-Bye.'
jlm699 320 Veteran Poster
>>> '%e' % (5 * 0.00544)
'2.720000e-002'
>>> '%.2e' % (5 * 0.00544) ## This is the correct form of sci. notation *10^-2
'2.72e-002'
>>> 
>>> 0.0272 * 10**18  ## This is what your number was
27200000000000000.0

You see? Like I said, you were way off. That last one is 10^18

jlm699 320 Veteran Poster

You are mistaking sub/superscript for scientific/exponential notation (P.S. your scientific notation conversion is way off).

>>> '%e' % (5 * 0.00544)
'2.720000e-002'
>>> '%.2e' % (5 * 0.00544)
'2.72e-002'
>>>

That illustrates some text formatting in Python. If you'd like information check out this page on Formatting

jlm699 320 Veteran Poster

For superscript you could use:

>>> print '\xb2'
²
>>> print '\xb3'
³

I'm not so sure about subscript though. Just try typing into your interpreter:

>>> a = '<your_character_here>'
>>> a
'\<escaped_version_of_your_character>'