4,305 Posted Topics
Re: 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. | |
Re: [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 … | |
Re: 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 … | |
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. | |
Re: You have to put your increase calculation in the loop. ![]() | |
Re: 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] | |
Re: [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. | |
Re: 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! | |
Re: Take a look at the example at: [url]http://www.daniweb.com/forums/showthread.php?p=1056184#post1056184[/url] | |
Re: 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] | |
![]() | Re: Also take a look at: [url]http://www.daniweb.com/forums/post1055261.html#post1055261[/url] for a mildly more general version. ![]() |
Re: 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 … | |
Re: All I can think of is that a tuple is an immutable object and a dictionary is a mutable object. | |
![]() | Re: 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. |
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 … | |
Re: If you use Linux, be aware that filenames are case sensitive. | |
Re: 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] | |
Re: Study up on regex then ... [url]http://www.amk.ca/python/howto/regex/[/url] Give attention to section [B]Search and Replace[/B] | |
Re: 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. | |
Re: 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] | |
Re: 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? | |
Re: 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, … | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: [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 … | |
Re: [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 … | |
Re: 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 ' | |
Re: 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) # … | |
Re: Use something like that ... [code]s = "My Title" width = 70 s = s.center(width) print( s ) [/code] | |
Re: Looks like I need to mark this thread. | |
Re: If you use Python3, then you can display what range(1, 10) iterates over with this ... [B]print( list(range(1, 10)) )[/B] | |
Re: 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. | |
Re: 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 … | |
Re: I trust that by now you have figured out that names in Python are case sensitive. | |
Re: 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 … | |
Re: For Windows7 gadgets you might have to wait for the new wxPython. | |
Re: 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 … | |
Re: [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 … | |
Re: You might take a look at USB Central [url]http://www.lvr.com/usb.htm[/url] USBs like to use drivers. | |
Re: 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] … | |
Re: 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] | |
Re: 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 … | |
Re: 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 … | |
Re: 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] |
The End.