4,305 Posted Topics
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] | |
Re: 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, … | |
Re: 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); … | |
Re: 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 … | |
Re: 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 ... | |
Re: 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, … | |
Re: Since you are using Python3, this should solve your problem: [url]http://www.daniweb.com/forums/showthread.php?p=1317527#post1317527[/url] | |
Re: Take a look at the QInputDialog widget at: [url]http://www.riverbankcomputing.com/static/Docs/PyQt4/html/qinputdialog.html[/url] | |
Re: [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] | |
Re: 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] | |
Re: 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) ) … | |
Re: Take a look at the Python Win32 extensions & Demos: [url]http://sourceforge.net/projects/pywin32/files/[/url] | |
Re: You can also look in the wxPython Demo program under Miscellaneous/ShapedWindow | |
Re: This will not work [B]pix[10,15] = letters['H'][/B] PIL uses [B]pix.paste(letters['H'], (10,15))[/B] | |
Re: Do we have to guess what problem 3 is? | |
Re: 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 … | |
Re: 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 … | |
Re: Check if the order of installations (Python first then Blender) makes a difference. | |
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 … | |
Re: 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 >>> … | |
Re: You did not fix the misnamed __init__() function in your class! These are double underlines front and back! | |
Re: cx_freeze is listed as a cross platform utility: [url]http://cx-freeze.sourceforge.net/[/url] | |
Re: 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] | |
Re: [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 … | |
| |
Re: Take a look at: [url]http://www.daniweb.com/forums/showthread.php?p=1309905#post1309905[/url] | |
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 … | |
Re: 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. | |
Re: An adaptive merge sort is built into Python since version 2.3 It offers a good combination of high speed and stability. | |
Re: 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 … | |
Re: 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) … | |
Re: 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] | |
Re: 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 … | |
Re: 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. | |
Re: 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. | |
Re: 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. | |
| |
| |
Re: At this point it might be best for you to at least study the basics of the Python language. | |
Re: 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. | |
Re: 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 … | |
Re: 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++. | |
Re: [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! | |
Re: 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 … | |
Re: 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, … | |
Re: The creators of the pygame module expect its users to be somewhat familiar with the basics of Python. | |
Re: 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. | |
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. | |
![]() | Re: 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": … ![]() |
Re: 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 … |
The End.