4,305 Posted Topics

Member Avatar for georgerohith

Looks like Java has similar problems with older versions of Fedora: [url]http://fedoraproject.org/wiki/JavaStackTraces?action=raw[/url]

Member Avatar for vegaseat
0
109
Member Avatar for john_27

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]

Member Avatar for vegaseat
0
213
Member Avatar for qwester

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 …

Member Avatar for bumsfeld
0
366
Member Avatar for TheSkunkMan

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) # …

Member Avatar for TheSkunkMan
0
4K
Member Avatar for Jackiemonster

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) …

Member Avatar for vegaseat
0
173
Member Avatar for bumsfeld

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 …

Member Avatar for vegaseat
0
123
Member Avatar for Skyline_GTR

Nice little game program! Could you gives us your latest project zip file? Makes it easier to look at and help you!

Member Avatar for Skyline_GTR
0
568
Member Avatar for mikul86

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!

Member Avatar for vegaseat
0
74
Member Avatar for coder_gus

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 …

Member Avatar for coder_gus
0
244
Member Avatar for c_shaft05

[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() # …

Member Avatar for vegaseat
0
3K
Member Avatar for Avner .H.

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 …

Member Avatar for vegaseat
0
163
Member Avatar for shanenin

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 = …

Member Avatar for shanenin
0
126
Member Avatar for bumsfeld

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" # …

Member Avatar for bumsfeld
0
153
Member Avatar for bumsfeld

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 …

Member Avatar for bumsfeld
0
146
Member Avatar for bumsfeld

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, …

Member Avatar for vegaseat
2
411
Member Avatar for bumsfeld

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 …

Member Avatar for vegaseat
0
153
Member Avatar for FinnDutch

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]

Member Avatar for FinnDutch
0
155
Member Avatar for vegaseat

[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 …

0
679
Member Avatar for vegaseat

[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: …

0
6K
Member Avatar for Dani

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 …

Member Avatar for vegaseat
0
156
Member Avatar for bumsfeld

Look at KeyboardInterrupt in the Python reference. Right now, I don't have a good example. I try to work on one!

Member Avatar for a1eio
0
296
Member Avatar for shanenin

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 …

Member Avatar for vegaseat
0
142
Member Avatar for Ene Uran

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++. …

Member Avatar for vegaseat
0
178
Member Avatar for Avner .H.

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.

Member Avatar for kerumai
0
235
Member Avatar for bumsfeld

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.

Member Avatar for vegaseat
0
118
Member Avatar for CutCrusader

Python looks like pseudocode by design, so write down what you would do in pseudocode, and you should be almost there.

Member Avatar for vegaseat
0
131
Member Avatar for bumsfeld

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.

Member Avatar for vegaseat
0
109
Member Avatar for CutCrusader

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 …

Member Avatar for CutCrusader
0
99
Member Avatar for Micko

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 …

Member Avatar for vegaseat
0
188
Member Avatar for sifuedition

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.

Member Avatar for vegaseat
0
177
Member Avatar for shanenin

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.

Member Avatar for vegaseat
0
91
Member Avatar for Micko

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 …

Member Avatar for vegaseat
0
245
Member Avatar for altheastronut

[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.

Member Avatar for Raven11
0
227
Member Avatar for iamboredguy

[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]

Member Avatar for vegaseat
0
163
Member Avatar for aripaka

Not sure, if this is what you want for displaying a BMP file: [url]http://www.daniweb.com/code/snippet174.html[/url]

Member Avatar for vegaseat
0
212
Member Avatar for sara.rythm

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)) …

Member Avatar for Dave Sinkula
0
943
Member Avatar for G-Do

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.

Member Avatar for G-Do
0
390
Member Avatar for Micko

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 …

Member Avatar for Micko
0
181
Member Avatar for a1eio

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.

Member Avatar for vegaseat
0
504
Member Avatar for cleblanc

A very interesting problem! Just out of curiosity, where is the module normalDate from?

Member Avatar for cleblanc
0
252
Member Avatar for nephish
Member Avatar for nephish
0
176
Member Avatar for xav.vijay

The module commands only works in Linux and popen() is in module os that would explain few things. Otherwise I don't know nothing!

Member Avatar for xav.vijay
0
8K
Member Avatar for nephish

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++

Member Avatar for nephish
0
161
Member Avatar for Avner .H.

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 &quot is an HTML/XML thing.

Member Avatar for vegaseat
0
229
Member Avatar for vancasas
Member Avatar for Micko

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, …

Member Avatar for bumsfeld
0
213
Member Avatar for Mahen

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); …

Member Avatar for vegaseat
0
178
Member Avatar for Micko

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 …

Member Avatar for vegaseat
0
407
Member Avatar for mccarthp

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.

Member Avatar for vegaseat
0
197
Member Avatar for shanenin

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 …

Member Avatar for vegaseat
0
156

The End.