jlm699 320 Veteran Poster
elif rows[4][2] and rows[3][3] and rows[2][4] and rows[1][5]=='O':
        return "O Wins"

As already stated, you must move the call to main() to the end of your program; however the above syntax is WRONG.

It should be:

elif rows[4][2] == 'O' and rows[3][3] == 'O' and rows[2][2] == 'O' and rows[1][5] == 'O':
jlm699 320 Veteran Poster

Tkinter certainly would let you do it, but if it were me I'd go with wxPython. It'll probably get you there quicker.

jlm699 320 Veteran Poster

Search this forum for mentions of pygame. It's a great module that will help you in making use of your sprites and granting you the ability to move them in response to button presses, etc.

jlm699 320 Veteran Poster

Well you can still use your Python skills on the query that you send to SQL, it's only the syntax within the quotes that needs to be SQL:

cursor.execute("CREATE TABLE %s (%s TEXT, %s TEXT, %s TEXT, %s TEXT, %s TEXT)" % (t_name, t_date, t_explanations, t_deposit, t_withdraw, t_balance)  )
jlm699 320 Veteran Poster
cursor.execute("CREATE TABLE  ? (? TEXT, ? TEXT, ? TEXT, ? TEXT, ? TEXT)", (t_name, t_date, t_explanations, t_deposit, t_withdraw, t_balance)  )

Are you allowed to create things with a '?' for the name? That doesn't look right to me...

jlm699 320 Veteran Poster

I've used IcoFX in the past with no trouble

jlm699 320 Veteran Poster

When you return someting from a function you should use a container to "catch" it...

returned_list = mod2.calc(pile2,m,pile3)
return returned_list

Understand what I mean?

jlm699 320 Veteran Poster

What is it? Python is an OO scripting language.
What's good about it? Everything.

That's all you need to know, now dive into Python!

jlm699 320 Veteran Poster

What's a search engine?

The best part is that two people didn't pick up on the sarcasm and actually replied. Makes this triple-funny

Salem commented: *bows* +26
jlm699 320 Veteran Poster

If those classes are in the file myfile.py the easiest thing to do is:

from myfile import ClassA
from myfile import ClassB
# OR, simpler:
from myfile import *

If the files are named after the class, are set up correctly, and in the same directory as the file calling them, you can simply do:

import classA, classB

And P.S. in the future: please use code tags when posting code in this forum, it makes it easier for us to read your code. use the tags as following:
[code=python] # Code in here

[/code]

jlm699 320 Veteran Poster
while (guess != correct) and (guess !=""):
    
   if guess != correct:
        print "Incorrect..\n"

   print "Thanks for playing."     
   raw_input("\n\nPress the enter key to exit.")
        

if guess == correct:
   print "That's it! You guessed it!\n"

print "Thanks for playing."
raw_input("\n\nPress the enter key to exit.")

Looky here: you've got an infinite loop with the while statement. Especially because inside that while loop you're not updating the value of guess. So it will just repeatedly print and ask the user to press enter...

jlm699 320 Veteran Poster

It would seem that your network is blocking the site.

Are you able to access it via web browser?

jlm699 320 Veteran Poster

I reiterate: you never update the variable named count in your while loop, so it's stuck in an infinite loop. You'll need to increase it on every iteration, ie count += 1

jlm699 320 Veteran Poster

Try and see if you can ping that server/port from your office. It seems like it's getting blocked.

jlm699 320 Veteran Poster

Would you see what I'm doing wrong.

You've got an infinite loop at the end there...

while count < len(word):
    if (word[count] in vowel):
        numVowels = numVowels + 1

You see? You never update the count variable, so it'll always be less than the length of word (ie, infinite loop).

In the future please post your code surrounded by code brackets so that it's easier to read
[code=python] # Code in here

[/code]

And like that C-loving guy suggested, it would help if you could ignore caps vowels by doing something like this:

word = raw_input("Enter X: ")
word = word.lower()

lower() is a string method that returns the lower-case representation of the string.

jlm699 320 Veteran Poster

You could also take this one step further and use a dictionary of dictionaries with row and column number as keys.

Brilliant. I really like this idea! Nice!

jlm699 320 Veteran Poster

hoe to write a generic code for creating a empty 2D array and dynamically insert values in it.

>>> arr_2d = [[]]
>>> arr_2d[0].append(0)
>>> arr_2d[0].append(1)
>>> arr_2d.append([3,4,5])
>>> arr_2d
[[0, 1], [3, 4, 5]]
>>>

It might benefit you to create a 2d array class to handle the many different aspects of working with a 2d array.

vegaseat commented: as dynamic as it gets, good example +11
educapps commented: Great logic! +0
jlm699 320 Veteran Poster
screen.blit(image, (10,10))

I think..

vegaseat commented: great help +11
jlm699 320 Veteran Poster

Two examples of appeding to tuples:

>>> my_tup = ()
>>> my_tup2 = ()
>>> for i in xrange( 5 ):
...     my_tup += ( 'Entry %d' % i, )
...     my_tup2 += tuple( str( i ) )
...     
>>> my_tup
('Entry 0', 'Entry 1', 'Entry 2', 'Entry 3', 'Entry 4')
>>> my_tup2
('0', '1', '2', '3', '4')
>>>
jlm699 320 Veteran Poster

If you're using a tuple to keep track of what the user has already tried then you'll need to concatenate in the following manner:

>>> a = ()
>>> a += 'a'
Traceback (most recent call last):
  File "<input>", line 1, in <module>
TypeError: can only concatenate tuple (not "str") to tuple
>>> a += ( 'a', )
>>> a
('a',)

Perhaps you'd be better off using a list so that you can do this:

>>> b = []
>>> b.append( 'a' )
>>> b
['a']
>>>

HTH

jlm699 320 Veteran Poster

Your loop starting on line 129 is only one line long (130)

AKA, infinite loop:

while 1:
        clock.tick(60)
jlm699 320 Veteran Poster

You're calling the function findprogram before defining it.... if you simply rearrange your code so that the def findprogram(program): block is first, you'll solve the problem. You'll then find that you forgot to import sys And then you'll find that you're trying to use some variable called program_path when instead you might have wanted fullpath

A good way to avoid this is to not ever let your code hang out in the ether like that... commonplace is to place your code all into functions, and have a main() function to call them... Here's a pretty commonly used method:

#!/usr/bin/python
import #whatever needs imported

def # Define some functions

def main():
    # Do anything that needs done here
    # Call functions, etc...

if __name__ == '__main__':
    main()
jlm699 320 Veteran Poster

I don't quite remember but I believe that treectrl structure can be loaded from a dictionary, right?

If that is correct then you can simply use pickle to store/load the dictionary.. which will save a few lines of code I guess...

jlm699 320 Veteran Poster

Your problem is that you've got prod_cost as both a function and a variable. So once your assigning a value to prod_cost, it removed the definition of prod_cost as a function.

jlm699 320 Veteran Poster

As far as conversions are concerned there are a number of functions:

int(x [,base]) converts x to an integer
long(x [,base]) converts x to a long integer
float(x) converts x to a floating-point number
complex(real [,imag]) creates a complex number
chr(x) converts an integer to a character
unichr(x) converts an integer to a Unicode character
ord(c) converts a character to its integer value
hex(x) converts an integer to a hexadecimal string
oct(x) converts an integer to an octal string

Make sure you take note that int() and long() can take numbers of a different base, provided that you specify which base you are converting from, ie:

>>> int(0xAF)
175
>>> int('101',2)
5
>>> int('0xaf3', 16)
2803
>>>
jlm699 320 Veteran Poster

pickling is more beneficial for custom classes. For a built-in class (dictionary, list, etc.) simply use eval (NOTE: this solution has been posted before on this forum, but I couldn't find it)

>>> d1 = {'a':2, 'b':3}
>>> d2 = eval(repr(d1))
>>> d2
{'a': 2, 'b': 3}
>>> d2['c']=1
>>> d1
{'a': 2, 'b': 3}
>>> d2
{'a': 2, 'c': 1, 'b': 3}

So for what you're looking for you'd write the repr() bit to a file, and then use eval after reading said file.

*I think the previous solution used execfile instead of bothering to open said file; however like I said I couldn't find it and don't remember exactly, but it answered exactly what you're asking.

Otherwise, use the forum search and look for "pickle" to find examples of dumping/loading pickled objects.

jlm699 320 Veteran Poster

I guess what you could do is set up a menu with the CTRL+<Letter> shortcuts binded and then just keep it hidden.

That way the bindings are taken care of but you don't have to see it...

jlm699 320 Veteran Poster

I ran the code unmodified and got this:

Nov 12 - /tor/cto/915709511.html FS: 2004 Honda Civic Si Low Km - $12500 -
Nov 12 - /tor/cto/915669421.html FS; 1993 HONDA CIVIC CX HATCHBACK (EG) - $850
-
Nov 12 - /tor/cto/915654012.html FS: 1997 HONDA CIVIC CX HATCHBACK - $1500 -
Nov 11 - /yrk/cto/915504337.html 95 civic ex coupe -
Nov 11 - /mss/cto/915500509.html 997 HONDA CIVIC -
Nov 11 - /tor/cto/915425141.html 2006 honda civic DX-g - $15000 -
Nov 11 - /yrk/cto/915372101.html 1999 HONDA CIVIC EX, 4 DOOR, AUTO, $4000 !! -
$4000 -
... (Continues for 142 lines)

How are you running the code? If you're just double clicking the .py file perhaps the console is closing before you're able to capture the output...

jlm699 320 Veteran Poster

Are you trying to make a text editor? In my opinion, a text editor would most definitely benefit from a menu system.

jlm699 320 Veteran Poster

I think the better way would just be to map CTRL+<character> to the items under an Edit menu.

ie,

File, Edit, Help
       |_Bold Ctrl+B
       |_Italic Ctrl+I
jlm699 320 Veteran Poster
for featureline in ffeaturefile.readlines():
        featureline = featureline.strip().split("|")
        addlist += "'%s', '%s'," % (featureline[0], featureline[3])
        resfeaturelist = dict(addlist)
for number, resline in enumerate(fresfile):
        resline = resline.strip().split("|")

        for count in [0, 21]:
                if (count == 21):
                       #change values to text in features.txt
                        resfields = resline[count].split(",")
                        for i, item in enumerate(resfields):
                                if (featureline[0] == item):
                                        print resfields[3]
                else:
                        fsqlfile.write ("Insert into openrealty_en_listingsdbelements (listingdbelements_field_name,listingdbelements_field_value,listingsdb_id,userdb_id) values ('" + resheader[count] + "','" + resline[count] + "','" + str(number) + "','0');\n")

Also, once I get the features.txt into a dictionary how do I do the substitution?

I'm not quite sure what you mean by substituion.. do you mean use the value instead of the key? Also, I'm wary of how you are creating your dictionary.

I propose the following modification to the first bit of code:

resfeaturelist = {}
for featureline in ffeaturefile.readlines():
        featureline = featureline.strip().split("|")
        addlist += "'%s', '%s'," % (featureline[0], featureline[3])
        resfeaturelist[ featureline[0] ] = featureline[3]

Now take a look at this example of working with a dictionary to see if it answers your question about "substitution":

>>> dd = {} # Initialize the dictionary
>>> dd[ '7801' ] = 'Heat Pump'
>>> dd[ '7902' ] = 'Central A/C'
>>> dd[ '8901' ] = 'Box Fan'
>>> print dd[ '7801' ]
Heat Pump
>>> "INSERT x into y VALUES( '%s', '%s', '0' );" % ( dd['7801'], dd['8901'] )
"INSERT x into y VALUES( 'Heat Pump', 'Box Fan', '0' );"
>>> dd.get( '7901' )
>>> dd.get( '7902' )
'Central A/C'
>>>

As you …

jlm699 320 Veteran Poster

To avoid this problem in the future you could do this:

def read_rebase(filename):
    enz_dict={}
    infh= open("rebase.dat")
    for line in infh.xreadlines():
        fields = line.split()
        if len(fields) > 2:
            name = line.split()[0]
            pat = line.split()[2]
            enz_dict[name] = get_site_only(pat)

    infh.close()
    return enz_dict

This way you make sure that the number of elements matches the indices that you're requesting.

jlm699 320 Veteran Poster

Yes, RichTextCtrl is usable, I believe vegaseat has an example or two in the wx sticky thread on this forum.

jlm699 320 Veteran Poster

join takes every element of an iterable container (must contain strings/chars) and "joins" them together using the first argument as the joining element.

Examples:

>>> a = '12345'
>>> '__'.join(a)
'1__2__3__4__5'
>>> b=('1','2','3','4','5')
>>> '|!|'.join(b)
'1|!|2|!|3|!|4|!|5'
>>> c = ['1','2','3','4','5']
>>> import string
>>> string.join( c, '(*)' )
'1(*)2(*)3(*)4(*)5'
>>> d = {1:'a', 2:'b', 3:'c'}
>>> ','.join(d.values())
'a,b,c'
>>>

As you can see, join(list [,sep]) is analgous to sep.join(list) . Here's the official description of the second way:

join(...)
S.join(sequence) -> string

Return a string which is the concatenation of the strings in the
sequence. The separator between elements is S.

jlm699 320 Veteran Poster
>>> answer =('7', 'Q', '5', 'H', '9', '4', '3', '8', 'L')
>>> ''.join(answer)
'7Q5H9438L'
>>>
jlm699 320 Veteran Poster

I'm not versed in Tk but I assume that it's event driven like wx is. That means that in order to have "whatever" appear in the box, you need to bind it to an event.

So anything after root.mainloop() isn't going to happen until you quit the mainloop (ie, close the window, hit CTRL+C, etc)

jlm699 320 Veteran Poster

Was this supposed to be a question or just you telling us what your next project is?

jlm699 320 Veteran Poster

If you wrap your code in code tags and explain to us your error we will gladly help.

Please put your code between tags like this:
[code=python] # Your code in here

[/code]

This way your code won't look like a garbled mess with no indentation.

Also, please explain to us what problems you're having and provide ample error information (traceback, etc.)

jlm699 320 Veteran Poster

I think you may need to use demo.a_listbox.insert(0,"whatever") , since demo is the instance of Testgui.

jlm699 320 Veteran Poster
>>> import random
>>> my_seq = ''.join([random.choice('AGTC') for x in range(10)])
>>> my_seq
'TATCCTTGTT'
>>> len(my_seq)
10
>>>

I'm not quite sure what you mean by "printing in FASTA format with the > "

jlm699 320 Veteran Poster
jlm699 320 Veteran Poster
import wx

dir(wx)

Will give you all the attributes, functions, etc. of wx. And if you use the re module or a custom search you can filter out everything that starts with ID_

There's also the documentation

I don't understand your second question...

jlm699 320 Veteran Poster

(I think (I) (Might) ((See) A Problem) (Here)

This is improper syntax, you're missing a closing parenthesis ;)

No but seriously, to the OP: the error you are getting is trying to tell you that the image file that you're trying to open doesn't exist. You need to check your current working directory during runtime and verify that the file is located within the same directory

import os

os.getcwd()

If it is not, you'll need to provide the entire path to the file name in order to use it. That or change your current working directory. And yes, it looks like perhaps having those parenthesis around your assignment might have something to do with it.

tyincali commented: Why didn't I catch this... +1
jlm699 320 Veteran Poster

Hi all,

How can I split a Progress Bar(wx guage) into two parts?. I want the first part to function normally and in the second part I want to display the percentage. I have attached a snap shot of what I am trying to achieve.
Is this possible?
Any help is much appreciated!

Regards,
Dinil

You wouldn't actually be splitting the progress bar, you would just simply have an object (like static text) next to the progress bar, which you would update with the percentage.

Use a horizontal sizer to contain these two elements, and then add that horizontal sizer to your main window's sizer as a child object.

jlm699 320 Veteran Poster

he was saying if you expect us to look at your code, put that before and after your code in your post. so that we can see syntax highlighting and what not.

Yes, this is for the forum members' sake. This way your code doesn't lose indentation and become unreadable to us. It also saves space, and turns on syntax highlighting.

jlm699 320 Veteran Poster

WConio

Is that kind of like the curses library for C?

jlm699 320 Veteran Poster

Sorry, I don't understand you. What are you trying to say about Python 2.5? It's what I use, even though Python 2.6 is out now (or the early releases for 3.0).

I believe his question was in regards to the OP.

He was asking why he is still using 2.4 instead of 2.5 or later. And then he asked if he stuck with 2.4 because of a "special function"... I think

jlm699 320 Veteran Poster

Yes, you would need to import turtle. Here's a good place to start: docs.

And an excerpt from that site:

Because [turtle] uses Tkinter for the underlying graphics, it needs a version of python installed with Tk support.

So make sure you've got a more recent version of python.

Finally, a typical for loop:

for x in [1,2,3,4,5]:
    print x

Instead of a hard list you could use range(1,6) or better yet xrange(1,6); however the above example gives you a better idea of what's happening. Try typing that into your favorite Python interpreter to see what happens.

jlm699 320 Veteran Poster

It helps when you tell us what "doesn't work". Do you get an error, does your computer light on fire, what?

jlm699 320 Veteran Poster

Wrap your code in code tags:
[code=python] # Code here

[/code]