988 Posted Topics

Member Avatar for Ancient Dragon
Member Avatar for Ene Uran
0
163
Member Avatar for vegaseat

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

Member Avatar for Ene Uran
3
804
Member Avatar for jrcagle
Member Avatar for lewashby

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

Member Avatar for woooee
0
237
Member Avatar for elbert.leach

Assume the sentences end with '.' or '?' or '!' so count these characters and divide the total words by the number of these characters.

Member Avatar for Ene Uran
0
343
Member Avatar for silversonicaxel

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 …

Member Avatar for Ene Uran
0
341
Member Avatar for slasel

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

Member Avatar for Ene Uran
0
438
Member Avatar for inaxassan
Member Avatar for vegaseat

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 …

Member Avatar for Ene Uran
0
1K
Member Avatar for vegaseat

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

Member Avatar for Ene Uran
2
484
Member Avatar for idRATHERgoHUNT
Member Avatar for GrimJack

Henry Ford [QUOTE]"Thinking is the hardest work there is, which is probably the reason so few engage in it." [/QUOTE]

Member Avatar for GrimJack
3
534
Member Avatar for crishein14
Member Avatar for lewashby

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 …

Member Avatar for ~s.o.s~
0
146
Member Avatar for lewashby

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

Member Avatar for lewashby
0
202
Member Avatar for cjquines

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

Member Avatar for want_learn
0
108
Member Avatar for vegaseat

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 …

Member Avatar for woooee
0
2K
Member Avatar for dan.nitschke

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

Member Avatar for vegaseat
0
5K
Member Avatar for Lardmeister

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

Member Avatar for Ene Uran
0
246
Member Avatar for hughesadam_87
Member Avatar for rexmorgan

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

Member Avatar for rexmorgan
0
1K
Member Avatar for python1956

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 …

Member Avatar for vegaseat
0
545
Member Avatar for BobTheLob

Re: rexmorgan see: http://www.daniweb.com/software-development/python/threads/432830/importing-csv-into-array#post1856686

Member Avatar for Ene Uran
0
6K
Member Avatar for duyencaothi
Member Avatar for Max00355
0
180
Member Avatar for chris99

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 …

Member Avatar for Jacklittle01
0
1K
Member Avatar for WolfShield

If you smoke you are honest, at least it shows the rest of us that you are not very smart.

Member Avatar for BitBlt
0
250
Member Avatar for PrimeOutsourcin

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!

Member Avatar for Ene Uran
0
232
Member Avatar for GrimJack
Member Avatar for britanicus

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

Member Avatar for Ene Uran
0
485
Member Avatar for Frensi

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 …

Member Avatar for Ene Uran
0
7K
Member Avatar for nchy13
Member Avatar for Ene Uran
0
195
Member Avatar for Ancient Dragon

Rednecks only have to count to 10. "Pain is temporary; pride is forever!"

Member Avatar for vinnitro
1
150
Member Avatar for pato

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 …

Member Avatar for PythonHelper
0
1K
Member Avatar for Ene Uran

Does anybody have experience with Python on the iPad? Is it easy to get and use Python?

Member Avatar for chriswelborn
1
148
Member Avatar for WolfShield

She got a mudpack and looked great for two days. Then the mud fell off.

Member Avatar for itzarun
0
1K
Member Avatar for mattyd

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 …

Member Avatar for ZZucker
0
5K
Member Avatar for werydude

2 problems: line 11 the list yfoo needs to end with a ] line 26 needs to be if Fail == True:

Member Avatar for TrustyTony
0
519
Member Avatar for TrustyTony
Member Avatar for sneekula

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.

Member Avatar for Sanchixx
0
482
Member Avatar for 4evrmrepylrning
Member Avatar for rasizzle

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]

Member Avatar for Gribouillis
0
28K
Member Avatar for aot

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

Member Avatar for BBTK
0
9K
Member Avatar for Ancient Dragon

Even worse, one can barely watch TV anymore because of all those mudslinging ads.

Member Avatar for Ene Uran
1
189
Member Avatar for TrustyTony
Member Avatar for jackbauer24

Pick Java so Oracle can sue you if you make money like they did with Google?

Member Avatar for Rashakil Fol
0
500
Member Avatar for Programmer_Girl
Member Avatar for Stevo812
Member Avatar for NormR1
1
1K
Member Avatar for hsayid

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 …

Member Avatar for studentba065
0
6K
Member Avatar for Azmah
Member Avatar for BDove
0
2K
Member Avatar for pseudorandom21

The End.