4,305 Posted Topics
Re: 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 … | |
Re: 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 | |
![]() | Re: You might want to replace the messagebox with a label of your own design. |
Re: 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. | |
Re: 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. | |
Re: 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" … | |
Re: A Whiter Shade Of Pale - Procol Harum http://www.youtube.com/watch?v=Mb3iPP-tHdA | |
Re: 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 … | |
Re: 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] | |
Re: Which version of Python are you using? | |
Re: What is your operating system and which version of Python are you using? | |
Re: Test print list1 and list2 also i and j. You might have to remove all the newline '\n' characters. | |
Re: 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) | |
Re: 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) … | |
Re: 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] | |
Re: 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 … | |
Re: A user friendly computer first requires a friendly user. | |
![]() | Re: "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) ![]() |
Re: You might want to explain what "Flask" is. | |
Re: 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. | |
| |
Re: mylist1 = [1, 2, 3] mylist2 = mylist1[:] print(id(mylist1)) print(id(mylist2)) ''' result show 2 different memory locations ... 42368056 34857768 ''' | |
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 … | |
Re: A pie-eating competition would be a nice addition to the olympic zoo. | |
Re: 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 | |
Re: What you have in mind is very poor programming! Use a list or dictionary instead. | |
Re: 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 … | |
![]() | Re: 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 ![]() |
Re: 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. | |
Re: 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() = … | |
Re: wx.Slider(parent, id, value, minValue, maxValue, pos, size, style) Looks like you set minValue higher than maxValue. | |
![]() | Re: 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, … |
Re: Please don't highjack existing threads. Create your own with the proper title. Also show some coding effort. | |
Re: 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 … | |
Re: MFS NCCCC please show us what you have done. Letting someone else write your homework for you will not allow you to learn much. | |
Re: 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. | |
Re: 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, … | |
Re: Time travel sound interesting! To live 10 times longer than you should sounds boring. The Earth would be hopelessly overgrowded and polluted. | |
![]() | Re: 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. |
Re: 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 … | |
Re: A Porsche is made for speed, not all drivers can handle it. I feel sorry for Mister Walker since he was the innocent passenger. | |
Re: 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 … | |
![]() | Re: 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 … |
Re: 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) … | |
Shows you how to play sound files with the pySFML module and Python. | |
![]() | |
Re: 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 … | |
Re: 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. | |
Re: Maybe something simple like ... `sides = int(input("Dice has how many sides, 4, 6, or 12? "))` |
The End.