851 Posted Topics

Member Avatar for <M/>
Member Avatar for bulleh

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 …

Member Avatar for bulleh
0
254
Member Avatar for krystosan

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.

Member Avatar for krystosan
0
1K
Member Avatar for movielinks

A happy New Year to all of yous! May the world be more nutty this year!

Member Avatar for TracyPortner
0
222
Member Avatar for thanadaray

Try this: s = '''\ good film stunt scheduling i think ''' mylist = s.split() print(mylist) s2 = mylist[0] + '\n ' + " ".join(mylist[1:]) print(s2)

Member Avatar for Lucaci Andrew
0
132
Member Avatar for woooee
Member Avatar for giancan

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 …

Member Avatar for vegaseat
0
187
Member Avatar for Ancient Dragon

I can imagine that an employer gets real excited about hiring you, when you show up covered with tattoos.

Member Avatar for happygeek
0
287
Member Avatar for rbyrd
Member Avatar for ImZick

It would be nice to get anything Apple makes. I would settle for one day nobody gets shot.

Member Avatar for kemcar
1
351
Member Avatar for efwon

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))

Member Avatar for snippsat
0
234
Member Avatar for slasel

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 …

Member Avatar for Lardmeister
0
109
Member Avatar for nitin1

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 …

Member Avatar for nitin1
0
526
Member Avatar for slasel
Member Avatar for giancan

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 …

Member Avatar for ZZucker
0
325
Member Avatar for vegaseat

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)) # …

Member Avatar for Lardmeister
5
756
Member Avatar for biancairis93

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 …

Member Avatar for Lardmeister
0
127
Member Avatar for JohnnyBoy324

A tutorial on the GUI toolit Tkinter (comes with your Python installation) and using class objects: http://zetcode.com/gui/tkinter/drawing/

Member Avatar for Lardmeister
0
28
Member Avatar for june.pierre.311

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] …

Member Avatar for vegaseat
0
345
Member Avatar for slasel
Member Avatar for vegaseat
0
243
Member Avatar for redcar2228
Member Avatar for That.T3rr11
Member Avatar for TeaAnyOne
Member Avatar for biscayne

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 …

Member Avatar for biscayne
0
318
Member Avatar for Aiban

It would be helpful to tell us which GUI toolkit and layout manager (boxsizer, gridsizer etc.) you used

Member Avatar for Aiban
0
229
Member Avatar for Ancient Dragon

I bet you that there isn't a person with an IQ over 30 amongst this sorry lot of humanity.

Member Avatar for <M/>
1
181
Member Avatar for MissAuditore
Member Avatar for ashley9210

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) …

Member Avatar for woooee
0
198
Member Avatar for Frensi
Member Avatar for Lardmeister
0
167
Member Avatar for eminenz cw
Member Avatar for giancan

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 …

Member Avatar for Lardmeister
0
478
Member Avatar for vegaseat
Member Avatar for darkwing

Where does module gst come from? Maybe it is written with a different version of GTK then Ubuntu uses.

Member Avatar for Lardmeister
0
176
Member Avatar for ohmang841

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 …

Member Avatar for Lardmeister
0
9K
Member Avatar for elrond
Member Avatar for BigPaw

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 …

Member Avatar for Lardmeister
0
269
Member Avatar for Vusumuzi

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: …

Member Avatar for Vusumuzi
0
156
Member Avatar for vegaseat

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: …

Member Avatar for HiHe
5
8K
Member Avatar for premminister

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' : …

Member Avatar for Lardmeister
0
11K
Member Avatar for lewashby
Re: wx

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.

Member Avatar for Lardmeister
0
136
Member Avatar for Matigo
Member Avatar for nUmbdA

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)**

Member Avatar for Lardmeister
0
332
Member Avatar for nickick
Member Avatar for chao.lee.927
Member Avatar for apayn

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 += …

Member Avatar for Lardmeister
0
167
Member Avatar for apayn

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)

Member Avatar for Lardmeister
0
212
Member Avatar for ThePythonNoob

Take a peek at this: http://blog.carduner.net/2011/09/06/easy-facebook-scripting-in-python/

Member Avatar for Lardmeister
0
63
Member Avatar for sick vapor

You might want to take one look at: http://www.daniweb.com/software-development/python/threads/20774/starting-python/9#post796257

Member Avatar for sick vapor
0
2K
Member Avatar for Blacktono4

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.

Member Avatar for Lardmeister
0
347
Member Avatar for BigPaw

The End.