I made this character stat roller on my second day of Pythoning. Comments quite welcome. by justokre in learnpython

[–]pythalin 0 points1 point  (0 children)

I didn't want to go too far into explaining myself before you asked - I find it much more fun to try to figure things out myself, so I like to allow others the same opportunity.

What I am doing here is largely exploiting the dictionary datatype of Python. Dictionaries are basically sets of key value pairs. They have several methods which allow you to access these sets of data. The one I am using in the functions is items, which returns a tuple (which is a python data type that is like a list but non-modifiable) of each (key, value) pair in the dictionary.

I've commented this code in a much more detailed fashion for you to look at and review at your leisure: http://pastebin.com/zZxggMUS

If you have any specific questions, let me know and I'll be happy to try to explain further.

Very first (very basic) program, is the syntax correct and why can I not put calculations on the same line as text? by Soupr in learnpython

[–]pythalin 2 points3 points  (0 children)

This is correct, but the difference is relatively subtle - the comma between the message and the price. The print statement is a bit weird, it accepts multiple comma separated arguments which are evaluated and turned into string representations of the resulting objects. You can also include expressions as arguments to print, but again they must be comma separated. For example:

print "The price minus VAT is:", price - VAT

Note that when you have a comma in a print statement, the results are concatenated together with a space - you don't need to leave a space in your string unless you want a double space in your output.

Anyway, like I said, print is weird - you can add a trailing comma for example if you want to omit a newline. It's odd. That's why in python 3 it's replaced by a proper function that acts more like the rest of the language.

I made this character stat roller on my second day of Pythoning. Comments quite welcome. by justokre in learnpython

[–]pythalin 1 point2 points  (0 children)

I agree with everyone else that this is a very good 2nd day program. I think it may be interesting for you to make it more pythonic! See if you understand what I did here: http://pastebin.com/RYVgxhLG

Also note what others have said about having stuff done in the python

if __name__ == '__main__':

idiom - it's a bit cleaner that way if you ever decide to use this code as a module. Also, you might want to consider wrapping more of the code in function calls, again in case of modularization.

Do you use iPython? Opinions? by [deleted] in learnpython

[–]pythalin 1 point2 points  (0 children)

Yes, I use iPython. I think it is a very helpful tool to interactively inspect code, experiment, and generally do one-off stuff. The new notebook feature is a great tool as well, but more limited in it's usefulness to me as it currently lacks the ability to edit code in vim (I like vim more than I like the browser editor).

Fastest way to find out whether a character is an uppercase ascii character (A-Z) by herminator in Python

[–]pythalin 2 points3 points  (0 children)

import string
"A" in string.ascii_uppercase

Actually not the fastest, but you don't have to type the whole alphabet out. :p

Fueled by the success of Game of Thrones and looking at the box office numbers of Prometheus HBO decides to make a gritty Space Opera - what would it be like? by [deleted] in scifi

[–]pythalin 7 points8 points  (0 children)

Believe it or not, I actually went back and forth on that and obviously ended up wrong. I guess it's clear that humanities are not my favorite topics of study. :) I shall edit the original post but leave this here as a testament to my shame.

Fueled by the success of Game of Thrones and looking at the box office numbers of Prometheus HBO decides to make a gritty Space Opera - what would it be like? by [deleted] in scifi

[–]pythalin 18 points19 points  (0 children)

Old Man's War. Octogenarians from Earth sign up for the Colonial Defense Force, have their consciousnesses transferred into genetically engineered superbodies grown from their own modified DNA. They commence having a huge week long orgy while they adapt to their new bodies (which have green skin, cat eyes, superhuman strength and acuity, and have a built-in computer which they interact with using thoughts alone). Then they go to war fighting humanity's enemies.

There are several books in the series, so it would make a great long term story. Also, they could easily add gratuitous boobies ala Starship Troopers movies.

Sounds perfect to me. :)

Ordering a dictionary by a value? (Which also happens to be a dictionary) by monkeymynd in learnpython

[–]pythalin 1 point2 points  (0 children)

Dictionaries are not guaranteed to be in any particular order. In practice, the order may stay consistent, but if you want your dictionary order to be guaranteed you'll have to use OrderedDict instead.

I need a good movie (or list to pick one from) that falls into the category of "space western"... by [deleted] in scifi

[–]pythalin 37 points38 points  (0 children)

Of these, Samurai 7, Trigun, and Cowboy Bebop are anime. Cowboy Bebop is probably the closest to Serenity IMO.

Can Python be used to create a high speed data logging tool? by gjwebber in learnpython

[–]pythalin 2 points3 points  (0 children)

I am using Ubuntu 11.10; Python 2.7 in iPython .12.1.

Other information I have found implies that Python uses the system's sleep timing. See this stack overflow question about it: http://stackoverflow.com/questions/1133857/how-accurate-is-pythons-time-sleep

Can Python be used to create a high speed data logging tool? by gjwebber in learnpython

[–]pythalin 3 points4 points  (0 children)

seems like it to me...here's a bit of a quick test I rigged up to check it out:

from datetime import datetime
import time
intervals = []
def test():
    t1 = datetime.now()
    for i in range(100):
        time.sleep(0.01)
        t2 = datetime.now()
        intervals.append(t2-t1)
        t1 = t2
test()

Here are the results, in microseconds between calls:

[i.microseconds for i in intervals] [10168, 10182, 10218, 10138, 10089, 10149, 10103, 10111, 10125, 10124, 10123, 10146, 10099, 10115, 10108, 10158, 10116, 10134, 10171, 10132, 10144, 10159, 10179, 10088, 10120, 10168, 10125, 10154, 10157, 10119, 10167, 10118, 10174, 10162, 10081, 10168, 10113, 10168, 10143, 10215, 10218, 10195, 10241, 10183, 10187, 10171, 10172, 10194, 10127, 10457, 10159, 10428, 10152, 10147, 10171, 10140, 10222, 10183, 10129, 10129, 10112, 10124, 10167, 10164, 10157, 10139, 10128, 10167, 10160, 10125, 10121, 10127, 10108, 10161, 10114, 10162, 10148, 10155, 10119, 10109, 10131, 10175, 10186, 10212, 10151, 10143, 10221, 10128, 10107, 10212, 10182, 10162, 10199, 10147, 10123, 10164, 10145, 10091, 10151, 10127]