Go to advanced search

by BlackJack
Fri Nov 02, 2012 10:29 pm
Forum: Python
Topic: Quitting Pygame
Replies: 2
Views: 1695

Re: Quitting Pygame

@davef21370: If the program was started in a terminal you could try pressing Ctrl+C to interrupt it. Otherwise killing the process should stop it. Of course it is better to call `pygame.quit()` at the end. Either right before you exit, or by registering the function with the `atexit` module. @antilo...
by BlackJack
Fri Nov 02, 2012 1:50 pm
Forum: Python
Topic: a bases converter
Replies: 6
Views: 1201

Re: a bases converter

@antiloquax: The name `to_denary()` is misleading. The function converts a string into an integer. A number itself does not have a base at all, it is only representations of a number as a string that have a base. There is nothing ten-based about an `int`. If at all one could say it is base two as mo...
by BlackJack
Fri Nov 02, 2012 1:07 pm
Forum: Python
Topic: When to declare variables as global
Replies: 27
Views: 5107

Re: When to declare variables as global

@Grumpy Mike: In an object oriented programming language classes are the preferred language construct to describe stateful objects. That does not make it a poor language.
by BlackJack
Fri Nov 02, 2012 5:04 am
Forum: Python
Topic: Image Sequence
Replies: 3
Views: 696

Re: Image Sequence

@f22lightning: Could you describe the problem in more detail? I'm not sure I understand what you want to do. If you want to load numbered images into a sequence data structure, then work through a Python tutorial — there is one in the Python documentation — and learn about integers, strings, formatt...
by BlackJack
Fri Nov 02, 2012 4:58 am
Forum: Python
Topic: Detecting differences between images
Replies: 6
Views: 1168

Re: Detecting differences between images

@TfromNYC: Use `numpy` arrays as croston suggested. Or better make proper use of the `numpy` arrays you are already using! `pygame.surfarray` uses `numpy` already. Replace the nested Python loops by array operations.
by BlackJack
Fri Nov 02, 2012 4:50 am
Forum: Python
Topic: Python Sound Sampler with Pygame.Mixer
Replies: 12
Views: 4991

Re: Python Sound Sampler with Pygame.Mixer

@hakanl: The SyntaxError is caused by the syntax error in the source. ;-) The second ``try:`` makes no sense. After the ``try`` block there has to be ``except:`` or ``finally:`` but not another ``try:``.
by BlackJack
Thu Nov 01, 2012 9:31 am
Forum: Python
Topic: When to declare variables as global
Replies: 27
Views: 5107

Re: When to declare variables as global

@Grumpy Mike: The rule is: when a name is 1. not declared ``global`` or 2. declared ``nonlocal`` or 3. or is an argument 4. or somewhere in the function there is a value assigned to a name, that name is local. Mind the difference between assigning an object to a name and manipulating the state of an...
by BlackJack
Thu Nov 01, 2012 9:08 am
Forum: Python
Topic: Python serial problem
Replies: 1
Views: 677

Re: Python serial problem

@piacco: Port numbers only work for devices with names like ``/dev/ttyS*``. If you want to use something with a device filename not matching that pattern you have to supply the device filename instead of a port number.
by BlackJack
Thu Nov 01, 2012 9:02 am
Forum: Python
Topic: simple adventure game.
Replies: 22
Views: 5508

Re: simple adventure game.

@emba: You are using function calls somewhat as BASIC GOTO, as jumps to named code sections, but they are more like GOSUB. The code seems to do what you want, but only for a limited time, then the program will stop with an error. So while you can postpone learning about recursion, you should not use...
by BlackJack
Thu Nov 01, 2012 8:35 am
Forum: Python
Topic: randomly occurring struct.error
Replies: 3
Views: 1080

Re: randomly occurring struct.error

@Fr4nky: You are much to sloppy with the socket code. Neither does `send()` guarantee all bytes are actually written to the stream, nor does `read(x)` guarantee that x bytes are read — it could be less or more. At the sender you have to write a loop that makes sure all bytes have been send. And when...
by BlackJack
Thu Nov 01, 2012 8:23 am
Forum: Python
Topic: Keyboard interrupts other than Ctrl-C
Replies: 5
Views: 2932

Re: Keyboard interrupts other than Ctrl-C

@Hove: Pygame has an event loop. The programmer has to poll and loop over the events.
by BlackJack
Thu Nov 01, 2012 8:14 am
Forum: Python
Topic: OCR High Scores Task
Replies: 5
Views: 1290

Re: OCR High Scores Task

With public API I mean functions that are meant to be called by the user of the module vs. the private API: helper functions only meant to be used by the module internally. A naming convention in Python is to prefix internal stuff with one underscore.
by BlackJack
Sat Oct 27, 2012 4:00 pm
Forum: Python
Topic: WJEC Programming GCSE task.
Replies: 2
Views: 542

Re: WJEC Programming GCSE task.

@antiloquax: I don't get the idea behind the class here. It is not separated from the code on module level and it does not separate business logic from GUI code either. The decision what goes into the class and what's on module level seems to be completely arbitrary. Global variables are bad style w...
by BlackJack
Sat Oct 27, 2012 3:37 pm
Forum: Python
Topic: OCR High Scores Task
Replies: 5
Views: 1290

Re: OCR High Scores Task

@antiloquax: The program allows more than one entry for a given user which contradicts the assignement and makes the update functionality ambigious. The assignments says „users and their highest score” which exludes multiple scores per user because there is just one highest. The `add()` function sho...
by BlackJack
Sat Oct 27, 2012 1:17 pm
Forum: Python
Topic: OCR Set Password task.
Replies: 2
Views: 541

Re: OCR Set Password task.

@antiloquax: It shows a use case of recursion that is not a good idea in a language without tail call optimization. While it probably doesn't end *this* program with an Exception, the general technique fills up the stack memory unnecessarily and will fail eventually. So it's not a good idea to show ...
by BlackJack
Sat Oct 27, 2012 12:05 pm
Forum: Python
Topic: Help on editing script..
Replies: 12
Views: 1933

Re: Help on editing script..

@urra901109: As shown the return value from the external command to get the free memory contains the newline at the end.
by BlackJack
Sat Oct 27, 2012 12:02 pm
Forum: Python
Topic: When to declare variables as global
Replies: 27
Views: 5107

Re: When to declare variables as global

@SiriusHardware: Using global variables is not illegal but in general a bad idea and should be treated as illegal unless there is a good explanation for the use case. Python's design philosophy isn't to prevent the programmer from shooting himself in the foot but to trust the programmer not to do st...
by BlackJack
Fri Oct 26, 2012 1:16 pm
Forum: General programming discussion
Topic: Best way to start shell script on startup?
Replies: 10
Views: 5299

Re: Best way to start shell script on startup?

@jal: Then the answer is definitely ``crontab``.
by BlackJack
Fri Oct 26, 2012 1:14 pm
Forum: Python
Topic: simple adventure game.
Replies: 22
Views: 5508

Re: simple adventure game.

@emba: Those endless recursive calls limit the runtime as the program will stop with a ``RuntimeError: maximum recursion depth exceeded`` eventually. I would go so far to say it is broken. This recursive programming style is not made for programming languages where the language specification doesn't...
by BlackJack
Fri Oct 26, 2012 11:43 am
Forum: Python
Topic: Help on editing script..
Replies: 12
Views: 1933

Re: Help on editing script..

@urra901109: I guess `mem` already contains a newline character when you get it from the external command. So you have to remove it. Edit: Tested it on my desktop computer: In [336]: subprocess.Popen("free -m | grep cache: | awk '{print $4}' | cut -d/ -f1", shell=True, stdout=subprocess.PIPE).commun...
by BlackJack
Thu Oct 25, 2012 8:03 am
Forum: Python
Topic: simple adventure game.
Replies: 22
Views: 5508

Re: simple adventure game.

@jburke71: The program makes very little use of Python. It almost looks like it is written with another programming language in mind. No classes, not even dictionaries are used. But lists with magical numerical indices as constants to make it a little more readable instead. Truth values and `None` a...
by BlackJack
Wed Oct 24, 2012 9:20 pm
Forum: Python
Topic: convert number to length-specified hex string
Replies: 7
Views: 2454

Re: convert number to length-specified hex string

@jojopi: C#/.NET uses similar syntax to format values into strings.
by BlackJack
Wed Oct 24, 2012 9:08 pm
Forum: Python
Topic: When to declare variables as global
Replies: 27
Views: 5107

Re: When to declare variables as global

Rule of thumb: Never use the ``global`` keyword, and don't use global data structures either. Objects other than those with a constant should be passed into functions as arguments. Otherwise any program that grows a bit larger will become messy and the data flow is hard to understand, functions are ...
by BlackJack
Wed Oct 24, 2012 8:28 pm
Forum: Python
Topic: Adding non-printable characters to strings
Replies: 8
Views: 1550

Re: Adding non-printable characters to strings

@SiriusHardware: The `rstrip()` function does not remove spaces between words. It strips characters from the end of a string, or *r*ight side, which is why it is called `*r*strip()`. If you have a string containing multiple lines and want them in a list with every element being one of the lines, the...
by BlackJack
Sun Oct 21, 2012 7:57 pm
Forum: Python
Topic: executing a program
Replies: 6
Views: 1128

Re: executing a program

@Dotterelly: See http://docs.python.org/using/unix.html#miscellaneous

So making the file executable and adding the „shebang”-line should work.

Go to advanced search