15,175 Topics
| |
I'm new to this forum and to python in general, so be easy on me please. :icon_smile: I'm making a class to handle all events including mouse events. (I'm using pygame by the way) Heres how it looks so far: [CODE] class Event: #controlls all actions relating to events including … | |
If I have a text file that contains strings and integers such as: Alabama 3200 Denver 4500 Chicago 3200 Atlanta 2000 what code could I use to print the smallest number (2000) after reading in that textfile. I know I first have to split the text so I'm just operating … | |
I should be getting this as my output, but it keeps going through each result: [CODE]10 -> 5 -> 16 -> 8 -> 4 -> 2 -> 1 ; length = 7 11 -> 34 -> 17 -> 52 -> 26 -> 13 -> 40 -> 20 -> 10 -> … | |
I have written a script for scraping a web site, and it works fine. What does not work fine, is when I try to use the write function, to write the results to a txt-file. I am trying to run this: import BeautifulSoup, urllib2, re, time import codecs path='C:/Users/Me/Documents/Python' outfile=open(r'C:/Users/Steinar/Documents/Python/Vegvesen/vegresultat.txt', … | |
This is one simple way to emulate a singleton class on behalf of a normal class. (A singleton class is a class with at most one instance.) The implementation does not emulate a class 100% (for example it lacks the special attributes lile __dict__ or __bases__), but it should be … | |
Hello everyone, I'm learning Python and I have a few questions about Dictionaries and sorting them by a value other than the key. Lets say, for example, I have a Dictionary full of data that needs to be sorted on the 3rd value instead of the key. How would I … | |
I have a file of the following format: a 1 a 2 a 3 b 4 b 5 b 6 c 7 c 8 c 9 Here is my code: [CODE]def file_to_dict(fname): f = open("file.txt") d = {} for line in f: columns = line.split(" ") letters = columns[0] numbers … | |
i have to write a rock paper scissors program in python, but every time i run my code... [CODE]def rockPaperScissors(): import random computerIndex = random.randint(1,3) if computerIndex == 1: computer = "rock" elif computerIndex == 2: computer = "scissors" else: computer = "paper" player = raw_input("rock, paper or scissors :") … | |
Hi, may anybody tell me what "initializes the interpreter" mean in detail? Does this function starts a new process or thread of the python interpreter in the background or what does this call do?? Hopefully somebody can give me a little hint :) Jonny | |
Hi all, I want to take this code: [CODE]list_in_list = [[1,5,13,30,-4], [1,5,10,30,-4], [1,5,15,30,-4], [1,5,9,30,-4], [1,5,16,30,-8]][/CODE] and sort it by the 3rd item in each sublist (list_in_list[x][2]) I'd like to do it by the highest number so my output would be: [CODE]sorted_list_in_list = [[1,5,16,30,-8],[1,5,15,30,-4], [1,5,13,30,-4],[1,5,10,30,-4], [1,5,9,30,-4]][/CODE] Any help or suggestions? | |
I have a dictionary like {"a":["b", "c", "d"], "b":["h", "i", "j"], "c":["k", "l", "m"]. I need to write a function that returns True if a requested key has requested value. Also, if "a" has "b" and "b" has "h", "i", and "j", then "a" has "b", "c", "d", "h", "i", … | |
I am new to programming (but not to the concepts) and I need to process some .csv files. Here's what I have: The files containing Cartesian coordinates, XYZ of various "polygons." (They are cell perimeters of a mouse embryo) The polygons are in quotes because they are not closed, and … | |
Hi, I'm stuck with a certain problem. I'm using URLLIB2 to get the end url of a list of links. This was pretty straightforward. Some of the links I'm probing pass through 1 or more other urls before landing the user at the end destination. For example, the start url … | |
Hi, I'm a newbie! I'm writing because I have a question about wxpython and trasparency... I'm trying to design a visible frame with a trasparent window inside it (think about a sort of "window" in which you can see the desktop). With SetTrasparent() on the wxFrame the entire frame becomes … | |
is it possible to search a multi dimensional list for a certain letter then print out where that letter is? i know u can use list.index() to find a letter but i could figure out how to do it with multi dimensional lists. thx in advance | |
Hi guys , Im new at pythons . Hope you all can help me out here : Im trying to write a code which prints the elements from every list as a line . so If my lists are : l1 = ['0000002', '0000003', '0000004', '0000005', '0000008', '0000009', '0000010'] l2 … | |
I am facing problem connecting problem connecting remote MySQL server which is firewall protected. I used the valid user name and password, but it throws me the error [I]OperationalError: (2003, "Can't connect to MySQL server on 'www.myreomtemysqlserver.com' (10061)")[/I] I want to connect from python. I searched in Google is there … | |
I am trying to make pygame draw a shape from a list of shapes imported with fileIO but i get a pygame import error please help [CODE]import random import pygame w = 640 h = 480 x = open("shapes.txt") z = x.readlines()[n] n = random.randrange(6) screen = pygame.display.set_mode((w, h)) pygame.draw.z(screen, … | |
Ok so if anyone can spare a few minutes and can tell me what each of these things are in terms of python (or plain english), that would be FANTASTIC! [code] (this is in a for loop where d is defined as 1-9) D = load(['digit' num2str(d) '.ascii'],'-ascii'); save(['digit' num2str(d) … | |
Correction: The subject line was supposed to have said BAR CHARTS, not bar codes. Rather than reinventing the wheel, I'd like to know if something already exists that will get going me in the right direction. I have a program that, among other things, ftp's files to multiple computers in … | |
Oh man, I'm sure you guys are going to have a good time making fun of my newbie self, so enjoy! I have output that looks like this: [' sum\n', '\n', '1257869640: 6.8744400000e-02\n', '1257869660: 6.8744400000e-02\n', '1257869680: 6.8634000000e-02\n', '1257869700: 6.9022750000e-02\n', '1257869720: 7.0189000000e-02\n', '1257869740: 7.0189000000e-02\n', '1257869760: 6.9119800000e-02\n', '1257869780: 6.8245000000e-02\n', '1257869800: 6.8245000000e-02\n', '1257869820: … | |
[CODE]#include <iostream> #include <sstream> #include <fstream> #include <string> #include "Python.h" using namespace std; #define tP PyRun_SimpleString(pyCom.c_str()) double func(double x); int main() { //file to write numbers to ofstream file; file.open("numCache.txt"); //string for int to string conversion string temp; stringstream output; //string that is read from console string numCache; //returned number … | |
I'm making a small game in which you can choose the amount of points needed for victory. You play until either cpu_point or player_point is equal to (or greater than) the rounds. You get one point per win. What I'm having trouble with is the while check. I'd like to … | |
Hey guys, I want to create a new array in python. But cant seem to find a way of doing it without having to give initializing values... Basically i want to do wat this java line does float myArr[65353]; and to make matters worse when storing/retrieving data i wont be … | |
hey guys, i have a problem.. i have this chunk of text like this..... [code] No. Time Source Destination Protocol Info 2 0.005318 192.168.110.33 192.168.110.44 ICMP Echo (ping) request Frame 2 (98 bytes on wire, 98 bytes captured) Ethernet II, Src: Cisco-Li_4d:e1:30 (00:1c:10:4d:e1:30), Dst: IntelCor_4d:77:83 (00:13:02:4d:77:83) Internet Protocol, Src: 192.168.110.33 … | |
hey guys, Got another question: in C programming etc we can stop an execution of say an infinite look by pressing Ctrl+C. What's the equivalent in python? i'm using the IDLE GUI. I've found myself in situations where its running a never ending long task which i want to stall, … | |
Hi, from below output I need to capture the DKC0 and DKA100 respectively to PKC0 and PKA0. Idea is if I pass PKA0 it should print DKA0 and if I pass PKA0 then it shd print DKA100. If I pass PKD0 and PKC0 it shd not print anything. SCSI Summary … | |
Can I pass a string filename as a parameter to a function? For example, [CODE]def func("something.txt"):[/CODE] When I do this, it says that the syntax is invalid. Is there a proper way to do it or it is simply not done? | |
I have a file like this: a,z,1 b,y c,x,1 d,w,1 e,v f,u What I need to do is to create a dictionary that has the characters in the first column as keys and characters in the third column as values. The rest should be ignored, i.e. {a:1, c:1, d:1}. This … |
The End.