4,305 Posted Topics

Member Avatar for nouth

Check this ... # tested with Python33 mystr = """\ test of a multiline string """ # encode string to <class 'bytes'> or byte string mybytes = mystr.encode("utf8") fname = "aatest.dat" # write out the byte string with open(fname, "wb") as fout: fout.write(mybytes) # read the data back in with …

Member Avatar for nouth
0
721
Member Avatar for kxjakkk

Since in the above code the variable spellchecking is a string, item in the for loop will be a character. You might also want to look into third party module pyenchant

Member Avatar for vegaseat
0
276
Member Avatar for rbyrd
Member Avatar for kxjakkk

Use module os ... os.getcwd() return the current working directory (path) os.chdir(path) change directory to the one in path You would ask the user with an input for the required path.

Member Avatar for snippsat
0
2K
Member Avatar for asadmoosvi

Class in a nutshell ... a class combines a number of methods/functions that belong together. A class can be passed to another class to inherit it's behavior. A class definition is just code running in a namespace.

Member Avatar for vegaseat
0
325
Member Avatar for tutsie12

Another example ... ''' class_classmethod2.py classmethod allows to call a method in the class Foo this way Foo.bar() normally it would be via the instance class_instance = Foo() class_instance.bar() ''' class Foo2(object): def bar(self): print("Foobar2") bar = classmethod(bar) # simpler via a decorator class Foo3(object): @classmethod def bar(self): print "Foobar3" …

Member Avatar for vegaseat
0
378
Member Avatar for azareth

A Whiter Shade Of Pale - Procol Harum http://www.youtube.com/watch?v=Mb3iPP-tHdA

Member Avatar for GrimJack
0
1K
Member Avatar for kxjakkk

Here is a hint ... ''' set comprehension101.py show a list of unique words in a sentence via set comrehension ''' import string s = "Girl meets boy, and boy meets girl once a week." print("\nOriginal sentence:") print(s) # remove all punctuation marks and make lower case s_nopunct = "".join(c …

Member Avatar for kxjakkk
0
643
Member Avatar for knan

Just one caveat ... [code]# sorting a list of alphanumeric data numerically a = ['77', '123', '18'] # sort alphabetic a.sort() print(a) # ['123', '18', '77'] # sort numeric a.sort(key=int) print(a) # ['18', '77', '123'] [/code]

Member Avatar for grantjenks
0
813
Member Avatar for Spencer_3
Member Avatar for Nafisa Morsalin

What is your operating system and which version of Python are you using?

Member Avatar for vegaseat
-1
67
Member Avatar for reham.mostafa.14268

Test print list1 and list2 also i and j. You might have to remove all the newline '\n' characters.

Member Avatar for vegaseat
0
496
Member Avatar for haze man

Python can help you ... ''' turtle_functions101.py show the classes, functions/methods and constants of module turtle ''' import turtle # sort the items case insensitive for item in sorted(dir(turtle), key=str.lower): print(item) # optional print('-'*30) help(turtle.bgcolor)

Member Avatar for vegaseat
0
912
Member Avatar for liz517

I think it would be easier, if you ... 1) read the file in as a string 2) convert to a list of words 3) process each word in the list 4) create a new list of the process results 5) join the new list back to a string 6) …

Member Avatar for kcm1
0
1K
Member Avatar for katharnakh

If you want to disable copy/paste set your text widget, for instance text1, to ... [code=python]text1['state'] = 'disabled' [/code]This also disables insert so you have to temporarily change it with ... [code=python]text1['state'] = 'normal' [/code]

Member Avatar for Gribouillis
0
2K
Member Avatar for foshan

You could do something like this ... import random name = ("stephen", "bob", "robert", "bill") word = random.choice(name) correct = word jumble = "" while word: position = random.randrange(len(word)) jumble += word[position] word = word[:position] + word[(position +1):] print("\nThe jumble word is: ",jumble) guess = input("\nTake a guess: ") count …

Member Avatar for foshan
0
217
Member Avatar for prashantsharmazz
Member Avatar for Alex_20

"Dive Into Python" Mark Pilgrim's Free online book, novice to pro, is updated constantly, and has been rewritten for Python3, see ... http://getpython3.com/diveintopython3/ (check appendix A for Py2-to-Py3 differences)

Member Avatar for Alex_20
0
127
Member Avatar for debasisdas
Member Avatar for aokono
Member Avatar for Wilever

Check out this very old snippet ... http://www.daniweb.com/software-development/python/code/216414/a-very-simple-python-program It shows you the basics of a function and to loop a table. You need to modifiy this to your case. Also the print statement has changed to a print() function with Python3.

Member Avatar for Greg_4
0
16K
Member Avatar for trade19
Member Avatar for ram619

mylist1 = [1, 2, 3] mylist2 = mylist1[:] print(id(mylist1)) print(id(mylist2)) ''' result show 2 different memory locations ... 42368056 34857768 '''

Member Avatar for vegaseat
0
170
Member Avatar for vegaseat

Here is an example on how to put at least lines and circles onto your windows console display. Yes, you have to jump through a hoop to do it. Dev-C++ can do this thanks to some BCX generated code. You have to set up your project as a Console Application …

Member Avatar for petersvp
0
10K
Member Avatar for Reverend Jim
Member Avatar for vegaseat
0
295
Member Avatar for The Dude

1) Boynton Beach Club 2) Star Trek: the motion picture 3) The Family Stone 4) Twister 5) The Whole Nine Yards 6) Dan in Real Life 7) Crazy Stupid Love 8) Anything with Benny Hill 9) Deep Impact 10) Sideways

Member Avatar for Reverend Jim
0
279
Member Avatar for bnn678

What you have in mind is very poor programming! Use a list or dictionary instead.

Member Avatar for Gribouillis
0
213
Member Avatar for CodingCabbage

Maybe this will help ... # a Tkinter menu example similar to: # http://effbot.org/tkinterbook/tkinter-application-windows.htm try: # Python2 import Tkinter as tk except ImportError: # Python3 import tkinter as tk def outer(val): """using a closure to pass args""" def inner(): root.title(val) return inner root = tk.Tk() # create a menu menu …

Member Avatar for CodingCabbage
0
308
Member Avatar for rbyrd

Interesting, I don't need line `wx.EVT_LEFT_DOWN(self.panel, self.OnLeftDown)` Could it be the version of wxPython? I used installer wxPython2.9-win32-2.9.1.1-py27.exe

Member Avatar for rbyrd
0
248
Member Avatar for stich

I used computer languages to solve science problems at work, starting with C then Pascal, followed by Python. Python was and is by far the most powerful tool and actually fun to use.

Member Avatar for pritaeas
0
212
Member Avatar for hariza

For something like a dictionary sized array of strings I would use a combination of sorting routines with look-ahead. Something Narue's snippet "Optimized quicksort implementation" shows: [url]http://www.daniweb.com/code/snippet61.html[/url] I did a comparison of simple sorting routines and came up with this: Sorting an integer array (50000 random integers) --> qsort() = …

Member Avatar for Ancient Dragon
0
2K
Member Avatar for dsushmareddy

wx.Slider(parent, id, value, minValue, maxValue, pos, size, style) Looks like you set minValue higher than maxValue.

Member Avatar for vegaseat
0
371
Member Avatar for rbyrd

Generally ... # get the position of the mouse when clicked or moved # vega import wx class MyFrame(wx.Frame): """create a color frame, inherits from wx.Frame""" def __init__(self, parent): wx.Frame.__init__(self, parent, wx.ID_ANY, "Move or click mouse") self.SetBackgroundColour('Goldenrod') # give it a fancier cursor self.SetCursor(wx.StockCursor(wx.CURSOR_PENCIL)) # bind some mouse events self.Bind(wx.EVT_LEFT_DOWN, …

Member Avatar for vegaseat
0
556
Member Avatar for eplymale3043

Please don't highjack existing threads. Create your own with the proper title. Also show some coding effort.

Member Avatar for vegaseat
0
2K
Member Avatar for RikTelner

The recent security breach at Target stores that stole data from 110 million hapless customers was done with a malware program that copies and diverts data coming from the working program. It looks like someone forgot to encrypt the customer data stream, or it wasn't encrypted very well. Also, the …

Member Avatar for Coloradojaguar
0
358
Member Avatar for MFS NCCCC

MFS NCCCC please show us what you have done. Letting someone else write your homework for you will not allow you to learn much.

Member Avatar for bryann
0
193
Member Avatar for reuben_1

Follow the advice of Anima Templi, and also check out ... http://www.daniweb.com/software-development/python/threads/32007/projects-for-the-beginner There are plenty of samll projects there.

Member Avatar for vegaseat
0
180
Member Avatar for Vish0203

You can use the Schwartzian transform algorithm ... ''' sort_Schwartzian.py example of the Schwartzian transform algorithm ''' def get_vowel_count(word, count=0): for c in word: if c in 'aeiou': count += 1 return count mylist = ["engine", "ant", "aeiou"] # use the Schwartzian transform algorithm # temporarily put count into (count, …

Member Avatar for vegaseat
0
303
Member Avatar for ddanbe

Time travel sound interesting! To live 10 times longer than you should sounds boring. The Earth would be hopelessly overgrowded and polluted.

Member Avatar for Ancient Dragon
2
2K
Member Avatar for Warrens80

I heard in Germany an angel brings the presents on Christmas eve. A little more believable for little kids than a fat guy sliding down the non existent chimney.

Member Avatar for Reverend Jim
0
1K
Member Avatar for davidw87

Using a base64 encoded GIF image string with Tkinter is very easy and usefull for smaller images. First you create the image string ... ''' Base64encGIF2.py create a base64 image string changes the bytes of an image file into printable char combinations you can then copy and paste this string …

Member Avatar for vegaseat
0
474
Member Avatar for alone88

A Porsche is made for speed, not all drivers can handle it. I feel sorry for Mister Walker since he was the innocent passenger.

Member Avatar for ZZucker
0
439
Member Avatar for fheppell

This works ... ''' urllib2_info_getheaders.py tested with Python275 ''' import urllib2 import os def download(url, download_dir): file_name = url.split('/')[-1] u = urllib2.urlopen(url) f = open(os.path.join(download_dir, file_name), 'wb') meta = u.info() file_size = int(meta.getheaders("Content-Length")[0]) print "Downloading: %s Bytes: %s" % (file_name, file_size) url = "http://www.cs.cmu.edu/~enron/enron_mail_20110402.tgz" download_dir = "C:/Python27/Atest27/Bull" # future download …

Member Avatar for snippsat
0
2K
Member Avatar for sravan953

You can use the module pygame from: [url]http://www.pygame.org/[/url] Here is a small example ... [code=python]# play MP3 music files using Python module pygame # (does not create a GUI frame in this case) # modified code from Ene Uran import pygame as pg def play_music(music_file): """ stream music with mixer.music …

Member Avatar for aru123
0
2K
Member Avatar for marigold23

Here is the use of the Python Image Library, works well with Tkinter, to get image formats other than .gif ... [code=python]# use a Tkinter label as a panel/frame with a background image # note that Tkinter only reads gif and ppm images # use the Python Image Library (PIL) …

Member Avatar for mrv8corvette
0
6K
Member Avatar for vegaseat
Member Avatar for vunkas
2
767
Member Avatar for Warrens80
Member Avatar for ddanbe
0
176
Member Avatar for Zahra_1

You can apply an endless while loop (with an exit condition) like this ... import random # optional, make string input work with Python2 or Python3 try: input = raw_input except: pass info = ''' Which sided dice would you like to roll? You can choose a 4-sided dice, a …

Member Avatar for sneekula
0
3K
Member Avatar for kuchi

Any reason why you have to use such old version? I think old Python 2.4 comes with the Tkinter GUI toolkit that has plenty of nice graphics mothods.

Member Avatar for vegaseat
0
324
Member Avatar for Zahra_1

Maybe something simple like ... `sides = int(input("Dice has how many sides, 4, 6, or 12? "))`

Member Avatar for vegaseat
0
162

The End.