4,305 Posted Topics

Member Avatar for vegaseat

Compress and decompress files using the popular pkzip format and the Python module 'zipfile'. [B][COLOR="Red"]Concept Error! This code just does archiving into a zip file, no compression![/COLOR][/B] To compress and archive files it is best to use module tarfile, see the snippet at: [url]http://www.daniweb.com/code/snippet216860.html[/url]

Member Avatar for tudza
0
871
Member Avatar for bomko

The PIL show() function internally saves a temporary bitmap file, then calls the default viewer to show it. Looks like your default viewer does not accept command line image files. You can use module webbrowser instead ... [code]from PIL import Image, ImageDraw from random import randint picture = Image.new("RGB", (600, …

Member Avatar for bomko
0
2K
Member Avatar for tyalangan

Test drive this one! It's old and dusty, but works on Dev-C++ version 4.9.9.0 [php]// Find number of days between dates // Turbo C converted to run on Dev-Cpp (vegaseat) #include <iostream> #include <stdlib.h> using namespace std; long days(int sm, int sd, int sy, int em, int ed, int ey); …

Member Avatar for Davish
0
279
Member Avatar for pwnmercury

Switch/case is rather slow in C or C++ and therefore was not implemented in Python. You can however use the much faster dictionary look-up to mimic a switch/case type function ... [code]# a dictionary switch/case like statement to replace # multiple if/elif/else statements in Python def switch_case(case): return "You entered …

Member Avatar for vegaseat
0
235
Member Avatar for lewashby

Python assigns the type by inference. value = 42 is an integer value = 12.34 is a flost value = 'top' is a string value = (1, 2, 3) is a tuple and so on ...

Member Avatar for vegaseat
0
124
Member Avatar for Xzarik

Something like this should help ... [code]active_days = [ [1, '27/07/2009', '28/07/2009', '29/07/2009', '30/07/2009', '31/07/2009'], [2, '03/08/2009', '04/08/2009', '05/08/2009', '06/08/2009', '07/08/2009'], [3, '10/08/2009', '11/08/2009', '12/08/2009', '13/08/2009', '14/08/2009'], [4, '17/08/2009', '18/08/2009', '19/08/2009', '20/08/2009', '21/08/2009'] ] active_weeks= '0010' for ix, week in enumerate(active_weeks): if week == '1': print(active_days[ix]) """ result >>> [3, …

Member Avatar for Xzarik
0
115
Member Avatar for gh0st0

Since you are using Python3, this should solve your problem: [url]http://www.daniweb.com/forums/showthread.php?p=1317527#post1317527[/url]

Member Avatar for gh0st0
0
160
Member Avatar for linuxoidoz

Take a look at the QInputDialog widget at: [url]http://www.riverbankcomputing.com/static/Docs/PyQt4/html/qinputdialog.html[/url]

Member Avatar for raptr_dflo
0
16K
Member Avatar for bpatt22

[code]mylist1 = [1,2,3,4] mylist2 = [3,4,5,6] myset1 = set(mylist1) myset2 = set(mylist2) # intersection of sets myset1 and myset2 # gives a new set containing the common elements myset3 = myset1.intersection(myset2) print(myset3) # set([3, 4]) print(len(myset3)) # 2 [/code]

Member Avatar for bpatt22
0
104
Member Avatar for Xzarik

You seem to have a tuple of numeric strings. Change it to a list this way ... [code]data_tuple = '4', '3', '1', '3', '2', '1' data_list = [int(item) for item in data_tuple] print(data_list) # [4, 3, 1, 3, 2, 1] [/code]

Member Avatar for Xzarik
0
157
Member Avatar for ultimatebuster

Talking about inheritance, isinstance() might be somewhat confusing to beginners when it comes to an inherited class ... [code]class Class1: def method1(self): pass class Class2(Class1): def method1(self): pass c1 = Class1() c2 = Class2() print( isinstance(c1, Class1) ) # True print( isinstance(c1, Class2) ) # False print( isinstance(c2, Class1) ) …

Member Avatar for TrustyTony
0
188
Member Avatar for frankinaround

Take a look at the Python Win32 extensions & Demos: [url]http://sourceforge.net/projects/pywin32/files/[/url]

Member Avatar for vegaseat
0
100
Member Avatar for Stefano Mtangoo

You can also look in the wxPython Demo program under Miscellaneous/ShapedWindow

Member Avatar for Beat_Slayer
0
457
Member Avatar for n1220

This will not work [B]pix[10,15] = letters['H'][/B] PIL uses [B]pix.paste(letters['H'], (10,15))[/B]

Member Avatar for vegaseat
0
461
Member Avatar for acejhon
Member Avatar for insanely_sane

The for loop is really an iterator, it iterates through sequences ... [code]# here the sequence is a string name = "paul" for c in name: print(c) """ result >>> p a u l """ # range(start, stop, step) creates an iterator if integer values # range starts from 0 …

Member Avatar for insanely_sane
0
210
Member Avatar for Pinchanzee

The Python module glob is much better for these things. Also note that glob has the advantage that extension are not case sensitive ... [code]# use module glob to get a list of selected files import glob import os # select only .exe files # or any other file extension …

Member Avatar for Pinchanzee
0
571
Member Avatar for dlannetts
Member Avatar for dlannetts
0
495
Member Avatar for vegaseat

If you bind a Tkinter widget to an event, normally only the event information is passed to the function responding to the specific event like a mouse click. Python allows you to expand the event handler to include any number of values to be passed on. Here is a typical …

Member Avatar for bvdet
1
1K
Member Avatar for ronparker

The best way is to convert this into a list of floating point numbers ... [code]result1 = (('15.64',), ('-5.2',), ('24.25',), ('22.18',), ('14.52',), ('21.8',), ('21.2804',), ('-0.13',), ('15.48',), ('2.2',), ('-6.81',)) data_list = [float(item[0]) for item in result1] import pprint pprint.pprint(data_list) print('-'*30) average = sum(data_list)/len(data_list) print("average = %0.2f" % average) """ result >>> …

Member Avatar for vegaseat
0
973
Member Avatar for Laurence26

You did not fix the misnamed __init__() function in your class! These are double underlines front and back!

Member Avatar for umbuty
0
172
Member Avatar for cleve23

cx_freeze is listed as a cross platform utility: [url]http://cx-freeze.sourceforge.net/[/url]

Member Avatar for vegaseat
0
55
Member Avatar for Pinchanzee

write() takes a string parameter concatenation needs string types so try this ... [code]counter = 3 item = "milk" s = "Error - invalid first qualifier (Line " + str(counter) + ")\n" + item print(s) # test for write(s) [/code]

Member Avatar for Pinchanzee
0
2K
Member Avatar for zandiago

[QUOTE=jwenting;506713]... I've heard every lame excuse for piracy a thousand times, and none of them make any sense except maybe to hardline communists and then only as a means of destroying the "bourgeois capitalist imperial system" as preparation for "the communist world revolution" which will inevitably lead to "the dictatorship …

Member Avatar for jon.kiparsky
2
981
Member Avatar for Ancient Dragon
Member Avatar for vegaseat
0
213
Member Avatar for PythonNewbie2

Take a look at: [url]http://www.daniweb.com/forums/showthread.php?p=1309905#post1309905[/url]

Member Avatar for vegaseat
0
234
Member Avatar for vegaseat

This code sample shows how to represent employee data as a list of dictionaries. This list can be sorted and grouped by dictionary keys. In this particular example, I demonstrate how to calculate each department's average age from the data after sorting and grouping. The code is heavily commented to …

Member Avatar for shahjapan
1
6K
Member Avatar for trakyng

These things are very much depending on the Operating System you are using. On Windows you have to bring in functions from the Kernel32.dll. Pretty hairy code though! You are much better off using one of the GUI toolkits.

Member Avatar for trakyng
0
86
Member Avatar for techie1991

An adaptive merge sort is built into Python since version 2.3 It offers a good combination of high speed and stability.

Member Avatar for TrustyTony
0
229
Member Avatar for danholding

File dates are best sorted by the seconds since epoch value. The elimination of exact duplicates (time and path/name) makes not much sense, since they shouldn't even exist ... [code]# sorts files by modifed date, # pulls 6 most recent files, # and delete all others. #created by dan holding …

Member Avatar for danholding
0
204
Member Avatar for acrocephalus

Here is an example that Henri left somewhere ... [code]# exploring wxPython's # wx.lib.filebrowsebutton.FileBrowseButton() import wx import wx.lib.filebrowsebutton class MyFrame(wx.Frame): def __init__(self, parent, mytitle): wx.Frame.__init__(self, parent, -1, mytitle, size=(500,100)) self.SetBackgroundColour("green") panel = wx.Panel(self) self.fbb = wx.lib.filebrowsebutton.FileBrowseButton(panel, labelText="Select a WAVE file:", fileMask="*.wav") play_button = wx.Button(panel, -1, ">> Play") self.Bind(wx.EVT_BUTTON, self.onPlay, play_button) …

Member Avatar for acrocephalus
0
594
Member Avatar for JDuch

You can pipe the output of a help request to a string and then save, as shown here: [url]http://www.daniweb.com/forums/post1306519.html#post1306519[/url]

Member Avatar for vegaseat
0
2K
Member Avatar for student_

Another option would be to create a list of (name, order_total) tuples. This way you can sort the list by name or find a person that ordered several times ... [code]# a simple purchase order program shipping = 4.95 order_number = int(raw_input("How many orders today: ")) order_list = [] for …

Member Avatar for vegaseat
0
291
Member Avatar for JDuch

Not too many of us use the Amiga Standard Library (ASL). It is nice to know that Python is an integral part of Amiga Computer OS.

Member Avatar for JDuch
0
188
Member Avatar for fekioh

You may want to look into a relatively new (Python 2.6.5 +) container called [B]namedtuple[/B] in module [B]collections[/B]. It uses about as much memory as a regular tuple.

Member Avatar for ultimatebuster
0
2K
Member Avatar for lewashby

Looks like your problem is in module [B]sound_panel[/B] and function call [B]track.stop()[/B]. You have two tracks going, but only stop one.

Member Avatar for vegaseat
0
84
Member Avatar for jenzilla
Member Avatar for server_crash
Member Avatar for -ordi-

At this point it might be best for you to at least study the basics of the Python language.

Member Avatar for -ordi-
0
140
Member Avatar for babug

Actually 22/7 is pretty crude. The Chinese Approximation of pi is much better. Simply use 355/113. You can remember this by looking at the first three odd integers written this way 113355.

Member Avatar for Sriman_Laxmi
0
1K
Member Avatar for andrewtrench

Python is a modular language, and half the difficulty is discovering these optimized little gems ... [code]# use Python module textwrap to break up a long text into # columns of maximum 40 characters, words are kept whole import textwrap description = """\ Ngqolomashe was hit with fists and open …

Member Avatar for andrewtrench
0
133
Member Avatar for reviloera

Look at the code examples given in the other thread called "Python GUI Programming." One of the GUI tool kits there might suit your taste or needs. Other than Tkinter, most GUI toolkits for Python are wrappers for code written in C++.

Member Avatar for vegaseat
0
86
Member Avatar for eldeingles

[QUOTE=eldeingles;1299077]Would like to be able to replace every [I]nth[/I] word in a text file with a blank space. I'm sure python is so capable.[/QUOTE]If this is homework, please show at least a little effort!

Member Avatar for TrustyTony
0
323
Member Avatar for ke24126

You can play around with this ... [code]# sort cards (2 letter names) by first and second character # TC = Ten of Club KD = King of Diamond AH = Ace of Heart etc. import operator cards = ['3S', 'KD','5S', 'TC','2D','3D'] # sort by first character in each card …

Member Avatar for bpatt22
0
4K
Member Avatar for cleve23

My advice, use some simple code to explore the basics of what you want to accomplish ... [code]# exploring wxPython widget's # wx.SplitterWindow(parent, id, pos, size, style) # wx.ListBox(parent, id, pos, size, choices, style) # wx.TextCtrl(parent, id, value, pos, size, style) import wx class MyFrame(wx.Frame): def __init__(self, parent, mytitle, mysize, …

Member Avatar for vegaseat
0
151
Member Avatar for lewashby

The creators of the pygame module expect its users to be somewhat familiar with the basics of Python.

Member Avatar for lewashby
0
1K
Member Avatar for Musing888

Actually the first time I have ever seen this on DaniWeb, you are using CODE as part of your script which messes up the code tags. You may want to consider renaming all CODE references to CODE or such.

Member Avatar for TrustyTony
0
293
Member Avatar for vegaseat

Python programming can have its lighter moments. Here we use one of those moments to draw an optical illusion using the Tkinter canvas to draw a rectangle, some lines and circles.

2
722
Member Avatar for leegeorg07

You have to make the variable [B]pass_entered[/B] available to the function. The simplest way is to use [B]global pass_entered[/B]. There were some other errors ... [code]import time import Tkinter as tk import ctypes root = tk.Tk() pass_entered = False def show_pw(): global pass_entered pw = pw_entry.get() if pw == "password": …

Member Avatar for leegeorg07
0
123
Member Avatar for ish13

Here is one way you can approach your problem ... [code]import pprint test_data = """\ (231.2314,32434.344,134.2342,345.345,1234.45) (2323.567,32.6754,12323.8776,12323.575,233.5673) """ # write the test data file out fname = "atest.txt" fout = open(fname, "w") fout.write(test_data) fout.close() # read the test data file back in fin = open(fname, "r") data_list1 = [] data_list2 …

Member Avatar for TrustyTony
0
191

The End.