4,305 Posted Topics

Member Avatar for wolfeater017

Here is a good PyGame font example ... [code]""" customFont.py use of a customized font with PyGame: http://www.cs.iupui.edu/~aharris/pygame/ch05/customFont.py download custom font from: http://www.cs.iupui.edu/~aharris/pygame/ch05/GringoNights.ttf """ import pygame pygame.init() def main(): screen = pygame.display.set_mode((640, 480)) pygame.display.set_caption("display some text") background = pygame.Surface(screen.get_size()) background = background.convert() # rgb tuple (0, 0, 0) is black …

Member Avatar for vegaseat
0
5K
Member Avatar for wolfeater017

Rumor has it that further development of py2exe has stopped. Use cx-freeze instead: [url]http://cx-freeze.sourceforge.net/[/url]

Member Avatar for Beat_Slayer
0
200
Member Avatar for acrocephalus

One of the very useful modules for imaging is PIL ... [code]# explore the Python Image Library (PIL) # download PIL from: # http://www.pythonware.com/products/pil/ from PIL import Image # pick an image file you have in the working directory # (or give full path name) image_file = "french_flag.bmp" img = …

Member Avatar for Beat_Slayer
0
11K
Member Avatar for prashanth s j
Member Avatar for Archenemie

Well, you can put other widgets (wx.StaticText or wx.StaticBitmap) on the button, in this case 2 labels each showing a line of text ... [code]import wx class MyFrame(wx.Frame): def __init__(self, parent, mytitle): wx.Frame.__init__(self, parent, -1, mytitle, size=(275, 300)) panel = wx.Panel(self) s = "HUGE CENTRED TITLE" face = "Comic Sans …

Member Avatar for Archenemie
0
99
Member Avatar for vmanes
Member Avatar for vegaseat

A simple program to count the words, lines and sentences contained in a text file. The assumptions are made that words are separated by whitespaces, and sentences end with a period, question mark or exclamation mark.

Member Avatar for snippsat
2
2K
Member Avatar for echellwig

You can use sys.path ... [code]# show the system path (aka. PYTHONPATH) # as a list of directories that Python by default looks into # the first item will be the working directory # the directory C:\\Python26\\lib\\site-packages # might be the best to add your own modules to # even …

Member Avatar for ultimatebuster
0
197
Member Avatar for Dan08

Not a very good approach, since your variable names A1, A2, ... are rather meaningless.

Member Avatar for TrustyTony
0
185
Member Avatar for TrustyTony

[QUOTE=;][/QUOTE] In this case you can use the usual Python approach ... [code]# add an 's' to indicate plural when k is not 1 for k in range(5): print( "%s kilobyte%s" % (k, 's'*(k != 1)) ) [/code]

Member Avatar for TrustyTony
0
771
Member Avatar for sneekula

Python's regex module re allows you to establish english plural rules in a more condensed from. This one should take care of most common plurals, you may add more rules ... [code=python]# using module re to pluralize most common english words # (rule_tuple used as function default, so establish it …

Member Avatar for TrustyTony
0
6K
Member Avatar for cleve23

Here is an example of the wx.StyledTextCtrl widget. You can simplify it by removing code folding and code highlighting: [url]http://www.daniweb.com/forums/showthread.php?p=1271167#post1271167[/url]

Member Avatar for vegaseat
0
594
Member Avatar for PythonNewbie2

Formatting time/date strings is easy with Python module time ... [code]# convert 14-05-1999 to May-14 # see Python manual for module time format specifiers import time date_old = "14-05-1999" # use strptime(time_str, format_str) to form a time tuple time_tuple = time.strptime(date_old, "%d-%m-%Y") #print(time_tuple) # test # use time.strftime(format_str, time_tuple) to …

Member Avatar for PythonNewbie2
0
141
Member Avatar for Member 784833
Member Avatar for prashanth s j

Extracting the number at the end of a data string is fairly simple ... [code]data = """\ No of records Date Status 1 7/7/2010 Progress Total Number of records Processed so far: 1012 Currently active records: 1""" # split into a list of words and take the final element active_records …

Member Avatar for Beat_Slayer
0
104
Member Avatar for sandeepxd

You cannot expect to simply combine two Python files and get the resulting code to work. You can write one file as a module and import it into the main file.

Member Avatar for griswolf
-3
6K
Member Avatar for modalgvr

Here is one solution ... [code]list1 = [ "['1426', '1095', '1094', '1093', '1092', '974', '869', '1572']\n", "['1495', '1305', '1264', '1227', '1215', '1142', '1141', '1115']\n", "['1001', '997', '927', '904', '871', '776', '712', '612']\n", "['567', '538', '429', '415', '332', '326', '250', '247']\n", "['246', '245', '244', '155', '145', '133', '101']\n"] list2 = [] …

Member Avatar for TrustyTony
0
178
Member Avatar for freesoft_2000

Richard "Little Dick" West (1860 - 1898) was an outlaw of the Old West, and a member of Bill Doolin's Wild Bunch gang.

Member Avatar for vegaseat
-1
133
Member Avatar for Mkaveli

Visual Python (VPython) comes to mind. Here is an example ... [code]# use the curve function to draw a helix in space # press the right mouse button to rotate the object # experiments with visual Python (VPython) from: http://vpython.org/ """ radius is thickness color (red, green, blue) color values …

Member Avatar for Tech B
0
338
Member Avatar for lewashby
Member Avatar for albo1125
0
292
Member Avatar for ihatehippies

Replace your list comprehension with a generator expression ( simply replace [] with () ), then you can use the ifilter() method of module itertools to limit the range of values ... [code]# create an iterable of square numbers and return only numbers that # are above 20 and below …

Member Avatar for snippsat
0
11K
Member Avatar for heyday21c
Member Avatar for foren

Use an editor program like notepad or IDLE to look at the contents of file output.txt

Member Avatar for foren
0
240
Member Avatar for vegaseat

The wxPython GUI toolkit makes a very nice plotting component/widget available. You can select line or marker plotting, or a combination of both. All you have to supply is a list of x,y point tuples. Other features include zooming and printing.

Member Avatar for aernie
1
2K
Member Avatar for mack00234

You can use multiple labels on a scrolled panel. Here is an example ... [code]# the wx.lib.scrolledpanel.ScrolledPanel() widget scrolls # multiple labels in the panel import wx import wx.lib.scrolledpanel as sp class MyScrolledPanel(sp.ScrolledPanel): def __init__(self, parent): # make the scrolled panel larger than its parent sp.ScrolledPanel.__init__(self, parent, wx.ID_ANY, size=(300, 600), …

Member Avatar for mack00234
0
876
Member Avatar for gangster88

The correct arguments for Circle() are (center_point, radius) and you gave two points.

Member Avatar for vegaseat
0
203
Member Avatar for angraca

[QUOTE=angraca;1254994]I am new to python and this is my first program. The program factorize a number given by a user. It also makes a list of all the primenumbers, that it finds and stores them in a file. Is there anybody who can see a way that I can make …

Member Avatar for vegaseat
0
938
Member Avatar for prashanth s j

Here is one way to accomplish this. I don't know which version of Python you are using. If you have a newer version you may want to use a with statement to simplify this experimental code a little ... [code]# read a file line by line and write out a …

Member Avatar for Beat_Slayer
0
1K
Member Avatar for lrh9

It might just be the space-in-directory-name problem the some versions of Windows have. Try the well known kludge ... [code]# the Microsoft kludge, quoting a string within a string fixes the # space-in-folder-name problem, tells the OS to use the whole string # including spaces as a single command '"C:/Documents …

Member Avatar for lrh9
0
2K
Member Avatar for prashanth s j

Non-ASCII char '\xb1' is a [B]±[/B] You may need to add [B]# -*- coding: iso-8859-15 -*-[/B] or [B]# -*- coding: <utf-8> -*-[/B] as the first line in your Python code

Member Avatar for prashanth s j
0
205
Member Avatar for sureronald
Member Avatar for gangster88

This might be a simple way to do this ... [code]# experiment with graphics.py # from: http://mcsp.wartburg.edu/zelle/python/graphics.py # draw five alternating color concentric circles from graphics import * def main(): win = GraphWin("My Circle", 300, 300) # count backwards for k in range(6, 1, -1): c = Circle(Point(150,150), 20*k) # …

Member Avatar for Beat_Slayer
0
2K
Member Avatar for Pytho

Here is an example of a Tkinter scale/slider bar ... [code]# exploring Tkinter's Scale (slider) widget try: # Python2 import Tkinter as tk except ImportError: # Python3 import tkinter as tk class ScaleDemo(tk.Frame): def __init__(self, parent=tk.Tk()): tk.Frame.__init__(self, parent) self.pack() self.parent = parent tk.Label(self, text="Scale/Slider").pack() #self.var = tk.IntVar() self.scale1 = tk.Scale(self, …

Member Avatar for vegaseat
0
971
Member Avatar for vegaseat

Write a Python program that creates upside down sentences, like [B] upside down --> umop apisdn [/B] The sentence above is flipped 180 degrees around the end. Some freedom allowed, like an 'a' upside down and reversed is the closest thing to an 'e'. Conversely a 'w' would be a …

Member Avatar for TrustyTony
0
1K
Member Avatar for katmai539

[QUOTE=ardav;1233426]Complicated algorithms mean NO singing/shouting - Holst (the quiet Planets!). My mortal mind muddles 'mid metallic music. Great for drudgery of html/css though - Metallica, System of a Down and classic old 70/80's metal.[/QUOTE]I will go along with that kind of music.

Member Avatar for Bench
1
251
Member Avatar for cc11rocks

You may want to use a dictionary. Here is a simple example ... [code]def select_action(choice): print "You now can do the following:" for action in menu_items[choice]: print action # ask for action choice ... action_choice = raw_input("Select an action: ") return action_choice # create a dictionary of menu:submenu pairs menu_items …

Member Avatar for vegaseat
0
2K
Member Avatar for waxydock

All I could find in my Python toolbox that pertains to the retrieval of form values is this little NET module written by Mark Lee Smith. It is supposed to make CGI programming in Python easier.

Member Avatar for bikehike90
0
3K
Member Avatar for vegaseat

Let Python do the work for you and figure out the roman numerals for a given integer. I have to ask you to keep the integer values somewhat reasonably low (from 1 to 4999), since roman numerals from 5000 on use characters with an overline and most PCs don't have …

Member Avatar for eljakim
0
3K
Member Avatar for blah32

I assume you mean this example ... [code]# tally occurrences of words in a list # needs Python3 import collections cnt = collections.Counter() for word in ['red', 'blue', 'red', 'green', 'blue', 'blue']: cnt[word] += 1 print(cnt) """my result --> Counter({'blue': 3, 'red': 2, 'green': 1}) """ [/code]

Member Avatar for vegaseat
1
128
Member Avatar for aint

If you use a Python container called a dictionary, you can come close to what you aspire ... [code]text = 'ARARAKHTLROGKFMBLFKKGOHMFDGRKLRNGROGINFBLMNFBAEKJGFGOQEITHRGLFDKBN' abc = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' # create a letter dictionary with character:frequency pairs letter = {} for c in text: letter[c] = letter.get(c, 0) + 1 print letter['A'] # 4 print …

Member Avatar for TrustyTony
0
107
Member Avatar for elvis1
Member Avatar for Alfarata

At first glance use the string function strtok() to build a two-dimensional array of numeric strings signifying row and column. Convert the strings without a period to integer values and the ones with a period to float on the fly as you do your math using atoi() and atof(). Now …

Member Avatar for sinju
0
153
Member Avatar for j23

One way you can do this (Python2 syntax) ... [code]while True: print "the number entered must be a decimal number" int_x = raw_input("Enter a decimal number:") if int_x.isdigit(): int_x = int(int_x) break print int_x [/code]

Member Avatar for ultimatebuster
0
2K
Member Avatar for niehaoma

So, what was your questions and what was your answer? Maybe other people can learn from your skills.

Member Avatar for niehaoma
0
106
Member Avatar for theguy126

A typical py2exe program you can use for Tkinter code ... [code]""" Py2ExeWinSetupTkZ.py A simple py2exe program used for Tkinter programs. Run this program to create a windows exe file with py2exe. Run it in a folder that also contains your source code file. It will create 2 folders named …

Member Avatar for vegaseat
0
1K
Member Avatar for Syphilis

There is another PyQT-UI example at: [url]http://www.daniweb.com/forums/showthread.php?p=1246492#post1246492[/url]

Member Avatar for vegaseat
0
64
Member Avatar for lewashby

[QUOTE=Garrett85;1245846][CODE]import sqlite3 def find_details(id2find): db = sqlite3.connect("surfersDB.sdb") # grap surfer data from database db.row_factory = sqlite3.Row cursor = db.cursor() cursor.execute("select * from surfers") rows = cursor.fetchall()[/CODE] In the code snippet above from "Head First Programming", the syntax for the database code is poorly explained. Is row_factory a call, method, or …

Member Avatar for lewashby
0
137
Member Avatar for lewashby

There are a couple of obvious mistakes in the original code, tony pointed some of those out already: Looks like there are 6 items to extract in each line, [B]s["name"][/B] is missing Python indentations are important, [B]return({})[/B] needs to line up with the [B]for[/B], or it will return an empty …

Member Avatar for TrustyTony
1
250
Member Avatar for jv_05

Here is another code example using Python module sqlite3 that you can use to experiment with ... [code]# test module sqlite3 write and read a database file # (Python25 and higher have module sqlite3 built in) # sqlite3.connect(database, timeout=5.0, isolation_level=None, # detect_types=0, factory=100) # keywords: # timeout=5.0 --> allows multiple …

Member Avatar for vegaseat
0
363
Member Avatar for alphaOri

Picking [B]str[/B] for a variable name is not good, since it is a Python function. So let's change that to [B]str1[/B]. In function choose() you return the child object, but never do anything with it. You have to let class parent know which child you picked, so change your code …

Member Avatar for alphaOri
0
151

The End.