904 Posted Topics

Member Avatar for leegeorg07

Why so complicated? Using a similar english dictionary file: [code=python]# mydict.txt has one English word per line # about 74500 in total mydict = open("mydict.txt", "r").readlines() print(mydict[:10]) """my display of some words in mydict --> ['aardvark\n', 'aardvarks\n', 'aaron\n', 'abaci\n', ... ] """ # strip the trailing newline char mydict = …

Member Avatar for leegeorg07
0
116
Member Avatar for A_Dubbs

The reason you want to make something private to the class is to keep it from easily spilling out into external code. So pseudo-private will do one good job. Remember it's called private, not secret!

Member Avatar for bumsfeld
1
231
Member Avatar for sneekula

Fred walks into the post office one day and sees one middle-aged, balding man standing at the counter methodically placing "Love" stamps on bright pink envelopes with hearts all over them. He then takes out perfume bottle and starts spraying scent all over them. Fred's curiosity gets the better of …

Member Avatar for vegaseat
1
495
Member Avatar for cookware_ok
Member Avatar for muzaffar85
0
317
Member Avatar for mahela007

[code=python]# staticmethod() and classmethod() # make it easier to call one class method class ClassA(object): def test(this): print this test = staticmethod(test) ClassA.test(4) # 4 class ClassB(object): @classmethod def test(self, this): print this ClassB.test(4) # 4 [/code] See: [url]http://www.techexperiment.com/2008/08/21/creating-static-methods-in-python/[/url]

Member Avatar for mahela007
0
85
Member Avatar for masterofpuppets
Member Avatar for lrh9
1
765
Member Avatar for AutoPython

[code=python]import os # works on windows nt (also xp and vista) or linux os.system(['clear','cls'][os.name == 'nt']) [/code]If [os.name == 'nt'] is True then this becomes effectively 1. So it picks item at index 1 from the list which is the Windows command 'cls'. If it's False, it becomes 0 and …

Member Avatar for bumsfeld
0
171
Member Avatar for xaeubanks

Did you download the code or retype it manually yourself? There are some errors due to indentations and typos. The return outside function error is really indentation error!

Member Avatar for bumsfeld
0
136
Member Avatar for simpatar

Also with Python3 you don't have to use fahrenheit = (9.0 / 5.0) * celsius + 32 you can just use fahrenheit = (9 / 5) * celsius + 32 since '/' is now floating point division and '//' is integer division.

Member Avatar for bumsfeld
0
270
Member Avatar for Gribouillis
Member Avatar for bumsfeld
1
621
Member Avatar for jsw24

Some corrections: [code=python]num = 0 mylist = [] while num < 10: num = num + 1 mylist.append(num) print(mylist) for item in mylist: print(item) [/code]

Member Avatar for masterofpuppets
0
15K
Member Avatar for Kruptein

[QUOTE=Kruptein;1019652]Okay that was quit stupid :f[/QUOTE]Asking questions is never stupid! :)

Member Avatar for jlm699
0
262
Member Avatar for Kruptein

This will also trap number exceeding the index: [code=python]import string def numtolet(num): if num > 25: return return string.ascii_uppercase[num] print( numtolet(0) ) # A print( numtolet(5) ) # F print( numtolet(25) ) # Z print( numtolet(26) ) # None [/code]

Member Avatar for bumsfeld
0
205
Member Avatar for jmark13

One of the solutions is pretty straight forward, with easy logic: [code=python]list1 = [[1,2,3],[4,5,6],[7,8,9],[10,11,12]] list2 = [1,2,3,4,11] list3 = [] # q1 is each sublist in list1 for q1 in list1: # q2 is each item in list2 for q2 in list2: # do not append if sublist is already …

Member Avatar for lukerobi
0
193
Member Avatar for AutoPython

Similar to jice's code: [code=python]# simply ignore index zero pos = [' '] * 11 print( pos ) POS = 1 pos[POS] = '->' print( pos ) """my display --> [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', …

Member Avatar for AutoPython
0
148
Member Avatar for kenmeck03

[QUOTE=kenmeck03;1011443]I need to prompt a user to type in a text file name and then take that file and and count the amount of words in the file. I have this code which counts the words in a file(that may not be "perfectly" written). I cannot figure out how to …

Member Avatar for bumsfeld
0
126
Member Avatar for wotthe2000

[QUOTE=ammalu;1011900]please help me to develop a program in C for the given problems? 1. Read the string and print the first letters of word? 2. Read the array elements and find the greater and smallest after sorting it? 3. Read the string and print the digits and vowels ?[/QUOTE]You are …

Member Avatar for bumsfeld
0
2K
Member Avatar for Joe Hart
Member Avatar for Joe Hart
0
123
Member Avatar for masterofpuppets
Member Avatar for ov3rcl0ck
0
137
Member Avatar for DoEds
Member Avatar for CurtisEClark

At least for some time, it would be very nice if people indicated which version of Python they are using.

Member Avatar for masterofpuppets
0
85
Member Avatar for majestic0110

[QUOTE=jbennet;595814]historically it was the other way around as loads of wemen died in childbirth[/QUOTE]On the other hand, lots of young men died as they were sent off to war.

Member Avatar for quicktpgo
1
268
Member Avatar for bumsfeld

The Python module datetime allows you to calculate the days between two given dates with relative ease. I am using the US date format month/day/year, but you can change that by giving attention to the order of the extracted tuple.

0
492
Member Avatar for bumsfeld

The wxPython GUI toolkit has a nice numeric LED widget (LEDNumberCtrl from the wx.gizmos module) that is used here for displaying the current time in very visible 7 segment LED color display. It also shows the application of the time module and wx.Timer(). The code is simple as far as …

0
2K
Member Avatar for bumsfeld

The FlashWindow component of wxPython will play those nice animated flash files found on the internet. They have file extension .swf usually.

Member Avatar for akennedy93612
0
422
Member Avatar for bumsfeld

The wxPython GUI tool makes it very simple to create nice looking analog clock. The analog clock component was put into simple dialog frame and can be moved about the screen.

0
729
Member Avatar for ~s.o.s~
Member Avatar for bumsfeld

Here we search a Python script file (or other text file) for one certain string, and copy any files containing this string to another folder.

0
213
Member Avatar for bumsfeld

Search for a file given its name and the starting search directory. The search is limited to a set depth of subdirectories. Python makes this easy to do.

0
223
Member Avatar for bumsfeld

This Python code will search for given filename starting with given directory. It will also search all the subdirectories in the given directory. The search will end at the first hit.

0
153
Member Avatar for bumsfeld

Code snippet to show you how to verify exit events from wxPython using dialog window. One event is from menu exit and the other from frame exit (x symbol in corner).

0
715
Member Avatar for bumsfeld

This short code shows how to indicate the mouse-over event on wxPython button, similar to the mouse-over in web pages. Button changes colour when mouse pointer is over its area.

0
2K
Member Avatar for bumsfeld

The myth is around that while loop is faster than the corresponding for loop. I checked it out with Python module timeit, and came to surprising conclusion. This snippet can easily be modified to time any of your functions you write.

Member Avatar for Begjinner
0
2K
Member Avatar for bumsfeld

The program takes text and establishes dictionary of character:frequency. This dictionary is then presented sorted by character. Since it is important to show the most frequent characters, two methods are given to present dictionary sorted by frequency. Should all be very good for learning Python.

0
626
Member Avatar for bumsfeld

Do you think that people act demented during full moon nights? This small python program will tell you moon phase of a date you give it, so you can take precautions!

0
4K
Member Avatar for bumsfeld

Question of wordcount program similar to Unix wc came up in the forum and I worked on a solution. Program shows number of lines, number of words, number of characters and text file's name. Good learning for commandline, file and string handling.

1
3K
Member Avatar for kharri5
Member Avatar for bumsfeld

The little program allows eye patients to test their color skills. They are given a random color rectangle by the computer and are then asked to match the color as closely as they can using sliders of the three basic colors. An evaluation button examines the closeness of the results.

0
417
Member Avatar for ShawnCplus
Member Avatar for vegaseat

I would be temded to bring the story in from a text file, but than of course you need to distrubute two files.

Member Avatar for bumsfeld
2
115
Member Avatar for bumsfeld
Member Avatar for vegaseat

Vegaseat, to keep primes from going over n, replace line s = range(3, n+2, 2) with s = range(3, n+1, 2) Henri

Member Avatar for vegaseat
1
2K
Member Avatar for bumsfeld

This program use a while loop to delete trailing spaces and tabs from a string. It is meant to be more of an example of the application of the while loop.

0
1K
Member Avatar for bumsfeld

Commonly strings consist of ASCII characters, some are printable, some are in the backgrounds like the bell, carriage return, linefeed, tab and so forth. This code displays a table of ASCII characters and the corresponding decimal value. As always, you are encouraged to learn here.

Member Avatar for bofarull
1
164
Member Avatar for bumsfeld

Just a colorful ten second countdown to New Year. Hope you can learn some code from it.

0
3K
Member Avatar for bumsfeld

My first experience with pointers. Learned how to spell a string foreward and backward using pointers. I hope you can learn too!

1
119
Member Avatar for vegaseat
Member Avatar for bumsfeld
1
181
Member Avatar for vegaseat

I do not know Python much, but I was taught that you start with Adam and Eve, not one trillion old people!

Member Avatar for vegaseat
0
198
Member Avatar for anurag_pareek
Member Avatar for maxthrill
0
119
Member Avatar for anurag_pareek

The End.