python,pygame,documentationRelated issues-Collection of common programming errors


  • tkf
    python
    I know what double underscore means for Python class attributes/methods, but does it mean something for method argument?It looks like you cannot pass argument starting with double underscore to methods. It is confusing because you can do that for normal functions.Consider this script:def egg(__a=None):return __aprint “egg(1) =”, print egg(1) printclass Spam(object):def egg(self, __a=None):return __aprint “Spam().egg(__a=1) =”, print Spam().egg(__a=1)Running this script yields:egg(1) = 1Spam().e

  • thefourtheye
    python iterator generator
    Can I reset an iterator / generator in Python? I am using DictReader and would like to reset it (from the csv module) to the beginning of the file.

  • James Lin
    python django
    Lets say I want to get a record that match a value and I have 2 approaches to do it:First:try:obj = Model.objects.get(field = value) exceptpassSecond:if Model.objects.filter(field = value).count() > 0:obj = Model.objects.filter(field_value)[0]Lets put the code comments aside,which way should I use or which one do you prefer to read? The first one seems faster because only 1 DB look up, but the second way seems a bit more readable, but requires 2 DB look ups.

  • Carlo Pires
    python debugging assert
    I’ve found python assert statement is a good way to catch situations that should never happen. And can be removed by python optimization when the code is trusted. It seems to be a perfect mechanism to run python applications in debug mode. But looking at several python projects like django, twisted and zope it is almost never used. So, why this happens?Why asserts statements is not largely used in python community?

  • parxier
    python comparison types operators logic
    This is somehow related to my question Why is ”>0 True in Python?In Python 2.6.4:>> Decimal(‘0’) > 9999.0 TrueFrom the answer to my original question I understand that when comparing objects of different types in Python 2.x the types are ordered by their name. But in this case:>> type(Decimal(‘0’)).__name__ > type(9999.0).__name__ FalseWhy is Decimal(‘0’) > 9999.0 == True then?UPDATE: I usually work on Ubuntu (Linux 2.6.31-20-generic #57-Ubuntu SMP Mon Feb 8 09:05:19 UTC 20

  • wim
    python list dictionary tuples hashable
    I’m a bit confused about what can/can’t be used as a key for a python dict. dicked = {} dicked[None] = ‘foo’ # None ok dicked[(1,3)] = ‘baz’ # tuple ok import sys dicked[sys] = ‘bar’ # wow, even a module is ok ! dicked[(1,[3])] = ‘qux’ # oops, not allowedSo a tuple is an immutable type but if I hide a list inside of it, then it can’t be a key.. couldn’t I just as easily hide a list inside a module?I had some vague idea that that the key has to be “hashable” but I’m just going to ad

  • Galuvian
    python pylons
    I have a Pylons app where I would like to move some of the logic to a separate batch process. I’ve been running it under the main app for testing, but it is going to be doing a lot of work in the database, and I’d like it to be a separate process that will be running in the background constantly. The main pylons app will submit jobs into the database, and the new process will do the work requested in each job.How can I launch a controller as a stand alone script?I currently have:from warehou

  • larsmans
    python multidimensional-array numpy swap
    I love the way python is handling swaps of variables:a, b, = b, aand I would like to use this functionality to swap values between arrays as well, not only one at a time, but a number of them (without using a temp variable). This does not what I expected (I hoped both entries along the third dimension would swap for both):import numpy as np a = np.random.randint(0, 10, (2, 3,3)) b = np.random.randint(0, 10, (2, 5,5)) # display before a[:,0, 0] b[:,0,0] a[:,0,0], b[:, 0, 0] = b[:, 0, 0], a[:,0,0]

  • boleto
    c++ python boost
    Including this#include <boost/python.hpp>in VS 2012 produces the error below:Although the code works with#include <boost/lexical_cast.hpp>c:\projects\vs\reports\kdb\CKDBData.h(66): warning C4800: ‘G’ : forcing value to bool ‘true’ or ‘false’ (performance warning) C:\Projects\Library\boost_1_54_0\boost/function/function_fwd.hpp(43): error C2143: syntax error : missing ‘,’ before ‘return’ C:\Projects\Library\boost_1_54_0\boost/function/function_fwd.hpp(44): error C2143: syntax error :

  • F.J
    python sqlite3
    I was testing some code on the interpreter and I noticed some unexpected behavior for the sqlite3.Row class.My understanding was that print obj will always get the same result as print str(obj), and typing obj into the interpreter will get the same result as print repr(obj), however this is not the case for sqlite3.Row:>>> print row # the row object prints like a tuple (u’string’,) >>> print str(row) # why wouldn’t this match the output from above? <sqlite3.Row object

  • user2388331
    python pygame conways-game-of-life
    I have been trying to write my own version of Conway’s Game of Life as practice for Python using Pygame. I first wrote the functions for initializing the game field, and then calculating the next generation. I verified it’s functionality using the console to print the results and verify that they returned the expected results (just 2 generations deep by hand on a 5×5 grid).An important note of how I am calculating the neighbors… Instead of doing a for loop through the entire array and doing fo

  • user2565140
    python-2.7 pygame
    i have just started programming with python and i have write this code:import sys, pygame pygame.init()size = width, height = 800, 600 speed = [2, 2] black = 1, 1, 1screen = pygame.display.set_mode(size)ball = pygame.image.load(“ball.bmp”) ballrect = ball.get_rect() player1 = pygame.image.load(“player1.png”) player1rect = player1.get_rect()mod_x = mod_y = 0while 1:for event in pygame.event.get():if event.type == pygame.QUIT: sys.exit()elif event.type == KEYDOWN:if event.key == K_Wmovex = 2if eve

  • Maciej Miasik
    python pygame transparent
    Is it possible to display PyGame surfaces with controllable alpha? I would like to take a surface with its own per pixel alpha and display it with variable level of translucency without affecting the surface data and keep the transparency intact i.e. the objects on the surface would keep their shapes but their “contents” becoming more or less translucent.In other words I want to combine per-pixel alpha from the source image with per-surface alpha calculated at the runtime.

  • Twinborn
    python graphics pygame
    http://cache.kotaku.com/assets/resources/2008/02/dbzburstcell.jpg-edit- bassically just detailed vectorized 2d games.When making a side scroller in pygame or any other comparable 2d framework with python, can you utilize graphics such as in the above link?Thanks.

  • Tshepang
    python pygame runtime-error executable py2exe
    I made a game with Python 2.6. I think its a good game so I would like to share it to my friends. I made an executable with it however it came up with an error:Runtime ErrorThis application has requested the Runtime to terminate in an unusual way. Please contact the application’s support team for more information.I searched this up on google and I came up with information about how to solve the problem. Even though I try to understand the steps they say it just doesn’t make sense. I looked at m

  • MrLog
    dll pygame py2exe
    I’ve started making a game using python and pygame, and tried using py2exe. It didn’t work, (like it should), so I used the pygame2exe code found here: http://www.pygame.org/wiki/Pygame2exeIt still doesn’t work, and comes up with the error stated in the title. I have a suspicion it’s to do with not having the correct dlls, but I’m clueless apart from that.Also, I managed to create a pygame executable in what I think was exactly the same way a few months ago, but now it doesn’t work. If you’d lik

  • user2727932
    python pygame windows-vista compatibility cx-freeze
    I made a game with Python 2.6. I also made it into an executable with cx_Freeze 4.3. When I run the executable on my computer it came up with this:Microsoft Visual C++ Runtime LibraryProgram: C:\Users\smm\Desktop\asteroid shower 1.4.5\asteroid.exeThis application has requested the Runtime to terminate it in an unusual way. Please contact the application’s support team for more information.I don’t understand what happened here. I tried solving the problem but with no luck. Then I searched the run

  • HuntR2
    python segmentation-fault pygame kinect simplecv
    I have been using SimpleCV for find blobs to be used with a self-driving robot. The problem is when I call the findBlobs command in SimpleCV. When I completely block the lens of the Kinect Camera, PyGame crashes giving me this error:Fatal Python error: (pygame parachute) Segmentation FaultSometimes it works and other times it just crashes, even when the lens is unblocked. It will almost always crash when i run it for longer than about thirty seconds. I have re-installed and fixed many problems

  • Viruss mca
    python while-loop switch-statement pygame
    I am working on a program and i need to switch through different loops. this works thought when i try to switch back to the previous loop i crashes.Any suggestions?P.S. the bellow are examplese.g. Function = Home(change loop)Function = txtbox(change loop)Function = Home (Crashes here)import pygame, sys, time, random from pygame.locals import * import math import sys import os # set up pygame pygame.init()# set up the window WINDOWWIDTH = 1200 WINDOWHEIGHT = 650 windowSurface = pygame.display.set

  • Quaki Gabbar
    pygame
    i am trying to play sounds with pygame sound. My code is this:from tkinter import * import pygame root= Tk() pygame.init() bass = pygame.mixer.Sound(‘sounds\\bass.wav’) snare = pygame.mixer.Sound(‘sounds\snare.wav’) crash = pygame.mixer.Sound(‘sounds\crash.wav’) bass.play() snare.play() crash.play() root.mainloop()When i run this code all three wave files are played together. I want to play them one after the other, and possibly have control over the time difference between each successive sound

  • user983022
    documentation xsd jibx
    Any ideas on how to include the xsd:annotation and xsd:documentation content defined in the schema as javadoc in the generated pojo using jibx???For now I only get the schema fragment on top of the class but cant see the annotation documentation for the schema.thanks for you time.

  • Günter Zöchbauer
    documentation dart dart-editor
    I’m trying to generate the documentation of dart code. I’ve noticed that I cannot generate any documentation through DartDoc because inside my library I sometime need to import some external libraries. Below I have a small example that shows my actual problem.listController.dartpart of controllers;@NgController (selector: ‘[list-control]’,publishAs: ‘listCtrl’ ) class ListController {}controllers.dartlibrary controllers;import ‘package:angular/angular.dart’;part ‘listController.dart’;The end res

  • Ben
    php ide documentation phpdoc
    I’ve been coding php for a while, and have never done much documenting. Sure I’ll give 2 word summaries of functions that I might forget about later. I am starting a large project soon, and decided this should be my jumping in point for better documentation. So are there any good tips on documenting? Any nice IDEs that make it useful/intuitive? I currently use notepad++, but there doesn’t seem to be much support for phpdoc syntax, so what would be a good (preferably open source) alternative?

  • Martijn Pieters
    python unit-testing class documentation doctest
    I would like to use a doctest comment block to demonstrate the usage of a particular base class, but either this cannot be done with doctest or I am doing something wrong. Here is my simple demo code.class MyClass(object):”’>>> m = MyClass()>>> print m.x1>>> class A(MyClass):>>> def __init__(self):>>> super(A,self).__init__()>>>>>> a = A()>>> print a.x1”’def __init__(self):self.x = 1if __name__ == “__main__”:import doc

  • makerofthings7
    ios objective-c azure documentation azure-mobile-services
    I’m a new Objective C programmer and am following the directions here to set up push notification. When I add the following “optional” code I get an error, and am unable to compile:- (void)application:(UIApplication *)application didReceiveRemoteNotification: (NSDictionary *)userInfo {NSLog(@”%@”, userInfo);UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@”Notification” message:[[userInfo objectForKey:@”aps”] valueForKey:@”alert”] delegate:nil cancelButtonTitle:@”OK” otherButtonTitles:n

  • cvsguimaraes
    language-agnostic coding-style documentation tags
    Many software engineers are familiar with the usage of special comment “tags” that can be added to their code comments, for use in searches, automated task tracking, and so forth. Some of the most popular are FIXME, TODO, UNDONE, and HACK. I’m a bit confused with the usage of HACK and UNDONE tags. Little help please?Bonus points for showing the basic difference between FIXME and TODO

  • Noldorin
    .net documentation xml-comments xml-documentation
    I’ve been attempting to fully document all types, methods, properties, etc. of a class library using XML comments but have run into a curious effect involving the cref attribute (used by see tags for example). Going by the advice of this MSDN page as well as following various other examples on MSDN and other websites, it seems that whenever one specifies a reference value using the cref tag, it must be prefixed with a certain marker that classifies the refence (such as ‘T:’ for type and ‘M:’ for

  • mutewinter
    ruby documentation
    Say I’m writing some ruby code and I want to use the standard Date type to get the current date. Instead of using a search engine, is there a faster way to find the documentation for this class? I know I can get the methods for Date by typing Date.methods, but as far as I know this doesn’t provide details about argument types or return value.Editor-specific answers are welcomed. My editor of choice is Emacs.

  • Gilles
    linux documentation iproute
    I use use ip by system(“ip link set eth0 up”) in a C program. I know that system returns -1 if it fails and returns what the called function returns(exit). E.g., if eth0 is not exist on the system, it returns 256. Where can I find what these numerical values defined for ip? For example ifconfig’s Return Codes:Return Code Description 0 The command completed successfully. 4 The command completed successfully, but a warning condition was detected. 8 The command was not specified correctly.

  • Ben Jencks
    linux storage documentation reference
    Can someone point me to a fairly complete reference on the Linux I/O system, primarily how all the buffers and caches are handled and flushed?My understanding so far is that there areApplication buffers (including fread/fwrite buffers allocated by libc) VFS buffers that read and write act on pages that are mmaped (same as VFS buffers?) Filesystem-specific buffers (same as VFS buffers? Filesystem supplies some policy at least, e.g. XFS is more aggressive about write caching) The disk driver proba

Web site is in building