15,181 Topics
| |
I'm writing a code to minimize a function and I'm having problems storing the new move. [CODE]import math import random #minimze the function: def f(x): return math.pow(x,2) + math.sin(10*x) x_list=[] energy_list=[] g=2 #starting position def move(): #Generate a random move random.uniform(-0.5,0.5) def energy(): h=g+move() #generate random move E = f(g)-f(h) … | |
Is it possible to read and write to a queue at the same time? for example, one thread is using put() and another thread get() on the same queue? When threading, I've added the task_done() but queue.join() seems to wait for all jobs to finish before the main thread continues. | |
Hi, I am new to python and am wondering is it possible to name a method after a variable. I know I can name a variable after another variable using [code=python] test = "temp" vars()[test] = 123 print temp [/code] this will print 123. so I was thinking something like … | |
Hi, myself and two of my friends are creating a game that imitates that of Whack-a-mole. I am trying to implement code so that when I click on the mole with the mouse, the image changes to a different image, eg. the image when just moving the mouse is a … | |
[CODE] class Player(object): def __init__(self): self.points = 0 def add_points(): plyr1.points += 1 plyr2.points += 1 plyr3.points += 1 if __name__ == '__main__': (plyr1, plyr2, plyr3 = (Player(), Player(), Player()) add_points()[/CODE] How could the 3 lines in add_points() be written better/shorter? | |
Hey All, am looking for a way to break an xml Tag line into tag and attributes. Say I have This line [code=xml] <event time="12:30" value="This is a Sample Value" type="event"> </event> [/code] I have this so far [code=python] # Open file to read f=open("myTest2.xml") #start reading File for line … | |
Hi all, after many hours, I decided to ask my question. I'm making an editor for the ABC music notation language. It is not a supported language in the standard wx.stc lexers. It should be possible to add my own lexer, but how do I do it? If it is … | |
Hey, I have a function, though it's not working as it should be. My program is Dijkstra's algorithm, and I am trying to build a list of a node's nearest neighbours using info contained in a text file of the network (7 nodes in this case), in the form: 0,2,4,1,6,0,0 … | |
Hi all,i can send AT commands to my phone(over Bluetooth) using Hyper Terminal.I am trying to do the same process using python.So here is my code: [CODE]import time import serial # configure the serial connections (the parameters differs on the device you are connecting to) ser = serial.Serial( port='COM8', baudrate=2400, … | |
I am using python in win32 enviornment.i wanna add extra library for using serial port.So i have downloaded the lib for windows env. The package is installing fine.But when ever i import serial following error i get.Can anyone please help me out... [CODE]>>> import serial Traceback (most recent call last): … | |
Hello, how i can creat menu in wx.ListCtrl(), for example when i double click in item list, i return menu like for wx.Menu(). | |
hi all, I am trying to make a prog. which will download image from a web site.But the problem is the dynamic nature of the web site. The url is like [url]http://www.site.com/image.aspx?id=445[/url] If i wanna access image 1,2 or anything i can change the id and i can view the … | |
i am using a template which is working fine with mozilla, but it shows allignment problems with safari, is there any code to make templates cross - browser compatible. | |
I am having problems accessing a variable from one class to another. [CODE] class Player(pygame.sprite.Sprite): def rotateShip(self, rotAmt): radians = self.rotation * math.pi / 180 [/CODE] I am trying to use the variable radians from class Player to another class. radians only exists in 'rotateShip'. Thanks for your help in … | |
I everyone, I need help with making a program where the program would allow anyone to type in a certain weight of a package and the output would come out with a pricing. I will attach the detailed instructions to this thread. Help would be appreciated! This is what I … | |
hello all, i'm new to python programming and i'm facing a problem and need ur help i finished my script and i'm trying to execute it on windows cmd the script takes a file as an argument , when i run the script with the argument it works very well … | |
Hi All I have just started using a subprocess.call()to call external commands. I want to call R from command line and that I can do it easily by subprocess.call('Rscript script.R') and it works fine. I want to pass the several arguments instead of using default arguments. I tried using Rscript … | |
I have been working on pygame for awhile, and now I am working on making a fairly complex space ship game. I want the player to be able to go forward with 'w' and steer by rotating the ship with the 'a' and 'd'. I've tried pygame.transform.rotate, but it makes … | |
hello. I am quite new in python so i have a question. I have a csv file in which i have names of 30 cities and their coordinates(lat and long). i want to generate a distance matrix for these cities. How can i do this ? | |
Hello, I want to write to a file in a particular format. There should be 2 columns, the first column should allocate 5 spaces to store digits and the next column should allocate 30 spaces to store characters. Ex:- [code] 1 Dave 234 Einstein 100000 Bob . . . [/code] … | |
Recently I have been learning about the socket module and how you can create networking applications using it. I was curious if it would be possible using the socket module to either: Set the port as a USB port to trick the computer into thinking a USB is plugged in … | |
How would you go about extracting part of a key from a dictionary. I have a text file that lists about 1000 birthdays Ex. 1/2/1980 I want to extract just the year portion from the dictionary and then run a count against each year. I have no problems with any … | |
My code tries to solve an optimization problem constrained to hyperbolic PDE by matching a numerical solution to a desired one. The basic idea is that: I've initial condition "U" as input which is being updated by this line: U = Initialize(Update_Design_Parameter(U)). I expect that updated U will affect all … | |
Hello all. I am new to programming, taking my first class in college. Im enjoying it a lot so far, and much of the info on daniweb has been a huge help. Due to some unforeseen circumstances, I had to miss class and am now having some troubles with a … | |
Hello, I have some code that passes arguments between functions, though I am failing to understand why my code isn't working. This is the relevant section of my Dijkstra's algorithm code: [CODE]def network(): f = open ('network.txt', 'r') network = [[int(node) for node in line.split(',')] for line in f.readlines()] print … | |
Hello, I am having some trouble in working out the distance of each node from the starting node in my Dijkstra Algorithm code. Here is my code with the section i'm stuck on in bold: [CODE]infinity = 1000000 invalid_node = -1 startNode = 0 class Node: distFromSource = infinity previous … | |
Ok, so I pretty much have my program up and running, but it's not the best looking program aesthetically, and I am trying to do a couple of things to make it look better, and none of them are working. Here is what I want to do. 1) change the … | |
Hey everyone. I would really appreciate some help. I'm currently building a program in Python 2.6 for an introductory Comp Sci class. The program is supposed to use functions to read a text file from a URL, parse the data into tokens, and use the data to calculate a sort … | |
Hey !can somebody help me how to create a incremental search(numerical method) program using python! | |
Hey, I am doing a 'Helicopter'-style game for a project where the player holds the spacebar for the main sprite to go up, releases to go down. Objects come from the right side of the screen at random y-cords moving until they hit 0 on the x-cord. The player must … |
The End.