4,305 Posted Topics
Re: Or try this ... slist = ['10015, John, Smith, 2, 3.01', '10334, Jane, Roberts, 4, 3.81' , '10208, Patrick, Green, 1, 3.95'] mylist = [item.strip() for s in slist for item in s.split(',')] print(mylist) ''' result ... ['10015', 'John', 'Smith', '2', '3.01', '10334', 'Jane', 'Roberts', '4', '3.81', '10208', 'Patrick', 'Green', … | |
Re: Even shorter ... def toNums2(lst): return map(int, lst) | |
If you draw shapes that are closely spaced and shifted, you can create interesting interference patterns, so called moire patterns. Here is an example using the Python module PyGame to do the drawing. | |
Re: You need a file **DailyExpenses.py** in a folder that Python usually scans. | |
Re: Just to mention another famous futurist. The years 2008 through 2012 are referred to by Nostradamus as the "Time of Troubles", a period full of war, despair, and evil, but also of hope and promise. | |
Re: Of the huge number of eggs laid in history, one must have finally hatched a chicken. | |
Re: In these days I code mostly in Python, and use an IDE geared for that language, like Eric or PyScripter. CodeBlocks isn't too bad for generic C or C++ code. I am still looking for an IDE for Jython. NetBeans was supposed to work, but was ghastly! | |
Re: Take a look at: http://www.daniweb.com/software-development/python/code/445504/an-almost-ide-wxpython Should have enough hints how to do this with wxPython. Basically ... # using module subprocess to get the # directory of drive C:\ # Python27 code import subprocess p = subprocess.Popen("dir C:\\", shell=True, stdout=subprocess.PIPE) # allow external program to work p.wait() # read the … | |
This small code example shows you how to approach the beginning concept of an very simple "IDE" for Python. | |
Re: Interestingly, Python syntax is closer to normal pseudocode than any other computer language. | |
Re: Here is a typical example: http://www.daniweb.com/software-development/python/code/445498/pyside-mainwindow | |
If you want a window with a menubar, toolbar, statusbar, dock and central widgets, you can use the PySide GUI toolkit's QMainWindow. To use the more traditional box and grid layouts, you simply add a QWidget instance as the central widget. Here is an example. | |
Re: Load the data if phonelist is empty and data file exists. Something like this ... from tkinter import * import pickle import os def save_phonelist(addressbookfile, phonelist): addressbook = phonelist # write to storage f = open(addressbookfile, 'wb') pickle.dump(addressbook, f) f.close() def load_phonelist(addressbookfile): # 'r'ead back from storage f = open(addressbookfile, … | |
A colorful look at the PySide GUI toolkit and its QPainter class and methods. Well commented and demonstrated with the drawing of a number of rectangles and the different ways to apply colors. | |
Re: If you use format minutes:seconds:milliseconds and show 00:02:20 do you mean 00:02:200 | |
Re: Santa Claus is based on St. Nicholas of Myra. He was a 5-foot-tall Greek man with a broken nose, and lived in modern-day Turkey around A.D. 200 to 300. He was renowned for his generosity, his kindness to children and his amazing boxing skills. | |
Re: Remember that raw_input() does return a string. | |
Re: Line 62 should be **else: print("Unknown Option. Goodbye")** Also put in a console wait line after that line ... **raw_input("Press Enter to go on ...")** Line 36 should be part of the line 29 if statment. Your print statements are misleading. For instance, line 38 is a dangerous mix of … | |
Re: Replace **QtGui.QMainWindow** with **QtGui.QWidget** also comment out **win.floatingToolBar()** or you will be calling it twice | |
Re: The class itself cannot be pickled, but the list of instances can. To use the pickled data file in another program, you have to recode the class in that program. See: http://www.daniweb.com/software-development/python/code/444923/pickle-class-instances-python# | |
A Python code example to find an approximate value for x in f(x) = 0 using Newton's method. | |
Explore Python's sqlite3 database module, create, write and read a database file. | |
This snippet shows you how to create a list of class instances. The class itself cannot be pickled, but the list of instances can. To use the pickled data file in another program, you have to recode the class in that program. | |
Re: A happy New Year to all! May the world be slightly less crazy this year! | |
Jython is a version of Python that can use the extensive Java library. Jython uses Python syntax and avoids the rather ugly syntax (at least for Pythonions) of Java. Here we apply it to bring up an image from a file. | |
Re: Thanks for letting us know! | |
Re: You might take a look at: http://opencv.willowgarage.com/documentation/python/index.html Also check this paper: http://ojs.pythonpapers.org/index.php/tppm/article/download/94/111 Also: http://simplecv.org/ Simple starter code: http://examples.simplecv.org/en/latest/examples/helloworld.html | |
Re: What is the name of your directory, the name of your path file, and the contents of it? | |
![]() | |
Re: If I understand this right, you want something like this ... import pprint mylist = [['a00002.doc', 'image38.jpg'], ['a00003.doc', 'image40.jpg'], ['a00001.doc', 'image50.jpg']] newlist = [] for ix, item in enumerate(mylist): #print(item[0]) # testing item[0] = "a%05d.doc" % (ix+1) #print(item[0]) # testing newlist.append(item) pprint.pprint(newlist) ''' result ... [['a00001.doc', 'image38.jpg'], ['a00002.doc', 'image40.jpg'], ['a00003.doc', … | |
Re: Just an observation on your code ... class Mac: def __init__(self,hexmac): self.hexmac = hexmac def resolve(self): return self.hexmac # after the above return the following will be ignored!!! return mac_address print(mac_address) mac_address = { '000000':'xerox0', '000001':'xerox1', '000002':'xerox2', } So rewrite your code as snippsat indicated already ... class Mac: def … | |
Re: Remember row index starts at zero, so use for instance ... contact_ID = row[0] email = row[25] rather than unpacking the whole row. | |
Re: For an example see: http://wiki.wxpython.org/LongRunningTasks?highlight=%28start%29|%28stop%29 | |
Re: Just a few changes will do ... from math import * from Tkinter import * #imports module class Calculation: def __init__(self,master): self.num = "" self.button = [None] # element at index 0 is None frame=Frame(master) frame.grid() self.returnScreen = Label(frame, background = "White", text="") self.returnScreen.grid(row=0, column=0,columnspan=3) r = 1 c = … | |
Re: () implies a function call You are using **self.clock_start = time.clock()** and **def clock_start(self):** This method would be called with self.clock_start(), but the name is used by a variable of the same name containing a float value. Simply rename one of them. | |
Re: This test code might help ... row = ['1.234', '4.563', '7.143'] print(row) # test # change list of strings to list of floats row_float = map(float, row) print(row_float) # test # change list of floats to list of integers row_int = map(int, row_float) print(row_int) # test # sum the integer … | |
Re: Here is an example ... """ rotate.py demonstrate rotating a sprite http://www.cs.iupui.edu/~aharris/pygame/ch08/rotate.py download image from: http://www.cs.iupui.edu/~aharris/pygame/ch08/ship.bmp """ import pygame pygame.init() class Ship(pygame.sprite.Sprite): def __init__(self): pygame.sprite.Sprite.__init__(self) self.imageMaster = pygame.image.load("ship.bmp") self.imageMaster = self.imageMaster.convert() self.image = self.imageMaster self.rect = self.image.get_rect() self.rect.center = (320, 240) self.dir = 0 def update(self): oldCenter = self.rect.center self.image … | |
Re: Get together with friends over some good chow and drink. | |
Re: Assuming you downloaded and installed Python with the python-2.7.3.msi installer, you can used a batch file like c:/python27/python.exe -u c:/myscriptfolder/myscript.py On a Windows machine you can also just double click on the script file. See: http://www.daniweb.com/software-development/python/threads/20774/starting-python#post104865 Even better, download the portable version of Python and use the PyScripter IDE that … | |
Re: `for d in data` will give you list objects Example ... ''' contents of file or.csv: 1, 23.27, 23.21, 83.22 2, 34.25, 65.31, 34.75 ''' import csv Or = csv.reader(open('Or.csv')) for d in Or: print(d, type(d)) ''' result ... ['1', ' 23.27', ' 23.21', ' 83.22'], <type 'list'> ['2', ' … | |
![]() | Re: You can get a selected list of Fibonacci numbers this way: http://www.daniweb.com/software-development/python/threads/20774/starting-python/18#post1910427 |
Re: Maybe you can take the 'n' out of taken in `crntItem = self.listWidget.takenItem(crntRow)` | |
Re: You will have to keep the PIL images in your list and convert them to something Tkinter can handle with `photo=ImageTk.PhotoImage(image)` just before you use them. | |
Re: The % (modulo) operator yields the remainder from the division of the first argument by the second. | |
Re: You have the pseudo code for your sort algorithm, so simply expand it to Python and test it ... mylist = [5, 3, 7, 2, 8, 4] print(mylist) n = len(mylist) for i in range(n): for j in range(1, n-i): # swap if prev value is less than current value … | |
Re: You can also use the Tkinter canvas as a label... ''' tk_canvas_create_text1.py show text at a given x, y location on a Tkinter canvas ''' try: # Python2 import Tkinter as tk except ImportError: # Python3 import tkinter as tk root = tk.Tk() root.title('Tkinter canvas text') canvas = tk.Canvas(root, height=200, … | |
Re: I wouldn't mind spending some time exploring the Google Chromebook computer. Sleek, thin, leightweight and relatively inexpensive. If I could just get my hands on the Acer C7 Chromebook, sold out everywhere I go. Looks like Python is available too. |
The End.