4,305 Posted Topics
Re: An attribute is a way to get from one object to another. Apply the power of the almighty dot. There is a book out titled "Python Attributes and Methods", I suggest you read it. You can download a pdf version from: [url]http://www.cafepy.com/article/python_attributes_and_methods/python_attributes_and_methods.pdf[/url] | |
Re: [QUOTE=hondros;1086432]:D I never knew about that module! I only knew about the math module... anyways, I like my method better, more work and thinking involved xD Never mind the fact that I love math.[/QUOTE]It can be very interesting to roll your own functions, but an important part of learning Python … | |
Re: Just one more tricky way ... [code]a = '(nf+nfpermult+nf)' # uses '~' for temporary '+' substitute x = a.replace('nf+', '1.0~').replace('+nf', '~1.0').replace('~', '+') print( x ) # (1.0+nfpermult+1.0) [/code] | |
Re: A simple application of sequence combinations is shown here: [url]http://www.daniweb.com/forums/showthread.php?p=1084858#post1084858[/url] | |
Re: You have an endless recursive loop within your function comp_placement(ship) that creates new random numbers each time it is called. In other words, this would be an endless loop ... [code]def comp_placement(ship): # function calls itself comp_placement(ship) [/code] Also, carefully look at your logic statements and allow the function to … | |
Re: They are Flags for compile(): re.MULTILINE (or re.M) string and each line re.DOTALL (or re.S) match any character, including a newline re,IGNORECASE (or re.I) case-insensitive matching | |
Re: If you have wx-2.8-gtk2-unicode, there is no need for an older version. | |
Re: Ypu could use something simple like this ... [code]mydata = """\ <Ranking: AA (John)> <Ranking: CA (Peter)> <Ranking: TA-A (Samantha)> """ for line in mydata.split('\n'): if line: head, rank, name = line.split() if 'Peter' in name: print "Name: Peter Rank:", rank # Name: Peter Rank: CA [/code] | |
Re: Pulling usable code out the wxPython demo code is a royal pain. However, there are a lot of nicely working examples here: [url]http://www.daniweb.com/forums/thread128350.html[/url] Tell us which widget of the demo you are interested in and we can try to help. | |
Re: IDLE will work with Linux and so will DrPython and Geany. | |
Re: A very readable way to do this ... [code]fin = open("File1.txt", "r") data1 = fin.read() fin.close() fin = open("File2.txt", "r") data2 = fin.read() fin.close() combined_data = data1 + data2 fout = open("File1&2.txt", "w") fout.write(combined_data) fout.close() [/code]This can of course be simplified. Or you can simply append ... [code]# append file2 … | |
Re: [QUOTE]Secondly, why is there an __init__ method inside the Positionable_Card class with rank and suit, but is then instructed to use rank and suit from it's base class? Thanks for any and all replies.[/QUOTE] Take it out and see what happens. | |
Re: Actually Windows accepts the '/' instead of the somewhat awkward escape character '' | |
Re: Yes, py2exe also packages all the imported modules that your program needs. | |
Re: If you install Python using the Windows binary installer file (.msi), than you don't have to worry about setting the path. | |
Re: IronPython uses the Windows .NET CLR (Common Language Runtime) & libraries and most of the common Python syntax. The standard CPython is written to be cross platform, and that does not include the CLR. For IronPython see: [url]http://www.ironpython.org/[/url] | |
Python uses the Mersenne Twister as the core random generator. The module random contains a fair number of methods (or functions) that help you to do random things. Here are some examples ... | |
Re: As woooee already mentioned, don't use the Python Shell (has those screwy looking >>> prompts) for writing programs. The Shell is only used for testing small parts of code. You can modify woooee's code ... [code]import os a = [] a = os.listdir('.') for t in a: if os.path.isfile(t): f … | |
Re: Looks like a bug in wxPython version 2.8.10.1 Can you go back to version 2.8.7.1 ? | |
Re: The wxPython demo code is poorly written and confusing to adopt. Look at the many examples of wxPython code here: [url]http://www.daniweb.com/forums/thread128350.html[/url] DrPython is a nice IDE to work with Python code and is actually written with wxPython. You can look a that source for wxPython examples. There are a number … | |
Re: Which version of Python are you using? Using Python2 you would use something like this to create an array of names. Generally Python uses lists for arrays. [code]# create the name list name_list = [] while True: name = raw_input("Enter your name (q to quit): ") if name.lower() == 'q': … | |
The module tkSnack from our friends at KTH in Stockholm, Sweden allows you to play a variety of sound files using the Tkinter GUI. Supported sound files are WAV, MP3, AU, SND and AIFF formats. | |
Re: There is a C++ code snippet right here on DaniWeb called "Add a little Graphics to your Console" at: [url]http://www.daniweb.com/code/snippet173.html[/url] You could potentially draw short lines following the x,y coordinates of your sin(x) function. Forget about the old graphics.h and Borland BGI DOS stuff, that was left in the 16 … | |
| |
Re: You might want to use bind() rather then the command arg. Take a look at: [url]http://www.daniweb.com/forums/showthread.php?p=1077620#post1077620[/url] | |
Re: Yes Paul, have a happy birthday! Let's just say that if I would put a candle for every year on my birthday cake, I would set the house on fire! I think that you have a birthday every day and a birthyear only once a year. | |
Re: The random.normalvariate( mu, sigma) function has to be called with the arguments: mu = the requested mean sigma = the requested standard deviation You have to supply those arguments. Also, if you want to loop 10 times use range(10). Indentations are important with Python. Line up your code properly. | |
Re: You have to skip the empty line in the data ,,, [code]# -*- coding: iso-8859-15 -*- #öppna fil File = open("bo.txt", "r") print "\n Välkommen till bostsadsprogrammet. \n Bostäder hämtade frÃ¥n bo.txt \n" #typkonvertera lista properties = ['location', 'price', 'size', 'rent', 'phone', 'address'] types = [str, int, float, int, str, … | |
Re: [QUOTE=Graxxis;1077678]hondros - thank you, this helps alot! ill have a tinker and see if i can get it running :D[/QUOTE]Don't forget to set a and b to zero outside the loop. | |
Re: Two bad things stick out right away from your code: 1) Don't mix Tkinter geometry managers pack and grid within the same frame. 2) Command accepts a function reference not a function call. To pass an argument use lambda, a closure, or the new partial function (Python25). Take a look … | |
Re: [QUOTE=woooee;1076659]It should be something with ButtonReleaseMask. Try this code and Google for ButtonReleaseMask if it doesn't work. [CODE]import Xlib import Xlib.display display = Xlib.display.Display(':0') root = display.screen().root root.change_attributes(event_mask= Xlib.X.ButtonPressMask | Xlib.X.ButtonReleaseMask) while True: event = root.display.next_event() print "Hello button press" [/CODE][/QUOTE] woooee, just out of curiosity, what would be the … | |
Re: Hint, don't use [B]list[/B] as a variable name. It is a Python function name. Use something like [B]mylist[/B]. Did you test out your approach? There are a few things missing. | |
Re: I ran this concept program a few times and it seems to behave perfectly random ... [code]# draw a series of lines in random directions # using module graphics.py # a Tkinter graphics wrapper from: # http://mcsp.wartburg.edu/zelle/python/graphics.py from graphics import * from random import randint from time import sleep w … | |
Re: Just a note that Python3 has introduced a new format() function, but you can still use the % formatting. Here is an example ... [code]# works with Python2 and Python3 sf = "I will pick up %s in %d hours" % ('Mary', 3) print(sf) # works with Python3.1 (string is … | |
Re: Make the weight for row 1 very high to keep row 0 almost constant, like this eaxample shows ... [code]from tkinter import * class app( Frame ): def __init__( self, master=None ): Frame.__init__( self, master ) self.grid( sticky='nswe' ) top = root.winfo_toplevel() top.rowconfigure( 0, weight=1 ) top.columnconfigure( 0, weight=1 ) … | |
Re: Be aware that there are a number of differences between Python2 and Python3 versions. | |
Re: Only mutable objects are passed by reference, since they can change internally. So, assignment will not create a true copy, just an alias. The module copy handles many mutable objects. However there are more complex objects than cannot be easily copied. For instance a recursive situation. | |
Re: You can use the module turtle to show the formation of a dragon curve fractal ... [code]# yet another Dragon Curve program using module turtle # this module ships and works with Python2 and Python3 import turtle def initialize (color='blue'): '''prepare to draw''' turtle.clear() # values for speed are 'fastest' … | |
Re: Which version of Python are you using, it makes a difference. | |
Re: Sorry, masterofpuppets already suggested slicing the list. | |
Re: Wow, nasty language there! However, C++ is the livelihood of quite a few people. Many of them enjoy the challenge it brings. | |
Re: If you call a function like this [B]check_if_true(user_choice)[/B] and you use variable user_choice in that function then you have to define the function like this [B]def check_if_true(user_choice):[/B] to get the argument passed. | |
Re: Also, when you open a file for reading or writing, it is a good idea to close it when you are done. | |
Re: In all fairness to snippsat, he did point out that DaniWeb contains a fair number of well commented PyQT examples to study and experiment with. As of 08dec2009 we have: Mainwindow frame ... [url]http://www.daniweb.com/forums/post864990.html#post864990[/url] Boxlayout, button and canvas ... [url]http://www.daniweb.com/forums/post865059.html#post865059[/url] Image display ... [url]http://www.daniweb.com/forums/post866067.html#post866067[/url] Import, gridlayout, label and buttons ... … | |
Re: You could simplify main() a little to make the yes/no exit work ... [code]def main(): print while True: print # Declare Variables Here: pints = [0] * 7 pintsTotal = 0 pintsAvg = 0 pintsHigh = 0 pintsLow = 0 # Function Calls Here: pints = getPints(pints) pintsTotal = getTotal(pints, … | |
Re: [QUOTE=fubhasan;1074691]file_pointer = open("Handylist.csv", "r") name_in = raw_input("Enter the name") for rec in file_pointer: substrs = rec.split() name = substrs[x] ## don't know where this is if name == name_in: print("%s Found",% (name)) u have to put comma[/QUOTE]Let's not be silly, there is [B]no[/B] comma needed in [B]print("%s Found"[COLOR="Red"],[/COLOR]% (name))[/B] basti!, … | |
Re: Someone was nice enough to post this in another thread, but it deserves repeating ... [QUOTE]Great fleas have little fleas upon their backs to bite 'em, And little fleas have lesser fleas, and so ad infinitum. And the great fleas themselves, in turn, have greater fleas to go on, While … | |
Re: Something like this works ... [code]# main program firstscript.py # display an image using Tkinter and PIL # PIL allows Tkinter to read more than just .gif image files import Tkinter as tk from PIL import ImageTk def next_image(): import secondscript root = tk.Tk() # size the window so the … |
The End.