4,305 Posted Topics
Re: Looks like Java has similar problems with older versions of Fedora: [url]http://fedoraproject.org/wiki/JavaStackTraces?action=raw[/url] | |
Re: Are you following an example from a book? Normally I would use the ctypes module from: [url]http://starship.python.net/crew/theller/ctypes/[/url] | |
Re: I am experimenting with your attachment. Please do not mix tabs and spaces for indentations, stick with spaces! A few comments would be nice! It just makes it nicer for other people to use and check your code. What do you want to use to start the program? Just for … | |
Re: This the most basic test for PyGame that I have, give it a fly ... [php]import pygame from pygame.locals import * yellow = (255,255,0) # RGB color tuple # initialise screen pygame.init() screen = pygame.display.set_mode((350, 250)) pygame.display.set_caption('Basic Pygame program') # fill background background = pygame.Surface(screen.get_size()) background = background.convert() background.fill(yellow) # … | |
Re: This would be one way to shorten your code with a for loop: [code]import turtle import time def x(n): "draw a turtle x of size n, shortened version using a for loop" t3=turtle.Pen() for k in (1, 2): if k == 1: t3.left(60) else: t3.right(120) t3.forward(n) t3.left(60) t3.forward(n) t3.right(120) t3.forward(n) … | |
Re: Oh gee, I do remember the peek and poke days of some basic dialects. You could use peek and poke to copy one array to another real fast. Borland C and Pascal have a way to write and read to absolute memory. Python, I don't know, must not be needed … | |
Re: Nice little game program! Could you gives us your latest project zip file? Makes it easier to look at and help you! | |
Re: Please put your Python code between code tags Python needs the proper indentation and with the amount of if and else groupings you have, it is almost impossible to figure out what belongs to what! | |
Re: This will do it ... [code=python]print "Fill a string with a - z:" alphaStr = "" # letters a to z are ASCII code 97 to 122 for k in range(97, 123): alphaStr += chr(k) print alphaStr # if you don't have an ASCII table handy let Python do it … | |
Re: [QUOTE=shanenin]do acronyms even have periods in them?[/QUOTE] Most of the time they don't! Here is just one more way to do it ... [code=python]str1 = "senior health inFormation development" # just in case it isn't all lower case str2 = str1.lower() # make a title-cased copy str3 = str2.title() # … | |
Re: Do you mean something like this ... # a function can return a function def func1 () : def func2 () : print "Blaaaa" def func3 () : print "Yaaaaa" return func2, func3 func2, func3 = func1() func2() func3() print func2 # test, what is it? print func3 Please put … | |
Re: Running your script from an IDE like IDLE or DrPython will keep the display window open for the errors to show up. You might try to add a time.sleep(10) at the end. I think there is way to pipe the error messages to a file too. [php]import sys sys.stderr = … | |
Re: You can only inherit another class. The module calendar contains a function calendar, but you can't inherit a function. This small code might explain a few basic things ... [code=python]import calendar import Cookie import inspect if inspect.isclass(calendar): print "calendar is a class" else: print "calendar is not a class" # … | |
Re: I was looking for a halfway decent example code, but when you also asked for list comprehension, a light went up, and I combined the two questions: [code=python]# using the module profile to profile a function or a statement import profile #help('profile.run') def evenList1(): """returns a list of even numbers … | |
Re: Python's lambda allows you to declare a one-line nameless minifunction on the fly. The format is: lambda parameter(s): expression using the parameter(s) It returns the result of the expression. The expression has to be a one-liner (no newlines)! Here is a little example ... [code=python]# sort strings in a list, … | |
Re: List comprehension is something Python borrowed from a language called Haskell. It returns a new list and is shorter and simply faster than the traditional loop/append alternative. I repeated the earlier code for the Python profile module here. Look at the two functions and you can get an idea how … | |
Re: Sounds like you are a candidate for "Regular Expression" pattern matching and searches contained in the Python module re, more detail at: [url]http://www.amk.ca/python/howto/regex/[/url] | |
[B]Python and the JPEG Image File, Part 1, The Header[/B] [B]Intro[/B] The JPEG image file format (.jpg) is very popular on the internet because you can pack a lot of picture information into a relatively small file. There are competing file formats like GIF and PNG. GIF is rather limited … | |
[B]Intro[/B] When you declare an integer variable in C, the variable is assigned a fixed memory location with enough space to hold the type integer. When you then initialize the variable with a value, the value is put into that space. Take a look at the C code sample below: … | |
Re: When I first learned Python, I was very familiar with STL in C++ and easily recognized many of Python's containers. Now there was an understandable way to work with STL. Actually Python reminded me of the transition I made from Pascal to C in my early school days. The computer … | |
Re: Look at KeyboardInterrupt in the Python reference. Right now, I don't have a good example. I try to work on one! | |
Re: It depends what you want the IDE to do. For pure quick Python I like the DrPython IDE. It brings up code on a tabbed notebook and you can cut and paste existing code easily from one page to another. It splits the screen to show results, again you can … | |
Re: I am using C++ and Python, the two languages complement each other well. To develop an idea, Python will get you there faster. The code is easier on the eyes and more intelligible. Of course, Python is an interpreted language, so it will be inherently slower in execution than C++. … | |
Re: Would be nice to have an actual example! Check the "mimic a C struct type with an empty Python class " in the Starting Python sticky. You could do something along that line. | |
Re: In C I used lots of switch/case statements. Now Python does not have a switch/case construct. You could use mutliple if/elif, or better a dictionary with lambda functions. Come to think of it, a Python dictionary almost looks like a C switch/case. Read up on lambda too. | |
Re: Python looks like pseudocode by design, so write down what you would do in pseudocode, and you should be almost there. | |
Re: See, if this example makes any sense to you: [url]http://www.daniweb.com/code/snippet368.html[/url] I am sure there are much better and simpler examples out there. | |
Re: Like Micko said, it is in the representation ... [code=python]# two different ways to represent integer 705083 as a hexadecimal number # 0x is the official prefix for a hexnumber # the results appear different, but both are of type string and change back to base 10 properly # pick … | |
Re: DrPython has a plugin called PyCheckerSupport. You have to download and install PyChecker on your own and then give PyCheckerSupport the location of Checker.py You can read about PyChecker here: [url]http://pychecker.sourceforge.net/[/url] A classic debugger is part of Python in module pdb. Simply use help('pdb') to get more information. That module … | |
Re: Dave Sinkula reports something like that and a smart solution in thread: [url]http://www.daniweb.com/techtalkforums/thread19956-2.html[/url] It could be compiler dependent, since I was not able to repeat the problem. | |
Re: Thanks Shanenin, this book strikes a nice balance of theory and examples. I do recommend it for anyone, be they beginners or skindeep in Python. | |
Re: Look at variable k in the code snippet at: [url]http://www.daniweb.com/code/snippet354.html[/url] This is a similar situation, it is declared outside of the class methods and needs self to bring it into the methods. The class name won't do. If your book uses this, then it is wrong (can happen). Maybe very … | |
Re: [QUOTE=prog-bman]umm what's with the unneeded goto is while(1) not good enough anymore?[/QUOTE] I have to agree with prog-man (again). The goto should only be used to get out of deeply nested loops, otherwise it is considered bad style. | |
Re: [QUOTE=prog-bman]Gooog. Don't recommend that compiler. Go and get a graphics lib like SDL or Allegro you can draw shapes with them.[/QUOTE] I agree with prog-bman! SDL is free and used a lot for games. For a short code snippet and how to download SDL take a look at: [url]http://www.daniweb.com/code/snippet193.html[/url] | |
Re: Not sure, if this is what you want for displaying a BMP file: [url]http://www.daniweb.com/code/snippet174.html[/url] | |
Re: 1. could be a trick question ... [code] std::cout << "numbers from 1 to 100 and 100 to 1"; [/code] 2. assuming we are talking integers, use a macro like ... [code]// macro to swap two arguments of any type #define SWAP(x, y) ((x) ^= (y) ^= (x) ^= (y)) … | |
Re: G-Do very nice indeed! This would make a good contribution to the Python Code Snippets on DaniWeb. Right now there is mostly my stuff there, new blood and new ideas are always welcome! Just a thought. | |
Re: I think just to start out with any computer language, the foreign character issue is hot tar on the road to progress. As a beginner, try to do without it for a while. The following should scare anybody. ASCII admittedly is only a 7-bit character set (0 to 127), originally … | |
Re: Actually using the Python Shell in this case gave the clue that this was not a text file, since most of the ASCII text characters are less than hex A0. | |
Re: A very interesting problem! Just out of curiosity, where is the module normalDate from? | |
Re: Look in your Python documentation under thread or threading. | |
Re: The module commands only works in Linux and popen() is in module os that would explain few things. Otherwise I don't know nothing! | |
Re: I used to do that sort of thing in C, and I know the operator module has most of the C like syntax in it. You will have to learn to be a "shifty" person. With all those >> and << your code looks like C++ | |
Re: I think Avner doesn't want his double quotes replaced by single quotes? I have seen this happen with Python before, but it didn't make any difference. Other languages ar not quite so forgiving. The " is an HTML/XML thing. | |
| |
Re: A good tutorial for beginners is at: [url]http://www.byteofpython.info/[/url] Also read through the Starting Python "sticky" and the Python code snippets here on DaniWeb. Above everything, run the code and experiment with it! Change it a little at first and then get braver! I have bought a number of Python books, … | |
Re: Other C compilers use strftime() ... [CODE]#include <time.h> size_t strftime(char *s, size_t maxsize, const char *fmt, const struct tm *t); [/CODE] ... with this as a typical example ... [CODE]#include <stdio.h> #include <time.h> #include <dos.h> int main(void) { struct tm *time_now; time_t secs_now; char str[80]; tzset(); time(&secs_now); time_now = localtime(&secs_now); … | |
Re: Which IDE are you using now? Which operating system do you have? To create a subdirectory/subfolder you can use the "Save File As" dialog box of your IDE. There is a small icon in the top row you can click to create a new folder. Oops now I know what … | |
Re: For COM support with IE you need to download the Python Win32 Extensions from: [url]http://starship.python.net/crew/mhammond/win32/Downloads.html[/url] That installation package also includes a number of sample files you might be intersted in. | |
Re: Either example is okay. If I would have to show somebody how Python works, the second example using a different variable name would be less confusing. Make your function names "action verb" descriptive like printNumber(num1) or printValue(val1). I started using a number with a variable name after I used str … |
The End.