851 Posted Topics
Re: Here is an example how to write your program in OOP style. Look no global stuff! Study the details. ''' class_word_game1.py guess the word game using Object Oriented Programming (OOP) ''' import random # avoids using raw_input() for strings # code can be used with Python2 or Python3 try: input … | |
Re: You could add a QWidget to its center area and then go on with the familiar layouts in that widget. Kind of cumbersome. Might as well go with Qwidget rigth away. | |
Re: A happy New Year to all of yous! May the world be more nutty this year! | |
Re: Try this: s = '''\ good film stunt scheduling i think ''' mylist = s.split() print(mylist) s2 = mylist[0] + '\n ' + " ".join(mylist[1:]) print(s2) | |
| |
Re: This should get you partway there: import os import pprint data_str = '''\ 00001.doc d:\pathtofile\image50.jpg 00002.doc d:\pathtofile\image38.jpg 00003.doc d:\pathtofile\image40.jpg ''' data_list = [] temp_list = [] for ix, line in enumerate(data_str.split()): #print(line, len(temp_list), ix, ix%2) # test if ix % 2 == 0: temp_list.append('a' + line) if ix % 2 … | |
Re: I can imagine that an employer gets real excited about hiring you, when you show up covered with tattoos. | |
![]() | |
Re: It would be nice to get anything Apple makes. I would settle for one day nobody gets shot. | |
Re: Just to leave no stone unturned: import random mylist = [] for x in range(100): if random.randint(1,10) == 3: mylist.append(3) print(len(mylist)) | |
Re: Another way, but you can use it only one time: # allows Python27 to use Python3 print options from __future__ import print_function def text_xy(text, x, y): '''print the text at location x, y''' xx = " " * x yy = '\n' * y print(yy, end="") print(xx, end="") print(text) text … | |
Re: I would go with Python. Free from http://www.python.org/download/ IDLE is a simple IDE that comes with the Python installation. You can write your program in the IDLE editor, save and run. For small code experiments you can use the Python shell option (has >>> prompts). If you just want to … | |
| |
Re: Assuming filenames are unique, create a Python dictionary where the filenames are the keys: `mydict = {"file1": ("val0", "val1", "val2"), "fil2": ("val10", "val11", "val12"), ...}` and then use Python module shelve to create a 'persistent to file' dictionary. Here is an example of module shelve: ''' Shelve_test1.py use a Python … | |
Re: Trying to make mild improvements: ''' list_closest_pair3a.py find the closest pair of numeric elements in a list Python27/Python33 experiments ''' import mpmath as mpm def closest_pair1(mylist): ''' return the closest pair of numeric elements in mylist original by snippsat ''' # make elements unique and sort lst = sorted(set(mylist)) # … | |
Re: If you want to use a class attrribute, don't make it private with the double underline prefix. Also make sure that ni_number is an integer, if you want to use it as such. Here is the corrected code example: # format: ni_number firstname lastname age data_str = '''\ 55512 Bart … | |
Re: A tutorial on the GUI toolit Tkinter (comes with your Python installation) and using class objects: http://zetcode.com/gui/tkinter/drawing/ | |
Re: Recursion calls the function from within the function with an adjusted parameter. Example: def remove_char_right(mystr, num, count=0): """ remove num of characters to the right of a string """ print("{} {}".format(count, mystr)) # test # exit condition, return the final result if count >= num: return mystr mystr = mystr[:-1] … | |
| |
Re: Please gives us the total Traceback Error Message. | |
Re: Use the filehandle f not filename | |
Re: You can go from there: # data format: # productcode, pricea, qtya, priceb, qtyb, # pricec, qtyc, priced, qtyd, pricee, qtye data = '''\ aa,10,5,9,10,8,50,7,100,6,500 ab,10,5,9,10,8,50,7,100,4,500 ba,10,5,9,10,8,50,8,100,6,500 bb,10,5,9,10,8,50,6,100,6,500 ca,10,5,9,10,8,50,7.5,100,6,500 cb,10,5,9,10,8,50,7.3,100,6,500 cc,10,5,9,10,8,50,7.2,100,6,500 ''' fname = "price_data.csv" # write the test file with open(fname, "w") as fout: fout.write(data) # read the test … | |
Re: It would be helpful to tell us which GUI toolkit and layout manager (boxsizer, gridsizer etc.) you used | |
Re: I bet you that there isn't a person with an IQ over 30 amongst this sorry lot of humanity. | |
Re: Get the module graphics.py from: http://mcsp.wartburg.edu/zelle/python/graphics.py Here is a wintery example: '''gr_SnowMan1.py draw a snowman with module graphis.py (based on Tkinter) http://mcsp.wartburg.edu/zelle/python/graphics.py newer version works with Python2 and Python3 ''' from graphics import * def main(): # drawing canvas/window with title and size win = GraphWin("Snowman",400,500) top = Circle(Point(200,115), 45) … | |
Re: Put in line pygame.time.wait(1000) as your last line to slow down the update | |
Re: Golf anyone? Or is it Underwater Basket Weaving on TV? | |
Re: The Python module base64 allows you to convert image data to a string that can be included in your code. Here is an example from vegaseat I saved a while ago: # playing with wxPython's # wx.BitmapButton(parent, id, bitmap, pos, size, style) # for a small image it is best … | |
Re: A good example of using pickle with a class. | |
Re: Where does module gst come from? Maybe it is written with a different version of GTK then Ubuntu uses. | |
Re: Just as an exercise: ''' use very basic Python syntax to form a list of strings and process ''' import sys # make string input work with Python2 or Python3 if sys.version_info[0] < 3: input = raw_input def makeList(num): ''' store the strings input in a list ''' alist=[] for … | |
Re: You want to create a list of [name, year, day. month] lists. | |
Re: Looks like the Python3 series is rapidly progressing. The release schedule for Python34 has already been announced. Might be best to stick with Python27 until Python37 comes out. I like the Python3 new features, so I am using it. Sometimes it's a pain converting old code. If you have a … | |
Re: Clean it up a little: def display_player(): team = raw_input("Which team is the player (A or B): ") position = raw_input("Which position: ") return team, position team, position = display_player() sf = "Player is on team %s in position %s" if team in 'AB': print sf % (team, position) else: … | |
Re: Thanks Gribouillis, to make your code example work with Python3 I modified it a little: '''tk_base64_jpg_image1.py use a base64 encoded non-gif image with Tkinter and PIL tested with Python27 and Python33 ''' import base64 import io from PIL import ImageTk, Image try: # Python2 import Tkinter as tk except ImportError: … | |
Re: This could help: '''sort_dictionary_list1.py sort a list of dictionaries by a value with a helper function ''' import pprint def sort_by_age(d): '''a helper function for sorting''' return d['age'] d_list = [ { 'name' : 'frank', 'age' : 24, }, { 'name' : 'joe', 'age' : 21, }, { 'name' : … | |
Re: According to http://www.wxpython.org/download.php wxPython has not been ported to Python3 yet. However, PySide/PyQT is available for all versions of Python. Tkinter and its extensions tix and ttk are included in Python27 and all higher versions. | |
Re: Try http://www.daniweb.com/software-development/vbnet/58 | |
Re: This line in main(): **average = calc_average(first, second, third, forth, fifth)** should have the variable names given in main(): **average = calc_average(test1, test2, test3, test4, test5)** | |
Re: On Linux filenames are case sensitive, so check that too. | |
Re: What kind of GUI toolkit are you using? | |
Re: Try this: import random class Location(object): def __init__(self, index, desc, lootvalue=0, loot_type=0): self.index = index self.desc = desc self.lootvalue = lootvalue self.loot_type = loot_type #self.nuetralmobspawn = nuetral_mob_spawn #self.passivemobspawn = passive_mob_spawn #self.hostilemobspawn = hostile_mob_spawn def __repr__(self): text = "Location: %s" % self.desc text += ", Index: %s" % self.index text += … | |
Re: You mean something like this: # your Python3 program ... # for Python2 use raw_input input("Press enter to go on ... ") # this would be Python's input python = "Python is great!" print(python) | |
Re: Take a peek at this: http://blog.carduner.net/2011/09/06/easy-facebook-scripting-in-python/ | |
Re: You might want to take one look at: http://www.daniweb.com/software-development/python/threads/20774/starting-python/9#post796257 | |
Re: You can also look at a class as a collection of functions/methods that belong together. Once a class is established it can be inherited by other classes. This can save you a lot of coding. | |
The End.