4,305 Posted Topics

Member Avatar for aot

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 …

Member Avatar for BBTK
0
9K
Member Avatar for vegaseat

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 …

Member Avatar for nagendra_rao
0
873
Member Avatar for Ancient Dragon

My answer to the large volume of mostly political robo calls has been the answering machine. I will call back any friends.

Member Avatar for Ene Uran
1
189
Member Avatar for adam93

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 …

Member Avatar for HiHe
0
90
Member Avatar for geansra

Line 7 needs an extra **]** at the end line 8 needs to be **else:** Are you sure you want **&** rather than **and**

Member Avatar for vegaseat
0
125
Member Avatar for TrustyTony

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 …

Member Avatar for vegaseat
0
551
Member Avatar for thanadaray

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

Member Avatar for vegaseat
0
8K
Member Avatar for hhol1101

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 …

Member Avatar for TrustyTony
0
2K
Member Avatar for neilaggarwal

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

Member Avatar for vegaseat
0
1K
Member Avatar for JustinsAngel25
Member Avatar for audrey110
0
220
Member Avatar for NeoSyn

It might be worthwhile to visit: [http://www.cs.iupui.edu/~aharris/pygame/](http://www.cs.iupui.edu/~aharris/pygame/)

Member Avatar for vegaseat
0
464
Member Avatar for ckugblenu
Member Avatar for abhik1368

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

Member Avatar for TrustyTony
0
133
Member Avatar for webstart

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

Member Avatar for vegaseat
0
6K
Member Avatar for Twin802

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

Member Avatar for Twin802
0
171
Member Avatar for C0ding

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.

Member Avatar for C0ding
0
324
Member Avatar for Twin802

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

Member Avatar for vegaseat
0
246
Member Avatar for gge18
Member Avatar for vegaseat
0
147
Member Avatar for A_Dubbs
Member Avatar for vegaseat

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 …

Member Avatar for warunn
1
8K
Member Avatar for xopenex

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 …

Member Avatar for HiHe
0
2K
Member Avatar for hughesadam_87

Our friend Gribouillis has a masterful solution. Let's just hope nobody at the job interview asks you to explain how it works.

Member Avatar for hughesadam_87
0
121
Member Avatar for R.S.Chourasia

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 …

Member Avatar for TrustyTony
0
6K
Member Avatar for MegaMan15

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 …

Member Avatar for TrustyTony
0
222
Member Avatar for zaatlob

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 …

Member Avatar for vegaseat
0
252
Member Avatar for varunrathi

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 …

Member Avatar for gerard4143
0
1K
Member Avatar for breatheasier

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 …

Member Avatar for xopenex
0
5K
Member Avatar for Thropian

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 …

Member Avatar for floatingshed
0
6K
Member Avatar for fatalaccidents

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.

Member Avatar for moroccanplaya
0
363
Member Avatar for giancan

You could import your frame2 file into your frame1 code and instantiate it there.

Member Avatar for woooee
0
314
Member Avatar for vegaseat

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

Member Avatar for Mavericks
1
3K
Member Avatar for oiwah

There are servers that have Python installed, but I never heard of one that also has wxPython installed.

Member Avatar for TrustyTony
0
190
Member Avatar for DanWebb3148

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 …

Member Avatar for DanWebb3148
0
20K
Member Avatar for Daniel200911
Member Avatar for pwolf

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 …

Member Avatar for pwolf
0
2K
Member Avatar for cwarn23
Member Avatar for Tcll

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

Member Avatar for Tcll
0
1K
Member Avatar for vegaseat

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.

Member Avatar for pyphil
2
284
Member Avatar for Lingson

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

Member Avatar for Rocketdlib
0
2K
Member Avatar for pygmalion
Member Avatar for webecedarian
Member Avatar for Ismatus3

It is important to use command argument 'build' Run the build process by running the command: python makeexe.py build

Member Avatar for telmo96
0
246
Member Avatar for Azmah
Member Avatar for sun_2588

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 …

Member Avatar for sun_2588
0
147
Member Avatar for Azmah
Member Avatar for draven07

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]

Member Avatar for vegaseat
0
2K
Member Avatar for vegaseat

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.

Member Avatar for woooee
1
2K
Member Avatar for MarkWalker84

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

Member Avatar for mr_snarf
0
2K
Member Avatar for Cenchrus

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 …

Member Avatar for vegaseat
0
166
Member Avatar for skix

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 …

Member Avatar for Notouch
0
11K

The End.