Posts
 
Reputation
Joined
Last Seen
Ranked #3K
Strength to Increase Rep
+0
Strength to Decrease Rep
-0
91% Quality Score
Upvotes Received
10
Posts with Upvotes
10
Upvoting Members
7
Downvotes Received
1
Posts with Downvotes
1
Downvoting Members
1
2 Commented Posts
3 Endorsements
Ranked #487
Ranked #261
~166.26K People Reached

102 Posted Topics

Member Avatar for pyguy25

[code=Python]... for char in message: # check if the character is alphabetic if char.isalpha(): ...[/code] Regards, mawe

Member Avatar for FaZeSkwlSh00ter
0
7K
Member Avatar for sneekula

Hi sneekula, sorry, I totally forgot to answer in the last thread :confused: Ok, your second question is an easy one ;) [php]import Tkinter as tk import tkMessageBox def ask_quit(): if tkMessageBox.askokcancel("Quit", "You want to quit now? *sniff*"): root.destroy() root = tk.Tk() root.protocol("WM_DELETE_WINDOW", ask_quit) root.mainloop()[/php] Ok, now the quit - …

Member Avatar for entropicII
0
45K
Member Avatar for Lardmeister
Member Avatar for bumsfeld
0
6K
Member Avatar for R.S.Chourasia

[code=Python]a = [4,5,6] s = set(a)[/code] Now s is a set :) For further info have a look at the [url=http://docs.python.org/lib/types-set.html]documentation[/url].

Member Avatar for TrustyTony
0
6K
Member Avatar for sneekula

sneekula, I don't want to sound rude, but your one-sentence-question-posts are annoying. Why don't you try to find the answer alone first? If you're stuck, post what you have tried and we will try to help you. BTW: The internet is full of isprime functions in any language you can …

Member Avatar for wallars
0
1K
Member Avatar for NetByte

Hi! You have to install idle first (via apt-get or synaptic) ;) The dependency package is called [i]idle[/i], the current one [i]idle-python2.4[/i]. Regards, mawe

Member Avatar for snippsat
-1
1K
Member Avatar for pyguy25

Hi! Well, you did it ... nearly :) [code]words = string.split(p)[/code] Ok, [i]words[/i] 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 ... so ... how do you get the number of elements in …

Member Avatar for j6m8
0
278
Member Avatar for cmpt

Hi! The first one without any if-elif: [code=Python]def search(l, key): return key in l[/code] For the second one, [b].index()[/b] is your friend ;) [code=Python]def search(l, key): if key in l: return l.index(key) return False[/code] EDIT: Oh sorry, I didn't see it had to be recursive. [code=Python]def search(l, key, index=0): if …

Member Avatar for ptirthgirikar
-1
165
Member Avatar for sneekula
Member Avatar for Stefano Mtangoo
0
566
Member Avatar for katharnakh

Hi! [quote="Python Doku"]__call__( self[, args...]) Called when the instance is ``called'' as a function; if this method is defined, x(arg1, arg2, ...) is a shorthand for x.__call__(arg1, arg2, ...). [/quote] So ... [code]In [35]: class A: ....: def __init__(self): ....: print "init" ....: def __call__(self): ....: print "call" ....: In …

Member Avatar for snippsat
0
17K
Member Avatar for Dark_Omen

Hi! [quote="Dark_Omen"] I know this is from awhile back, but you can use print in ruby and it does the same thing as puts. [/quote] Nor really ;). Try this [code]print "not" puts "the" p "same"[/code] Regards, mawe

Member Avatar for pkc
0
428
Member Avatar for Member #114542

Hi! Nice! :) I didn't have a detailed look on the code, but *) instead of [code]% (board_list[0], board_list[1], board_list[2], board_list[3], board_list[4], board_list[5], board_list[6], board_list[7], board_list[8]) [/code] it may be easier to write [inlinecode]% (tuple(board_list))[/inlinecode] ;) *) I won several times, but the program didn't notice it. That's frustrating :-| …

Member Avatar for vegaseat
0
1K
Member Avatar for 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 ;)

1
873
Member Avatar for liz517
Member Avatar for anatashinu
0
181
Member Avatar for mattyd

I'm having trouble unzipping it on Linux. All I get is the error message [i]unsupported compression method 98[/i] :confused:

Member Avatar for vegaseat
1
251
Member Avatar for danizzil14

Another way: [code=Python]def group( lst, n ): ''' splits an iterable in parts with length n, e.g. group( [1,2,3,4], 2 ) ==> [ (1,2), (3,4) ] ''' return zip( *[ lst[i::n] for i in range(n) ] ) aa_dict = { "AAA": "A", "GGG": "C", "CCC": "B" } s = "AAAGGGCCC" …

Member Avatar for Gribouillis
0
217
Member Avatar for Micko

Hi! Here's a snippet using Tkinter: [code]from Tkinter import * def click(key): if key == "=": # here comes the calculation part pass # but that's up to you ;-) else: display.insert(END, key) root = Tk() keys = ["789/", "456*", "123-", "0.=+"] display = Entry(bg="white") display.grid(row=0,column=0,columnspan=4) x,y = 1,0 for …

Member Avatar for vegaseat
0
5K
Member Avatar for alex05

Hi! I guess what you are looking for is [b]basename[/b] and [b]dirname[/b]. [code] $ dirname /users4/st/jdoe/prog.c /users4/st/jdoe $ basename /users4/st/jdoe/prog.c prog.c [/code] Regards, mawe

Member Avatar for msr_viz
0
253
Member Avatar for sneekula

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 [url=http://freshmeat.net/projects/pyperiod/]here[/url]. Then there is [url=http://pyparsing.wikispaces.com/]pyparsing[/url]. You might be interested in one of the examples ... [url=http://pyparsing.wikispaces.com/space/showimage/chemicalFormulas.py]chemicalFormulas.py[/url] :)

Member Avatar for sneekula
0
119
Member Avatar for Tetch

700 loc for a simple roulette game? I guess you could shorten it a bit :icon_wink: [code=Python]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 …

Member Avatar for Tetch
0
2K
Member Avatar for vegaseat

I think OCaml is still missing: [code]print_endline "Hello World!";;[/code] Two GUI versions: The first one with the built in Graphics module: [code]Graphics.open_graph " 80x20";; Graphics.moveto 5 5;; Graphics.draw_string "Hello World";; read_line () [/code] And one with Tk: [code]open Tk let top = openTk () let l = Label.create top ~text:"Hello …

Member Avatar for sgssergio
0
1K
Member Avatar for Jusa

Hi, your "error" is a very common source of confusion :) Let's take a slightly simpler example: [code=Python]In [1]: lst = ["a", "b", "b", "d"] In [2]: for elem in lst: ....: print "before: ", lst # check the list ....: print elem, lst.index(elem) # check which element we are …

Member Avatar for pandu22
0
525
Member Avatar for fredzik

[quote]But I'm again puzzled by how Tkinter does things. Some examples of code at the beginning say "from Tkinter import *" and some say "import Tkinter as tk" and I've even seen "from Tkinter"...nothing else?[/quote] Let's see how you e.g. call an Entry with these (from Tkinter alone won't work, …

Member Avatar for fredzik
0
307
Member Avatar for Zorbie

[code=Python]>>> import sys >>>[/code] Hmm, it seems to work. What did you expect to happen? :)

Member Avatar for StrikerX11
0
162
Member Avatar for justmonkey23

[code=Python]writer = csv.writer(open(("beta_%i.%i.%i.csv" % (now.day, now.month, now.year)), "ab")[/code]

Member Avatar for justmonkey23
0
121
Member Avatar for Matt Tacular

Hi! [code=Python]print "\\".join((str1, str2))[/code] or [code=Python]print "%s\\%s" % (str1, str2)[/code] If you want to make this os-independent, have a look at the [b]os[/b] module ([i]os.path.join[/i] might be your friend :)) Regards, mawe

Member Avatar for ghostdog74
0
186
Member Avatar for lineman60
Member Avatar for mawe
1
573
Member Avatar for jwjazz

[code=Python]def increase(num, b2, x): if num%(b2**x) < num: return increase(num, b2, x+1) print x return x[/code]

Member Avatar for jrcagle
0
146
Member Avatar for pkraop

Hi, here's one way (not very clever, but it works): [code=Perl]@numbers = (12, 12, 23, 123, 3, 234, 22333, 223, 3); foreach $number (@numbers) { # fill all numbers with whitespace to a length of 5 $number = sprintf("%-5i", $number); # replace the whitespaces with . $number =~ s/ /./g; …

Member Avatar for pkraop
0
107
Member Avatar for nam5a

You don't need a [i]begin[/i] in Python,: [code=Scheme](if (condition) (begin (do-something-1) (do-something-2)) do-something-else)[/code] [code=Python]if condition: do_something_1 do_something_2 else: do_something_else[/code]

Member Avatar for nam5a
0
119
Member Avatar for fredzik

[i]place[/i] 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 (mostly) _everything_ you positioned :icon_wink: BTW, you can use a combination …

Member Avatar for fredzik
0
145
Member Avatar for Python23
Member Avatar for Python23
0
455
Member Avatar for jtxay

Hi, please put your code in code tags, otherwise the indentation is lost :icon_wink: `if number != 4 and number != 5 and number != 6 and number != 8 and number != 9 and number != 10:` This can be written a bit shorter: `if number not in [4,5,6,7,8,9,10]:` …

Member Avatar for mawe
0
123
Member Avatar for fredzik

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"? I'm just asking because you talk about a "main Idle" and …

Member Avatar for fredzik
0
889
Member Avatar for fonzali

You enter a number (say 10), press Enter and the [i]update()[/i] function does the following: - it sets [i]amount[/i] to 0 - reads the number from the Entry (10), adds it to amount (10), sets the label text to amount (10) - reads the number from the Entry (10), adds …

Member Avatar for fonzali
0
885
Member Avatar for aot

There is a widget called [i]Text[/i], which I think is what you want. An [i]Entry[/i] is always one line high (per definition ;))

Member Avatar for aot
0
88
Member Avatar for Lardmeister

Is this from [i]diveintopython[/i]? If so, then the first snippet [url=http://www.diveintopython.org/power_of_introspection/index.html]on this page[/url] is what you need ;)

Member Avatar for mawe
0
142
Member Avatar for pyguy25

[quote]I keep getting an error like 'list' object has no attribute 'split'.[/quote] And you really don't know why? [code]words = string.split(s)[/code] Ok, from your other post you know that [i]words[/i] is a list. Fine. [code]ch = string.split(words)[/code] What are you doing here? You want to split a list? Worse than …

Member Avatar for ghostdog74
0
12K
Member Avatar for Lardmeister

Hi! Python usually produces very useful error-messages, like here [quote="Python"]TypeError: argument 1 must be string or read-only character buffer, not float[/quote] Ok, you know what to do, right? Just convert your number to a string ;) [code=Python]a = 123.44 f = open("data1.dat", "w") f.write( str(a) ) # str() converts to …

Member Avatar for mawe
0
1K
Member Avatar for wandie

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 :) [code=Python]def flatten(lst): for elem in lst: if type(elem) in (tuple, list): for i in flatten(elem): yield i else: yield elem[/code] With this, the …

Member Avatar for wandie
0
858
Member Avatar for mouigher

Congratulations for finding the solution by yourself! [code=Python]def main(): import string[/code] This is bad style. Imports should be the first lines in your script. BTW, you don't need the string-module here. Strings have their [i]lower()[/i] method ;) If you are interested, with the builtin [i]sum()[/i] and list comprehension, this can …

Member Avatar for mawe
0
203
Member Avatar for jwintersmith

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, [i]id()[/i] returns the memory address of an object): [code=Python]>>> a = [1,2,3] >>> b = a >>> c = a[:] >>> id(a) -1210949716 >>> …

Member Avatar for vegaseat
0
113
Member Avatar for sneekula

Untested! [code=Python]lunch_start = time.mktime(time.strptime("11:00-20.02.2007","%H:%M-%d.%m.%Y")) lunch_end = time.mktime(time.strptime("12:30-20.02.2007", "%H:%M-%d.%m.%Y")) now = time.mktime(time.localtime()) if lunch_start < now < lunch_end: print "Hey, it's lunch time!![/code]

Member Avatar for sneekula
0
165
Member Avatar for Matt Tacular

Hi! If you do all this in a Canvas, that's very easy: [code=Python]import Tkinter as tk root = tk.Tk() c = tk.Canvas() c.pack() # the image image = PhotoImage(file="whatever.gif") c.create_image(0, 0, image=image) # and now the text at coordinates (50, 50) c.create_text(50, 50, text="whatever", fill="blue") root.mainloop()[/code] Regards, mawe

Member Avatar for mawe
0
4K
Member Avatar for aot

Yes, there are ways to do this. Here is one: [code=Python]import os def do_y( filename ): print filename for filename in os.listdir("/path/to/dir/x"): do_y( filename )[/code] Regards, mawe

Member Avatar for mawe
0
104
Member Avatar for jrcagle

Hi! Well, at least it's an interesting way to do it :) Because Python is an OO language, I would probably have a class [i]Monster[/i] and an instance-variable [i]self.current_direction[/i]. I think this would be [i]cleaner[/i]. Regards, mawe

Member Avatar for jrcagle
0
100
Member Avatar for sneekula

Hi! This works: [code=Python]text = file("recipe.txt", "r").read() words = [ i.strip(".?!") for i in text.split() ] chemicals = ["chemicalA", "compoundB", "compoundC", "methanol"] recipe = {} for chemical in chemicals: ind = words.index(chemical) recipe[chemical] = [words[ind-2], words[ind-1]] print recipe[/code] DON'T USE IT!! :) It works with your example text, but is …

Member Avatar for jbennet
0
216
Member Avatar for sneekula

Hi! [code=Python]import Tkinter as tk root = tk.Tk() listbox = tk.Listbox(root) listbox.pack() for item in ["one", "two", "three", "four"]: listbox.insert(tk.END, item) listbox.selection_set(first=2) root.mainloop()[/code] Regards, mawe

Member Avatar for sneekula
0
1K
Member Avatar for scru

Hi! Change your [i]aggregate[/i] function to: [code=Python] def aggregate(self): #This function is supposed to decrement the time for hours in range(self.hh, -1, -1): for minutes in range(self.mm, -1, -1): for seconds in range(self.ss, -1, -1): time.sleep(1) self.update() # <== ...[/code] @jrcagle: Do you see the [b]Toggle Plain Text[/b] below the …

Member Avatar for scru
0
849
Member Avatar for mattyd

Hi! Ad 1: Show some code ;) Ad 2: Tkinter isn't responsible for the window decorations, but your window-manager is. So, no, it is not possilbe to change them from Tkinter. Regards, mawe

Member Avatar for mattyd
0
194

The End.