Search Results

Showing results 1 to 40 of 133
Search took 0.01 seconds.
Search: Posts Made By: mawe
Forum: Python Dec 29th, 2007
Replies: 4
Views: 1,035
Posted By mawe
I once wrote one :icon_wink: It's part of one of the greatest periodic table programs of the world *cough*. You can find it here (http://freshmeat.net/projects/pyperiod/).

Then there is pyparsing...
Forum: Python Dec 4th, 2007
Replies: 5
Views: 1,224
Posted By mawe
currentFunds = CurrentFunds()
currentFunds.getValue()

while currentFunds.getValue() > 0:
rouletteTable.bind("<Button-1>", click)
...
Forum: Python Dec 4th, 2007
Replies: 5
Views: 1,224
Posted By mawe
700 loc for a simple roulette game? I guess you could shorten it a bit :icon_wink:
if spin == 3 or spin == 4 or spin == 5 or spin == 6 or spin == 7 or spin == 8 \
or spin == 9 or spin == 10 or...
Forum: Python Nov 26th, 2007
Replies: 7
Views: 7,989
Posted By mawe
Forum: Python Nov 26th, 2007
Replies: 7
Views: 7,989
Posted By mawe
a = [4,5,6]
s = set(a)
Now s is a set :)
For further info have a look at the documentation (http://docs.python.org/lib/types-set.html).
Forum: Python Jun 10th, 2007
Replies: 7
Solved: Where's Nemo?
Views: 1,473
Posted By mawe
>>> import sys
>>>
Hmm, it seems to work. What did you expect to happen? :)
Forum: Python Jun 8th, 2007
Replies: 2
Views: 2,212
Posted By mawe
writer = csv.writer(open(("beta_%i.%i.%i.csv" % (now.day, now.month, now.year)), "ab")
Forum: Python May 29th, 2007
Replies: 3
Views: 2,235
Posted By mawe
Hi!

print "\\".join((str1, str2))
or
print "%s\\%s" % (str1, str2)
If you want to make this os-independent, have a look at the os module (os.path.join might be your friend :))

Regards, mawe
Forum: Python May 29th, 2007
Replies: 10
Views: 2,705
Posted By mawe
Let's see how you e.g. call an Entry with these (from Tkinter alone won't work, I guess you mean import Tkinter):

1. from Tkinter import * -> entry = Entry()
2. import Tkinter as tk -> entry =...
Forum: Python May 18th, 2007
Replies: 1
Views: 29,825
Posted By mawe
str() is your friend.
FILE.writelines( str(b) )
Forum: Python May 7th, 2007
Replies: 7
Views: 1,247
Posted By mawe
def increase(num, b2, x):
if num%(b2**x) < num:
return increase(num, b2, x+1)
print x
return x
Forum: Python May 3rd, 2007
Replies: 3
Views: 1,158
Posted By mawe
You don't need a begin in Python,:
(if (condition)
(begin
(do-something-1)
(do-something-2))
do-something-else)
if condition:
do_something_1
do_something_2
else:
Forum: Perl May 2nd, 2007
Replies: 12
Views: 2,969
Posted By mawe
We can help you better if you show us the code you use.
Forum: Python Apr 29th, 2007
Replies: 6
Views: 1,498
Posted By mawe
place seems to be a nice and easy way for positioning, but it's not often used. e.g. think of what happens if you want to make some little changes to the GUI. You have to change all coordinates of...
Forum: Python Apr 28th, 2007
Replies: 3
Views: 2,673
Posted By mawe
A little hint:
for i in range(1, 5):
print i
Forum: Perl Apr 27th, 2007
Replies: 12
Views: 2,969
Posted By mawe
Hi,

here's one way (not very clever, but it works):
@numbers = (12, 12, 23, 123, 3, 234, 22333, 223, 3);

foreach $number (@numbers) {
# fill all numbers with whitespace to a length of 5
...
Forum: Python Apr 25th, 2007
Replies: 3
Views: 1,939
Posted By mawe
Sorry, forgot to mention it: there should be not space after the "[" in [code]
Forum: Python Apr 23rd, 2007
Replies: 3
Views: 1,939
Posted By mawe
Hi,

please put your code in [ code=Python]...[/code], otherwise the indentation is lost :icon_wink:
if number != 4 and number != 5 and number != 6 and number != 8 and number != 9 and number !=...
Forum: Python Apr 21st, 2007
Replies: 9
Solved: S.o.s. Gui
Views: 1,483
Posted By mawe
Very good posts, jrcagle! I see that yours are much more useful than mine, and, much more polite :) I think I have to say sorry to fredzik.

PS: I _hate_ the new smilies!!! :@
Forum: Python Apr 20th, 2007
Replies: 9
Solved: S.o.s. Gui
Views: 1,483
Posted By mawe
I don't really understand what you want. You want to run this "game" from Idle _and_ have a Tk-GUI? What should be displayed in the GUI. And why run it from Idle? BTW, do you mean the editor "idle"?...
Forum: Python Apr 10th, 2007
Replies: 8
Views: 2,078
Posted By mawe
You enter a number (say 10), press Enter and the update() function does the following:
- it sets amount to 0
- reads the number from the Entry (10), adds it to amount (10), sets the label...
Forum: Python Apr 10th, 2007
Replies: 2
Views: 1,018
Posted By mawe
There is a widget called Text, which I think is what you want. An Entry is always one line high (per definition ;))
Forum: Python Apr 9th, 2007
Replies: 5
Views: 7,303
Posted By mawe
You are right, that's another way. It may be a matter of taste, but ... I don't like it :) I would rather do something like this:
In [1]: def valid( elem ): # very complicated function
...: ...
Forum: Python Apr 6th, 2007
Replies: 7
Views: 3,719
Posted By mawe
from random import randint

def roll( num ):
# this counts the "5 of a kind"
hit = 0
# we try this num times
for i in range(num):
# roll the dices
dices = [...
Forum: Python Apr 5th, 2007
Replies: 7
Views: 3,719
Posted By mawe
liz517, could you please explain what your code should do.
Forum: Python Apr 1st, 2007
Replies: 5
Views: 7,303
Posted By mawe
Hi,

your "error" is a very common source of confusion :)
Let's take a slightly simpler example:
In [1]: lst = ["a", "b", "b", "d"]

In [2]: for elem in lst:
....: print "before: ", lst ...
Forum: Python Mar 31st, 2007
Replies: 6
Views: 3,773
Posted By mawe
Hi!

The first one without any if-elif:
def search(l, key):
return key in l
For the second one, .index() is your friend ;)
def search(l, key):
if key in l: return l.index(key)
...
Forum: Python Mar 26th, 2007
Replies: 1
Views: 1,483
Posted By mawe
Is this from diveintopython? If so, then the first snippet on this page (http://www.diveintopython.org/power_of_introspection/index.html) is what you need ;)
Forum: Python Mar 26th, 2007
Replies: 2
Views: 13,395
Posted By mawe
This should do what you want:
print "%x" % 255
Forum: Python Mar 11th, 2007
Replies: 8
Views: 3,948
Posted By mawe
If my posts sound somewhat rude, I'm sorry for that. It's not meant this way.
Your questions are absolutely not stupid, and before you ask you try to find a solution by yourself. That's more than...
Forum: Python Mar 11th, 2007
Replies: 8
Views: 3,948
Posted By mawe
And you really don't know why?
words = string.split(s)
Ok, from your other post you know that words is a list. Fine.
ch = string.split(words)
What are you doing here? You want to split a list?...
Forum: Python Mar 11th, 2007
Replies: 5
Views: 3,572
Posted By mawe
Hi!

Well, you did it ... nearly :)
words = string.split(p)
Ok, words is now a list, and it's elements are the words in the sentence. You want to know how many words there are in the sentence ......
Forum: Python Mar 8th, 2007
Replies: 3
Views: 4,419
Posted By mawe
That's right. You read the data always as a string, so you have to convert it by hand to whatever you need.
Forum: Python Mar 8th, 2007
Replies: 3
Views: 4,419
Posted By mawe
Hi!

Python usually produces very useful error-messages, like here

Ok, you know what to do, right? Just convert your number to a string ;)
a = 123.44
f = open("data1.dat", "w")
f.write(...
Forum: Python Mar 8th, 2007
Replies: 6
Views: 6,867
Posted By mawe
...
for char in message:
# check if the character is alphabetic
if char.isalpha():
...

Regards, mawe
Forum: Python Feb 28th, 2007
Replies: 0
Code Snippet: flatten nested lists
Views: 5,246
Posted By mawe
The name says it all, I think. You have a nested list, you want to flatten it (e.g. because you want to count the occurence of an element), this function is all you need ;)
Forum: Python Feb 28th, 2007
Replies: 4
Views: 1,710
Posted By mawe
As scru says, this is not an easy task if you have such a nested structure ;)

I once wrote a function which "flattens" these monsters :)
def flatten(lst):
for elem in lst:
if...
Forum: Python Feb 28th, 2007
Replies: 3
Views: 1,286
Posted By mawe
Congratulations for finding the solution by yourself!
def main():
import string
This is bad style. Imports should be the first lines in your script.
BTW, you don't need the string-module...
Forum: Python Feb 26th, 2007
Replies: 2
Views: 1,023
Posted By mawe
Hi!

This question is not dumb, in fact it's probably the most frequently asked one on the net :)
Maybe these lines will help you (btw, id() returns the memory address of an object):
>>> a =...
Forum: Python Feb 21st, 2007
Replies: 6
Views: 9,931
Posted By mawe
You are absolutely right, a search should always start in our snippets section :) But, searching for prime python via Google, I found a link to a snippet here (on the second page). You see, Google is...
Showing results 1 to 40 of 133

 


About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC