shadwickman 159 Posting Pro in Training

You can browse through that svn tree like folders, and save/view the files in each one. Look at their GoogleCode wiki for info about each of the topics (boot, boa, etc.).

shadwickman 159 Posting Pro in Training

Yield is for generator functions. Return ends the function and sends back the specified value.
Generators are functions that return iterators, i.e. they 'yield' a value after each iteration of them, before proceeding to the next one. This is generally used for things where you don't need all the results returned at once (which must load them all into memory), but instead only gives back the results one at a time (which can vastly reduce memory usage).

Python documentation on generators,
And on iterators.

Here's their example of a simple generator:

def reverse(data):
    # start at the last index and step back one each time.
    for index in range(len(data)-1, -1, -1):
        yield data[index]

for char in reverse('golf'):
    print char

"""result:
f
l
o
g
"""

What this does is call each iteration of the reverse function each time the "for" loop executes in the statement for char in reverse('golf') . This way, only a single letter is sent back each time, rather than the fully-reversed string.
This isn't a great example of generator usage, but say if you had a dataset with 1000s of numbers and you needed to perform calculations on them, but you'd only be working on one item in the set at a time anyway. Then a generator would be useful as it would save a TON of memory by only returning each item as it's needed.
Hope that helped!

Your_mum commented: helpful +1
shadwickman 159 Posting Pro in Training

Looks like you can connect anonymously via HTTP and browse the source.
http://cleese.googlecode.com/svn/trunk/

You'd need to build it yourself, and definitely have a look through their wiki to see if they have any in-depth instructions for that, along with dependencies, etc.

shadwickman 159 Posting Pro in Training

If you mean by "Python OS", an operating system that's built purely on Python, then no. As far as I know, that wouldn't work anyway because the interpreter to run Python needs an OS to run on in the first place (?). Correct me if I'm wrong though...

And I'm not sure about Python with Android, although I believe Jython may work and you can access the Java API that way.

shadwickman 159 Posting Pro in Training

Brazil !

Yay! I had completely forgotten about that strange, strange movie by the brilliant Terry Gilliam.

shadwickman 159 Posting Pro in Training

By the way, you've now gotten me interested in a little side project to make a simple web browser with wxPython :P
Unfortunately, the html capabilities of the HtmlWindow in wx.html are quite poor, but I'm going to try to work on improving them possibly.

P.S. I already have my GUI done, I'm down to just the coding of the inner mechanics now :D

shadwickman 159 Posting Pro in Training

Well, there is no return statement at all in that function... so it would return <i>None</i>.

shadwickman 159 Posting Pro in Training

Definitely read that "VERY good tutorial" link in that post (the tut on zetcode.com) as it's very comprehensive and you'll get a good understanding of wxPython :)

shadwickman 159 Posting Pro in Training

Have you never used wxPython before? If not, check out one of my previous posts to a thread concerning good resources for it:
http://www.daniweb.com/forums/post898473-7.html

shadwickman 159 Posting Pro in Training

Well if you're using it to handle form data, I'll just post a quick script.
Here's my HTML form:

<form action='cgi-bin/pycgi.py'>
        <input type='text' name='person' value='First Name' size=20>
        <input type='submit' value='Submit'>
</form>

And the script I specified as the action, "pycgi.py":

#!/usr/bin/python
import cgi

def main():
    # you need to print this line before any others!
    print "Content-type: text/html\n"

    # parse form data into dictionary
    form = cgi.FieldStorage()
    # our text field was named 'person',
    # so check to see if we have a value for it
    if form.has_key("person") and form["person"].value != "":
        print "<h1>Hello %s.</h1>" % form["person"].value
    
main()

This is a very, very simple example but as you see, you can get form data this way. You could also have Python just run calculations that you need and post them (if you can use POST, I haven't tried) so that a PHP page can use $_POST to get the values Python passed to it, and then display them, etc.

shadwickman 159 Posting Pro in Training

Like I was saying, C++ has the benefits of extremely fast execution speed (which you'd need for 3D stuff), and also object oriented design. I most prefer Python, but it's not as logical a choice as C++ for 3D graphics as it's a lot slower in execution. I don't know much of anything about .NET, but my suggestion for C++ still stands. And with it, you can try using OpenGL, or the more difficult DirectX (but the SDK for DirectX is only available on Windows).

shadwickman 159 Posting Pro in Training

Update:
I currently have a python cgi script running on a free web host, which I find a pretty damn good deal. It supports Python, Django, Perl, MySQL, PHP, ASP.NET, Ruby on Rails, and JSP.

I registered a co.cc domain name and just set the nameservers to the ones for my heliohost account, which they have a tutorial somewhere on how to do it if you're confused.

shadwickman 159 Posting Pro in Training

As a side note, "super" is a reserved keyword in Python already, and you named your script that. It shouldn't cause this problem at all but in the future it might raise some sort of issue if you expand on this.

As for the current situation, what was the value you typed into the textbox in the HTML form? Was it "hello"?

shadwickman 159 Posting Pro in Training

@ William
And mathematics? How very threatening :P

shadwickman 159 Posting Pro in Training

I'm curious now how long it takes your computer to parse this "50 million line file" with Python, seeing how slow Python is compared to things like C... unless of course you were exaggerating the number of lines.
Anyways, if you open a file with fhandle = open('myfile', 'a') then when you call write("") on it, it'll just append it. Like The_Kernel said, just make sure you keep track of whether the file has been created yet, and if not, open it with the mode parameter as "w".

shadwickman 159 Posting Pro in Training

PLEASE! Use code tags! If you look at your post, you realize your Python code has no indentation anymore, and indentation is a crucial part of Python. I'm not going to bother looking through your code until you edit that post and put your code in those tags to preserve the spacing.

Salem commented: Well said! +36
shadwickman 159 Posting Pro in Training

In case you didn't notice, your linedata dictionary has no key "id". Hence you receiving the "KeyError" problem. You need the ID of the column you're inserting this into if I'm correct (I barely touched on MySQL about a year ago). Is the table you're inserting this into blank, and you're building it up? Or does it contain data and you're just overwriting/editing rows?
If you're building up a blank table, why not just track the number of rows you've added to the table so far and then you can use that as the id? Set "rowsadded" to zero at the beginning of your script and then increment it after each row input to the table. That way you can have your linedata dictionary as this:

linedata = {'id':rowsadded, 'time':data[1], 'date':data[9],'latitude':latitude,'longitude':longitude,'speed':data[7]}
sneekula commented: thanks for taking the tough ones +8
shadwickman 159 Posting Pro in Training

Because when you read lines from a file, a string is returned. Your data[3] is "0833.6323" (as a string). You can just convert it to a float first before the calculation like this: latitude=str(float(data[3])/100.0) EDIT:
I noticed you signed your post "sraven". You already have an account here (under that name) so why did you start this new one?

shadwickman 159 Posting Pro in Training

Alas, "shadwickman" was too long for it so I had to settle to just "shadwick".

S.H.A.D.W.I.C.K.:
Synthetic Handcrafted Android Designed for Worldwide Infiltration and Ceaseless Killing

It gives the same for the "C.K." as you.

shadwickman 159 Posting Pro in Training

@serken sendur
Regardless who brought it up, let's just drop it. And of course we weren't meant to spend such long amounts of time tucked away in a virtual world online. Hence why I go on hiking, camping, and cycling trips to take breaks from time to time, and why I try not to code for obscene amounts of hours, even when I want to due to a good idea/implementation.
Now, back to movies!

For amazing westerns, I'd suggest "The Good, The Bad, and The Ugly" or "Billy Cassidy and the Sundance Kid".

shadwickman 159 Posting Pro in Training

Zymic.com, where I have a free site hosted on their vndv.com server. I haven't tried executing Python scripts on their server, but the FTP didn't block my uploading of Python scripts when I wanted a place to back some up, whereas other free hosts wouldn't allow any .py or .pyw files.

shadwickman 159 Posting Pro in Training

Sorry, I usually associate education with some sort of intelligence, apparently lacking due to your posts which are difficult enough to try to read and comprehend. That and 90% of people who post in this forum about trying to make a game don't even know any programming yet, they just have ambitions, and your atrocious spelling linked you in my mind with those people. Sorry for the confusion.
So which programming language are you going to go with then? If you're doing a masters in comp. sci. you should understand the strengths and weaknesses of various languages.

shadwickman 159 Posting Pro in Training

Ahahah! Wow, this is just getting a little odd guys (not to mention off topic, what happened to movies? :P)

William Hemsworth commented: *nods* i'll stop. +12
shadwickman 159 Posting Pro in Training

Yes good one! And to stay on the topic of drugs : requiem for a dream

Methinks I should watch this movie now...

As for powerfully moving films, Full Metal Jacket and Platoon are definitely up there.

shadwickman 159 Posting Pro in Training

If anyone is still interested in those old, nostalgic text-based games to run in the console, there's Python Universe Builder by Joe Strout. Yes, it's a dead project as the last release dates back to 2006, but it still works fine if anyone is interested. On the Sourceforge page for PUB, the download section contains 1.0a2 and 2.0, but as far as I know 2.0 isn't a full release, so 1.0a2 is the working one (i'll need to double-check). And by 'working' I mean you'll need to manually install it into your site-packages folder for Python, after changing a few things like instances in its scripts of the "whrandom" module which was phased out long ago in lieu of the "random" module. Oh, and this will only work for Python 2.x installations, not 3.0.

I'm posting this here because I know an unbelievable amount of users post here about either making a 3D game or making a game engine, without actually knowing anything about those topics in the least. If people want to make a game, then a simple text-based one can still be a lot of fun (comes down to how well the story is written), and should provide good practice for anyone interested in Python or in getting into game development.

Here's a tutorial for it if anyone's interested.

Nick Evan commented: Nice project. +19
shadwickman 159 Posting Pro in Training

If you look at this forum, there is a permanent thread called "Projects for the Beginner". See here.
It has a huge amount of projects/ideas in it, so you can start looking through it for stuff to do.

shadwickman 159 Posting Pro in Training

Got it :D

data = [['4/18/94', '29.125', '442.46'],
    ['4/19/94', '29.336', '442.54'],
    ['1/20/04', '75.175', '1138.77'],
    ['1/21/04', '75.711', '1147.62'],
    ['1/22/04', '75.595', '1143.94']]
    
result = []

for item in data:
    # current middle index as a float
    n = float(item[1])
    
    # if there are no items in the result list yet
    if not result:
        result.append(item)
        
    # otherwise, if there are,
    else:
        # previous number (last one in result list) as a float
        prevnum = float(result[-1][1])
        
        if (prevnum < 30 and n > 75) or (prevnum > 75 and n < 30):
            result.append(item)

"""
My result:
[['4/18/94', '29.125', '442.46'], ['1/20/04', '75.175', '1138.77']]
"""
rasizzle commented: excellent advice +1
shadwickman 159 Posting Pro in Training

This post on stackoverflow seems to have the skeleton code for going about and making it a service.

And there's something about using srvany.exe here.

I've never actually done this myself so I can't offer much more insight...

shadwickman 159 Posting Pro in Training

This mail might help:
http://mail.python.org/pipermail/python-list/2002-August/161778.html

It looks like there are some good example's of it being used in the code, and about adjusting privileges.

EDIT:
It looks like the last argument you'd want to be 1 or True because that's the reboot option...

shadwickman 159 Posting Pro in Training

Can you post some of your code? I'm confused as to why you need to hold so many files open at one time... could you just cycle them one by one and not have them all open?

shadwickman 159 Posting Pro in Training

sraven, this only works when the command prompt window is in focus. If you're trying to capture all input for other applications too, then you'll need to use pyHook or be able to expand on sneekula's getch() example, but I'm not sure how to make that grab key presses with the command prompt not being in focus....

shadwickman 159 Posting Pro in Training

Before trying to create a game, try learning a programming language first so that you understand how it works and you've grasped the basics.
If you want games anyway, I'd suggest C++, but for simple 2D stuff you can use Python + pygame.

@Salem
Thank you for posting that link :)

shadwickman 159 Posting Pro in Training

I think you can have it pass the command to the computer via the os module. Like for Debian-based GNU/Linux distros you could write:

import os
os.system("halt")

The only problem I can think of is that this would require super-user privileges to execute the shut down.

With Windows, if you have the win32api module, you can try this:

import win32api
win32api.InitiateSystemShutdown()

I haven't tried that before though, so you may want to look deeper into that. Hope I helped a bit!

shadwickman 159 Posting Pro in Training

No they won't. I've only found one free host that let me upload Python scripts so far...

shadwickman 159 Posting Pro in Training

As far as I know you'll have to set up your server for this to work. It's not going to happen client-side, for security reasons AND because the client would need Python installed AND because web-browsers don't execute python code in them. If you customize the server I'm sure you can trigger the script in the server to run, and then return results in the form of a web page which the visitor sees.

shadwickman 159 Posting Pro in Training

Why did you post VB code? This is the Python forum. Regardless, please put it in code tags.

shadwickman 159 Posting Pro in Training

I'd say split the string into a list and use the filter method:

file_Name1 = 'abc123de'
# store that string as a list of characters
L1 = list(file_Name1)
# call filter on it using a lambda expression
L1 = filter(lambda x: x in '1234567890', L1)
# L1 now = ['1', '2', '3']
num_digits = len(L1)

EDIT:
If you need to know what filter does, lookie here:

filter(function, iterable)

    Construct a list from those elements of iterable for which function returns true. iterable may be either a sequence, a container which supports iteration, or an iterator. If iterable is a string or a tuple, the result also has that type; otherwise it is always a list. If function is None, the identity function is assumed, that is, all elements of iterable that are false are removed.

    Note that filter(function, iterable) is equivalent to [item for item in iterable if function(item)] if function is not None and [item for item in iterable if item] if function is None.

    See itertools.filterfalse() for the complementary function that returns elements of iterable for which function returns false.
shadwickman 159 Posting Pro in Training

I never have used VB, but what you'd need is to track the pointers to the ships in an array (or objects in the array, however VB does it). That way you can directly access the ship instances through the array. In Python it would be like this:

# my ship class
class Ship(object):
    def __init__(self, name):
         self.name = name

# test ships
a = Ship("Galleon")
b = Ship("Skiff")
c = Ship("Rowboat")
myships = [a, b, c]  # list of ship objects

# access ships
print myships[0].name  # result is "Galleon"
myships[1].name = "Wreckage"
print myships[1].name  # result is "Wreckage"

You can see that the list contains the objects so that you can directly modify them or access their properties.

shadwickman 159 Posting Pro in Training

Ohhh boy. It looks like you need to actually learn a programming language still. What are you currently making this game in? It sounds like you don't know the basics of what an object is, or about classes and inheritance, etc... Are you using VisualBasic or something?

shadwickman 159 Posting Pro in Training

Adam's Crunchy is by far the best. You can't beat it.

shadwickman 159 Posting Pro in Training

Just store your data in one file for each map, simple solution. Each row is a row in the map, and each value between commas in a column:

1,5,6,3,5
4,8,9,6,4
2,4,6,7,6
0,0,1,3,2
5,7,4,2,1

That could be a 5 x 5 map. Then just read the file and split data into a 2D array or a list, depending on your programming language.

shadwickman 159 Posting Pro in Training

Yeah, HTML can't do anything like that on its own, it's just a mark-up language. If you want to develop text-based games first, and have no prior programming experience, I'd suggest Python. The syntax is simple and understandable. The one thing is that the recipient's computer needs Python installed on it to run the scripts (it comes pre-installed on most Linux distros), unless you use the py2exe module to make an executable.
C or C++ is another good bet, but the syntax I find harder for beginners to get into. This is what I'd choose for 2D or 3D development, or some Windows applications.

shadwickman 159 Posting Pro in Training

If you haven't done programming/development before, please, for the love of god, do not start trying to make 3D games. You need to learn the basic concepts first, then work your way up.

And I wouldn't suggest Java for 3D games anyway. C++ would be your best bet. If you really wanted, you could do simplistic things with Python and a 3D library for that, like Panda3D. But I'd suggest going with C++ anyways because it seems that programmers who start off with C/C#/C++ understand more on the concept/theory end of it all, which you'll need for 3D stuff. Plus, you'll need great skill at mathematics too if you want to build 3D games.

As for Windows application development, you'll probably hear a lot about Java and C or C++, but Python usually works just as well, and Python's syntax is usually a lot easier to grasp for beginners too. Just depends if your program needs to run as quickly as possible, in which case I'd go with C.

Anyways, good luck getting into programming. The key thing is: START OUT SMALL. Don't jump onto huge projects without building skill with the language first.

shadwickman 159 Posting Pro in Training

Threading is for running multiple things at once. Such as having a thread run to update a GUI while another performs some sort of data manipulation. So, threading is much different than what you're after.

shadwickman 159 Posting Pro in Training

Please, edit your above post and put whatever is Python code inside tags like this:

[code=python] CODE GOES HERE [/code]

Indenting is essential to Python, so your code needs to retain it in the post.

shadwickman 159 Posting Pro in Training

If you want a copy of the sorted object, instead of directly modifying the object itself, use the built-in "sorted" function.

>>> L = ['z', 'aa', 'g', 'ab', 'yz']
>>> Ls = sorted(L)
>>> Ls  # returned copy
['aa', 'ab', 'g', 'yz', 'z']
>>> L  # original stays the same
['z', 'aa', 'g', 'ab', 'yz']

And if you use it on strings, it breaks them apart into a list of characters, and then proceeds to sort that. And it works on tuples (but returns the sorted one as a list!):

>>> sorted("Hello World!")
[' ', '!', 'H', 'W', 'd', 'e', 'l', 'l', 'l', 'o', 'o', 'r']
>>> sorted((5,3,4,1,2))
[1, 2, 3, 4, 5]

Just in case you wanted to sort something without modifying the original, or sort a string!

shadwickman 159 Posting Pro in Training

Which Linux distro are you using? Regardless, if you want a visual editor for wxPython, I'd suggest wxGlade. It generates nice code but it may take a little getting used to using. I mostly just code all my GUIs by hand anyways.
As for good wxPython resources, here's some:

Style Guide - Not too comprehensive, but might offer some standardizing tips.
wxPython by Example - A short tutorial which has good examples for bare-bones apps.
wxPython Cookbook - Contains a lot of information on various aspects of wxPython. Lots of examples.
Widget Examples - Has a number of good application skeletons and examples about individual widgets and their uses.
Documentation - The regular documentation for wxPython.

VERY GOOD Tutorial - I'd recommend giving this a read through and looking at the example code as it's quite large and it covers a lot in an understandable way.

wxGlade Tutorial - If you decide to give wxGlade a go. Make sure to learn pure wxPython coding first so that you can do it by hand. Then use this for large GUIs just to speed things up if you want.

There was another very definitive page with all the widgets and examples and information about them, but I can't seem to find it at the moment. I'll post it later if I do find it. Hope these help for now! :)

shadwickman 159 Posting Pro in Training

As for a regular application, I'd go with wxPython for sure. Best GUI toolkit I've used for Python (I can't stand Tkinter at all).
If you want to make it more graphics-rich and not look like a regular program, you can try pygame, but that might be a bit difficult to jump into right away.

shadwickman 159 Posting Pro in Training

Trainspotting
One Flew Over the Cuckoo's Nest
A Clockwork Orange
A Scanner Darkly
Fear and Loathing in Las Vegas

jephthah commented: quality head trips. +11
shadwickman 159 Posting Pro in Training

Expanding even further:

import random

mini = 1  # min. number of tuple indices
maxi = 5  # max. number of tuple indices
low = 1  # low-end of range of number
high = 9  # high-end of range of number

result = []
for j in range(10):
    current = []
    # add a random number of indices to the tuple
    for k in range(random.randint(mini, maxi)):
        # add another number to the current list
        current.append(random.randint(low, high))
    # convert current list into a tuple and add to resulting list
    result.append(tuple(current))
"""
my result:
[(2, 1), (5, 9, 6, 1), (3,), (7, 1, 3), (5, 2, 5, 6, 1), (3,), (1, 1, 9, 8, 7), (2,), (9, 5, 3), (6,)]
"""

Just allows for a random number of indices in each tuple.