4,305 Posted Topics
Re: Lots of folks get married on the date. Easy wedding date for the husband to remember. | |
This Python code allows you to get selected statistics of a story text. It will count lines, sentences, words, list words and characters by frequency, and give the average word length. It should be easy to add more statistics using the dictionaries created. | |
Re: You can also move your lines on and off the canvas screen as shown in: http://www.daniweb.com/software-development/python/code/442856/alternate-canvas-objects-tkinterpython | |
Re: Another approach to a circular list ... '''' ringbuffer_function_deque1.py using the Python deque module as a ringbuffer as the buffer fills up first entries are dropped tested wth Python27 and Python33 ''' import collections def ringbuffer_10(mylist, dq=collections.deque(maxlen=10)): ''' mimics a ringbuffer of default length 10 you can change that to … | |
You can alternately show one of two lines drawn on the Tkinter canvas by simply moving them on and off the canvas screen. This beats a cumbersome create and delete cycle. | |
Re: You need to employ a Toplevel window. See: http://www.daniweb.com/software-development/python/code/442746/toplevel-child-window-example-tkinterpython# | |
A closer look at the Tkinter GUI toolkit Toplevel Window and how to lift and lower it respective to other windows. | |
Re: A typical example ... '''tk_button_loop1.py create five Tkinter image buttons using a for loop ''' # needs Python25 or higher from functools import partial try: # Python2 import Tkinter as tk except ImportError: # Python3 import tkinter as tk def click(val): s = "Button " + val + " clicked" … | |
Re: sneekula is correct, you need to give us your code so we can help. | |
Re: I don't understand your question entirely, but there is a Python snippet at: [URL]http://www.daniweb.com/code/snippet452.html[/URL] that looks at various sorting algorithms, including the ever so slow bubblesort. | |
Comparing a number of different approaches to finding the closest pair of numeric elements in a list. The timing is done with the mpmath module, but you can also use Python module timeit. | |
Re: You can keep track of the lines of text by using a list and the index number ... [code]# text for the test test_text = """\ apple banana lemon melon pear""" fname = "myfruits.txt" #write the multiline text to a test file fout = open(fname, "w") fout.write(test_text) fout.close() # read … | |
Python is entirely object oriented and using classes is made relatively simple. Beginners have a certain angst when it comes to using classes. There is a hump in the learning curve, which I like to overcome with this example. Inheritance really makes sense and saves you a lot of extra … | |
An approach to create multiple GUI buttons (or other widgets) using list comprehension. In this case I used the Tkinter GUI toolkit that comes with the Python installation. | |
Re: You can also use the Schwartzian approach. Create a list of (abs(x - y), x, y) tuples, excluding matches where abs(x - y) == 0. Then use the min() function on the list. | |
Re: Notice that a while loop mimics a recursive function rather closely. It should give you hints how to set it up ... ''' maxnum1.py find the highest number in a list not using Python's max(list) function ''' mylist = [1, 2, 3, 4, 5 ,6, 7, 3, 5] maxnum = … | |
Re: I would write the code like this ... def newton_approx(x): """ Newton's method to get the square root of x using successive approximations """ tolerance = 0.000001 estimate = 1.0 while True: estimate = (estimate + x / estimate) / 2 difference = abs(x - estimate ** 2) if difference … | |
Re: You could do something like this ... # Guess the number game by Johnathan Millsap import random myName = input('Hello! What is your name? ') level = int(input('Pick a level of difficulty (1 to 3): ')) # change range and number of allowed guesses with level if level == 1: … | |
Re: What kind of error messages are you getting? | |
Re: The way sneekula has written the class code, it would be very easy to change for instance the name of the patient from outside the class ... class Patient(object): # by convention class names are capitalized def __init__(self, ID, name, bdate, gender, phone, address): # assing class parameters to instance … | |
Re: Here is a class example that has helped a fair number of students ... # a look at Python's class constructor, method and instance # class names are capitalized by convention to aid readability class Animal: def __init__(self, animal, sound): """ The constructor __init__() brings in external parameters when an … | |
Re: Our friend sneekula has left an excellent example of Tkinter font code at: http://www.daniweb.com/software-development/python/threads/191210/python-gui-programming/11#post1902534 | |
Re: You could use something like this ... raw_data = '''\ 10.25, 9.23, 8.97, 8.71, 8.40, 8.36, 8.30, 8.21 10.25, 9.23, 8.97, 8.71, 8.40, 8.36, 8.30, 8.61 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15 0.60, 0.60, 0.60, 0.60, 0.50, 0.50, 0.50, 0.15 4.85, 2.85, 1.85, 1.25, 0.95, 0.85, 0.80, 0.45 … | |
Re: Here is one example ... ''' show only the data lines that contain the search word ''' # test data string data = '''\ 12347 10000 secretary James Harrison 12348 20000 secretary Jade Powell 12341 40000 consultant Adam Johnson''' # pick a somewhat unique file name fname = "aaatest123.txt" # … | |
Re: As far as I know pymysql has not been ported to Python3 yet. I wonder if you can use module sqlite3 that is part of the Python installation. | |
Re: You can use certain pygame modules like the pygame mixer with Tkinter to play sounds. However, IMHO for the application you want to use the pygame and the Tkinter **event loops** will clash. You may have to use module **threading** to make this go. | |
Re: Just experiment with this example ... '''turtle_circle1.py explore Python's turtle graphic circles turtle.circle(radius, extent=None, steps=None) turtle.color('red') --> set pen color and fill color ''' import turtle as tu tu.title('turtle circles and semi-circles') # set turtle speed, default = 'normal' # pick from ['fastest', 'fast', 'normal', 'slow', 'slowest'] tu.speed('fastest') # optional … | |
Re: Here is an example of multiple Tkinter radio buttons and how to use IntVar() ... '''tk_RadioButton_multi1.py exploring multiple Tkinter radio buttons radio buttons only allow one item to be selected/checked original code from: Ene Uran ''' try: # Python2 import Tkinter as tk except ImportError: # Python3 import tkinter as … | |
Re: You need to show us some of your coding efforts. Tell us where you got stuck and we will help. | |
Just a small example showing how to draw circles with PySide (public PyQT). I used LightShot to capture the display, which gives you a link to the picture. http://prntscr.com/kw6b6 | |
Re: > EDIT: Gained access to my 32bit XP machine and the buttons and text line up perfectly. Its a clean and fresh install > > Thanks for your time. Let's assume then that this is solved. | |
Re: My hunch is that the problem dean.ong.14 (Dean Ong) encounters is caused by a user file saved as random.py, something to be avoided. | |
Re: Yes, your indentations are really screwed up. In Python the code blocks that belong together need to show the same indents. | |
Let's say you have a whole bunch of nicely named lists and want to save them all and their names in a pickle file. One solution can be to store these lists and their names in a Bag container class and pickle the bag instance object. Now you can use … | |
Re: [QUOTE=soUPERMan;1167687]but raw_input is compatible to both version 3 and 2.x[/QUOTE]Using raw_input() will give an error in Python3. | |
Re: Age of Empires II I like to set traps for invading armies. | |
Re: HiHe ... The SharpDevelop IDE uses IronPython to produce executable files. Here is a test ... ''' code executed on SharpDevlop 4.2 IDE Python console solution used: IronPython-2.7.3.msi from: http://ironpython.net/download/ and: SharpDevelop_4.2.2.8818_Setup.msi from: http://www.icsharpcode.net/OpenSource/SD/Download/#SharpDevelop4x the IDE was installed after the IronPython27 installation the 'Run compiled exe' produced 2 files in … | |
Re: Peking used to suffer much from air pollution, then they clean up their act for the Olympics and it was an eye opener. | |
A real useful piece of code, hence I put it under Z. It does nothing but open and close the door of the CD-ROM player, and pushes the tray in and out. Should your coffee be too hot, you can put it on the moving tray and cool it off! … | |
If you have a smaller image, you can include it in your program as a base64 encoded string. This way you don't have to worry about an image file to go with your code. In your program you can then decode it back to the familiar bytes of an image … | |
Re: Just because it would be nice. What did you do to make it work? Another option would be to write Python code that will find the file and its path. | |
Re: You can also go smart with this ... '''count_vowels1.py using class Counter to count vowels in a text ''' from collections import Counter text = ''' Python? That is for children. A Klingon Warrior uses only machine code, keyed in on the front panel switches in raw binary. ''' vowels … | |
Re: Dev-C++ creates a new makefile every time it compiles. Messing with the old one is futile, it gets overwritten. | |
Re: Looks like Narue is in the usual good mood this morning. You have to forgive! Good person though! I took BCX, the basic to C translator, and figured it out in 5 minutes flat. Here is the C code. You may throw in a little C++ lingo. The name of … | |
Re: Is file **firefox.exe** really in folder **C**? | |
Re: My hunch is that the problem dean.ong.14 (Dean Ong) encounters is caused by a user file saved as random.py, something to be avoided. | |
Re: Please use **True** (it is capitalized) ... # initialize count count = 0 # you could use 1 instead of True, but True is clearer while True: print(count) count += 1 # exit condition needed to stop endless loop if count > 8: break '''result ... 0 1 2 3 … | |
Re: A simple search for **python text wordwrap** might give you enough hints to start. |
The End.