4,305 Posted Topics
Re: 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 … | |
Re: Rumor has it that further development of py2exe has stopped. Use cx-freeze instead: [url]http://cx-freeze.sourceforge.net/[/url] | |
Re: 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 = … | |
Re: 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 … | |
Re: [B]Bad or missing mouse driver. Spank the cat [Y/N]?[/B] | |
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. | |
Re: 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 … | |
Re: Not a very good approach, since your variable names A1, A2, ... are rather meaningless. | |
Re: [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] | |
Re: 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 … | |
Re: 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] | |
Re: 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 … | |
| |
Re: 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 … | |
Re: 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. | |
Re: 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 = [] … | |
Re: Richard "Little Dick" West (1860 - 1898) was an outlaw of the Old West, and a member of Bill Doolin's Wild Bunch gang. | |
Re: 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 … | |
Re: Any book that uses the hopelessly outdated livewires stuff should be dumped! ![]() | |
Re: 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 … | |
Re: One of the ways to do this would be to use slicing. | |
Re: Use an editor program like notepad or IDLE to look at the contents of file output.txt | |
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. | |
Re: 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), … | |
Re: The correct arguments for Circle() are (center_point, radius) and you gave two points. | |
Re: [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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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 | |
Re: So the question is: How large is your data file? | |
Re: 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) # … | |
Re: 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, … | |
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 … | |
Re: [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. | |
Re: 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 … | |
Re: 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. | |
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 … | |
Re: 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] | |
Re: 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 … | |
Re: 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 … | |
Re: 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] | |
Re: So, what was your questions and what was your answer? Maybe other people can learn from your skills. | |
Re: 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 … | |
Re: There is another PyQT-UI example at: [url]http://www.daniweb.com/forums/showthread.php?p=1246492#post1246492[/url] | |
Re: [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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … |
The End.