988 Posted Topics
Re: http://en.wikipedia.org/wiki/Gravina_Island_Bridge Tough on the tax payer! | |
Re: A list can have a number of the same elements, whereas a set has only unique elements. mylist = ['b', 'a', 'n', 'a', 'n', 'a', 'b', 'o', 'a', 't'] print(mylist) # elements will be unique and in hash order myset = set(mylist) print(myset) print(list(myset)) ''' result --> ['b', 'a', 'n', … | |
| |
Re: # Define a procedure, biggest, that takes three # numbers as inputs and returns the largest of # those three numbers. def biggest(first, second, third): if first > second and first > third: return first if second > first and second > third: return second else: return third # result … | |
Re: Assume the sentences end with '.' or '?' or '!' so count these characters and divide the total words by the number of these characters. | |
Re: Another option you can use: ''' wx_FancyText2.py wxPython's wx.lib.fancytext can apply XML code to color text ''' import wx import wx.lib.fancytext as fancytext class FancyText(wx.Panel): def __init__(self, parent, text_black, text_red): wx.Panel.__init__(self, parent, wx.ID_ANY) self.Bind(wx.EVT_PAINT, self.OnPaint) self.xml_str = '%s<font color="red">%s</font>' % (text_black, text_red) def OnPaint(self, evt): """generate the fancytext on a … | |
Re: You need to update the canvas as shown. Otherwise the Tkinter event loop just waits till time.sleep(5) is done. import ImageTk import tkMessageBox from Tkinter import* from turtle import * import time root = Tk() #main window canvas = Canvas(root, width=800, height=480, bg="white") canvas.grid(column=1, rowspan=6, row=0, columnspan=5) start=ImageTk.PhotoImage(file="start.gif") after_prymase2a=ImageTk.PhotoImage(file="after_prymase2a.gif") canvas.create_image(200,400,image=start) … | |
Re: Just a few more rumblings: ''' class_private1.py class variable or method names with a two underline prefix will be private too the class ''' class A(object): # actually creates self.k which is public k = 1234 # variable names like # __m or __m_ will be private to the class … | |
Re: Here we create radiobuttons with list comprehension: ''' tk_RadioButton_multi3.py explore Tkinter's Radiobutton widget create muliple radio buttons with list comprehension ''' try: # Python2 import Tkinter as tk except ImportError: # Python3 import tkinter as tk def click(): """shows the value of the radio button selected""" root.title(vs.get()) root = tk.Tk() … | |
| |
Re: Henry Ford [QUOTE]"Thinking is the hardest work there is, which is probably the reason so few engage in it." [/QUOTE] | |
| |
Re: Look at this: # named tuples have named indexes they behave similar to class # instances but require no more memory than regular tuples # the record_list of named tuples can be saved(dumped) and loaded # with Python module pickle import collections as co # create the named tuple Movies … | |
Re: Don't jump the gun and download Python 3.3 yet, it still has a few bugs. Download the much more stable Python 3.2 | |
Re: There are a number of other errors, wit this: # calculates sum of squares of natural numbers print "Enter number of terms." n = int(raw_input("Terms? ")) first_term = ( ( n * n + n ) / 2 ) - 1 m = n if m != 0: b = … | |
Re: Another look at the Python module turtle: # module turtle is part of Tkinter # turtle starts in the center of canvas (0, 0) by default # draw 3 turtle lines to form a triangle import turtle as tu tu.title('draw an equilateral triangle') # set at 50% of original size … | |
Re: Maybe this will help you: import string allowed_alpha = string.ascii_letters + string.whitespace # a test name name = "Mark Zumkoff" # gives False because of space print(name.isalpha()) # this test allows spaces if all(c in allowed_alpha for c in name): print(name) else: print("not an allowed name") | |
Re: Or you can do this: import sys def myprint(item): ''' print items on the same line works with Python2 and Python3 versions ''' sys.stdout.write(str(item)) sys.stdout.flush() for x in range(10): myprint(x) '''result --> 0123456789 ''' | |
Re: Mutable objects can change their value but keep their id(). | |
Re: This might help: # sum some data of a csv file raw_data = '''\ Station Name,Lat,Long,Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec Test 1,45.125478,-105.623154,3.12,0.15,0.08,0.61,0.67,1.24,2.32,1.06,0.64,0.07,0.32,1.02 Test 2,42.854123,-106.321587,0.09,3.15,1.61,0.03,0.84,1.62,3.01,1.51,0.81,0.02,0.23,1.09 Test 3,43.974532,-105.896214,2.65,2.01,0.05,3.02,1.05,0.08,0.08,1.06,0.43,0.65,0.12,1.06 ''' # create the test data file fname = "mydata.csv" with open(fname, "w") as fout: fout.write(raw_data) # read the data file data_list = [] for line in open(fname): … | |
Re: Even though the numpy array is shown as a list of tuples, you can change the items in the tuples. For example: # test module numpy loadtxt() # Python27 or Python32 import numpy as np try: # Python2 from StringIO import StringIO except ImportError: # Python3 from io import StringIO … | |
![]() | Re: Re: rexmorgan see: http://www.daniweb.com/software-development/python/threads/432830/importing-csv-into-array#post1856686 |
Re: I am not sure if the book "Python for Idiots" has been published yet. I am waiting! | |
Re: The easiest game would be with a number of rooms. Draw yourself a map of 9 rooms (maybe a 3x3 pattern). Make notes on the map about details of the room, number of doors, contents, pictures, furniture and so on. Let's say you come into the first room from the … | |
Re: If you smoke you are honest, at least it shows the rest of us that you are not very smart. | |
Re: If you are bored, you most like know less than 0.0001% of the world. So, get to know the remaining percentage of the world! | |
Re: To test out your program and possible help you, I installed python-djvulibre-0.3.4.win32-py2.7.exe from http://pypi.python.org/pypi/python-djvulibre/0.3.4 This works: import djvu help(djvu) '''output --> Help on package djvu: NAME djvu FILE c:\python27\lib\site-packages\djvu\__init__.py PACKAGE CONTENTS const decode dllpath sexpr ''' However, this gives an error: import djvu.decode '''output --> Traceback (most recent call last): … | |
Re: Threading may solve your problem, here is an example: '''threading_Timer1_sound.py threading allows other program segments to run at the same time threading.Timer() forms an interruptable sleep() function t = threading.Timer(interval, function, args=[], kwargs={}) t.start() starts the thread t.cancel() stops the thread t.isAlive() checks active thread winsound.Beep(frequency, duration) needs Windows OS … | |
Re: You will end up with two competing event loops. Threading might be the answer. | |
Re: Rednecks only have to count to 10. "Pain is temporary; pride is forever!" | |
Re: To find experiments with the Python random module see: [url]http://www.daniweb.com/code/snippet306.html[/url] For loops and function range() are covered in: [url]http://www.daniweb.com/code/snippet386.html[/url] You can search the Python snippets and this forum for other things like lists, strings, dictionaries, tuples, file handling and so on. Different text types are the realm of GUI programming … | |
Does anybody have experience with Python on the iPad? Is it easy to get and use Python? | |
Re: She got a mudpack and looked great for two days. Then the mud fell off. | |
Re: Yes you can change the icon to anything you have: [php]from Tkinter import * form1 = Tk() # use an icon file you have in the working folder form1.wm_iconbitmap('py.ico') form1.wm_title('Title') form1.mainloop() [/php]You could create an icon that blends in with the title color, using something like LiquidIcon from [url]www.x2studios.com[/url] (it's … | |
Re: 2 problems: line 11 the list yfoo needs to end with a ] line 26 needs to be if Fail == True: | |
Re: The C languages rule on DaniWeb. This will be a tough contest. | |
Re: The Python frog module is a more advanced turtle module with sound and such: http://pypi.python.org/pypi/frog/0.87 Should be very interesting for children. | |
Re: Nice clean start! | |
Re: It's as simple as this: [code]# convert a .png image file to a .bmp image file using PIL from PIL import Image file_in = "test1.png" img = Image.open(file_in) file_out = "test1.bmp" img.save(file_out) [/code] | |
Re: [QUOTE=woooee;348995]The datetime module will do micro-seconds [code]import datetime print datetime.datetime.now() time_now = datetime.datetime.now() print time_now[/code][/QUOTE]Not really! If you look at the output, the digits that correspond to microseconds will always be zeroes. But you could hope for millisecond resolution. | |
Re: Even worse, one can barely watch TV anymore because of all those mudslinging ads. | |
| |
Re: Pick Java so Oracle can sue you if you make money like they did with Google? | |
Re: You can use woooee's code, just replace raw_input with input | |
Re: Is there a way to highlight and copy this code so I can try it out? | |
Re: I would set up a vector of doubles, load it with the resistance values using push_back(). This will take care of size too. You can load from a file or user input. Now loop through the vector and invert all the resistance values. You can sum up the inverted resistance … | |
| |
|
The End.