324 Posted Topics

Member Avatar for ddannieellee
Member Avatar for fonzali

I might be wrong, but code published in daniweb belongs to daniweb.

Member Avatar for fonzali
0
188
Member Avatar for azareth

Python forces you to do proper indentations. Yes, it does make the code easier to maintain. Comments only if needed for clarity.

Member Avatar for <M/>
0
248
Member Avatar for vegaseat
Member Avatar for HiHe
3
642
Member Avatar for amweasel
Member Avatar for TrustyTony
Member Avatar for HiHe

Explore the Python module bisect to search a sorted list and insert elements in the proper location in a sorted list.

Member Avatar for TrustyTony
3
636
Member Avatar for BigPaw

I don't like bloated IDEs like Eclipse. Even Eric (written in Python and PyQT) is rather large and sometimes sluggish. The small IDLE IDE that comes with Python is remarkably elegant for its size. On my Windows machine I use PyScripter (an exe written in Delphi).

Member Avatar for Lardmeister
0
270
Member Avatar for ashley9210
Member Avatar for woooee
0
494
Member Avatar for krystosan

Something like **C:\Python33\Lib\site-packages** is a directory Python will automatically look into.

Member Avatar for krystosan
0
145
Member Avatar for eminenz cw

Googling gets you to http://factspy.net/top-10-most-polluted-places-around-the-world/

Member Avatar for vegaseat
-2
109
Member Avatar for Nethral
Member Avatar for vegaseat

With the Tkinter GUI toolkit it is much simpler to use GIF files: '''Base64encodedGIF.py create a base64 encoded image string from a .gif image file changes the bytes of an image file into printable char combinations You can then copy and paste the result into your program. With Tkinter you …

Member Avatar for HiHe
5
8K
Member Avatar for shayallenhill

Something else: class HoldAttr(object): pass a = HoldAttr() print(hasattr(a, 'myattr1')) # False # create the attribute externally # unless the class uses __slots__ a.myattr1 = [] print(hasattr(a, 'myattr1')) # True # test it a.myattr1.append(1) print(a.myattr1) # [1]

Member Avatar for hughesadam_87
0
431
Member Avatar for blahblah1234las

import random # by default seeds with the system time random.seed() # random.randrange([start], stop[, step]) mylist = [] for k in range(10): # produce integers between 0 and 99 n = random.randrange(0, 100) mylist.append(n) print(mylist) print("sum = %d" % sum(mylist)) print("avg = %f" % (sum(mylist)/len(mylist))) '''possible result >>> [32, 23, …

Member Avatar for HiHe
0
127
Member Avatar for aaron.jensen.923

Using a oneliner seems to be very pythonic, but may be hard to comprehend for mere mortals. So here is an alternative with comments to help you: # each line has these space separated data # first last ID credit-hours quality-points raw_data = ''' Max Medium 12345678 58 152 Jane …

Member Avatar for HiHe
0
311
Member Avatar for hisan
Member Avatar for MissAuditore

I agree with rrashkin, the csv module is overkill here. Here is an example how you can do this with simple Python stuff: # test data showing depth, time and temperature using ';' as a delimiter raw_data = """\ Depth (m);15.08.2012 15:39:09;15.08.2012 16:09:10;15.08.2012 16:39:10;15.08.2012 16:43:36 0;53.218;52.804;52.865;51.202 0.128;53.107;52.709;52.414;52.141 1.143;52.205;51.88;51.664;51.234 2.159;51.026;50.846;50.842;51.258 3.174;50.061;50.055;50.457;50.19 …

Member Avatar for HiHe
0
236
Member Avatar for krystosan

Example: http://www.daniweb.com/software-development/python/threads/20774/starting-python/17#post1892126

Member Avatar for krystosan
0
171
Member Avatar for HiHe

Seconds since epoch should be zero, but are not: '''timetuple1.py create a time tuple for epoch 1/1/1970 00:00:00 however, seconds since epoch does not give 0 ''' import time timetuple = time.strptime("01/01/1970 00:00:00", "%m/%d/%Y %H:%M:%S") print(timetuple) print('-'*40) # seconds since epoch 1/1/1970 00:00:00 secs = time.mktime(timetuple) print(secs) '''my result >> …

Member Avatar for HiHe
0
391
Member Avatar for HiHe

Method onPaint does not change the color. Does anyone know why? (there are no errors received) # explore the wxChoice widget # a simple ComboBox (dropdown box) that combines a ListBox with an EditBox # can't get the self.onPaint method to work!!!!! import wx ID_CHOICE = 120 ID_PANEL = 130 …

Member Avatar for HiHe
0
705
Member Avatar for Triarius_1

Your sample data file has errors in it. Let's assume this is a corrected file: # uses comma + space as data separator test_data = '''\ ID, Last, First, Lecture, Tutorial, A1, A2, A3, A4, A5 10034567, Smith, Winston, L01, T03, 6, 5.5, 8, 10, 8.5 10045678, Lee, Bruce, L02, …

Member Avatar for vesuvius
0
393
Member Avatar for nUmbdA

Here is an example of how it should be done: # initial value total_sold = 0 for x in range(3): sold = int(input("Enter number of items sold: ")) total_sold += sold print(total_sold) # test If you put the initial value in the loop, it would continually reset.

Member Avatar for nUmbdA
0
211
Member Avatar for Sarah2012

Like Schol-R-LEA (Joseph Osako) pointed out the rukes have to be ''' Let's assume the rules are as follows Word length: < 3: 0 points 3-6: 1 point per character in word 7-10: 2 points per character in word 11+: 3 points per character in word ''' for you to …

Member Avatar for HiHe
0
124
Member Avatar for GrimJack
Member Avatar for M.S.

Sounds like a fun project! Another possibility: text = """\ arguing with a software engineer is like wrestling with a pig in the mud after a while you realize the pig is enjoying it """ print("Longest word = {}".format(max(text.split(), key=len)))

Member Avatar for M.S.
0
310
Member Avatar for PythonMonty

It might be simpler to have the user enter the Fahrenheit value as 32F. Your program finds the 'F' and knows that the result has to be Celsius. Conversely for Celsius values entered ...... ts = raw_input("Enter temperature like 32F or 36C : ").upper() if 'F' in ts: tf = …

Member Avatar for HiHe
0
797
Member Avatar for lewashby

It might be better to use a record than a deeply nested list, see: http://www.daniweb.com/software-development/python/code/431887/the-employee-class-record-revisited The class can be originally something like this: class Movie(): """ mimics a C Structure or Pascal Record """ def __init__(self, title, year, director, cast): self.title = title self.year = year self.director = director self.cast …

Member Avatar for ~s.o.s~
0
146
Member Avatar for GrimJack
Member Avatar for Reverend Jim

People that buy guns should first pass a mental competency test, and so should Politicians.

Member Avatar for Reverend Jim
1
394
Member Avatar for Iceman10284

This might help to get you started: http://www.daniweb.com/software-development/python/threads/32007/projects-for-the-beginner/14#post1840242

Member Avatar for HiHe
0
124
Member Avatar for 3e0jUn
Member Avatar for HTMLperson5

Mild corrections to make this work: var_file = raw_input('nof$ ') #nof, number of files. try: text = raw_input('ttwtf$ ') #ttwtf, text to write to files. print text, ">>> ", var_file except ValueError: print "Error: Not a string" #main()

Member Avatar for HiHe
1
176
Member Avatar for hughesadam_87

Here is a related example using the Python dictionary: # to simplify things create a comma separated value (CSV) file data = """\ keith,100,50,puppy bill,300,32,cat frank,200,9x9,mouse """ fname = "mydata.csv" # write the test data file with open(fname, "w") as fout: fout.write(data) # read the data in line by line …

Member Avatar for hughesadam_87
0
441
Member Avatar for nishant.rathee

Check out your python documentation under 'ctypes' or use: import ctypes help('ctypes')

Member Avatar for HiHe
0
580
Member Avatar for Frensi

Since all the troublemakers have to be imported, I would change 'os' to 'import' like this: print("A math expression is something like 3+5+7 (no spaces)") math_expression = raw_input("Enter a math expression: ") if 'import' not in math_expression: result = eval(math_expression) print("Result of %s is %s" % (math_expression, result))

Member Avatar for HiHe
0
6K
Member Avatar for 3e0jUn

You can use the Tkinter GUI toolkit that ships with Python: # KeyLogger.py # show a character key when pressed without using Enter key # arrow keys are 'Up' 'Down' 'Left' 'Right' in event.keysym # hide the Tkinter GUI window, only console shows # Python3 change Tkinter to tkinter (now …

Member Avatar for 3e0jUn
0
99
Member Avatar for HTMLperson5
Member Avatar for HiHe
0
416
Member Avatar for javanub123

You can quickly test these things out: data_text = """\ one two three """ # write the data text to a text file fname = "mydata1.txt" with open(fname, "w") as fout: fout.write(data_text) # read data back in as a text string # the with block will close the file for …

Member Avatar for HiHe
0
152
Member Avatar for pn1925

A small test code: line = 'abcdefghijklmnopqrstuvwxyz' print line print line[17] if line[17] == 'r': line = line[0:17] + 'R' + line[18:len(line)] print line '''result >> abcdefghijklmnopqrstuvwxyz r abcdefghijklmnopqRstuvwxyz '''

Member Avatar for pn1925
0
148
Member Avatar for veledrom

If you use the wxPython GUI toolkit, there is also the wxFormBuilder program, very nice and free. See the examples at: http://www.daniweb.com/software-development/python/threads/128350/starting-wxpython-gui-code/8#post1802067 http://www.daniweb.com/software-development/python/threads/259746/wxformbuilder-support-wxpython#post1129943

Member Avatar for HiHe
0
2K
Member Avatar for 3e0jUn

If you need several integer values in your file, do this: # write a test file using several integers data = """\ 177 233 567 876 """ with open('money.$','w') as fout: fout.write(data) # now read the test file back in as a list money_list = [] for line in open('money.$','r'): …

Member Avatar for HiHe
0
156
Member Avatar for Lardmeister

Well, water is not hydrogen. It takes a large amount of energy to create hydrogen from water. All Toyota Prius owners hate to see the time their super expensive battery dies on them a few years down the road.

Member Avatar for Stuugie
1
178
Member Avatar for frivolous
Member Avatar for sneekula

Once you get the hang of using the languages required indentations for blocks of code, Python is much like a pseudo language and rather powerful. Simple example: [code]food = 'fish', 'fowl', 'fruit', 'veggies', 'meat' # show all food items for item in food: print(item) # print 10 dashes print('-'*10) # …

Member Avatar for Sanchixx
0
482
Member Avatar for 4evrmrepylrning

This may help: # a basic recursive function # there is a limit to recursions # sys.getrecursionlimit() --> usually 1000 # can be changed with # sys.setrecursionlimit(x) def factorial(n): """ just an example, would be poor choice because of the many calls, each call uses another stack frame """ # …

Member Avatar for TrustyTony
0
212
Member Avatar for TrustyTony

You can keep the import local in a function: def mylocals(): import math print(vars()) mylocals()

Member Avatar for HiHe
0
308
Member Avatar for deepthought

# you have to give b an initial value # so you can increment by 1 in the loop b = 0 while b <= 10: print (b) b += 1

Member Avatar for deepthought
0
8K
Member Avatar for mozart_azul

What layout manager are you using? For instance the **grid** layout manager: # looking at the Tkinter grid() layout manager # # The size of a grid cell in a given row or column is # determined by its largest widget. # # If you give a grid layout more …

Member Avatar for mozart_azul
0
926
Member Avatar for marcin19962

# a very simple template to test PyQT widgets # PyQT free from: # http://www.riverbankcomputing.co.uk/software/pyqt/download # used Windows installer PyQt-Py3.2-x86-gpl-4.8.4-1.exe # tested with PyQT 4.8 and Python 3.2 from PyQt4.QtCore import * from PyQt4.QtGui import * app = QApplication([]) # ----- start your widget test code ---- # create the …

Member Avatar for marcin19962
0
400

The End.