4,305 Posted Topics

Member Avatar for gabb810

Again, the simple rule of Python coding: import define main code Giving your code a common sense structure makes it easier to read and understand for people you are asking for help.

Member Avatar for vegaseat
0
219
Member Avatar for Fo.katia

You may want to modify something like that ... [code]# using the Zelle graphics module (derived from Tkinter) # http://mcsp.wartburg.edu/zelle/python/graphics.py from graphics import * def main(): w = 350 h = 250 win = GraphWin("Click to move shape (10 clicks max)", w, h) #shape = Rectangle(Point(200,200),Point(250,250)) shape = Circle(Point(100,100), 20) …

Member Avatar for vegaseat
0
471
Member Avatar for aaronmk2

Simple Python coding rules: import define main program flow Giving your code a common sense structure makes it easier to read and understand for people you are asking for help. Also, a few temporary test-prints will help you a lot here!

Member Avatar for vegaseat
0
102
Member Avatar for aaronmk2

You can use operator.itemgetter() as shown in this example ... [code]# count words in a text and show them by decreasing frequency # using operator.itemgetter() # collections.Counter() needs Python27 or Python3 import collections import operator # sample text for testing (could come from a text file) text = """\ If …

Member Avatar for TrustyTony
0
3K
Member Avatar for Thropian

The simplest way to rotate an image with the Tkinter GUI toolkit is to use the Python Image Library (PIL) rotate function. Check: [url]http://www.lfd.uci.edu/~gohlke/pythonlibs/[/url] to download PIL versions for Python27 and Python32 A simple example ... [code]from PIL import Image image = Image.open('Audi.jpg') # rotate 270 degrees counter-clockwise imRotate = …

Member Avatar for vegaseat
0
22K
Member Avatar for e-papa
Member Avatar for e-papa
0
130
Member Avatar for ithelp

The Singularity that was at the origin of the Big Bang was unmeasurable small. You could think of it as an unmeasurable small particle with an unmeasurable large temperature. Wonder how many those would fit into a cubic meter?

Member Avatar for vegaseat
0
494
Member Avatar for parijat24

Here is one way to do this ... [code]# list filenames with full path in a folder and its subfolders import os # use current folder or give a folder name folder = os.getcwd() for (paths, dirs, files) in os.walk(folder): for fname in files: full_name = os.path.join(paths, fname) print(full_name) # …

Member Avatar for TrustyTony
0
202
Member Avatar for magnetpest2k5

Numpy arrays allow for numeric elements of a certain type only. Those can be integer, float or complex numbers. You can convert a Numpy array to a Python list ... [code]# using Python module numpy to create a multi-dimensional array/list import numpy as np # create a 2x3 array of …

Member Avatar for vegaseat
0
2K
Member Avatar for e-papa

Go to: [url]http://pypi.python.org/pypi/pep8/0.4#downloads[/url] download: pep8-0.4.tar.gz extract contents into a temp folder using WinRAR.exe or alike find file pep8.py and copy it to a folder with your code Take a look at pep8.py with an editor, it has all the help built-in

Member Avatar for e-papa
0
730
Member Avatar for parijat24

Hint, do not use tabs for indentations. It makes your code much harder to read.

Member Avatar for vegaseat
0
136
Member Avatar for izabwlla

Since you don't have the Python Image Library (PIL) for C#, this task will be just about impossible. Also, this code uses block indentations of one space, very hard to read!

Member Avatar for vegaseat
-1
839
Member Avatar for levic22

Here is the classy way I prefer ... [code]# Tkinter with class (preferred template syntax) # create a label with font and color try: # Python2 import Tkinter as tk except ImportError: # Python3 import tkinter as tk class MyApp(tk.Tk): def __init__(self): # the root will be self tk.Tk.__init__(self) self.title("Lab …

Member Avatar for vegaseat
0
837
Member Avatar for kacieh80

The problem with the wxPython GUI toolkit is that you are stuck using the old Python2 versions at this time. For a simple syntax comparison of four Python GUI toolkits see: [url]http://www.daniweb.com/software-development/python/threads/191210/866067#post866067[/url] With the advent of Python27 and Python31 (or higher) Tkinter has received an update with the ttk module, …

Member Avatar for e-papa
0
407
Member Avatar for e-papa

A simple explanation of a Python class object ... [code]# 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 instance of the class is …

Member Avatar for e-papa
0
359
Member Avatar for e-papa
Member Avatar for e-papa
0
164
Member Avatar for vegaseat

The tkSnack sound module was developed at KTH in Stockholm, Sweden. A great module to generate sound, play and analyze sound files and speech. It was written using Tkinter and its native TCL language. Alas, the latest release is from 2005. However, the important file tkSnack.py can be converted to …

Member Avatar for vegaseat
2
4K
Member Avatar for Rockpile

Strange! Works fine with Python31, but not with Python32. You could be on to something! The egg-heads updated the str() function in Python32 to be more in line with the repr() function.

Member Avatar for vegaseat
2
448
Member Avatar for TrustyTony

Thanks Tony! I posted an example of PySide code at: [url]http://www.daniweb.com/software-development/python/threads/191210/1522002#post1522002[/url]

Member Avatar for e-papa
2
420
Member Avatar for danholding

The example in the Python32 docs elucidates that in earlier versions of Python here was a difference, the str() result was rounded off ... [code]import math print(repr(math.pi)) print(str(math.pi)) ''' result (Python31 and earlier) --> 3.141592653589793 3.14159265359 result (Python32) --> 3.141592653589793 3.141592653589793 ''' [/code]

Member Avatar for vegaseat
0
1K
Member Avatar for e-papa

I assume you are using the Windows OS and Python 3.2, simply do this ... For PyQT download and run the Windows 32 bit self-extracting installer PyQt-Py3.2-x86-gpl-4.8.3-1.exe from [url]http://www.riverbankcomputing.co.uk/.../pyqt/download[/url] Py3.2 indicates that this the installer for Python 3.2, there are installers for other versions of Python too. You can copy, …

Member Avatar for e-papa
1
882
Member Avatar for e-papa

[QUOTE=e-papa;1518448]Thanks for showing me something new, but how can i get the itertools, and then what are the things it does, is there a way i can get docs on it, please i really want to leard more.Is it built in with python.[/QUOTE] The Python module itertools is part of …

Member Avatar for e-papa
0
731
Member Avatar for e-papa

This should be the stable release date of Python 3.2 final: February 19, 2011 Can you give us an example of which module gives you problems, and what is the error message? Also, avoid the 64bit version. There are plenty of third party modules that will only work with the …

Member Avatar for e-papa
0
932
Member Avatar for e-papa

Kindly see: [url]http://www.daniweb.com/software-development/python/threads/355545/1519470#post1519470[/url]

Member Avatar for e-papa
0
178
Member Avatar for e-papa

Nice try, but it will be too slow for large prime numbers. For instance try it with a large prime like 2147483647 You can speed things up a little realizing that all even numbers (except 2) are not primes.

Member Avatar for e-papa
0
221
Member Avatar for JetsFan
Member Avatar for zekish
0
204
Member Avatar for vmanes
Member Avatar for vegaseat

Crypting with xor allows one to write one function that can encrypt and decrypt a file. In this example a text file is used, but it could be an image file as well. Once you have created the encrypted file you simply send it through the same function again to …

Member Avatar for TrustyTony
3
7K
Member Avatar for Echo_2011

e-papa's more exact download URL ... [url]http://sourceforge.net/projects/npppythonscript/[/url]

Member Avatar for e-papa
0
1K
Member Avatar for ThePythonNoob

Logic statements following the while are not always intuitive. I would code it this way ... [code]print("\nWould you like be X's or O's ? <O/X>:") human=["",""] while True: human[0]=raw_input("").upper() if human[0] == "X" or human[0] == "O": break print(human) # for test only [/code]

Member Avatar for ThePythonNoob
0
102
Member Avatar for Thropian

Here is a simple way to accomplish transparency using the Tkinter GUI toolkit ... [code]# explore Tkinter transparency (simplified) try: # Python2 import Tkinter as tk except ImportError: # Python3 import tkinter as tk root = tk.Tk() # use opacity alpha values from 0.0 to 1.0 # opacity/tranparency applies to …

Member Avatar for Thropian
0
27K
Member Avatar for ywang
Member Avatar for vegaseat
0
1K
Member Avatar for jworld2

Floating point algorithms in all computer languages suffer from a small error as the floating point world meets the binary world. Representing -0.5 in just a sequence of 1 and 0 is not possible with true accuracy. Look at this ... [code]import math # use a list to show the …

Member Avatar for jworld2
0
539
Member Avatar for bertm81

Well sort of ... [code]class myClass: def __init__(self, methodName): vars()[methodName] = "This is the result" self.__dict__ = vars() methodName = "myMethod" q = myClass(methodName) print( q.myMethod ) # This is the result [/code]

Member Avatar for bertm81
0
222
Member Avatar for appsrox

If you use Python3, you can apply formatting this way ... [code]# needs Python3 data_list = [ (1, 'Dave'), (234, 'Einstein'), (100000, 'Bob') ] print("Printing out to file 'test123.txt' ...") fout = open("test123.txt", "w") for item in data_list: sf = "{0:>10d} {1:30}" # show on the screen as a test …

Member Avatar for richieking
0
951
Member Avatar for WASDted

Nice find! Of course you could look into subatomic particles and feel gigantic!

Member Avatar for JamieLynnSEO
8
492
Member Avatar for Ancient Dragon

I remember the days when restaurants used to serve chicken liver. Now most folks throw the stuff away. Actually, I feel sorry for the mechanic that has to do the separation. :)

Member Avatar for bumsfeld
0
150
Member Avatar for dos_killer
Member Avatar for vegaseat
0
246
Member Avatar for Michael_Knight

If fire fighters fight fires and crime fighters fight crime, what do freedom fighters fight?

Member Avatar for happygeek
0
1K
Member Avatar for toritza

You are so close! Add a few test prints and things become more clear ... [code]'''assume test file Be.csv is: name2,number2;name3,number3;name1,number1 ''' fin = open("Be.csv") text_data = fin.read() fin.close() print(text_data) # test line_list = text_data.split(';') print(line_list) # test line_list.sort() print(line_list) # test fout = open("Ord.csv", "w") for line in line_list: …

Member Avatar for toritza
0
184
Member Avatar for The Dude
Member Avatar for vegaseat
1
90
Member Avatar for vegaseat

I am afraid, I am starting to like C#, despite the somewhat bloated .Net Framework requirements. Mister Bill's Microsoft is very supportive though. The language has a nice flow compared to GUI programming in C++. Here we are looking at a standard ListBox, add some items, sort them and select …

Member Avatar for anucom
0
714
Member Avatar for vegaseat

Mine without a doubt is Marilyn Monroe. [QUOTE]"It's not true that I had nothing on. I had the radio on."[/QUOTE]

Member Avatar for JamieLynnSEO
0
1K
Member Avatar for And1

You can expand on something like this ... [code]''' ttk_multicolumn_listbox2.py Python31 includes the Tkinter Tile extension ttk. Ttk comes with 17 widgets, 11 of which already exist in Tkinter: Button, Checkbutton, Entry, Frame, Label, LabelFrame, Menubutton, PanedWindow, Radiobutton, Scale and Scrollbar The 6 new widget classes are: Combobox, Notebook, Progressbar, …

Member Avatar for vegaseat
0
14K
Member Avatar for Borzoi

Why do cemeteries have fences around them? ni teg ot gniyd era elpoep esuaceb

Member Avatar for Borzoi
0
745
Member Avatar for Archenemie

You can use something like this ... [code]# exploring the wxPython widget # wx.TextCtrl(parent, id, value, pos, size, style) # limit entry to numeric values with max 2 decimals import wx class MyFrame(wx.Frame): def __init__(self, parent, mytitle, mysize): wx.Frame.__init__(self, parent, -1, mytitle, size=mysize) self.SetBackgroundColour("white") s = "Enter the price:" label …

Member Avatar for Archenemie
0
4K
Member Avatar for sravan953
Member Avatar for Micko

at the >>> prompt type the following: [COLOR=Green]execfile("script.py")[/COLOR] and press enter

Member Avatar for danholding
0
2K
Member Avatar for nish88

Here is an example how to do this with the Windows OS ... [code=python]# disable window title bar corner x click # you need to supply your own exit button from Tkinter import * def exit(): "dummy function" pass root = Tk() root.protocol("WM_DELETE_WINDOW", exit) btn_quit = Button( text="Quit", command=root.destroy ) …

Member Avatar for gleam.uahmed
0
4K
Member Avatar for bumsfeld

[QUOTE=frogboy77;1464573]How long does the average American football match last and what percentage of that time is actually play?[/QUOTE]Just think about all the time it took in ancient Rome to remove the dead bodies and severed parts from the Colosseum.

Member Avatar for diafol
1
162

The End.