4,305 Posted Topics
Re: If you have a windows machine, you can achieve accuracy better than 1 millisecond with time.clock() ... [code=python]# time.clock() gives wallclock seconds accurate to at least 1 millisecond # it updates every millisecond, but only works with windows # time.time() is more portable, but has quantization errors # since it … | |
I borrowed this from C#, where you can easily send output, that normally goes to the ugly black console window, to a nice looking Windows MessageBox with an OK button to close after you read your results. You can accumulate your output in a string to send to one message … | |
Re: My answer to the large volume of mostly political robo calls has been the answering machine. I will call back any friends. | |
Re: Here would be one approach ... # Python27 # create two different test sets list1 = list('abcde') list2 = list('acdef') set1 = set(list1) set2 = set(list2) print(set1) print(set2) ''' set(['a', 'c', 'b', 'e', 'd']) set(['a', 'c', 'e', 'd', 'f']) ''' match = True # now iterate through set1 and print … | |
Re: Line 7 needs an extra **]** at the end line 8 needs to be **else:** Are you sure you want **&** rather than **and** | |
Re: Or you can modify this old code to suit your needs ... # input a sequence of integer numbers separated by a space and convert to a list # works with Python2 or Python3 try: input = raw_input except: pass def get_integer_list(): while True: # get the sequence string and … | |
Re: With Python's builtin module sqlite3 you have a CREATE TABLE IF NOT EXISTS command ... # explore Python module sqlite3 # create a database file # query language in upper case (optional) import sqlite3 import os # create/connect to a permanent database file file_name = "stock_portfolio1.db3" con = sqlite3.connect(file_name) # … | |
Re: Here is the program written in Tkinter, It was originally posted using Python24 about 5 years ago somewhere in "Starting Python" together with the card image zip file you have ... # using Tkinter to display a hand of 5 random card images # each time you click the canvas … | |
Re: You can also use the PyQT or PySide GUI toolkit ... # test PySide widgets # copy text to and from the clipboard # tested with PySide474 and Python27 or Python32 from PySide.QtCore import * from PySide.QtGui import * app = QApplication([]) # ----- start your widget test code ---- … | |
| |
Re: It might be worthwhile to visit: [http://www.cs.iupui.edu/~aharris/pygame/](http://www.cs.iupui.edu/~aharris/pygame/) | |
Re: Data-mining might be an awesome area to be in. | |
Re: A somewhat old fashioned approach that better shows what you have to do ... # space separated data raw_data = '''DB01967 ZIPA DB01967 PFAZ DB01992 YVBK DB01992 ZAP70 DB02191 ZIPA DB02319 YQHD DB02552 ZFPP''' # save the raw data as text fname = 'data1.txt' with open(fname, 'w') as fout: fout.write(raw_data) … | |
Re: You basic problem is explained here ... alist = [[u'', u'-0', u'-3', u'-6', u'-9', u'-12', u'-15', u'-18']] # alist is a list within a list, so use alist[0] # the if x statement filters out the empty string u'' xval = [int(x) for x in alist[0] if x] print(xval) # … | |
Re: This should help ... # pygame key events # control a small moving circle with the arrow keys # avoid crashing against the screen borders # modified http://wordpress.com/tag/pygame-tutorial/ import pygame as pg # r, g, b color values white = 255, 255, 255 black = 0, 0, 0 blue = … | |
Re: It might be time to use the editor environment that comes normally with your Python distribution. Since you are using Python26 try this batch file ... C:\Python26\pythonw.exe -u C:\Python26\Lib\idlelib\idle.pyw Otherwise you have to give the full file path in your commandline. That does get tiresome. | |
Re: This might help you ... import random def difficult_menu(): print("""Difficulties: 1.) - Easy 2.) - Medium 3.) - Hard""") return int(raw_input("Choose a difficulty: ")) def type_menu(): print("""Types of Math: 1.) - Add 2.) - Subtract 3.) - Divide 4.) - Multiply""") return int(raw_input("Choose one of the choices:")) def pick_random_integer(difficulty): # … | |
Re: Double-clicking on the code area will highlight it proberly for copying and pasting. | |
Re: Now remember that raw_input will give you a string. | |
This snippet explores the change of a hexadecimal (base 16) string to a denary (base 10) integer and the reverse. Interestingly Python allows the representation of the hexadecimal string in two different forms. For instance 255 can be changed to 'FF' (also 'ff') or '0xff'. Any of these hexadecimal strings … | |
Re: Here is an example how to connect a button to a label ... [code]''' run_button_label1.py a simple loader for .ui XML files generated with PySide Designer the Designer's XML file was saved as "button_label1.ui" it contains a QMainWindow form with a QPushButton and a QLabel select the QPushButton and use … | |
Re: Our friend Gribouillis has a masterful solution. Let's just hope nobody at the job interview asks you to explain how it works. | |
Re: Actually there are many ways to solve this, but here would be an example for a beginning student. Study it and try to understand it ... [code=python] a = [4,5,6] b = [1,3,8,6,7,9] c = [] for bx in b: if bx in a: c.append(bx) if c: print "these are … | |
Re: Let's assume you want something like this ... [code]import pprint # create a dictionary of keys a to z and zero values d = dict([(chr(k), 0) for k in range(ord('a'),ord('z'))]) #pprint.pprint(d) # test # the test sentence s = "Albert has many marvelous attributes" # convert to all lower characters … | |
Re: You might want to use os.listdir(directory) ... [code]# list filenames in a given directory import os # assign a directory name for test directory = "C:/Python27/Atest27/Bull" # os.listdir(directory) creates a list of filenames in directory #print(os.listdir(directory)) # test # test print the list one filename each line for fname in … | |
Re: Look at: [url]http://www.daniweb.com/code/snippet105.html[/url] There is a little entry in there ... [php] // how many elements can a vector hold? // a huge number, actually until memory runs out! // well, let's test it to a million elements ... vector<int> kV; cout << "loading an integer vector with numbers 0 … | |
Re: Your example is really not stupid! Remember, even the best of us were stupid about Python at one time ... [code=python]a = 0 while a < 10: a = a + 1 if a == 4 or a == 6: # create file for instance 'output4.dat' # only strings concatinate … | |
Re: Just one idea how you do this ... [code]# toggle a Tkinter button up/down # using images and no button border # tested with Python 2.7 and Python 3.2 by vegaseat try: # Python2 import Tkinter as tk except ImportError: # Python3 import tkinter as tk def action(toggle=[True]): """ toggle … | |
Re: Python does a lot more hand-holding than C or C++ when it comes to those pesky memory leaks. Like C++ Python is object oriented. | |
Re: You could import your frame2 file into your frame1 code and instantiate it there. | |
The code shows a fast prime number generator using a sieve algorithm. It looks at only odd numbers. Technically 1 and 2 are prime numbers too, since they are only divisible by unity and themselves, exceptions are made for 1 and 2. Zero and negative numbers return an empty list. … | |
Re: There are servers that have Python installed, but I never heard of one that also has wxPython installed. | |
Re: With the Tkinter GUI toolkit there a several ways to layout the position of the widgets. Here is an example of an absolute place layout ... [code]# set position and size of a Tkinter window # also set the position of any widgets using place(x, y) layout try: # Python2 … | |
| |
Re: Example ... [code]# two ways to represent integer 1234 as a hexadecimal number # 0x is the official prefix for a hexnumber # the results appear different, but both are of type string # and change back to base 10 properly # tested with Python27 n = 1234 # using … | |
Re: You can try: [url]http://pyopengl.sourceforge.net/[/url] Also the wxPython GUI toolkit has OGL pretty well integrated ... [code]# the Open Graphics Library (OGL) is now pretty well # integrated with wxPython import wx import wx.lib.ogl as ogl class MyFrame(wx.Frame): def __init__(self): wx.Frame.__init__( self, None, wx.ID_ANY, "wx.lib.ogl Demo", size=(400,300)) canvas = ogl.ShapeCanvas(self) canvas.SetBackgroundColour("yellow") … | |
Take a look at a typical Windows GUI frame (form) with a menubar, statusbar, panel, label and buttons. Set the font and size of text, click the buttons to create some events. All of this and much more is in the free wxPython package. | |
Re: UTF8 is pretty much the defacto standard for decoding in Python. However there may be other standards on the internet, depending on the country and its native language. In this particular case ( [url]http://www.python.org[/url] ), you can find the encoding used in this line: [code] <meta http-equiv="content-type" content="text/html; charset=utf-8" /> … | |
Re: It is important to use command argument 'build' Run the build process by running the command: python makeexe.py build | |
Re: I am in love! 2012 promises to be a good year! | |
Re: Not sure about Tkinter, but the PyQT or PySide GUI toolkit can do HTML code for you ... [code]''' PySide's QLabel widget can display html formatted text (PySide is the license free version of PyQT) tested with PySide474 and Python32 ''' from PySide.QtCore import * from PySide.QtGui import * class … | |
![]() | Re: Actually the new PySide version for Python32 comes with Designer.exe, just download and install: PySide-1.1.0qt474.win32-py3.2.exe Take a look at a typical XML PyQT example here: [url]http://www.daniweb.com/software-development/python/threads/191210/1108430#post1108430[/url] |
Version 2.6 of wxPython has support for playing animated gif image files. The example sets up a panel on a frame and then uses wx.animate.GIFAnimationCtrl() to do the hard work. Actually pretty simple code. | |
Re: Mark, I think it is just a very specialized area. I did a lot of that kind of work in my earlier days using Delphi and the RS232 serial port. The modules (ADAM from Advantech Co., Ltd.) I used exchanged data as strings. It worked very well and was fun! … | |
Re: You can expand that with slicing ... [code]# using del and slicing on a list ar = range(7) print ar # [0, 1, 2, 3, 4, 5, 6] # delete element 1 and 2 del ar[1:3] print ar # [0, 3, 4, 5, 6] ar = range(7) # delete every … | |
Re: I assume you are using the Tkinter GUI toolkit. Using the tkFileDialog will make your life much easier, and brings up a dialog familiar to most users. Here is a short example ... [code=python]# a very simple Tkinter editor to show file read/write dialog from Tkinter import * from tkFileDialog … |
The End.