jlm699 320 Veteran Poster

This was a change from python 2.X to 3.0 to provide better performance.

In Python 2.X versions, zip() returned a list:

>>> zip(['Blue', 'Bunny', 'Red'],['1','2','3'])
[('Blue', '1'), ('Bunny', '2'), ('Red', '3')]
>>>

However for the sake of saving time, in 3.0 they decided to change the behavior so that zip() returned an iterator instead. The same thing happened with range()... if you type range(5) into 3.0 you'll get an iterator; yet 2.X gives this:

>>> range(5)
[0, 1, 2, 3, 4]
>>>

Try it!
**Note: range() in Python 3.0 is actually xrange() from python 2.X**

jlm699 320 Veteran Poster

print only supports simple printing

What do you mean simple printing? I don't know of anything that stdout.write can do that print cannot...

jlm699 320 Veteran Poster

Perhaps this can help: button.set_sensitive(False) Documentation

jlm699 320 Veteran Poster

What version of Python are you using here? On 2.5.2 I get the following:

>>> my_lines = [
...     "======================================================",
... "Name Place Age",
... "======================================================",
... "John US 11",
... "Mary UK 12",
... "Mike US 14" ]
>>> for line in my_lines:
...     if len(line.split()) == 3:
...         sys.stdout.writelines("%s %10s %10s\n" % tuple(line.split()))
...     else:
...         sys.stdout.writelines("%s\n" % line)
...     
======================================================
Name      Place        Age
======================================================
John         US         11
Mary         UK         12
Mike         US         14
>>>

Why are you using stdout.writelines ? Do you specifically need it or can you make use of print ?

jlm699 320 Veteran Poster

Looks like sample code is buggy:

Product Description

Python 3 is the best version of the language yet: It is more powerful, convenient, consistent, and expressive than ever before. Now, leading Python programmer Mark Summerfield demonstrates how to write code that takes full advantage of Python 3’s features and idioms. The first book written from a completely “Python 3” viewpoint, Programming in Python 3 brings together all the knowledge you need to write any program, use any standard or third-party Python 3 library, and create new library modules of your own.

Source

jlm699 320 Veteran Poster

In order to use os.listdir you would also want to combine it with os.path.isdir since you'll receive a list of both file and directory names.

jlm699 320 Veteran Poster

@Lizapotter: To preserve indentation and get syntax highlighting (and also spare the forum-goer's eyes) please use code tags as such:

[code=python]
# Your code goes in here
[/code]
jlm699 320 Veteran Poster

Let me re-write your program to show you what you're actually doing. Maybe you'll understand the execution of Python code a little better in this form:

import random

def Dieroll():
 randomnumber = random.randrange(10)+1
 return randomnumber

def Healthmod():
 x = Dieroll()
 global health
 health = health - x

def main():
    # Here comes an infinite loop with no breaks
    while True:
        action = raw_input("Do you want to Attack or Defend? ")
        if action == "attack":
            # Two print statements
            print "You are attacking!"
            print "Your health is ", health
        elif action == "defend":
            # One print statement
            print "You are defending!"
        else:
            # One print statement
            print "Type 'attack' or 'defend'!"
        # End of loop... return to beginning...

    # Still only printing
    print "Your health is ", health

    # Checking health, but still not calling functions
    if health < 0:
        print "You're dead."

    raw_input ("Press a key to exit.")

# The above function declarations are simply declarations
# Up until this point, no code has been executed
if __name__ == '__main__':
    # The above makes sure that this script isn't simply
    #   being called by another script..
    # Now we'll start our main execution by calling the
    #   main() function:
    main()
jlm699 320 Veteran Poster

Yeah.. all you're doing is printing a bunch of things. You fail to call any health-affecting functions

jlm699 320 Veteran Poster
import random

def dieroll(): 
 user_input = int(raw_input("How many random numbers do you want?\n"))
 for each in xrange(user_input):
    randomnumber = random.randrange(20)+1
    print randomnumber

answer = 'y'
while answer == 'y':
    dieroll()
    answer=raw_input("Do you want to repeat this (y=yes, n = no)?")

print " okay bye!"
raw_input("\n\nPress the enter key to exit.")

Do you understand what I did?

jlm699 320 Veteran Poster

In Python 3.0 the built-in method zip() contains an iterable instead of a list (much like the new range() function)... meaning that after the first sorted() call, the internal pointer of the zip object is pointed at the END position of the object.

I don't think it's possible to "reset" the iterator without simply re-zipping the two lists....
HTH

jlm699 320 Veteran Poster

Since user_input is a number, it is not an iterable item (ie, list, dictionary, string, etc). In order to get an iterable number use range() or xrange(). In Python 2.X xrange is preferrable; however in Python 3.0 xrange will be the new range.

so you'll do:

for each in xrange(user_input):
## On Python 2.X installation
jlm699 320 Veteran Poster

Use a for loop, ie

usr_inp = User's Input
for each in usr_inp:
    generate_number
jlm699 320 Veteran Poster

You really should've tried google

But since this is such a simple request here:

>>> import random
>>> random.randint(0, 100)
20
>>>

There are many great functions within the random module... take a look at the documentation for examples of how to use them.

jlm699 320 Veteran Poster

You would want to initialize the counter to 0 before your while loop like my_count = 0 and then near the end of the loop contents you can add a my_count += 1 (which is equivalent to my_count = my_count + 1 )

eyewirejets commented: Soved it easily +1
jlm699 320 Veteran Poster

Maybe you need

self.gladefile = open( "hello.glade" )

instead of

self.gladefile="hello.glade"

?

jlm699 320 Veteran Poster

This would be a great beginner project for Python. The forum members are here to help you but not here to do your work for you. Help us help you by fleshing out your ideas.

jlm699 320 Veteran Poster

In the past I've used matplotlib for a real-time data logging utility. It already had a control that took no effort on my part to integrate into wxPython, and because it was very similar to matlab, it took minimal effort to manipulate the graph's data...

I suggest looking into it and if it suits your needs I can share some examples of integrating it into a wxApp

jlm699 320 Veteran Poster
class Grid(object):
    ...
    @property
    def height(self):
        return len(self.grid)
    @property
    def width(self):
        return len(self.grid[0])

Can you explain the @property portion a little bit? What does that do for us ?

jlm699 320 Veteran Poster

You can place that check at the end of your while loop only add a break to each case so that if either X or O wins, the while loop is ended.

jlm699 320 Veteran Poster

It should iterate as (x, y)

You just have your x and y mixed up:

>>> def printGrid(w,h):
...     for y in xrange(h):
...         for x in xrange(w):
...             print '%d,%d' % (x,y),
...         print
...     
>>> printGrid(w=7,h=6)
0,0 1,0 2,0 3,0 4,0 5,0 6,0
0,1 1,1 2,1 3,1 4,1 5,1 6,1
0,2 1,2 2,2 3,2 4,2 5,2 6,2
0,3 1,3 2,3 3,3 4,3 5,3 6,3
0,4 1,4 2,4 3,4 4,4 5,4 6,4
0,5 1,5 2,5 3,5 4,5 5,5 6,5
>>>
jlm699 320 Veteran Poster

I can see the teams name in the source code... But, unfortunatly, what I'm getting from the webiste isn't the source

Take note of the type of webpage you're getting your information from (.aspx)

The ASP.NET framework allows dynamic websites to be created (take note of the web address as you click around on the site... it doesn't change much, yet the content changes.

So until the page is rendered with your actions, the "source" will be the basic framework.

jlm699 320 Veteran Poster

Many editors have an option to set the tab key to use 4 or 8 spaces instead of the '\t' character. Also, there is usually a batch edit command such as "Replace leading tabs with spaces", or "Replace all tabs", etc. It's usually a good idea to check what the tab preferences are in any editor the first time you use it.

I use Notepad++ and always have the 'View' -> 'Show whitespace' option on. It adds a barely visible 'dot' in place of spaces and a ----> In space of tabs which helps to instantly identify which is being used. This is esecially helpful when using someone else's code (it's the first thing I noticed when I copy-pasted your code)

jlm699 320 Veteran Poster
self.buthello = wx.Button(self, wx.ID_ANY, label ='helo')
		self.buthello.Bind(wx.EVT_LEFT_DOWN, self.helloevent)

Q1. in the line 'wx.Frame.__init__', what is wx.ID_ANY, what is the purpose of it?.
Q5. This is another tutorial i was looking at and on this it has used '-1' instead of wx.ID_ANY. whys that?
Q2. Also self.buthello isnt defined anywhere? (confused here)

Q1 & Q5: id=wx.ID_ANY and id=-1 are both equivalent in saying "I don't really care what ID this object has"
Q2: self.buthello is defined above as a wx.Button

Q3. Also...

def helloevent(self, event):

how does 'event' work in here. Shouldnt it work without 'event'?

When a function is bound to an event (a key press or button click), the event parameter is required as it passes useful information such as which key was pressed, or what position the mouse was in at the time of event, etc.

In order to call one of these methods in your code (ie, without the event being triggered first) you'll have to define it as def helloevent(self, event=None): unless you want to have to pass it some garbage variable every time you call it.

Q4. How can ShowModal be used in other cases?

Not quite sure what you're asking here, but showModal() causes the window to come to the user's attention and require action before going away. This is particularly useful for dialog boxes, especially file select dialogs and message windows.

import wx

class Dockable(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title)

        menubar = wx.MenuBar(wx.MB_DOCKABLE)
        file = wx.Menu() …
jlm699 320 Veteran Poster
def printGrid(self):
        for y in range(self.height):
            for x in range(self.width):
                print self[x, y].value,
            print

	def printGrid2(self):
		for y in range(self.height):
			for x in range(self.width):
				print self[x, y].value,
			print

the printGrid2 method can't be found or something.

Indentation is very important in Python. Your printGrid2 method is defined within printGrid, so it isn't a member of the class Grid

This should fix it:

def printGrid(self):
        for y in range(self.height):
            for x in range(self.width):
                print self[x, y].value,
                print

    def printGrid2(self):
        for y in range(self.height):
            for x in range(self.width):
                print self[x, y].value,
                print

It appears that you're using a mix of tabs and spaces, which is a no-no. Save yourself the trouble and convert all your tabs to spaces (4)

jlm699 320 Veteran Poster

I'm not sure how to multiply the digits

Here's multiplication in Python

>>> 1 * 2 * 3 * 4
24
>>>

I suggest you peruse the Python documentation to learn yourself something. I suggest the First Steps Towards Programming section

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

why don't you just use allfile=file_in.read() ?

I typically like to use allfile = file_in.read_lines()

jlm699 320 Veteran Poster

Please only post Python questions in this forum

jlm699 320 Veteran Poster

why is this in the python forum?

Because he thinks we'll do his homework for him.

jlm699 320 Veteran Poster

Looks like somebody made a widget that will handle sub/superscripting... I suggest downloading their source code and figuring out how they do it... then possibly try to implement it for your own purposes.

jlm699 320 Veteran Poster

The extra two characters that you are adding (ie 32 -> 1200) are over writing the '\n' and the '<', which is why editing a file with seek is a terrible idea unless you're simply replacing character for character.

A better idea would be to load the file into memory, edit to your heart's content, and then re-write the file.

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

error: FileCookieJar has not attribue '_self_load'.

Oh here

jlm699 320 Veteran Poster

I think I read something in Guido's Python regrets that he wished he would've enforced that only spaces be used and not allow tabs whatsoever. It's been a while so perhaps I just made that up.

jlm699 320 Veteran Poster
jlm699 320 Veteran Poster

Did you remember to get new versions of your modules when you upgraded ?

jlm699 320 Veteran Poster

Is that chat speak or did he get disemvoweled ?

Ezzaral commented: :) +16
jlm699 320 Veteran Poster

How about you show us what you've tried and we'll help you. That's how it's supposed to work, we're not here to do your homework.

And when you're posting code please use code tags:
[code=python] # Code in here

[/code]
When you do that you can make code that looks like this:

import os
#
if os.path.exists('/home/user/friends'):
    print 'Nice!  Friends!!'

See how nice that looks?

vegaseat commented: thanks for the code tag info +11
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

Here's some examples of string formatting:

>>> my_car = 'Ford'
>>> my_friend = 'Bob'
>>> print 'Hai.  I drive a %s with my friend %s' % (my_car, my_friend)
Hai.  I drive a Ford with my friend Bob
>>> print 'Wait, I too drive a', my_car, 'with my friend', my_friend
Wait, I too drive a Ford with my friend Bob
>>> msg = 'What?!  No wai we both drive %s cars and have friends named %s?!'
>>> print msg
What?!  No wai we both drive %s cars and have friends named %s?!
>>> print msg % (my_car, my_friend)
What?!  No wai we both drive Ford cars and have friends named Bob?!
>>>

Hope that provides a tiny bit of insight into improving your class assignment

Oh, and you'll need to make use of the random module to randomize your selections

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

Try out this guy

jlm699 320 Veteran Poster

One question I have about these new fantastic software is which will survive.

Are you speaking of Python or wxPython ?

In either case, neither will be going away any time soon. Python gets more and more popular every year and wxPython seems to be the de facto toolset for developing native GUIs under Python.

When big companies (ie, IBM, NASA) start using a language that pretty much ensures that it will be sticking around for a while.

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

Look into wxPython, as there are multiple options for creating a tabbed interface:
Tabbed Notebook
Aui MDI
etc...

Go for the docs and demos package to get lots of examples of building tabbed interfaces