jephthah commented: Big deal. there are entire ______ managment systems written entirely in _______ and sold for big bucks. +0
Gribouillis commented: Useful test. Thanks also for linux users :) +2
Could you mark this as solved?
"Invent Your Own Computer Games with Python" is a free e-Book that teaches you how to program in the Python programming language. Each chapter gives you the complete source code for a new game, and then teaches the programming concepts from the example. Many examples are written with the GUI toolkit module pygame, see:
http://inventwithpython.com/
Editor's note:
Thanks snee, this chapter in the e-Book has a very nice introduction to pygame programming ...
http://inventwithpython.com/chapter16.html
It works.
Could you mark this solved?
Looks like you need to study up on dictionaries first!
dictionary[key] --> value
You got me wrong, its not about the decoding, its about sending a form.
it seems that the doesn't send the "user" and "pass".
my question is how do I fix this problem?I found the solution, I had to send it to "http://yoni-examples.freehostia.com/scam/form.php"
How could it have worked with the wrong encoding?
Could you please mark this thread as solved.
You are close:
import string
def punc(s):
txt = open(s, 'r').read()
print(txt) # for test only
for punct in string.punctuation:
if punct in txt:
# update txt
txt = txt.replace(punct, "")
return txt
# test your potential function.py module
if __name__ == '__main__':
# pick a text file you have in the working folder
fname = "name.txt"
new_text = punc(fname)
# show the result return from the function punc()
print(new_text)
"""my test display -->
Frank, Miller: III
Dr. August Jarr
Mrs. Lola Meyer-Lipstick
Frank Miller III
Dr August Jarr
Mrs Lola MeyerLipstick
"""
The devil's boots don't creak.
I am hoping for a robotic laser beam lawn mower. :)
I buy my groceries at Wal-Mart and avoid any food item made in China.
As long as I can still download a chicken breast recipe. If it's done by the government it is bound to be stupid!
Grilled chicken breast with broccoli and garlic mashed potatoes.
The module numpy is your friend here:
# create matrix with arange().reshape()
# perform add and multiply matrix operations
# module numpy (numeric python extensions, high speed)
# free from: http://sourceforge.net/projects/numpy
import numpy as np
# create 2 matrices using
# arange([start,] stop[, step,], dtype=None) and
# reshape((row, col)) use (row, col) tuple
# list created by arange() has to fit 3x3 matrix
mx1 = np.arange(11, 20).reshape((3, 3))
mx2 = np.arange(31, 40).reshape((3, 3))
# add the 2 matrices
mx3 = np.add(mx1, mx2)
# multiply the 2 matrices
mx4 = np.multiply(mx1, mx2)
# show the result
print('mx1 =')
print(mx1)
print('-'*15)
print('mx2 =')
print(mx2)
print('-'*15)
print('mx1 + mx2 =')
print(mx3)
print('-'*15)
print('mx1 * mx2 =')
print(mx4)
"""my result -->
mx1 =
[[11 12 13]
[14 15 16]
[17 18 19]]
---------------
mx2 =
[[31 32 33]
[34 35 36]
[37 38 39]]
---------------
mx1 + mx2 =
[[42 44 46]
[48 50 52]
[54 56 58]]
---------------
mx1 * mx2 =
[[341 384 429]
[476 525 576]
[629 684 741]]
"""
It looks like badboy00z is correct. The last result is really a permutation with a sample size of 2.
I think badboy00z is correct. You can use module itertools to show it:
# combinations and permutations using Python3 itertools
import itertools
iterable = [1, 2, 3]
# sample_size < len(iterable)
sample_size = 2
combi_list = list(itertools.combinations(iterable, sample_size))
print(combi_list)
print( '-'*50 )
sample_size = 2
combi_list2 = \
list(itertools.combinations_with_replacement(iterable, sample_size))
print(combi_list2)
print( '-'*50 )
perm_list = list(itertools.permutations(iterable))
print(perm_list)
print( '-'*50 )
perm_list2 = list(itertools.permutations(iterable, 2))
print(perm_list2)
""" my result -->
[(1, 2), (1, 3), (2, 3)]
--------------------------------------------------
[(1, 1), (1, 2), (1, 3), (2, 2), (2, 3), (3, 3)]
--------------------------------------------------
[(1, 2, 3), (1, 3, 2), (2, 1, 3), (2, 3, 1), (3, 1, 2), (3, 2, 1)]
--------------------------------------------------
[(1, 2), (1, 3), (2, 1), (2, 3), (3, 1), (3, 2)]
"""
I modified the code in the previous post to join two images into one:
# use a drawing bitmap and wx.MemoryDC to create a canvas you can
# draw on and optionally save the drawing to an image file
# here we draw two images side by side and save the combined image
# vegaseat code modified by sneek
import wx
class MyFrame(wx.Frame):
def __init__(self, parent, title, mysize):
wx.Frame.__init__(self, parent, -1, title, size=mysize)
# create a bitmp for display and optional saving
self.show_bmp = wx.StaticBitmap(self)
# get the width and height for the blank bitmap
w, h = self.GetClientSize()
# create a blank bitmap as a drawing background
# should be large enough to fit the 2 images side by side
draw_bmp = wx.EmptyBitmap(w, h)
# put a canvas on top of draw_bmp
canvas = wx.MemoryDC(draw_bmp)
# fill the canvas white
canvas.SetBrush(wx.Brush('white'))
canvas.Clear()
# pick 2 image files you have in the working folder
# (can be a .jpg, .png, .gif, .bmp image files)
# note that filenames are case sensitive in Linux
image1 = wx.Bitmap("Duck_right.jpg")
image2 = wx.Bitmap("Duck_left.jpg")
# draw the 2 images side by side
canvas.DrawBitmap(image1, 0, 0)
canvas.DrawBitmap(image2, w/2, 0)
# this also shows your drawing
self.show_bmp.SetBitmap(draw_bmp)
# get the image object
myimage = self.show_bmp.GetBitmap()
# save it to a file
myimage.SaveFile("joined_pic1.jpg", wx.BITMAP_TYPE_JPEG)
app = wx.App(0)
# make width w large enough to have the 2 images next to each other
w = 610
# make height h large enough to fit the max height of …
I modified the code in the previous post to join two images into one:
# use a drawing bitmap and wx.MemoryDC to create a canvas you can
# draw on and optionally save the drawing to an image file
# here we draw two images side by side and save the combined image
# vegaseat code modified by sneek
import wx
class MyFrame(wx.Frame):
def __init__(self, parent, title, mysize):
wx.Frame.__init__(self, parent, -1, title, size=mysize)
# create a bitmp for display and optional saving
self.show_bmp = wx.StaticBitmap(self)
# get the width and height for the blank bitmap
w, h = self.GetClientSize()
# create a blank bitmap as a drawing background
# should be large enough to fit the 2 images side by side
draw_bmp = wx.EmptyBitmap(w, h)
# put a canvas on top of draw_bmp
canvas = wx.MemoryDC(draw_bmp)
# fill the canvas white
canvas.SetBrush(wx.Brush('white'))
canvas.Clear()
# pick 2 image files you have in the working folder
# (can be a .jpg, .png, .gif, .bmp image files)
# note that filenames are case sensitive in Linux
image1 = wx.Bitmap("Duck_right.jpg")
image2 = wx.Bitmap("Duck_left.jpg")
# draw the 2 images side by side
canvas.DrawBitmap(image1, 0, 0)
canvas.DrawBitmap(image2, w/2, 0)
# this also shows your drawing
self.show_bmp.SetBitmap(draw_bmp)
# get the image object
myimage = self.show_bmp.GetBitmap()
# save it to a file
myimage.SaveFile("joined_pic1.jpg", wx.BITMAP_TYPE_JPEG)
app = wx.App(0)
# make width w large enough to have the 2 images next to each other
w = 610
# make height h large enough to fit the max height of …
Call for update() as shown below:
from tkinter import *
class fb( Frame ):
def fastbuttons( self ):
b = Button(self)
b.grid()
self.update()
print( b.winfo_ismapped() )
def __init__( self, master=None ):
Frame.__init__( self, master )
self.grid( sticky='nsew' )
self.button = Button( self, text='Start', command=self.fastbuttons )
self.button.grid()
if __name__ == '__main__':
root = Tk()
app = fb( master=root )
app.mainloop()
The module threading is the higher level module and actually uses module thread, since that one has the lower level tasks. So one can assume that threading is somewhat slower in speed, but nicer in syntax.
Python3 adds another module called multiprocessing that can take advantage of multiple processsor machines.
December 4th is International Root Beer Day.
Fried lake perch and German potato salad. Finishing off a bottle AW root beer.
Q. "How did the programmer die in the shower?"
A. " The programmer read the shampoo bottle instructions: Lather. Rinse. Repeat."
A man walks into a bar and asks the bartender, "If I show you a really good trick, will you give me a free drink?" The bartender considers it, and then agrees. The man reaches into his pocket and pulls out a tiny rat. He reaches into his other pocket and pulls out a tiny piano. The rat stretches, cracks his knuckles, and proceeds to play the blues.
After the man finished his drink, he asked the bartender, "If I show you an even better trick, will you give me free drinks for the rest of the evening?" The bartender agrees, thinking that no trick could possibly be better than the first. The man reaches into his pocket and pulls out a tiny rat. He reaches into his other pocket and pulls out a tiny piano. The rat stretches, cracks his knuckles, and proceeds to play the blues again. The man reaches into another pocket and pulls out a small bullfrog, that begins to sing along with the rat's music.
While the man is enjoying his free drinks, a stranger confronts him and offers him $100,000 for the bullfrog. "Sorry," the man replies, "he's not for sale." The stranger increases the offer to $200,000 cash up front. "No," he insists, "he's not for sale." The stranger again increases the offer, this time to $500,000 cash, tax free too. The man finally agrees, and turns the frog over to the stranger in exchange for the money.
"Are you …
If there is no space in the rank or name you can do it this simple way:
mydata = """\
<Ranking: AA (John)>
<Ranking: CA (Peter)>
<Ranking: TA-A (Samantha)>
"""
rank_list = []
for line in mydata.split('\n'):
print line, line.split() # testing
if line:
rank_list.append(line.split()[1])
print
print rank_list
"""my result -->
<Ranking: AA (John)> ['<Ranking:', 'AA', '(John)>']
<Ranking: CA (Peter)> ['<Ranking:', 'CA', '(Peter)>']
<Ranking: TA-A (Samantha)> ['<Ranking:', 'TA-A', '(Samantha)>']
[]
['AA', 'CA', 'TA-A']
"""
Here would be one way to accomplish this:
mylist = [
['A', 60],
['B', 40],
['C', 90],
['B', 150],
['C', 230],
['A', 220]
]
# convert to dictionary, put collision values into a list
mydict = {}
for sub in mylist:
print sub # testing
mydict.setdefault(sub[0], []).append(sub[1])
print
print mydict
print
# convert dictionary to list of lists
newlist = []
for k, v in mydict.items():
print k, v, sum(v) # testing
newlist.append([k, sum(v)])
print
print newlist
"""my result -->
['A', 60]
['B', 40]
['C', 90]
['B', 150]
['C', 230]
['A', 220]
{'A': [60, 220], 'C': [90, 230], 'B': [40, 150]}
A [60, 220] 280
C [90, 230] 320
B [40, 150] 190
[['A', 280], ['C', 320], ['B', 190]]
"""
You can also calculate pi with this simple mathematical formula:
4*.atan(1) :)
Lake Superior whitefish and eggplant with rice.
Scrambled eggs with mushrooms and low fat hot milk.
Yep, I've been forced to do VB in college, I really don't like it.
One of my favourite languages is Flash Actionscript 2.0, its syntax is very similar to C++/Java, and it's extremely flexible and easy to use.
There are entire hospital management systems written in vb, and sold for big bucks.
When you use
os.system('cls')
you limit yourself to the Windows OS.
In 99.9% percent of console apps you really don't need to clear the console screen.
Well, in Python just about anything is an object not just the typical OOP stuff. I assume that your instructor forgot about that and actualy means creating a class Student where each instance is a particular student.
snippsat.. Everybody is here with a question to be answered.. Google gives result for everything.. Then why people are answering and wasting their time??? Just can give the link to www.google.com..
I think you might not(matured) know the concept of a forum even though you are a member:S.. It is created for like minded people to share their ideas of what they know.. You know there is always a difference between what machine(google) gives and a man can give to you out of their experience(Every human Knows. But you????).
I asked for some materials to refer on PyQt.. I've already googled around and got some materials(i've mentioned that too in my post. open your eyes and see that or put on specs). I've asked here coz. good people like vegaseat,griboulis etc., have got first hand experience in GUI programming and they might give some ideas,suggestions,useful links and in what way i've to proceed(from so and so book to so and so book) as a beginner to become a good programmer(out of their handful of experience)..
If u can't answer for the question please just stop discouraging others who ask questions(especially beginners). I posted this question expecting reply from guys who got positive attitude of assisting and motivating a beginner rather than getting reply from people like you...Maybe because this is a jobb for goolge
By the by nobody knows any search engine in the name goolge:D..
Let's be somewhat pleasant about this. If you search …
If you search DaniWeb, you will find a whole lot of similar requests about queues, stacks and html tag names. Looks like this homework has been given in the last few weeks to a bunch of folks. The Python manual describes the use of queues in detail. Your problem will be to find start and end tags in the html code and shove them onto the stack or queue.
Sorry, I am using Python 3.1.1 and graphics.py does not work with Python3.
This little module has been updated to work with Python2 and Python3 recently, look at the new beta version at:
http://mcsp.wartburg.edu/zelle/python/
This should give you an idea how to split the window into three parts. One could add to the left side score, the other to the right side score, and the third is for a click to exit.
#
from graphics import *
def main():
win = GraphWin("My Score", 120, 100)
rect_left = Rectangle(Point(0, 0), Point(50,100))
rect_left.setFill('red')
rect_left.draw(win)
rect_right = Rectangle(Point(50, 0), Point(100,100))
rect_right.setFill('green')
rect_right.draw(win)
while True:
# get the x position of the mouse click
click_posx = win.getMouse().getX()
print( click_posx ) # test
if click_posx < 51:
print ( "left rect has been clicked")
elif click_posx < 101:
print ( "right rect has been clicked")
else:
break
win.close()
main()
The title is somewhat misleading. You want to add 2.
Yeah, I have heard enough of my fellow students brag about the amount of disk space on their brand new notebooks. I have never bought anything but a used notebook computer, so I have to be happy with disk space they gave you a few years ago. Actually more than plenty!
Everybody has been young before, but not everybody has been old before.
~~~ An African Proverb
Oh my God! This is just too funny! Nice find AD!
A DiGiorno pizza and a Leinenkugel beer. The best combination to watch the Northwestern Wildcats football game on a Saturday.
Okay, this might even be mildly better:
import string
a = list(string.ascii_lowercase + "!@#$%^&*()-+={}|\/?><,.'") + range(1, 10)
print a
For Python3 change to list(range(1, 10)). Oh, the joys of Python! :)
What do you mean with "WxGlade does not show value"?
Is it WxGlade or your program you wrote using WxGlade?
Just a note on the smart side of things. If you have a problem for others to look at and possible solve, it behooves you to supply as much needed information as you can. Otherwise buzz off and don't waste everyone's time.
Just testing wxPython's wx.TextCtrl widget used as an edit field for input and output of text based data:
# testing wxPython's
# wx.TextCtrl(parent, id, value, pos, size, style)
# a widget used for text data input or output
# note:
# style=wx.TE_PROCESS_ENTER is needed for Linux to
# respond to the enter key event!!!
# snee
import wx
class MyFrame(wx.Frame):
def __init__(self, parent, mytitle, mysize):
wx.Frame.__init__(self, parent, wx.ID_ANY, mytitle, size=mysize)
self.SetBackgroundColour("yellow")
s = "Enter name below:"
edit_label = wx.StaticText(self, wx.ID_ANY, s)
# create a single line edit input area
self.edit = wx.TextCtrl(self, wx.ID_ANY, value="",
style=wx.TE_PROCESS_ENTER)
# put the cursor in edit
self.edit.SetFocus()
# respond to enter key when focus is on edit
self.edit.Bind(wx.EVT_TEXT_ENTER, self.onEnter)
# create a scrolled multiline text output area
self.text_out = wx.TextCtrl(self, wx.ID_ANY, value="",
style=wx.TE_MULTILINE|wx.HSCROLL|wx.TE_READONLY)
# use a box sizer for vertical widget layout
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(edit_label, 0, wx.LEFT|wx.TOP|wx.EXPAND, border=10)
sizer.Add(self.edit, 0, wx.ALL|wx.EXPAND, border=10)
sizer.Add(self.text_out, 2, wx.ALL|wx.EXPAND, border=10)
self.SetSizer(sizer)
def onEnter(self, event):
"""the Enter key has been pressed, do something"""
# GetValue() gives a string
name = self.edit.GetValue()
s = "You entered the name: " + name + '\n'
# text output, either method works
#self.text_out.AppendText(s)
self.text_out.WriteText(s)
# clear edit input space
self.edit.Clear()
app = wx.App(0)
# create a MyFrame instance and show the frame
MyFrame(None, 'testing wx.TextCtrl()', (300, 480)).Show()
app.MainLoop()
Notice the special requirement for Linux users.
Also the OP didn't want a zero in the digits part. :)
It's always good to use a few test prints:
import operator
OPERATORS = {
'+': operator.add,
'-': operator.sub,
'*': operator.mul,
'/': operator.div,
}
class Stack(object):
"Creates a stack to enter numbers or operators into"
def __init__(self):
self.storage = [0,0,0,0]
self.sptn = -1
def push(self, item):
self.sptn = self.sptn + 1
self.storage[self.sptn] = item
def pop(self):
self.sptn = self.sptn -1
def top(self):
return self.storage[self.sptn]
def __rep__(self):
return self.storage[:self.sptn + 1]
def get_input():
equation = raw_input("Enter the equation in reverse polish notation: ")
return equation
def evaluate_rpn(equation):
s = Stack()
try:
for item in equation.split():
try:
result = float(item)
s.push(result)
except ValueError:
x = s.pop()
y = s.pop()
print x, y # test --> None None problem is here!!!
result = OPERATORS[item](x, y)
s.push(result)
result = s.top()
print result # test
return result
except IndexError:
print "Please input at least two numbers before entering an operator."
def main():
# use for testing
equation = '2 3 +'
#equation = get_input()
answer = evaluate_rpn(equation)
print answer
main()
The problem is in your class Stack. If you use a Python Queue as a stack it works fine:
import operator
import Queue
OPERATORS = {
'+': operator.add,
'-': operator.sub,
'*': operator.mul,
'/': operator.div,
}
def get_input():
equation = raw_input("Enter the equation in reverse polish notation: ")
return equation
def evaluate_rpn(equation):
# use a Python queue for a stack
s = Queue.Queue(-1)
try:
for item in equation.split():
try:
result = float(item)
s.put(result)
except ValueError:
x = s.get()
y = s.get()
#print x, y # …