4,305 Posted Topics

Member Avatar for bsod1

Can you tell us in detail what you understand under [B]advanced[/B] code completion? Note (so you don't waste your time): bpython uses Linux's curses and does not work with Windows.

Member Avatar for AutoPython
-1
92
Member Avatar for MRWIGGLES

[QUOTE=MRWIGGLES;1057518]Is there a more simplistic way to do this without having to import things? I'm a beginning at Python.[/QUOTE]You really don't need a queue, a list will do fine. Here is a more simple version of Gribouillis' code that actually works in Python2 or Python3 ... [code]# extract tag names …

Member Avatar for vegaseat
0
214
Member Avatar for Archenemie

I modified the program slightly for testing, but this work just fine ... [code]#!/usr/local/bin/python import re, os from os.path import join as pjoin, isdir while True: #targetfolder = raw_input('enter a target folder:\n').strip() targetfolder = "D:/Renamer3" # for testing only if isdir(targetfolder): break else: print("you must enter an existing folder!") newname …

Member Avatar for Archenemie
0
217
Member Avatar for vegaseat

This code snippet shows you how to sort more complicated objects like a list of lists (or tuples) by selecting an index of the item to sort by.

Member Avatar for Ene Uran
2
375
Member Avatar for Ancient Dragon
Member Avatar for jaison2
Member Avatar for Yeen

You are using old style Python code! Long ago it used to be like this ... [code]import string a = "Why does string.split() not work?" x = string.split(a) print("SUCCESS!", x) [/code]... now it's like this ... [code]a = "Why does string.split() not work?" x = a.split() print("SUCCESS!", x) [/code]

Member Avatar for vegaseat
0
3K
Member Avatar for lewashby

[B]__str__()[/B] does operator overloading in a class and "hijacks" [B]str()[/B] in any class instance operation that uses [B]str()[/B]. So [B]print crit1[/B] will use it, because it uses [B]str()[/B] to make it printable. Whereas [B]crit1.name[/B] is already printable.

Member Avatar for mn_kthompson
0
203
Member Avatar for ffs82defxp

You can use function exec() ... [code]# create variables num1, num2, num3 and num4 and set to 77 for n in range(1, 4): exec( "%s = %d" % ('num' + str(n), 77) ) print(num1) # 77 print(num3) # 77 [/code]Doing something like this is not recommend!

Member Avatar for vegaseat
0
130
Member Avatar for ffs82defxp

Take a look at the example at: [url]http://www.daniweb.com/forums/showthread.php?p=1056184#post1056184[/url]

Member Avatar for vegaseat
0
122
Member Avatar for gangster88

Will be less complex with a for loop and range(start, end, step) starting at the high value, ending at the low value (exclusive) and stepping -1 ... [code]n = 3 for x in range(n, 0, -1): print str(x)*n """result --> 333 222 111 """ [/code]

Member Avatar for vegaseat
0
147
Member Avatar for masterofpuppets

Also take a look at: [url]http://www.daniweb.com/forums/post1055261.html#post1055261[/url] for a mildly more general version.

Member Avatar for masterofpuppets
0
5K
Member Avatar for saikeraku

When you use [B]a.extend(b)[/B] or [B]a.sort()[/B] then list a is changed, since both are [B]inplace[/B] functions. Also when you pass a list to a function argument, be aware that the list is a mutable object and changes of a mutable object within the function will feed back. The reason is …

Member Avatar for saikeraku
0
92
Member Avatar for sneek

All I can think of is that a tuple is an immutable object and a dictionary is a mutable object.

Member Avatar for sneek
0
416
Member Avatar for TheManual
Member Avatar for Mouche

Sorry LaMouche, I think we were thinking the same thing at the same moment. Take a look at [url]http://www.daniweb.com/techtalkforums/thread59965.html[/url] I was thinking of changing the hitlist itself depending on weapon, armor or monster.

Member Avatar for python user
0
267
Member Avatar for vegaseat

Here is an example I was thinking of ... [code=python]import random import time def delay(seconds): time.sleep(seconds) def shuffle_hitlists(my_hitlist, mo_hitlist): """shuffle the two lists and return the result""" random.shuffle(my_hitlist) random.shuffle(mo_hitlist) return my_hitlist, mo_hitlist def battle(my_hitlist, mo_hitlist, my_strength, mo_strength): # player starts swinging first for k in range(len(my_hitlist)): my_hit = my_hitlist[k] mo_hit …

Member Avatar for python user
0
732
Member Avatar for emir_gradacac
Member Avatar for python user
-1
211
Member Avatar for njam
Member Avatar for mahela007

You can play with this ... [code]# test Python command line arguments import sys if (len(sys.argv) >= 2): # skip sys.argv[0] commandline_args = sys.argv[1:] print( commandline_args ) raw_input("Press Enter to go on ...") # wait """my output for args 1 2 3 --> ['1', '2', '3'] """ [/code]

Member Avatar for mahela007
0
97
Member Avatar for ov3rcl0ck

Study up on regex then ... [url]http://www.amk.ca/python/howto/regex/[/url] Give attention to section [B]Search and Replace[/B]

Member Avatar for jlm699
0
109
Member Avatar for scrace89

If you make the regular polygon a square with side length = 1.0, you should get an area of 1.0. A simple test to see if the area formula is correct.

Member Avatar for vegaseat
0
121
Member Avatar for sanchitgarg

Another way to solve this is to use string function isdigit() ... [code]while True: num = raw_input("Enter an integer: ") if num.isdigit(): num = int(num) break print "Try again, value you entered was not an integer." print(num) [/code]

Member Avatar for sanchitgarg
0
85
Member Avatar for Dark_Omen

Pure genius Dark! Here is the same in Python ... [code] print "Hello, World! I am writing in the Python programming language" [/code] How are your C# efforts coming along?

Member Avatar for pkc
0
426
Member Avatar for Vector_Joe

A dictionary will serve you better ... [code]# create a large number of spheres referencing them # with a (x, y):sphere_object dictionary pair import visual as vs spheres = {} for x in range (0, 100): for y in range (0, 100): z = 0 spheres[(x, y)] = vs.sphere(pos=(x, y, …

Member Avatar for bumsfeld
0
854
Member Avatar for Dani
Member Avatar for AndreRet
1
430
Member Avatar for Musafir

If you want to start with the population after 1/2 year, then every year you have to change your code to this (Python2 or Python3) ... [code]def populationGrowth(): x = int(input("What is the current population: ")) y = 0.08 x = int(x * (1 + y/2)) # population after 1/2 …

Member Avatar for woooee
0
115
Member Avatar for tlj333

I assume your error is here ... [code]def print_list(names): print 'Here are the names in the original order:' for names in name_list: # <-------- print names names.sort() print 'Here are the names sorted:' for names in name_list: # <------- print names [/code]Change it to ... [code]def print_list(names): print 'Here are …

Member Avatar for vegaseat
0
130
Member Avatar for Aiban

Here is the story: In Python2 Tkinter is a Python module file named Tkinter.py a wrapper for the TCL code Tkinter is written in. With the advent of Python3 Tkinter became a more modern package called tkinter. Python version 3.1 started to include a wrapper for the Tkinter Tile Expansion …

Member Avatar for Aiban
0
141
Member Avatar for lewashby

The use of the new style class had a practical implication, it allowed the use of __slots__ as shown in this example ... [code]class Oldstyle: def __init__(self): self.a = 1 self.b = 2 self.c = 3 print(self.__dict__) # {'a': 1, 'c': 3, 'b': 2} class Newstyle(object): """ __slots__ prevents new …

Member Avatar for mn_kthompson
0
131
Member Avatar for lewashby

[QUOTE=Garrett85;1047297]Does anyone know where I can find a goo pdf python reference for the following? pre built constructors, functions/methods for the follwoing tuples, lists, dicts...etc I hate reading a book with nothing but quick explanation, I want to see them for myself. And I already know how to find them …

Member Avatar for python user
0
187
Member Avatar for Musafir

[QUOTE=Musafir;1049234]I am writing a function that has two parameters F & L and the function returns the sum of the squares of all the intergers between F & L e.g if i call def sum(3,5) should output 50 (9 + 16 + 25) def sum(first,last): sqaure = i for i …

Member Avatar for snippsat
0
118
Member Avatar for hdk

Try something like this ... [code] #plt.show() plt.savefig("test.png") # create an internal image image = wx.Bitmap("test.png") # show the image as static bitmap wx.StaticBitmap(self, wx.ID_ANY, image) perf_plot = 'test.png' [/code]Also correct the error in line 63, needs a closing '

Member Avatar for hdk
0
1K
Member Avatar for python user

Pygame can load quite a number of image formats. Here is an example ... [code]# experiments with module pygame # free from: http://www.pygame.org/ # load and display an image using pygame import pygame as pg # initialize pygame pg.init() # pick an image you have (.bmp .jpg .png .gif) # …

Member Avatar for vegaseat
0
114
Member Avatar for persianprez

Use something like that ... [code]s = "My Title" width = 70 s = s.center(width) print( s ) [/code]

Member Avatar for Stefano Mtangoo
0
106
Member Avatar for AutoPython
Member Avatar for jwxie

If you use Python3, then you can display what range(1, 10) iterates over with this ... [B]print( list(range(1, 10)) )[/B]

Member Avatar for vegaseat
0
82
Member Avatar for Fetch

There are certain characters a file name can not have, might depend on the OS. On Unix you have to have permission to write to some of the directories.

Member Avatar for vegaseat
0
97
Member Avatar for gangster88

You could do something simple like this ... [code]from graphics import * import random def drawCircle(win, centre, radius, colour): circle = Circle(centre, radius) circle.setFill(colour) circle.setWidth(2) circle.draw(win) def drawEye(win, centre): drawCircle(win, centre, 40, "green") drawCircle(win, centre, 20, "brown") drawCircle(win, centre, 10, "blue") def createWin(): w = 250 h = 250 win …

Member Avatar for vegaseat
0
156
Member Avatar for Polar67
Member Avatar for vegaseat
0
91
Member Avatar for lewashby

Don't worry about adding (object) right now. It is only needed in special cases, and that need is gone in Python3 anyway. Here is an example class that should explain some of your questions ... [code]class MyClass: def __init__(self, animal, sound): """ The constructor __init__() brings in external parameters when …

Member Avatar for vegaseat
0
89
Member Avatar for Aiban
Member Avatar for vegaseat
0
81
Member Avatar for mahela007

IMHO, a dictionary would be the way to go ... [code]str_dict = {} count = 1 while True: mystr = raw_input("Enter a string (just Enter to quit): ") if not mystr: break str_dict[count] = mystr count += 1 # test print(str_dict) # show string at key 2 key = 2 …

Member Avatar for mahela007
0
111
Member Avatar for hockfan86

[QUOTE=hockfan86;1044763]High Score Keeper 0 - Quit 1 - List Scores 2 - Add a Score Please choose an option (0-2): 2 Traceback (most recent call last): File "/Users/benjaminholcomb/NetBeansProjects/lab9/src/lab9.py", line 34, in <module> line = inFile.readline() NameError: name 'inFile' is not defined[/QUOTE]Your program does not know inFile because it is tucked …

Member Avatar for hockfan86
0
122
Member Avatar for paul2594

You might take a look at USB Central [url]http://www.lvr.com/usb.htm[/url] USBs like to use drivers.

Member Avatar for nokki
0
2K
Member Avatar for A_Dubbs

Back to the original code, this would have made more sense ... [code]class Player: """Enter name as string""" def __init__(self, playername): self.name = playername def getName(self): return "I am %s" % self.name # create the class instance bob bob = Player("Bob") print(bob.name) # Bob print(bob.getName()) # I am Bob [/code] …

Member Avatar for bumsfeld
1
230
Member Avatar for TheManual

You need to test the logic in your if statements like [B]if mystr in accepted:[/B] Here is a little test ... [code]accepted = '0123456789dr+-*/%^=' mystr = '2' print(mystr in accepted) # True mystr = '27' print(mystr in accepted) # False ouch!!! [/code]

Member Avatar for TheManual
0
92
Member Avatar for mahela007

That depends on what kind of graphics you are talking about. If yo just want to draw lines and circles and so on, you can use Jim Zelle's module graphics.py, a free download from: [url]http://mcsp.wartburg.edu/zelle/python/graphics.py[/url] This module is a thin wrapper for Tkinter and may appeal to you because of …

Member Avatar for mahela007
0
261
Member Avatar for jex89

I would not mess with the pickle file directly. Better load (unpickle) the file, do your changes and then dump (pickle) it again. If the pickled file was created using protocol=0, then you can look at the pickled file with a regular text editor, see if you can find the …

Member Avatar for pythopian
0
3K
Member Avatar for jaison2

Strange, works fine for me. You do use Python2, do you? You may want to put a console wait line at the end, something like ... [code]raw_input("Press Enter to go on ... ") [/code]

Member Avatar for snippsat
0
224

The End.