4,305 Posted Topics

Member Avatar for eva yang

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]

Member Avatar for vegaseat
0
131
Member Avatar for punter999

[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 …

Member Avatar for vegaseat
0
148
Member Avatar for kbalamuk

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]

Member Avatar for vegaseat
-1
6K
Member Avatar for badboy00z

A simple application of sequence combinations is shown here: [url]http://www.daniweb.com/forums/showthread.php?p=1084858#post1084858[/url]

Member Avatar for badboy00z
0
858
Member Avatar for hondros

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 …

Member Avatar for hondros
0
103
Member Avatar for masterinex

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

Member Avatar for vegaseat
0
236
Member Avatar for mehdi0016
Member Avatar for vegaseat
0
94
Member Avatar for El Duke

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]

Member Avatar for vegaseat
0
139
Member Avatar for punter999

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.

Member Avatar for vegaseat
0
99
Member Avatar for Stefano Mtangoo
Member Avatar for rajeshwari_ib

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 …

Member Avatar for eva yang
0
7K
Member Avatar for lewashby

[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.

Member Avatar for woooee
0
100
Member Avatar for fatalblade

Actually Windows accepts the '/' instead of the somewhat awkward escape character ''

Member Avatar for fatalblade
0
170
Member Avatar for hondros

Yes, py2exe also packages all the imported modules that your program needs.

Member Avatar for vegaseat
0
90
Member Avatar for badboy00z

If you install Python using the Windows binary installer file (.msi), than you don't have to worry about setting the path.

Member Avatar for vegaseat
0
116
Member Avatar for jcao219

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]

Member Avatar for jcao219
0
121
Member Avatar for vegaseat

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 ...

Member Avatar for sainandan
1
221
Member Avatar for WOPR

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 …

Member Avatar for WOPR
0
90
Member Avatar for Indran

Looks like a bug in wxPython version 2.8.10.1 Can you go back to version 2.8.7.1 ?

Member Avatar for snippsat
0
326
Member Avatar for punter999

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 …

Member Avatar for vegaseat
0
125
Member Avatar for letlet_pogs

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': …

Member Avatar for vegaseat
-2
103
Member Avatar for vegaseat

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.

Member Avatar for yvos91
0
1K
Member Avatar for free_eagle

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 …

Member Avatar for peter_budo
0
4K
Member Avatar for rajeshwari_ib
Member Avatar for wildplace

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]

Member Avatar for lrh9
0
129
Member Avatar for lllllIllIlllI

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.

Member Avatar for William Hemsworth
7
135
Member Avatar for Skrutten

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.

Member Avatar for vegaseat
0
186
Member Avatar for Adam2k

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, …

Member Avatar for Adam2k
0
112
Member Avatar for Graxxis

[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.

Member Avatar for hondros
0
100
Member Avatar for chris99

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 …

Member Avatar for vegaseat
0
209
Member Avatar for saisai81
Member Avatar for SoulMazer

[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 …

Member Avatar for SoulMazer
0
583
Member Avatar for ahspats

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.

Member Avatar for woooee
0
145
Member Avatar for takarii

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 …

Member Avatar for takarii
0
121
Member Avatar for ffs82defxp

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 …

Member Avatar for vegaseat
0
777
Member Avatar for ribot

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 ) …

Member Avatar for ribot
0
2K
Member Avatar for qq263020776
Member Avatar for ffs82defxp

Be aware that there are a number of differences between Python2 and Python3 versions.

Member Avatar for vegaseat
0
332
Member Avatar for lrh9

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.

Member Avatar for lrh9
0
190
Member Avatar for MRWIGGLES

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' …

Member Avatar for vegaseat
0
1K
Member Avatar for hondros
Member Avatar for vegaseat
0
166
Member Avatar for goisagi
Member Avatar for mrnutty

Wow, nasty language there! However, C++ is the livelihood of quite a few people. Many of them enjoy the challenge it brings.

Member Avatar for ddanbe
0
246
Member Avatar for ffs82defxp

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.

Member Avatar for ffs82defxp
0
113
Member Avatar for Nazere

Also, when you open a file for reading or writing, it is a good idea to close it when you are done.

Member Avatar for vegaseat
0
113
Member Avatar for python.noob

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 ... …

Member Avatar for vegaseat
0
161
Member Avatar for Kippstah

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, …

Member Avatar for Kippstah
0
1K
Member Avatar for basti!

[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!, …

Member Avatar for vegaseat
0
118
Member Avatar for Ene Uran

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 …

Member Avatar for chickenfarmer
0
359
Member Avatar for Elvedon

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 …

Member Avatar for vegaseat
0
713

The End.