4,305 Posted Topics

Member Avatar for nitin1
Member Avatar for nitin1
0
170
Member Avatar for vegaseat

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.

Member Avatar for Ene Uran
3
804
Member Avatar for satsujin

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

Member Avatar for satsujin
0
190
Member Avatar for jrcagle

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 …

Member Avatar for vegaseat
2
191
Member Avatar for vegaseat

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.

3
535
Member Avatar for slasel

You need to employ a Toplevel window. See: http://www.daniweb.com/software-development/python/code/442746/toplevel-child-window-example-tkinterpython#

Member Avatar for vegaseat
0
2K
Member Avatar for vegaseat

A closer look at the Tkinter GUI toolkit Toplevel Window and how to lift and lower it respective to other windows.

0
6K
Member Avatar for slasel

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

Member Avatar for slasel
0
286
Member Avatar for slasel
Member Avatar for slasel
-1
78
Member Avatar for pinbustersrule

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.

Member Avatar for noonecares
0
889
Member Avatar for vegaseat

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.

Member Avatar for Lardmeister
5
756
Member Avatar for biancairis93
Member Avatar for Lardmeister
0
127
Member Avatar for elvis1

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 …

Member Avatar for noonecares
1
3K
Member Avatar for vegaseat

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 …

Member Avatar for Ene Uran
0
1K
Member Avatar for vegaseat

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.

Member Avatar for Ene Uran
2
484
Member Avatar for ailen.samson

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.

Member Avatar for woooee
0
904
Member Avatar for june.pierre.311

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

Member Avatar for vegaseat
0
345
Member Avatar for siaosituimoloaublood

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 …

Member Avatar for TrustyTony
0
5K
Member Avatar for johnathan.millsap

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

Member Avatar for vegaseat
1
1K
Member Avatar for tizzqman
Member Avatar for flopoe
Member Avatar for inaxassan

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 …

Member Avatar for vegaseat
0
2K
Member Avatar for inaxassan

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 …

Member Avatar for vegaseat
-1
756
Member Avatar for slasel

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

Member Avatar for vegaseat
0
243
Member Avatar for biscayne

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 …

Member Avatar for biscayne
0
247
Member Avatar for TeaAnyOne

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" # …

Member Avatar for TeaAnyOne
0
180
Member Avatar for chophouse

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.

Member Avatar for chophouse
0
106
Member Avatar for slasel

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.

Member Avatar for vegaseat
0
234
Member Avatar for shills300

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 …

Member Avatar for vegaseat
0
3K
Member Avatar for slasel

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 …

Member Avatar for vegaseat
0
285
Member Avatar for ahmad.alfananda

You need to show us some of your coding efforts. Tell us where you got stuck and we will help.

Member Avatar for vegaseat
0
74
Member Avatar for vegaseat

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

2
10K
Member Avatar for Aiban

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

Member Avatar for Aiban
0
229
Member Avatar for dean.ong.14

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.

Member Avatar for dean.ong.14
0
455
Member Avatar for Cosmo_Kramer

Yes, your indentations are really screwed up. In Python the code blocks that belong together need to show the same indents.

Member Avatar for Cosmo_Kramer
-1
303
Member Avatar for vegaseat

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 …

Member Avatar for Lardmeister
4
253
Member Avatar for ohmang841

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

Member Avatar for Lardmeister
0
9K
Member Avatar for arohideep13
Member Avatar for BigPaw

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 …

Member Avatar for Lardmeister
0
269
Member Avatar for eminenz cw

Peking used to suffer much from air pollution, then they clean up their act for the Olympics and it was an eye opener.

Member Avatar for vegaseat
-2
109
Member Avatar for vegaseat

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

Member Avatar for RonalBertogi
1
652
Member Avatar for vegaseat

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 …

Member Avatar for HiHe
5
8K
Member Avatar for rocket3443

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.

Member Avatar for woooee
0
448
Member Avatar for TeaAnyOne

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 …

Member Avatar for vegaseat
0
170
Member Avatar for Asif_NSU

Dev-C++ creates a new makefile every time it compiles. Messing with the old one is futile, it gets overwritten.

Member Avatar for Musa_Jutt
0
3K
Member Avatar for kakilang

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 …

Member Avatar for ganeshchhetri
0
1K
Member Avatar for PhilEaton
Member Avatar for dean.ong.14

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.

Member Avatar for dean.ong.14
0
292
Member Avatar for techyworld

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 …

Member Avatar for TrustyTony
0
141
Member Avatar for SandD

A simple search for **python text wordwrap** might give you enough hints to start.

Member Avatar for vegaseat
0
162

The End.